Search in sources :

Example 1 with DeploymentConfigMerger

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);
}
Also used : ThingGroupHelper(com.aws.greengrass.deployment.ThingGroupHelper) DeploymentDocumentDownloader(com.aws.greengrass.deployment.DeploymentDocumentDownloader) DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) ComponentManager(com.aws.greengrass.componentmanager.ComponentManager) KernelConfigResolver(com.aws.greengrass.componentmanager.KernelConfigResolver) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) ComponentStore(com.aws.greengrass.componentmanager.ComponentStore) DependencyResolver(com.aws.greengrass.componentmanager.DependencyResolver) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with DeploymentConfigMerger

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) HashMap(java.util.HashMap) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with DeploymentConfigMerger

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());
}
Also used : HashMap(java.util.HashMap) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) URL(java.net.URL) LinkedList(java.util.LinkedList) ExpectedStateTransition(com.aws.greengrass.integrationtests.lifecyclemanager.KernelTest.ExpectedStateTransition) DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with DeploymentConfigMerger

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);
}
Also used : DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with DeploymentConfigMerger

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());
}
Also used : HashMap(java.util.HashMap) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) URL(java.net.URL) LinkedList(java.util.LinkedList) ExpectedStateTransition(com.aws.greengrass.integrationtests.lifecyclemanager.KernelTest.ExpectedStateTransition) DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

DeploymentConfigMerger (com.aws.greengrass.deployment.DeploymentConfigMerger)7 Kernel (com.aws.greengrass.lifecyclemanager.Kernel)6 HashMap (java.util.HashMap)4 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)3 ExpectedStateTransition (com.aws.greengrass.integrationtests.lifecyclemanager.KernelTest.ExpectedStateTransition)3 URL (java.net.URL)3 Test (org.junit.jupiter.api.Test)3 ComponentManager (com.aws.greengrass.componentmanager.ComponentManager)2 DependencyResolver (com.aws.greengrass.componentmanager.DependencyResolver)2 KernelConfigResolver (com.aws.greengrass.componentmanager.KernelConfigResolver)2 DeploymentDocumentDownloader (com.aws.greengrass.deployment.DeploymentDocumentDownloader)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ComponentStore (com.aws.greengrass.componentmanager.ComponentStore)1 DefaultDeploymentTask (com.aws.greengrass.deployment.DefaultDeploymentTask)1 ThingGroupHelper (com.aws.greengrass.deployment.ThingGroupHelper)1 Deployment (com.aws.greengrass.deployment.model.Deployment)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1