// Method = "GET", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/hdinsight/~/containers/{containerName}/jobs/{jobId}"
        public async Task <IHttpResponseMessageAbstraction> GetJobDetail(string containerName, string location, string jobId)
        {
            // Creates an HTTP client
            var resolver = ServiceLocator.Instance.Locate <ICloudServiceNameResolver>();

            using (
                IHttpClientAbstraction client = ServiceLocator.Instance.Locate <IHDInsightHttpClientAbstractionFactory>().Create(this.credentials, this.context, this.ignoreSslErrors))
            {
                string regionCloudServicename = resolver.GetCloudServiceName(
                    this.credentials.SubscriptionId, this.credentials.DeploymentNamespace, location);

                string relativeUri = string.Format(
                    "{0}/cloudservices/{1}/resources/{2}/~/containers/{3}/jobs/{4}",
                    this.credentials.SubscriptionId,
                    regionCloudServicename,
                    this.credentials.DeploymentNamespace,
                    containerName,
                    jobId);

                client.RequestUri = new Uri(this.credentials.Endpoint, new Uri(relativeUri, UriKind.Relative));
                client.Method     = HttpMethod.Get;
                client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
                client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion2);
                client.RequestHeaders.Add(HDInsightRestConstants.Accept);

                IHttpResponseMessageAbstraction httpResponse = await client.SendAsync();

                if (httpResponse.StatusCode != HttpStatusCode.Accepted)
                {
                    throw new HttpLayerException(httpResponse.StatusCode, httpResponse.Content);
                }
                return(httpResponse);
            }
        }
 public HttpAbstractionSimulatorClient(HttpAbstractionSimulatorFactory factory, IHttpClientAbstraction underlying, Func<IHttpClientAbstraction, IHttpResponseMessageAbstraction> asyncMoc)
 {
     this.factory = factory;
     this.underlying = underlying;
     this.asyncMoc = asyncMoc;
     this.Logger = new Logger();
 }
Example #3
0
        public void TestWithValidCredentials()
        {
            string accessToken = "somestring";
            IHDInsightSubscriptionCredentials credentials = new HDInsightAccessTokenCredential()
            {
                AccessToken         = accessToken,
                DeploymentNamespace = "hdinsight",
                Endpoint            = new Uri("http://notrdfe.com/"),
                SubscriptionId      = Guid.NewGuid()
            };
            Exception error = null;

            try
            {
                IHttpClientAbstraction validAbstraction =
                    ServiceLocator.Instance.Locate <IHDInsightHttpClientAbstractionFactory>().Create(credentials, false);
                Assert.IsTrue(validAbstraction.RequestHeaders.ContainsKey("Authorization"));
                Assert.AreEqual(validAbstraction.RequestHeaders["Authorization"], "Bearer " + accessToken);
            }
            catch (NotSupportedException e)
            {
                error = e;
            }
            Assert.IsNull(error);
        }
        // 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);
            }
        }
 public HttpAbstractionSimulatorClient(HttpAbstractionSimulatorFactory factory, IHttpClientAbstraction underlying, Func <IHttpClientAbstraction, IHttpResponseMessageAbstraction> asyncMoc)
 {
     this.factory    = factory;
     this.underlying = underlying;
     this.asyncMoc   = asyncMoc;
     this.Logger     = new Logger();
 }
 /// <summary>
 /// Provides the basic authorization for a connection.
 /// </summary>
 /// <param name="httpClient">
 /// The HttpClient to which authorization should be added.
 /// </param>
 private void ProvideStandardHeaders(IHttpClientAbstraction httpClient)
 {
     if (this.credentials.UserName != null && this.credentials.Password != null)
     {
         var byteArray = Encoding.ASCII.GetBytes(this.credentials.UserName + ":" + this.credentials.Password);
         httpClient.RequestHeaders.Add(System.Net.HttpRequestHeader.Authorization.ToString(), "Basic " + Convert.ToBase64String(byteArray));
     }
     httpClient.RequestHeaders.Add("accept", "application/json");
 }
Example #7
0
 /// <summary>
 /// Provides the basic authorization for a connection.
 /// </summary>
 /// <param name="httpClient">
 /// The HttpClient to which authorization should be added.
 /// </param>
 private void ProvideStandardHeaders(IHttpClientAbstraction httpClient)
 {
     if (this.credentials.UserName != null && this.credentials.Password != null)
     {
         var byteArray = Encoding.ASCII.GetBytes(this.credentials.UserName + ":" + this.credentials.Password);
         httpClient.RequestHeaders.Add(System.Net.HttpRequestHeader.Authorization.ToString(), "Basic " + Convert.ToBase64String(byteArray));
     }
     httpClient.RequestHeaders.Add("accept", "application/json");
 }
 internal IHttpResponseMessageAbstraction ReturnNextResponse(IHttpClientAbstraction client)
 {
     this.attempts++;
     var response = this.responses.Remove();
     if (response.Exception.IsNotNull())
     {
         throw response.Exception;
     }
     return response.ResponseMessage;
 }
        public async Task<IHttpResponseMessageAbstraction> ProcessGetOperationStatus(IHttpClientAbstraction client, string dnsName, string location, Guid operationId)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate<IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder = overrideHandlers.UriBuilder;
            client.RequestUri = uriBuilder.GetOperationStatusUri(dnsName, location, this.credentials.DeploymentNamespace, operationId);
            client.Method = HttpMethod.Get;
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion2);

            return await this.ProcessSendAsync(client);
        }
        private async Task<IHttpResponseMessageAbstraction> ProcessSendAsync(IHttpClientAbstraction client)
        {
            // Sends, validates and parses the response
            var httpResponse = await client.SendAsync();

            if (httpResponse.StatusCode != HttpStatusCode.Accepted && httpResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpLayerException(httpResponse.StatusCode, httpResponse.Content);
            }
            return httpResponse;
        }
        private async Task <IHttpResponseMessageAbstraction> ProcessSendAsync(IHttpClientAbstraction client)
        {
            // Sends, validates and parses the response
            var httpResponse = await client.SendAsync();

            if (httpResponse.StatusCode != HttpStatusCode.Accepted && httpResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpLayerException(httpResponse.StatusCode, httpResponse.Content);
            }
            return(httpResponse);
        }
 /// <summary>
 /// Provides the basic authorization for a connection.
 /// </summary>
 /// <param name="httpClient">
 /// The HttpClient to which authorization should be added.
 /// </param>
 private void ProvideStandardHeaders(IHttpClientAbstraction httpClient)
 {
     if (this.credentials.UserName != null && this.credentials.Password != null)
     {
         var byteArray = Encoding.ASCII.GetBytes(this.credentials.UserName + ":" + this.credentials.Password);
         httpClient.RequestHeaders.Add(HadoopRemoteRestConstants.Authorization, "Basic " + Convert.ToBase64String(byteArray));
     }
     httpClient.RequestHeaders.Add("accept", "application/json");
     httpClient.RequestHeaders.Add("useragent", this.GetUserAgentString());
     httpClient.RequestHeaders.Add("User-Agent", this.GetUserAgentString());
 }
Example #13
0
        internal IHttpResponseMessageAbstraction ReturnNextResponse(IHttpClientAbstraction client)
        {
            this.attempts++;
            var response = this.responses.Remove();

            if (response.Exception.IsNotNull())
            {
                throw response.Exception;
            }
            return(response.ResponseMessage);
        }
        private async Task<IHttpResponseMessageAbstraction> ProcessListCloudServices(IHttpClientAbstraction client)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate<IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder = overrideHandlers.UriBuilder;

            client.RequestUri = uriBuilder.GetListCloudServicesUri();
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            client.RequestHeaders.Add(HDInsightRestConstants.Accept);
            client.RequestHeaders.Add(HDInsightRestConstants.UserAgent);
            client.Method = HttpMethod.Get;
            return await this.ProcessSendAsync(client);
        }
        private async Task<IHttpResponseMessageAbstraction> ProcessListCloudServices(IHttpClientAbstraction client)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate<IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder = overrideHandlers.UriBuilder;

            client.RequestUri = uriBuilder.GetListCloudServicesUri();
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            client.RequestHeaders.Add(HDInsightRestConstants.Accept);
            client.RequestHeaders.Add(HDInsightRestConstants.UserAgent);
            client.Method = HttpMethod.Get;
            return await this.ProcessSendAsync(client);
        }
        private async Task <IHttpResponseMessageAbstraction> ProcessDeleteContainer(IHttpClientAbstraction client, string dnsName, string location)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate <IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder       = overrideHandlers.UriBuilder;

            client.RequestUri = uriBuilder.GetDeleteContainerUri(dnsName, location);

            client.Method = HttpMethod.Delete;
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            client.RequestHeaders.Add(HDInsightRestConstants.Accept);

            return(await this.ProcessSendAsync(client));
        }
Example #17
0
        internal async Task <IHttpResponseMessageAbstraction> DoClientSend(IHttpClientAbstraction client)
        {
            client.ContentType = "text/HTML";
            client.Method      = HttpMethod.Get;
            client.RequestHeaders.Add("test", "value");
            client.RequestUri = new Uri("http://www.microsoft.com");
            client.Timeout    = new TimeSpan(0, 5, 0);
            var ret = await client.SendAsync();

            if (ret.StatusCode != HttpStatusCode.Accepted && ret.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpLayerException(ret.StatusCode, ret.Content);
            }
            return(ret);
        }
Example #18
0
        public void TestWithNullCredentials()
        {
            IHDInsightSubscriptionCredentials credentials = null;
            Exception error = null;

            try
            {
                IHttpClientAbstraction invalidAbstraction =
                    ServiceLocator.Instance.Locate <IHDInsightHttpClientAbstractionFactory>().Create(credentials, false);
                Assert.Fail("No Http client should be created with null credentials");
            }
            catch (NotSupportedException e)
            {
                error = e;
            }
            Assert.IsNotNull(error);
        }
        // Method = "PUT", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/{resourceProviderNamespace}/{resourceType}/{resourceName}"
        public async Task<IHttpResponseMessageAbstraction> CreateResource(IHttpClientAbstraction client, string resourceId, string resourceType, string location, string clusterPayload, int schemaVersion = 2)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate<IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder = overrideHandlers.UriBuilder;
            client.RequestUri = uriBuilder.GetCreateResourceUri(resourceId, resourceType, location);
            client.Method = HttpMethod.Put;
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            switch (schemaVersion)
            {
                case 2:
                    client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion2);
                    break;
                case 3:
                    client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion3);
                    break;
            }
            client.RequestHeaders.Add(HDInsightRestConstants.Accept);
            client.Content = new StringContent(clusterPayload);

            return await this.ProcessSendAsync(client);
        }
Example #20
0
        public void TestWithInvalidCredentialType()
        {
            IHDInsightSubscriptionCredentials credentials = new TestInvalidCredentials()
            {
                DeploymentNamespace = "hdinsight",
                Endpoint            = new Uri("http://notrdfe.com/"),
                SubscriptionId      = Guid.NewGuid()
            };
            Exception error = null;

            try
            {
                IHttpClientAbstraction invalidAbstraction =
                    ServiceLocator.Instance.Locate <IHDInsightHttpClientAbstractionFactory>().Create(credentials, false);
                Assert.Fail("No Http client should be created with unsupported credential types");
            }
            catch (NotSupportedException e)
            {
                error = e;
            }
            Assert.IsNotNull(error);
        }
        // Method = "GET", UriTemplate = "{subscriptionId}/cloudservices"
        internal async Task<IHttpResponseMessageAbstraction> ProcessGetResourceProviderPropertiesRequest(IHttpClientAbstraction client)
        {
            Guid subscriptionId = this.credentials.SubscriptionId;
            string relativeUri = string.Format(CultureInfo.InvariantCulture,
                                                "{0}/resourceproviders/{1}/Properties?resourceType={2}",
                                                subscriptionId,
                                                this.credentials.DeploymentNamespace,
                                                "containers");
            client.RequestUri = new Uri(this.credentials.Endpoint, new Uri(relativeUri, UriKind.Relative));

            client.Method = HttpMethod.Get;
            if (!client.RequestHeaders.ContainsKey(HDInsightRestConstants.XMsVersion.Key))
            {
                client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            }
            if (!client.RequestHeaders.ContainsKey(HDInsightRestConstants.Accept.Key))
            {
                client.RequestHeaders.Add(HDInsightRestConstants.Accept);
            }

            var httpResponse = await client.SendAsync();
            return httpResponse;
        }
Example #22
0
        public void TestWithCertificateCredentials()
        {
            IHDInsightSubscriptionCredentials credentials = new HDInsightCertificateCredential()
            {
                Certificate         = new X509Certificate2(IntegrationTestBase.TestCredentials.Certificate),
                DeploymentNamespace = "hdinsight",
                Endpoint            = new Uri("http://notrdfe.com/"),
                SubscriptionId      = Guid.NewGuid()
            };
            Exception error = null;

            try
            {
                //Should not have token header set when using a certificate
                IHttpClientAbstraction validAbstraction =
                    ServiceLocator.Instance.Locate <IHDInsightHttpClientAbstractionFactory>().Create(credentials, false);
                Assert.IsFalse(validAbstraction.RequestHeaders.ContainsKey("Authorization"));
            }
            catch (NotSupportedException e)
            {
                error = e;
            }
            Assert.IsNull(error);
        }
        private async Task <IHttpResponseMessageAbstraction> ProcessGetClusterResourceDetail(IHttpClientAbstraction client, string resourceId, string resourceType, string location)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate <IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder       = overrideHandlers.UriBuilder;

            client.RequestUri = uriBuilder.GetGetClusterResourceDetailUri(resourceId, resourceType, location);
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            client.RequestHeaders.Add(HDInsightRestConstants.Accept);
            client.RequestHeaders.Add(HDInsightRestConstants.UserAgent);
            client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion3);
            client.Method = HttpMethod.Get;

            // Sends, validates and parses the response
            return(await this.ProcessSendAsync(client));
        }
        private async Task<IHttpResponseMessageAbstraction> ProcessDeleteContainer(IHttpClientAbstraction client, string dnsName, string location)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate<IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder = overrideHandlers.UriBuilder;

            client.RequestUri = uriBuilder.GetDeleteContainerUri(dnsName, location);

            client.Method = HttpMethod.Delete;
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            client.RequestHeaders.Add(HDInsightRestConstants.Accept);

            return await this.ProcessSendAsync(client);
        }
 internal async Task<IHttpResponseMessageAbstraction> DoClientSend(IHttpClientAbstraction client)
 {
     client.ContentType = "text/HTML";
     client.Method = HttpMethod.Get;
     client.RequestHeaders.Add("test", "value");
     client.RequestUri = new Uri("http://www.microsoft.com");
     client.Timeout = new TimeSpan(0, 5, 0);
     var ret = await client.SendAsync();
     if (ret.StatusCode != HttpStatusCode.Accepted && ret.StatusCode != HttpStatusCode.OK)
     {
         throw new HttpLayerException(ret.StatusCode, ret.Content);
     }
     return ret;
 }
        public async Task<IHttpResponseMessageAbstraction> ProcessGetOperationStatus(IHttpClientAbstraction client, string dnsName, string location, Guid operationId)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate<IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder = overrideHandlers.UriBuilder;
            client.RequestUri = uriBuilder.GetOperationStatusUri(dnsName, location, this.credentials.DeploymentNamespace, operationId);
            client.Method = HttpMethod.Get;
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion2);

            return await this.ProcessSendAsync(client);
        }
        /// <summary>
        /// Sends a HttpCLient request, while checking for errors on the return value.
        /// </summary>
        /// <param name="httpClient">The HttpCLient instance to send.</param>
        /// <param name="expectedStatusCode">The status code expected for a succesful response.</param>
        /// <returns>The HttpResponse, after it has been checked for errors.</returns>
        private static async Task<IHttpResponseMessageAbstraction> SendRequestWithErrorChecking(IHttpClientAbstraction httpClient, HttpStatusCode expectedStatusCode)
        {
            var httpResponseMessage = await httpClient.SendAsync();

            if (httpResponseMessage.StatusCode != expectedStatusCode)
            {
                throw new HttpLayerException(httpResponseMessage.StatusCode, httpResponseMessage.Content);
    }

            return httpResponseMessage;
}
Example #28
0
        /// <summary>
        /// Sends a HttpCLient request, while checking for errors on the return value.
        /// </summary>
        /// <param name="httpClient">The HttpCLient instance to send.</param>
        /// <param name="allowedStatusCodes">Allowed status codes for a succesful response.</param>
        /// <returns>The HttpResponse, after it has been checked for errors.</returns>
        private static async Task <IHttpResponseMessageAbstraction> SendRequestWithErrorChecking(IHttpClientAbstraction httpClient, params HttpStatusCode[] allowedStatusCodes)
        {
            var httpResponseMessage = await httpClient.SendAsync();

            if (!allowedStatusCodes.Contains(httpResponseMessage.StatusCode))
            {
                throw new HttpLayerException(httpResponseMessage.StatusCode, httpResponseMessage.Content);
            }

            return(httpResponseMessage);
        }
        // Method = "PUT", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/{resourceProviderNamespace}/{resourceType}/{resourceName}"
        public async Task<IHttpResponseMessageAbstraction> CreateResource(IHttpClientAbstraction client, string resourceId, string resourceType, string location, string clusterPayload, int schemaVersion = 2)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate<IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder = overrideHandlers.UriBuilder;
            client.RequestUri = uriBuilder.GetCreateResourceUri(resourceId, resourceType, location);
            client.Method = HttpMethod.Put;
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            switch (schemaVersion)
            {
                case 2:
                    client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion2);
                    break;
                case 3:
                    client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion3);
                    break;
            }
            client.RequestHeaders.Add(HDInsightRestConstants.Accept);
            client.Content = new StringContent(clusterPayload);

            return await this.ProcessSendAsync(client);
        }
Example #30
0
        // Method = "GET", UriTemplate = "{subscriptionId}/cloudservices"
        internal async Task <IHttpResponseMessageAbstraction> ProcessGetResourceProviderPropertiesRequest(IHttpClientAbstraction client)
        {
            Guid   subscriptionId = this.credentials.SubscriptionId;
            string relativeUri    = string.Format(CultureInfo.InvariantCulture,
                                                  "{0}/resourceproviders/{1}/Properties?resourceType={2}",
                                                  subscriptionId,
                                                  this.credentials.DeploymentNamespace,
                                                  "containers");

            client.RequestUri = new Uri(this.credentials.Endpoint, new Uri(relativeUri, UriKind.Relative));

            client.Method = HttpMethod.Get;
            if (!client.RequestHeaders.ContainsKey(HDInsightRestConstants.XMsVersion.Key))
            {
                client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            }
            if (!client.RequestHeaders.ContainsKey(HDInsightRestConstants.Accept.Key))
            {
                client.RequestHeaders.Add(HDInsightRestConstants.Accept);
            }

            var httpResponse = await client.SendAsync();

            return(httpResponse);
        }
        /// <summary>
        /// Sends a HttpCLient request, while checking for errors on the return value.
        /// </summary>
        /// <param name="httpClient">The HttpCLient instance to send.</param>
        /// <param name="allowedStatusCodes">Allowed status codes for a succesful response.</param>
        /// <returns>The HttpResponse, after it has been checked for errors.</returns>
        private static async Task<IHttpResponseMessageAbstraction> SendRequestWithErrorChecking(IHttpClientAbstraction httpClient, params HttpStatusCode[] allowedStatusCodes)
        {
            var httpResponseMessage = await httpClient.SendAsync();

            if (!allowedStatusCodes.Contains(httpResponseMessage.StatusCode))
            {
                throw new HttpLayerException(httpResponseMessage.StatusCode, httpResponseMessage.Content);
            }

            return httpResponseMessage;
        }
        private async Task<IHttpResponseMessageAbstraction> ProcessGetClusterResourceDetail(IHttpClientAbstraction client, string resourceId, string resourceType, string location)
        {
            var overrideHandlers = ServiceLocator.Instance.Locate<IHDInsightClusterOverrideManager>().GetHandlers(this.credentials, this.context, this.ignoreSslErrors);
            var uriBuilder = overrideHandlers.UriBuilder;

            client.RequestUri = uriBuilder.GetGetClusterResourceDetailUri(resourceId, resourceType, location);
            client.RequestHeaders.Add(HDInsightRestConstants.XMsVersion);
            client.RequestHeaders.Add(HDInsightRestConstants.Accept);
            client.RequestHeaders.Add(HDInsightRestConstants.UserAgent);
            client.RequestHeaders.Add(HDInsightRestConstants.SchemaVersion3);
            client.Method = HttpMethod.Get;

            // Sends, validates and parses the response
            return await this.ProcessSendAsync(client);
        }
        /// <summary>
        /// Sends a HttpCLient request, while checking for errors on the return value.
        /// </summary>
        /// <param name="httpClient">The HttpCLient instance to send.</param>
        /// <param name="expectedStatusCode">The status code expected for a succesful response.</param>
        /// <returns>The HttpResponse, after it has been checked for errors.</returns>
        private static async Task <IHttpResponseMessageAbstraction> SendRequestWithErrorChecking(IHttpClientAbstraction httpClient, HttpStatusCode expectedStatusCode)
        {
            var httpResponseMessage = await httpClient.SendAsync();

            if (httpResponseMessage.StatusCode != expectedStatusCode)
            {
                throw new HttpLayerException(httpResponseMessage.StatusCode, httpResponseMessage.Content);
            }

            return(httpResponseMessage);
        }
 /// <summary>
 /// Provides the basic authorization for a connection.
 /// </summary>
 /// <param name="httpClient">
 /// The HttpClient to which authorization should be added.
 /// </param>
 private void ProvideStandardHeaders(IHttpClientAbstraction httpClient)
 {
     if (this.credentials.UserName != null && this.credentials.Password != null)
     {
         var byteArray = Encoding.ASCII.GetBytes(this.credentials.UserName + ":" + this.credentials.Password);
         httpClient.RequestHeaders.Add(HadoopRemoteRestConstants.Authorization, "Basic " + Convert.ToBase64String(byteArray));
     }
     httpClient.RequestHeaders.Add("accept", "application/json");
     httpClient.RequestHeaders.Add("useragent", this.GetUserAgentString());
     httpClient.RequestHeaders.Add("User-Agent", this.GetUserAgentString());
 }