use of software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest in project aws-greengrass-cli by aws-greengrass.
the class CLIEventStreamAgentTest method test_GetComponentDetails_component_does_not_exist.
@Test
void test_GetComponentDetails_component_does_not_exist(ExtensionContext context) throws ServiceLoadException {
ignoreExceptionOfType(context, ServiceLoadException.class);
GetComponentDetailsRequest request = new GetComponentDetailsRequest();
request.setComponentName(TEST_SERVICE);
when(kernel.locate(TEST_SERVICE)).thenThrow(new ServiceLoadException("error"));
assertThrows(ResourceNotFoundError.class, () -> cliEventStreamAgent.getGetComponentDetailsHandler(mockContext).handleRequest(request));
}
use of software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest in project aws-greengrass-cli by aws-greengrass.
the class CLIEventStreamAgentTest method test_GetComponentDetails_empty_component_name.
@Test
void test_GetComponentDetails_empty_component_name() {
GetComponentDetailsRequest request = new GetComponentDetailsRequest();
assertThrows(InvalidArgumentsError.class, () -> cliEventStreamAgent.getGetComponentDetailsHandler(mockContext).handleRequest(request));
}
use of software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest in project aws-greengrass-cli by aws-greengrass.
the class CLIEventStreamAgentTest method test_GetComponentDetails_with_bad_auth_token_rejects.
@Test
void test_GetComponentDetails_with_bad_auth_token_rejects() {
// Pretend that TEST_SERVICE has connected and wants to call the CLI APIs
when(mockContext.getAuthenticationData()).thenReturn(() -> TEST_SERVICE);
GetComponentDetailsRequest request = new GetComponentDetailsRequest();
request.setComponentName("any");
assertThrows(UnauthorizedError.class, () -> cliEventStreamAgent.getGetComponentDetailsHandler(mockContext).handleRequest(request));
}
use of software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest 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));
}
use of software.amazon.awssdk.aws.greengrass.model.GetComponentDetailsRequest 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")));
}
Aggregations