use of software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsRequest in project aws-greengrass-cli by aws-greengrass.
the class CLIEventStreamAgentTest method testListLocalDeployment_successful.
@Test
@SuppressWarnings("PMD.CloseResource")
void testListLocalDeployment_successful() throws IOException {
Topics mockCliConfig = mock(Topics.class);
try (Context context = new Context()) {
Topics localDeployments = Topics.of(context, "localDeployments", null);
String deploymentId1 = UUID.randomUUID().toString();
localDeployments.lookupTopics(deploymentId1).lookup(DEPLOYMENT_STATUS_KEY_NAME).withValue(DeploymentStatus.IN_PROGRESS.toString());
String deploymentId2 = UUID.randomUUID().toString();
localDeployments.lookupTopics(deploymentId2).lookup(DEPLOYMENT_STATUS_KEY_NAME).withValue(DeploymentStatus.SUCCEEDED.toString());
when(mockCliConfig.findTopics(PERSISTENT_LOCAL_DEPLOYMENTS)).thenReturn(localDeployments);
ListLocalDeploymentsRequest request = new ListLocalDeploymentsRequest();
ListLocalDeploymentsResponse response = cliEventStreamAgent.getListLocalDeploymentsHandler(mockContext, mockCliConfig).handleRequest(request);
assertEquals(2, response.getLocalDeployments().size());
response.getLocalDeployments().stream().forEach(ld -> {
if (ld.getDeploymentId().equals(deploymentId1)) {
assertEquals(DeploymentStatus.IN_PROGRESS, ld.getStatus());
} else if (ld.getDeploymentId().equals(deploymentId2)) {
assertEquals(DeploymentStatus.SUCCEEDED, ld.getStatus());
} else {
fail("Invalid deploymentId found in list of local deployments");
}
});
}
}
use of software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsRequest in project aws-greengrass-cli by aws-greengrass.
the class CLIEventStreamAgentTest method testListLocalDeployment_no_local_deployments.
@Test
@SuppressWarnings("PMD.CloseResource")
void testListLocalDeployment_no_local_deployments() throws IOException {
Topics mockCliConfig = mock(Topics.class);
try (Context context = new Context()) {
Topics localDeployments = Topics.of(context, "localDeployments", null);
when(mockCliConfig.findTopics(PERSISTENT_LOCAL_DEPLOYMENTS)).thenReturn(localDeployments);
ListLocalDeploymentsRequest request = new ListLocalDeploymentsRequest();
ListLocalDeploymentsResponse response = cliEventStreamAgent.getListLocalDeploymentsHandler(mockContext, mockCliConfig).handleRequest(request);
assertEquals(0, response.getLocalDeployments().size());
}
}
use of software.amazon.awssdk.aws.greengrass.model.ListLocalDeploymentsRequest 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.ListLocalDeploymentsRequest in project aws-greengrass-cli by aws-greengrass.
the class NucleusAdapterIpcClientImpl method listLocalDeployments.
@Override
public List<LocalDeployment> listLocalDeployments() {
try {
ListLocalDeploymentsRequest request = new ListLocalDeploymentsRequest();
ListLocalDeploymentsResponse listLocalDeploymentsResponse = getIpcClient().listLocalDeployments(request, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
return listLocalDeploymentsResponse.getLocalDeployments();
} catch (ExecutionException | TimeoutException | InterruptedException e) {
clientConnection.disconnect();
// TODO: update when the sdk method signature includes exceptions
throw new RuntimeException(e);
} finally {
close();
}
}
Aggregations