/// <summary> /// Waits for replication to become in status "Mirrored" /// </summary> /// <param name="client">ANF Client</param> /// <param name="resourceId">Resource Id of the resource being waited for being deleted</param> /// <param name="intervalInSec">Time in seconds that the sample will poll to check if the resource got deleted or not. Defaults to 10 seconds.</param> /// <param name="retries">How many retries before exting the wait for no resource function. Defaults to 60 retries.</param> /// <returns></returns> static public async Task WaitForCompleteReplicationStatus(AzureNetAppFilesManagementClient client, string resourceId, int intervalInSec = 10, int retries = 60) { using AzureEventSourceListener listener = AzureEventSourceListener.CreateTraceLogger(EventLevel.Verbose); for (int i = 0; i < retries; i++) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(intervalInSec)); try { var status = await client.Volumes.ReplicationStatusMethodAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId), ResourceUriUtils.GetAnfVolume(resourceId)); if (status.MirrorState.ToLower().Equals("mirrored")) { break; } } catch (Exception ex) { if (!(ex.Message.ToLower().Contains("creating") && ex.Message.ToLower().Contains("replication"))) { throw; } } } }
/// <summary> /// Function used to wait for a specific ANF resource complete its deletion and ARM caching gets cleared /// </summary> /// <typeparam name="T">Resource Types as Snapshot, Volume, CapacityPool, and NetAppAccount</typeparam> /// <param name="client">ANF Client</param> /// <param name="resourceId">Resource Id of the resource being waited for being deleted</param> /// <param name="intervalInSec">Time in seconds that the sample will poll to check if the resource got deleted or not. Defaults to 10 seconds.</param> /// <param name="retries">How many retries before exting the wait for no resource function. Defaults to 60 retries.</param> /// <returns></returns> static public async Task WaitForAnfResource <T>(AzureNetAppFilesManagementClient client, string resourceId, int intervalInSec = 10, int retries = 60) { bool isFound = false; for (int i = 0; i < retries; i++) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(intervalInSec)); try { if (typeof(T) == typeof(NetAppAccount)) { await client.Accounts.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId)); } else if (typeof(T) == typeof(CapacityPool)) { await client.Pools.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId)); } else if (typeof(T) == typeof(Volume)) { await client.Volumes.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId), ResourceUriUtils.GetAnfVolume(resourceId)); } else if (typeof(T) == typeof(Snapshot)) { await client.Snapshots.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId), ResourceUriUtils.GetAnfVolume(resourceId), ResourceUriUtils.GetAnfSnapshot(resourceId)); } isFound = true; break; } catch { continue; } } if (!isFound) { throw new Exception($"Resource: {resourceId} is not found"); } }
/// <summary> /// Function used to wait for a specific ANF resource complete its deletion and ARM caching gets cleared /// </summary> /// <typeparam name="T">Resource Types as Snapshot, Volume, CapacityPool, and NetAppAccount</typeparam> /// <param name="client">ANF Client</param> /// <param name="resourceId">Resource Id of the resource being waited for being deleted</param> /// <param name="intervalInSec">Time in seconds that the sample will poll to check if the resource got deleted or not. Defaults to 10 seconds.</param> /// <param name="retries">How many retries before exting the wait for no resource function. Defaults to 60 retries.</param> /// <returns></returns> static public async Task WaitForNoAnfResource <T>(AzureNetAppFilesManagementClient client, string resourceId, int intervalInSec = 10, int retries = 60) { for (int i = 0; i < retries; i++) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(intervalInSec)); try { if (typeof(T) == typeof(Snapshot)) { var resource = await client.Snapshots.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId), ResourceUriUtils.GetAnfVolume(resourceId), ResourceUriUtils.GetAnfSnapshot(resourceId)); } else if (typeof(T) == typeof(Volume)) { var resource = await client.Volumes.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId), ResourceUriUtils.GetAnfVolume(resourceId)); } else if (typeof(T) == typeof(CapacityPool)) { var resource = await client.Pools.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId)); } else if (typeof(T) == typeof(NetAppAccount)) { var resource = await client.Accounts.GetAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId)); } } catch (Exception ex) { // The following HResult is thrown if no resource is found if (ex.HResult == -2146233088) { break; } throw; } } }
/// <summary> /// Waits for replication to become in "Broken" status /// </summary> /// <param name="client">ANF Client</param> /// <param name="resourceId">Resource Id of the resource being waited for being deleted</param> /// <param name="intervalInSec">Time in seconds that the sample will poll to check if the resource got deleted or not. Defaults to 10 seconds.</param> /// <param name="retries">How many retries before exting the wait for no resource function. Defaults to 60 retries.</param> /// <returns></returns> static public async Task WaitForBrokenReplicationStatus(AzureNetAppFilesManagementClient client, string resourceId, int intervalInSec = 10, int retries = 60) { for (int i = 0; i < retries; i++) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(intervalInSec)); try { var status = await client.Volumes.ReplicationStatusMethodAsync(ResourceUriUtils.GetResourceGroup(resourceId), ResourceUriUtils.GetAnfAccount(resourceId), ResourceUriUtils.GetAnfCapacityPool(resourceId), ResourceUriUtils.GetAnfVolume(resourceId)); if (status.MirrorState.ToLower().Equals("broken")) { break; } } catch { throw; } } }