Search in sources :

Example 1 with RegistryManager

use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.

the class RegistryStatisticsTests method constructorSucceeds.

@Test
public void constructorSucceeds(@Mocked RegistryManager mockedRegistryManager) throws IOException, IotHubException {
    //arrange
    String connectionString = "HostName=aaa.bbb.ccc;SharedAccessKeyName=XXX;SharedAccessKey=YYY";
    RegistryManager registryManager = RegistryManager.createFromConnectionString(connectionString);
    // act
    RegistryStatistics statistics = registryManager.getStatistics();
}
Also used : RegistryStatistics(com.microsoft.azure.sdk.iot.service.RegistryStatistics) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) Test(org.junit.Test)

Example 2 with RegistryManager

use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.

the class AzureSasCredentialSample method runRegistryManagerSample.

private static String runRegistryManagerSample(String iotHubHostName, AzureSasCredential credential) {
    // RegistryManager has some configurable options for HTTP read and connect timeouts, as well as for setting proxies.
    // For this sample, the default options will be used though.
    RegistryManagerOptions options = RegistryManagerOptions.builder().build();
    // This constructor takes in your implementation of AzureSasCredential which allows you to use symmetric key based
    // authentication without giving the client your connection string.
    RegistryManager registryManager = new RegistryManager(iotHubHostName, credential, options);
    String deviceId = "my-new-device-" + UUID.randomUUID().toString();
    Device newDevice = Device.createDevice(deviceId, AuthenticationType.SAS);
    try {
        System.out.println("Creating device " + deviceId);
        registryManager.addDevice(newDevice);
        System.out.println("Successfully created device " + deviceId);
    } catch (IOException | IotHubException e) {
        System.err.println("Failed to register new device");
        e.printStackTrace();
        System.exit(-1);
    }
    return deviceId;
}
Also used : Device(com.microsoft.azure.sdk.iot.service.Device) DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) RegistryManagerOptions(com.microsoft.azure.sdk.iot.service.RegistryManagerOptions) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 3 with RegistryManager

use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.

the class ConfigurationManangerSample method AddConfiguration.

private static void AddConfiguration() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    ConfigurationContent content = new ConfigurationContent();
    content.setDeviceContent(DEVICE_CONTENT_SAMPLE);
    Configuration config = new Configuration(SampleUtils.configurationId);
    config.setContent(content);
    config.getMetrics().setQueries(new HashMap<String, String>() {

        {
            put("waterSettingsPending", "SELECT deviceId FROM devices WHERE properties.reported.chillerWaterSettings.status='pending'");
        }
    });
    config.setTargetCondition("properties.reported.chillerProperties.model='4000x'");
    config.setPriority(20);
    try {
        config = registryManager.addConfiguration(config);
        System.out.println("Add configuration " + config.getId() + " succeeded.");
        printConfiguration(config);
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    registryManager.close();
}
Also used : Configuration(com.microsoft.azure.sdk.iot.service.Configuration) RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) ConfigurationContent(com.microsoft.azure.sdk.iot.service.ConfigurationContent) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 4 with RegistryManager

use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.

the class ConfigurationManangerSample method UpdateConfiguration.

private static void UpdateConfiguration(Configuration config) throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    config.setPriority(1);
    try {
        config = registryManager.updateConfiguration(config);
        printConfiguration(config);
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    registryManager.close();
}
Also used : RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 5 with RegistryManager

use of com.microsoft.azure.sdk.iot.service.RegistryManager in project azure-iot-sdk-java by Azure.

the class ConfigurationManangerSample method RemoveConfiguration.

private static void RemoveConfiguration() throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    try {
        registryManager.removeConfiguration(SampleUtils.configurationId);
        System.out.println("Device removed: " + SampleUtils.configurationId);
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    registryManager.close();
}
Also used : RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Aggregations

RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)39 IOException (java.io.IOException)20 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)19 Device (com.microsoft.azure.sdk.iot.service.Device)15 Test (org.junit.Test)14 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)7 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)6 AzureSasCredential (com.azure.core.credential.AzureSasCredential)5 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)5 IotHubServiceSasToken (com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken)5 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)5 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)5 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)5 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)5 RegistryStatistics (com.microsoft.azure.sdk.iot.service.RegistryStatistics)4 DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)3 Configuration (com.microsoft.azure.sdk.iot.service.Configuration)3 JobProperties (com.microsoft.azure.sdk.iot.service.JobProperties)3 Message (com.microsoft.azure.sdk.iot.service.Message)3 Module (com.microsoft.azure.sdk.iot.service.Module)3