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

refactor(iot-dev, iot-serv, dps-dev, dps-serv): Add logs to clients that say what version is being run #1430

Merged
merged 1 commit into from
Dec 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.microsoft.azure.sdk.iot.device.fileupload.FileUpload;
import com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask;
import com.microsoft.azure.sdk.iot.device.transport.RetryPolicy;
import com.microsoft.azure.sdk.iot.device.transport.TransportUtils;
import com.microsoft.azure.sdk.iot.device.transport.amqps.IoTHubConnectionType;
import com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager;
import com.microsoft.azure.sdk.iot.provisioning.security.SecurityProvider;
Expand Down Expand Up @@ -401,6 +402,7 @@ private void commonConstructorSetup()
{
this.ioTHubConnectionType = IoTHubConnectionType.SINGLE_CLIENT;
this.transportClient = null;
log.debug("Initialized a DeviceClient instance using SDK version {}", TransportUtils.CLIENT_VERSION);
timtay-microsoft marked this conversation as resolved.
Show resolved Hide resolved
}

private void commonConstructorVerifications() throws UnsupportedOperationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.microsoft.azure.sdk.iot.device.hsm.HsmException;
import com.microsoft.azure.sdk.iot.device.hsm.HttpHsmSignatureProvider;
import com.microsoft.azure.sdk.iot.device.hsm.IotHubSasTokenHsmAuthenticationProvider;
import com.microsoft.azure.sdk.iot.device.transport.TransportUtils;
import com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -85,6 +86,7 @@ public ModuleClient(String connectionString, IotHubClientProtocol protocol) thro
//Codes_SRS_MODULECLIENT_34_007: [If the provided protocol is not MQTT, AMQPS, MQTT_WS, or AMQPS_WS, this function shall throw an UnsupportedOperationException.]
//Codes_SRS_MODULECLIENT_34_004: [If the provided connection string does not contain a module id, this function shall throw an IllegalArgumentException.]
commonConstructorVerifications(protocol, this.config);
commonConstructorSetup();
}

/**
Expand All @@ -109,6 +111,7 @@ public ModuleClient(String connectionString, IotHubClientProtocol protocol, Clie
{
super(new IotHubConnectionString(connectionString), protocol, SEND_PERIOD_MILLIS, getReceivePeriod(protocol), clientOptions);
commonConstructorVerifications(protocol, this.config);
commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -149,6 +152,7 @@ public ModuleClient(String connectionString, IotHubClientProtocol protocol, Stri
//Codes_SRS_MODULECLIENT_34_008: [If the provided protocol is not MQTT, AMQPS, MQTT_WS, or AMQPS_WS, this function shall throw an UnsupportedOperationException.]
//Codes_SRS_MODULECLIENT_34_009: [If the provided connection string does not contain a module id, this function shall throw an IllegalArgumentException.]
commonConstructorVerifications(protocol, this.getConfig());
commonConstructorSetup();
}

/**
Expand All @@ -174,6 +178,7 @@ public ModuleClient(String connectionString, IotHubClientProtocol protocol, SSLC
{
super(new IotHubConnectionString(connectionString), protocol, sslContext, SEND_PERIOD_MILLIS, getReceivePeriod(protocol));
commonConstructorVerifications(protocol, this.getConfig());
commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -208,6 +213,7 @@ public ModuleClient(String hostName, String deviceId, String moduleId, SasTokenP
{
super(hostName, deviceId, moduleId, sasTokenProvider, protocol, clientOptions, SEND_PERIOD_MILLIS, getReceivePeriod(protocol));
commonConstructorVerifications(protocol, this.getConfig());
commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -372,6 +378,8 @@ public static ModuleClient createFromEnvironment(IotHubClientProtocol protocol,
private ModuleClient(IotHubAuthenticationProvider iotHubAuthenticationProvider, IotHubClientProtocol protocol, long sendPeriodMillis, long receivePeriodMillis) throws IOException, TransportException
{
super(iotHubAuthenticationProvider, protocol, sendPeriodMillis, receivePeriodMillis);

commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -678,4 +686,9 @@ private static void commonConstructorVerifications(IotHubClientProtocol protocol
throw new IllegalArgumentException("Connection string must contain field for ModuleId");
}
}

private static void commonConstructorSetup()
{
log.debug("Initialized a ModuleClient instance using SDK version {}", TransportUtils.CLIENT_VERSION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TransportUtils
public static final String IOTHUB_API_VERSION = "2020-09-30";

private static final String JAVA_DEVICE_CLIENT_IDENTIFIER = "com.microsoft.azure.sdk.iot.iot-device-client";
private static final String CLIENT_VERSION = "1.33.1";
public static final String CLIENT_VERSION = "1.33.1";

private static final String JAVA_RUNTIME = System.getProperty("java.version");
private static final String OPERATING_SYSTEM = System.getProperty("java.runtime.name").toLowerCase().contains("android") ? "Android" : System.getProperty("os.name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.microsoft.azure.sdk.iot.provisioning.device;

import com.microsoft.azure.sdk.iot.provisioning.device.internal.ProvisioningDeviceClientConfig;
import com.microsoft.azure.sdk.iot.provisioning.device.internal.SDKUtils;
import com.microsoft.azure.sdk.iot.provisioning.device.internal.task.ProvisioningTask;
import com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.ProvisioningDeviceClientContract;
import com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceClientException;
Expand Down Expand Up @@ -80,6 +81,8 @@ private ProvisioningDeviceClient(String globalEndpoint, String idScope, Provisio
this.provisioningDeviceClientContract = ProvisioningDeviceClientContract.createProvisioningContract(this.provisioningDeviceClientConfig);
//SRS_ProvisioningDeviceClient_25_007: [ The constructor shall create an executor service with fixed thread pool of size 1. ]
this.executor = Executors.newFixedThreadPool(MAX_THREADS_TO_RUN);

log.debug("Initialized a ProvisioningDeviceClient instance using SDK version {}", SDKUtils.PROVISIONING_DEVICE_CLIENT_VERSION);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions provisioning/provisioning-service-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<version>1.0.4</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.jmockit</groupId>
Expand All @@ -67,6 +72,12 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString;
import com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionStringBuilder;
import com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp;
import com.microsoft.azure.sdk.iot.provisioning.service.contract.SDKUtils;
import com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientException;
import com.microsoft.azure.sdk.iot.provisioning.service.configs.*;
import com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientExceptionManager;
import com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientNotFoundException;
import com.microsoft.azure.sdk.iot.provisioning.service.exceptions.ProvisioningServiceClientTransportException;
import lombok.extern.slf4j.Slf4j;

import java.util.Collection;

Expand Down Expand Up @@ -73,6 +75,7 @@
* @see <a href="https://docs.microsoft.com/en-us/azure/iot-dps">Azure IoT Hub Device Provisioning Service</a>
* @see <a href="https://docs.microsoft.com/en-us/azure/iot-dps/about-iot-dps">Provisioning devices with Azure IoT Hub Device Provisioning Service</a>
*/
@Slf4j
public final class ProvisioningServiceClient
{

Expand Down Expand Up @@ -124,6 +127,8 @@ private ProvisioningServiceClient(String connectionString)
this.enrollmentGroupManager = EnrollmentGroupManager.createFromContractApiHttp(contractApiHttp);
/* SRS_PROVISIONING_SERVICE_CLIENT_21_007: [The constructor shall create a new instance of the RegistrationStatusManager.] */
this.registrationStatusManager = RegistrationStatusManager.createFromContractApiHttp(contractApiHttp);

log.debug("Initialized a ProvisioningServiceClient instance using SDK version {}", SDKUtils.getServiceApiVersion());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import com.microsoft.azure.sdk.iot.service.auth.TokenCredentialCache;
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException;
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubExceptionManager;
import com.microsoft.azure.sdk.iot.service.transport.TransportUtils;
import com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod;
import com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest;
import com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse;
import lombok.extern.slf4j.Slf4j;

import javax.json.Json;
import javax.json.JsonArray;
Expand All @@ -40,6 +42,7 @@
* Use the RegistryManager client to manage the identity registry in IoT hubs.
* To access twins, use the {@link com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin} client.
*/
@Slf4j
public class RegistryManager
{
private static final int EXECUTOR_THREAD_POOL_SIZE = 10;
Expand Down Expand Up @@ -137,6 +140,7 @@ public RegistryManager(String connectionString, RegistryManagerOptions options)
this.hostName = iotHubConnectionString.getHostName();
this.options = options;
this.executor = Executors.newFixedThreadPool(EXECUTOR_THREAD_POOL_SIZE);
commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -172,6 +176,7 @@ public RegistryManager(String hostName, TokenCredential credential, RegistryMana
this.options = options;
this.credentialCache = new TokenCredentialCache(credential);
this.hostName = hostName;
commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -205,6 +210,12 @@ public RegistryManager(String hostName, AzureSasCredential azureSasCredential, R
this.options = options;
this.azureSasCredential = azureSasCredential;
this.hostName = hostName;
commonConstructorSetup();
}

private static void commonConstructorSetup()
{
log.debug("Initialized a RegistryManager instance client using SDK version {}", TransportUtils.serviceVersion);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.azure.core.credential.TokenCredential;
import com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken;
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException;
import com.microsoft.azure.sdk.iot.service.transport.TransportUtils;
import com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -123,6 +124,8 @@ public ServiceClient(
iotHubServiceClientProtocol,
options.getProxyOptions(),
options.getSslContext());

commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -190,6 +193,8 @@ public ServiceClient(
this.iotHubServiceClientProtocol,
options.getProxyOptions(),
options.getSslContext());

commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -238,6 +243,8 @@ public ServiceClient(
iotHubServiceClientProtocol,
options.getProxyOptions(),
options.getSslContext());

commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -285,6 +292,13 @@ protected ServiceClient(
this.iotHubServiceClientProtocol,
options.getProxyOptions(),
options.getSslContext());

commonConstructorSetup();
}

private static void commonConstructorSetup()
{
log.debug("Initialized a ServiceClient instance using SDK version {}", TransportUtils.serviceVersion);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken;
import com.microsoft.azure.sdk.iot.service.auth.TokenCredentialCache;
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException;
import com.microsoft.azure.sdk.iot.service.transport.TransportUtils;
import com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod;
import com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.Proxy;
Expand All @@ -26,6 +28,7 @@
/**
* Use the DeviceMethod client to directly invoke methods on devices and modules in IoT hub.
*/
@Slf4j
public class DeviceMethod
{
private Integer requestId = 0;
Expand Down Expand Up @@ -108,6 +111,7 @@ public DeviceMethod(String connectionString, DeviceMethodClientOptions options)
this.hostName = IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString).getHostName();
this.options = options;
this.iotHubConnectionString = IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -142,6 +146,8 @@ public DeviceMethod(String hostName, TokenCredential credential, DeviceMethodCli
this.options = options;
this.credentialCache = new TokenCredentialCache(credential);
this.hostName = hostName;
commonConstructorSetup();

}

/**
Expand Down Expand Up @@ -174,6 +180,12 @@ public DeviceMethod(String hostName, AzureSasCredential azureSasCredential, Devi
this.options = options;
this.azureSasCredential = azureSasCredential;
this.hostName = hostName;
commonConstructorSetup();
}

private static void commonConstructorSetup()
{
log.debug("Initialized a DeviceMethod client instance using SDK version {}", TransportUtils.serviceVersion);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import com.microsoft.azure.sdk.iot.service.auth.IotHubServiceSasToken;
import com.microsoft.azure.sdk.iot.service.auth.TokenCredentialCache;
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException;
import com.microsoft.azure.sdk.iot.service.transport.TransportUtils;
import com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod;
import com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.MalformedURLException;
Expand All @@ -34,6 +36,7 @@
/**
* Use the DeviceTwin class to manage the device twins in IoT hubs.
*/
@Slf4j
public class DeviceTwin
{
private int requestId = 0;
Expand Down Expand Up @@ -106,6 +109,7 @@ public DeviceTwin(String connectionString, DeviceTwinClientOptions options)
this.options = options;
this.iotHubConnectionString = IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
this.hostName = this.iotHubConnectionString.getHostName();
commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -140,6 +144,7 @@ public DeviceTwin(String hostName, TokenCredential credential, DeviceTwinClientO
this.options = options;
this.credentialCache = new TokenCredentialCache(credential);
this.hostName = hostName;
commonConstructorSetup();
}

/**
Expand Down Expand Up @@ -172,6 +177,12 @@ public DeviceTwin(String hostName, AzureSasCredential azureSasCredential, Device
this.options = options;
this.azureSasCredential = azureSasCredential;
this.hostName = hostName;
commonConstructorSetup();
}

private static void commonConstructorSetup()
{
log.debug("Initialized a DeviceTwin client instance using SDK version {}", TransportUtils.serviceVersion);
}

/**
Expand Down
Loading