use of com.aws.greengrass.deployment.model.Deployment in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method GIVEN_a_deployment_has_component_use_system_config_WHEN_submitted_THEN_system_configs_are_interpolated.
@Test
@Order(7)
void GIVEN_a_deployment_has_component_use_system_config_WHEN_submitted_THEN_system_configs_are_interpolated() throws Exception {
CountDownLatch stdoutLatch = new CountDownLatch(1);
// Set up stdout listener to capture stdout for verify #2 interpolation
List<String> stdouts = new CopyOnWriteArrayList<>();
Consumer<GreengrassLogMessage> listener = m -> {
String messageOnStdout = m.getMessage();
if (messageOnStdout != null && messageOnStdout.contains("aws.iot.gg.test.integ.SystemConfigTest output")) {
stdouts.add(messageOnStdout);
stdoutLatch.countDown();
}
};
Slf4jLogAdapter.addGlobalListener(listener);
try {
/*
* 1st deployment. Default Config.
*/
Future<DeploymentResult> resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("SystemConfigTest_DeployDocument.json").toURI(), System.currentTimeMillis());
resultFuture.get(10, TimeUnit.SECONDS);
// The main comes from SystemConfigTest_DeployDocument.json
String mainComponentName = "aws.iot.gg.test.integ.SystemConfigTest";
String mainComponentNameVer = "0.0.1";
// The dependency is specified in aws.iot.gg.test.integ.SystemConfigTest-0.1.1
String otherComponentName = "GreenSignal";
String otherComponentVer = "1.0.0";
assertThat("has output", stdoutLatch.await(STDOUT_TIMEOUT, TimeUnit.SECONDS), is(true));
// verify interpolation result
assertThat(stdouts.get(0), containsString("I'm kernel's root path: " + rootDir.toAbsolutePath()));
assertThat(stdouts.get(0), containsString("I'm my own artifact path: " + rootDir.resolve("packages").resolve(ComponentStore.ARTIFACT_DIRECTORY).resolve(mainComponentName).resolve(mainComponentNameVer).toAbsolutePath()));
assertTrue(stdouts.get(0).contains("I'm my own artifact decompressed path: " + rootDir.resolve("packages").resolve(ComponentStore.ARTIFACTS_DECOMPRESSED_DIRECTORY).resolve(mainComponentName).resolve(mainComponentNameVer).toAbsolutePath()));
assertThat(stdouts.get(0), containsString("I'm GreenSignal's artifact path: " + rootDir.resolve("packages").resolve(ComponentStore.ARTIFACT_DIRECTORY).resolve(otherComponentName).resolve(otherComponentVer).toAbsolutePath()));
assertThat(stdouts.get(0), containsString("I'm GreenSignal's artifact decompressed path: " + rootDir.resolve("packages").resolve(ComponentStore.ARTIFACTS_DECOMPRESSED_DIRECTORY).resolve(otherComponentName).resolve(otherComponentVer).toAbsolutePath()));
} finally {
Slf4jLogAdapter.removeGlobalListener(listener);
}
}
use of com.aws.greengrass.deployment.model.Deployment in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method GIVEN_services_running_WHEN_new_service_breaks_failure_handling_policy_do_nothing_THEN_service_stays_broken.
/**
* First deployment starts some services. Second deployment tries to add a service that breaks and removes an
* existing service but the failure handling policy is to do nothing As a result, no corrective action will be taken
* on failure
*
* @throws Exception
*/
@Test
@Order(10)
void GIVEN_services_running_WHEN_new_service_breaks_failure_handling_policy_do_nothing_THEN_service_stays_broken(ExtensionContext context) throws Exception {
Future<DeploymentResult> resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("YellowAndRedSignal.json").toURI(), System.currentTimeMillis());
resultFuture.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
List<String> services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
// should contain main, Nucleus, YellowSignal and RedSignal
assertEquals(4, services.size());
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "YellowSignal", "RedSignal"));
groupToRootComponentsTopics.lookupTopics("RedSignal").replaceAndWait(ImmutableMap.of(GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0"));
groupToRootComponentsTopics.lookupTopics("YellowSignal").replaceAndWait(ImmutableMap.of(GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0"));
ignoreExceptionUltimateCauseOfType(context, ServiceUpdateException.class);
preloadLocalStoreContent();
resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("FailureDoNothingDeployment.json").toURI(), System.currentTimeMillis());
DeploymentResult result = resultFuture.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
// should contain main, Nucleus, RedSignal, BreakingService, Mosquitto and GreenSignal
assertEquals(6, services.size());
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "RedSignal", "BreakingService", "Mosquitto", "GreenSignal"));
assertEquals(State.BROKEN, kernel.locate("BreakingService").getState());
assertEquals(DeploymentResult.DeploymentStatus.FAILED_ROLLBACK_NOT_REQUESTED, result.getDeploymentStatus());
}
use of com.aws.greengrass.deployment.model.Deployment in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method GIVEN_a_deployment_with_dependency_has_config_WHEN_submitted_THEN_dependency_configs_are_interpolated.
@Test
@Order(5)
void GIVEN_a_deployment_with_dependency_has_config_WHEN_submitted_THEN_dependency_configs_are_interpolated() throws Exception {
// Set up stdout listener to capture stdout for verify #2 interpolation
countDownLatch = new CountDownLatch(1);
List<String> stdouts = new CopyOnWriteArrayList<>();
Consumer<GreengrassLogMessage> listener = m -> {
String messageOnStdout = m.getMessage();
if (messageOnStdout != null && messageOnStdout.contains("aws.iot.gg.test.integ.ComponentConfigTestMain output")) {
countDownLatch.countDown();
stdouts.add(messageOnStdout);
}
};
Slf4jLogAdapter.addGlobalListener(listener);
try {
/*
* 1st deployment. Default Config.
*/
Future<DeploymentResult> resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("CrossComponentConfigTest_DeployDocument.json").toURI(), System.currentTimeMillis());
resultFuture.get(10, TimeUnit.SECONDS);
// verify interpolation result
assertThat("The stdout should be captured within seconds.", countDownLatch.await(STDOUT_TIMEOUT, TimeUnit.SECONDS));
String stdout = stdouts.get(0);
assertThat(stdout, containsString("Value for /singleLevelKey: default value of singleLevelKey."));
assertThat(stdout, containsString("Value for /path/leafKey: default value of /path/leafKey."));
assertThat(stdout, containsString("Value for /listKey/0: item1."));
assertThat(stdout, containsString("Value for /emptyStringKey: ."));
} finally {
Slf4jLogAdapter.removeGlobalListener(listener);
}
}
use of com.aws.greengrass.deployment.model.Deployment in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method GIVEN_services_running_WHEN_new_service_breaks_failure_handling_policy_rollback_THEN_services_are_rolled_back.
/**
* First deployment starts some services. Second deployment tries to add a service that breaks and removes an
* existing service and the failure handling policy is to rollback As a result, kernel should be reverted to the
* state before deployment
*
* @throws Exception
*/
@Test
@Order(11)
void GIVEN_services_running_WHEN_new_service_breaks_failure_handling_policy_rollback_THEN_services_are_rolled_back(ExtensionContext context) throws Exception {
Map<String, Object> pkgDetails = new HashMap<>();
pkgDetails.put(GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0");
groupToRootComponentsTopics.lookupTopics("RedSignal").replaceAndWait(pkgDetails);
groupToRootComponentsTopics.lookupTopics("YellowSignal").replaceAndWait(pkgDetails);
Future<DeploymentResult> resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("YellowAndRedSignal.json").toURI(), System.currentTimeMillis());
resultFuture.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
List<String> services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
// should contain main, Nucleus, YellowSignal and RedSignal
assertEquals(4, services.size());
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "YellowSignal", "RedSignal"));
ignoreExceptionUltimateCauseOfType(context, ServiceUpdateException.class);
groupToRootComponentsTopics.lookupTopics("YellowSignal").remove();
groupToRootComponentsTopics.lookupTopics("BreakingService").replaceAndWait(ImmutableMap.of(GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0"));
preloadLocalStoreContent();
resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("FailureRollbackDeployment.json").toURI(), System.currentTimeMillis());
DeploymentResult result = resultFuture.get(60, TimeUnit.SECONDS);
services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
// should contain main, Nucleus, YellowSignal, RedSignal
assertEquals(4, services.size());
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "YellowSignal", "RedSignal"));
assertThrows(ServiceLoadException.class, () -> kernel.locate("BreakingService"));
assertThrows(ServiceLoadException.class, () -> kernel.locate("Mosquitto"));
assertThrows(ServiceLoadException.class, () -> kernel.locate("GreenSignal"));
assertEquals(DeploymentResult.DeploymentStatus.FAILED_ROLLBACK_COMPLETE, result.getDeploymentStatus());
}
use of com.aws.greengrass.deployment.model.Deployment in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method GIVEN_broken_service_WHEN_new_service_breaks_failure_handling_policy_rollback_THEN_services_are_rolled_back.
/**
* This test verifies that if a deployment has a broken service and then a new deployment comes which removes that
* one, but fails for a different reason and rolls back, then it is able to roll back successfully.
*/
@Test
@Order(12)
void GIVEN_broken_service_WHEN_new_service_breaks_failure_handling_policy_rollback_THEN_services_are_rolled_back(ExtensionContext context) throws Exception {
ignoreExceptionUltimateCauseOfType(context, ServiceUpdateException.class);
// Deploy a broken config with no rollback
Future<DeploymentResult> resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("FailureDoNothingDeployment.json").toURI(), System.currentTimeMillis());
resultFuture.get(60, TimeUnit.SECONDS);
List<String> services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "BreakingService", "RedSignal", "GreenSignal", "Mosquitto"));
// Deploy a new broken config (using a different service) which does rollback
preloadLocalStoreContent();
resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("Failure2RollbackDeployment.json").toURI(), System.currentTimeMillis());
DeploymentResult result = resultFuture.get(60, TimeUnit.SECONDS);
services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
// Make sure that it rolls back to the previous state
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "BreakingService", "RedSignal", "GreenSignal", "Mosquitto"));
assertEquals(DeploymentResult.DeploymentStatus.FAILED_ROLLBACK_COMPLETE, result.getDeploymentStatus());
}
Aggregations