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 adab61c6e5..77dec9326b 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 @@ -24,6 +24,7 @@ package org.jclouds.vcloud.terremark; import static javax.ws.rs.core.MediaType.APPLICATION_XML; +import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; @@ -50,12 +51,16 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.functions.InetAddressToHostAddress; import org.jclouds.vcloud.VCloudAsyncClient; +import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.functions.CatalogIdToUri; +import org.jclouds.vcloud.functions.VAppIdToUri; +import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.binders.BindInternetServiceConfigurationToXmlPayload; import org.jclouds.vcloud.terremark.binders.BindNodeConfigurationToXmlPayload; +import org.jclouds.vcloud.terremark.binders.TerremarkBindCloneVAppParamsToXmlPayload; import org.jclouds.vcloud.terremark.binders.TerremarkBindInstantiateVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.terremark.domain.ComputeOptions; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; @@ -80,6 +85,7 @@ import org.jclouds.vcloud.terremark.xml.NodesHandler; import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler; +import org.jclouds.vcloud.xml.TaskHandler; /** * Provides access to VCloud resources via their REST API. @@ -363,5 +369,16 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @XMLResponseParser(IpAddressesHandler.class) Future> getIpAddressesForNetwork( @PathParam("networkId") String networkId); - + + @POST + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/vdc/{vDCId}/action/cloneVApp") + @Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml") + @Consumes(TASK_XML) + @XMLResponseParser(TaskHandler.class) + @MapBinder(TerremarkBindCloneVAppParamsToXmlPayload.class) + @Override + Future cloneVAppInVDC(@PathParam("vDCId") String vDCId, + @MapPayloadParam("vApp") @ParamParser(VAppIdToUri.class) String vAppIdToClone, + @MapPayloadParam("newName") String newName, CloneVAppOptions... options); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindCloneVAppParamsToXmlPayload.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindCloneVAppParamsToXmlPayload.java new file mode 100644 index 0000000000..f797e9cd05 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindCloneVAppParamsToXmlPayload.java @@ -0,0 +1,65 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.terremark.binders; + +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; + +import javax.inject.Named; +import javax.inject.Singleton; +import javax.xml.parsers.FactoryConfigurationError; +import javax.xml.parsers.ParserConfigurationException; + +import org.jclouds.rest.binders.BindToStringPayload; +import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload; + +import com.google.inject.Inject; +import com.jamesmurty.utils.XMLBuilder; + +/** + * + * @author Adrian Cole + * + */ +@Singleton +public class TerremarkBindCloneVAppParamsToXmlPayload extends BindCloneVAppParamsToXmlPayload { + + @Inject + public TerremarkBindCloneVAppParamsToXmlPayload(BindToStringPayload stringBinder, + @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, + @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) { + super(stringBinder, ns,schema); + } + + @Override + protected XMLBuilder buildRoot(String name, boolean deploy, boolean powerOn) + throws ParserConfigurationException, FactoryConfigurationError { + XMLBuilder rootBuilder = XMLBuilder.create("CloneVAppParamsType").a("name", name).a("deploy", + deploy+"").a("powerOn", powerOn+"").a("xmlns", ns).a("xmlns:xsi", + "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", + ns + " " + schema); + return rootBuilder; + } + +} 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 546fadae6c..ade50d6d9e 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 @@ -212,7 +212,7 @@ public class TerremarkVCloudComputeClient { if (services.size() == 0) { logger.debug(">> deleting PublicIpAddress(%s) %s", address.getId(), address .getAddress().getHostAddress()); - tmClient.deleteInternetService(address.getId()); + tmClient.deletePublicIp(address.getId()); logger.debug("<< deleted PublicIpAddress(%s)", address.getId()); continue IPADDRESS; } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java index fb7ecab5f8..0b93a6cb66 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java @@ -60,6 +60,7 @@ import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.terremark.domain.ComputeOptions; import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.InternetServiceConfiguration; import org.jclouds.vcloud.terremark.domain.IpAddress; import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.NodeConfiguration; @@ -237,10 +238,20 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { TimeoutException, IOException { is = tmClient.addInternetServiceToVDC(tmClient.getDefaultVDC().getId(), "SSH", Protocol.TCP, 22); + publicIp = is.getPublicIpAddress().getAddress(); } - - // throws 500 errors - @Test(enabled = false, dependsOnMethods = { "testInstantiateAndPowerOn" }) + + // 400 errors + @Test(dependsOnMethods = { "testAddInternetService" }, expectedExceptions=HttpResponseException.class) + public void testConfigureInternetService() throws InterruptedException, ExecutionException, + TimeoutException, IOException { + is = tmClient.configureInternetService(is.getId(), new InternetServiceConfiguration() + .changeDescriptionTo("holy cow")); + assertEquals(is.getDescription(), "holy cow"); + } + + // 500 errors + @Test(dependsOnMethods = { "testInstantiateAndPowerOn" }, expectedExceptions=HttpResponseException.class) public void testCloneVApp() { // lookup the id of the datacenter you are deploying into String vDCId = tmClient.getDefaultVDC().getId(); @@ -273,12 +284,11 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { IOException { node = tmClient.addNode(is.getId(), Iterables.getLast(vApp.getNetworkToAddresses().values()), vApp.getName() + "-SSH", 22); - - publicIp = is.getPublicIpAddress().getAddress(); doCheckPass(publicIp); } - - @Test(dependsOnMethods = { "testPublicIp" }) + + // 400 errors + @Test(dependsOnMethods = { "testPublicIp" }, expectedExceptions=HttpResponseException.class) public void testConfigureNode() throws InterruptedException, ExecutionException, TimeoutException, IOException { node = tmClient.configureNode(node.getId(), new NodeConfiguration() diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java index 71e938efe0..4c18a076f3 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java @@ -119,11 +119,7 @@ public class TerremarkVCloudComputeClientLiveTest { @Test(dependsOnMethods = "testGetAnyPrivateAddress") public void testSshLoadBalanceIp() { - // bug creating more than one internet service returns 503 or 500 - // InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22, - // 80, - // 8080); - InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22); + InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22, 80, 8080); assert addressTester.apply(publicIp); // client.exec(publicIp, "uname -a"); }