Skip to content

Commit

Permalink
Bug fixes (Azure#38034)
Browse files Browse the repository at this point in the history
* Bug fixes

* Fix build

* Update version

* Update version

* Update version

* Update version

* update version_client.txt

* update version_client.txt

* Update chaNGELOG.md

* Fix versions

* Make changes non-breaking

* Fix build

* UpdateQueue test

* Address comments
  • Loading branch information
cparisineti authored Dec 27, 2023
1 parent fac376f commit 40ab17a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion sdk/communication/azure-communication-jobrouter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
25 changes: 16 additions & 9 deletions sdk/communication/azure-communication-jobrouter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <endpoint>;
String accessKey = <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.
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>azure-communication-jobrouter</artifactId>
<groupId>com.azure</groupId>
<version>1.1.0-beta.1</version> <!-- {x-version-update;com.azure:azure-communication-jobrouter;current} -->
<version>1.1.0</version> <!-- {x-version-update;com.azure:azure-communication-jobrouter;current} -->
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
3 changes: 1 addition & 2 deletions sdk/communication/azure-communication-jobrouter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>com.azure</groupId>
<artifactId>azure-communication-jobrouter</artifactId>
<version>1.1.0-beta.1</version> <!-- {x-version-update;com.azure:azure-communication-jobrouter;current} -->
<version>1.1.0</version> <!-- {x-version-update;com.azure:azure-communication-jobrouter;current} -->

<name>Microsoft Azure client library for Azure Communication Services JobRouter application</name>
<description>
Expand Down Expand Up @@ -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
</javaModulesSurefireArgLine>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -528,9 +529,13 @@ public BinaryData updateJob(String jobId, BinaryData resource, RequestOptions re
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> createJobWithResponse(CreateJobOptions createJobOptions,
RequestOptions requestOptions) {
// Note: Update return type to Response<RouterJob> in version 2.
RouterJobInternal routerJob = JobAdapter.convertCreateJobOptionsToRouterJob(createJobOptions);
return this.serviceClient.upsertJobWithResponse(createJobOptions.getJobId(), BinaryData.fromObject(routerJob),
requestOptions);
Response<BinaryData> response = this.serviceClient.upsertJobWithResponse(createJobOptions.getJobId(),
BinaryData.fromObject(routerJob), requestOptions);
return new SimpleResponse<BinaryData>(response.getRequest(), response.getStatusCode(), response.getHeaders(),
BinaryData
.fromObject(RouterJobConstructorProxy.create(response.getValue().toObject(RouterJobInternal.class))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class QueueAdapter {
* @return JobQueue
*/
public static RouterQueueInternal convertCreateQueueOptionsToRouterQueueInternal(CreateQueueOptions createQueueOptions) {
Map<String, Object> labels = createQueueOptions.getLabels().entrySet()
Map<String, Object> 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())
Expand All @@ -34,9 +34,9 @@ public static RouterQueueInternal convertCreateQueueOptionsToRouterQueueInternal
}

public static RouterQueueInternal convertRouterQueueToRouterQueueInternal(RouterQueue routerQueue) {
Map<String, Object> labels = routerQueue.getLabels()
Map<String, Object> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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<String, RouterValue> updatedQueueLabels = new HashMap<String, RouterValue>() {
{
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);
Expand Down

0 comments on commit 40ab17a

Please sign in to comment.