private async Task ValidateCreateClusterSucceeds(ClusterCreateParametersV2 cluster, Action <ClusterDetails> postCreateValidation) { IHDInsightCertificateCredential credentials = IntegrationTestBase.GetValidCredentials(); using (var client = ServiceLocator.Instance.Locate <IHDInsightManagementPocoClientFactory>().Create(credentials, GetAbstractionContext(), false)) { client.CreateContainer(cluster).Wait(); await client.WaitForClusterInConditionOrError(null, cluster.Name, cluster.Location, TimeSpan.FromMinutes(30), HDInsightClient.DefaultPollingInterval, GetAbstractionContext(), this.CreatingStates); var task = client.ListContainer(cluster.Name); task.WaitForResult(); var container = task.Result; Assert.IsNotNull(container); if (container.Error.IsNotNull()) { Assert.Fail("The Container was not expected to return an error but returned ({0}) ({1})", container.Error.HttpCode, container.Error.Message); } if (postCreateValidation != null) { postCreateValidation(container); } await client.DeleteContainer(cluster.Name); await client.WaitForClusterNullOrError(cluster.Name, cluster.Location, TimeSpan.FromMinutes(10), IntegrationTestBase.GetAbstractionContext().CancellationToken); Assert.IsNull(container.Error); Assert.IsNull(client.ListContainer(cluster.Name).WaitForResult()); } }
public async Task UnregisterSubscriptionLocation(string location) { await Task.Delay(TimeSpan.FromMilliseconds(1)); lock (locker) { var managementClient = ServiceLocator.Instance.Locate <IHDInsightManagementRestClientFactory>().Create(this.credentials, IntegrationTestBase.GetAbstractionContext(), false); var payload = managementClient.ListCloudServices().WaitForResult(); var clusters = new PayloadConverter().DeserializeListContainersResult(payload.Content, this.credentials.DeploymentNamespace, this.credentials.SubscriptionId); if (clusters.Any(cluster => cluster.Location == location)) { throw new InvalidOperationException("Cannot unregister a subscription location if it contains clusters"); } List <string> registeredLocations; if (!subcriptions.TryGetValue(credentials.SubscriptionId, out registeredLocations)) { throw new InvalidOperationException("Invalid subscription"); } // The service doesn't fail if the location wasn't registered if (!registeredLocations.Any(registeredLocation => string.Equals(registeredLocation, location))) { var resolver = ServiceLocator.Instance.Locate <ICloudServiceNameResolver>(); string regionCloudServicename = resolver.GetCloudServiceName(this.credentials.SubscriptionId, this.credentials.DeploymentNamespace, location); throw new HttpLayerException( HttpStatusCode.NotFound, string.Format("The cloud service with name {0} was not found.", regionCloudServicename)); } registeredLocations.Remove(registeredLocations.First(registeredLocation => string.Equals(registeredLocation, location))); } }