Search in sources :

Example 1 with ListComponentsRequest

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

the class IPCCliTest method GIVEN_kernel_running_WHEN_CLI_authorized_groups_updated_THEN_old_token_revoked_and_new_token_accepted.

@Test
@Order(10)
void GIVEN_kernel_running_WHEN_CLI_authorized_groups_updated_THEN_old_token_revoked_and_new_token_accepted(ExtensionContext context) throws Exception {
    ignoreExceptionOfType(context, RuntimeException.class);
    String oldAuthToken = getAuthTokenFromInfoFile();
    CountDownLatch awaitIpcServiceLatch = new CountDownLatch(1);
    GlobalStateChangeListener listener = getListenerForServiceRunning(awaitIpcServiceLatch, CLI_SERVICE);
    kernel.getContext().addGlobalStateChangeListener(listener);
    String validGid;
    if (PlatformResolver.isWindows) {
        // GG_NEEDS_REVIEW: TODO support windows
        validGid = "0";
    } else {
        validGid = selectAValidGid();
    }
    assertNotNull(validGid, "Failed to find a single valid GID on this test instance");
    kernel.locate(CLI_SERVICE).getConfig().lookup(CONFIGURATION_CONFIG_KEY, AUTHORIZED_POSIX_GROUPS).withValue(validGid);
    assertTrue(awaitIpcServiceLatch.await(10, TimeUnit.SECONDS));
    kernel.getContext().removeGlobalStateChangeListener(listener);
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> IPCTestUtils.connectToGGCOverEventStreamIPC(TestUtils.getSocketOptionsForIPC(), oldAuthToken, kernel));
    assertEquals(AccessDeniedException.class, executionException.getCause().getClass());
    try (EventStreamRPCConnection eventStreamRPCConnection = IPCTestUtils.connectToGGCOverEventStreamIPC(TestUtils.getSocketOptionsForIPC(), getAuthTokenFromInfoFile(), kernel)) {
        GreengrassCoreIPCClient client = new GreengrassCoreIPCClient(eventStreamRPCConnection);
        ListComponentsResponse listComponentsResponse = client.listComponents(new ListComponentsRequest(), Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
        assertTrue(listComponentsResponse.getComponents().size() > 0);
    }
}
Also used : GreengrassCoreIPCClient(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient) EventStreamRPCConnection(software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection) ListComponentsResponse(software.amazon.awssdk.aws.greengrass.model.ListComponentsResponse) GlobalStateChangeListener(com.aws.greengrass.lifecyclemanager.GlobalStateChangeListener) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) ListComponentsRequest(software.amazon.awssdk.aws.greengrass.model.ListComponentsRequest) 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 2 with ListComponentsRequest

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

the class CLIEventStreamAgentTest method test_GetListComponent_success.

@Test
@SuppressWarnings("PMD.CloseResource")
void test_GetListComponent_success() throws IOException {
    ListComponentsRequest request = new ListComponentsRequest();
    GreengrassService mockTestService = mock(GreengrassService.class);
    GreengrassService mockMainService = mock(GreengrassService.class);
    when(mockTestService.getName()).thenReturn(TEST_SERVICE);
    when(mockTestService.getState()).thenReturn(State.RUNNING);
    try (Context context = new Context()) {
        Topics mockServiceConfig = Topics.of(context, TEST_SERVICE, null);
        mockServiceConfig.lookup(VERSION_CONFIG_KEY).withValue("1.0.0");
        Map<String, Object> mockParameterConfig = ImmutableMap.of("param1", "value1");
        mockServiceConfig.lookupTopics(CONFIGURATION_CONFIG_KEY).replaceAndWait(mockParameterConfig);
        when(mockTestService.getServiceConfig()).thenReturn(mockServiceConfig);
        when(kernel.getMain()).thenReturn(mockMainService);
        when(kernel.orderedDependencies()).thenReturn(Arrays.asList(mockTestService, mockMainService));
        ListComponentsResponse response = cliEventStreamAgent.getListComponentsHandler(mockContext).handleRequest(request);
        assertEquals(1, response.getComponents().size());
        ComponentDetails componentDetails = response.getComponents().get(0);
        assertEquals(TEST_SERVICE, componentDetails.getComponentName());
        assertEquals(mockParameterConfig, componentDetails.getConfiguration());
        assertEquals("1.0.0", componentDetails.getVersion());
    }
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Context(com.aws.greengrass.dependency.Context) OperationContinuationHandlerContext(software.amazon.awssdk.eventstreamrpc.OperationContinuationHandlerContext) Topics(com.aws.greengrass.config.Topics) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) ListComponentsResponse(software.amazon.awssdk.aws.greengrass.model.ListComponentsResponse) ComponentDetails(software.amazon.awssdk.aws.greengrass.model.ComponentDetails) ListComponentsRequest(software.amazon.awssdk.aws.greengrass.model.ListComponentsRequest) Test(org.junit.jupiter.api.Test)

Example 3 with ListComponentsRequest

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

the class IPCCliTest method GIVEN_kernel_running_WHEN_list_component_request_made_THEN_components_details_sent.

@Test
@Order(4)
void GIVEN_kernel_running_WHEN_list_component_request_made_THEN_components_details_sent() throws Exception {
    ListComponentsRequest request = new ListComponentsRequest();
    ListComponentsResponse listComponentsResponse = clientConnection.listComponents(request, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
    List<String> components = listComponentsResponse.getComponents().stream().map(ComponentDetails::getComponentName).collect(Collectors.toList());
    assertTrue(components.contains("mqtt"));
    assertTrue(components.contains(TEST_SERVICE_NAME));
    assertFalse(components.contains("main"));
    try (EventStreamRPCConnection connection = IPCTestUtils.getEventStreamRpcConnection(kernel, "ServiceName")) {
        GreengrassCoreIPCClientV2 client = GreengrassCoreIPCClientV2.builder().withClient(new GreengrassCoreIPCClient(connection)).build();
        assertEquals(components, client.listComponents(request).getComponents().stream().map(ComponentDetails::getComponentName).collect(Collectors.toList()));
    }
}
Also used : GreengrassCoreIPCClientV2(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClientV2) GreengrassCoreIPCClient(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient) EventStreamRPCConnection(software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection) ListComponentsResponse(software.amazon.awssdk.aws.greengrass.model.ListComponentsResponse) ComponentDetails(software.amazon.awssdk.aws.greengrass.model.ComponentDetails) ListComponentsRequest(software.amazon.awssdk.aws.greengrass.model.ListComponentsRequest) 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 4 with ListComponentsRequest

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

the class NucleusAdapterIpcClientImpl method listComponents.

@Override
public List<ComponentDetails> listComponents() {
    try {
        ListComponentsRequest request = new ListComponentsRequest();
        ListComponentsResponse listComponentsResponse = getIpcClient().listComponents(request, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
        return listComponentsResponse.getComponents();
    } catch (ExecutionException | TimeoutException | InterruptedException e) {
        // TODO: update when the sdk method signature includes exceptions
        throw new RuntimeException(e);
    } finally {
        close();
    }
}
Also used : ListComponentsResponse(software.amazon.awssdk.aws.greengrass.model.ListComponentsResponse) ExecutionException(java.util.concurrent.ExecutionException) ListComponentsRequest(software.amazon.awssdk.aws.greengrass.model.ListComponentsRequest) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ListComponentsRequest (software.amazon.awssdk.aws.greengrass.model.ListComponentsRequest)4 ListComponentsResponse (software.amazon.awssdk.aws.greengrass.model.ListComponentsResponse)4 Test (org.junit.jupiter.api.Test)3 ExecutionException (java.util.concurrent.ExecutionException)2 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)2 Order (org.junit.jupiter.api.Order)2 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)2 GreengrassCoreIPCClient (software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient)2 ComponentDetails (software.amazon.awssdk.aws.greengrass.model.ComponentDetails)2 EventStreamRPCConnection (software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection)2 Topics (com.aws.greengrass.config.Topics)1 Context (com.aws.greengrass.dependency.Context)1 GlobalStateChangeListener (com.aws.greengrass.lifecyclemanager.GlobalStateChangeListener)1 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 GreengrassCoreIPCClientV2 (software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClientV2)1 OperationContinuationHandlerContext (software.amazon.awssdk.eventstreamrpc.OperationContinuationHandlerContext)1