diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index 018c93965c2df..205f2b9f83931 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -72,7 +72,7 @@ com.azure:azure-communication-common;1.2.15;1.3.0-beta.2 com.azure:azure-communication-common-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-communication-email;1.0.9;1.1.0-beta.1 com.azure:azure-communication-identity;1.5.1;1.6.0-beta.1 -com.azure:azure-communication-jobrouter;1.0.0;1.1.0-beta.1 +com.azure:azure-communication-jobrouter;1.0.0;1.1.0 com.azure:azure-communication-networktraversal;1.1.0-beta.2;1.1.0-beta.3 com.azure:azure-communication-phonenumbers;1.1.9;1.2.0-beta.1 com.azure:azure-communication-rooms;1.0.7;1.1.0-beta.2 diff --git a/sdk/communication/azure-communication-jobrouter/CHANGELOG.md b/sdk/communication/azure-communication-jobrouter/CHANGELOG.md index 110f646ecc016..e814c4862f1b1 100644 --- a/sdk/communication/azure-communication-jobrouter/CHANGELOG.md +++ b/sdk/communication/azure-communication-jobrouter/CHANGELOG.md @@ -1,12 +1,14 @@ # Release History -## 1.1.0-beta.1 (Unreleased) +## 1.1.0 (Unreleased) ### Features Added ### Breaking Changes ### Bugs Fixed +* NullPointerException in routerQueue.getLabels() +* createJob() deserialization error. ### Other Changes diff --git a/sdk/communication/azure-communication-jobrouter/README.md b/sdk/communication/azure-communication-jobrouter/README.md index a03f036ff2aea..326285e769f5e 100644 --- a/sdk/communication/azure-communication-jobrouter/README.md +++ b/sdk/communication/azure-communication-jobrouter/README.md @@ -130,13 +130,20 @@ An exception policy controls the behavior of a Job based on a trigger and execut ## Examples ### Client Initialization -To initialize the JobRouter Client, the connection string can be used to instantiate. -Alternatively, you can also use Active Directory authentication using DefaultAzureCredential. +JobRouter has two clients, JobRouterAdministrationClient and JobRouterClient. Both of them +can be initialized using the endpoint and access key. ```java -JobRouterClient jobRouterClient = new JobRouterClientBuilder() - .connectionString(connectionString) - .buildClient(); +String endpoint = ; +String accessKey = ; +JobRouterAdministrationClient routerAdminClient = new JobRouterAdministrationClientBuilder() + .endpoint(endpoint) + .addPolicy(new HmacAuthenticationPolicy(new AzureKeyCredential(accessKey))) + .buildClient(); +JobRouterClient routerClient = new JobRouterClientBuilder() + .endpoint(endpoint) + .addPolicy(new HmacAuthenticationPolicy(new AzureKeyCredential(accessKey))) + .buildClient(); ``` Using `JobRouterClient` created from builder, create Job Router entities as described below. @@ -151,14 +158,14 @@ CreateDistributionPolicyOptions createDistributionPolicyOptions = new CreateDist .setMinConcurrentOffers(1) .setMaxConcurrentOffers(10) ); -DistributionPolicy distributionPolicy = jobRouterClient.createDistributionPolicy(createDistributionPolicyOptions); +DistributionPolicy distributionPolicy = routerAdminClient.createDistributionPolicy(createDistributionPolicyOptions); ``` ### Create a Queue ```java CreateQueueOptions createQueueOptions = new CreateQueueOptions("queue-id", distributionPolicy.getId()); -RouterQueue jobQueue = jobRouterClient.createQueue(createQueueOptions); +RouterQueue jobQueue = routerAdminClient.createQueue(createQueueOptions); ``` ### Create a Job @@ -175,7 +182,7 @@ CreateJobOptions createJobOptions = new CreateJobOptions("job-id", "chat-channel .setValue(new LabelValue(10)); }} ); -RouterJob routerJob = jobRouterClient.createJob(createJobOptions); +RouterJob routerJob = routerClient.createJob(createJobOptions); ``` ### Create a Worker @@ -214,7 +221,7 @@ CreateWorkerOptions createWorkerOptions = new CreateWorkerOptions(workerId, 10) .setChannels(channels) .setQueues(queues); -RouterWorker routerWorker = jobRouterClient.createWorker(createWorkerOptions); +RouterWorker routerWorker = routerClient.createWorker(createWorkerOptions); ``` ## Troubleshooting diff --git a/sdk/communication/azure-communication-jobrouter/assets.json b/sdk/communication/azure-communication-jobrouter/assets.json index 7f9504b301359..6d21299a3bab8 100644 --- a/sdk/communication/azure-communication-jobrouter/assets.json +++ b/sdk/communication/azure-communication-jobrouter/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/communication/azure-communication-jobrouter", - "Tag": "java/communication/azure-communication-jobrouter_4ac2c0636a" + "Tag": "java/communication/azure-communication-jobrouter_5a7c315465" } diff --git a/sdk/communication/azure-communication-jobrouter/customization/pom.xml b/sdk/communication/azure-communication-jobrouter/customization/pom.xml index c168177c3918f..6198fffd7187f 100644 --- a/sdk/communication/azure-communication-jobrouter/customization/pom.xml +++ b/sdk/communication/azure-communication-jobrouter/customization/pom.xml @@ -5,7 +5,7 @@ azure-communication-jobrouter com.azure - 1.1.0-beta.1 + 1.1.0 4.0.0 diff --git a/sdk/communication/azure-communication-jobrouter/pom.xml b/sdk/communication/azure-communication-jobrouter/pom.xml index e59b482537b04..35beedaac1cd1 100644 --- a/sdk/communication/azure-communication-jobrouter/pom.xml +++ b/sdk/communication/azure-communication-jobrouter/pom.xml @@ -14,7 +14,7 @@ com.azure azure-communication-jobrouter - 1.1.0-beta.1 + 1.1.0 Microsoft Azure client library for Azure Communication Services JobRouter application @@ -44,7 +44,6 @@ --add-opens com.azure.communication.jobrouter/com.azure.communication.jobrouter.implementation=ALL-UNNAMED --add-opens com.azure.communication.common/com.azure.communication.common.implementation=ALL-UNNAMED --add-opens com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED - --add-opens com.azure.http.netty/com.azure.core.http.netty.NettyAsyncHttpClientBuilder=ALL-UNNAMED diff --git a/sdk/communication/azure-communication-jobrouter/src/main/java/com/azure/communication/jobrouter/JobRouterClient.java b/sdk/communication/azure-communication-jobrouter/src/main/java/com/azure/communication/jobrouter/JobRouterClient.java index 70ec16dcf0d1c..3a83691c97e1e 100644 --- a/sdk/communication/azure-communication-jobrouter/src/main/java/com/azure/communication/jobrouter/JobRouterClient.java +++ b/sdk/communication/azure-communication-jobrouter/src/main/java/com/azure/communication/jobrouter/JobRouterClient.java @@ -4,6 +4,7 @@ package com.azure.communication.jobrouter; import com.azure.communication.jobrouter.implementation.JobRouterClientImpl; +import com.azure.communication.jobrouter.implementation.accesshelpers.RouterJobConstructorProxy; import com.azure.communication.jobrouter.implementation.accesshelpers.RouterWorkerConstructorProxy; import com.azure.communication.jobrouter.implementation.converters.JobAdapter; import com.azure.communication.jobrouter.implementation.converters.WorkerAdapter; @@ -528,9 +529,13 @@ public BinaryData updateJob(String jobId, BinaryData resource, RequestOptions re @ServiceMethod(returns = ReturnType.SINGLE) public Response createJobWithResponse(CreateJobOptions createJobOptions, RequestOptions requestOptions) { + // Note: Update return type to Response in version 2. RouterJobInternal routerJob = JobAdapter.convertCreateJobOptionsToRouterJob(createJobOptions); - return this.serviceClient.upsertJobWithResponse(createJobOptions.getJobId(), BinaryData.fromObject(routerJob), - requestOptions); + Response response = this.serviceClient.upsertJobWithResponse(createJobOptions.getJobId(), + BinaryData.fromObject(routerJob), requestOptions); + return new SimpleResponse(response.getRequest(), response.getStatusCode(), response.getHeaders(), + BinaryData + .fromObject(RouterJobConstructorProxy.create(response.getValue().toObject(RouterJobInternal.class)))); } /** diff --git a/sdk/communication/azure-communication-jobrouter/src/main/java/com/azure/communication/jobrouter/implementation/converters/QueueAdapter.java b/sdk/communication/azure-communication-jobrouter/src/main/java/com/azure/communication/jobrouter/implementation/converters/QueueAdapter.java index 795acf95228ac..2a8b0b38b3858 100644 --- a/sdk/communication/azure-communication-jobrouter/src/main/java/com/azure/communication/jobrouter/implementation/converters/QueueAdapter.java +++ b/sdk/communication/azure-communication-jobrouter/src/main/java/com/azure/communication/jobrouter/implementation/converters/QueueAdapter.java @@ -21,10 +21,10 @@ public class QueueAdapter { * @return JobQueue */ public static RouterQueueInternal convertCreateQueueOptionsToRouterQueueInternal(CreateQueueOptions createQueueOptions) { - Map labels = createQueueOptions.getLabels().entrySet() + Map labels = createQueueOptions.getLabels() != null ? createQueueOptions.getLabels().entrySet() .stream() .collect(Collectors.toMap(entry -> entry.getKey(), - entry -> RouterValueAdapter.getValue(entry.getValue()))); + entry -> RouterValueAdapter.getValue(entry.getValue()))) : null; return new RouterQueueInternal() .setName(createQueueOptions.getName()) @@ -34,9 +34,9 @@ public static RouterQueueInternal convertCreateQueueOptionsToRouterQueueInternal } public static RouterQueueInternal convertRouterQueueToRouterQueueInternal(RouterQueue routerQueue) { - Map labels = routerQueue.getLabels() + Map labels = routerQueue.getLabels() != null ? routerQueue.getLabels() .entrySet().stream() - .collect(Collectors.toMap(entry -> entry.getKey(), entry -> RouterValueAdapter.getValue(entry.getValue()))); + .collect(Collectors.toMap(entry -> entry.getKey(), entry -> RouterValueAdapter.getValue(entry.getValue()))) : null; return new RouterQueueInternal() .setEtag(routerQueue.getEtag()) .setId(routerQueue.getId()) diff --git a/sdk/communication/azure-communication-jobrouter/src/test/java/com.azure.communication.jobrouter/RouterQueueLiveTests.java b/sdk/communication/azure-communication-jobrouter/src/test/java/com.azure.communication.jobrouter/RouterQueueLiveTests.java index 6a38ac86afadf..dec66be0f6000 100644 --- a/sdk/communication/azure-communication-jobrouter/src/test/java/com.azure.communication.jobrouter/RouterQueueLiveTests.java +++ b/sdk/communication/azure-communication-jobrouter/src/test/java/com.azure.communication.jobrouter/RouterQueueLiveTests.java @@ -11,17 +11,22 @@ import com.azure.core.util.BinaryData; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; import java.util.HashMap; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class RouterQueueLiveTests extends JobRouterTestBase { private JobRouterClient jobRouterClient; private JobRouterAdministrationClient routerAdminClient; + private static final Logger LOGGER = LoggerFactory.getLogger(RouterQueueLiveTests.class); + @ParameterizedTest @MethodSource("com.azure.core.test.TestBase#getHttpClients") public void createQueue(HttpClient httpClient) { @@ -44,7 +49,7 @@ public void createQueue(HttpClient httpClient) { routerAdminClient.deleteDistributionPolicy(distributionPolicyId); } -// @ParameterizedTest + @ParameterizedTest @MethodSource("com.azure.core.test.TestBase#getHttpClients") public void updateQueue(HttpClient httpClient) { // Setup @@ -56,18 +61,20 @@ public void updateQueue(HttpClient httpClient) { String queueId = String.format("%s-CreateQueue-Queue", JAVA_LIVE_TESTS); RouterQueue queue = createQueue(routerAdminClient, queueId, distributionPolicy.getId()); + String updatedRouterQueue = "{\"name\":\"JAVA_LIVE_TEST-CreateQueue-Queue\",\"distributionPolicyId\":\"JAVA_LIVE_TEST-CreateQueue-DistributionPolicy\",\"labels\":{\"Label_1\":\"UpdatedValue\"}}"; + Map updatedQueueLabels = new HashMap() { { put("Label_1", new RouterValue("UpdatedValue")); } }; // Action - RouterQueue updatedRouterQueue = queue.setLabels(updatedQueueLabels); - queue = routerAdminClient.updateQueueWithResponse(queueId, BinaryData.fromObject(updatedRouterQueue), new RequestOptions()) - .getValue().toObject(RouterQueue.class); + BinaryData updatedQueue = routerAdminClient.updateQueueWithResponse(queueId, BinaryData.fromString(updatedRouterQueue), new RequestOptions()) + .getValue(); + LOGGER.info(updatedQueue.toString()); // Verify - assertEquals(updatedQueueLabels.get("Label_1").getStringValue(), queue.getLabels().get("Label_1").getStringValue()); + assertTrue(updatedQueue.toString().contains("\"Label_1\":\"UpdatedValue\"")); // Cleanup routerAdminClient.deleteQueue(queueId);