From 9fd39e7df2cca0741fd47b77fd703a05ae6725a4 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 18 Mar 2011 17:12:44 -0700 Subject: [PATCH 1/4] updated savvis to latest test case --- .../savvis/vpdc/compute/SymphonyVPDCComputeServiceLiveTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCComputeServiceLiveTest.java b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCComputeServiceLiveTest.java index f269cb8723..b3ee5db239 100644 --- a/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCComputeServiceLiveTest.java +++ b/sandbox-providers/savvis-symphony-vpdc/src/test/java/org/jclouds/savvis/vpdc/compute/SymphonyVPDCComputeServiceLiveTest.java @@ -40,7 +40,7 @@ public class SymphonyVPDCComputeServiceLiveTest extends BaseComputeServiceLiveTe } @Override - protected Properties getRestProperties() { + protected Properties setupRestProperties() { // TODO remove these lines when this is registered under jclouds-core/rest.properties Properties restProperties = new Properties(); restProperties.setProperty("savvis-symphony-vpdc.contextbuilder", SymphonyVPDCContextBuilder.class.getName()); From 0e18bbeba5f0bf3a072cae88e053a8f0addd37f9 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 18 Mar 2011 17:42:21 -0700 Subject: [PATCH 2/4] ec2 amzn linux now out of beta --- .../jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java index 1aebbc681b..afc232ca5a 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2TemplateBuilderLiveTest.java @@ -116,7 +116,7 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { Template defaultTemplate = context.getComputeService().templateBuilder().build(); assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "2010.11.1-beta"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "2011.02.1"); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); From 743b94c76782dfa416ec786f87f9037896580b9a Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 18 Mar 2011 17:49:20 -0700 Subject: [PATCH 3/4] restructured softlayer into separate feature classes --- core/src/main/resources/rest.properties | 3 + .../softlayer/SoftLayerAsyncClient.java | 39 ++------ .../jclouds/softlayer/SoftLayerClient.java | 22 ++--- .../softlayer/SoftLayerContextBuilder.java | 2 +- .../config/SoftLayerRestClientModule.java | 12 ++- .../features/VirtualGuestAsyncClient.java | 68 +++++++++++++ .../features/VirtualGuestClient.java | 53 +++++++++++ .../softlayer/SoftLayerAsyncClientTest.java | 89 +++++------------ .../BaseSoftLayerAsyncClientTest.java | 51 ++++++++++ .../features/BaseSoftLayerClientLiveTest.java | 70 ++++++++++++++ .../features/VirtualGuestAsyncClientTest.java | 95 +++++++++++++++++++ .../VirtualGuestClientLiveTest.java} | 38 ++------ 12 files changed, 395 insertions(+), 147 deletions(-) create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java create mode 100644 sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java create mode 100644 sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java create mode 100644 sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java rename sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/{SoftLayerClientLiveTest.java => features/VirtualGuestClientLiveTest.java} (62%) diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index 5730204d1f..d3c5a8770a 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -154,6 +154,9 @@ swift.propertiesbuilder=org.jclouds.openstack.swift.SwiftPropertiesBuilder cloudstack.contextbuilder=org.jclouds.cloudstack.CloudStackContextBuilder cloudstack.propertiesbuilder=org.jclouds.cloudstack.CloudStackPropertiesBuilder +softlayer.contextbuilder=org.jclouds.softlayer.SoftLayerContextBuilder +softlayer.propertiesbuilder=org.jclouds.softlayer.SoftLayerPropertiesBuilder + cloudfiles-us.contextbuilder=org.jclouds.cloudfiles.CloudFilesContextBuilder cloudfiles-us.propertiesbuilder=org.jclouds.rackspace.cloudfiles.CloudFilesUSPropertiesBuilder diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java index 0205a16710..bc72b03220 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2011 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,22 +19,8 @@ package org.jclouds.softlayer; -import java.util.Set; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.MediaType; - -import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.rest.annotations.ExceptionParser; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.softlayer.domain.VirtualGuest; - -import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.softlayer.features.VirtualGuestAsyncClient; /** * Provides asynchronous access to SoftLayer via their REST API. @@ -44,25 +30,12 @@ import com.google.common.util.concurrent.ListenableFuture; * @see * @author Adrian Cole */ -@RequestFilters(BasicAuthentication.class) -@Path("/v{jclouds.api-version}") public interface SoftLayerAsyncClient { /** - * @see SoftLayerClient#listVirtualGuests + * Provides asynchronous access to VirtualGuest features. */ - @GET - @Path("/SoftLayer_Account/VirtualGuests.json") - @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture> listVirtualGuests(); + @Delegate + VirtualGuestAsyncClient getVirtualGuestClient(); - /** - * @see SoftLayerClient#getVirtualGuest - */ - @GET - @Path("/SoftLayer_Virtual_Guest/{id}.json") - @Consumes(MediaType.APPLICATION_JSON) - @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture getVirtualGuest(@PathParam("id") long id); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java index 46f5fafa02..faea8510cf 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2011 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,11 +19,11 @@ package org.jclouds.softlayer; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.softlayer.domain.VirtualGuest; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.softlayer.features.VirtualGuestClient; /** * Provides synchronous access to SoftLayer. @@ -33,21 +33,13 @@ import org.jclouds.softlayer.domain.VirtualGuest; * @see * @author Adrian Cole */ -@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS) +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) public interface SoftLayerClient { /** - * - * @return an account's associated virtual guest objects. + * Provides synchronous access to VirtualGuest features. */ - Set listVirtualGuests(); - - /** - * - * @param id - * id of the virtual guest - * @return virtual guest or null if not found - */ - VirtualGuest getVirtualGuest(long id); + @Delegate + VirtualGuestClient getVirtualGuestClient(); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java index e97f4914ba..7d38d7e7a3 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerContextBuilder.java @@ -22,8 +22,8 @@ package org.jclouds.softlayer; import java.util.List; import java.util.Properties; -import org.jclouds.softlayer.config.SoftLayerRestClientModule; import org.jclouds.rest.RestContextBuilder; +import org.jclouds.softlayer.config.SoftLayerRestClientModule; import com.google.inject.Module; diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java index 0de8505212..2cd212b771 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java @@ -19,6 +19,8 @@ package org.jclouds.softlayer.config; +import java.util.Map; + import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.RequiresHttp; @@ -32,8 +34,12 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; import org.jclouds.softlayer.SoftLayerAsyncClient; import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.softlayer.features.VirtualGuestAsyncClient; +import org.jclouds.softlayer.features.VirtualGuestClient; import org.jclouds.softlayer.handlers.SoftLayerErrorHandler; +import com.google.common.collect.ImmutableMap; + /** * Configures the SoftLayer connection. * @@ -43,8 +49,12 @@ import org.jclouds.softlayer.handlers.SoftLayerErrorHandler; @ConfiguresRestClient public class SoftLayerRestClientModule extends RestClientModule { + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// + .put(VirtualGuestClient.class, VirtualGuestAsyncClient.class)// + .build(); + public SoftLayerRestClientModule() { - super(SoftLayerClient.class, SoftLayerAsyncClient.class); + super(SoftLayerClient.class, SoftLayerAsyncClient.class, DELEGATE_MAP); } @Override diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java new file mode 100644 index 0000000000..cd2ffaef62 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java @@ -0,0 +1,68 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.softlayer.features; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.softlayer.domain.VirtualGuest; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to VirtualGuest via their REST API. + *

+ * + * @see VirtualGuestClient + * @see + * @author Adrian Cole + */ +@RequestFilters(BasicAuthentication.class) +@Path("/v{jclouds.api-version}") +public interface VirtualGuestAsyncClient { + + /** + * @see VirtualGuestClient#listVirtualGuests + */ + @GET + @Path("/VirtualGuest_Account/VirtualGuests.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listVirtualGuests(); + + /** + * @see VirtualGuestClient#getVirtualGuest + */ + @GET + @Path("/VirtualGuest_Virtual_Guest/{id}.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVirtualGuest(@PathParam("id") long id); +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java new file mode 100644 index 0000000000..c5fe226f2d --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.softlayer.features; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.softlayer.domain.VirtualGuest; + +/** + * Provides synchronous access to VirtualGuest. + *

+ * + * @see VirtualGuestAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS) +public interface VirtualGuestClient { + + /** + * + * @return an account's associated virtual guest objects. + */ + Set listVirtualGuests(); + + /** + * + * @param id + * id of the virtual guest + * @return virtual guest or null if not found + */ + VirtualGuest getVirtualGuest(long id); + +} diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerAsyncClientTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerAsyncClientTest.java index 1146d84b02..1b9333aa2a 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerAsyncClientTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerAsyncClientTest.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2011 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,83 +19,35 @@ package org.jclouds.softlayer; -import static org.jclouds.rest.RestContextFactory.contextSpec; -import static org.testng.Assert.assertEquals; - import java.io.IOException; -import java.lang.reflect.Method; +import java.util.concurrent.ExecutionException; import org.jclouds.http.HttpRequest; -import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.RestContextSpec; -import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.softlayer.features.BaseSoftLayerAsyncClientTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; import com.google.inject.TypeLiteral; /** - * Tests annotation parsing of {@code SoftLayerAsyncClient} + * Tests behavior of {@code SoftLayerAsyncClient} * * @author Adrian Cole */ -@Test(groups = "unit") -public class SoftLayerAsyncClientTest extends RestClientTest { +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "SoftLayerAsyncClientTest") +public class SoftLayerAsyncClientTest extends BaseSoftLayerAsyncClientTest { - public void testListVirtualGuests() throws SecurityException, NoSuchMethodException, IOException { - Method method = SoftLayerAsyncClient.class.getMethod("listVirtualGuests"); - HttpRequest httpRequest = processor.createRequest(method); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // now make sure request filters apply by replaying - httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json HTTP/1.1"); - // for example, using basic authentication, we should get "only one" - // header - assertNonPayloadHeadersEqual(httpRequest, - "Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); - - checkFilters(httpRequest); + private SoftLayerAsyncClient asyncClient; + private SoftLayerClient syncClient; + public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { + assert syncClient.getVirtualGuestClient() != null; } - public void testGetVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Method method = SoftLayerAsyncClient.class.getMethod("getVirtualGuest", long.class); - HttpRequest httpRequest = processor.createRequest(method, 1234); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - @Override - protected void checkFilters(HttpRequest request) { - assertEquals(request.getFilters().size(), 1); - assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); + public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { + assert asyncClient.getVirtualGuestClient() != null; } @Override @@ -104,9 +56,16 @@ public class SoftLayerAsyncClientTest extends RestClientTest createContextSpec() { - return contextSpec("softlayer", "https://api.softlayer.com/rest", "3", "", "identity", "credential", - SoftLayerClient.class, SoftLayerAsyncClient.class); + protected void setupFactory() throws IOException { + super.setupFactory(); + asyncClient = injector.getInstance(SoftLayerAsyncClient.class); + syncClient = injector.getInstance(SoftLayerClient.class); + } + + @Override + protected void checkFilters(HttpRequest request) { + } } diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java new file mode 100644 index 0000000000..3ea5c7bf74 --- /dev/null +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java @@ -0,0 +1,51 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.softlayer.features; + +import static org.testng.Assert.assertEquals; + +import java.util.Properties; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.rest.RestContextSpec; +import org.jclouds.softlayer.SoftLayerAsyncClient; +import org.jclouds.softlayer.SoftLayerClient; + +/** + * @author Adrian Cole + */ +public abstract class BaseSoftLayerAsyncClientTest extends RestClientTest { + + @Override + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); + } + + @Override + public RestContextSpec createContextSpec() { + Properties props = new Properties(); + return new RestContextFactory().createContextSpec("softlayer", "apiKey", "secretKey", props); + } + +} \ No newline at end of file diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java new file mode 100644 index 0000000000..ea820057e7 --- /dev/null +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.softlayer.features; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Properties; + +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.softlayer.SoftLayerAsyncClient; +import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.softlayer.SoftLayerContextBuilder; +import org.jclouds.softlayer.SoftLayerPropertiesBuilder; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Tests behavior of {@code SoftLayerClient} + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class BaseSoftLayerClientLiveTest { + + protected RestContext context; + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity"); + String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential"); + + Properties restProperties = new Properties(); + restProperties.setProperty("softlayer.contextbuilder", SoftLayerContextBuilder.class.getName()); + restProperties.setProperty("softlayer.propertiesbuilder", SoftLayerPropertiesBuilder.class.getName()); + + context = new RestContextFactory(restProperties).createContext("softlayer", identity, credential, + ImmutableSet. of(new Log4JLoggingModule())); + + } + + @AfterGroups(groups = "live") + protected void tearDown() { + if (context != null) + context.close(); + } + +} diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java new file mode 100644 index 0000000000..42bfb14232 --- /dev/null +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java @@ -0,0 +1,95 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.softlayer.features; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code VirtualGuestAsyncClient} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest { + + public void testListVirtualGuests() throws SecurityException, NoSuchMethodException, IOException { + Method method = VirtualGuestAsyncClient.class.getMethod("listVirtualGuests"); + HttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, + "GET https://api.softlayer.com/rest/v3/VirtualGuest_Account/VirtualGuests.json HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + // now make sure request filters apply by replaying + httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + + assertRequestLineEquals(httpRequest, + "GET https://api.softlayer.com/rest/v3/VirtualGuest_Account/VirtualGuests.json HTTP/1.1"); + // for example, using basic authentication, we should get "only one" + // header + assertNonPayloadHeadersEqual(httpRequest, + "Accept: application/json\nAuthorization: Basic YXBpS2V5OnNlY3JldEtleQ==\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseJson.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testGetVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { + Method method = VirtualGuestAsyncClient.class.getMethod("getVirtualGuest", long.class); + HttpRequest httpRequest = processor.createRequest(method, 1234); + + assertRequestLineEquals(httpRequest, + "GET https://api.softlayer.com/rest/v3/VirtualGuest_Virtual_Guest/1234.json HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseJson.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java similarity index 62% rename from sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerClientLiveTest.java rename to sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java index 93a09e5b02..5f407f75bc 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerClientLiveTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java @@ -17,57 +17,31 @@ * ==================================================================== */ -package org.jclouds.softlayer; +package org.jclouds.softlayer.features; -import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; -import java.util.Properties; import java.util.Set; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.RestContext; -import org.jclouds.rest.RestContextFactory; import org.jclouds.softlayer.domain.VirtualGuest; -import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - /** - * Tests behavior of {@code SoftLayerClient} + * Tests behavior of {@code VirtualGuestClient} * * @author Adrian Cole */ @Test(groups = "live") -public class SoftLayerClientLiveTest { - - private SoftLayerClient client; - private RestContext context; - +public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest { @BeforeGroups(groups = { "live" }) public void setupClient() { - String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity"); - String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential"); - - Properties restProperties = new Properties(); - restProperties.setProperty("softlayer.contextbuilder", SoftLayerContextBuilder.class.getName()); - restProperties.setProperty("softlayer.propertiesbuilder", SoftLayerPropertiesBuilder.class.getName()); - - context = new RestContextFactory(restProperties).createContext("softlayer", identity, credential, ImmutableSet - . of(new Log4JLoggingModule())); - - client = context.getApi(); + super.setupClient(); + client = context.getApi().getVirtualGuestClient(); } - @AfterGroups(groups = "live") - void tearDown() { - if (context != null) - context.close(); - } + private VirtualGuestClient client; @Test public void testListVirtualGuests() throws Exception { From bbf6ba525dc6e9fa158c595945b445419511ffa8 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 19 Mar 2011 00:41:39 -0700 Subject: [PATCH 4/4] added ops to vm and datacenter features to softlayer --- .../softlayer/SoftLayerAsyncClient.java | 6 + .../jclouds/softlayer/SoftLayerClient.java | 6 + .../config/SoftLayerRestClientModule.java | 3 + .../jclouds/softlayer/domain/Datacenter.java | 106 ++++++++++++++++++ .../features/DatacenterAsyncClient.java | 70 ++++++++++++ .../softlayer/features/DatacenterClient.java | 53 +++++++++ .../features/VirtualGuestAsyncClient.java | 54 ++++++++- .../features/VirtualGuestClient.java | 39 +++++++ .../softlayer/SoftLayerAsyncClientTest.java | 2 + .../features/DatacenterAsyncClientTest.java | 94 ++++++++++++++++ .../features/DatacenterClientLiveTest.java | 64 +++++++++++ .../features/VirtualGuestAsyncClientTest.java | 103 +++++++++++++++-- 12 files changed, 591 insertions(+), 9 deletions(-) create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Datacenter.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterAsyncClient.java create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterClient.java create mode 100644 sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterAsyncClientTest.java create mode 100644 sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java index bc72b03220..533ce738af 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java @@ -20,6 +20,7 @@ package org.jclouds.softlayer; import org.jclouds.rest.annotations.Delegate; +import org.jclouds.softlayer.features.DatacenterAsyncClient; import org.jclouds.softlayer.features.VirtualGuestAsyncClient; /** @@ -38,4 +39,9 @@ public interface SoftLayerAsyncClient { @Delegate VirtualGuestAsyncClient getVirtualGuestClient(); + /** + * Provides asynchronous access to Datacenter features. + */ + @Delegate + DatacenterAsyncClient getDatacenterClient(); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java index faea8510cf..b69ba34ab2 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; +import org.jclouds.softlayer.features.DatacenterClient; import org.jclouds.softlayer.features.VirtualGuestClient; /** @@ -42,4 +43,9 @@ public interface SoftLayerClient { @Delegate VirtualGuestClient getVirtualGuestClient(); + /** + * Provides synchronous access to Datacenter features. + */ + @Delegate + DatacenterClient getDatacenterClient(); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java index 2cd212b771..87c7f70b45 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java @@ -34,6 +34,8 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; import org.jclouds.softlayer.SoftLayerAsyncClient; import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.softlayer.features.DatacenterAsyncClient; +import org.jclouds.softlayer.features.DatacenterClient; import org.jclouds.softlayer.features.VirtualGuestAsyncClient; import org.jclouds.softlayer.features.VirtualGuestClient; import org.jclouds.softlayer.handlers.SoftLayerErrorHandler; @@ -51,6 +53,7 @@ public class SoftLayerRestClientModule extends RestClientModule, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// .put(VirtualGuestClient.class, VirtualGuestAsyncClient.class)// + .put(DatacenterClient.class, DatacenterAsyncClient.class)// .build(); public SoftLayerRestClientModule() { diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Datacenter.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Datacenter.java new file mode 100644 index 0000000000..6716a78836 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/domain/Datacenter.java @@ -0,0 +1,106 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.softlayer.domain; + +/** + * + * @author Adrian Cole + * @see + */ +public class Datacenter implements Comparable { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private long id = -1; + private String name; + private String longName; + + public Builder id(long id) { + this.id = id; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder longName(String longName) { + this.longName = longName; + return this; + } + + public Datacenter build() { + return new Datacenter(id, name, longName); + } + + public static Builder fromDatacenter(Datacenter in) { + return Datacenter.builder().id(in.getId()).name(in.getName()).longName(in.getLongName()); + } + } + + private long id = -1; + private String name; + private String longName; + + // for deserializer + Datacenter() { + + } + + public Datacenter(long id, String name, String longName) { + this.id = id; + this.name = name; + this.longName = longName; + } + + @Override + public int compareTo(Datacenter arg0) { + return new Long(id).compareTo(arg0.getId()); + } + + /** + * @return The unique identifier of a specific location. + */ + public long getId() { + return id; + } + + /** + * @return A short location description. + */ + public String getName() { + return name; + } + + /** + * @return A longer location description. + */ + public String getLongName() { + return longName; + } + + public Builder toBuilder() { + return Builder.fromDatacenter(this); + } +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterAsyncClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterAsyncClient.java new file mode 100644 index 0000000000..97f60ecf78 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterAsyncClient.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.softlayer.features; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.softlayer.domain.Datacenter; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to LocationDatacenter via their REST API. + *

+ * + * @see DatacenterClient + * @see + * @author Adrian Cole + */ +@RequestFilters(BasicAuthentication.class) +@Path("/v{jclouds.api-version}") +public interface DatacenterAsyncClient { + + /** + * @see LocationDatacenterClient#listDatacenters + */ + @GET + @Path("/SoftLayer_Location_Datacenter/Datacenters.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listDatacenters(); + + /** + * @see LocationDatacenterClient#getLocationDatacenter + */ + @GET + @Path("/SoftLayer_Location_Datacenter/{id}.json") + @QueryParams(keys = "objectMask", values = "locationAddress") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getDatacenter(@PathParam("id") long id); +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterClient.java new file mode 100644 index 0000000000..f0bf83b987 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/DatacenterClient.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.softlayer.features; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.softlayer.domain.Datacenter; + +/** + * Provides synchronous access to LocationDatacenter. + *

+ * + * @see DatacenterAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS) +public interface DatacenterClient { + + /** + * + * @return an account's associated datacenter objects. + */ + Set listDatacenters(); + + /** + * + * @param id + * id of the datacenter + * @return datacenter or null if not found + */ + Datacenter getDatacenter(long id); + +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java index cd2ffaef62..58654a4ebc 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestAsyncClient.java @@ -29,9 +29,11 @@ import javax.ws.rs.core.MediaType; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.QueryParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.softlayer.domain.VirtualGuest; import com.google.common.util.concurrent.ListenableFuture; @@ -47,12 +49,14 @@ import com.google.common.util.concurrent.ListenableFuture; @RequestFilters(BasicAuthentication.class) @Path("/v{jclouds.api-version}") public interface VirtualGuestAsyncClient { + public static String GUEST_MASK = "powerState;networkVlans;operatingSystem.passwords;datacenter"; /** * @see VirtualGuestClient#listVirtualGuests */ @GET - @Path("/VirtualGuest_Account/VirtualGuests.json") + @Path("/SoftLayer_Account/VirtualGuests.json") + @QueryParams(keys = "objectMask", values = GUEST_MASK) @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) ListenableFuture> listVirtualGuests(); @@ -61,8 +65,54 @@ public interface VirtualGuestAsyncClient { * @see VirtualGuestClient#getVirtualGuest */ @GET - @Path("/VirtualGuest_Virtual_Guest/{id}.json") + @Path("/SoftLayer_Virtual_Guest/{id}.json") + @QueryParams(keys = "objectMask", values = GUEST_MASK) @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getVirtualGuest(@PathParam("id") long id); + + /** + * @see VirtualGuestClient#rebootHardVirtualGuest + */ + @GET + @Path("/SoftLayer_Virtual_Guest/{id}/rebootHard.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture rebootHardVirtualGuest(@PathParam("id") long id); + + /** + * @see VirtualGuestClient#powerOffVirtualGuest + */ + @GET + @Path("/SoftLayer_Virtual_Guest/{id}/powerOff.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture powerOffVirtualGuest(@PathParam("id") long id); + + /** + * @see VirtualGuestClient#powerOnVirtualGuest + */ + @GET + @Path("/SoftLayer_Virtual_Guest/{id}/powerOn.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture powerOnVirtualGuest(@PathParam("id") long id); + + /** + * @see VirtualGuestClient#pauseVirtualGuest + */ + @GET + @Path("/SoftLayer_Virtual_Guest/{id}/pause.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture pauseVirtualGuest(@PathParam("id") long id); + + /** + * @see VirtualGuestClient#resumeVirtualGuest + */ + @GET + @Path("/SoftLayer_Virtual_Guest/{id}/resume.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture resumeVirtualGuest(@PathParam("id") long id); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java index c5fe226f2d..a391f1f4d8 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/VirtualGuestClient.java @@ -50,4 +50,43 @@ public interface VirtualGuestClient { */ VirtualGuest getVirtualGuest(long id); + /** + * hard reboot the guest. + * + * @param id + * id of the virtual guest + */ + void rebootHardVirtualGuest(long id); + + /** + * Power off a guest + * + * @param id + * id of the virtual guest + */ + void powerOffVirtualGuest(long id); + + /** + * Power on a guest + * + * @param id + * id of the virtual guest + */ + void powerOnVirtualGuest(long id); + + /** + * pause the guest. + * + * @param id + * id of the virtual guest + */ + void pauseVirtualGuest(long id); + + /** + * resume the guest. + * + * @param id + * id of the virtual guest + */ + void resumeVirtualGuest(long id); } diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerAsyncClientTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerAsyncClientTest.java index 1b9333aa2a..e8c4c34247 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerAsyncClientTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/SoftLayerAsyncClientTest.java @@ -44,10 +44,12 @@ public class SoftLayerAsyncClientTest extends BaseSoftLayerAsyncClientTest + * + * ==================================================================== + * 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 org.jclouds.softlayer.features; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code DatacenterAsyncClient} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class DatacenterAsyncClientTest extends BaseSoftLayerAsyncClientTest { + + public void testListDatacenters() throws SecurityException, NoSuchMethodException, IOException { + Method method = DatacenterAsyncClient.class.getMethod("listDatacenters"); + HttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, + "GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + // now make sure request filters apply by replaying + httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + + assertRequestLineEquals(httpRequest, + "GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json HTTP/1.1"); + // for example, using basic authentication, we should get "only one" + // header + assertNonPayloadHeadersEqual(httpRequest, + "Accept: application/json\nAuthorization: Basic YXBpS2V5OnNlY3JldEtleQ==\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseJson.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testGetDatacenter() throws SecurityException, NoSuchMethodException, IOException { + Method method = DatacenterAsyncClient.class.getMethod("getDatacenter", long.class); + HttpRequest httpRequest = processor.createRequest(method, 1234); + + assertRequestLineEquals(httpRequest, + "GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/1234.json?objectMask=locationAddress HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseJson.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java new file mode 100644 index 0000000000..4605e91381 --- /dev/null +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.softlayer.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.jclouds.softlayer.domain.Datacenter; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code DatacenterClient} + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class DatacenterClientLiveTest extends BaseSoftLayerClientLiveTest { + @BeforeGroups(groups = { "live" }) + public void setupClient() { + super.setupClient(); + client = context.getApi().getDatacenterClient(); + } + + private DatacenterClient client; + + @Test + public void testListDatacenters() throws Exception { + Set response = client.listDatacenters(); + assert null != response; + assertTrue(response.size() >= 0); + for (Datacenter vg : response) { + Datacenter newDetails = client.getDatacenter(vg.getId()); + assertEquals(vg.getId(), newDetails.getId()); + checkDatacenter(vg); + } + } + + private void checkDatacenter(Datacenter vg) { + assert vg.getId() > 0 : vg; + assert vg.getName() != null : vg; + assert vg.getLongName() != null : vg; + } + +} diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java index 42bfb14232..c473564944 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java @@ -24,8 +24,10 @@ import java.lang.reflect.Method; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseJson; +import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; @@ -44,8 +46,9 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest> createTypeLiteral() {