Ejemplo n.º 1
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);
            }
        }
        // Method = "GET", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/{resourceProviderNamespace}/~/{resourceType}/{resourceName}"
        public async Task <IHttpResponseMessageAbstraction> GetClusterResourceDetail(string resourceId, string resourceType, string location)
        {
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                () => this.ProcessGetClusterResourceDetail(this.CreateClient(), resourceId, resourceType, location),
                this.context.RetryPolicy,
                this.context,
                this.context.Logger);

            if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted && result.ExecutionOutput.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content, result.Attempts, result.TotalTime);
            }

            return(result.ExecutionOutput);
        }
        // Method = "GET", UriTemplate = "{subscriptionId}/cloudservices"
        public async Task<IHttpResponseMessageAbstraction> ListCloudServices()
        {
            OperationExecutionResult<IHttpResponseMessageAbstraction> result = await OperationExecutor.ExecuteOperationWithRetry(
                () => this.ProcessListCloudServices(this.CreateClient()),
                this.context.RetryPolicy,
                this.context,
                this.context.Logger);

            if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted && result.ExecutionOutput.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content, result.Attempts, result.TotalTime);
            }

            return result.ExecutionOutput;
        }
        // Method = "DELETE", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/{resourceProviderNamespace}/{resourceType}/{resourceName}"
        public async Task<IHttpResponseMessageAbstraction> DeleteContainer(string dnsName, string location)
        {
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                    () => this.ProcessDeleteContainer(this.CreateClient(), dnsName, location),
                    this.context.RetryPolicy,
                    this.context,
                    this.context.Logger);

            if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted)
            {
                throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content) { HelpLink = HelpLinkForException };
            }

            return result.ExecutionOutput;
        }
        // Method = "PUT", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/{resourceProviderNamespace}/{resourceType}/{resourceName}"
        public async Task<IHttpResponseMessageAbstraction> CreateContainer(string dnsName, string location, string clusterPayload, int schemaVersion = 2)
        {
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                    () => this.CreateResource(this.CreateClient(), dnsName, "containers", location, clusterPayload, schemaVersion),
                    this.context.RetryPolicy,
                    this.context,
                    this.context.Logger);

            if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted)
            {
                throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content) { HelpLink = HelpLinkForException };
            }

            return result.ExecutionOutput;
        }
        // Method = "GET", UriTemplate = "/{subscriptionId}/cloudservices/{cloudServiceName}/resources/{deploymentNamespace}/~/containers/{containerName}/users/operations/{operationId}",
        public async Task <IHttpResponseMessageAbstraction> GetOperationStatus(string dnsName, string location, Guid operationId)
        {
            var start  = DateTime.UtcNow;
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                () => this.ProcessGetOperationStatus(this.CreateClient(), dnsName, location, operationId),
                this.context.RetryPolicy,
                this.context,
                this.context.Logger);

            if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted && result.ExecutionOutput.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content, result.Attempts, result.TotalTime);
            }

            return(result.ExecutionOutput);
        }
Ejemplo n.º 7
0
        // Method = "GET", UriTemplate = "UriTemplate = "{subscriptionId}/resourceproviders/{resourceProviderNamespace}/Properties?resourceType={resourceType}"
        public async Task <IEnumerable <KeyValuePair <string, string> > > GetResourceProviderProperties()
        {
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                () =>
            {
                Task <IHttpResponseMessageAbstraction> retval = this.ProcessGetResourceProviderPropertiesRequest(this.CreateClient());
                var x = retval.Result;
                if (x.StatusCode != HttpStatusCode.Accepted && x.StatusCode != HttpStatusCode.OK)
                {
                    throw new HttpLayerException(x.StatusCode, x.Content);
                }
                return(retval);
            },
                this.context.RetryPolicy,
                this.context,
                this.context.Logger);

            return(this.ParseCapabilities(result.ExecutionOutput.Content));
        }
Ejemplo n.º 8
0
        internal async Task <IHttpResponseMessageAbstraction> PerformRequest()
        {
            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                var factory = ServiceLocator.Instance.Locate <IHttpClientAbstractionFactory>();
                OperationExecutionResult <IHttpResponseMessageAbstraction> result = await
                                                                                    OperationExecutor.ExecuteOperationWithRetry(
                    () => this.DoClientSend(factory.Create()),
                    this.GetRetryPolicy(),
                    new HDInsightSubscriptionAbstractionContext(GetValidCredentials(), source.Token),
                    new Logger());

                if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted && result.ExecutionOutput.StatusCode != HttpStatusCode.OK)
                {
                    throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content, result.Attempts, result.TotalTime);
                }

                return(result.ExecutionOutput);
            }
        }
Ejemplo n.º 9
0
        public async Task TimeOutExceptionOnTheHttpCallShouldRetry()
        {
            var factory = ServiceLocator.Instance.Locate <IHttpClientAbstractionFactory>();
            OperationExecutionResult <IHttpResponseMessageAbstraction> response;

            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                this.AddHttpException(new TimeoutException("The Operation Timed Out"));
                this.AddHttpResponse(new HttpResponseMessageAbstraction(HttpStatusCode.Accepted, new HttpResponseHeadersAbstraction(), "<Okay />"));
                response =
                    await
                    OperationExecutor.ExecuteOperationWithRetry(
                        () => this.DoClientSend(factory.Create()),
                        this.GetRetryPolicy(),
                        new HDInsightSubscriptionAbstractionContext(GetValidCredentials(), source.Token),
                        new Logger());
            }
            Assert.AreEqual(2, this.attempts);
            Assert.AreEqual(0, this.responses.Count);
            Assert.AreEqual(HttpStatusCode.Accepted, response.ExecutionOutput.StatusCode);
            Assert.AreEqual("<Okay />", response.ExecutionOutput.Content);
        }