use of com.aws.greengrass.deployment.DeploymentConfigMerger in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method setupKernel.
@BeforeAll
static void setupKernel() throws IOException {
kernel = new Kernel();
rootDir = Paths.get(System.getProperty("root"));
NoOpPathOwnershipHandler.register(kernel);
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, DeploymentTaskIntegrationTest.class.getResource("onlyMain.yaml"));
kernel.launch();
// get required instances from context
componentManager = kernel.getContext().get(ComponentManager.class);
componentStore = kernel.getContext().get(ComponentStore.class);
dependencyResolver = kernel.getContext().get(DependencyResolver.class);
kernelConfigResolver = kernel.getContext().get(KernelConfigResolver.class);
deploymentConfigMerger = kernel.getContext().get(DeploymentConfigMerger.class);
deploymentDocumentDownloader = kernel.getContext().get(DeploymentDocumentDownloader.class);
thingGroupHelper = kernel.getContext().get(ThingGroupHelper.class);
}
use of com.aws.greengrass.deployment.DeploymentConfigMerger in project aws-greengrass-nucleus by aws-greengrass.
the class DynamicComponentConfigurationValidationTest method before.
@BeforeEach
void before(ExtensionContext context) throws Exception {
ignoreExceptionWithMessage(context, "Connection reset by peer");
socketOptions = TestUtils.getSocketOptionsForIPC();
kernel = new Kernel();
NoOpPathOwnershipHandler.register(kernel);
deploymentConfigMerger = kernel.getContext().get(DeploymentConfigMerger.class);
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, DynamicComponentConfigurationValidationTest.class.getResource("onlyMain.yaml"));
// launch kernel
Runnable mainFinished = createServiceStateChangeWaiter(kernel, "main", 10, State.FINISHED);
kernel.launch();
mainFinished.run();
// Start a new service
AtomicBoolean mainRestarted = new AtomicBoolean(false);
AtomicBoolean serviceStarted = new AtomicBoolean(false);
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals("main") && newState.equals(State.RUNNING) || newState.equals(State.FINISHED)) {
mainRestarted.set(true);
}
if (service.getName().equals("OldService") && newState.equals(State.RUNNING) && oldState.equals(State.STARTING)) {
serviceStarted.set(true);
}
});
List<String> serviceList = kernel.getMain().getDependencies().keySet().stream().map(GreengrassService::getName).collect(Collectors.toList());
serviceList.add("OldService");
Map<String, Object> newConfig = new HashMap<String, Object>() {
{
put(SERVICES_NAMESPACE_TOPIC, new HashMap<String, Object>() {
{
put("main", new HashMap<String, Object>() {
{
put(SERVICE_DEPENDENCIES_NAMESPACE_TOPIC, serviceList);
put(SERVICE_LIFECYCLE_NAMESPACE_TOPIC, kernel.getMain().getServiceConfig().lookupTopics(SERVICE_LIFECYCLE_NAMESPACE_TOPIC).toPOJO());
}
});
put(DEFAULT_NUCLEUS_COMPONENT_NAME, getNucleusConfig(kernel));
put("OldService", new HashMap<String, Object>() {
{
put(CONFIGURATION_CONFIG_KEY, new HashMap<String, Object>() {
{
put("ConfigKey1", "ConfigValue1");
}
});
put(SERVICE_LIFECYCLE_NAMESPACE_TOPIC, new HashMap<String, Object>() {
{
put(LIFECYCLE_RUN_NAMESPACE_TOPIC, "echo Running OldService");
}
});
put(VERSION_CONFIG_KEY, DEFAULT_EXISTING_SERVICE_VERSION);
}
});
}
});
}
};
deploymentConfigMerger.mergeInNewConfig(createTestDeployment(), newConfig).get(60, TimeUnit.SECONDS);
assertTrue(mainRestarted.get());
assertTrue(serviceStarted.get());
}
use of com.aws.greengrass.deployment.DeploymentConfigMerger in project aws-greengrass-nucleus by aws-greengrass.
the class ServiceDependencyLifecycleTest method GIVEN_hard_dependency_WHEN_dependency_goes_through_lifecycle_events_THEN_customer_app_is_impacted.
@Test
void GIVEN_hard_dependency_WHEN_dependency_goes_through_lifecycle_events_THEN_customer_app_is_impacted() throws Throwable {
// setup
kernel = new Kernel();
URL configFile = ServiceDependencyLifecycleTest.class.getResource("service_with_hard_dependency.yaml");
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, configFile);
// WHEN_kernel_launch_THEN_customer_app_starts_after_hard_dependency_is_running
LinkedList<ExpectedStateTransition> expectedDuringLaunch = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(HardDependency, State.INSTALLED, State.STARTING), new ExpectedStateTransition(HardDependency, State.STARTING, State.RUNNING), new ExpectedStateTransition(CustomerApp, State.INSTALLED, State.STARTING), new ExpectedStateTransition(CustomerApp, State.STARTING, State.RUNNING), new ExpectedStateTransition("main", State.STOPPING, State.FINISHED)));
testRoutine(TEST_ROUTINE_SHORT_TIMEOUT, kernel, kernel::launch, "kernel launched", expectedDuringLaunch, Collections.emptySet());
// WHEN_dependency_removed_THEN_customer_app_stays_running
LinkedList<ExpectedStateTransition> expectedDepRemoved = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(HardDependency, State.RUNNING, State.STOPPING)));
Set<ExpectedStateTransition> unexpectedDepRemoved = new HashSet<>(Arrays.asList(new ExpectedStateTransition(CustomerApp, State.RUNNING, State.STOPPING), new ExpectedStateTransition(CustomerApp, State.STOPPING, State.FINISHED)));
Map<String, Object> configRemoveDep = new HashMap<String, Object>() {
{
put(SERVICES_NAMESPACE_TOPIC, new HashMap<String, Object>() {
{
put("main", new HashMap<String, Object>() {
{
put(SERVICE_DEPENDENCIES_NAMESPACE_TOPIC, Arrays.asList(CustomerApp, DEFAULT_NUCLEUS_COMPONENT_NAME));
}
});
put(CustomerApp, new HashMap<String, Object>() {
{
putAll(kernel.findServiceTopic(CustomerApp).toPOJO());
put(SERVICE_DEPENDENCIES_NAMESPACE_TOPIC, Collections.emptyList());
}
});
put(DEFAULT_NUCLEUS_COMPONENT_NAME, new HashMap<String, Object>() {
{
putAll(kernel.findServiceTopic(DEFAULT_NUCLEUS_COMPONENT_NAME).toPOJO());
}
});
}
});
}
};
DeploymentConfigMerger configMerger = kernel.getContext().get(DeploymentConfigMerger.class);
DeploymentDocument doc1 = mock(DeploymentDocument.class);
when(doc1.getTimestamp()).thenReturn(System.currentTimeMillis());
when(doc1.getDeploymentId()).thenReturn("removeHardDep");
when(doc1.getFailureHandlingPolicy()).thenReturn(FailureHandlingPolicy.DO_NOTHING);
testRoutine(TEST_ROUTINE_LONG_TIMEOUT, kernel, () -> configMerger.mergeInNewConfig(createMockDeployment(doc1), configRemoveDep).get(60, TimeUnit.SECONDS), "dependency removed", expectedDepRemoved, unexpectedDepRemoved);
// WHEN_dependency_added_THEN_customer_app_restarts
LinkedList<ExpectedStateTransition> expectedDepAdded = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(CustomerApp, State.RUNNING, State.STOPPING), new ExpectedStateTransition(CustomerApp, State.STARTING, State.RUNNING)));
Map<String, Object> configAddDep = ConfigPlatformResolver.resolvePlatformMap(configFile);
DeploymentDocument doc2 = mock(DeploymentDocument.class);
when(doc2.getTimestamp()).thenReturn(System.currentTimeMillis());
when(doc2.getDeploymentId()).thenReturn("addHardDep");
when(doc2.getFailureHandlingPolicy()).thenReturn(FailureHandlingPolicy.DO_NOTHING);
testRoutine(60, kernel, () -> configMerger.mergeInNewConfig(createMockDeployment(doc2), configAddDep).get(10, TimeUnit.SECONDS), "dependency added", expectedDepAdded, Collections.emptySet());
// WHEN_dependency_errored_THEN_customer_app_restarts
LinkedList<ExpectedStateTransition> expectedDuringDepError = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(HardDependency, State.RUNNING, State.ERRORED), new ExpectedStateTransition(CustomerApp, State.RUNNING, State.STOPPING), new ExpectedStateTransition(CustomerApp, State.STARTING, State.RUNNING)));
testRoutine(TEST_ROUTINE_SHORT_TIMEOUT, kernel, () -> kernel.locate(HardDependency).serviceErrored("mock dependency error"), "dependency errored", expectedDuringDepError, Collections.emptySet());
// WHEN_dependency_stops_THEN_customer_app_stays_running
LinkedList<ExpectedStateTransition> expectedDepFinish = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(HardDependency, State.STOPPING, State.FINISHED)));
Set<ExpectedStateTransition> unexpectedDepFinish = new HashSet<>(Arrays.asList(new ExpectedStateTransition(CustomerApp, State.RUNNING, State.STOPPING), new ExpectedStateTransition(CustomerApp, State.STOPPING, State.FINISHED)));
testRoutine(TEST_ROUTINE_MEDIUM_TIMEOUT, kernel, () -> kernel.locate(HardDependency).requestStop(), "dependency stop", expectedDepFinish, unexpectedDepFinish);
// WHEN_dependency_restarts_THEN_customer_app_restarts
LinkedList<ExpectedStateTransition> expectedDepRestart = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(HardDependency, State.STARTING, State.RUNNING), new ExpectedStateTransition(CustomerApp, State.STARTING, State.RUNNING)));
testRoutine(TEST_ROUTINE_SHORT_TIMEOUT, kernel, () -> kernel.locate(HardDependency).requestRestart(), "dependency restart", expectedDepRestart, Collections.emptySet());
// WHEN_dependency_reinstalled_THEN_customer_app_restarts
LinkedList<ExpectedStateTransition> expectedDepReinstall = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(HardDependency, State.NEW, State.INSTALLED), new ExpectedStateTransition(HardDependency, State.STARTING, State.RUNNING), new ExpectedStateTransition(CustomerApp, State.STARTING, State.RUNNING)));
testRoutine(TEST_ROUTINE_SHORT_TIMEOUT, kernel, () -> kernel.locate(HardDependency).requestReinstall(), "dependency reinstall", expectedDepReinstall, Collections.emptySet());
// WHEN_kernel_shutdown_THEN_hard_dependency_waits_for_customer_app_to_close
LinkedList<ExpectedStateTransition> expectedDuringShutdown = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(CustomerApp, State.STOPPING, State.FINISHED), new ExpectedStateTransition(HardDependency, State.STOPPING, State.FINISHED)));
testRoutine(TEST_ROUTINE_SHORT_TIMEOUT, kernel, kernel::shutdown, "kernel shutdown", expectedDuringShutdown, Collections.emptySet());
}
use of com.aws.greengrass.deployment.DeploymentConfigMerger in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentConfigMergingTest method before.
@BeforeEach
void before() {
kernel = new Kernel();
NoOpPathOwnershipHandler.register(kernel);
deploymentConfigMerger = kernel.getContext().get(DeploymentConfigMerger.class);
}
use of com.aws.greengrass.deployment.DeploymentConfigMerger in project aws-greengrass-nucleus by aws-greengrass.
the class ServiceDependencyLifecycleTest method GIVEN_soft_dependency_WHEN_dependency_goes_through_lifecycle_events_THEN_customer_app_is_not_impacted.
@Test
void GIVEN_soft_dependency_WHEN_dependency_goes_through_lifecycle_events_THEN_customer_app_is_not_impacted() throws Throwable {
// setup
kernel = new Kernel();
URL configFile = ServiceDependencyLifecycleTest.class.getResource("service_with_soft_dependency.yaml");
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, configFile);
Set<ExpectedStateTransition> unexpectedDuringAllSoftDepChange = new HashSet<>(Arrays.asList(new ExpectedStateTransition(CustomerApp, State.RUNNING, State.STOPPING), new ExpectedStateTransition(CustomerApp, State.STOPPING, State.FINISHED)));
HashSet<ExpectedStateTransition> expectedStateTransitions = new HashSet<>(Arrays.asList(new ExpectedStateTransition(CustomerApp, State.NEW, State.INSTALLED), new ExpectedStateTransition(CustomerApp, State.INSTALLED, State.STARTING), new ExpectedStateTransition(SoftDependency, State.INSTALLED, State.STARTING), new ExpectedStateTransition(SoftDependency, State.STARTING, State.RUNNING), new ExpectedStateTransition(CustomerApp, State.STARTING, State.RUNNING)));
testStateTransitionsInNoOrder(TEST_ROUTINE_SHORT_TIMEOUT, kernel, kernel::launch, "kernel launch", expectedStateTransitions);
// WHEN_dependency_removed_THEN_customer_app_stays_running
LinkedList<ExpectedStateTransition> expectedDepRemoved = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(SoftDependency, State.RUNNING, State.STOPPING)));
Map<String, Object> configRemoveDep = new HashMap<String, Object>() {
{
put(SERVICES_NAMESPACE_TOPIC, new HashMap<String, Object>() {
{
put("main", new HashMap<String, Object>() {
{
put(SERVICE_DEPENDENCIES_NAMESPACE_TOPIC, Arrays.asList(CustomerApp, DEFAULT_NUCLEUS_COMPONENT_NAME));
}
});
put(CustomerApp, new HashMap<String, Object>() {
{
putAll(kernel.findServiceTopic(CustomerApp).toPOJO());
put(SERVICE_DEPENDENCIES_NAMESPACE_TOPIC, Collections.emptyList());
}
});
put(DEFAULT_NUCLEUS_COMPONENT_NAME, new HashMap<String, Object>() {
{
putAll(kernel.findServiceTopic(DEFAULT_NUCLEUS_COMPONENT_NAME).toPOJO());
}
});
}
});
}
};
DeploymentConfigMerger configMerger = kernel.getContext().get(DeploymentConfigMerger.class);
DeploymentDocument doc1 = mock(DeploymentDocument.class);
when(doc1.getTimestamp()).thenReturn(System.currentTimeMillis());
when(doc1.getDeploymentId()).thenReturn("removeSoftDep");
when(doc1.getFailureHandlingPolicy()).thenReturn(FailureHandlingPolicy.DO_NOTHING);
testRoutine(TEST_ROUTINE_MEDIUM_TIMEOUT, kernel, () -> configMerger.mergeInNewConfig(createMockDeployment(doc1), configRemoveDep).get(30, TimeUnit.SECONDS), "dependency removed", expectedDepRemoved, unexpectedDuringAllSoftDepChange);
// WHEN_dependency_added_THEN_customer_app_restarts
LinkedList<ExpectedStateTransition> expectedDepAdded = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(CustomerApp, State.RUNNING, State.STOPPING), new ExpectedStateTransition(SoftDependency, State.STARTING, State.RUNNING), new ExpectedStateTransition(CustomerApp, State.STARTING, State.RUNNING)));
Map<String, Object> configAddDep = ConfigPlatformResolver.resolvePlatformMap(configFile);
DeploymentDocument doc2 = mock(DeploymentDocument.class);
when(doc2.getTimestamp()).thenReturn(System.currentTimeMillis());
when(doc2.getDeploymentId()).thenReturn("addSoftDep");
when(doc2.getFailureHandlingPolicy()).thenReturn(FailureHandlingPolicy.DO_NOTHING);
testRoutine(TEST_ROUTINE_LONG_TIMEOUT, kernel, () -> configMerger.mergeInNewConfig(createMockDeployment(doc2), configAddDep).get(60, TimeUnit.SECONDS), "dependency added", expectedDepAdded, Collections.emptySet());
// WHEN_dependency_errored_THEN_customer_app_stays_running
LinkedList<ExpectedStateTransition> expectedDuringDepError = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(SoftDependency, State.RUNNING, State.ERRORED), new ExpectedStateTransition(SoftDependency, State.STARTING, State.RUNNING)));
testRoutine(TEST_ROUTINE_LONG_TIMEOUT, kernel, () -> kernel.locate(SoftDependency).serviceErrored("mock dependency error"), "dependency errored", expectedDuringDepError, unexpectedDuringAllSoftDepChange);
// WHEN_dependency_stops_THEN_customer_app_stays_running
LinkedList<ExpectedStateTransition> expectedDepFinish = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(SoftDependency, State.STOPPING, State.FINISHED)));
testRoutine(TEST_ROUTINE_MEDIUM_TIMEOUT, kernel, () -> kernel.locate(SoftDependency).requestStop(), "dependency " + "stop", expectedDepFinish, unexpectedDuringAllSoftDepChange);
// WHEN_dependency_restarts_THEN_customer_app_stays_running
LinkedList<ExpectedStateTransition> expectedDepRestart = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(SoftDependency, State.STARTING, State.RUNNING)));
testRoutine(TEST_ROUTINE_MEDIUM_TIMEOUT, kernel, () -> kernel.locate(SoftDependency).requestRestart(), "dependency restart", expectedDepRestart, unexpectedDuringAllSoftDepChange);
// WHEN_dependency_reinstalled_THEN_customer_app_stays_running
LinkedList<ExpectedStateTransition> expectedDepReinstall = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(SoftDependency, State.NEW, State.INSTALLED), new ExpectedStateTransition(SoftDependency, State.STARTING, State.RUNNING)));
testRoutine(TEST_ROUTINE_MEDIUM_TIMEOUT, kernel, () -> kernel.locate(SoftDependency).requestReinstall(), "dependency reinstall", expectedDepReinstall, unexpectedDuringAllSoftDepChange);
// WHEN_kernel_shutdown_THEN_soft_dependency_does_not_wait_for_customer_app_to_close
LinkedList<ExpectedStateTransition> expectedDuringShutdown = new LinkedList<>(Arrays.asList(new ExpectedStateTransition(SoftDependency, State.STOPPING, State.FINISHED), new ExpectedStateTransition(CustomerApp, State.STOPPING, State.FINISHED)));
testRoutine(TEST_ROUTINE_MEDIUM_TIMEOUT, kernel, () -> kernel.shutdown(60), "kernel shutdown", expectedDuringShutdown, Collections.emptySet());
}
Aggregations