use of com.aws.greengrass.logging.impl.GreengrassLogMessage 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.logging.impl.GreengrassLogMessage 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.logging.impl.GreengrassLogMessage in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentConfigMergingTest method GIVEN_kernel_running_single_service_WHEN_merge_changes_service_THEN_service_restarts_with_new_config.
@Test
void GIVEN_kernel_running_single_service_WHEN_merge_changes_service_THEN_service_restarts_with_new_config() throws Throwable {
// GIVEN
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, getClass().getResource("single_service.yaml"));
CountDownLatch mainRunning = new CountDownLatch(1);
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals("main") && newState.equals(State.RUNNING)) {
mainRunning.countDown();
}
});
AtomicBoolean safeUpdateRegistered = new AtomicBoolean();
Consumer<GreengrassLogMessage> listener = (m) -> {
if ("register-service-update-action".equals(m.getEventType())) {
safeUpdateRegistered.set(true);
}
};
try (AutoCloseable l = createCloseableLogListener(listener)) {
kernel.launch();
assertTrue(mainRunning.await(5, TimeUnit.SECONDS));
// WHEN
CountDownLatch mainRestarted = new CountDownLatch(1);
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals("main") && newState.equals(State.FINISHED) && oldState.equals(State.STARTING)) {
mainRestarted.countDown();
}
});
deploymentConfigMerger.mergeInNewConfig(testDeployment(), new HashMap<String, Object>() {
{
put(SERVICES_NAMESPACE_TOPIC, new HashMap<String, Object>() {
{
put("main", new HashMap<String, Object>() {
{
put(SETENV_CONFIG_NAMESPACE, new HashMap<String, Object>() {
{
put("HELLO", "redefined");
}
});
}
});
put(DEFAULT_NUCLEUS_COMPONENT_NAME, getNucleusConfig());
}
});
}
}).get(60, TimeUnit.SECONDS);
// THEN
assertTrue(mainRestarted.await(10, TimeUnit.SECONDS), "main restarted");
assertEquals("redefined", kernel.findServiceTopic("main").find(SETENV_CONFIG_NAMESPACE, "HELLO").getOnce());
assertTrue(safeUpdateRegistered.get(), "safe update registered");
}
}
use of com.aws.greengrass.logging.impl.GreengrassLogMessage in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentConfigMergingTest method GIVEN_kernel_running_single_service_WHEN_deployment_with_skip_safety_check_config_THEN_merge_without_checking_safety.
@Test
void GIVEN_kernel_running_single_service_WHEN_deployment_with_skip_safety_check_config_THEN_merge_without_checking_safety() throws Throwable {
// GIVEN
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, getClass().getResource("single_service.yaml"));
Runnable mainRunning = createServiceStateChangeWaiter(kernel, "main", 5, State.RUNNING);
kernel.launch();
mainRunning.run();
// WHEN
Runnable mainRestarted = createServiceStateChangeWaiter(kernel, "main", 10, State.FINISHED, State.STARTING);
AtomicBoolean safeUpdateSkipped = new AtomicBoolean();
Consumer<GreengrassLogMessage> listener = (m) -> {
if ("Deployment is configured to skip update policy check, not waiting for disruptable time to update".equals(m.getMessage())) {
safeUpdateSkipped.set(true);
}
};
try (AutoCloseable l = createCloseableLogListener(listener)) {
deploymentConfigMerger.mergeInNewConfig(testDeploymentWithSkipPolicyCheckConfig(), new HashMap<String, Object>() {
{
put(SERVICES_NAMESPACE_TOPIC, new HashMap<String, Object>() {
{
put("main", new HashMap<String, Object>() {
{
put(SETENV_CONFIG_NAMESPACE, new HashMap<String, Object>() {
{
put("HELLO", "redefined");
}
});
}
});
put(DEFAULT_NUCLEUS_COMPONENT_NAME, getNucleusConfig());
}
});
}
}).get(60, TimeUnit.SECONDS);
// THEN
mainRestarted.run();
assertEquals("redefined", kernel.findServiceTopic("main").find(SETENV_CONFIG_NAMESPACE, "HELLO").getOnce());
assertTrue(safeUpdateSkipped.get(), "safe updated skipped");
}
}
use of com.aws.greengrass.logging.impl.GreengrassLogMessage in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentServiceIntegrationTest method GIVEN_a_cloud_deployment_WHEN_receives_deployment_THEN_service_runs_and_deployment_succeeds.
@Test
void GIVEN_a_cloud_deployment_WHEN_receives_deployment_THEN_service_runs_and_deployment_succeeds() throws Exception {
CountDownLatch cdlDeployRedSignal = new CountDownLatch(1);
Consumer<GreengrassLogMessage> listener = m -> {
if (m.getMessage() != null) {
if (m.getMessage().contains("Current deployment finished") && m.getContexts().get("DeploymentId").equals("deployRedSignal")) {
cdlDeployRedSignal.countDown();
}
}
};
try (AutoCloseable l = TestUtils.createCloseableLogListener(listener)) {
CountDownLatch redSignalServiceLatch = new CountDownLatch(1);
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals("RedSignal") && newState.equals(State.RUNNING)) {
redSignalServiceLatch.countDown();
}
});
submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithRedSignalService.json").toURI(), "deployRedSignal", // DeploymentType.SHADOW is used here and it
DeploymentType.SHADOW);
// is same for DeploymentType.IOT_JOBS
assertTrue(redSignalServiceLatch.await(30, TimeUnit.SECONDS));
assertTrue(cdlDeployRedSignal.await(30, TimeUnit.SECONDS));
}
}
Aggregations