From fa6651be08c54adcba46916af81d7be19a8fea57 Mon Sep 17 00:00:00 2001 From: Philipp Fehre Date: Fri, 15 Jan 2016 16:42:55 +0000 Subject: [PATCH] EventHub management support Add create, show, delete, index for event hubs. - eventhubs types (Result types, description type, info type) - Added needed actions to `ServiceBusContract` - Added lifecycle test for event hub (create, list, show, delete) fixes #553 --- .../servicebus/ServiceBusContract.java | 162 ++++++++--- .../ServiceBusExceptionProcessor.java | 66 ++++- .../implementation/ServiceBusRestProxy.java | 49 +++- .../models/CreateEventHubResult.java | 59 ++++ .../servicebus/models/EventHubInfo.java | 273 ++++++++++++++++++ .../servicebus/models/GetEventHubResult.java | 59 ++++ .../models/ListEventHubsOptions.java | 22 ++ .../models/ListEventHubsResult.java | 46 +++ ...netservices.2010.10.servicebus.connect.xsd | 61 ++++ .../resources/serviceBus/servicebus-atom.xsd | 1 + .../servicebus/ServiceBusIntegrationTest.java | 25 ++ 11 files changed, 773 insertions(+), 50 deletions(-) create mode 100644 services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/CreateEventHubResult.java create mode 100644 services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/EventHubInfo.java create mode 100644 services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/GetEventHubResult.java create mode 100644 services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/ListEventHubsOptions.java create mode 100644 services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/ListEventHubsResult.java diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/ServiceBusContract.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/ServiceBusContract.java index 2b0c276442cd..730382d13840 100644 --- a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/ServiceBusContract.java +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/ServiceBusContract.java @@ -1,11 +1,11 @@ /** * Copyright Microsoft Corporation - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,14 +17,19 @@ import com.microsoft.windowsazure.core.pipeline.jersey.JerseyFilterableService; import com.microsoft.windowsazure.exception.ServiceException; import com.microsoft.windowsazure.services.servicebus.models.BrokeredMessage; +import com.microsoft.windowsazure.services.servicebus.models.CreateEventHubResult; import com.microsoft.windowsazure.services.servicebus.models.CreateQueueResult; import com.microsoft.windowsazure.services.servicebus.models.CreateRuleResult; import com.microsoft.windowsazure.services.servicebus.models.CreateSubscriptionResult; import com.microsoft.windowsazure.services.servicebus.models.CreateTopicResult; +import com.microsoft.windowsazure.services.servicebus.models.EventHubInfo; +import com.microsoft.windowsazure.services.servicebus.models.GetEventHubResult; import com.microsoft.windowsazure.services.servicebus.models.GetQueueResult; import com.microsoft.windowsazure.services.servicebus.models.GetRuleResult; import com.microsoft.windowsazure.services.servicebus.models.GetSubscriptionResult; import com.microsoft.windowsazure.services.servicebus.models.GetTopicResult; +import com.microsoft.windowsazure.services.servicebus.models.ListEventHubsOptions; +import com.microsoft.windowsazure.services.servicebus.models.ListEventHubsResult; import com.microsoft.windowsazure.services.servicebus.models.ListQueuesOptions; import com.microsoft.windowsazure.services.servicebus.models.ListQueuesResult; import com.microsoft.windowsazure.services.servicebus.models.ListRulesOptions; @@ -43,16 +48,16 @@ import com.microsoft.windowsazure.services.servicebus.models.TopicInfo; /** - * + * * Defines the service bus contract. - * + * */ public interface ServiceBusContract extends JerseyFilterableService { /** * Sends a queue message. - * + * * @param queuePath * A String object that represents the name of the * queue to which the message will be sent. @@ -67,7 +72,7 @@ void sendQueueMessage(String queuePath, BrokeredMessage message) /** * Receives a queue message. - * + * * @param queuePath * A String object that represents the name of the * queue from which to receive the message. @@ -81,7 +86,7 @@ ReceiveQueueMessageResult receiveQueueMessage(String queuePath) /** * Receives a queue message using the specified receive message options. - * + * * @param queuePath * A String object that represents the name of the * queue from which to receive the message. @@ -98,7 +103,7 @@ ReceiveQueueMessageResult receiveQueueMessage(String queuePath, /** * Sends a topic message. - * + * * @param topicPath * A String object that represents the name of the * topic to which the message will be sent. @@ -113,7 +118,7 @@ void sendTopicMessage(String topicPath, BrokeredMessage message) /** * Receives a subscription message. - * + * * @param topicPath * A String object that represents the name of the * topic to receive. @@ -131,7 +136,7 @@ ReceiveSubscriptionMessageResult receiveSubscriptionMessage( /** * Receives a subscription message using the specified receive message * options. - * + * * @param topicPath * A String object that represents the name of the * topic to receive. @@ -152,7 +157,7 @@ ReceiveSubscriptionMessageResult receiveSubscriptionMessage( /** * Unlocks a message. - * + * * @param message * A Message object that represents the message to * unlock. @@ -163,7 +168,7 @@ ReceiveSubscriptionMessageResult receiveSubscriptionMessage( /** * Sends a message. - * + * * @param path * A String object that represents the path to which * the message will be sent. This may be the value of a queuePath @@ -171,7 +176,7 @@ ReceiveSubscriptionMessageResult receiveSubscriptionMessage( * @param message * A Message object that represents the message to * send. - * + * * @throws ServiceException * If a service exception is encountered. */ @@ -180,7 +185,7 @@ void sendMessage(String path, BrokeredMessage message) /** * Receives a message. - * + * * @param path * A String object that represents the path from * which a message will be received. This may either be the value @@ -195,7 +200,7 @@ void sendMessage(String path, BrokeredMessage message) /** * Receives a message using the specified receive message options. - * + * * @param path * A String object that represents the path from * which a message will be received. This may either be the value @@ -214,7 +219,7 @@ ReceiveMessageResult receiveMessage(String path, /** * Deletes a message. - * + * * @param message * A Message object that represents the message to * delete. @@ -225,7 +230,7 @@ ReceiveMessageResult receiveMessage(String path, /** * Creates a queue. - * + * * @param queueInfo * A QueueInfo object that represents the queue to * create. @@ -238,7 +243,7 @@ ReceiveMessageResult receiveMessage(String path, /** * Deletes a queue. - * + * * @param queuePath * A String object that represents the name of the * queue to delete. @@ -249,7 +254,7 @@ ReceiveMessageResult receiveMessage(String path, /** * Retrieves a queue. - * + * * @param queuePath * A String object that represents the name of the * queue to retrieve. @@ -261,7 +266,7 @@ ReceiveMessageResult receiveMessage(String path, /** * Returns a list of queues. - * + * * @return A ListQueuesResult object that represents the * result. * @throws ServiceException @@ -271,7 +276,7 @@ ReceiveMessageResult receiveMessage(String path, /** * Returns a list of queues. - * + * * @param options * A ListQueueOptions object that represents the * options to list the queue. @@ -285,21 +290,82 @@ ListQueuesResult listQueues(ListQueuesOptions options) /** * Updates the information of a queue. - * + * * @param queueInfo * The information of a queue to be updated. - * + * * @return A QueueInfo object that represents the updated * queue. - * + * * @throws ServiceException * If a service exception is encountered. */ QueueInfo updateQueue(QueueInfo queueInfo) throws ServiceException; + /** + * Creates an event hub. + * + * @param eventHub + * A EventHub object that represents the event hub to + * create. + * @return A CreateEventHubResult object that represents the + * result. + * @throws ServiceException + * If a service exception is encountered. + */ + CreateEventHubResult createEventHub(EventHubInfo eventHub) throws ServiceException; + + /** + * Deletes an event hub. + * + * @param eventHubPath + * A String object that represents the name of the + * event hub to delete. + * @throws ServiceException + * If a service exception is encountered. + */ + void deleteEventHub(String eventHubPath) throws ServiceException; + + /** + * Retrieves an event hub. + * + * @param eventHubPath + * A String object that represents the name of the + * event hub to retrieve. + * @return A GetEventHubResult object that represents the result. + * @throws ServiceException + * If a service exception is encountered. + */ + GetEventHubResult getEventHub(String eventHubPath) throws ServiceException; + + /** + * Returns a list of event hubs. + * + * @return A ListEventHubsResult object that represents the + * result. + * @throws ServiceException + * If a service exception is encountered. + */ + ListEventHubsResult listEventHubs() throws ServiceException; + + /** + * Returns a list of event hubs. + * + * @param options + * A ListEventHubsOptions object that represents the + * options to list the topic. + * @return A ListEventHubsOptions object that represents the + * result. + * @throws ServiceException + * If a service exception is encountered. + */ + ListEventHubsResult listEventHubs(ListEventHubsOptions options) + throws ServiceException; + + /** * Creates a topic. - * + * * @param topic * A Topic object that represents the topic to * create. @@ -312,7 +378,7 @@ ListQueuesResult listQueues(ListQueuesOptions options) /** * Deletes a topic. - * + * * @param topicPath * A String object that represents the name of the * queue to delete. @@ -323,7 +389,7 @@ ListQueuesResult listQueues(ListQueuesOptions options) /** * Retrieves a topic. - * + * * @param topicPath * A String object that represents the name of the * topic to retrieve. @@ -335,7 +401,7 @@ ListQueuesResult listQueues(ListQueuesOptions options) /** * Returns a list of topics. - * + * * @return A ListTopicsResult object that represents the * result. * @throws ServiceException @@ -345,7 +411,7 @@ ListQueuesResult listQueues(ListQueuesOptions options) /** * Returns a list of topics. - * + * * @param options * A ListTopicsOptions object that represents the * options to list the topic. @@ -359,11 +425,11 @@ ListTopicsResult listTopics(ListTopicsOptions options) /** * Updates a topic. - * + * * @param topicInfo * A TopicInfo object that represents the topic to * be updated. - * + * * @return A TopicInfo object that represents the update topic * result. * @throws ServiceException @@ -373,7 +439,7 @@ ListTopicsResult listTopics(ListTopicsOptions options) /** * Creates a subscription. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscription. @@ -390,7 +456,7 @@ CreateSubscriptionResult createSubscription(String topicPath, /** * Deletes a subscription. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscription. @@ -405,7 +471,7 @@ void deleteSubscription(String topicPath, String subscriptionName) /** * Retrieves a subscription. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscription. @@ -423,7 +489,7 @@ GetSubscriptionResult getSubscription(String topicPath, /** * Returns a list of subscriptions. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscriptions to retrieve. @@ -437,18 +503,18 @@ ListSubscriptionsResult listSubscriptions(String topicPath) /** * Returns a list of subscriptions. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscriptions to retrieve. - * + * * @param options * A ListSubscriptionsOptions object that represents * the options to list subscriptions. - * + * * @return A ListSubscriptionsResult object that represents the * result. - * + * * @throws ServiceException * the service exception */ @@ -457,7 +523,7 @@ ListSubscriptionsResult listSubscriptions(String topicPath, /** * Updates a subscription. - * + * * @param topicName * A String option which represents the name of the * topic. @@ -474,7 +540,7 @@ SubscriptionInfo updateSubscription(String topicName, /** * Creates a rule. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscription. @@ -493,7 +559,7 @@ CreateRuleResult createRule(String topicPath, String subscriptionName, /** * Deletes a rule. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscription. @@ -511,7 +577,7 @@ void deleteRule(String topicPath, String subscriptionName, String ruleName) /** * Retrieves a rule. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscription. @@ -530,7 +596,7 @@ GetRuleResult getRule(String topicPath, String subscriptionName, /** * Returns a list of rules. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscription. @@ -546,7 +612,7 @@ ListRulesResult listRules(String topicPath, String subscriptionName) /** * Returns a list of rules. - * + * * @param topicPath * A String object that represents the name of the * topic for the subscription. @@ -565,7 +631,7 @@ ListRulesResult listRules(String topicPath, String subscriptionName, /** * Renew queue lock. - * + * * @param queueName * A String object that represents the name of the * queue. @@ -583,7 +649,7 @@ void renewQueueLock(String queueName, String messageId, String lockToken) /** * Renew subscription lock. - * + * * @param topicName * A String object that represents the name of the * topic. @@ -601,4 +667,6 @@ void renewQueueLock(String queueName, String messageId, String lockToken) */ void renewSubscriptionLock(String topicName, String subscriptionName, String messageId, String lockToken) throws ServiceException; + + } diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/ServiceBusExceptionProcessor.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/ServiceBusExceptionProcessor.java index 2b6f15f4adbb..62741a563e87 100644 --- a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/ServiceBusExceptionProcessor.java +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/ServiceBusExceptionProcessor.java @@ -1,11 +1,11 @@ /** * Copyright Microsoft Corporation - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,14 +27,19 @@ import com.microsoft.windowsazure.services.servicebus.ServiceBusContract; import com.microsoft.windowsazure.services.servicebus.models.BrokeredMessage; +import com.microsoft.windowsazure.services.servicebus.models.CreateEventHubResult; import com.microsoft.windowsazure.services.servicebus.models.CreateQueueResult; import com.microsoft.windowsazure.services.servicebus.models.CreateRuleResult; import com.microsoft.windowsazure.services.servicebus.models.CreateSubscriptionResult; import com.microsoft.windowsazure.services.servicebus.models.CreateTopicResult; +import com.microsoft.windowsazure.services.servicebus.models.EventHubInfo; +import com.microsoft.windowsazure.services.servicebus.models.GetEventHubResult; import com.microsoft.windowsazure.services.servicebus.models.GetQueueResult; import com.microsoft.windowsazure.services.servicebus.models.GetRuleResult; import com.microsoft.windowsazure.services.servicebus.models.GetSubscriptionResult; import com.microsoft.windowsazure.services.servicebus.models.GetTopicResult; +import com.microsoft.windowsazure.services.servicebus.models.ListEventHubsOptions; +import com.microsoft.windowsazure.services.servicebus.models.ListEventHubsResult; import com.microsoft.windowsazure.services.servicebus.models.ListQueuesOptions; import com.microsoft.windowsazure.services.servicebus.models.ListQueuesResult; import com.microsoft.windowsazure.services.servicebus.models.ListRulesOptions; @@ -260,6 +265,63 @@ public QueueInfo updateQueue(QueueInfo queueInfo) throws ServiceException { } } + @Override + public CreateEventHubResult createEventHub(EventHubInfo eventHub) + throws ServiceException { + try { + return next.createEventHub(eventHub); + } catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } + } + + @Override + public void deleteEventHub(String eventHubPath) throws ServiceException { + try { + next.deleteEventHub(eventHubPath); + } catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } + } + + @Override + public GetEventHubResult getEventHub(String eventHubPath) throws ServiceException { + try { + return next.getEventHub(eventHubPath); + } catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } + } + + @Override + public ListEventHubsResult listEventHubs() throws ServiceException { + try { + return next.listEventHubs(); + } catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } + } + + @Override + public ListEventHubsResult listEventHubs(ListEventHubsOptions options) + throws ServiceException { + try { + return next.listEventHubs(options); + } catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } + } + @Override public CreateTopicResult createTopic(TopicInfo topic) throws ServiceException { diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/ServiceBusRestProxy.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/ServiceBusRestProxy.java index 6f7d4a61bdca..8d36182214df 100644 --- a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/ServiceBusRestProxy.java +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/implementation/ServiceBusRestProxy.java @@ -35,14 +35,19 @@ import com.microsoft.windowsazure.services.servicebus.ServiceBusContract; import com.microsoft.windowsazure.services.servicebus.models.AbstractListOptions; import com.microsoft.windowsazure.services.servicebus.models.BrokeredMessage; +import com.microsoft.windowsazure.services.servicebus.models.CreateEventHubResult; import com.microsoft.windowsazure.services.servicebus.models.CreateQueueResult; import com.microsoft.windowsazure.services.servicebus.models.CreateRuleResult; import com.microsoft.windowsazure.services.servicebus.models.CreateSubscriptionResult; import com.microsoft.windowsazure.services.servicebus.models.CreateTopicResult; +import com.microsoft.windowsazure.services.servicebus.models.EventHubInfo; +import com.microsoft.windowsazure.services.servicebus.models.GetEventHubResult; import com.microsoft.windowsazure.services.servicebus.models.GetQueueResult; import com.microsoft.windowsazure.services.servicebus.models.GetRuleResult; import com.microsoft.windowsazure.services.servicebus.models.GetSubscriptionResult; import com.microsoft.windowsazure.services.servicebus.models.GetTopicResult; +import com.microsoft.windowsazure.services.servicebus.models.ListEventHubsOptions; +import com.microsoft.windowsazure.services.servicebus.models.ListEventHubsResult; import com.microsoft.windowsazure.services.servicebus.models.ListQueuesOptions; import com.microsoft.windowsazure.services.servicebus.models.ListQueuesResult; import com.microsoft.windowsazure.services.servicebus.models.ListRulesOptions; @@ -163,8 +168,12 @@ public void setChannel(Client channel) { } private WebResource getResource() { + return getResourceWithApiVersion("2013-07"); + } + + private WebResource getResourceWithApiVersion(String version) { WebResource resource = getChannel().resource(uri).queryParam( - "api-version", "2013-07"); + "api-version", version); for (ClientFilter filter : filters) { resource.addFilter(filter); } @@ -400,6 +409,44 @@ private WebResource listOptions(AbstractListOptions options, return path; } + @Override + public CreateEventHubResult createEventHub(EventHubInfo entry) + throws ServiceException { + return new CreateEventHubResult(getResourceWithApiVersion("2014-01").path(entry.getPath()) + .type("application/atom+xml;type=entry;charset=utf-8") + .put(EventHubInfo.class, entry)); + } + + @Override + public void deleteEventHub(String eventHubPath) throws ServiceException { + getResourceWithApiVersion("2014-01").path(eventHubPath).delete(); + } + + @Override + public GetEventHubResult getEventHub(String eventHubPath) throws ServiceException { + return new GetEventHubResult(getResourceWithApiVersion("2014-01").path(eventHubPath).get( + EventHubInfo.class)); + } + + @Override + public ListEventHubsResult listEventHubs(ListEventHubsOptions options) + throws ServiceException { + Feed feed = listOptions(options, + getResourceWithApiVersion("2014-01").path("$Resources/EventHubs")).get(Feed.class); + ArrayList eventHubs = new ArrayList(); + for (Entry entry : feed.getEntries()) { + eventHubs.add(new EventHubInfo(entry)); + } + ListEventHubsResult result = new ListEventHubsResult(); + result.setItems(eventHubs); + return result; + } + + @Override + public ListEventHubsResult listEventHubs() throws ServiceException { + return listEventHubs(ListEventHubsOptions.DEFAULT); + } + @Override public CreateTopicResult createTopic(TopicInfo entry) throws ServiceException { diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/CreateEventHubResult.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/CreateEventHubResult.java new file mode 100644 index 000000000000..11dbb0843d23 --- /dev/null +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/CreateEventHubResult.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (c) Microsoft and contributors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.microsoft.windowsazure.services.servicebus.models; + +/** + * Represents the result of a createTopic operation. + */ +public class CreateEventHubResult { + + private EventHubInfo value; + + /** + * Creates an instance of the CreateEventHubResult class. + * + * @param value + * A {@link EventHubInfo} object assigned as the value of the + * result. + */ + public CreateEventHubResult(EventHubInfo value) { + this.setValue(value); + } + + /** + * Specfies the value of the result. + * + * @param value + * A {@link EventHubInfo} object assigned as the value of the + * result. + */ + public void setValue(EventHubInfo value) { + this.value = value; + } + + /** + * Returns the value of the result. + * + * @return A {@link EventHubInfo} object that represents the value of the + * result. + */ + public EventHubInfo getValue() { + return value; + } + +} diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/EventHubInfo.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/EventHubInfo.java new file mode 100644 index 000000000000..3fa8904dcf60 --- /dev/null +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/EventHubInfo.java @@ -0,0 +1,273 @@ +package com.microsoft.windowsazure.services.servicebus.models; + +import com.microsoft.windowsazure.services.servicebus.implementation.Content; +import com.microsoft.windowsazure.services.servicebus.implementation.EntityAvailabilityStatus; +import com.microsoft.windowsazure.services.servicebus.implementation.EntityStatus; +import com.microsoft.windowsazure.services.servicebus.implementation.Entry; +import com.microsoft.windowsazure.services.servicebus.implementation.EntryModel; +import com.microsoft.windowsazure.services.servicebus.implementation.EventHubDescription; + +import java.net.URI; +import java.util.Calendar; + +import javax.ws.rs.core.MediaType; + +public class EventHubInfo extends EntryModel { + + /** + * Creates an instance of the EventHubInfo class. + */ + public EventHubInfo() { + super(new Entry(), new EventHubDescription()); + getEntry().setContent(new Content()); + getEntry().getContent().setType(MediaType.APPLICATION_XML); + getEntry().getContent().setEventHubDescription(getModel()); + } + + /** + * Creates an instance of the EventHubInfo class using the + * specified entry. + * + * @param entry + * An Entry object that represents the entry for the + * topic. + */ + public EventHubInfo(Entry entry) { + super(entry, entry.getContent().getEventHubDescription()); + } + + /** + * Creates an instance of the EventHubInfo class using the + * specified name. + * + * @param path + * A String object that represents the name for the + * event hub. + */ + public EventHubInfo(String path) { + this(); + setPath(path); + } + + /** + * Returns the name of the event hub. + * + * @return A String object that represents the name of the + * event hub. + */ + public String getPath() { + return getEntry().getTitle(); + } + + /** + * Sets the name of the event hub. + * + * @param value + * A String that represents the name of the EventHub. + * + * @return A EventHubInfo object that represents the updated + * event hub. + */ + public EventHubInfo setPath(String value) { + getEntry().setTitle(value); + return this; + } + + /** + * Returns the message retention in days. + * + * @return A long that represents the + * message retention in days. + */ + public Long getDefaultMessageRetention() { + return getModel().getDefaultMessageRetention(); + } + + /** + * Sets the message retention in days. + * + * @param value + * A long that represents the + * message retention in days. + * + * @return A EventHubInfo object that represents the updated + * event hub. + */ + public EventHubInfo setDefaultMessageRetention(Long value) { + getModel().setDefaultMessageRetention(value); + return this; + } + + /** + * Returns the partition count of the event hub. + * + * @return The partition count of the event hub. + */ + public Integer getPartitionCount() { + return getModel().getPartitionCount(); + } + + /** + * Sets the partition count of the event hub. + * + * @param value + * The partition count of the event hub. + * + * @return A EventHubInfo object that represents the updated + * event hub. + */ + public EventHubInfo setPartitionCount(Integer value) { + getModel().setPartitionCount(value); + return this; + } + + /** + * Sets the status. + * + * @param status + * the status + * @return A EventHubInfo object that represents the updated + * event hub. + */ + public EventHubInfo setStatus(EntityStatus status) { + getModel().setStatus(status); + return this; + } + + /** + * Gets the status. + * + * @return An EntityStatus object that represents the status of + * the object. + */ + public EntityStatus getStatus() { + return getModel().getStatus(); + } + + /** + * Sets the created at. + * + * @param createdAt + * the created at + * @return A TopicInfo object that represents the updated + * event hub. + */ + public EventHubInfo setCreatedAt(Calendar createdAt) { + getModel().setCreatedAt(createdAt); + return this; + } + + /** + * Gets the created at. + * + * @return A Calendar object which represents when the event hub + * was created. + */ + public Calendar getCreatedAt() { + return getModel().getCreatedAt(); + } + + /** + * Sets the updated at. + * + * @param updatedAt + * A Calendar object which represents when the event hub + * was updated. + * @return A TopicInfo object that represents the updated + * event hub. + */ + public EventHubInfo setUpdatedAt(Calendar updatedAt) { + getModel().setUpdatedAt(updatedAt); + return this; + } + + /** + * Gets the updated at. + * + * @return A Calendar object which represents when the event hub + * was updated. + */ + public Calendar getUpdatedAt() { + return getModel().getUpdatedAt(); + } + + /** + * Sets the accessed at. + * + * @param accessedAt + * A Calendar instance representing when event hub was + * last accessed at. + * @return A EventHubInfo object that represents the updated + * event hub. + */ + public EventHubInfo setAccessedAt(Calendar accessedAt) { + getModel().setAccessedAt(accessedAt); + return this; + } + + /** + * Gets the accessed at. + * + * @return A Calendar instance representing when event hub was last + * accessed at. + */ + public Calendar getAccessedAt() { + return getModel().getAccessedAt(); + } + + /** + * Sets the user metadata. + * + * @param userMetadata + * A String represents the user metadata. + * @return A EventHubInfo object that represents the updated + * event hub. + */ + public EventHubInfo setUserMetadata(String userMetadata) { + getModel().setUserMetadata(userMetadata); + return this; + } + + /** + * Gets the user metadata. + * + * @return A String represents the user metadata. + */ + public String getUserMetadata() { + return getModel().getUserMetadata(); + } + + /** + * Sets the entity availability status. + * + * @param entityAvailabilityStatus + * An EntityAvailabilityStatus instance which + * represents the entity availability status. + * @return A TopicInfo object that represents the updated + * event hub. + */ + public EventHubInfo setEntityAvailabilityStatus( + EntityAvailabilityStatus entityAvailabilityStatus) { + getModel().setEntityAvailabilityStatus(entityAvailabilityStatus); + return this; + } + + /** + * Gets the entity availability status. + * + * @return An EntityAvailabilityStatus instance which + * represents the entity availability status. + */ + public EntityAvailabilityStatus getEntityAvailabilityStatus() { + return getModel().getEntityAvailabilityStatus(); + } + + /** + * Gets the uri. + * + * @return the uri + */ + public URI getUri() { + return URI.create(getEntry().getId()); + } +} diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/GetEventHubResult.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/GetEventHubResult.java new file mode 100644 index 000000000000..575859355275 --- /dev/null +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/GetEventHubResult.java @@ -0,0 +1,59 @@ +/** + * + * Copyright (c) Microsoft and contributors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.microsoft.windowsazure.services.servicebus.models; + +/** + * Represents the result of a getEventHub operation. + */ +public class GetEventHubResult { + + private EventHubInfo value; + + /** + * Creates an instance of the GetEventHubResult class. + * + * @param value + * A {@link EventHubInfo} object assigned as the value of the + * result. + */ + public GetEventHubResult(EventHubInfo value) { + this.setValue(value); + } + + /** + * Specfies the value of the result. + * + * @param value + * A {@link EventHubInfo} object assigned as the value of the + * result. + */ + public void setValue(EventHubInfo value) { + this.value = value; + } + + /** + * Returns the value of the result. + * + * @return A {@link EventHubInfo} object that represents the value of the + * result. + */ + public EventHubInfo getValue() { + return value; + } + +} diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/ListEventHubsOptions.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/ListEventHubsOptions.java new file mode 100644 index 000000000000..fca19e6a5b9e --- /dev/null +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/ListEventHubsOptions.java @@ -0,0 +1,22 @@ +/** + * + * Copyright (c) Microsoft and contributors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.microsoft.windowsazure.services.servicebus.models; + +public class ListEventHubsOptions extends AbstractListOptions { + public static final ListEventHubsOptions DEFAULT = new ListEventHubsOptions(); +} diff --git a/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/ListEventHubsResult.java b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/ListEventHubsResult.java new file mode 100644 index 000000000000..946c8d8c2882 --- /dev/null +++ b/services/azure-servicebus/src/main/java/com/microsoft/windowsazure/services/servicebus/models/ListEventHubsResult.java @@ -0,0 +1,46 @@ +/** + * Copyright Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.microsoft.windowsazure.services.servicebus.models; + +import java.util.List; + +/** + * Represents the result of a listEventHubs operation. + */ +public class ListEventHubsResult { + + private List items; + + /** + * Returns the items in the result list. + * + * @return A List of {@link EventHubInfo} objects that represent + * the items in the result list. + */ + public List getItems() { + return items; + } + + /** + * Specifies the items in the result list. + * + * @param items + * A List object that contains the {@link EventHubInfo} + * objects assigned as the value of the result. + */ + public void setItems(List items) { + this.items = items; + } +} diff --git a/services/azure-servicebus/src/main/resources/serviceBus/schemas.microsoft.com.netservices.2010.10.servicebus.connect.xsd b/services/azure-servicebus/src/main/resources/serviceBus/schemas.microsoft.com.netservices.2010.10.servicebus.connect.xsd index a544e3ecfadb..66abcd4986b2 100644 --- a/services/azure-servicebus/src/main/resources/serviceBus/schemas.microsoft.com.netservices.2010.10.servicebus.connect.xsd +++ b/services/azure-servicebus/src/main/resources/serviceBus/schemas.microsoft.com.netservices.2010.10.servicebus.connect.xsd @@ -599,4 +599,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/azure-servicebus/src/main/resources/serviceBus/servicebus-atom.xsd b/services/azure-servicebus/src/main/resources/serviceBus/servicebus-atom.xsd index 6b7f6b1eff23..166623bded39 100644 --- a/services/azure-servicebus/src/main/resources/serviceBus/servicebus-atom.xsd +++ b/services/azure-servicebus/src/main/resources/serviceBus/servicebus-atom.xsd @@ -32,6 +32,7 @@ + diff --git a/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/ServiceBusIntegrationTest.java b/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/ServiceBusIntegrationTest.java index 90e98a25f89b..fe3a1a2dd483 100644 --- a/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/ServiceBusIntegrationTest.java +++ b/services/azure-servicebus/src/test/java/com/microsoft/windowsazure/services/servicebus/ServiceBusIntegrationTest.java @@ -44,7 +44,9 @@ import com.microsoft.windowsazure.services.servicebus.implementation.SqlRuleAction; import com.microsoft.windowsazure.services.servicebus.implementation.TrueFilter; import com.microsoft.windowsazure.services.servicebus.models.BrokeredMessage; +import com.microsoft.windowsazure.services.servicebus.models.EventHubInfo; import com.microsoft.windowsazure.services.servicebus.models.GetQueueResult; +import com.microsoft.windowsazure.services.servicebus.models.ListEventHubsResult; import com.microsoft.windowsazure.services.servicebus.models.ListQueuesResult; import com.microsoft.windowsazure.services.servicebus.models.ListRulesResult; import com.microsoft.windowsazure.services.servicebus.models.ListSubscriptionsResult; @@ -762,6 +764,29 @@ public void topicCanBeCreatedListedFetchedAndDeleted() assertEquals(listed.getItems().size() - 1, listed2.getItems().size()); } + @Test + public void eventHubCanBeCreatedListedFetchedAndDeleted() + throws ServiceException { + // Arrange + String eventHubName = "TestEventHubCanBeCreatedListedFetchedAndDeleted"; + + // Act + EventHubInfo created = service.createEventHub( + new EventHubInfo().setPath(eventHubName)).getValue(); + ListEventHubsResult listed = service.listEventHubs(); + EventHubInfo fetched = service.getEventHub(eventHubName).getValue(); + service.deleteEventHub(eventHubName); + ListEventHubsResult listed2 = service.listEventHubs(); + + // Assert + assertNotNull(created); + assertNotNull(listed); + assertNotNull(fetched); + assertNotNull(listed2); + + assertEquals(listed.getItems().size() - 1, listed2.getItems().size()); + } + @Test public void listTopicsUnderASpecificPath() throws ServiceException { // Arrange