Search in sources :

Example 61 with Query

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

the class AzureSasCredentialSample method runJobClientSample.

private static void runJobClientSample(String iotHubHostName, AzureSasCredential credential) {
    // JobClient 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.
    JobClientOptions options = JobClientOptions.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.
    JobClient jobClient = new JobClient(iotHubHostName, credential, options);
    try {
        System.out.println("Querying all active jobs for your IoT Hub");
        Query deviceJobQuery = jobClient.queryDeviceJob(SqlQuery.createSqlQuery("*", SqlQuery.FromType.JOBS, null, null).getQuery());
        int queriedJobCount = 0;
        while (jobClient.hasNextJob(deviceJobQuery)) {
            queriedJobCount++;
            JobResult job = jobClient.getNextJob(deviceJobQuery);
            System.out.println(String.format("Job %s of type %s has status %s", job.getJobId(), job.getJobType(), job.getJobStatus()));
        }
        if (queriedJobCount == 0) {
            System.out.println("No active jobs found for your IoT Hub");
        }
    } catch (IotHubException | IOException e) {
        System.err.println("Failed to query the jobs for your IoT Hub");
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : JobClientOptions(com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions) SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) IOException(java.io.IOException) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 62 with Query

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

the class RoleBasedAuthenticationSample method runJobClientSample.

private static void runJobClientSample(String iotHubHostName, TokenCredential credential) {
    // JobClient 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.
    JobClientOptions options = JobClientOptions.builder().build();
    // This constructor takes in your implementation of TokenCredential which allows you to use RBAC authentication
    // rather than symmetric key based authentication that comes with constructors that take connection strings.
    JobClient jobClient = new JobClient(iotHubHostName, credential, options);
    try {
        System.out.println("Querying all active jobs for your IoT Hub");
        Query deviceJobQuery = jobClient.queryDeviceJob(SqlQuery.createSqlQuery("*", SqlQuery.FromType.JOBS, null, null).getQuery());
        int queriedJobCount = 0;
        while (jobClient.hasNextJob(deviceJobQuery)) {
            queriedJobCount++;
            JobResult job = jobClient.getNextJob(deviceJobQuery);
            System.out.println(String.format("Job %s of type %s has status %s", job.getJobId(), job.getJobType(), job.getJobStatus()));
        }
        if (queriedJobCount == 0) {
            System.out.println("No active jobs found for your IoT Hub");
        }
    } catch (IotHubException | IOException e) {
        System.err.println("Failed to query the jobs for your IoT Hub");
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : JobClientOptions(com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions) SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) IOException(java.io.IOException) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)

Example 63 with Query

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

the class JobClientSample method queryJobsResponse.

private static void queryJobsResponse(JobClient jobClient) throws IOException, IotHubException {
    System.out.println("Querying job response");
    Query jobResponseQuery = jobClient.queryJobResponse(JobType.scheduleDeviceMethod, JobStatus.completed);
    while (jobClient.hasNextJob(jobResponseQuery)) {
        System.out.println("job response");
        System.out.println(jobClient.getNextJob(jobResponseQuery));
    }
}
Also used : SqlQuery(com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery) Query(com.microsoft.azure.sdk.iot.service.devicetwin.Query)

Aggregations

Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)63 Test (org.junit.Test)51 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)49 SqlQuery (com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery)34 HashMap (java.util.HashMap)17 NonStrictExpectations (mockit.NonStrictExpectations)17 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)10 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)10 RawTwinQuery (com.microsoft.azure.sdk.iot.service.devicetwin.RawTwinQuery)8 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)8 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)6 HttpRequest (com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest)6 JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)4 IOException (java.io.IOException)3 NoSuchElementException (java.util.NoSuchElementException)3 Verifications (mockit.Verifications)3 TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)2 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)2 JobClientOptions (com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions)2 Proxy (java.net.Proxy)2