diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index d1c008b552..a3d20f6e5f 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -74,6 +74,9 @@ opscodeplatform.propertiesbuilder=org.jclouds.opscodeplatform.OpscodePlatformPro vcloud.contextbuilder=org.jclouds.vcloud.VCloudContextBuilder vcloud.propertiesbuilder=org.jclouds.vcloud.VCloudPropertiesBuilder +vcloudexpress.contextbuilder=org.jclouds.vcloud.VCloudExpressContextBuilder +vcloudexpress.propertiesbuilder=org.jclouds.vcloud.VCloudExpressPropertiesBuilder + eucalyptus.contextbuilder=org.jclouds.aws.ec2.EC2ContextBuilder eucalyptus.propertiesbuilder=org.jclouds.aws.ec2.EucalyptusPropertiesBuilder diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudDirectorContextBuilder.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudDirectorContextBuilder.java index 22120c1566..7f9c2e80e8 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudDirectorContextBuilder.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudDirectorContextBuilder.java @@ -25,8 +25,8 @@ import java.util.Properties; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.vcloud.VCloudContextBuilder; -import org.jclouds.vcloud.bluelock.compute.config.BlueLockVCloudExpressComputeServiceContextModule; -import org.jclouds.vcloud.bluelock.config.BlueLockVCloudExpressRestClientModule; +import org.jclouds.vcloud.bluelock.compute.config.BlueLockVCloudDirectorComputeServiceContextModule; +import org.jclouds.vcloud.bluelock.config.BlueLockVCloudDirectorRestClientModule; import com.google.inject.Injector; import com.google.inject.Module; @@ -52,12 +52,12 @@ public class BlueLockVCloudDirectorContextBuilder extends VCloudContextBuilder { @Override protected void addContextModule(List modules) { - modules.add(new BlueLockVCloudExpressComputeServiceContextModule()); + modules.add(new BlueLockVCloudDirectorComputeServiceContextModule()); } @Override protected void addClientModule(List modules) { - modules.add(new BlueLockVCloudExpressRestClientModule()); + modules.add(new BlueLockVCloudDirectorRestClientModule()); } } diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudDirectorPropertiesBuilder.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudDirectorPropertiesBuilder.java index 94816202ed..dd171d19c6 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudDirectorPropertiesBuilder.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudDirectorPropertiesBuilder.java @@ -19,9 +19,7 @@ package org.jclouds.vcloud.bluelock; -import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA; import java.util.Properties; @@ -36,8 +34,6 @@ public class BlueLockVCloudDirectorPropertiesBuilder extends VCloudPropertiesBui @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "1.0"); - properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1.0"); properties.setProperty(PROPERTY_ENDPOINT, "https://vcenterprise.bluelock.com/api"); return properties; } diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressContextBuilder.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressContextBuilder.java index f9187854b5..7dd776267c 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressContextBuilder.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressContextBuilder.java @@ -24,7 +24,7 @@ import java.util.Properties; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; -import org.jclouds.vcloud.VCloudContextBuilder; +import org.jclouds.vcloud.VCloudExpressContextBuilder; import org.jclouds.vcloud.bluelock.compute.config.BlueLockVCloudExpressComputeServiceContextModule; import org.jclouds.vcloud.bluelock.config.BlueLockVCloudExpressRestClientModule; @@ -44,7 +44,7 @@ import com.google.inject.Module; * @author Adrian Cole * @see BlueLockVCloudComputeServiceContext */ -public class BlueLockVCloudExpressContextBuilder extends VCloudContextBuilder { +public class BlueLockVCloudExpressContextBuilder extends VCloudExpressContextBuilder { public BlueLockVCloudExpressContextBuilder(Properties props) { super(props); diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressPropertiesBuilder.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressPropertiesBuilder.java index 22b7455a56..1d1ee131e6 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressPropertiesBuilder.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressPropertiesBuilder.java @@ -23,14 +23,14 @@ import static org.jclouds.Constants.PROPERTY_ENDPOINT; import java.util.Properties; -import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.VCloudExpressPropertiesBuilder; /** * Builds properties used in bluelock VCloud Clients * * @author Adrian Cole */ -public class BlueLockVCloudExpressPropertiesBuilder extends VCloudPropertiesBuilder { +public class BlueLockVCloudExpressPropertiesBuilder extends VCloudExpressPropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeClient.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeClient.java new file mode 100644 index 0000000000..7ab82f6be6 --- /dev/null +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeClient.java @@ -0,0 +1,62 @@ +/** + * + * Copyright (C) 2010 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.vcloud.bluelock.compute; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.domain.Credentials; +import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.compute.BaseVCloudComputeClient; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; + +import com.google.common.base.Predicate; + +/** + * @author Adrian Cole + */ +@Singleton +public class BlueLockVCloudDirectorComputeClient extends BaseVCloudComputeClient { + private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider; + + @Inject + protected BlueLockVCloudDirectorComputeClient(PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, + VCloudClient client, Predicate successTester, Map vAppStatusToNodeState) { + super(client, successTester, vAppStatusToNodeState); + this.credentialsProvider = credentialsProvider; + } + + @Override + protected Map parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) { + Credentials credentials = credentialsProvider.execute(template); + Map toReturn = super.parseResponse(template, vAppResponse); + toReturn.put("username", credentials.identity); + toReturn.put("password", credentials.credential); + return toReturn; + } + +} \ No newline at end of file diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeClient.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeClient.java index 9c7e4369fc..dd685c19df 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeClient.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeClient.java @@ -28,8 +28,8 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.domain.Credentials; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.compute.BaseVCloudComputeClient; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppTemplate; @@ -40,12 +40,12 @@ import com.google.common.base.Predicate; * @author Adrian Cole */ @Singleton -public class BlueLockVCloudExpressComputeClient extends BaseVCloudComputeClient { +public class BlueLockVCloudExpressComputeClient extends BaseVCloudExpressComputeClient { private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider; @Inject protected BlueLockVCloudExpressComputeClient(PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, - VCloudClient client, Predicate successTester, Map vAppStatusToNodeState) { + VCloudExpressClient client, Predicate successTester, Map vAppStatusToNodeState) { super(client, successTester, vAppStatusToNodeState); this.credentialsProvider = credentialsProvider; } diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudDirectorComputeServiceContextModule.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudDirectorComputeServiceContextModule.java new file mode 100644 index 0000000000..acbf6d57e1 --- /dev/null +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudDirectorComputeServiceContextModule.java @@ -0,0 +1,57 @@ +/** + * + * Copyright (C) 2010 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.vcloud.bluelock.compute.config; + +import java.util.Set; + +import org.jclouds.compute.domain.Size; +import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.vcloud.bluelock.compute.BlueLockVCloudDirectorComputeClient; +import org.jclouds.vcloud.bluelock.compute.config.suppliers.ParseSizeFromImageSupplier; +import org.jclouds.vcloud.bluelock.compute.functions.BlueLockVCloudImageForVAppTemplate; +import org.jclouds.vcloud.bluelock.compute.strategy.DefaultLoginCredentialsFromBlueLockFAQ; +import org.jclouds.vcloud.compute.VCloudComputeClient; +import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; +import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate; + +import com.google.common.base.Supplier; +import com.google.inject.Injector; + +/** + * Configures the {@link BlueLockVCloudComputeServiceContext}; requires + * {@link BlueLockVCloudComputeClient} bound. + * + * @author Adrian Cole + */ +public class BlueLockVCloudDirectorComputeServiceContextModule extends VCloudComputeServiceContextModule { + + @Override + protected void configure() { + super.configure(); + bind(ImageForVAppTemplate.class).to(BlueLockVCloudImageForVAppTemplate.class); + bind(VCloudComputeClient.class).to(BlueLockVCloudDirectorComputeClient.class); + bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(DefaultLoginCredentialsFromBlueLockFAQ.class); + } + + @Override + protected Supplier> getSourceSizeSupplier(Injector injector) { + return injector.getInstance(ParseSizeFromImageSupplier.class); + } +} diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudExpressComputeServiceContextModule.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudExpressComputeServiceContextModule.java index 1390275b01..ff3659e864 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudExpressComputeServiceContextModule.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/config/BlueLockVCloudExpressComputeServiceContextModule.java @@ -25,10 +25,10 @@ import org.jclouds.compute.domain.Size; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.vcloud.bluelock.compute.BlueLockVCloudExpressComputeClient; import org.jclouds.vcloud.bluelock.compute.config.suppliers.ParseSizeFromImageSupplier; -import org.jclouds.vcloud.bluelock.compute.functions.BlueLockVCloudExpressImageForVAppTemplate; +import org.jclouds.vcloud.bluelock.compute.functions.BlueLockVCloudImageForVAppTemplate; import org.jclouds.vcloud.bluelock.compute.strategy.DefaultLoginCredentialsFromBlueLockFAQ; -import org.jclouds.vcloud.compute.VCloudComputeClient; -import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; +import org.jclouds.vcloud.compute.VCloudExpressComputeClient; +import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule; import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate; import com.google.common.base.Supplier; @@ -40,13 +40,13 @@ import com.google.inject.Injector; * * @author Adrian Cole */ -public class BlueLockVCloudExpressComputeServiceContextModule extends VCloudComputeServiceContextModule { +public class BlueLockVCloudExpressComputeServiceContextModule extends VCloudExpressComputeServiceContextModule { @Override protected void configure() { super.configure(); - bind(ImageForVAppTemplate.class).to(BlueLockVCloudExpressImageForVAppTemplate.class); - bind(VCloudComputeClient.class).to(BlueLockVCloudExpressComputeClient.class); + bind(ImageForVAppTemplate.class).to(BlueLockVCloudImageForVAppTemplate.class); + bind(VCloudExpressComputeClient.class).to(BlueLockVCloudExpressComputeClient.class); bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(DefaultLoginCredentialsFromBlueLockFAQ.class); } diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudExpressImageForVAppTemplate.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudImageForVAppTemplate.java similarity index 89% rename from vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudExpressImageForVAppTemplate.java rename to vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudImageForVAppTemplate.java index 5214728345..1e1e12c70a 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudExpressImageForVAppTemplate.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/compute/functions/BlueLockVCloudImageForVAppTemplate.java @@ -31,10 +31,10 @@ import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate; * @author Adrian Cole */ @Singleton -public class BlueLockVCloudExpressImageForVAppTemplate extends ImageForVAppTemplate { +public class BlueLockVCloudImageForVAppTemplate extends ImageForVAppTemplate { @Inject - protected BlueLockVCloudExpressImageForVAppTemplate(FindLocationForResource findLocationForResource, + protected BlueLockVCloudImageForVAppTemplate(FindLocationForResource findLocationForResource, PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider) { super(findLocationForResource, credentialsProvider); } diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/config/BlueLockVCloudDirectorRestClientModule.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/config/BlueLockVCloudDirectorRestClientModule.java new file mode 100644 index 0000000000..2d552cbd0b --- /dev/null +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/config/BlueLockVCloudDirectorRestClientModule.java @@ -0,0 +1,35 @@ +/** + * + * Copyright (C) 2010 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.vcloud.bluelock.config; + +import org.jclouds.http.RequiresHttp; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.vcloud.config.VCloudRestClientModule; + +/** + * Configures the VCloud authentication service connection, including logging and http transport. + * + * @author Adrian Cole + */ +@RequiresHttp +@ConfiguresRestClient +public class BlueLockVCloudDirectorRestClientModule extends VCloudRestClientModule { + +} diff --git a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/config/BlueLockVCloudExpressRestClientModule.java b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/config/BlueLockVCloudExpressRestClientModule.java index f8a3ea852d..cd77f6d93a 100644 --- a/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/config/BlueLockVCloudExpressRestClientModule.java +++ b/vcloud/bluelock/src/main/java/org/jclouds/vcloud/bluelock/config/BlueLockVCloudExpressRestClientModule.java @@ -24,15 +24,13 @@ import static org.jclouds.Constants.PROPERTY_IDENTITY; import java.net.URI; import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; import javax.inject.Named; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.config.VCloudRestClientModule; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.config.VCloudExpressRestClientModule; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; @@ -40,18 +38,16 @@ import com.google.common.base.Predicate; import com.google.common.collect.Iterables; /** - * Configures the VCloud authentication service connection, including logging - * and http transport. + * Configures the VCloud authentication service connection, including logging and http transport. * * @author Adrian Cole */ @RequiresHttp @ConfiguresRestClient -public class BlueLockVCloudExpressRestClientModule extends VCloudRestClientModule { +public class BlueLockVCloudExpressRestClientModule extends VCloudExpressRestClientModule { @Override - protected URI provideDefaultNetwork(VCloudClient client) throws InterruptedException, ExecutionException, - TimeoutException { + protected URI provideDefaultNetwork(VCloudExpressClient client) { org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null); Map networks = vDC.getAvailableNetworks(); checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName()); diff --git a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressClientLiveTest.java b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressClientLiveTest.java index b4c5bdbb25..c8185718e7 100644 --- a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressClientLiveTest.java +++ b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/BlueLockVCloudExpressClientLiveTest.java @@ -25,7 +25,7 @@ import java.util.Properties; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rest.RestContextFactory; -import org.jclouds.vcloud.VCloudClientLiveTest; +import org.jclouds.vcloud.VCloudExpressClientLiveTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -38,7 +38,7 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", sequential = true, testName = "vcloud.BlueLockVCloudClientLiveTest") -public class BlueLockVCloudExpressClientLiveTest extends VCloudClientLiveTest { +public class BlueLockVCloudExpressClientLiveTest extends VCloudExpressClientLiveTest { @BeforeGroups(groups = { "live" }) @Override diff --git a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java index ce801b154b..aba4db23fd 100644 --- a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java +++ b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java @@ -34,7 +34,7 @@ import org.testng.annotations.Test; * * @author Adrian Cole */ -@Test(groups = "live", enabled = true, sequential = true, testName = "bluelock.BlueLockVCloudExpressComputeServiceLiveTest") +@Test(groups = "live", enabled = true, sequential = true, testName = "bluelock.BlueLockVCloudComputeServiceLiveTest") public class BlueLockVCloudDirectorComputeServiceLiveTest extends VCloudComputeServiceLiveTest { @Override public void setServiceDefaults() { diff --git a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeServiceLiveTest.java b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeServiceLiveTest.java index cb66134353..4b0d1ef294 100644 --- a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeServiceLiveTest.java +++ b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudExpressComputeServiceLiveTest.java @@ -26,7 +26,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.vcloud.compute.VCloudComputeServiceLiveTest; +import org.jclouds.vcloud.compute.VCloudExpressComputeServiceLiveTest; import org.testng.annotations.Test; /** @@ -35,7 +35,7 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", enabled = true, sequential = true, testName = "bluelock.BlueLockVCloudExpressComputeServiceLiveTest") -public class BlueLockVCloudExpressComputeServiceLiveTest extends VCloudComputeServiceLiveTest { +public class BlueLockVCloudExpressComputeServiceLiveTest extends VCloudExpressComputeServiceLiveTest { @Override public void setServiceDefaults() { provider = "bluelock-vcloudexpress"; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index ae80a69b64..03e158fa0f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -19,15 +19,15 @@ package org.jclouds.vcloud; -import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; -import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; -import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML; -import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; -import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; -import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; -import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; -import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; -import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOGITEM_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.NETWORK_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.ORG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.TASKSLIST_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.TASK_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VAPPTEMPLATE_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VAPP_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VDC_XML; import java.net.URI; @@ -95,7 +95,7 @@ import com.google.common.util.concurrent.ListenableFuture; @RequestFilters(SetVCloudTokenCookie.class) public interface VCloudAsyncClient { /** - * @see VCloudClient#getDefaultOrganization + * @see VCloudExpressClient#getDefaultOrganization */ @Deprecated @GET @@ -105,7 +105,7 @@ public interface VCloudAsyncClient { ListenableFuture getDefaultOrganization(); /** - * @see VCloudClient#getOrganization + * @see VCloudExpressClient#getOrganization */ @GET @XMLResponseParser(OrgHandler.class) @@ -114,7 +114,7 @@ public interface VCloudAsyncClient { ListenableFuture getOrganization(@EndpointParam URI orgId); /** - * @see VCloudClient#getOrganizationNamed + * @see VCloudExpressClient#getOrganizationNamed */ @GET @XMLResponseParser(OrgHandler.class) @@ -124,7 +124,7 @@ public interface VCloudAsyncClient { @Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName); /** - * @see VCloudClient#getDefaultCatalog + * @see VCloudExpressClient#getDefaultCatalog */ @Deprecated @GET @@ -134,7 +134,7 @@ public interface VCloudAsyncClient { ListenableFuture getDefaultCatalog(); /** - * @see VCloudClient#getCatalog + * @see VCloudExpressClient#getCatalog */ @GET @XMLResponseParser(CatalogHandler.class) @@ -143,7 +143,7 @@ public interface VCloudAsyncClient { ListenableFuture getCatalog(@EndpointParam URI catalogId); /** - * @see VCloudClient#findCatalogInOrgNamed + * @see VCloudExpressClient#findCatalogInOrgNamed */ @GET @XMLResponseParser(CatalogHandler.class) @@ -154,7 +154,7 @@ public interface VCloudAsyncClient { @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName); /** - * @see VCloudClient#getVAppTemplate + * @see VCloudExpressClient#getVAppTemplate */ @GET @Consumes(VAPPTEMPLATE_XML) @@ -163,7 +163,7 @@ public interface VCloudAsyncClient { ListenableFuture getVAppTemplate(@EndpointParam URI vAppTemplate); /** - * @see VCloudClient#findVAppTemplateInOrgCatalogNameds + * @see VCloudExpressClient#findVAppTemplateInOrgCatalogNameds */ @GET @Consumes(VAPPTEMPLATE_XML) @@ -175,7 +175,7 @@ public interface VCloudAsyncClient { @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName); /** - * @see VCloudClient#getCatalogItem + * @see VCloudExpressClient#getCatalogItem */ @GET @Consumes(CATALOGITEM_XML) @@ -184,7 +184,7 @@ public interface VCloudAsyncClient { ListenableFuture getCatalogItem(@EndpointParam URI catalogItem); /** - * @see VCloudClient#getCatalogItemInOrg + * @see VCloudExpressClient#getCatalogItemInOrg */ @GET @Consumes(CATALOGITEM_XML) @@ -196,7 +196,7 @@ public interface VCloudAsyncClient { @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName); /** - * @see VCloudClient#findNetworkInOrgVDCNamed + * @see VCloudExpressClient#findNetworkInOrgVDCNamed */ @GET @Consumes(NETWORK_XML) @@ -208,7 +208,7 @@ public interface VCloudAsyncClient { @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName); /** - * @see VCloudClient#getNetwork + * @see VCloudExpressClient#getNetwork */ @GET @Consumes(NETWORK_XML) @@ -217,7 +217,7 @@ public interface VCloudAsyncClient { ListenableFuture getNetwork(@EndpointParam URI network); /** - * @see VCloudClient#getDefaultVDC + * @see VCloudExpressClient#getDefaultVDC */ @Deprecated @GET @@ -227,7 +227,7 @@ public interface VCloudAsyncClient { ListenableFuture getDefaultVDC(); /** - * @see VCloudClient#getVDC(URI) + * @see VCloudExpressClient#getVDC(URI) */ @GET @XMLResponseParser(VDCHandler.class) @@ -236,7 +236,7 @@ public interface VCloudAsyncClient { ListenableFuture getVDC(@EndpointParam URI vdc); /** - * @see VCloudClient#findVDCInOrgNamed(String, String) + * @see VCloudExpressClient#findVDCInOrgNamed(String, String) */ @GET @XMLResponseParser(VDCHandler.class) @@ -247,7 +247,7 @@ public interface VCloudAsyncClient { @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName); /** - * @see VCloudClient#getTasksList + * @see VCloudExpressClient#getTasksList */ @GET @Consumes(TASKSLIST_XML) @@ -256,7 +256,7 @@ public interface VCloudAsyncClient { ListenableFuture getTasksList(@EndpointParam URI tasksListId); /** - * @see VCloudClient#getTasksListInOrg + * @see VCloudExpressClient#getTasksListInOrg */ @GET @Consumes(TASKSLIST_XML) @@ -267,7 +267,7 @@ public interface VCloudAsyncClient { @Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String tasksListName); /** - * @see VCloudClient#getDefaultTasksList + * @see VCloudExpressClient#getDefaultTasksList */ @Deprecated @GET @@ -277,7 +277,7 @@ public interface VCloudAsyncClient { ListenableFuture getDefaultTasksList(); /** - * @see VCloudClient#deployVApp + * @see VCloudExpressClient#deployVApp */ @POST @Consumes(TASK_XML) @@ -286,14 +286,14 @@ public interface VCloudAsyncClient { ListenableFuture deployVApp(@EndpointParam URI vAppId); /** - * @see VCloudClient#deleteVApp + * @see VCloudExpressClient#deleteVApp */ @DELETE @ExceptionParser(ReturnVoidOnNotFoundOr404.class) ListenableFuture deleteVApp(@EndpointParam URI vAppId); /** - * @see VCloudClient#undeployVApp + * @see VCloudExpressClient#undeployVApp */ @POST @Consumes(TASK_XML) @@ -302,7 +302,7 @@ public interface VCloudAsyncClient { ListenableFuture undeployVApp(@EndpointParam URI vAppId); /** - * @see VCloudClient#powerOnVApp + * @see VCloudExpressClient#powerOnVApp */ @POST @Consumes(TASK_XML) @@ -311,7 +311,7 @@ public interface VCloudAsyncClient { ListenableFuture powerOnVApp(@EndpointParam URI vAppId); /** - * @see VCloudClient#powerOffVApp + * @see VCloudExpressClient#powerOffVApp */ @POST @Consumes(TASK_XML) @@ -320,14 +320,14 @@ public interface VCloudAsyncClient { ListenableFuture powerOffVApp(@EndpointParam URI vAppId); /** - * @see VCloudClient#shutdownVApp + * @see VCloudExpressClient#shutdownVApp */ @POST @Path("/power/action/shutdown") ListenableFuture shutdownVApp(@EndpointParam URI vAppId); /** - * @see VCloudClient#resetVApp + * @see VCloudExpressClient#resetVApp */ @POST @Consumes(TASK_XML) @@ -336,7 +336,7 @@ public interface VCloudAsyncClient { ListenableFuture resetVApp(@EndpointParam URI vAppId); /** - * @see VCloudClient#suspendVApp + * @see VCloudExpressClient#suspendVApp */ @POST @Consumes(TASK_XML) @@ -345,7 +345,7 @@ public interface VCloudAsyncClient { ListenableFuture suspendVApp(@EndpointParam URI vAppId); /** - * @see VCloudClient#getTask + * @see VCloudExpressClient#getTask */ @GET @Consumes(TASK_XML) @@ -354,14 +354,14 @@ public interface VCloudAsyncClient { ListenableFuture getTask(@EndpointParam URI taskId); /** - * @see VCloudClient#cancelTask + * @see VCloudExpressClient#cancelTask */ @POST @Path("/action/cancel") ListenableFuture cancelTask(@EndpointParam URI taskId); /** - * @see VCloudClient#findVAppInOrgVDCNamed + * @see VCloudExpressClient#findVAppInOrgVDCNamed */ @GET @Consumes(VAPP_XML) @@ -373,7 +373,7 @@ public interface VCloudAsyncClient { @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName); /** - * @see VCloudClient#getVApp + * @see VCloudExpressClient#getVApp */ @GET @Consumes(VAPP_XML) @@ -382,7 +382,7 @@ public interface VCloudAsyncClient { ListenableFuture getVApp(@EndpointParam URI vApp); /** - * @see VCloudClient#instantiateVAppTemplateInVDC + * @see VCloudExpressClient#instantiateVAppTemplateInVDC */ @POST @Path("action/instantiateVAppTemplate") @@ -396,7 +396,7 @@ public interface VCloudAsyncClient { InstantiateVAppTemplateOptions... options); /** - * @see VCloudClient#cloneVAppInVDC + * @see VCloudExpressClient#cloneVAppInVDC */ @POST @Path("/action/cloneVApp") diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudContextBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudContextBuilder.java index fd6d54c329..1ce37d6e7d 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudContextBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudContextBuilder.java @@ -48,8 +48,7 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole * @see VCloudComputeServiceContext */ -public class VCloudContextBuilder extends - ComputeServiceContextBuilder { +public class VCloudContextBuilder extends ComputeServiceContextBuilder { public VCloudContextBuilder(Properties props) { super(VCloudClient.class, VCloudAsyncClient.class, props); @@ -68,11 +67,8 @@ public class VCloudContextBuilder extends @Override public ComputeServiceContext buildComputeServiceContext() { // need the generic type information - return (ComputeServiceContext) this - .buildInjector() - .getInstance( - Key - .get(new TypeLiteral>() { - })); + return (ComputeServiceContext) this.buildInjector().getInstance( + Key.get(new TypeLiteral>() { + })); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressAsyncClient.java new file mode 100644 index 0000000000..da8341ba11 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressAsyncClient.java @@ -0,0 +1,411 @@ +/** + * + * Copyright (C) 2010 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.vcloud; + +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOGITEM_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.NETWORK_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.ORG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.TASKSLIST_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.TASK_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VAPPTEMPLATE_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VAPP_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VDC_XML; + +import java.net.URI; + +import javax.annotation.Nullable; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.jclouds.predicates.validators.DnsNameValidator; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.EndpointParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.MapPayloadParam; +import org.jclouds.rest.annotations.ParamValidators; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload; +import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.Network; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.TasksList; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameAndTasksListNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameToEndpoint; +import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint; +import org.jclouds.vcloud.options.CloneVAppOptions; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.jclouds.vcloud.xml.CatalogHandler; +import org.jclouds.vcloud.xml.CatalogItemHandler; +import org.jclouds.vcloud.xml.NetworkHandler; +import org.jclouds.vcloud.xml.OrgHandler; +import org.jclouds.vcloud.xml.TaskHandler; +import org.jclouds.vcloud.xml.TasksListHandler; +import org.jclouds.vcloud.xml.VAppHandler; +import org.jclouds.vcloud.xml.VAppTemplateHandler; +import org.jclouds.vcloud.xml.VDCHandler; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to VCloud resources via their REST API. + *

+ * + * @see + * @author Adrian Cole + */ +@RequestFilters(SetVCloudTokenCookie.class) +public interface VCloudExpressAsyncClient { + /** + * @see VCloudExpressClient#getDefaultOrganization + */ + @Deprecated + @GET + @Endpoint(Org.class) + @Consumes(ORG_XML) + @XMLResponseParser(OrgHandler.class) + ListenableFuture getDefaultOrganization(); + + /** + * @see VCloudExpressClient#getOrganization + */ + @GET + @XMLResponseParser(OrgHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(ORG_XML) + ListenableFuture getOrganization(@EndpointParam URI orgId); + + /** + * @see VCloudExpressClient#getOrganizationNamed + */ + @GET + @XMLResponseParser(OrgHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(ORG_XML) + ListenableFuture findOrganizationNamed( + @Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName); + + /** + * @see VCloudExpressClient#getDefaultCatalog + */ + @Deprecated + @GET + @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) + @Consumes(CATALOG_XML) + @XMLResponseParser(CatalogHandler.class) + ListenableFuture getDefaultCatalog(); + + /** + * @see VCloudExpressClient#getCatalog + */ + @GET + @XMLResponseParser(CatalogHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(CATALOG_XML) + ListenableFuture getCatalog(@EndpointParam URI catalogId); + + /** + * @see VCloudExpressClient#findCatalogInOrgNamed + */ + @GET + @XMLResponseParser(CatalogHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Consumes(CATALOG_XML) + ListenableFuture findCatalogInOrgNamed( + @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName); + + /** + * @see VCloudExpressClient#getVAppTemplate + */ + @GET + @Consumes(VAPPTEMPLATE_XML) + @XMLResponseParser(VAppTemplateHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVAppTemplate(@EndpointParam URI vAppTemplate); + + /** + * @see VCloudExpressClient#findVAppTemplateInOrgCatalogNameds + */ + @GET + @Consumes(VAPPTEMPLATE_XML) + @XMLResponseParser(VAppTemplateHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findVAppTemplateInOrgCatalogNamed( + @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName, + @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName); + + /** + * @see VCloudExpressClient#getCatalogItem + */ + @GET + @Consumes(CATALOGITEM_XML) + @XMLResponseParser(CatalogItemHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getCatalogItem(@EndpointParam URI catalogItem); + + /** + * @see VCloudExpressClient#getCatalogItemInOrg + */ + @GET + @Consumes(CATALOGITEM_XML) + @XMLResponseParser(CatalogItemHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findCatalogItemInOrgCatalogNamed( + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName, + @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName); + + /** + * @see VCloudExpressClient#findNetworkInOrgVDCNamed + */ + @GET + @Consumes(NETWORK_XML) + @XMLResponseParser(NetworkHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findNetworkInOrgVDCNamed( + @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName, + @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName); + + /** + * @see VCloudExpressClient#getNetwork + */ + @GET + @Consumes(NETWORK_XML) + @XMLResponseParser(NetworkHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getNetwork(@EndpointParam URI network); + + /** + * @see VCloudExpressClient#getDefaultVDC + */ + @Deprecated + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) + @XMLResponseParser(VDCHandler.class) + @Consumes(VDC_XML) + ListenableFuture getDefaultVDC(); + + /** + * @see VCloudExpressClient#getVDC(URI) + */ + @GET + @XMLResponseParser(VDCHandler.class) + @Consumes(VDC_XML) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVDC(@EndpointParam URI vdc); + + /** + * @see VCloudExpressClient#findVDCInOrgNamed(String, String) + */ + @GET + @XMLResponseParser(VDCHandler.class) + @Consumes(VDC_XML) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findVDCInOrgNamed( + @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName); + + /** + * @see VCloudExpressClient#getTasksList + */ + @GET + @Consumes(TASKSLIST_XML) + @XMLResponseParser(TasksListHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTasksList(@EndpointParam URI tasksListId); + + /** + * @see VCloudExpressClient#getTasksListInOrg + */ + @GET + @Consumes(TASKSLIST_XML) + @XMLResponseParser(TasksListHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findTasksListInOrgNamed( + @Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String tasksListName); + + /** + * @see VCloudExpressClient#getDefaultTasksList + */ + @Deprecated + @GET + @Endpoint(org.jclouds.vcloud.endpoints.TasksList.class) + @Consumes(TASKSLIST_XML) + @XMLResponseParser(TasksListHandler.class) + ListenableFuture getDefaultTasksList(); + + /** + * @see VCloudExpressClient#deployVApp + */ + @POST + @Consumes(TASK_XML) + @Path("/action/deploy") + @XMLResponseParser(TaskHandler.class) + ListenableFuture deployVApp(@EndpointParam URI vAppId); + + /** + * @see VCloudExpressClient#deleteVApp + */ + @DELETE + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture deleteVApp(@EndpointParam URI vAppId); + + /** + * @see VCloudExpressClient#undeployVApp + */ + @POST + @Consumes(TASK_XML) + @Path("/action/undeploy") + @XMLResponseParser(TaskHandler.class) + ListenableFuture undeployVApp(@EndpointParam URI vAppId); + + /** + * @see VCloudExpressClient#powerOnVApp + */ + @POST + @Consumes(TASK_XML) + @Path("/power/action/powerOn") + @XMLResponseParser(TaskHandler.class) + ListenableFuture powerOnVApp(@EndpointParam URI vAppId); + + /** + * @see VCloudExpressClient#powerOffVApp + */ + @POST + @Consumes(TASK_XML) + @Path("/power/action/powerOff") + @XMLResponseParser(TaskHandler.class) + ListenableFuture powerOffVApp(@EndpointParam URI vAppId); + + /** + * @see VCloudExpressClient#shutdownVApp + */ + @POST + @Path("/power/action/shutdown") + ListenableFuture shutdownVApp(@EndpointParam URI vAppId); + + /** + * @see VCloudExpressClient#resetVApp + */ + @POST + @Consumes(TASK_XML) + @Path("/power/action/reset") + @XMLResponseParser(TaskHandler.class) + ListenableFuture resetVApp(@EndpointParam URI vAppId); + + /** + * @see VCloudExpressClient#suspendVApp + */ + @POST + @Consumes(TASK_XML) + @Path("/power/action/suspend") + @XMLResponseParser(TaskHandler.class) + ListenableFuture suspendVApp(@EndpointParam URI vAppId); + + /** + * @see VCloudExpressClient#getTask + */ + @GET + @Consumes(TASK_XML) + @XMLResponseParser(TaskHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getTask(@EndpointParam URI taskId); + + /** + * @see VCloudExpressClient#cancelTask + */ + @POST + @Path("/action/cancel") + ListenableFuture cancelTask(@EndpointParam URI taskId); + + /** + * @see VCloudExpressClient#findVAppInOrgVDCNamed + */ + @GET + @Consumes(VAPP_XML) + @XMLResponseParser(VAppHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture findVAppInOrgVDCNamed( + @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName, + @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName, + @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName); + + /** + * @see VCloudExpressClient#getVApp + */ + @GET + @Consumes(VAPP_XML) + @XMLResponseParser(VAppHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVApp(@EndpointParam URI vApp); + + /** + * @see VCloudExpressClient#instantiateVAppTemplateInVDC + */ + @POST + @Path("action/instantiateVAppTemplate") + @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") + @Consumes(VAPP_XML) + @XMLResponseParser(VAppHandler.class) + @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) + ListenableFuture instantiateVAppTemplateInVDC(@EndpointParam URI vdc, + @MapPayloadParam("template") URI template, + @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, + InstantiateVAppTemplateOptions... options); + + /** + * @see VCloudExpressClient#cloneVAppInVDC + */ + @POST + @Path("/action/cloneVApp") + @Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml") + @Consumes(TASK_XML) + @XMLResponseParser(TaskHandler.class) + @MapBinder(BindCloneVAppParamsToXmlPayload.class) + ListenableFuture cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone, + @MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, + CloneVAppOptions... options); + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressClient.java new file mode 100644 index 0000000000..ad99254809 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressClient.java @@ -0,0 +1,213 @@ +/** + * + * Copyright (C) 2010 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.vcloud; + +import java.net.URI; +import java.util.NoSuchElementException; +import java.util.concurrent.TimeUnit; + +import javax.annotation.Nullable; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.Network; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.TasksList; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.options.CloneVAppOptions; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; + +/** + * Provides access to VCloud resources via their REST API. + *

+ * + * @see + * @author Adrian Cole + */ +@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) +public interface VCloudExpressClient { + + /** + * Please use {@link #findOrganizationNamed(String)} passing null + */ + @Deprecated + Organization getDefaultOrganization(); + + Organization getOrganization(URI orgId); + + /** + * This call returns a list of all vCloud Data Centers (vdcs), catalogs, and + * task lists within the organization. + * + * @param name + * organization name, or null for the default + * @throws NoSuchElementException + * if you specified an org name that isn't present + */ + Organization findOrganizationNamed(@Nullable String name); + + /** + * Please use #findCatalogInOrgNamed(null, null) + */ + @Deprecated + Catalog getDefaultCatalog(); + + Catalog getCatalog(URI catalogId); + + /** + * returns the catalog in the organization associated with the specified + * name. Note that both parameters can be null to choose default. + * + * @param orgName + * organization name, or null for the default + * @param catalogName + * catalog name, or null for the default + * @throws NoSuchElementException + * if you specified an org or catalog name that isn't present + */ + Catalog findCatalogInOrgNamed(@Nullable String orgName, @Nullable String catalogName); + + CatalogItem getCatalogItem(URI catalogItem); + + /** + * returns the catalog item in the catalog associated with the specified + * name. Note that the org and catalog parameters can be null to choose + * default. + * + * @param orgName + * organization name, or null for the default + * @param catalogName + * catalog name, or null for the default + * @param itemName + * item you wish to lookup + * + * @throws NoSuchElementException + * if you specified an org, catalog, or catalog item name that + * isn't present + */ + CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName); + + VAppTemplate getVAppTemplate(URI vAppTemplate); + + /** + * returns the vapp template corresponding to a catalog item in the catalog + * associated with the specified name. Note that the org and catalog + * parameters can be null to choose default. + * + * @param orgName + * organization name, or null for the default + * @param catalogName + * catalog name, or null for the default + * @param itemName + * item you wish to lookup + * + * @throws NoSuchElementException + * if you specified an org, catalog, or catalog item name that + * isn't present + */ + VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, + String itemName); + + Network findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName); + + Network getNetwork(URI network); + + VDC getVDC(URI vdc); + + /** + * returns the VDC in the organization associated with the specified name. + * Note that both parameters can be null to choose default. + * + * @param orgName + * organization name, or null for the default + * @param vdcName + * catalog name, or null for the default + * @throws NoSuchElementException + * if you specified an org or vdc name that isn't present + */ + VDC findVDCInOrgNamed(String orgName, String vdcName); + + /** + * Please use #findVDCInOrgNamed + */ + @Deprecated + VDC getDefaultVDC(); + + TasksList getTasksList(URI tasksListId); + + TasksList findTasksListInOrgNamed(String orgName, String tasksListName); + + /** + * Please use #getTasksListInOrg(null, null) + */ + @Deprecated + TasksList getDefaultTasksList(); + + Task deployVApp(URI vAppId); + + void deleteVApp(URI vAppId); + + Task undeployVApp(URI vAppId); + + /** + * This call powers on the vApp, as specified in the vApp's ovf:Startup + * element. + */ + Task powerOnVApp(URI vAppId); + + /** + * This call powers off the vApp, as specified in the vApp's ovf:Startup + * element. + */ + Task powerOffVApp(URI vAppId); + + /** + * This call shuts down the vApp. + */ + void shutdownVApp(URI vAppId); + + /** + * This call resets the vApp. + */ + Task resetVApp(URI vAppId); + + /** + * This call suspends the vApp. + */ + Task suspendVApp(URI vAppId); + + Task getTask(URI taskId); + + void cancelTask(URI taskId); + + VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName); + + VApp getVApp(URI vApp); + + VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options); + + Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options); + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressContextBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressContextBuilder.java new file mode 100644 index 0000000000..ec99f5db0d --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressContextBuilder.java @@ -0,0 +1,74 @@ +/** + * + * Copyright (C) 2010 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.vcloud; + +import java.util.List; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.compute.internal.ComputeServiceContextImpl; +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule; +import org.jclouds.vcloud.config.VCloudExpressRestClientModule; + +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * Creates {@link VCloudComputeServiceContext} or {@link Injector} instances based on the most + * commonly requested arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole + * @see VCloudComputeServiceContext + */ +public class VCloudExpressContextBuilder extends ComputeServiceContextBuilder { + + public VCloudExpressContextBuilder(Properties props) { + super(VCloudExpressClient.class, VCloudExpressAsyncClient.class, props); + } + + @Override + protected void addContextModule(List modules) { + modules.add(new VCloudExpressComputeServiceContextModule()); + } + + @Override + protected void addClientModule(List modules) { + modules.add(new VCloudExpressRestClientModule()); + } + + @Override + public ComputeServiceContext buildComputeServiceContext() { + // need the generic type information + return (ComputeServiceContext) this.buildInjector().getInstance( + Key.get(new TypeLiteral>() { + })); + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressMediaType.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressMediaType.java new file mode 100644 index 0000000000..115de8d915 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressMediaType.java @@ -0,0 +1,42 @@ +/** + * + * Copyright (C) 2010 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.vcloud; + +import javax.ws.rs.core.MediaType; + +/** + * Resource Types used in VCloud express + * + * @see MediaType + */ +public interface VCloudExpressMediaType extends VCloudMediaType { + + /** + * "application/vnd.vmware.vcloud.organizationList+xml" + */ + public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.organizationList+xml"; + + /** + * "application/vnd.vmware.vcloud.organizationList+xml" + */ + public final static MediaType ORGLIST_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.organizationList+xml"); + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressPropertiesBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressPropertiesBuilder.java new file mode 100644 index 0000000000..d964e99bb8 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudExpressPropertiesBuilder.java @@ -0,0 +1,90 @@ +/** + * + * Copyright (C) 2010 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.vcloud; + +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; + +import java.util.Properties; + +import org.jclouds.PropertiesBuilder; +import org.jclouds.vcloud.domain.FenceMode; + +/** + * Builds properties used in VCloud Clients + * + * @author Adrian Cole + */ +public class VCloudExpressPropertiesBuilder extends PropertiesBuilder { + @Override + protected Properties defaultProperties() { + Properties properties = super.defaultProperties(); + properties.setProperty(PROPERTY_API_VERSION, "0.8"); + properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8"); + properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + ""); + properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, + "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); + properties.setProperty("jclouds.dns_name_length_min", "1"); + properties.setProperty("jclouds.dns_name_length_max", "80"); + properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 180l * 1000l + ""); + return properties; + } + + public VCloudExpressPropertiesBuilder(Properties properties) { + super(properties); + } + + protected void setNs() { + if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null) + properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v" + + properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA)); + } + + protected void setFenceMode() { + if (properties.getProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) == null) { + if (properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA).startsWith("0.8")) + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, "allowInOut"); + else + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED); + } + } + + public VCloudExpressPropertiesBuilder withApiVersion(String version) { + properties.setProperty(PROPERTY_API_VERSION, "0.8"); + return this; + } + + public VCloudExpressPropertiesBuilder withSchemaVersion(String version) { + properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8"); + return this; + } + + @Override + public Properties build() { + setNs(); + setFenceMode(); + return super.build(); + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java index 6747db515c..1d7f54be2a 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java @@ -22,31 +22,29 @@ package org.jclouds.vcloud; import javax.ws.rs.core.MediaType; /** - * Resource Types used in VCloud express + * Resource Types used in VCloud * * @see MediaType */ public interface VCloudMediaType { /** - * "application/vnd.vmware.vcloud.organizationList+xml" + * "application/vnd.vmware.vcloud.vcloud+xml" */ public final static String VCLOUD_XML = "application/vnd.vmware.vcloud.vcloud+xml"; /** - * "application/vnd.vmware.vcloud.organizationList+xml" + * "application/vnd.vmware.vcloud.vcloud+xml" */ - public final static MediaType VCLOUD_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.vcloud+xml"); + public final static MediaType VCLOUD_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vcloud+xml"); /** - * "application/vnd.vmware.vcloud.organizationList+xml" + * "application/vnd.vmware.vcloud.orgList+xml" */ - public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.organizationList+xml"; + public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml"; /** - * "application/vnd.vmware.vcloud.organizationList+xml" + * "application/vnd.vmware.vcloud.orgList+xml" */ - public final static MediaType ORGLIST_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.organizationList+xml"); + public final static MediaType ORGLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.orgList+xml"); /** * "application/vnd.vmware.vcloud.org+xml" */ @@ -54,8 +52,7 @@ public interface VCloudMediaType { /** * "application/vnd.vmware.vcloud.org+xml" */ - public final static MediaType ORG_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.org+xml"); + public final static MediaType ORG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.org+xml"); /** * "application/vnd.vmware.vcloud.vdc+xml" @@ -64,8 +61,7 @@ public interface VCloudMediaType { /** * "application/vnd.vmware.vcloud.vdc+xml" */ - public final static MediaType VDC_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.vdc+xml"); + public final static MediaType VDC_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vdc+xml"); /** * "application/vnd.vmware.vcloud.catalog+xml" @@ -74,8 +70,7 @@ public interface VCloudMediaType { /** * "application/vnd.vmware.vcloud.catalog+xml" */ - public final static MediaType CATALOG_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.catalog+xml"); + public final static MediaType CATALOG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.catalog+xml"); /** * "application/vnd.vmware.vcloud.tasksList+xml" @@ -84,8 +79,7 @@ public interface VCloudMediaType { /** * "application/vnd.vmware.vcloud.tasksList+xml" */ - public final static MediaType TASKSLIST_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.tasksList+xml"); + public final static MediaType TASKSLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.tasksList+xml"); /** * "application/vnd.vmware.vcloud.catalogItem+xml" @@ -104,8 +98,7 @@ public interface VCloudMediaType { /** * "application/vnd.vmware.vcloud.task+xml" */ - public final static MediaType TASK_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.task+xml"); + public final static MediaType TASK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.task+xml"); /** * "application/vnd.vmware.vcloud.vApp+xml" @@ -114,8 +107,7 @@ public interface VCloudMediaType { /** * "application/vnd.vmware.vcloud.vApp+xml" */ - public final static MediaType VAPP_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.vApp+xml"); + public final static MediaType VAPP_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vApp+xml"); /** * "application/vnd.vmware.vcloud.vAppTemplate+xml" @@ -134,7 +126,6 @@ public interface VCloudMediaType { /** * "application/vnd.vmware.vcloud.network+xml" */ - public final static MediaType NETWORK_XML_TYPE = new MediaType("application", - "vnd.vmware.vcloud.network+xml"); + public final static MediaType NETWORK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.network+xml"); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java index 2831f23b07..a357ab9bc8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java @@ -41,13 +41,14 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_API_VERSION, "0.8"); - properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8"); + properties.setProperty(PROPERTY_API_VERSION, "1.0"); + properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1.0"); properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + ""); properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); properties.setProperty("jclouds.dns_name_length_min", "1"); properties.setProperty("jclouds.dns_name_length_max", "80"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED); properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 180l * 1000l + ""); return properties; } @@ -62,29 +63,20 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder { + properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA)); } - protected void setFenceMode() { - if (properties.getProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) == null) { - if (properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA).startsWith("0.8")) - properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, "allowInOut"); - else - properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED); - } - } public VCloudPropertiesBuilder withApiVersion(String version) { - properties.setProperty(PROPERTY_API_VERSION, "0.8"); + properties.setProperty(PROPERTY_API_VERSION, "1.0"); return this; } public VCloudPropertiesBuilder withSchemaVersion(String version) { - properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8"); + properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1.0"); return this; } @Override public Properties build() { setNs(); - setFenceMode(); return super.build(); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayload.java b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayload.java index 22542ab9d3..fb5d8ecf09 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayload.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayload.java @@ -38,7 +38,7 @@ import org.jclouds.http.HttpRequest; import org.jclouds.rest.MapBinder; import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.options.CloneVAppOptions; import com.google.inject.Inject; @@ -95,7 +95,7 @@ public class BindCloneVAppParamsToXmlPayload implements MapBinder { XMLBuilder rootBuilder = buildRoot(newName, options.isDeploy(), options.isPowerOn()); if (options.getDescription() != null) rootBuilder.e("Description").text(options.getDescription()); - rootBuilder.e("VApp").a("href", vApp).a("type", VCloudMediaType.VAPP_XML); + rootBuilder.e("VApp").a("href", vApp).a("type", VCloudExpressMediaType.VAPP_XML); Properties outputProperties = new Properties(); outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); return rootBuilder.asString(outputProperties); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java index 61e5ad1c89..3970622875 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java @@ -63,7 +63,7 @@ public class BaseVCloudComputeClient implements VCloudComputeClient { @Inject public BaseVCloudComputeClient(VCloudClient client, Predicate successTester, - Map vAppStatusToNodeState) { + Map vAppStatusToNodeState) { this.client = client; this.taskTester = successTester; this.vAppStatusToNodeState = vAppStatusToNodeState; @@ -71,7 +71,7 @@ public class BaseVCloudComputeClient implements VCloudComputeClient { @Override public Map start(@Nullable URI VDC, URI templateId, String name, - InstantiateVAppTemplateOptions options, int... portsToOpen) { + InstantiateVAppTemplateOptions options, int... portsToOpen) { checkNotNull(options, "options"); logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options); @@ -175,7 +175,7 @@ public class BaseVCloudComputeClient implements VCloudComputeClient { public TaskException(String type, VApp vApp, Task task) { super(String.format("failed to %s vApp %s status %s;task %s status %s", type, vApp.getName(), - vApp.getStatus(), task.getLocation(), task.getStatus()), vApp); + vApp.getStatus(), task.getLocation(), task.getStatus()), vApp); this.task = task; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudExpressComputeClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudExpressComputeClient.java new file mode 100644 index 0000000000..38cbca0732 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudExpressComputeClient.java @@ -0,0 +1,216 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import java.net.URI; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Nullable; +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.google.inject.Inject; + +/** + * @author Adrian Cole + */ +@Singleton +public class BaseVCloudExpressComputeClient implements VCloudExpressComputeClient { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + protected final VCloudExpressClient client; + protected final Predicate taskTester; + protected final Map vAppStatusToNodeState; + + @Inject + public BaseVCloudExpressComputeClient(VCloudExpressClient client, Predicate successTester, + Map vAppStatusToNodeState) { + this.client = client; + this.taskTester = successTester; + this.vAppStatusToNodeState = vAppStatusToNodeState; + } + + @Override + public Map start(@Nullable URI VDC, URI templateId, String name, + InstantiateVAppTemplateOptions options, int... portsToOpen) { + checkNotNull(options, "options"); + logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options); + + VDC vdc = client.getVDC(VDC); + VAppTemplate template = client.getVAppTemplate(templateId); + + VApp vAppResponse = client.instantiateVAppTemplateInVDC(vdc.getId(), template.getId(), name, options); + logger.debug("<< instantiated VApp(%s)", vAppResponse.getName()); + + logger.debug(">> deploying vApp(%s)", vAppResponse.getName()); + + Task task = client.deployVApp(vAppResponse.getId()); + if (options.shouldBlockOnDeploy()) { + if (!taskTester.apply(task.getLocation())) { + throw new TaskException("deploy", vAppResponse, task); + } + logger.debug("<< deployed vApp(%s)", vAppResponse.getName()); + + logger.debug(">> powering vApp(%s)", vAppResponse.getName()); + task = client.powerOnVApp(vAppResponse.getId()); + if (!taskTester.apply(task.getLocation())) { + throw new TaskException("powerOn", vAppResponse, task); + } + logger.debug("<< on vApp(%s)", vAppResponse.getName()); + } + return parseAndValidateResponse(template, vAppResponse); + } + + protected Map parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) { + Map response = parseResponse(template, vAppResponse); + checkState(response.containsKey("id"), "bad configuration: [id] should be in response"); + checkState(response.containsKey("username"), "bad configuration: [username] should be in response"); + checkState(response.containsKey("password"), "bad configuration: [password] should be in response"); + return response; + } + + protected Map parseResponse(VAppTemplate template, VApp vAppResponse) { + Map config = Maps.newLinkedHashMap();// Allows nulls + config.put("id", vAppResponse.getId().toASCIIString()); + config.put("username", null); + config.put("password", null); + return config; + } + + @Override + public void reboot(URI id) { + VApp vApp = client.getVApp(id); + logger.debug(">> resetting vApp(%s)", vApp.getName()); + Task task = client.resetVApp(vApp.getId()); + if (!taskTester.apply(task.getLocation())) { + throw new TaskException("resetVApp", vApp, task); + } + logger.debug("<< on vApp(%s)", vApp.getName()); + } + + @Override + public void stop(URI id) { + VApp vApp = client.getVApp(id); + vApp = powerOffVAppIfDeployed(vApp); + vApp = undeployVAppIfDeployed(vApp); + deleteVApp(vApp); + logger.debug("<< deleted vApp(%s)", vApp.getName()); + } + + private void deleteVApp(VApp vApp) { + logger.debug(">> deleting vApp(%s)", vApp.getName()); + client.deleteVApp(vApp.getId()); + } + + private VApp undeployVAppIfDeployed(VApp vApp) { + if (vApp.getStatus().compareTo(VAppStatus.RESOLVED) > 0) { + logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), vApp.getStatus()); + Task task = client.undeployVApp(vApp.getId()); + if (!taskTester.apply(task.getLocation())) { + throw new TaskException("undeploy", vApp, task); + } + vApp = client.getVApp(vApp.getId()); + logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName()); + } + return vApp; + } + + private VApp powerOffVAppIfDeployed(VApp vApp) { + if (vApp.getStatus().compareTo(VAppStatus.OFF) > 0) { + logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus()); + Task task = client.powerOffVApp(vApp.getId()); + if (!taskTester.apply(task.getLocation())) { + throw new TaskException("powerOff", vApp, task); + } + vApp = client.getVApp(vApp.getId()); + logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName()); + } + return vApp; + } + + public static class TaskException extends VAppException { + + private final Task task; + /** The serialVersionUID */ + private static final long serialVersionUID = 251801929573211256L; + + public TaskException(String type, VApp vApp, Task task) { + super(String.format("failed to %s vApp %s status %s;task %s status %s", type, vApp.getName(), + vApp.getStatus(), task.getLocation(), task.getStatus()), vApp); + this.task = task; + } + + public Task getTask() { + return task; + } + + } + + public static class VAppException extends RuntimeException { + + private final VApp vApp; + /** The serialVersionUID */ + private static final long serialVersionUID = 251801929573211256L; + + public VAppException(String message, VApp vApp) { + super(message); + this.vApp = vApp; + } + + public VApp getvApp() { + return vApp; + } + + } + + @Override + public Set getPrivateAddresses(URI id) { + return ImmutableSet.of(); + } + + @Override + public Set getPublicAddresses(URI id) { + VApp vApp = client.getVApp(id); + return Sets.newHashSet(vApp.getNetworkToAddresses().values()); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudExpressComputeClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudExpressComputeClient.java new file mode 100644 index 0000000000..516a8d7a81 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudExpressComputeClient.java @@ -0,0 +1,101 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute; + +import java.net.URI; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Nullable; + +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; + +import com.google.inject.ImplementedBy; + +/** + * + * @author Adrian Cole + */ +@ImplementedBy(BaseVCloudExpressComputeClient.class) +public interface VCloudExpressComputeClient { + /** + * Runs through all commands necessary to startup a vApp, opening at least + * one ip address to the public network. These are the steps: + *

+ * instantiate -> deploy -> powerOn + *

+ * This command blocks until the vApp is in state {@code VAppStatus#ON} + * + * @param VDC + * id of the virtual datacenter {@code VCloudClient#getDefaultVDC} + * @param templateId + * id of the vAppTemplate you wish to instantiate + * @param name + * name of the vApp + * @param cores + * amount of virtual cpu cores + * @param megs + * amount of ram in megabytes + * @param options + * options for instantiating the vApp; null is ok + * @param portsToOpen + * opens the following ports on the public ip address + * @return map contains at least the following properties + *

    + *
  1. id - vApp id
  2. username - console login user
  3. + * password - console login password
  4. + *
+ */ + Map start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options, + int... portsToOpen); + + /** + * returns a set of addresses that are only visible to the private network. + */ + Set getPrivateAddresses(URI vAppId); + + /** + * returns a set of addresses that are publically visible + */ + Set getPublicAddresses(URI vAppId); + + /** + * reboots the vApp, blocking until the following state transition is + * complete: + *

+ * current -> {@code VAppStatus#OFF} -> {@code VAppStatus#ON} + * + * @param vAppId + * vApp to reboot + */ + void reboot(URI vAppId); + + /** + * Destroys dependent resources, powers off and deletes the vApp, blocking + * until the following state transition is complete: + *

+ * current -> {@code VAppStatus#OFF} -> deleted + * + * @param vAppId + * vApp to stop + */ + void stop(URI vAppId); + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java new file mode 100644 index 0000000000..6410bfdc89 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java @@ -0,0 +1,92 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute.config; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Singleton; + +import org.jclouds.compute.LoadBalancerService; +import org.jclouds.compute.config.BaseComputeServiceContextModule; +import org.jclouds.compute.config.ComputeServiceTimeoutsModule; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.Size; +import org.jclouds.domain.Location; +import org.jclouds.vcloud.compute.BaseVCloudComputeClient; +import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier; +import org.jclouds.vcloud.compute.suppliers.StaticSizeSupplier; +import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier; +import org.jclouds.vcloud.domain.VAppStatus; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.inject.Injector; +import com.google.inject.Provides; +import com.google.inject.util.Providers; + +/** + * Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient} + * bound. + * + * @author Adrian Cole + */ +public class CommonVCloudComputeServiceContextModule extends BaseComputeServiceContextModule { + + @VisibleForTesting + static final Map vAppStatusToNodeState = ImmutableMap. builder().put( + VAppStatus.OFF, NodeState.SUSPENDED).put(VAppStatus.ON, NodeState.RUNNING).put(VAppStatus.RESOLVED, + NodeState.PENDING).put(VAppStatus.SUSPENDED, NodeState.SUSPENDED).put(VAppStatus.UNRESOLVED, + NodeState.PENDING).build(); + + @Singleton + @Provides + Map provideVAppStatusToNodeState() { + return vAppStatusToNodeState; + } + + @Override + protected void configure() { + install(new ComputeServiceTimeoutsModule()); + bindLoadBalancer(); + } + + protected void bindLoadBalancer() { + bind(LoadBalancerService.class).toProvider(Providers. of(null)); + } + + @Override + protected Supplier> getSourceImageSupplier(Injector injector) { + return injector.getInstance(VCloudImageSupplier.class); + } + + @Override + protected Supplier> getSourceLocationSupplier(Injector injector) { + return injector.getInstance(OrgAndVDCToLocationSupplier.class); + } + + @Override + protected Supplier> getSourceSizeSupplier(Injector injector) { + return injector.getInstance(StaticSizeSupplier.class); + } + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java old mode 100755 new mode 100644 index 8f800bcf91..623ff2cf1a --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -19,18 +19,7 @@ package org.jclouds.vcloud.compute.config; -import java.util.Map; -import java.util.Set; - -import javax.inject.Singleton; - import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.LoadBalancerService; -import org.jclouds.compute.config.BaseComputeServiceContextModule; -import org.jclouds.compute.config.ComputeServiceTimeoutsModule; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeState; -import org.jclouds.compute.domain.Size; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy; @@ -39,10 +28,8 @@ import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; -import org.jclouds.domain.Location; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; -import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.BaseVCloudComputeClient; import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy; @@ -50,19 +37,9 @@ import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy; import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy; -import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier; -import org.jclouds.vcloud.compute.suppliers.StaticSizeSupplier; -import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier; -import org.jclouds.vcloud.domain.VAppStatus; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; -import com.google.inject.Injector; -import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; -import com.google.inject.util.Providers; /** * Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient} @@ -70,55 +47,22 @@ import com.google.inject.util.Providers; * * @author Adrian Cole */ -public class VCloudComputeServiceContextModule extends BaseComputeServiceContextModule { - - @VisibleForTesting - static final Map vAppStatusToNodeState = ImmutableMap. builder().put( - VAppStatus.OFF, NodeState.SUSPENDED).put(VAppStatus.ON, NodeState.RUNNING).put(VAppStatus.RESOLVED, - NodeState.PENDING).put(VAppStatus.SUSPENDED, NodeState.SUSPENDED).put(VAppStatus.UNRESOLVED, - NodeState.PENDING).build(); - - @Singleton - @Provides - Map provideVAppStatusToNodeState() { - return vAppStatusToNodeState; - } +public class VCloudComputeServiceContextModule extends CommonVCloudComputeServiceContextModule { @Override protected void configure() { - install(new ComputeServiceTimeoutsModule()); - bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class); + super.configure(); bind(new TypeLiteral() { - }).to(new TypeLiteral>() { + }).to(new TypeLiteral>() { }).in(Scopes.SINGLETON); - bind(new TypeLiteral>() { - }).to(new TypeLiteral>() { + bind(new TypeLiteral>() { + }).to(new TypeLiteral>() { }).in(Scopes.SINGLETON); + bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class); + bind(DestroyNodeStrategy.class).to(VCloudDestroyNodeStrategy.class); bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class); bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class); bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class); bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class); - bind(DestroyNodeStrategy.class).to(VCloudDestroyNodeStrategy.class); - bindLoadBalancer(); } - - protected void bindLoadBalancer() { - bind(LoadBalancerService.class).toProvider(Providers. of(null)); - } - - @Override - protected Supplier> getSourceImageSupplier(Injector injector) { - return injector.getInstance(VCloudImageSupplier.class); - } - - @Override - protected Supplier> getSourceLocationSupplier(Injector injector) { - return injector.getInstance(OrgAndVDCToLocationSupplier.class); - } - - @Override - protected Supplier> getSourceSizeSupplier(Injector injector) { - return injector.getInstance(StaticSizeSupplier.class); - } - } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModule.java new file mode 100755 index 0000000000..688050440d --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModule.java @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute.config; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.internal.ComputeServiceContextImpl; +import org.jclouds.compute.strategy.AddNodeWithTagStrategy; +import org.jclouds.compute.strategy.DestroyNodeStrategy; +import org.jclouds.compute.strategy.GetNodeMetadataStrategy; +import org.jclouds.compute.strategy.ListNodesStrategy; +import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; +import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.RestContextImpl; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient; +import org.jclouds.vcloud.compute.strategy.VCloudExpressAddNodeWithTagStrategy; +import org.jclouds.vcloud.compute.strategy.VCloudExpressDestroyNodeStrategy; +import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy; +import org.jclouds.vcloud.compute.strategy.VCloudExpressListNodesStrategy; +import org.jclouds.vcloud.compute.strategy.VCloudExpressRebootNodeStrategy; + +import com.google.inject.Scopes; +import com.google.inject.TypeLiteral; + +/** + * Configures the {@link VCloudComputeServiceContext}; requires + * {@link BaseVCloudExpressComputeClient} bound. + * + * @author Adrian Cole + */ +public class VCloudExpressComputeServiceContextModule extends CommonVCloudComputeServiceContextModule { + + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral() { + }).to(new TypeLiteral>() { + }).in(Scopes.SINGLETON); + bind(new TypeLiteral>() { + }).to(new TypeLiteral>() { + }).in(Scopes.SINGLETON); + bind(AddNodeWithTagStrategy.class).to(VCloudExpressAddNodeWithTagStrategy.class); + bind(DestroyNodeStrategy.class).to(VCloudExpressDestroyNodeStrategy.class); + bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class); + bind(ListNodesStrategy.class).to(VCloudExpressListNodesStrategy.class); + bind(GetNodeMetadataStrategy.class).to(VCloudExpressGetNodeMetadataStrategy.class); + bind(RebootNodeStrategy.class).to(VCloudExpressRebootNodeStrategy.class); + } + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/GetExtra.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/GetExtra.java index 3661c0ae9d..21648b4832 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/GetExtra.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/GetExtra.java @@ -31,7 +31,7 @@ import javax.annotation.Resource; import javax.inject.Singleton; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.compute.BaseVCloudComputeClient; +import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient; import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.VApp; @@ -40,7 +40,7 @@ import com.google.common.base.Function; /** * Configures the {@link VCloudComputeServiceContext}; requires - * {@link BaseVCloudComputeClient} bound. + * {@link BaseVCloudExpressComputeClient} bound. * * @author Adrian Cole */ diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInOrganization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInOrganization.java index fa865f7d6c..6724eb69d2 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInOrganization.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImagesInOrganization.java @@ -28,7 +28,6 @@ import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.functions.AllCatalogItemsInOrganization; -import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems; import com.google.common.base.Function; import com.google.common.collect.Iterables; @@ -40,13 +39,13 @@ import com.google.common.collect.Iterables; public class ImagesInOrganization implements Function> { private final AllCatalogItemsInOrganization allCatalogItemsInOrganization; - private final VAppTemplatesForCatalogItems vAppTemplatesForCatalogItems; + private final Function, Iterable> vAppTemplatesForCatalogItems; private final Provider imageForVAppTemplateProvider; @Inject ImagesInOrganization(AllCatalogItemsInOrganization allCatalogItemsInOrganization, Provider imageForVAppTemplateProvider, - VAppTemplatesForCatalogItems vAppTemplatesForCatalogItems) { + Function, Iterable> vAppTemplatesForCatalogItems) { this.imageForVAppTemplateProvider = imageForVAppTemplateProvider; this.allCatalogItemsInOrganization = allCatalogItemsInOrganization; this.vAppTemplatesForCatalogItems = vAppTemplatesForCatalogItems; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressAddNodeWithTagStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressAddNodeWithTagStrategy.java new file mode 100644 index 0000000000..b62872f063 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressAddNodeWithTagStrategy.java @@ -0,0 +1,89 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute.strategy; + +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.internal.NodeMetadataImpl; +import org.jclouds.compute.domain.os.CIMOperatingSystem; +import org.jclouds.compute.strategy.AddNodeWithTagStrategy; +import org.jclouds.domain.Credentials; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.compute.VCloudExpressComputeClient; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrategy { + protected final VCloudExpressClient client; + protected final VCloudExpressComputeClient computeClient; + protected final Map vAppStatusToNodeState; + + @Inject + protected VCloudExpressAddNodeWithTagStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient, + Map vAppStatusToNodeState) { + this.client = client; + this.computeClient = computeClient; + this.vAppStatusToNodeState = vAppStatusToNodeState; + } + + @Override + public NodeMetadata execute(String tag, String name, Template template) { + InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue()) + .memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l); + if (!template.getOptions().shouldBlockUntilRunning()) + options.blockOnDeploy(false); + Map metaMap = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template + .getImage().getId()), name, options, template.getOptions().getInboundPorts()); + VApp vApp = client.getVApp(URI.create(metaMap.get("id"))); + return newCreateNodeResponse(tag, template, metaMap, vApp); + } + + protected NodeMetadata newCreateNodeResponse(String tag, Template template, Map metaMap, VApp vApp) { + return new NodeMetadataImpl(vApp.getId().toASCIIString(), vApp.getName(), vApp.getId().toASCIIString(), template + .getLocation(), vApp.getId(), ImmutableMap. of(), tag, template.getImage().getId(), + getOperatingSystemForVAppOrDefaultTo(vApp, template.getImage().getOperatingSystem()), + vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(vApp.getId()), + computeClient.getPrivateAddresses(vApp.getId()), ImmutableMap. of(), new Credentials( + metaMap.get("username"), metaMap.get("password"))); + } + + private OperatingSystem getOperatingSystemForVAppOrDefaultTo(VApp vApp, OperatingSystem operatingSystem) { + return vApp.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(vApp.getOsType()), + null, null, vApp.getOperatingSystemDescription()) : operatingSystem; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressDestroyNodeStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressDestroyNodeStrategy.java new file mode 100644 index 0000000000..43ebb452a8 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressDestroyNodeStrategy.java @@ -0,0 +1,55 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.strategy.DestroyNodeStrategy; +import org.jclouds.compute.strategy.GetNodeMetadataStrategy; +import org.jclouds.vcloud.compute.VCloudExpressComputeClient; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressDestroyNodeStrategy implements DestroyNodeStrategy { + protected final VCloudExpressComputeClient computeClient; + protected final GetNodeMetadataStrategy getNode; + + @Inject + protected VCloudExpressDestroyNodeStrategy(VCloudExpressComputeClient computeClient, GetNodeMetadataStrategy getNode) { + this.computeClient = computeClient; + this.getNode = getNode; + + } + + @Override + public NodeMetadata execute(String id) { + computeClient.stop(URI.create(checkNotNull(id, "node.id"))); + return getNode.execute(id); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressGetNodeMetadataStrategy.java similarity index 84% rename from vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressGetNodeMetadataStrategy.java index 131698ec59..cae361c8a8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressGetNodeMetadataStrategy.java @@ -17,7 +17,7 @@ * ==================================================================== */ -package org.jclouds.vcloud.compute.functions; +package org.jclouds.vcloud.compute.strategy; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; @@ -37,11 +37,13 @@ import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.os.CIMOperatingSystem; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.domain.Location; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.compute.BaseVCloudComputeClient; -import org.jclouds.vcloud.compute.VCloudComputeClient; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.compute.VCloudExpressComputeClient; +import org.jclouds.vcloud.compute.functions.FindLocationForResource; +import org.jclouds.vcloud.compute.functions.GetExtra; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; @@ -49,26 +51,23 @@ import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; /** - * Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient} - * bound. - * * @author Adrian Cole */ @Singleton -public class VCloudGetNodeMetadata { +public class VCloudExpressGetNodeMetadataStrategy implements GetNodeMetadataStrategy { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; - protected final VCloudClient client; - protected final VCloudComputeClient computeClient; + protected final VCloudExpressClient client; + protected final VCloudExpressComputeClient computeClient; protected final Supplier> images; protected final FindLocationForResource findLocationForResourceInVDC; protected final GetExtra getExtra; protected final Map vAppStatusToNodeState; @Inject - VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient, + protected VCloudExpressGetNodeMetadataStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient, Map vAppStatusToNodeState, GetExtra getExtra, FindLocationForResource findLocationForResourceInVDC, Supplier> images) { this.client = checkNotNull(client, "client"); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressListNodesStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressListNodesStrategy.java new file mode 100644 index 0000000000..12bb9ae52d --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressListNodesStrategy.java @@ -0,0 +1,141 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute.strategy; + +import static org.jclouds.compute.reference.ComputeServiceConstants.COMPUTE_LOGGER; +import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_BLACKLIST_NODES; + +import java.util.Map; +import java.util.Set; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.ComputeType; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.internal.ComputeMetadataImpl; +import org.jclouds.compute.strategy.ListNodesStrategy; +import org.jclouds.domain.Location; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.VCloudExpressMediaType; +import org.jclouds.vcloud.compute.functions.FindLocationForResource; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.endpoints.Org; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Predicate; +import com.google.common.base.Splitter; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Sets; +import com.google.inject.Inject; +import com.google.inject.internal.util.ImmutableSet; + +/** + * @author Adrian Cole + */ +// TODO REFACTOR!!! needs to be parallel +@Singleton +public class VCloudExpressListNodesStrategy implements ListNodesStrategy { + @Resource + @Named(COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + protected final VCloudExpressGetNodeMetadataStrategy getNodeMetadata; + protected final VCloudExpressClient client; + protected final FindLocationForResource findLocationForResourceInVDC; + Set blackListVAppNames = ImmutableSet. of(); + + @Inject(optional = true) + void setBlackList(@Named(PROPERTY_BLACKLIST_NODES) String blackListNodes) { + if (blackListNodes != null && !"".equals(blackListNodes)) + this.blackListVAppNames = ImmutableSet.copyOf(Splitter.on(',').split(blackListNodes)); + } + + private final Supplier> orgNameToEndpoint; + + @Inject + protected VCloudExpressListNodesStrategy(VCloudExpressClient client, + @Org Supplier> orgNameToEndpoint, + VCloudExpressGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) { + this.client = client; + this.orgNameToEndpoint = orgNameToEndpoint; + this.getNodeMetadata = getNodeMetadata; + this.findLocationForResourceInVDC = findLocationForResourceInVDC; + } + + @Override + public Iterable list() { + Set nodes = Sets.newHashSet(); + for (String org : orgNameToEndpoint.get().keySet()) { + for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) { + for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) { + if (validVApp(resource)) { + nodes.add(convertVAppToComputeMetadata(vdc, resource)); + } + } + } + } + return nodes; + } + + private boolean validVApp(NamedResource resource) { + return resource.getType().equals(VCloudExpressMediaType.VAPP_XML) + && !blackListVAppNames.contains(resource.getName()); + } + + private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc, NamedResource resource) { + Location location = findLocationForResourceInVDC.apply(vdc); + return new ComputeMetadataImpl(ComputeType.NODE, resource.getId().toASCIIString(), resource.getName(), resource + .getId().toASCIIString(), location, null, ImmutableMap. of()); + } + + @Override + public Iterable listDetailsOnNodesMatching(Predicate filter) { + Set nodes = Sets.newHashSet(); + for (String org : orgNameToEndpoint.get().keySet()) { + for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) { + for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) { + if (validVApp(resource) && filter.apply(convertVAppToComputeMetadata(vdc, resource))) { + addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource); + } + } + } + } + return nodes; + } + + @VisibleForTesting + void addVAppToSetRetryingIfNotYetPresent(Set nodes, NamedResource vdc, NamedResource resource) { + NodeMetadata node = null; + int i = 0; + while (node == null && i++ < 3) { + try { + node = getNodeMetadata.execute(resource.getId().toASCIIString()); + nodes.add(node); + } catch (NullPointerException e) { + logger.warn("vApp %s not yet present in vdc %s", resource.getName(), vdc.getName()); + } + } + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressRebootNodeStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressRebootNodeStrategy.java new file mode 100644 index 0000000000..ee09736728 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressRebootNodeStrategy.java @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.strategy.GetNodeMetadataStrategy; +import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.domain.Task; + +import com.google.common.base.Predicate; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressRebootNodeStrategy implements RebootNodeStrategy { + private final VCloudExpressClient client; + protected final Predicate taskTester; + protected final GetNodeMetadataStrategy getNode; + + @Inject + protected VCloudExpressRebootNodeStrategy(VCloudExpressClient client, Predicate taskTester, GetNodeMetadataStrategy getNode) { + this.client = client; + this.taskTester = taskTester; + this.getNode = getNode; + } + + @Override + public NodeMetadata execute(String in) { + URI id = URI.create(checkNotNull(in, "node.id")); + Task task = client.resetVApp(id); + taskTester.apply(task.getLocation()); + return getNode.execute(in); + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudGetNodeMetadataStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudGetNodeMetadataStrategy.java index 8bfa0b70eb..18b5ee6271 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudGetNodeMetadataStrategy.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudGetNodeMetadataStrategy.java @@ -20,30 +20,75 @@ package org.jclouds.vcloud.compute.strategy; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; +import java.net.URI; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Resource; import javax.inject.Inject; +import javax.inject.Named; import javax.inject.Singleton; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.internal.NodeMetadataImpl; +import org.jclouds.compute.domain.os.CIMOperatingSystem; +import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata; +import org.jclouds.domain.Location; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.compute.VCloudComputeClient; +import org.jclouds.vcloud.compute.functions.FindLocationForResource; +import org.jclouds.vcloud.compute.functions.GetExtra; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppStatus; + +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; /** * @author Adrian Cole */ @Singleton public class VCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy { - - protected final VCloudGetNodeMetadata getNodeMetadata; + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + protected final VCloudClient client; + protected final VCloudComputeClient computeClient; + protected final Supplier> images; + protected final FindLocationForResource findLocationForResourceInVDC; + protected final GetExtra getExtra; + protected final Map vAppStatusToNodeState; @Inject - protected VCloudGetNodeMetadataStrategy(VCloudGetNodeMetadata getNodeMetadata) { - this.getNodeMetadata = getNodeMetadata; + VCloudGetNodeMetadataStrategy(VCloudClient client, VCloudComputeClient computeClient, + Map vAppStatusToNodeState, GetExtra getExtra, + FindLocationForResource findLocationForResourceInVDC, Supplier> images) { + this.client = checkNotNull(client, "client"); + this.images = checkNotNull(images, "images"); + this.getExtra = checkNotNull(getExtra, "getExtra"); + this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC"); + this.computeClient = checkNotNull(computeClient, "computeClient"); + this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState"); } - @Override - public NodeMetadata execute(String id) { - return getNodeMetadata.execute(checkNotNull(id, "node.id")); + public NodeMetadata execute(String in) { + URI id = URI.create(in); + VApp from = client.getVApp(id); + if (from == null) + return null; + String tag = parseTagFromName(from.getName()); + Location location = findLocationForResourceInVDC.apply(from.getVDC()); + return new NodeMetadataImpl(in, from.getName(), in, location, from.getId(), ImmutableMap. of(), + tag, null, from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(from + .getOsType()), null, null, from.getOperatingSystemDescription()) : null, vAppStatusToNodeState + .get(from.getStatus()), computeClient.getPublicAddresses(id), computeClient + .getPrivateAddresses(id), getExtra.apply(from), null); } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java index 661d965f2e..00abf0da97 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudListNodesStrategy.java @@ -39,7 +39,6 @@ import org.jclouds.logging.Logger; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.compute.functions.FindLocationForResource; -import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.endpoints.Org; @@ -55,13 +54,13 @@ import com.google.inject.internal.util.ImmutableSet; /** * @author Adrian Cole */ -//TODO REFACTOR!!! needs to be parallel +// TODO REFACTOR!!! needs to be parallel @Singleton public class VCloudListNodesStrategy implements ListNodesStrategy { @Resource @Named(COMPUTE_LOGGER) public Logger logger = Logger.NULL; - protected final VCloudGetNodeMetadata getNodeMetadata; + protected final VCloudGetNodeMetadataStrategy getNodeMetadata; protected final VCloudClient client; protected final FindLocationForResource findLocationForResourceInVDC; Set blackListVAppNames = ImmutableSet. of(); @@ -76,7 +75,7 @@ public class VCloudListNodesStrategy implements ListNodesStrategy { @Inject protected VCloudListNodesStrategy(VCloudClient client, @Org Supplier> orgNameToEndpoint, - VCloudGetNodeMetadata getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) { + VCloudGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) { this.client = client; this.orgNameToEndpoint = orgNameToEndpoint; this.getNodeMetadata = getNodeMetadata; @@ -104,8 +103,8 @@ public class VCloudListNodesStrategy implements ListNodesStrategy { private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc, NamedResource resource) { Location location = findLocationForResourceInVDC.apply(vdc); - return new ComputeMetadataImpl(ComputeType.NODE, resource.getId().toASCIIString(), resource.getName(), - resource.getId().toASCIIString(), location, null, ImmutableMap. of()); + return new ComputeMetadataImpl(ComputeType.NODE, resource.getId().toASCIIString(), resource.getName(), resource + .getId().toASCIIString(), location, null, ImmutableMap. of()); } @Override diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudExpressRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudExpressRestClientModule.java new file mode 100644 index 0000000000..772f41f35f --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudExpressRestClientModule.java @@ -0,0 +1,126 @@ +/** + * + * Copyright (C) 2010 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.vcloud.config; + +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterables.get; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Named; + +import org.jclouds.domain.Location; +import org.jclouds.http.RequiresHttp; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.functions.VCloudExpressAllCatalogItemsInCatalog; +import org.jclouds.vcloud.functions.VCloudExpressAllCatalogsInOrganization; +import org.jclouds.vcloud.functions.VCloudExpressAllVDCsInOrganization; +import org.jclouds.vcloud.functions.VCloudExpressOrganizationsForNames; +import org.jclouds.vcloud.functions.VCloudExpressOrganizatonsForLocations; +import org.jclouds.vcloud.functions.VCloudExpressVAppTemplatesForCatalogItems; +import org.jclouds.vcloud.predicates.VCloudExpressTaskSuccess; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.inject.Injector; +import com.google.inject.TypeLiteral; + +/** + * Configures the VCloud authentication service connection, including logging and http transport. + * + * @author Adrian Cole + */ +@RequiresHttp +@ConfiguresRestClient +public abstract class BaseVCloudExpressRestClientModule + extends CommonVCloudRestClientModule { + + public BaseVCloudExpressRestClientModule(Class syncClientType, Class asyncClientType) { + super(syncClientType, asyncClientType); + } + + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + } + + @Override + protected Organization provideOrganization(VCloudExpressClient discovery) { + if (authException.get() != null) + throw authException.get(); + try { + return discovery.findOrganizationNamed(null); + } catch (AuthorizationException e) { + authException.set(e); + throw e; + } + } + + @Override + protected URI provideDefaultNetwork(VCloudExpressClient client) { + if (authException.get() != null) + throw authException.get(); + try { + org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null); + Map networks = vDC.getAvailableNetworks(); + checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName()); + return get(networks.values(), 0).getId(); + } catch (AuthorizationException e) { + authException.set(e); + throw e; + } + } + + @Override + protected Predicate successTester(Injector injector, + @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) { + return new RetryablePredicate(injector.getInstance(VCloudExpressTaskSuccess.class), completed); + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java index c45ba9b192..eca147a9dd 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/BaseVCloudRestClientModule.java @@ -19,84 +19,50 @@ package org.jclouds.vcloud.config; -import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Throwables.propagate; -import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.get; -import static com.google.common.collect.Iterables.getLast; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Maps.newLinkedHashMap; -import static com.google.common.collect.Maps.transformValues; -import static com.google.common.collect.Maps.uniqueIndex; -import static org.jclouds.Constants.PROPERTY_API_VERSION; -import static org.jclouds.Constants.PROPERTY_IDENTITY; -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; -import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; import java.net.URI; import java.util.Map; -import java.util.SortedMap; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicReference; -import javax.annotation.Resource; -import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Singleton; -import org.jclouds.http.HttpErrorHandler; +import org.jclouds.domain.Location; import org.jclouds.http.RequiresHttp; -import org.jclouds.http.annotation.ClientError; -import org.jclouds.http.annotation.Redirection; -import org.jclouds.http.annotation.ServerError; -import org.jclouds.logging.Logger; import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.rest.AsyncClientFactory; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.config.RestClientModule; -import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.VCloudToken; +import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; -import org.jclouds.vcloud.endpoints.Catalog; -import org.jclouds.vcloud.endpoints.Network; -import org.jclouds.vcloud.endpoints.Org; -import org.jclouds.vcloud.endpoints.TasksList; -import org.jclouds.vcloud.endpoints.VDC; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog; import org.jclouds.vcloud.functions.AllCatalogsInOrganization; import org.jclouds.vcloud.functions.AllVDCsInOrganization; +import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems; +import org.jclouds.vcloud.functions.OrganizatonsForLocations; import org.jclouds.vcloud.functions.OrganizationsForNames; -import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse; -import org.jclouds.vcloud.internal.VCloudLoginAsyncClient; -import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; -import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; import org.jclouds.vcloud.predicates.TaskSuccess; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.inject.Provides; +import com.google.inject.Injector; +import com.google.inject.TypeLiteral; /** - * Configures the VCloud authentication service connection, including logging - * and http transport. + * Configures the VCloud authentication service connection, including logging and http transport. * * @author Adrian Cole */ @RequiresHttp @ConfiguresRestClient public abstract class BaseVCloudRestClientModule extends - RestClientModule { + CommonVCloudRestClientModule { public BaseVCloudRestClientModule(Class syncClientType, Class asyncClientType) { super(syncClientType, asyncClientType); @@ -104,378 +70,29 @@ public abstract class BaseVCloudRestClientModule>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); + bind(new TypeLiteral, Iterable>>() { + }).to(new TypeLiteral() { + }); } - @Resource - protected Logger logger = Logger.NULL; - - @Provides - @Singleton - protected Predicate successTester(TaskSuccess success, - @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) { - return new RetryablePredicate(success, completed); - } - - @VCloudToken - @Provides - String provideVCloudToken(Supplier cache) { - return checkNotNull(cache.get().getVCloudToken(), "No token present in session"); - } - - @Provides - @Org - @Singleton - protected URI provideOrg(@Org Iterable orgs) { - return getLast(orgs).getId(); - } - - @Provides - @Org - @Singleton - protected String provideOrgName(@Org Iterable orgs) { - return getLast(orgs).getName(); - } - - @Provides - @Org - @Singleton - protected Supplier> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final OrgNameToOrgSupplier supplier) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, - seconds, new Supplier>() { - @Override - public Map get() { - return supplier.get(); - } - }); - } - - @Provides - @Singleton - protected Supplier> provideURIToVDC( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final URItoVDC supplier) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( - authException, seconds, new Supplier>() { - @Override - public Map get() { - return supplier.get(); - } - }); - } - - @Provides - @Singleton - @VDC - protected Supplier> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final Supplier> orgToVDCSupplier) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, seconds, - new Supplier>() { - @Override - public Map get() { - Map returnVal = newLinkedHashMap(); - for (Entry orgr : orgToVDCSupplier.get().entrySet()) { - for (String vdc : orgr.getValue().getVDCs().keySet()) { - returnVal.put(vdc, orgr.getKey()); - } - } - return returnVal; - } - }); - - } - - @Singleton - public static class URItoVDC implements Supplier> { - private final Supplier>> orgVDCMap; - - @Inject - URItoVDC(Supplier>> orgVDCMap) { - this.orgVDCMap = orgVDCMap; - } - - @Override - public Map get() { - return uniqueIndex( - concat(transform( - orgVDCMap.get().values(), - new Function, Iterable>() { - - @Override - public Iterable apply( - Map from) { - return from.values(); - } - - })), new Function() { - - @Override - public URI apply(org.jclouds.vcloud.domain.VDC from) { - return from.getId(); - } - - }); - } - - } - - @Provides - @Org - @Singleton - protected Iterable provideOrgs(Supplier cache, @Named(PROPERTY_IDENTITY) String user) { - VCloudSession discovery = cache.get(); - checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user); - return discovery.getOrgs().values(); - } - - protected AtomicReference authException = new AtomicReference(); - - @Provides - @Singleton - protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final VCloudLoginAsyncClient login) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier(authException, seconds, - new Supplier() { - - @Override - public VCloudSession get() { - try { - return login.login().get(10, TimeUnit.SECONDS); - } catch (Exception e) { - propagate(e); - assert false : e; - return null; - } - } - - }); - } - - @Provides - @Singleton - protected Supplier> provideOrgMapCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationMapSupplier supplier) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( - authException, seconds, new Supplier>() { - @Override - public Map get() { - return supplier.get(); - } - - }); - } - - private final static Function name = new Function() { - - @Override - public String apply(NamedResource from) { - return from.getName(); - } - - }; - - @Singleton - public static class OrganizationMapSupplier implements Supplier> { - protected final Supplier sessionSupplier; - private final OrganizationsForNames organizationsForNames; - - @Inject - protected OrganizationMapSupplier(Supplier sessionSupplier, - OrganizationsForNames organizationsForNames) { - this.sessionSupplier = sessionSupplier; - this.organizationsForNames = organizationsForNames; - } - - @Override - public Map get() { - return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name); - } - } - - @Singleton - public static class OrganizationCatalogSupplier implements - Supplier>> { - protected final Supplier> orgSupplier; - private final AllCatalogsInOrganization allCatalogsInOrganization; - - @Inject - protected OrganizationCatalogSupplier(Supplier> orgSupplier, - AllCatalogsInOrganization allCatalogsInOrganization) { - this.orgSupplier = orgSupplier; - this.allCatalogsInOrganization = allCatalogsInOrganization; - } - - @Override - public Map> get() { - return transformValues( - transformValues(orgSupplier.get(), allCatalogsInOrganization), - new Function, Map>() { - - @Override - public Map apply( - Iterable from) { - return uniqueIndex(from, name); - } - - }); - } - } - - @Provides - @Singleton - protected Supplier>> provideOrganizationCatalogItemMapSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogSupplier supplier) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>( - authException, seconds, - new Supplier>>() { - @Override - public Map> get() { - return supplier.get(); - } - - }); - } - - @Provides - @Singleton - protected Supplier>> provideOrganizationVDCSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationVDCSupplier supplier) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>( - authException, seconds, new Supplier>>() { - @Override - public Map> get() { - return supplier.get(); - } - - }); - } - - @Singleton - public static class OrganizationVDCSupplier implements - Supplier>> { - protected final Supplier> orgSupplier; - private final AllVDCsInOrganization allVDCsInOrganization; - - @Inject - protected OrganizationVDCSupplier(Supplier> orgSupplier, - AllVDCsInOrganization allVDCsInOrganization) { - this.orgSupplier = orgSupplier; - this.allVDCsInOrganization = allVDCsInOrganization; - } - - @Override - public Map> get() { - return transformValues( - transformValues(orgSupplier.get(), allVDCsInOrganization), - new Function, Map>() { - - @Override - public Map apply( - Iterable from) { - return uniqueIndex(from, name); - } - - }); - } - } - - @Singleton - public static class OrganizationCatalogItemSupplier implements - Supplier>>> { - protected final Supplier>> catalogSupplier; - private final AllCatalogItemsInCatalog allCatalogItemsInCatalog; - - @Inject - protected OrganizationCatalogItemSupplier( - Supplier>> catalogSupplier, - AllCatalogItemsInCatalog allCatalogItemsInCatalog) { - this.catalogSupplier = catalogSupplier; - this.allCatalogItemsInCatalog = allCatalogItemsInCatalog; - } - - @Override - public Map>> get() { - return transformValues( - catalogSupplier.get(), - new Function, Map>>() { - - @Override - public Map> apply( - Map from) { - return transformValues( - from, - new Function>() { - - @Override - public Map apply(org.jclouds.vcloud.domain.Catalog from) { - return uniqueIndex(allCatalogItemsInCatalog.apply(from), name); - } - }); - - } - }); - } - } - - @Provides - @Singleton - protected Supplier>>> provideOrganizationCatalogItemSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogItemSupplier supplier) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>>( - authException, seconds, - new Supplier>>>() { - @Override - public Map>> get() { - return supplier.get(); - } - }); - } - - @Provides - @Singleton - @org.jclouds.vcloud.endpoints.VCloudLogin - protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, - @Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, TimeoutException { - SortedMap versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS); - checkState(versions.size() > 0, "No versions present"); - checkState(versions.containsKey(version), "version " + version + " not present in: " + versions); - return versions.get(version); - } - - @Singleton - private static class OrgNameToOrgSupplier implements Supplier> { - private final Supplier sessionSupplier; - - @SuppressWarnings("unused") - @Inject - OrgNameToOrgSupplier(Supplier sessionSupplier) { - this.sessionSupplier = sessionSupplier; - } - - @Override - public Map get() { - return sessionSupplier.get().getOrgs(); - } - - } - - @Provides - @Singleton - protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) { - return factory.create(VCloudLoginAsyncClient.class); - } - - @Provides - @Singleton - protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) { - return factory.create(VCloudVersionsAsyncClient.class); - } - - @Provides - @Singleton - protected Organization provideOrganization(VCloudClient discovery) throws ExecutionException, TimeoutException, - InterruptedException { + @Override + protected Organization provideOrganization(VCloudClient discovery) { if (authException.get() != null) throw authException.get(); try { @@ -486,35 +103,8 @@ public abstract class BaseVCloudRestClientModule 0, "No vdcs present in org: " + org.getName()); - return get(org.getVDCs().values(), 0).getId(); - } - - @Provides - @Catalog - @Singleton - protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) { - checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName()); - return get(org.getCatalogs().values(), 0).getId(); - } - - @Provides - @Catalog - @Singleton - protected String provideCatalogName( - Supplier>> catalogs) { - return getLast(getLast(catalogs.get().values()).keySet()); - } - - @Provides - @Network - @Singleton - protected URI provideDefaultNetwork(VCloudClient client) throws InterruptedException, ExecutionException, - TimeoutException { + @Override + protected URI provideDefaultNetwork(VCloudClient client) { if (authException.get() != null) throw authException.get(); try { @@ -526,27 +116,10 @@ public abstract class BaseVCloudRestClientModule 0, "No tasks lists present in org: " + org.getName()); - return get(org.getTasksLists().values(), 0).getId(); + protected Predicate successTester(Injector injector, + @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) { + return new RetryablePredicate(injector.getInstance(TaskSuccess.class), completed); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java new file mode 100644 index 0000000000..98c402b25e --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/CommonVCloudRestClientModule.java @@ -0,0 +1,521 @@ +/** + * + * Copyright (C) 2010 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.vcloud.config; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Throwables.propagate; +import static com.google.common.collect.Iterables.concat; +import static com.google.common.collect.Iterables.get; +import static com.google.common.collect.Iterables.getLast; +import static com.google.common.collect.Iterables.transform; +import static com.google.common.collect.Maps.newLinkedHashMap; +import static com.google.common.collect.Maps.transformValues; +import static com.google.common.collect.Maps.uniqueIndex; +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.Constants.PROPERTY_IDENTITY; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; + +import java.net.URI; +import java.util.Map; +import java.util.SortedMap; +import java.util.Map.Entry; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicReference; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.RequiresHttp; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.logging.Logger; +import org.jclouds.rest.AsyncClientFactory; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.config.RestClientModule; +import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; +import org.jclouds.vcloud.VCloudToken; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.endpoints.Catalog; +import org.jclouds.vcloud.endpoints.Network; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.endpoints.TasksList; +import org.jclouds.vcloud.endpoints.VDC; +import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse; +import org.jclouds.vcloud.internal.VCloudLoginAsyncClient; +import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; +import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; +import com.google.inject.Injector; +import com.google.inject.Provides; + +/** + * Configures the VCloud authentication service connection, including logging and http transport. + * + * @author Adrian Cole + */ +@RequiresHttp +@ConfiguresRestClient +public abstract class CommonVCloudRestClientModule extends RestClientModule { + + public CommonVCloudRestClientModule(Class syncClientType, Class asyncClientType) { + super(syncClientType, asyncClientType); + } + + @Override + protected void configure() { + requestInjection(this); + super.configure(); + } + + @Resource + protected Logger logger = Logger.NULL; + + @Provides + @Singleton + protected abstract Predicate successTester(Injector injector, + @Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed); + + @VCloudToken + @Provides + String provideVCloudToken(Supplier cache) { + return checkNotNull(cache.get().getVCloudToken(), "No token present in session"); + } + + @Provides + @Org + @Singleton + protected URI provideOrg(@Org Iterable orgs) { + return getLast(orgs).getId(); + } + + @Provides + @Org + @Singleton + protected String provideOrgName(@Org Iterable orgs) { + return getLast(orgs).getName(); + } + + @Provides + @Org + @Singleton + protected Supplier> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + final OrgNameToOrgSupplier supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, + seconds, new Supplier>() { + @Override + public Map get() { + return supplier.get(); + } + }); + } + + @Provides + @Singleton + protected Supplier> provideURIToVDC( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final URItoVDC supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( + authException, seconds, new Supplier>() { + @Override + public Map get() { + return supplier.get(); + } + }); + } + + @Provides + @Singleton + @VDC + protected Supplier> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + final Supplier> orgToVDCSupplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, seconds, + new Supplier>() { + @Override + public Map get() { + Map returnVal = newLinkedHashMap(); + for (Entry orgr : orgToVDCSupplier.get().entrySet()) { + for (String vdc : orgr.getValue().getVDCs().keySet()) { + returnVal.put(vdc, orgr.getKey()); + } + } + return returnVal; + } + }); + + } + + @Singleton + public static class URItoVDC implements Supplier> { + private final Supplier>> orgVDCMap; + + @Inject + URItoVDC(Supplier>> orgVDCMap) { + this.orgVDCMap = orgVDCMap; + } + + @Override + public Map get() { + return uniqueIndex( + concat(transform( + orgVDCMap.get().values(), + new Function, Iterable>() { + + @Override + public Iterable apply( + Map from) { + return from.values(); + } + + })), new Function() { + + @Override + public URI apply(org.jclouds.vcloud.domain.VDC from) { + return from.getId(); + } + + }); + } + + } + + @Provides + @Org + @Singleton + protected Iterable provideOrgs(Supplier cache, @Named(PROPERTY_IDENTITY) String user) { + VCloudSession discovery = cache.get(); + checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user); + return discovery.getOrgs().values(); + } + + protected AtomicReference authException = new AtomicReference(); + + @Provides + @Singleton + protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + final VCloudLoginAsyncClient login) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier(authException, seconds, + new Supplier() { + + @Override + public VCloudSession get() { + try { + return login.login().get(10, TimeUnit.SECONDS); + } catch (Exception e) { + propagate(e); + assert false : e; + return null; + } + } + + }); + } + + @Provides + @Singleton + protected Supplier> provideOrgMapCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationMapSupplier supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>( + authException, seconds, new Supplier>() { + @Override + public Map get() { + return supplier.get(); + } + + }); + } + + private final static Function name = new Function() { + + @Override + public String apply(NamedResource from) { + return from.getName(); + } + + }; + + @Singleton + public static class OrganizationMapSupplier implements Supplier> { + protected final Supplier sessionSupplier; + private final Function, Iterable> organizationsForNames; + + @Inject + protected OrganizationMapSupplier(Supplier sessionSupplier, + Function, Iterable> organizationsForNames) { + this.sessionSupplier = sessionSupplier; + this.organizationsForNames = organizationsForNames; + } + + @Override + public Map get() { + return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name); + } + } + + @Singleton + public static class OrganizationCatalogSupplier implements + Supplier>> { + protected final Supplier> orgSupplier; + private final Function> allCatalogsInOrganization; + + @Inject + protected OrganizationCatalogSupplier(Supplier> orgSupplier, + Function> allCatalogsInOrganization) { + this.orgSupplier = orgSupplier; + this.allCatalogsInOrganization = allCatalogsInOrganization; + } + + @Override + public Map> get() { + return transformValues( + transformValues(orgSupplier.get(), allCatalogsInOrganization), + new Function, Map>() { + + @Override + public Map apply( + Iterable from) { + return uniqueIndex(from, name); + } + + }); + } + } + + @Provides + @Singleton + protected Supplier>> provideOrganizationCatalogItemMapSupplierCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogSupplier supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>( + authException, seconds, + new Supplier>>() { + @Override + public Map> get() { + return supplier.get(); + } + + }); + } + + @Provides + @Singleton + protected Supplier>> provideOrganizationVDCSupplierCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationVDCSupplier supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>( + authException, seconds, + new Supplier>>() { + @Override + public Map> get() { + return supplier.get(); + } + + }); + } + + @Singleton + public static class OrganizationVDCSupplier implements + Supplier>> { + protected final Supplier> orgSupplier; + private final Function> allVDCsInOrganization; + + @Inject + protected OrganizationVDCSupplier(Supplier> orgSupplier, + Function> allVDCsInOrganization) { + this.orgSupplier = orgSupplier; + this.allVDCsInOrganization = allVDCsInOrganization; + } + + @Override + public Map> get() { + return transformValues( + transformValues(orgSupplier.get(), allVDCsInOrganization), + new Function, Map>() { + + @Override + public Map apply( + Iterable from) { + return uniqueIndex(from, name); + } + + }); + } + } + + @Singleton + public static class OrganizationCatalogItemSupplier implements + Supplier>>> { + protected final Supplier>> catalogSupplier; + private final Function> allCatalogItemsInCatalog; + + @Inject + protected OrganizationCatalogItemSupplier( + Supplier>> catalogSupplier, + Function> allCatalogItemsInCatalog) { + this.catalogSupplier = catalogSupplier; + this.allCatalogItemsInCatalog = allCatalogItemsInCatalog; + } + + @Override + public Map>> get() { + return transformValues( + catalogSupplier.get(), + new Function, Map>>() { + + @Override + public Map> apply( + Map from) { + return transformValues( + from, + new Function>() { + + @Override + public Map apply( + org.jclouds.vcloud.domain.Catalog from) { + return uniqueIndex(allCatalogItemsInCatalog.apply(from), name); + } + }); + + } + }); + } + } + + @Provides + @Singleton + protected Supplier>>> provideOrganizationCatalogItemSupplierCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogItemSupplier supplier) { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>>>( + authException, seconds, + new Supplier>>>() { + @Override + public Map>> get() { + return supplier.get(); + } + }); + } + + @Provides + @Singleton + @org.jclouds.vcloud.endpoints.VCloudLogin + protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, + @Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, + TimeoutException { + SortedMap versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS); + checkState(versions.size() > 0, "No versions present"); + checkState(versions.containsKey(version), "version " + version + " not present in: " + versions); + return versions.get(version); + } + + @Singleton + private static class OrgNameToOrgSupplier implements Supplier> { + private final Supplier sessionSupplier; + + @SuppressWarnings("unused") + @Inject + OrgNameToOrgSupplier(Supplier sessionSupplier) { + this.sessionSupplier = sessionSupplier; + } + + @Override + public Map get() { + return sessionSupplier.get().getOrgs(); + } + + } + + @Provides + @Singleton + protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) { + return factory.create(VCloudLoginAsyncClient.class); + } + + @Provides + @Singleton + protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) { + return factory.create(VCloudVersionsAsyncClient.class); + } + + @Provides + @Singleton + protected abstract Organization provideOrganization(S client); + + @Provides + @VDC + @Singleton + protected URI provideDefaultVDC(Organization org) { + checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName()); + return get(org.getVDCs().values(), 0).getId(); + } + + @Provides + @Catalog + @Singleton + protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) { + checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName()); + return get(org.getCatalogs().values(), 0).getId(); + } + + @Provides + @Catalog + @Singleton + protected String provideCatalogName( + Supplier>> catalogs) { + return getLast(getLast(catalogs.get().values()).keySet()); + } + + @Provides + @Network + @Singleton + protected abstract URI provideDefaultNetwork(S client); + + @Provides + @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) + @Singleton + String provideDefaultNetworkString(@Network URI network) { + return network.toASCIIString(); + } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseVCloudErrorFromHttpResponse.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseVCloudErrorFromHttpResponse.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseVCloudErrorFromHttpResponse.class); + } + + @Provides + @TasksList + @Singleton + protected URI provideDefaultTasksList(Organization org) { + checkState(org.getTasksLists().size() > 0, "No tasks lists present in org: " + org.getName()); + return get(org.getTasksLists().values(), 0).getId(); + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudExpressRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudExpressRestClientModule.java new file mode 100644 index 0000000000..3b402f0dd1 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudExpressRestClientModule.java @@ -0,0 +1,41 @@ +/** + * + * Copyright (C) 2010 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.vcloud.config; + +import org.jclouds.http.RequiresHttp; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressClient; + +/** + * Configures the VCloud authentication service connection, including logging and http transport. + * + * @author Adrian Cole + */ +@RequiresHttp +@ConfiguresRestClient +public class VCloudExpressRestClientModule extends + BaseVCloudExpressRestClientModule { + + public VCloudExpressRestClientModule() { + super(VCloudExpressClient.class, VCloudExpressAsyncClient.class); + } + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index f178373306..435483ec4e 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -25,8 +25,7 @@ import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; /** - * Configures the VCloud authentication service connection, including logging - * and http transport. + * Configures the VCloud authentication service connection, including logging and http transport. * * @author Adrian Cole */ diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java index 8e624b55a1..06071d796f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java @@ -21,14 +21,14 @@ package org.jclouds.vcloud.domain; import static com.google.common.base.Preconditions.checkNotNull; -import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudExpressAsyncClient; /** * * VirtualResource such as disks or CPU * * @author Adrian Cole - * @see VCloudAsyncClient#getVApp + * @see VCloudExpressAsyncClient#getVApp * @see * */ diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java index 305128c46d..44f4a97696 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java @@ -25,7 +25,7 @@ import java.net.URI; import java.util.LinkedHashMap; import java.util.Map; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.NamedResource; @@ -105,7 +105,7 @@ public class CatalogImpl extends LinkedHashMap implements @Override public String getType() { - return VCloudMediaType.CATALOG_XML; + return VCloudExpressMediaType.CATALOG_XML; } @Override diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogItemImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogItemImpl.java index f9fa88455b..e1e7e8cc02 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogItemImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogItemImpl.java @@ -26,7 +26,7 @@ import java.util.Map; import javax.annotation.Nullable; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.NamedResource; @@ -47,7 +47,7 @@ public class CatalogItemImpl extends NamedResourceImpl implements CatalogItem { public CatalogItemImpl(String name, URI id, @Nullable String description, NamedResource entity, Map properties) { - super(name, VCloudMediaType.CATALOGITEM_XML, id); + super(name, VCloudExpressMediaType.CATALOGITEM_XML, id); this.description = description; this.entity = checkNotNull(entity, "entity"); this.properties.putAll(checkNotNull(properties, "properties")); @@ -55,7 +55,7 @@ public class CatalogItemImpl extends NamedResourceImpl implements CatalogItem { @Override public String getType() { - return VCloudMediaType.CATALOGITEM_XML; + return VCloudExpressMediaType.CATALOGITEM_XML; } public NamedResource getEntity() { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NetworkImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NetworkImpl.java index 1db1bb2557..dd98c835f6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NetworkImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NetworkImpl.java @@ -22,7 +22,7 @@ package org.jclouds.vcloud.domain.internal; import java.net.URI; import java.util.Set; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.FirewallRule; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.NatRule; @@ -53,7 +53,7 @@ public class NetworkImpl extends NamedResourceImpl implements Network { public NetworkImpl(String name, URI id, String description, Set dnsServers, String gateway, String netmask, Set fenceModes, Boolean dhcp, Set natRules, Set firewallRules) { - super(name, VCloudMediaType.NETWORK_XML, id); + super(name, VCloudExpressMediaType.NETWORK_XML, id); this.description = description; this.dnsServers.addAll(dnsServers); this.gateway = gateway; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java index 041f24efef..1abe2bbf0f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java @@ -22,7 +22,7 @@ package org.jclouds.vcloud.domain.internal; import java.net.URI; import java.util.Map; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.endpoints.Catalog; @@ -130,7 +130,7 @@ public class OrganizationImpl implements Organization { @Override public String getType() { - return VCloudMediaType.ORG_XML; + return VCloudExpressMediaType.ORG_XML; } @Override diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java index eecebcc461..6f642ff1b8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java @@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; import java.util.Set; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.VApp; @@ -207,7 +207,7 @@ public class VAppImpl implements VApp { @Override public String getType() { - return VCloudMediaType.VAPP_XML; + return VCloudExpressMediaType.VAPP_XML; } @Override diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java index 90f5c63246..b79e252111 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java @@ -23,7 +23,7 @@ import java.net.URI; import javax.annotation.Nullable; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppTemplate; @@ -40,7 +40,7 @@ public class VAppTemplateImpl extends NamedResourceImpl implements VAppTemplate private final VAppStatus status; public VAppTemplateImpl(String name, URI id, @Nullable String description, @Nullable VAppStatus status) { - super(name, VCloudMediaType.VAPPTEMPLATE_XML, id); + super(name, VCloudExpressMediaType.VAPPTEMPLATE_XML, id); this.description = description; this.status = status; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java index d718ba4e18..8da53d08de 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java @@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; import java.util.Map; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.Capacity; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Quota; @@ -198,7 +198,7 @@ public class VDCImpl implements VDC { @Override public String getType() { - return VCloudMediaType.VDC_XML; + return VCloudExpressMediaType.VDC_XML; } @Override diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java index 71baa347dc..3e269f5594 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogItemsInCatalog.java @@ -55,7 +55,8 @@ public class AllCatalogItemsInCatalog implements Function> allCatalogsInOrganization; - private final AllCatalogItemsInCatalog allCatalogItemsInCatalog; + private final Function> allCatalogItemsInCatalog; @Inject - AllCatalogItemsInOrganization(AllCatalogsInOrganization allCatalogsInOrganization, - AllCatalogItemsInCatalog allCatalogItemsInCatalog) { + AllCatalogItemsInOrganization(Function> allCatalogsInOrganization, + Function> allCatalogItemsInCatalog) { this.allCatalogsInOrganization = allCatalogsInOrganization; this.allCatalogItemsInCatalog = allCatalogItemsInCatalog; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrganization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrganization.java index eec53aeaaf..c344c15408 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrganization.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllCatalogsInOrganization.java @@ -52,7 +52,8 @@ public class AllCatalogsInOrganization implements Function apply(final Organization org) { Iterable catalogs = transformParallel(org.getCatalogs().values(), - new Function>() { - @SuppressWarnings("unchecked") - @Override - public Future apply(NamedResource from) { - return (Future) aclient.getCatalog(from.getId()); - } + new Function>() { + @SuppressWarnings("unchecked") + @Override + public Future apply(NamedResource from) { + return (Future) aclient.getCatalog(from.getId()); + } - }, executor, null, logger, "catalogs in " + org.getName()); + }, executor, null, logger, "catalogs in " + org.getName()); return catalogs; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrganization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrganization.java index 7045872267..bc61a34be3 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrganization.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/AllVDCsInOrganization.java @@ -52,7 +52,8 @@ public class AllVDCsInOrganization implements Function apply(final Organization org) { Iterable catalogItems = transformParallel(org.getVDCs().values(), - new Function>() { - @SuppressWarnings("unchecked") - @Override - public Future apply(NamedResource from) { - return (Future) aclient.getVDC(from.getId()); - } + new Function>() { + @SuppressWarnings("unchecked") + @Override + public Future apply(NamedResource from) { + return (Future) aclient.getVDC(from.getId()); + } - }, executor, null, logger, "vdcs in org " + org.getName()); + }, executor, null, logger, "vdcs in org " + org.getName()); return catalogItems; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java index ad06b1b09f..15577bf4ba 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForCatalogItems.java @@ -46,7 +46,7 @@ import com.google.common.base.Predicate; */ @Singleton public class VAppTemplatesForCatalogItems implements - Function, Iterable> { + Function, Iterable> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; @@ -55,7 +55,7 @@ public class VAppTemplatesForCatalogItems implements @Inject VAppTemplatesForCatalogItems(VCloudAsyncClient aclient, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForResourceEntities.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForResourceEntities.java index 02484150d0..4f2c2b5dbd 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForResourceEntities.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesForResourceEntities.java @@ -34,8 +34,8 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.VCloudAsyncClient; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.VAppTemplate; @@ -51,11 +51,11 @@ public class VAppTemplatesForResourceEntities implements @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; - private final VCloudAsyncClient aclient; + private final VCloudExpressAsyncClient aclient; private final ExecutorService executor; @Inject - VAppTemplatesForResourceEntities(VCloudAsyncClient aclient, + VAppTemplatesForResourceEntities(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.aclient = aclient; this.executor = executor; @@ -67,7 +67,7 @@ public class VAppTemplatesForResourceEntities implements @Override public boolean apply(NamedResource input) { - return input.getType().equals(VCloudMediaType.VAPPTEMPLATE_XML); + return input.getType().equals(VCloudExpressMediaType.VAPPTEMPLATE_XML); } }), new Function>() { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressAllCatalogItemsInCatalog.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressAllCatalogItemsInCatalog.java new file mode 100644 index 0000000000..e94c7b3115 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressAllCatalogItemsInCatalog.java @@ -0,0 +1,85 @@ +/** + * + * Copyright (C) 2010 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.vcloud.functions; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressMediaType; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.NamedResource; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressAllCatalogItemsInCatalog implements Function> { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + + private final VCloudExpressAsyncClient aclient; + private final ExecutorService executor; + + @Inject + VCloudExpressAllCatalogItemsInCatalog(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.aclient = aclient; + this.executor = executor; + } + + @Override + public Iterable apply(Catalog from) { + + Iterable catalogItems = transformParallel(filter(from.values(), new Predicate() { + + @Override + public boolean apply(NamedResource input) { + return input.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML); + } + + }), new Function>() { + + @SuppressWarnings("unchecked") + @Override + public Future apply(NamedResource from) { + return (Future) aclient.getCatalogItem(from.getId()); + } + + }, executor, null, logger, "catalogItems in " + from.getId()); + return catalogItems; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressAllCatalogsInOrganization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressAllCatalogsInOrganization.java new file mode 100644 index 0000000000..7880a55c76 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressAllCatalogsInOrganization.java @@ -0,0 +1,73 @@ +/** + * + * Copyright (C) 2010 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.vcloud.functions; + +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.Organization; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressAllCatalogsInOrganization implements Function> { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + + private final VCloudExpressAsyncClient aclient; + private final ExecutorService executor; + + @Inject + VCloudExpressAllCatalogsInOrganization(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.aclient = aclient; + this.executor = executor; + } + + @Override + public Iterable apply(final Organization org) { + Iterable catalogs = transformParallel(org.getCatalogs().values(), + new Function>() { + @SuppressWarnings("unchecked") + @Override + public Future apply(NamedResource from) { + return (Future) aclient.getCatalog(from.getId()); + } + + }, executor, null, logger, "catalogs in " + org.getName()); + return catalogs; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressAllVDCsInOrganization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressAllVDCsInOrganization.java new file mode 100644 index 0000000000..1bada11e0d --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressAllVDCsInOrganization.java @@ -0,0 +1,75 @@ +/** + * + * Copyright (C) 2010 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.vcloud.functions; + +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.VDC; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressAllVDCsInOrganization implements Function> { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + + private final VCloudExpressAsyncClient aclient; + private final ExecutorService executor; + + @Inject + VCloudExpressAllVDCsInOrganization(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.aclient = aclient; + this.executor = executor; + } + + @Override + public Iterable apply(final Organization org) { + + Iterable catalogItems = transformParallel(org.getVDCs().values(), + new Function>() { + @SuppressWarnings("unchecked") + @Override + public Future apply(NamedResource from) { + return (Future) aclient.getVDC(from.getId()); + } + + }, executor, null, logger, "vdcs in org " + org.getName()); + return catalogItems; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressOrganizationsForNames.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressOrganizationsForNames.java new file mode 100644 index 0000000000..4b4d1a14ae --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressOrganizationsForNames.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2010 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.vcloud.functions; + +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.domain.Organization; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressOrganizationsForNames implements Function, Iterable> { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + private final VCloudExpressAsyncClient aclient; + private final ExecutorService executor; + + @Inject + VCloudExpressOrganizationsForNames(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.aclient = aclient; + this.executor = executor; + } + + @Override + public Iterable apply(Iterable from) { + return transformParallel(from, new Function>() { + + @SuppressWarnings("unchecked") + @Override + public Future apply(String from) { + return (Future) aclient.findOrganizationNamed(from); + } + + }, executor, null, logger, "organizations for names"); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressOrganizatonsForLocations.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressOrganizatonsForLocations.java new file mode 100644 index 0000000000..5b15bde489 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressOrganizatonsForLocations.java @@ -0,0 +1,98 @@ +/** + * + * Copyright (C) 2010 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.vcloud.functions; + +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.net.URI; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.compute.domain.VCloudLocation; +import org.jclouds.vcloud.domain.Organization; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressOrganizatonsForLocations implements + Function, Iterable> { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + private final VCloudExpressAsyncClient aclient; + private final ExecutorService executor; + + @Inject + VCloudExpressOrganizatonsForLocations(VCloudExpressAsyncClient aclient, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.aclient = aclient; + this.executor = executor; + } + + /** + * Zones are assignable, but we want regions. so we look for zones, whose + * parent is region. then, we use a set to extract the unique set. + */ + @Override + public Iterable apply(Iterable from) { + + return transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate() { + + @Override + public boolean apply(Location input) { + return input.getScope() == LocationScope.ZONE; + } + + }), new Function() { + + @Override + public URI apply(Location from) { + return VCloudLocation.class.cast(from.getParent()).getResource().getId(); + } + + })), new Function>() { + + @SuppressWarnings("unchecked") + @Override + public Future apply(URI from) { + return (Future) aclient.getOrganization(from); + } + + }, executor, null, logger, "organizations for uris"); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForCatalogItems.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForCatalogItems.java new file mode 100644 index 0000000000..fa664717de --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VCloudExpressVAppTemplatesForCatalogItems.java @@ -0,0 +1,83 @@ +/** + * + * Copyright (C) 2010 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.vcloud.functions; + +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.concurrent.FutureIterables.transformParallel; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressMediaType; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.VAppTemplate; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; + +/** + * @author Adrian Cole + */ +@Singleton +public class VCloudExpressVAppTemplatesForCatalogItems implements + Function, Iterable> { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + public Logger logger = Logger.NULL; + private final VCloudExpressAsyncClient aclient; + private final ExecutorService executor; + + @Inject + VCloudExpressVAppTemplatesForCatalogItems(VCloudExpressAsyncClient aclient, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { + this.aclient = aclient; + this.executor = executor; + } + + @Override + public Iterable apply(Iterable from) { + return transformParallel(filter(from, new Predicate() { + + @Override + public boolean apply(CatalogItem input) { + return input.getEntity().getType().equals(VCloudExpressMediaType.VAPPTEMPLATE_XML); + } + + }), new Function>() { + + @SuppressWarnings("unchecked") + @Override + public Future apply(CatalogItem from) { + return (Future) aclient.getVAppTemplate(from.getEntity().getId()); + } + + }, executor, null, logger, "vappTemplates in"); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClient.java index f5658b9b82..2d2d21ec94 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/internal/VCloudLoginAsyncClient.java @@ -28,7 +28,7 @@ import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.VCloudToken; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.endpoints.Org; @@ -61,6 +61,6 @@ public interface VCloudLoginAsyncClient { */ @POST @ResponseParser(ParseLoginResponseFromHeaders.class) - @Consumes(VCloudMediaType.ORGLIST_XML) + @Consumes(VCloudExpressMediaType.ORGLIST_XML) ListenableFuture login(); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java b/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java index e0121b1d20..88797e5f0f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java @@ -54,14 +54,12 @@ public class InstantiateVAppTemplateOptions { return this; } - public InstantiateVAppTemplateOptions productProperty(String key, - String value) { + public InstantiateVAppTemplateOptions productProperty(String key, String value) { properties.put(checkNotNull(key, "key"), checkNotNull(value, "value")); return this; } - public InstantiateVAppTemplateOptions productProperties( - Map properties) { + public InstantiateVAppTemplateOptions productProperties(Map properties) { this.properties.putAll(checkNotNull(properties, "properties")); return this; } @@ -95,8 +93,7 @@ public class InstantiateVAppTemplateOptions { } public InstantiateVAppTemplateOptions inNetwork(URI networkLocation) { - this.network = checkNotNull(networkLocation, "networkLocation") - .toASCIIString(); + this.network = checkNotNull(networkLocation, "networkLocation").toASCIIString(); return this; } @@ -133,8 +130,7 @@ public class InstantiateVAppTemplateOptions { /** * @see InstantiateVAppTemplateOptions#blockOnDeploy */ - public static InstantiateVAppTemplateOptions blockOnDeploy( - boolean blockOnDeploy) { + public static InstantiateVAppTemplateOptions blockOnDeploy(boolean blockOnDeploy) { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); return options.blockOnDeploy(blockOnDeploy); } @@ -182,8 +178,7 @@ public class InstantiateVAppTemplateOptions { /** * @see InstantiateVAppTemplateOptions#networkName(String) */ - public static InstantiateVAppTemplateOptions networkName( - String networkName) { + public static InstantiateVAppTemplateOptions networkName(String networkName) { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); return options.networkName(networkName); } @@ -191,8 +186,7 @@ public class InstantiateVAppTemplateOptions { /** * @see InstantiateVAppTemplateOptions#productProperty(String,String) */ - public static InstantiateVAppTemplateOptions productProperty(String key, - String value) { + public static InstantiateVAppTemplateOptions productProperty(String key, String value) { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); return options.productProperty(key, value); } @@ -200,8 +194,7 @@ public class InstantiateVAppTemplateOptions { /** * @see InstantiateVAppTemplateOptions#setProperties(Map) */ - public static InstantiateVAppTemplateOptions productProperties( - Map properties) { + public static InstantiateVAppTemplateOptions productProperties(Map properties) { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); return options.productProperties(properties); } @@ -209,11 +202,9 @@ public class InstantiateVAppTemplateOptions { @Override public String toString() { - return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount - + ", memorySizeMegabytes=" + memorySizeMegabytes - + ", diskSizeKilobytes=" + diskSizeKilobytes + ", network=" - + network + ", networkName=" + networkName + ", fenceMode=" - + fenceMode + ", properties=" + properties + "]"; + return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes=" + memorySizeMegabytes + + ", diskSizeKilobytes=" + diskSizeKilobytes + ", network=" + network + ", networkName=" + networkName + + ", fenceMode=" + fenceMode + ", properties=" + properties + "]"; } @Override @@ -221,19 +212,12 @@ public class InstantiateVAppTemplateOptions { final int prime = 31; int result = 1; result = prime * result + ((cpuCount == null) ? 0 : cpuCount.hashCode()); - result = prime * result - + ((diskSizeKilobytes == null) ? 0 : diskSizeKilobytes.hashCode()); - result = prime * result - + ((fenceMode == null) ? 0 : fenceMode.hashCode()); - result = prime - * result - + ((memorySizeMegabytes == null) ? 0 : memorySizeMegabytes - .hashCode()); + result = prime * result + ((diskSizeKilobytes == null) ? 0 : diskSizeKilobytes.hashCode()); + result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode()); + result = prime * result + ((memorySizeMegabytes == null) ? 0 : memorySizeMegabytes.hashCode()); result = prime * result + ((network == null) ? 0 : network.hashCode()); - result = prime * result - + ((networkName == null) ? 0 : networkName.hashCode()); - result = prime * result - + ((properties == null) ? 0 : properties.hashCode()); + result = prime * result + ((networkName == null) ? 0 : networkName.hashCode()); + result = prime * result + ((properties == null) ? 0 : properties.hashCode()); return result; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/predicates/VAppNotFound.java b/vcloud/core/src/main/java/org/jclouds/vcloud/predicates/VCloudExpressTaskSuccess.java similarity index 59% rename from vcloud/core/src/main/java/org/jclouds/vcloud/predicates/VAppNotFound.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/predicates/VCloudExpressTaskSuccess.java index ccd7d874fc..4234c08f62 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/predicates/VAppNotFound.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/predicates/VCloudExpressTaskSuccess.java @@ -19,13 +19,15 @@ package org.jclouds.vcloud.predicates; +import java.net.URI; + import javax.annotation.Resource; import javax.inject.Singleton; import org.jclouds.logging.Logger; -import org.jclouds.rest.ResourceNotFoundException; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.TaskStatus; import com.google.common.base.Predicate; import com.google.inject.Inject; @@ -37,23 +39,27 @@ import com.google.inject.Inject; * @author Adrian Cole */ @Singleton -public class VAppNotFound implements Predicate { +public class VCloudExpressTaskSuccess implements Predicate { - private final VCloudClient client; + private final VCloudExpressClient client; @Resource protected Logger logger = Logger.NULL; @Inject - public VAppNotFound(VCloudClient client) { + public VCloudExpressTaskSuccess(VCloudExpressClient client) { this.client = client; } - public boolean apply(VApp vApp) { - try { - return client.getVApp(vApp.getId()) == null; - } catch (ResourceNotFoundException e) { - return true; - } + public boolean apply(URI taskId) { + logger.trace("looking for status on task %s", taskId); + + Task task = client.getTask(taskId); + logger.trace("%s: looking for status %s: currently: %s", task, TaskStatus.SUCCESS, task + .getStatus()); + if (task.getStatus() == TaskStatus.ERROR) + throw new RuntimeException("error on task: " + task.getLocation() + " error: " + task.getError()); + return task.getStatus() == TaskStatus.SUCCESS; } + } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java index 6595ccb06e..3be3c036b8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java @@ -19,9 +19,9 @@ package org.jclouds.vcloud.xml; -import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; -import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; -import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.TASKSLIST_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VDC_XML; import static org.jclouds.vcloud.util.Utils.newNamedResource; import static org.jclouds.vcloud.util.Utils.putNamedResource; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgListHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgListHandler.java index 10f398041e..f54698853e 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgListHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgListHandler.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.xml; -import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.ORG_XML; import static org.jclouds.vcloud.util.Utils.putNamedResource; import java.util.Map; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java index efa50e6162..7c1e5aad0e 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java @@ -27,7 +27,7 @@ import javax.inject.Inject; import org.jclouds.http.functions.ParseSax; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.VApp; @@ -87,7 +87,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult { size = new Long(attributes.getValue(attributes.getIndex("size"))); } else if (qName.equals("Link")) { // type should never be missing if (attributes.getIndex("type") != -1 - && attributes.getValue(attributes.getIndex("type")).equals(VCloudMediaType.VDC_XML)) { + && attributes.getValue(attributes.getIndex("type")).equals(VCloudExpressMediaType.VDC_XML)) { vDC = Utils.newNamedResource(attributes); } } else if (qName.equals("OperatingSystemSection")) { diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/ProvidersInPropertiesTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/ProvidersInPropertiesTest.java index f901baf125..5fc189bc9f 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/ProvidersInPropertiesTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/ProvidersInPropertiesTest.java @@ -37,12 +37,14 @@ public class ProvidersInPropertiesTest { public void testSupportedProviders() { Iterable providers = Utils.getSupportedProviders(); assert Iterables.contains(providers, "vcloud") : providers; + assert Iterables.contains(providers, "vcloudexpress") : providers; } @Test public void testSupportedComputeServiceProviders() { Iterable providers = ComputeServiceUtils.getSupportedProviders(); assert Iterables.contains(providers, "vcloud") : providers; + assert Iterables.contains(providers, "vcloudexpress") : providers; } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index c34a72c8b3..bf8d273754 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -90,16 +90,16 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); + String.class, InstantiateVAppTemplateOptions[].class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp"); + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp"); assertRequestLineEquals(request, - "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); - assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-hosting.xml")), - "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); + assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp.xml")), + "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); @@ -109,21 +109,20 @@ public class VCloudAsyncClientTest extends RestClientTest { } public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException, - IOException { + IOException { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", processorCount(1).memory( - 512).disk(1024).fenceMode("allowInOut").inNetwork( - URI.create("https://vcloud.safesecureweb.com/network/1990"))); + String.class, InstantiateVAppTemplateOptions[].class); + HttpRequest request = processor + .createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp", + processorCount(1).memory(512).disk(1024).inNetwork( + URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"))); assertRequestLineEquals(request, - "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); - assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream( - "/newvapp-hostingcpumemdisk.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", - false); + assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-cpumemdisk.xml")), + "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, VAppHandler.class); @@ -134,25 +133,26 @@ public class VCloudAsyncClientTest extends RestClientTest { @Test(expectedExceptions = IllegalArgumentException.class) public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException, - IOException { + IOException { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); - processor.createRequest(method, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "CentOS 01", processorCount(1).memory(512) - .disk(1024).inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990"))); + String.class, InstantiateVAppTemplateOptions[].class); + processor.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "CentOS 01", processorCount(1).memory(512) + .disk(1024).inNetwork(URI.create("https://vcenterprise.bluelock.com/network/1990"))); } public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, - CloneVAppOptions[].class); + CloneVAppOptions[].class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/4181"), "my-vapp"); + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-vapp"); - assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")), - "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -163,16 +163,17 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, - CloneVAppOptions[].class); + CloneVAppOptions[].class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/201"), "new-linux-server", new CloneVAppOptions() - .deploy().powerOn().withDescription("The description of the new vApp")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "new-linux-server", + new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp")); - assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml")), - "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); assertResponseParserClassEquals(method, request, ParseSax.class); assertSaxResponseParserClassEquals(method, TaskHandler.class); @@ -185,7 +186,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("getDefaultOrganization"); HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); assertPayloadEquals(request, null, null, false); @@ -199,9 +200,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getOrganization", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/org/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/org/1")); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); assertPayloadEquals(request, null, null, false); @@ -216,7 +217,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("findOrganizationNamed", String.class); HttpRequest request = processor.createRequest(method, "org"); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); assertPayloadEquals(request, null, null, false); @@ -231,7 +232,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("getDefaultCatalog"); HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); assertPayloadEquals(request, null, null, false); @@ -245,9 +246,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalog", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1")); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); assertPayloadEquals(request, null, null, false); @@ -262,7 +263,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("findCatalogInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, "org", "catalog"); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); assertPayloadEquals(request, null, null, false); @@ -276,9 +277,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getNetwork", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/network/2")); + .create("https://vcenterprise.bluelock.com/api/v1.0/network/2")); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/network/2 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/network/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); assertPayloadEquals(request, null, null, false); @@ -292,9 +293,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")); + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2")); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); assertPayloadEquals(request, null, null, false); @@ -307,10 +308,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, String.class, - String.class); + String.class); HttpRequest request = processor.createRequest(method, "org", "catalog", "item"); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); assertPayloadEquals(request, null, null, false); @@ -323,10 +324,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class, - String.class, String.class); + String.class, String.class); HttpRequest request = processor.createRequest(method, "org", "catalog", "template"); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); assertPayloadEquals(request, null, null, false); @@ -340,9 +341,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); assertPayloadEquals(request, null, null, false); @@ -357,7 +358,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("getDefaultVDC"); HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertPayloadEquals(request, null, null, false); @@ -372,7 +373,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, "org", "vdc"); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertPayloadEquals(request, null, null, false); @@ -399,7 +400,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, null, "vdc"); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertPayloadEquals(request, null, null, false); @@ -414,7 +415,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, null, null); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertPayloadEquals(request, null, null, false); @@ -428,9 +429,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1")); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertPayloadEquals(request, null, null, false); @@ -445,7 +446,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("getDefaultTasksList"); HttpRequest request = processor.createRequest(method); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/taskslist HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/taskslist HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); assertPayloadEquals(request, null, null, false); @@ -459,9 +460,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getTasksList", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); assertPayloadEquals(request, null, null, false); @@ -476,7 +477,7 @@ public class VCloudAsyncClientTest extends RestClientTest { Method method = VCloudAsyncClient.class.getMethod("findTasksListInOrgNamed", String.class, String.class); HttpRequest request = processor.createRequest(method, "org", "tasksList"); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); assertPayloadEquals(request, null, null, false); @@ -490,9 +491,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("deployVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); - assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/deploy HTTP/1.1"); + assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -506,9 +507,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); assertPayloadEquals(request, null, null, false); @@ -522,9 +523,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("undeployVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); - assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/undeploy HTTP/1.1"); + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -538,9 +540,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("deleteVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); - assertRequestLineEquals(request, "DELETE https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1"); + assertRequestLineEquals(request, "DELETE https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -554,10 +556,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOn HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -571,10 +573,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOff HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -588,10 +590,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testReset() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("resetVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/reset HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -605,10 +607,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testSuspend() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("suspendVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/suspend HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -622,10 +624,10 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testShutdown() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); assertRequestLineEquals(request, - "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/shutdown HTTP/1.1"); + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -639,9 +641,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getTask", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/task/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); - assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/task/1 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/task/1 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertPayloadEquals(request, null, null, false); @@ -655,9 +657,9 @@ public class VCloudAsyncClientTest extends RestClientTest { public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("cancelTask", URI.class); HttpRequest request = processor.createRequest(method, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/task/1")); + .create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); - assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/task/1/action/cancel HTTP/1.1"); + assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/task/1/action/cancel HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); @@ -688,7 +690,7 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override public ContextSpec createContextSpec() { Properties overrides = new Properties(); - overrides.setProperty("vcloud.endpoint", "https://vcloud.safesecureweb.com/api/v0.8"); + overrides.setProperty("vcloud.endpoint", "https://vcenterprise.bluelock.com/api/v1.0"); return new RestContextFactory().createContextSpec("vcloud", "identity", "credential", overrides); } @@ -697,13 +699,13 @@ public class VCloudAsyncClientTest extends RestClientTest { public static class VCloudRestClientModuleExtension extends VCloudRestClientModule { @Override protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, - @Named(PROPERTY_API_VERSION) String version) { - return URI.create("https://vcloud.safesecureweb.com/api/v0.8/login"); + @Named(PROPERTY_API_VERSION) String version) { + return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login"); } @Override protected URI provideOrg(@Org Iterable orgs) { - return URI.create("https://vcloud.safesecureweb.com/api/v0.8/org"); + return URI.create("https://vcenterprise.bluelock.com/api/v1.0/org"); } @@ -714,7 +716,7 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) { - return URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog"); + return URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog"); } @@ -730,28 +732,28 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override protected URI provideDefaultTasksList(Organization org) { - return URI.create("https://vcloud.safesecureweb.com/api/v0.8/taskslist"); + return URI.create("https://vcenterprise.bluelock.com/api/v1.0/taskslist"); } @Override protected URI provideDefaultVDC(Organization org) { - return URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"); + return URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"); } @Override protected URI provideDefaultNetwork(VCloudClient client) { - return URI.create("https://vcloud.safesecureweb.com/network/1990"); + return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"); } @Override protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final VCloudLoginAsyncClient login) { + final VCloudLoginAsyncClient login) { return Suppliers. ofInstance(new VCloudSession() { @Override public Map getOrgs() { return ImmutableMap. of("org", new NamedResourceImpl("org", - VCloudMediaType.ORG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"))); + VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"))); } @Override @@ -772,18 +774,41 @@ public class VCloudAsyncClientTest extends RestClientTest { } protected Supplier>> provideOrganizationVDCSupplierCache( - @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationVDCSupplier supplier) { + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationVDCSupplier supplier) { - return Suppliers.>> ofInstance(ImmutableMap - .> of("org", + return Suppliers + .>> ofInstance(ImmutableMap + .> of( + "org", - ImmutableMap. of("vdc", new VDCImpl("vdc", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "description", null, null, null, null, - null, ImmutableMap. of("vapp", new NamedResourceImpl("vapp", - "application/vnd.vmware.vcloud.vApp+xml", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")), "network", - new NamedResourceImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), null)))); + ImmutableMap + . of( + "vdc", + new VDCImpl( + "vdc", + URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), + "description", + null, + null, + null, + null, + null, + ImmutableMap + . of( + "vapp", + new NamedResourceImpl( + "vapp", + "application/vnd.vmware.vcloud.vApp+xml", + URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")), + "network", + new NamedResourceImpl( + "network", + "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))), + null)))); } @@ -797,14 +822,15 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override public Map get() { return ImmutableMap. of("org", new OrganizationImpl("org", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), ImmutableMap. of( - "catalog", new NamedResourceImpl("catalog", VCloudMediaType.CATALOG_XML, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap - . of("vdc", new NamedResourceImpl("vdc", VCloudMediaType.VDC_XML, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap - . of("tasksList", new NamedResourceImpl("tasksList", - VCloudMediaType.TASKSLIST_XML, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1"))))); + .create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), ImmutableMap + . of("catalog", new NamedResourceImpl("catalog", + VCloudMediaType.CATALOG_XML, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap + . of("vdc", new NamedResourceImpl("vdc", VCloudMediaType.VDC_XML, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap + . of("tasksList", new NamedResourceImpl("tasksList", + VCloudMediaType.TASKSLIST_XML, URI + .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1"))))); } } @@ -817,15 +843,32 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override public Map> get() { - return ImmutableMap.> of("org", + return ImmutableMap + .> of( + "org", - ImmutableMap. of("catalog", new CatalogImpl("catalog", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"), "description", ImmutableMap - . of("item", new NamedResourceImpl("item", - "application/vnd.vmware.vcloud.catalogItem+xml", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")), "template", - new NamedResourceImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")))))); + ImmutableMap + . of( + "catalog", + new CatalogImpl( + "catalog", + URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), + "description", + ImmutableMap + . of( + "item", + new NamedResourceImpl( + "item", + "application/vnd.vmware.vcloud.catalogItem+xml", + URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")), + "template", + new NamedResourceImpl( + "template", + "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2")))))); } } @@ -837,14 +880,26 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override public Map>> get() { - return ImmutableMap.>> of( - "org", ImmutableMap.> of( - "catalog", ImmutableMap. of("template", - new CatalogItemImpl("template", URI - .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), "description", - new NamedResourceImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", - URI.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")), - ImmutableMap. of())))); + return ImmutableMap + .>> of( + "org", + ImmutableMap + .> of( + "catalog", + ImmutableMap + . of( + "template", + new CatalogItemImpl( + "template", + URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), + "description", + new NamedResourceImpl( + "template", + "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")), + ImmutableMap. of())))); } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java index c25943fe9f..600fda0805 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -53,6 +53,7 @@ public class VCloudClientLiveTest { protected VCloudClient connection; protected String identity; protected RestContext context; + private String credential; @Test public void testOrganization() throws Exception { @@ -156,16 +157,17 @@ public class VCloudClientLiveTest { } } + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("vcloud.identity"), "vcloud.identity"); + credential = checkNotNull(System.getProperty("vcloud.credential"), "vcloud.credential"); + } + @BeforeGroups(groups = { "live" }) public void setupClient() { - String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint"); - identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); - String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); - + setupCredentials(); Properties props = new Properties(); - props.setProperty("vcloud.endpoint", endpoint); context = new RestContextFactory().createContext("vcloud", identity, credential, ImmutableSet - . of(new Log4JLoggingModule()), props); + . of(new Log4JLoggingModule()), props); connection = context.getApi(); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressAsyncClientTest.java new file mode 100644 index 0000000000..a809bb99c6 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressAsyncClientTest.java @@ -0,0 +1,870 @@ +/** + * + * Copyright (C) 2010 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.vcloud; + +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.Constants.PROPERTY_IDENTITY; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Properties; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.RequiresHttp; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.rest.RestContextFactory.ContextSpec; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.util.Utils; +import org.jclouds.vcloud.config.VCloudExpressRestClientModule; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.internal.CatalogImpl; +import org.jclouds.vcloud.domain.internal.CatalogItemImpl; +import org.jclouds.vcloud.domain.internal.NamedResourceImpl; +import org.jclouds.vcloud.domain.internal.OrganizationImpl; +import org.jclouds.vcloud.domain.internal.VDCImpl; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.filters.SetVCloudTokenCookie; +import org.jclouds.vcloud.internal.VCloudLoginAsyncClient; +import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient; +import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; +import org.jclouds.vcloud.options.CloneVAppOptions; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.jclouds.vcloud.xml.CatalogHandler; +import org.jclouds.vcloud.xml.CatalogItemHandler; +import org.jclouds.vcloud.xml.NetworkHandler; +import org.jclouds.vcloud.xml.OrgHandler; +import org.jclouds.vcloud.xml.TaskHandler; +import org.jclouds.vcloud.xml.TasksListHandler; +import org.jclouds.vcloud.xml.VAppHandler; +import org.jclouds.vcloud.xml.VAppTemplateHandler; +import org.jclouds.vcloud.xml.VDCHandler; +import org.testng.annotations.Test; + +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code VCloudExpressAsyncClient} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.VCloudExpressAsyncClientTest") +public class VCloudExpressAsyncClientTest extends RestClientTest { + + public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, + String.class, InstantiateVAppTemplateOptions[].class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp"); + + assertRequestLineEquals(request, + "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); + assertPayloadEquals(request, Utils.toStringAndClose(getClass() + .getResourceAsStream("/express/newvapp-hosting.xml")), + "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException, + IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, + String.class, InstantiateVAppTemplateOptions[].class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", processorCount(1) + .memory(512).disk(1024).fenceMode("allowInOut").inNetwork( + URI.create("https://vcloud.safesecureweb.com/network/1990"))); + + assertRequestLineEquals(request, + "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); + assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream( + "/express/newvapp-hostingcpumemdisk.xml")), + "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException, + IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, + String.class, InstantiateVAppTemplateOptions[].class); + processor.createRequest(method, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "CentOS 01", processorCount(1).memory(512) + .disk(1024).inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990"))); + } + + public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, + CloneVAppOptions[].class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/4181"), "my-vapp"); + + assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream( + "/express/cloneVApp-default.xml")), "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, + CloneVAppOptions[].class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/201"), "new-linux-server", + new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp")); + + assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/cloneVApp HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/express/cloneVApp.xml")), + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDefaultOrganization() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getDefaultOrganization"); + HttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getOrganization", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/org/1")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindOrganizationNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findOrganizationNamed", String.class); + HttpRequest request = processor.createRequest(method, "org"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/org/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testDefaultCatalog() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getDefaultCatalog"); + HttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getCatalog", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCatalogInOrg() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findCatalogInOrgNamed", String.class, String.class); + HttpRequest request = processor.createRequest(method, "org", "catalog"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalog/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getNetwork", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/network/2")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/network/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, NetworkHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getCatalogItem", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, + String.class, String.class); + HttpRequest request = processor.createRequest(method, "org", "catalog", "item"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class, + String.class, String.class); + HttpRequest request = processor.createRequest(method, "org", "catalog", "template"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getVAppTemplate", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getDefaultVDC"); + HttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testFindVDCInOrgNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); + HttpRequest request = processor.createRequest(method, "org", "vdc"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + @Test(expectedExceptions = NoSuchElementException.class) + public void testFindVDCInOrgNamedBadVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); + processor.createRequest(method, "org", "vdc1"); + } + + @Test(expectedExceptions = NoSuchElementException.class) + public void testFindVDCInOrgNamedBadOrg() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); + processor.createRequest(method, "org1", "vdc"); + } + + public void testFindVDCInOrgNamedNullOrg() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); + HttpRequest request = processor.createRequest(method, null, "vdc"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindVDCInOrgNamedNullOrgAndVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findVDCInOrgNamed", String.class, String.class); + HttpRequest request = processor.createRequest(method, null, null); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getVDC", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vdc/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetDefaultTasksList() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getDefaultTasksList"); + HttpRequest request = processor.createRequest(method); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/taskslist HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TasksListHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getTasksList", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TasksListHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindTasksListInOrgNamed() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("findTasksListInOrgNamed", String.class, String.class); + HttpRequest request = processor.createRequest(method, "org", "tasksList"); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/tasksList/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TasksListHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("deployVApp", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + + assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/deploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getVApp", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("undeployVApp", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + + assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/action/undeploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("deleteVApp", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + + assertRequestLineEquals(request, "DELETE https://vcloud.safesecureweb.com/api/v0.8/vApp/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("powerOnVApp", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + + assertRequestLineEquals(request, + "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOn HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("powerOffVApp", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + + assertRequestLineEquals(request, + "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/powerOff HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testReset() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("resetVApp", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + + assertRequestLineEquals(request, + "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/reset HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testSuspend() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("suspendVApp", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + + assertRequestLineEquals(request, + "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/suspend HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testShutdown() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("shutdownVApp", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/1")); + + assertRequestLineEquals(request, + "POST https://vcloud.safesecureweb.com/api/v0.8/vApp/1/power/action/shutdown HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("getTask", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/task/1")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/api/v0.8/task/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudExpressAsyncClient.class.getMethod("cancelTask", URI.class); + HttpRequest request = processor.createRequest(method, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/task/1")); + + assertRequestLineEquals(request, "POST https://vcloud.safesecureweb.com/api/v0.8/task/1/action/cancel HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(request); + } + + @Override + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 1); + assertEquals(request.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + protected Module createModule() { + return new VCloudRestClientModuleExtension(); + } + + @Override + public ContextSpec createContextSpec() { + Properties overrides = new Properties(); + overrides.setProperty("vcloudexpress.endpoint", "https://vcloud.safesecureweb.com/api/v0.8"); + return new RestContextFactory().createContextSpec("vcloudexpress", "identity", "credential", overrides); + } + + @RequiresHttp + @ConfiguresRestClient + public static class VCloudRestClientModuleExtension extends VCloudExpressRestClientModule { + @Override + protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, + @Named(PROPERTY_API_VERSION) String version) { + return URI.create("https://vcloud.safesecureweb.com/api/v0.8/login"); + } + + @Override + protected URI provideOrg(@Org Iterable orgs) { + return URI.create("https://vcloud.safesecureweb.com/api/v0.8/org"); + + } + + @Override + protected String provideOrgName(@Org Iterable orgs) { + return "org"; + } + + @Override + protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) { + return URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog"); + + } + + @Override + protected Organization provideOrganization(VCloudExpressClient discovery) { + return null; + } + + @Override + protected Iterable provideOrgs(Supplier cache, @Named(PROPERTY_IDENTITY) String user) { + return null; + } + + @Override + protected URI provideDefaultTasksList(Organization org) { + return URI.create("https://vcloud.safesecureweb.com/api/v0.8/taskslist"); + } + + @Override + protected URI provideDefaultVDC(Organization org) { + return URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"); + } + + @Override + protected URI provideDefaultNetwork(VCloudExpressClient client) { + return URI.create("https://vcloud.safesecureweb.com/network/1990"); + } + + @Override + protected Supplier provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + final VCloudLoginAsyncClient login) { + return Suppliers. ofInstance(new VCloudSession() { + + @Override + public Map getOrgs() { + return ImmutableMap. of("org", new NamedResourceImpl("org", + VCloudExpressMediaType.ORG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/org/1"))); + } + + @Override + public String getVCloudToken() { + return "token"; + } + + }); + + } + + @Override + protected void configure() { + super.configure(); + bind(OrganizationMapSupplier.class).to(TestOrganizationMapSupplier.class); + bind(OrganizationCatalogSupplier.class).to(TestOrganizationCatalogSupplier.class); + bind(OrganizationCatalogItemSupplier.class).to(TestOrganizationCatalogItemSupplier.class); + } + + protected Supplier>> provideOrganizationVDCSupplierCache( + @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationVDCSupplier supplier) { + + return Suppliers.>> ofInstance(ImmutableMap + .> of("org", + + ImmutableMap. of("vdc", new VDCImpl("vdc", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "description", null, null, null, + null, null, ImmutableMap. of("vapp", new NamedResourceImpl("vapp", + "application/vnd.vmware.vcloud.vApp+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")), + "network", new NamedResourceImpl("network", + "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdcItem/2"))), + null)))); + + } + + @Singleton + public static class TestOrganizationMapSupplier extends OrganizationMapSupplier { + @Inject + protected TestOrganizationMapSupplier() { + super(null, null); + } + + @Override + public Map get() { + return ImmutableMap. of("org", new OrganizationImpl("org", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/org/1"), ImmutableMap + . of("catalog", new NamedResourceImpl("catalog", + VCloudExpressMediaType.CATALOG_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap + . of("vdc", new NamedResourceImpl("vdc", VCloudExpressMediaType.VDC_XML, + URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap + . of("tasksList", new NamedResourceImpl("tasksList", + VCloudExpressMediaType.TASKSLIST_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1"))))); + } + } + + @Singleton + public static class TestOrganizationCatalogSupplier extends OrganizationCatalogSupplier { + @Inject + protected TestOrganizationCatalogSupplier() { + super(null, null); + } + + @Override + public Map> get() { + return ImmutableMap.> of("org", + + ImmutableMap. of("catalog", new CatalogImpl("catalog", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"), "description", ImmutableMap + . of("item", new NamedResourceImpl("item", + "application/vnd.vmware.vcloud.catalogItem+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")), "template", + new NamedResourceImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")))))); + } + } + + @Singleton + public static class TestOrganizationCatalogItemSupplier extends OrganizationCatalogItemSupplier { + protected TestOrganizationCatalogItemSupplier() { + super(null, null); + } + + @Override + public Map>> get() { + return ImmutableMap + .>> of( + "org", + ImmutableMap + .> of( + "catalog", + ImmutableMap + . of( + "template", + new CatalogItemImpl( + "template", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"), + "description", + new NamedResourceImpl( + "template", + "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")), + ImmutableMap. of())))); + + } + } + + } + +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressClientLiveTest.java new file mode 100644 index 0000000000..b14e0d6a8d --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressClientLiveTest.java @@ -0,0 +1,175 @@ +/** + * + * Copyright (C) 2010 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.vcloud; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.util.Properties; + +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.Network; +import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VDC; +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 VCloudClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", sequential = true, testName = "vcloud.VCloudClientLiveTest") +public class VCloudExpressClientLiveTest { + + protected VCloudExpressClient connection; + protected String identity; + protected RestContext context; + private String credential; + + @Test + public void testOrganization() throws Exception { + Organization response = connection.findOrganizationNamed(null); + assertNotNull(response); + assertNotNull(response.getName()); + assert response.getCatalogs().size() >= 1; + assert response.getTasksLists().size() >= 1; + assert response.getVDCs().size() >= 1; + assertEquals(connection.findOrganizationNamed(response.getName()), response); + } + + @Test + public void testCatalog() throws Exception { + Catalog response = connection.findCatalogInOrgNamed(null, null); + assertNotNull(response); + assertNotNull(response.getName()); + assertNotNull(response.getId()); + assertEquals(connection.findCatalogInOrgNamed(null, response.getName()), response); + } + + @Test + public void testGetNetwork() throws Exception { + VDC response = connection.findVDCInOrgNamed(null, null); + for (NamedResource resource : response.getAvailableNetworks().values()) { + if (resource.getType().equals(VCloudExpressMediaType.NETWORK_XML)) { + Network item = connection.getNetwork(resource.getId()); + assertNotNull(item); + } + } + } + + @Test + public void testGetCatalogItem() throws Exception { + Catalog response = connection.findCatalogInOrgNamed(null, null); + for (NamedResource resource : response.values()) { + if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) { + CatalogItem item = connection.findCatalogItemInOrgCatalogNamed(null, null, resource.getName()); + assertNotNull(item); + assertNotNull(item.getEntity()); + assertNotNull(item.getId()); + assertNotNull(item.getProperties()); + assertNotNull(item.getType()); + } + } + } + + @Test + public void testGetVAppTemplate() throws Exception { + Catalog response = connection.findCatalogInOrgNamed(null, null); + for (NamedResource resource : response.values()) { + if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) { + CatalogItem item = connection.getCatalogItem(resource.getId()); + if (item.getEntity().getType().equals(VCloudExpressMediaType.VAPPTEMPLATE_XML)) { + assertNotNull(connection.findVAppTemplateInOrgCatalogNamed(null, null, item.getEntity().getName())); + } + } + } + } + + @Test + public void testDefaultVDC() throws Exception { + VDC response = connection.findVDCInOrgNamed(null, null); + assertNotNull(response); + assertNotNull(response.getName()); + assertNotNull(response.getId()); + assertNotNull(response.getResourceEntities()); + assertNotNull(response.getAvailableNetworks()); + assertEquals(connection.getVDC(response.getId()), response); + } + + @Test + public void testDefaultTasksList() throws Exception { + org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null, null); + assertNotNull(response); + assertNotNull(response.getLocation()); + assertNotNull(response.getTasks()); + assertEquals(connection.getTasksList(response.getLocation()).getLocation(), response.getLocation()); + } + + @Test + public void testGetTask() throws Exception { + org.jclouds.vcloud.domain.TasksList response = connection.findTasksListInOrgNamed(null, null); + assertNotNull(response); + assertNotNull(response.getLocation()); + assertNotNull(response.getTasks()); + if (response.getTasks().size() > 0) { + Task task = response.getTasks().last(); + assertEquals(connection.getTask(task.getLocation()).getLocation(), task.getLocation()); + } + } + + @Test + public void testGetVApp() throws Exception { + VDC response = connection.findVDCInOrgNamed(null, null); + for (NamedResource item : response.getResourceEntities().values()) { + if (item.getType().equals(VCloudExpressMediaType.VAPP_XML)) { + VApp app = connection.getVApp(item.getId()); + assertNotNull(app); + } + } + } + + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("vcloudexpress.identity"), "vcloudexpress.identity"); + credential = checkNotNull(System.getProperty("vcloudexpress.credential"), "vcloudexpress.credential"); + } + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + setupCredentials(); + Properties props = new Properties(); + context = new RestContextFactory().createContext("vcloudexpress", identity, credential, ImmutableSet + . of(new Log4JLoggingModule()), props); + + connection = context.getApi(); + } + +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayloadTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayloadTest.java index ccb79b2764..d15325e409 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayloadTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayloadTest.java @@ -54,8 +54,7 @@ public class BindCloneVAppParamsToXmlPayloadTest { @Override protected void configure() { Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), - "properties")); + Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); } }); @@ -70,19 +69,17 @@ public class BindCloneVAppParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindCloneVAppParamsToXmlPayload binder = injector - .getInstance(BindCloneVAppParamsToXmlPayload.class); + BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("newName", "new-linux-server"); - map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/201"); + map.put("vApp", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201"); binder.bindToRequest(request, map); verify(request); } public void testDefault() throws IOException { - String expected = Utils.toStringAndClose(getClass().getResourceAsStream( - "/cloneVApp-default.xml")); + String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")); GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); @@ -90,12 +87,11 @@ public class BindCloneVAppParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindCloneVAppParamsToXmlPayload binder = injector - .getInstance(BindCloneVAppParamsToXmlPayload.class); + BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("newName", "my-vapp"); - map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181"); + map.put("vApp", "https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"); binder.bindToRequest(request, map); verify(request); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java index b46046ee40..cbc6d7ef85 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -56,17 +56,13 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { @Override protected void configure() { Properties props = new Properties(); - props - .put(PROPERTY_VCLOUD_DEFAULT_NETWORK, - "https://vcloud.safesecureweb.com/network/1990"); - Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), - "properties")); + props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK, "https://vcenterprise.bluelock.com/api/v1.0/network/1990"); + Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); } }); public void testDefault() throws IOException { - String expected = Utils.toStringAndClose(getClass().getResourceAsStream( - "/newvapp-hosting.xml")); + String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp.xml")); GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); @@ -78,7 +74,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { Map map = Maps.newHashMap(); map.put("name", "my-vapp"); - map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); + map.put("template", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"); binder.bindToRequest(request, map); verify(request); @@ -88,8 +84,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); options.processorCount(1).memory(512).disk(1024); - String expected = Utils.toStringAndClose(getClass().getResourceAsStream( - "/newvapp-hostingcpumemdisk.xml")); + String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-cpumemdisk.xml")); GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); expect(request.getArgs()).andReturn(new Object[] { options }).atLeastOnce(); @@ -101,8 +96,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { Map map = Maps.newHashMap(); map.put("name", "my-vapp"); - map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); - map.put("network", "https://vcloud.safesecureweb.com/network/1990"); + map.put("template", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"); + map.put("network", "https://vcenterprise.bluelock.com/api/v1.0/network/1990"); binder.bindToRequest(request, map); verify(request); @@ -110,8 +105,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { } public void testWithNetworkNameDhcpFenceMode() throws IOException { - String expected = Utils.toStringAndClose(getClass().getResourceAsStream( - "/newvapp-hostingnetworknamedhcpfencemode.xml")); + String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-networknamedhcpfencemode.xml")); GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); @@ -124,8 +118,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { Map map = Maps.newHashMap(); map.put("name", "my-vapp"); - map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); - map.put("network", "https://vcloud.safesecureweb.com/network/1990"); + map.put("template", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"); + map.put("network", "https://vcenterprise.bluelock.com/api/v1.0/network/1990"); map.put("networkName", "aloha"); map.put("fenceMode", FenceMode.BRIDGED); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/VCloudExpressBindCloneVAppParamsToXmlPayloadTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/VCloudExpressBindCloneVAppParamsToXmlPayloadTest.java new file mode 100644 index 0000000000..a9176fba3a --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/VCloudExpressBindCloneVAppParamsToXmlPayloadTest.java @@ -0,0 +1,98 @@ +/** + * + * Copyright (C) 2010 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.vcloud.binders; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import java.util.Properties; + +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.util.Utils; +import org.jclouds.vcloud.VCloudExpressPropertiesBuilder; +import org.jclouds.vcloud.options.CloneVAppOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.Maps; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.name.Names; + +/** + * Tests behavior of {@code BindCloneVAppParamsToXmlPayload} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.BindCloneVAppParamsToXmlPayloadTest") +public class VCloudExpressBindCloneVAppParamsToXmlPayloadTest { + Injector injector = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + Properties props = new Properties(); + Names.bindProperties(binder(), checkNotNull(new VCloudExpressPropertiesBuilder(props).build(), "properties")); + } + }); + + public void testWithDescriptionDeployOn() throws IOException { + String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/express/cloneVApp.xml")); + + CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().withDescription( + "The description of the new vApp"); + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn(new Object[] { options }).atLeastOnce(); + request.setPayload(expected); + replay(request); + + BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); + + Map map = Maps.newHashMap(); + map.put("newName", "new-linux-server"); + map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/201"); + binder.bindToRequest(request, map); + verify(request); + } + + public void testDefault() throws IOException { + String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/express/cloneVApp-default.xml")); + + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); + request.setPayload(expected); + replay(request); + + BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); + + Map map = Maps.newHashMap(); + map.put("newName", "my-vapp"); + map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181"); + binder.bindToRequest(request, map); + verify(request); + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest.java new file mode 100644 index 0000000000..8f14f070fe --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -0,0 +1,132 @@ +/** + * + * Copyright (C) 2010 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.vcloud.binders; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; + +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import java.util.Properties; + +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.util.Utils; +import org.jclouds.vcloud.VCloudExpressPropertiesBuilder; +import org.jclouds.vcloud.domain.FenceMode; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.Maps; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.name.Names; + +/** + * Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlPayloadTest") +public class VCloudExpressBindInstantiateVAppTemplateParamsToXmlPayloadTest { + Injector injector = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + Properties props = new Properties(); + props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK, "https://vcloud.safesecureweb.com/network/1990"); + Names.bindProperties(binder(), checkNotNull(new VCloudExpressPropertiesBuilder(props).build(), "properties")); + } + }); + + public void testDefault() throws IOException { + String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/express/newvapp-hosting.xml")); + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); + request.setPayload(expected); + replay(request); + + BindInstantiateVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + + Map map = Maps.newHashMap(); + map.put("name", "my-vapp"); + map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); + binder.bindToRequest(request, map); + verify(request); + + } + + public void testWithProcessorMemoryDisk() throws IOException { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + options.processorCount(1).memory(512).disk(1024); + + String expected = Utils + .toStringAndClose(getClass().getResourceAsStream("/express/newvapp-hostingcpumemdisk.xml")); + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn(new Object[] { options }).atLeastOnce(); + request.setPayload(expected); + replay(request); + + BindInstantiateVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + + Map map = Maps.newHashMap(); + map.put("name", "my-vapp"); + map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); + map.put("network", "https://vcloud.safesecureweb.com/network/1990"); + + binder.bindToRequest(request, map); + verify(request); + + } + + public void testWithNetworkNameDhcpFenceMode() throws IOException { + String expected = Utils.toStringAndClose(getClass().getResourceAsStream( + "/express/newvapp-hostingnetworknamedhcpfencemode.xml")); + + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); + request.setPayload(expected); + replay(request); + + BindInstantiateVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + + Map map = Maps.newHashMap(); + map.put("name", "my-vapp"); + map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); + map.put("network", "https://vcloud.safesecureweb.com/network/1990"); + map.put("networkName", "aloha"); + map.put("fenceMode", FenceMode.BRIDGED); + + binder.bindToRequest(request, map); + verify(request); + + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java index 446c8db74a..8b01de97a2 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java @@ -28,7 +28,6 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.net.URI; import java.util.Map; -import java.util.Properties; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -83,6 +82,8 @@ public class VCloudComputeClientLiveTest { protected Map expectationMap; protected Predicate addressTester; + private String identity; + private String credential; @Test(enabled = true) public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException, IOException { @@ -94,7 +95,7 @@ public class VCloudComputeClientLiveTest { VAppTemplate template = client.findVAppTemplateInOrgCatalogNamed(null, null, templateName); InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024).productProperties( - ImmutableMap.of("foo", "bar")); + ImmutableMap.of("foo", "bar")); id = URI.create(computeClient.start(null, template.getId(), templateName, options).get("id")); Expectation expectation = expectationMap.get(toTest); @@ -106,7 +107,7 @@ public class VCloudComputeClientLiveTest { private String getCompatibleServerName(OsFamily toTest) { String serverName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0, - toTest.toString().length() <= 15 ? toTest.toString().length() : 14); + toTest.toString().length() <= 15 ? toTest.toString().length() : 14); return serverName; } @@ -117,19 +118,20 @@ public class VCloudComputeClientLiveTest { } private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, int processorCount, - int memory, long hardDisk) { + int memory, long hardDisk) { // assertEquals(vApp.getName(), serverName); // assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(Iterables - .getOnlyElement(filter(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR))) - .getVirtualQuantity(), processorCount); + .getOnlyElement(filter(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR))) + .getVirtualQuantity(), processorCount); assertEquals(Iterables.getOnlyElement( - filter(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER))).getVirtualQuantity(), 1); + filter(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER))).getVirtualQuantity(), + 1); assertEquals(Iterables.getOnlyElement(filter(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY))) - .getVirtualQuantity(), memory); + .getVirtualQuantity(), memory); assertEquals(Iterables.getOnlyElement( - filter(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE))).getVirtualQuantity(), - hardDisk); + filter(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE))).getVirtualQuantity(), + hardDisk); } @AfterTest @@ -138,23 +140,23 @@ public class VCloudComputeClientLiveTest { computeClient.stop(id); } + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("vcloud.identity"), "vcloud.identity"); + credential = checkNotNull(System.getProperty("vcloud.credential"), "vcloud.credential"); + } + @BeforeGroups(groups = { "live" }) public void setupClient() { - String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); - String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); - String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint"); - - Properties props = new Properties(); - props.setProperty("vcloud.endpoint", endpoint); + setupCredentials(); Injector injector = new RestContextFactory().createContextBuilder("vcloud", identity, credential, - ImmutableSet. of(new Log4JLoggingModule()), props).buildInjector(); + ImmutableSet. of(new Log4JLoggingModule())).buildInjector(); computeClient = injector.getInstance(VCloudComputeClient.class); client = injector.getInstance(VCloudClient.class); addressTester = injector.getInstance(Key.get(new TypeLiteral>() { })); expectationMap = ImmutableMap. builder().put(OsFamily.CENTOS, - new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); + new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); provider = "vcloudtest"; templateName = "Ubuntu JeOS 9.10 (32-bit)"; } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java index 3aaa7c0482..77d34de59c 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java @@ -43,11 +43,15 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { @Override public void setServiceDefaults() { - System.setProperty("vcloud.endpoint", checkNotNull(System.getProperty("jclouds.test.endpoint"), - "jclouds.test.endpoint")); provider = "vcloud"; } + @Override + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("vcloud.identity"), "vcloud.identity"); + credential = checkNotNull(System.getProperty("vcloud.credential"), "vcloud.credential"); + } + @Override protected JschSshClientModule getSshModule() { return new JschSshClientModule(); @@ -56,7 +60,7 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { public void testAssignability() throws Exception { @SuppressWarnings("unused") RestContext tmContext = new ComputeServiceContextFactory().createContext( - provider, identity, credential).getProviderSpecificContext(); + provider, identity, credential).getProviderSpecificContext(); } @Override diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeClientLiveTest.java new file mode 100644 index 0000000000..ec49f08ad1 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeClientLiveTest.java @@ -0,0 +1,164 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; +import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.RestContextFactory; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.domain.ResourceType; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.base.CaseFormat; +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code VCloudClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", enabled = true, sequential = true, testName = "vcloud.VCloudClientLiveTest") +public class VCloudExpressComputeClientLiveTest { + protected String provider; + protected VCloudExpressComputeClient computeClient; + protected VCloudExpressClient client; + + protected URI id; + protected String publicAddress; + protected String templateName; + + public static class Expectation { + final long hardDisk; + final String os; + + public Expectation(long hardDisk, String os) { + this.hardDisk = hardDisk; + this.os = os; + } + } + + protected Map expectationMap; + + protected Predicate addressTester; + private String identity; + private String credential; + + @Test(enabled = true) + public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException, IOException { + OsFamily toTest = OsFamily.CENTOS; + + String serverName = getCompatibleServerName(toTest); + int processorCount = 1; + int memory = 512; + + VAppTemplate template = client.findVAppTemplateInOrgCatalogNamed(null, null, templateName); + InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024).productProperties( + ImmutableMap.of("foo", "bar")); + + id = URI.create(computeClient.start(null, template.getId(), templateName, options).get("id")); + Expectation expectation = expectationMap.get(toTest); + + VApp vApp = client.getVApp(id); + verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory, expectation.hardDisk); + assertEquals(vApp.getStatus(), VAppStatus.ON); + } + + private String getCompatibleServerName(OsFamily toTest) { + String serverName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0, + toTest.toString().length() <= 15 ? toTest.toString().length() : 14); + return serverName; + } + + @Test(dependsOnMethods = "testPowerOn", enabled = true) + public void testGetPublicAddresses() { + publicAddress = Iterables.getLast(computeClient.getPublicAddresses(id)); + assert !addressTester.apply(publicAddress); + } + + private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, int processorCount, + int memory, long hardDisk) { + // assertEquals(vApp.getName(), serverName); + // assertEquals(vApp.getOperatingSystemDescription(), expectedOs); + assertEquals(Iterables + .getOnlyElement(filter(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR))) + .getVirtualQuantity(), processorCount); + assertEquals(Iterables.getOnlyElement( + filter(vApp.getResourceAllocations(), resourceType(ResourceType.SCSI_CONTROLLER))).getVirtualQuantity(), + 1); + assertEquals(Iterables.getOnlyElement(filter(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY))) + .getVirtualQuantity(), memory); + assertEquals(Iterables.getOnlyElement( + filter(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE))).getVirtualQuantity(), + hardDisk); + } + + @AfterTest + void cleanup() throws InterruptedException, ExecutionException, TimeoutException { + if (id != null) + computeClient.stop(id); + } + + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("vcloudexpress.identity"), "vcloudexpress.identity"); + credential = checkNotNull(System.getProperty("vcloudexpress.credential"), "vcloudexpress.credential"); + } + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + setupCredentials(); + Injector injector = new RestContextFactory().createContextBuilder("vcloudexpress", identity, credential, + ImmutableSet. of(new Log4JLoggingModule())).buildInjector(); + + computeClient = injector.getInstance(VCloudExpressComputeClient.class); + client = injector.getInstance(VCloudExpressClient.class); + addressTester = injector.getInstance(Key.get(new TypeLiteral>() { + })); + expectationMap = ImmutableMap. builder().put(OsFamily.CENTOS, + new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); + provider = "vcloudtest"; + templateName = "Ubuntu JeOS 9.10 (32-bit)"; + } + +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeServiceLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeServiceLiveTest.java new file mode 100644 index 0000000000..832b90459a --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudExpressComputeServiceLiveTest.java @@ -0,0 +1,80 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.ComputeType; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.rest.RestContext; +import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressClient; +import org.testng.annotations.Test; + +/** + * + * + * @author Adrian Cole + */ +@Test(groups = "live", enabled = true, sequential = true, testName = "vcloud.VCloudExpressComputeServiceLiveTest") +public class VCloudExpressComputeServiceLiveTest extends BaseComputeServiceLiveTest { + + @Override + public void setServiceDefaults() { + provider = "vcloudexpress"; + } + + @Override + protected void setupCredentials() { + identity = checkNotNull(System.getProperty("vcloudexpress.identity"), "vcloudexpress.identity"); + credential = checkNotNull(System.getProperty("vcloudexpress.credential"), "vcloudexpress.credential"); + } + + @Override + protected JschSshClientModule getSshModule() { + return new JschSshClientModule(); + } + + public void testAssignability() throws Exception { + @SuppressWarnings("unused") + RestContext tmContext = new ComputeServiceContextFactory() + .createContext(provider, identity, credential).getProviderSpecificContext(); + } + + @Override + public void testListNodes() throws Exception { + for (ComputeMetadata node : client.listNodes()) { + assert node.getProviderId() != null; + assert node.getLocation() != null; + assertEquals(node.getType(), ComputeType.NODE); + NodeMetadata allData = client.getNodeMetadata(node.getId()); + assert allData.getExtra().get("processor/count") != null : allData.getExtra(); + assert allData.getExtra().get("disk_drive/0/kb") != null : allData.getExtra(); + assert allData.getExtra().get("memory/mb") != null : allData.getExtra(); + System.out.println(allData.getExtra()); + } + } + +} \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModuleTest.java new file mode 100644 index 0000000000..32836b6598 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudExpressComputeServiceContextModuleTest.java @@ -0,0 +1,38 @@ +/** + * + * Copyright (C) 2010 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.vcloud.compute.config; + +import org.jclouds.vcloud.domain.VAppStatus; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.VCloudExpressComputeServiceContextModuleTest") +public class VCloudExpressComputeServiceContextModuleTest { + + public void testAllStatusCovered() { + + for (VAppStatus state : VAppStatus.values()) { + assert VCloudExpressComputeServiceContextModule.vAppStatusToNodeState.containsKey(state) : state; + } + + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java index cf4f31ea74..49842e393b 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/functions/ParseLoginResponseFromHeadersTest.java @@ -28,7 +28,7 @@ import javax.ws.rs.core.HttpHeaders; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.io.Payloads; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; import org.testng.annotations.BeforeTest; @@ -59,7 +59,7 @@ public class ParseLoginResponseFromHeadersTest extends BaseHandlerTest { VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "9er4d061-4bff-48fa-84b1-5da7166764d2"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new NamedResourceImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); + VCloudExpressMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); } @@ -75,7 +75,7 @@ public class ParseLoginResponseFromHeadersTest extends BaseHandlerTest { VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "c9f232506df9b65d7b7d97b7499eddd7"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new NamedResourceImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); + VCloudExpressMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogItemHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogItemHandlerTest.java index 8ab0cc7b5a..6704615c75 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogItemHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogItemHandlerTest.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.xml; -import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOGITEM_XML; import static org.testng.Assert.assertEquals; import java.io.InputStream; diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java index fb6928d218..ce4ea7338f 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java @@ -19,8 +19,8 @@ package org.jclouds.vcloud.xml; -import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; -import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.TASKSLIST_XML; import static org.testng.Assert.assertEquals; import java.io.InputStream; @@ -29,7 +29,7 @@ import java.net.URI; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.SaxParserModule; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.testng.annotations.Test; @@ -59,7 +59,7 @@ public class OrgHandlerTest { "Miami Environment 1 Catalog", CATALOG_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")))); assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new NamedResourceImpl( - "Miami Environment 1", VCloudMediaType.VDC_XML, URI + "Miami Environment 1", VCloudExpressMediaType.VDC_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")))); assertEquals(result.getTasksLists(), ImmutableMap.of("Miami Environment 1 Tasks List", new NamedResourceImpl( "Miami Environment 1 Tasks List", TASKSLIST_XML, URI @@ -76,7 +76,7 @@ public class OrgHandlerTest { assertEquals(result.getCatalogs(), ImmutableMap.of("HMS Shared Catalog", new NamedResourceImpl( "HMS Shared Catalog", CATALOG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")))); assertEquals(result.getVDCs(), ImmutableMap.of("188849 Virtual DataCenter", new NamedResourceImpl( - "188849 Virtual DataCenter", VCloudMediaType.VDC_XML, URI + "188849 Virtual DataCenter", VCloudExpressMediaType.VDC_XML, URI .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")))); assertEquals(result.getTasksLists(), ImmutableMap.of("188849 Task List", new NamedResourceImpl("188849 Task List", TASKSLIST_XML, URI diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgListHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgListHandlerTest.java index 01a0371e7f..fa51ff5798 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgListHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgListHandlerTest.java @@ -26,7 +26,7 @@ import java.net.URI; import java.util.Map; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.testng.annotations.Test; @@ -46,6 +46,6 @@ public class OrgListHandlerTest extends BaseHandlerTest { Map result = factory.create(injector.getInstance(OrgListHandler.class)).parse(is); assertEquals(result, ImmutableMap.of("adrian@jclouds.org", new NamedResourceImpl("adrian@jclouds.org", - VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); + VCloudExpressMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")))); } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java index 2c59cef295..dc22c24af0 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java @@ -26,7 +26,7 @@ import java.net.URI; import org.jclouds.date.DateService; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.VAppStatus; @@ -60,8 +60,8 @@ public class TaskHandlerTest extends BaseHandlerTest { Task expects = new TaskImpl(URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"), TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), dateService .iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("VDC Name", - VCloudMediaType.VDC_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), - new NamedResourceImpl("Server1", VCloudMediaType.VAPP_XML, URI + VCloudExpressMediaType.VDC_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), + new NamedResourceImpl("Server1", VCloudExpressMediaType.VAPP_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012") ), null @@ -98,7 +98,7 @@ public class TaskHandlerTest extends BaseHandlerTest { .iso8601SecondsDateParse("2010-01-14T20:05:02Z"), dateService .iso8601SecondsDateParse("2010-01-15T20:05:02Z"), - new NamedResourceImpl("188849-96", VCloudMediaType.VAPP_XML, URI + new NamedResourceImpl("188849-96", VCloudExpressMediaType.VAPP_XML, URI .create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-96")), null, null); assertEquals(result, expects); } @@ -111,8 +111,8 @@ public class TaskHandlerTest extends BaseHandlerTest { Task expects = new TaskImpl(URI.create("http://10.150.4.49/api/v0.8/task/23"), TaskStatus.ERROR, dateService .iso8601SecondsDateParse("2009-12-07T19:05:02Z"), dateService .iso8601SecondsDateParse("2009-12-10T14:40:32Z"), null, new NamedResourceImpl("APIOrg", - VCloudMediaType.ORG_XML, URI.create("http://10.150.4.49/api/v0.8/org/1")), new NamedResourceImpl( - "testapp1", VCloudMediaType.VAPP_XML, URI.create("http://10.150.4.49/api/v0.8/vapp/1")), + VCloudExpressMediaType.ORG_XML, URI.create("http://10.150.4.49/api/v0.8/org/1")), new NamedResourceImpl( + "testapp1", VCloudExpressMediaType.VAPP_XML, URI.create("http://10.150.4.49/api/v0.8/vapp/1")), new TaskImpl.ErrorImpl("Error processing job", "500", " Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00")); assertEquals(result, expects); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java index 699616722c..846d1e1068 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java @@ -26,7 +26,7 @@ import java.net.URI; import org.jclouds.date.DateService; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.TasksList; @@ -64,15 +64,15 @@ public class TasksListHandlerTest extends BaseHandlerTest { URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3300"), TaskStatus.SUCCESS, dateService .iso8601DateParse("2009-08-24T21:30:19.587Z"), dateService.iso8601DateParse("2009-08-24T21:30:32.63Z"), - null, new NamedResourceImpl("VDC Name", VCloudMediaType.VDC_XML, URI + null, new NamedResourceImpl("VDC Name", VCloudExpressMediaType.VDC_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), new NamedResourceImpl( - "Server1", VCloudMediaType.VAPP_XML, URI + "Server1", VCloudExpressMediaType.VAPP_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")), null); Task task2 = new TaskImpl(URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"), TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), dateService .iso8601DateParse("2009-08-24T21:29:44.65Z"), null, new NamedResourceImpl("VDC Name", - VCloudMediaType.VDC_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), - new NamedResourceImpl("Server1", VCloudMediaType.VAPP_XML, URI + VCloudExpressMediaType.VDC_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), + new NamedResourceImpl("Server1", VCloudExpressMediaType.VAPP_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")), null); assertEquals(result.getTasks(), ImmutableSortedSet.of(task1, task2)); } diff --git a/vcloud/core/src/test/resources/cloneVApp-default.xml b/vcloud/core/src/test/resources/cloneVApp-default.xml index 48e0681e92..fdddd98fb4 100644 --- a/vcloud/core/src/test/resources/cloneVApp-default.xml +++ b/vcloud/core/src/test/resources/cloneVApp-default.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/cloneVApp.xml b/vcloud/core/src/test/resources/cloneVApp.xml index bdc3aaeb3a..35690f61fc 100644 --- a/vcloud/core/src/test/resources/cloneVApp.xml +++ b/vcloud/core/src/test/resources/cloneVApp.xml @@ -1 +1 @@ -The description of the new vApp \ No newline at end of file +The description of the new vApp \ No newline at end of file diff --git a/vcloud/core/src/test/resources/express/cloneVApp-default.xml b/vcloud/core/src/test/resources/express/cloneVApp-default.xml new file mode 100644 index 0000000000..48e0681e92 --- /dev/null +++ b/vcloud/core/src/test/resources/express/cloneVApp-default.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/express/cloneVApp.xml b/vcloud/core/src/test/resources/express/cloneVApp.xml new file mode 100644 index 0000000000..bdc3aaeb3a --- /dev/null +++ b/vcloud/core/src/test/resources/express/cloneVApp.xml @@ -0,0 +1 @@ +The description of the new vApp \ No newline at end of file diff --git a/vcloud/core/src/test/resources/newvapp-hosting.xml b/vcloud/core/src/test/resources/express/newvapp-hosting.xml similarity index 100% rename from vcloud/core/src/test/resources/newvapp-hosting.xml rename to vcloud/core/src/test/resources/express/newvapp-hosting.xml diff --git a/vcloud/core/src/test/resources/newvapp-hostingcpumemdisk.xml b/vcloud/core/src/test/resources/express/newvapp-hostingcpumemdisk.xml similarity index 100% rename from vcloud/core/src/test/resources/newvapp-hostingcpumemdisk.xml rename to vcloud/core/src/test/resources/express/newvapp-hostingcpumemdisk.xml diff --git a/vcloud/core/src/test/resources/newvapp-hostingnetworknamedhcpfencemode.xml b/vcloud/core/src/test/resources/express/newvapp-hostingnetworknamedhcpfencemode.xml similarity index 100% rename from vcloud/core/src/test/resources/newvapp-hostingnetworknamedhcpfencemode.xml rename to vcloud/core/src/test/resources/express/newvapp-hostingnetworknamedhcpfencemode.xml diff --git a/vcloud/core/src/test/resources/newvapp-cpumemdisk.xml b/vcloud/core/src/test/resources/newvapp-cpumemdisk.xml new file mode 100644 index 0000000000..20426183fe --- /dev/null +++ b/vcloud/core/src/test/resources/newvapp-cpumemdisk.xml @@ -0,0 +1 @@ +131245129171024bridged \ No newline at end of file diff --git a/vcloud/core/src/test/resources/newvapp-networknamedhcpfencemode.xml b/vcloud/core/src/test/resources/newvapp-networknamedhcpfencemode.xml new file mode 100644 index 0000000000..60c097b45a --- /dev/null +++ b/vcloud/core/src/test/resources/newvapp-networknamedhcpfencemode.xml @@ -0,0 +1 @@ +bridged \ No newline at end of file diff --git a/vcloud/core/src/test/resources/newvapp.xml b/vcloud/core/src/test/resources/newvapp.xml new file mode 100644 index 0000000000..60c097b45a --- /dev/null +++ b/vcloud/core/src/test/resources/newvapp.xml @@ -0,0 +1 @@ +bridged \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java index fbd10b2f81..47b0bf8b06 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java @@ -19,8 +19,8 @@ package org.jclouds.vcloud.hostingdotcom; -import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; -import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VAPP_XML; import java.net.URI; @@ -40,7 +40,7 @@ import org.jclouds.rest.annotations.ParamValidators; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; @@ -60,7 +60,7 @@ import com.google.common.util.concurrent.ListenableFuture; * @author Adrian Cole */ @RequestFilters(SetVCloudTokenCookie.class) -public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient { +public interface HostingDotComVCloudAsyncClient extends VCloudExpressAsyncClient { @GET @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java index f0cb42288a..91cab53760 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java @@ -23,7 +23,7 @@ import java.net.URI; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -36,7 +36,7 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; * @author Adrian Cole */ @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) -public interface HostingDotComVCloudClient extends VCloudClient { +public interface HostingDotComVCloudClient extends VCloudExpressClient { @Override @Timeout(duration = 600, timeUnit = TimeUnit.SECONDS) diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java index a760e292c7..24300385eb 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java @@ -24,7 +24,7 @@ import java.util.Properties; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; -import org.jclouds.vcloud.VCloudContextBuilder; +import org.jclouds.vcloud.VCloudExpressContextBuilder; import org.jclouds.vcloud.hostingdotcom.compute.config.HostingDotComVCloudComputeServiceContextModule; import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudRestClientModule; @@ -44,7 +44,7 @@ import com.google.inject.Module; * @author Adrian Cole * @see HostingDotComVCloudComputeServiceContext */ -public class HostingDotComVCloudContextBuilder extends VCloudContextBuilder { +public class HostingDotComVCloudContextBuilder extends VCloudExpressContextBuilder { public HostingDotComVCloudContextBuilder(Properties props) { super(props); diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudPropertiesBuilder.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudPropertiesBuilder.java index e9a6a1b1b4..79ea4dec00 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudPropertiesBuilder.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudPropertiesBuilder.java @@ -24,14 +24,14 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEO import java.util.Properties; -import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.VCloudExpressPropertiesBuilder; /** * Builds properties used in hosting.com VCloud Clients * * @author Adrian Cole */ -public class HostingDotComVCloudPropertiesBuilder extends VCloudPropertiesBuilder { +public class HostingDotComVCloudPropertiesBuilder extends VCloudExpressPropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java index bb89b0b253..6fd82e187b 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java @@ -26,8 +26,8 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.compute.domain.NodeState; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.compute.BaseVCloudComputeClient; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppTemplate; @@ -40,10 +40,10 @@ import com.google.common.collect.ImmutableMap; * @author Adrian Cole */ @Singleton -public class HostingDotComVCloudComputeClient extends BaseVCloudComputeClient { +public class HostingDotComVCloudComputeClient extends BaseVCloudExpressComputeClient { @Inject - protected HostingDotComVCloudComputeClient(VCloudClient client, Predicate successTester, + protected HostingDotComVCloudComputeClient(VCloudExpressClient client, Predicate successTester, Map vAppStatusToNodeState) { super(client, successTester, vAppStatusToNodeState); } diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/config/HostingDotComVCloudComputeServiceContextModule.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/config/HostingDotComVCloudComputeServiceContextModule.java index 7e930272c3..68cab3a3da 100755 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/config/HostingDotComVCloudComputeServiceContextModule.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/config/HostingDotComVCloudComputeServiceContextModule.java @@ -22,8 +22,8 @@ package org.jclouds.vcloud.hostingdotcom.compute.config; import static org.jclouds.compute.domain.OsFamily.CENTOS; import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.vcloud.compute.VCloudComputeClient; -import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; +import org.jclouds.vcloud.compute.VCloudExpressComputeClient; +import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule; import org.jclouds.vcloud.hostingdotcom.compute.HostingDotComVCloudComputeClient; import com.google.inject.Injector; @@ -34,12 +34,12 @@ import com.google.inject.Injector; * * @author Adrian Cole */ -public class HostingDotComVCloudComputeServiceContextModule extends VCloudComputeServiceContextModule { +public class HostingDotComVCloudComputeServiceContextModule extends VCloudExpressComputeServiceContextModule { @Override protected void configure() { super.configure(); - bind(VCloudComputeClient.class).to(HostingDotComVCloudComputeClient.class); + bind(VCloudExpressComputeClient.class).to(HostingDotComVCloudComputeClient.class); } @Override diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java index 86cd186403..1034d4dfaf 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java @@ -25,9 +25,9 @@ import javax.inject.Singleton; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.vcloud.VCloudAsyncClient; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.config.BaseVCloudRestClientModule; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule; import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudAsyncClient; import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient; @@ -43,7 +43,7 @@ import com.google.inject.Provides; @ConfiguresRestClient public class HostingDotComVCloudRestClientModule extends - BaseVCloudRestClientModule { + BaseVCloudExpressRestClientModule { public HostingDotComVCloudRestClientModule() { super(HostingDotComVCloudClient.class, @@ -52,19 +52,19 @@ public class HostingDotComVCloudRestClientModule @Provides @Singleton - protected VCloudAsyncClient provideVCloudAsyncClient( + protected VCloudExpressAsyncClient provideVCloudAsyncClient( HostingDotComVCloudAsyncClient in) { return in; } @Provides @Singleton - protected VCloudClient provideVCloudClient(HostingDotComVCloudClient in) { + protected VCloudExpressClient provideVCloudClient(HostingDotComVCloudClient in) { return in; } @Override - protected URI provideDefaultNetwork(VCloudClient client) { + protected URI provideDefaultNetwork(VCloudExpressClient client) { return URI.create("https://vcloud.safesecureweb.com/network/1990"); } diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java index 6c1759ea63..ecbada0a2b 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java @@ -38,7 +38,7 @@ import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.endpoints.Org; @@ -119,7 +119,7 @@ public class HostingDotComVCloudAsyncClientTest extends RestClientTest modules) { // TODO make ecloud version which retrieves passwords from the vapptemplate description - modules.add(new VCloudComputeServiceContextModule()); + modules.add(new VCloudExpressComputeServiceContextModule()); } @Override diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java index a755c6f133..c7a051bb0c 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java @@ -19,11 +19,11 @@ package org.jclouds.vcloud.terremark; -import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; -import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; -import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; -import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; -import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOGITEM_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.ORG_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VAPP_XML; +import static org.jclouds.vcloud.VCloudExpressMediaType.VDC_XML; import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.CATALOGITEMCUSTOMIZATIONPARAMETERS_XML; import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.INTERNETSERVICESLIST_XML; import static org.jclouds.vcloud.terremark.TerremarkVCloudMediaType.INTERNETSERVICE_XML; @@ -56,8 +56,8 @@ import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; -import org.jclouds.vcloud.VCloudAsyncClient; -import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; @@ -109,9 +109,9 @@ import com.google.common.util.concurrent.ListenableFuture; * @author Adrian Cole */ @RequestFilters(SetVCloudTokenCookie.class) -public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { +public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient { /** - * @see VCloudClient#getCatalogItemInOrg + * @see VCloudExpressClient#getCatalogItemInOrg */ @Override @GET @@ -124,7 +124,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName); /** - * @see VCloudClient#getCatalogItem + * @see VCloudExpressClient#getCatalogItem */ @Override @GET @@ -149,7 +149,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { ListenableFuture getOrganization(@EndpointParam URI orgId); /** - * @see VCloudClient#findOrganizationNamed + * @see VCloudExpressClient#findOrganizationNamed */ @Override @GET @@ -190,7 +190,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { ListenableFuture getVDC(@EndpointParam URI vdc); /** - * @see VCloudClient#findVDCInOrgNamed + * @see VCloudExpressClient#findVDCInOrgNamed */ @GET @Override @@ -202,7 +202,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName); /** - * @see VCloudClient#instantiateVAppTemplateInVDC + * @see VCloudExpressClient#instantiateVAppTemplateInVDC */ @Override @POST diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java index 1646a8491e..dbc638197a 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; import org.jclouds.concurrent.Timeout; -import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; @@ -50,7 +50,7 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions; * @author Adrian Cole */ @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) -public interface TerremarkVCloudClient extends VCloudClient { +public interface TerremarkVCloudClient extends VCloudExpressClient { @Override TerremarkCatalogItem getCatalogItem(URI catalogItem); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressContextBuilder.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressContextBuilder.java index 69d065fdb2..3ce7713c9f 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressContextBuilder.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressContextBuilder.java @@ -24,7 +24,7 @@ import java.util.Properties; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; -import org.jclouds.vcloud.VCloudContextBuilder; +import org.jclouds.vcloud.VCloudExpressContextBuilder; import org.jclouds.vcloud.terremark.compute.config.TerremarkVCloudComputeServiceContextModule; import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule; @@ -44,7 +44,7 @@ import com.google.inject.Module; * @author Adrian Cole * @see TerremarkVCloudComputeServiceContext */ -public class TerremarkVCloudExpressContextBuilder extends VCloudContextBuilder { +public class TerremarkVCloudExpressContextBuilder extends VCloudExpressContextBuilder { public TerremarkVCloudExpressContextBuilder(Properties props) { super(props); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudMediaType.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudMediaType.java index 951460c484..0da3343c3a 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudMediaType.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudMediaType.java @@ -21,14 +21,14 @@ package org.jclouds.vcloud.terremark; import javax.ws.rs.core.MediaType; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; /** * Resource Types used in Terremark VCloud * * @see MediaType */ -public interface TerremarkVCloudMediaType extends VCloudMediaType { +public interface TerremarkVCloudMediaType extends VCloudExpressMediaType { /** * "application/vnd.tmrk.vCloud.publicIp+xml" diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java index 73c6f3ba99..e9389b8b38 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudPropertiesBuilder.java @@ -26,14 +26,14 @@ import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY import java.util.Properties; -import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.VCloudExpressPropertiesBuilder; /** * Builds properties used in Terremark VCloud Clients * * @author Adrian Cole */ -public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder { +public class TerremarkVCloudPropertiesBuilder extends VCloudExpressPropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java index 657b093ab3..2cf0f2859e 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java @@ -38,7 +38,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.domain.Credentials; -import org.jclouds.vcloud.compute.BaseVCloudComputeClient; +import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.TasksList; @@ -61,7 +61,7 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Singleton -public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient { +public class TerremarkVCloudComputeClient extends BaseVCloudExpressComputeClient { private final TerremarkVCloudExpressClient client; private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider; diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java index 958c3f5ee3..0262264685 100755 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java @@ -42,13 +42,13 @@ import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; -import org.jclouds.vcloud.VCloudAsyncClient; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.compute.VCloudComputeClient; -import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule; -import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy; -import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; -import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.compute.VCloudExpressComputeClient; +import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule; +import org.jclouds.vcloud.compute.strategy.VCloudExpressDestroyNodeStrategy; +import org.jclouds.vcloud.compute.strategy.VCloudExpressListNodesStrategy; +import org.jclouds.vcloud.compute.strategy.VCloudExpressRebootNodeStrategy; import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient; import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeService; import org.jclouds.vcloud.terremark.compute.domain.KeyPairCredentials; @@ -74,7 +74,7 @@ import com.google.inject.TypeLiteral; * * @author Adrian Cole */ -public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeServiceContextModule { +public class TerremarkVCloudComputeServiceContextModule extends VCloudExpressComputeServiceContextModule { @Provides @Singleton @@ -94,15 +94,15 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer // NOTE bind(AddNodeWithTagStrategy.class).to(TerremarkVCloudAddNodeWithTagStrategy.class); bind(new TypeLiteral() { - }).to(new TypeLiteral>() { + }).to(new TypeLiteral>() { }).in(Scopes.SINGLETON); // NOTE bind(RunNodesAndAddToSetStrategy.class).to(TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.class); - bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class); + bind(ListNodesStrategy.class).to(VCloudExpressListNodesStrategy.class); // NOTE bind(GetNodeMetadataStrategy.class).to(TerremarkVCloudGetNodeMetadataStrategy.class); - bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class); - bind(DestroyNodeStrategy.class).to(VCloudDestroyNodeStrategy.class); + bind(RebootNodeStrategy.class).to(VCloudExpressRebootNodeStrategy.class); + bind(DestroyNodeStrategy.class).to(VCloudExpressDestroyNodeStrategy.class); bindLoadBalancer(); // MORE specifics... bind(new TypeLiteral>() { @@ -110,7 +110,7 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer }); bind(TemplateOptions.class).to(TerremarkVCloudTemplateOptions.class); bind(ComputeService.class).to(TerremarkVCloudComputeService.class); - bind(VCloudComputeClient.class).to(TerremarkVCloudComputeClient.class); + bind(VCloudExpressComputeClient.class).to(TerremarkVCloudComputeClient.class); bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to( ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.class); bind(SecureRandom.class).toInstance(new SecureRandom()); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/NodeMetadataToOrgAndName.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/NodeMetadataToOrgAndName.java index ae248953e8..0e8be44799 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/NodeMetadataToOrgAndName.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/NodeMetadataToOrgAndName.java @@ -29,7 +29,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.terremark.compute.domain.OrgAndName; @@ -51,10 +51,10 @@ public class NodeMetadataToOrgAndName implements Function> vdcToOrg; - private final VCloudClient client; + private final VCloudExpressClient client; @Inject - NodeMetadataToOrgAndName(VCloudClient client, @VDC Supplier> vdcToOrg) { + NodeMetadataToOrgAndName(VCloudExpressClient client, @VDC Supplier> vdcToOrg) { this.vdcToOrg = vdcToOrg; this.client = client; } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkVCloudGetNodeMetadataStrategy.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkVCloudGetNodeMetadataStrategy.java index b916e6bdeb..bf7632bca0 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkVCloudGetNodeMetadataStrategy.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkVCloudGetNodeMetadataStrategy.java @@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.util.ComputeServiceUtils.installNewCredentials; import java.net.URI; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentMap; import javax.annotation.Resource; @@ -30,21 +32,29 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Credentials; import org.jclouds.logging.Logger; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.compute.VCloudExpressComputeClient; import org.jclouds.vcloud.compute.domain.VCloudLocation; -import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata; -import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy; +import org.jclouds.vcloud.compute.functions.FindLocationForResource; +import org.jclouds.vcloud.compute.functions.GetExtra; +import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy; +import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.terremark.compute.domain.KeyPairCredentials; import org.jclouds.vcloud.terremark.compute.domain.OrgAndName; +import com.google.common.base.Supplier; + /** * @author Adrian Cole */ @Singleton -public class TerremarkVCloudGetNodeMetadataStrategy extends VCloudGetNodeMetadataStrategy { +public class TerremarkVCloudGetNodeMetadataStrategy extends VCloudExpressGetNodeMetadataStrategy { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @@ -52,15 +62,17 @@ public class TerremarkVCloudGetNodeMetadataStrategy extends VCloudGetNodeMetadat private final ConcurrentMap credentialsMap; @Inject - protected TerremarkVCloudGetNodeMetadataStrategy(VCloudGetNodeMetadata getNodeMetadata, - ConcurrentMap credentialsMap) { - super(getNodeMetadata); + protected TerremarkVCloudGetNodeMetadataStrategy(VCloudExpressClient client, + VCloudExpressComputeClient computeClient, Map vAppStatusToNodeState, + GetExtra getExtra, FindLocationForResource findLocationForResourceInVDC, + Supplier> images, ConcurrentMap credentialsMap) { + super(client, computeClient, vAppStatusToNodeState, getExtra, findLocationForResourceInVDC, images); this.credentialsMap = credentialsMap; } @Override public NodeMetadata execute(String id) { - NodeMetadata node = getNodeMetadata.execute(checkNotNull(id, "node.id")); + NodeMetadata node = super.execute(checkNotNull(id, "node.id")); if (node == null) return null; if (node.getTag() != null) { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgs.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgs.java index 8bc6c7a3aa..5aa536fecc 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgs.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/suppliers/VAppTemplatesInOrgs.java @@ -33,8 +33,9 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; import org.jclouds.logging.Logger; import org.jclouds.vcloud.compute.functions.ImagesInOrganization; -import org.jclouds.vcloud.functions.OrganizatonsForLocations; +import org.jclouds.vcloud.domain.Organization; +import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.collect.Iterables; @@ -49,11 +50,12 @@ public class VAppTemplatesInOrgs implements Supplier> { public Logger logger = Logger.NULL; private final Supplier> locations; - private final OrganizatonsForLocations organizatonsForLocations; + private final Function, Iterable> organizatonsForLocations; private final ImagesInOrganization imagesInOrganization; @Inject - VAppTemplatesInOrgs(Supplier> locations, OrganizatonsForLocations organizatonsForLocations, + VAppTemplatesInOrgs(Supplier> locations, + Function, Iterable> organizatonsForLocations, ImagesInOrganization imagesInOrganization) { this.locations = locations; this.organizatonsForLocations = organizatonsForLocations; diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkECloudRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkECloudRestClientModule.java index fe64668cf8..fbb096657e 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkECloudRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkECloudRestClientModule.java @@ -23,8 +23,8 @@ import javax.inject.Singleton; import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.vcloud.VCloudAsyncClient; -import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.TerremarkECloudAsyncClient; @@ -48,13 +48,13 @@ public class TerremarkECloudRestClientModule extends @Provides @Singleton - protected VCloudAsyncClient provideVCloudAsyncClient(TerremarkECloudAsyncClient in) { + protected VCloudExpressAsyncClient provideVCloudAsyncClient(TerremarkECloudAsyncClient in) { return in; } @Provides @Singleton - protected VCloudClient provideVCloudClient(TerremarkECloudClient in) { + protected VCloudExpressClient provideVCloudClient(TerremarkECloudClient in) { return in; } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkRestClientModule.java index 2b9bdadd84..1016e7b63c 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkRestClientModule.java @@ -29,7 +29,7 @@ import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.util.Utils; -import org.jclouds.vcloud.config.BaseVCloudRestClientModule; +import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule; import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.handlers.ParseTerremarkVCloudErrorFromHttpResponse; @@ -37,7 +37,7 @@ import org.jclouds.vcloud.terremark.handlers.ParseTerremarkVCloudErrorFromHttpRe import com.google.inject.Provides; public abstract class TerremarkRestClientModule - extends BaseVCloudRestClientModule { + extends BaseVCloudExpressRestClientModule { public TerremarkRestClientModule(Class syncClientType, Class asyncClientType) { super(syncClientType, asyncClientType); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java index a115e2815d..e15a3f971a 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudExpressRestClientModule.java @@ -32,8 +32,8 @@ import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.util.Utils; -import org.jclouds.vcloud.VCloudAsyncClient; -import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.VCloudExpressAsyncClient; +import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession; import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient; @@ -63,13 +63,13 @@ public class TerremarkVCloudExpressRestClientModule extends @Provides @Singleton - protected VCloudAsyncClient provideVCloudAsyncClient(TerremarkVCloudExpressAsyncClient in) { + protected VCloudExpressAsyncClient provideVCloudAsyncClient(TerremarkVCloudExpressAsyncClient in) { return in; } @Provides @Singleton - protected VCloudClient provideVCloudClient(TerremarkVCloudExpressClient in) { + protected VCloudExpressClient provideVCloudClient(TerremarkVCloudExpressClient in) { return in; } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandler.java index fe9c131c91..cd9871e836 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandler.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.terremark.xml; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.terremark.domain.TerremarkVDC; @@ -56,7 +56,7 @@ public class TerremarkVDCHandler extends VDCHandler { publicIps = Utils.newNamedResource(attributes); } else { String type = attributes.getValue(attributes.getIndex("type")); - if (type.equals(VCloudMediaType.CATALOG_XML)) { + if (type.equals(VCloudExpressMediaType.CATALOG_XML)) { catalog = Utils.newNamedResource(attributes); } } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java index 55d49e2e46..14f1ae0d90 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkClientLiveTest.java @@ -47,8 +47,8 @@ import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshClient.Factory; import org.jclouds.ssh.jsch.config.JschSshClientModule; -import org.jclouds.vcloud.VCloudClientLiveTest; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressClientLiveTest; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.ResourceAllocation; @@ -59,7 +59,7 @@ import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.options.CloneVAppOptions; -import org.jclouds.vcloud.predicates.TaskSuccess; +import org.jclouds.vcloud.predicates.VCloudExpressTaskSuccess; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; @@ -78,7 +78,7 @@ import com.google.common.collect.Lists; import com.google.inject.Injector; import com.google.inject.Module; -public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { +public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTest { // Terremark service call 695,490 @Override @@ -124,7 +124,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { public void testGetConfigCustomizationOptions() throws Exception { Catalog response = connection.findCatalogInOrgNamed(null, null); for (NamedResource resource : response.values()) { - if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { + if (resource.getType().equals(VCloudExpressMediaType.CATALOGITEM_XML)) { TerremarkCatalogItem item = tmClient.findCatalogItemInOrgCatalogNamed(null, null, resource.getName()); assert tmClient.getCustomizationOptions(item.getCustomizationOptions().getId()) != null; } @@ -444,7 +444,7 @@ public abstract class TerremarkClientLiveTest extends VCloudClientLiveTest { // then // default internet // service timeout - successTester = new RetryablePredicate(injector.getInstance(TaskSuccess.class), 650, 10, TimeUnit.SECONDS); + successTester = new RetryablePredicate(injector.getInstance(VCloudExpressTaskSuccess.class), 650, 10, TimeUnit.SECONDS); } protected abstract void setupCredentials(); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java index 4d5bc4212f..2bb7eb1543 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java @@ -44,9 +44,9 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.VCloudAsyncClientTest.VCloudRestClientModuleExtension.TestOrganizationCatalogItemSupplier; -import org.jclouds.vcloud.VCloudAsyncClientTest.VCloudRestClientModuleExtension.TestOrganizationCatalogSupplier; +import org.jclouds.vcloud.VCloudExpressClient; +import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrganizationCatalogItemSupplier; +import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExtension.TestOrganizationCatalogSupplier; import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.endpoints.Org; @@ -467,7 +467,7 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest of("adriantest", - new NamedResourceImpl("adriantest", VCloudMediaType.VAPP_XML, URI + new NamedResourceImpl("adriantest", VCloudExpressMediaType.VAPP_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15124")), "centos-53", - new NamedResourceImpl("centos-53", VCloudMediaType.VAPP_XML, URI + new NamedResourceImpl("centos-53", VCloudExpressMediaType.VAPP_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15120")))); assertEquals(result.getAvailableNetworks(), ImmutableMap.of("10.114.34.128/26", new NamedResourceImpl( diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/VAppHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/VAppHandlerTest.java index b5bc94113e..93b814603c 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/VAppHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/VAppHandlerTest.java @@ -32,7 +32,7 @@ import java.util.List; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.config.SaxParserModule; -import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.VCloudExpressMediaType; import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.VApp; @@ -91,7 +91,7 @@ public class VAppHandlerTest extends BaseHandlerTest { assertEquals(result.getOperatingSystemDescription(), "Red Hat Enterprise Linux 5 (64-bit)"); assertEquals(result.getId(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/16238")); - assertEquals(result.getVDC(), new NamedResourceImpl(null, VCloudMediaType.VDC_XML, URI + assertEquals(result.getVDC(), new NamedResourceImpl(null, VCloudExpressMediaType.VDC_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); assertEquals(result.getSystem(), new VirtualSystem(0, "Virtual Hardware Family", "centos-53", "vmx-07")); @@ -129,7 +129,7 @@ public class VAppHandlerTest extends BaseHandlerTest { assertEquals(vApp.getOperatingSystemDescription(), "Ubuntu Linux (32-bit)"); assertEquals(vApp.getId(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15639")); - assertEquals(vApp.getVDC(), new NamedResourceImpl(null, VCloudMediaType.VDC_XML, URI + assertEquals(vApp.getVDC(), new NamedResourceImpl(null, VCloudExpressMediaType.VDC_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); assertEquals(vApp.getSystem(), new VirtualSystem(0, "Virtual Hardware Family", "eduardo", "vmx-07"));