From 0145df6d8b58059b80eeac892773f7167f7ea815 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 5 Jun 2013 14:38:09 -0700 Subject: [PATCH 01/57] initial check in for affinity group. --- .../services/management/Exports.java | 51 +++++++++++ .../management/ManagementConfiguration.java | 88 ++++++++++++++++++ .../management/ManagementContract.java | 48 ++++++++++ .../management/ManagementService.java | 67 ++++++++++++++ .../ManagementExceptionProcessor.java | 73 +++++++++++++++ .../implementation/ManagementRestProxy.java | 89 +++++++++++++++++++ .../services/management/package.html | 6 ++ .../management/IntegrationTestBase.java | 55 ++++++++++++ 8 files changed, 477 insertions(+) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/package.html create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java new file mode 100644 index 0000000000000..deeaf03771a1c --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -0,0 +1,51 @@ +/** + * 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.management; + +import java.util.Map; + +import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.UserAgentFilter; +import com.microsoft.windowsazure.services.management.implementation.ManagementExceptionProcessor; +import com.microsoft.windowsazure.services.serviceBus.implementation.BrokerPropertiesMapper; +import com.sun.jersey.api.client.config.ClientConfig; + +public class Exports implements Builder.Exports { + @Override + public void register(Builder.Registry registry) { + + // provide contract implementation + registry.add(ManagementContract.class, ManagementExceptionProcessor.class); + registry.add(UserAgentFilter.class); + + // alter jersey client config for serviceBus + registry.alter(ClientConfig.class, new Builder.Alteration() { + + @Override + public ClientConfig alter(ClientConfig instance, Builder builder, Map properties) { + + // need to avoid certain element prefixes, which the service does not ignore + + // add body reader/writer for EntryModel descendant classes + + return instance; + } + }); + + // convenience provider to transform BrokerProperty headers to json + registry.add(BrokerPropertiesMapper.class); + + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java new file mode 100644 index 0000000000000..ff8015b9921dc --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java @@ -0,0 +1,88 @@ +/** + * 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.management; + +import com.microsoft.windowsazure.services.core.Configuration; + +/** + * Provides functionality to create a service bus configuration. + * + */ +public class ManagementConfiguration { + + /** + * Defines the location of the certificate. + * + */ + public final static String CERTIFICATE_LOCATION = "certificate.location"; + + /** + * Defines the configuration URI constant. + * + */ + public final static String URI = "management.uri"; + + /** + * Creates a service bus configuration using the specified namespace, name, and password. + * + * @param namespace + * A String object that represents the namespace. + * + * @param authenticationName + * A String object that represents the authentication name. + * + * @param authenticationPassword + * A String object that represents the authentication password. + * + * @param serviceBusRootUri + * A String object containing the base URI that is added to your + * Service Bus namespace to form the URI to connect to the Service Bus service. + * + * To access the default public Azure service, pass ".servicebus.windows.net" + * + * @param wrapRootUri + * A String object containing the base URI that is added to your + * Service Bus namespace to form the URI to get an access token for the Service + * Bus service. + * + * To access the default public Azure service, pass "-sb.accesscontrol.windows.net/WRAPv0.9" + * + * @return + * A Configuration object that can be used when creating an instance of the + * ServiceBusService class. + * + */ + public static Configuration configureWithWrapAuthentication(String uri, String certificateLocation) { + return configureWithWrapAuthentication(null, Configuration.getInstance(), uri, certificateLocation); + } + + public static Configuration configureWithWrapAuthentication(String profile, Configuration configuration, + String uri, String certificateLocation) { + + if (profile == null) { + profile = ""; + } + else if (profile.length() != 0 && !profile.endsWith(".")) { + profile = profile + "."; + } + + configuration.setProperty(profile + URI, "https://" + uri); + + configuration.setProperty(profile + CERTIFICATE_LOCATION, certificateLocation); + + return configuration; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java new file mode 100644 index 0000000000000..bbe40816dd68f --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -0,0 +1,48 @@ +/** + * 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.management; + +import com.microsoft.windowsazure.services.core.FilterableService; +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; + +/** + * + * Defines the service bus contract. + * + */ +public interface ManagementContract extends FilterableService { + + /** + * Renew subscription lock. + * + * @param topicName + * A String object that represents the name of the topic. + * @param queueName + * A String object that represents the name of the queue. + * @param messageId + * A String object that represents the ID of the message. + * @param lockToken + * A String object that represents the token of the lock. + * @throws ServiceException + * If a service exception is encountered. + */ + // void createAffinityGroup(AffinityGroup affinityGroup) throws ServiceException; + + ListAffinityGroupsResult listAffinityGroups(String subscriptionId) throws ServiceException; + + void listVirtualMachines(String subscriptionId); + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java new file mode 100644 index 0000000000000..e8488c31bf0b9 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java @@ -0,0 +1,67 @@ +/** + * 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.management; + +import com.microsoft.windowsazure.services.core.Configuration; + +/** + * + * Access service bus functionality. + * + */ +public class ManagementService { + + private ManagementService() { + // class is not instantiated + } + + /** + * Creates an instance of the ServiceBusContract API. + * + */ + public static ManagementContract create() { + return Configuration.getInstance().create(ManagementContract.class); + } + + /** + * Creates an instance of the ServiceBusContract API using the specified configuration. + * + * @param config + * A Configuration object that represents the configuration for the service bus service. + * + */ + public static ManagementContract create(Configuration config) { + return config.create(ManagementContract.class); + } + + /** + * Creates an instance of the ServiceBusContract API. + * + */ + public static ManagementContract create(String profile) { + return Configuration.getInstance().create(profile, ManagementContract.class); + } + + /** + * Creates an instance of the ServiceBusContract API using the specified configuration. + * + * @param config + * A Configuration object that represents the configuration for the service bus service. + * + */ + public static ManagementContract create(String profile, Configuration config) { + return config.create(profile, ManagementContract.class); + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java new file mode 100644 index 0000000000000..10ef5d855b487 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java @@ -0,0 +1,73 @@ +/** + * 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.management.implementation; + +import javax.inject.Inject; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; +import com.microsoft.windowsazure.services.management.ManagementContract; +import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.UniformInterfaceException; + +public class ManagementExceptionProcessor implements ManagementContract { + + private final ManagementContract next; + static Log log = LogFactory.getLog(ManagementContract.class); + + public ManagementExceptionProcessor(ManagementContract next) { + this.next = next; + } + + @Inject + public ManagementExceptionProcessor(ManagementRestProxy next) { + this.next = next; + } + + @Override + public ManagementContract withFilter(ServiceFilter filter) { + return new ManagementExceptionProcessor(next.withFilter(filter)); + } + + private ServiceException processCatch(ServiceException e) { + log.warn(e.getMessage(), e.getCause()); + return ServiceExceptionFactory.process("serviceBus", e); + } + + @Override + public ListAffinityGroupsResult listAffinityGroups(String subscriptionId) throws ServiceException { + try { + return next.listAffinityGroups(subscriptionId); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } + } + + @Override + public void listVirtualMachines(String subscriptionId) { + // TODO Auto-generated method stub + + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java new file mode 100644 index 0000000000000..cb6dbd383c6d0 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -0,0 +1,89 @@ +/** + * 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.management.implementation; + +import java.util.Arrays; + +import javax.inject.Inject; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; +import com.microsoft.windowsazure.services.management.ManagementContract; +import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; + +public class ManagementRestProxy implements ManagementContract { + + private Client channel; + static Log log = LogFactory.getLog(ManagementContract.class); + + ServiceFilter[] filters; + + @Inject + public ManagementRestProxy(Client channel) { + + this.channel = channel; + this.filters = new ServiceFilter[0]; + } + + public ManagementRestProxy(Client channel, ServiceFilter[] serviceFilter) { + this.channel = channel; + this.filters = serviceFilter; + } + + public Client getChannel() { + return channel; + } + + public void setChannel(Client channel) { + this.channel = channel; + } + + private WebResource getResource() { + WebResource resource = getChannel().resource("uri"); + for (ServiceFilter filter : filters) { + resource.addFilter(new ClientFilterAdapter(filter)); + } + return resource; + } + + @Override + public ManagementContract withFilter(ServiceFilter filter) { + ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); + newFilters[filters.length] = filter; + return new ManagementRestProxy(channel, newFilters); + } + + @Override + public ListAffinityGroupsResult listAffinityGroups(String subscriptionId) { + ClientResponse clientResponse = getResource().path(subscriptionId).header("x-ms-version", "2013-03-01") + .get(ClientResponse.class); + String requestId = clientResponse.getHeaders().getFirst("x-ms-request-id"); + return new ListAffinityGroupsResult(requestId); + + } + + @Override + public void listVirtualMachines(String subscriptionId) { + // TODO Auto-generated method stub + + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/package.html b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/package.html new file mode 100644 index 0000000000000..e8dfd96862b70 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/package.html @@ -0,0 +1,6 @@ + + +This package contains the service management class, + interface, and associated configuration and utility classes. + + diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java new file mode 100644 index 0000000000000..e03d5db97a36e --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java @@ -0,0 +1,55 @@ +/** + * 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.management; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +import com.microsoft.windowsazure.services.core.Configuration; + +public abstract class IntegrationTestBase { + @BeforeClass + public static void initializeSystem() { + System.setProperty("http.keepAlive", "false"); + } + + @Before + public void initialize() throws Exception { + // Configuration config = createConfiguration(); + // ManagementContract service = ManagementService.create(config); + + } + + @AfterClass + public static void cleanUpTestArtifacts() throws Exception { + // Configuration config = createConfiguration(); + // ManagementContract service = ManagementService.create(config); + } + + protected static Configuration createConfiguration() throws Exception { + Configuration config = Configuration.load(); + overrideWithEnv(config, ManagementConfiguration.URI); + return config; + } + + private static void overrideWithEnv(Configuration config, String key) { + String value = System.getenv(key); + if (value == null) + return; + + config.setProperty(key, value); + } +} From 6a8db2e9edaecabfd82e5c42c30c9b657fb2adff Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 5 Jun 2013 14:57:38 -0700 Subject: [PATCH 02/57] add management integration test. --- .../management/ManagementIntegrationTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java new file mode 100644 index 0000000000000..310453a1d44ab --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -0,0 +1,80 @@ +/** + * 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.management; + +import static org.junit.Assert.*; + +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.Builder.Alteration; +import com.microsoft.windowsazure.services.core.Builder.Registry; +import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.filter.LoggingFilter; + +public class ManagementIntegrationTest extends IntegrationTestBase { + + private ManagementContract service; + + @Before + public void createService() throws Exception { + // reinitialize configuration from known state + Configuration config = createConfiguration(); + + // add LoggingFilter to any pipeline that is created + Registry builder = (Registry) config.getBuilder(); + builder.alter(Client.class, new Alteration() { + @Override + public Client alter(Client instance, Builder builder, Map properties) { + instance.addFilter(new LoggingFilter()); + return instance; + } + }); + + // applied as default configuration + Configuration.setInstance(config); + service = ManagementService.create(); + } + + @Test + public void createAffinityGroupSuccess() { + // Arrange + String subscriptionId = "12345"; + + // Act + // service.createAffinityGroup(subscriptionId); + + // Assert + } + + @Test + public void listAffinityGroupsSuccess() throws ServiceException { + // Arrange + String subscriptionId = "12345"; + + // Act + ListAffinityGroupsResult result = service.listAffinityGroups(subscriptionId); + + // Assert + assertNotNull(result); + + } +} From 27ad4dd0db3839ce1891181fb2ca1a4976335108 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 11 Jun 2013 17:21:00 -0700 Subject: [PATCH 03/57] initial check in to support SSL. --- .../services/management/Exports.java | 27 ++++++++++++------- .../implementation/ManagementRestProxy.java | 12 ++++++--- ...windowsazure.services.core.Builder$Exports | 2 +- .../management/ManagementIntegrationTest.java | 2 +- .../com.microsoft.windowsazure.properties | 1 + 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index deeaf03771a1c..0dee7e1bd9176 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -14,13 +14,17 @@ */ package com.microsoft.windowsazure.services.management; +import java.security.NoSuchAlgorithmException; import java.util.Map; +import javax.net.ssl.SSLContext; + import com.microsoft.windowsazure.services.core.Builder; import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.management.implementation.ManagementExceptionProcessor; -import com.microsoft.windowsazure.services.serviceBus.implementation.BrokerPropertiesMapper; +import com.microsoft.windowsazure.services.management.implementation.ManagementRestProxy; import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.client.urlconnection.HTTPSProperties; public class Exports implements Builder.Exports { @Override @@ -28,24 +32,29 @@ public void register(Builder.Registry registry) { // provide contract implementation registry.add(ManagementContract.class, ManagementExceptionProcessor.class); + registry.add(ManagementRestProxy.class); registry.add(UserAgentFilter.class); - // alter jersey client config for serviceBus + // alter jersey client config for service management registry.alter(ClientConfig.class, new Builder.Alteration() { @Override public ClientConfig alter(ClientConfig instance, Builder builder, Map properties) { - // need to avoid certain element prefixes, which the service does not ignore - - // add body reader/writer for EntryModel descendant classes - + SSLContext sslContext = null; + try { + sslContext = SSLContext.getInstance("SSL"); + } + catch (NoSuchAlgorithmException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + sslContext.init(null, myTrustManager, null); + instance.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, + new HTTPSProperties(null, sslContext)); return instance; } }); - // convenience provider to transform BrokerProperty headers to json - registry.add(BrokerPropertiesMapper.class); - } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index cb6dbd383c6d0..d6b7877f4f220 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -17,12 +17,14 @@ import java.util.Arrays; import javax.inject.Inject; +import javax.inject.Named; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; +import com.microsoft.windowsazure.services.management.ManagementConfiguration; import com.microsoft.windowsazure.services.management.ManagementContract; import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; import com.sun.jersey.api.client.Client; @@ -32,15 +34,17 @@ public class ManagementRestProxy implements ManagementContract { private Client channel; + private String uri; static Log log = LogFactory.getLog(ManagementContract.class); ServiceFilter[] filters; @Inject - public ManagementRestProxy(Client channel) { + public ManagementRestProxy(Client channel, @Named(ManagementConfiguration.URI) String uri) { this.channel = channel; this.filters = new ServiceFilter[0]; + this.uri = uri; } public ManagementRestProxy(Client channel, ServiceFilter[] serviceFilter) { @@ -57,7 +61,7 @@ public void setChannel(Client channel) { } private WebResource getResource() { - WebResource resource = getChannel().resource("uri"); + WebResource resource = getChannel().resource(this.uri); for (ServiceFilter filter : filters) { resource.addFilter(new ClientFilterAdapter(filter)); } @@ -73,8 +77,8 @@ public ManagementContract withFilter(ServiceFilter filter) { @Override public ListAffinityGroupsResult listAffinityGroups(String subscriptionId) { - ClientResponse clientResponse = getResource().path(subscriptionId).header("x-ms-version", "2013-03-01") - .get(ClientResponse.class); + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") + .header("x-ms-version", "2013-03-01").get(ClientResponse.class); String requestId = clientResponse.getHeaders().getFirst("x-ms-request-id"); return new ListAffinityGroupsResult(requestId); diff --git a/microsoft-azure-api/src/main/resources/META-INF/services/com.microsoft.windowsazure.services.core.Builder$Exports b/microsoft-azure-api/src/main/resources/META-INF/services/com.microsoft.windowsazure.services.core.Builder$Exports index e49188d4c09af..7ba2c8c10b49e 100644 --- a/microsoft-azure-api/src/main/resources/META-INF/services/com.microsoft.windowsazure.services.core.Builder$Exports +++ b/microsoft-azure-api/src/main/resources/META-INF/services/com.microsoft.windowsazure.services.core.Builder$Exports @@ -6,4 +6,4 @@ com.microsoft.windowsazure.services.serviceBus.implementation.Exports com.microsoft.windowsazure.services.core.utils.Exports com.microsoft.windowsazure.services.core.utils.pipeline.Exports com.microsoft.windowsazure.services.media.Exports - +com.microsoft.windowsazure.services.management.Exports diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index 310453a1d44ab..ed3ca7223397f 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -68,7 +68,7 @@ public void createAffinityGroupSuccess() { @Test public void listAffinityGroupsSuccess() throws ServiceException { // Arrange - String subscriptionId = "12345"; + String subscriptionId = "279b0675-cf67-467f-98f0-67ae31eb540f"; // Act ListAffinityGroupsResult result = service.listAffinityGroups(subscriptionId); diff --git a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties index 27b1e28139515..ac480e1b39af5 100644 --- a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties +++ b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties @@ -17,6 +17,7 @@ media.oauth.uri=%MEDIA.OAUTH.URI% media.oauth.client.id=%OMEDIA.AUTH.CLIENT.ID% media.oauth.client.secret=%MEDIA.OAUTH.CLIENT.SECRET% media.oauth.scope=urn:WindowsAzureMediaServices +management.uri=%MANAGEMENT.URI% testprefix.com.microsoft.windowsazure.services.core.Configuration.connectTimeout=3 testprefix.com.microsoft.windowsazure.services.core.Configuration.readTimeout=7 From 6a9c1f7181fc193f962147ebee9b368a93e1d20d Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 13 Jun 2013 16:28:36 -0700 Subject: [PATCH 04/57] adds prototype support for key store and trust store. --- .../services/management/Exports.java | 133 +++++++++++++++++- 1 file changed, 129 insertions(+), 4 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index 0dee7e1bd9176..332ea9d1e7edb 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -14,10 +14,22 @@ */ package com.microsoft.windowsazure.services.management; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; import java.util.Map; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; import com.microsoft.windowsazure.services.core.Builder; import com.microsoft.windowsazure.services.core.UserAgentFilter; @@ -39,9 +51,15 @@ public void register(Builder.Registry registry) { registry.alter(ClientConfig.class, new Builder.Alteration() { @Override - public ClientConfig alter(ClientConfig instance, Builder builder, Map properties) { + public ClientConfig alter(ClientConfig clientConfig, Builder builder, Map properties) { + + String keyStoreName = "c:\\src\\keystore.jks"; + // String trustStoreName = "c:\\src\\truststore.jks"; + String keyStorePass = "newpass"; + String keyPass = "keypass"; SSLContext sslContext = null; + try { sslContext = SSLContext.getInstance("SSL"); } @@ -49,12 +67,119 @@ public ClientConfig alter(ClientConfig instance, Builder builder, Map Date: Sun, 16 Jun 2013 21:54:01 -0700 Subject: [PATCH 05/57] intermedia checkin for affinity group support. --- .../org.eclipse.core.resources.prefs | 1 + microsoft-azure-api/pom.xml | 4 +- .../management/ManagementContract.java | 5 +- .../ManagementExceptionProcessor.java | 5 +- .../implementation/ManagementRestProxy.java | 7 +- .../management/models/AffinityGroupInfo.java | 63 ++++++++ .../management/models/ListResult.java | 152 ++++++++++++++++++ 7 files changed, 228 insertions(+), 9 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfo.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java diff --git a/microsoft-azure-api/.settings/org.eclipse.core.resources.prefs b/microsoft-azure-api/.settings/org.eclipse.core.resources.prefs index 29abf99956411..5240b69c1bc49 100644 --- a/microsoft-azure-api/.settings/org.eclipse.core.resources.prefs +++ b/microsoft-azure-api/.settings/org.eclipse.core.resources.prefs @@ -3,4 +3,5 @@ encoding//src/main/java=UTF-8 encoding//src/main/resources=UTF-8 encoding//src/test/java=UTF-8 encoding//src/test/resources=UTF-8 +encoding//target/generated-sources/xjc=UTF-8 encoding/=UTF-8 diff --git a/microsoft-azure-api/pom.xml b/microsoft-azure-api/pom.xml index 9c0bb981d0a7e..bec3d45818d69 100644 --- a/microsoft-azure-api/pom.xml +++ b/microsoft-azure-api/pom.xml @@ -134,7 +134,7 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.1 1.6 1.6 @@ -143,7 +143,7 @@ org.jvnet.jaxb2.maven2 maven-jaxb2-plugin - 0.8.0 + 0.8.3 generate-sources diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java index bbe40816dd68f..0481e9afff0d2 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -16,7 +16,8 @@ import com.microsoft.windowsazure.services.core.FilterableService; import com.microsoft.windowsazure.services.core.ServiceException; -import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.ListResult; /** * @@ -41,7 +42,7 @@ public interface ManagementContract extends FilterableService listAffinityGroups(String subscriptionId) throws ServiceException; void listVirtualMachines(String subscriptionId); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java index 10ef5d855b487..db7c45b353089 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java @@ -23,7 +23,8 @@ import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; import com.microsoft.windowsazure.services.management.ManagementContract; -import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.ListResult; import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.UniformInterfaceException; @@ -52,7 +53,7 @@ private ServiceException processCatch(ServiceException e) { } @Override - public ListAffinityGroupsResult listAffinityGroups(String subscriptionId) throws ServiceException { + public ListResult listAffinityGroups(String subscriptionId) throws ServiceException { try { return next.listAffinityGroups(subscriptionId); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index d6b7877f4f220..6e9d24bc255df 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -26,7 +26,8 @@ import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; import com.microsoft.windowsazure.services.management.ManagementConfiguration; import com.microsoft.windowsazure.services.management.ManagementContract; -import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.ListResult; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; @@ -76,11 +77,11 @@ public ManagementContract withFilter(ServiceFilter filter) { } @Override - public ListAffinityGroupsResult listAffinityGroups(String subscriptionId) { + public ListResult listAffinityGroups(String subscriptionId) { ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") .header("x-ms-version", "2013-03-01").get(ClientResponse.class); String requestId = clientResponse.getHeaders().getFirst("x-ms-request-id"); - return new ListAffinityGroupsResult(requestId); + return new ListResult(null); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfo.java new file mode 100644 index 0000000000000..cfc9c37531f89 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfo.java @@ -0,0 +1,63 @@ +/** + * 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.management.models; + +/** + * Type containing data about affinity group. + * + */ +public class AffinityGroupInfo { + private String name; + private String label; + private String description; + private String location; + + public String getName() { + return this.name; + } + + public AffinityGroupInfo setName(String name) { + this.name = name; + return this; + } + + public String getLabel() { + return this.label; + } + + public AffinityGroupInfo setLabel(String label) { + this.label = label; + return this; + } + + public String getDescription() { + return this.description; + } + + public AffinityGroupInfo setDescription(String description) { + this.description = description; + return this; + } + + public String getLocation() { + return this.location; + } + + public AffinityGroupInfo setLocation(String location) { + this.location = location; + return this; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java new file mode 100644 index 0000000000000..198d14003264c --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java @@ -0,0 +1,152 @@ +/** + * 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.management.models; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +/** + * Wrapper class for all returned lists from Media Services + * + */ +public class ListResult implements List { + + private final List contents; + + public ListResult(Collection contentList) { + contents = Collections.unmodifiableList(new ArrayList(contentList)); + } + + @Override + public boolean add(T element) { + return contents.add(element); + } + + @Override + public void add(int index, T element) { + contents.add(index, element); + } + + @Override + public boolean addAll(Collection c) { + return contents.addAll(c); + } + + @Override + public boolean addAll(int index, Collection c) { + return contents.addAll(index, c); + } + + @Override + public void clear() { + contents.clear(); + } + + @Override + public boolean contains(Object object) { + return contents.contains(object); + } + + @Override + public boolean containsAll(Collection c) { + return contents.containsAll(c); + } + + @Override + public T get(int index) { + return contents.get(index); + } + + @Override + public int indexOf(Object object) { + return contents.indexOf(object); + } + + @Override + public boolean isEmpty() { + return contents.isEmpty(); + } + + @Override + public Iterator iterator() { + return contents.iterator(); + } + + @Override + public int lastIndexOf(Object object) { + return contents.lastIndexOf(object); + } + + @Override + public ListIterator listIterator() { + return contents.listIterator(); + } + + @Override + public ListIterator listIterator(int index) { + return contents.listIterator(index); + + } + + @Override + public boolean remove(Object o) { + return contents.remove(o); + } + + @Override + public T remove(int index) { + return contents.remove(index); + } + + @Override + public boolean removeAll(Collection c) { + return contents.removeAll(c); + } + + @Override + public boolean retainAll(Collection c) { + return contents.retainAll(c); + } + + @Override + public T set(int index, T element) { + return contents.set(index, element); + } + + @Override + public int size() { + return contents.size(); + } + + @Override + public List subList(int fromIndex, int toIndex) { + return contents.subList(fromIndex, toIndex); + } + + @Override + public Object[] toArray() { + return contents.toArray(); + } + + @Override + public U[] toArray(U[] a) { + return contents.toArray(a); + } +} From 4251b7326ae1af3ee425e23dd0da459461261979 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 18 Jun 2013 15:53:26 -0700 Subject: [PATCH 06/57] update on service management infrastructure. --- .../services/management/Exports.java | 6 +-- .../implementation/ManagementRestProxy.java | 3 +- .../management/models/ListResult.java | 4 +- .../management/models/OperationResult.java | 42 +++++++++++++++++++ .../management/ManagementIntegrationTest.java | 5 ++- 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index 332ea9d1e7edb..e807794483c3a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -53,10 +53,10 @@ public void register(Builder.Registry registry) { @Override public ClientConfig alter(ClientConfig clientConfig, Builder builder, Map properties) { - String keyStoreName = "c:\\src\\keystore.jks"; + String keyStoreName = "d:\\src\\javacert\\azurecertkeystore.jks"; // String trustStoreName = "c:\\src\\truststore.jks"; - String keyStorePass = "newpass"; - String keyPass = "keypass"; + String keyStorePass = "azurerocks"; + String keyPass = "azurecert"; SSLContext sslContext = null; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 6e9d24bc255df..4e9f6ed9393da 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -15,6 +15,7 @@ package com.microsoft.windowsazure.services.management.implementation; import java.util.Arrays; +import java.util.UUID; import javax.inject.Inject; import javax.inject.Named; @@ -81,8 +82,8 @@ public ListResult listAffinityGroups(String subscriptionId) { ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") .header("x-ms-version", "2013-03-01").get(ClientResponse.class); String requestId = clientResponse.getHeaders().getFirst("x-ms-request-id"); + UUID requestIdUUID = UUID.fromString(requestId); return new ListResult(null); - } @Override diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java index 198d14003264c..9297aa3837863 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java @@ -21,16 +21,18 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; +import java.util.UUID; /** * Wrapper class for all returned lists from Media Services * */ -public class ListResult implements List { +public class ListResult extends OperationResult implements List { private final List contents; public ListResult(Collection contentList) { + super(3, UUID.randomUUID()); contents = Collections.unmodifiableList(new ArrayList(contentList)); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java new file mode 100644 index 0000000000000..e556d078434bf --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java @@ -0,0 +1,42 @@ +/** + * 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.management.models; + +import java.util.UUID; + +/** + * The base result class for all the result of service management operation. + * + */ +public class OperationResult { + + private final UUID requestId; + private final int statusCode; + + public OperationResult(int statusCode, UUID requestId) { + this.statusCode = statusCode; + this.requestId = requestId; + } + + public int getStatusCode() { + return this.statusCode; + } + + public UUID getRequestId() { + return this.requestId; + } + +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index ed3ca7223397f..97ae16911e8bf 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -26,7 +26,8 @@ import com.microsoft.windowsazure.services.core.Builder.Registry; import com.microsoft.windowsazure.services.core.Configuration; import com.microsoft.windowsazure.services.core.ServiceException; -import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.ListResult; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.filter.LoggingFilter; @@ -71,7 +72,7 @@ public void listAffinityGroupsSuccess() throws ServiceException { String subscriptionId = "279b0675-cf67-467f-98f0-67ae31eb540f"; // Act - ListAffinityGroupsResult result = service.listAffinityGroups(subscriptionId); + ListResult result = service.listAffinityGroups(subscriptionId); // Assert assertNotNull(result); From 7a2e1d3a323edd74fb2454455bf24af383fffb81 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 19 Jun 2013 17:48:35 -0700 Subject: [PATCH 07/57] update on affinity group unit tests. --- .../management/ManagementConfiguration.java | 2 + .../management/ManagementContract.java | 9 +- .../implementation/ManagementRestProxy.java | 25 +++- .../management/ManagementIntegrationTest.java | 114 ++++++++++++++++-- 4 files changed, 137 insertions(+), 13 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java index ff8015b9921dc..d95a6f17d46ea 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java @@ -34,6 +34,8 @@ public class ManagementConfiguration { */ public final static String URI = "management.uri"; + public static final String SUBSCRIPTIONID = "management.subscriptionid"; + /** * Creates a service bus configuration using the specified namespace, name, and password. * diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java index 0481e9afff0d2..856760bc91d3c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -42,8 +42,13 @@ public interface ManagementContract extends FilterableService listAffinityGroups(String subscriptionId) throws ServiceException; + ListResult listAffinityGroups() throws ServiceException; - void listVirtualMachines(String subscriptionId); + CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, + String expectedLocation); + + GetAffinityGroupResult getAffinityGroup(String affinityGroupName); + + void deleteAffinityGroup(String affinityGroupName); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 4e9f6ed9393da..0cac5890805a5 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -37,12 +37,14 @@ public class ManagementRestProxy implements ManagementContract { private Client channel; private String uri; + private String subscriptionId; static Log log = LogFactory.getLog(ManagementContract.class); ServiceFilter[] filters; @Inject - public ManagementRestProxy(Client channel, @Named(ManagementConfiguration.URI) String uri) { + public ManagementRestProxy(Client channel, @Named(ManagementConfiguration.URI) String uri, + @Named(ManagementConfiguration.SUBSCRIPTIONID) String subscriptionId) { this.channel = channel; this.filters = new ServiceFilter[0]; @@ -78,7 +80,7 @@ public ManagementContract withFilter(ServiceFilter filter) { } @Override - public ListResult listAffinityGroups(String subscriptionId) { + public ListResult listAffinityGroups() { ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") .header("x-ms-version", "2013-03-01").get(ClientResponse.class); String requestId = clientResponse.getHeaders().getFirst("x-ms-request-id"); @@ -92,4 +94,23 @@ public void listVirtualMachines(String subscriptionId) { } + @Override + public CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, + String expectedLocation) { + // TODO Auto-generated method stub + return null; + } + + @Override + public GetAffinityGroupResult getAffinityGroup(String affinityGroupName) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void deleteAffinityGroup(String affinityGroupName) { + // TODO Auto-generated method stub + + } + } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index 97ae16911e8bf..675004b7f9254 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -26,6 +26,7 @@ import com.microsoft.windowsazure.services.core.Builder.Registry; import com.microsoft.windowsazure.services.core.Configuration; import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.core.storage.utils.Base64; import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; import com.microsoft.windowsazure.services.management.models.ListResult; import com.sun.jersey.api.client.Client; @@ -44,9 +45,9 @@ public void createService() throws Exception { Registry builder = (Registry) config.getBuilder(); builder.alter(Client.class, new Alteration() { @Override - public Client alter(Client instance, Builder builder, Map properties) { - instance.addFilter(new LoggingFilter()); - return instance; + public Client alter(Client client, Builder builder, Map properties) { + client.addFilter(new LoggingFilter()); + return client; } }); @@ -58,24 +59,119 @@ public Client alter(Client instance, Builder builder, Map proper @Test public void createAffinityGroupSuccess() { // Arrange - String subscriptionId = "12345"; + String expectedAffinityGroupName = "testCreateAffinityGroupSuccess"; + String expectedLabel = Base64.encode("testCreateAffinityGroupSuccess".getBytes("UTF-8")); + String expectedLocation = "US West"; // Act - // service.createAffinityGroup(subscriptionId); + CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(expectedAffinityGroupName, + expectedLabel, expectedLocation); + AffinityGroupInfo affinityGroupInfo = createAffinityGroupResult.getValue(); // Assert + assertEquals(expectedAffinityGroupName, affinityGroupInfo.getName()); + assertEquals(expectedLabel, affinityGroupInfo.getLabel()); + assertEquals(expectedLocation, affinityGroupInfo.getLocation()); + } @Test - public void listAffinityGroupsSuccess() throws ServiceException { + public void createAffinityGroupWithOptionalParametersSuccess() { // Arrange - String subscriptionId = "279b0675-cf67-467f-98f0-67ae31eb540f"; + String expectedAffinityGroupName = "testCreateAffinityGroupWithOptionalParametersSuccess"; + String expectedLabel = Base64.encode("testCreateAffinityGroupWithOptionalParameterSuccess".getBytes("UTF-8")); + String expectedLocation = "US West"; + String expectedDescription = "testCreateAffinityGroupWithOptionalParameterSuccessDescription"; + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions() + .setDescription(expectedDescription); + + // Act + CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(expectedAffinityGroupName, + expectedLabel, expectedLocation, createAffinityGroupOptions); + AffinityGroupInfo affinityGroupInfo = createAffinityGroupResult.getValue(); + + // Assert + assertEquals(expectedAffinityGroupName, affinityGroupInfo.getName()); + assertEquals(expectedLabel, affinityGroupInfo.getLabel()); + assertEquals(expectedDescription, affinityGroupInfo.getDescription()); + assertEquals(expectedLocation, affinityGroupInfo.getLocation()); + + } + + @Test + public void listAffinityGroupsSuccess() throws ServiceException { + // Arrange // Act - ListResult result = service.listAffinityGroups(subscriptionId); + ListResult listAffinityGroupsResult = service.listAffinityGroups(); // Assert - assertNotNull(result); + assertNotNull(listAffinityGroupsResult); } + + @Test + public void listAffinityGroupsWithOptionsSuccess() throws ServiceException { + // Arrange + ListAffinityGroupsOptions listAffinityGroupsOptions = new ListAffinityGroupsOptions(); + + // Act + ListResult listAffinityGroupsResult = service.listAffinityGroups(listAffinityGroupsOptions); + + // Assert + assertNotNull(listAffinityGroupsResult); + } + + @Test + public void deleteAffinityGroupSuccess() throws ServiceException { + // Arrange + String affinityGroupName = "testDeleteAffinityGroupSuccess"; + String label = Base64.encode("testDeleteAffinityGroupSuccesslabel".getBytes("UTF-8")); + String location = "West US"; + service.createAffinityGroup(affinityGroupName, label, location); + + // Act + service.deleteAffinityGroup(affinityGroupName); + + // Assert + + } + + @Test + public void updateAffinityGroupSuccess() throws ServiceException { + // Arrange + String expectedAffinityGroupName = "testUpdateAffinityGroupSuccess"; + String expectedAffinityGroupLabel = Base64.encode("testUpdateAffinityGroupSuccess".getBytes("UTF-8")); + String expectedLocation = "US West"; + String expectedDescription = "updateAffinityGroupSuccess"; + service.createAffinityGroup(expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); + UpdateAffinityGroupOptions updateAffinityGroupOptions = new UpdateAffinityGroupOptions() + .setDescription(expectedDescription); + + // Act + UpdateAffinityGroupResult updateAffinityGroupResult = service.updateAffinityGroup(expectedAffinityGroupLabel, + updateAffinityGroupOptions); + AffinityGroupInfo affinityGroupInfo = updateAffinityGroupResult.getValue(); + + // Assert + assertEquals(expectedDescription, affinityGroupInfo.getDescription()); + + } + + @Test + public void getAffinityGroupPropertiesSuccess() throws ServiceException { + // Arrange + String expectedAffinityGroupName = "testGetAffinityGroupPropertiesSuccess"; + String expectedAffinityGroupLabel = Base64.encode("testGetAffinityGroupPropertiesSuccess".getBytes("UTF-8")); + String expectedLocation = "US West"; + service.createAffinityGroup(expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); + + // Act + GetAffinityGroupResult getAffinityGroupResult = service.getAffinityGroup(expectedAffinityGroupName); + AffinityGroupInfo affinityGroupInfo = getAffinityGroupResult.getValue(); + + // Assert + assertEquals(expectedAffinityGroupName, affinityGroupInfo.getName()); + } + } From 82e7af3442da34e0d3a5dae6bd0c076b5579339a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 20 Jun 2013 06:59:05 -0700 Subject: [PATCH 08/57] update management integration test. --- .../services/management/ManagementIntegrationTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index ed3ca7223397f..97ae16911e8bf 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -26,7 +26,8 @@ import com.microsoft.windowsazure.services.core.Builder.Registry; import com.microsoft.windowsazure.services.core.Configuration; import com.microsoft.windowsazure.services.core.ServiceException; -import com.microsoft.windowsazure.services.management.models.ListAffinityGroupsResult; +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.ListResult; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.filter.LoggingFilter; @@ -71,7 +72,7 @@ public void listAffinityGroupsSuccess() throws ServiceException { String subscriptionId = "279b0675-cf67-467f-98f0-67ae31eb540f"; // Act - ListAffinityGroupsResult result = service.listAffinityGroups(subscriptionId); + ListResult result = service.listAffinityGroups(subscriptionId); // Assert assertNotNull(result); From f5718f0526681fbda4588ea202a9e294fb570f71 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 20 Jun 2013 09:52:43 -0700 Subject: [PATCH 09/57] add classes into models directory. --- .../management/ManagementContract.java | 11 +++++ .../ManagementExceptionProcessor.java | 49 ++++++++++++++----- .../implementation/ManagementRestProxy.java | 25 +++++++--- .../models/CreateAffinityGroupOptions.java | 29 +++++++++++ .../models/CreateAffinityGroupResult.java | 37 ++++++++++++++ .../models/GetAffinityGroupResult.java | 35 +++++++++++++ .../management/models/OperationResult.java | 4 +- .../models/UpdateAffinityGroupOptions.java | 29 +++++++++++ .../models/UpdateAffinityGroupResult.java | 35 +++++++++++++ .../management/ManagementIntegrationTest.java | 27 ++++------ 10 files changed, 243 insertions(+), 38 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java index 856760bc91d3c..6690c41e16621 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -17,7 +17,12 @@ import com.microsoft.windowsazure.services.core.FilterableService; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions; +import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupResult; +import com.microsoft.windowsazure.services.management.models.GetAffinityGroupResult; import com.microsoft.windowsazure.services.management.models.ListResult; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupResult; /** * @@ -51,4 +56,10 @@ CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, void deleteAffinityGroup(String affinityGroupName); + CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, + String expectedLocation, CreateAffinityGroupOptions createAffinityGroupOptions); + + UpdateAffinityGroupResult updateAffinityGroup(String expectedAffinityGroupLabel, + UpdateAffinityGroupOptions updateAffinityGroupOptions); + } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java index db7c45b353089..75e9ad91d635b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java @@ -24,9 +24,12 @@ import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; import com.microsoft.windowsazure.services.management.ManagementContract; import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions; +import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupResult; +import com.microsoft.windowsazure.services.management.models.GetAffinityGroupResult; import com.microsoft.windowsazure.services.management.models.ListResult; -import com.sun.jersey.api.client.ClientHandlerException; -import com.sun.jersey.api.client.UniformInterfaceException; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupResult; public class ManagementExceptionProcessor implements ManagementContract { @@ -53,22 +56,42 @@ private ServiceException processCatch(ServiceException e) { } @Override - public ListResult listAffinityGroups(String subscriptionId) throws ServiceException { - try { - return next.listAffinityGroups(subscriptionId); - } - catch (UniformInterfaceException e) { - throw processCatch(new ServiceException(e)); - } - catch (ClientHandlerException e) { - throw processCatch(new ServiceException(e)); - } + public ListResult listAffinityGroups() throws ServiceException { + // TODO Auto-generated method stub + return null; + } + + @Override + public CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, + String expectedLocation) { + // TODO Auto-generated method stub + return null; + } + + @Override + public GetAffinityGroupResult getAffinityGroup(String affinityGroupName) { + // TODO Auto-generated method stub + return null; } @Override - public void listVirtualMachines(String subscriptionId) { + public void deleteAffinityGroup(String affinityGroupName) { // TODO Auto-generated method stub } + @Override + public CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, + String expectedLocation, CreateAffinityGroupOptions createAffinityGroupOptions) { + // TODO Auto-generated method stub + return null; + } + + @Override + public UpdateAffinityGroupResult updateAffinityGroup(String expectedAffinityGroupLabel, + UpdateAffinityGroupOptions updateAffinityGroupOptions) { + // TODO Auto-generated method stub + return null; + } + } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 0cac5890805a5..bb8645a38bb74 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -28,7 +28,12 @@ import com.microsoft.windowsazure.services.management.ManagementConfiguration; import com.microsoft.windowsazure.services.management.ManagementContract; import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions; +import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupResult; +import com.microsoft.windowsazure.services.management.models.GetAffinityGroupResult; import com.microsoft.windowsazure.services.management.models.ListResult; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupResult; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; @@ -88,12 +93,6 @@ public ListResult listAffinityGroups() { return new ListResult(null); } - @Override - public void listVirtualMachines(String subscriptionId) { - // TODO Auto-generated method stub - - } - @Override public CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, String expectedLocation) { @@ -113,4 +112,18 @@ public void deleteAffinityGroup(String affinityGroupName) { } + @Override + public CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, + String expectedLocation, CreateAffinityGroupOptions createAffinityGroupOptions) { + // TODO Auto-generated method stub + return null; + } + + @Override + public UpdateAffinityGroupResult updateAffinityGroup(String expectedAffinityGroupLabel, + UpdateAffinityGroupOptions updateAffinityGroupOptions) { + // TODO Auto-generated method stub + return null; + } + } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java new file mode 100644 index 0000000000000..1d9f207eebe8a --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java @@ -0,0 +1,29 @@ +/** + * 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.management.models; + +/** + * The base result class for all the result of service management operation. + * + */ +public class CreateAffinityGroupOptions { + + public CreateAffinityGroupOptions setDescription(String expectedDescription) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java new file mode 100644 index 0000000000000..07f79a531cf6c --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java @@ -0,0 +1,37 @@ +/** + * 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.management.models; + +import java.util.UUID; + +/** + * The base result class for all the result of service management operation. + * + */ +public class CreateAffinityGroupResult extends OperationResult { + + public CreateAffinityGroupResult(int statusCode, UUID requestId) { + super(statusCode, requestId); + // TODO Auto-generated constructor stub + + } + + public AffinityGroupInfo getValue() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java new file mode 100644 index 0000000000000..26f4d1e16b8ad --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java @@ -0,0 +1,35 @@ +/** + * 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.management.models; + +import java.util.UUID; + +/** + * The base result class for all the result of service management operation. + * + */ +public class GetAffinityGroupResult extends OperationResult { + + public GetAffinityGroupResult(int statusCode, UUID requestId) { + super(statusCode, requestId); + } + + public AffinityGroupInfo getValue() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java index e556d078434bf..2788a20617662 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java @@ -23,8 +23,8 @@ */ public class OperationResult { - private final UUID requestId; - private final int statusCode; + protected final UUID requestId; + protected final int statusCode; public OperationResult(int statusCode, UUID requestId) { this.statusCode = statusCode; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java new file mode 100644 index 0000000000000..2a66a7c5aeea0 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java @@ -0,0 +1,29 @@ +/** + * 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.management.models; + +/** + * The base result class for all the result of service management operation. + * + */ +public class UpdateAffinityGroupOptions { + + public UpdateAffinityGroupOptions setDescription(String description) { + // TODO Auto-generated method stub + return this; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java new file mode 100644 index 0000000000000..e935e1c6afdea --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java @@ -0,0 +1,35 @@ +/** + * 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.management.models; + +import java.util.UUID; + +/** + * The base result class for all the result of service management operation. + * + */ +public class UpdateAffinityGroupResult extends OperationResult { + + public UpdateAffinityGroupResult(int statusCode, UUID requestId) { + super(statusCode, requestId); + } + + public AffinityGroupInfo getValue() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index 675004b7f9254..555643006ef39 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -28,7 +28,12 @@ import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.storage.utils.Base64; import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions; +import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupResult; +import com.microsoft.windowsazure.services.management.models.GetAffinityGroupResult; import com.microsoft.windowsazure.services.management.models.ListResult; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupResult; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.filter.LoggingFilter; @@ -57,7 +62,7 @@ public Client alter(Client client, Builder builder, Map properti } @Test - public void createAffinityGroupSuccess() { + public void createAffinityGroupSuccess() throws Exception { // Arrange String expectedAffinityGroupName = "testCreateAffinityGroupSuccess"; String expectedLabel = Base64.encode("testCreateAffinityGroupSuccess".getBytes("UTF-8")); @@ -76,7 +81,7 @@ public void createAffinityGroupSuccess() { } @Test - public void createAffinityGroupWithOptionalParametersSuccess() { + public void createAffinityGroupWithOptionalParametersSuccess() throws Exception { // Arrange String expectedAffinityGroupName = "testCreateAffinityGroupWithOptionalParametersSuccess"; String expectedLabel = Base64.encode("testCreateAffinityGroupWithOptionalParameterSuccess".getBytes("UTF-8")); @@ -111,19 +116,7 @@ public void listAffinityGroupsSuccess() throws ServiceException { } @Test - public void listAffinityGroupsWithOptionsSuccess() throws ServiceException { - // Arrange - ListAffinityGroupsOptions listAffinityGroupsOptions = new ListAffinityGroupsOptions(); - - // Act - ListResult listAffinityGroupsResult = service.listAffinityGroups(listAffinityGroupsOptions); - - // Assert - assertNotNull(listAffinityGroupsResult); - } - - @Test - public void deleteAffinityGroupSuccess() throws ServiceException { + public void deleteAffinityGroupSuccess() throws ServiceException, Exception { // Arrange String affinityGroupName = "testDeleteAffinityGroupSuccess"; String label = Base64.encode("testDeleteAffinityGroupSuccesslabel".getBytes("UTF-8")); @@ -138,7 +131,7 @@ public void deleteAffinityGroupSuccess() throws ServiceException { } @Test - public void updateAffinityGroupSuccess() throws ServiceException { + public void updateAffinityGroupSuccess() throws Exception { // Arrange String expectedAffinityGroupName = "testUpdateAffinityGroupSuccess"; String expectedAffinityGroupLabel = Base64.encode("testUpdateAffinityGroupSuccess".getBytes("UTF-8")); @@ -159,7 +152,7 @@ public void updateAffinityGroupSuccess() throws ServiceException { } @Test - public void getAffinityGroupPropertiesSuccess() throws ServiceException { + public void getAffinityGroupPropertiesSuccess() throws Exception { // Arrange String expectedAffinityGroupName = "testGetAffinityGroupPropertiesSuccess"; String expectedAffinityGroupLabel = Base64.encode("testGetAffinityGroupPropertiesSuccess".getBytes("UTF-8")); From bed64a0e8587a080b8133d52536e9a71d2b4ca50 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 20 Jun 2013 14:15:25 -0700 Subject: [PATCH 10/57] update service management configuration class. --- .../management/ManagementConfiguration.java | 55 +++++++++---------- .../management/ManagementIntegrationTest.java | 7 --- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java index d95a6f17d46ea..c84c82adce135 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java @@ -23,55 +23,50 @@ public class ManagementConfiguration { /** - * Defines the location of the certificate. + * Defines the location of the keystore. * */ - public final static String CERTIFICATE_LOCATION = "certificate.location"; + public final static String KEYSTORE_PATH = "management.keystore.path"; /** - * Defines the configuration URI constant. + * Defines the URI of service management. * */ public final static String URI = "management.uri"; - public static final String SUBSCRIPTIONID = "management.subscriptionid"; + /** + * Defines the subscription ID of the service management. + */ + public static final String SUBSCRIPTION_ID = "management.subscription.id"; /** - * Creates a service bus configuration using the specified namespace, name, and password. - * - * @param namespace - * A String object that represents the namespace. - * - * @param authenticationName - * A String object that represents the authentication name. + * Creates a service management configuration using the specified uri, keystore path, and subscription id. * - * @param authenticationPassword - * A String object that represents the authentication password. * - * @param serviceBusRootUri - * A String object containing the base URI that is added to your - * Service Bus namespace to form the URI to connect to the Service Bus service. + * @param uri + * A String object that represents the URI. * - * To access the default public Azure service, pass ".servicebus.windows.net" + * @param subscriptionId + * A String object that represents the subscription ID. * - * @param wrapRootUri - * A String object containing the base URI that is added to your - * Service Bus namespace to form the URI to get an access token for the Service - * Bus service. - * - * To access the default public Azure service, pass "-sb.accesscontrol.windows.net/WRAPv0.9" + * @param keystorePath + * A String object that represents the path of the keystore. * * @return * A Configuration object that can be used when creating an instance of the - * ServiceBusService class. + * ManagementService class. * */ - public static Configuration configureWithWrapAuthentication(String uri, String certificateLocation) { - return configureWithWrapAuthentication(null, Configuration.getInstance(), uri, certificateLocation); + public static Configuration configure(String uri, String subscriptionId) { + return configure(null, Configuration.getInstance(), uri, subscriptionId, null); + } + + public static Configuration configure(String uri, String subscriptionId, String keyStorePath) { + return configure(null, Configuration.getInstance(), uri, subscriptionId, keyStorePath); } - public static Configuration configureWithWrapAuthentication(String profile, Configuration configuration, - String uri, String certificateLocation) { + public static Configuration configure(String profile, Configuration configuration, String uri, + String subscriptionId, String keyStoreLocation) { if (profile == null) { profile = ""; @@ -81,8 +76,8 @@ else if (profile.length() != 0 && !profile.endsWith(".")) { } configuration.setProperty(profile + URI, "https://" + uri); - - configuration.setProperty(profile + CERTIFICATE_LOCATION, certificateLocation); + configuration.setProperty(profile + SUBSCRIPTION_ID, subscriptionId); + configuration.setProperty(profile + KEYSTORE_PATH, keyStoreLocation); return configuration; } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index a8f6f676fa37b..555643006ef39 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -26,10 +26,7 @@ import com.microsoft.windowsazure.services.core.Builder.Registry; import com.microsoft.windowsazure.services.core.Configuration; import com.microsoft.windowsazure.services.core.ServiceException; -<<<<<<< HEAD -======= import com.microsoft.windowsazure.services.core.storage.utils.Base64; ->>>>>>> 7a2e1d3a323edd74fb2454455bf24af383fffb81 import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions; import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupResult; @@ -111,11 +108,7 @@ public void listAffinityGroupsSuccess() throws ServiceException { // Arrange // Act -<<<<<<< HEAD - ListResult result = service.listAffinityGroups(subscriptionId); -======= ListResult listAffinityGroupsResult = service.listAffinityGroups(); ->>>>>>> 7a2e1d3a323edd74fb2454455bf24af383fffb81 // Assert assertNotNull(listAffinityGroupsResult); From 0471281c8a7e4469ca9e32b0737eb96fb1b0a2a7 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 20 Jun 2013 17:18:03 -0700 Subject: [PATCH 11/57] modify jaxb plugin to enable generate both service management and service bus. --- .../org.eclipse.core.resources.prefs | 1 - microsoft-azure-api/pom.xml | 24 ++++++ .../implementation/ManagementRestProxy.java | 32 ++++++-- .../management/models/ListResult.java | 4 +- .../resources/management/package-names.xjb | 13 +++ .../schemas.microsoft.com.windowsazure.xsd | 26 ++++++ .../{ => serviceBus}/package-names.xjb | 1 + ...as.microsoft.com.2003.10.Serialization.xsd | 82 +++++++++---------- ...netservices.2010.10.servicebus.connect.xsd | 0 .../{ => serviceBus}/servicebus-atom.xsd | 0 10 files changed, 131 insertions(+), 52 deletions(-) create mode 100644 microsoft-azure-api/src/main/resources/management/package-names.xjb create mode 100644 microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd rename microsoft-azure-api/src/main/resources/{ => serviceBus}/package-names.xjb (99%) rename microsoft-azure-api/src/main/resources/{ => serviceBus}/schemas.microsoft.com.2003.10.Serialization.xsd (98%) rename microsoft-azure-api/src/main/resources/{ => serviceBus}/schemas.microsoft.com.netservices.2010.10.servicebus.connect.xsd (100%) rename microsoft-azure-api/src/main/resources/{ => serviceBus}/servicebus-atom.xsd (100%) diff --git a/microsoft-azure-api/.settings/org.eclipse.core.resources.prefs b/microsoft-azure-api/.settings/org.eclipse.core.resources.prefs index 5240b69c1bc49..29abf99956411 100644 --- a/microsoft-azure-api/.settings/org.eclipse.core.resources.prefs +++ b/microsoft-azure-api/.settings/org.eclipse.core.resources.prefs @@ -3,5 +3,4 @@ encoding//src/main/java=UTF-8 encoding//src/main/resources=UTF-8 encoding//src/test/java=UTF-8 encoding//src/test/resources=UTF-8 -encoding//target/generated-sources/xjc=UTF-8 encoding/=UTF-8 diff --git a/microsoft-azure-api/pom.xml b/microsoft-azure-api/pom.xml index bec3d45818d69..8a13839e8423c 100644 --- a/microsoft-azure-api/pom.xml +++ b/microsoft-azure-api/pom.xml @@ -146,10 +146,34 @@ 0.8.3 + serviceBus generate-sources generate + + target/generated-sources/xjc/com/microsoft/windowsazure/services/serviceBus/implementation + src/main/resources/serviceBus + + servicebus-atom.xsd + + com.microsoft.windowsazure.services.serviceBus.implementation + + + + management + generate-sources + + generate + + + target/generated-sources/xjc/com/microsoft/windowsazure/services/management/implementation + src/main/resources/management/ + + schemas.microsoft.com.windowsazure.xsd + + com.microsoft.windowsazure.services.management.implementation + diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index bb8645a38bb74..00dfe580da21a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -14,6 +14,7 @@ */ package com.microsoft.windowsazure.services.management.implementation; +import java.util.ArrayList; import java.util.Arrays; import java.util.UUID; @@ -25,6 +26,7 @@ import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; +import com.microsoft.windowsazure.services.core.utils.pipeline.PipelineHelpers; import com.microsoft.windowsazure.services.management.ManagementConfiguration; import com.microsoft.windowsazure.services.management.ManagementContract; import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; @@ -41,24 +43,32 @@ public class ManagementRestProxy implements ManagementContract { private Client channel; - private String uri; - private String subscriptionId; + private final String uri; + private final String subscriptionId; + private final String keyStorePath; static Log log = LogFactory.getLog(ManagementContract.class); ServiceFilter[] filters; @Inject public ManagementRestProxy(Client channel, @Named(ManagementConfiguration.URI) String uri, - @Named(ManagementConfiguration.SUBSCRIPTIONID) String subscriptionId) { + @Named(ManagementConfiguration.SUBSCRIPTION_ID) String subscriptionId, + @Named(ManagementConfiguration.KEYSTORE_PATH) String keyStorePath) { this.channel = channel; this.filters = new ServiceFilter[0]; this.uri = uri; + this.subscriptionId = subscriptionId; + this.keyStorePath = keyStorePath; } - public ManagementRestProxy(Client channel, ServiceFilter[] serviceFilter) { + public ManagementRestProxy(Client channel, ServiceFilter[] serviceFilter, String uri, String subscriptionId, + String keyStorePath) { this.channel = channel; this.filters = serviceFilter; + this.uri = uri; + this.subscriptionId = subscriptionId; + this.keyStorePath = keyStorePath; } public Client getChannel() { @@ -77,20 +87,26 @@ private WebResource getResource() { return resource; } + private UUID getRequestId(ClientResponse clientResponse) { + String requestId = clientResponse.getHeaders().getFirst("x-ms-request-id"); + return UUID.fromString(requestId); + } + @Override public ManagementContract withFilter(ServiceFilter filter) { ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); newFilters[filters.length] = filter; - return new ManagementRestProxy(channel, newFilters); + return new ManagementRestProxy(channel, newFilters, uri, subscriptionId, keyStorePath); } @Override public ListResult listAffinityGroups() { ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") .header("x-ms-version", "2013-03-01").get(ClientResponse.class); - String requestId = clientResponse.getHeaders().getFirst("x-ms-request-id"); - UUID requestIdUUID = UUID.fromString(requestId); - return new ListResult(null); + PipelineHelpers.ThrowIfNotSuccess(clientResponse); + UUID requestId = getRequestId(clientResponse); + return new ListResult(clientResponse.getStatus(), requestId, + new ArrayList()); } @Override diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java index 9297aa3837863..6dd3594dd2d8f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java @@ -31,8 +31,8 @@ public class ListResult extends OperationResult implements List { private final List contents; - public ListResult(Collection contentList) { - super(3, UUID.randomUUID()); + public ListResult(int statusCode, UUID requestId, Collection contentList) { + super(statusCode, requestId); contents = Collections.unmodifiableList(new ArrayList(contentList)); } diff --git a/microsoft-azure-api/src/main/resources/management/package-names.xjb b/microsoft-azure-api/src/main/resources/management/package-names.xjb new file mode 100644 index 0000000000000..183b2abd31b39 --- /dev/null +++ b/microsoft-azure-api/src/main/resources/management/package-names.xjb @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd new file mode 100644 index 0000000000000..b756aab9a77c9 --- /dev/null +++ b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/microsoft-azure-api/src/main/resources/package-names.xjb b/microsoft-azure-api/src/main/resources/serviceBus/package-names.xjb similarity index 99% rename from microsoft-azure-api/src/main/resources/package-names.xjb rename to microsoft-azure-api/src/main/resources/serviceBus/package-names.xjb index 70e0e3714dd7b..0d8f7b1d9a053 100644 --- a/microsoft-azure-api/src/main/resources/package-names.xjb +++ b/microsoft-azure-api/src/main/resources/serviceBus/package-names.xjb @@ -4,6 +4,7 @@ xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="2.0" jaxb:extensionBindingPrefixes="xjc"> + diff --git a/microsoft-azure-api/src/main/resources/schemas.microsoft.com.2003.10.Serialization.xsd b/microsoft-azure-api/src/main/resources/serviceBus/schemas.microsoft.com.2003.10.Serialization.xsd similarity index 98% rename from microsoft-azure-api/src/main/resources/schemas.microsoft.com.2003.10.Serialization.xsd rename to microsoft-azure-api/src/main/resources/serviceBus/schemas.microsoft.com.2003.10.Serialization.xsd index 62ff1db89253b..b4d5ff0f12270 100644 --- a/microsoft-azure-api/src/main/resources/schemas.microsoft.com.2003.10.Serialization.xsd +++ b/microsoft-azure-api/src/main/resources/serviceBus/schemas.microsoft.com.2003.10.Serialization.xsd @@ -1,42 +1,42 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/microsoft-azure-api/src/main/resources/schemas.microsoft.com.netservices.2010.10.servicebus.connect.xsd b/microsoft-azure-api/src/main/resources/serviceBus/schemas.microsoft.com.netservices.2010.10.servicebus.connect.xsd similarity index 100% rename from microsoft-azure-api/src/main/resources/schemas.microsoft.com.netservices.2010.10.servicebus.connect.xsd rename to microsoft-azure-api/src/main/resources/serviceBus/schemas.microsoft.com.netservices.2010.10.servicebus.connect.xsd diff --git a/microsoft-azure-api/src/main/resources/servicebus-atom.xsd b/microsoft-azure-api/src/main/resources/serviceBus/servicebus-atom.xsd similarity index 100% rename from microsoft-azure-api/src/main/resources/servicebus-atom.xsd rename to microsoft-azure-api/src/main/resources/serviceBus/servicebus-atom.xsd From 6b924fa9d814398f6b6369560ec3e1d8c5d14c3d Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 20 Jun 2013 17:46:49 -0700 Subject: [PATCH 12/57] fix a eclipse plugin issue --- microsoft-azure-api/pom.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/microsoft-azure-api/pom.xml b/microsoft-azure-api/pom.xml index 8a13839e8423c..62c685243d824 100644 --- a/microsoft-azure-api/pom.xml +++ b/microsoft-azure-api/pom.xml @@ -152,12 +152,14 @@ generate - target/generated-sources/xjc/com/microsoft/windowsazure/services/serviceBus/implementation + target/generated-sources/xjc src/main/resources/serviceBus servicebus-atom.xsd com.microsoft.windowsazure.services.serviceBus.implementation + false + true @@ -167,12 +169,14 @@ generate - target/generated-sources/xjc/com/microsoft/windowsazure/services/management/implementation + target/generated-sources/xjc src/main/resources/management/ schemas.microsoft.com.windowsazure.xsd com.microsoft.windowsazure.services.management.implementation + false + true From 885ae1d6c2ccf680ffc4ecc40316ec31116af7e8 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 20 Jun 2013 18:04:30 -0700 Subject: [PATCH 13/57] throw the right type of exception during initialization. --- .../services/management/Exports.java | 55 +++++++------------ 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index e807794483c3a..6a4d35ca0da56 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -64,8 +64,7 @@ public ClientConfig alter(ClientConfig clientConfig, Builder builder, Map Date: Thu, 20 Jun 2013 18:58:26 -0700 Subject: [PATCH 14/57] add affinity group info factory and affinity group info list factory. --- .../AffinityGroupInfoFactory.java | 12 +++++++++++ .../AffinityGroupInfoListFactory.java | 20 +++++++++++++++++++ .../implementation/ManagementRestProxy.java | 7 ++++--- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java new file mode 100644 index 0000000000000..cb052064b2485 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java @@ -0,0 +1,12 @@ +package com.microsoft.windowsazure.services.management.implementation; + +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; + +public class AffinityGroupInfoFactory { + + public static AffinityGroupInfo getItem(AffinityGroup affinityGroup) { + return new AffinityGroupInfo().setName(affinityGroup.getName()).setLabel(affinityGroup.getLabel()) + .setLocation(affinityGroup.getLocation()).setDescription(affinityGroup.getDescription()); + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java new file mode 100644 index 0000000000000..49e4e4a35f99b --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java @@ -0,0 +1,20 @@ +package com.microsoft.windowsazure.services.management.implementation; + +import java.util.ArrayList; +import java.util.List; + +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; + +public class AffinityGroupInfoListFactory { + + public static List getItem(AffinityGroups affinityGroups) { + List result = new ArrayList(); + List affinityGroupList = affinityGroups.getAffinityGroup(); + for (AffinityGroup affinityGroup : affinityGroupList) { + AffinityGroupInfo affinityGroupInfo = AffinityGroupInfoFactory.getItem(affinityGroup); + result.add(affinityGroupInfo); + } + return result; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 00dfe580da21a..7c9a2f2171668 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -14,8 +14,8 @@ */ package com.microsoft.windowsazure.services.management.implementation; -import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.UUID; import javax.inject.Inject; @@ -105,8 +105,9 @@ public ListResult listAffinityGroups() { .header("x-ms-version", "2013-03-01").get(ClientResponse.class); PipelineHelpers.ThrowIfNotSuccess(clientResponse); UUID requestId = getRequestId(clientResponse); - return new ListResult(clientResponse.getStatus(), requestId, - new ArrayList()); + AffinityGroups affinityGroups = clientResponse.getEntity(AffinityGroups.class); + List affinityGroupInfoList = AffinityGroupInfoListFactory.getItem(affinityGroups); + return new ListResult(clientResponse.getStatus(), requestId, affinityGroupInfoList); } @Override From 84eacacc56871facae68e0d2da97e2d43e93241b Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 21 Jun 2013 08:38:03 -0700 Subject: [PATCH 15/57] adds implementation to management rest proxy. --- .../implementation/ManagementRestProxy.java | 50 +++++++++++++------ .../models/GetAffinityGroupResult.java | 10 +++- .../schemas.microsoft.com.windowsazure.xsd | 9 ++++ 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 7c9a2f2171668..7e93df7527e1d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -40,7 +40,7 @@ import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; -public class ManagementRestProxy implements ManagementContract { +public class ManagementRestProxy implements ManagementContract { private Client channel; private final String uri; @@ -111,29 +111,49 @@ public ListResult listAffinityGroups() { } @Override - public CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, - String expectedLocation) { - // TODO Auto-generated method stub - return null; + public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, String label, String location) { + return createAffinityGroup(affinityGroupName, label, location, null); } @Override - public GetAffinityGroupResult getAffinityGroup(String affinityGroupName) { - // TODO Auto-generated method stub - return null; + public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, String label, String location, + CreateAffinityGroupOptions createAffinityGroupOptions) { + + CreateAffinityGroup createAffinityGroup = new CreateAffinityGroup(); + createAffinityGroup.setName(affinityGroupName); + createAffinityGroup.setLabel(label); + createAffinityGroup.setLocation(location); + if (createAffinityGroupOptions != null) { + createAffinityGroup.setDescription(createAffinityGroup.getDescription()); + } + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") + .header("x-ms-version", "2013-03-01").put(ClientResponse.class, createAffinityGroup); + CreateAffinityGroupResult createAffinityGroupResult = new CreateAffinityGroupResult(clientResponse.getStatus(), + getRequestId(clientResponse)); + return createAffinityGroupResult; } @Override - public void deleteAffinityGroup(String affinityGroupName) { - // TODO Auto-generated method stub - + public GetAffinityGroupResult getAffinityGroup(String affinityGroupName) { + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") + .path(affinityGroupName).header("x-ms-version", "2013-03-01").get(ClientResponse.class); + PipelineHelpers.ThrowIfError(clientResponse); + GetAffinityGroupResult getAffinityGroupResult = new GetAffinityGroupResult(clientResponse.getStatus(), + getRequestId(clientResponse)); + AffinityGroup affinityGroup = clientResponse.getEntity(AffinityGroup.class); + AffinityGroupInfo affinityGroupInfo = AffinityGroupInfoFactory.getItem(affinityGroup); + getAffinityGroupResult.setValue(affinityGroupInfo); + return getAffinityGroupResult; } @Override - public CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, - String expectedLocation, CreateAffinityGroupOptions createAffinityGroupOptions) { - // TODO Auto-generated method stub - return null; + public DeleteAffinityGroupResult deleteAffinityGroup(String affinityGroupName) { + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") + .path(affinityGroupName).header("x-ms-version", "2013-03-01").delete(ClientResponse.class); + PipelineHelpers.ThrowIfError(clientResponse); + DeleteAffinityGroupResult deleteAffinityGroupResult = new DeleteAffinityGroupResult(clientResponse.getStatus(), + getRequestId(clientResponse)); + return deleteAffinityGroupResult; } @Override diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java index 26f4d1e16b8ad..87692dd0a383c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java @@ -23,13 +23,19 @@ */ public class GetAffinityGroupResult extends OperationResult { + private AffinityGroupInfo value; + public GetAffinityGroupResult(int statusCode, UUID requestId) { super(statusCode, requestId); } public AffinityGroupInfo getValue() { - // TODO Auto-generated method stub - return null; + return value; + } + + public GetAffinityGroupResult setValue(AffinityGroupInfo affinityGroupInfo) { + this.value = affinityGroupInfo; + return this; } } diff --git a/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd index b756aab9a77c9..b104ceadd3a26 100644 --- a/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd +++ b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd @@ -1,5 +1,14 @@  + + + + + + + + + From a99994ba0857f6756107892b3bb41c8d24b7d7c2 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 21 Jun 2013 10:46:22 -0700 Subject: [PATCH 16/57] complete the logic for management rest proxy for affinity group. --- .../management/ManagementContract.java | 11 +++--- .../ManagementExceptionProcessor.java | 6 ++-- .../implementation/ManagementRestProxy.java | 15 +++++--- .../models/DeleteAffinityGroupResult.java | 35 +++++++++++++++++++ .../schemas.microsoft.com.windowsazure.xsd | 6 ++++ 5 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/DeleteAffinityGroupResult.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java index 6690c41e16621..95bbb90db4fc3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -19,6 +19,7 @@ import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions; import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupResult; +import com.microsoft.windowsazure.services.management.models.DeleteAffinityGroupResult; import com.microsoft.windowsazure.services.management.models.GetAffinityGroupResult; import com.microsoft.windowsazure.services.management.models.ListResult; import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions; @@ -52,14 +53,14 @@ public interface ManagementContract extends FilterableService implements ManagementContract { +public class ManagementRestProxy implements ManagementContract { private Client channel; private final String uri; @@ -157,10 +158,16 @@ public DeleteAffinityGroupResult deleteAffinityGroup(String affinityGroupName) { } @Override - public UpdateAffinityGroupResult updateAffinityGroup(String expectedAffinityGroupLabel, + public UpdateAffinityGroupResult updateAffinityGroup(String affinityGroupName, String affinityGroupLabel, UpdateAffinityGroupOptions updateAffinityGroupOptions) { - // TODO Auto-generated method stub - return null; + UpdateAffinityGroup updateAffinityGroup = new UpdateAffinityGroup(); + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") + .path(affinityGroupName).header("x-ms-version", "2011-02-25") + .put(ClientResponse.class, updateAffinityGroup); + PipelineHelpers.ThrowIfError(clientResponse); + UpdateAffinityGroupResult updateAffinityGroupResult = new UpdateAffinityGroupResult(clientResponse.getStatus(), + getRequestId(clientResponse)); + return updateAffinityGroupResult; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/DeleteAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/DeleteAffinityGroupResult.java new file mode 100644 index 0000000000000..4b6aeb908ca26 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/DeleteAffinityGroupResult.java @@ -0,0 +1,35 @@ +/** + * 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.management.models; + +import java.util.UUID; + +/** + * The base result class for all the result of service management operation. + * + */ +public class DeleteAffinityGroupResult extends OperationResult { + + public DeleteAffinityGroupResult(int statusCode, UUID requestId) { + super(statusCode, requestId); + } + + public AffinityGroupInfo getValue() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd index b104ceadd3a26..df9f5ca1e66ff 100644 --- a/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd +++ b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd @@ -9,6 +9,12 @@ + + + + + + From 7bcbe4592ce656d0a02070879986529a90acd67a Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 21 Jun 2013 10:57:32 -0700 Subject: [PATCH 17/57] implement management exception processor. --- .../management/ManagementContract.java | 12 ++- .../ManagementExceptionProcessor.java | 83 ++++++++++++++----- .../implementation/ManagementRestProxy.java | 22 +++-- .../models/UpdateAffinityGroupOptions.java | 8 +- 4 files changed, 88 insertions(+), 37 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java index 95bbb90db4fc3..c6f1f6c8bc669 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -46,21 +46,19 @@ public interface ManagementContract extends FilterableService listAffinityGroups() throws ServiceException; - CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, - String expectedLocation); + CreateAffinityGroupResult createAffinityGroup(String name, String label, String location) throws ServiceException; - GetAffinityGroupResult getAffinityGroup(String name); + GetAffinityGroupResult getAffinityGroup(String name) throws ServiceException; - DeleteAffinityGroupResult deleteAffinityGroup(String name); + DeleteAffinityGroupResult deleteAffinityGroup(String name) throws ServiceException; CreateAffinityGroupResult createAffinityGroup(String name, String label, String location, - CreateAffinityGroupOptions createAffinityGroupOptions); + CreateAffinityGroupOptions createAffinityGroupOptions) throws ServiceException; UpdateAffinityGroupResult updateAffinityGroup(String name, String label, - UpdateAffinityGroupOptions updateAffinityGroupOptions); + UpdateAffinityGroupOptions updateAffinityGroupOptions) throws ServiceException; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java index ddf8e095f4825..78061ea49e17e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java @@ -31,6 +31,8 @@ import com.microsoft.windowsazure.services.management.models.ListResult; import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions; import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupResult; +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.UniformInterfaceException; public class ManagementExceptionProcessor implements ManagementContract { @@ -58,42 +60,83 @@ private ServiceException processCatch(ServiceException e) { @Override public ListResult listAffinityGroups() throws ServiceException { - // TODO Auto-generated method stub - return null; + try { + return next.listAffinityGroups(); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } } @Override - public CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, - String expectedLocation) { - // TODO Auto-generated method stub - return null; + public CreateAffinityGroupResult createAffinityGroup(String name, String label, String location) + throws ServiceException { + try { + return next.createAffinityGroup(name, label, location); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } } @Override - public GetAffinityGroupResult getAffinityGroup(String affinityGroupName) { - // TODO Auto-generated method stub - return null; + public GetAffinityGroupResult getAffinityGroup(String name) throws ServiceException { + try { + return next.getAffinityGroup(name); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } } @Override - public DeleteAffinityGroupResult deleteAffinityGroup(String affinityGroupName) { - return null; - // TODO Auto-generated method stub - + public DeleteAffinityGroupResult deleteAffinityGroup(String name) throws ServiceException { + try { + return next.deleteAffinityGroup(name); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } } @Override - public CreateAffinityGroupResult createAffinityGroup(String expectedAffinityGroupName, String expectedLabel, - String expectedLocation, CreateAffinityGroupOptions createAffinityGroupOptions) { - // TODO Auto-generated method stub - return null; + public CreateAffinityGroupResult createAffinityGroup(String name, String label, String location, + CreateAffinityGroupOptions createAffinityGroupOptions) throws ServiceException { + try { + return next.createAffinityGroup(name, label, location, createAffinityGroupOptions); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } } @Override public UpdateAffinityGroupResult updateAffinityGroup(String name, String label, - UpdateAffinityGroupOptions updateAffinityGroupOptions) { - // TODO Auto-generated method stub - return null; + UpdateAffinityGroupOptions updateAffinityGroupOptions) throws ServiceException { + try { + return next.updateAffinityGroup(name, label, updateAffinityGroupOptions); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } + catch (ClientHandlerException e) { + throw processCatch(new ServiceException(e)); + } } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index a13d10dd33c01..1f44aebb10e8b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -135,9 +135,9 @@ public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, S } @Override - public GetAffinityGroupResult getAffinityGroup(String affinityGroupName) { - ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") - .path(affinityGroupName).header("x-ms-version", "2013-03-01").get(ClientResponse.class); + public GetAffinityGroupResult getAffinityGroup(String name) { + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups").path(name) + .header("x-ms-version", "2013-03-01").get(ClientResponse.class); PipelineHelpers.ThrowIfError(clientResponse); GetAffinityGroupResult getAffinityGroupResult = new GetAffinityGroupResult(clientResponse.getStatus(), getRequestId(clientResponse)); @@ -148,9 +148,9 @@ public GetAffinityGroupResult getAffinityGroup(String affinityGroupName) { } @Override - public DeleteAffinityGroupResult deleteAffinityGroup(String affinityGroupName) { - ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") - .path(affinityGroupName).header("x-ms-version", "2013-03-01").delete(ClientResponse.class); + public DeleteAffinityGroupResult deleteAffinityGroup(String name) { + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups").path(name) + .header("x-ms-version", "2013-03-01").delete(ClientResponse.class); PipelineHelpers.ThrowIfError(clientResponse); DeleteAffinityGroupResult deleteAffinityGroupResult = new DeleteAffinityGroupResult(clientResponse.getStatus(), getRequestId(clientResponse)); @@ -158,16 +158,20 @@ public DeleteAffinityGroupResult deleteAffinityGroup(String affinityGroupName) { } @Override - public UpdateAffinityGroupResult updateAffinityGroup(String affinityGroupName, String affinityGroupLabel, + public UpdateAffinityGroupResult updateAffinityGroup(String name, String label, UpdateAffinityGroupOptions updateAffinityGroupOptions) { UpdateAffinityGroup updateAffinityGroup = new UpdateAffinityGroup(); + updateAffinityGroup.setLabel(label); + if (updateAffinityGroupOptions != null) + { + updateAffinityGroup.setDescription(updateAffinityGroupOptions.getDescription()) + } ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") - .path(affinityGroupName).header("x-ms-version", "2011-02-25") + .path(name).header("x-ms-version", "2011-02-25") .put(ClientResponse.class, updateAffinityGroup); PipelineHelpers.ThrowIfError(clientResponse); UpdateAffinityGroupResult updateAffinityGroupResult = new UpdateAffinityGroupResult(clientResponse.getStatus(), getRequestId(clientResponse)); return updateAffinityGroupResult; } - } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java index 2a66a7c5aeea0..bf2c0ef1906ce 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java @@ -21,9 +21,15 @@ */ public class UpdateAffinityGroupOptions { + private String description; + public UpdateAffinityGroupOptions setDescription(String description) { - // TODO Auto-generated method stub + this.description = description; return this; } + public String getDescription() { + return this.description; + } + } From b7c912deb7bb5b4103fbb7800a982a22b7eedfca Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 21 Jun 2013 17:21:30 -0700 Subject: [PATCH 18/57] adds Microsoft copyright headers. --- .../implementation/AffinityGroupInfoFactory.java | 15 +++++++++++++++ .../AffinityGroupInfoListFactory.java | 15 +++++++++++++++ .../implementation/ManagementRestProxy.java | 10 ++++------ .../management/ManagementIntegrationTest.java | 2 +- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java index cb052064b2485..964d0133bcc6c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java @@ -1,3 +1,18 @@ +/** + * 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.management.implementation; import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java index 49e4e4a35f99b..a6a8d4af46e62 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java @@ -1,3 +1,18 @@ +/** + * 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.management.implementation; import java.util.ArrayList; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 1f44aebb10e8b..211ef40ef1b1a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -162,13 +162,11 @@ public UpdateAffinityGroupResult updateAffinityGroup(String name, String label, UpdateAffinityGroupOptions updateAffinityGroupOptions) { UpdateAffinityGroup updateAffinityGroup = new UpdateAffinityGroup(); updateAffinityGroup.setLabel(label); - if (updateAffinityGroupOptions != null) - { - updateAffinityGroup.setDescription(updateAffinityGroupOptions.getDescription()) + if (updateAffinityGroupOptions != null) { + updateAffinityGroup.setDescription(updateAffinityGroupOptions.getDescription()); } - ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") - .path(name).header("x-ms-version", "2011-02-25") - .put(ClientResponse.class, updateAffinityGroup); + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups").path(name) + .header("x-ms-version", "2011-02-25").put(ClientResponse.class, updateAffinityGroup); PipelineHelpers.ThrowIfError(clientResponse); UpdateAffinityGroupResult updateAffinityGroupResult = new UpdateAffinityGroupResult(clientResponse.getStatus(), getRequestId(clientResponse)); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index 555643006ef39..8d21b69643d7e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -143,7 +143,7 @@ public void updateAffinityGroupSuccess() throws Exception { // Act UpdateAffinityGroupResult updateAffinityGroupResult = service.updateAffinityGroup(expectedAffinityGroupLabel, - updateAffinityGroupOptions); + expectedDescription, updateAffinityGroupOptions); AffinityGroupInfo affinityGroupInfo = updateAffinityGroupResult.getValue(); // Assert From 5c3228b7abf1715845ca2d8e6e4b51a127cb7382 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 21 Jun 2013 17:48:19 -0700 Subject: [PATCH 19/57] update configuration to support password for management configuration. --- .../management/ManagementConfiguration.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java index c84c82adce135..4cf509ce1de74 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java @@ -28,6 +28,12 @@ public class ManagementConfiguration { */ public final static String KEYSTORE_PATH = "management.keystore.path"; + /** + * Defines the password of the keystore. + * + */ + public final static String KEYSTORE_PASSWORD = "management.keystore.password"; + /** * Defines the URI of service management. * @@ -58,15 +64,16 @@ public class ManagementConfiguration { * */ public static Configuration configure(String uri, String subscriptionId) { - return configure(null, Configuration.getInstance(), uri, subscriptionId, null); + return configure(null, Configuration.getInstance(), uri, subscriptionId, null, null); } - public static Configuration configure(String uri, String subscriptionId, String keyStorePath) { - return configure(null, Configuration.getInstance(), uri, subscriptionId, keyStorePath); + public static Configuration configure(String uri, String subscriptionId, String keyStorePath, + String keyStorePassword) { + return configure(null, Configuration.getInstance(), uri, subscriptionId, keyStorePath, keyStorePassword); } public static Configuration configure(String profile, Configuration configuration, String uri, - String subscriptionId, String keyStoreLocation) { + String subscriptionId, String keyStoreLocation, String keyStorePassword) { if (profile == null) { profile = ""; @@ -78,6 +85,7 @@ else if (profile.length() != 0 && !profile.endsWith(".")) { configuration.setProperty(profile + URI, "https://" + uri); configuration.setProperty(profile + SUBSCRIPTION_ID, subscriptionId); configuration.setProperty(profile + KEYSTORE_PATH, keyStoreLocation); + configuration.setProperty(profile + KEYSTORE_PASSWORD, keyStorePassword); return configuration; } From 1869bf8a2d5a9dbfbacab84d2cf5617ccbb39ee1 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 28 Jun 2013 13:35:32 -0700 Subject: [PATCH 20/57] reduce the chance of potential unit test failure. --- .../scenarios/MediaServiceScenarioTest.java | 6 ++++-- .../services/scenarios/MediaServiceWrapper.java | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java index 41bc23269daba..0d4ef704f2233 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java @@ -40,6 +40,7 @@ public class MediaServiceScenarioTest extends ScenarioTestBase { private static final String rootTestAssetPrefix = "testAssetPrefix-"; + private static final String testJobPrefix = "testJobPrefix"; private static String testAssetPrefix; private static MediaServiceWrapper wrapper; private static MediaServiceValidation validator; @@ -57,6 +58,7 @@ public static void setup() throws ServiceException { public static void cleanup() throws ServiceException { wrapper.removeAllAssetsWithPrefix(rootTestAssetPrefix); wrapper.removeAllAccessPoliciesWithPrefix(); + wrapper.removeAllJobWithPrefix(testJobPrefix); } @Test @@ -119,7 +121,7 @@ public void createJob() throws Exception { wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles()); signalSetupFinished(); - String jobName = "my job createJob" + UUID.randomUUID().toString(); + String jobName = testJobPrefix + UUID.randomUUID().toString(); JobInfo job = wrapper.createJob(jobName, asset, createTasks()); validator.validateJob(job, jobName, asset, createTasks()); } @@ -129,7 +131,7 @@ public void transformAsset() throws Exception { signalSetupStarting(); AssetInfo asset = wrapper.createAsset(testAssetPrefix + "transformAsset", AssetOption.None); wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles()); - String jobName = "my job transformAsset" + UUID.randomUUID().toString(); + String jobName = testJobPrefix + UUID.randomUUID().toString(); JobInfo job = wrapper.createJob(jobName, asset, wrapper.createTaskOptions("Transform", 0, 0, EncoderType.WindowsAzureMediaEncoder)); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java index bb996eb10b77b..8b8779d173b55 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java @@ -432,6 +432,19 @@ public void removeAllAccessPoliciesWithPrefix() throws ServiceException { } } + public void removeAllJobWithPrefix(String testJobPrefix) throws ServiceException { + List jobInfos = service.list(Job.list()); + for (JobInfo jobInfo : jobInfos) { + if (jobInfo.getName().startsWith(testJobPrefix)) { + try { + service.delete(Job.delete(jobInfo.getId())); + } + catch (ServiceException e) { + } + } + } + } + private static class EncryptionHelper { public static boolean canUseStrongCrypto() { try { From f63f83f4945623a5d3fa1eec86eef689ecc4fe49 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 28 Jun 2013 17:36:20 -0700 Subject: [PATCH 21/57] check in community contribution. --- microsoft-azure-api/pom.xml | 5 ++ .../services/core/DefaultBuilder.java | 34 +++++++----- .../management/ConnectionCredential.java | 54 +++++++++++++++++++ .../services/management/KeyStoreType.java | 12 +++++ .../management/SSLContextFactory.java | 50 +++++++++++++++++ .../management/IntegrationTestBase.java | 5 ++ 6 files changed, 146 insertions(+), 14 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java diff --git a/microsoft-azure-api/pom.xml b/microsoft-azure-api/pom.xml index 62c685243d824..f8cf7f54d9d4c 100644 --- a/microsoft-azure-api/pom.xml +++ b/microsoft-azure-api/pom.xml @@ -110,6 +110,11 @@ 1.46 test + + com.google.guava + guava-io + r03 + diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java index f72f4c935c37e..5b44dc07c0e28 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java @@ -2,15 +2,15 @@ * 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 + * 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. + * 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.core; @@ -51,6 +51,7 @@ void addFactory(Class service, Factory factory) { factories.put(service, factory); } + @Override public Builder.Registry add(Class service) { return add(service, service); } @@ -84,15 +85,17 @@ Constructor findInjectConstructor(Class implementation) { return withoutInject; } + @Override public Builder.Registry add(Class service, final Class implementation) { final Constructor ctor = findInjectConstructor(implementation); final Class[] parameterTypes = ctor.getParameterTypes(); final Annotation[][] parameterAnnotations = ctor.getParameterAnnotations(); addFactory(service, new Builder.Factory() { + @Override @SuppressWarnings("unchecked") public T create(String profile, Builder builder, Map properties) { - Object[] initargs = new Object[parameterTypes.length]; + Object[] initializationArguments = new Object[parameterTypes.length]; for (int i = 0; i != parameterTypes.length; ++i) { boolean located = false; @@ -103,10 +106,10 @@ public T create(String profile, Builder builder, Map properties) boolean probeProperties = fullName != null && fullName != ""; int startingIndex = 0; while (!located && probeProperties) { - String probeName = fullName.substring(startingIndex); - if (!located && named != null && properties.containsKey(probeName)) { + String nameProbe = fullName.substring(startingIndex); + if (!located && named != null && properties.containsKey(nameProbe)) { located = true; - initargs[i] = properties.get(probeName); + initializationArguments[i] = properties.get(nameProbe); } else { startingIndex = fullName.indexOf('.', startingIndex) + 1; @@ -118,12 +121,12 @@ public T create(String profile, Builder builder, Map properties) if (!located) { located = true; - initargs[i] = builder.build(fullName, parameterTypes[i], properties); + initializationArguments[i] = builder.build(fullName, parameterTypes[i], properties); } } try { - return (T) ctor.newInstance(initargs); + return (T) ctor.newInstance(initializationArguments); } catch (InstantiationException e) { throw new ConfigurationException(e); @@ -158,6 +161,7 @@ protected String findNamedAnnotation(Annotation[] annotations) { return null; } + @Override public Registry add(Factory factory) { for (Type genericInterface : factory.getClass().getGenericInterfaces()) { ParameterizedType parameterizedType = (ParameterizedType) genericInterface; @@ -169,6 +173,7 @@ public Registry add(Factory factory) { return this; } + @Override @SuppressWarnings("unchecked") public T build(String profile, Class service, Map properties) { Factory factory = (Factory) factories.get(service); @@ -185,6 +190,7 @@ public T build(String profile, Class service, Map propert return instance; } + @Override public void alter(Class service, Alteration alteration) { if (!this.alterations.containsKey(service)) { this.alterations.put(service, new ArrayList>()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java new file mode 100644 index 0000000000000..97aa547fe8094 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java @@ -0,0 +1,54 @@ +/* + * + * + * The author contributes this code to the public domain, + * retaining no rights and incurring no responsibilities for its use in whole or in part. + */ + +package com.microsoft.windowsazure.services.management; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import com.google.common.io.ByteStreams; + +public class ConnectionCredential { + private final byte[] keyStore; + + private final String keyPasswd; + + private final KeyStoreType keyStoreType; + + /** + * Creates a Credential from a keyStore. + * + * @param keyPass + * - keyStore password, key for store and the internal private key must be + * symmetric + * @param keys + * - an InputStream probably a FileInputStream from a keyStore, the jks containing + * your management cert + * @throws IOException + */ + ConnectionCredential(InputStream keys, String keyPass, KeyStoreType type) throws IOException { + keyPasswd = keyPass; + // Apache IOUtils could be used instead of google.common.io, + // or do a brute force read into List and then into an array. + keyStore = ByteStreams.toByteArray(keys); + keyStoreType = type; + } + + public KeyStoreType getKeyStoreType() { + return keyStoreType; + } + + public InputStream getKeyStore() { + return new ByteArrayInputStream(keyStore); + } + + public String getKeyPasswd() { + return keyPasswd; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java new file mode 100644 index 0000000000000..7d1d37b0901f6 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java @@ -0,0 +1,12 @@ +/* + * + * + * The author contributes this code to the public domain, + * retaining no rights and incurring no responsibilities for its use in whole or in part. + */ + +package com.microsoft.windowsazure.services.management; + +public enum KeyStoreType { + jks, pkcs12 +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java new file mode 100644 index 0000000000000..12d06b8336df9 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java @@ -0,0 +1,50 @@ +package com.microsoft.windowsazure.services.management; + +import java.io.IOException; +import java.io.InputStream; +import java.security.GeneralSecurityException; +import java.security.KeyStore; + +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; + +/** + * Note: as it stands this provides a TLS SSLContext from jks and pfx stores. It could be modified to + * support other protocols (SSLv3, SSLv2, etc) and different key stores... + * + * Note that older .pfx files may need to be updated to pkcs12 format.... + * + */ +public class SSLContextFactory { + + public static SSLContext createSSLContext(ConnectionCredential cred) throws GeneralSecurityException, IOException { + return createSSLContext(cred.getKeyStore(), cred.getKeyPasswd(), cred.getKeyStoreType()); + } + + public static SSLContext createSSLContext(InputStream keyStoreStream, String keyStreamPasswd, KeyStoreType type) + throws GeneralSecurityException, IOException { + // Could Proxy KeyManagers to include only those with a specific alias for multi-cert file.... + KeyManager[] keyManagers = getKeyManagers(keyStoreStream, keyStreamPasswd, type.name()); + // note: may want to broaden this to SSLv3, SSLv2, SSL, etc... + SSLContext context = SSLContext.getInstance("TLS"); + // use default TrustManager and SecureRandom + context.init(keyManagers, null, null); + return context; + } + + private static KeyManager[] getKeyManagers(InputStream keyStoreStream, String keyStreamPasswd, String type) + throws IOException, GeneralSecurityException { + + KeyStore ks = KeyStore.getInstance(type); + ks.load(keyStoreStream, keyStreamPasswd.toCharArray()); + keyStoreStream.close(); + + String alg = KeyManagerFactory.getDefaultAlgorithm(); + KeyManagerFactory kmFact = KeyManagerFactory.getInstance(alg); + kmFact.init(ks, keyStreamPasswd.toCharArray()); + + return kmFact.getKeyManagers(); + } + +} \ No newline at end of file diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java index e03d5db97a36e..af50b085ebde7 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java @@ -41,7 +41,12 @@ public static void cleanUpTestArtifacts() throws Exception { protected static Configuration createConfiguration() throws Exception { Configuration config = Configuration.load(); + overrideWithEnv(config, ManagementConfiguration.URI); + overrideWithEnv(config, ManagementConfiguration.SUBSCRIPTION_ID); + overrideWithEnv(config, ManagementConfiguration.KEYSTORE_PASSWORD); + overrideWithEnv(config, ManagementConfiguration.KEYSTORE_PATH); + return config; } From 1a9adee83d675eb4aa7f20ff235b6e8812e6af1b Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Mon, 8 Jul 2013 14:35:20 -0700 Subject: [PATCH 22/57] Supports Client Certificate validation. --- .../services/management/Exports.java | 77 ++++++++--------- .../management/ManagementContract.java | 83 +++++++++++++++---- .../management/SSLContextFactory.java | 6 +- .../implementation/ManagementRestProxy.java | 8 +- .../models/CreateAffinityGroupResult.java | 3 +- .../models/DeleteAffinityGroupResult.java | 3 +- .../models/GetAffinityGroupResult.java | 3 +- .../management/models/ListResult.java | 3 +- .../management/models/OperationResult.java | 7 +- .../models/UpdateAffinityGroupResult.java | 3 +- 10 files changed, 116 insertions(+), 80 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index 6a4d35ca0da56..ed229321bee56 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -17,7 +17,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.security.KeyManagementException; +import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -25,11 +25,10 @@ import java.security.cert.CertificateException; import java.util.Map; -import javax.net.ssl.KeyManager; +import javax.net.ssl.HostnameVerifier; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.SSLSession; import com.microsoft.windowsazure.services.core.Builder; import com.microsoft.windowsazure.services.core.UserAgentFilter; @@ -53,62 +52,52 @@ public void register(Builder.Registry registry) { @Override public ClientConfig alter(ClientConfig clientConfig, Builder builder, Map properties) { - String keyStoreName = "d:\\src\\javacert\\azurecertkeystore.jks"; + String keyStoreName = "d:\\src\\javacert\\iiscert\\democert.jks"; // String trustStoreName = "c:\\src\\truststore.jks"; - String keyStorePass = "azurerocks"; - String keyPass = "azurecert"; - - SSLContext sslContext = null; + String keyStorePass = "democert"; + String keyPass = "democert"; + ConnectionCredential credential = null; try { - sslContext = SSLContext.getInstance("SSL"); + credential = new ConnectionCredential(new FileInputStream(keyStoreName), keyStorePass, + KeyStoreType.jks); } - catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); + catch (FileNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); } - KeyManager[] keyManager = createKeyManager(keyStoreName, keyStorePass, keyPass); - TrustManager[] trustManager = createDefaultTrustManager(); - + SSLContext sslContext = null; try { - sslContext.init(keyManager, trustManager, null); + sslContext = SSLContextFactory.createSSLContext(credential); + } + catch (GeneralSecurityException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); } - catch (KeyManagementException e) { - throw new RuntimeException(e); + catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); } + clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, - new HTTPSProperties(null, sslContext)); + new HTTPSProperties(new HostnameVerifier() { + + @Override + public boolean verify(String arg0, SSLSession arg1) { + return true; + } + }, sslContext)); return clientConfig; } }); } - private TrustManager[] createDefaultTrustManager() { - - TrustManagerFactory trustManagerFactory = null; - try { - trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - } - catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - - try { - trustManagerFactory.init((KeyStore) null); - } - catch (KeyStoreException e) { - throw new RuntimeException(e); - } - return trustManagerFactory.getTrustManagers(); - - } - - private KeyManager[] createKeyManager(String keyStoreName, String keyStorePass, String keyPass) { - KeyManagerFactory keyManagerFactory = createKeyManagerFactory(keyStoreName, keyStorePass, keyPass); - return keyManagerFactory.getKeyManagers(); - } - private KeyManagerFactory createKeyManagerFactory(String keyStoreName, String keyStorePass, String keyPass) { KeyManagerFactory keyManagerFactory = null; KeyStore keyStore = createKeyStore(keyStoreName, keyStorePass); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java index c6f1f6c8bc669..0b7391fa71858 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -27,37 +27,88 @@ /** * - * Defines the service bus contract. + * Defines the service management contract. * */ public interface ManagementContract extends FilterableService { /** - * Renew subscription lock. + * Creates the affinity group. * - * @param topicName - * A String object that represents the name of the topic. - * @param queueName - * A String object that represents the name of the queue. - * @param messageId - * A String object that represents the ID of the message. - * @param lockToken - * A String object that represents the token of the lock. + * @param name + * the name + * @param label + * the label + * @param location + * the location + * @return the creates the affinity group result * @throws ServiceException - * If a service exception is encountered. + * the service exception */ - - ListResult listAffinityGroups() throws ServiceException; - CreateAffinityGroupResult createAffinityGroup(String name, String label, String location) throws ServiceException; + /** + * Gets the affinity group. + * + * @param name + * the name + * @return the affinity group + * @throws ServiceException + * the service exception + */ GetAffinityGroupResult getAffinityGroup(String name) throws ServiceException; - DeleteAffinityGroupResult deleteAffinityGroup(String name) throws ServiceException; - + /** + * Creates the affinity group. + * + * @param name + * the name + * @param label + * the label + * @param location + * the location + * @param createAffinityGroupOptions + * the create affinity group options + * @return the creates the affinity group result + * @throws ServiceException + * the service exception + */ CreateAffinityGroupResult createAffinityGroup(String name, String label, String location, CreateAffinityGroupOptions createAffinityGroupOptions) throws ServiceException; + /** + * Delete affinity group. + * + * @param name + * the name + * @return the delete affinity group result + * @throws ServiceException + * the service exception + */ + DeleteAffinityGroupResult deleteAffinityGroup(String name) throws ServiceException; + + /** + * List affinity groups. + * + * @return the list result + * @throws ServiceException + * the service exception + */ + ListResult listAffinityGroups() throws ServiceException; + + /** + * Update affinity group. + * + * @param name + * the name + * @param label + * the label + * @param updateAffinityGroupOptions + * the update affinity group options + * @return the update affinity group result + * @throws ServiceException + * the service exception + */ UpdateAffinityGroupResult updateAffinityGroup(String name, String label, UpdateAffinityGroupOptions updateAffinityGroupOptions) throws ServiceException; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java index 12d06b8336df9..0fd56d95eea55 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java @@ -4,7 +4,9 @@ import java.io.InputStream; import java.security.GeneralSecurityException; import java.security.KeyStore; +import java.security.SecureRandom; +import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; @@ -29,7 +31,9 @@ public static SSLContext createSSLContext(InputStream keyStoreStream, String key // note: may want to broaden this to SSLv3, SSLv2, SSL, etc... SSLContext context = SSLContext.getInstance("TLS"); // use default TrustManager and SecureRandom - context.init(keyManagers, null, null); + context.init(keyManagers, null, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); + return context; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 211ef40ef1b1a..9c80bf6945b46 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -16,7 +16,6 @@ import java.util.Arrays; import java.util.List; -import java.util.UUID; import javax.inject.Inject; import javax.inject.Named; @@ -88,9 +87,8 @@ private WebResource getResource() { return resource; } - private UUID getRequestId(ClientResponse clientResponse) { - String requestId = clientResponse.getHeaders().getFirst("x-ms-request-id"); - return UUID.fromString(requestId); + private String getRequestId(ClientResponse clientResponse) { + return clientResponse.getHeaders().getFirst("x-ms-request-id"); } @Override @@ -105,7 +103,7 @@ public ListResult listAffinityGroups() { ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") .header("x-ms-version", "2013-03-01").get(ClientResponse.class); PipelineHelpers.ThrowIfNotSuccess(clientResponse); - UUID requestId = getRequestId(clientResponse); + String requestId = getRequestId(clientResponse); AffinityGroups affinityGroups = clientResponse.getEntity(AffinityGroups.class); List affinityGroupInfoList = AffinityGroupInfoListFactory.getItem(affinityGroups); return new ListResult(clientResponse.getStatus(), requestId, affinityGroupInfoList); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java index 07f79a531cf6c..51b822ca131ec 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java @@ -15,7 +15,6 @@ package com.microsoft.windowsazure.services.management.models; -import java.util.UUID; /** * The base result class for all the result of service management operation. @@ -23,7 +22,7 @@ */ public class CreateAffinityGroupResult extends OperationResult { - public CreateAffinityGroupResult(int statusCode, UUID requestId) { + public CreateAffinityGroupResult(int statusCode, String requestId) { super(statusCode, requestId); // TODO Auto-generated constructor stub diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/DeleteAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/DeleteAffinityGroupResult.java index 4b6aeb908ca26..9150ea812c2b9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/DeleteAffinityGroupResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/DeleteAffinityGroupResult.java @@ -15,7 +15,6 @@ package com.microsoft.windowsazure.services.management.models; -import java.util.UUID; /** * The base result class for all the result of service management operation. @@ -23,7 +22,7 @@ */ public class DeleteAffinityGroupResult extends OperationResult { - public DeleteAffinityGroupResult(int statusCode, UUID requestId) { + public DeleteAffinityGroupResult(int statusCode, String requestId) { super(statusCode, requestId); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java index 87692dd0a383c..41b39decb7623 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java @@ -15,7 +15,6 @@ package com.microsoft.windowsazure.services.management.models; -import java.util.UUID; /** * The base result class for all the result of service management operation. @@ -25,7 +24,7 @@ public class GetAffinityGroupResult extends OperationResult { private AffinityGroupInfo value; - public GetAffinityGroupResult(int statusCode, UUID requestId) { + public GetAffinityGroupResult(int statusCode, String requestId) { super(statusCode, requestId); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java index 6dd3594dd2d8f..96620aaaaebc7 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java @@ -21,7 +21,6 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; -import java.util.UUID; /** * Wrapper class for all returned lists from Media Services @@ -31,7 +30,7 @@ public class ListResult extends OperationResult implements List { private final List contents; - public ListResult(int statusCode, UUID requestId, Collection contentList) { + public ListResult(int statusCode, String requestId, Collection contentList) { super(statusCode, requestId); contents = Collections.unmodifiableList(new ArrayList(contentList)); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java index 2788a20617662..c426891bfd1c0 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java @@ -15,7 +15,6 @@ package com.microsoft.windowsazure.services.management.models; -import java.util.UUID; /** * The base result class for all the result of service management operation. @@ -23,10 +22,10 @@ */ public class OperationResult { - protected final UUID requestId; + protected final String requestId; protected final int statusCode; - public OperationResult(int statusCode, UUID requestId) { + public OperationResult(int statusCode, String requestId) { this.statusCode = statusCode; this.requestId = requestId; } @@ -35,7 +34,7 @@ public int getStatusCode() { return this.statusCode; } - public UUID getRequestId() { + public String getRequestId() { return this.requestId; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java index e935e1c6afdea..8561296cfc32a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java @@ -15,7 +15,6 @@ package com.microsoft.windowsazure.services.management.models; -import java.util.UUID; /** * The base result class for all the result of service management operation. @@ -23,7 +22,7 @@ */ public class UpdateAffinityGroupResult extends OperationResult { - public UpdateAffinityGroupResult(int statusCode, UUID requestId) { + public UpdateAffinityGroupResult(int statusCode, String requestId) { super(statusCode, requestId); } From 8ae34749b591c377bbd9cafee19ba5fd557b2cd3 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 9 Jul 2013 11:25:30 -0700 Subject: [PATCH 23/57] Gets create affinity group call success. --- .../AffinityGroupInfoListFactory.java | 2 +- .../implementation/ManagementRestProxy.java | 4 ++- .../schemas.microsoft.com.windowsazure.xsd | 28 ++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java index a6a8d4af46e62..0aebb7c6919a6 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java @@ -24,7 +24,7 @@ public class AffinityGroupInfoListFactory { public static List getItem(AffinityGroups affinityGroups) { List result = new ArrayList(); - List affinityGroupList = affinityGroups.getAffinityGroup(); + List affinityGroupList = affinityGroups.getAffinityGroups(); for (AffinityGroup affinityGroup : affinityGroupList) { AffinityGroupInfo affinityGroupInfo = AffinityGroupInfoFactory.getItem(affinityGroup); result.add(affinityGroupInfo); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 9c80bf6945b46..8a5fee6125755 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -19,6 +19,7 @@ import javax.inject.Inject; import javax.inject.Named; +import javax.ws.rs.core.MediaType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -126,7 +127,8 @@ public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, S createAffinityGroup.setDescription(createAffinityGroup.getDescription()); } ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") - .header("x-ms-version", "2013-03-01").put(ClientResponse.class, createAffinityGroup); + .header("x-ms-version", "2013-03-01").type(MediaType.APPLICATION_XML) + .put(ClientResponse.class, createAffinityGroup); CreateAffinityGroupResult createAffinityGroupResult = new CreateAffinityGroupResult(clientResponse.getStatus(), getRequestId(clientResponse)); return createAffinityGroupResult; diff --git a/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd index df9f5ca1e66ff..f5894217cf427 100644 --- a/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd +++ b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd @@ -1,14 +1,22 @@  - - - - - - - - - - + + + + + + + + + + + + + + + + + + From 127c9962087dcdfce17251284c6f12d258a16319 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 9 Jul 2013 15:39:06 -0700 Subject: [PATCH 24/57] enable enviroment variable injection for service management. --- .../windowsazure/services/core/Builder.java | 18 ++++++++-------- .../services/core/DefaultBuilder.java | 2 +- .../services/management/Exports.java | 16 +++++++++----- .../windowsazure/services/media/Exports.java | 3 ++- .../services/serviceBus/Exports.java | 3 ++- .../builder/AlterClassWithProperties.java | 21 ++++++++++--------- .../management/ManagementIntegrationTest.java | 2 +- .../serviceBus/ServiceBusIntegrationTest.java | 2 +- 8 files changed, 38 insertions(+), 29 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Builder.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Builder.java index f6a194e3349db..9ce1494b5ffb1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Builder.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Builder.java @@ -2,15 +2,15 @@ * 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 + * 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. + * 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.core; @@ -25,7 +25,7 @@ public interface Factory { } public interface Alteration { - T alter(T instance, Builder builder, Map properties); + T alter(String profile, T instance, Builder builder, Map properties); } public interface Registry { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java index 5b44dc07c0e28..369989af9a5e3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java @@ -184,7 +184,7 @@ public T build(String profile, Class service, Map propert List> alterationList = alterations.get(service); if (alterationList != null) { for (Alteration alteration : alterationList) { - instance = ((Alteration) alteration).alter(instance, this, properties); + instance = ((Alteration) alteration).alter(profile, instance, this, properties); } } return instance; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index ed229321bee56..ca98ee1e6d7b5 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -14,6 +14,8 @@ */ package com.microsoft.windowsazure.services.management; +import static com.microsoft.windowsazure.services.core.utils.ExportUtils.*; + import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -50,13 +52,17 @@ public void register(Builder.Registry registry) { registry.alter(ClientConfig.class, new Builder.Alteration() { @Override - public ClientConfig alter(ClientConfig clientConfig, Builder builder, Map properties) { + public ClientConfig alter(String profile, ClientConfig clientConfig, Builder builder, + Map properties) { - String keyStoreName = "d:\\src\\javacert\\iiscert\\democert.jks"; - // String trustStoreName = "c:\\src\\truststore.jks"; - String keyStorePass = "democert"; - String keyPass = "democert"; + // String keyStoreName = "d:\\src\\javacert\\iiscert\\democert.jks"; + String keyStoreName = (String) getPropertyIfExists(profile, properties, + ManagementConfiguration.KEYSTORE_PATH); + // String trustStoreName = "c:\\src\\truststore.jks"; + // String keyStorePass = "democert"; + String keyStorePass = (String) getPropertyIfExists(profile, properties, + ManagementConfiguration.KEYSTORE_PASSWORD); ConnectionCredential credential = null; try { credential = new ConnectionCredential(new FileInputStream(keyStoreName), keyStorePass, diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java index f2c6e3afbc287..cfc946c718d3f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java @@ -56,7 +56,8 @@ public void register(Builder.Registry registry) { registry.alter(ClientConfig.class, new Builder.Alteration() { @SuppressWarnings("rawtypes") @Override - public ClientConfig alter(ClientConfig instance, Builder builder, Map properties) { + public ClientConfig alter(String profile, ClientConfig instance, Builder builder, + Map properties) { instance.getProperties().put(JSONConfiguration.FEATURE_POJO_MAPPING, true); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java index d0466bb31cb75..76fd462f2b689 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java @@ -40,7 +40,8 @@ public void register(Builder.Registry registry) { registry.alter(ClientConfig.class, new Builder.Alteration() { @Override - public ClientConfig alter(ClientConfig instance, Builder builder, Map properties) { + public ClientConfig alter(String profile, ClientConfig instance, Builder builder, + Map properties) { // enable this feature for unattributed json object serialization instance.getProperties().put(JSONConfiguration.FEATURE_POJO_MAPPING, true); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/configuration/builder/AlterClassWithProperties.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/configuration/builder/AlterClassWithProperties.java index 4c208fd7932b2..ddac6c4ac80bb 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/configuration/builder/AlterClassWithProperties.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/configuration/builder/AlterClassWithProperties.java @@ -2,15 +2,15 @@ * 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 + * 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. + * 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.configuration.builder; @@ -19,8 +19,9 @@ import com.microsoft.windowsazure.services.core.Builder; public class AlterClassWithProperties implements Builder.Alteration { - - public ClassWithProperties alter(ClassWithProperties instance, Builder builder, Map properties) { + @Override + public ClassWithProperties alter(String profile, ClassWithProperties instance, Builder builder, + Map properties) { instance.setFoo(instance.getFoo() + " - changed"); return instance; } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index 8d21b69643d7e..10be6031dfd45 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -50,7 +50,7 @@ public void createService() throws Exception { Registry builder = (Registry) config.getBuilder(); builder.alter(Client.class, new Alteration() { @Override - public Client alter(Client client, Builder builder, Map properties) { + public Client alter(String profile, Client client, Builder builder, Map properties) { client.addFilter(new LoggingFilter()); return client; } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java index ef1ffded6b895..dc2fe3a799b7c 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java @@ -76,7 +76,7 @@ public void createService() throws Exception { Registry builder = (Registry) config.getBuilder(); builder.alter(Client.class, new Alteration() { @Override - public Client alter(Client instance, Builder builder, Map properties) { + public Client alter(String profile, Client instance, Builder builder, Map properties) { instance.addFilter(new LoggingFilter()); return instance; } From cf62e01a046c46323b0ba8c71a5a6e87b484a7d5 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 10 Jul 2013 15:51:57 -0700 Subject: [PATCH 25/57] get all the methods functioning. --- .../implementation/ManagementRestProxy.java | 8 +++++--- .../schemas.microsoft.com.windowsazure.xsd | 12 +++++++----- .../management/ManagementIntegrationTest.java | 12 ++++++------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 8a5fee6125755..34c84b8f5f575 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -16,6 +16,7 @@ import java.util.Arrays; import java.util.List; +import java.util.UUID; import javax.inject.Inject; import javax.inject.Named; @@ -102,7 +103,8 @@ public ManagementContract withFilter(ServiceFilter filter) { @Override public ListResult listAffinityGroups() { ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") - .header("x-ms-version", "2013-03-01").get(ClientResponse.class); + .header("x-ms-version", "2013-03-01").header("x-ms-client-request-id", UUID.randomUUID()) + .get(ClientResponse.class); PipelineHelpers.ThrowIfNotSuccess(clientResponse); String requestId = getRequestId(clientResponse); AffinityGroups affinityGroups = clientResponse.getEntity(AffinityGroups.class); @@ -127,8 +129,8 @@ public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, S createAffinityGroup.setDescription(createAffinityGroup.getDescription()); } ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") - .header("x-ms-version", "2013-03-01").type(MediaType.APPLICATION_XML) - .put(ClientResponse.class, createAffinityGroup); + .header("x-ms-version", "2013-03-01").header("x-ms-client-request-id", UUID.randomUUID().toString()) + .type(MediaType.APPLICATION_XML).post(ClientResponse.class, createAffinityGroup); CreateAffinityGroupResult createAffinityGroupResult = new CreateAffinityGroupResult(clientResponse.getStatus(), getRequestId(clientResponse)); return createAffinityGroupResult; diff --git a/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd index f5894217cf427..a09632d1c7725 100644 --- a/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd +++ b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd @@ -1,5 +1,5 @@  - + @@ -17,12 +17,14 @@ - - + + + - - + + + diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index 10be6031dfd45..dfd53924414c1 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -66,7 +66,7 @@ public void createAffinityGroupSuccess() throws Exception { // Arrange String expectedAffinityGroupName = "testCreateAffinityGroupSuccess"; String expectedLabel = Base64.encode("testCreateAffinityGroupSuccess".getBytes("UTF-8")); - String expectedLocation = "US West"; + String expectedLocation = "West US"; // Act CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(expectedAffinityGroupName, @@ -85,7 +85,7 @@ public void createAffinityGroupWithOptionalParametersSuccess() throws Exception // Arrange String expectedAffinityGroupName = "testCreateAffinityGroupWithOptionalParametersSuccess"; String expectedLabel = Base64.encode("testCreateAffinityGroupWithOptionalParameterSuccess".getBytes("UTF-8")); - String expectedLocation = "US West"; + String expectedLocation = "West US"; String expectedDescription = "testCreateAffinityGroupWithOptionalParameterSuccessDescription"; CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions() .setDescription(expectedDescription); @@ -135,15 +135,15 @@ public void updateAffinityGroupSuccess() throws Exception { // Arrange String expectedAffinityGroupName = "testUpdateAffinityGroupSuccess"; String expectedAffinityGroupLabel = Base64.encode("testUpdateAffinityGroupSuccess".getBytes("UTF-8")); - String expectedLocation = "US West"; + String expectedLocation = "West US"; String expectedDescription = "updateAffinityGroupSuccess"; service.createAffinityGroup(expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); UpdateAffinityGroupOptions updateAffinityGroupOptions = new UpdateAffinityGroupOptions() .setDescription(expectedDescription); // Act - UpdateAffinityGroupResult updateAffinityGroupResult = service.updateAffinityGroup(expectedAffinityGroupLabel, - expectedDescription, updateAffinityGroupOptions); + UpdateAffinityGroupResult updateAffinityGroupResult = service.updateAffinityGroup(expectedAffinityGroupName, + expectedAffinityGroupLabel, updateAffinityGroupOptions); AffinityGroupInfo affinityGroupInfo = updateAffinityGroupResult.getValue(); // Assert @@ -156,7 +156,7 @@ public void getAffinityGroupPropertiesSuccess() throws Exception { // Arrange String expectedAffinityGroupName = "testGetAffinityGroupPropertiesSuccess"; String expectedAffinityGroupLabel = Base64.encode("testGetAffinityGroupPropertiesSuccess".getBytes("UTF-8")); - String expectedLocation = "US West"; + String expectedLocation = "West US"; service.createAffinityGroup(expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); // Act From 6c9cad87c7130dfbdb4fdf12af5cde4d83a7c209 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 12 Jul 2013 15:11:24 -0700 Subject: [PATCH 26/57] make all the unit tests passed. --- .../implementation/ManagementRestProxy.java | 11 ++++ .../models/CreateAffinityGroupResult.java | 44 ++++++++++++-- .../models/UpdateAffinityGroupResult.java | 22 ++++++- .../management/IntegrationTestBase.java | 57 ++++++++++++++++++- .../management/ManagementIntegrationTest.java | 53 ++++------------- 5 files changed, 135 insertions(+), 52 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 34c84b8f5f575..ea2cbcc5c453a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -21,10 +21,12 @@ import javax.inject.Inject; import javax.inject.Named; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; import com.microsoft.windowsazure.services.core.utils.pipeline.PipelineHelpers; @@ -48,6 +50,7 @@ public class ManagementRestProxy implements ManagementContract { private final String uri; private final String subscriptionId; private final String keyStorePath; + private final RFC1123DateConverter rfc1123DateConvert = new RFC1123DateConverter(); static Log log = LogFactory.getLog(ManagementContract.class); ServiceFilter[] filters; @@ -133,6 +136,11 @@ public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, S .type(MediaType.APPLICATION_XML).post(ClientResponse.class, createAffinityGroup); CreateAffinityGroupResult createAffinityGroupResult = new CreateAffinityGroupResult(clientResponse.getStatus(), getRequestId(clientResponse)); + MultivaluedMap headers = clientResponse.getHeaders(); + createAffinityGroupResult.setLocation(headers.getFirst("Location")); + createAffinityGroupResult.setRegion(headers.getFirst("x-ms-servedbyregion")); + createAffinityGroupResult.setServer(headers.getFirst("Server")); + createAffinityGroupResult.setDate(rfc1123DateConvert.parse((headers.getFirst("Date")))); return createAffinityGroupResult; } @@ -172,6 +180,9 @@ public UpdateAffinityGroupResult updateAffinityGroup(String name, String label, PipelineHelpers.ThrowIfError(clientResponse); UpdateAffinityGroupResult updateAffinityGroupResult = new UpdateAffinityGroupResult(clientResponse.getStatus(), getRequestId(clientResponse)); + MultivaluedMap headers = clientResponse.getHeaders(); + updateAffinityGroupResult.setRegion(headers.getFirst("x-ms-servedbyregion")); + updateAffinityGroupResult.setDate(rfc1123DateConvert.parse((headers.getFirst("Date")))); return updateAffinityGroupResult; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java index 51b822ca131ec..33bb8b6640a47 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java @@ -15,6 +15,7 @@ package com.microsoft.windowsazure.services.management.models; +import java.util.Date; /** * The base result class for all the result of service management operation. @@ -22,15 +23,50 @@ */ public class CreateAffinityGroupResult extends OperationResult { + private String location; + private String region; + private String server; + private Date date; + public CreateAffinityGroupResult(int statusCode, String requestId) { super(statusCode, requestId); - // TODO Auto-generated constructor stub + } + + public CreateAffinityGroupResult setLocation(String location) { + this.location = location; + return this; + + } + + public CreateAffinityGroupResult setRegion(String region) { + this.region = region; + return this; + } + + public CreateAffinityGroupResult setServer(String server) { + this.server = server; + return this; + } + + public CreateAffinityGroupResult setDate(Date date) { + this.date = date; + return this; + } + + public String getLocation() { + return this.location; + } + + public String getRegion() { + return this.region; + } + public String getServer() { + return this.server; } - public AffinityGroupInfo getValue() { - // TODO Auto-generated method stub - return null; + public Date getDate() { + return this.date; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java index 8561296cfc32a..90b60432f9697 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java @@ -15,6 +15,7 @@ package com.microsoft.windowsazure.services.management.models; +import java.util.Date; /** * The base result class for all the result of service management operation. @@ -22,13 +23,28 @@ */ public class UpdateAffinityGroupResult extends OperationResult { + private String region; + private Date date; + public UpdateAffinityGroupResult(int statusCode, String requestId) { super(statusCode, requestId); } - public AffinityGroupInfo getValue() { - // TODO Auto-generated method stub - return null; + public UpdateAffinityGroupResult setRegion(String region) { + this.region = region; + return this; + } + + public UpdateAffinityGroupResult setDate(Date date) { + this.date = date; + return this; } + public String getRegion() { + return this.region; + } + + public Date getDate() { + return this.date; + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java index af50b085ebde7..5f3be9e34ef15 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java @@ -14,13 +14,26 @@ */ package com.microsoft.windowsazure.services.management; +import java.util.Map; + import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; +import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.Builder.Alteration; +import com.microsoft.windowsazure.services.core.Builder.Registry; import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.ListResult; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.filter.LoggingFilter; public abstract class IntegrationTestBase { + + protected ManagementContract service; + @BeforeClass public static void initializeSystem() { System.setProperty("http.keepAlive", "false"); @@ -28,15 +41,53 @@ public static void initializeSystem() { @Before public void initialize() throws Exception { - // Configuration config = createConfiguration(); - // ManagementContract service = ManagementService.create(config); + createService(); + removeEntities(); + } + + private void createService() throws Exception { + // reinitialize configuration from known state + Configuration config = createConfiguration(); + + // add LoggingFilter to any pipeline that is created + Registry builder = (Registry) config.getBuilder(); + builder.alter(Client.class, new Alteration() { + @Override + public Client alter(String profile, Client client, Builder builder, Map properties) { + client.addFilter(new LoggingFilter()); + return client; + } + }); + + // applied as default configuration + Configuration.setInstance(config); + service = ManagementService.create(config); + } + + private void removeEntities() { + ListResult listAffinityGroupResult = null; + try { + listAffinityGroupResult = service.listAffinityGroups(); + } + catch (ServiceException e) { + } + + for (AffinityGroupInfo affinityGroupInfo : listAffinityGroupResult) { + try { + String affinityGroupName = affinityGroupInfo.getName(); + if ((affinityGroupName != null) && (affinityGroupName.startsWith("test"))) { + service.deleteAffinityGroup(affinityGroupInfo.getName()); + } + } + catch (ServiceException e) { + } + } } @AfterClass public static void cleanUpTestArtifacts() throws Exception { // Configuration config = createConfiguration(); - // ManagementContract service = ManagementService.create(config); } protected static Configuration createConfiguration() throws Exception { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index dfd53924414c1..306c19f126261 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -16,15 +16,8 @@ import static org.junit.Assert.*; -import java.util.Map; - -import org.junit.Before; import org.junit.Test; -import com.microsoft.windowsazure.services.core.Builder; -import com.microsoft.windowsazure.services.core.Builder.Alteration; -import com.microsoft.windowsazure.services.core.Builder.Registry; -import com.microsoft.windowsazure.services.core.Configuration; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.storage.utils.Base64; import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; @@ -34,33 +27,9 @@ import com.microsoft.windowsazure.services.management.models.ListResult; import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions; import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupResult; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.filter.LoggingFilter; public class ManagementIntegrationTest extends IntegrationTestBase { - private ManagementContract service; - - @Before - public void createService() throws Exception { - // reinitialize configuration from known state - Configuration config = createConfiguration(); - - // add LoggingFilter to any pipeline that is created - Registry builder = (Registry) config.getBuilder(); - builder.alter(Client.class, new Alteration() { - @Override - public Client alter(String profile, Client client, Builder builder, Map properties) { - client.addFilter(new LoggingFilter()); - return client; - } - }); - - // applied as default configuration - Configuration.setInstance(config); - service = ManagementService.create(); - } - @Test public void createAffinityGroupSuccess() throws Exception { // Arrange @@ -71,12 +40,12 @@ public void createAffinityGroupSuccess() throws Exception { // Act CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(expectedAffinityGroupName, expectedLabel, expectedLocation); - AffinityGroupInfo affinityGroupInfo = createAffinityGroupResult.getValue(); // Assert - assertEquals(expectedAffinityGroupName, affinityGroupInfo.getName()); - assertEquals(expectedLabel, affinityGroupInfo.getLabel()); - assertEquals(expectedLocation, affinityGroupInfo.getLocation()); + assertNotNull(createAffinityGroupResult.getLocation()); + assertNotNull(createAffinityGroupResult.getRegion()); + assertNotNull(createAffinityGroupResult.getServer()); + assertNotNull(createAffinityGroupResult.getDate()); } @@ -93,13 +62,12 @@ public void createAffinityGroupWithOptionalParametersSuccess() throws Exception // Act CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(expectedAffinityGroupName, expectedLabel, expectedLocation, createAffinityGroupOptions); - AffinityGroupInfo affinityGroupInfo = createAffinityGroupResult.getValue(); // Assert - assertEquals(expectedAffinityGroupName, affinityGroupInfo.getName()); - assertEquals(expectedLabel, affinityGroupInfo.getLabel()); - assertEquals(expectedDescription, affinityGroupInfo.getDescription()); - assertEquals(expectedLocation, affinityGroupInfo.getLocation()); + assertNotNull(createAffinityGroupResult.getLocation()); + assertNotNull(createAffinityGroupResult.getRegion()); + assertNotNull(createAffinityGroupResult.getServer()); + assertNotNull(createAffinityGroupResult.getDate()); } @@ -144,10 +112,11 @@ public void updateAffinityGroupSuccess() throws Exception { // Act UpdateAffinityGroupResult updateAffinityGroupResult = service.updateAffinityGroup(expectedAffinityGroupName, expectedAffinityGroupLabel, updateAffinityGroupOptions); - AffinityGroupInfo affinityGroupInfo = updateAffinityGroupResult.getValue(); // Assert - assertEquals(expectedDescription, affinityGroupInfo.getDescription()); + assertNotNull(updateAffinityGroupResult.getRegion()); + assertNotNull(updateAffinityGroupResult.getDate()); + assertNotNull(updateAffinityGroupResult.getRequestId()); } From 17e8b82bdc29f08f832d8654eb30190a603be0dc Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 12 Jul 2013 15:58:09 -0700 Subject: [PATCH 27/57] remove dependency on google gauva. --- microsoft-azure-api/pom.xml | 5 ----- .../services/management/ConnectionCredential.java | 9 +++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/microsoft-azure-api/pom.xml b/microsoft-azure-api/pom.xml index f8cf7f54d9d4c..62c685243d824 100644 --- a/microsoft-azure-api/pom.xml +++ b/microsoft-azure-api/pom.xml @@ -110,11 +110,6 @@ 1.46 test - - com.google.guava - guava-io - r03 - diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java index 97aa547fe8094..e5eb606843a33 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java @@ -8,10 +8,11 @@ package com.microsoft.windowsazure.services.management; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import com.google.common.io.ByteStreams; +import com.sun.jersey.core.util.ReaderWriter; public class ConnectionCredential { private final byte[] keyStore; @@ -33,9 +34,9 @@ public class ConnectionCredential { */ ConnectionCredential(InputStream keys, String keyPass, KeyStoreType type) throws IOException { keyPasswd = keyPass; - // Apache IOUtils could be used instead of google.common.io, - // or do a brute force read into List and then into an array. - keyStore = ByteStreams.toByteArray(keys); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ReaderWriter.writeTo(keys, byteArrayOutputStream); + keyStore = byteArrayOutputStream.toByteArray(); keyStoreType = type; } From 7939e511376fe83125b5f8afc32f967cf7fc2c34 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 12 Jul 2013 16:25:47 -0700 Subject: [PATCH 28/57] add microsoft copy right. --- .../management/ConnectionCredential.java | 14 +++++++++--- .../services/management/KeyStoreType.java | 14 +++++++++--- .../management/SSLContextFactory.java | 22 +++++++++++++------ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java index e5eb606843a33..7ab1d407e233e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java @@ -1,8 +1,16 @@ -/* +/** + * 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 * - * The author contributes this code to the public domain, - * retaining no rights and incurring no responsibilities for its use in whole or in part. + * 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.management; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java index 7d1d37b0901f6..cccc872816f96 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java @@ -1,8 +1,16 @@ -/* +/** + * 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 * - * The author contributes this code to the public domain, - * retaining no rights and incurring no responsibilities for its use in whole or in part. + * 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.management; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java index 0fd56d95eea55..d5a20d99b8ad7 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java @@ -1,3 +1,18 @@ +/** + * 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.management; import java.io.IOException; @@ -11,13 +26,6 @@ import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; -/** - * Note: as it stands this provides a TLS SSLContext from jks and pfx stores. It could be modified to - * support other protocols (SSLv3, SSLv2, etc) and different key stores... - * - * Note that older .pfx files may need to be updated to pkcs12 format.... - * - */ public class SSLContextFactory { public static SSLContext createSSLContext(ConnectionCredential cred) throws GeneralSecurityException, IOException { From f020b1f6e367a5663b52500a4c70678a483fc1c1 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 12 Jul 2013 18:06:43 -0700 Subject: [PATCH 29/57] refactor and clean up service managmenet infrastructure code. --- .../management/ConnectionCredential.java | 63 ---------- .../services/management/Exports.java | 109 ++++-------------- .../management/ManagementConfiguration.java | 47 ++++++-- .../management/ManagementContract.java | 48 ++++---- .../management/ManagementService.java | 14 +-- .../management/SSLContextFactory.java | 62 ---------- .../AffinityGroupInfoFactory.java | 10 ++ .../AffinityGroupInfoListFactory.java | 10 ++ .../{ => implementation}/KeyStoreType.java | 2 +- .../ManagementExceptionProcessor.java | 46 ++++++++ .../implementation/ManagementRestProxy.java | 85 ++++++++++++++ .../implementation/SSLContextFactory.java | 106 +++++++++++++++++ 12 files changed, 350 insertions(+), 252 deletions(-) delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/{ => implementation}/KeyStoreType.java (90%) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java deleted file mode 100644 index 7ab1d407e233e..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ConnectionCredential.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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.management; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -import com.sun.jersey.core.util.ReaderWriter; - -public class ConnectionCredential { - private final byte[] keyStore; - - private final String keyPasswd; - - private final KeyStoreType keyStoreType; - - /** - * Creates a Credential from a keyStore. - * - * @param keyPass - * - keyStore password, key for store and the internal private key must be - * symmetric - * @param keys - * - an InputStream probably a FileInputStream from a keyStore, the jks containing - * your management cert - * @throws IOException - */ - ConnectionCredential(InputStream keys, String keyPass, KeyStoreType type) throws IOException { - keyPasswd = keyPass; - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - ReaderWriter.writeTo(keys, byteArrayOutputStream); - keyStore = byteArrayOutputStream.toByteArray(); - keyStoreType = type; - } - - public KeyStoreType getKeyStoreType() { - return keyStoreType; - } - - public InputStream getKeyStore() { - return new ByteArrayInputStream(keyStore); - } - - public String getKeyPasswd() { - return keyPasswd; - } - -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index ca98ee1e6d7b5..9f3a2faf1ae11 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -20,26 +20,30 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.security.GeneralSecurityException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; import java.util.Map; import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import com.microsoft.windowsazure.services.core.Builder; import com.microsoft.windowsazure.services.core.UserAgentFilter; +import com.microsoft.windowsazure.services.management.implementation.KeyStoreCredential; +import com.microsoft.windowsazure.services.management.implementation.KeyStoreType; import com.microsoft.windowsazure.services.management.implementation.ManagementExceptionProcessor; import com.microsoft.windowsazure.services.management.implementation.ManagementRestProxy; +import com.microsoft.windowsazure.services.management.implementation.SSLContextFactory; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.client.urlconnection.HTTPSProperties; +/** + * The Class Exports. + */ public class Exports implements Builder.Exports { + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.core.Builder.Exports#register(com.microsoft.windowsazure.services.core.Builder.Registry) + */ @Override public void register(Builder.Registry registry) { @@ -55,44 +59,36 @@ public void register(Builder.Registry registry) { public ClientConfig alter(String profile, ClientConfig clientConfig, Builder builder, Map properties) { - // String keyStoreName = "d:\\src\\javacert\\iiscert\\democert.jks"; - String keyStoreName = (String) getPropertyIfExists(profile, properties, ManagementConfiguration.KEYSTORE_PATH); - // String trustStoreName = "c:\\src\\truststore.jks"; - // String keyStorePass = "democert"; String keyStorePass = (String) getPropertyIfExists(profile, properties, ManagementConfiguration.KEYSTORE_PASSWORD); - ConnectionCredential credential = null; + + KeyStoreCredential keyStoreCredential = null; try { - credential = new ConnectionCredential(new FileInputStream(keyStoreName), keyStorePass, + keyStoreCredential = new KeyStoreCredential(new FileInputStream(keyStoreName), keyStorePass, KeyStoreType.jks); } - catch (FileNotFoundException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + catch (FileNotFoundException e) { + throw new RuntimeException(e); } - catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + catch (IOException e) { + throw new RuntimeException(e); } SSLContext sslContext = null; try { - sslContext = SSLContextFactory.createSSLContext(credential); + sslContext = SSLContextFactory.createSSLContext(keyStoreCredential); } - catch (GeneralSecurityException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + catch (GeneralSecurityException e) { + throw new RuntimeException(e); } - catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + catch (IOException e) { + throw new RuntimeException(e); } clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() { - @Override public boolean verify(String arg0, SSLSession arg1) { return true; @@ -103,65 +99,4 @@ public boolean verify(String arg0, SSLSession arg1) { }); } - - private KeyManagerFactory createKeyManagerFactory(String keyStoreName, String keyStorePass, String keyPass) { - KeyManagerFactory keyManagerFactory = null; - KeyStore keyStore = createKeyStore(keyStoreName, keyStorePass); - - try { - keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); - } - catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - - try { - keyManagerFactory.init(keyStore, keyPass.toCharArray()); - } - catch (UnrecoverableKeyException e) { - throw new RuntimeException(e); - } - catch (KeyStoreException e) { - throw new RuntimeException(e); - } - catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - - return keyManagerFactory; - } - - private KeyStore createKeyStore(String keyStoreFileName, String keyStorePassword) { - KeyStore keyStore = null; - try { - keyStore = KeyStore.getInstance("JKS"); - } - catch (KeyStoreException e) { - throw new RuntimeException(e); - } - - FileInputStream keyStoreFileInputStream = null; - try { - keyStoreFileInputStream = new FileInputStream(keyStoreFileName); - } - catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - - try { - keyStore.load(keyStoreFileInputStream, keyStorePassword.toCharArray()); - } - catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - catch (CertificateException e) { - throw new RuntimeException(e); - } - catch (IOException e) { - throw new RuntimeException(e); - } - - return keyStore; - - } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java index 4cf509ce1de74..6cfc75a5a618c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java @@ -17,7 +17,7 @@ import com.microsoft.windowsazure.services.core.Configuration; /** - * Provides functionality to create a service bus configuration. + * Provides functionality to create a service management configuration. * */ public class ManagementConfiguration { @@ -48,30 +48,55 @@ public class ManagementConfiguration { /** * Creates a service management configuration using the specified uri, keystore path, and subscription id. * - * * @param uri - * A String object that represents the URI. - * + * A String object that represents the URI of the service management service. * @param subscriptionId * A String object that represents the subscription ID. - * - * @param keystorePath - * A String object that represents the path of the keystore. - * - * @return + * @return the configuration * A Configuration object that can be used when creating an instance of the - * ManagementService class. - * + * ManagementContract class. */ public static Configuration configure(String uri, String subscriptionId) { return configure(null, Configuration.getInstance(), uri, subscriptionId, null, null); } + /** + * Creates a service management configuration with specified values. + * + * @param uri + * A String object that represents the URI of the service management service. + * @param subscriptionId + * A String object that represents the subscription ID. + * @param keyStorePath + * A String object that represents the path of the keystore. + * @param keyStorePassword + * A String object that represents the password of the keystore. + * @return A Configuration object that can be used when creating an instance of the + * ManagementContract class. + */ public static Configuration configure(String uri, String subscriptionId, String keyStorePath, String keyStorePassword) { return configure(null, Configuration.getInstance(), uri, subscriptionId, keyStorePath, keyStorePassword); } + /** + * Creates a service management configuration with specified values. + * + * @param profile + * A String object that represents the profile. + * @param configuration + * A previously instantiated Configuration object. + * @param uri + * A String object that represents the URI of the service management service. + * @param subscriptionId + * A String object that represents the subscription ID. + * @param keyStorePath + * A String object that represents the path of the keystore. + * @param keyStorePassword + * A String object that represents the password of the keystore. + * @return A Configuration object that can be used when creating an instance of the + * ManagementContract class. + */ public static Configuration configure(String profile, Configuration configuration, String uri, String subscriptionId, String keyStoreLocation, String keyStorePassword) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java index 0b7391fa71858..b6fbe24720319 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -33,43 +33,45 @@ public interface ManagementContract extends FilterableService { /** - * Creates the affinity group. + * Creates a affinity group. * * @param name - * the name + * The name of the affinity group. * @param label - * the label + * The label of the affinity group. * @param location - * the location - * @return the creates the affinity group result + * The geographic location of the affinity group. + * + * @return A CreateAffinityGroupResult instance containing the result of the create affinity group + * request. * @throws ServiceException * the service exception */ CreateAffinityGroupResult createAffinityGroup(String name, String label, String location) throws ServiceException; /** - * Gets the affinity group. + * Gets the information of an affinity group. * * @param name - * the name - * @return the affinity group + * The name of the affinity group. + * @return A GetAffinityGroupResult instance which contains the information of the affinity group. * @throws ServiceException * the service exception */ GetAffinityGroupResult getAffinityGroup(String name) throws ServiceException; /** - * Creates the affinity group. + * Creates an affinity group. * * @param name - * the name + * The name of the affinity group. * @param label - * the label + * The label of the affinity group. * @param location - * the location + * The location of the affinity group. * @param createAffinityGroupOptions - * the create affinity group options - * @return the creates the affinity group result + * The options to create an affinity group. + * @return A CreateAffinityGroupResult instance which contains the information of the affinity group. * @throws ServiceException * the service exception */ @@ -80,8 +82,10 @@ CreateAffinityGroupResult createAffinityGroup(String name, String label, String * Delete affinity group. * * @param name - * the name - * @return the delete affinity group result + * The name of the affinity group. + * @return A DeleteAffinityGroupResult instance containing the result of delete affinity group + * operation. + * * @throws ServiceException * the service exception */ @@ -90,7 +94,7 @@ CreateAffinityGroupResult createAffinityGroup(String name, String label, String /** * List affinity groups. * - * @return the list result + * @return the result of the list affinity group operation. * @throws ServiceException * the service exception */ @@ -100,12 +104,14 @@ CreateAffinityGroupResult createAffinityGroup(String name, String label, String * Update affinity group. * * @param name - * the name + * The name of the affinity group. * @param label - * the label + * The label of the affinity group. * @param updateAffinityGroupOptions - * the update affinity group options - * @return the update affinity group result + * The options to update the affinity group. + * @return A UpdateAffinityGroupResult class instance which contains the result of update affinity + * group operation. + * * @throws ServiceException * the service exception */ diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java index e8488c31bf0b9..29a78b2065940 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java @@ -18,7 +18,7 @@ /** * - * Access service bus functionality. + * Access service management functionality. * */ public class ManagementService { @@ -28,7 +28,7 @@ private ManagementService() { } /** - * Creates an instance of the ServiceBusContract API. + * Creates an instance of the ManagementContract API. * */ public static ManagementContract create() { @@ -36,10 +36,10 @@ public static ManagementContract create() { } /** - * Creates an instance of the ServiceBusContract API using the specified configuration. + * Creates an instance of the ManagementContract API using the specified configuration. * * @param config - * A Configuration object that represents the configuration for the service bus service. + * A Configuration object that represents the configuration for the service management. * */ public static ManagementContract create(Configuration config) { @@ -47,7 +47,7 @@ public static ManagementContract create(Configuration config) { } /** - * Creates an instance of the ServiceBusContract API. + * Creates an instance of the ManagementContract API. * */ public static ManagementContract create(String profile) { @@ -55,10 +55,10 @@ public static ManagementContract create(String profile) { } /** - * Creates an instance of the ServiceBusContract API using the specified configuration. + * Creates an instance of the ManagementContract API using the specified configuration. * * @param config - * A Configuration object that represents the configuration for the service bus service. + * A Configuration object that represents the configuration for the service management. * */ public static ManagementContract create(String profile, Configuration config) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java deleted file mode 100644 index d5a20d99b8ad7..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/SSLContextFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * 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.management; - -import java.io.IOException; -import java.io.InputStream; -import java.security.GeneralSecurityException; -import java.security.KeyStore; -import java.security.SecureRandom; - -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; - -public class SSLContextFactory { - - public static SSLContext createSSLContext(ConnectionCredential cred) throws GeneralSecurityException, IOException { - return createSSLContext(cred.getKeyStore(), cred.getKeyPasswd(), cred.getKeyStoreType()); - } - - public static SSLContext createSSLContext(InputStream keyStoreStream, String keyStreamPasswd, KeyStoreType type) - throws GeneralSecurityException, IOException { - // Could Proxy KeyManagers to include only those with a specific alias for multi-cert file.... - KeyManager[] keyManagers = getKeyManagers(keyStoreStream, keyStreamPasswd, type.name()); - // note: may want to broaden this to SSLv3, SSLv2, SSL, etc... - SSLContext context = SSLContext.getInstance("TLS"); - // use default TrustManager and SecureRandom - context.init(keyManagers, null, new SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); - - return context; - } - - private static KeyManager[] getKeyManagers(InputStream keyStoreStream, String keyStreamPasswd, String type) - throws IOException, GeneralSecurityException { - - KeyStore ks = KeyStore.getInstance(type); - ks.load(keyStoreStream, keyStreamPasswd.toCharArray()); - keyStoreStream.close(); - - String alg = KeyManagerFactory.getDefaultAlgorithm(); - KeyManagerFactory kmFact = KeyManagerFactory.getInstance(alg); - kmFact.init(ks, keyStreamPasswd.toCharArray()); - - return kmFact.getKeyManagers(); - } - -} \ No newline at end of file diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java index 964d0133bcc6c..09f2a0fad5133 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java @@ -17,8 +17,18 @@ import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +/** + * A factory for creating AffinityGroupInfo objects. + */ public class AffinityGroupInfoFactory { + /** + * Gets the item. + * + * @param affinityGroup + * the affinity group + * @return the item + */ public static AffinityGroupInfo getItem(AffinityGroup affinityGroup) { return new AffinityGroupInfo().setName(affinityGroup.getName()).setLabel(affinityGroup.getLabel()) .setLocation(affinityGroup.getLocation()).setDescription(affinityGroup.getDescription()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java index 0aebb7c6919a6..99847b1aa7d50 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java @@ -20,8 +20,18 @@ import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +/** + * A factory for creating AffinityGroupInfoList objects. + */ public class AffinityGroupInfoListFactory { + /** + * Gets the item. + * + * @param affinityGroups + * the affinity groups + * @return the item + */ public static List getItem(AffinityGroups affinityGroups) { List result = new ArrayList(); List affinityGroupList = affinityGroups.getAffinityGroups(); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreType.java similarity index 90% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreType.java index cccc872816f96..ecb3944fa1303 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/KeyStoreType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreType.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package com.microsoft.windowsazure.services.management; +package com.microsoft.windowsazure.services.management.implementation; public enum KeyStoreType { jks, pkcs12 diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java index 78061ea49e17e..b073a8ebf3504 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java @@ -34,30 +34,61 @@ import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.UniformInterfaceException; +/** + * The Class ManagementExceptionProcessor. + */ public class ManagementExceptionProcessor implements ManagementContract { + /** The next. */ private final ManagementContract next; + + /** The log. */ static Log log = LogFactory.getLog(ManagementContract.class); + /** + * Instantiates a new management exception processor. + * + * @param next + * the next + */ public ManagementExceptionProcessor(ManagementContract next) { this.next = next; } + /** + * Instantiates a new management exception processor. + * + * @param next + * the next + */ @Inject public ManagementExceptionProcessor(ManagementRestProxy next) { this.next = next; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.core.FilterableService#withFilter(com.microsoft.windowsazure.services.core.ServiceFilter) + */ @Override public ManagementContract withFilter(ServiceFilter filter) { return new ManagementExceptionProcessor(next.withFilter(filter)); } + /** + * Process catch. + * + * @param e + * the e + * @return the service exception + */ private ServiceException processCatch(ServiceException e) { log.warn(e.getMessage(), e.getCause()); return ServiceExceptionFactory.process("serviceBus", e); } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#listAffinityGroups() + */ @Override public ListResult listAffinityGroups() throws ServiceException { try { @@ -71,6 +102,9 @@ public ListResult listAffinityGroups() throws ServiceExceptio } } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(java.lang.String, java.lang.String, java.lang.String) + */ @Override public CreateAffinityGroupResult createAffinityGroup(String name, String label, String location) throws ServiceException { @@ -85,6 +119,9 @@ public CreateAffinityGroupResult createAffinityGroup(String name, String label, } } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#getAffinityGroup(java.lang.String) + */ @Override public GetAffinityGroupResult getAffinityGroup(String name) throws ServiceException { try { @@ -98,6 +135,9 @@ public GetAffinityGroupResult getAffinityGroup(String name) throws ServiceExcept } } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#deleteAffinityGroup(java.lang.String) + */ @Override public DeleteAffinityGroupResult deleteAffinityGroup(String name) throws ServiceException { try { @@ -111,6 +151,9 @@ public DeleteAffinityGroupResult deleteAffinityGroup(String name) throws Service } } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(java.lang.String, java.lang.String, java.lang.String, com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions) + */ @Override public CreateAffinityGroupResult createAffinityGroup(String name, String label, String location, CreateAffinityGroupOptions createAffinityGroupOptions) throws ServiceException { @@ -125,6 +168,9 @@ public CreateAffinityGroupResult createAffinityGroup(String name, String label, } } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#updateAffinityGroup(java.lang.String, java.lang.String, com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions) + */ @Override public UpdateAffinityGroupResult updateAffinityGroup(String name, String label, UpdateAffinityGroupOptions updateAffinityGroupOptions) throws ServiceException { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index ea2cbcc5c453a..3736eccfc6452 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -44,17 +44,44 @@ import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; +/** + * The Class ManagementRestProxy. + */ public class ManagementRestProxy implements ManagementContract { + /** The channel. */ private Client channel; + + /** The uri. */ private final String uri; + + /** The subscription id. */ private final String subscriptionId; + + /** The key store path. */ private final String keyStorePath; + + /** The rfc1123 date convert. */ private final RFC1123DateConverter rfc1123DateConvert = new RFC1123DateConverter(); + + /** The log. */ static Log log = LogFactory.getLog(ManagementContract.class); + /** The filters. */ ServiceFilter[] filters; + /** + * Instantiates a new management rest proxy. + * + * @param channel + * the channel + * @param uri + * the uri + * @param subscriptionId + * the subscription id + * @param keyStorePath + * the key store path + */ @Inject public ManagementRestProxy(Client channel, @Named(ManagementConfiguration.URI) String uri, @Named(ManagementConfiguration.SUBSCRIPTION_ID) String subscriptionId, @@ -67,6 +94,20 @@ public ManagementRestProxy(Client channel, @Named(ManagementConfiguration.URI) S this.keyStorePath = keyStorePath; } + /** + * Instantiates a new management rest proxy. + * + * @param channel + * the channel + * @param serviceFilter + * the service filter + * @param uri + * the uri + * @param subscriptionId + * the subscription id + * @param keyStorePath + * the key store path + */ public ManagementRestProxy(Client channel, ServiceFilter[] serviceFilter, String uri, String subscriptionId, String keyStorePath) { this.channel = channel; @@ -76,14 +117,30 @@ public ManagementRestProxy(Client channel, ServiceFilter[] serviceFilter, String this.keyStorePath = keyStorePath; } + /** + * Gets the channel. + * + * @return the channel + */ public Client getChannel() { return channel; } + /** + * Sets the channel. + * + * @param channel + * the new channel + */ public void setChannel(Client channel) { this.channel = channel; } + /** + * Gets the resource. + * + * @return the resource + */ private WebResource getResource() { WebResource resource = getChannel().resource(this.uri); for (ServiceFilter filter : filters) { @@ -92,10 +149,20 @@ private WebResource getResource() { return resource; } + /** + * Gets the request id. + * + * @param clientResponse + * the client response + * @return the request id + */ private String getRequestId(ClientResponse clientResponse) { return clientResponse.getHeaders().getFirst("x-ms-request-id"); } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.core.FilterableService#withFilter(com.microsoft.windowsazure.services.core.ServiceFilter) + */ @Override public ManagementContract withFilter(ServiceFilter filter) { ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); @@ -103,6 +170,9 @@ public ManagementContract withFilter(ServiceFilter filter) { return new ManagementRestProxy(channel, newFilters, uri, subscriptionId, keyStorePath); } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#listAffinityGroups() + */ @Override public ListResult listAffinityGroups() { ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") @@ -115,11 +185,17 @@ public ListResult listAffinityGroups() { return new ListResult(clientResponse.getStatus(), requestId, affinityGroupInfoList); } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(java.lang.String, java.lang.String, java.lang.String) + */ @Override public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, String label, String location) { return createAffinityGroup(affinityGroupName, label, location, null); } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(java.lang.String, java.lang.String, java.lang.String, com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions) + */ @Override public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, String label, String location, CreateAffinityGroupOptions createAffinityGroupOptions) { @@ -144,6 +220,9 @@ public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, S return createAffinityGroupResult; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#getAffinityGroup(java.lang.String) + */ @Override public GetAffinityGroupResult getAffinityGroup(String name) { ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups").path(name) @@ -157,6 +236,9 @@ public GetAffinityGroupResult getAffinityGroup(String name) { return getAffinityGroupResult; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#deleteAffinityGroup(java.lang.String) + */ @Override public DeleteAffinityGroupResult deleteAffinityGroup(String name) { ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups").path(name) @@ -167,6 +249,9 @@ public DeleteAffinityGroupResult deleteAffinityGroup(String name) { return deleteAffinityGroupResult; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#updateAffinityGroup(java.lang.String, java.lang.String, com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions) + */ @Override public UpdateAffinityGroupResult updateAffinityGroup(String name, String label, UpdateAffinityGroupOptions updateAffinityGroupOptions) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java new file mode 100644 index 0000000000000..9a34a9cf08e3b --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java @@ -0,0 +1,106 @@ +/** + * 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.management.implementation; + +import java.io.IOException; +import java.io.InputStream; +import java.security.GeneralSecurityException; +import java.security.KeyStore; +import java.security.SecureRandom; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; + +/** + * A factory for creating SSLContext objects. + */ +public class SSLContextFactory { + + /** + * Creates a new SSLContext object. + * + * @param cred + * the cred + * @return the SSL context + * @throws GeneralSecurityException + * the general security exception + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static SSLContext createSSLContext(KeyStoreCredential keyStoreCredential) throws GeneralSecurityException, + IOException { + return createSSLContext(keyStoreCredential.getKeyStore(), keyStoreCredential.getKeystorePassword(), + keyStoreCredential.getKeyStoreType()); + } + + /** + * Creates a new SSLContext object. + * + * @param keyStoreStream + * the key store stream + * @param keyStorePassword + * the key stream passwd + * @param keyStoreType + * the type + * @return the SSL context + * @throws GeneralSecurityException + * the general security exception + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static SSLContext createSSLContext(InputStream keyStoreStream, String keyStorePassword, KeyStoreType keyStoreType) + throws GeneralSecurityException, IOException { + + KeyManager[] keyManagers = getKeyManagers(keyStoreStream, keyStorePassword, keyStoreType.name()); + SSLContext context = SSLContext.getInstance("TLS"); + context.init(keyManagers, null, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); + + return context; + } + + /** + * Gets the key managers. + * + * @param keyStoreStream + * the key store stream + * @param keyStorePassword + * the key stream passwd + * @param type + * the type + * @return the key managers + * @throws IOException + * Signals that an I/O exception has occurred. + * @throws GeneralSecurityException + * the general security exception + */ + private static KeyManager[] getKeyManagers(InputStream keyStoreStream, String keyStorePassword, String type) + throws IOException, GeneralSecurityException { + + KeyStore ks = KeyStore.getInstance(type); + ks.load(keyStoreStream, keyStorePassword.toCharArray()); + keyStoreStream.close(); + + String alg = KeyManagerFactory.getDefaultAlgorithm(); + KeyManagerFactory kmFact = KeyManagerFactory.getInstance(alg); + kmFact.init(ks, keyStorePassword.toCharArray()); + + return kmFact.getKeyManagers(); + } + +} \ No newline at end of file From 21d4be30b7bd255cbe6cf656021fe8601dd4e457 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Sun, 14 Jul 2013 13:17:54 -0700 Subject: [PATCH 30/57] refactor service managment infrastructure. --- .../services/management/Exports.java | 8 +- .../implementation/KeyStoreCredential.java | 90 +++++++++++++++++++ .../implementation/ManagementRestProxy.java | 2 + .../implementation/SSLContextFactory.java | 22 ++--- .../AffinityGroupInfoFactory.java | 4 +- .../AffinityGroupInfoListFactory.java | 5 +- 6 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.java rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/{implementation => models}/AffinityGroupInfoFactory.java (88%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/{implementation => models}/AffinityGroupInfoListFactory.java (85%) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index 9f3a2faf1ae11..460ce66fd9cca 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -16,7 +16,6 @@ import static com.microsoft.windowsazure.services.core.utils.ExportUtils.*; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.security.GeneralSecurityException; @@ -52,22 +51,21 @@ public void register(Builder.Registry registry) { registry.add(ManagementRestProxy.class); registry.add(UserAgentFilter.class); - // alter jersey client config for service management + // alter jersey client config for service management. registry.alter(ClientConfig.class, new Builder.Alteration() { @Override public ClientConfig alter(String profile, ClientConfig clientConfig, Builder builder, Map properties) { - String keyStoreName = (String) getPropertyIfExists(profile, properties, + String keyStorePath = (String) getPropertyIfExists(profile, properties, ManagementConfiguration.KEYSTORE_PATH); String keyStorePass = (String) getPropertyIfExists(profile, properties, ManagementConfiguration.KEYSTORE_PASSWORD); KeyStoreCredential keyStoreCredential = null; try { - keyStoreCredential = new KeyStoreCredential(new FileInputStream(keyStoreName), keyStorePass, - KeyStoreType.jks); + keyStoreCredential = new KeyStoreCredential(keyStorePath, keyStorePass, KeyStoreType.jks); } catch (FileNotFoundException e) { throw new RuntimeException(e); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.java new file mode 100644 index 0000000000000..33e153e326dd9 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.java @@ -0,0 +1,90 @@ +/** + * 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.management.implementation; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import com.sun.jersey.core.util.ReaderWriter; + +/** + * The Class KeyStoreCredential. + */ +public class KeyStoreCredential { + + /** The keystore. */ + private final byte[] keyStore; + + /** The password of the keystore. */ + private final String keystorePassword; + + /** The key store type. */ + private final KeyStoreType keyStoreType; + + /** + * Creates a KeyStoreCredential instance from a keyStore. + * + * @param keyStore + * - an InputStream probably a FileInputStream from a keyStore, the jks containing + * your management cert + * @param keyPass + * - keyStore password, key for store and the internal private key must be + * symmetric + * @param type + * the type + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public KeyStoreCredential(String keyStorePath, String keyPass, KeyStoreType type) throws IOException { + keystorePassword = keyPass; + InputStream keyStoreInputStream = new FileInputStream(keyStorePath); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ReaderWriter.writeTo(keyStoreInputStream, byteArrayOutputStream); + keyStore = byteArrayOutputStream.toByteArray(); + keyStoreType = type; + } + + /** + * Gets the key store type. + * + * @return the key store type + */ + public KeyStoreType getKeyStoreType() { + return keyStoreType; + } + + /** + * Gets the key store. + * + * @return the key store + */ + public InputStream getKeyStore() { + return new ByteArrayInputStream(keyStore); + } + + /** + * Gets the keystore password. + * + * @return the keystore password + */ + public String getKeystorePassword() { + return keystorePassword; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 3736eccfc6452..0aa44e7f47ded 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -33,6 +33,8 @@ import com.microsoft.windowsazure.services.management.ManagementConfiguration; import com.microsoft.windowsazure.services.management.ManagementContract; import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfoFactory; +import com.microsoft.windowsazure.services.management.models.AffinityGroupInfoListFactory; import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions; import com.microsoft.windowsazure.services.management.models.CreateAffinityGroupResult; import com.microsoft.windowsazure.services.management.models.DeleteAffinityGroupResult; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java index 9a34a9cf08e3b..3b90f0352811c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java @@ -27,16 +27,16 @@ import javax.net.ssl.SSLContext; /** - * A factory for creating SSLContext objects. + * A factory for creating SSLContext instance. */ public class SSLContextFactory { /** - * Creates a new SSLContext object. + * Creates a SSLContext with specified keystore credential. * - * @param cred - * the cred - * @return the SSL context + * @param keyStoreCredential + * the credential of the keystore. + * @return a SSLContext instance. * @throws GeneralSecurityException * the general security exception * @throws IOException @@ -44,12 +44,14 @@ public class SSLContextFactory { */ public static SSLContext createSSLContext(KeyStoreCredential keyStoreCredential) throws GeneralSecurityException, IOException { - return createSSLContext(keyStoreCredential.getKeyStore(), keyStoreCredential.getKeystorePassword(), - keyStoreCredential.getKeyStoreType()); + if (keyStoreCredential == null) { + throw new IllegalArgumentException("KeyStoreCredential cannot be null."); + } + return create(keyStoreCredential.getKeyStore(), keyStoreCredential.getKeystorePassword()); } /** - * Creates a new SSLContext object. + * Creates a SSLContext object with specified keystore stream and password. * * @param keyStoreStream * the key store stream @@ -63,10 +65,10 @@ public static SSLContext createSSLContext(KeyStoreCredential keyStoreCredential) * @throws IOException * Signals that an I/O exception has occurred. */ - public static SSLContext createSSLContext(InputStream keyStoreStream, String keyStorePassword, KeyStoreType keyStoreType) + public static SSLContext create(InputStream keyStoreStream, String keyStorePassword) throws GeneralSecurityException, IOException { - KeyManager[] keyManagers = getKeyManagers(keyStoreStream, keyStorePassword, keyStoreType.name()); + KeyManager[] keyManagers = getKeyManagers(keyStoreStream, keyStorePassword, "jks"); SSLContext context = SSLContext.getInstance("TLS"); context.init(keyManagers, null, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoFactory.java similarity index 88% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoFactory.java index 09f2a0fad5133..1786fef3f8404 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoFactory.java @@ -13,9 +13,9 @@ * limitations under the License. */ -package com.microsoft.windowsazure.services.management.implementation; +package com.microsoft.windowsazure.services.management.models; -import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.implementation.AffinityGroup; /** * A factory for creating AffinityGroupInfo objects. diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoListFactory.java similarity index 85% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoListFactory.java index 99847b1aa7d50..6f131867b8465 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/AffinityGroupInfoListFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoListFactory.java @@ -13,12 +13,13 @@ * limitations under the License. */ -package com.microsoft.windowsazure.services.management.implementation; +package com.microsoft.windowsazure.services.management.models; import java.util.ArrayList; import java.util.List; -import com.microsoft.windowsazure.services.management.models.AffinityGroupInfo; +import com.microsoft.windowsazure.services.management.implementation.AffinityGroup; +import com.microsoft.windowsazure.services.management.implementation.AffinityGroups; /** * A factory for creating AffinityGroupInfoList objects. From f10daa8a392d832f16c78335feb0f0b25e41cdb7 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Sun, 14 Jul 2013 14:08:57 -0700 Subject: [PATCH 31/57] clean up services.management directory. --- .../services/management/Exports.java | 1 + .../management/ManagementConfiguration.java | 29 ++++--------------- .../management/ManagementService.java | 3 ++ 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index 460ce66fd9cca..f104550d7ef9e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -60,6 +60,7 @@ public ClientConfig alter(String profile, ClientConfig clientConfig, Builder bui String keyStorePath = (String) getPropertyIfExists(profile, properties, ManagementConfiguration.KEYSTORE_PATH); + String keyStorePass = (String) getPropertyIfExists(profile, properties, ManagementConfiguration.KEYSTORE_PASSWORD); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java index 6cfc75a5a618c..291a95e504f72 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java @@ -23,7 +23,7 @@ public class ManagementConfiguration { /** - * Defines the location of the keystore. + * Defines the path of the keystore. * */ public final static String KEYSTORE_PATH = "management.keystore.path"; @@ -41,15 +41,15 @@ public class ManagementConfiguration { public final static String URI = "management.uri"; /** - * Defines the subscription ID of the service management. + * Defines the subscription ID of the Windows Azure account. */ public static final String SUBSCRIPTION_ID = "management.subscription.id"; /** - * Creates a service management configuration using the specified uri, keystore path, and subscription id. + * Creates a service management configuration using specified URI, and subscription ID. * * @param uri - * A String object that represents the URI of the service management service. + * A String object that represents the root URI of the service management service. * @param subscriptionId * A String object that represents the subscription ID. * @return the configuration @@ -61,26 +61,7 @@ public static Configuration configure(String uri, String subscriptionId) { } /** - * Creates a service management configuration with specified values. - * - * @param uri - * A String object that represents the URI of the service management service. - * @param subscriptionId - * A String object that represents the subscription ID. - * @param keyStorePath - * A String object that represents the path of the keystore. - * @param keyStorePassword - * A String object that represents the password of the keystore. - * @return A Configuration object that can be used when creating an instance of the - * ManagementContract class. - */ - public static Configuration configure(String uri, String subscriptionId, String keyStorePath, - String keyStorePassword) { - return configure(null, Configuration.getInstance(), uri, subscriptionId, keyStorePath, keyStorePassword); - } - - /** - * Creates a service management configuration with specified values. + * Creates a service management configuration with specified parameters. * * @param profile * A String object that represents the profile. diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java index 29a78b2065940..5413546069826 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java @@ -49,6 +49,9 @@ public static ManagementContract create(Configuration config) { /** * Creates an instance of the ManagementContract API. * + * @param profile + * A String object that representing the profile of the service management service. + * */ public static ManagementContract create(String profile) { return Configuration.getInstance().create(profile, ManagementContract.class); From 3121aaa4dec710a6450f8c1c4b59501d7aaf1187 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Mon, 15 Jul 2013 10:10:39 -0700 Subject: [PATCH 32/57] adds user agent filter. --- .../services/management/Exports.java | 5 +- .../management/ManagementConfiguration.java | 9 ++- .../implementation/KeyStoreCredential.java | 60 ++++++++----------- .../implementation/KeyStoreType.java | 11 +++- .../implementation/ManagementRestProxy.java | 19 +++--- .../implementation/SSLContextFactory.java | 56 +++++++++-------- .../management/IntegrationTestBase.java | 1 + .../com.microsoft.windowsazure.properties | 4 ++ 8 files changed, 90 insertions(+), 75 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index f104550d7ef9e..3a1127800e37f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -64,9 +64,12 @@ public ClientConfig alter(String profile, ClientConfig clientConfig, Builder bui String keyStorePass = (String) getPropertyIfExists(profile, properties, ManagementConfiguration.KEYSTORE_PASSWORD); + KeyStoreType keyStoreType = KeyStoreType.valueOf((String) getPropertyIfExists(profile, properties, + ManagementConfiguration.KEYSTORE_TYPE)); + KeyStoreCredential keyStoreCredential = null; try { - keyStoreCredential = new KeyStoreCredential(keyStorePath, keyStorePass, KeyStoreType.jks); + keyStoreCredential = new KeyStoreCredential(keyStorePath, keyStorePass, keyStoreType); } catch (FileNotFoundException e) { throw new RuntimeException(e); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java index 291a95e504f72..1adc84750a9f1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java @@ -34,6 +34,11 @@ public class ManagementConfiguration { */ public final static String KEYSTORE_PASSWORD = "management.keystore.password"; + /** + * Defines the type of the keystore. + */ + public static final String KEYSTORE_TYPE = "management.keystore.type"; + /** * Defines the URI of service management. * @@ -71,8 +76,8 @@ public static Configuration configure(String uri, String subscriptionId) { * A String object that represents the URI of the service management service. * @param subscriptionId * A String object that represents the subscription ID. - * @param keyStorePath - * A String object that represents the path of the keystore. + * @param keyStoreLocation + * the key store location * @param keyStorePassword * A String object that represents the password of the keystore. * @return A Configuration object that can be used when creating an instance of the diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.java index 33e153e326dd9..c58b8d77eb5e1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.java @@ -15,76 +15,66 @@ package com.microsoft.windowsazure.services.management.implementation; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; - -import com.sun.jersey.core.util.ReaderWriter; /** * The Class KeyStoreCredential. */ public class KeyStoreCredential { - /** The keystore. */ - private final byte[] keyStore; - /** The password of the keystore. */ private final String keystorePassword; + /** The key store path. */ + private final String keyStorePath; + /** The key store type. */ private final KeyStoreType keyStoreType; /** * Creates a KeyStoreCredential instance from a keyStore. * - * @param keyStore - * - an InputStream probably a FileInputStream from a keyStore, the jks containing - * your management cert - * @param keyPass - * - keyStore password, key for store and the internal private key must be - * symmetric - * @param type - * the type + * @param keyStorePath + * the path of the keystore. + * @param keyStorePassword + * the password for the keystore. + * @param keyStoreType + * the type of the keyStore. * @throws IOException - * Signals that an I/O exception has occurred. + * when a I/O exception has occurred. */ - public KeyStoreCredential(String keyStorePath, String keyPass, KeyStoreType type) throws IOException { - keystorePassword = keyPass; - InputStream keyStoreInputStream = new FileInputStream(keyStorePath); - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - ReaderWriter.writeTo(keyStoreInputStream, byteArrayOutputStream); - keyStore = byteArrayOutputStream.toByteArray(); - keyStoreType = type; + public KeyStoreCredential(String keyStorePath, String keyStorePassword, KeyStoreType keyStoreType) + throws IOException { + this.keystorePassword = keyStorePassword; + this.keyStorePath = keyStorePath; + this.keyStoreType = keyStoreType; } /** - * Gets the key store type. + * Gets the type of the key store. * - * @return the key store type + * @return A KeyStoreType representing the type of the key store. */ public KeyStoreType getKeyStoreType() { return keyStoreType; } /** - * Gets the key store. + * Gets the keystore password. * - * @return the key store + * @return A String instance representing the password of the keystore. */ - public InputStream getKeyStore() { - return new ByteArrayInputStream(keyStore); + public String getKeystorePassword() { + return keystorePassword; } /** - * Gets the keystore password. + * Gets the key store path. * - * @return the keystore password + * @return the key store path */ - public String getKeystorePassword() { - return keystorePassword; + public String getKeyStorePath() { + return this.keyStorePath; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreType.java index ecb3944fa1303..ffd178b12687c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreType.java @@ -15,6 +15,15 @@ package com.microsoft.windowsazure.services.management.implementation; +/** + * The Enum representing the type of the KeyStore. + */ public enum KeyStoreType { - jks, pkcs12 + + /** The jceks. */ + jceks, + /** The jks. */ + jks, + /** The pkcs12. */ + pkcs12 } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index 0aa44e7f47ded..a8ebb5c45dae1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -28,6 +28,7 @@ import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; import com.microsoft.windowsazure.services.core.utils.pipeline.PipelineHelpers; import com.microsoft.windowsazure.services.management.ManagementConfiguration; @@ -60,9 +61,6 @@ public class ManagementRestProxy implements ManagementContract { /** The subscription id. */ private final String subscriptionId; - /** The key store path. */ - private final String keyStorePath; - /** The rfc1123 date convert. */ private final RFC1123DateConverter rfc1123DateConvert = new RFC1123DateConverter(); @@ -81,19 +79,18 @@ public class ManagementRestProxy implements ManagementContract { * the uri * @param subscriptionId * the subscription id - * @param keyStorePath - * the key store path + * @param userAgentFilter + * the user agent filter */ @Inject public ManagementRestProxy(Client channel, @Named(ManagementConfiguration.URI) String uri, - @Named(ManagementConfiguration.SUBSCRIPTION_ID) String subscriptionId, - @Named(ManagementConfiguration.KEYSTORE_PATH) String keyStorePath) { + @Named(ManagementConfiguration.SUBSCRIPTION_ID) String subscriptionId, UserAgentFilter userAgentFilter) { this.channel = channel; this.filters = new ServiceFilter[0]; this.uri = uri; this.subscriptionId = subscriptionId; - this.keyStorePath = keyStorePath; + this.channel.addFilter(userAgentFilter); } /** @@ -110,13 +107,11 @@ public ManagementRestProxy(Client channel, @Named(ManagementConfiguration.URI) S * @param keyStorePath * the key store path */ - public ManagementRestProxy(Client channel, ServiceFilter[] serviceFilter, String uri, String subscriptionId, - String keyStorePath) { + public ManagementRestProxy(Client channel, ServiceFilter[] serviceFilter, String uri, String subscriptionId) { this.channel = channel; this.filters = serviceFilter; this.uri = uri; this.subscriptionId = subscriptionId; - this.keyStorePath = keyStorePath; } /** @@ -169,7 +164,7 @@ private String getRequestId(ClientResponse clientResponse) { public ManagementContract withFilter(ServiceFilter filter) { ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); newFilters[filters.length] = filter; - return new ManagementRestProxy(channel, newFilters, uri, subscriptionId, keyStorePath); + return new ManagementRestProxy(channel, newFilters, uri, subscriptionId); } /* (non-Javadoc) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java index 3b90f0352811c..e19d2f291f7f7 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java @@ -15,6 +15,7 @@ package com.microsoft.windowsazure.services.management.implementation; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.GeneralSecurityException; @@ -40,40 +41,50 @@ public class SSLContextFactory { * @throws GeneralSecurityException * the general security exception * @throws IOException - * Signals that an I/O exception has occurred. + * when an I/O exception has occurred. */ public static SSLContext createSSLContext(KeyStoreCredential keyStoreCredential) throws GeneralSecurityException, IOException { if (keyStoreCredential == null) { throw new IllegalArgumentException("KeyStoreCredential cannot be null."); } - return create(keyStoreCredential.getKeyStore(), keyStoreCredential.getKeystorePassword()); + return create(keyStoreCredential.getKeyStorePath(), keyStoreCredential.getKeystorePassword(), + keyStoreCredential.getKeyStoreType()); } /** * Creates a SSLContext object with specified keystore stream and password. * - * @param keyStoreStream - * the key store stream + * @param keyStorePath + * the path of the keystore. * @param keyStorePassword - * the key stream passwd + * the password of the keystore. * @param keyStoreType - * the type - * @return the SSL context + * the type of the keystore. + * @return An SSLContext instance. * @throws GeneralSecurityException * the general security exception * @throws IOException * Signals that an I/O exception has occurred. */ - public static SSLContext create(InputStream keyStoreStream, String keyStorePassword) + public static SSLContext create(String keyStorePath, String keyStorePassword, KeyStoreType keyStoreType) throws GeneralSecurityException, IOException { - KeyManager[] keyManagers = getKeyManagers(keyStoreStream, keyStorePassword, "jks"); - SSLContext context = SSLContext.getInstance("TLS"); - context.init(keyManagers, null, new SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); + if ((keyStorePath == null) || (keyStorePath.isEmpty())) { + throw new IllegalArgumentException("The keystore path cannot be null or empty."); + } + + if (keyStoreType == null) { + throw new IllegalArgumentException("The type of the keystore cannot be null"); + } - return context; + InputStream keyStoreInputStream = new FileInputStream(keyStorePath); + KeyManager[] keyManagers = getKeyManagers(keyStoreInputStream, keyStorePassword, keyStoreType); + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(keyManagers, null, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); + keyStoreInputStream.close(); + return sslContext; } /** @@ -82,7 +93,7 @@ public static SSLContext create(InputStream keyStoreStream, String keyStorePassw * @param keyStoreStream * the key store stream * @param keyStorePassword - * the key stream passwd + * the key stream password * @param type * the type * @return the key managers @@ -91,18 +102,15 @@ public static SSLContext create(InputStream keyStoreStream, String keyStorePassw * @throws GeneralSecurityException * the general security exception */ - private static KeyManager[] getKeyManagers(InputStream keyStoreStream, String keyStorePassword, String type) - throws IOException, GeneralSecurityException { - - KeyStore ks = KeyStore.getInstance(type); - ks.load(keyStoreStream, keyStorePassword.toCharArray()); - keyStoreStream.close(); + private static KeyManager[] getKeyManagers(InputStream keyStoreInputStream, String keyStorePassword, + KeyStoreType keyStoreType) throws IOException, GeneralSecurityException { - String alg = KeyManagerFactory.getDefaultAlgorithm(); - KeyManagerFactory kmFact = KeyManagerFactory.getInstance(alg); - kmFact.init(ks, keyStorePassword.toCharArray()); + KeyStore keyStore = KeyStore.getInstance(keyStoreType.name()); + keyStore.load(keyStoreInputStream, keyStorePassword.toCharArray()); + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); - return kmFact.getKeyManagers(); + return keyManagerFactory.getKeyManagers(); } } \ No newline at end of file diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java index 5f3be9e34ef15..f8a5f1eb94cf0 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java @@ -97,6 +97,7 @@ protected static Configuration createConfiguration() throws Exception { overrideWithEnv(config, ManagementConfiguration.SUBSCRIPTION_ID); overrideWithEnv(config, ManagementConfiguration.KEYSTORE_PASSWORD); overrideWithEnv(config, ManagementConfiguration.KEYSTORE_PATH); + overrideWithEnv(config, ManagementConfiguration.KEYSTORE_TYPE); return config; } diff --git a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties index ac480e1b39af5..eb2c358c922c9 100644 --- a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties +++ b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties @@ -17,6 +17,10 @@ media.oauth.uri=%MEDIA.OAUTH.URI% media.oauth.client.id=%OMEDIA.AUTH.CLIENT.ID% media.oauth.client.secret=%MEDIA.OAUTH.CLIENT.SECRET% media.oauth.scope=urn:WindowsAzureMediaServices +management.keystore.path=%MANAGEMENT.KEYSTORE.PATH% +management.keystore.password=%MANAGEMENT.KEYSTORE.PASSWORD% +management.keystore.type=%MANAGEMENT.KEYSTORE.TYPE% +management.subscription.id=%MANAGEMENT.SUBSCRIPTION.ID% management.uri=%MANAGEMENT.URI% testprefix.com.microsoft.windowsazure.services.core.Configuration.connectTimeout=3 testprefix.com.microsoft.windowsazure.services.core.Configuration.readTimeout=7 From 02c8337c8979a5fc2efc65b49e80eaa3f73caf39 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Mon, 15 Jul 2013 12:38:25 -0700 Subject: [PATCH 33/57] remove warnings! --- .../windowsazure/services/serviceBus/Util.java | 18 ++++++++---------- .../table/implementation/TableRestProxy.java | 3 --- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Util.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Util.java index 026cb9c517718..128e23fe2f506 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Util.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Util.java @@ -2,15 +2,15 @@ * 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 + * 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. + * 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; @@ -20,12 +20,10 @@ public class Util { public static Iterable iterateQueues(ServiceBusContract service) throws ServiceException { - // TODO: iterate over link rel=next pagination return service.listQueues().getItems(); } public static Iterable iterateTopics(ServiceBusContract service) throws ServiceException { - // TODO: iterate over link rel=next pagination return service.listTopics().getItems(); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java index 0daec9926c025..93cfbc41eb628 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java @@ -157,7 +157,6 @@ private void ThrowIfError(ClientResponse r) { } private String encodeODataURIValue(String value) { - //TODO: Unclear if OData value in URI's need to be encoded or not return value; } @@ -757,7 +756,6 @@ private DataSource createBatchInsertOrUpdateEntityPart(String table, Entity enti headers.addHeader("If-Match", entity.getEtag()); } - //TODO: Review code to make sure encoding is correct ByteArrayOutputStream httpRequest = new ByteArrayOutputStream(); httpReaderWriter.appendMethod(httpRequest, verb, path); httpReaderWriter.appendHeaders(httpRequest, headers); @@ -780,7 +778,6 @@ private DataSource createBatchDeleteEntityPart(String table, String partitionKey headers.addHeader("Content-ID", Integer.toString(contentId)); headers.addHeader("If-Match", etag == null ? "*" : etag); - //TODO: Review code to make sure encoding is correct ByteArrayOutputStream httpRequest = new ByteArrayOutputStream(); httpReaderWriter.appendMethod(httpRequest, "DELETE", path); httpReaderWriter.appendHeaders(httpRequest, headers); From 921a24ec8f45205f06a2b4ea6d0e996f787713d8 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 17 Jul 2013 10:48:10 -0700 Subject: [PATCH 34/57] fix warning. --- .../services/serviceBus/models/AbstractListOptions.java | 1 + .../services/core/utils/ParsedConnectionStringTest.java | 1 + 2 files changed, 2 insertions(+) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/AbstractListOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/AbstractListOptions.java index d18d87edf874d..79fbb5a31769f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/AbstractListOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/AbstractListOptions.java @@ -43,6 +43,7 @@ public String getFilter() { return filter; } + @SuppressWarnings("unchecked") public T setFilter(String filter) { this.filter = filter; return (T) this; diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/utils/ParsedConnectionStringTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/utils/ParsedConnectionStringTest.java index 68c5972d1d7f3..096149abaeb72 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/utils/ParsedConnectionStringTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/utils/ParsedConnectionStringTest.java @@ -80,6 +80,7 @@ public int getFieldThree() { return fieldThree; } + @SuppressWarnings("unused") @ConnectionStringField(name = "fieldthree") protected void setNumericField(String fieldThree) { this.fieldThree = Integer.parseInt(fieldThree); From 29a1551eae05f11fc58b04b20a397fb6d044ef51 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 18 Jul 2013 10:35:37 -0700 Subject: [PATCH 35/57] a unit test trying to repeat service bus large message failure. --- .../serviceBus/ServiceBusIntegrationTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java index 971df258c02cb..51462c07c5fcf 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java @@ -67,6 +67,14 @@ public class ServiceBusIntegrationTest extends IntegrationTestBase { .setTimeout(5); static ReceiveMessageOptions PEEK_LOCK_5_SECONDS = new ReceiveMessageOptions().setPeekLock().setTimeout(5); + private String createLongString(int length) { + String result = new String(); + for (int i = 0; i < length; i++) { + result = result + "a"; + } + return result; + } + @Before public void createService() throws Exception { // reinitialize configuration from known state @@ -278,6 +286,26 @@ public void receiveMessageWorks() throws Exception { assertArrayEquals("Hello World".getBytes(), Arrays.copyOf(data, size)); } + @Test + public void receiveLargeMessageWorks() throws Exception { + // Arrange + String queueName = "TestReceiveLargeMessageWorks"; + service.createQueue(new QueueInfo(queueName)); + String expectedBody = createLongString(64000); + BrokeredMessage expectedMessage = new BrokeredMessage(expectedBody); + service.sendQueueMessage(queueName, expectedMessage); + + // Act + BrokeredMessage message = service.receiveQueueMessage(queueName, RECEIVE_AND_DELETE_5_SECONDS).getValue(); + byte[] data = new byte[64000]; + int size = message.getBody().read(data); + + // Assert + assertEquals(expectedBody.length(), size); + assertArrayEquals(expectedBody.getBytes(), Arrays.copyOf(data, size)); + + } + @Test public void renewSubscriptionMessageLockWorks() throws Exception { // Arrange From f603bce889e9333a7d585eb17b8954c22a09fb72 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 18 Jul 2013 15:13:04 -0700 Subject: [PATCH 36/57] fix a minor bug in statusline --- .../windowsazure/services/media/implementation/StatusLine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/StatusLine.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/StatusLine.java index 7fcc5d5ea948b..1b330c9e93bca 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/StatusLine.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/StatusLine.java @@ -59,7 +59,7 @@ private static void expect(Reader reader, String string) { ch = reader.read(); if (ch != byteArray[i]) { throw new RuntimeException(String.format("Expected '%s', found '%s' instead", string, - string.substring(0, i) + ch)); + string.substring(0, i) + (char) ch)); } } } From 3d6474b439f0c469449e97e1ea3deee823e5236b Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 18 Jul 2013 16:17:45 -0700 Subject: [PATCH 37/57] put new service bus schema to the right place. --- .../schemas.microsoft.com.netservices.2011.06.servicebus.xsd | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename microsoft-azure-api/src/main/resources/{ => serviceBus}/schemas.microsoft.com.netservices.2011.06.servicebus.xsd (100%) diff --git a/microsoft-azure-api/src/main/resources/schemas.microsoft.com.netservices.2011.06.servicebus.xsd b/microsoft-azure-api/src/main/resources/serviceBus/schemas.microsoft.com.netservices.2011.06.servicebus.xsd similarity index 100% rename from microsoft-azure-api/src/main/resources/schemas.microsoft.com.netservices.2011.06.servicebus.xsd rename to microsoft-azure-api/src/main/resources/serviceBus/schemas.microsoft.com.netservices.2011.06.servicebus.xsd From 753e01b586cabe70ee1c43a5879d55faa59d4322 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 19 Jul 2013 16:26:08 -0700 Subject: [PATCH 38/57] address code review feedback for service management. --- .../implementation/ManagementRestProxy.java | 2 +- .../management/models/AffinityGroupInfo.java | 57 +++++++++++++++++++ .../models/AffinityGroupInfoFactory.java | 13 +++-- .../models/CreateAffinityGroupOptions.java | 14 +++-- .../management/models/ListResult.java | 2 +- .../management/ManagementIntegrationTest.java | 7 +++ 6 files changed, 85 insertions(+), 10 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index a8ebb5c45dae1..e1f5fa9686f79 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -202,7 +202,7 @@ public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, S createAffinityGroup.setLabel(label); createAffinityGroup.setLocation(location); if (createAffinityGroupOptions != null) { - createAffinityGroup.setDescription(createAffinityGroup.getDescription()); + createAffinityGroup.setDescription(createAffinityGroupOptions.getDescription()); } ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") .header("x-ms-version", "2013-03-01").header("x-ms-client-request-id", UUID.randomUUID().toString()) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfo.java index cfc9c37531f89..58698b4ce6865 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfo.java @@ -20,44 +20,101 @@ * */ public class AffinityGroupInfo { + + /** The name. */ private String name; + + /** The label. */ private String label; + + /** The description. */ private String description; + + /** The location. */ private String location; + /** + * Gets the name. + * + * @return the name + */ public String getName() { return this.name; } + /** + * Sets the name. + * + * @param name + * the name + * @return the affinity group info + */ public AffinityGroupInfo setName(String name) { this.name = name; return this; } + /** + * Gets the label. + * + * @return the label + */ public String getLabel() { return this.label; } + /** + * Sets the label. + * + * @param label + * the label + * @return the affinity group info + */ public AffinityGroupInfo setLabel(String label) { this.label = label; return this; } + /** + * Gets the description. + * + * @return the description + */ public String getDescription() { return this.description; } + /** + * Sets the description. + * + * @param description + * the description + * @return the affinity group info + */ public AffinityGroupInfo setDescription(String description) { this.description = description; return this; } + /** + * Gets the location. + * + * @return the location + */ public String getLocation() { return this.location; } + /** + * Sets the location. + * + * @param location + * the location + * @return the affinity group info + */ public AffinityGroupInfo setLocation(String location) { this.location = location; return this; } + } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoFactory.java index 1786fef3f8404..65f9d39a95c51 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoFactory.java @@ -23,15 +23,20 @@ public class AffinityGroupInfoFactory { /** - * Gets the item. + * Gets an affinity group info instance with specified affinity group. * * @param affinityGroup * the affinity group - * @return the item + * @return A AffinityGroupInfo instance. */ public static AffinityGroupInfo getItem(AffinityGroup affinityGroup) { - return new AffinityGroupInfo().setName(affinityGroup.getName()).setLabel(affinityGroup.getLabel()) - .setLocation(affinityGroup.getLocation()).setDescription(affinityGroup.getDescription()); + if (affinityGroup == null) { + return null; + } + else { + return new AffinityGroupInfo().setName(affinityGroup.getName()).setLabel(affinityGroup.getLabel()) + .setLocation(affinityGroup.getLocation()).setDescription(affinityGroup.getDescription()); + } } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java index 1d9f207eebe8a..f90720e7fb68d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java @@ -16,14 +16,20 @@ package com.microsoft.windowsazure.services.management.models; /** - * The base result class for all the result of service management operation. + * The options to create affinity group. * */ public class CreateAffinityGroupOptions { - public CreateAffinityGroupOptions setDescription(String expectedDescription) { - // TODO Auto-generated method stub - return null; + private String descrption; + + public CreateAffinityGroupOptions setDescription(String description) { + this.descrption = description; + return this; + } + + public String getDescription() { + return this.descrption; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java index 96620aaaaebc7..f0f600740e19e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java @@ -23,7 +23,7 @@ import java.util.ListIterator; /** - * Wrapper class for all returned lists from Media Services + * Wrapper class for all returned lists from service management. * */ public class ListResult extends OperationResult implements List { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index 306c19f126261..244a93859e142 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -41,11 +41,16 @@ public void createAffinityGroupSuccess() throws Exception { CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(expectedAffinityGroupName, expectedLabel, expectedLocation); + AffinityGroupInfo affinityGroupInfo = service.getAffinityGroup(expectedAffinityGroupName).getValue(); + // Assert assertNotNull(createAffinityGroupResult.getLocation()); assertNotNull(createAffinityGroupResult.getRegion()); assertNotNull(createAffinityGroupResult.getServer()); assertNotNull(createAffinityGroupResult.getDate()); + assertEquals(expectedAffinityGroupName, affinityGroupInfo.getName()); + assertEquals(expectedLabel, affinityGroupInfo.getLabel()); + assertEquals(expectedLocation, affinityGroupInfo.getLocation()); } @@ -64,10 +69,12 @@ public void createAffinityGroupWithOptionalParametersSuccess() throws Exception expectedLabel, expectedLocation, createAffinityGroupOptions); // Assert + AffinityGroupInfo actualAffinityGroupInfo = service.getAffinityGroup(expectedAffinityGroupName).getValue(); assertNotNull(createAffinityGroupResult.getLocation()); assertNotNull(createAffinityGroupResult.getRegion()); assertNotNull(createAffinityGroupResult.getServer()); assertNotNull(createAffinityGroupResult.getDate()); + assertEquals(expectedDescription, actualAffinityGroupInfo.getDescription()); } From aa90e5e059a27fde4a502ca728da83409359d4e5 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 25 Jul 2013 14:46:52 -0700 Subject: [PATCH 39/57] refactor the infrastructure to allow service specific alter during IoC. --- .../windowsazure/services/core/Builder.java | 6 +- .../services/core/Configuration.java | 4 +- .../services/core/DefaultBuilder.java | 25 +++++---- .../services/core/utils/pipeline/Exports.java | 26 +++++---- .../services/management/Exports.java | 2 +- .../windowsazure/services/media/Exports.java | 2 +- .../services/serviceBus/Exports.java | 2 +- .../serviceBus/implementation/Exports.java | 50 +++++++++-------- .../builder/DefaultBuilderTest.java | 56 +++++++++++-------- .../management/IntegrationTestBase.java | 2 +- .../serviceBus/ServiceBusIntegrationTest.java | 2 +- 11 files changed, 98 insertions(+), 79 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Builder.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Builder.java index 9ce1494b5ffb1..5f25c2bb67b34 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Builder.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Builder.java @@ -18,10 +18,10 @@ public interface Builder { - public abstract T build(String profile, Class service, Map properties); + public abstract T build(String profile, Class service, Class instance, Map properties); public interface Factory { - T create(String profile, Builder builder, Map properties); + T create(String profile, Class service, Builder builder, Map properties); } public interface Alteration { @@ -35,7 +35,7 @@ public interface Registry { Registry add(Factory factory); - void alter(Class service, Alteration alteration); + void alter(Class service, Class instance, Alteration alteration); } public interface Exports { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java index 764db7bab9b34..34c58ff4142d1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java @@ -91,11 +91,11 @@ public static Configuration load() throws IOException { } public T create(Class service) { - return builder.build("", service, properties); + return builder.build("", service, service, properties); } public T create(String profile, Class service) { - return builder.build(profile, service, properties); + return builder.build(profile, service, service, properties); } public Builder getBuilder() { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java index 369989af9a5e3..fc492e0eaa314 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java @@ -30,11 +30,11 @@ public class DefaultBuilder implements Builder, Builder.Registry { Map, Factory> factories; - Map, List>> alterations; + Map, Map, List>>> alterations; public DefaultBuilder() { factories = new HashMap, Factory>(); - alterations = new HashMap, List>>(); + alterations = new HashMap, Map, List>>>(); } public static DefaultBuilder create() { @@ -94,7 +94,7 @@ public Builder.Registry add(Class service, final Class impl addFactory(service, new Builder.Factory() { @Override @SuppressWarnings("unchecked") - public T create(String profile, Builder builder, Map properties) { + public T create(String profile, Class service, Builder builder, Map properties) { Object[] initializationArguments = new Object[parameterTypes.length]; for (int i = 0; i != parameterTypes.length; ++i) { @@ -121,7 +121,7 @@ public T create(String profile, Builder builder, Map properties) if (!located) { located = true; - initializationArguments[i] = builder.build(fullName, parameterTypes[i], properties); + initializationArguments[i] = builder.build(fullName, service, parameterTypes[i], properties); } } @@ -175,13 +175,13 @@ public Registry add(Factory factory) { @Override @SuppressWarnings("unchecked") - public T build(String profile, Class service, Map properties) { - Factory factory = (Factory) factories.get(service); + public T build(String profile, Class service, Class instanceClass, Map properties) { + Factory factory = (Factory) factories.get(instanceClass); if (factory == null) { throw new RuntimeException("Service or property not registered: " + profile + " " + service.getName()); } - T instance = factory.create(profile, this, properties); - List> alterationList = alterations.get(service); + T instance = factory.create(profile, service, this, properties); + List> alterationList = alterations.get(service).get(instanceClass); if (alterationList != null) { for (Alteration alteration : alterationList) { instance = ((Alteration) alteration).alter(profile, instance, this, properties); @@ -191,11 +191,14 @@ public T build(String profile, Class service, Map propert } @Override - public void alter(Class service, Alteration alteration) { + public void alter(Class service, Class instance, Alteration alteration) { if (!this.alterations.containsKey(service)) { - this.alterations.put(service, new ArrayList>()); + this.alterations.put(service, new HashMap, List>>()); } - this.alterations.get(service).add(alteration); + if (!this.alterations.get(service).containsKey(instance)) { + this.alterations.get(service).put(instance, new ArrayList>()); + } + this.alterations.get(service).get(instance).add(alteration); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java index 4acda86f735b6..9028aa8a1adcf 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java @@ -14,6 +14,8 @@ */ package com.microsoft.windowsazure.services.core.utils.pipeline; +import static com.microsoft.windowsazure.services.core.utils.ExportUtils.*; + import java.util.Map; import com.microsoft.windowsazure.services.core.Builder; @@ -23,17 +25,16 @@ import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; -import static com.microsoft.windowsazure.services.core.utils.ExportUtils.getPropertyIfExists; - public class Exports implements Builder.Exports { @Override public void register(Registry registry) { registry.add(new Builder.Factory() { @Override - public ClientConfig create(String profile, Builder builder, Map properties) { + public ClientConfig create(String profile, Class service, Builder builder, + Map properties) { ClientConfig clientConfig = new DefaultClientConfig(); - ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties); + ClientConfigSettings settings = builder.build(profile, service, ClientConfigSettings.class, properties); settings.applyConfig(clientConfig); return clientConfig; } @@ -42,20 +43,22 @@ public ClientConfig create(String profile, Builder builder, Map registry.add(new Builder.Factory() { @Override - public ClientConfigSettings create(String profile, Builder builder, Map properties) { + public ClientConfigSettings create(String profile, Class service, Builder builder, + Map properties) { Object connectTimeout = getPropertyIfExists(profile, properties, Configuration.PROPERTY_CONNECT_TIMEOUT); Object readTimeout = getPropertyIfExists(profile, properties, Configuration.PROPERTY_READ_TIMEOUT); return new ClientConfigSettings(connectTimeout, readTimeout, getPropertyIfExists(profile, properties, Configuration.PROPERTY_LOG_HTTP_REQUESTS) != null); } + }); registry.add(new Builder.Factory() { @Override - public Client create(String profile, Builder builder, Map properties) { - ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties); - ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties); + public Client create(String profile, Class service, Builder builder, Map properties) { + ClientConfig clientConfig = builder.build(profile, service, ClientConfig.class, properties); + ClientConfigSettings settings = builder.build(profile, service, ClientConfigSettings.class, properties); Client client = Client.create(clientConfig); settings.applyConfig(client); return client; @@ -64,9 +67,10 @@ public Client create(String profile, Builder builder, Map proper registry.add(new Builder.Factory() { @Override - public HttpURLConnectionClient create(String profile, Builder builder, Map properties) { - ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties); - ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties); + public HttpURLConnectionClient create(String profile, Class service, Builder builder, + Map properties) { + ClientConfig clientConfig = builder.build(profile, service, ClientConfig.class, properties); + ClientConfigSettings settings = builder.build(profile, service, ClientConfigSettings.class, properties); HttpURLConnectionClient client = HttpURLConnectionClient.create(clientConfig); settings.applyConfig(client); return client; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java index 3a1127800e37f..5c562f4ad58bb 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -52,7 +52,7 @@ public void register(Builder.Registry registry) { registry.add(UserAgentFilter.class); // alter jersey client config for service management. - registry.alter(ClientConfig.class, new Builder.Alteration() { + registry.alter(ManagementContract.class, ClientConfig.class, new Builder.Alteration() { @Override public ClientConfig alter(String profile, ClientConfig clientConfig, Builder builder, diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java index cfc946c718d3f..ff79a26d66370 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java @@ -53,7 +53,7 @@ public void register(Builder.Registry registry) { registry.add(VersionHeadersFilter.class); registry.add(UserAgentFilter.class); - registry.alter(ClientConfig.class, new Builder.Alteration() { + registry.alter(MediaContract.class, ClientConfig.class, new Builder.Alteration() { @SuppressWarnings("rawtypes") @Override public ClientConfig alter(String profile, ClientConfig instance, Builder builder, diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java index 76fd462f2b689..4c5929ec18eb2 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java @@ -37,7 +37,7 @@ public void register(Builder.Registry registry) { registry.add(UserAgentFilter.class); // alter jersey client config for serviceBus - registry.alter(ClientConfig.class, new Builder.Alteration() { + registry.alter(ServiceBusContract.class, ClientConfig.class, new Builder.Alteration() { @Override public ClientConfig alter(String profile, ClientConfig instance, Builder builder, diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/Exports.java index 40a04ba676def..e5a2629fa9c7c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/Exports.java @@ -1,30 +1,31 @@ /** * 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. + * 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.implementation; -import com.microsoft.windowsazure.services.core.Builder; -import com.microsoft.windowsazure.services.core.utils.ConnectionStringSyntaxException; -import com.microsoft.windowsazure.services.serviceBus.ServiceBusConfiguration; +import static com.microsoft.windowsazure.services.core.utils.ExportUtils.*; import java.net.URISyntaxException; import java.util.Map; -import static com.microsoft.windowsazure.services.core.utils.ExportUtils.getPropertyIfExists; +import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.utils.ConnectionStringSyntaxException; +import com.microsoft.windowsazure.services.serviceBus.ServiceBusConfiguration; public class Exports implements Builder.Exports { + @Override public void register(Builder.Registry registry) { registry.add(WrapContract.class, WrapRestProxy.class); registry.add(WrapTokenManager.class); @@ -33,17 +34,20 @@ public void register(Builder.Registry registry) { registry.add(new Builder.Factory() { @Override - public ServiceBusConnectionSettings create(String profile, Builder builder, Map properties) { + public ServiceBusConnectionSettings create(String profile, Class service, Builder builder, + Map properties) { try { - return new ServiceBusConnectionSettings( - (String) getPropertyIfExists(profile, properties, ServiceBusConfiguration.CONNECTION_STRING), - (String) getPropertyIfExists(profile, properties, ServiceBusConfiguration.URI), - (String) getPropertyIfExists(profile, properties, ServiceBusConfiguration.WRAP_URI), - (String) getPropertyIfExists(profile, properties, ServiceBusConfiguration.WRAP_NAME), - (String) getPropertyIfExists(profile, properties, ServiceBusConfiguration.WRAP_PASSWORD)); - } catch (ConnectionStringSyntaxException e) { + return new ServiceBusConnectionSettings((String) getPropertyIfExists(profile, properties, + ServiceBusConfiguration.CONNECTION_STRING), (String) getPropertyIfExists(profile, + properties, ServiceBusConfiguration.URI), (String) getPropertyIfExists(profile, properties, + ServiceBusConfiguration.WRAP_URI), (String) getPropertyIfExists(profile, properties, + ServiceBusConfiguration.WRAP_NAME), (String) getPropertyIfExists(profile, properties, + ServiceBusConfiguration.WRAP_PASSWORD)); + } + catch (ConnectionStringSyntaxException e) { throw new RuntimeException(e.getMessage(), e); - } catch (URISyntaxException e) { + } + catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/configuration/builder/DefaultBuilderTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/configuration/builder/DefaultBuilderTest.java index 0b164cd91178b..5dd190c78b24e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/configuration/builder/DefaultBuilderTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/configuration/builder/DefaultBuilderTest.java @@ -2,15 +2,15 @@ * 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 + * 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. + * 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.configuration.builder; @@ -48,8 +48,8 @@ public void namedAnnotationsComeFromBuildProperties() throws Exception { // Act Map properties = new HashMap(); properties.put("Foo", "world"); - ClassWithNamedParameter cwnp = builder.build("", - ClassWithNamedParameter.class, properties); + ClassWithNamedParameter cwnp = builder.build("", ClassWithNamedParameter.class, ClassWithNamedParameter.class, + properties); // Assert Assert.assertEquals("world", cwnp.getHello()); @@ -63,8 +63,8 @@ public void namedAnnotationReportsMissingProperty() throws Exception { builder.add(ClassWithNamedParameter.class); // Act - ClassWithNamedParameter cwnp = builder.build("", - ClassWithNamedParameter.class, properties); + ClassWithNamedParameter cwnp = builder.build("", ClassWithNamedParameter.class, ClassWithNamedParameter.class, + properties); // Assert Assert.assertEquals("world", cwnp.getHello()); @@ -76,7 +76,7 @@ public void singleCtorWithNoInjectShouldBeUsed() throws Exception { builder.add(ClassWithSingleCtorNoInject.class); // Act - ClassWithSingleCtorNoInject result = builder.build("", + ClassWithSingleCtorNoInject result = builder.build("", ClassWithSingleCtorNoInject.class, ClassWithSingleCtorNoInject.class, properties); // Assert @@ -91,7 +91,7 @@ public void multipleCtorWithNoInjectShouldFail() throws Exception { builder.add(ClassWithMultipleCtorNoInject.class); // Act - ClassWithMultipleCtorNoInject result = builder.build("", + ClassWithMultipleCtorNoInject result = builder.build("", ClassWithMultipleCtorNoInject.class, ClassWithMultipleCtorNoInject.class, properties); // Assert @@ -107,7 +107,7 @@ public void multipleCtorWithMultipleInjectShouldFail() throws Exception { builder.add(ClassWithMultipleCtorMultipleInject.class); // Act - ClassWithMultipleCtorMultipleInject result = builder.build("", + ClassWithMultipleCtorMultipleInject result = builder.build("", ClassWithMultipleCtorMultipleInject.class, ClassWithMultipleCtorMultipleInject.class, properties); // Assert @@ -119,10 +119,11 @@ public void multipleCtorWithMultipleInjectShouldFail() throws Exception { public void alterationExecutesWhenInstanceCreated() throws Exception { // Arrange builder.add(ClassWithProperties.class); - builder.alter(ClassWithProperties.class, new AlterClassWithProperties()); + builder.alter(ClassWithProperties.class, ClassWithProperties.class, new AlterClassWithProperties()); // Act - ClassWithProperties result = builder.build("", ClassWithProperties.class, properties); + ClassWithProperties result = builder + .build("", ClassWithProperties.class, ClassWithProperties.class, properties); // Assert Assert.assertEquals("one - changed", result.getFoo()); @@ -136,7 +137,8 @@ public void namedParametersUseProfileBasedKeysFirst() throws Exception { properties.put("testing.Foo", "Profile foo value"); // Act - ClassWithNamedParameter result = builder.build("testing", ClassWithNamedParameter.class, properties); + ClassWithNamedParameter result = builder.build("testing", ClassWithNamedParameter.class, + ClassWithNamedParameter.class, properties); // Assert Assert.assertEquals("Profile foo value", result.getHello()); @@ -150,9 +152,12 @@ public void namedParametersFallBackToNonProfileBasedKeys() throws Exception { properties.put("testing.Foo", "Profile foo value"); // Act - ClassWithNamedParameter result1 = builder.build("", ClassWithNamedParameter.class, properties); - ClassWithNamedParameter result2 = builder.build("production", ClassWithNamedParameter.class, properties); - ClassWithNamedParameter result3 = builder.build("testing.custom", ClassWithNamedParameter.class, properties); + ClassWithNamedParameter result1 = builder.build("", ClassWithNamedParameter.class, + ClassWithNamedParameter.class, properties); + ClassWithNamedParameter result2 = builder.build("production", ClassWithNamedParameter.class, + ClassWithNamedParameter.class, properties); + ClassWithNamedParameter result3 = builder.build("testing.custom", ClassWithNamedParameter.class, + ClassWithNamedParameter.class, properties); // Assert Assert.assertEquals("fallback", result1.getHello()); @@ -169,9 +174,12 @@ public void namedParamatersFallBackFromLeftToRight() throws Exception { properties.put("testing.custom.Foo", "testing.custom.Foo value"); // Act - ClassWithNamedParameter result1 = builder.build("custom", ClassWithNamedParameter.class, properties); - ClassWithNamedParameter result2 = builder.build("production.custom", ClassWithNamedParameter.class, properties); - ClassWithNamedParameter result3 = builder.build("testing.custom", ClassWithNamedParameter.class, properties); + ClassWithNamedParameter result1 = builder.build("custom", ClassWithNamedParameter.class, + ClassWithNamedParameter.class, properties); + ClassWithNamedParameter result2 = builder.build("production.custom", ClassWithNamedParameter.class, + ClassWithNamedParameter.class, properties); + ClassWithNamedParameter result3 = builder.build("testing.custom", ClassWithNamedParameter.class, + ClassWithNamedParameter.class, properties); // Assert Assert.assertEquals("custom.Foo value", result1.getHello()); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java index f8a5f1eb94cf0..c9e6c5787e3b1 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java @@ -51,7 +51,7 @@ private void createService() throws Exception { // add LoggingFilter to any pipeline that is created Registry builder = (Registry) config.getBuilder(); - builder.alter(Client.class, new Alteration() { + builder.alter(ManagementContract.class, Client.class, new Alteration() { @Override public Client alter(String profile, Client client, Builder builder, Map properties) { client.addFilter(new LoggingFilter()); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java index f628ec48f8d64..c9d99e58d3bad 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/ServiceBusIntegrationTest.java @@ -74,7 +74,7 @@ public void createService() throws Exception { // add LoggingFilter to any pipeline that is created Registry builder = (Registry) config.getBuilder(); - builder.alter(Client.class, new Alteration() { + builder.alter(ServiceBusContract.class, Client.class, new Alteration() { @Override public Client alter(String profile, Client instance, Builder builder, Map properties) { instance.addFilter(new LoggingFilter()); From fa89d126f42d9989d76c565e5fd1762041c5170a Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 25 Jul 2013 16:23:14 -0700 Subject: [PATCH 40/57] incorporated some code review feedback. --- .../services/core/DefaultBuilder.java | 11 +++++++---- .../WrapTokenManagerIntegrationTest.java | 16 ++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java index fc492e0eaa314..ad045e85da2e2 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/DefaultBuilder.java @@ -181,10 +181,13 @@ public T build(String profile, Class service, Class instanceClass, throw new RuntimeException("Service or property not registered: " + profile + " " + service.getName()); } T instance = factory.create(profile, service, this, properties); - List> alterationList = alterations.get(service).get(instanceClass); - if (alterationList != null) { - for (Alteration alteration : alterationList) { - instance = ((Alteration) alteration).alter(profile, instance, this, properties); + Map, List>> alterationMap = alterations.get(service); + if (alterationMap != null) { + List> alterationList = alterationMap.get(instanceClass); + if (alterationList != null) { + for (Alteration alteration : alterationList) { + instance = ((Alteration) alteration).alter(profile, instance, this, properties); + } } } return instance; diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapTokenManagerIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapTokenManagerIntegrationTest.java index 6d2cefd85fbf9..d6ca3faf8e7b8 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapTokenManagerIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/serviceBus/implementation/WrapTokenManagerIntegrationTest.java @@ -2,15 +2,15 @@ * 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 + * 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. + * 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.implementation; From f2775c4e463dbd12babb96e5682eb5f8ebeaabb6 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 30 Jul 2013 16:41:55 -0700 Subject: [PATCH 41/57] initial check in to add job notification for media services. --- .../JobNotificationSubscriptionType.java | 80 +++++++++++++++++++ .../media/implementation/content/JobType.java | 11 +++ .../services/media/models/JobInfo.java | 9 +++ .../models/JobNotificationSubscription.java | 49 ++++++++++++ .../media/models/TaskHistoricalEvent.java | 2 +- .../services/media/IntegrationTestBase.java | 30 +++++++ .../services/media/JobIntegrationTest.java | 43 ++++++++++ 7 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java new file mode 100644 index 0000000000000..b495684124725 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java @@ -0,0 +1,80 @@ +/** + * 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.media.implementation.content; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +/** + * This type maps the XML returned in the odata ATOM serialization + * for ErrorDetail entities. + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class JobNotificationSubscriptionType implements MediaServiceDTO { + + /** The message. */ + @XmlElement(name = "NotificationEndPointId", namespace = Constants.ODATA_DATA_NS) + protected String notificationEndPointId; + + /** The time stamp. */ + @XmlElement(name = "TargetJobState", namespace = Constants.ODATA_DATA_NS) + protected int targetJobState; + + /** + * Gets the code. + * + * @return the code + */ + public String getNotificationEndPointId() { + return this.notificationEndPointId; + } + + /** + * Sets the code. + * + * @param code + * the id to set + * @return the error detail type + */ + public JobNotificationSubscriptionType setNotificationEndPointId(String notificationEndPointId) { + this.notificationEndPointId = notificationEndPointId; + return this; + } + + /** + * Gets the message. + * + * @return the message + */ + public int getTargetJobState() { + return targetJobState; + } + + /** + * Sets the message. + * + * @param message + * the message to set + * @return the error detail type + */ + public JobNotificationSubscriptionType setTargetJobState(int targetJobState) { + this.targetJobState = targetJobState; + return this; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java index 18a8d027d0c3a..f42832ab288ee 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java @@ -16,10 +16,12 @@ package com.microsoft.windowsazure.services.media.implementation.content; import java.util.Date; +import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; /** * This type maps the XML returned in the odata ATOM serialization @@ -33,6 +35,11 @@ public class JobType implements MediaServiceDTO { @XmlElement(name = "Id", namespace = Constants.ODATA_DATA_NS) protected String id; + /** The job notification subscriptions */ + @XmlElementWrapper(name = "JobNotificationSubscriptions", namespace = Constants.ODATA_DATA_NS) + @XmlElement(name = "element", namespace = Constants.ODATA_DATA_NS) + protected List jobNotificationSubscriptions; + /** The name. */ @XmlElement(name = "Name", namespace = Constants.ODATA_DATA_NS) protected String name; @@ -269,4 +276,8 @@ public JobType setTemplateId(String templateId) { return this; } + public List getJobNotificationSubscriptions() { + return this.jobNotificationSubscriptions; + } + } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java index ba723e01f25c5..6ce8eac170708 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java @@ -19,6 +19,7 @@ import com.microsoft.windowsazure.services.media.implementation.ODataEntity; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; +import com.microsoft.windowsazure.services.media.implementation.content.JobNotificationSubscriptionType; import com.microsoft.windowsazure.services.media.implementation.content.JobType; /** @@ -154,4 +155,12 @@ public LinkInfo getOutputAssetsLink() { public LinkInfo getTasksLink() { return this. getRelationLink("Tasks"); } + + public JobInfo addJobNotificationSubscription(JobNotificationSubscription jobNotificationSubscription) { + getContent().getJobNotificationSubscriptions().add( + new JobNotificationSubscriptionType().setNotificationEndPointId( + jobNotificationSubscription.getNotificationEndPointId()).setTargetJobState( + jobNotificationSubscription.getTargetJobState().getCode())); + return this; + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java new file mode 100644 index 0000000000000..2c67d246373bc --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java @@ -0,0 +1,49 @@ +/* + * 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.media.models; + +/** + * The Class TaskHistoricalEvent. + */ +public class JobNotificationSubscription { + + private final String notificationEndPointId; + + private final JobState targetJobState; + + public JobNotificationSubscription(String notificationEndPointId, JobState targetJobState) { + this.notificationEndPointId = notificationEndPointId; + this.targetJobState = targetJobState; + } + + /** + * Gets the code. + * + * @return the code + */ + public String getNotificationEndPointId() { + return this.notificationEndPointId; + } + + /** + * Gets the message. + * + * @return the message + */ + public JobState getTargetJobState() { + return this.targetJobState; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskHistoricalEvent.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskHistoricalEvent.java index 14d44fc85142e..bd7d13f7daa19 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskHistoricalEvent.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskHistoricalEvent.java @@ -32,7 +32,7 @@ public class TaskHistoricalEvent { private final Date timeStamp; /** - * Instantiates a new error detail. + * Instantiates a new task historical event. * * @param code * the code diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java index 6e125ca859b16..ee0b8d347780e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java @@ -49,15 +49,22 @@ import com.microsoft.windowsazure.services.media.models.Locator; import com.microsoft.windowsazure.services.media.models.LocatorInfo; import com.microsoft.windowsazure.services.media.models.LocatorType; +import com.microsoft.windowsazure.services.queue.QueueConfiguration; +import com.microsoft.windowsazure.services.queue.QueueContract; +import com.microsoft.windowsazure.services.queue.QueueService; +import com.microsoft.windowsazure.services.queue.models.ListQueuesResult; +import com.microsoft.windowsazure.services.queue.models.ListQueuesResult.Queue; public abstract class IntegrationTestBase { protected static MediaContract service; + protected static QueueContract queueService; protected static Configuration config; protected static final String testAssetPrefix = "testAsset"; protected static final String testPolicyPrefix = "testPolicy"; protected static final String testContentKeyPrefix = "testContentKey"; protected static final String testJobPrefix = "testJobPrefix"; + protected static final String testQueuePrefix = "testqueueprefix"; protected static final String validButNonexistAssetId = "nb:cid:UUID:0239f11f-2d36-4e5f-aa35-44d58ccc0973"; protected static final String validButNonexistAccessPolicyId = "nb:pid:UUID:38dcb3a0-ef64-4ad0-bbb5-67a14c6df2f7"; @@ -79,7 +86,12 @@ public static void setup() throws Exception { overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_SECRET); overrideWithEnv(config, MediaConfiguration.OAUTH_SCOPE); + overrideWithEnv(config, QueueConfiguration.ACCOUNT_KEY); + overrideWithEnv(config, QueueConfiguration.ACCOUNT_NAME); + overrideWithEnv(config, QueueConfiguration.URI); + service = MediaService.create(config); + queueService = QueueService.create(config); cleanupEnvironment(); } @@ -103,6 +115,24 @@ protected static void cleanupEnvironment() { removeAllTestAccessPolicies(); removeAllTestJobs(); removeAllTestContentKeys(); + removeAllTestQueues(); + } + + private static void removeAllTestQueues() { + try { + ListQueuesResult listQueueResult = queueService.listQueues(); + for (Queue queue : listQueueResult.getQueues()) { + try { + queueService.deleteQueue(queue.getName()); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } } private static void removeAllTestContentKeys() { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java index a8032b0bdd3df..df9ec8526bdeb 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java @@ -30,6 +30,7 @@ import com.microsoft.windowsazure.services.media.models.ErrorDetail; import com.microsoft.windowsazure.services.media.models.Job; import com.microsoft.windowsazure.services.media.models.JobInfo; +import com.microsoft.windowsazure.services.media.models.JobNotificationSubscription; import com.microsoft.windowsazure.services.media.models.JobState; import com.microsoft.windowsazure.services.media.models.LinkInfo; import com.microsoft.windowsazure.services.media.models.ListResult; @@ -37,6 +38,8 @@ import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation; import com.microsoft.windowsazure.services.media.models.TaskHistoricalEvent; import com.microsoft.windowsazure.services.media.models.TaskInfo; +import com.microsoft.windowsazure.services.queue.models.ListQueuesResult.Queue; +import com.microsoft.windowsazure.services.queue.models.PeekMessagesResult.QueueMessage; public class JobIntegrationTest extends IntegrationTestBase { @@ -115,6 +118,46 @@ public void createJobSuccess() throws ServiceException { endTime, 1, actualJob); } + @Test + public void createJobWithNotificationSuccess() throws ServiceException { + // Arrange + String name = testJobPrefix + "createJobWithNotificationSuccess"; + String queueName = testQueuePrefix + "createjobwithnotificationsuccess"; + int priority = 3; + double duration = 0.0; + JobState state = JobState.Queued; + String templateId = null; + Date created = new Date(); + Date lastModified = new Date(); + Date stateTime = null; + Date endTime = null; + + queueService.createQueue(queueName); + List queues = queueService.listQueues().getQueues(); + String id = ""; + for (Queue queue : queues) { + if (queue.getName().equals(queueName)) { + id = queue.getUrl(); + } + } + + // Act + JobInfo actualJob = service.create( + Job.create().setName(name).setPriority(priority).addInputMediaAsset(assetInfo.getId()) + .addTaskCreator(getTaskCreator(0))).addJobNotificationSubscription( + getJobNotificationSubscription(id, JobState.Canceled)); + + // Assert + verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, + endTime, 1, actualJob); + List queueMessages = queueService.peekMessages(queueName).getQueueMessages(); + assertEquals(1, queueMessages.size()); + } + + private JobNotificationSubscription getJobNotificationSubscription(String id, JobState targetJobState) { + return new JobNotificationSubscription(id, targetJobState); + } + @Test public void createJobTwoTasksSuccess() throws ServiceException { // Arrange From abc8d3cd2488fdee54316eb93c7a9f007a3f440e Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 30 Jul 2013 17:27:16 -0700 Subject: [PATCH 42/57] move some classes that should belong to core to the core. --- .../windowsazure/services/blob/Exports.java | 2 +- .../BlobOperationRestProxy.java | 1 + .../blob/implementation/BlobRestProxy.java | 1 + .../ContainerACLDateAdapter.java | 18 +++++---- .../blob/implementation/SharedKeyFilter.java | 1 + .../implementation/SharedKeyLiteFilter.java | 1 + .../services/blob/models/AccessCondition.java | 2 +- .../services/blob/models/BlobProperties.java | 2 +- .../blob/models/ListContainersResult.java | 2 +- .../ISO8601DateConverter.java | 2 +- .../RFC1123DateAdapter.java | 18 ++++----- .../RFC1123DateConverter.java | 18 ++++----- .../implementation/MediaBlobRestProxy.java | 2 +- .../queue/implementation/QueueRestProxy.java | 2 +- .../queue/models/ListMessagesResult.java | 2 +- .../queue/models/PeekMessagesResult.java | 2 +- .../implementation/AtomReaderWriter.java | 39 ++++++++++++------- .../DefaultEdmValueConverter.java | 2 +- .../table/implementation/TableRestProxy.java | 4 +- .../ISO8601DateConverterTests.java | 2 +- .../implementation/AtomReaderWriterTests.java | 2 +- 21 files changed, 71 insertions(+), 54 deletions(-) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/{blob/implementation => core}/ISO8601DateConverter.java (98%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/{blob/implementation => core}/RFC1123DateAdapter.java (51%) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/{blob/implementation => core}/RFC1123DateConverter.java (66%) rename microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/{blob/implementation => core}/ISO8601DateConverterTests.java (98%) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/Exports.java index 7dfef8f100dbd..d4a5a7269bd65 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/Exports.java @@ -16,10 +16,10 @@ import com.microsoft.windowsazure.services.blob.implementation.BlobExceptionProcessor; import com.microsoft.windowsazure.services.blob.implementation.BlobRestProxy; -import com.microsoft.windowsazure.services.blob.implementation.ISO8601DateConverter; import com.microsoft.windowsazure.services.blob.implementation.SharedKeyFilter; import com.microsoft.windowsazure.services.blob.implementation.SharedKeyLiteFilter; import com.microsoft.windowsazure.services.core.Builder; +import com.microsoft.windowsazure.services.core.ISO8601DateConverter; import com.microsoft.windowsazure.services.core.UserAgentFilter; public class Exports implements Builder.Exports { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobOperationRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobOperationRestProxy.java index 5b865241508f4..4a9daa0e4b2b1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobOperationRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobOperationRestProxy.java @@ -67,6 +67,7 @@ import com.microsoft.windowsazure.services.blob.models.SetBlobPropertiesOptions; import com.microsoft.windowsazure.services.blob.models.SetBlobPropertiesResult; import com.microsoft.windowsazure.services.blob.models.SetContainerMetadataOptions; +import com.microsoft.windowsazure.services.core.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.CommaStringBuilder; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java index ed87b549f79be..3c5c7325d1c19 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java @@ -21,6 +21,7 @@ import com.microsoft.windowsazure.services.blob.BlobConfiguration; import com.microsoft.windowsazure.services.blob.BlobContract; +import com.microsoft.windowsazure.services.core.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.HttpURLConnectionClient; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/ContainerACLDateAdapter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/ContainerACLDateAdapter.java index 06ef3c975a264..5697162a06ab6 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/ContainerACLDateAdapter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/ContainerACLDateAdapter.java @@ -2,15 +2,15 @@ * 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 + * 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. + * 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.blob.implementation; @@ -18,6 +18,8 @@ import javax.xml.bind.annotation.adapters.XmlAdapter; +import com.microsoft.windowsazure.services.core.ISO8601DateConverter; + /* * JAXB adapter for a "not quite" ISO 8601 date time element */ diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/SharedKeyFilter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/SharedKeyFilter.java index b3ab2cd850cef..6030c865d47b5 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/SharedKeyFilter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/SharedKeyFilter.java @@ -26,6 +26,7 @@ import com.microsoft.windowsazure.services.blob.BlobConfiguration; import com.microsoft.windowsazure.services.blob.implementation.SharedKeyUtils.QueryParam; +import com.microsoft.windowsazure.services.core.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.utils.pipeline.EntityStreamingListener; import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.ClientRequest; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/SharedKeyLiteFilter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/SharedKeyLiteFilter.java index 696c73cd6d901..5600b07e8ecdb 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/SharedKeyLiteFilter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/SharedKeyLiteFilter.java @@ -24,6 +24,7 @@ import com.microsoft.windowsazure.services.blob.BlobConfiguration; import com.microsoft.windowsazure.services.blob.implementation.SharedKeyUtils.QueryParam; +import com.microsoft.windowsazure.services.core.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.utils.pipeline.EntityStreamingListener; import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.ClientRequest; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/AccessCondition.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/AccessCondition.java index f9a24919bdc01..cd4a21fb17bf5 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/AccessCondition.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/AccessCondition.java @@ -16,7 +16,7 @@ import java.util.Date; -import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateConverter; +import com.microsoft.windowsazure.services.core.RFC1123DateConverter; /** * Represents a set of access conditions for operations that use storage services. diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/BlobProperties.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/BlobProperties.java index 630e1a9fb2696..a19d7e73f8c95 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/BlobProperties.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/BlobProperties.java @@ -19,7 +19,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateAdapter; +import com.microsoft.windowsazure.services.core.RFC1123DateAdapter; /** * Represents the HTML properties and system properties that may be set on a blob. diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/ListContainersResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/ListContainersResult.java index 17c6d23aea2b4..e3e7a035b6f77 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/ListContainersResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/ListContainersResult.java @@ -26,7 +26,7 @@ import com.microsoft.windowsazure.services.blob.BlobContract; import com.microsoft.windowsazure.services.blob.implementation.MetadataAdapter; -import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateAdapter; +import com.microsoft.windowsazure.services.core.RFC1123DateAdapter; /** * A wrapper class for the response returned from a Blob Service REST API List Containers operation. This is returned by diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/ISO8601DateConverter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/ISO8601DateConverter.java similarity index 98% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/ISO8601DateConverter.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/ISO8601DateConverter.java index cac734d4dc6e2..71d5bc3d4992f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/ISO8601DateConverter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/ISO8601DateConverter.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.microsoft.windowsazure.services.blob.implementation; +package com.microsoft.windowsazure.services.core; import java.text.DateFormat; import java.text.ParseException; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/RFC1123DateAdapter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/RFC1123DateAdapter.java similarity index 51% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/RFC1123DateAdapter.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/RFC1123DateAdapter.java index aff36b78c73e7..559abd770daab 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/RFC1123DateAdapter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/RFC1123DateAdapter.java @@ -2,17 +2,17 @@ * 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 + * 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. + * 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.blob.implementation; +package com.microsoft.windowsazure.services.core; import java.util.Date; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/RFC1123DateConverter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/RFC1123DateConverter.java similarity index 66% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/RFC1123DateConverter.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/RFC1123DateConverter.java index 91d2acda79bb9..418a5782ba4b9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/RFC1123DateConverter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/RFC1123DateConverter.java @@ -2,17 +2,17 @@ * 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 + * 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. + * 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.blob.implementation; +package com.microsoft.windowsazure.services.core; import java.text.DateFormat; import java.text.ParseException; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaBlobRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaBlobRestProxy.java index 46d0ba286ee96..a698b280f7ce9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaBlobRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaBlobRestProxy.java @@ -19,7 +19,7 @@ import com.microsoft.windowsazure.services.blob.BlobContract; import com.microsoft.windowsazure.services.blob.implementation.BlobOperationRestProxy; -import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateConverter; +import com.microsoft.windowsazure.services.core.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.ServiceFilter; import com.sun.jersey.api.client.Client; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java index 454f51e44c9d7..27d2576bbd9f0 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/implementation/QueueRestProxy.java @@ -21,7 +21,7 @@ import javax.inject.Inject; import javax.inject.Named; -import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateConverter; +import com.microsoft.windowsazure.services.core.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.UserAgentFilter; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/models/ListMessagesResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/models/ListMessagesResult.java index 04f85095706dc..4c83ca513ee4b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/models/ListMessagesResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/models/ListMessagesResult.java @@ -22,7 +22,7 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateAdapter; +import com.microsoft.windowsazure.services.core.RFC1123DateAdapter; import com.microsoft.windowsazure.services.queue.QueueContract; /** diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/models/PeekMessagesResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/models/PeekMessagesResult.java index 34fc7f725ffaf..aac5f1990cb06 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/models/PeekMessagesResult.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/models/PeekMessagesResult.java @@ -22,7 +22,7 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateAdapter; +import com.microsoft.windowsazure.services.core.RFC1123DateAdapter; import com.microsoft.windowsazure.services.queue.QueueContract; /** diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriter.java index fc4003870ce83..18e20e08abb58 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriter.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. @@ -29,7 +29,7 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; -import com.microsoft.windowsazure.services.blob.implementation.ISO8601DateConverter; +import com.microsoft.windowsazure.services.core.ISO8601DateConverter; import com.microsoft.windowsazure.services.core.utils.DateFactory; import com.microsoft.windowsazure.services.table.EdmValueConverter; import com.microsoft.windowsazure.services.table.models.Entity; @@ -84,7 +84,8 @@ public void write(XMLStreamWriter writer) throws XMLStreamException { if (value != null) { writer.writeCharacters(value); - } else { + } + else { writer.writeAttribute("m:null", "true"); } @@ -107,7 +108,8 @@ public List parseTableEntries(InputStream stream) { // Process "entry" elements only if (isStartElement(xmlr, "entry")) { result.add(parseTableEntry(xmlr)); - } else { + } + else { nextSignificant(xmlr); } } @@ -116,7 +118,8 @@ public List parseTableEntries(InputStream stream) { expect(xmlr, XMLStreamConstants.END_DOCUMENT); return result; - } catch (XMLStreamException e) { + } + catch (XMLStreamException e) { throw new RuntimeException(e); } } @@ -130,7 +133,8 @@ public TableEntry parseTableEntry(InputStream stream) { expect(xmlr, XMLStreamConstants.END_DOCUMENT); return result; - } catch (XMLStreamException e) { + } + catch (XMLStreamException e) { throw new RuntimeException(e); } } @@ -147,7 +151,8 @@ public List parseEntityEntries(InputStream stream) { // Process "entry" elements only if (isStartElement(xmlr, "entry")) { result.add(parseEntityEntry(xmlr)); - } else { + } + else { nextSignificant(xmlr); } } @@ -156,7 +161,8 @@ public List parseEntityEntries(InputStream stream) { expect(xmlr, XMLStreamConstants.END_DOCUMENT); return result; - } catch (XMLStreamException e) { + } + catch (XMLStreamException e) { throw new RuntimeException(e); } } @@ -170,7 +176,8 @@ public Entity parseEntityEntry(InputStream stream) { expect(xmlr, XMLStreamConstants.END_DOCUMENT); return result; - } catch (XMLStreamException e) { + } + catch (XMLStreamException e) { throw new RuntimeException(e); } } @@ -220,7 +227,8 @@ private InputStream generateEntry(PropertiesWriter propertiesWriter) { writer.close(); return new ByteArrayInputStream(stream.toByteArray()); - } catch (XMLStreamException e) { + } + catch (XMLStreamException e) { throw new RuntimeException(e); } } @@ -235,7 +243,8 @@ private TableEntry parseTableEntry(XMLStreamReader xmlr) throws XMLStreamExcepti Map properties = parseEntryProperties(xmlr); result.setName((String) properties.get("TableName").getValue()); - } else { + } + else { nextSignificant(xmlr); } } @@ -254,7 +263,8 @@ private Entity parseEntityEntry(XMLStreamReader xmlr) throws XMLStreamException while (!isEndElement(xmlr, "entry")) { if (isStartElement(xmlr, "properties")) { result.setProperties(parseEntryProperties(xmlr)); - } else { + } + else { nextSignificant(xmlr); } } @@ -326,7 +336,8 @@ private void expect(XMLStreamReader xmlr, int eventType, String localName) throw private String encodeNumericCharacterReference(String value) { if (value == null) { return null; - } else { + } + else { char[] charArray = value.toCharArray(); StringBuffer stringBuffer = new StringBuffer(); for (int index = 0; index < charArray.length; index++) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConverter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConverter.java index cdf08312d8ae1..de73a55c8c627 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConverter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConverter.java @@ -20,7 +20,7 @@ import javax.inject.Inject; -import com.microsoft.windowsazure.services.blob.implementation.ISO8601DateConverter; +import com.microsoft.windowsazure.services.core.ISO8601DateConverter; import com.microsoft.windowsazure.services.table.EdmValueConverter; import com.microsoft.windowsazure.services.table.models.EdmType; import com.sun.jersey.core.util.Base64; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java index 0daec9926c025..6ffde10657f97 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java @@ -39,8 +39,8 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import com.microsoft.windowsazure.services.blob.implementation.ISO8601DateConverter; -import com.microsoft.windowsazure.services.blob.implementation.RFC1123DateConverter; +import com.microsoft.windowsazure.services.core.ISO8601DateConverter; +import com.microsoft.windowsazure.services.core.RFC1123DateConverter; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.UserAgentFilter; diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/implementation/ISO8601DateConverterTests.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/ISO8601DateConverterTests.java similarity index 98% rename from microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/implementation/ISO8601DateConverterTests.java rename to microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/ISO8601DateConverterTests.java index 669b1a29fb88d..f25703bad210a 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/implementation/ISO8601DateConverterTests.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/core/ISO8601DateConverterTests.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.microsoft.windowsazure.services.blob.implementation; +package com.microsoft.windowsazure.services.core; import static org.junit.Assert.*; diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriterTests.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriterTests.java index 1a2fd1ef0895d..03e5e11400522 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriterTests.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriterTests.java @@ -22,7 +22,7 @@ import org.junit.Test; -import com.microsoft.windowsazure.services.blob.implementation.ISO8601DateConverter; +import com.microsoft.windowsazure.services.core.ISO8601DateConverter; import com.microsoft.windowsazure.services.core.utils.DefaultDateFactory; import com.microsoft.windowsazure.services.table.IntegrationTestBase; import com.microsoft.windowsazure.services.table.models.TableEntry; From 538ccadc32eafe4234d3bf2d1253fc2024c575f0 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 31 Jul 2013 13:58:48 -0700 Subject: [PATCH 43/57] consolidate the create queue service into the BeforeClass method. --- .../queue/QueueServiceIntegrationTest.java | 47 ++++--------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java index ecfeb03a02596..079b6c22d77b4 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java @@ -59,6 +59,8 @@ public class QueueServiceIntegrationTest extends IntegrationTestBase { private static String CREATABLE_QUEUE_3; private static String[] creatableQueues; private static String[] testQueues; + private static QueueContract service; + private static Configuration config; @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -91,16 +93,14 @@ public static void setup() throws Exception { CREATABLE_QUEUE_3 = creatableQueues[2]; // Create all test containers and their content - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); + config = createConfiguration(); + service = QueueService.create(config); createQueues(service, testQueuesPrefix, testQueues); } @AfterClass public static void cleanup() throws Exception { - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); deleteQueues(service, testQueuesPrefix, testQueues); deleteQueues(service, createableQueuesPrefix, creatableQueues); @@ -136,8 +136,6 @@ private static Set listQueues(QueueContract service, String prefix) thro @Test public void getServicePropertiesWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Don't run this test with emulator, as v1.6 doesn't support this method if (isRunningWithEmulator(config)) { @@ -159,8 +157,6 @@ public void getServicePropertiesWorks() throws Exception { @Test public void setServicePropertiesWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Don't run this test with emulator, as v1.6 doesn't support this method if (isRunningWithEmulator(config)) { @@ -188,8 +184,6 @@ public void setServicePropertiesWorks() throws Exception { @Test public void createQueueWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act service.createQueue(CREATABLE_QUEUE_1); @@ -203,11 +197,14 @@ public void createQueueWorks() throws Exception { assertEquals(0, result.getMetadata().size()); } + @Test + public void deleteQueueWorks() throws Exception { + + } + @Test public void createQueueWithOptionsWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act service.createQueue(CREATABLE_QUEUE_2, @@ -227,8 +224,6 @@ public void createQueueWithOptionsWorks() throws Exception { @Test public void listQueuesWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act ListQueuesResult result = service.listQueues(); @@ -245,8 +240,6 @@ public void listQueuesWorks() throws Exception { @Test public void listQueuesWithOptionsWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act ListQueuesResult result = service.listQueues(new ListQueuesOptions().setMaxResults(3).setPrefix( @@ -281,8 +274,6 @@ public void listQueuesWithOptionsWorks() throws Exception { @Test public void setQueueMetadataWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act service.createQueue(CREATABLE_QUEUE_3); @@ -308,8 +299,6 @@ public void setQueueMetadataWorks() throws Exception { @Test public void createMessageWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act service.createMessage(TEST_QUEUE_FOR_MESSAGES, "message1"); @@ -323,8 +312,6 @@ public void createMessageWorks() throws Exception { @Test public void createNullMessageException() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act expectedException.expect(NullPointerException.class); @@ -334,8 +321,6 @@ public void createNullMessageException() throws Exception { @Test public void listMessagesWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.set(2010, 01, 01); @@ -372,8 +357,6 @@ public void listMessagesWorks() throws Exception { @Test public void listMessagesWithOptionsWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.set(2010, 01, 01); @@ -412,8 +395,6 @@ public void listMessagesWithOptionsWorks() throws Exception { @Test public void peekMessagesWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.set(2010, 01, 01); @@ -447,8 +428,6 @@ public void peekMessagesWorks() throws Exception { @Test public void peekMessagesWithOptionsWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.set(2010, 01, 01); @@ -484,8 +463,6 @@ public void peekMessagesWithOptionsWorks() throws Exception { @Test public void clearMessagesWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act service.createMessage(TEST_QUEUE_FOR_MESSAGES_6, "message1"); @@ -504,8 +481,6 @@ public void clearMessagesWorks() throws Exception { @Test public void deleteMessageWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act service.createMessage(TEST_QUEUE_FOR_MESSAGES_7, "message1"); @@ -527,8 +502,6 @@ public void deleteMessageWorks() throws Exception { @Test public void updateNullMessageException() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); String messageId = "messageId"; String popReceipt = "popReceipt"; @@ -544,8 +517,6 @@ public void updateNullMessageException() throws Exception { @Test public void updateMessageWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.set(2010, 01, 01); From 65d76fc420869cdcb9b2dae266881f92f10f5156 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 31 Jul 2013 14:25:05 -0700 Subject: [PATCH 44/57] add list queue operation. --- .../services/queue/QueueServiceIntegrationTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java index 079b6c22d77b4..c8fc533a59e27 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/QueueServiceIntegrationTest.java @@ -30,6 +30,8 @@ import org.junit.rules.ExpectedException; import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.media.ServiceExceptionMatcher; import com.microsoft.windowsazure.services.queue.models.CreateQueueOptions; import com.microsoft.windowsazure.services.queue.models.GetQueueMetadataResult; import com.microsoft.windowsazure.services.queue.models.ListMessagesOptions; @@ -199,7 +201,18 @@ public void createQueueWorks() throws Exception { @Test public void deleteQueueWorks() throws Exception { + // Arrange + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(404)); + + service.createQueue(CREATABLE_QUEUE_1); + + // Act + service.deleteQueue(CREATABLE_QUEUE_1); + GetQueueMetadataResult result = service.getQueueMetadata(CREATABLE_QUEUE_1); + // Assert + assertNull(result); } @Test From 9aedc1bd8b7d75760905fcc4a9808c1e23041373 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 31 Jul 2013 17:54:32 -0700 Subject: [PATCH 45/57] interdiate checkin for job notification. --- .../content/NotificationEndPointType.java | 108 +++++++++ .../services/media/models/EndPointType.java | 65 ++++++ .../media/models/NotificationEndPoint.java | 119 ++++++++++ .../models/NotificationEndPointInfo.java | 97 +++++++++ .../services/media/JobIntegrationTest.java | 18 +- .../NotificationEndPointIntegrationTest.java | 206 ++++++++++++++++++ 6 files changed, 600 insertions(+), 13 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EndPointType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfo.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java new file mode 100644 index 0000000000000..893fcd3cbb9f1 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java @@ -0,0 +1,108 @@ +/** + * 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.media.implementation.content; + +import java.util.Date; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlValue; + +/** + * This type maps the URI. + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "NotificationEndPointType", namespace = Constants.ODATA_DATA_NS) +public class NotificationEndPointType implements MediaServiceDTO { + @XmlValue + private String id; + + @XmlValue + private String name; + + @XmlValue + private Date created; + + @XmlValue + private int endpointType; + + @XmlValue + private String endpointAddress; + + /** + * @return the id. + */ + public String getId() { + return id; + } + + /** + * @param id + * id + * the id to set + */ + public NotificationEndPointType setId(String id) { + this.id = id; + return this; + } + + /** + * @return the name. + */ + public String getName() { + return name; + } + + /** + * @param name + * name + * the name to set + */ + public NotificationEndPointType setName(String name) { + this.name = name; + return this; + } + + public Date getCreated() { + return this.created; + } + + public NotificationEndPointType setCreated(Date created) { + this.created = created; + return this; + } + + public int getEndPointType() { + return this.endpointType; + } + + public NotificationEndPointType setEndPointType(int endpointType) { + this.endpointType = endpointType; + return this; + } + + public String getEndPointAddress() { + return this.endpointAddress; + } + + public NotificationEndPointType setEndPointAddress(String endpointAddress) { + this.endpointAddress = endpointAddress; + return this; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EndPointType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EndPointType.java new file mode 100644 index 0000000000000..86a8e2367a25c --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EndPointType.java @@ -0,0 +1,65 @@ +/** + * 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.media.models; + +import java.security.InvalidParameterException; + +/** + * Enum defining the type of the end point. + */ +public enum EndPointType { + + /** Azure Queue. */ + AzureQueue(1); + + /** The code. */ + private int code; + + /** + * Instantiates a new end point type. + * + * @param code + * the code + */ + private EndPointType(int code) { + this.code = code; + } + + /** + * Get integer code corresponding to enum value. + * + * @return the code + */ + public int getCode() { + return code; + } + + /** + * Convert code into enum value. + * + * @param code + * the code + * @return the corresponding enum value + */ + public static EndPointType fromCode(int code) { + switch (code) { + case 1: + return AzureQueue; + default: + throw new InvalidParameterException("code"); + } + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java new file mode 100644 index 0000000000000..3cf4b7823de34 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java @@ -0,0 +1,119 @@ +/** + * 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.media.models; + +import com.microsoft.windowsazure.services.media.entityoperations.DefaultDeleteOperation; +import com.microsoft.windowsazure.services.media.entityoperations.DefaultGetOperation; +import com.microsoft.windowsazure.services.media.entityoperations.DefaultListOperation; +import com.microsoft.windowsazure.services.media.entityoperations.EntityCreateOperation; +import com.microsoft.windowsazure.services.media.entityoperations.EntityDeleteOperation; +import com.microsoft.windowsazure.services.media.entityoperations.EntityGetOperation; +import com.microsoft.windowsazure.services.media.entityoperations.EntityOperationSingleResultBase; +import com.microsoft.windowsazure.services.media.implementation.content.NotificationEndPointType; +import com.sun.jersey.api.client.GenericType; + +/** + * Class for creating operations to manipulate notification end point entities. + * + */ +public class NotificationEndPoint { + + private static final String ENTITY_SET = "NotificationEndPoints"; + + private NotificationEndPoint() { + } + + /** + * Creates an operation to create a new notification end point. + * + * @param name + * name of the access policy + * @param durationInMinutes + * how long the access policy will be in force + * @param permissions + * permissions allowed by this access policy + * @return The operation + */ + public static EntityCreateOperation create(String name, EndPointType endPointType, + String endPointAddress) { + return new Creator(name, endPointType, endPointAddress); + } + + private static class Creator extends EntityOperationSingleResultBase implements + EntityCreateOperation { + private final String name; + private final EndPointType endPointType; + private final String endPointAddress; + + public Creator(String name, EndPointType endPointType, String endPointAddress) { + + super(ENTITY_SET, NotificationEndPointInfo.class); + + this.name = name; + this.endPointType = endPointType; + this.endPointAddress = endPointAddress; + } + + @Override + public Object getRequestContents() { + return new NotificationEndPointType().setName(name).setEndPointType(endPointType.getCode()) + .setEndPointAddress(endPointAddress); + } + } + + /** + * Create an operation that will retrieve the given access policy + * + * @param accessPolicyId + * id of access policy to retrieve + * @return the operation + */ + public static EntityGetOperation get(String accessPolicyId) { + return new DefaultGetOperation(ENTITY_SET, accessPolicyId, AccessPolicyInfo.class); + } + + /** + * Create an operation that will retrieve the access policy at the given link + * + * @param link + * the link + * @return the operation + */ + public static EntityGetOperation get(LinkInfo link) { + return new DefaultGetOperation(link.getHref(), AccessPolicyInfo.class); + } + + /** + * Create an operation that will retrieve all access policies + * + * @return the operation + */ + public static DefaultListOperation list() { + return new DefaultListOperation(ENTITY_SET, new GenericType>() { + }); + } + + /** + * Create an operation to delete the given access policy + * + * @param accessPolicyId + * id of access policy to delete + * @return the delete operation + */ + public static EntityDeleteOperation delete(String accessPolicyId) { + return new DefaultDeleteOperation(ENTITY_SET, accessPolicyId); + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfo.java new file mode 100644 index 0000000000000..a183a5af2376c --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfo.java @@ -0,0 +1,97 @@ +/** + * 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.media.models; + +import java.util.Date; +import java.util.EnumSet; + +import com.microsoft.windowsazure.services.media.implementation.ODataEntity; +import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; +import com.microsoft.windowsazure.services.media.implementation.content.AccessPolicyType; + +/** + * Type containing data about access policies. + * + */ +public class NotificationEndPointInfo extends ODataEntity { + + /** + * Creates a new {@link NotificationEndPointInfo} wrapping the given ATOM + * entry and content objects. + * + * @param entry + * Entry containing this AccessPolicy data + * @param content + * Content with the AccessPolicy data + */ + public NotificationEndPointInfo(EntryType entry, AccessPolicyType content) { + super(entry, content); + } + + /** + * Get the access policy id. + * + * @return the id. + */ + public String getId() { + return getContent().getId(); + } + + /** + * Get the creation date. + * + * @return the date. + */ + public Date getCreated() { + return getContent().getCreated(); + } + + /** + * Get the last modified date. + * + * @return the date. + */ + public Date getLastModified() { + return getContent().getLastModified(); + } + + /** + * Get the name. + * + * @return the name. + */ + public String getName() { + return getContent().getName(); + } + + /** + * Get the duration. + * + * @return the duration. + */ + public double getDurationInMinutes() { + return getContent().getDurationInMinutes(); + } + + /** + * Get the permissions. + * + * @return the permissions. + */ + public EnumSet getPermissions() { + return AccessPolicyPermission.permissionsFromBits(getContent().getPermissions()); + } +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java index df9ec8526bdeb..6fcb80f01b28c 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java @@ -38,7 +38,6 @@ import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation; import com.microsoft.windowsazure.services.media.models.TaskHistoricalEvent; import com.microsoft.windowsazure.services.media.models.TaskInfo; -import com.microsoft.windowsazure.services.queue.models.ListQueuesResult.Queue; import com.microsoft.windowsazure.services.queue.models.PeekMessagesResult.QueueMessage; public class JobIntegrationTest extends IntegrationTestBase { @@ -77,6 +76,10 @@ private void verifyJobProperties(String message, String testName, Integer priori } } + private JobNotificationSubscription getJobNotificationSubscription(String id, JobState targetJobState) { + return new JobNotificationSubscription(id, targetJobState); + } + private JobInfo createJob(String name) throws ServiceException { return service.create(Job.create().setName(name).setPriority(3).addInputMediaAsset(assetInfo.getId()) .addTaskCreator(getTaskCreator(0))); @@ -133,19 +136,12 @@ public void createJobWithNotificationSuccess() throws ServiceException { Date endTime = null; queueService.createQueue(queueName); - List queues = queueService.listQueues().getQueues(); - String id = ""; - for (Queue queue : queues) { - if (queue.getName().equals(queueName)) { - id = queue.getUrl(); - } - } // Act JobInfo actualJob = service.create( Job.create().setName(name).setPriority(priority).addInputMediaAsset(assetInfo.getId()) .addTaskCreator(getTaskCreator(0))).addJobNotificationSubscription( - getJobNotificationSubscription(id, JobState.Canceled)); + getJobNotificationSubscription(queueName, JobState.Canceled)); // Assert verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, @@ -154,10 +150,6 @@ public void createJobWithNotificationSuccess() throws ServiceException { assertEquals(1, queueMessages.size()); } - private JobNotificationSubscription getJobNotificationSubscription(String id, JobState targetJobState) { - return new JobNotificationSubscription(id, targetJobState); - } - @Test public void createJobTwoTasksSuccess() throws ServiceException { // Arrange diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java new file mode 100644 index 0000000000000..9991b20bc17f3 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java @@ -0,0 +1,206 @@ +/** + * 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.media; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +import org.junit.Test; + +import com.microsoft.windowsazure.services.core.ExponentialRetryPolicy; +import com.microsoft.windowsazure.services.core.RetryPolicyFilter; +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.media.models.AccessPolicy; +import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo; +import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; + +public class NotificationEndPointIntegrationTest extends IntegrationTestBase { + private void verifyInfosEqual(String message, AccessPolicyInfo expected, AccessPolicyInfo actual) { + verifyPolicyProperties(message, expected.getName(), expected.getDurationInMinutes(), expected.getPermissions(), + actual); + } + + private void verifyPolicyProperties(String message, String testName, double duration, + AccessPolicyPermission permission, AccessPolicyInfo policy) { + verifyPolicyProperties(message, testName, duration, EnumSet.of(permission), policy); + } + + private void verifyPolicyProperties(String message, String testName, double duration, + EnumSet permissions, AccessPolicyInfo policy) { + assertNotNull(message, policy); + assertEquals(message + " Name", testName, policy.getName()); + assertEquals(message + " DurationInMinutes", duration, policy.getDurationInMinutes(), 0.00001); + for (AccessPolicyPermission permission : permissions) { + if (permission != AccessPolicyPermission.NONE) { + assertTrue(message + "permissions should contain " + permission, + policy.getPermissions().contains(permission)); + } + } + assertEquals(message + " Permissions", permissions, policy.getPermissions()); + + assertNotNull(message + " Id", policy.getId()); + assertNotNull(message + " Created", policy.getCreated()); + assertNotNull(message + " LastModified", policy.getLastModified()); + assertEquals(message + " Created & LastModified", policy.getCreated(), policy.getLastModified()); + } + + @Test + public void canCreateNotificationEndPoint() throws Exception { + String testName = testNotificationEndPointPrefix + "CanCreate"; + + NotificationEndPointInfo notificationEndPoint = service.create(NotificationEndPoint.create(testName, + EndPointType.AzureQueue, endpointAddress)); + + verifyPolicyProperties("policy", testName, duration, AccessPolicyPermission.WRITE, policy); + } + + @Test + public void canCreateAccessPolicyWithReadPermissions() throws Exception { + String testName = testPolicyPrefix + "CanCreateRead"; + double duration = 5; + + AccessPolicyInfo policy = service.create(AccessPolicy.create(testName, duration, + EnumSet.of(AccessPolicyPermission.READ))); + + verifyPolicyProperties("policy", testName, duration, AccessPolicyPermission.READ, policy); + } + + @Test + public void canGetSinglePolicyById() throws Exception { + String expectedName = testPolicyPrefix + "GetOne"; + double duration = 1; + AccessPolicyInfo policyToGet = service.create(AccessPolicy.create(expectedName, duration, + EnumSet.of(AccessPolicyPermission.WRITE))); + + AccessPolicyInfo retrievedPolicy = service.get(AccessPolicy.get(policyToGet.getId())); + + assertEquals(policyToGet.getId(), retrievedPolicy.getId()); + verifyPolicyProperties("retrievedPolicy", expectedName, duration, AccessPolicyPermission.WRITE, retrievedPolicy); + } + + @Test + public void canGetSinglePolicyByInvalidId() throws Exception { + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(400)); + service.get(AccessPolicy.get(invalidId)); + } + + @Test + public void canGetSinglePolicyByNonexistId() throws Exception { + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(404)); + service.get(AccessPolicy.get(validButNonexistAccessPolicyId)); + } + + @Test + public void canRetrieveListOfAccessPolicies() throws Exception { + String[] policyNames = new String[] { testPolicyPrefix + "ListOne", testPolicyPrefix + "ListTwo" }; + double duration = 3; + EnumSet permissions = EnumSet.of(AccessPolicyPermission.WRITE, + AccessPolicyPermission.LIST); + + List expectedAccessPolicies = new ArrayList(); + for (int i = 0; i < policyNames.length; i++) { + AccessPolicyInfo policy = service.create(AccessPolicy.create(policyNames[i], duration, permissions)); + expectedAccessPolicies.add(policy); + } + + List actualAccessPolicies = service.list(AccessPolicy.list()); + + verifyListResultContains("listAccessPolicies", expectedAccessPolicies, actualAccessPolicies, + new ComponentDelegate() { + @Override + public void verifyEquals(String message, Object expected, Object actual) { + verifyInfosEqual(message, (AccessPolicyInfo) expected, (AccessPolicyInfo) actual); + } + }); + } + + @Test + public void canUseQueryParametersWhenListingAccessPolicies() throws Exception { + String[] policyNames = new String[] { testPolicyPrefix + "ListThree", testPolicyPrefix + "ListFour", + testPolicyPrefix + "ListFive", testPolicyPrefix + "ListSix", testPolicyPrefix + "ListSeven" }; + + double duration = 3; + EnumSet permissions = EnumSet.of(AccessPolicyPermission.WRITE, + AccessPolicyPermission.LIST); + + List expectedAccessPolicies = new ArrayList(); + for (int i = 0; i < policyNames.length; i++) { + AccessPolicyInfo policy = service.create(AccessPolicy.create(policyNames[i], duration, permissions)); + expectedAccessPolicies.add(policy); + } + + List actualAccessPolicies = service.list(AccessPolicy.list().setTop(2)); + + assertEquals(2, actualAccessPolicies.size()); + } + + // Note: Access Policy cannot be updated. + + @Test + public void canDeleteAccessPolicyById() throws Exception { + String policyName = testPolicyPrefix + "ToDelete"; + double duration = 1; + AccessPolicyInfo policyToDelete = service.create(AccessPolicy.create(policyName, duration, + EnumSet.of(AccessPolicyPermission.WRITE))); + List listPoliciesResult = service.list(AccessPolicy.list()); + int policyCountBaseline = listPoliciesResult.size(); + + service.delete(AccessPolicy.delete(policyToDelete.getId())); + + listPoliciesResult = service.list(AccessPolicy.list()); + assertEquals("listPoliciesResult.size", policyCountBaseline - 1, listPoliciesResult.size()); + + for (AccessPolicyInfo policy : service.list(AccessPolicy.list())) { + assertFalse(policyToDelete.getId().equals(policy.getId())); + } + + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(404)); + service.get(AccessPolicy.get(policyToDelete.getId())); + } + + @Test + public void canDeleteAccessPolicyByInvalidId() throws Exception { + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(400)); + service.delete(AccessPolicy.delete(invalidId)); + } + + @Test + public void canDeleteAccessPolicyByNonexistId() throws Exception { + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(404)); + service.delete(AccessPolicy.delete(validButNonexistAccessPolicyId)); + } + + @Test + public void canRetryAccessPolicyCreation() throws Exception { + String name = testPolicyPrefix + "canRetryAccessPolicyCreationPolicy"; + double duration = 1; + EnumSet write = EnumSet.of(AccessPolicyPermission.WRITE); + service.create(AccessPolicy.create(name + "1", duration, write)); + + ExponentialRetryPolicy forceRetryPolicy = new ExponentialRetryPolicy(1, 1, new int[] { 201 }); + MediaContract forceRetryService = service.withFilter(new RetryPolicyFilter(forceRetryPolicy)); + + forceRetryService.create(AccessPolicy.create(name + "2", duration, write)); + } +} From 3c8e2d201bffee2965dde6c4b3abb302aa3dabf5 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 1 Aug 2013 17:20:55 -0700 Subject: [PATCH 46/57] add NotificationEndPointIntegrationTest ... --- .../implementation/ODataAtomMarshaller.java | 4 + .../content/NotificationEndPointType.java | 12 +- .../implementation/content/ObjectFactory.java | 8 + .../media/models/NotificationEndPoint.java | 40 ++-- .../models/NotificationEndPointInfo.java | 49 ++--- .../NotificationEndPointIntegrationTest.java | 185 ++++++++---------- 6 files changed, 139 insertions(+), 159 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomMarshaller.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomMarshaller.java index 5f8a41ccbd96a..c64044c0f93dc 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomMarshaller.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomMarshaller.java @@ -38,8 +38,10 @@ import com.microsoft.windowsazure.services.media.implementation.content.AssetType; import com.microsoft.windowsazure.services.media.implementation.content.Constants; import com.microsoft.windowsazure.services.media.implementation.content.ContentKeyRestType; +import com.microsoft.windowsazure.services.media.implementation.content.JobNotificationSubscriptionType; import com.microsoft.windowsazure.services.media.implementation.content.JobType; import com.microsoft.windowsazure.services.media.implementation.content.LocatorRestType; +import com.microsoft.windowsazure.services.media.implementation.content.NotificationEndPointType; import com.microsoft.windowsazure.services.media.implementation.content.TaskType; /** @@ -133,6 +135,8 @@ private static Class[] getMarshalledClasses() { classes.add(TaskType.class); classes.add(ContentKeyRestType.class); classes.add(AssetFileType.class); + classes.add(NotificationEndPointType.class); + classes.add(JobNotificationSubscriptionType.class); return classes.toArray(new Class[0]); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java index 893fcd3cbb9f1..a8c9befd05175 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java @@ -19,8 +19,8 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlValue; /** * This type maps the URI. @@ -29,19 +29,19 @@ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "NotificationEndPointType", namespace = Constants.ODATA_DATA_NS) public class NotificationEndPointType implements MediaServiceDTO { - @XmlValue + @XmlElement(name = "Id", namespace = Constants.ODATA_DATA_NS) private String id; - @XmlValue + @XmlElement(name = "Name", namespace = Constants.ODATA_DATA_NS) private String name; - @XmlValue + @XmlElement(name = "Created", namespace = Constants.ODATA_DATA_NS) private Date created; - @XmlValue + @XmlElement(name = "EndpointType", namespace = Constants.ODATA_DATA_NS) private int endpointType; - @XmlValue + @XmlElement(name = "EndpointAddress", namespace = Constants.ODATA_DATA_NS) private String endpointAddress; /** diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java index 3aa8d5bfbfe95..bc605637adfb1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java @@ -121,4 +121,12 @@ public AssetFileType createAssetFileType() { public RebindContentKeyType createRebindContentKeyType() { return new RebindContentKeyType(); } + + public JobNotificationSubscriptionType createJobNotificationSubscriptionType() { + return new JobNotificationSubscriptionType(); + } + + public NotificationEndPointType createNotificationEndPointType() { + return new NotificationEndPointType(); + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java index 3cf4b7823de34..d8812377732da 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java @@ -40,11 +40,11 @@ private NotificationEndPoint() { * Creates an operation to create a new notification end point. * * @param name - * name of the access policy + * name of the notification end point * @param durationInMinutes - * how long the access policy will be in force + * how long the notification end point will be in force * @param permissions - * permissions allowed by this access policy + * permissions allowed by this notification end point * @return The operation */ public static EntityCreateOperation create(String name, EndPointType endPointType, @@ -75,25 +75,26 @@ public Object getRequestContents() { } /** - * Create an operation that will retrieve the given access policy + * Create an operation that will retrieve the given notification end point * - * @param accessPolicyId - * id of access policy to retrieve + * @param notificationEndPointId + * id of notification end point to retrieve * @return the operation */ - public static EntityGetOperation get(String accessPolicyId) { - return new DefaultGetOperation(ENTITY_SET, accessPolicyId, AccessPolicyInfo.class); + public static EntityGetOperation get(String notificationEndPointId) { + return new DefaultGetOperation(ENTITY_SET, notificationEndPointId, + NotificationEndPointInfo.class); } /** - * Create an operation that will retrieve the access policy at the given link + * Create an operation that will retrieve the notification end point at the given link * * @param link * the link * @return the operation */ - public static EntityGetOperation get(LinkInfo link) { - return new DefaultGetOperation(link.getHref(), AccessPolicyInfo.class); + public static EntityGetOperation get(LinkInfo link) { + return new DefaultGetOperation(link.getHref(), NotificationEndPointInfo.class); } /** @@ -101,19 +102,20 @@ public static EntityGetOperation get(LinkInfo list() { - return new DefaultListOperation(ENTITY_SET, new GenericType>() { - }); + public static DefaultListOperation list() { + return new DefaultListOperation(ENTITY_SET, + new GenericType>() { + }); } /** - * Create an operation to delete the given access policy + * Create an operation to delete the given notification end point * - * @param accessPolicyId - * id of access policy to delete + * @param notificationEndPointId + * id of notification end point to delete * @return the delete operation */ - public static EntityDeleteOperation delete(String accessPolicyId) { - return new DefaultDeleteOperation(ENTITY_SET, accessPolicyId); + public static EntityDeleteOperation delete(String notificationEndPointId) { + return new DefaultDeleteOperation(ENTITY_SET, notificationEndPointId); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfo.java index a183a5af2376c..511b5194a70f3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfo.java @@ -16,17 +16,16 @@ package com.microsoft.windowsazure.services.media.models; import java.util.Date; -import java.util.EnumSet; import com.microsoft.windowsazure.services.media.implementation.ODataEntity; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; -import com.microsoft.windowsazure.services.media.implementation.content.AccessPolicyType; +import com.microsoft.windowsazure.services.media.implementation.content.NotificationEndPointType; /** - * Type containing data about access policies. + * Type containing data about notification end points. * */ -public class NotificationEndPointInfo extends ODataEntity { +public class NotificationEndPointInfo extends ODataEntity { /** * Creates a new {@link NotificationEndPointInfo} wrapping the given ATOM @@ -37,12 +36,12 @@ public class NotificationEndPointInfo extends ODataEntity { * @param content * Content with the AccessPolicy data */ - public NotificationEndPointInfo(EntryType entry, AccessPolicyType content) { + public NotificationEndPointInfo(EntryType entry, NotificationEndPointType content) { super(entry, content); } /** - * Get the access policy id. + * Get the notification end point id. * * @return the id. */ @@ -51,47 +50,39 @@ public String getId() { } /** - * Get the creation date. + * Get the name. * - * @return the date. + * @return the name. */ - public Date getCreated() { - return getContent().getCreated(); + public String getName() { + return getContent().getName(); } /** - * Get the last modified date. + * Get the creation date. * * @return the date. */ - public Date getLastModified() { - return getContent().getLastModified(); + public Date getCreated() { + return getContent().getCreated(); } /** - * Get the name. + * Get the type of the end point. * - * @return the name. + * @return the end point type. */ - public String getName() { - return getContent().getName(); + public EndPointType getEndPointType() { + return EndPointType.fromCode(getContent().getEndPointType()); } /** - * Get the duration. + * Gets the end point address. * - * @return the duration. + * @return the end point address */ - public double getDurationInMinutes() { - return getContent().getDurationInMinutes(); + public String getEndPointAddress() { + return getContent().getEndPointAddress(); } - /** - * Get the permissions. - * - * @return the permissions. - */ - public EnumSet getPermissions() { - return AccessPolicyPermission.permissionsFromBits(getContent().getPermissions()); - } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java index 9991b20bc17f3..2cc9cfb87c6f0 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java @@ -18,189 +18,164 @@ import static org.junit.Assert.*; import java.util.ArrayList; -import java.util.EnumSet; import java.util.List; import org.junit.Test; -import com.microsoft.windowsazure.services.core.ExponentialRetryPolicy; -import com.microsoft.windowsazure.services.core.RetryPolicyFilter; import com.microsoft.windowsazure.services.core.ServiceException; -import com.microsoft.windowsazure.services.media.models.AccessPolicy; -import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo; -import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; +import com.microsoft.windowsazure.services.media.models.EndPointType; +import com.microsoft.windowsazure.services.media.models.NotificationEndPoint; +import com.microsoft.windowsazure.services.media.models.NotificationEndPointInfo; public class NotificationEndPointIntegrationTest extends IntegrationTestBase { - private void verifyInfosEqual(String message, AccessPolicyInfo expected, AccessPolicyInfo actual) { - verifyPolicyProperties(message, expected.getName(), expected.getDurationInMinutes(), expected.getPermissions(), - actual); + private final String validButNonexistNotificationEndPointId = "notificationEndPointId"; + private final String testNotificationEndPointPrefix = "testNotificationEndPointPrefix"; + private final String testEndPointAddress = "testEndPointAddress"; + + private void verifyNotificationEndPointInfosEqual(String message, NotificationEndPointInfo expected, + NotificationEndPointInfo actual) { + verifyNotificationEndPointProperties(message, expected.getName(), expected.getEndPointType(), + expected.getEndPointAddress(), actual); } - private void verifyPolicyProperties(String message, String testName, double duration, - AccessPolicyPermission permission, AccessPolicyInfo policy) { - verifyPolicyProperties(message, testName, duration, EnumSet.of(permission), policy); - } - - private void verifyPolicyProperties(String message, String testName, double duration, - EnumSet permissions, AccessPolicyInfo policy) { - assertNotNull(message, policy); - assertEquals(message + " Name", testName, policy.getName()); - assertEquals(message + " DurationInMinutes", duration, policy.getDurationInMinutes(), 0.00001); - for (AccessPolicyPermission permission : permissions) { - if (permission != AccessPolicyPermission.NONE) { - assertTrue(message + "permissions should contain " + permission, - policy.getPermissions().contains(permission)); - } - } - assertEquals(message + " Permissions", permissions, policy.getPermissions()); - - assertNotNull(message + " Id", policy.getId()); - assertNotNull(message + " Created", policy.getCreated()); - assertNotNull(message + " LastModified", policy.getLastModified()); - assertEquals(message + " Created & LastModified", policy.getCreated(), policy.getLastModified()); + private void verifyNotificationEndPointProperties(String message, String name, EndPointType endPointType, + String endPointAddress, NotificationEndPointInfo notificationEndPointInfo) { + assertNotNull(message, notificationEndPointInfo); + assertEquals(message + " Name", name, notificationEndPointInfo.getName()); + assertEquals(message + " EndPointType", endPointType, notificationEndPointInfo.getEndPointType()); + assertEquals(message + " EndPointAddress", endPointAddress, notificationEndPointInfo.getEndPointAddress()); + assertNotNull(message + " Created", notificationEndPointInfo.getCreated()); + assertNotNull(message + " Id", notificationEndPointInfo.getId()); } @Test public void canCreateNotificationEndPoint() throws Exception { String testName = testNotificationEndPointPrefix + "CanCreate"; + String testEndPointAddress = "testEndPointAddress"; - NotificationEndPointInfo notificationEndPoint = service.create(NotificationEndPoint.create(testName, - EndPointType.AzureQueue, endpointAddress)); + NotificationEndPointInfo actualNotificationEndPoint = service.create(NotificationEndPoint.create(testName, + EndPointType.AzureQueue, testEndPointAddress)); - verifyPolicyProperties("policy", testName, duration, AccessPolicyPermission.WRITE, policy); + verifyNotificationEndPointProperties("notification end point ", testName, EndPointType.AzureQueue, + testEndPointAddress, actualNotificationEndPoint); } @Test - public void canCreateAccessPolicyWithReadPermissions() throws Exception { - String testName = testPolicyPrefix + "CanCreateRead"; - double duration = 5; + public void canCreateNotificationEndPointWithReadPermissions() throws Exception { + String testName = testNotificationEndPointPrefix + "CanCreate"; - AccessPolicyInfo policy = service.create(AccessPolicy.create(testName, duration, - EnumSet.of(AccessPolicyPermission.READ))); + NotificationEndPointInfo actualNotificationEndPoint = service.create(NotificationEndPoint.create(testName, + EndPointType.AzureQueue, testEndPointAddress)); - verifyPolicyProperties("policy", testName, duration, AccessPolicyPermission.READ, policy); + verifyNotificationEndPointProperties("notification end point", testName, EndPointType.AzureQueue, + testEndPointAddress, actualNotificationEndPoint); } @Test - public void canGetSinglePolicyById() throws Exception { - String expectedName = testPolicyPrefix + "GetOne"; - double duration = 1; - AccessPolicyInfo policyToGet = service.create(AccessPolicy.create(expectedName, duration, - EnumSet.of(AccessPolicyPermission.WRITE))); + public void canGetSingleNotificationEndPointById() throws Exception { + String expectedName = testNotificationEndPointPrefix + "GetOne"; + NotificationEndPointInfo expectedNotificationEndPointInfo = service.create(NotificationEndPoint.create( + expectedName, EndPointType.AzureQueue, testEndPointAddress)); - AccessPolicyInfo retrievedPolicy = service.get(AccessPolicy.get(policyToGet.getId())); + NotificationEndPointInfo actualNotificationEndPointInfo = service.get(NotificationEndPoint + .get(expectedNotificationEndPointInfo.getId())); - assertEquals(policyToGet.getId(), retrievedPolicy.getId()); - verifyPolicyProperties("retrievedPolicy", expectedName, duration, AccessPolicyPermission.WRITE, retrievedPolicy); + assertEquals(expectedNotificationEndPointInfo.getId(), actualNotificationEndPointInfo.getId()); + verifyNotificationEndPointProperties("notification end point", expectedName, EndPointType.AzureQueue, + testEndPointAddress, actualNotificationEndPointInfo); } @Test public void canGetSinglePolicyByInvalidId() throws Exception { expectedException.expect(ServiceException.class); expectedException.expect(new ServiceExceptionMatcher(400)); - service.get(AccessPolicy.get(invalidId)); + service.get(NotificationEndPoint.get(invalidId)); } @Test public void canGetSinglePolicyByNonexistId() throws Exception { expectedException.expect(ServiceException.class); expectedException.expect(new ServiceExceptionMatcher(404)); - service.get(AccessPolicy.get(validButNonexistAccessPolicyId)); + service.get(NotificationEndPoint.get(validButNonexistNotificationEndPointId)); } @Test public void canRetrieveListOfAccessPolicies() throws Exception { - String[] policyNames = new String[] { testPolicyPrefix + "ListOne", testPolicyPrefix + "ListTwo" }; - double duration = 3; - EnumSet permissions = EnumSet.of(AccessPolicyPermission.WRITE, - AccessPolicyPermission.LIST); - - List expectedAccessPolicies = new ArrayList(); - for (int i = 0; i < policyNames.length; i++) { - AccessPolicyInfo policy = service.create(AccessPolicy.create(policyNames[i], duration, permissions)); - expectedAccessPolicies.add(policy); + String[] notificationEndPointNames = new String[] { testNotificationEndPointPrefix + "ListOne", + testNotificationEndPointPrefix + "ListTwo" }; + + List expectedNotificationEndPoints = new ArrayList(); + for (int i = 0; i < notificationEndPointNames.length; i++) { + NotificationEndPointInfo notificationEndPointInfo = service.create(NotificationEndPoint.create( + notificationEndPointNames[i], EndPointType.AzureQueue, testEndPointAddress)); + expectedNotificationEndPoints.add(notificationEndPointInfo); } - List actualAccessPolicies = service.list(AccessPolicy.list()); + List actualAccessPolicies = service.list(NotificationEndPoint.list()); - verifyListResultContains("listAccessPolicies", expectedAccessPolicies, actualAccessPolicies, + verifyListResultContains("listNotificationEndPoints", expectedNotificationEndPoints, actualAccessPolicies, new ComponentDelegate() { @Override public void verifyEquals(String message, Object expected, Object actual) { - verifyInfosEqual(message, (AccessPolicyInfo) expected, (AccessPolicyInfo) actual); + verifyNotificationEndPointInfosEqual(message, (NotificationEndPointInfo) expected, + (NotificationEndPointInfo) actual); } }); } @Test - public void canUseQueryParametersWhenListingAccessPolicies() throws Exception { - String[] policyNames = new String[] { testPolicyPrefix + "ListThree", testPolicyPrefix + "ListFour", - testPolicyPrefix + "ListFive", testPolicyPrefix + "ListSix", testPolicyPrefix + "ListSeven" }; - - double duration = 3; - EnumSet permissions = EnumSet.of(AccessPolicyPermission.WRITE, - AccessPolicyPermission.LIST); - - List expectedAccessPolicies = new ArrayList(); - for (int i = 0; i < policyNames.length; i++) { - AccessPolicyInfo policy = service.create(AccessPolicy.create(policyNames[i], duration, permissions)); - expectedAccessPolicies.add(policy); + public void canUseQueryParametersWhenListingNotificationEndPoints() throws Exception { + String[] notificationEndPointNames = new String[] { testNotificationEndPointPrefix + "ListThree", + testNotificationEndPointPrefix + "ListFour", testNotificationEndPointPrefix + "ListFive", + testNotificationEndPointPrefix + "ListSix", testNotificationEndPointPrefix + "ListSeven" }; + + List expectedNotificationEndPointInfos = new ArrayList(); + for (int i = 0; i < notificationEndPointNames.length; i++) { + NotificationEndPointInfo notificationEndPointInfo = service.create(NotificationEndPoint.create( + notificationEndPointNames[i], EndPointType.AzureQueue, testEndPointAddress)); + expectedNotificationEndPointInfos.add(notificationEndPointInfo); } - List actualAccessPolicies = service.list(AccessPolicy.list().setTop(2)); + List actualNotificationEndPointInfos = service.list(NotificationEndPoint.list() + .setTop(2)); - assertEquals(2, actualAccessPolicies.size()); + assertEquals(2, actualNotificationEndPointInfos.size()); } - // Note: Access Policy cannot be updated. - @Test - public void canDeleteAccessPolicyById() throws Exception { - String policyName = testPolicyPrefix + "ToDelete"; - double duration = 1; - AccessPolicyInfo policyToDelete = service.create(AccessPolicy.create(policyName, duration, - EnumSet.of(AccessPolicyPermission.WRITE))); - List listPoliciesResult = service.list(AccessPolicy.list()); + public void canDeleteNotificationEndPointById() throws Exception { + String testNotificationEndPointName = testNotificationEndPointPrefix + "ToDelete"; + NotificationEndPointInfo notificationEndPointToBeDeleted = service.create(NotificationEndPoint.create( + testNotificationEndPointName, EndPointType.AzureQueue, testEndPointAddress)); + List listPoliciesResult = service.list(NotificationEndPoint.list()); int policyCountBaseline = listPoliciesResult.size(); - service.delete(AccessPolicy.delete(policyToDelete.getId())); + service.delete(NotificationEndPoint.delete(notificationEndPointToBeDeleted.getId())); - listPoliciesResult = service.list(AccessPolicy.list()); + listPoliciesResult = service.list(NotificationEndPoint.list()); assertEquals("listPoliciesResult.size", policyCountBaseline - 1, listPoliciesResult.size()); - for (AccessPolicyInfo policy : service.list(AccessPolicy.list())) { - assertFalse(policyToDelete.getId().equals(policy.getId())); + for (NotificationEndPointInfo policy : service.list(NotificationEndPoint.list())) { + assertFalse(notificationEndPointToBeDeleted.getId().equals(policy.getId())); } expectedException.expect(ServiceException.class); expectedException.expect(new ServiceExceptionMatcher(404)); - service.get(AccessPolicy.get(policyToDelete.getId())); + service.get(NotificationEndPoint.get(notificationEndPointToBeDeleted.getId())); } @Test - public void canDeleteAccessPolicyByInvalidId() throws Exception { + public void canDeleteNotificationEndPointByInvalidId() throws Exception { expectedException.expect(ServiceException.class); expectedException.expect(new ServiceExceptionMatcher(400)); - service.delete(AccessPolicy.delete(invalidId)); + service.delete(NotificationEndPoint.delete(invalidId)); } @Test - public void canDeleteAccessPolicyByNonexistId() throws Exception { + public void canDeleteNotificationEndPointByNonexistId() throws Exception { expectedException.expect(ServiceException.class); expectedException.expect(new ServiceExceptionMatcher(404)); - service.delete(AccessPolicy.delete(validButNonexistAccessPolicyId)); + service.delete(NotificationEndPoint.delete(validButNonexistNotificationEndPointId)); } - @Test - public void canRetryAccessPolicyCreation() throws Exception { - String name = testPolicyPrefix + "canRetryAccessPolicyCreationPolicy"; - double duration = 1; - EnumSet write = EnumSet.of(AccessPolicyPermission.WRITE); - service.create(AccessPolicy.create(name + "1", duration, write)); - - ExponentialRetryPolicy forceRetryPolicy = new ExponentialRetryPolicy(1, 1, new int[] { 201 }); - MediaContract forceRetryService = service.withFilter(new RetryPolicyFilter(forceRetryPolicy)); - - forceRetryService.create(AccessPolicy.create(name + "2", duration, write)); - } } From 69a821423e0e1f6e90c1e3c792370c8fa46f1fe9 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 2 Aug 2013 10:50:36 -0700 Subject: [PATCH 47/57] the notification end point integration test passed. --- .../implementation/VersionHeadersFilter.java | 2 +- .../content/NotificationEndPointType.java | 4 ++-- .../NotificationEndPointIntegrationTest.java | 15 +++++++-------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java index 84b1a670a763a..80ebd577cce34 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java @@ -36,7 +36,7 @@ public ClientResponse doHandle(ClientRequest cr) { MultivaluedMap headers = cr.getHeaders(); headers.add("DataServiceVersion", "3.0"); headers.add("MaxDataServiceVersion", "3.0"); - headers.add("x-ms-version", "2.0"); + headers.add("x-ms-version", "2.2"); return getNext().handle(cr); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java index a8c9befd05175..57a6f4e461826 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java @@ -38,10 +38,10 @@ public class NotificationEndPointType implements MediaServiceDTO { @XmlElement(name = "Created", namespace = Constants.ODATA_DATA_NS) private Date created; - @XmlElement(name = "EndpointType", namespace = Constants.ODATA_DATA_NS) + @XmlElement(name = "EndPointType", namespace = Constants.ODATA_DATA_NS) private int endpointType; - @XmlElement(name = "EndpointAddress", namespace = Constants.ODATA_DATA_NS) + @XmlElement(name = "EndPointAddress", namespace = Constants.ODATA_DATA_NS) private String endpointAddress; /** diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java index 2cc9cfb87c6f0..9a27e93e077ab 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java @@ -30,7 +30,7 @@ public class NotificationEndPointIntegrationTest extends IntegrationTestBase { private final String validButNonexistNotificationEndPointId = "notificationEndPointId"; private final String testNotificationEndPointPrefix = "testNotificationEndPointPrefix"; - private final String testEndPointAddress = "testEndPointAddress"; + private final String testEndPointAddress = "testendpointaddress"; private void verifyNotificationEndPointInfosEqual(String message, NotificationEndPointInfo expected, NotificationEndPointInfo actual) { @@ -51,7 +51,6 @@ private void verifyNotificationEndPointProperties(String message, String name, E @Test public void canCreateNotificationEndPoint() throws Exception { String testName = testNotificationEndPointPrefix + "CanCreate"; - String testEndPointAddress = "testEndPointAddress"; NotificationEndPointInfo actualNotificationEndPoint = service.create(NotificationEndPoint.create(testName, EndPointType.AzureQueue, testEndPointAddress)); @@ -86,21 +85,21 @@ public void canGetSingleNotificationEndPointById() throws Exception { } @Test - public void canGetSinglePolicyByInvalidId() throws Exception { + public void canGetSingleNotificationEndPointByInvalidId() throws Exception { expectedException.expect(ServiceException.class); expectedException.expect(new ServiceExceptionMatcher(400)); service.get(NotificationEndPoint.get(invalidId)); } @Test - public void canGetSinglePolicyByNonexistId() throws Exception { + public void cannotGetSingleNotificationEndPointByNonexistId() throws Exception { expectedException.expect(ServiceException.class); - expectedException.expect(new ServiceExceptionMatcher(404)); + expectedException.expect(new ServiceExceptionMatcher(400)); service.get(NotificationEndPoint.get(validButNonexistNotificationEndPointId)); } @Test - public void canRetrieveListOfAccessPolicies() throws Exception { + public void canRetrieveListOfNotificationEndPoints() throws Exception { String[] notificationEndPointNames = new String[] { testNotificationEndPointPrefix + "ListOne", testNotificationEndPointPrefix + "ListTwo" }; @@ -172,9 +171,9 @@ public void canDeleteNotificationEndPointByInvalidId() throws Exception { } @Test - public void canDeleteNotificationEndPointByNonexistId() throws Exception { + public void cannotDeleteNotificationEndPointByNonexistId() throws Exception { expectedException.expect(ServiceException.class); - expectedException.expect(new ServiceExceptionMatcher(404)); + expectedException.expect(new ServiceExceptionMatcher(400)); service.delete(NotificationEndPoint.delete(validButNonexistNotificationEndPointId)); } From d303c40d575296eebaf0e60a9e9258865dd56701 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 2 Aug 2013 15:41:22 -0700 Subject: [PATCH 48/57] clean up the documentation for notification end point. --- .../JobNotificationSubscriptionType.java | 26 ++++---- .../content/NotificationEndPointType.java | 66 +++++++++++++++++-- .../implementation/content/ObjectFactory.java | 10 +++ .../models/JobNotificationSubscription.java | 12 +++- .../media/models/NotificationEndPoint.java | 12 ++-- .../services/media/JobIntegrationTest.java | 27 +++++++- 6 files changed, 125 insertions(+), 28 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java index b495684124725..f0a42d681205d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java @@ -21,7 +21,7 @@ /** * This type maps the XML returned in the odata ATOM serialization - * for ErrorDetail entities. + * for job notification subscription. * */ @XmlAccessorType(XmlAccessType.FIELD) @@ -36,20 +36,20 @@ public class JobNotificationSubscriptionType implements MediaServiceDTO { protected int targetJobState; /** - * Gets the code. + * Gets the ID of the notification end point. * - * @return the code + * @return the ID of the notification end point. */ public String getNotificationEndPointId() { return this.notificationEndPointId; } /** - * Sets the code. + * Sets the ID of the notification end point. * - * @param code - * the id to set - * @return the error detail type + * @param notificationEndPointId + * the ID of the notification end point to set + * @return the job notification subscription type */ public JobNotificationSubscriptionType setNotificationEndPointId(String notificationEndPointId) { this.notificationEndPointId = notificationEndPointId; @@ -57,20 +57,20 @@ public JobNotificationSubscriptionType setNotificationEndPointId(String notifica } /** - * Gets the message. + * Gets the target job state. * - * @return the message + * @return an integer representing the target job state. */ public int getTargetJobState() { return targetJobState; } /** - * Sets the message. + * Sets the target job state. * - * @param message - * the message to set - * @return the error detail type + * @param targetJobState + * the target job state + * @return the target job state */ public JobNotificationSubscriptionType setTargetJobState(int targetJobState) { this.targetJobState = targetJobState; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java index 57a6f4e461826..836e31d053628 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java @@ -23,28 +23,36 @@ import javax.xml.bind.annotation.XmlRootElement; /** - * This type maps the URI. + * The type of notification end point. * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "NotificationEndPointType", namespace = Constants.ODATA_DATA_NS) public class NotificationEndPointType implements MediaServiceDTO { + + /** The id. */ @XmlElement(name = "Id", namespace = Constants.ODATA_DATA_NS) private String id; + /** The name. */ @XmlElement(name = "Name", namespace = Constants.ODATA_DATA_NS) private String name; + /** The created. */ @XmlElement(name = "Created", namespace = Constants.ODATA_DATA_NS) private Date created; + /** The end point type. */ @XmlElement(name = "EndPointType", namespace = Constants.ODATA_DATA_NS) - private int endpointType; + private int endPointType; + /** The end point address. */ @XmlElement(name = "EndPointAddress", namespace = Constants.ODATA_DATA_NS) - private String endpointAddress; + private String endPointAddress; /** + * Gets the id. + * * @return the id. */ public String getId() { @@ -52,9 +60,12 @@ public String getId() { } /** + * Sets the id. + * * @param id * id * the id to set + * @return the notification end point type */ public NotificationEndPointType setId(String id) { this.id = id; @@ -62,6 +73,8 @@ public NotificationEndPointType setId(String id) { } /** + * Gets the name. + * * @return the name. */ public String getName() { @@ -69,39 +82,78 @@ public String getName() { } /** + * Sets the name. + * * @param name * name * the name to set + * @return the notification end point type */ public NotificationEndPointType setName(String name) { this.name = name; return this; } + /** + * Gets the created. + * + * @return the created + */ public Date getCreated() { return this.created; } + /** + * Sets the created. + * + * @param created + * the created + * @return the notification end point type + */ public NotificationEndPointType setCreated(Date created) { this.created = created; return this; } + /** + * Gets the end point type. + * + * @return the end point type + */ public int getEndPointType() { - return this.endpointType; + return this.endPointType; } + /** + * Sets the end point type. + * + * @param endpointType + * the endpoint type + * @return the notification end point type + */ public NotificationEndPointType setEndPointType(int endpointType) { - this.endpointType = endpointType; + this.endPointType = endpointType; return this; } + /** + * Gets the end point address. + * + * @return the end point address + */ public String getEndPointAddress() { - return this.endpointAddress; + return this.endPointAddress; } + /** + * Sets the end point address. + * + * @param endpointAddress + * the endpoint address + * @return the notification end point type + */ public NotificationEndPointType setEndPointAddress(String endpointAddress) { - this.endpointAddress = endpointAddress; + this.endPointAddress = endpointAddress; return this; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java index bc605637adfb1..ae260c170fb33 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java @@ -122,10 +122,20 @@ public RebindContentKeyType createRebindContentKeyType() { return new RebindContentKeyType(); } + /** + * Creates an instance of (@link JobNotificationSubscriptionType). + * + * @return the job notification subscription type. + */ public JobNotificationSubscriptionType createJobNotificationSubscriptionType() { return new JobNotificationSubscriptionType(); } + /** + * Creates an instance of (@link NotificationEndPointType). + * + * @return the notification end point type. + */ public NotificationEndPointType createNotificationEndPointType() { return new NotificationEndPointType(); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java index 2c67d246373bc..ad436cac7b236 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java @@ -16,14 +16,24 @@ package com.microsoft.windowsazure.services.media.models; /** - * The Class TaskHistoricalEvent. + * The Class JobNotificationSubscription. */ public class JobNotificationSubscription { + /** The notification end point id. */ private final String notificationEndPointId; + /** The target job state. */ private final JobState targetJobState; + /** + * Instantiates a new job notification subscription. + * + * @param notificationEndPointId + * the notification end point id + * @param targetJobState + * the target job state + */ public JobNotificationSubscription(String notificationEndPointId, JobState targetJobState) { this.notificationEndPointId = notificationEndPointId; this.targetJobState = targetJobState; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java index d8812377732da..b671d009f414d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java @@ -40,11 +40,11 @@ private NotificationEndPoint() { * Creates an operation to create a new notification end point. * * @param name - * name of the notification end point - * @param durationInMinutes - * how long the notification end point will be in force - * @param permissions - * permissions allowed by this notification end point + * name of the notification end point. + * @param endPointType + * the type of the notification end point. + * @param endPointAddress + * the address of the end point. * @return The operation */ public static EntityCreateOperation create(String name, EndPointType endPointType, @@ -98,7 +98,7 @@ public static EntityGetOperation get(LinkInfo queueList = listQueueResult.getQueues(); + for (Queue queue : queueList) { + if (queue.getName().equals(queueName)) { + endPointAddress = queue.getUrl(); + } + } + + service.create(NotificationEndPoint.create(notificationEndPointName, EndPointType.AzureQueue, queueName)); + ListResult listNotificationEndPointInfos = service.list(NotificationEndPoint.list()); + String notificationEndPointId = null; + + for (NotificationEndPointInfo notificationEndPointInfo : listNotificationEndPointInfos) { + if (notificationEndPointInfo.getName().equals(notificationEndPointName)) { + notificationEndPointId = notificationEndPointInfo.getId(); + } + } // Act JobInfo actualJob = service.create( Job.create().setName(name).setPriority(priority).addInputMediaAsset(assetInfo.getId()) .addTaskCreator(getTaskCreator(0))).addJobNotificationSubscription( - getJobNotificationSubscription(queueName, JobState.Canceled)); + getJobNotificationSubscription(notificationEndPointId, JobState.Canceled)); // Assert verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, From 3e5d2d262c16f2ba2c2454e4e8f33c53efa9a21c Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 6 Aug 2013 10:26:52 -0700 Subject: [PATCH 49/57] get integration test for job notification for media services working. --- .../services/media/IntegrationTestBase.java | 14 +++++++++++--- .../services/media/JobIntegrationTest.java | 10 ---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java index ee0b8d347780e..c64c90dd6fe8e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java @@ -86,9 +86,9 @@ public static void setup() throws Exception { overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_SECRET); overrideWithEnv(config, MediaConfiguration.OAUTH_SCOPE); - overrideWithEnv(config, QueueConfiguration.ACCOUNT_KEY); - overrideWithEnv(config, QueueConfiguration.ACCOUNT_NAME); - overrideWithEnv(config, QueueConfiguration.URI); + overrideWithEnv(config, QueueConfiguration.ACCOUNT_KEY, "media.queue.account.key"); + overrideWithEnv(config, QueueConfiguration.ACCOUNT_NAME, "media.queue.account.name"); + overrideWithEnv(config, QueueConfiguration.URI, "media.queue.uri"); service = MediaService.create(config); queueService = QueueService.create(config); @@ -104,6 +104,14 @@ protected static void overrideWithEnv(Configuration config, String key) { config.setProperty(key, value); } + protected static void overrideWithEnv(Configuration config, String key, String enviromentKey) { + String value = System.getenv(enviromentKey); + if (value == null) + return; + + config.setProperty(key, value); + } + @AfterClass public static void cleanup() throws Exception { cleanupEnvironment(); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java index e27b274d6b8a0..3fe587a966b8a 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java @@ -42,8 +42,6 @@ import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation; import com.microsoft.windowsazure.services.media.models.TaskHistoricalEvent; import com.microsoft.windowsazure.services.media.models.TaskInfo; -import com.microsoft.windowsazure.services.queue.models.ListQueuesResult; -import com.microsoft.windowsazure.services.queue.models.ListQueuesResult.Queue; import com.microsoft.windowsazure.services.queue.models.PeekMessagesResult.QueueMessage; public class JobIntegrationTest extends IntegrationTestBase { @@ -142,15 +140,7 @@ public void createJobWithNotificationSuccess() throws ServiceException { Date endTime = null; queueService.createQueue(queueName); - String endPointAddress = null; String notificationEndPointName = UUID.randomUUID().toString(); - ListQueuesResult listQueueResult = queueService.listQueues(); - List queueList = listQueueResult.getQueues(); - for (Queue queue : queueList) { - if (queue.getName().equals(queueName)) { - endPointAddress = queue.getUrl(); - } - } service.create(NotificationEndPoint.create(notificationEndPointName, EndPointType.AzureQueue, queueName)); ListResult listNotificationEndPointInfos = service.list(NotificationEndPoint.list()); From 52a661046e5f5f45395ff8f37adf295202c6428d Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 8 Aug 2013 14:16:55 -0700 Subject: [PATCH 50/57] add more unit tests for media service job notification. --- .../JobNotificationSubscriptionType.java | 4 +- .../media/implementation/content/JobType.java | 20 ++- .../services/media/models/Job.java | 40 +++++- .../services/media/models/JobInfo.java | 17 +++ .../models/JobNotificationSubscription.java | 5 +- ...obNotificationSubscriptionListFactory.java | 42 ++++++ .../media/models/NotificationEndPoint.java | 50 ++++++- .../services/media/JobIntegrationTest.java | 17 ++- .../services/media/models/JobInfoTest.java | 24 ++++ .../NotificationEndPointEntityTest.java | 135 ++++++++++++++++++ .../models/NotificationEndPointInfoTest.java | 122 ++++++++++++++++ 11 files changed, 461 insertions(+), 15 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscriptionListFactory.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointEntityTest.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfoTest.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java index f0a42d681205d..d6f42ecae21e7 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java @@ -27,11 +27,11 @@ @XmlAccessorType(XmlAccessType.FIELD) public class JobNotificationSubscriptionType implements MediaServiceDTO { - /** The message. */ + /** The ID of the notification end point. */ @XmlElement(name = "NotificationEndPointId", namespace = Constants.ODATA_DATA_NS) protected String notificationEndPointId; - /** The time stamp. */ + /** The target state of the job. */ @XmlElement(name = "TargetJobState", namespace = Constants.ODATA_DATA_NS) protected int targetJobState; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java index f42832ab288ee..2536907575886 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java @@ -15,6 +15,7 @@ package com.microsoft.windowsazure.services.media.implementation.content; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -35,10 +36,10 @@ public class JobType implements MediaServiceDTO { @XmlElement(name = "Id", namespace = Constants.ODATA_DATA_NS) protected String id; - /** The job notification subscriptions */ + /** The job notification subscriptions. */ @XmlElementWrapper(name = "JobNotificationSubscriptions", namespace = Constants.ODATA_DATA_NS) @XmlElement(name = "element", namespace = Constants.ODATA_DATA_NS) - protected List jobNotificationSubscriptions; + protected List jobNotificationSubscriptions = new ArrayList(); /** The name. */ @XmlElement(name = "Name", namespace = Constants.ODATA_DATA_NS) @@ -90,6 +91,7 @@ public String getId() { * * @param id * the new id + * @return the job type */ public JobType setId(String id) { this.id = id; @@ -110,6 +112,7 @@ public String getName() { * * @param name * the new name + * @return the job type */ public JobType setName(String name) { this.name = name; @@ -130,6 +133,7 @@ public Date getCreated() { * * @param created * the new created + * @return the job type */ public JobType setCreated(Date created) { this.created = created; @@ -150,6 +154,7 @@ public Date getLastModified() { * * @param lastModified * the new last modified + * @return the job type */ public JobType setLastModified(Date lastModified) { this.lastModified = lastModified; @@ -170,6 +175,7 @@ public Date getEndTime() { * * @param endTime * the new end time + * @return the job type */ public JobType setEndTime(Date endTime) { this.endTime = endTime; @@ -190,6 +196,7 @@ public Integer getPriority() { * * @param priority * the new priority + * @return the job type */ public JobType setPriority(Integer priority) { this.priority = priority; @@ -210,6 +217,7 @@ public Double getRunningDuration() { * * @param runningDuration * the new running duration + * @return the job type */ public JobType setRunningDuration(Double runningDuration) { this.runningDuration = runningDuration; @@ -230,6 +238,7 @@ public Date getStartTime() { * * @param startTime * the new start time + * @return the job type */ public JobType setStartTime(Date startTime) { this.startTime = startTime; @@ -250,6 +259,7 @@ public Integer getState() { * * @param state * the new state + * @return the job type */ public JobType setState(Integer state) { this.state = state; @@ -270,12 +280,18 @@ public String getTemplateId() { * * @param templateId * the new template id + * @return the job type */ public JobType setTemplateId(String templateId) { this.templateId = templateId; return this; } + /** + * Gets the job notification subscriptions. + * + * @return the job notification subscriptions + */ public List getJobNotificationSubscriptions() { return this.jobNotificationSubscriptions; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java index ca7bf086105ad..cf3063371424a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java @@ -38,6 +38,7 @@ import com.microsoft.windowsazure.services.media.entityoperations.EntityGetOperation; import com.microsoft.windowsazure.services.media.entityoperations.EntityOperationSingleResultBase; import com.microsoft.windowsazure.services.media.implementation.MediaBatchOperations; +import com.microsoft.windowsazure.services.media.implementation.content.JobNotificationSubscriptionType; import com.microsoft.windowsazure.services.media.implementation.content.JobType; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.GenericType; @@ -97,11 +98,14 @@ public static class Creator extends EntityOperationSingleResultBase imp /** The media batch operations. */ private MediaBatchOperations mediaBatchOperations; + /** The job notification subscriptions. */ + private final List jobNotificationSubscriptions = new ArrayList(); + /** * Builds the mime multipart. * - * @throws ServiceException - * the service exception + * @param serviceUri + * the service uri */ private void buildMimeMultipart(URI serviceUri) { mediaBatchOperations = null; @@ -298,6 +302,28 @@ public MediaType getContentType() { public String getUri() { return "$batch"; } + + /** + * Adds the job notification subscription. + * + * @param jobNotificationSubscription + * the job notification subscription + * @return the creator + */ + public Creator addJobNotificationSubscription(JobNotificationSubscription jobNotificationSubscription) { + this.jobNotificationSubscriptions.add(jobNotificationSubscription); + this.fresh = true; + return this; + } + + /** + * Gets the job notification subscription. + * + * @return the job notification subscription + */ + public List getJobNotificationSubscription() { + return this.jobNotificationSubscriptions; + } } /** @@ -325,6 +351,8 @@ public CreateBatchOperation(URI serviceUri) { /** * Creates the. * + * @param serviceUri + * the service uri * @param creator * the creator * @return the creates the batch operation @@ -335,6 +363,14 @@ public static CreateBatchOperation create(URI serviceUri, Creator creator) { JobType jobType = new JobType(); jobType.setName(creator.getName()); jobType.setPriority(creator.getPriority()); + for (JobNotificationSubscription jobNotificationSubscription : creator.getJobNotificationSubscription()) { + JobNotificationSubscriptionType jobNotificationSubscriptionType = new JobNotificationSubscriptionType(); + jobNotificationSubscriptionType.setNotificationEndPointId(jobNotificationSubscription + .getNotificationEndPointId()); + jobNotificationSubscriptionType.setTargetJobState(jobNotificationSubscription.getTargetJobState() + .getCode()); + jobType.getJobNotificationSubscriptions().add(jobNotificationSubscriptionType); + } for (String inputMediaAsset : creator.getInputMediaAssets()) { createBatchOperation.addLink("InputMediaAssets", String.format("%s/Assets('%s')", createBatchOperation diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java index 6ce8eac170708..2a6c39fcde5d9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java @@ -16,6 +16,7 @@ package com.microsoft.windowsazure.services.media.models; import java.util.Date; +import java.util.List; import com.microsoft.windowsazure.services.media.implementation.ODataEntity; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; @@ -156,6 +157,22 @@ public LinkInfo getTasksLink() { return this. getRelationLink("Tasks"); } + /** + * Gets the job notification subscriptions. + * + * @return the job notification subscriptions + */ + public List getJobNotificationSubscriptions() { + return JobNotificationSubscriptionListFactory.create(getContent().getJobNotificationSubscriptions()); + } + + /** + * Adds the job notification subscription. + * + * @param jobNotificationSubscription + * the job notification subscription + * @return the job info + */ public JobInfo addJobNotificationSubscription(JobNotificationSubscription jobNotificationSubscription) { getContent().getJobNotificationSubscriptions().add( new JobNotificationSubscriptionType().setNotificationEndPointId( diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java index ad436cac7b236..f98e45e7e009d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java @@ -15,6 +15,7 @@ package com.microsoft.windowsazure.services.media.models; + /** * The Class JobNotificationSubscription. */ @@ -29,7 +30,7 @@ public class JobNotificationSubscription { /** * Instantiates a new job notification subscription. * - * @param notificationEndPointId + * @param uuid * the notification end point id * @param targetJobState * the target job state @@ -40,7 +41,7 @@ public JobNotificationSubscription(String notificationEndPointId, JobState targe } /** - * Gets the code. + * Gets the notification end point. * * @return the code */ diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscriptionListFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscriptionListFactory.java new file mode 100644 index 0000000000000..49159441efcd2 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscriptionListFactory.java @@ -0,0 +1,42 @@ +/* + * 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.media.models; + +import java.util.ArrayList; +import java.util.List; + +import com.microsoft.windowsazure.services.media.implementation.content.JobNotificationSubscriptionType; + +/** + * The Class JobNotificationSubscription factory. + */ +public class JobNotificationSubscriptionListFactory { + + public static List create( + List jobNotificationSubscriptionTypeList) { + if (jobNotificationSubscriptionTypeList == null) { + throw new IllegalArgumentException("The jobNotificationSubscriptionTypeList cannot be null."); + } + List jobNotificationSubscriptionList = new ArrayList(); + for (JobNotificationSubscriptionType jobNotificationSubscriptionType : jobNotificationSubscriptionTypeList) { + jobNotificationSubscriptionList.add(new JobNotificationSubscription(jobNotificationSubscriptionType + .getNotificationEndPointId(), + JobState.fromCode(jobNotificationSubscriptionType.getTargetJobState()))); + } + return jobNotificationSubscriptionList; + + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java index b671d009f414d..123e4c2255b4d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java @@ -21,7 +21,9 @@ import com.microsoft.windowsazure.services.media.entityoperations.EntityCreateOperation; import com.microsoft.windowsazure.services.media.entityoperations.EntityDeleteOperation; import com.microsoft.windowsazure.services.media.entityoperations.EntityGetOperation; +import com.microsoft.windowsazure.services.media.entityoperations.EntityOperationBase; import com.microsoft.windowsazure.services.media.entityoperations.EntityOperationSingleResultBase; +import com.microsoft.windowsazure.services.media.entityoperations.EntityUpdateOperation; import com.microsoft.windowsazure.services.media.implementation.content.NotificationEndPointType; import com.sun.jersey.api.client.GenericType; @@ -52,7 +54,7 @@ public static EntityCreateOperation create(String name return new Creator(name, endPointType, endPointAddress); } - private static class Creator extends EntityOperationSingleResultBase implements + public static class Creator extends EntityOperationSingleResultBase implements EntityCreateOperation { private final String name; private final EndPointType endPointType; @@ -108,6 +110,10 @@ public static DefaultListOperation list() { }); } + public static Updater update(String notificationEndPointId) { + return new Updater(notificationEndPointId); + } + /** * Create an operation to delete the given notification end point * @@ -118,4 +124,46 @@ public static DefaultListOperation list() { public static EntityDeleteOperation delete(String notificationEndPointId) { return new DefaultDeleteOperation(ENTITY_SET, notificationEndPointId); } + + /** + * The Class Updater. + */ + public static class Updater extends EntityOperationBase implements EntityUpdateOperation { + + /** The name. */ + private String name; + + /** + * Instantiates a new updater. + * + * @param notificationEndPointId + * the asset id + */ + protected Updater(String notificationEndPointId) { + super(new EntityOperationBase.EntityIdUriBuilder(ENTITY_SET, notificationEndPointId)); + } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.entityoperations.EntityUpdateOperation#getRequestContents() + */ + @Override + public Object getRequestContents() { + NotificationEndPointType notificationEndPointType = new NotificationEndPointType(); + notificationEndPointType.setName(name); + return notificationEndPointType; + } + + /** + * Sets new name for asset. + * + * @param name + * The new name + * @return Updater instance + */ + public Updater setName(String name) { + this.name = name; + return this; + } + } + } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java index 3fe587a966b8a..25e71d0eaf1da 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java @@ -31,6 +31,7 @@ import com.microsoft.windowsazure.services.media.models.EndPointType; import com.microsoft.windowsazure.services.media.models.ErrorDetail; import com.microsoft.windowsazure.services.media.models.Job; +import com.microsoft.windowsazure.services.media.models.Job.Creator; import com.microsoft.windowsazure.services.media.models.JobInfo; import com.microsoft.windowsazure.services.media.models.JobNotificationSubscription; import com.microsoft.windowsazure.services.media.models.JobState; @@ -80,8 +81,9 @@ private void verifyJobProperties(String message, String testName, Integer priori } } - private JobNotificationSubscription getJobNotificationSubscription(String id, JobState targetJobState) { - return new JobNotificationSubscription(id, targetJobState); + private JobNotificationSubscription getJobNotificationSubscription(String jobNotificationSubscriptionId, + JobState targetJobState) { + return new JobNotificationSubscription(jobNotificationSubscriptionId, targetJobState); } private JobInfo createJob(String name) throws ServiceException { @@ -152,11 +154,14 @@ public void createJobWithNotificationSuccess() throws ServiceException { } } + JobNotificationSubscription jobNotificationSubcription = getJobNotificationSubscription(notificationEndPointId, + JobState.Canceled); + + Creator creator = Job.create().setName(name).setPriority(priority).addInputMediaAsset(assetInfo.getId()) + .addTaskCreator(getTaskCreator(0)).addJobNotificationSubscription(jobNotificationSubcription); + // Act - JobInfo actualJob = service.create( - Job.create().setName(name).setPriority(priority).addInputMediaAsset(assetInfo.getId()) - .addTaskCreator(getTaskCreator(0))).addJobNotificationSubscription( - getJobNotificationSubscription(notificationEndPointId, JobState.Canceled)); + JobInfo actualJob = service.create(creator); // Assert verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java index 6ed12b3649d51..24397f5ac8645 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java @@ -20,6 +20,7 @@ import org.junit.Test; +import com.microsoft.windowsazure.services.media.implementation.content.JobNotificationSubscriptionType; import com.microsoft.windowsazure.services.media.implementation.content.JobType; public class JobInfoTest { @@ -131,4 +132,27 @@ public void testGetSetState() { assertEquals(expectedJobState, actualJobState); } + @Test + public void testGetSetNotificationEndPoint() { + // Arrange + String expectedNotificationEndPointId = "testNotificationEndPointId"; + JobNotificationSubscription expectedJobNotificationSubscription = new JobNotificationSubscription( + expectedNotificationEndPointId, JobState.Canceled); + JobNotificationSubscriptionType expectedJobNotificationSubscriptionType = new JobNotificationSubscriptionType(); + JobType expectedJobType = new JobType(); + expectedJobType.getJobNotificationSubscriptions().add( + expectedJobNotificationSubscriptionType.setNotificationEndPointId(expectedNotificationEndPointId) + .setTargetJobState(JobState.Canceled.getCode())); + JobInfo jobInfo = new JobInfo(null, expectedJobType); + + // Act + JobNotificationSubscription actualJobNotificationSubscription = jobInfo.getJobNotificationSubscriptions() + .get(0); + + // Assert + assertEquals(expectedJobNotificationSubscription.getNotificationEndPointId(), + actualJobNotificationSubscription.getNotificationEndPointId()); + assertEquals(expectedJobNotificationSubscription.getTargetJobState(), + actualJobNotificationSubscription.getTargetJobState()); + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointEntityTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointEntityTest.java new file mode 100644 index 0000000000000..a1b2b0c094181 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointEntityTest.java @@ -0,0 +1,135 @@ +/** + * 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.media.models; + +import static org.junit.Assert.*; + +import java.net.URLEncoder; + +import org.junit.Test; + +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.media.entityoperations.EntityDeleteOperation; +import com.microsoft.windowsazure.services.media.entityoperations.EntityGetOperation; +import com.microsoft.windowsazure.services.media.entityoperations.EntityListOperation; +import com.microsoft.windowsazure.services.media.entityoperations.EntityUpdateOperation; +import com.microsoft.windowsazure.services.media.implementation.content.NotificationEndPointType; +import com.microsoft.windowsazure.services.media.models.NotificationEndPoint.Creator; + +/** + * Tests for the methods and factories of the NotificationEndPoint entity. + */ +public class NotificationEndPointEntityTest { + static final String sampleNotificationEndPointId = "nb:cid:UUID:1151b8bd-9ada-4e7f-9787-8dfa49968eab"; + private final String expectedUri = String.format("NotificationEndPoints('%s')", + URLEncoder.encode(sampleNotificationEndPointId, "UTF-8")); + private final String testNotificationEndPoint = "testNotificationEndPoint"; + private final String testQueueName = "testqueue"; + + public NotificationEndPointEntityTest() throws Exception { + } + + @Test + public void NotificationEndPointCreateReturnsDefaultCreatePayload() throws ServiceException { + NotificationEndPointType payload = (NotificationEndPointType) NotificationEndPoint.create( + testNotificationEndPoint, EndPointType.AzureQueue, testQueueName).getRequestContents(); + + assertNotNull(payload); + assertNull(payload.getId()); + assertNull(payload.getCreated()); + assertNotNull(payload.getName()); + assertNotNull(payload.getEndPointAddress()); + assertNotNull(payload.getEndPointType()); + } + + @Test + public void NotificationEndPointCreateCanSetNotificationEndPointName() { + String name = "NotificationEndPointCreateCanSetNotificationEndPointName"; + + NotificationEndPoint.Creator creator = (Creator) NotificationEndPoint.create(name, EndPointType.AzureQueue, + testQueueName); + + NotificationEndPointType payload = (NotificationEndPointType) creator.getRequestContents(); + + assertNotNull(payload); + assertNull(payload.getId()); + assertNull(payload.getCreated()); + assertEquals(name, payload.getName()); + } + + @Test + public void NotificationEndPointGetReturnsExpectedUri() throws Exception { + String expectedUri = String.format("NotificationEndPoints('%s')", + URLEncoder.encode(sampleNotificationEndPointId, "UTF-8")); + + EntityGetOperation getter = NotificationEndPoint.get(sampleNotificationEndPointId); + + assertEquals(expectedUri, getter.getUri()); + } + + @Test + public void NotificationEndPointListReturnsExpectedUri() { + EntityListOperation lister = NotificationEndPoint.list(); + + assertEquals("NotificationEndPoints", lister.getUri()); + assertNotNull(lister.getQueryParameters()); + assertEquals(0, lister.getQueryParameters().size()); + } + + @Test + public void NotificationEndPointListCanTakeQueryParameters() { + EntityListOperation lister = NotificationEndPoint.list().setTop(10).setSkip(2); + + assertEquals("10", lister.getQueryParameters().getFirst("$top")); + assertEquals("2", lister.getQueryParameters().getFirst("$skip")); + assertEquals(2, lister.getQueryParameters().size()); + } + + @Test + public void NotificationEndPointListCanTakeQueryParametersChained() { + EntityListOperation lister = NotificationEndPoint.list().setTop(10).setSkip(2) + .set("filter", "something"); + + assertEquals("10", lister.getQueryParameters().getFirst("$top")); + assertEquals("2", lister.getQueryParameters().getFirst("$skip")); + assertEquals("something", lister.getQueryParameters().getFirst("filter")); + assertEquals(3, lister.getQueryParameters().size()); + } + + @Test + public void NotificationEndPointUpdateReturnsExpectedUri() throws Exception { + EntityUpdateOperation updater = NotificationEndPoint.update(sampleNotificationEndPointId); + assertEquals(expectedUri, updater.getUri()); + } + + @Test + public void NotificationEndPointUpdateCanSetNameAndAltId() throws Exception { + + String expectedName = "newNotificationEndPointName"; + + EntityUpdateOperation updater = NotificationEndPoint.update(sampleNotificationEndPointId).setName(expectedName); + + NotificationEndPointType payload = (NotificationEndPointType) updater.getRequestContents(); + + assertEquals(expectedName, payload.getName()); + } + + @Test + public void NotificationEndPointDeleteReturnsExpectedUri() throws Exception { + EntityDeleteOperation deleter = NotificationEndPoint.delete(sampleNotificationEndPointId); + assertEquals(expectedUri, deleter.getUri()); + } +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfoTest.java new file mode 100644 index 0000000000000..9a2799b3676bf --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfoTest.java @@ -0,0 +1,122 @@ +/** + * 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.media.models; + +import static org.junit.Assert.*; + +import java.util.Date; + +import org.junit.Test; + +import com.microsoft.windowsazure.services.media.implementation.content.AssetType; + +public class NotificationEndPointInfoTest { + + @Test + public void testGetSetId() { + // Arrange + String expectedId = "expectedId"; + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setId(expectedId)); + + // Act + String actualId = assetInfo.getId(); + + // Assert + assertEquals(expectedId, actualId); + + } + + @Test + public void testGetSetState() { + // Arrange + AssetState expectedState = AssetState.Published; + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setState(expectedState.getCode())); + + // Act + AssetState actualState = assetInfo.getState(); + + // Assert + assertEquals(expectedState, actualState); + } + + @Test + public void testGetSetCreated() throws Exception { + // Arrange + Date expectedCreated = new Date(); + + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setCreated(expectedCreated)); + + // Act + Date actualCreated = assetInfo.getCreated(); + + // Assert + assertEquals(expectedCreated, actualCreated); + + } + + @Test + public void testGetSetLastModified() throws Exception { + // Arrange + Date expectedLastModified = new Date(); + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setLastModified(expectedLastModified)); + + // Act + Date actualLastModified = assetInfo.getLastModified(); + + // Assert + assertEquals(expectedLastModified, actualLastModified); + } + + @Test + public void testGetSetAlternateId() { + // Arrange + String expectedAlternateId = "testAlternateId"; + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setAlternateId(expectedAlternateId)); + + // Act + String actualAlternateId = assetInfo.getAlternateId(); + + // Assert + assertEquals(expectedAlternateId, actualAlternateId); + } + + @Test + public void testGetSetName() { + // Arrange + String expectedName = "testName"; + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setName(expectedName)); + + // Act + String actualName = assetInfo.getName(); + + // Assert + assertEquals(expectedName, actualName); + } + + @Test + public void testGetSetOptions() { + // Arrange + + AssetOption expectedOptions = AssetOption.None; + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setOptions(expectedOptions.getCode())); + + // Act + AssetOption actualOptions = assetInfo.getOptions(); + + // Assert + assertEquals(expectedOptions, actualOptions); + } + +} From 398ad13b664f54457b378a547c330af706dd2879 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 8 Aug 2013 14:43:33 -0700 Subject: [PATCH 51/57] fix broken unit tests. --- .../media/implementation/content/JobType.java | 21 ++++++++++++++++--- .../services/media/models/Job.java | 2 +- .../services/media/models/JobInfo.java | 4 ++-- .../services/media/models/JobInfoTest.java | 6 +++--- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java index 2536907575886..9c3dede3da4e2 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java @@ -39,7 +39,7 @@ public class JobType implements MediaServiceDTO { /** The job notification subscriptions. */ @XmlElementWrapper(name = "JobNotificationSubscriptions", namespace = Constants.ODATA_DATA_NS) @XmlElement(name = "element", namespace = Constants.ODATA_DATA_NS) - protected List jobNotificationSubscriptions = new ArrayList(); + protected List jobNotificationSubscriptionTypes; /** The name. */ @XmlElement(name = "Name", namespace = Constants.ODATA_DATA_NS) @@ -292,8 +292,23 @@ public JobType setTemplateId(String templateId) { * * @return the job notification subscriptions */ - public List getJobNotificationSubscriptions() { - return this.jobNotificationSubscriptions; + public List getJobNotificationSubscriptionTypes() { + return this.jobNotificationSubscriptionTypes; + } + + /** + * Adds the job notification subscription type. + * + * @param jobNotificationSubscription + * the job notification subscription + * @return the job type + */ + public JobType addJobNotificationSubscriptionType(JobNotificationSubscriptionType jobNotificationSubscription) { + if (this.jobNotificationSubscriptionTypes == null) { + this.jobNotificationSubscriptionTypes = new ArrayList(); + } + this.jobNotificationSubscriptionTypes.add(jobNotificationSubscription); + return this; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java index cf3063371424a..6103da02d6def 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java @@ -369,7 +369,7 @@ public static CreateBatchOperation create(URI serviceUri, Creator creator) { .getNotificationEndPointId()); jobNotificationSubscriptionType.setTargetJobState(jobNotificationSubscription.getTargetJobState() .getCode()); - jobType.getJobNotificationSubscriptions().add(jobNotificationSubscriptionType); + jobType.addJobNotificationSubscriptionType(jobNotificationSubscriptionType); } for (String inputMediaAsset : creator.getInputMediaAssets()) { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java index 2a6c39fcde5d9..d6bb193f1a279 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java @@ -163,7 +163,7 @@ public LinkInfo getTasksLink() { * @return the job notification subscriptions */ public List getJobNotificationSubscriptions() { - return JobNotificationSubscriptionListFactory.create(getContent().getJobNotificationSubscriptions()); + return JobNotificationSubscriptionListFactory.create(getContent().getJobNotificationSubscriptionTypes()); } /** @@ -174,7 +174,7 @@ public List getJobNotificationSubscriptions() { * @return the job info */ public JobInfo addJobNotificationSubscription(JobNotificationSubscription jobNotificationSubscription) { - getContent().getJobNotificationSubscriptions().add( + getContent().addJobNotificationSubscriptionType( new JobNotificationSubscriptionType().setNotificationEndPointId( jobNotificationSubscription.getNotificationEndPointId()).setTargetJobState( jobNotificationSubscription.getTargetJobState().getCode())); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java index 24397f5ac8645..ce5146ab8a1e4 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java @@ -140,9 +140,9 @@ public void testGetSetNotificationEndPoint() { expectedNotificationEndPointId, JobState.Canceled); JobNotificationSubscriptionType expectedJobNotificationSubscriptionType = new JobNotificationSubscriptionType(); JobType expectedJobType = new JobType(); - expectedJobType.getJobNotificationSubscriptions().add( - expectedJobNotificationSubscriptionType.setNotificationEndPointId(expectedNotificationEndPointId) - .setTargetJobState(JobState.Canceled.getCode())); + expectedJobType.addJobNotificationSubscriptionType(expectedJobNotificationSubscriptionType + .setNotificationEndPointId(expectedNotificationEndPointId).setTargetJobState( + JobState.Canceled.getCode())); JobInfo jobInfo = new JobInfo(null, expectedJobType); // Act From 7ccebab97967fbf87d0b4a57bd993d11128c1ba1 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 8 Aug 2013 16:11:46 -0700 Subject: [PATCH 52/57] design change of the option classes for service management. --- .../management/ManagementContract.java | 35 ++-------- .../ManagementExceptionProcessor.java | 33 +++------- .../implementation/ManagementRestProxy.java | 31 ++++----- .../models/CreateAffinityGroupOptions.java | 65 +++++++++++++++++++ .../models/UpdateAffinityGroupOptions.java | 15 +++++ .../management/ManagementIntegrationTest.java | 31 +++++---- 6 files changed, 121 insertions(+), 89 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java index b6fbe24720319..febe9e49fff11 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -32,23 +32,6 @@ */ public interface ManagementContract extends FilterableService { - /** - * Creates a affinity group. - * - * @param name - * The name of the affinity group. - * @param label - * The label of the affinity group. - * @param location - * The geographic location of the affinity group. - * - * @return A CreateAffinityGroupResult instance containing the result of the create affinity group - * request. - * @throws ServiceException - * the service exception - */ - CreateAffinityGroupResult createAffinityGroup(String name, String label, String location) throws ServiceException; - /** * Gets the information of an affinity group. * @@ -63,20 +46,14 @@ public interface ManagementContract extends FilterableServiceCreateAffinityGroupResult instance which contains the information of the affinity group. * @throws ServiceException * the service exception */ - CreateAffinityGroupResult createAffinityGroup(String name, String label, String location, - CreateAffinityGroupOptions createAffinityGroupOptions) throws ServiceException; + CreateAffinityGroupResult createAffinityGroup(CreateAffinityGroupOptions createAffinityGroupOptions) + throws ServiceException; /** * Delete affinity group. @@ -103,10 +80,6 @@ CreateAffinityGroupResult createAffinityGroup(String name, String label, String /** * Update affinity group. * - * @param name - * The name of the affinity group. - * @param label - * The label of the affinity group. * @param updateAffinityGroupOptions * The options to update the affinity group. * @return A UpdateAffinityGroupResult class instance which contains the result of update affinity @@ -115,7 +88,7 @@ CreateAffinityGroupResult createAffinityGroup(String name, String label, String * @throws ServiceException * the service exception */ - UpdateAffinityGroupResult updateAffinityGroup(String name, String label, - UpdateAffinityGroupOptions updateAffinityGroupOptions) throws ServiceException; + UpdateAffinityGroupResult updateAffinityGroup(UpdateAffinityGroupOptions updateAffinityGroupOptions) + throws ServiceException; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java index b073a8ebf3504..ef82bc576ddab 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java @@ -102,23 +102,6 @@ public ListResult listAffinityGroups() throws ServiceExceptio } } - /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public CreateAffinityGroupResult createAffinityGroup(String name, String label, String location) - throws ServiceException { - try { - return next.createAffinityGroup(name, label, location); - } - catch (UniformInterfaceException e) { - throw processCatch(new ServiceException(e)); - } - catch (ClientHandlerException e) { - throw processCatch(new ServiceException(e)); - } - } - /* (non-Javadoc) * @see com.microsoft.windowsazure.services.management.ManagementContract#getAffinityGroup(java.lang.String) */ @@ -152,13 +135,13 @@ public DeleteAffinityGroupResult deleteAffinityGroup(String name) throws Service } /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(java.lang.String, java.lang.String, java.lang.String, com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions) + * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions) */ @Override - public CreateAffinityGroupResult createAffinityGroup(String name, String label, String location, - CreateAffinityGroupOptions createAffinityGroupOptions) throws ServiceException { + public CreateAffinityGroupResult createAffinityGroup(CreateAffinityGroupOptions createAffinityGroupOptions) + throws ServiceException { try { - return next.createAffinityGroup(name, label, location, createAffinityGroupOptions); + return next.createAffinityGroup(createAffinityGroupOptions); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -169,13 +152,13 @@ public CreateAffinityGroupResult createAffinityGroup(String name, String label, } /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.management.ManagementContract#updateAffinityGroup(java.lang.String, java.lang.String, com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions) + * @see com.microsoft.windowsazure.services.management.ManagementContract#updateAffinityGroup(com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions) */ @Override - public UpdateAffinityGroupResult updateAffinityGroup(String name, String label, - UpdateAffinityGroupOptions updateAffinityGroupOptions) throws ServiceException { + public UpdateAffinityGroupResult updateAffinityGroup(UpdateAffinityGroupOptions updateAffinityGroupOptions) + throws ServiceException { try { - return next.updateAffinityGroup(name, label, updateAffinityGroupOptions); + return next.updateAffinityGroup(updateAffinityGroupOptions); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java index e1f5fa9686f79..21349275cb11e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -183,24 +183,15 @@ public ListResult listAffinityGroups() { } /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(java.lang.String, java.lang.String, java.lang.String) + * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions) */ @Override - public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, String label, String location) { - return createAffinityGroup(affinityGroupName, label, location, null); - } - - /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(java.lang.String, java.lang.String, java.lang.String, com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions) - */ - @Override - public CreateAffinityGroupResult createAffinityGroup(String affinityGroupName, String label, String location, - CreateAffinityGroupOptions createAffinityGroupOptions) { + public CreateAffinityGroupResult createAffinityGroup(CreateAffinityGroupOptions createAffinityGroupOptions) { CreateAffinityGroup createAffinityGroup = new CreateAffinityGroup(); - createAffinityGroup.setName(affinityGroupName); - createAffinityGroup.setLabel(label); - createAffinityGroup.setLocation(location); + createAffinityGroup.setName(createAffinityGroupOptions.getName()); + createAffinityGroup.setLabel(createAffinityGroupOptions.getLabel()); + createAffinityGroup.setLocation(createAffinityGroupOptions.getLocation()); if (createAffinityGroupOptions != null) { createAffinityGroup.setDescription(createAffinityGroupOptions.getDescription()); } @@ -247,18 +238,18 @@ public DeleteAffinityGroupResult deleteAffinityGroup(String name) { } /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.management.ManagementContract#updateAffinityGroup(java.lang.String, java.lang.String, com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions) + * @see com.microsoft.windowsazure.services.management.ManagementContract#updateAffinityGroup(com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions) */ @Override - public UpdateAffinityGroupResult updateAffinityGroup(String name, String label, - UpdateAffinityGroupOptions updateAffinityGroupOptions) { + public UpdateAffinityGroupResult updateAffinityGroup(UpdateAffinityGroupOptions updateAffinityGroupOptions) { UpdateAffinityGroup updateAffinityGroup = new UpdateAffinityGroup(); - updateAffinityGroup.setLabel(label); + updateAffinityGroup.setLabel(updateAffinityGroupOptions.getLabel()); if (updateAffinityGroupOptions != null) { updateAffinityGroup.setDescription(updateAffinityGroupOptions.getDescription()); } - ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups").path(name) - .header("x-ms-version", "2011-02-25").put(ClientResponse.class, updateAffinityGroup); + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") + .path(updateAffinityGroupOptions.getName()).header("x-ms-version", "2011-02-25") + .put(ClientResponse.class, updateAffinityGroup); PipelineHelpers.ThrowIfError(clientResponse); UpdateAffinityGroupResult updateAffinityGroupResult = new UpdateAffinityGroupResult(clientResponse.getStatus(), getRequestId(clientResponse)); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java index f90720e7fb68d..ec8c91aa320e6 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java @@ -21,15 +21,80 @@ */ public class CreateAffinityGroupOptions { + /** The descrption. */ private String descrption; + /** The name. */ + private final String name; + + /** The label. */ + private final String label; + + /** The location. */ + private final String location; + + /** + * Instantiates a new creates the affinity group options. + * + * @param name + * the name + * @param label + * the label + * @param location + * the location + */ + public CreateAffinityGroupOptions(String name, String label, String location) { + this.name = name; + this.label = label; + this.location = location; + } + + /** + * Sets the description. + * + * @param description + * the description + * @return the creates the affinity group options + */ public CreateAffinityGroupOptions setDescription(String description) { this.descrption = description; return this; } + /** + * Gets the description. + * + * @return the description + */ public String getDescription() { return this.descrption; } + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Gets the label. + * + * @return the label + */ + public String getLabel() { + return this.label; + } + + /** + * Gets the location. + * + * @return the location + */ + public String getLocation() { + return this.location; + } + } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java index bf2c0ef1906ce..27bcd82890c38 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java @@ -22,6 +22,13 @@ public class UpdateAffinityGroupOptions { private String description; + private final String name; + private final String label; + + public UpdateAffinityGroupOptions(String name, String label) { + this.name = name; + this.label = label; + } public UpdateAffinityGroupOptions setDescription(String description) { this.description = description; @@ -32,4 +39,12 @@ public String getDescription() { return this.description; } + public String getName() { + return this.name; + } + + public String getLabel() { + return this.label; + } + } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java index 244a93859e142..0900786b8cd48 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -36,10 +36,11 @@ public void createAffinityGroupSuccess() throws Exception { String expectedAffinityGroupName = "testCreateAffinityGroupSuccess"; String expectedLabel = Base64.encode("testCreateAffinityGroupSuccess".getBytes("UTF-8")); String expectedLocation = "West US"; + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions( + expectedAffinityGroupName, expectedLabel, expectedLocation); // Act - CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(expectedAffinityGroupName, - expectedLabel, expectedLocation); + CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(createAffinityGroupOptions); AffinityGroupInfo affinityGroupInfo = service.getAffinityGroup(expectedAffinityGroupName).getValue(); @@ -61,12 +62,11 @@ public void createAffinityGroupWithOptionalParametersSuccess() throws Exception String expectedLabel = Base64.encode("testCreateAffinityGroupWithOptionalParameterSuccess".getBytes("UTF-8")); String expectedLocation = "West US"; String expectedDescription = "testCreateAffinityGroupWithOptionalParameterSuccessDescription"; - CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions() - .setDescription(expectedDescription); + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions( + expectedAffinityGroupName, expectedLabel, expectedLocation).setDescription(expectedDescription); // Act - CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(expectedAffinityGroupName, - expectedLabel, expectedLocation, createAffinityGroupOptions); + CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(createAffinityGroupOptions); // Assert AffinityGroupInfo actualAffinityGroupInfo = service.getAffinityGroup(expectedAffinityGroupName).getValue(); @@ -96,7 +96,9 @@ public void deleteAffinityGroupSuccess() throws ServiceException, Exception { String affinityGroupName = "testDeleteAffinityGroupSuccess"; String label = Base64.encode("testDeleteAffinityGroupSuccesslabel".getBytes("UTF-8")); String location = "West US"; - service.createAffinityGroup(affinityGroupName, label, location); + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions(affinityGroupName, + label, location); + service.createAffinityGroup(createAffinityGroupOptions); // Act service.deleteAffinityGroup(affinityGroupName); @@ -112,13 +114,14 @@ public void updateAffinityGroupSuccess() throws Exception { String expectedAffinityGroupLabel = Base64.encode("testUpdateAffinityGroupSuccess".getBytes("UTF-8")); String expectedLocation = "West US"; String expectedDescription = "updateAffinityGroupSuccess"; - service.createAffinityGroup(expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); - UpdateAffinityGroupOptions updateAffinityGroupOptions = new UpdateAffinityGroupOptions() - .setDescription(expectedDescription); + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions( + expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); + service.createAffinityGroup(createAffinityGroupOptions); + UpdateAffinityGroupOptions updateAffinityGroupOptions = new UpdateAffinityGroupOptions( + expectedAffinityGroupName, expectedAffinityGroupLabel).setDescription(expectedDescription); // Act - UpdateAffinityGroupResult updateAffinityGroupResult = service.updateAffinityGroup(expectedAffinityGroupName, - expectedAffinityGroupLabel, updateAffinityGroupOptions); + UpdateAffinityGroupResult updateAffinityGroupResult = service.updateAffinityGroup(updateAffinityGroupOptions); // Assert assertNotNull(updateAffinityGroupResult.getRegion()); @@ -133,7 +136,9 @@ public void getAffinityGroupPropertiesSuccess() throws Exception { String expectedAffinityGroupName = "testGetAffinityGroupPropertiesSuccess"; String expectedAffinityGroupLabel = Base64.encode("testGetAffinityGroupPropertiesSuccess".getBytes("UTF-8")); String expectedLocation = "West US"; - service.createAffinityGroup(expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions( + expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); + service.createAffinityGroup(createAffinityGroupOptions); // Act GetAffinityGroupResult getAffinityGroupResult = service.getAffinityGroup(expectedAffinityGroupName); From efeabd414a0091675afafce4c2e307baebfec745 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Mon, 12 Aug 2013 10:12:07 -0700 Subject: [PATCH 53/57] let all the unit tests passed. --- .../implementation/MediaBatchOperations.java | 2 +- .../models/JobNotificationSubscription.java | 7 +- ...obNotificationSubscriptionListFactory.java | 4 +- .../services/media/models/TargetJobState.java | 74 +++++++++++++++++++ .../services/media/JobIntegrationTest.java | 5 +- .../services/media/models/JobInfoTest.java | 2 +- 6 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TargetJobState.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaBatchOperations.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaBatchOperations.java index f3798aed41e2b..b7e99a44e1012 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaBatchOperations.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaBatchOperations.java @@ -277,7 +277,7 @@ private DataSource createBatchCreateEntityPart(String verb, String entityName, E headers.addHeader("Content-ID", Integer.toString(contentId)); headers.addHeader("Content-Type", "application/atom+xml;type=entry"); headers.addHeader("Content-Length", Integer.toString(bytes.length)); - headers.addHeader("DataServiceVersion", "1.0;NetFx"); + headers.addHeader("DataServiceVersion", "3.0;NetFx"); headers.addHeader("MaxDataServiceVersion", "3.0;NetFx"); // adds body diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java index f98e45e7e009d..6cd4ea59e3011 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java @@ -15,7 +15,6 @@ package com.microsoft.windowsazure.services.media.models; - /** * The Class JobNotificationSubscription. */ @@ -25,7 +24,7 @@ public class JobNotificationSubscription { private final String notificationEndPointId; /** The target job state. */ - private final JobState targetJobState; + private final TargetJobState targetJobState; /** * Instantiates a new job notification subscription. @@ -35,7 +34,7 @@ public class JobNotificationSubscription { * @param targetJobState * the target job state */ - public JobNotificationSubscription(String notificationEndPointId, JobState targetJobState) { + public JobNotificationSubscription(String notificationEndPointId, TargetJobState targetJobState) { this.notificationEndPointId = notificationEndPointId; this.targetJobState = targetJobState; } @@ -54,7 +53,7 @@ public String getNotificationEndPointId() { * * @return the message */ - public JobState getTargetJobState() { + public TargetJobState getTargetJobState() { return this.targetJobState; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscriptionListFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscriptionListFactory.java index 49159441efcd2..4d9b132a8b30c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscriptionListFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscriptionListFactory.java @@ -33,8 +33,8 @@ public static List create( List jobNotificationSubscriptionList = new ArrayList(); for (JobNotificationSubscriptionType jobNotificationSubscriptionType : jobNotificationSubscriptionTypeList) { jobNotificationSubscriptionList.add(new JobNotificationSubscription(jobNotificationSubscriptionType - .getNotificationEndPointId(), - JobState.fromCode(jobNotificationSubscriptionType.getTargetJobState()))); + .getNotificationEndPointId(), TargetJobState.fromCode(jobNotificationSubscriptionType + .getTargetJobState()))); } return jobNotificationSubscriptionList; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TargetJobState.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TargetJobState.java new file mode 100644 index 0000000000000..edfc3099d43f4 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TargetJobState.java @@ -0,0 +1,74 @@ +/** + * 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.media.models; + +import java.security.InvalidParameterException; + +/** + * The Enum TargetJobState. + */ +public enum TargetJobState { + /** None. */ + None(0), + + /** FinalStatesOnly. */ + FinalStatesOnly(1), + + /** All. */ + All(2); + + /** The target job state code. */ + private int targetJobStateCode; + + /** + * Instantiates a new job state. + * + * @param targetJobStateCode + * the job state code + */ + private TargetJobState(int targetJobStateCode) { + this.targetJobStateCode = targetJobStateCode; + } + + /** + * Gets the code. + * + * @return the code + */ + public int getCode() { + return this.targetJobStateCode; + } + + /** + * From code. + * + * @param targetJobStateCode + * the target job state code + * @return the job state + */ + public static TargetJobState fromCode(int targetJobStateCode) { + switch (targetJobStateCode) { + case 0: + return TargetJobState.None; + case 1: + return TargetJobState.FinalStatesOnly; + case 2: + return TargetJobState.All; + default: + throw new InvalidParameterException("targetJobStateCode"); + } + } +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java index 25e71d0eaf1da..c835af0634cf6 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java @@ -39,6 +39,7 @@ import com.microsoft.windowsazure.services.media.models.ListResult; import com.microsoft.windowsazure.services.media.models.NotificationEndPoint; import com.microsoft.windowsazure.services.media.models.NotificationEndPointInfo; +import com.microsoft.windowsazure.services.media.models.TargetJobState; import com.microsoft.windowsazure.services.media.models.Task; import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation; import com.microsoft.windowsazure.services.media.models.TaskHistoricalEvent; @@ -82,7 +83,7 @@ private void verifyJobProperties(String message, String testName, Integer priori } private JobNotificationSubscription getJobNotificationSubscription(String jobNotificationSubscriptionId, - JobState targetJobState) { + TargetJobState targetJobState) { return new JobNotificationSubscription(jobNotificationSubscriptionId, targetJobState); } @@ -155,7 +156,7 @@ public void createJobWithNotificationSuccess() throws ServiceException { } JobNotificationSubscription jobNotificationSubcription = getJobNotificationSubscription(notificationEndPointId, - JobState.Canceled); + TargetJobState.All); Creator creator = Job.create().setName(name).setPriority(priority).addInputMediaAsset(assetInfo.getId()) .addTaskCreator(getTaskCreator(0)).addJobNotificationSubscription(jobNotificationSubcription); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java index ce5146ab8a1e4..59a5f13f9c506 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java @@ -137,7 +137,7 @@ public void testGetSetNotificationEndPoint() { // Arrange String expectedNotificationEndPointId = "testNotificationEndPointId"; JobNotificationSubscription expectedJobNotificationSubscription = new JobNotificationSubscription( - expectedNotificationEndPointId, JobState.Canceled); + expectedNotificationEndPointId, TargetJobState.All); JobNotificationSubscriptionType expectedJobNotificationSubscriptionType = new JobNotificationSubscriptionType(); JobType expectedJobType = new JobType(); expectedJobType.addJobNotificationSubscriptionType(expectedJobNotificationSubscriptionType From 35e36bda5f9c95499afc1718e6dc09598fee0581 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 13 Aug 2013 16:11:15 -0700 Subject: [PATCH 54/57] update the unit test for notification end point info according to code review. --- .../models/NotificationEndPointInfoTest.java | 73 +++++++------------ 1 file changed, 25 insertions(+), 48 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfoTest.java index 9a2799b3676bf..18331b5f38014 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfoTest.java @@ -20,7 +20,7 @@ import org.junit.Test; -import com.microsoft.windowsazure.services.media.implementation.content.AssetType; +import com.microsoft.windowsazure.services.media.implementation.content.NotificationEndPointType; public class NotificationEndPointInfoTest { @@ -28,10 +28,11 @@ public class NotificationEndPointInfoTest { public void testGetSetId() { // Arrange String expectedId = "expectedId"; - AssetInfo assetInfo = new AssetInfo(null, new AssetType().setId(expectedId)); + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setId(expectedId)); // Act - String actualId = assetInfo.getId(); + String actualId = notificationEndPointInfo.getId(); // Assert assertEquals(expectedId, actualId); @@ -39,16 +40,17 @@ public void testGetSetId() { } @Test - public void testGetSetState() { + public void testGetSetName() { // Arrange - AssetState expectedState = AssetState.Published; - AssetInfo assetInfo = new AssetInfo(null, new AssetType().setState(expectedState.getCode())); + String expectedName = "notificationEndPointName"; + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setName(expectedName)); // Act - AssetState actualState = assetInfo.getState(); + String actualName = notificationEndPointInfo.getName(); // Assert - assertEquals(expectedState, actualState); + assertEquals(expectedName, actualName); } @Test @@ -56,10 +58,11 @@ public void testGetSetCreated() throws Exception { // Arrange Date expectedCreated = new Date(); - AssetInfo assetInfo = new AssetInfo(null, new AssetType().setCreated(expectedCreated)); + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setCreated(expectedCreated)); // Act - Date actualCreated = assetInfo.getCreated(); + Date actualCreated = notificationEndPointInfo.getCreated(); // Assert assertEquals(expectedCreated, actualCreated); @@ -67,56 +70,30 @@ public void testGetSetCreated() throws Exception { } @Test - public void testGetSetLastModified() throws Exception { - // Arrange - Date expectedLastModified = new Date(); - AssetInfo assetInfo = new AssetInfo(null, new AssetType().setLastModified(expectedLastModified)); - - // Act - Date actualLastModified = assetInfo.getLastModified(); - - // Assert - assertEquals(expectedLastModified, actualLastModified); - } - - @Test - public void testGetSetAlternateId() { - // Arrange - String expectedAlternateId = "testAlternateId"; - AssetInfo assetInfo = new AssetInfo(null, new AssetType().setAlternateId(expectedAlternateId)); - - // Act - String actualAlternateId = assetInfo.getAlternateId(); - - // Assert - assertEquals(expectedAlternateId, actualAlternateId); - } - - @Test - public void testGetSetName() { + public void testGetSetEndPointType() throws Exception { // Arrange - String expectedName = "testName"; - AssetInfo assetInfo = new AssetInfo(null, new AssetType().setName(expectedName)); + EndPointType expectedEndPointType = EndPointType.AzureQueue; + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setEndPointType(expectedEndPointType.getCode())); // Act - String actualName = assetInfo.getName(); + EndPointType actualEndPointType = notificationEndPointInfo.getEndPointType(); // Assert - assertEquals(expectedName, actualName); + assertEquals(expectedEndPointType, actualEndPointType); } @Test - public void testGetSetOptions() { + public void testGetSetEndPointAddress() { // Arrange - - AssetOption expectedOptions = AssetOption.None; - AssetInfo assetInfo = new AssetInfo(null, new AssetType().setOptions(expectedOptions.getCode())); + String expectedEndPointAddress = "testGetSetEndPointAddress"; + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setEndPointAddress(expectedEndPointAddress)); // Act - AssetOption actualOptions = assetInfo.getOptions(); + String actualEndPointAddress = notificationEndPointInfo.getEndPointAddress(); // Assert - assertEquals(expectedOptions, actualOptions); + assertEquals(expectedEndPointAddress, actualEndPointAddress); } - } From 85d1211e2858acb882763d25dc5177267e769fe5 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 13 Aug 2013 17:21:45 -0700 Subject: [PATCH 55/57] fix a broken unit test. --- .../windowsazure/services/media/models/JobInfoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java index 59a5f13f9c506..a4e7fd95fe34b 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/JobInfoTest.java @@ -142,7 +142,7 @@ public void testGetSetNotificationEndPoint() { JobType expectedJobType = new JobType(); expectedJobType.addJobNotificationSubscriptionType(expectedJobNotificationSubscriptionType .setNotificationEndPointId(expectedNotificationEndPointId).setTargetJobState( - JobState.Canceled.getCode())); + TargetJobState.All.getCode())); JobInfo jobInfo = new JobInfo(null, expectedJobType); // Act From df0da8b9d67846d49503963fd1ab1e5a8a3fdf47 Mon Sep 17 00:00:00 2001 From: Guang Yang Date: Wed, 21 Aug 2013 17:50:45 -0700 Subject: [PATCH 56/57] update pom, readme and changelog for 0.4.5 --- ChangeLog.txt | 6 +++++- README.md | 5 ++++- microsoft-azure-api/pom.xml | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 18378c9cde813..6d805948bd80e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,9 @@ +2013.08.26 Version 0.4.5 + * Added support for manage affinity groups + * Added support for Media Services job notification + 2013.07.03 Version 0.4.4 - * Windows Azure China environemnt support + * Windows Azure China environment support * Service Bus metadata support updated to the latest version * Rich Odata entity query support for Service Bus Queue/Topic/Subscription * Added support for Service Bus message forwarding diff --git a/README.md b/README.md index 86248e1374fb0..20ebf2a061135 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ This project provides a client library in Java that makes it easy to consume Win * Create/Read/Update/Delete assets * Create/Read/Update/Delete/Rebind content keys * Create/Read/Update/Cancel/Delete jobs + * Add/Get job notifications +* Service Management + * Manage affinity groups * Service Runtime * Retrieve information about the state of your Azure Compute instances @@ -59,7 +62,7 @@ within your project you can also have them installed by the Java package manager com.microsoft.windowsazure microsoft-windowsazure-api - 0.4.4 + 0.4.5 ``` diff --git a/microsoft-azure-api/pom.xml b/microsoft-azure-api/pom.xml index 68a1429e2e6a6..d347b27fb3037 100644 --- a/microsoft-azure-api/pom.xml +++ b/microsoft-azure-api/pom.xml @@ -17,7 +17,7 @@ 4.0.0 com.microsoft.windowsazure microsoft-windowsazure-api - 0.4.4 + 0.4.5 jar Microsoft Windows Azure Client API From bc35502a6986c68bfe4098b95c580c70abd40976 Mon Sep 17 00:00:00 2001 From: Guang Yang Date: Wed, 21 Aug 2013 18:12:40 -0700 Subject: [PATCH 57/57] address code review feedback --- ChangeLog.txt | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 6d805948bd80e..166c01ca6e6f0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,5 @@ 2013.08.26 Version 0.4.5 - * Added support for manage affinity groups + * Added support for managing affinity groups * Added support for Media Services job notification 2013.07.03 Version 0.4.4 diff --git a/README.md b/README.md index 20ebf2a061135..93e0046cec226 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ This project provides a client library in Java that makes it easy to consume Win * Create/Read/Update/Delete/Rebind content keys * Create/Read/Update/Cancel/Delete jobs * Add/Get job notifications + * Create/Read/Update/Delete notification endpoints * Service Management * Manage affinity groups * Service Runtime