use of software.amazon.awssdk.services.greengrassv2.model.DeploymentFailureHandlingPolicy.ROLLBACK in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentE2ETest method GIVEN_deployment_fails_due_to_service_broken_WHEN_failure_policy_is_rollback_THEN_deployment_is_rolled_back_and_job_fails.
@Timeout(value = 10, unit = TimeUnit.MINUTES)
@Test
void GIVEN_deployment_fails_due_to_service_broken_WHEN_failure_policy_is_rollback_THEN_deployment_is_rolled_back_and_job_fails(ExtensionContext context) throws Exception {
ignoreExceptionUltimateCauseWithMessage(context, "Service " + getTestComponentNameInCloud("CustomerApp") + " in broken state after deployment");
// Deploy some services that can be used for verification later
CreateDeploymentRequest createDeploymentRequest1 = CreateDeploymentRequest.builder().components(Utils.immutableMap("RedSignal", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").build(), "YellowSignal", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").build())).build();
CreateDeploymentResponse result1 = draftAndCreateDeployment(createDeploymentRequest1);
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, result1.iotJobId(), thingInfo.getThingName(), Duration.ofMinutes(5), s -> s.equals(JobExecutionStatus.SUCCEEDED));
// Create a Job Doc with a faulty service (CustomerApp-0.9.0) requesting rollback on failure
CreateDeploymentRequest createDeploymentRequest = CreateDeploymentRequest.builder().deploymentPolicies(DeploymentPolicies.builder().configurationValidationPolicy(DeploymentConfigurationValidationPolicy.builder().timeoutInSeconds(120).build()).componentUpdatePolicy(DeploymentComponentUpdatePolicy.builder().action(SKIP_NOTIFY_COMPONENTS).timeoutInSeconds(120).build()).failureHandlingPolicy(ROLLBACK).build()).components(Utils.immutableMap("RedSignal", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").build(), "YellowSignal", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").build(), "CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("0.9.0").build())).build();
CreateDeploymentResponse createDeploymentResult = draftAndCreateDeployment(createDeploymentRequest);
String jobId2 = createDeploymentResult.iotJobId();
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, jobId2, thingInfo.getThingName(), Duration.ofMinutes(5), s -> s.equals(JobExecutionStatus.FAILED));
// Main should be INSTALLED state and CustomerApp should be stopped and removed
assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED)));
assertThat(getCloudDeployedComponent("RedSignal")::getState, eventuallyEval(is(State.FINISHED), Duration.ofSeconds(10L)));
assertThat(getCloudDeployedComponent("YellowSignal")::getState, eventuallyEval(is(State.FINISHED)));
assertThrows(ServiceLoadException.class, () -> getCloudDeployedComponent("CustomerApp").getState());
assertThrows(ServiceLoadException.class, () -> getCloudDeployedComponent("Mosquitto").getState());
assertThrows(ServiceLoadException.class, () -> getCloudDeployedComponent("GreenSignal").getState());
// IoT Job should have failed with correct message.
assertEquals(DeploymentResult.DeploymentStatus.FAILED_ROLLBACK_COMPLETE.name(), iotClient.describeJobExecution(DescribeJobExecutionRequest.builder().jobId(jobId2).thingName(thingInfo.getThingName()).build()).execution().statusDetails().detailsMap().get(DEPLOYMENT_DETAILED_STATUS_KEY));
}
Aggregations