Skip to content

Commit 46fa2ef

Browse files
MQTT5 Support (#340)
Add MQTT5 support to aws-iot-device-sdk-java-v2
1 parent 4b80a3d commit 46fa2ef

File tree

40 files changed

+2440
-48
lines changed

40 files changed

+2440
-48
lines changed

.github/workflows/ci.yml

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ env:
2424
CI_JOBS_ROLE: ${{ secrets.AWS_CI_JOBS_ROLE }}
2525
CI_FLEET_PROVISIONING_ROLE: ${{ secrets.AWS_CI_FLEET_PROVISIONING_ROLE }}
2626
CI_DEVICE_ADVISOR: ${{ secrets.AWS_CI_DEVICE_ADVISOR_ROLE }}
27+
CI_MQTT5_ROLE: ${{ secrets.AWS_CI_MQTT5_ROLE }}
2728

2829
jobs:
2930
linux-compat:
@@ -51,7 +52,7 @@ jobs:
5152
./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ matrix.image }} build -p ${{ env.PACKAGE_NAME }}
5253
# NOTE: we cannot run samples or DeviceAdvisor here due to container restrictions
5354

54-
55+
5556
raspberry:
5657
runs-on: ubuntu-20.04 # latest
5758
strategy:
@@ -74,7 +75,7 @@ jobs:
7475
run: |
7576
aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh
7677
./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ matrix.image }} build -p ${{ env.PACKAGE_NAME }}
77-
78+
7879
7980
windows:
8081
runs-on: windows-latest
@@ -100,6 +101,17 @@ jobs:
100101
run: |
101102
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
102103
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream
104+
- name: configure AWS credentials (MQTT5)
105+
uses: aws-actions/configure-aws-credentials@v1
106+
with:
107+
role-to-assume: ${{ env.CI_MQTT5_ROLE }}
108+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
109+
- name: MQTT5 tests
110+
shell: bash
111+
run: |
112+
source utils/mqtt5_test_setup.sh s3://iot-sdk-ci-bucket-us-east1/IotUsProdMqtt5EnvironmentVariables.txt us-east-1
113+
mvn test -Dtest=Mqtt5BuilderTest -DfailIfNoTests=false
114+
source utils/mqtt5_test_setup.sh s3://iot-sdk-ci-bucket-us-east1/IotUsProdMqtt5EnvironmentVariables.txt cleanup
103115
- name: Running samples in CI setup
104116
run: |
105117
python -m pip install boto3
@@ -115,6 +127,14 @@ jobs:
115127
- name: run Windows Certificate Connect sample
116128
run: |
117129
python ./utils/run_sample_ci.py --language Java --sample_file 'samples/WindowsCertConnect' --sample_region ${{ env.AWS_DEFAULT_REGION }} --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/PubSub/cert' --sample_secret_private_key 'ci/PubSub/key' --sample_run_certutil true --sample_main_class 'windowscertconnect.WindowsCertConnect'
130+
- name: configure AWS credentials (MQTT5)
131+
uses: aws-actions/configure-aws-credentials@v1
132+
with:
133+
role-to-assume: ${{ env.CI_MQTT5_ROLE }}
134+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
135+
- name: run MQTT5 PubSub sample
136+
run: |
137+
python ./utils/run_sample_ci.py --language Java --sample_file 'samples/Mqtt5/PubSub' --sample_region ${{ env.AWS_DEFAULT_REGION }} --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/mqtt5/us/mqtt5_thing/cert' --sample_secret_private_key 'ci/mqtt5/us/mqtt5_thing/key' --sample_main_class 'mqtt5.pubsub.PubSub'
118138
- name: configure AWS credentials (Device Advisor)
119139
uses: aws-actions/configure-aws-credentials@v1
120140
with:
@@ -149,6 +169,16 @@ jobs:
149169
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
150170
chmod a+x builder
151171
./builder build -p ${{ env.PACKAGE_NAME }} --spec=downstream
172+
- name: configure AWS credentials (MQTT5)
173+
uses: aws-actions/configure-aws-credentials@v1
174+
with:
175+
role-to-assume: ${{ env.CI_MQTT5_ROLE }}
176+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
177+
- name: MQTT5 tests
178+
run: |
179+
source utils/mqtt5_test_setup.sh s3://iot-sdk-ci-bucket-us-east1/IotUsProdMqtt5EnvironmentVariables.txt us-east-1
180+
mvn test -Dtest=Mqtt5BuilderTest -DfailIfNoTests=false
181+
source utils/mqtt5_test_setup.sh s3://iot-sdk-ci-bucket-us-east1/IotUsProdMqtt5EnvironmentVariables.txt cleanup
152182
- name: Running samples in CI setup
153183
run: |
154184
python3 -m pip install boto3
@@ -161,6 +191,14 @@ jobs:
161191
- name: run PubSub sample
162192
run: |
163193
python3 ./utils/run_sample_ci.py --language Java --sample_file 'samples/BasicPubSub' --sample_region ${{ env.AWS_DEFAULT_REGION }} --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/PubSub/cert' --sample_secret_private_key 'ci/PubSub/key' --sample_main_class 'pubsub.PubSub'
194+
- name: configure AWS credentials (MQTT5)
195+
uses: aws-actions/configure-aws-credentials@v1
196+
with:
197+
role-to-assume: ${{ env.CI_MQTT5_ROLE }}
198+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
199+
- name: run MQTT5 PubSub sample
200+
run: |
201+
python3 ./utils/run_sample_ci.py --language Java --sample_file 'samples/Mqtt5/PubSub' --sample_region ${{ env.AWS_DEFAULT_REGION }} --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/mqtt5/us/mqtt5_thing/cert' --sample_secret_private_key 'ci/mqtt5/us/mqtt5_thing/key' --sample_main_class 'mqtt5.pubsub.PubSub'
164202
- name: configure AWS credentials (Device Advisor)
165203
uses: aws-actions/configure-aws-credentials@v1
166204
with:
@@ -195,6 +233,16 @@ jobs:
195233
java -version
196234
mvn -B test -Daws.crt.debugnative=true
197235
mvn install -Dmaven.test.skip
236+
- name: configure AWS credentials (MQTT5)
237+
uses: aws-actions/configure-aws-credentials@v1
238+
with:
239+
role-to-assume: ${{ env.CI_MQTT5_ROLE }}
240+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
241+
- name: MQTT5 tests
242+
run: |
243+
source utils/mqtt5_test_setup.sh s3://iot-sdk-ci-bucket-us-east1/IotUsProdMqtt5EnvironmentVariables.txt us-east-1
244+
mvn test -Dtest=Mqtt5BuilderTest -DfailIfNoTests=false
245+
source utils/mqtt5_test_setup.sh s3://iot-sdk-ci-bucket-us-east1/IotUsProdMqtt5EnvironmentVariables.txt cleanup
198246
- name: Running samples in CI setup
199247
run: |
200248
python3 -m pip install boto3
@@ -206,6 +254,14 @@ jobs:
206254
- name: run PubSub sample
207255
run: |
208256
python3 ./utils/run_sample_ci.py --language Java --sample_file 'samples/BasicPubSub' --sample_region ${{ env.AWS_DEFAULT_REGION }} --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/PubSub/cert' --sample_secret_private_key 'ci/PubSub/key' --sample_main_class 'pubsub.PubSub'
257+
- name: configure AWS credentials (MQTT5)
258+
uses: aws-actions/configure-aws-credentials@v1
259+
with:
260+
role-to-assume: ${{ env.CI_MQTT5_ROLE }}
261+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
262+
- name: run MQTT5 PubSub sample
263+
run: |
264+
python3 ./utils/run_sample_ci.py --language Java --sample_file 'samples/Mqtt5/PubSub' --sample_region ${{ env.AWS_DEFAULT_REGION }} --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/mqtt5/us/mqtt5_thing/cert' --sample_secret_private_key 'ci/mqtt5/us/mqtt5_thing/key' --sample_main_class 'mqtt5.pubsub.PubSub'
209265
- name: configure AWS credentials (Device Advisor)
210266
uses: aws-actions/configure-aws-credentials@v1
211267
with:
@@ -331,3 +387,11 @@ jobs:
331387
Sample_UUID=$(python3 -c "import uuid; print (uuid.uuid4())")
332388
python3 ./utils/run_sample_ci.py --language Java --sample_file 'samples/Identity' --sample_region ${{ env.AWS_DEFAULT_REGION }} --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/FleetProvisioning/cert' --sample_secret_private_key 'ci/FleetProvisioning/key' --sample_arguments "--template_name CI_FleetProvisioning_Template --template_parameters '{SerialNumber:${Sample_UUID}}'" --sample_main_class 'identity.FleetProvisioningSample'
333389
python3 utils/delete_iot_thing_ci.py --thing_name "Fleet_Thing_${Sample_UUID}" --region "us-east-1"
390+
- name: configure AWS credentials (MQTT5)
391+
uses: aws-actions/configure-aws-credentials@v1
392+
with:
393+
role-to-assume: ${{ env.CI_MQTT5_ROLE }}
394+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
395+
- name: run MQTT5 PubSub sample
396+
run: |
397+
python3 ./utils/run_sample_ci.py --language Java --sample_file 'samples/Mqtt5/PubSub' --sample_region ${{ env.AWS_DEFAULT_REGION }} --sample_secret_endpoint 'ci/endpoint' --sample_secret_certificate 'ci/mqtt5/us/mqtt5_thing/cert' --sample_secret_private_key 'ci/mqtt5/us/mqtt5_thing/key' --sample_main_class 'mqtt5.pubsub.PubSub'

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ mvn clean install
8080
mkdir sdk-workspace
8181
cd sdk-workspace
8282
# Clone the CRT repository
83-
# (Use the latest version of the CRT here instead of "v0.18.0")
84-
git clone --branch v0.19.11 --recurse-submodules https://github.com/awslabs/aws-crt-java.git
83+
# (Use the latest version of the CRT here instead of "v0.20.0")
84+
git clone --branch v0.20.0 --recurse-submodules https://github.com/awslabs/aws-crt-java.git
8585
cd aws-crt-java
8686
# Compile and install the CRT
8787
mvn install -Dmaven.test.skip=true
@@ -102,8 +102,8 @@ NOTE: The shadow sample does not currently complete on android due to its depend
102102
mkdir sdk-workspace
103103
cd sdk-workspace
104104
# Clone the CRT repository
105-
# (Use the latest version of the CRT here instead of "v0.18.0")
106-
git clone --branch v0.19.11 --recurse-submodules https://github.com/awslabs/aws-crt-java.git
105+
# (Use the latest version of the CRT here instead of "v0.20.0")
106+
git clone --branch v0.20.0 --recurse-submodules https://github.com/awslabs/aws-crt-java.git
107107
# Compile and install the CRT for Android
108108
cd aws-crt-java/android
109109
./gradlew connectedCheck # optional, will run the unit tests on any connected devices/emulators
@@ -127,11 +127,11 @@ repositories {
127127
}
128128
129129
dependencies {
130-
implementation 'software.amazon.awssdk.crt:android:0.19.11'
130+
implementation 'software.amazon.awssdk.crt:android:0.20.0'
131131
}
132132
```
133133

134-
Replace `0.18.0` in `software.amazon.awssdk.crt:android:0.18.0` with the latest version of the CRT.
134+
Replace `0.20.0` in `software.amazon.awssdk.crt:android:0.20.0` with the latest version of the CRT.
135135
Look up the latest CRT version here: https://github.com/awslabs/aws-crt-java/releases
136136

137137
#### Caution
@@ -149,6 +149,7 @@ Please make sure to check out our resources too before opening an issue:
149149

150150
* Our [FAQ](./documents/FAQ.md)
151151
* Our [Developer Guide](https://docs.aws.amazon.com/iot/latest/developerguide/what-is-aws-iot.html) ([source](https://github.com/awsdocs/aws-iot-docs))
152+
* [MQTT5 User Guide](./documents/MQTT5_Userguide.md)
152153
* Check for similar [Issues](https://github.com/aws/aws-iot-device-sdk-java-v2/issues)
153154
* [AWS IoT Core Documentation](https://docs.aws.amazon.com/iot/)
154155
* [Dev Blog](https://aws.amazon.com/blogs/?awsf.blog-master-iot=category-internet-of-things%23amazon-freertos%7Ccategory-internet-of-things%23aws-greengrass%7Ccategory-internet-of-things%23aws-iot-analytics%7Ccategory-internet-of-things%23aws-iot-button%7Ccategory-internet-of-things%23aws-iot-device-defender%7Ccategory-internet-of-things%23aws-iot-device-management%7Ccategory-internet-of-things%23aws-iot-platform)

android/iotdevicesdk/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ repositories {
9191
}
9292

9393
dependencies {
94-
api 'software.amazon.awssdk.crt:aws-crt-android:0.19.11'
94+
api 'software.amazon.awssdk.crt:aws-crt-android:0.20.0'
9595
implementation 'org.slf4j:slf4j-api:1.7.30'
9696
implementation 'com.google.code.gson:gson:2.9.0'
9797
implementation 'androidx.appcompat:appcompat:1.1.0'

builder.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"build_steps": [
77
"mvn -B compile"
88
],
9-
"test_steps": [
10-
],
9+
"test_steps": [],
1110
"imports": [
1211
"JDK8"
1312
],
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
env
6+
7+
pushd $CODEBUILD_SRC_DIR/samples/CustomAuthorizerConnect
8+
9+
ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "unit-test/endpoint" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g')
10+
11+
AUTH_NAME=$(aws secretsmanager get-secret-value --secret-id "unit-test/authorizer-name" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g')
12+
AUTH_PASSWORD=$(aws secretsmanager get-secret-value --secret-id "unit-test/authorizer-password" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g')
13+
14+
mvn compile
15+
16+
echo "Mqtt Connect with Custom Authorizer test"
17+
mvn exec:java -Dexec.mainClass="customauthorizerconnect.CustomAuthorizerConnect" -Daws.crt.ci="True" -Dexec.arguments="--endpoint,$ENDPOINT,--custom_auth_authorizer_name,$AUTH_NAME,--custom_auth_password,$AUTH_PASSWORD"
18+
19+
popd
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
env
6+
7+
pushd $CODEBUILD_SRC_DIR/samples/CustomKeyOpsPubSub
8+
9+
ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "unit-test/endpoint" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g')
10+
11+
mvn compile
12+
13+
echo "Custom Key Ops test"
14+
mvn exec:java -Dexec.mainClass="customkeyopspubsub.CustomKeyOpsPubSub" -Daws.crt.ci="True" -Dexec.arguments="--endpoint,$ENDPOINT,--key,/tmp/privatekey_p8.pem,--cert,/tmp/certificate.pem"
15+
16+
popd

codebuild/samples/linux-smoke-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ phases:
2424
- $CODEBUILD_SRC_DIR/codebuild/samples/pkcs11-connect-linux.sh
2525
- $CODEBUILD_SRC_DIR/codebuild/samples/pubsub-linux.sh
2626
- $CODEBUILD_SRC_DIR/codebuild/samples/shadow-linux.sh
27+
- $CODEBUILD_SRC_DIR/codebuild/samples/pubsub-mqtt5-linux.sh
2728
post_build:
2829
commands:
2930
- echo Build completed on `date`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -o pipefail
5+
6+
env
7+
8+
pushd $CODEBUILD_SRC_DIR/samples/Mqtt5/PubSub
9+
10+
ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "ci/endpoint" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g')
11+
12+
mvn compile
13+
14+
echo "MQTT5 PubSub test"
15+
mvn exec:java -Dexec.mainClass="mqtt5.pubsub.PubSub" -Daws.crt.ci="True" -Dexec.arguments="--endpoint,$ENDPOINT,--key,/tmp/privatekey.pem,--cert,/tmp/certificate.pem"
16+
17+
popd

deviceadvisor/script/DATestRun.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def sleep_with_backoff(base, max):
131131
create_cert_response = client.create_keys_and_certificate(
132132
setAsActive=True
133133
)
134-
135134
# write certificate to file
136135
f = open(certificate_path, "w")
137136
f.write(create_cert_response['certificatePem'])
@@ -255,7 +254,6 @@ def sleep_with_backoff(base, max):
255254
suiteDefinitionId=DATestConfig['test_suite_ids'][test_name],
256255
suiteRunId=test_start_response['suiteRunId']
257256
)
258-
259257
# If the status is PENDING or the responds does not loaded, the test suite is still loading
260258
if (test_result_responds['status'] == 'PENDING' or
261259
len(test_result_responds['testResult']['groups']) == 0 or # test group has not been loaded

deviceadvisor/tests/DATestUtils/DATestUtils.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,18 @@ public static Boolean init(TestType type)
3434
thing_name = System.getenv(ENV_THING_NAME);
3535
shadowProperty = System.getenv(ENV_SHADOW_PROPERTY);
3636
shadowValue = System.getenv(ENV_SHADOW_VALUE_SET);
37-
3837
if (endpoint.isEmpty() || certificatePath.isEmpty() || keyPath.isEmpty())
3938
{
4039
return false;
4140
}
42-
4341
if (topic.isEmpty() && type == TestType.SUB_PUB)
4442
{
4543
return false;
4644
}
47-
4845
if ((thing_name.isEmpty() || shadowProperty.isEmpty() || shadowValue.isEmpty()) && type == TestType.SHADOW)
4946
{
5047
return false;
5148
}
52-
5349
return true;
5450

5551
}

0 commit comments

Comments
 (0)