private void createLambda() { final CloudFrontIpSynchronizerParameters cloudFrontIpSynchronizerParameters = new CloudFrontIpSynchronizerParameters() .setLambdaBucket(environmentMetadata.getBucketName()) .setLambdaKey(LambdaName.CLOUD_FRONT_SG_GROUP_IP_SYNC.getBucketKey()); final TypeReference<Map<String, String>> typeReference = new TypeReference<Map<String, String>>() {}; final Map<String, String> parameters = cloudformationObjectMapper.convertValue(cloudFrontIpSynchronizerParameters, typeReference); final String stackId = cloudFormationService.createStack(StackName.CLOUD_FRONT_IP_SYNCHRONIZER.getName(), parameters, ConfigConstants.CF_ELB_IP_SYNC_STACK_TEMPLATE_PATH, true); final StackStatus endStatus = cloudFormationService.waitForStatus(stackId, Sets.newHashSet(StackStatus.CREATE_COMPLETE, StackStatus.ROLLBACK_COMPLETE)); if (endStatus != StackStatus.CREATE_COMPLETE) { final String errorMessage = String.format("Unexpected end status: %s", endStatus.name()); logger.error(errorMessage); throw new UnexpectedCloudFormationStatusException(errorMessage); } }
/** * Returns the current status of the named stack. * * @param stackId Stack ID. * @return Stack status data. */ @Nullable public StackStatus getStackStatus(final String stackId) { final DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackId); try { final DescribeStacksResult result = cloudFormationClient.describeStacks(request); if (result.getStacks().size() > 0) { final String status = result.getStacks().get(0).getStackStatus(); if (StringUtils.isNotBlank(status)) { return StackStatus.fromValue(status); } } } catch (final AmazonServiceException ase) { // Stack doesn't exist, just return with no status if (ase.getStatusCode() != 400) { throw ase; } } return null; }
private void deleteFailedCreate(final String stackName, AmazonCloudFormation cf, int statusPollingIntervalMs) { { // delete an application in ROLLBACK_COMPLETE status ListStacksResult r = cf.listStacks(); r.getStackSummaries() // .stream() // .filter(x -> x.getStackName().equals(stackName)) // .limit(1) // .filter(x -> StackStatus.ROLLBACK_COMPLETE.toString().equals(x.getStackStatus())) // .forEach(x -> { log.info("Deleting stack with status " + x.getStackStatus()); // cf.deleteStack(new DeleteStackRequest().withStackName(stackName)); waitForCompletion(cf, stackName, statusPollingIntervalMs, log); }); } }
private List<Output> getOutputForRequest(String vpcStackName, AmazonCloudFormationClient client) { int tried = 0; while (tried < MAX_TRY) { LOGGER.info("checking vpc stack creation result, tried: " + tried + '/' + MAX_TRY); DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.withStackName(vpcStackName); Stack resultStack = client.describeStacks(describeStacksRequest).getStacks().get(0); StackStatus stackStatus = StackStatus.valueOf(resultStack.getStackStatus()); if (FAILED_STATUSES.contains(stackStatus)) { LOGGER.error("stack creation failed: ", stackStatus); throw new RuntimeException(); } else if (CREATE_COMPLETE.equals(stackStatus)) { return resultStack.getOutputs(); } try { Thread.sleep(10000); } catch (InterruptedException e) { LOGGER.error("thread sleep interrupted", e); } tried++; } throw new RuntimeException("vpc creation timed out"); }
public String waitForDeleteFinished(StackNameAndId stackId) throws WrongNumberOfStacksException, InterruptedException { StackStatus initialStatus = StackStatus.DELETE_IN_PROGRESS; String result; try { result = cfnRepository.waitForStatusToChangeFrom(stackId.getStackName(), initialStatus, Arrays.asList(DELETE_ABORTS)); } catch(com.amazonaws.AmazonServiceException awsException) { logger.warn("Caught exception during status check", awsException); String errorCode = awsException.getErrorCode(); // TODO should this be using statuscode=400? if (errorCode.equals("ValidationError")) { result = StackStatus.DELETE_COMPLETE.toString(); } else { result = StackStatus.DELETE_FAILED.toString(); } } if (!result.equals(StackStatus.DELETE_COMPLETE.toString())) { logger.error("Failed to delete stack, status is " + result); logStackEvents(cfnRepository.getStackEvents(stackId.getStackName())); } return result; }
@Override public String waitForUpdateFinished(StackNameAndId id) throws WrongNumberOfStacksException, InterruptedException, WrongStackStatus { String stackName = id.getStackName(); String result = cfnRepository.waitForStatusToChangeFrom(stackName, StackStatus.UPDATE_IN_PROGRESS, Arrays.asList(UPDATE_ABORTS)); if (result.equals(StackStatus.UPDATE_COMPLETE_CLEANUP_IN_PROGRESS.toString())) { logger.info("Update now in cleanup status"); result = cfnRepository.waitForStatusToChangeFrom(stackName, StackStatus.UPDATE_COMPLETE_CLEANUP_IN_PROGRESS, Arrays.asList(UPDATE_ABORTS)); } String complete = StackStatus.UPDATE_COMPLETE.toString(); if (!result.equals(complete)) { logger.error("Expected " + complete); logStackEvents(cfnRepository.getStackEvents(id.getStackName())); throw new WrongStackStatus(id, complete, result); } return result; }
private void processNotificationsWithPendingDeletions(DeletionsPending pending, List<StackNotification> notifications) throws WrongStackStatus { String deleteStatus = StackStatus.DELETE_COMPLETE.toString(); for(StackNotification notification : notifications) { String resourceType = notification.getResourceType(); if (resourceType.equals(STACK_RESOURCE_TYPE)) { String status = notification.getStatus(); String stackName = notification.getStackName(); String stackId = notification.getStackId(); if (status.equals(deleteStatus)) { logger.info(String.format("Delete complete for stack name %s and id %s", stackName, stackId)); pending.markIdAsDeleted(stackId); } else if (deleteAborts.contains(status)) { logger.error(String.format("Detected delete has failed for stackid %s name %s status was %s", stackId, stackName, status)); throw new WrongStackStatus(new StackNameAndId(stackName, stackId), deleteStatus, status); } else { logger.info(String.format("Delete not yet complete for stack %s status is %s",stackName, notification.getStatus())); } } else { logger.info(String.format("Got notification for resource type %s, status is %s", resourceType, notification.getStatus())); } } }
protected StackNameAndId setUpdateExpectations(String stackName, String filename, List<TemplateParameter> templateParameters, Collection<Parameter> parameters) throws CfnAssistException, InterruptedException, IOException { String stackId = "stackId"; Stack stack = new Stack().withStackId(stackId); StackNameAndId stackNameAndId = new StackNameAndId(stackName, stackId); String contents = EnvironmentSetupForTests.loadFile(filename); EasyMock.expect(vpcRepository.getCopyOfVpc(projectAndEnv)).andReturn(new Vpc().withVpcId(VPC_ID)); EasyMock.expect(cfnRepository.validateStackTemplate(contents)).andReturn(templateParameters); EasyMock.expect(cfnRepository.updateStack(contents, parameters, monitor, stackName)).andReturn(stackNameAndId); EasyMock.expect(monitor.waitForUpdateFinished(stackNameAndId)).andReturn(StackStatus.UPDATE_COMPLETE.toString()); EasyMock.expect(cfnRepository.updateSuccess(stackNameAndId)).andReturn(stack); EasyMock.expect(cloudRepository.getZones()).andReturn(zones); return stackNameAndId; }
@Test public void shouldThrowWhenExpectedStatusNotWithinTimeout() throws MissingArgumentException, InterruptedException, CfnAssistException { isStackFound= true; String inProgress = StackStatus.CREATE_IN_PROGRESS.toString(); setExpectationsForInitAndReady(); setExpectationsRepondInProgressUntilLimit(inProgress); replayAll(); monitor.init(); try { monitor.waitForRollbackComplete(stackNameAndId); fail("should have thrown"); } catch(WrongStackStatus expectedException) { // noop } verifyAll(); }
@Test public void shouldMonitorMultiplePendingDeletes() throws InterruptedException, CfnAssistException, MissingArgumentException { isStackFound = true; String targetStatus = StackStatus.DELETE_COMPLETE.toString(); DeletionsPending pending = createPendingDelete(); eventSource.init(); EasyMock.expectLastCall(); EasyMock.expect(eventSource.isInit()).andReturn(true); setEventStreamExpectations(StackStatus.DELETE_IN_PROGRESS.toString(), targetStatus, "stackC", "id3"); setEventStreamExpectations(StackStatus.DELETE_IN_PROGRESS.toString(), targetStatus, "stackB", "id2"); setEventStreamExpectations(StackStatus.DELETE_IN_PROGRESS.toString(), targetStatus, "stackA", "id1"); replayAll(); monitor.init(); monitor.waitForDeleteFinished(pending, this); assertEquals(0, deltaIndexResult); verifyAll(); }
@Test public void shouldMonitorMultiplePendingDeletesOutOfOrder() throws InterruptedException, CfnAssistException, MissingArgumentException { isStackFound = true; String targetStatus = StackStatus.DELETE_COMPLETE.toString(); DeletionsPending pending = createPendingDelete(); eventSource.init(); EasyMock.expectLastCall(); EasyMock.expect(eventSource.isInit()).andReturn(true); setEventStreamExpectations(StackStatus.DELETE_IN_PROGRESS.toString(), targetStatus, "stackB", "id2"); setEventStreamExpectations(StackStatus.DELETE_IN_PROGRESS.toString(), targetStatus, "stackA", "id1"); setEventStreamExpectations(StackStatus.DELETE_IN_PROGRESS.toString(), targetStatus, "stackC", "id3"); replayAll(); monitor.init(); monitor.waitForDeleteFinished(pending, this); assertEquals(0, deltaIndexResult); verifyAll(); }
@Test public void shouldMonitorMultiplePendingDeletesNotAll() throws InterruptedException, CfnAssistException, MissingArgumentException { isStackFound = true; String targetStatus = StackStatus.DELETE_COMPLETE.toString(); DeletionsPending pending = createPendingDelete(); eventSource.init(); EasyMock.expectLastCall(); EasyMock.expect(eventSource.isInit()).andReturn(true); setEventStreamExpectations(StackStatus.DELETE_IN_PROGRESS.toString(), targetStatus, "stackB", "id2"); setEventStreamExpectations(StackStatus.DELETE_IN_PROGRESS.toString(), targetStatus, "stackC", "id3"); setExpectationsRepondInProgressUntilLimit(StackStatus.DELETE_IN_PROGRESS.toString()); replayAll(); monitor.init(); monitor.waitForDeleteFinished(pending, this); assertEquals(1, deltaIndexResult); verifyAll(); }
@Test public void shouldMonitorMultiplePendingDeletesSomeMissing() throws InterruptedException, CfnAssistException, MissingArgumentException { isStackFound = true; String targetStatus = StackStatus.DELETE_COMPLETE.toString(); DeletionsPending pending = createPendingDelete(); eventSource.init(); EasyMock.expectLastCall(); EasyMock.expect(eventSource.isInit()).andReturn(true); setEventStreamExpectations(StackStatus.DELETE_IN_PROGRESS.toString(), targetStatus, "stackB", "id2"); setExpectationsRepondInProgressUntilLimit(StackStatus.DELETE_IN_PROGRESS.toString()); replayAll(); monitor.init(); monitor.waitForDeleteFinished(pending, this); assertEquals(1, deltaIndexResult); verifyAll(); }
@Test public void shouldListStacks() throws MissingArgumentException, CfnAssistException, InterruptedException, IOException { String stackName = "theStackName"; String project = "theProject"; String stackId = "theStackId"; String env = "theEnv"; setFactoryExpectations(); List<StackEntry> stackEntries = new LinkedList<>(); Stack stack = new Stack().withStackName(stackName).withStackId(stackId).withStackStatus(StackStatus.CREATE_COMPLETE); stackEntries.add(new StackEntry(project, new EnvironmentTag(env), stack)); EasyMock.expect(facade.listStacks(projectAndEnv)).andReturn(stackEntries); String output = validate(CLIArgBuilder.listStacks()); CLIArgBuilder.checkForExpectedLine(stackName, project, env, output); }
@Test public void shouldReturnStatusDeletionFailDueToOtherException() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.DELETE_ABORTS); AmazonServiceException amazonServiceException = new AmazonServiceException("message"); amazonServiceException.setErrorCode("someOtherError"); EasyMock.expect(cfnRepository.waitForStatusToChangeFrom(stackName, StackStatus.DELETE_IN_PROGRESS, aborts)). andThrow(amazonServiceException); List<StackEvent> events = new LinkedList<StackEvent>(); EasyMock.expect(cfnRepository.getStackEvents(stackName)).andReturn(events); replayAll(); String result = monitor.waitForDeleteFinished(stackId); assertEquals(StackStatus.DELETE_FAILED.toString(), result); verifyAll(); }
@Test public void shouldMonitorMultiplePendingDeletes() throws WrongNumberOfStacksException, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.DELETE_ABORTS); StackStatus targetStatus = StackStatus.DELETE_COMPLETE; DeletionsPending pending = new DeletionsPending(); pending.add(3, new StackNameAndId("stackC", "id3")); pending.add(2, new StackNameAndId("stackB", "id2")); pending.add(1, new StackNameAndId("stackA", "id1")); EasyMock.expect(cfnRepository.waitForStatusToChangeFrom("stackC", StackStatus.DELETE_IN_PROGRESS, aborts)) .andReturn(targetStatus.toString()); EasyMock.expect(cfnRepository.waitForStatusToChangeFrom("stackB", StackStatus.DELETE_IN_PROGRESS, aborts)) .andReturn(targetStatus.toString()); EasyMock.expect(cfnRepository.waitForStatusToChangeFrom("stackA", StackStatus.DELETE_IN_PROGRESS, aborts)) .andReturn(targetStatus.toString()); replayAll(); monitor.waitForDeleteFinished(pending, this); assertEquals(0, lastDeltaIndex); verifyAll(); }
@Test public void shouldMonitorMultiplePendingDeletesAndLeaveIndexCorrectOnFailure() throws WrongNumberOfStacksException, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.DELETE_ABORTS); StackStatus targetStatus = StackStatus.DELETE_COMPLETE; DeletionsPending pending = new DeletionsPending(); pending.add(3, new StackNameAndId("stackC", "id3")); pending.add(2, new StackNameAndId("stackB", "id2")); pending.add(1, new StackNameAndId("stackA", "id1")); EasyMock.expect(cfnRepository.waitForStatusToChangeFrom("stackC", StackStatus.DELETE_IN_PROGRESS, aborts)) .andReturn(targetStatus.toString()); EasyMock.expect(cfnRepository.waitForStatusToChangeFrom("stackB", StackStatus.DELETE_IN_PROGRESS, aborts)) .andReturn(StackStatus.DELETE_FAILED.toString()); List<StackEvent> events = new LinkedList<StackEvent>(); EasyMock.expect(cfnRepository.getStackEvents("stackB")).andReturn(events); replayAll(); monitor.waitForDeleteFinished(pending, this); assertEquals(2, lastDeltaIndex); verifyAll(); }
AbstractAwsStackStatusCheckerTask(AuthenticatedContext authenticatedContext, AmazonCloudFormationClient cfClient, StackStatus successStatus, StackStatus errorStatus, List<StackStatus> stackErrorStatuses, String cloudFormationStackName, boolean cancellable) { super(authenticatedContext, cancellable); this.cfClient = cfClient; this.successStatus = successStatus; this.errorStatus = errorStatus; this.stackErrorStatuses = stackErrorStatuses; this.cloudFormationStackName = cloudFormationStackName; describeStacksRequest = new DescribeStacksRequest().withStackName(cloudFormationStackName); stackEventsRequest = new DescribeStackEventsRequest().withStackName(cloudFormationStackName); }
protected boolean isSuccess(Stack cfStack, List<StackEvent> stackEvents) { if (!stackEvents.isEmpty() && cfStack != null) { StackStatus cfStackStatus = StackStatus.valueOf(cfStack.getStackStatus()); if (stackErrorStatuses.contains(cfStackStatus)) { throw new CloudConnectorException(getErrorMessage(errorStatus.toString(), getErrorCauseStatusReason(stackEvents, errorStatus))); } else if (cfStackStatus.equals(successStatus)) { return true; } } return false; }
private String getErrorCauseStatusReason(List<StackEvent> stackEvents, StackStatus errorStatus) { StackEvent cause = null; for (StackEvent event : stackEvents) { if (event.getResourceStatus().equals(errorStatus.toString())) { if (cause == null || cause.getTimestamp().getTime() > event.getTimestamp().getTime()) { cause = event; } } } return cause == null ? "unknown" : cause.getResourceStatusReason(); }
@Override public String waitForCreateFinished(StackNameAndId stackId) throws WrongNumberOfStacksException, InterruptedException, WrongStackStatus { String stackName = stackId.getStackName(); String result = cfnRepository.waitForStatusToChangeFrom(stackName, StackStatus.CREATE_IN_PROGRESS, Arrays.asList(CREATE_ABORTS)); String expected = StackStatus.CREATE_COMPLETE.toString(); if (!result.equals(expected)) { logger.error(String.format("Failed to create stack %s, status is %s", stackId, result)); logStackEvents(cfnRepository.getStackEvents(stackName)); throw new WrongStackStatus(stackId, expected,result); } return result; }
@Override public String waitForRollbackComplete(StackNameAndId id) throws NotReadyException, WrongNumberOfStacksException, WrongStackStatus, InterruptedException { String stackName = id.getStackName(); String result = cfnRepository.waitForStatusToChangeFrom(stackName, StackStatus.ROLLBACK_IN_PROGRESS, Arrays.asList(ROLLBACK_ABORTS)); String complete = StackStatus.ROLLBACK_COMPLETE.toString(); if (!result.equals(complete)) { logger.error("Expected " + complete); logStackEvents(cfnRepository.getStackEvents(stackName)); throw new WrongStackStatus(id, complete, result); } return result; }
@Override public String waitForCreateFinished(StackNameAndId stackId) throws WrongNumberOfStacksException, InterruptedException, NotReadyException, WrongStackStatus { guardForInit(); return waitForStatus(stackId, StackStatus.CREATE_COMPLETE.toString(), Arrays.asList(CREATE_ABORTS)); }
@Override public String waitForDeleteFinished(StackNameAndId stackId) throws WrongNumberOfStacksException, InterruptedException, NotReadyException, WrongStackStatus { guardForInit(); if (!checkStackExists.stackExists(stackId.getStackName())) { return StackStatus.DELETE_COMPLETE.toString(); // assume already gone } return waitForStatus(stackId, StackStatus.DELETE_COMPLETE.toString(), deleteAborts); }
private boolean isMatchingStackNotif(StackNotification notification, StackNameAndId stackId) { if (notification.getStackId().equals(stackId.getStackId())) { logger.info(String.format("Received notification for %s status was %s", notification.getResourceType(), notification.getStatus())); if (notification.getStatus().equals(StackStatus.CREATE_FAILED.toString())) { logger.warn(String.format("Failed to create resource of type %s reason was %s",notification.getResourceType(),notification.getStatusReason())); } return notification.getResourceType().equals(STACK_RESOURCE_TYPE); } logger.info(String.format("Notification did not match stackId, expected: %s was: %s", stackId.getStackId(), notification.getStackId())); return false; }
public static void checkForExpectedLine(String stackName, String project, String env, String result) { //String result = stream.toString(); String lines[] = result.split("\\r?\\n"); boolean found=false; for(String line : lines) { found = line.equals(String.format("%s\t%s\t%s\t%s",stackName, project, env, StackStatus.CREATE_COMPLETE.toString())); if (found) break; } assertTrue(found); }
@Test public void shouldTestWaitForStackCreationDoneEvents() throws InterruptedException, MissingArgumentException, CfnAssistException { isStackFound= true; String inProgress = StackStatus.CREATE_IN_PROGRESS.toString(); String complete = StackStatus.CREATE_COMPLETE.toString(); setExpectationsForInitAndReady(); setEventStreamExpectations(inProgress, complete); replayAll(); monitor.init(); String result = monitor.waitForCreateFinished(stackNameAndId); assertEquals(complete, result); verifyAll(); }
@Test public void shouldTestWaitForStackDeletionDoneEvents() throws InterruptedException, MissingArgumentException, CfnAssistException { isStackFound= true; String inProgress = StackStatus.DELETE_IN_PROGRESS.toString(); String complete = StackStatus.DELETE_COMPLETE.toString(); setExpectationsForInitAndReady(); setEventStreamExpectations(inProgress, complete); replayAll(); monitor.init(); String result = monitor.waitForDeleteFinished(stackNameAndId); assertEquals(complete, result); verifyAll(); }
@Test public void shouldTestWaitForStackDeletionStackAlreadyGone() throws InterruptedException, MissingArgumentException, CfnAssistException { String complete = StackStatus.DELETE_COMPLETE.toString(); isStackFound= false; setExpectationsForInitAndReady(); replayAll(); monitor.init(); String result = monitor.waitForDeleteFinished(stackNameAndId); assertEquals(complete, result); verifyAll(); }
@Test public void shouldTestWaitForStackRollbackDoneEvents() throws InterruptedException, MissingArgumentException, CfnAssistException { isStackFound= true; String inProgress = StackStatus.ROLLBACK_IN_PROGRESS.toString(); String complete = StackStatus.ROLLBACK_COMPLETE.toString(); setExpectationsForInitAndReady(); setEventStreamExpectations(inProgress, complete); replayAll(); monitor.init(); String result = monitor.waitForRollbackComplete(stackNameAndId); assertEquals(complete, result); verifyAll(); }
private void setExpectationsForFile(Integer count, File file, List<TemplateParameter> templateParameters) throws IOException, CfnAssistException, InterruptedException { String templateContents = EnvironmentSetupForTests.loadFile(file.getAbsolutePath()); Collection<Parameter> creationParameters = new LinkedList<>(); String stackName = aws.createStackName(file, projectAndEnv); StackNameAndId stackNameAndId = new StackNameAndId(stackName, count.toString()); EasyMock.expect(vpcRepository.getCopyOfVpc(projectAndEnv)).andReturn(new Vpc()); EasyMock.expect(cfnRepository.validateStackTemplate(templateContents)).andReturn(templateParameters); EasyMock.expect(cfnRepository.getStackStatus(stackName)).andReturn(""); // tagging Tagging tagging = new Tagging(); tagging.setIndexTag(count); // create stack EasyMock.expect(cfnRepository.createStack(projectAndEnv, templateContents, stackName, creationParameters, monitor, tagging)) .andReturn(stackNameAndId); // monitor EasyMock.expect(monitor.waitForCreateFinished(stackNameAndId)).andReturn(StackStatus.CREATE_COMPLETE.toString()); // notification EasyMock.expect(identityProvider.getUserId()).andReturn(user); CFNAssistNotification notification = new CFNAssistNotification(stackName, StackStatus.CREATE_COMPLETE.toString(), user); EasyMock.expect(notificationSender.sendNotification(notification)).andReturn("sentMessageId"); // success EasyMock.expect(cfnRepository.createSuccess(stackNameAndId)).andReturn( new Stack().withStackId(count.toString()).withStackName(stackName)); // index update vpcRepository.setVpcIndexTag(projectAndEnv, count.toString()); }
@Test public void shouldWaitForCreationToComplete() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.CREATE_ABORTS); StackStatus initialStatus = StackStatus.CREATE_IN_PROGRESS; StackStatus targetStatus = StackStatus.CREATE_COMPLETE; setRepoExcpetationsForSuccess(aborts, initialStatus, targetStatus); replayAll(); String status = monitor.waitForCreateFinished(stackId); assertEquals(targetStatus.toString(), status); verifyAll(); }
@Test public void shouldWaitForDeleteToComplete() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.DELETE_ABORTS); StackStatus initialStatus = StackStatus.DELETE_IN_PROGRESS; StackStatus targetStatus = StackStatus.DELETE_COMPLETE; setRepoExcpetationsForSuccess(aborts, initialStatus, targetStatus); replayAll(); String status = monitor.waitForDeleteFinished(stackId); assertEquals(targetStatus.toString(), status); verifyAll(); }
@Test public void shouldWaitForUpdateToComplete() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.UPDATE_ABORTS); StackStatus initialStatus = StackStatus.UPDATE_IN_PROGRESS; StackStatus targetStatus = StackStatus.UPDATE_COMPLETE; setRepoExcpetationsForSuccess(aborts, initialStatus, targetStatus); replayAll(); String status = monitor.waitForUpdateFinished(stackId); assertEquals(targetStatus.toString(), status); verifyAll(); }
@Test public void shouldWaitForUpdateToCompleteWithCleanUp() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.UPDATE_ABORTS); StackStatus initialStatus = StackStatus.UPDATE_IN_PROGRESS; StackStatus targetStatus = StackStatus.UPDATE_COMPLETE; setRepoExcpetationsForSuccess(aborts, initialStatus, StackStatus.UPDATE_COMPLETE_CLEANUP_IN_PROGRESS); setRepoExcpetationsForSuccess(aborts, StackStatus.UPDATE_COMPLETE_CLEANUP_IN_PROGRESS, targetStatus); replayAll(); String status = monitor.waitForUpdateFinished(stackId); assertEquals(targetStatus.toString(), status); verifyAll(); }
@Test public void shouldWaitForRollbackToComplete() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException, NotReadyException { List<String> aborts = Arrays.asList(StackMonitor.ROLLBACK_ABORTS); StackStatus initialStatus = StackStatus.ROLLBACK_IN_PROGRESS; StackStatus targetStatus = StackStatus.ROLLBACK_COMPLETE; setRepoExcpetationsForSuccess(aborts, initialStatus, targetStatus); replayAll(); String status = monitor.waitForRollbackComplete(stackId); assertEquals(targetStatus.toString(), status); verifyAll(); }
@Test public void shouldThrowForCreationFailure() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.CREATE_ABORTS); setRepoExcpetationsForFailure(aborts, StackStatus.CREATE_IN_PROGRESS, StackStatus.CREATE_FAILED); replayAll(); try { monitor.waitForCreateFinished(stackId); fail("exception expected"); } catch(WrongStackStatus expectedException) { // noop } verifyAll(); }
@Test public void shouldThrowForCreationFailureDueToRollback() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.CREATE_ABORTS); setRepoExcpetationsForFailure(aborts, StackStatus.CREATE_IN_PROGRESS, StackStatus.ROLLBACK_IN_PROGRESS); replayAll(); try { monitor.waitForCreateFinished(stackId); fail("exception expected"); } catch(WrongStackStatus expectedException) { // noop } verifyAll(); }
@Test public void shouldThrowForUpdateFailure() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException { List<String> aborts = Arrays.asList(StackMonitor.UPDATE_ABORTS); setRepoExcpetationsForFailure(aborts, StackStatus.UPDATE_IN_PROGRESS, StackStatus.UPDATE_ROLLBACK_COMPLETE); replayAll(); try { monitor.waitForUpdateFinished(stackId); fail("exception expected"); } catch(WrongStackStatus expectedException) { // noop } verifyAll(); }
@Test public void shouldThrowForRollbackFailure() throws WrongNumberOfStacksException, WrongStackStatus, InterruptedException, NotReadyException { List<String> aborts = Arrays.asList(StackMonitor.ROLLBACK_ABORTS); setRepoExcpetationsForFailure(aborts, StackStatus.ROLLBACK_IN_PROGRESS, StackStatus.ROLLBACK_FAILED); replayAll(); try { monitor.waitForRollbackComplete(stackId); fail("exception expected"); } catch(WrongStackStatus expectedException) { // noop } verifyAll(); }