Search in sources :

Example 11 with Configuration

use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.

the class LifecycleTest method GIVEN_config_updated_THEN_service_is_restarted_with_new_config.

@Test
void GIVEN_config_updated_THEN_service_is_restarted_with_new_config() throws Exception {
    Configuration config = new Configuration(context);
    Topics testServiceTopics = config.getRoot().createInteriorChild(GreengrassService.SERVICES_NAMESPACE_TOPIC).createInteriorChild("testService");
    TestService testService = new TestService(testServiceTopics);
    testServiceTopics.subscribe((child, newVal) -> {
        testService.requestRestart();
    });
    String newConfigString = "{\n" + "    \"services\":{\n" + "      \"testService\": {\n" + "          \"lifecycle\": {\n" + "              \"startup\": {\n" + "                  \"timeout\": 7\n" + "              },\n" + "              \"shutdown\": {\n" + "                  \"timeout\": 8\n" + "              }\n" + "          },\n" + "          \"dependencies\": []" + "      }\n" + "    }\n" + "}";
    Map<String, Object> newConfig = objectMapper.readValue(newConfigString, Map.class);
    AtomicBoolean configUnderUpdate = new AtomicBoolean(false);
    CountDownLatch configUpdateFinished = new CountDownLatch(1);
    testService.setStartupRunnable(() -> {
        if (configUnderUpdate.get()) {
            assertEquals(newConfig, config.toPOJO());
            configUnderUpdate.set(false);
            configUpdateFinished.countDown();
        }
        testService.reportState(State.RUNNING);
    });
    // init lifecycle
    testService.postInject();
    testService.requestStart();
    assertThat(testService::getState, eventuallyEval(is(State.RUNNING)));
    // merge in new config
    configUnderUpdate.set(true);
    config.updateMap(newConfig, new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.MERGE, Integer.MAX_VALUE));
    assertTrue(configUpdateFinished.await(2, TimeUnit.SECONDS), "updated config:" + config.toPOJO().toString());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Topics(com.aws.greengrass.config.Topics) Configuration(com.aws.greengrass.config.Configuration) UpdateBehaviorTree(com.aws.greengrass.config.UpdateBehaviorTree) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 12 with Configuration

use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.

the class LogManagerHelperTest method loggers_created_before_or_after_log_level_change_get_the_correct_level.

@Test
void loggers_created_before_or_after_log_level_change_get_the_correct_level() throws IOException {
    try (Context context = new Context()) {
        Configuration config = new Configuration(context);
        Topics logTopics = config.lookupTopics(SERVICES_NAMESPACE_TOPIC, DEFAULT_NUCLEUS_COMPONENT_NAME, CONFIGURATION_CONFIG_KEY, NUCLEUS_CONFIG_LOGGING_TOPICS);
        when(kernel.getConfig()).thenReturn(config);
        lenient().when(kernel.getNucleusPaths()).thenReturn(mock(NucleusPaths.class));
        when(mockGreengrassService.getServiceName()).thenReturn("MockService3");
        Logger logger1 = LogManagerHelper.getComponentLogger(mockGreengrassService);
        assertFalse(logger1.isDebugEnabled());
        new DeviceConfiguration(kernel);
        context.runOnPublishQueueAndWait(() -> logTopics.updateFromMap(Utils.immutableMap("level", "DEBUG"), new UpdateBehaviorTree(UpdateBehaviorTree.UpdateBehavior.REPLACE, System.currentTimeMillis())));
        context.waitForPublishQueueToClear();
        when(mockGreengrassService.getServiceName()).thenReturn("MockService4");
        Logger logger2 = LogManagerHelper.getComponentLogger(mockGreengrassService);
        assertTrue(logger2.isDebugEnabled());
        assertTrue(logger1.isDebugEnabled());
    }
}
Also used : Context(com.aws.greengrass.dependency.Context) Topics(com.aws.greengrass.config.Topics) Configuration(com.aws.greengrass.config.Configuration) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) UpdateBehaviorTree(com.aws.greengrass.config.UpdateBehaviorTree) NucleusPaths(com.aws.greengrass.util.NucleusPaths) Logger(com.aws.greengrass.logging.api.Logger) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Test(org.junit.jupiter.api.Test)

Example 13 with Configuration

use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentStatusKeeperTest method setup.

@BeforeEach
void setup() {
    context = new Context();
    Configuration config = new Configuration(context);
    when(deploymentService.getRuntimeConfig()).thenReturn(config.lookupTopics(GreengrassService.SERVICES_NAMESPACE_TOPIC, DeploymentService.DEPLOYMENT_SERVICE_TOPICS, GreengrassService.RUNTIME_STORE_NAMESPACE_TOPIC));
    deploymentStatusKeeper = new DeploymentStatusKeeper();
    deploymentStatusKeeper.setDeploymentService(deploymentService);
    processedDeployments = deploymentStatusKeeper.getProcessedDeployments();
}
Also used : Context(com.aws.greengrass.dependency.Context) Configuration(com.aws.greengrass.config.Configuration) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with Configuration

use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.

the class MergeTest method testSomeMethod.

@Test
void testSomeMethod() throws Exception {
    try (Context context = new Context()) {
        Configuration c = new Configuration(context);
        c.read(Kernel.class.getResource("config.yaml"), false);
        Configuration b = new Configuration(context).copyFrom(c);
        assertEquals(c.getRoot(), b.getRoot());
    }
}
Also used : Context(com.aws.greengrass.dependency.Context) Configuration(com.aws.greengrass.config.Configuration) Test(org.junit.jupiter.api.Test)

Example 15 with Configuration

use of com.aws.greengrass.config.Configuration in project aws-greengrass-nucleus by aws-greengrass.

the class KernelConfigResolverTest method setupMocks.

@BeforeEach
void setupMocks() throws IOException {
    path = Paths.get("Artifacts", TEST_INPUT_PACKAGE_A);
    lenient().when(nucleusPaths.artifactPath(any())).thenReturn(path.toAbsolutePath());
    config = new Configuration(new Context());
    lenient().when(kernel.getConfig()).thenReturn(config);
    lenient().when(deviceConfiguration.getNucleusComponentName()).thenReturn(DEFAULT_NUCLEUS_COMPONENT_NAME);
    lenient().when(deviceConfiguration.getThingName()).thenReturn(config.lookup("thingname").withValue(THE_THINGNAME));
}
Also used : Context(com.aws.greengrass.dependency.Context) DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) Configuration(com.aws.greengrass.config.Configuration) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) ComponentConfiguration(com.amazon.aws.iot.greengrass.component.common.ComponentConfiguration) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Configuration (com.aws.greengrass.config.Configuration)20 Context (com.aws.greengrass.dependency.Context)12 Topics (com.aws.greengrass.config.Topics)8 Test (org.junit.jupiter.api.Test)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 Topic (com.aws.greengrass.config.Topic)3 UpdateBehaviorTree (com.aws.greengrass.config.UpdateBehaviorTree)3 Path (java.nio.file.Path)3 Map (java.util.Map)3 ComponentConfiguration (com.amazon.aws.iot.greengrass.component.common.ComponentConfiguration)2 DeploymentPackageConfiguration (com.aws.greengrass.deployment.model.DeploymentPackageConfiguration)2 KernelLifecycle (com.aws.greengrass.lifecyclemanager.KernelLifecycle)2 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)2 InputStream (java.io.InputStream)2 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)2 ConfigurationWriter (com.aws.greengrass.config.ConfigurationWriter)1 State (com.aws.greengrass.dependency.State)1 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)1