use of software.amazon.awssdk.iot.iotjobs.model.RejectedError in project aws-iot-device-sdk-java-v2 by aws.
the class IotJobsClient method SubscribeToUpdateJobExecutionRejected.
/**
* Subscribes to the rejected topic for the UpdateJobExecution operation
*
* Once subscribed, `handler` is invoked each time a message matching
* the `topic` is received. It is possible for such messages to arrive before
* the SUBACK is received.
*
* AWS documentation: https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-updatejobexecution
*
* @param request Subscription request configuration
* @param qos Maximum requested QoS that server may use when sending messages to the client.
* The server may grant a lower QoS in the SUBACK
* @param handler callback function to invoke with messages received on the subscription topic
* @param exceptionHandler callback function to invoke if an exception occurred deserializing a message
*
* @return a future containing the MQTT packet id used to perform the subscribe operation
*/
public CompletableFuture<Integer> SubscribeToUpdateJobExecutionRejected(UpdateJobExecutionSubscriptionRequest request, QualityOfService qos, Consumer<RejectedError> handler, Consumer<Exception> exceptionHandler) {
String topic = "$aws/things/{thingName}/jobs/{jobId}/update/rejected";
if (request.jobId == null) {
CompletableFuture<Integer> result = new CompletableFuture<Integer>();
result.completeExceptionally(new MqttException("UpdateJobExecutionSubscriptionRequest must have a non-null jobId"));
return result;
}
topic = topic.replace("{jobId}", request.jobId);
if (request.thingName == null) {
CompletableFuture<Integer> result = new CompletableFuture<Integer>();
result.completeExceptionally(new MqttException("UpdateJobExecutionSubscriptionRequest must have a non-null thingName"));
return result;
}
topic = topic.replace("{thingName}", request.thingName);
Consumer<MqttMessage> messageHandler = (message) -> {
try {
String payload = new String(message.getPayload(), StandardCharsets.UTF_8);
RejectedError response = gson.fromJson(payload, RejectedError.class);
handler.accept(response);
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.accept(e);
}
}
};
return connection.subscribe(topic, qos, messageHandler);
}
use of software.amazon.awssdk.iot.iotjobs.model.RejectedError in project aws-iot-device-sdk-java-v2 by aws.
the class IotJobsClient method SubscribeToGetPendingJobExecutionsRejected.
/**
* Subscribes to the rejected topic for the GetPendingJobsExecutions operation
*
* Once subscribed, `handler` is invoked each time a message matching
* the `topic` is received. It is possible for such messages to arrive before
* the SUBACK is received.
*
* AWS documentation: https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-getpendingjobexecutions
*
* @param request Subscription request configuration
* @param qos Maximum requested QoS that server may use when sending messages to the client.
* The server may grant a lower QoS in the SUBACK
* @param handler callback function to invoke with messages received on the subscription topic
* @param exceptionHandler callback function to invoke if an exception occurred deserializing a message
*
* @return a future containing the MQTT packet id used to perform the subscribe operation
*/
public CompletableFuture<Integer> SubscribeToGetPendingJobExecutionsRejected(GetPendingJobExecutionsSubscriptionRequest request, QualityOfService qos, Consumer<RejectedError> handler, Consumer<Exception> exceptionHandler) {
String topic = "$aws/things/{thingName}/jobs/get/rejected";
if (request.thingName == null) {
CompletableFuture<Integer> result = new CompletableFuture<Integer>();
result.completeExceptionally(new MqttException("GetPendingJobExecutionsSubscriptionRequest must have a non-null thingName"));
return result;
}
topic = topic.replace("{thingName}", request.thingName);
Consumer<MqttMessage> messageHandler = (message) -> {
try {
String payload = new String(message.getPayload(), StandardCharsets.UTF_8);
RejectedError response = gson.fromJson(payload, RejectedError.class);
handler.accept(response);
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.accept(e);
}
}
};
return connection.subscribe(topic, qos, messageHandler);
}
use of software.amazon.awssdk.iot.iotjobs.model.RejectedError in project aws-iot-device-sdk-java-v2 by aws.
the class IotJobsClient method SubscribeToDescribeJobExecutionRejected.
/**
* Subscribes to the rejected topic for the DescribeJobExecution operation
*
* Once subscribed, `handler` is invoked each time a message matching
* the `topic` is received. It is possible for such messages to arrive before
* the SUBACK is received.
*
* AWS documentation: https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-describejobexecution
*
* @param request Subscription request configuration
* @param qos Maximum requested QoS that server may use when sending messages to the client.
* The server may grant a lower QoS in the SUBACK
* @param handler callback function to invoke with messages received on the subscription topic
* @param exceptionHandler callback function to invoke if an exception occurred deserializing a message
*
* @return a future containing the MQTT packet id used to perform the subscribe operation
*/
public CompletableFuture<Integer> SubscribeToDescribeJobExecutionRejected(DescribeJobExecutionSubscriptionRequest request, QualityOfService qos, Consumer<RejectedError> handler, Consumer<Exception> exceptionHandler) {
String topic = "$aws/things/{thingName}/jobs/{jobId}/get/rejected";
if (request.thingName == null) {
CompletableFuture<Integer> result = new CompletableFuture<Integer>();
result.completeExceptionally(new MqttException("DescribeJobExecutionSubscriptionRequest must have a non-null thingName"));
return result;
}
topic = topic.replace("{thingName}", request.thingName);
if (request.jobId == null) {
CompletableFuture<Integer> result = new CompletableFuture<Integer>();
result.completeExceptionally(new MqttException("DescribeJobExecutionSubscriptionRequest must have a non-null jobId"));
return result;
}
topic = topic.replace("{jobId}", request.jobId);
Consumer<MqttMessage> messageHandler = (message) -> {
try {
String payload = new String(message.getPayload(), StandardCharsets.UTF_8);
RejectedError response = gson.fromJson(payload, RejectedError.class);
handler.accept(response);
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.accept(e);
}
}
};
return connection.subscribe(topic, qos, messageHandler);
}
use of software.amazon.awssdk.iot.iotjobs.model.RejectedError in project aws-iot-device-sdk-java-v2 by aws.
the class IotJobsClient method SubscribeToStartNextPendingJobExecutionRejected.
/**
* Subscribes to the rejected topic for the StartNextPendingJobExecution operation
*
* Once subscribed, `handler` is invoked each time a message matching
* the `topic` is received. It is possible for such messages to arrive before
* the SUBACK is received.
*
* AWS documentation: https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-startnextpendingjobexecution
*
* @param request Subscription request configuration
* @param qos Maximum requested QoS that server may use when sending messages to the client.
* The server may grant a lower QoS in the SUBACK
* @param handler callback function to invoke with messages received on the subscription topic
* @param exceptionHandler callback function to invoke if an exception occurred deserializing a message
*
* @return a future containing the MQTT packet id used to perform the subscribe operation
*/
public CompletableFuture<Integer> SubscribeToStartNextPendingJobExecutionRejected(StartNextPendingJobExecutionSubscriptionRequest request, QualityOfService qos, Consumer<RejectedError> handler, Consumer<Exception> exceptionHandler) {
String topic = "$aws/things/{thingName}/jobs/start-next/rejected";
if (request.thingName == null) {
CompletableFuture<Integer> result = new CompletableFuture<Integer>();
result.completeExceptionally(new MqttException("StartNextPendingJobExecutionSubscriptionRequest must have a non-null thingName"));
return result;
}
topic = topic.replace("{thingName}", request.thingName);
Consumer<MqttMessage> messageHandler = (message) -> {
try {
String payload = new String(message.getPayload(), StandardCharsets.UTF_8);
RejectedError response = gson.fromJson(payload, RejectedError.class);
handler.accept(response);
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.accept(e);
}
}
};
return connection.subscribe(topic, qos, messageHandler);
}
use of software.amazon.awssdk.iot.iotjobs.model.RejectedError in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsHelperTest method GIVEN_jobsClient_and_mqttConnection_WHEN_mqtt_connected_THEN_update_jobStatus_failed.
@Test
void GIVEN_jobsClient_and_mqttConnection_WHEN_mqtt_connected_THEN_update_jobStatus_failed() throws Exception {
iotJobsHelper.postInject();
String TEST_JOB_ID = "statusUpdateFailure";
CompletableFuture cf = new CompletableFuture();
cf.complete(null);
ArgumentCaptor<UpdateJobExecutionSubscriptionRequest> requestArgumentCaptor = ArgumentCaptor.forClass(UpdateJobExecutionSubscriptionRequest.class);
when(mockIotJobsClientWrapper.PublishUpdateJobExecution(any(), any())).thenAnswer(invocationOnMock -> {
verify(mockIotJobsClientWrapper).SubscribeToUpdateJobExecutionRejected(requestArgumentCaptor.capture(), eq(QualityOfService.AT_LEAST_ONCE), rejectedErrorCaptor.capture());
Consumer<RejectedError> rejectedErrorConsumer = rejectedErrorCaptor.getValue();
RejectedError mockRejectError = new RejectedError();
mockRejectError.message = REJECTION_MESSAGE;
rejectedErrorConsumer.accept(mockRejectError);
return cf;
});
HashMap<String, String> statusDetails = new HashMap<>();
statusDetails.put("type", "test");
try {
iotJobsHelper.updateJobStatus(TEST_JOB_ID, JobStatus.IN_PROGRESS, statusDetails);
} catch (ExecutionException e) {
// verify that exception is thrown with the expected message
assertEquals(REJECTION_MESSAGE, e.getCause().getMessage());
}
UpdateJobExecutionSubscriptionRequest actualRequest = requestArgumentCaptor.getValue();
assertEquals(TEST_JOB_ID, actualRequest.jobId);
assertEquals(TEST_THING_NAME, actualRequest.thingName);
verify(mockWrapperMqttClientConnection).unsubscribe(eq(String.format(JOB_UPDATE_REJECTED_TOPIC, TEST_THING_NAME, TEST_JOB_ID)));
ArgumentCaptor<UpdateJobExecutionRequest> publishRequestCaptor = ArgumentCaptor.forClass(UpdateJobExecutionRequest.class);
verify(mockIotJobsClientWrapper).PublishUpdateJobExecution(publishRequestCaptor.capture(), eq(QualityOfService.AT_LEAST_ONCE));
UpdateJobExecutionRequest publishRequest = publishRequestCaptor.getValue();
assertEquals(TEST_JOB_ID, publishRequest.jobId);
assertEquals(JobStatus.IN_PROGRESS, publishRequest.status);
assertEquals(statusDetails, publishRequest.statusDetails);
assertEquals(TEST_THING_NAME, publishRequest.thingName);
}
Aggregations