/// <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); } }
private async Task <GetIaasClusterResult> GetIaasClusterFromCloudServiceResource(CloudService cloudService, Resource clusterResource) { var clusterDetails = PayloadConverterIaasClusters.CreateClusterDetailsFromRdfeResourceOutput(cloudService.GeoRegion, clusterResource); HDInsight.ClusterState clusterState = clusterDetails.State; IaasCluster 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 { PassthroughResponse response = await this.rdfeRestClient.GetCluster( this.credentials.SubscriptionId.ToString(), this.GetCloudServiceName(cloudService.GeoRegion), this.credentials.DeploymentNamespace, clusterResource.Name, this.Context.CancellationToken); clusterFromGetClusterCall = this.SafeGetDataFromPassthroughResponse <IaasCluster>(response); clusterDetails = PayloadConverterIaasClusters.CreateClusterDetailsFromGetClustersResult(clusterFromGetClusterCall); } catch (Exception) { // Ignore all exceptions. We don't want ListContainers to fail on customers for whatever reason. // If there is an issue with obtaining details about the cluster, mark the cluster in Error state with a generic error message clusterDetails.State = ClusterState.Error; if (clusterDetails.Error != null && string.IsNullOrEmpty(clusterDetails.Error.Message)) { clusterDetails.Error.Message = "Unexpected error occurred. Could not retrieve details about the cluster."; } } } clusterDetails.SubscriptionId = this.credentials.SubscriptionId; return(new GetIaasClusterResult(clusterDetails, clusterFromGetClusterCall)); }
/// <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); } }