Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated IoT Central Java SDK examples for 2021-06-01 release #18

Merged
merged 3 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions java/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.classpath
.gradle/
.project
.settings/
bin/
build/
build/
target/
3 changes: 3 additions & 0 deletions java/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
30 changes: 19 additions & 11 deletions java/README.MD
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)
gansvv marked this conversation as resolved.
Show resolved Hide resolved
- 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).
gansvv marked this conversation as resolved.
Show resolved Hide resolved

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
110 changes: 110 additions & 0 deletions java/SampleOutput.txt
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] ------------------------------------------------------------------------
24 changes: 0 additions & 24 deletions java/build.gradle

This file was deleted.

76 changes: 76 additions & 0 deletions java/pom.xml
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>
Loading