Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventHub management support #580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<EventHubInfo> eventHubs = new ArrayList<EventHubInfo>();
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this class? Seems to simply hold an instance of EventHubInfo and doesn't convey much information. Not to mention that a result should not be mutable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current structure of requests follows this pattern and I think it would be more confusing for one model to differ on this.

*
* 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 <code>createTopic</code> operation.
*/
public class CreateEventHubResult {

private EventHubInfo value;

/**
* Creates an instance of the <code>CreateEventHubResult</code> 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;
}

}
Loading