示例#1
0
        /// <inheritdoc />
        public async Task CreateContainer(HDInsight.ClusterCreateParametersV2 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
            {
                await this.RegisterSubscriptionIfExistsAsync();

                await this.CreateCloudServiceAsyncIfNotExists(clusterCreateParameters.Location);

                // TODO: fix hard-coded schema version
                string schemaVersion = "1.0";
                var    iaasCluster   = PayloadConverterIaasClusters.ConvertToIaasCluster(clusterCreateParameters, this.credentials.SubscriptionId.ToString());
                var    rdfeResource  = PayloadConverterIaasClusters.CreateRdfeResource(iaasCluster, schemaVersion);

                await
                this.rdfeRestClient.CreateCluster(
                    this.credentials.SubscriptionId.ToString(),
                    this.GetCloudServiceName(clusterCreateParameters.Location),
                    this.credentials.DeploymentNamespace,
                    clusterCreateParameters.Name,
                    rdfeResource,
                    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);
            }
        }
        /// <inheritdoc />
        public async Task CreateContainer(HDInsight.ClusterCreateParametersV2 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
            {
                await this.RegisterSubscriptionIfExistsAsync();

                await this.CreateCloudServiceAsyncIfNotExists(clusterCreateParameters.Location);

                // TODO: fix hard-coded schema version
                string schemaVersion = "1.0";
                var    iaasCluster   = PayloadConverterIaasClusters.ConvertToIaasCluster(clusterCreateParameters, this.credentials.SubscriptionId.ToString());
                var    rdfeResource  = PayloadConverterIaasClusters.CreateRdfeResource(iaasCluster, schemaVersion);

                var resp = await
                           this.rdfeRestClient.CreateCluster(
                    this.credentials.SubscriptionId.ToString(),
                    this.GetCloudServiceName(clusterCreateParameters.Location),
                    this.credentials.DeploymentNamespace,
                    clusterCreateParameters.Name,
                    rdfeResource,
                    this.Context.CancellationToken);

                IEnumerable <String> requestIds;
                if (resp.Headers.TryGetValues("x-ms-request-id", out requestIds))
                {
                    Guid operationId;
                    if (!Guid.TryParse(requestIds.First(), out operationId))
                    {
                        throw new InvalidOperationException("Could not retrieve a valid operation id for the PUT (cluster create) operation.");
                    }

                    // Wait for the operation specified by the request id to complete (succeed or fail).
                    TimeSpan interval = TimeSpan.FromSeconds(1);
                    TimeSpan timeout  = TimeSpan.FromMinutes(5);
                    await this.WaitForRdfeOperationToComplete(operationId, interval, timeout, Context.CancellationToken);
                }
            }
            catch (InvalidExpectedStatusCodeException iEx)
            {
                string content = iEx.Response.Content != null?iEx.Response.Content.ReadAsStringAsync().Result : string.Empty;

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