Search in sources :

Example 21 with Module

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

the class TokenRenewalTests method createModuleClient.

private InternalClient createModuleClient(IotHubClientProtocol protocol) throws IOException, IotHubException, ModuleClientException, URISyntaxException, InterruptedException {
    UUID uuid = UUID.randomUUID();
    String deviceId = "token-renewal-test-device-" + protocol + "-" + uuid.toString();
    String moduleId = "token-renewal-test-module-" + protocol + "-" + uuid.toString();
    com.microsoft.azure.sdk.iot.service.Device device = com.microsoft.azure.sdk.iot.service.Device.createFromId(deviceId, DeviceStatus.Enabled, null);
    device = Tools.addDeviceWithRetry(registryManager, device);
    Module module = Module.createModule(deviceId, moduleId, AuthenticationType.SAS);
    module = Tools.addModuleWithRetry(registryManager, module);
    ModuleClient moduleClient = new ModuleClient(DeviceConnectionString.get(iotHubConnectionString, device, module), protocol);
    testIdentities.add(new TestModuleIdentity(moduleClient, device, module));
    return moduleClient;
}
Also used : UUID(java.util.UUID) Module(com.microsoft.azure.sdk.iot.service.Module)

Example 22 with Module

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

the class ModuleManagerSample method UpdateModule.

private static void UpdateModule() throws Exception {
    String primaryKey = "[New primary key goes here]";
    String secondaryKey = "[New secondary key goes here]";
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    Module module = Module.createFromId(SampleUtils.deviceId, SampleUtils.moduleId0, null);
    module.getSymmetricKey().setPrimaryKeyFinal(primaryKey);
    module.getSymmetricKey().setSecondaryKeyFinal(secondaryKey);
    try {
        module = registryManager.updateModule(module);
        System.out.println("Device updated: " + module.getId());
        System.out.println("Device primary key: " + module.getPrimaryKey());
        System.out.println("Device secondary key: " + module.getSecondaryKey());
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    registryManager.close();
}
Also used : RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) Module(com.microsoft.azure.sdk.iot.service.Module) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 23 with Module

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

the class ModuleManagerSample method AddModule.

private static void AddModule(int n) throws Exception {
    RegistryManager registryManager = RegistryManager.createFromConnectionString(SampleUtils.iotHubConnectionString);
    String moduleId;
    if (n == 0) {
        moduleId = SampleUtils.moduleId0;
    } else {
        moduleId = SampleUtils.moduleId1;
    }
    Module module = Module.createFromId(SampleUtils.deviceId, moduleId, null);
    try {
        module = registryManager.addModule(module);
        System.out.println("Module created: " + module.getId());
    } catch (IotHubException | IOException iote) {
        iote.printStackTrace();
    }
    registryManager.close();
}
Also used : RegistryManager(com.microsoft.azure.sdk.iot.service.RegistryManager) IOException(java.io.IOException) Module(com.microsoft.azure.sdk.iot.service.Module) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Aggregations

Module (com.microsoft.azure.sdk.iot.service.Module)23 Test (org.junit.Test)14 Device (com.microsoft.azure.sdk.iot.service.Device)5 RegistryManager (com.microsoft.azure.sdk.iot.service.RegistryManager)3 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)3 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)3 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)3 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)3 ModuleClient (com.microsoft.azure.sdk.iot.device.ModuleClient)2 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)2 SocketException (java.net.SocketException)2 UnknownHostException (java.net.UnknownHostException)2 AuthenticationParser (com.microsoft.azure.sdk.iot.deps.serializer.AuthenticationParser)1 ExportImportDeviceParser (com.microsoft.azure.sdk.iot.deps.serializer.ExportImportDeviceParser)1 SymmetricKeyParser (com.microsoft.azure.sdk.iot.deps.serializer.SymmetricKeyParser)1 X509ThumbprintParser (com.microsoft.azure.sdk.iot.deps.serializer.X509ThumbprintParser)1