-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated IoT Central Java SDK examples for 2021-06-01 release (#18)
* Updated java samples for latest working IoT Central SDK version 1.0.0-beta.2 with support for managed identity and containing other improvements. Switched from gradle to maven. Updated readme.md.
- Loading branch information
Showing
10 changed files
with
559 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.classpath | ||
.gradle/ | ||
.project | ||
.settings/ | ||
bin/ | ||
build/ | ||
build/ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "automatic" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
# Azure IoT Central ARM Java SDK samples | ||
# Azure IoT Central Java SDK Samples for Management APIs | ||
|
||
Sample code for using [com.microsoft.azure.iotcentral.v2018_09_01:azure-mgmt-iotcentral](https://search.maven.org/artifact/com.microsoft.azure.iotcentral.v2018_09_01/azure-mgmt-iotcentral/1.0.0/jar) SDK provided by [Microsoft Azure](https://github.com/Azure). This sample code will check if the resource name is available, create or update an app, retrieve app information, update app, list all the apps that belongs to the specific resource group, and finally delete the app if uncommented. | ||
Sample code for using Azure IoT Central Management Plane APIs. | ||
|
||
## Get started | ||
|
||
### Prerequisites | ||
- [Java JDK or JRE](https://www.oracle.com/technetwork/java/javase/downloads/index.html) | ||
- [Gradle](https://gradle.org/install/) | ||
- A resource group called **myResourceGroup** in your Azure subscription | ||
- [Maven](http://maven.apache.org/install.html) | ||
- A service principal and a resource group to work with. Follow [these instructions](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). | ||
|
||
### Installation | ||
To begin, simply clone this repository onto your local machine and build it using Gradle. | ||
### SDK version | ||
|
||
``` | ||
gradle build | ||
``` | ||
The support SDK version is [1.0.0-beta.2](https://github.com/Azure/azure-sdk-for-java/tree/azure-resourcemanager-iotcentral_1.0.0-beta.2/sdk/iotcentral/azure-resourcemanager-iotcentral). | ||
|
||
See more samples on using IoT Central APIs [here](https://github.com/Azure/azure-sdk-for-java/blob/azure-resourcemanager-iotcentral_1.0.0-beta.2/sdk/iotcentral/azure-resourcemanager-iotcentral/SAMPLE.md). | ||
|
||
### Usage | ||
Make sure you head over to the src\main\java\sample\IoTCentralExample.java to change the configuration to the one that is shown on your [Microsoft Azure Portal](https://portal.azure.com). | ||
To begin, clone this repository, update the authentication settings in IotCentralMgmtApiSampleBase.java, the app configurations in Main.java, and compile/execute the project. | ||
|
||
``` | ||
gradle run | ||
cd src | ||
mvn clean compile exec:java | ||
``` | ||
|
||
See SampleOutput.txt in the basedir for output from the project execution. | ||
|
||
Continue developing using the samples shown [here](https://github.com/Azure/azure-sdk-for-java/blob/azure-resourcemanager-iotcentral_1.0.0-beta.2/sdk/iotcentral/azure-resourcemanager-iotcentral/SAMPLE.md). | ||
|
||
### Additional References: | ||
Overview: Use the Azure SDK for Java | Microsoft Docs | ||
Getting started: Get started with the Azure SDK for Java | Microsoft Docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
[INFO] Scanning for projects... | ||
[INFO] | ||
[INFO] --< com.microsoft.azure.iotcentral:azure-iot-central-java-sdk-samples >-- | ||
[INFO] Building azure-iot-central-java-sdk-samples 2.0-SNAPSHOT | ||
[INFO] --------------------------------[ jar ]--------------------------------- | ||
[INFO] | ||
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ azure-iot-central-java-sdk-samples --- | ||
[INFO] Deleting C:\code\final\azure-iot-central-arm-sdk-samples\java\target | ||
[INFO] | ||
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ azure-iot-central-java-sdk-samples --- | ||
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! | ||
[INFO] skip non existing resourceDirectory C:\code\final\azure-iot-central-arm-sdk-samples\java\src\main\resources | ||
[INFO] | ||
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ azure-iot-central-java-sdk-samples --- | ||
[INFO] Changes detected - recompiling the module! | ||
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! | ||
[INFO] Compiling 3 source files to C:\code\final\azure-iot-central-arm-sdk-samples\java\target\classes | ||
[INFO] | ||
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ azure-iot-central-java-sdk-samples --- | ||
------------------ | ||
Operations List: | ||
------------------ | ||
|
||
Microsoft.IoTCentral/IoTApps/read | ||
Microsoft.IoTCentral/IoTApps/write | ||
Microsoft.IoTCentral/IoTApps/delete | ||
Microsoft.IoTCentral/checkNameAvailability/action | ||
Microsoft.IoTCentral/checkSubdomainAvailability/action | ||
Microsoft.IoTCentral/operations/read | ||
Microsoft.IoTCentral/appTemplates/action | ||
Microsoft.IoTCentral/register/action | ||
Microsoft.IoTCentral/IoTApps/providers/Microsoft.Insights/metricDefinitions/read | ||
Microsoft.IoTCentral/IoTApps/providers/Microsoft.Insights/diagnosticSettings/read | ||
Microsoft.IoTCentral/IoTApps/providers/Microsoft.Insights/diagnosticSettings/write | ||
|
||
------------------ | ||
IOT Central App Templates: | ||
------------------ | ||
|
||
iotc-condition | ||
iotc-consumption | ||
iotc-distribution | ||
iotc-inventory | ||
iotc-logistics | ||
iotc-meter | ||
iotc-mfc | ||
iotc-patient | ||
iotc-pnp-preview | ||
iotc-power | ||
iotc-quality | ||
iotc-store | ||
iotc-video-analytics-om | ||
iotc-waste | ||
|
||
------------------ | ||
Apps in Resource Group: | ||
------------------ | ||
|
||
Name:gaviswanapp21636580090, Location: eastus | ||
Name:gtest1, Location: westus | ||
Name:gaviswanapp21636578314, Location: eastus | ||
|
||
------------------ | ||
Create/Update App: | ||
------------------ | ||
|
||
randomizedName: gaviswanapp21636580731 | ||
App created successfully. | ||
------------------ | ||
Get App: | ||
------------------ | ||
|
||
Name:gaviswanapp21636580731, Location: eastus, com.azure.resourcemanager.iotcentral.implementation.AppImpl@2df8aa39 | ||
|
||
------------------ | ||
Update App: | ||
------------------ | ||
|
||
App updated successfully. | ||
|
||
------------------ | ||
Delete App: | ||
------------------ | ||
|
||
App deleted! | ||
|
||
------------------ | ||
Validating Exceptions: | ||
------------------ | ||
|
||
randomizedName: gaviswanapp21636580772 | ||
Validated error with use of geo location. | ||
------------------ | ||
Validating Exceptions: | ||
------------------ | ||
|
||
randomizedName: gaviswanapp21636580772 | ||
Validated error with invalid sku 'S1'. | ||
------------------ | ||
Validating Exceptions: | ||
------------------ | ||
|
||
randomizedName: gaviswanapp21636580775 | ||
Validated error with F1 sku. | ||
[INFO] ------------------------------------------------------------------------ | ||
[INFO] BUILD SUCCESS | ||
[INFO] ------------------------------------------------------------------------ | ||
[INFO] Total time: 53.902 s | ||
[INFO] Finished at: 2021-11-10T13:46:18-08:00 | ||
[INFO] ------------------------------------------------------------------------ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.microsoft.azure.iotcentral</groupId> | ||
<artifactId>azure-iot-central-java-sdk-samples</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
<build> | ||
<sourceDirectory>${basedir}/src/main</sourceDirectory> | ||
<scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory> | ||
<testSourceDirectory>${basedir}/src/test</testSourceDirectory> | ||
<outputDirectory>${basedir}/target/classes</outputDirectory> | ||
<testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.7.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>Main</mainClass> | ||
<cleanupDaemonThreads>false</cleanupDaemonThreads> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<!-- https://mvnrepository.com/artifact/com.azure/azure-core-http-netty --> | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-core-http-netty</artifactId> | ||
<version>1.11.1</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.azure.resourcemanager/azure-resourcemanager --> | ||
<dependency> | ||
<groupId>com.azure.resourcemanager</groupId> | ||
<artifactId>azure-resourcemanager</artifactId> | ||
<version>2.9.0</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.azure/azure-core --> | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-core</artifactId> | ||
<version>1.21.0</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.azure/azure-identity --> | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-identity</artifactId> | ||
<version>1.4.0</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.azure.resourcemanager/azure-resourcemanager-iotcentral --> | ||
<dependency> | ||
<groupId>com.azure.resourcemanager</groupId> | ||
<artifactId>azure-resourcemanager-iotcentral</artifactId> | ||
<version>1.0.0-beta.2</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.