Skip to content

Commit

Permalink
Adding ServiceBusManagementClient and builder. (#11836)
Browse files Browse the repository at this point in the history
* Adding ServiceBusManagementClient and ServiceBusManagementAsyncClient.

* Adding builder and runtime info

* Add tests for sync and async client

* Making policy constructor public.

* Making classes final.

* Adding null check for empty body feeds.

* Regenerating AuthorizationRule.

* Fixing encoding bug in SerializerEncoding.

* Fixing test for azure-core SerializerEncodingTests.
  • Loading branch information
conniey authored Jun 7, 2020
1 parent e94e5e7 commit 95e2c61
Show file tree
Hide file tree
Showing 21 changed files with 2,156 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public static SerializerEncoding fromHeaders(HttpHeaders headers) {
return DEFAULT_ENCODING;
}

final SerializerEncoding encoding = SUPPORTED_MIME_TYPES.get(mimeContentType);
final String[] parts = mimeContentType.split(";");
final SerializerEncoding encoding = SUPPORTED_MIME_TYPES.get(parts[0]);
if (encoding != null) {
return encoding;
}

final String[] parts = mimeContentType.split(";");
final String[] mimeTypeParts = parts[0].split("/");
if (mimeTypeParts.length != 2) {
LOGGER.warning("Content-Type '{}' does not match mime-type formatting 'type'/'subtype'. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class SerializerEncodingTests {
private static final String CONTENT_TYPE = "Content-Type";

@ParameterizedTest
@ValueSource(strings = {"application/xml", "application/atom+xml", "text/xml", "application/foo+XML", "TEXT/XML"})
@ValueSource(strings = {"application/xml", "application/atom+xml", "text/xml", "application/foo+XML", "TEXT/XML",
"application/xml;charset=utf-8", "application/atom+xml; charset=utf-32"})
void recognizeXml(String mimeType) {
// Arrange
HttpHeaders headers = new HttpHeaders(Collections.singletonMap(CONTENT_TYPE, mimeType));
Expand All @@ -27,7 +28,8 @@ void recognizeXml(String mimeType) {
}

@ParameterizedTest
@ValueSource(strings = {"application/json", "application/kv+json", "APPLICATION/JSON", "application/FOO+JSON"})
@ValueSource(strings = {"application/json", "application/kv+json", "APPLICATION/JSON", "application/FOO+JSON",
"application/json;charset=utf-8", "application/config+json; charset=utf-32"})
void recognizeJson(String mimeType) {
// Arrange
HttpHeaders headers = new HttpHeaders(Collections.singletonMap(CONTENT_TYPE, mimeType));
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.messaging.servicebus;

import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.messaging.servicebus.models.QueueDescription;
import com.azure.messaging.servicebus.models.QueueRuntimeInfo;

import java.time.Duration;
import java.util.Objects;

/**
* A <b>synchronous</b> client for managing a Service Bus namespace.
*
* @see ServiceBusManagementAsyncClient ServiceBusManagementAsyncClient for an asynchronous client.
*/
@ServiceClient(builder = ServiceBusManagementClientBuilder.class)
public final class ServiceBusManagementClient {
private final ServiceBusManagementAsyncClient asyncClient;

/**
* Creates a new instance with the given client.
*
* @param asyncClient Asynchronous client to perform management calls through.
*/
ServiceBusManagementClient(ServiceBusManagementAsyncClient asyncClient) {
this.asyncClient = Objects.requireNonNull(asyncClient, "'asyncClient' cannot be null.");
}

/**
* Creates a queue the {@link QueueDescription}.
*
* @param queue Information about the queue to create.
*
* @return The created queue.
* @throws NullPointerException if {@code queue} is null.
* @throws IllegalArgumentException if {@link QueueDescription#getName() queue.getName()} is null or an empty
* string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public QueueDescription createQueue(QueueDescription queue) {
return asyncClient.createQueue(queue).block();
}

/**
* Creates a queue and returns the created queue in addition to the HTTP response.
*
* @param queue The queue to create.
* @param context Additional context that is passed through the HTTP pipeline during the service call.
*
* @return The created queue in addition to the HTTP response.
* @throws NullPointerException if {@code queue} is null.
* @throws IllegalArgumentException if {@link QueueDescription#getName() queue.getName()} is null or an empty
* string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<QueueDescription> createQueueWithResponse(QueueDescription queue, Context context) {
return asyncClient.createQueueWithResponse(queue, context).block();
}

/**
* Deletes a queue the matching {@code queueName}.
*
* @param queueName Name of queue to delete.
*
* @throws NullPointerException if {@code queueName} is null.
* @throws IllegalArgumentException if {@code queueName} is an empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void deleteQueue(String queueName) {
asyncClient.deleteQueue(queueName).block();
}

/**
* Deletes a queue the matching {@code queueName} and returns the HTTP response.
*
* @param queueName Name of queue to delete.
* @param context Additional context that is passed through the HTTP pipeline during the service call.
*
* @return The HTTP response when the queue is successfully deleted.
* @throws NullPointerException if {@code queueName} is null.
* @throws IllegalArgumentException if {@code queueName} is an empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> deleteQueueWithResponse(String queueName, Context context) {
return asyncClient.deleteQueueWithResponse(queueName, context).block();
}

/**
* Gets information about the queue.
*
* @param queueName Name of queue to get information about.
*
* @return Information about the queue.
* @throws NullPointerException if {@code queueName} is null or an empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public QueueDescription getQueue(String queueName) {
return asyncClient.getQueue(queueName).block();
}

/**
* Gets information about the queue along with its HTTP response.
*
* @param queueName Name of queue to get information about.
* @param context Additional context that is passed through the HTTP pipeline during the service call.
*
* @return Information about the queue and the associated HTTP response.
* @throws NullPointerException if {@code queueName} is null or an empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<QueueDescription> getQueueWithResponse(String queueName, Context context) {
return asyncClient.getQueueWithResponse(queueName, context).block();
}

/**
* Gets runtime information about the queue.
*
* @param queueName Name of queue to get information about.
*
* @return Runtime information about the queue.
* @throws NullPointerException if {@code queueName} is null or an empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public QueueRuntimeInfo getQueueRuntimeInfo(String queueName) {
return asyncClient.getQueueRuntimeInfo(queueName).block();
}

/**
* Gets runtime information about the queue along with its HTTP response.
*
* @param queueName Name of queue to get information about.
* @param context Additional context that is passed through the HTTP pipeline during the service call.
*
* @return Runtime information about the queue and the associated HTTP response.
* @throws NullPointerException if {@code queueName} is null or an empty string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<QueueRuntimeInfo> getQueueRuntimeInfoWithResponse(String queueName, Context context) {
return asyncClient.getQueueRuntimeInfoWithResponse(queueName, context).block();
}

/**
* Fetches all the queues in the Service Bus namespace.
*
* @return A PagedIterable of {@link QueueDescription queues} in the Service Bus namespace.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<QueueDescription> listQueues() {
return new PagedIterable<>(asyncClient.listQueues());
}

/**
* Fetches all the queues in the Service Bus namespace.
*
* @param context Additional context that is passed through the HTTP pipeline during the service call.
* @return A PagedIterable of {@link QueueDescription queues} in the Service Bus namespace.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<QueueDescription> listQueues(Context context) {
final PagedFlux<QueueDescription> pagedFlux = new PagedFlux<>(
() -> asyncClient.listQueuesFirstPage(context),
continuationToken -> asyncClient.listQueuesNextPage(continuationToken, context));

return new PagedIterable<>(pagedFlux);
}

/**
* Updates a queue with the given {@link QueueDescription}. The {@link QueueDescription} must be fully populated as
* all of the properties are replaced.
*
* The suggested flow is:
* <ol>
* <li>{@link #getQueue(String) Get queue description.}</li>
* <li>Update the required elements.</li>
* <li>Pass the updated description into this method.</li>
* </ol>
*
* <p>
* There are a subset of properties that can be updated. They are:
* <ul>
* <li>{@link QueueDescription#setDefaultMessageTimeToLive(Duration) DefaultMessageTimeToLive}</li>
* <li>{@link QueueDescription#setLockDuration(Duration) LockDuration}</li>
* <li>{@link QueueDescription#setDuplicateDetectionHistoryTimeWindow(Duration) DuplicateDetectionHistoryTimeWindow}
* </li>
* <li>{@link QueueDescription#setMaxDeliveryCount(Integer) MaxDeliveryCount}</li>
* </ul>
*
* @see <a href="https://docs.microsoft.com/rest/api/servicebus/update-queue">Update Queue</a>
* @param queue Information about the queue to update.
*
* @return The updated queue.
* @throws NullPointerException if {@code queue} is null.
* @throws IllegalArgumentException if {@link QueueDescription#getName() queue.getName()} is null or an empty
* string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public QueueDescription updateQueue(QueueDescription queue) {
return asyncClient.updateQueue(queue).block();
}

/**
* Updates a queue with the given {@link QueueDescription}. The {@link QueueDescription} must be fully populated as
* all of the properties are replaced.
*
* The suggested flow is:
* <ol>
* <li>{@link #getQueue(String) Get queue description.}</li>
* <li>Update the required elements.</li>
* <li>Pass the updated description into this method.</li>
* </ol>
*
* <p>
* There are a subset of properties that can be updated. They are:
* <ul>
* <li>{@link QueueDescription#setDefaultMessageTimeToLive(Duration) DefaultMessageTimeToLive}</li>
* <li>{@link QueueDescription#setLockDuration(Duration) LockDuration}</li>
* <li>{@link QueueDescription#setDuplicateDetectionHistoryTimeWindow(Duration) DuplicateDetectionHistoryTimeWindow}
* </li>
* <li>{@link QueueDescription#setMaxDeliveryCount(Integer) MaxDeliveryCount}</li>
* </ul>
*
* @see <a href="https://docs.microsoft.com/rest/api/servicebus/update-queue">Update Queue</a>
* @param queue The queue to update.
* @param context Additional context that is passed through the HTTP pipeline during the service call.
*
* @return The updated queue with its HTTP response.
* @throws NullPointerException if {@code queue} is null.
* @throws IllegalArgumentException if {@link QueueDescription#getName() queue.getName()} is null or an empty
* string.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<QueueDescription> updateQueueWithResponse(QueueDescription queue, Context context) {
return asyncClient.updateQueueWithResponse(queue, context).block();
}
}
Loading

0 comments on commit 95e2c61

Please sign in to comment.