public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            ExecutionBlock(() =>
            {
                WriteDebug(Resources.MakingClientCall);

                if (RecoveryPointId != null)
                {
                    CSMRecoveryPointResponse recoveryPointObject = AzureBackupClient.GetRecoveryPoint(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName, RecoveryPointId);
                    if (recoveryPointObject != null)
                    {
                        WriteAzureBackupRecoveryPoint(recoveryPointObject, Item);
                    }
                    else
                    {
                        WriteDebug(string.Format(Resources.NoRpExist, RecoveryPointId));
                    }
                }
                else
                {
                    IEnumerable <CSMRecoveryPointResponse> recoveryPointListResponse = AzureBackupClient.ListRecoveryPoints(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, Item.ItemName);
                    if (recoveryPointListResponse != null &&
                        recoveryPointListResponse.Count <CSMRecoveryPointResponse>() > 0)
                    {
                        IEnumerable <CSMRecoveryPointResponse> recoveryPointObjects = recoveryPointListResponse.OrderByDescending(x => x.Properties.RecoveryPointTime);
                        if (recoveryPointObjects.Count <CSMRecoveryPointResponse>() > 1)
                        {
                            WriteAzureBackupRecoveryPoint(recoveryPointObjects, Item);
                        }
                        else
                        {
                            WriteAzureBackupRecoveryPoint(recoveryPointObjects.FirstOrDefault <CSMRecoveryPointResponse>(), Item);
                        }
                    }
                    else
                    {
                        WriteDebug(Resources.NoRpFound);
                    }
                }
            });
        }
        public void GetRecoveryPointTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetServiceClient <BackupServicesManagementClient>();

                string containerName     = ConfigurationManager.AppSettings["ContainerName"];
                string itemName          = ConfigurationManager.AppSettings["ItemName"];
                string recoveryPointName = ConfigurationManager.AppSettings["RecoveryPointName"];

                var response = client.RecoveryPoint.Get(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, GetCustomRequestHeaders(), containerName, itemName, recoveryPointName);

                if (response != null &&
                    response.CSMRecoveryPointResponse != null)
                {
                    CSMRecoveryPointResponse rpo = response.CSMRecoveryPointResponse;
                    Assert.True(!string.IsNullOrEmpty(rpo.Name), "RecoveryPointId can't be null or empty");
                    Assert.True((rpo.Properties.RecoveryPointTime != null), "RecoveryPointTime can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(rpo.Properties.RecoveryPointType), "RecoveryPointType can't be null or empty");
                }
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
 public void WriteAzureBackupRecoveryPoint(CSMRecoveryPointResponse sourceRecoverPoint, AzureRMBackupItem azureBackupItem)
 {
     this.WriteObject(new AzureRMBackupRecoveryPoint(sourceRecoverPoint, azureBackupItem));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Get the recovery point.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required.
        /// </param>
        /// <param name='resourceName'>
        /// Required.
        /// </param>
        /// <param name='customRequestHeaders'>
        /// Optional. Request header parameters.
        /// </param>
        /// <param name='containerName'>
        /// Optional.
        /// </param>
        /// <param name='itemName'>
        /// Optional.
        /// </param>
        /// <param name='recoveryPointName'>
        /// Optional.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The definition of a CSMRecoveryPointGetOperationResponse.
        /// </returns>
        public async Task <CSMRecoveryPointGetOperationResponse> GetAsync(string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string containerName, string itemName, string recoveryPointName, 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("customRequestHeaders", customRequestHeaders);
                tracingParameters.Add("containerName", containerName);
                tracingParameters.Add("itemName", itemName);
                tracingParameters.Add("recoveryPointName", recoveryPointName);
                TracingAdapter.Enter(invocationId, this, "GetAsync", 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 + "/registeredContainers/";
            if (containerName != null)
            {
                url = url + Uri.EscapeDataString(containerName);
            }
            url = url + "/protectedItems/";
            if (itemName != null)
            {
                url = url + Uri.EscapeDataString(itemName);
            }
            url = url + "/recoveryPoints/";
            if (recoveryPointName != null)
            {
                url = url + Uri.EscapeDataString(recoveryPointName);
            }
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2014-09-01");
            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
                    CSMRecoveryPointGetOperationResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new CSMRecoveryPointGetOperationResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            CSMRecoveryPointResponse cSMRecoveryPointResponseInstance = new CSMRecoveryPointResponse();
                            result.CSMRecoveryPointResponse = cSMRecoveryPointResponseInstance;

                            JToken propertiesValue = responseDoc["properties"];
                            if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                            {
                                CSMRecoveryPointProperties propertiesInstance = new CSMRecoveryPointProperties();
                                cSMRecoveryPointResponseInstance.Properties = propertiesInstance;

                                JToken recoveryPointTypeValue = propertiesValue["recoveryPointType"];
                                if (recoveryPointTypeValue != null && recoveryPointTypeValue.Type != JTokenType.Null)
                                {
                                    string recoveryPointTypeInstance = ((string)recoveryPointTypeValue);
                                    propertiesInstance.RecoveryPointType = recoveryPointTypeInstance;
                                }

                                JToken recoveryPointTimeValue = propertiesValue["recoveryPointTime"];
                                if (recoveryPointTimeValue != null && recoveryPointTimeValue.Type != JTokenType.Null)
                                {
                                    DateTime recoveryPointTimeInstance = ((DateTime)recoveryPointTimeValue);
                                    propertiesInstance.RecoveryPointTime = recoveryPointTimeInstance;
                                }

                                JToken recoveryPointAdditionalInfoValue = propertiesValue["recoveryPointAdditionalInfo"];
                                if (recoveryPointAdditionalInfoValue != null && recoveryPointAdditionalInfoValue.Type != JTokenType.Null)
                                {
                                    string recoveryPointAdditionalInfoInstance = ((string)recoveryPointAdditionalInfoValue);
                                    propertiesInstance.RecoveryPointAdditionalInfo = recoveryPointAdditionalInfoInstance;
                                }
                            }

                            JToken idValue = responseDoc["id"];
                            if (idValue != null && idValue.Type != JTokenType.Null)
                            {
                                string idInstance = ((string)idValue);
                                cSMRecoveryPointResponseInstance.Id = idInstance;
                            }

                            JToken nameValue = responseDoc["name"];
                            if (nameValue != null && nameValue.Type != JTokenType.Null)
                            {
                                string nameInstance = ((string)nameValue);
                                cSMRecoveryPointResponseInstance.Name = nameInstance;
                            }

                            JToken typeValue = responseDoc["type"];
                            if (typeValue != null && typeValue.Type != JTokenType.Null)
                            {
                                string typeInstance = ((string)typeValue);
                                cSMRecoveryPointResponseInstance.Type = typeInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Exemplo n.º 5
0
 public AzureRMBackupRecoveryPoint(CSMRecoveryPointResponse recoveryPointInfo, AzureRMBackupItem azureBackupItem)
     : base(recoveryPointInfo, azureBackupItem)
 {
     RecoveryPointTime = recoveryPointInfo.Properties.RecoveryPointTime;
     RecoveryPointType = recoveryPointInfo.Properties.RecoveryPointType;
 }
Exemplo n.º 6
0
 public AzureBackupRecoveryPointContextObject(CSMRecoveryPointResponse recoveryPointInfo, AzureRMBackupItem azureBackupItem)
     : base(azureBackupItem)
 {
     RecoveryPointName = recoveryPointInfo.Name;
 }