public void ListAzureBackupItemPOTest() { using (UndoContext context = UndoContext.Current) { context.Start(); CSMItemQueryObject POQueryParam = new CSMItemQueryObject() { Status = null, Type = null }; var client = GetServiceClient <BackupServicesManagementClient>(); var response = client.ProtectableObject.ListCSMAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, POQueryParam, GetCustomRequestHeaders()).Result; Assert.True(response.CSMItemListResponse.Value.Count > 0, "Protectable Object Result count can't be less than 1"); foreach (var po in response.CSMItemListResponse.Value) { Assert.True(!string.IsNullOrEmpty(po.Properties.ContainerId), "ContainerId can't be null or empty"); Assert.True(!string.IsNullOrEmpty(po.Properties.FriendlyName), "FriendlyName can't be null or empty"); Assert.True(!string.IsNullOrEmpty(po.Properties.ItemType), "ItemType can't be null or empty"); Assert.True(!string.IsNullOrEmpty(po.Properties.Status), "Status can't be null or empty"); Assert.True(!string.IsNullOrEmpty(po.Name), "Name can't be null or empty"); Assert.True(!string.IsNullOrEmpty(po.Type), "Type can't be null or empty"); } Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); List <CSMProtectedItemResponse> azureBackupDatasourceObjects = null; List <CSMItemResponse> azureBackupPOObjects = null; WriteDebug(Resources.MakingClientCall); CSMProtectedItemQueryObject DSQueryParam = new CSMProtectedItemQueryObject() { ProtectionStatus = this.ProtectionStatus, Status = this.Status, Type = GetItemType(this.Type) }; CSMItemQueryObject POQueryParam = new CSMItemQueryObject() { Status = this.ProtectionStatus, Type = GetItemType(this.Type) }; var azureBackupDatasourceListResponse = AzureBackupClient.ListDataSources(Container.ResourceGroupName, Container.ResourceName, DSQueryParam); if (azureBackupDatasourceListResponse != null) { azureBackupDatasourceObjects = azureBackupDatasourceListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList(); } if (this.Status == null) { var azureBackupPOListResponse = AzureBackupClient.ListProtectableObjects(Container.ResourceGroupName, Container.ResourceName, POQueryParam); if (azureBackupPOListResponse != null) { azureBackupPOObjects = azureBackupPOListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList(); } } WriteDebug(Resources.AzureBackupItemResponse); WriteAzureBackupItem(azureBackupDatasourceObjects, azureBackupPOObjects, Container); }); }
/// <summary> /// Get the list of all items /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.BackupServices.IProtectableObjectOperations. /// </param> /// <param name='resourceGroupName'> /// Required. /// </param> /// <param name='resourceName'> /// Required. /// </param> /// <param name='csmparameters'> /// Optional. Protectable objects query parameter. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// The definition of a CSMItemListOperationResponse. /// </returns> public static Task <CSMItemListOperationResponse> ListCSMAsync(this IProtectableObjectOperations operations, string resourceGroupName, string resourceName, CSMItemQueryObject csmparameters, CustomRequestHeaders customRequestHeaders) { return(operations.ListCSMAsync(resourceGroupName, resourceName, csmparameters, customRequestHeaders, CancellationToken.None)); }
/// <summary> /// Get the list of all items /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.BackupServices.IProtectableObjectOperations. /// </param> /// <param name='resourceGroupName'> /// Required. /// </param> /// <param name='resourceName'> /// Required. /// </param> /// <param name='csmparameters'> /// Optional. Protectable objects query parameter. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// The definition of a CSMItemListOperationResponse. /// </returns> public static CSMItemListOperationResponse ListCSM(this IProtectableObjectOperations operations, string resourceGroupName, string resourceName, CSMItemQueryObject csmparameters, CustomRequestHeaders customRequestHeaders) { return(Task.Factory.StartNew((object s) => { return ((IProtectableObjectOperations)s).ListCSMAsync(resourceGroupName, resourceName, csmparameters, customRequestHeaders); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Lists protectable objects in the vault /// </summary> /// <param name="query"></param> /// <returns></returns> public IList <CSMItemResponse> ListProtectableObjects(string resourceGroupName, string resourceName, CSMItemQueryObject query) { var response = AzureBackupClient.ProtectableObject.ListCSMAsync(resourceGroupName, resourceName, query, GetCustomRequestHeaders(), CmdletCancellationToken).Result; return((response != null) ? response.CSMItemListResponse.Value : null); }
/// <summary> /// Get the list of all items /// </summary> /// <param name='resourceGroupName'> /// Required. /// </param> /// <param name='resourceName'> /// Required. /// </param> /// <param name='csmparameters'> /// Optional. Protectable objects query parameter. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The definition of a CSMItemListOperationResponse. /// </returns> public async Task <CSMItemListOperationResponse> ListCSMAsync(string resourceGroupName, string resourceName, CSMItemQueryObject csmparameters, CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken) { // Validate if (resourceGroupName == null) { throw new ArgumentNullException("resourceGroupName"); } if (resourceName == null) { throw new ArgumentNullException("resourceName"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("resourceName", resourceName); tracingParameters.Add("csmparameters", csmparameters); tracingParameters.Add("customRequestHeaders", customRequestHeaders); TracingAdapter.Enter(invocationId, this, "ListCSMAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/subscriptions/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/resourceGroups/"; url = url + Uri.EscapeDataString(resourceGroupName); url = url + "/providers/"; url = url + "Microsoft.Backup"; url = url + "/"; url = url + "BackupVault"; url = url + "/"; url = url + Uri.EscapeDataString(resourceName); url = url + "/items"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2014-09-01"); List <string> odataFilter = new List <string>(); if (csmparameters != null && csmparameters.Status != null) { odataFilter.Add("status eq '" + Uri.EscapeDataString(csmparameters.Status) + "'"); } if (csmparameters != null && csmparameters.Type != null) { odataFilter.Add("itemType eq '" + Uri.EscapeDataString(csmparameters.Type) + "'"); } if (odataFilter.Count > 0) { queryParameters.Add("$filter=" + string.Join(" and ", odataFilter)); } if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("Accept-Language", "en-us"); httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result CSMItemListOperationResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new CSMItemListOperationResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { CSMItemListResponse cSMItemListResponseInstance = new CSMItemListResponse(); result.CSMItemListResponse = cSMItemListResponseInstance; JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { CSMItemResponse cSMItemResponseInstance = new CSMItemResponse(); cSMItemListResponseInstance.Value.Add(cSMItemResponseInstance); JToken propertiesValue = valueValue["properties"]; if (propertiesValue != null && propertiesValue.Type != JTokenType.Null) { CSMItemProperties propertiesInstance = new CSMItemProperties(); cSMItemResponseInstance.Properties = propertiesInstance; JToken friendlyNameValue = propertiesValue["friendlyName"]; if (friendlyNameValue != null && friendlyNameValue.Type != JTokenType.Null) { string friendlyNameInstance = ((string)friendlyNameValue); propertiesInstance.FriendlyName = friendlyNameInstance; } JToken itemTypeValue = propertiesValue["itemType"]; if (itemTypeValue != null && itemTypeValue.Type != JTokenType.Null) { string itemTypeInstance = ((string)itemTypeValue); propertiesInstance.ItemType = itemTypeInstance; } JToken statusValue = propertiesValue["status"]; if (statusValue != null && statusValue.Type != JTokenType.Null) { string statusInstance = ((string)statusValue); propertiesInstance.Status = statusInstance; } JToken containerIdValue = propertiesValue["containerId"]; if (containerIdValue != null && containerIdValue.Type != JTokenType.Null) { string containerIdInstance = ((string)containerIdValue); propertiesInstance.ContainerId = containerIdInstance; } } JToken idValue = valueValue["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); cSMItemResponseInstance.Id = idInstance; } JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); cSMItemResponseInstance.Name = nameInstance; } JToken typeValue = valueValue["type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { string typeInstance = ((string)typeValue); cSMItemResponseInstance.Type = typeInstance; } } } JToken nextLinkValue = responseDoc["nextLink"]; if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null) { string nextLinkInstance = ((string)nextLinkValue); cSMItemListResponseInstance.NextLink = nextLinkInstance; } JToken idValue2 = responseDoc["id"]; if (idValue2 != null && idValue2.Type != JTokenType.Null) { string idInstance2 = ((string)idValue2); cSMItemListResponseInstance.Id = idInstance2; } JToken nameValue2 = responseDoc["name"]; if (nameValue2 != null && nameValue2.Type != JTokenType.Null) { string nameInstance2 = ((string)nameValue2); cSMItemListResponseInstance.Name = nameInstance2; } JToken typeValue2 = responseDoc["type"]; if (typeValue2 != null && typeValue2.Type != JTokenType.Null) { string typeInstance2 = ((string)typeValue2); cSMItemListResponseInstance.Type = typeInstance2; } } } result.StatusCode = statusCode; if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }