|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +#nullable disable |
| 5 | + |
| 6 | +using System; |
| 7 | +using System.Collections; |
| 8 | +using System.Collections.Generic; |
| 9 | +using System.Globalization; |
| 10 | +using System.Linq; |
| 11 | +using System.Threading; |
| 12 | +using System.Threading.Tasks; |
| 13 | +using Azure; |
| 14 | +using Azure.Core; |
| 15 | +using Azure.Core.Pipeline; |
| 16 | +using Azure.ResourceManager; |
| 17 | + |
| 18 | +namespace Azure.ResourceManager.Chaos |
| 19 | +{ |
| 20 | + /// <summary> |
| 21 | + /// A class representing a collection of <see cref="CapabilityResource" /> and their operations. |
| 22 | + /// Each <see cref="CapabilityResource" /> in the collection will belong to the same instance of <see cref="TargetResource" />. |
| 23 | + /// To get a <see cref="CapabilityCollection" /> instance call the GetCapabilities method from an instance of <see cref="TargetResource" />. |
| 24 | + /// </summary> |
| 25 | + public partial class CapabilityCollection : ArmCollection, IEnumerable<CapabilityResource>, IAsyncEnumerable<CapabilityResource> |
| 26 | + { |
| 27 | + /// <summary> |
| 28 | + /// Create or update a Capability resource that extends a Target resource. |
| 29 | + /// Request Path: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{parentProviderNamespace}/{parentResourceType}/{parentResourceName}/providers/Microsoft.Chaos/targets/{targetName}/capabilities/{capabilityName} |
| 30 | + /// Operation Id: Capabilities_CreateOrUpdate |
| 31 | + /// </summary> |
| 32 | + /// <param name="waitUntil"> <see cref="WaitUntil.Completed"/> if the method should wait to return until the long-running operation has completed on the service; <see cref="WaitUntil.Started"/> if it should return after starting the operation. For more information on long-running operations, please see <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/LongRunningOperations.md"> Azure.Core Long-Running Operation samples</see>. </param> |
| 33 | + /// <param name="capabilityName"> String that represents a Capability resource name. </param> |
| 34 | + /// <param name="data"> Capability resource to be created or updated. </param> |
| 35 | + /// <param name="cancellationToken"> The cancellation token to use. </param> |
| 36 | + /// <exception cref="ArgumentException"> <paramref name="capabilityName"/> is an empty string, and was expected to be non-empty. </exception> |
| 37 | + /// <exception cref="ArgumentNullException"> <paramref name="capabilityName"/> or <paramref name="data"/> is null. </exception> |
| 38 | + public virtual async Task<ArmOperation<CapabilityResource>> CreateOrUpdateAsync(WaitUntil waitUntil, string capabilityName, CapabilityData data, CancellationToken cancellationToken = default) |
| 39 | + { |
| 40 | + Argument.AssertNotNullOrEmpty(capabilityName, nameof(capabilityName)); |
| 41 | + Argument.AssertNotNull(data, nameof(data)); |
| 42 | + |
| 43 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.CreateOrUpdate"); |
| 44 | + scope.Start(); |
| 45 | + try |
| 46 | + { |
| 47 | + var response = await _capabilityRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, capabilityName, data, cancellationToken).ConfigureAwait(false); |
| 48 | + var operation = new ChaosArmOperation<CapabilityResource>(Response.FromValue(new CapabilityResource(Client, response), response.GetRawResponse())); |
| 49 | + if (waitUntil == WaitUntil.Completed) |
| 50 | + await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); |
| 51 | + return operation; |
| 52 | + } |
| 53 | + catch (Exception e) |
| 54 | + { |
| 55 | + scope.Failed(e); |
| 56 | + throw; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Create or update a Capability resource that extends a Target resource. |
| 62 | + /// Request Path: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{parentProviderNamespace}/{parentResourceType}/{parentResourceName}/providers/Microsoft.Chaos/targets/{targetName}/capabilities/{capabilityName} |
| 63 | + /// Operation Id: Capabilities_CreateOrUpdate |
| 64 | + /// </summary> |
| 65 | + /// <param name="waitUntil"> <see cref="WaitUntil.Completed"/> if the method should wait to return until the long-running operation has completed on the service; <see cref="WaitUntil.Started"/> if it should return after starting the operation. For more information on long-running operations, please see <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/LongRunningOperations.md"> Azure.Core Long-Running Operation samples</see>. </param> |
| 66 | + /// <param name="capabilityName"> String that represents a Capability resource name. </param> |
| 67 | + /// <param name="data"> Capability resource to be created or updated. </param> |
| 68 | + /// <param name="cancellationToken"> The cancellation token to use. </param> |
| 69 | + /// <exception cref="ArgumentException"> <paramref name="capabilityName"/> is an empty string, and was expected to be non-empty. </exception> |
| 70 | + /// <exception cref="ArgumentNullException"> <paramref name="capabilityName"/> or <paramref name="data"/> is null. </exception> |
| 71 | + public virtual ArmOperation<CapabilityResource> CreateOrUpdate(WaitUntil waitUntil, string capabilityName, CapabilityData data, CancellationToken cancellationToken = default) |
| 72 | + { |
| 73 | + Argument.AssertNotNullOrEmpty(capabilityName, nameof(capabilityName)); |
| 74 | + Argument.AssertNotNull(data, nameof(data)); |
| 75 | + |
| 76 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.CreateOrUpdate"); |
| 77 | + scope.Start(); |
| 78 | + try |
| 79 | + { |
| 80 | + var response = _capabilityRestClient.CreateOrUpdate(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, capabilityName, data, cancellationToken); |
| 81 | + var operation = new ChaosArmOperation<CapabilityResource>(Response.FromValue(new CapabilityResource(Client, response), response.GetRawResponse())); |
| 82 | + if (waitUntil == WaitUntil.Completed) |
| 83 | + operation.WaitForCompletion(cancellationToken); |
| 84 | + return operation; |
| 85 | + } |
| 86 | + catch (Exception e) |
| 87 | + { |
| 88 | + scope.Failed(e); |
| 89 | + throw; |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + /// <summary> |
| 94 | + /// Get a Capability resource that extends a Target resource. |
| 95 | + /// Request Path: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{parentProviderNamespace}/{parentResourceType}/{parentResourceName}/providers/Microsoft.Chaos/targets/{targetName}/capabilities/{capabilityName} |
| 96 | + /// Operation Id: Capabilities_Get |
| 97 | + /// </summary> |
| 98 | + /// <param name="capabilityName"> String that represents a Capability resource name. </param> |
| 99 | + /// <param name="cancellationToken"> The cancellation token to use. </param> |
| 100 | + /// <exception cref="ArgumentException"> <paramref name="capabilityName"/> is an empty string, and was expected to be non-empty. </exception> |
| 101 | + /// <exception cref="ArgumentNullException"> <paramref name="capabilityName"/> is null. </exception> |
| 102 | + public virtual async Task<Response<CapabilityResource>> GetAsync(string capabilityName, CancellationToken cancellationToken = default) |
| 103 | + { |
| 104 | + Argument.AssertNotNullOrEmpty(capabilityName, nameof(capabilityName)); |
| 105 | + |
| 106 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.Get"); |
| 107 | + scope.Start(); |
| 108 | + try |
| 109 | + { |
| 110 | + var response = await _capabilityRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, capabilityName, cancellationToken).ConfigureAwait(false); |
| 111 | + if (response.Value == null) |
| 112 | + throw new RequestFailedException(response.GetRawResponse()); |
| 113 | + return Response.FromValue(new CapabilityResource(Client, response.Value), response.GetRawResponse()); |
| 114 | + } |
| 115 | + catch (Exception e) |
| 116 | + { |
| 117 | + scope.Failed(e); |
| 118 | + throw; |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + /// <summary> |
| 123 | + /// Get a Capability resource that extends a Target resource. |
| 124 | + /// Request Path: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{parentProviderNamespace}/{parentResourceType}/{parentResourceName}/providers/Microsoft.Chaos/targets/{targetName}/capabilities/{capabilityName} |
| 125 | + /// Operation Id: Capabilities_Get |
| 126 | + /// </summary> |
| 127 | + /// <param name="capabilityName"> String that represents a Capability resource name. </param> |
| 128 | + /// <param name="cancellationToken"> The cancellation token to use. </param> |
| 129 | + /// <exception cref="ArgumentException"> <paramref name="capabilityName"/> is an empty string, and was expected to be non-empty. </exception> |
| 130 | + /// <exception cref="ArgumentNullException"> <paramref name="capabilityName"/> is null. </exception> |
| 131 | + public virtual Response<CapabilityResource> Get(string capabilityName, CancellationToken cancellationToken = default) |
| 132 | + { |
| 133 | + Argument.AssertNotNullOrEmpty(capabilityName, nameof(capabilityName)); |
| 134 | + |
| 135 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.Get"); |
| 136 | + scope.Start(); |
| 137 | + try |
| 138 | + { |
| 139 | + var response = _capabilityRestClient.Get(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, capabilityName, cancellationToken); |
| 140 | + if (response.Value == null) |
| 141 | + throw new RequestFailedException(response.GetRawResponse()); |
| 142 | + return Response.FromValue(new CapabilityResource(Client, response.Value), response.GetRawResponse()); |
| 143 | + } |
| 144 | + catch (Exception e) |
| 145 | + { |
| 146 | + scope.Failed(e); |
| 147 | + throw; |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + /// <summary> |
| 152 | + /// Get a list of Capability resources that extend a Target resource.. |
| 153 | + /// Request Path: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{parentProviderNamespace}/{parentResourceType}/{parentResourceName}/providers/Microsoft.Chaos/targets/{targetName}/capabilities |
| 154 | + /// Operation Id: Capabilities_List |
| 155 | + /// </summary> |
| 156 | + /// <param name="continuationToken"> String that sets the continuation token. </param> |
| 157 | + /// <param name="cancellationToken"> The cancellation token to use. </param> |
| 158 | + /// <returns> An async collection of <see cref="CapabilityResource" /> that may take multiple service requests to iterate over. </returns> |
| 159 | + public virtual AsyncPageable<CapabilityResource> GetAllAsync(string continuationToken = null, CancellationToken cancellationToken = default) |
| 160 | + { |
| 161 | + async Task<Page<CapabilityResource>> FirstPageFunc(int? pageSizeHint) |
| 162 | + { |
| 163 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.GetAll"); |
| 164 | + scope.Start(); |
| 165 | + try |
| 166 | + { |
| 167 | + var response = await _capabilityRestClient.ListAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, continuationToken, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 168 | + return Page.FromValues(response.Value.Value.Select(value => new CapabilityResource(Client, value)), response.Value.NextLink, response.GetRawResponse()); |
| 169 | + } |
| 170 | + catch (Exception e) |
| 171 | + { |
| 172 | + scope.Failed(e); |
| 173 | + throw; |
| 174 | + } |
| 175 | + } |
| 176 | + async Task<Page<CapabilityResource>> NextPageFunc(string nextLink, int? pageSizeHint) |
| 177 | + { |
| 178 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.GetAll"); |
| 179 | + scope.Start(); |
| 180 | + try |
| 181 | + { |
| 182 | + var response = await _capabilityRestClient.ListNextPageAsync(nextLink, Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, continuationToken, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 183 | + return Page.FromValues(response.Value.Value.Select(value => new CapabilityResource(Client, value)), response.Value.NextLink, response.GetRawResponse()); |
| 184 | + } |
| 185 | + catch (Exception e) |
| 186 | + { |
| 187 | + scope.Failed(e); |
| 188 | + throw; |
| 189 | + } |
| 190 | + } |
| 191 | + return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); |
| 192 | + } |
| 193 | + |
| 194 | + /// <summary> |
| 195 | + /// Get a list of Capability resources that extend a Target resource.. |
| 196 | + /// Request Path: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{parentProviderNamespace}/{parentResourceType}/{parentResourceName}/providers/Microsoft.Chaos/targets/{targetName}/capabilities |
| 197 | + /// Operation Id: Capabilities_List |
| 198 | + /// </summary> |
| 199 | + /// <param name="continuationToken"> String that sets the continuation token. </param> |
| 200 | + /// <param name="cancellationToken"> The cancellation token to use. </param> |
| 201 | + /// <returns> A collection of <see cref="CapabilityResource" /> that may take multiple service requests to iterate over. </returns> |
| 202 | + public virtual Pageable<CapabilityResource> GetAll(string continuationToken = null, CancellationToken cancellationToken = default) |
| 203 | + { |
| 204 | + Page<CapabilityResource> FirstPageFunc(int? pageSizeHint) |
| 205 | + { |
| 206 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.GetAll"); |
| 207 | + scope.Start(); |
| 208 | + try |
| 209 | + { |
| 210 | + var response = _capabilityRestClient.List(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, continuationToken, cancellationToken: cancellationToken); |
| 211 | + return Page.FromValues(response.Value.Value.Select(value => new CapabilityResource(Client, value)), response.Value.NextLink, response.GetRawResponse()); |
| 212 | + } |
| 213 | + catch (Exception e) |
| 214 | + { |
| 215 | + scope.Failed(e); |
| 216 | + throw; |
| 217 | + } |
| 218 | + } |
| 219 | + Page<CapabilityResource> NextPageFunc(string nextLink, int? pageSizeHint) |
| 220 | + { |
| 221 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.GetAll"); |
| 222 | + scope.Start(); |
| 223 | + try |
| 224 | + { |
| 225 | + var response = _capabilityRestClient.ListNextPage(nextLink, Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, continuationToken, cancellationToken: cancellationToken); |
| 226 | + return Page.FromValues(response.Value.Value.Select(value => new CapabilityResource(Client, value)), response.Value.NextLink, response.GetRawResponse()); |
| 227 | + } |
| 228 | + catch (Exception e) |
| 229 | + { |
| 230 | + scope.Failed(e); |
| 231 | + throw; |
| 232 | + } |
| 233 | + } |
| 234 | + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); |
| 235 | + } |
| 236 | + |
| 237 | + /// <summary> |
| 238 | + /// Checks to see if the resource exists in azure. |
| 239 | + /// Request Path: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{parentProviderNamespace}/{parentResourceType}/{parentResourceName}/providers/Microsoft.Chaos/targets/{targetName}/capabilities/{capabilityName} |
| 240 | + /// Operation Id: Capabilities_Get |
| 241 | + /// </summary> |
| 242 | + /// <param name="capabilityName"> String that represents a Capability resource name. </param> |
| 243 | + /// <param name="cancellationToken"> The cancellation token to use. </param> |
| 244 | + /// <exception cref="ArgumentException"> <paramref name="capabilityName"/> is an empty string, and was expected to be non-empty. </exception> |
| 245 | + /// <exception cref="ArgumentNullException"> <paramref name="capabilityName"/> is null. </exception> |
| 246 | + public virtual async Task<Response<bool>> ExistsAsync(string capabilityName, CancellationToken cancellationToken = default) |
| 247 | + { |
| 248 | + Argument.AssertNotNullOrEmpty(capabilityName, nameof(capabilityName)); |
| 249 | + |
| 250 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.Exists"); |
| 251 | + scope.Start(); |
| 252 | + try |
| 253 | + { |
| 254 | + var response = await _capabilityRestClient.GetAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, capabilityName, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 255 | + return Response.FromValue(response.Value != null, response.GetRawResponse()); |
| 256 | + } |
| 257 | + catch (Exception e) |
| 258 | + { |
| 259 | + scope.Failed(e); |
| 260 | + throw; |
| 261 | + } |
| 262 | + } |
| 263 | + |
| 264 | + /// <summary> |
| 265 | + /// Checks to see if the resource exists in azure. |
| 266 | + /// Request Path: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{parentProviderNamespace}/{parentResourceType}/{parentResourceName}/providers/Microsoft.Chaos/targets/{targetName}/capabilities/{capabilityName} |
| 267 | + /// Operation Id: Capabilities_Get |
| 268 | + /// </summary> |
| 269 | + /// <param name="capabilityName"> String that represents a Capability resource name. </param> |
| 270 | + /// <param name="cancellationToken"> The cancellation token to use. </param> |
| 271 | + /// <exception cref="ArgumentException"> <paramref name="capabilityName"/> is an empty string, and was expected to be non-empty. </exception> |
| 272 | + /// <exception cref="ArgumentNullException"> <paramref name="capabilityName"/> is null. </exception> |
| 273 | + public virtual Response<bool> Exists(string capabilityName, CancellationToken cancellationToken = default) |
| 274 | + { |
| 275 | + Argument.AssertNotNullOrEmpty(capabilityName, nameof(capabilityName)); |
| 276 | + |
| 277 | + using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.Exists"); |
| 278 | + scope.Start(); |
| 279 | + try |
| 280 | + { |
| 281 | + var response = _capabilityRestClient.Get(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, capabilityName, cancellationToken: cancellationToken); |
| 282 | + return Response.FromValue(response.Value != null, response.GetRawResponse()); |
| 283 | + } |
| 284 | + catch (Exception e) |
| 285 | + { |
| 286 | + scope.Failed(e); |
| 287 | + throw; |
| 288 | + } |
| 289 | + } |
| 290 | + } |
| 291 | +} |
0 commit comments