private async Task <GetClusterResult> GetClusterFromCloudServiceResource(CloudService cloudService, Resource clusterResource)
        {
            var clusterDetails = PayloadConverterClusters.CreateClusterDetailsFromRdfeResourceOutput(
                cloudService.GeoRegion,
                clusterResource);

            HDInsight.ClusterState clusterState = clusterDetails.State;

            Cluster clusterFromGetClusterCall = null;

            if (clusterState != HDInsight.ClusterState.Deleting &&
                clusterState != HDInsight.ClusterState.DeletePending)
            {
                //we want to poll if we are either in error or unknown state.
                //this is so that we can get the extended error information.
                try
                {
                    clusterFromGetClusterCall =
                        this.SafeGetDataFromPassthroughResponse <Cluster>(
                            await
                            this.rdfeClustersRestClient.GetCluster(
                                this.credentials.SubscriptionId.ToString(),
                                this.GetCloudServiceName(cloudService.GeoRegion),
                                this.credentials.DeploymentNamespace,
                                clusterResource.Name,
                                this.Context.CancellationToken));

                    clusterDetails = PayloadConverterClusters.CreateClusterDetailsFromGetClustersResult(clusterFromGetClusterCall);
                }
                catch (InvalidExpectedStatusCodeException ie)
                {
                    //if we got a not found back that we means the RP has no record of this cluster.
                    //It would happen if one of the basic validations fail, cluster dns name uniqueness
                    if (ie.ReceivedStatusCode == HttpStatusCode.NotFound)
                    {
                        //We may sometimes have a record of the cluster on the server,
                        //which means we can populate extended error information
                    }
                }
            }

            clusterDetails.SubscriptionId = this.credentials.SubscriptionId;

            return(new GetClusterResult(clusterDetails, clusterFromGetClusterCall));
        }
        /// <summary>
        /// Creates the container.
        /// </summary>
        /// <param name="clusterCreateParameters">The cluster create parameters.</param>
        /// <returns>A task.</returns>
        public async Task CreateContainer(HDInsight.ClusterCreateParameters clusterCreateParameters)
        {
            if (clusterCreateParameters == null)
            {
                throw new ArgumentNullException("clusterCreateParameters");
            }

            if (string.IsNullOrEmpty(clusterCreateParameters.Name))
            {
                throw new ArgumentException("ClusterCreateParameters.Name cannot be null or empty", "clusterCreateParameters");
            }

            if (string.IsNullOrEmpty(clusterCreateParameters.Location))
            {
                throw new ArgumentException("ClusterCreateParameters.Location cannot be null or empty", "clusterCreateParameters");
            }

            if (clusterCreateParameters.ClusterSizeInNodes < 1)
            {
                throw new ArgumentException("clusterCreateParameters.ClusterSizeInNodes must be > 0");
            }
            try
            {
                //Validate
                AsvValidationHelper.ValidateAndResolveAsvAccountsAndPrep(clusterCreateParameters);

                // Validates config action component.
                if (clusterCreateParameters.ConfigActions != null && clusterCreateParameters.ConfigActions.Count > 0)
                {
                    this.LogMessage("Validating parameters for config actions.", Severity.Informational, Verbosity.Detailed);

                    if (!ClustersPocoClient.HasClusterConfigActionCapability(this.capabilities) ||
                        !ClustersPocoClient.HasCorrectSchemaVersionForConfigAction(this.capabilities))
                    {
                        throw new NotSupportedException("Your subscription does not support config actions.");
                    }

                    this.LogMessage("Validating URIs for config actions.", Severity.Informational, Verbosity.Detailed);

                    // Validates that the config actions' Uris are downloadable.
                    UriEndpointValidator.ValidateAndResolveConfigActionEndpointUris(clusterCreateParameters);
                }

                var rdfeCapabilitiesClient =
                    ServiceLocator.Instance.Locate <IRdfeServiceRestClientFactory>().Create(this.credentials, this.Context, this.ignoreSslErrors);
                var capabilities = await rdfeCapabilitiesClient.GetResourceProviderProperties();

                // Validates the region for the cluster creation
                var locationClient     = ServiceLocator.Instance.Locate <ILocationFinderClientFactory>().Create(this.credentials, this.Context, this.ignoreSslErrors);
                var availableLocations = locationClient.ListAvailableLocations(capabilities);
                if (!availableLocations.Contains(clusterCreateParameters.Location, StringComparer.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException(string.Format(
                                                            "Cannot create a cluster in '{0}'. Available Locations for your subscription are: {1}",
                                                            clusterCreateParameters.Location,
                                                            string.Join(",", availableLocations)));
                }

                await this.RegisterSubscriptionIfExistsAsync();

                await this.CreateCloudServiceAsyncIfNotExists(clusterCreateParameters.Location);

                var wireCreateParameters           = PayloadConverterClusters.CreateWireClusterCreateParametersFromUserType(clusterCreateParameters);
                var rdfeResourceInputFromWireInput = PayloadConverterClusters.CreateRdfeResourceInputFromWireInput(wireCreateParameters, GetSchemaVersion(this.capabilities));

                await
                this.rdfeClustersRestClient.CreateCluster(
                    this.credentials.SubscriptionId.ToString(),
                    this.GetCloudServiceName(clusterCreateParameters.Location),
                    this.credentials.DeploymentNamespace,
                    clusterCreateParameters.Name,
                    rdfeResourceInputFromWireInput,
                    this.Context.CancellationToken);
            }
            catch (InvalidExpectedStatusCodeException iEx)
            {
                string content = iEx.Response.Content != null?iEx.Response.Content.ReadAsStringAsync().Result : string.Empty;

                throw new HttpLayerException(iEx.ReceivedStatusCode, content);
            }
        }