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);
}
}
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());
}
}
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()));
}
}
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();
}
}
Aggregations