Issue 440: reorganized terremark and added trmk-common, trmk-ecloud, trmk-vcloudexpress

This commit is contained in:
Adrian Cole 2011-01-09 17:52:48 -08:00
parent 3d9a4070fb
commit e71d412a0a
192 changed files with 928 additions and 181 deletions

View File

@ -69,6 +69,26 @@
<artifactId>vcloudexpress</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>trmk-vcloudexpress</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>trmk-ecloud</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>trmk-vcloudexpress</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>trmk-ecloud</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>bluelock-vcdirector</artifactId>

View File

@ -35,5 +35,7 @@
<modules>
<module>aws</module>
<module>openstack</module>
<module>vcloud</module>
<module>trmk</module>
</modules>
</project>

View File

@ -26,53 +26,69 @@
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<artifactId>jclouds-vcloud-project</artifactId>
<packaging>pom</packaging>
<name>jclouds vcloud project</name>
<modules>
<module>core</module>
<module>terremark</module>
<module>bluelock</module>
</modules>
<groupId>org.jclouds.common</groupId>
<artifactId>trmk-common</artifactId>
<name>common Terremark components</name>
<description>common Terremark components</description>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds.api</groupId>
<artifactId>vcloudexpress</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>vcloud-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds.common</groupId>
<artifactId>vcloud-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>vcloudexpress</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -29,6 +29,7 @@ import org.jclouds.vcloud.VCloudExpressMediaType;
* @see MediaType
*/
public interface TerremarkVCloudMediaType extends VCloudExpressMediaType {
/**
* "application/vnd.tmrk.vCloud.publicIp+xml"

View File

@ -80,7 +80,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");

View File

@ -27,6 +27,7 @@ import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import javax.inject.Inject;
@ -37,7 +38,6 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpResponseException;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task;
@ -46,14 +46,13 @@ import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.TerremarkECloudClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.suppliers.InternetServiceAndPublicIpAddressSupplier;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
@ -69,17 +68,20 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
protected final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
protected final Provider<String> passwordGenerator;
protected final Map<String, Credentials> credentialStore;
protected final InternetServiceAndPublicIpAddressSupplier internetServiceAndPublicIpAddressSupplier;
@Inject
protected TerremarkVCloudComputeClient(TerremarkVCloudClient client,
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
@Named("PASSWORD") Provider<String> passwordGenerator, Predicate<URI> successTester,
Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore) {
Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore,
InternetServiceAndPublicIpAddressSupplier internetServiceAndPublicIpAddressSupplier) {
super(client, successTester, vAppStatusToNodeState);
this.client = client;
this.credentialsProvider = credentialsProvider;
this.passwordGenerator = passwordGenerator;
this.credentialStore = credentialStore;
this.internetServiceAndPublicIpAddressSupplier = internetServiceAndPublicIpAddressSupplier;
}
@Override
@ -133,42 +135,12 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
break;
}
if (ip == null) {
if (client instanceof TerremarkVCloudExpressClient) {
is = TerremarkVCloudExpressClient.class.cast(client).addInternetServiceToVDC(
vApp.getVDC().getHref(),
vApp.getName() + "-" + port,
protocol,
port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(),
vApp.getName())));
ip = is.getPublicIpAddress();
} else {
logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getName(), protocol, port);
// http://support.theenterprisecloud.com/kb/default.asp?id=706&Lang=1&SID=
// response with a 500 error code means we should look for an existing public ip to
// use
try {
ip = TerremarkECloudClient.class.cast(client).activatePublicIpInVDC(vApp.getVDC().getHref());
} catch (HttpResponseException e) {
if (e.getResponse().getStatusCode() == 500) {
logger.warn(">> no more ip addresses available, looking for one to re-use");
for (PublicIpAddress existingIp : client.getPublicIpsAssociatedWithVDC(vApp.getVDC().getHref())) {
Set<InternetService> services = client.getInternetServicesOnPublicIp(existingIp.getId());
if (services.size() == 0) {
ip = existingIp;
break;
}
}
if (ip == null)
throw e;
} else {
throw e;
}
}
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,
withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(),
vApp.getName())));
}
Entry<InternetService, PublicIpAddress> entry = internetServiceAndPublicIpAddressSupplier
.getNewInternetServiceAndIp(vApp, port, protocol);
is = entry.getKey();
ip = entry.getValue();
} else {
logger.debug(">> adding InternetService %s:%s:%d", ip.getAddress(), protocol, port);
is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,

View File

@ -0,0 +1,35 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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.terremark.suppliers;
import java.util.Map.Entry;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
/**
* @author Adrian Cole
*/
public interface InternetServiceAndPublicIpAddressSupplier {
Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIp(VCloudExpressVApp vApp, int port,
Protocol protocol);
}

View File

@ -27,8 +27,6 @@ import java.util.Map;
import javax.inject.Inject;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.terremark.TerremarkECloudMediaType;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType;
import org.jclouds.vcloud.terremark.domain.TerremarkOrg;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkOrgImpl;
import org.jclouds.vcloud.xml.OrgHandler;
@ -59,12 +57,10 @@ public class TerremarkOrgHandler extends OrgHandler {
if (qName.equals("Link")) {
if (attributes.containsKey("type")) {
String type = attributes.get("type");
if (type.equals(TerremarkVCloudExpressMediaType.KEYSLIST_XML)
|| type.equals(TerremarkECloudMediaType.KEYSLIST_XML)) {
if (type != null && type.endsWith("keysList+xml")) {
keysList = newReferenceType(attributes);
}
}
}
}
}

View File

@ -35,6 +35,7 @@ import java.net.URI;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -66,7 +67,6 @@ import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
@ -115,7 +115,8 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
@Test
public void testGetPublicIpsAssociatedWithVDC() throws Exception {
for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getHref())) {
for (PublicIpAddress ip : tmClient
.getPublicIpsAssociatedWithVDC(tmClient.findVDCInOrgNamed(null, null).getHref())) {
assertNotNull(tmClient.getInternetServicesOnPublicIp(ip.getId()));
assertNotNull(tmClient.getPublicIp(ip.getId()));
}
@ -175,7 +176,8 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
VCloudExpressVAppTemplate vAppTemplate = tmClient.getVAppTemplate(item.getEntity().getHref());
// instantiate, noting vApp returned has minimal details
vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getHref(), vAppTemplate.getHref(), serverName, instantiateOptions);
vApp = tmClient.instantiateVAppTemplateInVDC(vdc.getHref(), vAppTemplate.getHref(), serverName,
instantiateOptions);
assertEquals(vApp.getStatus(), Status.RESOLVED);
@ -224,19 +226,16 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
abstract TerremarkInstantiateVAppTemplateOptions createInstantiateOptions();
protected abstract Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIpForSSH(URI vdc);
@Test
public void testAddInternetService() throws InterruptedException, ExecutionException, TimeoutException, IOException {
PublicIpAddress ip;
if (tmClient instanceof TerremarkVCloudExpressClient) {
is = TerremarkVCloudExpressClient.class.cast(tmClient).addInternetServiceToVDC(
tmClient.findVDCInOrgNamed(null, null).getHref(), "SSH", Protocol.TCP, 22);
ip = is.getPublicIpAddress();
} else {
ip = TerremarkECloudClient.class.cast(tmClient).activatePublicIpInVDC(
tmClient.findVDCInOrgNamed(null, null).getHref());
is = tmClient.addInternetServiceToExistingIp(ip.getId(), "SSH", Protocol.TCP, 22);
}
publicIp = ip.getAddress();
Entry<InternetService, PublicIpAddress> entry = getNewInternetServiceAndIpForSSH(tmClient.findVDCInOrgNamed(null,
null).getHref());
is = entry.getKey();
publicIp = entry.getValue().getAddress();
}
@Test(enabled = true, dependsOnMethods = "testInstantiateAndPowerOn")
@ -461,7 +460,8 @@ public abstract class TerremarkClientLiveTest extends VCloudExpressClientLiveTes
Properties overrides = setupProperties();
Injector injector = new RestContextFactory().createContextBuilder(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()),overrides).buildInjector();
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides)
.buildInjector();
connection = tmClient = injector.getInstance(TerremarkVCloudClient.class);

View File

@ -24,6 +24,10 @@ 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.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME;
import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION;
import java.io.IOException;
import java.net.URI;
@ -31,7 +35,7 @@ import java.util.Map;
import java.util.Properties;
import org.jclouds.http.HttpRequest;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressPropertiesBuilder;
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -51,8 +55,12 @@ public class BindNodeConfigurationToXmlPayloadTest {
@Override
protected void configure() {
Properties props = new Properties();
Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudExpressPropertiesBuilder(props).build(),
Properties properties = new Properties();
properties.setProperty(PROPERTY_API_VERSION, "0.8a-ext1.6");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "vCloudExpressExtensions");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "1.6");
properties.setProperty(PROPERTY_ENDPOINT, "https://services.vcloudexpress.terremark.com/api");
Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(properties).build(),
"properties"));
}
});

View File

@ -36,7 +36,7 @@ import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.internal.VCloudExpressVAppImpl;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressPropertiesBuilder;
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.testng.annotations.Test;
@ -62,7 +62,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
protected void configure() {
Properties props = new Properties();
Names.bindProperties(binder(),
checkNotNull(new TerremarkVCloudExpressPropertiesBuilder(props).build(), "properties"));
checkNotNull(new TerremarkVCloudPropertiesBuilder(props).build(), "properties"));
}
});

View File

@ -38,10 +38,11 @@ import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.compute.strategy.ParseVAppTemplateDescriptionToGetDefaultLoginCredentials;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.suppliers.InternetServiceAndPublicIpAddressSupplier;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
@ -65,14 +66,14 @@ public class TerremarkVCloudComputeClientTest {
URI vdcURI = URI.create("vdc");
expect(template.getDescription()).andReturn(description).atLeastOnce();
TerremarkVCloudExpressClient client = createMock(TerremarkVCloudExpressClient.class);
TerremarkVCloudClient client = createMock(TerremarkVCloudClient.class);
VCloudExpressVApp vApp = createMock(VCloudExpressVApp.class);
InternetServiceAndPublicIpAddressSupplier supplier = createMock(InternetServiceAndPublicIpAddressSupplier.class);
expect(client.getVAppTemplate(templateURI)).andReturn(template);
expect(
client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name",
new TerremarkInstantiateVAppTemplateOptions().productProperty("password", "password"))).andReturn(
vApp);
client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name",
new TerremarkInstantiateVAppTemplateOptions().productProperty("password", "password")))
.andReturn(vApp);
Task task = createMock(Task.class);
URI vappLocation = URI.create("vapp");
URI taskLocation = URI.create("task");
@ -89,14 +90,14 @@ public class TerremarkVCloudComputeClientTest {
Map<Status, NodeState> vAppStatusToNodeState = createMock(Map.class);
TerremarkVCloudComputeClient computeClient = new TerremarkVCloudComputeClient(client,
new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(), new Provider<String>() {
new ParseVAppTemplateDescriptionToGetDefaultLoginCredentials(), new Provider<String>() {
@Override
public String get() {
return "password";
}
@Override
public String get() {
return "password";
}
}, successTester, vAppStatusToNodeState, credentialStore);
}, successTester, vAppStatusToNodeState, credentialStore, supplier);
replay(vdc);
replay(template);
@ -108,7 +109,7 @@ public class TerremarkVCloudComputeClientTest {
replay(vAppStatusToNodeState);
VCloudExpressVApp response = computeClient.start(vdcURI, templateURI, "name",
new TerremarkInstantiateVAppTemplateOptions());
new TerremarkInstantiateVAppTemplateOptions());
assertEquals(response.getHref().toASCIIString(), "vapp");
assertEquals(credentialStore.get("node#vapp"), new Credentials("Administrator", "password"));

View File

@ -27,7 +27,7 @@ import static org.easymock.classextension.EasyMock.verify;
import java.net.URI;
import java.util.concurrent.ConcurrentMap;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.compute.domain.KeyPairCredentials;
import org.jclouds.vcloud.terremark.compute.domain.OrgAndName;
import org.jclouds.vcloud.terremark.domain.KeyPair;
@ -126,7 +126,7 @@ public class DeleteKeyPairTest {
@SuppressWarnings("unchecked")
private DeleteKeyPair setupStrategy() {
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap = createMock(ConcurrentMap.class);
TerremarkVCloudExpressClient terremarkClient = createMock(TerremarkVCloudExpressClient.class);
TerremarkVCloudClient terremarkClient = createMock(TerremarkVCloudClient.class);
return new DeleteKeyPair(terremarkClient, credentialsMap);
}

Some files were not shown because too many files have changed in this diff Show More