Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding singleton pattern in Arm.Core and Proto #20591

Merged
merged 12 commits into from
May 4, 2021
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.ResourceManager.Core
{
/// <summary>
/// A class representing the operations that can be performed over a specific resource.
/// </summary>
public abstract class SingletonOperationsBase : OperationsBase
{
/// <summary>
/// Initializes a new instance of the <see cref="SingletonOperationsBase"/> class for mocking.
/// </summary>
protected SingletonOperationsBase()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SingletonOperationsBase"/> class.
/// </summary>
/// <param name="clientContext"></param>
/// <param name="id"></param>
internal SingletonOperationsBase(ClientContext clientContext, ResourceIdentifier id)
: base(clientContext, id)
{
}
}

/// <summary>
/// Base class representing a singleton operation
/// </summary>
/// <typeparam name="TOperations"> The type of the class containing operations for the underlying resource. </typeparam>
/// <typeparam name="TIdentifier"> The type of the resource identifier. </typeparam>
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "<Pending>")]
public abstract class SingletonOperationsBase<TIdentifier, TOperations> : OperationsBase
where TOperations : SingletonOperationsBase<TIdentifier, TOperations>
where TIdentifier : ResourceIdentifier
{
/// <summary>
/// Initializes a new instance of the <see cref="SingletonOperationsBase{TIdentifier, TOperations}"/> class for mocking.
/// </summary>
protected SingletonOperationsBase()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ContainerBase{TOperations, TIdentifier}"/> class.
/// </summary>
/// <param name="parent"> The resource representing the parent resource. </param>
/// <param name="id"> The identifier of the resource that is the target of operations. </param>
protected SingletonOperationsBase(OperationsBase parent, ResourceIdentifier id)
: base(new ClientContext(parent.ClientOptions, parent.Credential, parent.BaseUri), id)
{
}

/// <summary>
/// The typed resource identifier for the underlying resource
/// </summary>
public new virtual TIdentifier Id
allenjzhang marked this conversation as resolved.
Show resolved Hide resolved
{
get { return base.Id as TIdentifier; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Core;

namespace Proto.Compute
{
/// <summary> The status of the latest virtual machine scale set rolling upgrade. </summary>
public partial class RollingUpgradeStatusInfo : ProxyResource<ResourceGroupResourceIdentifier, Azure.ResourceManager.Compute.Models.RollingUpgradeStatusInfo>
{
/// <summary>
/// Initializes a new instance of the <see cref="rollingUpgradeStatusInfo"/> class.
/// </summary>
public RollingUpgradeStatusInfo(Azure.ResourceManager.Compute.Models.RollingUpgradeStatusInfo rollingUpgradeStatusInfo)
: base(rollingUpgradeStatusInfo.Id, rollingUpgradeStatusInfo)
{
}

/// <summary>
/// Gets the subnet id.
///</summary>
public override string Name => Model.Name;

/// <summary> The rolling upgrade policies applied for this upgrade. </summary>
public RollingUpgradePolicy Policy => Model.Policy;

/// <summary> Information about the current running state of the overall upgrade. </summary>
public RollingUpgradeRunningStatus RunningStatus => Model.RunningStatus;

/// <summary> Information about the number of virtual machine instances in each upgrade state. </summary>
public RollingUpgradeProgressInfo Progress => Model.Progress;

/// <summary> Error details for this upgrade, if there are any. </summary>
public ApiError Error => Model.Error;
}
}
allenjzhang marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using Azure.ResourceManager.Compute.Models;
using Azure.ResourceManager.Core;
using Azure.ResourceManager.Core.Adapters;
using System.Collections.Generic;

namespace Proto.Compute
{
/// <summary> A class representing the VirtualMachineScaleSet data model. </summary>
public partial class VirtualMachineScaleSetData : TrackedResource<ResourceGroupResourceIdentifier, Azure.ResourceManager.Compute.Models.VirtualMachineScaleSet>
{
/// <summary> Initializes a new instance of VirtualMachineScaleSetData. </summary>
public VirtualMachineScaleSetData(Azure.ResourceManager.Compute.Models.VirtualMachineScaleSet vmScaleSet)
: base(vmScaleSet.Id, vmScaleSet.Location, vmScaleSet)
{
Sku = vmScaleSet.Sku;
Plan = vmScaleSet.Plan;
Identity = vmScaleSet.Identity;
Zones = vmScaleSet.Zones;
UpgradePolicy = vmScaleSet.UpgradePolicy;
AutomaticRepairsPolicy = vmScaleSet.AutomaticRepairsPolicy;
VirtualMachineProfile = vmScaleSet.VirtualMachineProfile;
ProvisioningState = vmScaleSet.ProvisioningState;
Overprovision = vmScaleSet.Overprovision;
DoNotRunExtensionsOnOverprovisionedVMs = vmScaleSet.DoNotRunExtensionsOnOverprovisionedVMs;
UniqueId = vmScaleSet.UniqueId;
SinglePlacementGroup = vmScaleSet.SinglePlacementGroup;
ZoneBalance = vmScaleSet.ZoneBalance;
PlatformFaultDomainCount = vmScaleSet.PlatformFaultDomainCount;
ProximityPlacementGroup = vmScaleSet.ProximityPlacementGroup;
AdditionalCapabilities = vmScaleSet.AdditionalCapabilities;
ScaleInPolicy = vmScaleSet.ScaleInPolicy;
}

/// <summary> The virtual machine scale set sku. </summary>
public Azure.ResourceManager.Compute.Models.Sku Sku { get; set; }
/// <summary> Specifies information about the marketplace image used to create the virtual machine. This element is only used for marketplace images. Before you can use a marketplace image from an API, you must enable the image for programmatic use. In the Azure portal, find the marketplace image that you want to use and then click **Want to deploy programmatically, Get Started -&gt;**. Enter any required information and then click **Save**. </summary>
public Azure.ResourceManager.Compute.Models.Plan Plan { get; set; }
/// <summary> The identity of the virtual machine scale set, if configured. </summary>
public VirtualMachineScaleSetIdentity Identity { get; set; }
/// <summary> The virtual machine scale set zones. NOTE: Availability zones can only be set when you create the scale set. </summary>
public IList<string> Zones { get; }
/// <summary> The upgrade policy. </summary>
public UpgradePolicy UpgradePolicy { get; set; }
/// <summary> Policy for automatic repairs. </summary>
public AutomaticRepairsPolicy AutomaticRepairsPolicy { get; set; }
/// <summary> The virtual machine profile. </summary>
public VirtualMachineScaleSetVMProfile VirtualMachineProfile { get; set; }
/// <summary> The provisioning state, which only appears in the response. </summary>
public string ProvisioningState { get; }
/// <summary> Specifies whether the Virtual Machine Scale Set should be overprovisioned. </summary>
public bool? Overprovision { get; set; }
/// <summary> When Overprovision is enabled, extensions are launched only on the requested number of VMs which are finally kept. This property will hence ensure that the extensions do not run on the extra overprovisioned VMs. </summary>
public bool? DoNotRunExtensionsOnOverprovisionedVMs { get; set; }
/// <summary> Specifies the ID which uniquely identifies a Virtual Machine Scale Set. </summary>
public string UniqueId { get; }
/// <summary> When true this limits the scale set to a single placement group, of max size 100 virtual machines. NOTE: If singlePlacementGroup is true, it may be modified to false. However, if singlePlacementGroup is false, it may not be modified to true. </summary>
public bool? SinglePlacementGroup { get; set; }
/// <summary> Whether to force strictly even Virtual Machine distribution cross x-zones in case there is zone outage. </summary>
public bool? ZoneBalance { get; set; }
/// <summary> Fault Domain count for each placement group. </summary>
public int? PlatformFaultDomainCount { get; set; }
/// <summary> Specifies information about the proximity placement group that the virtual machine scale set should be assigned to. &lt;br&gt;&lt;br&gt;Minimum api-version: 2018-04-01. </summary>
public SubResource ProximityPlacementGroup { get; set; }
/// <summary> Specifies information about the dedicated host group that the virtual machine scale set resides in. &lt;br&gt;&lt;br&gt;Minimum api-version: 2020-06-01. </summary>
public SubResource HostGroup { get; set; }
/// <summary> Specifies additional capabilities enabled or disabled on the Virtual Machines in the Virtual Machine Scale Set. For instance: whether the Virtual Machines have the capability to support attaching managed data disks with UltraSSD_LRS storage account type. </summary>
public AdditionalCapabilities AdditionalCapabilities { get; set; }
/// <summary> Specifies the scale-in policy that decides which virtual machines are chosen for removal when a Virtual Machine Scale Set is scaled-in. </summary>
public ScaleInPolicy ScaleInPolicy { get; set; }
}
}
40 changes: 40 additions & 0 deletions sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Threading;
using System.Threading.Tasks;
using Azure.ResourceManager.Core;

namespace Proto.Compute
{
/// <summary>
/// Class representing a VirtualMachineScaleSet along with the instance operations that can be performed on it.
/// </summary>
public class VirtualMachineScaleSet : VirtualMachineScaleSetOperations
{
/// <summary>
/// Gets the data representing this VirtualMachineScaleSet.
/// </summary>
public VirtualMachineScaleSetData Data { get; private set; }

/// <summary>
/// Initializes a new instance of the <see cref="VirtualMachineScaleSet"/> class.
/// </summary>
/// <param name="operations"> The client parameters to use in these operations. </param>
/// <param name="resource"> The resource that is the target of operations. </param>
internal VirtualMachineScaleSet(ResourceOperationsBase operations, VirtualMachineScaleSetData resource)
: base(operations, resource.Id)
{
Data = resource;
}

/// <inheritdoc />
protected override VirtualMachineScaleSet GetResource(CancellationToken cancellation = default)
{
return this;
}

/// <inheritdoc />
protected override Task<VirtualMachineScaleSet> GetResourceAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(this);
}
}
}
Loading