Search in sources :

Example 1 with CreateLocalDeploymentResponse

use of software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse in project aws-iot-device-sdk-java-v2 by aws.

the class GreengrassV2ClientTest method testV2Client.

@Test
public void testV2Client() throws InterruptedException, ExecutionException, TimeoutException {
    assertEquals(authenticationRequest.getAuthToken(), "myAuthToken");
    CreateLocalDeploymentResponse depResp = client.createLocalDeployment(new CreateLocalDeploymentRequest());
    assertEquals("deployment", depResp.getDeploymentId());
    CompletableFuture<CreateLocalDeploymentResponse> asyncDepResp = client.createLocalDeploymentAsync(new CreateLocalDeploymentRequest());
    assertEquals("deployment", asyncDepResp.get().getDeploymentId());
    CompletableFuture<String> receivedMessage = new CompletableFuture<>();
    CompletableFuture<String> finalReceivedMessage = receivedMessage;
    GreengrassCoreIPCClientV2.StreamingResponse<SubscribeToTopicResponse, SubscribeToTopicResponseHandler> subResp = client.subscribeToTopic(new SubscribeToTopicRequest().withTopic("abc"), (x) -> {
        if (!Thread.currentThread().getName().contains("pool")) {
            System.out.println(Thread.currentThread().getName());
            finalReceivedMessage.completeExceptionally(new RuntimeException("Ran on event loop instead of executor"));
        }
        finalReceivedMessage.complete(new String(x.getBinaryMessage().getMessage()));
    }, Optional.empty(), Optional.empty());
    assertEquals("message", receivedMessage.get());
    subResp.getHandler().closeStream().get();
    subscriptionClosed.get(1, TimeUnit.SECONDS);
    subscriptionClosed = new CompletableFuture<>();
    receivedMessage = new CompletableFuture<>();
    CompletableFuture<String> finalReceivedMessage1 = receivedMessage;
    subResp = client.subscribeToTopic(new SubscribeToTopicRequest().withTopic("abc"), new StreamResponseHandler<SubscriptionResponseMessage>() {

        @Override
        public void onStreamEvent(SubscriptionResponseMessage streamEvent) {
            if (!Thread.currentThread().getName().contains("pool")) {
                finalReceivedMessage1.completeExceptionally(new RuntimeException("Ran on event loop instead of executor"));
            }
            finalReceivedMessage1.complete(new String(streamEvent.getBinaryMessage().getMessage()));
        }

        @Override
        public boolean onStreamError(Throwable error) {
            return false;
        }

        @Override
        public void onStreamClosed() {
        }
    });
    assertEquals("message", receivedMessage.get());
    subResp.getHandler().closeStream().get();
    subscriptionClosed.get(1, TimeUnit.SECONDS);
    subscriptionClosed = new CompletableFuture<>();
    receivedMessage = new CompletableFuture<>();
    CompletableFuture<String> finalReceivedMessage2 = receivedMessage;
    GreengrassCoreIPCClientV2.StreamingResponse<CompletableFuture<SubscribeToTopicResponse>, SubscribeToTopicResponseHandler> subRespAsync = client.subscribeToTopicAsync(new SubscribeToTopicRequest().withTopic("abc"), new StreamResponseHandler<SubscriptionResponseMessage>() {

        @Override
        public void onStreamEvent(SubscriptionResponseMessage streamEvent) {
            if (!Thread.currentThread().getName().contains("pool")) {
                finalReceivedMessage2.completeExceptionally(new RuntimeException("Ran on event loop instead of executor"));
            }
            finalReceivedMessage2.complete(new String(streamEvent.getBinaryMessage().getMessage()));
        }

        @Override
        public boolean onStreamError(Throwable error) {
            return false;
        }

        @Override
        public void onStreamClosed() {
        }
    });
    assertEquals("message", receivedMessage.get());
    subRespAsync.getHandler().closeStream().get();
    subscriptionClosed.get(1, TimeUnit.SECONDS);
    subscriptionClosed = new CompletableFuture<>();
    receivedMessage = new CompletableFuture<>();
    CompletableFuture<String> finalReceivedMessage3 = receivedMessage;
    subRespAsync = client.subscribeToTopicAsync(new SubscribeToTopicRequest().withTopic("abc"), (x) -> {
        if (!Thread.currentThread().getName().contains("pool")) {
            finalReceivedMessage3.completeExceptionally(new RuntimeException("Ran on event loop instead of executor"));
        }
        finalReceivedMessage3.complete(new String(x.getBinaryMessage().getMessage()));
    }, Optional.empty(), Optional.empty());
    assertEquals("message", receivedMessage.get());
    subRespAsync.getHandler().closeStream().get();
    subscriptionClosed.get(1, TimeUnit.SECONDS);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) GreengrassCoreIPCClientV2(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClientV2) SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) TimeoutException(java.util.concurrent.TimeoutException) BinaryMessage(software.amazon.awssdk.aws.greengrass.model.BinaryMessage) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) GreengrassCoreIPCService(greengrass.GreengrassCoreIPCService) CrtResource(software.amazon.awssdk.crt.CrtResource) Gson(com.google.gson.Gson) GeneratedAbstractCreateLocalDeploymentOperationHandler(greengrass.GeneratedAbstractCreateLocalDeploymentOperationHandler) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SubscribeToTopicResponseHandler(software.amazon.awssdk.aws.greengrass.SubscribeToTopicResponseHandler) Authorization(software.amazon.awssdk.eventstreamrpc.Authorization) StreamResponseHandler(software.amazon.awssdk.eventstreamrpc.StreamResponseHandler) RpcServer(software.amazon.awssdk.eventstreamrpc.RpcServer) IOException(java.io.IOException) EventStreamJsonMessage(software.amazon.awssdk.eventstreamrpc.model.EventStreamJsonMessage) EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AfterEach(org.junit.jupiter.api.AfterEach) SubscriptionResponseMessage(software.amazon.awssdk.aws.greengrass.model.SubscriptionResponseMessage) CreateLocalDeploymentRequest(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest) GeneratedAbstractSubscribeToTopicOperationHandler(greengrass.GeneratedAbstractSubscribeToTopicOperationHandler) CreateLocalDeploymentResponse(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse) Optional(java.util.Optional) SubscribeToTopicRequest(software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicRequest) SubscribeToTopicResponse(software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicResponse) GreengrassEventStreamConnectMessage(software.amazon.awssdk.eventstreamrpc.GreengrassEventStreamConnectMessage) SubscribeToTopicResponseHandler(software.amazon.awssdk.aws.greengrass.SubscribeToTopicResponseHandler) GreengrassCoreIPCClientV2(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClientV2) StreamResponseHandler(software.amazon.awssdk.eventstreamrpc.StreamResponseHandler) CreateLocalDeploymentRequest(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest) CompletableFuture(java.util.concurrent.CompletableFuture) CreateLocalDeploymentResponse(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse) SubscriptionResponseMessage(software.amazon.awssdk.aws.greengrass.model.SubscriptionResponseMessage) SubscribeToTopicResponse(software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicResponse) SubscribeToTopicRequest(software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicRequest) Test(org.junit.jupiter.api.Test)

Example 2 with CreateLocalDeploymentResponse

use of software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse in project aws-iot-device-sdk-java-v2 by aws.

the class GreengrassV2ClientTest method before.

@BeforeEach
public void before() throws IOException {
    port = randomPort();
    try (final EventLoopGroup elGroup = new EventLoopGroup(1);
        SocketOptions socketOptions = new SocketOptions()) {
        socketOptions.connectTimeoutMs = 3000;
        socketOptions.domain = SocketOptions.SocketDomain.IPv4;
        socketOptions.type = SocketOptions.SocketType.STREAM;
        GreengrassCoreIPCService service = new GreengrassCoreIPCService();
        service.setCreateLocalDeploymentHandler((c) -> new GeneratedAbstractCreateLocalDeploymentOperationHandler(c) {

            @Override
            protected void onStreamClosed() {
            }

            @Override
            public CreateLocalDeploymentResponse handleRequest(CreateLocalDeploymentRequest request) {
                return new CreateLocalDeploymentResponse().withDeploymentId("deployment");
            }

            @Override
            public void handleStreamEvent(EventStreamJsonMessage streamRequestEvent) {
            }
        });
        service.setSubscribeToTopicHandler((c) -> new GeneratedAbstractSubscribeToTopicOperationHandler(c) {

            @Override
            protected void onStreamClosed() {
                subscriptionClosed.complete(null);
            }

            @Override
            public SubscribeToTopicResponse handleRequest(SubscribeToTopicRequest request) {
                new Thread(() -> {
                    sendStreamEvent(new SubscriptionResponseMessage().withBinaryMessage(new BinaryMessage().withMessage("message".getBytes(StandardCharsets.UTF_8))));
                }).start();
                return new SubscribeToTopicResponse().withTopicName(request.getTopic());
            }

            @Override
            public void handleStreamEvent(EventStreamJsonMessage streamRequestEvent) {
            }
        });
        service.setAuthenticationHandler((headers, bytes) -> {
            authenticationRequest = new Gson().fromJson(new String(bytes), GreengrassEventStreamConnectMessage.class);
            return () -> "connected";
        });
        service.setAuthorizationHandler(authenticationData -> Authorization.ACCEPT);
        ipcServer = new RpcServer(elGroup, socketOptions, null, "127.0.0.1", port, service);
        ipcServer.runServer();
        client = GreengrassCoreIPCClientV2.builder().withPort(port).withSocketPath("127.0.0.1").withSocketDomain(SocketOptions.SocketDomain.IPv4).withAuthToken("myAuthToken").build();
    }
}
Also used : SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) Gson(com.google.gson.Gson) EventStreamJsonMessage(software.amazon.awssdk.eventstreamrpc.model.EventStreamJsonMessage) BinaryMessage(software.amazon.awssdk.aws.greengrass.model.BinaryMessage) CreateLocalDeploymentRequest(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest) EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) CreateLocalDeploymentResponse(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse) SubscriptionResponseMessage(software.amazon.awssdk.aws.greengrass.model.SubscriptionResponseMessage) GeneratedAbstractCreateLocalDeploymentOperationHandler(greengrass.GeneratedAbstractCreateLocalDeploymentOperationHandler) RpcServer(software.amazon.awssdk.eventstreamrpc.RpcServer) GreengrassCoreIPCService(greengrass.GreengrassCoreIPCService) GeneratedAbstractSubscribeToTopicOperationHandler(greengrass.GeneratedAbstractSubscribeToTopicOperationHandler) SubscribeToTopicResponse(software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicResponse) GreengrassEventStreamConnectMessage(software.amazon.awssdk.eventstreamrpc.GreengrassEventStreamConnectMessage) SubscribeToTopicRequest(software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CreateLocalDeploymentResponse

use of software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse 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 4 with CreateLocalDeploymentResponse

use of software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse 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)

Example 5 with CreateLocalDeploymentResponse

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

the class IPCCliTest method GIVEN_kernel_running_WHEN_multiple_deployments_scheduled_THEN_all_deployments_succeed.

@Test
@Order(9)
void GIVEN_kernel_running_WHEN_multiple_deployments_scheduled_THEN_all_deployments_succeed(ExtensionContext context) throws Exception {
    ignoreExceptionOfType(context, SdkClientException.class);
    ignoreExceptionOfType(context, PackageDownloadException.class);
    ignoreExceptionOfType(context, ComponentVersionNegotiationException.class);
    Path recipesPath = Paths.get(this.getClass().getResource("recipes").toURI());
    Path artifactsPath = Paths.get(this.getClass().getResource("artifacts").toURI());
    CreateLocalDeploymentRequest createLocalDeploymentRequest = new CreateLocalDeploymentRequest();
    createLocalDeploymentRequest.setGroupName("NewGroup");
    createLocalDeploymentRequest.setRootComponentVersionsToAdd(Collections.singletonMap("Component1", "1.0.0"));
    createLocalDeploymentRequest.setRecipeDirectoryPath(recipesPath.toAbsolutePath().toString());
    createLocalDeploymentRequest.setArtifactsDirectoryPath(artifactsPath.toAbsolutePath().toString());
    CreateLocalDeploymentResponse firstDeploymentResponse = clientConnection.createLocalDeployment(createLocalDeploymentRequest, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
    CountDownLatch waitForFirstDeployment = waitForDeploymentToBeSuccessful(firstDeploymentResponse.getDeploymentId(), kernel);
    createLocalDeploymentRequest = new CreateLocalDeploymentRequest();
    createLocalDeploymentRequest.setGroupName("NewGroup");
    createLocalDeploymentRequest.setRootComponentVersionsToAdd(Collections.singletonMap("ServiceName", "1.0.1"));
    createLocalDeploymentRequest.setRecipeDirectoryPath(recipesPath.toAbsolutePath().toString());
    createLocalDeploymentRequest.setArtifactsDirectoryPath(artifactsPath.toAbsolutePath().toString());
    CreateLocalDeploymentResponse secondDeploymentResponse = clientConnection.createLocalDeployment(createLocalDeploymentRequest, Optional.empty()).getResponse().get(DEFAULT_TIMEOUT_IN_SEC, TimeUnit.SECONDS);
    CountDownLatch waitForSecondDeployment = waitForDeploymentToBeSuccessful(secondDeploymentResponse.getDeploymentId(), kernel);
    assertTrue(waitForFirstDeployment.await(60, TimeUnit.SECONDS));
    assertTrue(waitForSecondDeployment.await(60, TimeUnit.SECONDS));
}
Also used : Path(java.nio.file.Path) CreateLocalDeploymentRequest(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest) CreateLocalDeploymentResponse(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse) CountDownLatch(java.util.concurrent.CountDownLatch) 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

CreateLocalDeploymentRequest (software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest)5 CreateLocalDeploymentResponse (software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse)5 Test (org.junit.jupiter.api.Test)4 Path (java.nio.file.Path)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Order (org.junit.jupiter.api.Order)3 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)3 Topic (com.aws.greengrass.config.Topic)2 Gson (com.google.gson.Gson)2 GeneratedAbstractCreateLocalDeploymentOperationHandler (greengrass.GeneratedAbstractCreateLocalDeploymentOperationHandler)2 GeneratedAbstractSubscribeToTopicOperationHandler (greengrass.GeneratedAbstractSubscribeToTopicOperationHandler)2 GreengrassCoreIPCService (greengrass.GreengrassCoreIPCService)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeUnit (java.util.concurrent.TimeUnit)2