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();
}
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;
}
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();
}
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();
}
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();
}
Aggregations