public void VaultUpgrade_UpgradeResourceTests()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetRecoveryServicesVaultUpgradeClient(CustomHttpHandler);

                var requestHeaders = RequestHeaders;

                var resourcePath = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/{2}/{3}/{4}",
                                                 client.Credentials.SubscriptionId,
                                                 "TargetRg",
                                                 "Microsoft.RecoveryServicesBVTD2",
                                                 "Vaults",
                                                 VaultUpgradeTestsBase.MyVaultName);

                ResourceUpgradeInput input = new ResourceUpgradeInput()
                {
                    NewResourcePath = resourcePath
                };

                var response = client.RecoveryServicesVaultUpgrade.UpgradeResource(input, requestHeaders);

                Assert.NotNull(response);
                Assert.Equal(response.Status.ToString(), "InProgress");
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
Пример #2
0
 /// <summary>
 /// Check Prerequisites for Vault Upgrade.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RecoveryServicesVaultUpgrade.IRecoveryServicesVaultUpgradeOperations.
 /// </param>
 /// <param name='resourceUpgradeInput'>
 /// Required. Input required for the resource to be upgraded.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The response model for the Azure operations.
 /// </returns>
 public static Task <AzureResponse> CheckPrerequisitesForRecoveryServicesVaultUpgradeAsync(this IRecoveryServicesVaultUpgradeOperations operations, ResourceUpgradeInput resourceUpgradeInput, CustomRequestHeaders customRequestHeaders)
 {
     return(operations.CheckPrerequisitesForRecoveryServicesVaultUpgradeAsync(resourceUpgradeInput, customRequestHeaders, CancellationToken.None));
 }
Пример #3
0
 /// <summary>
 /// Check Prerequisites for Vault Upgrade.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RecoveryServicesVaultUpgrade.IRecoveryServicesVaultUpgradeOperations.
 /// </param>
 /// <param name='resourceUpgradeInput'>
 /// Required. Input required for the resource to be upgraded.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The response model for the Azure operations.
 /// </returns>
 public static AzureResponse CheckPrerequisitesForRecoveryServicesVaultUpgrade(this IRecoveryServicesVaultUpgradeOperations operations, ResourceUpgradeInput resourceUpgradeInput, CustomRequestHeaders customRequestHeaders)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IRecoveryServicesVaultUpgradeOperations)s).CheckPrerequisitesForRecoveryServicesVaultUpgradeAsync(resourceUpgradeInput, customRequestHeaders);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Пример #4
0
 /// <summary>
 /// Start Resource Upgrade.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RecoveryServicesVaultUpgrade.IRecoveryServicesVaultUpgradeOperations.
 /// </param>
 /// <param name='resourceUpgradeInput'>
 /// Required. Input required for resource upgradation.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The definition of a resource upgrade output object.
 /// </returns>
 public static Task <ResourceUpgradeDetails> UpgradeResourceAsync(this IRecoveryServicesVaultUpgradeOperations operations, ResourceUpgradeInput resourceUpgradeInput, CustomRequestHeaders customRequestHeaders)
 {
     return(operations.UpgradeResourceAsync(resourceUpgradeInput, customRequestHeaders, CancellationToken.None));
 }
        /// <summary>
        /// Check Prerequisites for Vault Upgrade.
        /// </summary>
        /// <param name='resourceUpgradeInput'>
        /// Required. Input required for the resource to be upgraded.
        /// </param>
        /// <param name='customRequestHeaders'>
        /// Optional. Request header parameters.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the Azure operations.
        /// </returns>
        public async Task <AzureResponse> CheckPrerequisitesForRecoveryServicesVaultUpgradeAsync(ResourceUpgradeInput resourceUpgradeInput, CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceUpgradeInput == null)
            {
                throw new ArgumentNullException("resourceUpgradeInput");
            }
            if (resourceUpgradeInput.NewResourcePath == null)
            {
                throw new ArgumentNullException("resourceUpgradeInput.NewResourcePath");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceUpgradeInput", resourceUpgradeInput);
                tracingParameters.Add("customRequestHeaders", customRequestHeaders);
                TracingAdapter.Enter(invocationId, this, "CheckPrerequisitesForRecoveryServicesVaultUpgradeAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/cloudservices/";
            url = url + Uri.EscapeDataString(this.Client.CloudServiceName);
            url = url + "/resources/";
            url = url + Uri.EscapeDataString(this.Client.ResourceNamespace);
            url = url + "/~/";
            url = url + Uri.EscapeDataString(this.Client.ResourceType);
            url = url + "/";
            url = url + Uri.EscapeDataString(this.Client.ResourceName);
            url = url + "/checkPrereqsForUpgrade";
            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.Post;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept", "application/xml");
                httpRequest.Headers.Add("Agent-Authentication", customRequestHeaders.AgentAuthenticationHeader);
                httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId);
                httpRequest.Headers.Add("x-ms-version", "2013-03-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Serialize Request
                string    requestContent = null;
                XDocument requestDoc     = new XDocument();

                XElement resourceUpgradeInputElement = new XElement(XName.Get("ResourceUpgradeInput", "http://schemas.microsoft.com/windowsazure"));
                requestDoc.Add(resourceUpgradeInputElement);

                XElement newResourcePathElement = new XElement(XName.Get("NewResourcePath", "http://schemas.microsoft.com/windowsazure"));
                newResourcePathElement.Value = resourceUpgradeInput.NewResourcePath;
                resourceUpgradeInputElement.Add(newResourcePathElement);

                requestContent      = requestDoc.ToString();
                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml");

                // 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, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    AzureResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new AzureResponse();
                        XDocument responseDoc = XDocument.Parse(responseContent);
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }