diff --git a/ChangeLog.txt b/ChangeLog.txt index 18378c9cde813..166c01ca6e6f0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,9 @@ +2013.08.26 Version 0.4.5 + * Added support for managing 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..93e0046cec226 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ 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 + * Create/Read/Update/Delete notification endpoints +* Service Management + * Manage affinity groups * Service Runtime * Retrieve information about the state of your Azure Compute instances @@ -59,7 +63,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 f3199d17474f3..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 @@ -134,7 +134,7 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.1 1.6 1.6 @@ -146,10 +146,38 @@ 0.8.3 + serviceBus + generate-sources + + generate + + + target/generated-sources/xjc + src/main/resources/serviceBus + + servicebus-atom.xsd + + com.microsoft.windowsazure.services.serviceBus.implementation + false + true + + + + management generate-sources generate + + target/generated-sources/xjc + src/main/resources/management/ + + schemas.microsoft.com.windowsazure.xsd + + com.microsoft.windowsazure.services.management.implementation + false + true + 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/core/Builder.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Builder.java index f6a194e3349db..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 @@ -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; @@ -18,14 +18,14 @@ 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 { - T alter(T instance, Builder builder, Map properties); + T alter(String profile, T instance, Builder builder, Map properties); } public interface Registry { @@ -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 f72f4c935c37e..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 @@ -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; @@ -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() { @@ -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]; + 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) { 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, service, 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,27 +173,35 @@ 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); + 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); - if (alterationList != null) { - for (Alteration alteration : alterationList) { - instance = ((Alteration) alteration).alter(instance, this, properties); + T instance = factory.create(profile, service, 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; } - public void alter(Class service, Alteration alteration) { + @Override + 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>>()); + } + if (!this.alterations.get(service).containsKey(instance)) { + this.alterations.get(service).put(instance, new ArrayList>()); } - this.alterations.get(service).add(alteration); + this.alterations.get(service).get(instance).add(alteration); } } 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/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 new file mode 100644 index 0000000000000..5c562f4ad58bb --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/Exports.java @@ -0,0 +1,104 @@ +/** + * 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 com.microsoft.windowsazure.services.core.utils.ExportUtils.*; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.Map; + +import javax.net.ssl.HostnameVerifier; +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) { + + // provide contract implementation + registry.add(ManagementContract.class, ManagementExceptionProcessor.class); + registry.add(ManagementRestProxy.class); + registry.add(UserAgentFilter.class); + + // alter jersey client config for service management. + registry.alter(ManagementContract.class, ClientConfig.class, new Builder.Alteration() { + + @Override + public ClientConfig alter(String profile, ClientConfig clientConfig, Builder builder, + Map properties) { + + String keyStorePath = (String) getPropertyIfExists(profile, properties, + ManagementConfiguration.KEYSTORE_PATH); + + 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); + } + catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + catch (IOException e) { + throw new RuntimeException(e); + } + + SSLContext sslContext = null; + try { + sslContext = SSLContextFactory.createSSLContext(keyStoreCredential); + } + catch (GeneralSecurityException e) { + throw new RuntimeException(e); + } + 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; + } + }, sslContext)); + return clientConfig; + } + }); + + } +} 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..1adc84750a9f1 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementConfiguration.java @@ -0,0 +1,104 @@ +/** + * 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 management configuration. + * + */ +public class ManagementConfiguration { + + /** + * Defines the path of the keystore. + * + */ + 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 type of the keystore. + */ + public static final String KEYSTORE_TYPE = "management.keystore.type"; + + /** + * Defines the URI of service management. + * + */ + public final static String URI = "management.uri"; + + /** + * Defines the subscription ID of the Windows Azure account. + */ + public static final String SUBSCRIPTION_ID = "management.subscription.id"; + + /** + * Creates a service management configuration using specified URI, and subscription ID. + * + * @param uri + * 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 + * A Configuration object that can be used when creating an instance of the + * 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 parameters. + * + * @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 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 + * ManagementContract class. + */ + public static Configuration configure(String profile, Configuration configuration, String uri, + String subscriptionId, String keyStoreLocation, String keyStorePassword) { + + if (profile == null) { + profile = ""; + } + else if (profile.length() != 0 && !profile.endsWith(".")) { + profile = profile + "."; + } + + 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; + } + +} 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..febe9e49fff11 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementContract.java @@ -0,0 +1,94 @@ +/** + * 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.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; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupResult; + +/** + * + * Defines the service management contract. + * + */ +public interface ManagementContract extends FilterableService { + + /** + * Gets the information of an affinity group. + * + * @param name + * 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 an affinity group. + * + * @param createAffinityGroupOptions + * The options to create an affinity group. + * @return A CreateAffinityGroupResult instance which contains the information of the affinity group. + * @throws ServiceException + * the service exception + */ + CreateAffinityGroupResult createAffinityGroup(CreateAffinityGroupOptions createAffinityGroupOptions) + throws ServiceException; + + /** + * Delete affinity group. + * + * @param name + * The name of the affinity group. + * @return A DeleteAffinityGroupResult instance containing the result of delete affinity group + * operation. + * + * @throws ServiceException + * the service exception + */ + DeleteAffinityGroupResult deleteAffinityGroup(String name) throws ServiceException; + + /** + * List affinity groups. + * + * @return the result of the list affinity group operation. + * @throws ServiceException + * the service exception + */ + ListResult listAffinityGroups() throws ServiceException; + + /** + * Update affinity group. + * + * @param updateAffinityGroupOptions + * 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 + */ + UpdateAffinityGroupResult updateAffinityGroup(UpdateAffinityGroupOptions updateAffinityGroupOptions) + throws ServiceException; + +} 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..5413546069826 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/ManagementService.java @@ -0,0 +1,70 @@ +/** + * 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 management functionality. + * + */ +public class ManagementService { + + private ManagementService() { + // class is not instantiated + } + + /** + * Creates an instance of the ManagementContract API. + * + */ + public static ManagementContract create() { + return Configuration.getInstance().create(ManagementContract.class); + } + + /** + * Creates an instance of the ManagementContract API using the specified configuration. + * + * @param config + * A Configuration object that represents the configuration for the service management. + * + */ + public static ManagementContract create(Configuration config) { + return config.create(ManagementContract.class); + } + + /** + * 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); + } + + /** + * Creates an instance of the ManagementContract API using the specified configuration. + * + * @param config + * A Configuration object that represents the configuration for the service management. + * + */ + 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/KeyStoreCredential.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.java new file mode 100644 index 0000000000000..c58b8d77eb5e1 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreCredential.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.implementation; + +import java.io.IOException; + +/** + * The Class KeyStoreCredential. + */ +public class KeyStoreCredential { + + /** 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 keyStorePath + * the path of the keystore. + * @param keyStorePassword + * the password for the keystore. + * @param keyStoreType + * the type of the keyStore. + * @throws IOException + * when a I/O exception has occurred. + */ + public KeyStoreCredential(String keyStorePath, String keyStorePassword, KeyStoreType keyStoreType) + throws IOException { + this.keystorePassword = keyStorePassword; + this.keyStorePath = keyStorePath; + this.keyStoreType = keyStoreType; + } + + /** + * Gets the type of the key store. + * + * @return A KeyStoreType representing the type of the key store. + */ + public KeyStoreType getKeyStoreType() { + return keyStoreType; + } + + /** + * Gets the keystore password. + * + * @return A String instance representing the password of the keystore. + */ + public String getKeystorePassword() { + return keystorePassword; + } + + /** + * Gets the key store path. + * + * @return the key store path + */ + 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 new file mode 100644 index 0000000000000..ffd178b12687c --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/KeyStoreType.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.implementation; + +/** + * The Enum representing the type of the KeyStore. + */ +public enum KeyStoreType { + + /** The jceks. */ + jceks, + /** The jks. */ + jks, + /** The pkcs12. */ + 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 new file mode 100644 index 0000000000000..ef82bc576ddab --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementExceptionProcessor.java @@ -0,0 +1,171 @@ +/** + * 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.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; +import com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupResult; +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 { + return next.listAffinityGroups(); + } + 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) + */ + @Override + 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)); + } + } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#deleteAffinityGroup(java.lang.String) + */ + @Override + 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)); + } + } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions) + */ + @Override + public CreateAffinityGroupResult createAffinityGroup(CreateAffinityGroupOptions createAffinityGroupOptions) + throws ServiceException { + try { + return next.createAffinityGroup(createAffinityGroupOptions); + } + 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#updateAffinityGroup(com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions) + */ + @Override + public UpdateAffinityGroupResult updateAffinityGroup(UpdateAffinityGroupOptions updateAffinityGroupOptions) + throws ServiceException { + try { + return next.updateAffinityGroup(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 new file mode 100644 index 0000000000000..21349275cb11e --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/ManagementRestProxy.java @@ -0,0 +1,261 @@ +/** + * 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 java.util.List; +import java.util.UUID; + +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.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; +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; +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; + +/** + * 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 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 userAgentFilter + * the user agent filter + */ + @Inject + public ManagementRestProxy(Client channel, @Named(ManagementConfiguration.URI) String uri, + @Named(ManagementConfiguration.SUBSCRIPTION_ID) String subscriptionId, UserAgentFilter userAgentFilter) { + + this.channel = channel; + this.filters = new ServiceFilter[0]; + this.uri = uri; + this.subscriptionId = subscriptionId; + this.channel.addFilter(userAgentFilter); + } + + /** + * 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) { + this.channel = channel; + this.filters = serviceFilter; + this.uri = uri; + this.subscriptionId = subscriptionId; + } + + /** + * 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) { + resource.addFilter(new ClientFilterAdapter(filter)); + } + 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); + newFilters[filters.length] = filter; + return new ManagementRestProxy(channel, newFilters, uri, subscriptionId); + } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#listAffinityGroups() + */ + @Override + public ListResult listAffinityGroups() { + ClientResponse clientResponse = getResource().path(subscriptionId).path("affinitygroups") + .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); + List affinityGroupInfoList = AffinityGroupInfoListFactory.getItem(affinityGroups); + return new ListResult(clientResponse.getStatus(), requestId, affinityGroupInfoList); + } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#createAffinityGroup(com.microsoft.windowsazure.services.management.models.CreateAffinityGroupOptions) + */ + @Override + public CreateAffinityGroupResult createAffinityGroup(CreateAffinityGroupOptions createAffinityGroupOptions) { + + CreateAffinityGroup createAffinityGroup = new CreateAffinityGroup(); + createAffinityGroup.setName(createAffinityGroupOptions.getName()); + createAffinityGroup.setLabel(createAffinityGroupOptions.getLabel()); + createAffinityGroup.setLocation(createAffinityGroupOptions.getLocation()); + if (createAffinityGroupOptions != null) { + 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()) + .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; + } + + /* (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) + .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; + } + + /* (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) + .header("x-ms-version", "2013-03-01").delete(ClientResponse.class); + PipelineHelpers.ThrowIfError(clientResponse); + DeleteAffinityGroupResult deleteAffinityGroupResult = new DeleteAffinityGroupResult(clientResponse.getStatus(), + getRequestId(clientResponse)); + return deleteAffinityGroupResult; + } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.management.ManagementContract#updateAffinityGroup(com.microsoft.windowsazure.services.management.models.UpdateAffinityGroupOptions) + */ + @Override + public UpdateAffinityGroupResult updateAffinityGroup(UpdateAffinityGroupOptions updateAffinityGroupOptions) { + UpdateAffinityGroup updateAffinityGroup = new UpdateAffinityGroup(); + updateAffinityGroup.setLabel(updateAffinityGroupOptions.getLabel()); + if (updateAffinityGroupOptions != null) { + updateAffinityGroup.setDescription(updateAffinityGroupOptions.getDescription()); + } + 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)); + 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/implementation/SSLContextFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java new file mode 100644 index 0000000000000..e19d2f291f7f7 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/implementation/SSLContextFactory.java @@ -0,0 +1,116 @@ +/** + * 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.FileInputStream; +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 instance. + */ +public class SSLContextFactory { + + /** + * Creates a SSLContext with specified keystore credential. + * + * @param keyStoreCredential + * the credential of the keystore. + * @return a SSLContext instance. + * @throws GeneralSecurityException + * the general security exception + * @throws IOException + * 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.getKeyStorePath(), keyStoreCredential.getKeystorePassword(), + keyStoreCredential.getKeyStoreType()); + } + + /** + * Creates a SSLContext object with specified keystore stream and password. + * + * @param keyStorePath + * the path of the keystore. + * @param keyStorePassword + * the password of the keystore. + * @param keyStoreType + * 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(String keyStorePath, String keyStorePassword, KeyStoreType keyStoreType) + throws GeneralSecurityException, IOException { + + 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"); + } + + 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; + } + + /** + * Gets the key managers. + * + * @param keyStoreStream + * the key store stream + * @param keyStorePassword + * the key stream password + * @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 keyStoreInputStream, String keyStorePassword, + KeyStoreType keyStoreType) throws IOException, GeneralSecurityException { + + KeyStore keyStore = KeyStore.getInstance(keyStoreType.name()); + keyStore.load(keyStoreInputStream, keyStorePassword.toCharArray()); + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + + return keyManagerFactory.getKeyManagers(); + } + +} \ No newline at end of file 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..58698b4ce6865 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfo.java @@ -0,0 +1,120 @@ +/** + * 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 { + + /** 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 new file mode 100644 index 0000000000000..65f9d39a95c51 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoFactory.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 com.microsoft.windowsazure.services.management.implementation.AffinityGroup; + +/** + * A factory for creating AffinityGroupInfo objects. + */ +public class AffinityGroupInfoFactory { + + /** + * Gets an affinity group info instance with specified affinity group. + * + * @param affinityGroup + * the affinity group + * @return A AffinityGroupInfo instance. + */ + public static AffinityGroupInfo getItem(AffinityGroup affinityGroup) { + 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/AffinityGroupInfoListFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoListFactory.java new file mode 100644 index 0000000000000..6f131867b8465 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/AffinityGroupInfoListFactory.java @@ -0,0 +1,46 @@ +/** + * Copyright Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.windowsazure.services.management.models; + +import java.util.ArrayList; +import java.util.List; + +import com.microsoft.windowsazure.services.management.implementation.AffinityGroup; +import com.microsoft.windowsazure.services.management.implementation.AffinityGroups; + +/** + * 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(); + 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/models/CreateAffinityGroupOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java new file mode 100644 index 0000000000000..ec8c91aa320e6 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupOptions.java @@ -0,0 +1,100 @@ +/** + * 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 options to create affinity group. + * + */ +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/CreateAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java new file mode 100644 index 0000000000000..33bb8b6640a47 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/CreateAffinityGroupResult.java @@ -0,0 +1,72 @@ +/** + * 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.Date; + +/** + * The base result class for all the result of service management operation. + * + */ +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); + } + + 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 Date getDate() { + return this.date; + } + +} 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..9150ea812c2b9 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/DeleteAffinityGroupResult.java @@ -0,0 +1,34 @@ +/** + * 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 DeleteAffinityGroupResult extends OperationResult { + + public DeleteAffinityGroupResult(int statusCode, String 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/GetAffinityGroupResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java new file mode 100644 index 0000000000000..41b39decb7623 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/GetAffinityGroupResult.java @@ -0,0 +1,40 @@ +/** + * 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 GetAffinityGroupResult extends OperationResult { + + private AffinityGroupInfo value; + + public GetAffinityGroupResult(int statusCode, String requestId) { + super(statusCode, requestId); + } + + public AffinityGroupInfo getValue() { + return value; + } + + public GetAffinityGroupResult setValue(AffinityGroupInfo affinityGroupInfo) { + this.value = affinityGroupInfo; + 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..f0f600740e19e --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/ListResult.java @@ -0,0 +1,153 @@ +/** + * 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 service management. + * + */ +public class ListResult extends OperationResult implements List { + + private final List contents; + + public ListResult(int statusCode, String requestId, Collection contentList) { + super(statusCode, requestId); + 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); + } +} 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..c426891bfd1c0 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/OperationResult.java @@ -0,0 +1,41 @@ +/** + * 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 OperationResult { + + protected final String requestId; + protected final int statusCode; + + public OperationResult(int statusCode, String requestId) { + this.statusCode = statusCode; + this.requestId = requestId; + } + + public int getStatusCode() { + return this.statusCode; + } + + public String getRequestId() { + return this.requestId; + } + +} 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..27bcd82890c38 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupOptions.java @@ -0,0 +1,50 @@ +/** + * 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 { + + 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; + return this; + } + + 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/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..90b60432f9697 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/management/models/UpdateAffinityGroupResult.java @@ -0,0 +1,50 @@ +/** + * 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.Date; + +/** + * The base result class for all the result of service management operation. + * + */ +public class UpdateAffinityGroupResult extends OperationResult { + + private String region; + private Date date; + + public UpdateAffinityGroupResult(int statusCode, String requestId) { + super(statusCode, requestId); + } + + 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/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/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..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,10 +53,11 @@ 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(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/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/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/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/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)); } } } 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/JobNotificationSubscriptionType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobNotificationSubscriptionType.java new file mode 100644 index 0000000000000..d6f42ecae21e7 --- /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 job notification subscription. + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class JobNotificationSubscriptionType implements MediaServiceDTO { + + /** The ID of the notification end point. */ + @XmlElement(name = "NotificationEndPointId", namespace = Constants.ODATA_DATA_NS) + protected String notificationEndPointId; + + /** The target state of the job. */ + @XmlElement(name = "TargetJobState", namespace = Constants.ODATA_DATA_NS) + protected int targetJobState; + + /** + * Gets the ID of the notification end point. + * + * @return the ID of the notification end point. + */ + public String getNotificationEndPointId() { + return this.notificationEndPointId; + } + + /** + * Sets the ID of the notification end point. + * + * @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; + return this; + } + + /** + * Gets the target job state. + * + * @return an integer representing the target job state. + */ + public int getTargetJobState() { + return targetJobState; + } + + /** + * Sets the target job state. + * + * @param targetJobState + * the target job state + * @return the target job state + */ + 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..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 @@ -15,11 +15,14 @@ package com.microsoft.windowsazure.services.media.implementation.content; +import java.util.ArrayList; 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 +36,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 jobNotificationSubscriptionTypes; + /** The name. */ @XmlElement(name = "Name", namespace = Constants.ODATA_DATA_NS) protected String name; @@ -83,6 +91,7 @@ public String getId() { * * @param id * the new id + * @return the job type */ public JobType setId(String id) { this.id = id; @@ -103,6 +112,7 @@ public String getName() { * * @param name * the new name + * @return the job type */ public JobType setName(String name) { this.name = name; @@ -123,6 +133,7 @@ public Date getCreated() { * * @param created * the new created + * @return the job type */ public JobType setCreated(Date created) { this.created = created; @@ -143,6 +154,7 @@ public Date getLastModified() { * * @param lastModified * the new last modified + * @return the job type */ public JobType setLastModified(Date lastModified) { this.lastModified = lastModified; @@ -163,6 +175,7 @@ public Date getEndTime() { * * @param endTime * the new end time + * @return the job type */ public JobType setEndTime(Date endTime) { this.endTime = endTime; @@ -183,6 +196,7 @@ public Integer getPriority() { * * @param priority * the new priority + * @return the job type */ public JobType setPriority(Integer priority) { this.priority = priority; @@ -203,6 +217,7 @@ public Double getRunningDuration() { * * @param runningDuration * the new running duration + * @return the job type */ public JobType setRunningDuration(Double runningDuration) { this.runningDuration = runningDuration; @@ -223,6 +238,7 @@ public Date getStartTime() { * * @param startTime * the new start time + * @return the job type */ public JobType setStartTime(Date startTime) { this.startTime = startTime; @@ -243,6 +259,7 @@ public Integer getState() { * * @param state * the new state + * @return the job type */ public JobType setState(Integer state) { this.state = state; @@ -263,10 +280,35 @@ 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 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/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..836e31d053628 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/NotificationEndPointType.java @@ -0,0 +1,160 @@ +/** + * 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.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * 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; + + /** The end point address. */ + @XmlElement(name = "EndPointAddress", namespace = Constants.ODATA_DATA_NS) + private String endPointAddress; + + /** + * Gets the id. + * + * @return the id. + */ + public String getId() { + return id; + } + + /** + * Sets the id. + * + * @param id + * id + * the id to set + * @return the notification end point type + */ + public NotificationEndPointType setId(String id) { + this.id = id; + return this; + } + + /** + * Gets the name. + * + * @return the name. + */ + public String getName() { + return name; + } + + /** + * 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; + } + + /** + * Sets the end point type. + * + * @param endpointType + * the endpoint type + * @return the notification end point type + */ + public NotificationEndPointType setEndPointType(int endpointType) { + this.endPointType = endpointType; + return this; + } + + /** + * Gets the end point address. + * + * @return the end point address + */ + public String getEndPointAddress() { + 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; + 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 3aa8d5bfbfe95..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 @@ -121,4 +121,22 @@ public AssetFileType createAssetFileType() { 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/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/Job.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java index ca7bf086105ad..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 @@ -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.addJobNotificationSubscriptionType(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 ba723e01f25c5..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 @@ -16,9 +16,11 @@ 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; +import com.microsoft.windowsazure.services.media.implementation.content.JobNotificationSubscriptionType; import com.microsoft.windowsazure.services.media.implementation.content.JobType; /** @@ -154,4 +156,28 @@ public LinkInfo getOutputAssetsLink() { public LinkInfo getTasksLink() { return this. getRelationLink("Tasks"); } + + /** + * Gets the job notification subscriptions. + * + * @return the job notification subscriptions + */ + public List getJobNotificationSubscriptions() { + return JobNotificationSubscriptionListFactory.create(getContent().getJobNotificationSubscriptionTypes()); + } + + /** + * Adds the job notification subscription. + * + * @param jobNotificationSubscription + * the job notification subscription + * @return the job info + */ + public JobInfo addJobNotificationSubscription(JobNotificationSubscription jobNotificationSubscription) { + getContent().addJobNotificationSubscriptionType( + 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..6cd4ea59e3011 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobNotificationSubscription.java @@ -0,0 +1,59 @@ +/* + * 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 JobNotificationSubscription. + */ +public class JobNotificationSubscription { + + /** The notification end point id. */ + private final String notificationEndPointId; + + /** The target job state. */ + private final TargetJobState targetJobState; + + /** + * Instantiates a new job notification subscription. + * + * @param uuid + * the notification end point id + * @param targetJobState + * the target job state + */ + public JobNotificationSubscription(String notificationEndPointId, TargetJobState targetJobState) { + this.notificationEndPointId = notificationEndPointId; + this.targetJobState = targetJobState; + } + + /** + * Gets the notification end point. + * + * @return the code + */ + public String getNotificationEndPointId() { + return this.notificationEndPointId; + } + + /** + * Gets the message. + * + * @return the message + */ + 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 new file mode 100644 index 0000000000000..4d9b132a8b30c --- /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(), TargetJobState.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 new file mode 100644 index 0000000000000..123e4c2255b4d --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPoint.java @@ -0,0 +1,169 @@ +/** + * 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.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; + +/** + * 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 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, + String endPointAddress) { + return new Creator(name, endPointType, endPointAddress); + } + + public 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 notification end point + * + * @param notificationEndPointId + * id of notification end point to retrieve + * @return the operation + */ + public static EntityGetOperation get(String notificationEndPointId) { + return new DefaultGetOperation(ENTITY_SET, notificationEndPointId, + NotificationEndPointInfo.class); + } + + /** + * 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(), NotificationEndPointInfo.class); + } + + /** + * Create an operation that will retrieve all notification end points + * + * @return the operation + */ + public static DefaultListOperation list() { + return new DefaultListOperation(ENTITY_SET, + new GenericType>() { + }); + } + + public static Updater update(String notificationEndPointId) { + return new Updater(notificationEndPointId); + } + + /** + * Create an operation to delete the given notification end point + * + * @param notificationEndPointId + * id of notification end point to delete + * @return the delete operation + */ + 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/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..511b5194a70f3 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfo.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.media.models; + +import java.util.Date; + +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.NotificationEndPointType; + +/** + * Type containing data about notification end points. + * + */ +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, NotificationEndPointType content) { + super(entry, content); + } + + /** + * Get the notification end point id. + * + * @return the id. + */ + public String getId() { + return getContent().getId(); + } + + /** + * Get the name. + * + * @return the name. + */ + public String getName() { + return getContent().getName(); + } + + /** + * Get the creation date. + * + * @return the date. + */ + public Date getCreated() { + return getContent().getCreated(); + } + + /** + * Get the type of the end point. + * + * @return the end point type. + */ + public EndPointType getEndPointType() { + return EndPointType.fromCode(getContent().getEndPointType()); + } + + /** + * Gets the end point address. + * + * @return the end point address + */ + public String getEndPointAddress() { + return getContent().getEndPointAddress(); + } + +} 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/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/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/serviceBus/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/Exports.java index d0466bb31cb75..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,10 +37,11 @@ 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(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/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/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/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/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..6b6f62b30860c 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; @@ -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); 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/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..a09632d1c7725 --- /dev/null +++ b/microsoft-azure-api/src/main/resources/management/schemas.microsoft.com.windowsazure.xsd @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 3befcf2e0bb08..534b69ac71b36 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/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 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 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/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/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/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); 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..c9e6c5787e3b1 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/IntegrationTestBase.java @@ -0,0 +1,112 @@ +/** + * 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 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"); + } + + @Before + public void initialize() throws Exception { + 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(ManagementContract.class, 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(); + } + + 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); + overrideWithEnv(config, ManagementConfiguration.KEYSTORE_TYPE); + + return config; + } + + private static void overrideWithEnv(Configuration config, String key) { + String value = System.getenv(key); + if (value == null) + return; + + config.setProperty(key, value); + } +} 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..0900786b8cd48 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/management/ManagementIntegrationTest.java @@ -0,0 +1,151 @@ +/** + * 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 org.junit.Test; + +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; + +public class ManagementIntegrationTest extends IntegrationTestBase { + + @Test + public void createAffinityGroupSuccess() throws Exception { + // Arrange + 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(createAffinityGroupOptions); + + 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()); + + } + + @Test + public void createAffinityGroupWithOptionalParametersSuccess() throws Exception { + // Arrange + String expectedAffinityGroupName = "testCreateAffinityGroupWithOptionalParametersSuccess"; + String expectedLabel = Base64.encode("testCreateAffinityGroupWithOptionalParameterSuccess".getBytes("UTF-8")); + String expectedLocation = "West US"; + String expectedDescription = "testCreateAffinityGroupWithOptionalParameterSuccessDescription"; + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions( + expectedAffinityGroupName, expectedLabel, expectedLocation).setDescription(expectedDescription); + + // Act + CreateAffinityGroupResult createAffinityGroupResult = service.createAffinityGroup(createAffinityGroupOptions); + + // Assert + AffinityGroupInfo actualAffinityGroupInfo = service.getAffinityGroup(expectedAffinityGroupName).getValue(); + assertNotNull(createAffinityGroupResult.getLocation()); + assertNotNull(createAffinityGroupResult.getRegion()); + assertNotNull(createAffinityGroupResult.getServer()); + assertNotNull(createAffinityGroupResult.getDate()); + assertEquals(expectedDescription, actualAffinityGroupInfo.getDescription()); + + } + + @Test + public void listAffinityGroupsSuccess() throws ServiceException { + // Arrange + + // Act + ListResult listAffinityGroupsResult = service.listAffinityGroups(); + + // Assert + assertNotNull(listAffinityGroupsResult); + + } + + @Test + public void deleteAffinityGroupSuccess() throws ServiceException, Exception { + // Arrange + String affinityGroupName = "testDeleteAffinityGroupSuccess"; + String label = Base64.encode("testDeleteAffinityGroupSuccesslabel".getBytes("UTF-8")); + String location = "West US"; + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions(affinityGroupName, + label, location); + service.createAffinityGroup(createAffinityGroupOptions); + + // Act + service.deleteAffinityGroup(affinityGroupName); + + // Assert + + } + + @Test + public void updateAffinityGroupSuccess() throws Exception { + // Arrange + String expectedAffinityGroupName = "testUpdateAffinityGroupSuccess"; + String expectedAffinityGroupLabel = Base64.encode("testUpdateAffinityGroupSuccess".getBytes("UTF-8")); + String expectedLocation = "West US"; + String expectedDescription = "updateAffinityGroupSuccess"; + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions( + expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); + service.createAffinityGroup(createAffinityGroupOptions); + UpdateAffinityGroupOptions updateAffinityGroupOptions = new UpdateAffinityGroupOptions( + expectedAffinityGroupName, expectedAffinityGroupLabel).setDescription(expectedDescription); + + // Act + UpdateAffinityGroupResult updateAffinityGroupResult = service.updateAffinityGroup(updateAffinityGroupOptions); + + // Assert + assertNotNull(updateAffinityGroupResult.getRegion()); + assertNotNull(updateAffinityGroupResult.getDate()); + assertNotNull(updateAffinityGroupResult.getRequestId()); + + } + + @Test + public void getAffinityGroupPropertiesSuccess() throws Exception { + // Arrange + String expectedAffinityGroupName = "testGetAffinityGroupPropertiesSuccess"; + String expectedAffinityGroupLabel = Base64.encode("testGetAffinityGroupPropertiesSuccess".getBytes("UTF-8")); + String expectedLocation = "West US"; + CreateAffinityGroupOptions createAffinityGroupOptions = new CreateAffinityGroupOptions( + expectedAffinityGroupName, expectedAffinityGroupLabel, expectedLocation); + service.createAffinityGroup(createAffinityGroupOptions); + + // Act + GetAffinityGroupResult getAffinityGroupResult = service.getAffinityGroup(expectedAffinityGroupName); + AffinityGroupInfo affinityGroupInfo = getAffinityGroupResult.getValue(); + + // Assert + assertEquals(expectedAffinityGroupName, affinityGroupInfo.getName()); + } + +} 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..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 @@ -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, "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); cleanupEnvironment(); } @@ -92,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(); @@ -103,6 +123,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..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 @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.UUID; import org.junit.BeforeClass; import org.junit.Test; @@ -27,16 +28,23 @@ import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.media.models.Asset; import com.microsoft.windowsazure.services.media.models.AssetInfo; +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; import com.microsoft.windowsazure.services.media.models.LinkInfo; 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; import com.microsoft.windowsazure.services.media.models.TaskInfo; +import com.microsoft.windowsazure.services.queue.models.PeekMessagesResult.QueueMessage; public class JobIntegrationTest extends IntegrationTestBase { @@ -74,6 +82,11 @@ private void verifyJobProperties(String message, String testName, Integer priori } } + private JobNotificationSubscription getJobNotificationSubscription(String jobNotificationSubscriptionId, + TargetJobState targetJobState) { + return new JobNotificationSubscription(jobNotificationSubscriptionId, targetJobState); + } + private JobInfo createJob(String name) throws ServiceException { return service.create(Job.create().setName(name).setPriority(3).addInputMediaAsset(assetInfo.getId()) .addTaskCreator(getTaskCreator(0))); @@ -115,6 +128,49 @@ 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); + String notificationEndPointName = UUID.randomUUID().toString(); + + 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(); + } + } + + JobNotificationSubscription jobNotificationSubcription = getJobNotificationSubscription(notificationEndPointId, + TargetJobState.All); + + Creator creator = Job.create().setName(name).setPriority(priority).addInputMediaAsset(assetInfo.getId()) + .addTaskCreator(getTaskCreator(0)).addJobNotificationSubscription(jobNotificationSubcription); + + // Act + JobInfo actualJob = service.create(creator); + + // Assert + verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, + endTime, 1, actualJob); + List queueMessages = queueService.peekMessages(queueName).getQueueMessages(); + assertEquals(1, queueMessages.size()); + } + @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..9a27e93e077ab --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/NotificationEndPointIntegrationTest.java @@ -0,0 +1,180 @@ +/** + * 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.List; + +import org.junit.Test; + +import com.microsoft.windowsazure.services.core.ServiceException; +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 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 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"; + + NotificationEndPointInfo actualNotificationEndPoint = service.create(NotificationEndPoint.create(testName, + EndPointType.AzureQueue, testEndPointAddress)); + + verifyNotificationEndPointProperties("notification end point ", testName, EndPointType.AzureQueue, + testEndPointAddress, actualNotificationEndPoint); + } + + @Test + public void canCreateNotificationEndPointWithReadPermissions() throws Exception { + String testName = testNotificationEndPointPrefix + "CanCreate"; + + NotificationEndPointInfo actualNotificationEndPoint = service.create(NotificationEndPoint.create(testName, + EndPointType.AzureQueue, testEndPointAddress)); + + verifyNotificationEndPointProperties("notification end point", testName, EndPointType.AzureQueue, + testEndPointAddress, actualNotificationEndPoint); + } + + @Test + public void canGetSingleNotificationEndPointById() throws Exception { + String expectedName = testNotificationEndPointPrefix + "GetOne"; + NotificationEndPointInfo expectedNotificationEndPointInfo = service.create(NotificationEndPoint.create( + expectedName, EndPointType.AzureQueue, testEndPointAddress)); + + NotificationEndPointInfo actualNotificationEndPointInfo = service.get(NotificationEndPoint + .get(expectedNotificationEndPointInfo.getId())); + + assertEquals(expectedNotificationEndPointInfo.getId(), actualNotificationEndPointInfo.getId()); + verifyNotificationEndPointProperties("notification end point", expectedName, EndPointType.AzureQueue, + testEndPointAddress, actualNotificationEndPointInfo); + } + + @Test + public void canGetSingleNotificationEndPointByInvalidId() throws Exception { + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(400)); + service.get(NotificationEndPoint.get(invalidId)); + } + + @Test + public void cannotGetSingleNotificationEndPointByNonexistId() throws Exception { + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(400)); + service.get(NotificationEndPoint.get(validButNonexistNotificationEndPointId)); + } + + @Test + public void canRetrieveListOfNotificationEndPoints() throws Exception { + 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(NotificationEndPoint.list()); + + verifyListResultContains("listNotificationEndPoints", expectedNotificationEndPoints, actualAccessPolicies, + new ComponentDelegate() { + @Override + public void verifyEquals(String message, Object expected, Object actual) { + verifyNotificationEndPointInfosEqual(message, (NotificationEndPointInfo) expected, + (NotificationEndPointInfo) actual); + } + }); + } + + @Test + 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 actualNotificationEndPointInfos = service.list(NotificationEndPoint.list() + .setTop(2)); + + assertEquals(2, actualNotificationEndPointInfos.size()); + } + + @Test + 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(NotificationEndPoint.delete(notificationEndPointToBeDeleted.getId())); + + listPoliciesResult = service.list(NotificationEndPoint.list()); + assertEquals("listPoliciesResult.size", policyCountBaseline - 1, listPoliciesResult.size()); + + for (NotificationEndPointInfo policy : service.list(NotificationEndPoint.list())) { + assertFalse(notificationEndPointToBeDeleted.getId().equals(policy.getId())); + } + + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(404)); + service.get(NotificationEndPoint.get(notificationEndPointToBeDeleted.getId())); + } + + @Test + public void canDeleteNotificationEndPointByInvalidId() throws Exception { + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(400)); + service.delete(NotificationEndPoint.delete(invalidId)); + } + + @Test + public void cannotDeleteNotificationEndPointByNonexistId() throws Exception { + expectedException.expect(ServiceException.class); + expectedException.expect(new ServiceExceptionMatcher(400)); + service.delete(NotificationEndPoint.delete(validButNonexistNotificationEndPointId)); + } + +} 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..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 @@ -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, TargetJobState.All); + JobNotificationSubscriptionType expectedJobNotificationSubscriptionType = new JobNotificationSubscriptionType(); + JobType expectedJobType = new JobType(); + expectedJobType.addJobNotificationSubscriptionType(expectedJobNotificationSubscriptionType + .setNotificationEndPointId(expectedNotificationEndPointId).setTargetJobState( + TargetJobState.All.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..18331b5f38014 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/NotificationEndPointInfoTest.java @@ -0,0 +1,99 @@ +/** + * 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.NotificationEndPointType; + +public class NotificationEndPointInfoTest { + + @Test + public void testGetSetId() { + // Arrange + String expectedId = "expectedId"; + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setId(expectedId)); + + // Act + String actualId = notificationEndPointInfo.getId(); + + // Assert + assertEquals(expectedId, actualId); + + } + + @Test + public void testGetSetName() { + // Arrange + String expectedName = "notificationEndPointName"; + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setName(expectedName)); + + // Act + String actualName = notificationEndPointInfo.getName(); + + // Assert + assertEquals(expectedName, actualName); + } + + @Test + public void testGetSetCreated() throws Exception { + // Arrange + Date expectedCreated = new Date(); + + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setCreated(expectedCreated)); + + // Act + Date actualCreated = notificationEndPointInfo.getCreated(); + + // Assert + assertEquals(expectedCreated, actualCreated); + + } + + @Test + public void testGetSetEndPointType() throws Exception { + // Arrange + EndPointType expectedEndPointType = EndPointType.AzureQueue; + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setEndPointType(expectedEndPointType.getCode())); + + // Act + EndPointType actualEndPointType = notificationEndPointInfo.getEndPointType(); + + // Assert + assertEquals(expectedEndPointType, actualEndPointType); + } + + @Test + public void testGetSetEndPointAddress() { + // Arrange + String expectedEndPointAddress = "testGetSetEndPointAddress"; + NotificationEndPointInfo notificationEndPointInfo = new NotificationEndPointInfo(null, + new NotificationEndPointType().setEndPointAddress(expectedEndPointAddress)); + + // Act + String actualEndPointAddress = notificationEndPointInfo.getEndPointAddress(); + + // Assert + assertEquals(expectedEndPointAddress, actualEndPointAddress); + } +} 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..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; @@ -59,6 +61,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 +95,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 +138,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 +159,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 +186,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 +199,25 @@ public void createQueueWorks() throws Exception { assertEquals(0, result.getMetadata().size()); } + @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 public void createQueueWithOptionsWorks() throws Exception { // Arrange - Configuration config = createConfiguration(); - QueueContract service = QueueService.create(config); // Act service.createQueue(CREATABLE_QUEUE_2, @@ -227,8 +237,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 +253,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 +287,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 +312,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 +325,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 +334,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 +370,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 +408,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 +441,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 +476,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 +494,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 +515,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 +530,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); 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 bc92439348ea8..4401044999b3d 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 @@ -431,6 +431,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 { 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 391a080279aee..0101756681134 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 @@ -74,9 +82,9 @@ 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(Client instance, Builder builder, Map properties) { + public Client alter(String profile, Client instance, Builder builder, Map properties) { instance.addFilter(new LoggingFilter()); return instance; } @@ -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 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; 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; 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..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,11 @@ 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