Search in sources :

Example 1 with DeploymentActivatorFactory

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

the class DeploymentConfigMergerTest method GIVEN_deployment_WHEN_check_safety_selected_THEN_check_safety_before_update.

@Test
void GIVEN_deployment_WHEN_check_safety_selected_THEN_check_safety_before_update() throws Exception {
    UpdateSystemPolicyService updateSystemPolicyService = mock(UpdateSystemPolicyService.class);
    when(context.get(UpdateSystemPolicyService.class)).thenReturn(updateSystemPolicyService);
    DeploymentActivatorFactory deploymentActivatorFactory = mock(DeploymentActivatorFactory.class);
    DeploymentActivator deploymentActivator = mock(DeploymentActivator.class);
    when(deploymentActivatorFactory.getDeploymentActivator(any())).thenReturn(deploymentActivator);
    when(context.get(DeploymentActivatorFactory.class)).thenReturn(deploymentActivatorFactory);
    DeploymentConfigMerger merger = new DeploymentConfigMerger(kernel, deviceConfiguration, validator);
    DeploymentDocument doc = new DeploymentDocument();
    doc.setConfigurationArn("NoSafetyCheckDeploy");
    doc.setComponentUpdatePolicy(new ComponentUpdatePolicy(0, SKIP_NOTIFY_COMPONENTS));
    merger.mergeInNewConfig(createMockDeployment(doc), new HashMap<>());
    verify(updateSystemPolicyService, times(0)).addUpdateAction(any(), any());
    doc.setConfigurationArn("DeploymentId");
    doc.setComponentUpdatePolicy(new ComponentUpdatePolicy(60, NOTIFY_COMPONENTS));
    merger.mergeInNewConfig(createMockDeployment(doc), new HashMap<>());
    verify(updateSystemPolicyService).addUpdateAction(any(), any());
}
Also used : UpdateSystemPolicyService(com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService) DeploymentActivatorFactory(com.aws.greengrass.deployment.activator.DeploymentActivatorFactory) ComponentUpdatePolicy(com.aws.greengrass.deployment.model.ComponentUpdatePolicy) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) DeploymentActivator(com.aws.greengrass.deployment.activator.DeploymentActivator) Test(org.junit.jupiter.api.Test)

Example 2 with DeploymentActivatorFactory

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

the class DeploymentConfigMergerTest method GIVEN_deployment_WHEN_task_cancelled_THEN_update_is_cancelled.

@Test
void GIVEN_deployment_WHEN_task_cancelled_THEN_update_is_cancelled() throws Throwable {
    ArgumentCaptor<UpdateAction> cancelledTaskCaptor = ArgumentCaptor.forClass(UpdateAction.class);
    UpdateSystemPolicyService updateSystemPolicyService = mock(UpdateSystemPolicyService.class);
    DeploymentActivatorFactory factory = mock(DeploymentActivatorFactory.class);
    when(factory.getDeploymentActivator(anyMap())).thenReturn(mock(KernelUpdateActivator.class));
    when(context.get(any())).thenAnswer(invocationOnMock -> {
        Object argument = invocationOnMock.getArgument(0);
        if (UpdateSystemPolicyService.class.equals(argument)) {
            return updateSystemPolicyService;
        } else if (DeploymentActivatorFactory.class.equals(argument)) {
            return factory;
        }
        throw new InvalidUseOfMatchersException(String.format("Argument %s does not match", argument));
    });
    // 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));
    Future<DeploymentResult> fut = merger.mergeInNewConfig(createMockDeployment(doc), new HashMap<>());
    verify(updateSystemPolicyService).addUpdateAction(any(), cancelledTaskCaptor.capture());
    assertEquals(0, cancelledTaskCaptor.getValue().getTimeout());
    assertEquals("DeploymentId", cancelledTaskCaptor.getValue().getDeploymentId());
    assertTrue(cancelledTaskCaptor.getValue().isGgcRestart());
    // WHEN
    fut.cancel(true);
    cancelledTaskCaptor.getValue().getAction().run();
    // THEN
    verify(doc, times(0)).getFailureHandlingPolicy();
}
Also used : DeploymentActivatorFactory(com.aws.greengrass.deployment.activator.DeploymentActivatorFactory) ComponentUpdatePolicy(com.aws.greengrass.deployment.model.ComponentUpdatePolicy) UpdateAction(com.aws.greengrass.lifecyclemanager.UpdateAction) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) KernelUpdateActivator(com.aws.greengrass.deployment.activator.KernelUpdateActivator) UpdateSystemPolicyService(com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService) InvalidUseOfMatchersException(org.mockito.exceptions.misusing.InvalidUseOfMatchersException) Test(org.junit.jupiter.api.Test)

Example 3 with DeploymentActivatorFactory

use of com.aws.greengrass.deployment.activator.DeploymentActivatorFactory 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 4 with DeploymentActivatorFactory

use of com.aws.greengrass.deployment.activator.DeploymentActivatorFactory 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 5 with DeploymentActivatorFactory

use of com.aws.greengrass.deployment.activator.DeploymentActivatorFactory 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

DeploymentActivatorFactory (com.aws.greengrass.deployment.activator.DeploymentActivatorFactory)5 ComponentUpdatePolicy (com.aws.greengrass.deployment.model.ComponentUpdatePolicy)5 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)5 UpdateSystemPolicyService (com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService)5 Test (org.junit.jupiter.api.Test)5 UpdateAction (com.aws.greengrass.lifecyclemanager.UpdateAction)4 DefaultActivator (com.aws.greengrass.deployment.activator.DefaultActivator)3 BootstrapManager (com.aws.greengrass.deployment.bootstrap.BootstrapManager)3 Topic (com.aws.greengrass.config.Topic)2 HashMap (java.util.HashMap)2 DeploymentActivator (com.aws.greengrass.deployment.activator.DeploymentActivator)1 KernelUpdateActivator (com.aws.greengrass.deployment.activator.KernelUpdateActivator)1 DeploymentResult (com.aws.greengrass.deployment.model.DeploymentResult)1 InvalidUseOfMatchersException (org.mockito.exceptions.misusing.InvalidUseOfMatchersException)1