Search in sources :

Example 1 with DefaultActivator

use of com.aws.greengrass.deployment.activator.DefaultActivator in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentConfigMergerTest method GIVEN_deployment_activate_WHEN_deployment_has_some_new_config_THEN_old_config_is_validated.

@Test
void GIVEN_deployment_activate_WHEN_deployment_has_some_new_config_THEN_old_config_is_validated(ExtensionContext extensionContext) throws Throwable {
    ArgumentCaptor<UpdateAction> taskCaptor = ArgumentCaptor.forClass(UpdateAction.class);
    UpdateSystemPolicyService updateSystemPolicyService = mock(UpdateSystemPolicyService.class);
    when(context.get(UpdateSystemPolicyService.class)).thenReturn(updateSystemPolicyService);
    DeploymentActivatorFactory deploymentActivatorFactory = new DeploymentActivatorFactory(kernel);
    when(context.get(DeploymentActivatorFactory.class)).thenReturn(deploymentActivatorFactory);
    BootstrapManager bootstrapManager = mock(BootstrapManager.class);
    when(bootstrapManager.isBootstrapRequired(any())).thenReturn(false);
    when(context.get(BootstrapManager.class)).thenReturn(bootstrapManager);
    DefaultActivator defaultActivator = mock(DefaultActivator.class);
    when(context.get(DefaultActivator.class)).thenReturn(defaultActivator);
    Topic regionTopic = Topic.of(context, DEVICE_PARAM_AWS_REGION, "us-west-2");
    when(deviceConfiguration.getAWSRegion()).thenReturn(regionTopic);
    Topic credEndpointTopic = Topic.of(context, DEVICE_PARAM_IOT_CRED_ENDPOINT, "xxxxxx.credentials.iot.us-west-2.amazonaws.com");
    when(deviceConfiguration.getIotCredentialEndpoint()).thenReturn(credEndpointTopic);
    Topic dataEndpointTopic = Topic.of(context, DEVICE_PARAM_IOT_DATA_ENDPOINT, "xxxxxx-ats.iot.us-west-2.amazonaws.com");
    when(deviceConfiguration.getIotDataEndpoint()).thenReturn(dataEndpointTopic);
    when(deviceConfiguration.getNucleusComponentName()).thenReturn(DEFAULT_NUCLEUS_COMPONENT_NAME);
    ArgumentCaptor<String> regionCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> credEndpointCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> dataEndpointCaptor = ArgumentCaptor.forClass(String.class);
    ignoreExceptionOfType(extensionContext, IOException.class);
    Map<String, Object> newConfig = new HashMap<>();
    Map<String, Object> newConfig2 = new HashMap<>();
    Map<String, Object> newConfig3 = new HashMap<>();
    Map<String, Object> newConfig4 = new HashMap<>();
    newConfig4.put(DEVICE_PARAM_AWS_REGION, "us-east-1");
    newConfig3.put(CONFIGURATION_CONFIG_KEY, newConfig4);
    newConfig2.put(DEFAULT_NUCLEUS_COMPONENT_NAME, newConfig3);
    newConfig.put(SERVICES_NAMESPACE_TOPIC, newConfig2);
    // GIVEN
    DeploymentConfigMerger merger = new DeploymentConfigMerger(kernel, deviceConfiguration, validator);
    DeploymentDocument doc = mock(DeploymentDocument.class);
    when(doc.getDeploymentId()).thenReturn("DeploymentId");
    when(doc.getComponentUpdatePolicy()).thenReturn(new ComponentUpdatePolicy(0, NOTIFY_COMPONENTS));
    merger.mergeInNewConfig(createMockDeployment(doc), newConfig);
    verify(updateSystemPolicyService).addUpdateAction(any(), taskCaptor.capture());
    assertEquals(0, taskCaptor.getValue().getTimeout());
    assertEquals("DeploymentId", taskCaptor.getValue().getDeploymentId());
    assertFalse(taskCaptor.getValue().isGgcRestart());
    // WHEN
    taskCaptor.getValue().getAction().run();
    // THEN
    verify(defaultActivator, times(1)).activate(any(), any(), any());
    verify(deviceConfiguration, times(1)).validateEndpoints(regionCaptor.capture(), credEndpointCaptor.capture(), dataEndpointCaptor.capture());
    assertNotNull(regionCaptor.getValue());
    assertEquals("us-east-1", regionCaptor.getValue());
    assertNotNull(credEndpointCaptor.getValue());
    assertEquals("xxxxxx.credentials.iot.us-west-2.amazonaws.com", credEndpointCaptor.getValue());
    assertNotNull(dataEndpointCaptor.getValue());
    assertEquals("xxxxxx-ats.iot.us-west-2.amazonaws.com", dataEndpointCaptor.getValue());
}
Also used : DeploymentActivatorFactory(com.aws.greengrass.deployment.activator.DeploymentActivatorFactory) BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) ComponentUpdatePolicy(com.aws.greengrass.deployment.model.ComponentUpdatePolicy) UpdateAction(com.aws.greengrass.lifecyclemanager.UpdateAction) HashMap(java.util.HashMap) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) UpdateSystemPolicyService(com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService) DefaultActivator(com.aws.greengrass.deployment.activator.DefaultActivator) Topic(com.aws.greengrass.config.Topic) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultActivator

use of com.aws.greengrass.deployment.activator.DefaultActivator in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentConfigMergerTest method GIVEN_deployment_WHEN_task_not_cancelled_THEN_update_is_continued.

@Test
void GIVEN_deployment_WHEN_task_not_cancelled_THEN_update_is_continued() throws Throwable {
    ArgumentCaptor<UpdateAction> taskCaptor = ArgumentCaptor.forClass(UpdateAction.class);
    UpdateSystemPolicyService updateSystemPolicyService = mock(UpdateSystemPolicyService.class);
    when(context.get(UpdateSystemPolicyService.class)).thenReturn(updateSystemPolicyService);
    DeploymentActivatorFactory deploymentActivatorFactory = new DeploymentActivatorFactory(kernel);
    when(context.get(DeploymentActivatorFactory.class)).thenReturn(deploymentActivatorFactory);
    BootstrapManager bootstrapManager = mock(BootstrapManager.class);
    when(bootstrapManager.isBootstrapRequired(any())).thenReturn(false);
    when(context.get(BootstrapManager.class)).thenReturn(bootstrapManager);
    DefaultActivator defaultActivator = mock(DefaultActivator.class);
    when(context.get(DefaultActivator.class)).thenReturn(defaultActivator);
    // GIVEN
    DeploymentConfigMerger merger = new DeploymentConfigMerger(kernel, deviceConfiguration, validator);
    DeploymentDocument doc = mock(DeploymentDocument.class);
    when(doc.getDeploymentId()).thenReturn("DeploymentId");
    when(doc.getComponentUpdatePolicy()).thenReturn(new ComponentUpdatePolicy(0, NOTIFY_COMPONENTS));
    merger.mergeInNewConfig(createMockDeployment(doc), new HashMap<>());
    verify(updateSystemPolicyService).addUpdateAction(any(), taskCaptor.capture());
    assertEquals(0, taskCaptor.getValue().getTimeout());
    assertEquals("DeploymentId", taskCaptor.getValue().getDeploymentId());
    assertFalse(taskCaptor.getValue().isGgcRestart());
    // WHEN
    taskCaptor.getValue().getAction().run();
    // THEN
    verify(defaultActivator, times(1)).activate(any(), any(), any());
}
Also used : UpdateSystemPolicyService(com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService) DeploymentActivatorFactory(com.aws.greengrass.deployment.activator.DeploymentActivatorFactory) BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) DefaultActivator(com.aws.greengrass.deployment.activator.DefaultActivator) ComponentUpdatePolicy(com.aws.greengrass.deployment.model.ComponentUpdatePolicy) UpdateAction(com.aws.greengrass.lifecyclemanager.UpdateAction) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultActivator

use of com.aws.greengrass.deployment.activator.DefaultActivator in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentConfigMergerTest method GIVEN_deployment_activate_WHEN_deployment_has_new_config_THEN_new_config_is_validated.

@Test
void GIVEN_deployment_activate_WHEN_deployment_has_new_config_THEN_new_config_is_validated(ExtensionContext extensionContext) throws Throwable {
    ArgumentCaptor<UpdateAction> taskCaptor = ArgumentCaptor.forClass(UpdateAction.class);
    UpdateSystemPolicyService updateSystemPolicyService = mock(UpdateSystemPolicyService.class);
    when(context.get(UpdateSystemPolicyService.class)).thenReturn(updateSystemPolicyService);
    DeploymentActivatorFactory deploymentActivatorFactory = new DeploymentActivatorFactory(kernel);
    when(context.get(DeploymentActivatorFactory.class)).thenReturn(deploymentActivatorFactory);
    BootstrapManager bootstrapManager = mock(BootstrapManager.class);
    when(bootstrapManager.isBootstrapRequired(any())).thenReturn(false);
    when(context.get(BootstrapManager.class)).thenReturn(bootstrapManager);
    DefaultActivator defaultActivator = mock(DefaultActivator.class);
    when(context.get(DefaultActivator.class)).thenReturn(defaultActivator);
    Topic regionTopic = Topic.of(context, DEVICE_PARAM_AWS_REGION, "us-west-2");
    when(deviceConfiguration.getAWSRegion()).thenReturn(regionTopic);
    Topic credEndpointTopic = Topic.of(context, DEVICE_PARAM_IOT_CRED_ENDPOINT, "xxxxxx.credentials.iot.us-west-2.amazonaws.com");
    when(deviceConfiguration.getIotCredentialEndpoint()).thenReturn(credEndpointTopic);
    Topic dataEndpointTopic = Topic.of(context, DEVICE_PARAM_IOT_DATA_ENDPOINT, "xxxxxx-ats.iot.us-west-2.amazonaws.com");
    when(deviceConfiguration.getIotDataEndpoint()).thenReturn(dataEndpointTopic);
    when(deviceConfiguration.getNucleusComponentName()).thenReturn(DEFAULT_NUCLEUS_COMPONENT_NAME);
    ArgumentCaptor<String> regionCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> credEndpointCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> dataEndpointCaptor = ArgumentCaptor.forClass(String.class);
    ignoreExceptionOfType(extensionContext, IOException.class);
    Map<String, Object> newConfig = new HashMap<>();
    Map<String, Object> newConfig2 = new HashMap<>();
    Map<String, Object> newConfig3 = new HashMap<>();
    Map<String, Object> newConfig4 = new HashMap<>();
    newConfig4.put(DEVICE_PARAM_AWS_REGION, "us-east-1");
    newConfig4.put(DEVICE_PARAM_IOT_CRED_ENDPOINT, "xxxxxx.credentials.iot.us-east-1.amazonaws.com");
    newConfig4.put(DEVICE_PARAM_IOT_DATA_ENDPOINT, "xxxxxx-ats.iot.us-east-1.amazonaws.com");
    newConfig3.put(CONFIGURATION_CONFIG_KEY, newConfig4);
    newConfig2.put(DEFAULT_NUCLEUS_COMPONENT_NAME, newConfig3);
    newConfig.put(SERVICES_NAMESPACE_TOPIC, newConfig2);
    // GIVEN
    DeploymentConfigMerger merger = new DeploymentConfigMerger(kernel, deviceConfiguration, validator);
    DeploymentDocument doc = mock(DeploymentDocument.class);
    when(doc.getDeploymentId()).thenReturn("DeploymentId");
    when(doc.getComponentUpdatePolicy()).thenReturn(new ComponentUpdatePolicy(0, NOTIFY_COMPONENTS));
    merger.mergeInNewConfig(createMockDeployment(doc), newConfig);
    verify(updateSystemPolicyService).addUpdateAction(any(), taskCaptor.capture());
    assertEquals(0, taskCaptor.getValue().getTimeout());
    assertEquals("DeploymentId", taskCaptor.getValue().getDeploymentId());
    assertFalse(taskCaptor.getValue().isGgcRestart());
    // WHEN
    taskCaptor.getValue().getAction().run();
    // THEN
    verify(defaultActivator, times(1)).activate(any(), any(), any());
    verify(deviceConfiguration, times(1)).validateEndpoints(regionCaptor.capture(), credEndpointCaptor.capture(), dataEndpointCaptor.capture());
    assertNotNull(regionCaptor.getValue());
    assertEquals("us-east-1", regionCaptor.getValue());
    assertNotNull(credEndpointCaptor.getValue());
    assertEquals("xxxxxx.credentials.iot.us-east-1.amazonaws.com", credEndpointCaptor.getValue());
    assertNotNull(dataEndpointCaptor.getValue());
    assertEquals("xxxxxx-ats.iot.us-east-1.amazonaws.com", dataEndpointCaptor.getValue());
}
Also used : DeploymentActivatorFactory(com.aws.greengrass.deployment.activator.DeploymentActivatorFactory) BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) ComponentUpdatePolicy(com.aws.greengrass.deployment.model.ComponentUpdatePolicy) UpdateAction(com.aws.greengrass.lifecyclemanager.UpdateAction) HashMap(java.util.HashMap) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) UpdateSystemPolicyService(com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService) DefaultActivator(com.aws.greengrass.deployment.activator.DefaultActivator) Topic(com.aws.greengrass.config.Topic) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultActivator (com.aws.greengrass.deployment.activator.DefaultActivator)3 DeploymentActivatorFactory (com.aws.greengrass.deployment.activator.DeploymentActivatorFactory)3 BootstrapManager (com.aws.greengrass.deployment.bootstrap.BootstrapManager)3 ComponentUpdatePolicy (com.aws.greengrass.deployment.model.ComponentUpdatePolicy)3 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)3 UpdateAction (com.aws.greengrass.lifecyclemanager.UpdateAction)3 UpdateSystemPolicyService (com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService)3 Test (org.junit.jupiter.api.Test)3 Topic (com.aws.greengrass.config.Topic)2 HashMap (java.util.HashMap)2