Search in sources :

Example 1 with JobExecutionData

use of software.amazon.awssdk.iot.iotjobs.model.JobExecutionData in project aws-greengrass-nucleus by aws-greengrass.

the class IotJobsHelperTest method GIVEN_ongoing_job_deployment_with_queued_job_in_cloud_WHEN_cancel_notification_THEN_cancel_current_deployment.

@Test
void GIVEN_ongoing_job_deployment_with_queued_job_in_cloud_WHEN_cancel_notification_THEN_cancel_current_deployment() throws Exception {
    iotJobsHelper.postInject();
    String TEST_JOB_ID = "jobToBeCancelled";
    iotJobsHelper.setDeploymentQueue(mockDeploymentQueue);
    when(mockDeploymentQueue.isEmpty()).thenReturn(true);
    CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.completedFuture(1);
    when(mockIotJobsClientWrapper.SubscribeToJobExecutionsChangedEvents(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
    when(mockIotJobsClientWrapper.SubscribeToDescribeJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
    when(mockIotJobsClientWrapper.SubscribeToDescribeJobExecutionRejected(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
    DeploymentTaskMetadata mockCurrentDeploymentTaskMetadata = mock(DeploymentTaskMetadata.class);
    when(mockCurrentDeploymentTaskMetadata.getDeploymentType()).thenReturn(IOT_JOBS);
    when(mockCurrentDeploymentTaskMetadata.isCancellable()).thenReturn(true);
    when(mockDeploymentService.getCurrentDeploymentTaskMetadata()).thenReturn(mockCurrentDeploymentTaskMetadata);
    iotJobsHelper.subscribeToJobsTopics();
    verify(mockIotJobsClientWrapper, times(2)).SubscribeToDescribeJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), describeJobResponseCaptor.capture());
    JobExecutionData jobExecutionData = new JobExecutionData();
    jobExecutionData.jobId = TEST_JOB_ID;
    jobExecutionData.status = JobStatus.QUEUED;
    jobExecutionData.queuedAt = new Timestamp(new Date());
    HashMap<String, Object> sampleJobDocument = new HashMap<>();
    sampleJobDocument.put("DeploymentId", TEST_JOB_ID);
    jobExecutionData.jobDocument = sampleJobDocument;
    DescribeJobExecutionResponse describeJobExecutionResponse = new DescribeJobExecutionResponse();
    describeJobExecutionResponse.execution = jobExecutionData;
    describeJobResponseCaptor.getValue().accept(describeJobExecutionResponse);
    ArgumentCaptor<Deployment> deploymentArgumentCaptor = ArgumentCaptor.forClass(Deployment.class);
    verify(mockDeploymentQueue, times(2)).offer(deploymentArgumentCaptor.capture());
    // First queued deployment should be for cancellation and then next one for next queued job
    List<Deployment> actualDeployments = deploymentArgumentCaptor.getAllValues();
    assertTrue(actualDeployments.get(0).isCancelled());
    assertEquals(IOT_JOBS, actualDeployments.get(0).getDeploymentType());
    assertFalse(actualDeployments.get(1).isCancelled());
    assertEquals(IOT_JOBS, actualDeployments.get(1).getDeploymentType());
    assertEquals(TEST_JOB_ID, actualDeployments.get(1).getId());
}
Also used : JobExecutionData(software.amazon.awssdk.iot.iotjobs.model.JobExecutionData) HashMap(java.util.HashMap) DescribeJobExecutionResponse(software.amazon.awssdk.iot.iotjobs.model.DescribeJobExecutionResponse) Deployment(com.aws.greengrass.deployment.model.Deployment) Timestamp(software.amazon.awssdk.iot.Timestamp) Date(java.util.Date) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeploymentTaskMetadata(com.aws.greengrass.deployment.model.DeploymentTaskMetadata) Test(org.junit.jupiter.api.Test)

Example 2 with JobExecutionData

use of software.amazon.awssdk.iot.iotjobs.model.JobExecutionData in project aws-greengrass-nucleus by aws-greengrass.

the class IotJobsHelperTest method GIVEN_connected_to_iot_WHEN_subscribe_to_jobs_topics_THEN_get_job_description.

@Test
void GIVEN_connected_to_iot_WHEN_subscribe_to_jobs_topics_THEN_get_job_description() throws Exception {
    iotJobsHelper.postInject();
    String TEST_JOB_ID = "jobToReceive";
    iotJobsHelper.setDeploymentQueue(mockDeploymentQueue);
    CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.completedFuture(1);
    when(mockIotJobsClientWrapper.SubscribeToJobExecutionsChangedEvents(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
    when(mockIotJobsClientWrapper.SubscribeToDescribeJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
    when(mockIotJobsClientWrapper.SubscribeToDescribeJobExecutionRejected(any(), eq(QualityOfService.AT_LEAST_ONCE), any())).thenReturn(integerCompletableFuture);
    when(mockDeploymentService.getCurrentDeploymentTaskMetadata()).thenReturn(null);
    iotJobsHelper.subscribeToJobsTopics();
    verify(mockIotJobsClientWrapper, times(2)).SubscribeToDescribeJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), describeJobResponseCaptor.capture());
    verify(mockIotJobsClientWrapper, times(2)).SubscribeToDescribeJobExecutionRejected(any(), eq(QualityOfService.AT_LEAST_ONCE), rejectedErrorCaptor.capture());
    JobExecutionData jobExecutionData = new JobExecutionData();
    jobExecutionData.jobId = TEST_JOB_ID;
    jobExecutionData.status = JobStatus.QUEUED;
    jobExecutionData.queuedAt = new Timestamp(new Date());
    HashMap<String, Object> sampleJobDocument = new HashMap<>();
    sampleJobDocument.put("DeploymentId", TEST_JOB_ID);
    jobExecutionData.jobDocument = sampleJobDocument;
    DescribeJobExecutionResponse describeJobExecutionResponse = new DescribeJobExecutionResponse();
    describeJobExecutionResponse.execution = jobExecutionData;
    describeJobResponseCaptor.getValue().accept(describeJobExecutionResponse);
    ArgumentCaptor<Deployment> deploymentArgumentCaptor = ArgumentCaptor.forClass(Deployment.class);
    verify(mockDeploymentQueue).offer(deploymentArgumentCaptor.capture());
    Deployment actualDeployment = deploymentArgumentCaptor.getValue();
    assertEquals(TEST_JOB_ID, actualDeployment.getId());
    assertEquals(IOT_JOBS, actualDeployment.getDeploymentType());
    assertEquals("{\"DeploymentId\":\"jobToReceive\"}", actualDeployment.getDeploymentDocument());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JobExecutionData(software.amazon.awssdk.iot.iotjobs.model.JobExecutionData) HashMap(java.util.HashMap) DescribeJobExecutionResponse(software.amazon.awssdk.iot.iotjobs.model.DescribeJobExecutionResponse) Deployment(com.aws.greengrass.deployment.model.Deployment) Timestamp(software.amazon.awssdk.iot.Timestamp) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with JobExecutionData

use of software.amazon.awssdk.iot.iotjobs.model.JobExecutionData in project aws-greengrass-nucleus by aws-greengrass.

the class IotJobsHelperTest method getMockJobExecutionData.

private JobExecutionData getMockJobExecutionData(String jobId, Timestamp ts) {
    JobExecutionData jobExecutionData = new JobExecutionData();
    jobExecutionData.jobId = jobId;
    jobExecutionData.status = JobStatus.QUEUED;
    jobExecutionData.queuedAt = ts;
    HashMap<String, Object> sampleJobDocument = new HashMap<>();
    sampleJobDocument.put("DeploymentId", jobId);
    jobExecutionData.jobDocument = sampleJobDocument;
    return jobExecutionData;
}
Also used : JobExecutionData(software.amazon.awssdk.iot.iotjobs.model.JobExecutionData) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)3 JobExecutionData (software.amazon.awssdk.iot.iotjobs.model.JobExecutionData)3 Deployment (com.aws.greengrass.deployment.model.Deployment)2 Date (java.util.Date)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.jupiter.api.Test)2 Timestamp (software.amazon.awssdk.iot.Timestamp)2 DescribeJobExecutionResponse (software.amazon.awssdk.iot.iotjobs.model.DescribeJobExecutionResponse)2 DeploymentTaskMetadata (com.aws.greengrass.deployment.model.DeploymentTaskMetadata)1