// Method = "POST", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/hdinsight/~/containers/{containerName}/services/http"
        public async Task <IHttpResponseMessageAbstraction> EnableDisableUserChangeRequest(string dnsName, string location, UserChangeRequestUserType requestType, string payload)
        {
            var manager = ServiceLocator.Instance.Locate <IUserChangeRequestManager>();
            var handler = manager.LocateUserChangeRequestHandler(this.credentials.GetType(), requestType);

            // Creates an HTTP client
            if (handler.IsNull())
            {
                throw new NotSupportedException("Request to submit a UserChangeRequest that is not supported by this client");
            }
            using (IHttpClientAbstraction client = ServiceLocator.Instance.Locate <IHDInsightHttpClientAbstractionFactory>().Create(this.credentials, this.context, this.ignoreSslErrors))
            {
                var hadoopContext = new HDInsightSubscriptionAbstractionContext(this.credentials, this.context);
                client.RequestUri = handler.Item1(hadoopContext, dnsName, location);
                client.Method     = HttpMethod.Post;
                client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
                client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion2);
                client.RequestHeaders.Add(HDInsightRestConstants.Accept);
                client.Content = new StringContent(payload);

                IHttpResponseMessageAbstraction httpResponse = await client.SendAsync();

                if (httpResponse.StatusCode != HttpStatusCode.Accepted)
                {
                    throw new HttpLayerException(httpResponse.StatusCode, httpResponse.Content)
                          {
                              HelpLink = HelpLinkForException
                          };
                }
                return(httpResponse);
            }
        }
예제 #2
0
        public async Task TaskCanceledByUserShouldNotRetry()
        {
            try
            {
                this.AddHttpResponse(new HttpResponseMessageAbstraction(HttpStatusCode.Accepted, new HttpResponseHeadersAbstraction(), "<Okay />"));
                var factory = ServiceLocator.Instance.Locate <IHttpClientAbstractionFactory>();
                using (CancellationTokenSource source = new CancellationTokenSource())
                {
                    var context = new HDInsightSubscriptionAbstractionContext(GetValidCredentials(), source.Token);
                    source.Cancel();
                    var val = await
                              OperationExecutor.ExecuteOperationWithRetry(
                        () => this.DoClientSend(factory.Create()),
                        this.GetRetryPolicy(),
                        context,
                        new Logger());

                    Assert.IsNotNull(val.ExecutionOutput);
                }
                Assert.Fail("Should have thrown an operation cancelled exception");
            }
            catch (OperationCanceledException tex)
            {
                Assert.IsNotNull(tex.CancellationToken);
                Assert.IsTrue(tex.CancellationToken.IsCancellationRequested);
            }
        }
예제 #3
0
 public virtual void TestInitialize()
 {
     Capabilities.Add("CAPABILITY_FEATURE_CLUSTERS_CONTRACT_1_SDK");
     Capabilities.Add("CAPABILITY_FEATURE_CLUSTERS_CONTRACT_2_SDK");
     this.DefaultHandler    = this.GetDefaultHandler();
     this.HdInsightCertCred = new HDInsightCertificateCredential(Guid.Parse(TestSubscription), Certificate);
     this.Context           = new HDInsightSubscriptionAbstractionContext(this.HdInsightCertCred, new CancellationTokenSource().Token);
 }
예제 #4
0
 public virtual void TestInitialize()
 {
     Capabilities.Add("CAPABILITY_FEATURE_CLUSTERS_CONTRACT_1_SDK");
     Capabilities.Add("CAPABILITY_FEATURE_CLUSTERS_CONTRACT_2_SDK");
     this.DefaultHandler = this.GetDefaultHandler();
     this.HdInsightCertCred = new HDInsightCertificateCredential(Guid.Parse(TestSubscription), Certificate);
     this.Context = new HDInsightSubscriptionAbstractionContext(this.HdInsightCertCred, new CancellationTokenSource().Token);
 }
예제 #5
0
 public async Task TaskCanceledByUserShouldNotRetry()
 {
     try
     {
         this.AddHttpResponse(new HttpResponseMessageAbstraction(HttpStatusCode.Accepted, new HttpResponseHeadersAbstraction(), "<Okay />"));
         var factory = ServiceLocator.Instance.Locate<IHttpClientAbstractionFactory>();
         using (CancellationTokenSource source = new CancellationTokenSource())
         {
             var context = new HDInsightSubscriptionAbstractionContext(GetValidCredentials(), source.Token);
             source.Cancel();
             var val = await
             OperationExecutor.ExecuteOperationWithRetry(
                 () => this.DoClientSend(factory.Create()),
                 this.GetRetryPolicy(),
                 context,
                 new Logger());
             Assert.IsNotNull(val.ExecutionOutput);
         }
         Assert.Fail("Should have thrown an operation cancelled exception");
     }
     catch (OperationCanceledException tex)
     {
         Assert.IsNotNull(tex.CancellationToken);
         Assert.IsTrue(tex.CancellationToken.IsCancellationRequested);
     }
 }