Search in sources :

Example 1 with ComponentDetails

use of software.amazon.awssdk.aws.greengrass.model.ComponentDetails in project aws-greengrass-cli by aws-greengrass.

the class ComponentCommandTest method GIVEN_a_running_component_WHEN_list_component_details_THEN_component_info_is_printed.

@Test
void GIVEN_a_running_component_WHEN_list_component_details_THEN_component_info_is_printed() {
    // GIVEN
    ComponentDetails componentDetails = getTestComponentDetails();
    when(nucleusAdapteripc.listComponents()).thenReturn(Collections.singletonList(componentDetails));
    // WHEN
    // We need to do some print stream magic here to verify the content of System.out.println
    // Create a stream to hold the output
    ByteArrayOutputStream outputCaptor = new ByteArrayOutputStream();
    // Save the old System.out!
    PrintStream old = System.out;
    // Switch special stream
    System.setOut(new PrintStream(outputCaptor));
    // Call. System.out.println now goes to outputCaptor
    int exitCode = runCommandLine("component", "list");
    // Put things back
    System.out.flush();
    System.setOut(old);
    // THEN
    assertThat(exitCode, is(0));
    String output = outputCaptor.toString();
    verifyComponentDetails(componentDetails, output);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ComponentDetails(software.amazon.awssdk.aws.greengrass.model.ComponentDetails) Test(org.junit.jupiter.api.Test)

Example 2 with ComponentDetails

use of software.amazon.awssdk.aws.greengrass.model.ComponentDetails in project aws-greengrass-cli by aws-greengrass.

the class ComponentCommandTest method GIVEN_a_running_component_WHEN_check_component_details_THEN_component_info_is_printed.

@Test
void GIVEN_a_running_component_WHEN_check_component_details_THEN_component_info_is_printed() {
    // GIVEN
    ComponentDetails componentDetails = getTestComponentDetails();
    when(nucleusAdapteripc.getComponentDetails(any())).thenReturn(componentDetails);
    // WHEN
    // We need to do some print stream magic here to verify the content of System.out.println
    // Create a stream to hold the output
    ByteArrayOutputStream outputCaptor = new ByteArrayOutputStream();
    // Save the old System.out!
    PrintStream old = System.out;
    // Switch special stream
    System.setOut(new PrintStream(outputCaptor));
    // Call. System.out.println now goes to outputCaptor
    int exitCode = runCommandLine("component", "details", "-n", NEW_COMPONENT_3);
    // Put things back
    System.out.flush();
    System.setOut(old);
    // THEN
    assertThat(exitCode, is(0));
    String output = outputCaptor.toString();
    verifyComponentDetails(componentDetails, output);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ComponentDetails(software.amazon.awssdk.aws.greengrass.model.ComponentDetails) Test(org.junit.jupiter.api.Test)

Example 3 with ComponentDetails

use of software.amazon.awssdk.aws.greengrass.model.ComponentDetails in project aws-greengrass-cli by aws-greengrass.

the class CLIEventStreamAgent method getComponentDetails.

private ComponentDetails getComponentDetails(GreengrassService service) {
    ComponentDetails componentDetails = new ComponentDetails();
    componentDetails.setComponentName(service.getName());
    componentDetails.setState(LifecycleState.valueOf(service.getState().toString()));
    if (service.getServiceConfig().find(VERSION_CONFIG_KEY) != null) {
        componentDetails.setVersion(Coerce.toString(service.getServiceConfig().find(VERSION_CONFIG_KEY)));
    }
    if (service.getServiceConfig().findInteriorChild(CONFIGURATION_CONFIG_KEY) != null) {
        componentDetails.setConfiguration(service.getServiceConfig().findInteriorChild(CONFIGURATION_CONFIG_KEY).toPOJO());
    }
    return componentDetails;
}
Also used : ComponentDetails(software.amazon.awssdk.aws.greengrass.model.ComponentDetails)

Example 4 with ComponentDetails

use of software.amazon.awssdk.aws.greengrass.model.ComponentDetails in project aws-greengrass-cli by aws-greengrass.

the class IPCCliTest method GIVEN_kernel_running_WHEN_create_deployment_after_recipe_update_THEN_kernel_runs_latest_recipe.

@Test
@Order(7)
void GIVEN_kernel_running_WHEN_create_deployment_after_recipe_update_THEN_kernel_runs_latest_recipe(ExtensionContext context) throws Exception {
    // updated recipes
    Path recipesPath = Paths.get(this.getClass().getResource("recipes").toURI());
    // Deployment to add a component
    CreateLocalDeploymentRequest createLocalDeploymentRequest = new CreateLocalDeploymentRequest();
    createLocalDeploymentRequest.setRootComponentVersionsToAdd(Collections.singletonMap(TEST_SERVICE_NAME, "1.0.1"));
    createLocalDeploymentRequest.setRecipeDirectoryPath(recipesPath.toAbsolutePath().toString());
    CountDownLatch serviceLatch = waitForServiceToComeInState(TEST_SERVICE_NAME, State.RUNNING, kernel);
    CreateLocalDeploymentResponse addComponentDeploymentResponse = clientConnection.createLocalDeployment(createLocalDeploymentRequest, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
    String deploymentId1 = addComponentDeploymentResponse.getDeploymentId();
    CountDownLatch deploymentLatch = waitForDeploymentToBeSuccessful(deploymentId1, kernel);
    assertTrue(serviceLatch.await(SERVICE_STATE_CHECK_TIMEOUT_SECONDS, TimeUnit.SECONDS));
    assertTrue(deploymentLatch.await(LOCAL_DEPLOYMENT_TIMEOUT_SECONDS, TimeUnit.SECONDS));
    GetComponentDetailsRequest getComponentDetailsRequest = new GetComponentDetailsRequest();
    getComponentDetailsRequest.setComponentName(TEST_SERVICE_NAME);
    ComponentDetails componentDetails = clientConnection.getComponentDetails(getComponentDetailsRequest, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS).getComponentDetails();
    assertEquals("1.0.1", componentDetails.getVersion());
    // Deployment to remove a component
    createLocalDeploymentRequest = new CreateLocalDeploymentRequest();
    createLocalDeploymentRequest.setRootComponentsToRemove(Arrays.asList(TEST_SERVICE_NAME));
    serviceLatch = waitForServiceToComeInState(TEST_SERVICE_NAME, State.FINISHED, kernel);
    CreateLocalDeploymentResponse deploymentToRemoveComponentResponse = clientConnection.createLocalDeployment(createLocalDeploymentRequest, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
    String deploymentId2 = deploymentToRemoveComponentResponse.getDeploymentId();
    deploymentLatch = waitForDeploymentToBeSuccessful(deploymentId2, kernel);
    assertTrue(serviceLatch.await(SERVICE_STATE_CHECK_TIMEOUT_SECONDS, TimeUnit.SECONDS));
    assertTrue(deploymentLatch.await(LOCAL_DEPLOYMENT_TIMEOUT_SECONDS, TimeUnit.SECONDS));
    ignoreExceptionOfType(context, ServiceLoadException.class);
    GetComponentDetailsRequest getRemovedComponent = new GetComponentDetailsRequest();
    getRemovedComponent.setComponentName(TEST_SERVICE_NAME);
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> clientConnection.getComponentDetails(getRemovedComponent, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS).getComponentDetails());
    assertEquals(ResourceNotFoundError.class, executionException.getCause().getClass());
    ListLocalDeploymentsRequest listLocalDeploymentsRequest = new ListLocalDeploymentsRequest();
    ListLocalDeploymentsResponse listLocalDeploymentsResponse = clientConnection.listLocalDeployments(listLocalDeploymentsRequest, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
    List<String> localDeploymentIds = listLocalDeploymentsResponse.getLocalDeployments().stream().map(ld -> ld.getDeploymentId()).collect(Collectors.toList());
    assertThat(localDeploymentIds, containsInAnyOrder(deploymentId1, deploymentId2));
}
Also used : Path(java.nio.file.Path) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) GreengrassCoreIPCClientV2(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClientV2) TEST_SERVICE_NAME(com.aws.greengrass.integrationtests.ipc.IPCTestUtils.TEST_SERVICE_NAME) Order(org.junit.jupiter.api.Order) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ListComponentsResponse(software.amazon.awssdk.aws.greengrass.model.ListComponentsResponse) AfterAll(org.junit.jupiter.api.AfterAll) IPCTestUtils(com.aws.greengrass.integrationtests.ipc.IPCTestUtils) LifecycleState(software.amazon.awssdk.aws.greengrass.model.LifecycleState) 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) Map(java.util.Map) IPCTestUtils.waitForServiceToComeInState(com.aws.greengrass.integrationtests.ipc.IPCTestUtils.waitForServiceToComeInState) InvalidArgumentsError(software.amazon.awssdk.aws.greengrass.model.InvalidArgumentsError) Path(java.nio.file.Path) ComponentVersionNegotiationException(com.aws.greengrass.componentmanager.exceptions.ComponentVersionNegotiationException) GreengrassCoreIPCClient(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient) CLI_SERVICE(com.aws.greengrass.cli.CLIService.CLI_SERVICE) TestUtils(com.aws.greengrass.testcommons.testutilities.TestUtils) Collectors(java.util.stream.Collectors) ExceptionLogProtector.ignoreExceptionOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionOfType) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) SERVICES_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICES_NAMESPACE_TOPIC) Test(org.junit.jupiter.api.Test) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) UnixPlatform(com.aws.greengrass.util.platforms.unix.UnixPlatform) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) GlobalStateChangeListener(com.aws.greengrass.lifecyclemanager.GlobalStateChangeListener) IPCTestUtils.getEventStreamRpcConnection(com.aws.greengrass.integrationtests.ipc.IPCTestUtils.getEventStreamRpcConnection) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) RunWithInfo(software.amazon.awssdk.aws.greengrass.model.RunWithInfo) CreateLocalDeploymentRequest(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ListLocalDeploymentsResponse(software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsResponse) CreateLocalDeploymentResponse(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse) Optional(java.util.Optional) CLI_AUTH_TOKEN(com.aws.greengrass.cli.CLIService.CLI_AUTH_TOKEN) ComponentStore(com.aws.greengrass.componentmanager.ComponentStore) GetComponentDetailsRequest(software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ListLocalDeploymentsRequest(software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsRequest) AUTHORIZED_POSIX_GROUPS(com.aws.greengrass.cli.CLIService.AUTHORIZED_POSIX_GROUPS) CONFIGURATION_CONFIG_KEY(com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY) ExceptionLogProtector.ignoreExceptionUltimateCauseWithMessage(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseWithMessage) ConfigPlatformResolver(com.aws.greengrass.integrationtests.util.ConfigPlatformResolver) HashMap(java.util.HashMap) ComponentDetails(software.amazon.awssdk.aws.greengrass.model.ComponentDetails) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Platform(com.aws.greengrass.util.platforms.Platform) IPCTestUtils.getListenerForServiceRunning(com.aws.greengrass.integrationtests.ipc.IPCTestUtils.getListenerForServiceRunning) PackageDownloadException(com.aws.greengrass.componentmanager.exceptions.PackageDownloadException) GGExtension(com.aws.greengrass.testcommons.testutilities.GGExtension) AccessDeniedException(software.amazon.awssdk.eventstreamrpc.model.AccessDeniedException) ResourceNotFoundError(software.amazon.awssdk.aws.greengrass.model.ResourceNotFoundError) ConnectException(java.net.ConnectException) 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) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) RestartComponentRequest(software.amazon.awssdk.aws.greengrass.model.RestartComponentRequest) RUN_WITH_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.RUN_WITH_NAMESPACE_TOPIC) ListComponentsRequest(software.amazon.awssdk.aws.greengrass.model.ListComponentsRequest) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UniqueRootPathExtension(com.aws.greengrass.testcommons.testutilities.UniqueRootPathExtension) ExceptionLogProtector.ignoreExceptionUltimateCauseOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseOfType) EventStreamRPCConnection(software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection) IOException(java.io.IOException) File(java.io.File) ExceptionLogProtector.ignoreExceptionWithMessage(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionWithMessage) MethodOrderer(org.junit.jupiter.api.MethodOrderer) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Topic(com.aws.greengrass.config.Topic) IPCTestUtils.waitForDeploymentToBeSuccessful(com.aws.greengrass.integrationtests.ipc.IPCTestUtils.waitForDeploymentToBeSuccessful) Paths(java.nio.file.Paths) NoOpPathOwnershipHandler(com.aws.greengrass.testcommons.testutilities.NoOpPathOwnershipHandler) Assertions(org.junit.jupiter.api.Assertions) Collections(java.util.Collections) CreateLocalDeploymentRequest(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest) CreateLocalDeploymentResponse(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse) ListLocalDeploymentsRequest(software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsRequest) ListLocalDeploymentsResponse(software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsResponse) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) ComponentDetails(software.amazon.awssdk.aws.greengrass.model.ComponentDetails) GetComponentDetailsRequest(software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest) Order(org.junit.jupiter.api.Order) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 5 with ComponentDetails

use of software.amazon.awssdk.aws.greengrass.model.ComponentDetails in project aws-greengrass-cli by aws-greengrass.

the class IPCCliTest method GIVEN_kernel_running_WHEN_change_configuration_and_deployment_THEN_kernel_copies_artifacts_correctly.

@Test
@Order(8)
void GIVEN_kernel_running_WHEN_change_configuration_and_deployment_THEN_kernel_copies_artifacts_correctly(ExtensionContext context) throws Exception {
    ignoreExceptionOfType(context, SdkClientException.class);
    ignoreExceptionOfType(context, PackageDownloadException.class);
    ignoreExceptionOfType(context, ComponentVersionNegotiationException.class);
    // updated recipes
    Path recipesPath = Paths.get(this.getClass().getResource("recipes").toURI());
    Path artifactsPath = Paths.get(this.getClass().getResource("artifacts").toURI());
    Map<String, Map<String, Object>> componentToConfiguration;
    String update = "{\"Component1\":{\"MERGE\":{\"Message\":\"NewWorld\"}}}";
    componentToConfiguration = OBJECT_MAPPER.readValue(update, Map.class);
    Map<String, RunWithInfo> componentToRunWithInfo = new HashMap<>();
    RunWithInfo runWithInfo = new RunWithInfo();
    runWithInfo.setPosixUser("nobody");
    componentToRunWithInfo.put("Component1", runWithInfo);
    CreateLocalDeploymentRequest createLocalDeploymentRequest = new CreateLocalDeploymentRequest();
    createLocalDeploymentRequest.setGroupName("NewGroup");
    createLocalDeploymentRequest.setRootComponentVersionsToAdd(Collections.singletonMap("Component1", "1.0.0"));
    createLocalDeploymentRequest.setComponentToConfiguration(componentToConfiguration);
    createLocalDeploymentRequest.setComponentToRunWithInfo(componentToRunWithInfo);
    createLocalDeploymentRequest.setRecipeDirectoryPath(recipesPath.toAbsolutePath().toString());
    createLocalDeploymentRequest.setArtifactsDirectoryPath(artifactsPath.toAbsolutePath().toString());
    CountDownLatch waitForComponent1ToRun = waitForServiceToComeInState("Component1", State.RUNNING, kernel);
    CreateLocalDeploymentResponse addComponentDeploymentResponse = clientConnection.createLocalDeployment(createLocalDeploymentRequest, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
    String deploymentId1 = addComponentDeploymentResponse.getDeploymentId();
    CountDownLatch waitFordeploymentId1 = waitForDeploymentToBeSuccessful(deploymentId1, kernel);
    assertTrue(waitForComponent1ToRun.await(SERVICE_STATE_CHECK_TIMEOUT_SECONDS, TimeUnit.SECONDS));
    assertTrue(waitFordeploymentId1.await(LOCAL_DEPLOYMENT_TIMEOUT_SECONDS, TimeUnit.SECONDS));
    GetComponentDetailsRequest getComponentDetailsRequest = new GetComponentDetailsRequest();
    getComponentDetailsRequest.setComponentName("Component1");
    ComponentDetails componentDetails = clientConnection.getComponentDetails(getComponentDetailsRequest, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS).getComponentDetails();
    assertEquals("NewWorld", componentDetails.getConfiguration().get("Message"));
    Topic posixUser = kernel.getConfig().find(SERVICES_NAMESPACE_TOPIC, "Component1", RUN_WITH_NAMESPACE_TOPIC, "posixUser");
    assertEquals("nobody", posixUser.getOnce());
    assertTrue(Files.exists(kernel.getNucleusPaths().componentStorePath().resolve(ComponentStore.ARTIFACT_DIRECTORY).resolve("Component1").resolve("1.0.0").resolve("run.sh")));
}
Also used : Path(java.nio.file.Path) RunWithInfo(software.amazon.awssdk.aws.greengrass.model.RunWithInfo) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) CreateLocalDeploymentRequest(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest) CreateLocalDeploymentResponse(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse) Topic(com.aws.greengrass.config.Topic) Map(java.util.Map) HashMap(java.util.HashMap) ComponentDetails(software.amazon.awssdk.aws.greengrass.model.ComponentDetails) GetComponentDetailsRequest(software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest) Order(org.junit.jupiter.api.Order) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Aggregations

ComponentDetails (software.amazon.awssdk.aws.greengrass.model.ComponentDetails)14 Test (org.junit.jupiter.api.Test)9 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)6 Order (org.junit.jupiter.api.Order)6 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)6 GetComponentDetailsRequest (software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 GreengrassCoreIPCClient (software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient)3 GreengrassCoreIPCClientV2 (software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClientV2)3 EventStreamRPCConnection (software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection)3 Topic (com.aws.greengrass.config.Topic)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CreateLocalDeploymentRequest (software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest)2 CreateLocalDeploymentResponse (software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse)2 ListComponentsRequest (software.amazon.awssdk.aws.greengrass.model.ListComponentsRequest)2 ListComponentsResponse (software.amazon.awssdk.aws.greengrass.model.ListComponentsResponse)2