com.amazonaws.waiters.Waiter Java Examples
The following examples show how to use
com.amazonaws.waiters.Waiter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsRdsStartService.java From cloudbreak with Apache License 2.0 | 6 votes |
public void start(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS rdsClient = awsClient.createRdsClient(credentialView, regionName); String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId(); StartDBInstanceRequest startDBInstanceRequest = new StartDBInstanceRequest(); startDBInstanceRequest.setDBInstanceIdentifier(dbInstanceIdentifier); try { rdsClient.startDBInstance(startDBInstanceRequest); } catch (RuntimeException ex) { throw new CloudConnectorException(ex.getMessage(), ex); } Waiter<DescribeDBInstancesRequest> rdsWaiter = rdsClient.waiters().dBInstanceAvailable(); DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); run(rdsWaiter, describeDBInstancesRequest, stackCancellationCheck); }
Example #2
Source File: EventPrinter.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
void waitAndPrintChangeSetEvents(String stack, String changeSet, Waiter<DescribeChangeSetRequest> waiter, PollConfiguration pollConfiguration) throws ExecutionException { final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null); waiter.runAsync(new WaiterParameters<>(new DescribeChangeSetRequest().withStackName(stack).withChangeSetName(changeSet)).withPollingStrategy(this.pollingStrategy(pollConfiguration)), new WaiterHandler() { @Override public void onWaitSuccess(AmazonWebServiceRequest request) { waitResult.completed(request); } @Override public void onWaitFailure(Exception e) { waitResult.failed(e); } }); this.waitAndPrintEvents(stack, pollConfiguration, waitResult); }
Example #3
Source File: EventPrinter.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter, PollConfiguration pollConfiguration) throws ExecutionException { final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null); waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)).withPollingStrategy(this.pollingStrategy(pollConfiguration)), new WaiterHandler() { @Override public void onWaitSuccess(AmazonWebServiceRequest request) { waitResult.completed(request); } @Override public void onWaitFailure(Exception e) { waitResult.failed(e); } }); this.waitAndPrintEvents(stack, pollConfiguration, waitResult); }
Example #4
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Test public void executeChangeSetWithChanges() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest() .withStackName("foo") .withChangeSetName("bar") )).thenReturn(new DescribeChangeSetResult() .withChanges(new Change()) ); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatus("CREATE_COMPLETE").withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); Map<String, String> outputs = stack.executeChangeSet("bar", PollConfiguration.DEFAULT); Mockito.verify(client).executeChangeSet(Mockito.any(ExecuteChangeSetRequest.class)); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #5
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Test public void createNewStackChangeSet() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult()); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); stack.createChangeSet("c1", "templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, ChangeSetType.CREATE, "myarn", null); ArgumentCaptor<CreateChangeSetRequest> captor = ArgumentCaptor.forClass(CreateChangeSetRequest.class); Mockito.verify(client).createChangeSet(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new CreateChangeSetRequest() .withChangeSetType(ChangeSetType.CREATE) .withStackName("foo") .withTemplateBody("templateBody") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withChangeSetName("c1") .withRoleARN("myarn") ); Mockito.verify(this.eventPrinter).waitAndPrintChangeSetEvents(Mockito.eq("foo"), Mockito.eq("c1"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); }
Example #6
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Test public void updateStackWithStackChangeSet() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatus("CREATE_COMPLETE"))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); stack.createChangeSet("c1", "templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, ChangeSetType.UPDATE, "myarn", null); ArgumentCaptor<CreateChangeSetRequest> captor = ArgumentCaptor.forClass(CreateChangeSetRequest.class); Mockito.verify(client).createChangeSet(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new CreateChangeSetRequest() .withChangeSetType(ChangeSetType.UPDATE) .withStackName("foo") .withTemplateBody("templateBody") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withChangeSetName("c1") .withRoleARN("myarn") ); Mockito.verify(this.eventPrinter).waitAndPrintChangeSetEvents(Mockito.eq("foo"), Mockito.eq("c1"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); }
Example #7
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Test public void createStackWithStackChangeSetReviewInProgress() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withStackStatus("REVIEW_IN_PROGRESS"))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); stack.createChangeSet("c1", "templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, ChangeSetType.UPDATE, "myarn", null); ArgumentCaptor<CreateChangeSetRequest> captor = ArgumentCaptor.forClass(CreateChangeSetRequest.class); Mockito.verify(client).createChangeSet(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new CreateChangeSetRequest() .withChangeSetType(ChangeSetType.CREATE) .withStackName("foo") .withTemplateBody("templateBody") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withChangeSetName("c1") .withRoleARN("myarn") ); Mockito.verify(this.eventPrinter).waitAndPrintChangeSetEvents(Mockito.eq("foo"), Mockito.eq("c1"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); }
Example #8
Source File: AwsRdsStopService.java From cloudbreak with Apache License 2.0 | 6 votes |
public void stop(AuthenticatedContext ac, DatabaseStack dbStack) throws ExecutionException, TimeoutException, InterruptedException { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS rdsClient = awsClient.createRdsClient(credentialView, regionName); String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId(); StopDBInstanceRequest stopDBInstanceRequest = new StopDBInstanceRequest(); stopDBInstanceRequest.setDBInstanceIdentifier(dbInstanceIdentifier); LOGGER.debug("RDS stop request"); try { rdsClient.stopDBInstance(stopDBInstanceRequest); } catch (RuntimeException ex) { throw new CloudConnectorException(ex.getMessage(), ex); } Waiter<DescribeDBInstancesRequest> rdsWaiter = customAmazonWaiterProvider .getDbInstanceStopWaiter(rdsClient); DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); run(rdsWaiter, describeDBInstancesRequest, stackCancellationCheck); LOGGER.debug("RDS stop process finished. DB Instance ID: {}", dbInstanceIdentifier); }
Example #9
Source File: EncryptedImageCopyService.java From cloudbreak with Apache License 2.0 | 6 votes |
public Map<String, String> createEncryptedImages(AuthenticatedContext ac, CloudStack cloudStack, PersistenceNotifier resourceNotifier) { String selectedAMIName = cloudStack.getImage().getImageName(); AwsCredentialView awsCredentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonEC2Client client = awsClient.createAccess(awsCredentialView, regionName); Map<String, EncryptedImageConfig> configByGroupName = getEncryptedImageConfigByGroup(cloudStack, selectedAMIName, ac, client, resourceNotifier); Map<String, String> imageIdByGroupName = configByGroupName.entrySet() .stream() .collect(Collectors.toMap(Entry::getKey, e -> e.getValue().getImageId())); if (!imageIdByGroupName.isEmpty()) { Collection<String> imageIds = new HashSet<>(imageIdByGroupName.values()); LOGGER.debug("Start polling the availability of the created encrypted AMIs: '{}'", String.join(",", imageIds)); Waiter<DescribeImagesRequest> imageWaiter = client.waiters().imageAvailable(); DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest().withImageIds(imageIds); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); run(imageWaiter, describeImagesRequest, stackCancellationCheck); LOGGER.info("All created encrypted AMIs are available: '{}'", String.join(",", imageIds)); } return imageIdByGroupName; }
Example #10
Source File: CustomAmazonWaiterProvider.java From cloudbreak with Apache License 2.0 | 6 votes |
public Waiter<DescribeAutoScalingGroupsRequest> getAutoscalingInstancesInServiceWaiter(AmazonAutoScalingClient asClient, Integer requiredCount) { return new WaiterBuilder<DescribeAutoScalingGroupsRequest, DescribeAutoScalingGroupsResult>() .withSdkFunction(new DescribeAutoScalingGroupsFunction(asClient)) .withAcceptors(new WaiterAcceptor<DescribeAutoScalingGroupsResult>() { @Override public boolean matches(DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult) { return describeAutoScalingGroupsResult.getAutoScalingGroups().get(0).getInstances() .stream().filter(instance -> IN_SERVICE.equals(instance.getLifecycleState())).count() == requiredCount; } @Override public WaiterState getState() { return WaiterState.SUCCESS; } }) .withDefaultPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(DEFAULT_MAX_ATTEMPTS), new FixedDelayStrategy(DEFAULT_DELAY_IN_SECONDS))) .withExecutorService(WaiterExecutorServiceFactory.buildExecutorServiceForWaiter("AmazonRDSWaiters")).build(); }
Example #11
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Test public void deleteStackByStackNameOnly() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); stack.delete(PollConfiguration.DEFAULT, null, null, null); ArgumentCaptor<DeleteStackRequest> captor = ArgumentCaptor.forClass(DeleteStackRequest.class); Mockito.verify(client).deleteStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new DeleteStackRequest() .withStackName("foo") ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); }
Example #12
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Test public void deleteStack() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); stack.delete(PollConfiguration.DEFAULT, new String[]{"myresourcetoretain"}, "myarn", "myclientrequesttoken"); ArgumentCaptor<DeleteStackRequest> captor = ArgumentCaptor.forClass(DeleteStackRequest.class); Mockito.verify(client).deleteStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new DeleteStackRequest() .withStackName("foo") .withClientRequestToken("myclientrequesttoken") .withRoleARN("myarn") .withRetainResources("myresourcetoretain") ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); }
Example #13
Source File: AwsRepairTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private void upscaleStack() throws Exception { AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext(); CloudStack stack = componentTestUtil.getStack(InstanceStatus.CREATE_REQUESTED, InstanceStatus.STARTED); List<CloudResource> cloudResources = List.of( CloudResource.builder() .name(AWS_SUBNET_ID) .type(ResourceType.AWS_SUBNET) .build(), createVolumeResource(VOLUME_ID_1, INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1, CommonStatus.DETACHED), createVolumeResource(VOLUME_ID_2, INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2, CommonStatus.DETACHED), createVolumeResource(VOLUME_ID_3, INSTANCE_ID_3, SIZE_DISK_2, FSTAB_2, CommonStatus.CREATED)); InMemoryStateStore.putStack(1L, PollGroup.POLLABLE); when(amazonCloudFormationRetryClient.describeStackResource(any())) .thenReturn(new DescribeStackResourceResult() .withStackResourceDetail(new StackResourceDetail().withPhysicalResourceId(AUTOSCALING_GROUP_NAME))); when(amazonAutoScalingRetryClient.describeAutoScalingGroups(any())) .thenReturn(new DescribeAutoScalingGroupsResult() .withAutoScalingGroups(new AutoScalingGroup() .withAutoScalingGroupName(AUTOSCALING_GROUP_NAME) .withInstances(List.of( new Instance().withInstanceId(INSTANCE_ID_1).withLifecycleState(LifecycleState.InService), new Instance().withInstanceId(INSTANCE_ID_2).withLifecycleState(LifecycleState.InService))) )); when(amazonEC2Client.describeVolumes(any())) .thenReturn(new DescribeVolumesResult().withVolumes( new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_1).withState(VolumeState.Available), new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_2).withState(VolumeState.Available), new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_3).withState(VolumeState.InUse) )); when(amazonEC2Client.describeInstances(any())).thenReturn( new DescribeInstancesResult().withReservations( new Reservation().withInstances(new com.amazonaws.services.ec2.model.Instance().withInstanceId("i-instance"))) ); AmazonEC2Waiters waiters = mock(AmazonEC2Waiters.class); when(amazonEC2Client.waiters()).thenReturn(waiters); Waiter<DescribeInstancesRequest> instanceWaiter = mock(Waiter.class); when(waiters.instanceRunning()).thenReturn(instanceWaiter); when(amazonAutoScalingClient.waiters()).thenReturn(asWaiters); when(asWaiters.groupInService()).thenReturn(describeAutoScalingGroupsRequestWaiter); underTest.upscale(authenticatedContext, stack, cloudResources); verify(amazonAutoScalingRetryClient).resumeProcesses(argThat(argument -> AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && argument.getScalingProcesses().contains("Launch"))); verify(amazonAutoScalingRetryClient).updateAutoScalingGroup(argThat(argument -> { Group workerGroup = stack.getGroups().get(1); return AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && workerGroup.getInstancesSize().equals(argument.getMaxSize()) && workerGroup.getInstancesSize().equals(argument.getDesiredCapacity()); })); verify(amazonAutoScalingRetryClient, times(stack.getGroups().size())) .suspendProcesses(argThat(argument -> AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && SUSPENDED_PROCESSES.equals(argument.getScalingProcesses()))); ArgumentCaptor<CloudResource> updatedCloudResourceArgumentCaptor = ArgumentCaptor.forClass(CloudResource.class); verify(resourceNotifier, times(4)).notifyUpdate(updatedCloudResourceArgumentCaptor.capture(), any()); assertVolumeResource(updatedCloudResourceArgumentCaptor.getAllValues(), INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1); assertVolumeResource(updatedCloudResourceArgumentCaptor.getAllValues(), INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2); }
Example #14
Source File: AwsNetworkConnector.java From cloudbreak with Apache License 2.0 | 5 votes |
private CreatedCloudNetwork getCreatedNetworkWithPolling(NetworkCreationRequest networkRequest, AwsCredentialView credentialView, AmazonCloudFormationRetryClient cloudFormationRetryClient, List<SubnetRequest> subnetRequests) { AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, networkRequest.getRegion().value()); Waiter<DescribeStacksRequest> creationWaiter = cfClient.waiters().stackCreateComplete(); DescribeStacksRequest stackRequestWithStackId = new DescribeStacksRequest().withStackName(networkRequest.getStackName()); EnvironmentCancellationCheck environmentCancellationCheck = new EnvironmentCancellationCheck(networkRequest.getEnvId(), networkRequest.getEnvName()); run(creationWaiter, stackRequestWithStackId, environmentCancellationCheck); return getCreatedCloudNetwork(cloudFormationRetryClient, networkRequest, subnetRequests); }
Example #15
Source File: AwsNetworkConnector.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public void deleteNetworkWithSubnets(NetworkDeletionRequest networkDeletionRequest) { if (!networkDeletionRequest.isExisting()) { AwsCredentialView credentialView = new AwsCredentialView(networkDeletionRequest.getCloudCredential()); AmazonCloudFormationRetryClient cloudFormationRetryClient = getCloudFormationRetryClient(credentialView, networkDeletionRequest.getRegion()); DeleteStackRequest deleteStackRequest = new DeleteStackRequest(); deleteStackRequest.setStackName(networkDeletionRequest.getStackName()); cloudFormationRetryClient.deleteStack(deleteStackRequest); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, networkDeletionRequest.getRegion()); Waiter<DescribeStacksRequest> deletionWaiter = cfClient.waiters().stackDeleteComplete(); LOGGER.debug("CloudFormation stack deletion request sent with stack name: '{}' ", networkDeletionRequest.getStackName()); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(networkDeletionRequest.getStackName()); run(deletionWaiter, describeStacksRequest, null); } }
Example #16
Source File: WaiterRunner.java From cloudbreak with Apache License 2.0 | 5 votes |
public static <I extends AmazonWebServiceRequest> void run(Waiter<I> waiter, I input, CancellationCheck cancellationCheck) { try { waiter.run(new WaiterParameters<I>() .withRequest(input) .withPollingStrategy(getBackoffCancellablePollingStrategy(cancellationCheck)) ); } catch (Exception e) { throw new CloudConnectorException(e.getMessage(), e); } }
Example #17
Source File: AWSProvider.java From testgrid with Apache License 2.0 | 5 votes |
/** * This method releases the provisioned AWS infrastructure. * * @param script the script config * @param inputs * @return true or false to indicate the result of destroy operation. * @throws TestGridInfrastructureException when AWS error occurs in deletion process. * @throws InterruptedException when there is an interruption while waiting for the result. */ private boolean doRelease(Script script, Properties inputs, TestPlan testPlan) throws TestGridInfrastructureException, InterruptedException, TestGridDAOException { Path configFilePath; String stackName = script.getName(); String region = inputs.getProperty(AWS_REGION_PARAMETER); configFilePath = TestGridUtil.getConfigFilePath(); AmazonCloudFormation stackdestroy = AmazonCloudFormationClientBuilder.standard() .withCredentials(new PropertiesFileCredentialsProvider(configFilePath.toString())) .withRegion(region) .build(); DeleteStackRequest deleteStackRequest = new DeleteStackRequest(); deleteStackRequest.setStackName(stackName); stackdestroy.deleteStack(deleteStackRequest); logger.info(StringUtil.concatStrings("Stack : ", stackName, " is handed over for deletion!")); //Notify AWSResourceManager about stack destruction to release acquired resources AWSResourceManager awsResourceManager = new AWSResourceManager(); awsResourceManager.notifyStackDeletion(testPlan, script, region); boolean waitForStackDeletion = Boolean .parseBoolean(getProperty(ConfigurationProperties.WAIT_FOR_STACK_DELETION)); if (waitForStackDeletion) { logger.info(StringUtil.concatStrings("Waiting for stack : ", stackName, " to delete..")); Waiter<DescribeStacksRequest> describeStacksRequestWaiter = new AmazonCloudFormationWaiters(stackdestroy).stackDeleteComplete(); try { describeStacksRequestWaiter.run(new WaiterParameters<>(new DescribeStacksRequest() .withStackName(stackName))); } catch (WaiterUnrecoverableException e) { throw new TestGridInfrastructureException("Error occurred while waiting for Stack :" + stackName + " deletion !"); } } return true; }
Example #18
Source File: S3Utils.java From wildfly-camel with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static void createBucket(AmazonS3Client client, String bucketName) throws Exception { client.createBucket(bucketName); HeadBucketRequest request = new HeadBucketRequest(bucketName); Waiter<HeadBucketRequest> waiter = client.waiters().bucketExists(); Future<Void> future = waiter.runAsync(new WaiterParameters<HeadBucketRequest>(request), new NoOpWaiterHandler()); future.get(1, TimeUnit.MINUTES); }
Example #19
Source File: KinesisUtils.java From wildfly-camel with Apache License 2.0 | 5 votes |
public static void createStream(AmazonKinesisClient client, String streamName) throws Exception { client.createStream(streamName, 1); Waiter<DescribeStreamRequest> waiter = client.waiters().streamExists(); DescribeStreamRequest request = new DescribeStreamRequest().withStreamName(streamName); Assert.assertNotNull("Cannot obtain stream description", request); Future<Void> future = waiter.runAsync(new WaiterParameters<DescribeStreamRequest>(request), new NoOpWaiterHandler()); future.get(1, TimeUnit.MINUTES); }
Example #20
Source File: AwsTerminateService.java From cloudbreak with Apache License 2.0 | 5 votes |
private void waitAndDeleteCloudformationStack(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources, AmazonCloudFormationClient amazonCloudFormationClient) { CloudResource stackResource = cfStackUtil.getCloudFormationStackResource(resources); if (stackResource == null) { LOGGER.debug("No cloudformation stack in resources"); return; } String cFStackName = stackResource.getName(); AmazonCloudFormationRetryClient cfRetryClient = awsClient.createCloudFormationRetryClient(amazonCloudFormationClient); LOGGER.debug("Search and wait stack with name: {}", cFStackName); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName); try { retryService.testWith2SecDelayMax15Times(() -> isStackExist(cfRetryClient, cFStackName, describeStacksRequest)); } catch (ActionFailedException ignored) { LOGGER.debug("Stack not found with name: {}", cFStackName); return; } resumeAutoScalingPolicies(ac, stack); LOGGER.debug("Delete cloudformation stack from resources"); DeleteStackRequest deleteStackRequest = new DeleteStackRequest().withStackName(cFStackName); cfRetryClient.deleteStack(deleteStackRequest); Waiter<DescribeStacksRequest> stackDeleteCompleteWaiter = amazonCloudFormationClient.waiters().stackDeleteComplete(); try { WaiterParameters<DescribeStacksRequest> describeStacksRequestWaiterParameters = new WaiterParameters<>(describeStacksRequest) .withPollingStrategy(getBackoffCancellablePollingStrategy(null)); stackDeleteCompleteWaiter.run(describeStacksRequestWaiterParameters); } catch (Exception e) { LOGGER.debug("Cloudformation stack delete failed ", e); throw new CloudConnectorException(e.getMessage(), e); } LOGGER.debug("Cloudformation stack from resources has been deleted"); }
Example #21
Source File: ECSService.java From amazon-ecs-plugin with MIT License | 5 votes |
public void waitForTasksRunning(String tasksArn, String clusterArn, long timeoutInMillis, int DelayBetweenPollsInSeconds) { final AmazonECS client = clientSupplier.get(); Waiter<DescribeTasksRequest> describeTaskWaiter = new AmazonECSWaiters(client).tasksRunning(); describeTaskWaiter.run(new WaiterParameters<DescribeTasksRequest>( new DescribeTasksRequest() .withTasks(tasksArn) .withCluster(clusterArn) .withSdkClientExecutionTimeout((int)timeoutInMillis)) .withPollingStrategy(new PollingStrategy(new MaxTimeRetryStrategy(timeoutInMillis), new FixedDelayStrategy(DelayBetweenPollsInSeconds)))); }
Example #22
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void createStackWithTemplateUrl() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); PollConfiguration pollConfiguration = PollConfiguration.builder() .timeout(Duration.ofMinutes(3)) .pollInterval(Duration.ofSeconds(17)) .build(); Map<String, String> outputs = stack.create(null, "bar", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), pollConfiguration, "myarn", OnFailure.DO_NOTHING.toString(), true); ArgumentCaptor<CreateStackRequest> captor = ArgumentCaptor.forClass(CreateStackRequest.class); Mockito.verify(client).createStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new CreateStackRequest() .withStackName("foo") .withEnableTerminationProtection(true) .withTemplateURL("bar") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withTimeoutInMinutes(3) .withOnFailure(OnFailure.DO_NOTHING) .withRoleARN("myarn") ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(pollConfiguration)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #23
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void createStack() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); Map<String, String> outputs = stack.create("templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", OnFailure.DO_NOTHING.toString(), null); ArgumentCaptor<CreateStackRequest> captor = ArgumentCaptor.forClass(CreateStackRequest.class); Mockito.verify(client).createStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new CreateStackRequest() .withStackName("foo") .withTemplateBody("templateBody") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withTimeoutInMinutes((int) PollConfiguration.DEFAULT.getTimeout().toMinutes()) .withOnFailure(OnFailure.DO_NOTHING) .withRoleARN("myarn") ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #24
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void updateStackWithPreviousTemplate() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); RollbackConfiguration rollbackConfig = new RollbackConfiguration().withMonitoringTimeInMinutes(10); Map<String, String> outputs = stack.update(null, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", rollbackConfig); ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class); Mockito.verify(client).updateStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest() .withStackName("foo") .withUsePreviousTemplate(true) .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withRoleARN("myarn") .withRollbackConfiguration(rollbackConfig) ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #25
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void updateStackWithTemplateUrl() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); RollbackConfiguration rollbackConfig = new RollbackConfiguration().withMonitoringTimeInMinutes(10); Map<String, String> outputs = stack.update(null, "bar", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", rollbackConfig); ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class); Mockito.verify(client).updateStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest() .withStackName("foo") .withTemplateURL("bar") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withRoleARN("myarn") .withRollbackConfiguration(rollbackConfig) ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #26
Source File: CloudformationStackTests.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Test public void updateStack() throws ExecutionException { TaskListener taskListener = Mockito.mock(TaskListener.class); Mockito.when(taskListener.getLogger()).thenReturn(System.out); AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class); Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client)); Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))) .thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz")))); CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener); RollbackConfiguration rollbackConfig = new RollbackConfiguration().withMonitoringTimeInMinutes(10); Map<String, String> outputs = stack.update("templateBody", null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), PollConfiguration.DEFAULT, "myarn", rollbackConfig); ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class); Mockito.verify(client).updateStack(captor.capture()); Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest() .withStackName("foo") .withTemplateBody("templateBody") .withCapabilities(Capability.values()) .withParameters(Collections.emptyList()) .withRoleARN("myarn") .withRollbackConfiguration(rollbackConfig) ); Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(PollConfiguration.DEFAULT)); Assertions.assertThat(outputs).containsEntry("bar", "baz").containsEntry("jenkinsStackUpdateStatus", "true"); }
Example #27
Source File: AwsLaunchService.java From cloudbreak with Apache License 2.0 | 4 votes |
public List<CloudResourceStatus> launch(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier resourceNotifier, AdjustmentType adjustmentType, Long threshold) throws Exception { createKeyPair(ac, stack); String cFStackName = cfStackUtil.getCfStackName(ac); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonCloudFormationRetryClient cfRetryClient = awsClient.createCloudFormationRetryClient(credentialView, regionName); AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName); Network network = stack.getNetwork(); AwsNetworkView awsNetworkView = new AwsNetworkView(network); boolean mapPublicIpOnLaunch = awsNetworkService.isMapPublicOnLaunch(awsNetworkView, amazonEC2Client); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName); try { cfRetryClient.describeStacks(describeStacksRequest); LOGGER.debug("Stack already exists: {}", cFStackName); } catch (AmazonServiceException ignored) { boolean existingVPC = awsNetworkView.isExistingVPC(); boolean existingSubnet = awsNetworkView.isExistingSubnet(); CloudResource cloudFormationStack = new Builder().type(ResourceType.CLOUDFORMATION_STACK).name(cFStackName).build(); resourceNotifier.notifyAllocation(cloudFormationStack, ac.getCloudContext()); String cidr = network.getSubnet().getCidr(); String subnet = isNoCIDRProvided(existingVPC, existingSubnet, cidr) ? awsNetworkService.findNonOverLappingCIDR(ac, stack) : cidr; AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack); ModelContext modelContext = new ModelContext() .withAuthenticatedContext(ac) .withStack(stack) .withExistingVpc(existingVPC) .withExistingIGW(awsNetworkView.isExistingIGW()) .withExistingSubnetCidr(existingSubnet ? awsNetworkService.getExistingSubnetCidr(ac, stack) : null) .withExistinVpcCidr(awsNetworkService.getVpcCidrs(ac, stack)) .withExistingSubnetIds(existingSubnet ? awsNetworkView.getSubnetList() : null) .mapPublicIpOnLaunch(mapPublicIpOnLaunch) .withEnableInstanceProfile(awsInstanceProfileView.isInstanceProfileAvailable()) .withInstanceProfileAvailable(awsInstanceProfileView.isInstanceProfileAvailable()) .withTemplate(stack.getTemplate()) .withDefaultSubnet(subnet) .withOutboundInternetTraffic(network.getOutboundInternetTraffic()) .withVpcCidrs(network.getNetworkCidrs()) .withPrefixListIds(getPrefixListIds(amazonEC2Client, regionName, network.getOutboundInternetTraffic())) .withEncryptedAMIByGroupName(encryptedImageCopyService.createEncryptedImages(ac, stack, resourceNotifier)); String cfTemplate = cloudFormationTemplateBuilder.build(modelContext); LOGGER.debug("CloudFormationTemplate: {}", cfTemplate); cfRetryClient.createStack(awsStackRequestHelper.createCreateStackRequest(ac, stack, cFStackName, subnet, cfTemplate)); } LOGGER.debug("CloudFormation stack creation request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId()); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName); Waiter<DescribeStacksRequest> creationWaiter = cfClient.waiters().stackCreateComplete(); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); run(creationWaiter, describeStacksRequest, stackCancellationCheck); List<CloudResource> networkResources = saveGeneratedSubnet(ac, stack, cFStackName, cfRetryClient, resourceNotifier); suspendAutoscalingGoupsWhenNewInstancesAreReady(ac, stack); AmazonAutoScalingRetryClient amazonASClient = awsClient.createAutoScalingRetryClient(credentialView, regionName); List<CloudResource> instances = cfStackUtil.getInstanceCloudResources(ac, cfRetryClient, amazonASClient, stack.getGroups()); if (mapPublicIpOnLaunch) { associatePublicIpsToGatewayInstances(stack, cFStackName, cfRetryClient, amazonEC2Client, instances); } awsComputeResourceService.buildComputeResourcesForLaunch(ac, stack, adjustmentType, threshold, instances, networkResources); awsTaggingService.tagRootVolumes(ac, amazonEC2Client, instances, stack.getTags()); awsCloudWatchService.addCloudWatchAlarmsForSystemFailures(instances, stack, regionName, credentialView); return awsResourceConnector.check(ac, instances); }
Example #28
Source File: AwsRdsLaunchService.java From cloudbreak with Apache License 2.0 | 4 votes |
public List<CloudResourceStatus> launch(AuthenticatedContext ac, DatabaseStack stack, PersistenceNotifier resourceNotifier) throws Exception { String cFStackName = cfStackUtil.getCfStackName(ac); AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonCloudFormationRetryClient cfRetryClient = awsClient.createCloudFormationRetryClient(credentialView, regionName); AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName); try { cfRetryClient.describeStacks(describeStacksRequest); LOGGER.debug("Stack already exists: {}", cFStackName); } catch (AmazonServiceException ignored) { // all subnets desired for DB subnet group are in the stack boolean existingSubnet = awsNetworkView.isExistingSubnet(); if (!existingSubnet) { throw new CloudConnectorException("Can only create RDS instance with existing subnets"); } CloudResource cloudFormationStack = new Builder().type(ResourceType.CLOUDFORMATION_STACK).name(cFStackName).build(); resourceNotifier.notifyAllocation(cloudFormationStack, ac.getCloudContext()); RDSModelContext rdsModelContext = new RDSModelContext() .withTemplate(stack.getTemplate()) .withNetworkCidrs(awsNetworkView.getExistingVpcCidrs()) .withHasPort(stack.getDatabaseServer().getPort() != null) .withHasSecurityGroup(!stack.getDatabaseServer().getSecurity().getCloudSecurityIds().isEmpty()); String cfTemplate = cloudFormationTemplateBuilder.build(rdsModelContext); LOGGER.debug("CloudFormationTemplate: {}", cfTemplate); cfRetryClient.createStack(awsStackRequestHelper.createCreateStackRequest(ac, stack, cFStackName, cfTemplate)); } LOGGER.debug("CloudFormation stack creation request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId()); AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName); Waiter<DescribeStacksRequest> creationWaiter = cfClient.waiters().stackCreateComplete(); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); run(creationWaiter, describeStacksRequest, stackCancellationCheck); List<CloudResource> databaseResources = getCreatedOutputs(ac, stack, cFStackName, cfRetryClient, resourceNotifier); databaseResources.forEach(dbr -> resourceNotifier.notifyAllocation(dbr, ac.getCloudContext())); // FIXME: For now, just return everything wrapped in a status object return databaseResources.stream() .map(resource -> new CloudResourceStatus(resource, ResourceStatus.CREATED)) .collect(Collectors.toList()); // FIXME check does nothing?! //return awsResourceConnector.check(ac, databaseResources); }
Example #29
Source File: AwsDownscaleService.java From cloudbreak with Apache License 2.0 | 4 votes |
public List<CloudResourceStatus> downscale(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vms, Object resourcesToRemove) { if (!vms.isEmpty()) { List<String> instanceIds = new ArrayList<>(); for (CloudInstance vm : vms) { instanceIds.add(vm.getInstanceId()); } AwsCredentialView credentialView = new AwsCredentialView(auth.getCloudCredential()); AuthenticatedContextView authenticatedContextView = new AuthenticatedContextView(auth); String regionName = authenticatedContextView.getRegion(); awsCloudWatchService.deleteCloudWatchAlarmsForSystemFailures(stack, regionName, credentialView, instanceIds); List<CloudResource> resourcesToDownscale = resources.stream() .filter(resource -> instanceIds.contains(resource.getInstanceId())) .collect(Collectors.toList()); awsComputeResourceService.deleteComputeResources(auth, stack, resourcesToDownscale); String asGroupName = cfStackUtil.getAutoscalingGroupName(auth, vms.get(0).getTemplate().getGroupName(), auth.getCloudContext().getLocation().getRegion().value()); AmazonAutoScalingRetryClient amazonASClient = awsClient.createAutoScalingRetryClient(credentialView, auth.getCloudContext().getLocation().getRegion().value()); detachInstances(asGroupName, instanceIds, amazonASClient); AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, auth.getCloudContext().getLocation().getRegion().value()); terminateInstances(instanceIds, amazonEC2Client); LOGGER.debug("Terminated instances in stack '{}': '{}'", auth.getCloudContext().getId(), instanceIds); try { amazonASClient.updateAutoScalingGroup(new UpdateAutoScalingGroupRequest() .withAutoScalingGroupName(asGroupName) .withMaxSize(getInstanceCount(stack, vms.get(0).getTemplate().getGroupName()))); } catch (AmazonServiceException e) { LOGGER.warn(e.getErrorMessage()); } LOGGER.debug("Polling instance until terminated. [stack: {}, instance: {}]", auth.getCloudContext().getId(), asGroupName); Waiter<DescribeInstancesRequest> instanceTerminatedWaiter = amazonEC2Client.waiters().instanceTerminated(); DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest().withInstanceIds(instanceIds); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(auth.getCloudContext().getId()); run(instanceTerminatedWaiter, describeInstancesRequest, stackCancellationCheck); } return awsResourceConnector.check(auth, resources); }
Example #30
Source File: EncryptedSnapshotService.java From cloudbreak with Apache License 2.0 | 4 votes |
private void checkSnapshotReadiness(AuthenticatedContext ac, AmazonEC2Client client, CreateSnapshotResult snapshotResult) { Waiter<DescribeSnapshotsRequest> snapshotWaiter = client.waiters().snapshotCompleted(); DescribeSnapshotsRequest describeSnapshotsRequest = new DescribeSnapshotsRequest().withSnapshotIds(snapshotResult.getSnapshot().getSnapshotId()); StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId()); run(snapshotWaiter, describeSnapshotsRequest, stackCancellationCheck); }