Skip to content

Commit cf561f1

Browse files
committed
First compilable client
1 parent 76d5c20 commit cf561f1

12 files changed

+888
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*
5+
* This file is generated.
6+
*/
7+
8+
package software.amazon.awssdk.iot.iotcommands;
9+
10+
import software.amazon.awssdk.iot.iotcommands.model.CommandExecutionEvent;
11+
import software.amazon.awssdk.iot.iotcommands.model.CommandExecutionStatus;
12+
import software.amazon.awssdk.iot.iotcommands.model.CommandExecutionsSubscriptionRequest;
13+
import software.amazon.awssdk.iot.iotcommands.model.DeviceType;
14+
import software.amazon.awssdk.iot.iotcommands.model.RejectedErrorCode;
15+
import software.amazon.awssdk.iot.iotcommands.model.StatusReason;
16+
import software.amazon.awssdk.iot.iotcommands.model.UpdateCommandExecutionRequest;
17+
import software.amazon.awssdk.iot.iotcommands.model.UpdateCommandExecutionResponse;
18+
import software.amazon.awssdk.iot.iotcommands.model.V2ErrorResponse;
19+
20+
import java.nio.charset.StandardCharsets;
21+
22+
import software.amazon.awssdk.crt.mqtt.MqttClientConnection;
23+
import software.amazon.awssdk.crt.mqtt.QualityOfService;
24+
import software.amazon.awssdk.crt.mqtt.MqttException;
25+
import software.amazon.awssdk.crt.mqtt.MqttMessage;
26+
27+
import software.amazon.awssdk.iot.Timestamp;
28+
import software.amazon.awssdk.iot.EnumSerializer;
29+
30+
import com.google.gson.Gson;
31+
import com.google.gson.GsonBuilder;
32+
33+
import java.io.UnsupportedEncodingException;
34+
import java.nio.ByteBuffer;
35+
import java.util.concurrent.CompletableFuture;
36+
import java.util.function.Consumer;
37+
38+
/**
39+
* The AWS IoT commands service is used to send an instruction from the cloud to a device that is connected to AWS IoT.
40+
*
41+
* AWS documentation: https://docs.aws.amazon.com/iot/latest/developerguide/iot-remote-command.html
42+
*
43+
*/
44+
public class IotCommandsClient {
45+
private MqttClientConnection connection = null;
46+
private final Gson gson = getGson();
47+
48+
/**
49+
* Constructs a new IotCommandsClient
50+
* @param connection The connection to use
51+
*/
52+
public IotCommandsClient(MqttClientConnection connection) {
53+
this.connection = connection;
54+
}
55+
56+
private Gson getGson() {
57+
GsonBuilder gson = new GsonBuilder();
58+
gson.disableHtmlEscaping();
59+
gson.registerTypeAdapter(Timestamp.class, new Timestamp.Serializer());
60+
gson.registerTypeAdapter(Timestamp.class, new Timestamp.Deserializer());
61+
addTypeAdapters(gson);
62+
return gson.create();
63+
}
64+
65+
private void addTypeAdapters(GsonBuilder gson) {
66+
gson.registerTypeAdapter(CommandExecutionStatus.class, new EnumSerializer<CommandExecutionStatus>());
67+
gson.registerTypeAdapter(DeviceType.class, new EnumSerializer<DeviceType>());
68+
gson.registerTypeAdapter(RejectedErrorCode.class, new EnumSerializer<RejectedErrorCode>());
69+
}
70+
71+
}

sdk/src/main/java/software/amazon/awssdk/iot/iotcommands/IotCommandsV2Client.java

Lines changed: 340 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*
5+
* This file is generated.
6+
*/
7+
8+
package software.amazon.awssdk.iot.iotcommands.model;
9+
10+
11+
/**
12+
* Sent whenever a command execution is added for a thing or a client.
13+
*
14+
*/
15+
public class CommandExecutionEvent {
16+
17+
/**
18+
* Opaque data containing instructions sent from the IoT commands service.
19+
*
20+
*/
21+
public byte[] payload;
22+
23+
24+
/**
25+
* Unique ID for the specific execution of a command. A command can have multiple executions, each with a unique ID.
26+
*
27+
*/
28+
public String executionId;
29+
30+
31+
/**
32+
* Data format of the payload. It is supposed to be a MIME type (IANA media type), but can be an arbitrary string.
33+
*
34+
*/
35+
public String contentType;
36+
37+
38+
/**
39+
* Number of seconds before the IoT commands service decides that this command execution is timed out.
40+
*
41+
*/
42+
public Integer timeout;
43+
44+
45+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*
5+
* This file is generated.
6+
*/
7+
8+
package software.amazon.awssdk.iot.iotcommands.model;
9+
10+
/**
11+
* The status of the command execution.
12+
*
13+
*/
14+
public enum CommandExecutionStatus {
15+
16+
/**
17+
* Enum value is an unknown value
18+
*/
19+
UNKNOWN_ENUM_VALUE("UNKNOWN_ENUM_VALUE"),
20+
21+
/**
22+
* The device is currently processing the received command.
23+
*/
24+
IN_PROGRESS("IN_PROGRESS"),
25+
26+
/**
27+
* The device successfully completed the command.
28+
*/
29+
SUCCEEDED("SUCCEEDED"),
30+
31+
/**
32+
* The device failed to complete the command.
33+
*/
34+
FAILED("FAILED"),
35+
36+
/**
37+
* The device received an invalid or incomplete request.
38+
*/
39+
REJECTED("REJECTED"),
40+
41+
/**
42+
* When the command execution timed out, this status can be used to provide additional information in the statusReason field in the UpdateCommandExecutionRequest request.
43+
*/
44+
TIMED_OUT("TIMED_OUT");
45+
46+
private String value;
47+
48+
private CommandExecutionStatus(String value) {
49+
this.value = value;
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return value;
55+
}
56+
57+
/**
58+
* Returns The enum associated with the given string or UNKNOWN_ENUM_VALUE
59+
* if no enum is found.
60+
* @param val The string to use
61+
* @return The enum associated with the string or UNKNOWN_ENUM_VALUE
62+
*/
63+
static CommandExecutionStatus fromString(String val) {
64+
for (CommandExecutionStatus e : CommandExecutionStatus.class.getEnumConstants()) {
65+
if (e.toString().compareTo(val) == 0) {
66+
return e;
67+
}
68+
}
69+
return UNKNOWN_ENUM_VALUE;
70+
}
71+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*
5+
* This file is generated.
6+
*/
7+
8+
package software.amazon.awssdk.iot.iotcommands.model;
9+
10+
import software.amazon.awssdk.iot.iotcommands.model.DeviceType;
11+
12+
/**
13+
* Data needed to subscribe to CommandExecution events.
14+
*
15+
*/
16+
public class CommandExecutionsSubscriptionRequest {
17+
18+
/**
19+
* The type of a target device. Determine if the device should subscribe for commands addressed to an IoT Thing or MQTT client.
20+
*
21+
*/
22+
public DeviceType deviceType;
23+
24+
25+
/**
26+
* Depending on device type value, this field is either an IoT Thing name or a client ID.
27+
*
28+
*/
29+
public String deviceId;
30+
31+
32+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*
5+
* This file is generated.
6+
*/
7+
8+
package software.amazon.awssdk.iot.iotcommands.model;
9+
10+
/**
11+
* Possible device types for command executions.
12+
*
13+
*/
14+
public enum DeviceType {
15+
16+
/**
17+
* Enum value is an unknown value
18+
*/
19+
UNKNOWN_ENUM_VALUE("UNKNOWN_ENUM_VALUE"),
20+
21+
/**
22+
* A target for the commands is an IoT Thing.
23+
*/
24+
THING("things"),
25+
26+
/**
27+
* A target for the commands is an MQTT client ID.
28+
*/
29+
CLIENT("clients");
30+
31+
private String value;
32+
33+
private DeviceType(String value) {
34+
this.value = value;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return value;
40+
}
41+
42+
/**
43+
* Returns The enum associated with the given string or UNKNOWN_ENUM_VALUE
44+
* if no enum is found.
45+
* @param val The string to use
46+
* @return The enum associated with the string or UNKNOWN_ENUM_VALUE
47+
*/
48+
static DeviceType fromString(String val) {
49+
for (DeviceType e : DeviceType.class.getEnumConstants()) {
50+
if (e.toString().compareTo(val) == 0) {
51+
return e;
52+
}
53+
}
54+
return UNKNOWN_ENUM_VALUE;
55+
}
56+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*
5+
* This file is generated.
6+
*/
7+
8+
package software.amazon.awssdk.iot.iotcommands.model;
9+
10+
/**
11+
* A value indicating the kind of error encountered while processing an AWS IoT Commands request
12+
*
13+
*/
14+
public enum RejectedErrorCode {
15+
16+
/**
17+
* Enum value is an unknown value
18+
*/
19+
UNKNOWN_ENUM_VALUE("UNKNOWN_ENUM_VALUE"),
20+
21+
/**
22+
* The request was sent to a topic in the AWS IoT Commands namespace that does not map to any API.
23+
*/
24+
INVALID_TOPIC("InvalidTopic"),
25+
26+
/**
27+
* The contents of the request could not be interpreted as valid UTF-8-encoded JSON.
28+
*/
29+
INVALID_JSON("InvalidJson"),
30+
31+
/**
32+
* The contents of the request were invalid. The message contains details about the error.
33+
*/
34+
INVALID_REQUEST("InvalidRequest"),
35+
36+
/**
37+
* An update attempted to change the command execution to a state that is invalid because of the command execution's current state. In this case, the body of the error message also contains the executionState field.
38+
*/
39+
INVALID_STATE_TRANSITION("InvalidStateTransition"),
40+
41+
/**
42+
* The CommandExecution specified by the request topic does not exist.
43+
*/
44+
RESOURCE_NOT_FOUND("ResourceNotFound"),
45+
46+
/**
47+
* The expected version specified in the request does not match the version of the command execution in the AWS IoT Commands service. In this case, the body of the error message also contains the executionState field.
48+
*/
49+
VERSION_MISMATCH("VersionMismatch"),
50+
51+
/**
52+
* There was an internal error during the processing of the request.
53+
*/
54+
INTERNAL_ERROR("InternalError"),
55+
56+
/**
57+
* The request was throttled.
58+
*/
59+
REQUEST_THROTTLED("RequestThrottled"),
60+
61+
/**
62+
* Occurs when a command to describe a command is performed on a command that is in a terminal state.
63+
*/
64+
TERMINAL_STATE_REACHED("TerminalStateReached");
65+
66+
private String value;
67+
68+
private RejectedErrorCode(String value) {
69+
this.value = value;
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return value;
75+
}
76+
77+
/**
78+
* Returns The enum associated with the given string or UNKNOWN_ENUM_VALUE
79+
* if no enum is found.
80+
* @param val The string to use
81+
* @return The enum associated with the string or UNKNOWN_ENUM_VALUE
82+
*/
83+
static RejectedErrorCode fromString(String val) {
84+
for (RejectedErrorCode e : RejectedErrorCode.class.getEnumConstants()) {
85+
if (e.toString().compareTo(val) == 0) {
86+
return e;
87+
}
88+
}
89+
return UNKNOWN_ENUM_VALUE;
90+
}
91+
}

0 commit comments

Comments
 (0)