Search in sources :

Example 1 with Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel 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 Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel 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());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Matchers.not(org.hamcrest.Matchers.not) GROUP_TO_ROOT_COMPONENTS_TOPICS(com.aws.greengrass.deployment.DeploymentService.GROUP_TO_ROOT_COMPONENTS_TOPICS) ComponentUpdatePolicyEvents(software.amazon.awssdk.aws.greengrass.model.ComponentUpdatePolicyEvents) SubscribeToComponentUpdatesResponse(software.amazon.awssdk.aws.greengrass.model.SubscribeToComponentUpdatesResponse) AfterAll(org.junit.jupiter.api.AfterAll) IPCTestUtils(com.aws.greengrass.integrationtests.ipc.IPCTestUtils) Future(java.util.concurrent.Future) BeforeAll(org.junit.jupiter.api.BeforeAll) GenericExternalService(com.aws.greengrass.lifecyclemanager.GenericExternalService) Duration(java.time.Duration) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) LogManager(com.aws.greengrass.logging.impl.LogManager) StreamResponseHandler(software.amazon.awssdk.eventstreamrpc.StreamResponseHandler) Path(java.nio.file.Path) DependencyResolver(com.aws.greengrass.componentmanager.DependencyResolver) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) GreengrassCoreIPCClient(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient) Set(java.util.Set) Utils.copyFolderRecursively(com.aws.greengrass.util.Utils.copyFolderRecursively) ExceptionLogProtector.ignoreExceptionOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionOfType) DeferComponentUpdateRequest(software.amazon.awssdk.aws.greengrass.model.DeferComponentUpdateRequest) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) CountDownLatch(java.util.concurrent.CountDownLatch) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Matchers.is(org.hamcrest.Matchers.is) DeploymentService(com.aws.greengrass.deployment.DeploymentService) Matchers.containsString(org.hamcrest.Matchers.containsString) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) PreloadComponentStoreHelper(com.aws.greengrass.helper.PreloadComponentStoreHelper) POSIX_USER_KEY(com.aws.greengrass.lifecyclemanager.GreengrassService.POSIX_USER_KEY) DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) SYSTEM_RESOURCE_LIMITS_TOPICS(com.aws.greengrass.lifecyclemanager.GreengrassService.SYSTEM_RESOURCE_LIMITS_TOPICS) GROUP_TO_ROOT_COMPONENTS_VERSION_KEY(com.aws.greengrass.deployment.DeploymentService.GROUP_TO_ROOT_COMPONENTS_VERSION_KEY) FileMatchers.anExistingDirectory(org.hamcrest.io.FileMatchers.anExistingDirectory) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Coerce(com.aws.greengrass.util.Coerce) WINDOWS_USER_KEY(com.aws.greengrass.lifecyclemanager.GreengrassService.WINDOWS_USER_KEY) ComponentManager(com.aws.greengrass.componentmanager.ComponentManager) SudoUtil.assumeCanSudoShell(com.aws.greengrass.testcommons.testutilities.SudoUtil.assumeCanSudoShell) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) ServiceLoadException(com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Files(java.nio.file.Files) IOException(java.io.IOException) File(java.io.File) AfterEach(org.junit.jupiter.api.AfterEach) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Paths(java.nio.file.Paths) ServiceUpdateException(com.aws.greengrass.deployment.exceptions.ServiceUpdateException) KernelConfigResolver(com.aws.greengrass.componentmanager.KernelConfigResolver) GreengrassLogMessage(com.aws.greengrass.logging.impl.GreengrassLogMessage) IsMapWithSize(org.hamcrest.collection.IsMapWithSize) Logger(com.aws.greengrass.logging.api.Logger) PackageLoadingException(com.aws.greengrass.componentmanager.exceptions.PackageLoadingException) SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) URISyntaxException(java.net.URISyntaxException) Deployment(com.aws.greengrass.deployment.model.Deployment) Order(org.junit.jupiter.api.Order) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) DEFAULT_NUCLEUS_COMPONENT_NAME(com.aws.greengrass.deployment.DeviceConfiguration.DEFAULT_NUCLEUS_COMPONENT_NAME) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) State(com.aws.greengrass.dependency.State) BaseITCase(com.aws.greengrass.integrationtests.BaseITCase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DEFAULT(com.aws.greengrass.deployment.model.Deployment.DeploymentStage.DEFAULT) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) URI(java.net.URI) TestUtils(com.aws.greengrass.testcommons.testutilities.TestUtils) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Topics(com.aws.greengrass.config.Topics) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) DeploymentDocumentDownloader(com.aws.greengrass.deployment.DeploymentDocumentDownloader) Optional(java.util.Optional) ComponentStore(com.aws.greengrass.componentmanager.ComponentStore) DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) ConfigPlatformResolver(com.aws.greengrass.integrationtests.util.ConfigPlatformResolver) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ThingGroupHelper(com.aws.greengrass.deployment.ThingGroupHelper) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) Semver(com.vdurmont.semver4j.Semver) PackageDownloadException(com.aws.greengrass.componentmanager.exceptions.PackageDownloadException) PlatformResolver(com.aws.greengrass.config.PlatformResolver) ExecutorService(java.util.concurrent.ExecutorService) RUN_WITH_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.RUN_WITH_NAMESPACE_TOPIC) ImmutableMap(software.amazon.awssdk.utils.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Matchers(org.hamcrest.Matchers) ExceptionLogProtector.ignoreExceptionUltimateCauseOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseOfType) EventStreamRPCConnection(software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection) SubscribeToComponentUpdatesRequest(software.amazon.awssdk.aws.greengrass.model.SubscribeToComponentUpdatesRequest) FileMatchers.anExistingFile(org.hamcrest.io.FileMatchers.anExistingFile) MethodOrderer(org.junit.jupiter.api.MethodOrderer) IsMapContaining(org.hamcrest.collection.IsMapContaining) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Slf4jLogAdapter(com.aws.greengrass.logging.impl.Slf4jLogAdapter) Utils(com.aws.greengrass.util.Utils) NoOpPathOwnershipHandler(com.aws.greengrass.testcommons.testutilities.NoOpPathOwnershipHandler) DefaultDeploymentTask(com.aws.greengrass.deployment.DefaultDeploymentTask) Collections(java.util.Collections) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) GenericExternalService(com.aws.greengrass.lifecyclemanager.GenericExternalService) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Test(org.junit.jupiter.api.Test)

Example 3 with Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel 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 4 with Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel 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");
    }
}
Also used : TestUtils.createCloseableLogListener(com.aws.greengrass.testcommons.testutilities.TestUtils.createCloseableLogListener) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) Deployment(com.aws.greengrass.deployment.model.Deployment) TimeoutException(java.util.concurrent.TimeoutException) Matchers.containsInRelativeOrder(org.hamcrest.Matchers.containsInRelativeOrder) ComponentUpdatePolicyEvents(software.amazon.awssdk.aws.greengrass.model.ComponentUpdatePolicyEvents) SubscribeToComponentUpdatesResponse(software.amazon.awssdk.aws.greengrass.model.SubscribeToComponentUpdatesResponse) AfterAll(org.junit.jupiter.api.AfterAll) DEFAULT_NUCLEUS_COMPONENT_NAME(com.aws.greengrass.deployment.DeviceConfiguration.DEFAULT_NUCLEUS_COMPONENT_NAME) IPCTestUtils(com.aws.greengrass.integrationtests.ipc.IPCTestUtils) Future(java.util.concurrent.Future) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) State(com.aws.greengrass.dependency.State) BaseITCase(com.aws.greengrass.integrationtests.BaseITCase) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GenericExternalService(com.aws.greengrass.lifecyclemanager.GenericExternalService) FleetStatusService(com.aws.greengrass.status.FleetStatusService) DEFAULT(com.aws.greengrass.deployment.model.Deployment.DeploymentStage.DEFAULT) Duration(java.time.Duration) Map(java.util.Map) LogManager(com.aws.greengrass.logging.impl.LogManager) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) StreamResponseHandler(software.amazon.awssdk.eventstreamrpc.StreamResponseHandler) ComponentUpdatePolicy(com.aws.greengrass.deployment.model.ComponentUpdatePolicy) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GreengrassCoreIPCClient(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient) TestUtils(com.aws.greengrass.testcommons.testutilities.TestUtils) EventuallyLambdaMatcher.eventuallyEval(com.github.grantwest.eventually.EventuallyLambdaMatcher.eventuallyEval) Collectors(java.util.stream.Collectors) DeferComponentUpdateRequest(software.amazon.awssdk.aws.greengrass.model.DeferComponentUpdateRequest) TestUtils.createServiceStateChangeWaiter(com.aws.greengrass.testcommons.testutilities.TestUtils.createServiceStateChangeWaiter) Test(org.junit.jupiter.api.Test) Topics(com.aws.greengrass.config.Topics) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) GlobalStateChangeListener(com.aws.greengrass.lifecyclemanager.GlobalStateChangeListener) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) LIFECYCLE_RUN_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GenericExternalService.LIFECYCLE_RUN_NAMESPACE_TOPIC) Matchers.is(org.hamcrest.Matchers.is) DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConfigPlatformResolver(com.aws.greengrass.integrationtests.util.ConfigPlatformResolver) DeploymentConfigurationValidationPolicy(software.amazon.awssdk.services.greengrassv2.model.DeploymentConfigurationValidationPolicy) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Coerce(com.aws.greengrass.util.Coerce) SKIP_NOTIFY_COMPONENTS(software.amazon.awssdk.services.greengrassv2.model.DeploymentComponentUpdatePolicyAction.SKIP_NOTIFY_COMPONENTS) ArrayList(java.util.ArrayList) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) SudoUtil.assumeCanSudoShell(com.aws.greengrass.testcommons.testutilities.SudoUtil.assumeCanSudoShell) GGExtension(com.aws.greengrass.testcommons.testutilities.GGExtension) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PlatformResolver(com.aws.greengrass.config.PlatformResolver) ServiceLoadException(com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException) SystemUtils(org.apache.commons.lang3.SystemUtils) Matchers(org.hamcrest.Matchers) EventStreamRPCConnection(software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection) IOException(java.io.IOException) NOTIFY_COMPONENTS(software.amazon.awssdk.services.greengrassv2.model.DeploymentComponentUpdatePolicyAction.NOTIFY_COMPONENTS) SubscribeToComponentUpdatesRequest(software.amazon.awssdk.aws.greengrass.model.SubscribeToComponentUpdatesRequest) SUCCESSFUL(com.aws.greengrass.deployment.model.DeploymentResult.DeploymentStatus.SUCCESSFUL) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Topic(com.aws.greengrass.config.Topic) AfterEach(org.junit.jupiter.api.AfterEach) Matchers.hasItem(org.hamcrest.Matchers.hasItem) WhatHappened(com.aws.greengrass.config.WhatHappened) NoOpPathOwnershipHandler(com.aws.greengrass.testcommons.testutilities.NoOpPathOwnershipHandler) FailureHandlingPolicy(com.aws.greengrass.deployment.model.FailureHandlingPolicy) GreengrassLogMessage(com.aws.greengrass.logging.impl.GreengrassLogMessage) Logger(com.aws.greengrass.logging.api.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GreengrassLogMessage(com.aws.greengrass.logging.impl.GreengrassLogMessage) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 5 with Kernel

use of com.aws.greengrass.lifecyclemanager.Kernel 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");
    }
}
Also used : TestUtils.createCloseableLogListener(com.aws.greengrass.testcommons.testutilities.TestUtils.createCloseableLogListener) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) Deployment(com.aws.greengrass.deployment.model.Deployment) TimeoutException(java.util.concurrent.TimeoutException) Matchers.containsInRelativeOrder(org.hamcrest.Matchers.containsInRelativeOrder) ComponentUpdatePolicyEvents(software.amazon.awssdk.aws.greengrass.model.ComponentUpdatePolicyEvents) SubscribeToComponentUpdatesResponse(software.amazon.awssdk.aws.greengrass.model.SubscribeToComponentUpdatesResponse) AfterAll(org.junit.jupiter.api.AfterAll) DEFAULT_NUCLEUS_COMPONENT_NAME(com.aws.greengrass.deployment.DeviceConfiguration.DEFAULT_NUCLEUS_COMPONENT_NAME) IPCTestUtils(com.aws.greengrass.integrationtests.ipc.IPCTestUtils) Future(java.util.concurrent.Future) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) State(com.aws.greengrass.dependency.State) BaseITCase(com.aws.greengrass.integrationtests.BaseITCase) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GenericExternalService(com.aws.greengrass.lifecyclemanager.GenericExternalService) FleetStatusService(com.aws.greengrass.status.FleetStatusService) DEFAULT(com.aws.greengrass.deployment.model.Deployment.DeploymentStage.DEFAULT) Duration(java.time.Duration) Map(java.util.Map) LogManager(com.aws.greengrass.logging.impl.LogManager) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) StreamResponseHandler(software.amazon.awssdk.eventstreamrpc.StreamResponseHandler) ComponentUpdatePolicy(com.aws.greengrass.deployment.model.ComponentUpdatePolicy) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GreengrassCoreIPCClient(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient) TestUtils(com.aws.greengrass.testcommons.testutilities.TestUtils) EventuallyLambdaMatcher.eventuallyEval(com.github.grantwest.eventually.EventuallyLambdaMatcher.eventuallyEval) Collectors(java.util.stream.Collectors) DeferComponentUpdateRequest(software.amazon.awssdk.aws.greengrass.model.DeferComponentUpdateRequest) TestUtils.createServiceStateChangeWaiter(com.aws.greengrass.testcommons.testutilities.TestUtils.createServiceStateChangeWaiter) Test(org.junit.jupiter.api.Test) Topics(com.aws.greengrass.config.Topics) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) GlobalStateChangeListener(com.aws.greengrass.lifecyclemanager.GlobalStateChangeListener) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) LIFECYCLE_RUN_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GenericExternalService.LIFECYCLE_RUN_NAMESPACE_TOPIC) Matchers.is(org.hamcrest.Matchers.is) DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConfigPlatformResolver(com.aws.greengrass.integrationtests.util.ConfigPlatformResolver) DeploymentConfigurationValidationPolicy(software.amazon.awssdk.services.greengrassv2.model.DeploymentConfigurationValidationPolicy) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Coerce(com.aws.greengrass.util.Coerce) SKIP_NOTIFY_COMPONENTS(software.amazon.awssdk.services.greengrassv2.model.DeploymentComponentUpdatePolicyAction.SKIP_NOTIFY_COMPONENTS) ArrayList(java.util.ArrayList) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) SudoUtil.assumeCanSudoShell(com.aws.greengrass.testcommons.testutilities.SudoUtil.assumeCanSudoShell) GGExtension(com.aws.greengrass.testcommons.testutilities.GGExtension) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PlatformResolver(com.aws.greengrass.config.PlatformResolver) ServiceLoadException(com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException) SystemUtils(org.apache.commons.lang3.SystemUtils) Matchers(org.hamcrest.Matchers) EventStreamRPCConnection(software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection) IOException(java.io.IOException) NOTIFY_COMPONENTS(software.amazon.awssdk.services.greengrassv2.model.DeploymentComponentUpdatePolicyAction.NOTIFY_COMPONENTS) SubscribeToComponentUpdatesRequest(software.amazon.awssdk.aws.greengrass.model.SubscribeToComponentUpdatesRequest) SUCCESSFUL(com.aws.greengrass.deployment.model.DeploymentResult.DeploymentStatus.SUCCESSFUL) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Topic(com.aws.greengrass.config.Topic) AfterEach(org.junit.jupiter.api.AfterEach) Matchers.hasItem(org.hamcrest.Matchers.hasItem) WhatHappened(com.aws.greengrass.config.WhatHappened) NoOpPathOwnershipHandler(com.aws.greengrass.testcommons.testutilities.NoOpPathOwnershipHandler) FailureHandlingPolicy(com.aws.greengrass.deployment.model.FailureHandlingPolicy) GreengrassLogMessage(com.aws.greengrass.logging.impl.GreengrassLogMessage) Logger(com.aws.greengrass.logging.api.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GreengrassLogMessage(com.aws.greengrass.logging.impl.GreengrassLogMessage) HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

Kernel (com.aws.greengrass.lifecyclemanager.Kernel)49 CountDownLatch (java.util.concurrent.CountDownLatch)22 BeforeEach (org.junit.jupiter.api.BeforeEach)22 Test (org.junit.jupiter.api.Test)22 HashMap (java.util.HashMap)13 IOException (java.io.IOException)12 DeploymentConfigMerger (com.aws.greengrass.deployment.DeploymentConfigMerger)11 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)11 Map (java.util.Map)11 List (java.util.List)10 TimeUnit (java.util.concurrent.TimeUnit)10 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)10 State (com.aws.greengrass.dependency.State)9 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)9 BaseITCase (com.aws.greengrass.integrationtests.BaseITCase)9 ConfigPlatformResolver (com.aws.greengrass.integrationtests.util.ConfigPlatformResolver)9 TestUtils (com.aws.greengrass.testcommons.testutilities.TestUtils)9 Coerce (com.aws.greengrass.util.Coerce)9 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 LogManager (com.aws.greengrass.logging.impl.LogManager)8