This commit is contained in:
Adrian Cole 2012-06-16 19:06:26 -04:00
commit 8900413995
297 changed files with 10156 additions and 2549 deletions

View File

@ -37,12 +37,10 @@
<properties> <properties>
<test.cloudservers.endpoint>https://auth.api.rackspacecloud.com</test.cloudservers.endpoint> <test.cloudservers.endpoint>https://auth.api.rackspacecloud.com</test.cloudservers.endpoint>
<test.cloudservers.api-version>1.0</test.cloudservers.api-version> <test.cloudservers.api-version>1.0</test.cloudservers.api-version>
<test.cloudservers.build-version /> <test.cloudservers.build-version></test.cloudservers.build-version>
<test.cloudservers.identity>${test.rackspace.identity}</test.cloudservers.identity> <test.cloudservers.identity>${test.rackspace.identity}</test.cloudservers.identity>
<test.cloudservers.credential>${test.rackspace.credential}</test.cloudservers.credential> <test.cloudservers.credential>${test.rackspace.credential}</test.cloudservers.credential>
<test.cloudservers.image-id /> <test.cloudservers.template></test.cloudservers.template>
<test.cloudservers.image.login-user />
<test.cloudservers.image.authenticate-sudo />
<jclouds.osgi.export>org.jclouds.cloudservers*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.cloudservers*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}", org.jclouds.compute.internal;version="${project.version}",
@ -120,10 +118,8 @@
<test.cloudstack.build-version>${test.cloudstack.build-version}</test.cloudstack.build-version> <test.cloudstack.build-version>${test.cloudstack.build-version}</test.cloudstack.build-version>
<test.cloudstack.identity>${test.cloudstack.identity}</test.cloudstack.identity> <test.cloudstack.identity>${test.cloudstack.identity}</test.cloudstack.identity>
<test.cloudstack.credential>${test.cloudstack.credential}</test.cloudstack.credential> <test.cloudstack.credential>${test.cloudstack.credential}</test.cloudstack.credential>
<test.cloudstack.image-id>${test.cloudstack.image-id}</test.cloudstack.image-id> <test.cloudstack.template>${test.cloudstack.template}</test.cloudstack.template>
<test.cloudstack.image.login-user>${test.cloudstack.image.login-user}</test.cloudstack.image.login-user> </systemPropertyVariables>
<test.cloudstack.image.authenticate-sudo>${test.cloudstack.image.authenticate-sudo}</test.cloudstack.image.authenticate-sudo>
</systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>

View File

@ -36,13 +36,10 @@
<properties> <properties>
<test.cloudsigma.endpoint>https://api.cloudsigma.com</test.cloudsigma.endpoint> <test.cloudsigma.endpoint>https://api.cloudsigma.com</test.cloudsigma.endpoint>
<test.cloudsigma.api-version>1.0</test.cloudsigma.api-version> <test.cloudsigma.api-version>1.0</test.cloudsigma.api-version>
<test.cloudsigma.build-version /> <test.cloudsigma.build-version></test.cloudsigma.build-version>
<test.cloudsigma.identity>FIXME</test.cloudsigma.identity> <test.cloudsigma.identity>FIXME</test.cloudsigma.identity>
<test.cloudsigma.credential>FIXME</test.cloudsigma.credential> <test.cloudsigma.credential>FIXME</test.cloudsigma.credential>
<test.cloudsigma.image-id>f3c7c665-cd54-4a78-8fd2-7ec2f028cf29</test.cloudsigma.image-id> <test.cloudsigma.template>imageId=f3c7c665-cd54-4a78-8fd2-7ec2f028cf29</test.cloudsigma.template>
<test.cloudsigma.image.login-user />
<test.cloudsigma.image.authenticate-sudo />
<jclouds.osgi.export>org.jclouds.cloudsigma*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.cloudsigma*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}", org.jclouds.compute.internal;version="${project.version}",
@ -107,9 +104,7 @@
<test.cloudsigma.build-version>${test.cloudsigma.build-version}</test.cloudsigma.build-version> <test.cloudsigma.build-version>${test.cloudsigma.build-version}</test.cloudsigma.build-version>
<test.cloudsigma.identity>${test.cloudsigma.identity}</test.cloudsigma.identity> <test.cloudsigma.identity>${test.cloudsigma.identity}</test.cloudsigma.identity>
<test.cloudsigma.credential>${test.cloudsigma.credential}</test.cloudsigma.credential> <test.cloudsigma.credential>${test.cloudsigma.credential}</test.cloudsigma.credential>
<test.cloudsigma.image-id>${test.cloudsigma.image-id}</test.cloudsigma.image-id> <test.cloudsigma.template>${test.cloudsigma.template}</test.cloudsigma.template>
<test.cloudsigma.image.login-user>${test.cloudsigma.image.login-user}</test.cloudsigma.image.login-user>
<test.cloudsigma.image.authenticate-sudo>${test.cloudsigma.image.authenticate-sudo}</test.cloudsigma.image.authenticate-sudo>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -57,7 +57,6 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.HostAndPort; import com.google.common.net.HostAndPort;
@ -84,6 +83,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest
protected Predicate<HostAndPort> socketTester; protected Predicate<HostAndPort> socketTester;
protected Predicate<DriveInfo> driveNotClaimed; protected Predicate<DriveInfo> driveNotClaimed;
protected String imageId;
@BeforeGroups(groups = { "integration", "live" }) @BeforeGroups(groups = { "integration", "live" })
@Override @Override
@ -97,7 +97,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest
socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), maxDriveImageTime, 1, socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), maxDriveImageTime, 1,
TimeUnit.SECONDS); TimeUnit.SECONDS);
if (Strings.emptyToNull(imageId) == null) { if (template == null || template.getImageId() == null) {
imageId = view.getComputeService().templateBuilder().build().getImage().getId(); imageId = view.getComputeService().templateBuilder().build().getImage().getId();
} }
} }

View File

@ -49,18 +49,15 @@
<properties> <properties>
<test.cloudstack.endpoint>http://localhost:8080/client/api</test.cloudstack.endpoint> <test.cloudstack.endpoint>http://localhost:8080/client/api</test.cloudstack.endpoint>
<test.cloudstack.api-version>2.2.12</test.cloudstack.api-version> <test.cloudstack.api-version>3.0.3</test.cloudstack.api-version>
<test.cloudstack.build-version /> <test.cloudstack.build-version></test.cloudstack.build-version>
<test.cloudstack.identity>FIXME_apiKey</test.cloudstack.identity> <test.cloudstack.identity>FIXME_apiKey</test.cloudstack.identity>
<test.cloudstack.credential>FIXME_secretKey</test.cloudstack.credential> <test.cloudstack.credential>FIXME_secretKey</test.cloudstack.credential>
<test.cloudstack.domainAdminIdentity /> <test.cloudstack.domainAdminIdentity></test.cloudstack.domainAdminIdentity>
<test.cloudstack.domainAdminCredential /> <test.cloudstack.domainAdminCredential></test.cloudstack.domainAdminCredential>
<test.cloudstack.globalAdminIdentity /> <test.cloudstack.globalAdminIdentity></test.cloudstack.globalAdminIdentity>
<test.cloudstack.globalAdminCredential /> <test.cloudstack.globalAdminCredential></test.cloudstack.globalAdminCredential>
<test.cloudstack.image-id /> <test.cloudstack.template></test.cloudstack.template>
<test.cloudstack.image.login-user />
<test.cloudstack.image.authenticate-sudo />
<jclouds.osgi.export>org.jclouds.cloudstack*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.cloudstack*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}", org.jclouds.compute.internal;version="${project.version}",
@ -137,9 +134,7 @@
<test.cloudstack.build-version>${test.cloudstack.build-version}</test.cloudstack.build-version> <test.cloudstack.build-version>${test.cloudstack.build-version}</test.cloudstack.build-version>
<test.cloudstack.identity>${test.cloudstack.identity}</test.cloudstack.identity> <test.cloudstack.identity>${test.cloudstack.identity}</test.cloudstack.identity>
<test.cloudstack.credential>${test.cloudstack.credential}</test.cloudstack.credential> <test.cloudstack.credential>${test.cloudstack.credential}</test.cloudstack.credential>
<test.cloudstack.image-id>${test.cloudstack.image-id}</test.cloudstack.image-id> <test.cloudstack.template>${test.cloudstack.template}</test.cloudstack.template>
<test.cloudstack.image.login-user>${test.cloudstack.image.login-user}</test.cloudstack.image.login-user>
<test.cloudstack.image.authenticate-sudo>${test.cloudstack.image.authenticate-sudo}</test.cloudstack.image.authenticate-sudo>
<test.cloudstack.domainAdminIdentity>${test.cloudstack.domainAdminIdentity}</test.cloudstack.domainAdminIdentity> <test.cloudstack.domainAdminIdentity>${test.cloudstack.domainAdminIdentity}</test.cloudstack.domainAdminIdentity>
<test.cloudstack.domainAdminCredential>${test.cloudstack.domainAdminCredential}</test.cloudstack.domainAdminCredential> <test.cloudstack.domainAdminCredential>${test.cloudstack.domainAdminCredential}</test.cloudstack.domainAdminCredential>
<test.cloudstack.globalAdminIdentity>${test.cloudstack.globalAdminIdentity}</test.cloudstack.globalAdminIdentity> <test.cloudstack.globalAdminIdentity>${test.cloudstack.globalAdminIdentity}</test.cloudstack.globalAdminIdentity>

View File

@ -75,7 +75,7 @@ public class FirewallClientLiveTest extends BaseCloudStackClientLiveTest {
} }
})); }));
String defaultTemplate = (imageId != null && !"".equals(imageId)) ? imageId : null; String defaultTemplate = template != null ? template.getImageId() : null;
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network,
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()),

View File

@ -92,7 +92,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
public void testCreateVm() { public void testCreateVm() {
if (networksDisabled) if (networksDisabled)
return; return;
String defaultTemplate = (imageId != null && !"".equals(imageId)) ? imageId : null; String defaultTemplate = template != null ? template.getImageId() : null;
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network,
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()),
client, jobComplete, virtualMachineRunning); client, jobComplete, virtualMachineRunning);

View File

@ -171,7 +171,7 @@ public class SecurityGroupClientLiveTest extends BaseCloudStackClientLiveTest {
public void testCreateVMInSecurityGroup() throws Exception { public void testCreateVMInSecurityGroup() throws Exception {
if (!securityGroupsSupported) if (!securityGroupsSupported)
return; return;
String defaultTemplate = (imageId != null && !"".equals(imageId)) ? imageId : null; String defaultTemplate = template != null ? template.getImageId() : null;
vm = VirtualMachineClientLiveTest.createVirtualMachineWithSecurityGroupInZone(zone.getId(), vm = VirtualMachineClientLiveTest.createVirtualMachineWithSecurityGroupInZone(zone.getId(),
defaultTemplateOrPreferredInZone(defaultTemplate, client, zone.getId()), group.getId(), client, defaultTemplateOrPreferredInZone(defaultTemplate, client, zone.getId()), group.getId(), client,
jobComplete, virtualMachineRunning); jobComplete, virtualMachineRunning);
@ -200,7 +200,7 @@ public class SecurityGroupClientLiveTest extends BaseCloudStackClientLiveTest {
public void testCreateVMWithoutSecurityGroupAssignsDefault() throws Exception { public void testCreateVMWithoutSecurityGroupAssignsDefault() throws Exception {
if (!securityGroupsSupported) if (!securityGroupsSupported)
return; return;
String defaultTemplate = (imageId != null && !"".equals(imageId)) ? imageId : null; String defaultTemplate = template != null ? template.getImageId() : null;
VirtualMachine newVm = VirtualMachineClientLiveTest.createVirtualMachineWithOptionsInZone(DeployVirtualMachineOptions.NONE, VirtualMachine newVm = VirtualMachineClientLiveTest.createVirtualMachineWithOptionsInZone(DeployVirtualMachineOptions.NONE,
zone.getId(), defaultTemplateOrPreferredInZone(defaultTemplate, client, zone.getId()), client, zone.getId(), defaultTemplateOrPreferredInZone(defaultTemplate, client, zone.getId()), client,
jobComplete, virtualMachineRunning); jobComplete, virtualMachineRunning);

View File

@ -115,8 +115,8 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
assertNotNull(network); assertNotNull(network);
// Create a VM and stop it // Create a VM and stop it
String templateId = (imageId != null && !"".equals(imageId)) ? imageId : null; String defaultTemplate = template != null ? template.getImageId() : null;
vmForCreation = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, templateId, client, jobComplete, virtualMachineRunning); vmForCreation = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, defaultTemplate, client, jobComplete, virtualMachineRunning);
assertTrue(jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())), vmForCreation.toString()); assertTrue(jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())), vmForCreation.toString());
// Work out the VM's volume // Work out the VM's volume

View File

@ -181,8 +181,8 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
@Test @Test
public void testCreateVirtualMachine() throws Exception { public void testCreateVirtualMachine() throws Exception {
String templateId = (imageId != null && !"".equals(imageId)) ? imageId : null; String defaultTemplate = template != null ? template.getImageId() : null;
vm = createVirtualMachine(client, templateId, jobComplete, virtualMachineRunning); vm = createVirtualMachine(client, defaultTemplate, jobComplete, virtualMachineRunning);
if (vm.getPassword() != null) { if (vm.getPassword() != null) {
conditionallyCheckSSH(); conditionallyCheckSSH();
} }
@ -195,12 +195,12 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
public void testCreateVirtualMachineWithSpecificIp() throws Exception { public void testCreateVirtualMachineWithSpecificIp() throws Exception {
skipIfNotGlobalAdmin(); skipIfNotGlobalAdmin();
String templateId = (imageId != null && !"".equals(imageId)) ? imageId : null; String defaultTemplate = template != null ? template.getImageId() : null;
Network network = null; Network network = null;
try { try {
Template template = getOnlyElement( Template template = getOnlyElement(
client.getTemplateClient().listTemplates(ListTemplatesOptions.Builder.id(templateId))); client.getTemplateClient().listTemplates(ListTemplatesOptions.Builder.id(defaultTemplate)));
logger.info("Using template: " + template); logger.info("Using template: " + template);
Set<Network> allSafeNetworksInZone = adminClient.getNetworkClient().listNetworks( Set<Network> allSafeNetworksInZone = adminClient.getNetworkClient().listNetworks(
@ -252,7 +252,7 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
ipsToNetworks.put(ipAddress, network.getId()); ipsToNetworks.put(ipAddress, network.getId());
vm = createVirtualMachineInNetworkWithIp( vm = createVirtualMachineInNetworkWithIp(
adminClient, templateId, ImmutableSet.of(requiredNetwork, network), adminClient, defaultTemplate, ImmutableSet.of(requiredNetwork, network),
ipsToNetworks, adminJobComplete, adminVirtualMachineRunning); ipsToNetworks, adminJobComplete, adminVirtualMachineRunning);
logger.info("Created VM: " + vm); logger.info("Created VM: " + vm);

View File

@ -64,7 +64,7 @@ public class StaticNATVirtualMachineInNetworkLiveTest extends NATClientLiveTest
prefix += "nat"; prefix += "nat";
try { try {
network = find(client.getNetworkClient().listNetworks(), NetworkPredicates.supportsStaticNAT()); network = find(client.getNetworkClient().listNetworks(), NetworkPredicates.supportsStaticNAT());
String defaultTemplate = (imageId != null && !"".equals(imageId)) ? imageId : null; String defaultTemplate = template != null ? template.getImageId() : null;
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network,
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete, defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
virtualMachineRunning); virtualMachineRunning);

View File

@ -27,9 +27,6 @@ import java.net.URI;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiMetadata;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
@ -111,8 +108,7 @@ public class CloudWatchAsyncClientTest extends BaseAsyncClientTest<CloudWatchAsy
} }
@Override @Override
protected String provideTimeStamp(final DateService dateService, protected String provideTimeStamp(final DateService dateService) {
@Named(Constants.PROPERTY_SESSION_INTERVAL) int expiration) {
return "2009-11-08T15:54:08.897Z"; return "2009-11-08T15:54:08.897Z";
} }
} }

View File

@ -23,9 +23,6 @@ import static com.google.common.collect.Maps.transformValues;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.inject.Named;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.cloudwatch.config.CloudWatchRestClientModule; import org.jclouds.cloudwatch.config.CloudWatchRestClientModule;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
@ -69,8 +66,7 @@ public class BaseCloudWatchExpectTest<T> extends BaseRestClientExpectTest<T> {
} }
@Override @Override
protected String provideTimeStamp(final DateService dateService, protected String provideTimeStamp(final DateService dateService) {
@Named(Constants.PROPERTY_SESSION_INTERVAL) int expiration) {
return "2009-11-08T15:54:08.897Z"; return "2009-11-08T15:54:08.897Z";
} }
} }

View File

@ -50,13 +50,10 @@
<properties> <properties>
<test.deltacloud.endpoint>http://localhost:3001/api</test.deltacloud.endpoint> <test.deltacloud.endpoint>http://localhost:3001/api</test.deltacloud.endpoint>
<test.deltacloud.api-version>0.3.0</test.deltacloud.api-version> <test.deltacloud.api-version>0.3.0</test.deltacloud.api-version>
<test.deltacloud.build-version /> <test.deltacloud.build-version></test.deltacloud.build-version>
<test.deltacloud.identity>mockuser</test.deltacloud.identity> <test.deltacloud.identity>mockuser</test.deltacloud.identity>
<test.deltacloud.credential>mockpassword</test.deltacloud.credential> <test.deltacloud.credential>mockpassword</test.deltacloud.credential>
<test.deltacloud.image-id /> <test.deltacloud.template></test.deltacloud.template>
<test.deltacloud.image.login-user />
<test.deltacloud.image.authenticate-sudo />
<jclouds.osgi.export>org.jclouds.deltacloud*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.deltacloud*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}", org.jclouds.compute.internal;version="${project.version}",
@ -120,9 +117,7 @@
<test.deltacloud.build-version>${test.deltacloud.build-version}</test.deltacloud.build-version> <test.deltacloud.build-version>${test.deltacloud.build-version}</test.deltacloud.build-version>
<test.deltacloud.identity>${test.deltacloud.identity}</test.deltacloud.identity> <test.deltacloud.identity>${test.deltacloud.identity}</test.deltacloud.identity>
<test.deltacloud.credential>${test.deltacloud.credential}</test.deltacloud.credential> <test.deltacloud.credential>${test.deltacloud.credential}</test.deltacloud.credential>
<test.deltacloud.image-id>${test.deltacloud.image-id}</test.deltacloud.image-id> <test.deltacloud.template>${test.deltacloud.template}</test.deltacloud.template>
<test.deltacloud.image.login-user>${test.deltacloud.image.login-user}</test.deltacloud.image.login-user>
<test.deltacloud.image.authenticate-sudo>${test.deltacloud.image.authenticate-sudo}</test.deltacloud.image.authenticate-sudo>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -36,13 +36,11 @@
<properties> <properties>
<test.ec2.endpoint>https://ec2.us-east-1.amazonaws.com</test.ec2.endpoint> <test.ec2.endpoint>https://ec2.us-east-1.amazonaws.com</test.ec2.endpoint>
<test.ec2.api-version>2010-06-15</test.ec2.api-version> <test.ec2.api-version>2010-06-15</test.ec2.api-version>
<test.ec2.build-version /> <test.ec2.build-version></test.ec2.build-version>
<test.ec2.identity>${test.aws.identity}</test.ec2.identity> <test.ec2.identity>${test.aws.identity}</test.ec2.identity>
<test.ec2.credential>${test.aws.credential}</test.ec2.credential> <test.ec2.credential>${test.aws.credential}</test.ec2.credential>
<test.ec2.image-id /> <test.ec2.template></test.ec2.template>
<test.ec2.image.login-user /> <test.ec2.ebs-template>hardwareId=m1.small,imageId=us-west-2/ami-38c64a08</test.ec2.ebs-template>
<test.ec2.image.authenticate-sudo />
<jclouds.osgi.export>org.jclouds.ec2*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.ec2*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}", org.jclouds.compute.internal;version="${project.version}",
@ -128,9 +126,8 @@
<test.ec2.build-version>${test.ec2.build-version}</test.ec2.build-version> <test.ec2.build-version>${test.ec2.build-version}</test.ec2.build-version>
<test.ec2.identity>${test.ec2.identity}</test.ec2.identity> <test.ec2.identity>${test.ec2.identity}</test.ec2.identity>
<test.ec2.credential>${test.ec2.credential}</test.ec2.credential> <test.ec2.credential>${test.ec2.credential}</test.ec2.credential>
<test.ec2.image-id>${test.ec2.image-id}</test.ec2.image-id> <test.ec2.template>${test.ec2.template}</test.ec2.template>
<test.ec2.image.login-user>${test.ec2.image.login-user}</test.ec2.image.login-user> <test.ec2.ebs-template>${test.ec2.ebs-template}</test.ec2.ebs-template>
<test.ec2.image.authenticate-sudo>${test.ec2.image.authenticate-sudo}</test.ec2.image.authenticate-sudo>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -32,10 +32,10 @@ import javax.inject.Singleton;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Image.Status;
import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Image.Status;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.compute.util.ComputeServiceUtils;
@ -100,7 +100,7 @@ public class EC2ImageParser implements Function<org.jclouds.ec2.domain.Image, Im
OperatingSystem.Builder osBuilder = OperatingSystem.builder(); OperatingSystem.Builder osBuilder = OperatingSystem.builder();
osBuilder.is64Bit(from.getArchitecture() == Architecture.X86_64); osBuilder.is64Bit(from.getArchitecture() == Architecture.X86_64);
OsFamily family = parseOsFamilyOrUnrecognized(from.getImageLocation()); OsFamily family = parseOsFamily(from);
osBuilder.family(family); osBuilder.family(family);
osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, from.getImageLocation(), osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, from.getImageLocation(),
osVersionMap)); osVersionMap));
@ -131,4 +131,20 @@ public class EC2ImageParser implements Function<org.jclouds.ec2.domain.Image, Im
return builder.build(); return builder.build();
} }
/**
* First treats windows as a special case: check if platform==windows.
* Then tries matching based on the image name.
* And then falls back to checking other types of platform.
*/
private OsFamily parseOsFamily(org.jclouds.ec2.domain.Image from) {
if (from.getPlatform() != null && from.getPlatform().equalsIgnoreCase("windows")) {
return OsFamily.WINDOWS;
}
OsFamily family = parseOsFamilyOrUnrecognized(from.getImageLocation());
if (family == OsFamily.UNRECOGNIZED && from.getPlatform() != null) {
family = parseOsFamilyOrUnrecognized(from.getPlatform());
}
return family;
}
} }

View File

@ -40,11 +40,15 @@ import org.jclouds.ec2.services.SecurityGroupClient;
import org.jclouds.ec2.services.WindowsAsyncClient; import org.jclouds.ec2.services.WindowsAsyncClient;
import org.jclouds.ec2.services.WindowsClient; import org.jclouds.ec2.services.WindowsClient;
import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion; import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion;
import org.jclouds.ec2.suppliers.DescribeRegionsForConfiguredRegions; import org.jclouds.ec2.suppliers.DescribeRegionsForRegionURIs;
import org.jclouds.location.config.LocationModule; import org.jclouds.location.config.LocationModule;
import org.jclouds.location.suppliers.RegionIdToURISupplier; import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier; import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
import org.jclouds.location.suppliers.RegionIdsSupplier;
import org.jclouds.location.suppliers.ZoneIdToURISupplier;
import org.jclouds.location.suppliers.ZoneIdsSupplier; import org.jclouds.location.suppliers.ZoneIdsSupplier;
import org.jclouds.location.suppliers.derived.RegionIdsFromRegionIdToURIKeySet;
import org.jclouds.location.suppliers.derived.ZoneIdToURIFromJoinOnRegionIdToURI;
import org.jclouds.location.suppliers.derived.ZoneIdsFromRegionIdToZoneIdsValues; import org.jclouds.location.suppliers.derived.ZoneIdsFromRegionIdToZoneIdsValues;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
@ -81,13 +85,13 @@ public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient>
super(syncClientType, asyncClientType, sync2Async); super(syncClientType, asyncClientType, sync2Async);
} }
@Override @Override
protected void installLocations() { protected void installLocations() {
install(new LocationModule()); install(new LocationModule());
bind(RegionIdToZoneIdsSupplier.class).to(DescribeAvailabilityZonesInRegion.class).in(Scopes.SINGLETON); bind(RegionIdToZoneIdsSupplier.class).to(DescribeAvailabilityZonesInRegion.class).in(Scopes.SINGLETON);
bind(RegionIdToURISupplier.class).to(DescribeRegionsForConfiguredRegions.class).in(Scopes.SINGLETON); bind(RegionIdToURISupplier.class).to(DescribeRegionsForRegionURIs.class).in(Scopes.SINGLETON);
bind(ZoneIdsSupplier.class).to(ZoneIdsFromRegionIdToZoneIdsValues.class).in(Scopes.SINGLETON); bind(ZoneIdsSupplier.class).to(ZoneIdsFromRegionIdToZoneIdsValues.class).in(Scopes.SINGLETON);
bind(RegionIdsSupplier.class).to(RegionIdsFromRegionIdToURIKeySet.class).in(Scopes.SINGLETON);
bind(ZoneIdToURISupplier.class).to(ZoneIdToURIFromJoinOnRegionIdToURI.class).in(Scopes.SINGLETON);
} }
} }

View File

@ -269,9 +269,9 @@ public class RunningInstance implements Comparable<RunningInstance> {
this.dnsName = dnsName; // nullable on runinstances. this.dnsName = dnsName; // nullable on runinstances.
this.imageId = imageId; // nullable on runinstances. this.imageId = imageId; // nullable on runinstances.
this.instanceId = checkNotNull(instanceId, "instanceId"); this.instanceId = checkNotNull(instanceId, "instanceId");
this.instanceState = checkNotNull(instanceState, "instanceState"); this.instanceState = checkNotNull(instanceState, "instanceState for %s/%s", region, instanceId);
this.rawState = checkNotNull(rawState, "rawState"); this.rawState = checkNotNull(rawState, "rawState for %s/%s", region, instanceId);
this.instanceType = checkNotNull(instanceType, "instanceType"); this.instanceType = checkNotNull(instanceType, "instanceType for %s/%s", region, instanceId);
this.ipAddress = ipAddress; this.ipAddress = ipAddress;
this.kernelId = kernelId; this.kernelId = kernelId;
this.keyName = keyName; this.keyName = keyName;
@ -283,10 +283,10 @@ public class RunningInstance implements Comparable<RunningInstance> {
this.privateIpAddress = privateIpAddress;// nullable on runinstances. this.privateIpAddress = privateIpAddress;// nullable on runinstances.
this.ramdiskId = ramdiskId; this.ramdiskId = ramdiskId;
this.reason = reason; this.reason = reason;
this.rootDeviceType = checkNotNull(rootDeviceType, "rootDeviceType"); this.rootDeviceType = checkNotNull(rootDeviceType, "rootDeviceType for %s/%s", region, instanceId);
this.rootDeviceName = rootDeviceName; this.rootDeviceName = rootDeviceName;
this.ebsBlockDevices = ImmutableMap.copyOf(checkNotNull(ebsBlockDevices, "ebsBlockDevices")); this.ebsBlockDevices = ImmutableMap.copyOf(checkNotNull(ebsBlockDevices, "ebsBlockDevices for %s/%s", region, instanceId));
this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds")); this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds for %s/%s", region, instanceId));
} }
/** /**

View File

@ -97,7 +97,7 @@ public class Volume implements Comparable<Volume> {
private String availabilityZone; private String availabilityZone;
private Status status; private Status status;
private Date createTime; private Date createTime;
private Set<Attachment> attachments; private Set<Attachment> attachments = ImmutableSet.of();
public Builder region(String region) { public Builder region(String region) {
this.region = region; this.region = region;

View File

@ -114,6 +114,7 @@ public interface InstanceAsyncClient {
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "TerminateInstances") @FormParams(keys = ACTION, values = "TerminateInstances")
@XMLResponseParser(InstanceStateChangeHandler.class) @XMLResponseParser(InstanceStateChangeHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<? extends InstanceStateChange>> terminateInstancesInRegion( ListenableFuture<Set<? extends InstanceStateChange>> terminateInstancesInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds); @BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);

View File

@ -20,7 +20,6 @@ package org.jclouds.ec2.suppliers;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -31,29 +30,23 @@ import org.jclouds.location.Region;
import org.jclouds.location.suppliers.RegionIdToURISupplier; import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.util.Suppliers2; import org.jclouds.util.Suppliers2;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@Singleton @Singleton
public class DescribeRegionsForConfiguredRegions implements RegionIdToURISupplier { public class DescribeRegionsForRegionURIs implements RegionIdToURISupplier {
private final AvailabilityZoneAndRegionClient client; private final AvailabilityZoneAndRegionClient client;
private final Supplier<Set<String>> regions;
@Inject @Inject
public DescribeRegionsForConfiguredRegions(EC2Client client, @Region Supplier<Set<String>> regions) { public DescribeRegionsForRegionURIs(EC2Client client) {
this.client = client.getAvailabilityZoneAndRegionServices(); this.client = client.getAvailabilityZoneAndRegionServices();
this.regions = regions;
} }
@Singleton @Singleton
@Region @Region
@Override @Override
public Map<String, Supplier<URI>> get() { public Map<String, Supplier<URI>> get() {
Set<String> regionWhiteList = regions.get();
Map<String, URI> regionToUris = client.describeRegions(); Map<String, URI> regionToUris = client.describeRegions();
if (regionWhiteList.size() > 0)
regionToUris = Maps.filterKeys(regionToUris, Predicates.in(regionWhiteList));
return Maps.transformValues(regionToUris, Suppliers2.<URI> ofInstanceFunction()); return Maps.transformValues(regionToUris, Suppliers2.<URI> ofInstanceFunction());
} }
} }

View File

@ -72,7 +72,10 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
protected Builder builder; protected Builder builder;
protected int itemDepth; protected int itemDepth;
boolean inInstancesSet; protected boolean inInstancesSet;
protected boolean inProductCodes;
protected boolean inGroupSet;
// attachments // attachments
private String volumeId; private String volumeId;
private Attachment.Status attachmentStatus; private Attachment.Status attachmentStatus;
@ -88,12 +91,17 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
private Set<RunningInstance> instances = Sets.newLinkedHashSet(); private Set<RunningInstance> instances = Sets.newLinkedHashSet();
public void startElement(String uri, String name, String qName, Attributes attrs) { public void startElement(String uri, String name, String qName, Attributes attrs) {
if (equalsOrSuffix(qName, "item")) { if (equalsOrSuffix(qName, "item")) {
itemDepth++; itemDepth++;
} else if (equalsOrSuffix(qName, "instancesSet")) { } else if (equalsOrSuffix(qName, "instancesSet")) {
inInstancesSet = true; inInstancesSet = true;
} } else if (equalsOrSuffix(qName, "productCodes")) {
inProductCodes = true;
} else if (equalsOrSuffix(qName, "groupSet")) {
inGroupSet = true;
}
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
@ -102,6 +110,10 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
itemDepth--; itemDepth--;
} else if (equalsOrSuffix(qName, "instancesSet")) { } else if (equalsOrSuffix(qName, "instancesSet")) {
inInstancesSet = false; inInstancesSet = false;
} else if (equalsOrSuffix(qName, "productCodes")) {
inProductCodes = false;
} else if (equalsOrSuffix(qName, "groupSet")) {
inGroupSet = false;
} else if (equalsOrSuffix(qName, "groupId")) { } else if (equalsOrSuffix(qName, "groupId")) {
groupIds.add(currentOrNull(currentText)); groupIds.add(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "ownerId")) { } else if (equalsOrSuffix(qName, "ownerId")) {
@ -219,7 +231,7 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
} }
protected boolean endOfInstanceItem() { protected boolean endOfInstanceItem() {
return itemDepth <= 2 && inInstancesSet; return itemDepth <= 2 && inInstancesSet && !inProductCodes && !inGroupSet;
} }
public void characters(char ch[], int start, int length) { public void characters(char ch[], int start, int length) {

View File

@ -55,7 +55,7 @@ public class DescribeRegionsResponseHandler extends ParseSax.HandlerWithResult<M
String pending = currentText.toString().trim(); String pending = currentText.toString().trim();
if (pending.indexOf("Walrus") == -1) if (pending.indexOf("Walrus") == -1)
regionEndpoint = URI.create(pending.startsWith("http") ? pending : String.format("https://%s", pending)); regionEndpoint = URI.create(pending.startsWith("http") ? pending : String.format("https://%s", pending));
} else if (qName.equals("item") && region != null) { } else if (qName.equals("item") && region != null && regionEndpoint != null) {
regionEndpoints.put(region, regionEndpoint); regionEndpoints.put(region, regionEndpoint);
this.region = null; this.region = null;
this.regionEndpoint = null; this.regionEndpoint = null;

View File

@ -59,8 +59,7 @@ public abstract class BaseEC2ComputeServiceExpectTest<T> extends BaseRestClientE
private static final class TestEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> { private static final class TestEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
@Override @Override
@Provides @Provides
protected String provideTimeStamp(final DateService dateService, protected String provideTimeStamp(DateService dateService) {
@Named(Constants.PROPERTY_SESSION_INTERVAL) final int expiration) {
return CONSTANT_DATE; return CONSTANT_DATE;
} }
} }

View File

@ -29,8 +29,8 @@ import java.util.Set;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilderSpec;
import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.compute.predicates.NodePredicates;
@ -41,7 +41,6 @@ import org.jclouds.ec2.EC2ApiMetadata;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.compute.options.EC2TemplateOptions; import org.jclouds.ec2.compute.options.EC2TemplateOptions;
import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.BlockDevice;
import org.jclouds.ec2.domain.InstanceType;
import org.jclouds.ec2.domain.IpProtocol; import org.jclouds.ec2.domain.IpProtocol;
import org.jclouds.ec2.domain.KeyPair; import org.jclouds.ec2.domain.KeyPair;
import org.jclouds.ec2.domain.PublicIpInstanceIdPair; import org.jclouds.ec2.domain.PublicIpInstanceIdPair;
@ -57,6 +56,7 @@ import org.jclouds.ec2.services.SecurityGroupClient;
import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.scriptbuilder.domain.Statements;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.util.InetAddresses2; import org.jclouds.util.InetAddresses2;
import org.testng.SkipException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -74,6 +74,8 @@ import com.google.inject.Module;
@Test(groups = "live", singleThreaded = true) @Test(groups = "live", singleThreaded = true)
public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
protected TemplateBuilderSpec ebsTemplate;
public EC2ComputeServiceLiveTest() { public EC2ComputeServiceLiveTest() {
provider = "ec2"; provider = "ec2";
} }
@ -227,12 +229,24 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
} }
} }
@Override
protected Properties setupProperties() {
Properties overrides = super.setupProperties();
String ebsSpec = setIfTestSystemPropertyPresent(overrides, provider + ".ebs-template");
if (ebsSpec != null)
ebsTemplate = TemplateBuilderSpec.parse(ebsSpec);
return overrides;
}
/** /**
* Note we cannot use the micro size as it has no ephemeral space. * Note we cannot use the micro size as it has no ephemeral space.
*/ */
@Test(enabled = true) @Test
public void testMapEBS() throws Exception { public void testMapEBS() throws Exception {
if (ebsTemplate == null) {
throw new SkipException("Test cannot run without the parameter test." + provider
+ ".ebs-template; this property should be in the format defined in TemplateBuilderSpec");
}
InstanceClient instanceClient = EC2Client.class.cast(view.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi()) InstanceClient instanceClient = EC2Client.class.cast(view.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi())
.getInstanceServices(); .getInstanceServices();
@ -242,8 +256,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
String group = this.group + "e"; String group = this.group + "e";
int volumeSize = 8; int volumeSize = 8;
final Template template = view.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL) final Template template = view.getComputeService().templateBuilder().from(ebsTemplate).build();
.osFamily(OsFamily.UBUNTU).osVersionMatches("10.04").imageDescriptionMatches(".*ebs.*").build();
Location zone = Iterables.find(view.getComputeService().listAssignableLocations(), new Predicate<Location>() { Location zone = Iterables.find(view.getComputeService().listAssignableLocations(), new Predicate<Location>() {

View File

@ -24,10 +24,10 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.Image.Status;
import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Image.Status;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LocationBuilder;
@ -64,24 +64,48 @@ public class EC2ImageParserTest {
assertEquals(image.getBackendStatus(), "available"); assertEquals(image.getBackendStatus(), "available");
} }
assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem( assertImageEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem(
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description( new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description(
"137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).description("Amazon") "137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).description("Amazon")
.defaultCredentials(new LoginCredentials("ec2-user", false)).id("us-east-1/ami-82e4b5c7").name( .defaultCredentials(new LoginCredentials("ec2-user", false)).id("us-east-1/ami-82e4b5c7").name(
"amzn-ami-0.9.7-beta.i386-ebs").providerId("ami-82e4b5c7").location(defaultLocation) "amzn-ami-0.9.7-beta.i386-ebs").providerId("ami-82e4b5c7").location(defaultLocation)
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).status( .userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).status(
Status.AVAILABLE).build()); Status.AVAILABLE).backendStatus("available").build());
assertEquals(Iterables.get(result, 3), new ImageBuilder().operatingSystem( assertImageEquals(Iterables.get(result, 3), new ImageBuilder().operatingSystem(
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description( new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description(
"amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml").is64Bit(true).build()) "amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml").is64Bit(true).build())
.description("Amazon Linux AMI x86_64 S3").defaultCredentials(new LoginCredentials("ec2-user", false)) .description("Amazon Linux AMI x86_64 S3").defaultCredentials(new LoginCredentials("ec2-user", false))
.id("us-east-1/ami-f2e4b5b7").providerId("ami-f2e4b5b7").name("amzn-ami-0.9.7-beta.x86_64-S3").location( .id("us-east-1/ami-f2e4b5b7").providerId("ami-f2e4b5b7").name("amzn-ami-0.9.7-beta.x86_64-S3").location(
defaultLocation) defaultLocation)
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).status( .userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).status(
Status.AVAILABLE).build()); Status.AVAILABLE).backendStatus("available").build());
assertImageEquals(Iterables.get(result, 4), new ImageBuilder().operatingSystem(
new OperatingSystem.Builder().family(OsFamily.WINDOWS).arch("hvm").version("2008").description(
"amazon/NameGivesNoClue_Server-2008-R2_SP1-Language_Packs-64Bit-Base-2012.05.10")
.is64Bit(true).build())
.description("Microsoft Windows Server 2008 R2 SP1 Datacenter 64-bit Multi-language AMI provided by Amazon")
.defaultCredentials(new LoginCredentials("root", false))
.id("us-east-1/ami-85457ff1").providerId("ami-85457ff1").name("NameGivesNoClue_Server-2008-R2_SP1-Language_Packs-64Bit-Base-2012.05.10")
.location(defaultLocation)
.userMetadata(ImmutableMap.of("owner", "801119661308", "rootDeviceType", "ebs"))
.status(Status.AVAILABLE).backendStatus("available").build());
} }
private void assertImageEquals(org.jclouds.compute.domain.Image actual, org.jclouds.compute.domain.Image expected) {
// Note that ImageImpl.equals does not compare operating system etc; there's an explicit comment:
// equals from super is sufficient to establish identity equivalence
assertEquals(actual, expected);
assertEquals(actual.getOperatingSystem(), expected.getOperatingSystem());
assertEquals(actual.getStatus(), expected.getStatus());
assertEquals(actual.getBackendStatus(), expected.getBackendStatus());
assertEquals(actual.getVersion(), expected.getVersion());
assertEquals(actual.getDescription(), expected.getDescription());
assertEquals(actual.getDefaultCredentials(), expected.getDefaultCredentials());
}
static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description( static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description(
"us-east-1").build(); "us-east-1").build();

View File

@ -0,0 +1,143 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.ec2.config;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.jclouds.ec2.internal.BaseEC2ExpectTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.location.Region;
import org.jclouds.location.Zone;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.location.functions.ZoneToEndpoint;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "EC2RestClientModuleExpectTest")
public class EC2RestClientModuleExpectTest extends BaseEC2ExpectTest<Injector> {
private Injector injector;
public EC2RestClientModuleExpectTest() {
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse> builder();
builder.put(describeRegionsRequest, describeRegionsResponse);
builder.putAll(describeAvailabilityZonesRequestResponse);
injector = requestsSendResponses(builder.build());
}
public void testLocationIdAndURIBindings() {
assertEquals(injector.getInstance(Key.get(new TypeLiteral<Supplier<Set<String>>>() {
}, Region.class)).get(), ImmutableSet.<String> of("sa-east-1", "ap-northeast-1", "eu-west-1", "us-east-1",
"us-west-1", "us-west-2", "ap-southeast-1"));
assertEquals(injector.getInstance(Key.get(new TypeLiteral<Supplier<Set<String>>>() {
}, Zone.class)).get(), ImmutableSet.<String> of("sa-east-1a", "sa-east-1b", "ap-northeast-1a", "ap-northeast-1b",
"eu-west-1a", "eu-west-1b", "eu-west-1c", "us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d",
"us-east-1e", "us-west-1a", "us-west-1b", "us-west-1c", "us-west-2a", "us-west-2b", "us-west-2c",
"ap-southeast-1a", "ap-southeast-1b"));
Map<String, Supplier<URI>> regionToURISupplier = injector.getInstance(
Key.get(new TypeLiteral<Supplier<Map<String, Supplier<URI>>>>() {
}, Region.class)).get();
assertEquals(regionToURISupplier.get("sa-east-1").get(), URI.create("https://ec2.sa-east-1.amazonaws.com"));
assertEquals(regionToURISupplier.get("ap-northeast-1").get(),
URI.create("https://ec2.ap-northeast-1.amazonaws.com"));
assertEquals(regionToURISupplier.get("eu-west-1").get(), URI.create("https://ec2.eu-west-1.amazonaws.com"));
assertEquals(regionToURISupplier.get("us-east-1").get(), URI.create("https://ec2.us-east-1.amazonaws.com"));
assertEquals(regionToURISupplier.get("us-west-1").get(), URI.create("https://ec2.us-west-1.amazonaws.com"));
assertEquals(regionToURISupplier.get("us-west-2").get(), URI.create("https://ec2.us-west-2.amazonaws.com"));
assertEquals(regionToURISupplier.get("ap-southeast-1").get(),
URI.create("https://ec2.ap-southeast-1.amazonaws.com"));
Map<String, Supplier<Set<String>>> regionToZoneIdSupplier = injector.getInstance(
Key.get(new TypeLiteral<Supplier<Map<String, Supplier<Set<String>>>>>() {
}, Zone.class)).get();
assertEquals(regionToZoneIdSupplier.get("sa-east-1").get(), ImmutableSet.of("sa-east-1a", "sa-east-1b"));
assertEquals(regionToZoneIdSupplier.get("ap-northeast-1").get(),
ImmutableSet.of("ap-northeast-1a", "ap-northeast-1b"));
assertEquals(regionToZoneIdSupplier.get("eu-west-1").get(),
ImmutableSet.of("eu-west-1a", "eu-west-1b", "eu-west-1c"));
assertEquals(regionToZoneIdSupplier.get("us-east-1").get(),
ImmutableSet.of("us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d", "us-east-1e"));
assertEquals(regionToZoneIdSupplier.get("us-west-1").get(),
ImmutableSet.of("us-west-1a", "us-west-1b", "us-west-1c"));
assertEquals(regionToZoneIdSupplier.get("us-west-2").get(),
ImmutableSet.of("us-west-2a", "us-west-2b", "us-west-2c"));
assertEquals(regionToZoneIdSupplier.get("ap-southeast-1").get(),
ImmutableSet.of("ap-southeast-1a", "ap-southeast-1b"));
Map<String, Supplier<URI>> zoneToURISupplier = injector.getInstance(
Key.get(new TypeLiteral<Supplier<Map<String, Supplier<URI>>>>() {
}, Zone.class)).get();
assertEquals(zoneToURISupplier.get("sa-east-1a").get(), URI.create("https://ec2.sa-east-1.amazonaws.com"));
assertEquals(zoneToURISupplier.get("ap-northeast-1a").get(),
URI.create("https://ec2.ap-northeast-1.amazonaws.com"));
assertEquals(zoneToURISupplier.get("eu-west-1a").get(), URI.create("https://ec2.eu-west-1.amazonaws.com"));
assertEquals(zoneToURISupplier.get("us-east-1a").get(), URI.create("https://ec2.us-east-1.amazonaws.com"));
assertEquals(zoneToURISupplier.get("us-west-1a").get(), URI.create("https://ec2.us-west-1.amazonaws.com"));
assertEquals(zoneToURISupplier.get("us-west-2a").get(), URI.create("https://ec2.us-west-2.amazonaws.com"));
assertEquals(zoneToURISupplier.get("ap-southeast-1a").get(),
URI.create("https://ec2.ap-southeast-1.amazonaws.com"));
}
public void testZoneToEndpoint() {
assertEquals(injector.getInstance(ZoneToEndpoint.class).apply("us-west-2a"),
URI.create("https://ec2.us-west-2.amazonaws.com"));
}
public void testRegionToEndpointOrProviderIfNull() {
assertEquals(injector.getInstance(RegionToEndpointOrProviderIfNull.class).apply("us-west-2"),
URI.create("https://ec2.us-west-2.amazonaws.com"));
}
@Override
public Injector createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
return createInjector(fn, module, props);
}
}

View File

@ -0,0 +1,99 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.ec2.internal;
import java.net.URI;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.date.DateService;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.config.EC2RestClientModule;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.internal.BaseRestClientExpectTest;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import com.google.inject.Provides;
public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> {
protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z";
protected DateService dateService = new SimpleDateFormatDateService();
protected HttpRequest describeRegionsRequest = HttpRequest
.builder()
.method("POST")
.endpoint(URI.create("https://ec2.us-east-1.amazonaws.com/"))
.headers(ImmutableMultimap.of("Host", "ec2.us-east-1.amazonaws.com"))
.payload(payloadFromStringWithContentType(
"Action=DescribeRegions&Signature=s5OXKqaaeKhJW5FVrRntuMsUL4Ed5fjzgUWeukU96ko%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
MediaType.APPLICATION_FORM_URLENCODED)).build();
protected HttpResponse describeRegionsResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/regionEndpoints-all.xml", MediaType.APPLICATION_XML))
.build();
protected final Map<HttpRequest, HttpResponse> describeAvailabilityZonesRequestResponse;
public BaseEC2ExpectTest() {
provider = "ec2";
FormSigner formSigner = createInjector(Functions.forMap(ImmutableMap.<HttpRequest, HttpResponse> of()),
createModule(), setupProperties()).getInstance(FormSigner.class);
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse> builder();
for (String region : ImmutableSet.of("ap-northeast-1", "ap-southeast-1", "eu-west-1", "sa-east-1", "us-east-1", "us-west-1", "us-west-2")){
builder.put(
formSigner.filter(HttpRequest.builder()
.method("POST")
.endpoint(URI.create("https://ec2." + region + ".amazonaws.com/"))
.headers(ImmutableMultimap.of("Host", "ec2." + region + ".amazonaws.com"))
.payload(payloadFromStringWithContentType(
"Action=DescribeAvailabilityZones&Version=2010-06-15",
MediaType.APPLICATION_FORM_URLENCODED)).build()),
HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType(
"/availabilityZones-" + region + ".xml", MediaType.APPLICATION_XML)).build());
}
describeAvailabilityZonesRequestResponse = builder.build();
}
@ConfiguresRestClient
private static final class TestEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
@Override
@Provides
protected String provideTimeStamp(DateService dateService) {
return CONSTANT_DATE;
}
}
@Override
protected Module createModule() {
return new TestEC2RestClientModule();
}
}

View File

@ -0,0 +1,186 @@
package org.jclouds.ec2.services;
import static org.jclouds.ec2.options.DescribeImagesOptions.Builder.imageIds;
import static org.jclouds.ec2.options.RegisterImageBackedByEbsOptions.Builder.addNewBlockDevice;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilderSpec;
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.ec2.EC2ApiMetadata;
import org.jclouds.ec2.domain.BlockDevice;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.domain.Image.ImageType;
import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.ec2.domain.Snapshot;
import org.jclouds.ec2.services.AMIClient;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* Tests behavior of {@code AMIClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true)
public class AMIClientLiveTest extends BaseComputeServiceContextLiveTest {
private TemplateBuilderSpec ebsTemplate;
public AMIClientLiveTest() {
provider = "ec2";
}
@Override
protected Properties setupProperties() {
Properties overrides = super.setupProperties();
String ebsSpec = setIfTestSystemPropertyPresent(overrides, provider + ".ebs-template");
if (ebsSpec != null)
ebsTemplate = TemplateBuilderSpec.parse(ebsSpec);
return overrides;
}
protected AMIClient client;
protected Set<String> imagesToDeregister = Sets.newHashSet();
protected Set<String> snapshotsToDelete = Sets.newHashSet();
protected String regionId;
protected String ebsBackedImageId;
protected String ebsBackedImageName = "jcloudstest1";
@Override
@BeforeClass(groups = { "integration", "live" })
public void setupContext() {
super.setupContext();
client = view.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getAMIServices();
if (ebsTemplate != null) {
Template template = view.getComputeService().templateBuilder().from(ebsTemplate).build();
regionId = template.getLocation().getId();
for (Image image : client.describeImagesInRegion(regionId)) {
if (ebsBackedImageName.equals(image.getName()))
client.deregisterImageInRegion(regionId, image.getId());
}
}
}
public void testDescribeImageNotExists() {
assertEquals(client.describeImagesInRegion(null, imageIds("ami-cdf819a3")).size(), 0);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testDescribeImageBadId() {
client.describeImagesInRegion(null, imageIds("asdaasdsa"));
}
public void testDescribeImages() {
for (String region : view.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getAvailabilityZoneAndRegionServices()
.describeRegions().keySet()) {
Set<? extends Image> allResults = client.describeImagesInRegion(region);
assertNotNull(allResults);
assert allResults.size() >= 2 : allResults.size();
Iterator<? extends Image> iterator = allResults.iterator();
String id1 = iterator.next().getId();
String id2 = iterator.next().getId();
Set<? extends Image> twoResults = client.describeImagesInRegion(region, imageIds(id1, id2));
assertNotNull(twoResults);
assertEquals(twoResults.size(), 2);
iterator = twoResults.iterator();
assertEquals(iterator.next().getId(), id1);
assertEquals(iterator.next().getId(), id2);
}
}
@Test
public void testCreateAndListEBSBackedImage() throws Exception {
ComputeService computeService = view.getComputeService();
Snapshot snapshot = createSnapshot(computeService);
// List of images before...
int sizeBefore = computeService.listImages().size();
// Register a new image...
ebsBackedImageId = client.registerUnixImageBackedByEbsInRegion(regionId, ebsBackedImageName, snapshot.getId(),
addNewBlockDevice("/dev/sda2", "myvirtual", 1).withDescription("adrian"));
imagesToDeregister.add(ebsBackedImageId);
final Image ebsBackedImage = Iterables.getOnlyElement(client.describeImagesInRegion(regionId,
imageIds(ebsBackedImageId)));
assertEquals(ebsBackedImage.getName(), ebsBackedImageName);
assertEquals(ebsBackedImage.getImageType(), ImageType.MACHINE);
assertEquals(ebsBackedImage.getRootDeviceType(), RootDeviceType.EBS);
assertEquals(ebsBackedImage.getRootDeviceName(), "/dev/sda1");
assertEquals(ebsBackedImage.getDescription(), "adrian");
assertEquals(
ebsBackedImage.getEbsBlockDevices().entrySet(),
ImmutableMap.of("/dev/sda1", new Image.EbsBlockDevice(snapshot.getId(), snapshot.getVolumeSize(), true),
"/dev/sda2", new Image.EbsBlockDevice(null, 1, false)).entrySet());
// This is the suggested method to ensure the new image ID is inserted
// into the cache
// (suggested by adriancole_ on #jclouds)
computeService.templateBuilder().imageId(ebsBackedImage.getRegion() + "/" + ebsBackedImageId).build();
// List of images after - should be one larger than before
Set<? extends org.jclouds.compute.domain.Image> after = computeService.listImages();
assertEquals(after.size(), sizeBefore + 1);
// Detailed check: filter for the AMI ID
Iterable<? extends org.jclouds.compute.domain.Image> filtered = Iterables.filter(after,
ImagePredicates.idEquals(ebsBackedImage.getRegion() + "/" + ebsBackedImageId));
assertEquals(Iterables.size(filtered), 1);
}
// Fires up an instance, finds its root volume ID, takes a snapshot, then
// terminates the instance.
private Snapshot createSnapshot(ComputeService computeService) throws RunNodesException {
Template template = computeService.templateBuilder().from(ebsTemplate).build();
regionId = template.getLocation().getId();
Set<? extends NodeMetadata> nodes = computeService.createNodesInGroup("jcloudstest", 1, template);
try {
String instanceId = Iterables.getOnlyElement(nodes).getProviderId();
Reservation<? extends RunningInstance> reservation = Iterables.getOnlyElement(view
.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getInstanceServices()
.describeInstancesInRegion(regionId, instanceId));
RunningInstance instance = Iterables.getOnlyElement(reservation);
BlockDevice device = instance.getEbsBlockDevices().get("/dev/sda1");
Snapshot snapshot = view.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getElasticBlockStoreServices()
.createSnapshotInRegion(regionId, device.getVolumeId());
snapshotsToDelete.add(snapshot.getId());
return snapshot;
} finally {
computeService.destroyNodesMatching(Predicates.in(nodes));
}
}
@Test(dependsOnMethods = "testCreateAndListEBSBackedImage")
public void testGetLaunchPermissionForImage() {
System.out.println(client.getLaunchPermissionForImageInRegion(regionId, ebsBackedImageId));
}
@Override
@AfterClass(groups = { "integration", "live" })
protected void tearDownContext() {
for (String imageId : imagesToDeregister)
client.deregisterImageInRegion(regionId, imageId);
for (String snapshotId : snapshotsToDelete)
view.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi().getElasticBlockStoreServices()
.deleteSnapshotInRegion(regionId, snapshotId);
super.tearDownContext();
}
}

View File

@ -79,7 +79,7 @@ public abstract class BaseEC2AsyncClientTest<T> extends BaseAsyncClientTest<T> {
} }
@Override @Override
protected String provideTimeStamp(DateService dateService, int expiration) { protected String provideTimeStamp(DateService dateService) {
return "2009-11-08T15:54:08.897Z"; return "2009-11-08T15:54:08.897Z";
} }

View File

@ -0,0 +1,71 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.ec2.services;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.domain.Volume;
import org.jclouds.ec2.internal.BaseEC2ExpectTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableMultimap;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "EC2ElasticBlockStoreClientExpectTest")
public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ExpectTest<EC2Client> {
public void testCreateVolumeInAvailabilityZone() {
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse>builder();
builder.put(describeRegionsRequest, describeRegionsResponse);
builder.putAll(describeAvailabilityZonesRequestResponse);
builder.put(
HttpRequest.builder()
.method("POST")
.endpoint(URI.create("https://ec2.us-east-1.amazonaws.com/"))
.headers(ImmutableMultimap.of("Host", "ec2.us-east-1.amazonaws.com"))
.payload(payloadFromStringWithContentType("Action=CreateVolume&AvailabilityZone=us-east-1a&Signature=FB5hTZHKSAuiygoafIdJh1EnfTu0ogC2VfRQOar85mg%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Size=4&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(),
HttpResponse.builder()
.statusCode(200)
.payload(payloadFromResource("/created_volume.xml")).build());
ElasticBlockStoreClient client = requestsSendResponses(builder.build()).getElasticBlockStoreServices();
Volume expected = Volume
.builder()
.id("vol-2a21e543")
.status(Volume.Status.CREATING)
.availabilityZone("us-east-1a")
.region("us-east-1")
.id("vol-2a21e543")
.size(1)
.createTime(dateService.iso8601DateParse("2009-12-28T05:42:53.000Z"))
.build();
assertEquals(client.createVolumeInAvailabilityZone("us-east-1a", 4), expected);
}
}

View File

@ -99,7 +99,7 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class); assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(request); checkFilters(request);
} }

View File

@ -29,6 +29,7 @@ import org.jclouds.date.DateService;
import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.InstanceState;
import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.InstanceType;
import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
@ -57,7 +58,7 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest {
assert dateService != null; assert dateService != null;
} }
public void testApplyInputStream() { public void testEC2() {
InputStream is = getClass().getResourceAsStream("/run_instances.xml"); InputStream is = getClass().getResourceAsStream("/run_instances.xml");
@ -90,6 +91,26 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest {
assertEquals(result.toString(), expected.toString()); assertEquals(result.toString(), expected.toString());
} }
public void testCloudBridge() {
InputStream is = getClass().getResourceAsStream("/run_instances_cloudbridge.xml");
Reservation<? extends RunningInstance> expected = new Reservation<RunningInstance>(defaultRegion, ImmutableSet
.of("default"), ImmutableSet.of(
new RunningInstance.Builder().region(defaultRegion).groupId("jclouds#greenqloud-computeblock").amiLaunchIndex("0")
.imageId("qmi-9ac92558").instanceId("i-01b0dac3").instanceState(InstanceState.PENDING).rawState(
"pending").instanceType(InstanceType.M1_SMALL).keyName("jclouds#greenqloud-computeblock#35")
.launchTime(dateService.iso8601DateParse("2012-06-15T19:06:35.000+00:00"))
.rootDeviceType(RootDeviceType.EBS).availabilityZone("is-1a").build())
, "56eeacd9-c790-45c3-85f3-e4380b55e1d8<", null, "r-f847a6ca");
RunInstancesResponseHandler handler = injector.getInstance(RunInstancesResponseHandler.class);
addDefaultRegionToHandler(handler);
Reservation<? extends RunningInstance> result = factory.create(handler).parse(is);
assertEquals(result.toString(), expected.toString());
}
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) { private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce(); expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();

View File

@ -82,5 +82,32 @@
<blockDeviceMapping/> <blockDeviceMapping/>
<virtualizationType>paravirtual</virtualizationType> <virtualizationType>paravirtual</virtualizationType>
</item> </item>
<item>
<imageId>ami-85457ff1</imageId>
<imageLocation>amazon/NameGivesNoClue_Server-2008-R2_SP1-Language_Packs-64Bit-Base-2012.05.10</imageLocation>
<imageState>available</imageState>
<imageOwnerId>801119661308</imageOwnerId>
<isPublic>true</isPublic>
<architecture>x86_64</architecture>
<imageType>machine</imageType>
<platform>windows</platform>
<imageOwnerAlias>amazon</imageOwnerAlias>
<name>NameGivesNoClue_Server-2008-R2_SP1-Language_Packs-64Bit-Base-2012.05.10</name>
<description>Microsoft Windows Server 2008 R2 SP1 Datacenter 64-bit Multi-language AMI provided by Amazon</description>
<rootDeviceType>ebs</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<blockDeviceMapping>
<item>
<deviceName>/dev/sda1</deviceName>
<ebs>
<snapshotId>snap-84a433ef</snapshotId>
<volumeSize>30</volumeSize>
<deleteOnTermination>true</deleteOnTermination>
</ebs>
</item>
</blockDeviceMapping>
<virtualizationType>hvm</virtualizationType>
<hypervisor>xen</hypervisor>
</item>
</imagesSet> </imagesSet>
</DescribeImagesResponse> </DescribeImagesResponse>

View File

@ -0,0 +1,17 @@
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
<requestId>24251909-7fb6-4080-8ca3-fbb5a1ddb02d</requestId>
<availabilityZoneInfo>
<item>
<zoneName>ap-northeast-1a</zoneName>
<zoneState>available</zoneState>
<regionName>ap-northeast-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>ap-northeast-1b</zoneName>
<zoneState>available</zoneState>
<regionName>ap-northeast-1</regionName>
<messageSet/>
</item>
</availabilityZoneInfo>
</DescribeAvailabilityZonesResponse>

View File

@ -0,0 +1,17 @@
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
<requestId>22c5332d-c331-4310-b695-e21e76c3fdb0</requestId>
<availabilityZoneInfo>
<item>
<zoneName>ap-southeast-1a</zoneName>
<zoneState>available</zoneState>
<regionName>ap-southeast-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>ap-southeast-1b</zoneName>
<zoneState>available</zoneState>
<regionName>ap-southeast-1</regionName>
<messageSet/>
</item>
</availabilityZoneInfo>
</DescribeAvailabilityZonesResponse>

View File

@ -0,0 +1,23 @@
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
<requestId>386c8215-6ec8-4495-aaa6-8c4175688093</requestId>
<availabilityZoneInfo>
<item>
<zoneName>eu-west-1a</zoneName>
<zoneState>available</zoneState>
<regionName>eu-west-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>eu-west-1b</zoneName>
<zoneState>available</zoneState>
<regionName>eu-west-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>eu-west-1c</zoneName>
<zoneState>available</zoneState>
<regionName>eu-west-1</regionName>
<messageSet/>
</item>
</availabilityZoneInfo>
</DescribeAvailabilityZonesResponse>

View File

@ -0,0 +1,17 @@
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
<requestId>d2e09bd5-b2ec-4c6b-aac9-6bf1fa217cb5</requestId>
<availabilityZoneInfo>
<item>
<zoneName>sa-east-1a</zoneName>
<zoneState>available</zoneState>
<regionName>sa-east-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>sa-east-1b</zoneName>
<zoneState>available</zoneState>
<regionName>sa-east-1</regionName>
<messageSet/>
</item>
</availabilityZoneInfo>
</DescribeAvailabilityZonesResponse>

View File

@ -0,0 +1,35 @@
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
<requestId>ed825abf-edbb-4677-83d5-0fbd86ce5a5d</requestId>
<availabilityZoneInfo>
<item>
<zoneName>us-east-1a</zoneName>
<zoneState>available</zoneState>
<regionName>us-east-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>us-east-1b</zoneName>
<zoneState>available</zoneState>
<regionName>us-east-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>us-east-1c</zoneName>
<zoneState>available</zoneState>
<regionName>us-east-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>us-east-1d</zoneName>
<zoneState>available</zoneState>
<regionName>us-east-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>us-east-1e</zoneName>
<zoneState>available</zoneState>
<regionName>us-east-1</regionName>
<messageSet/>
</item>
</availabilityZoneInfo>
</DescribeAvailabilityZonesResponse>

View File

@ -0,0 +1,23 @@
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
<requestId>dbfb2a5f-ce75-49fb-846b-e2cf2fc5cdbb</requestId>
<availabilityZoneInfo>
<item>
<zoneName>us-west-1a</zoneName>
<zoneState>available</zoneState>
<regionName>us-west-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>us-west-1b</zoneName>
<zoneState>available</zoneState>
<regionName>us-west-1</regionName>
<messageSet/>
</item>
<item>
<zoneName>us-west-1c</zoneName>
<zoneState>available</zoneState>
<regionName>us-west-1</regionName>
<messageSet/>
</item>
</availabilityZoneInfo>
</DescribeAvailabilityZonesResponse>

View File

@ -0,0 +1,23 @@
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
<requestId>e40c2bc4-7231-4df1-a604-202bb8333332</requestId>
<availabilityZoneInfo>
<item>
<zoneName>us-west-2a</zoneName>
<zoneState>available</zoneState>
<regionName>us-west-2</regionName>
<messageSet/>
</item>
<item>
<zoneName>us-west-2b</zoneName>
<zoneState>available</zoneState>
<regionName>us-west-2</regionName>
<messageSet/>
</item>
<item>
<zoneName>us-west-2c</zoneName>
<zoneState>available</zoneState>
<regionName>us-west-2</regionName>
<messageSet/>
</item>
</availabilityZoneInfo>
</DescribeAvailabilityZonesResponse>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<DescribeRegionsResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
<requestId>8392a998-c7bb-41fc-be15-045f528d7627</requestId>
<regionInfo>
<item>
<regionName>eu-west-1</regionName>
<regionEndpoint>ec2.eu-west-1.amazonaws.com</regionEndpoint>
</item>
<item>
<regionName>sa-east-1</regionName>
<regionEndpoint>ec2.sa-east-1.amazonaws.com</regionEndpoint>
</item>
<item>
<regionName>us-east-1</regionName>
<regionEndpoint>ec2.us-east-1.amazonaws.com</regionEndpoint>
</item>
<item>
<regionName>ap-northeast-1</regionName>
<regionEndpoint>ec2.ap-northeast-1.amazonaws.com</regionEndpoint>
</item>
<item>
<regionName>us-west-2</regionName>
<regionEndpoint>ec2.us-west-2.amazonaws.com</regionEndpoint>
</item>
<item>
<regionName>us-west-1</regionName>
<regionEndpoint>ec2.us-west-1.amazonaws.com</regionEndpoint>
</item>
<item>
<regionName>ap-southeast-1</regionName>
<regionEndpoint>ec2.ap-southeast-1.amazonaws.com</regionEndpoint>
</item>
</regionInfo>
</DescribeRegionsResponse>

View File

@ -0,0 +1,68 @@
<?xml version="1.0"?>
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/">
<requestId>56eeacd9-c790-45c3-85f3-e4380b55e1d8</requestId>
<reservationId>r-f847a6ca</reservationId>
<ownerId>55ed6530-9b32-48f1-acb7-6ec0d3255a65</ownerId>
<groupSet>
<item>
<groupId>jclouds#greenqloud-computeblock</groupId>
</item>
<item>
<groupId>jclouds#greenqloud-computeblock</groupId>
</item>
</groupSet>
<instancesSet>
<item>
<instanceId>i-01b0dac3</instanceId>
<imageId>qmi-9ac92558</imageId>
<instanceState>
<code>0</code>
<name>pending</name>
</instanceState>
<privateDnsName/>
<dnsName/>
<reason/>
<keyName>jclouds#greenqloud-computeblock#35</keyName>
<amiLaunchIndex>0</amiLaunchIndex>
<productCodes>
<item>
<productCode/>
</item>
</productCodes>
<instanceType>m1.small</instanceType>
<launchTime>2012-06-15T19:06:35.000+00:00</launchTime>
<placement>
<availabilityZone>is-1a</availabilityZone>
</placement>
<kernelId/>
<ramdiskId/>
<platform/>
<monitoring>
<state>disabled</state>
</monitoring>
<subnetId/>
<vpcId/>
<privateIpAddress/>
<groupSet>
<item>
<groupId>jclouds#greenqloud-computeblock</groupId>
</item>
<item>
<groupId>jclouds#greenqloud-computeblock</groupId>
</item>
</groupSet>
<stateReason>
<code>pending</code>
<message>pending</message>
</stateReason>
<architecture/>
<rootDeviceType>ebs</rootDeviceType>
<rootDeviceName/>
<blockDeviceMapping/>
<instanceLifecycle/>
<spotInstanceRequestId/>
<hypervisor>xen</hypervisor>
</item>
</instancesSet>
<requesterId/>
</RunInstancesResponse>

View File

@ -50,13 +50,10 @@
<properties> <properties>
<test.elasticstack.endpoint>https://api.lon-p.elastichosts.com</test.elasticstack.endpoint> <test.elasticstack.endpoint>https://api.lon-p.elastichosts.com</test.elasticstack.endpoint>
<test.elasticstack.api-version>1.0</test.elasticstack.api-version> <test.elasticstack.api-version>1.0</test.elasticstack.api-version>
<test.elasticstack.build-version /> <test.elasticstack.build-version></test.elasticstack.build-version>
<test.elasticstack.identity>FIXME</test.elasticstack.identity> <test.elasticstack.identity>FIXME</test.elasticstack.identity>
<test.elasticstack.credential>FIXME</test.elasticstack.credential> <test.elasticstack.credential>FIXME</test.elasticstack.credential>
<test.elasticstack.image-id>38df0986-4d85-4b76-b502-3878ffc80161</test.elasticstack.image-id> <test.elasticstack.template>imageId=38df0986-4d85-4b76-b502-3878ffc80161</test.elasticstack.template>
<test.elasticstack.image.login-user />
<test.elasticstack.image.authenticate-sudo />
<jclouds.osgi.export>org.jclouds.elasticstack*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.elasticstack*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}", org.jclouds.compute.internal;version="${project.version}",
@ -120,9 +117,7 @@
<test.elasticstack.build-version>${test.elasticstack.build-version}</test.elasticstack.build-version> <test.elasticstack.build-version>${test.elasticstack.build-version}</test.elasticstack.build-version>
<test.elasticstack.identity>${test.elasticstack.identity}</test.elasticstack.identity> <test.elasticstack.identity>${test.elasticstack.identity}</test.elasticstack.identity>
<test.elasticstack.credential>${test.elasticstack.credential}</test.elasticstack.credential> <test.elasticstack.credential>${test.elasticstack.credential}</test.elasticstack.credential>
<test.elasticstack.image-id>${test.elasticstack.image-id}</test.elasticstack.image-id> <test.elasticstack.template>${test.elasticstack.template}</test.elasticstack.template>
<test.elasticstack.image.login-user>${test.elasticstack.image.login-user}</test.elasticstack.image.login-user>
<test.elasticstack.image.authenticate-sudo>${test.elasticstack.image.authenticate-sudo}</test.elasticstack.image.authenticate-sudo>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -55,7 +55,6 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.HostAndPort; import com.google.common.net.HostAndPort;
@ -83,6 +82,7 @@ public class ElasticStackClientLiveTest
protected RestContext<ElasticStackClient, ElasticStackAsyncClient> cloudStackContext; protected RestContext<ElasticStackClient, ElasticStackAsyncClient> cloudStackContext;
protected Predicate<HostAndPort> socketTester; protected Predicate<HostAndPort> socketTester;
protected Predicate<DriveInfo> driveNotClaimed; protected Predicate<DriveInfo> driveNotClaimed;
protected String imageId;
@BeforeGroups(groups = { "integration", "live" }) @BeforeGroups(groups = { "integration", "live" })
@Override @Override
@ -96,7 +96,7 @@ public class ElasticStackClientLiveTest
socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), maxDriveImageTime, 1, socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), maxDriveImageTime, 1,
TimeUnit.SECONDS); TimeUnit.SECONDS);
if (Strings.emptyToNull(imageId) == null) { if (template == null || template.getImageId() == null) {
imageId = view.getComputeService().templateBuilder().build().getImage().getId(); imageId = view.getComputeService().templateBuilder().build().getImage().getId();
} }
} }

View File

@ -36,13 +36,11 @@
<properties> <properties>
<test.eucalyptus.endpoint>http://ecc.eucalyptus.com:8773/services/Eucalyptus</test.eucalyptus.endpoint> <test.eucalyptus.endpoint>http://ecc.eucalyptus.com:8773/services/Eucalyptus</test.eucalyptus.endpoint>
<test.eucalyptus.api-version>2010-06-15</test.eucalyptus.api-version> <test.eucalyptus.api-version>2010-06-15</test.eucalyptus.api-version>
<test.eucalyptus.build-version /> <test.eucalyptus.build-version></test.eucalyptus.build-version>
<test.eucalyptus.identity>FIXME_IDENTITY</test.eucalyptus.identity> <test.eucalyptus.identity>FIXME_IDENTITY</test.eucalyptus.identity>
<test.eucalyptus.credential>FIXME_CREDENTIAL</test.eucalyptus.credential> <test.eucalyptus.credential>FIXME_CREDENTIAL</test.eucalyptus.credential>
<test.eucalyptus.image-id /> <test.eucalyptus.template></test.eucalyptus.template>
<test.eucalyptus.image.login-user /> <test.eucalyptus.ebs-template></test.eucalyptus.ebs-template>
<test.eucalyptus.image.authenticate-sudo />
<jclouds.osgi.export>org.jclouds.eucalyptus*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.eucalyptus*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}", org.jclouds.compute.internal;version="${project.version}",
@ -115,9 +113,8 @@
<test.eucalyptus.build-version>${test.eucalyptus.build-version}</test.eucalyptus.build-version> <test.eucalyptus.build-version>${test.eucalyptus.build-version}</test.eucalyptus.build-version>
<test.eucalyptus.identity>${test.eucalyptus.identity}</test.eucalyptus.identity> <test.eucalyptus.identity>${test.eucalyptus.identity}</test.eucalyptus.identity>
<test.eucalyptus.credential>${test.eucalyptus.credential}</test.eucalyptus.credential> <test.eucalyptus.credential>${test.eucalyptus.credential}</test.eucalyptus.credential>
<test.eucalyptus.image-id>${test.eucalyptus.image-id}</test.eucalyptus.image-id> <test.eucalyptus.template>${test.eucalyptus.template}</test.eucalyptus.template>
<test.eucalyptus.image.login-user>${test.eucalyptus.image.login-user}</test.eucalyptus.image.login-user> <test.eucalyptus.ebs-template>${test.eucalyptus.ebs-template}</test.eucalyptus.ebs-template>
<test.eucalyptus.image.authenticate-sudo>${test.eucalyptus.image.authenticate-sudo}</test.eucalyptus.image.authenticate-sudo>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -17,9 +17,7 @@
* under the License. * under the License.
*/ */
package org.jclouds.eucalyptus; package org.jclouds.eucalyptus;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_PORT_OPEN; import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_PORT_OPEN;
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Properties; import java.util.Properties;
@ -57,8 +55,8 @@ public class EucalyptusApiMetadata extends EC2ApiMetadata {
public static Properties defaultProperties() { public static Properties defaultProperties() {
Properties properties = EC2ApiMetadata.defaultProperties(); Properties properties = EC2ApiMetadata.defaultProperties();
properties.setProperty(PROPERTY_REGIONS, "Eucalyptus"); // in version 3, lowecase 'e' version 2, uppercase 'E'
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "admin"); properties.setProperty(PROPERTY_REGIONS, "eucalyptus");
properties.setProperty(TIMEOUT_PORT_OPEN, 5 * 60 * 1000 + ""); properties.setProperty(TIMEOUT_PORT_OPEN, 5 * 60 * 1000 + "");
return properties; return properties;
} }
@ -67,7 +65,7 @@ public class EucalyptusApiMetadata extends EC2ApiMetadata {
protected Builder(){ protected Builder(){
super(EC2Client.class, EC2AsyncClient.class); super(EC2Client.class, EC2AsyncClient.class);
id("eucalyptus") id("eucalyptus")
.defaultEndpoint("http://173.205.188.130:8773/services/Eucalyptus") .defaultEndpoint("http://partnercloud.eucalyptus.com:8773/services/Eucalyptus/")
.name("Eucalyptus (EC2 clone) API") .name("Eucalyptus (EC2 clone) API")
.defaultProperties(EucalyptusApiMetadata.defaultProperties()); .defaultProperties(EucalyptusApiMetadata.defaultProperties());
} }

View File

@ -0,0 +1,106 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.eucalyptus.config;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.jclouds.eucalyptus.internal.BaseEucalyptusExpectTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.location.Region;
import org.jclouds.location.Zone;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.location.functions.ZoneToEndpoint;
import org.testng.annotations.Test;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "EucalyptusRestClientModuleExpectTest")
public class EucalyptusRestClientModuleExpectTest extends BaseEucalyptusExpectTest<Injector> {
private Injector injector;
public EucalyptusRestClientModuleExpectTest() {
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse> builder();
builder.put(describeRegionsRequest, describeRegionsResponse);
builder.put(describeAZRequest, describeAZResponse);
injector = requestsSendResponses(builder.build());
}
public void testLocationIdAndURIBindings() {
assertEquals(injector.getInstance(Key.get(new TypeLiteral<Supplier<Set<String>>>() {
}, Region.class)).get(), ImmutableSet.<String> of("eucalyptus"));
assertEquals(injector.getInstance(Key.get(new TypeLiteral<Supplier<Set<String>>>() {
}, Zone.class)).get(), ImmutableSet.<String> of("partner01"));
Map<String, Supplier<URI>> regionToURISupplier = injector.getInstance(
Key.get(new TypeLiteral<Supplier<Map<String, Supplier<URI>>>>() {
}, Region.class)).get();
assertEquals(regionToURISupplier.get("eucalyptus").get(), URI.create("http://eucalyptus.partner.eucalyptus.com:8773/services/Eucalyptus"));
Map<String, Supplier<Set<String>>> regionToZoneIdSupplier = injector.getInstance(
Key.get(new TypeLiteral<Supplier<Map<String, Supplier<Set<String>>>>>() {
}, Zone.class)).get();
assertEquals(regionToZoneIdSupplier.get("eucalyptus").get(), ImmutableSet.of("partner01"));
Map<String, Supplier<URI>> zoneToURISupplier = injector.getInstance(
Key.get(new TypeLiteral<Supplier<Map<String, Supplier<URI>>>>() {
}, Zone.class)).get();
assertEquals(zoneToURISupplier.get("partner01").get(), URI.create("http://eucalyptus.partner.eucalyptus.com:8773/services/Eucalyptus"));
}
public void testZoneToEndpoint() {
assertEquals(injector.getInstance(ZoneToEndpoint.class).apply("partner01"),
URI.create("http://eucalyptus.partner.eucalyptus.com:8773/services/Eucalyptus"));
}
public void testRegionToEndpointOrProviderIfNull() {
assertEquals(injector.getInstance(RegionToEndpointOrProviderIfNull.class).apply("eucalyptus"),
URI.create("http://eucalyptus.partner.eucalyptus.com:8773/services/Eucalyptus"));
}
@Override
public Injector createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
return createInjector(fn, module, props);
}
}

View File

@ -0,0 +1,91 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.eucalyptus.internal;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.DateService;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.config.EC2RestClientModule;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.internal.BaseRestClientExpectTest;
import com.google.common.collect.ImmutableMultimap;
import com.google.inject.Module;
import com.google.inject.Provides;
/**
*
* @author Adrian Cole
*/
public abstract class BaseEucalyptusExpectTest<T> extends BaseRestClientExpectTest<T> {
protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z";
protected DateService dateService = new SimpleDateFormatDateService();
protected HttpRequest describeRegionsRequest = HttpRequest
.builder()
.method("POST")
.endpoint(URI.create("http://partnercloud.eucalyptus.com:8773/services/Eucalyptus/"))
.headers(ImmutableMultimap.of("Host", "partnercloud.eucalyptus.com:8773"))
.payload(payloadFromStringWithContentType(
"Action=DescribeRegions&Signature=tp9WpT8503JdxIXYu6Eu2Dmu%2Bd%2FpqviST7N7Fvr%2FyQo%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
MediaType.APPLICATION_FORM_URLENCODED)).build();
protected HttpResponse describeRegionsResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType("/regionEndpoints-euca.xml", MediaType.APPLICATION_XML))
.build();
protected HttpRequest describeAZRequest = HttpRequest.builder()
.method("POST")
.endpoint(URI.create("http://eucalyptus.partner.eucalyptus.com:8773/services/Eucalyptus/"))
.headers(ImmutableMultimap.of("Host", "eucalyptus.partner.eucalyptus.com:8773"))
.payload(payloadFromStringWithContentType(
"Action=DescribeAvailabilityZones&Signature=i4OkMed1sqQV7hlF%2Fl1KdbQwmwJ4Fh4o9W32eVGayPk%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
MediaType.APPLICATION_FORM_URLENCODED)).build();
protected HttpResponse describeAZResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResourceWithContentType(
"/availabilityZones-eucalyptus.xml", MediaType.APPLICATION_XML)).build();
public BaseEucalyptusExpectTest() {
provider = "eucalyptus";
}
@ConfiguresRestClient
private static final class TestEucalyptusRestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
@Override
@Provides
protected String provideTimeStamp(DateService dateService) {
return CONSTANT_DATE;
}
}
@Override
protected Module createModule() {
return new TestEucalyptusRestClientModule();
}
}

View File

@ -0,0 +1,11 @@
<DescribeAvailabilityZonesResponse
xmlns="http://ec2.amazonaws.com/doc/2010-06-15/">
<availabilityZoneInfo>
<item>
<zoneName>partner01</zoneName>
<zoneState>173.205.188.7 arn:euca:eucalyptus:partner01:cluster:cc_01/</zoneState>
<regionName />
<messageSet />
</item>
</availabilityZoneInfo>
</DescribeAvailabilityZonesResponse>

View File

@ -0,0 +1,12 @@
<DescribeRegionsResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/">
<regionInfo>
<item>
<regionName>eucalyptus</regionName>
<regionEndpoint>http://eucalyptus.partner.eucalyptus.com:8773/services/Eucalyptus</regionEndpoint>
</item>
<item>
<regionName>walrus</regionName>
<regionEndpoint>http://walrus.partner.eucalyptus.com:8773/services/Walrus</regionEndpoint>
</item>
</regionInfo>
</DescribeRegionsResponse>

View File

@ -858,7 +858,7 @@ public class FilesystemAsyncBlobStoreTest {
// nothing expected // nothing expected
if (null == expectedBlobKeys || 0 == expectedBlobKeys.size()) { if (null == expectedBlobKeys || 0 == expectedBlobKeys.size()) {
assertTrue(blobsRetrieved.isEmpty(), "Wrong blob number retrieved in the containter [" + containerName + "]"); assertTrue(blobsRetrieved.isEmpty(), "Wrong blob number retrieved in the container [" + containerName + "]");
return; return;
} }
@ -868,7 +868,7 @@ public class FilesystemAsyncBlobStoreTest {
expectedBlobKeysCopy.add(value); expectedBlobKeysCopy.add(value);
} }
assertEquals(blobsRetrieved.size(), expectedBlobKeysCopy.size(), assertEquals(blobsRetrieved.size(), expectedBlobKeysCopy.size(),
"Wrong blob number retrieved in the containter [" + containerName + "]"); "Wrong blob number retrieved in the container [" + containerName + "]");
for (StorageMetadata data : blobsRetrieved) { for (StorageMetadata data : blobsRetrieved) {
String blobName = data.getName(); String blobName = data.getName();
if (!expectedBlobKeysCopy.remove(blobName)) { if (!expectedBlobKeysCopy.remove(blobName)) {

View File

@ -36,14 +36,12 @@
<properties> <properties>
<test.nova.endpoint>http://localhost:8773/services/Cloud</test.nova.endpoint> <test.nova.endpoint>http://localhost:8773/services/Cloud</test.nova.endpoint>
<test.nova.api-version>1.1</test.nova.api-version> <test.nova.api-version>1.1</test.nova.api-version>
<test.nova.build-version /> <test.nova.build-version></test.nova.build-version>
<test.nova.identity>FIXME_IDENTITY</test.nova.identity> <test.nova.identity>FIXME_IDENTITY</test.nova.identity>
<test.nova.credential>FIXME_CREDENTIALS</test.nova.credential> <test.nova.credential>FIXME_CREDENTIALS</test.nova.credential>
<test.nova.image-id /> <test.nova.template></test.nova.template>
<test.nova.image.login-user /> <test.ssh.keyfile.public></test.ssh.keyfile.public>
<test.nova.image.authenticate-sudo /> <test.ssh.keyfile.private></test.ssh.keyfile.private>
<test.ssh.keyfile.public />
<test.ssh.keyfile.private />
<jclouds.osgi.export>org.jclouds.openstack.nova*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.openstack.nova*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
@ -122,9 +120,7 @@
<test.nova.build-version>${test.nova.build-version}</test.nova.build-version> <test.nova.build-version>${test.nova.build-version}</test.nova.build-version>
<test.nova.identity>${test.nova.identity}</test.nova.identity> <test.nova.identity>${test.nova.identity}</test.nova.identity>
<test.nova.credential>${test.nova.credential}</test.nova.credential> <test.nova.credential>${test.nova.credential}</test.nova.credential>
<test.nova.image-id>${test.nova.image-id}</test.nova.image-id> <test.nova.template>${test.nova.template}</test.nova.template>
<test.nova.image.login-user>${test.nova.image.login-user}</test.nova.image.login-user>
<test.nova.image.authenticate-sudo>${test.nova.image.authenticate-sudo}</test.nova.image.authenticate-sudo>
<test.ssh.keyfile.public>${test.ssh.keyfile.public}</test.ssh.keyfile.public> <test.ssh.keyfile.public>${test.ssh.keyfile.public}</test.ssh.keyfile.public>
<test.ssh.keyfile.private>${test.ssh.keyfile.private}</test.ssh.keyfile.private> <test.ssh.keyfile.private>${test.ssh.keyfile.private}</test.ssh.keyfile.private>
</systemPropertyVariables> </systemPropertyVariables>

View File

@ -214,7 +214,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
while (server == null) { while (server == null) {
String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt(); String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt();
try { try {
server = client.createServer(serverName, imageId, flavorId, withFile("/etc/jclouds.txt", server = client.createServer(serverName, template.getImageId(), flavorId, withFile("/etc/jclouds.txt",
"nova".getBytes()).withMetadata(metadata)); "nova".getBytes()).withMetadata(metadata));
} catch (UndeclaredThrowableException e) { } catch (UndeclaredThrowableException e) {
HttpResponseException htpe = (HttpResponseException) e.getCause().getCause(); HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();

View File

@ -43,9 +43,7 @@
<test.openstack-keystone.credential>FIXME_CREDENTIALS</test.openstack-keystone.credential> <test.openstack-keystone.credential>FIXME_CREDENTIALS</test.openstack-keystone.credential>
<test.jclouds.keystone.credential-type>passwordCredentials</test.jclouds.keystone.credential-type> <test.jclouds.keystone.credential-type>passwordCredentials</test.jclouds.keystone.credential-type>
<jclouds.osgi.export>org.jclouds.openstack.v2_0*;version="${project.version}", <jclouds.osgi.export>org.jclouds.openstack*;version="${project.version}"</jclouds.osgi.export>
org.jclouds.openstack.keystone.v2_0*;version="${project.version}"
</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.rest.internal;version="${project.version}", org.jclouds.rest.internal;version="${project.version}",
org.jclouds*;version="${project.version}", org.jclouds*;version="${project.version}",

View File

@ -36,13 +36,11 @@
<properties> <properties>
<test.openstack-nova-ec2.endpoint>http://localhost:8773/services/Cloud</test.openstack-nova-ec2.endpoint> <test.openstack-nova-ec2.endpoint>http://localhost:8773/services/Cloud</test.openstack-nova-ec2.endpoint>
<test.openstack-nova-ec2.api-version>2010-06-15</test.openstack-nova-ec2.api-version> <test.openstack-nova-ec2.api-version>2010-06-15</test.openstack-nova-ec2.api-version>
<test.openstack-nova-ec2.build-version /> <test.openstack-nova-ec2.build-version></test.openstack-nova-ec2.build-version>
<test.openstack-nova-ec2.identity>FIXME_IDENTITY</test.openstack-nova-ec2.identity> <test.openstack-nova-ec2.identity>FIXME_IDENTITY</test.openstack-nova-ec2.identity>
<test.openstack-nova-ec2.credential>FIXME_CREDENTIAL</test.openstack-nova-ec2.credential> <test.openstack-nova-ec2.credential>FIXME_CREDENTIAL</test.openstack-nova-ec2.credential>
<test.openstack-nova-ec2.image-id /> <test.openstack-nova-ec2.template></test.openstack-nova-ec2.template>
<test.openstack-nova-ec2.image.login-user /> <test.openstack-nova-ec2.ebs-template></test.openstack-nova-ec2.ebs-template>
<test.openstack-nova-ec2.image.authenticate-sudo />
<jclouds.osgi.export>org.jclouds.openstack.nova.ec2*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.openstack.nova.ec2*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}", org.jclouds.compute.internal;version="${project.version}",
@ -120,9 +118,8 @@
<test.openstack-nova-ec2.build-version>${test.openstack-nova-ec2.build-version}</test.openstack-nova-ec2.build-version> <test.openstack-nova-ec2.build-version>${test.openstack-nova-ec2.build-version}</test.openstack-nova-ec2.build-version>
<test.openstack-nova-ec2.identity>${test.openstack-nova-ec2.identity}</test.openstack-nova-ec2.identity> <test.openstack-nova-ec2.identity>${test.openstack-nova-ec2.identity}</test.openstack-nova-ec2.identity>
<test.openstack-nova-ec2.credential>${test.openstack-nova-ec2.credential}</test.openstack-nova-ec2.credential> <test.openstack-nova-ec2.credential>${test.openstack-nova-ec2.credential}</test.openstack-nova-ec2.credential>
<test.openstack-nova-ec2.image-id>${test.openstack-nova-ec2.image-id}</test.openstack-nova-ec2.image-id> <test.openstack-nova-ec2.template>${test.openstack-nova-ec2.template}</test.openstack-nova-ec2.template>
<test.openstack-nova-ec2.image.login-user>${test.openstack-nova-ec2.image.login-user}</test.openstack-nova-ec2.image.login-user> <test.openstack-nova-ec2.ebs-template>${test.openstack-nova-ec2.ebs-template}</test.openstack-nova-ec2.ebs-template>
<test.openstack-nova-ec2.image.authenticate-sudo>${test.openstack-nova-ec2.image.authenticate-sudo}</test.openstack-nova-ec2.image.authenticate-sudo>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -2,10 +2,8 @@ package org.jclouds.openstack.nova.ec2.internal;
import java.net.URI; import java.net.URI;
import javax.inject.Named;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.Constants;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
@ -45,8 +43,7 @@ public abstract class BaseNovaEC2RestClientExpectTest extends BaseRestClientExpe
private static final class TestNovaEC2RestClientModule extends NovaEC2RestClientModule { private static final class TestNovaEC2RestClientModule extends NovaEC2RestClientModule {
@Override @Override
@Provides @Provides
protected String provideTimeStamp(final DateService dateService, protected String provideTimeStamp(DateService dateService) {
@Named(Constants.PROPERTY_SESSION_INTERVAL) final int expiration) {
return CONSTANT_DATE; return CONSTANT_DATE;
} }
} }

View File

@ -38,12 +38,10 @@
<test.openstack-nova.endpoint>http://localhost:5000</test.openstack-nova.endpoint> <test.openstack-nova.endpoint>http://localhost:5000</test.openstack-nova.endpoint>
<!-- keystone version --> <!-- keystone version -->
<test.openstack-nova.api-version>1.1</test.openstack-nova.api-version> <test.openstack-nova.api-version>1.1</test.openstack-nova.api-version>
<test.openstack-nova.build-version /> <test.openstack-nova.build-version></test.openstack-nova.build-version>
<test.openstack-nova.identity>FIXME_IDENTITY</test.openstack-nova.identity> <test.openstack-nova.identity>FIXME_IDENTITY</test.openstack-nova.identity>
<test.openstack-nova.credential>FIXME_CREDENTIALS</test.openstack-nova.credential> <test.openstack-nova.credential>FIXME_CREDENTIALS</test.openstack-nova.credential>
<test.openstack-nova.image-id /> <test.openstack-nova.template></test.openstack-nova.template>
<test.openstack-nova.image.login-user />
<test.openstack-nova.image.authenticate-sudo />
<test.jclouds.openstack-nova.auto-allocate-floating-ips>false</test.jclouds.openstack-nova.auto-allocate-floating-ips> <test.jclouds.openstack-nova.auto-allocate-floating-ips>false</test.jclouds.openstack-nova.auto-allocate-floating-ips>
<test.jclouds.keystone.credential-type>passwordCredentials</test.jclouds.keystone.credential-type> <test.jclouds.keystone.credential-type>passwordCredentials</test.jclouds.keystone.credential-type>
@ -130,9 +128,7 @@
<test.openstack-nova.build-version>${test.openstack-nova.build-version}</test.openstack-nova.build-version> <test.openstack-nova.build-version>${test.openstack-nova.build-version}</test.openstack-nova.build-version>
<test.openstack-nova.identity>${test.openstack-nova.identity}</test.openstack-nova.identity> <test.openstack-nova.identity>${test.openstack-nova.identity}</test.openstack-nova.identity>
<test.openstack-nova.credential>${test.openstack-nova.credential}</test.openstack-nova.credential> <test.openstack-nova.credential>${test.openstack-nova.credential}</test.openstack-nova.credential>
<test.openstack-nova.image-id>${test.openstack-nova.image-id}</test.openstack-nova.image-id> <test.openstack-nova.template>${test.openstack-nova.template}</test.openstack-nova.template>
<test.openstack-nova.image.login-user>${test.openstack-nova.image.login-user}</test.openstack-nova.image.login-user>
<test.openstack-nova.image.authenticate-sudo>${test.openstack-nova.image.authenticate-sudo}</test.openstack-nova.image.authenticate-sudo>
<test.jclouds.openstack-nova.auto-allocate-floating-ips>${test.jclouds.openstack-nova.auto-allocate-floating-ips}</test.jclouds.openstack-nova.auto-allocate-floating-ips> <test.jclouds.openstack-nova.auto-allocate-floating-ips>${test.jclouds.openstack-nova.auto-allocate-floating-ips}</test.jclouds.openstack-nova.auto-allocate-floating-ips>
<test.jclouds.keystone.credential-type>${test.jclouds.keystone.credential-type}</test.jclouds.keystone.credential-type> <test.jclouds.keystone.credential-type>${test.jclouds.keystone.credential-type}</test.jclouds.keystone.credential-type>
</systemPropertyVariables> </systemPropertyVariables>

View File

@ -165,7 +165,7 @@ public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMe
} }
}); });
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
logger.debug("could not find %s with id(%s) for server(%s)", type, objectId, serverInZone); logger.trace("could not find %s with id(%s) for server(%s)", type, objectId, serverInZone);
} }
return null; return null;
} }

View File

@ -103,9 +103,16 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
@Override @Override
public ToStringHelper string() { public ToStringHelper string() {
return super.string().add("autoAssignFloatingIp", autoAssignFloatingIp) ToStringHelper toString = super.string();
.add("securityGroupNames", securityGroupNames).add("generateKeyPair", generateKeyPair) if (!autoAssignFloatingIp)
.add("keyPairName", keyPairName).add("userData", userData); toString.add("autoAssignFloatingIp", autoAssignFloatingIp);
if (securityGroupNames.size() != 0)
toString.add("securityGroupNames", securityGroupNames);
if (generateKeyPair)
toString.add("generateKeyPair", generateKeyPair);
toString.add("keyPairName", keyPairName);
toString.add("userData", userData);
return toString;
} }
public static final NovaTemplateOptions NONE = new NovaTemplateOptions(); public static final NovaTemplateOptions NONE = new NovaTemplateOptions();

View File

@ -32,14 +32,12 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.compute.config.CustomizationResponse; import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.functions.GroupNamingConvention; import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName; import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap; import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
@ -71,7 +69,6 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
private final LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache; private final LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache;
private final LoadingCache<ZoneAndName, KeyPair> keyPairCache; private final LoadingCache<ZoneAndName, KeyPair> keyPairCache;
private final NovaClient novaClient; private final NovaClient novaClient;
private final Provider<TemplateBuilder> templateBuilderProvider;
@Inject @Inject
protected ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet( protected ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet(
@ -80,13 +77,11 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
GroupNamingConvention.Factory namingConvention, GroupNamingConvention.Factory namingConvention,
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
Provider<TemplateBuilder> templateBuilderProvider,
AllocateAndAddFloatingIpToNode allocateAndAddFloatingIpToNode, AllocateAndAddFloatingIpToNode allocateAndAddFloatingIpToNode,
LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache, LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupCache,
LoadingCache<ZoneAndName, KeyPair> keyPairCache, NovaClient novaClient) { LoadingCache<ZoneAndName, KeyPair> keyPairCache, NovaClient novaClient) {
super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor, super(addNodeWithTagStrategy, listNodesStrategy, namingConvention, executor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory); customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider");
this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache"); this.securityGroupCache = checkNotNull(securityGroupCache, "securityGroupCache");
this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache"); this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");
this.allocateAndAddFloatingIpToNode = checkNotNull(allocateAndAddFloatingIpToNode, this.allocateAndAddFloatingIpToNode = checkNotNull(allocateAndAddFloatingIpToNode,
@ -98,16 +93,7 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
public Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, public Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Template mutableTemplate; Template mutableTemplate = template.clone();
// ensure we don't mutate the input template, fromTemplate ignores imageId so
// build directly from imageId if we have it
if (template.getImage() != null && template.getImage().getId() != null) {
mutableTemplate = templateBuilderProvider.get().imageId(template.getImage().getId()).fromTemplate(template)
.build();
// otherwise build from generic parameters
} else {
mutableTemplate = templateBuilderProvider.get().fromTemplate(template).build();
}
NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(mutableTemplate.getOptions()); NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(mutableTemplate.getOptions());

View File

@ -26,8 +26,8 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
@ -40,8 +40,8 @@ import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.util.Preconditions2; import org.jclouds.util.Preconditions2;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -133,10 +133,18 @@ public class CreateServerOptions implements MapBinder {
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return toStringHelper("").add("keyName", keyName).add("securityGroupNames", securityGroupNames) ToStringHelper toString = Objects.toStringHelper("").omitNullValues();
.add("metadata", metadata).add("personality", personality) toString.add("keyName", keyName);
.add("adminPassPresent", adminPass != null) if (securityGroupNames.size() > 0)
.add("userData", userData == null ? null : new String(userData)); toString.add("securityGroupNames", securityGroupNames);
if (metadata.size() > 0)
toString.add("metadata", metadata);
if (personality.size() > 0)
toString.add("personality", personality);
if (adminPass != null)
toString.add("adminPassPresent", true);
toString.add("userData", userData == null ? null : new String(userData));
return toString;
} }
@Override @Override

View File

@ -204,7 +204,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra
String eTag = client.putObjectManifest(container, key); String eTag = client.putObjectManifest(container, key);
logger.debug(String.format("multipart upload of %s to container %s" + logger.debug(String.format("multipart upload of %s to container %s" +
" succeffully finished with %s retries", key, container, errors.get())); " successfully finished with %s retries", key, container, errors.get()));
return eTag; return eTag;
} catch (Exception ex) { } catch (Exception ex) {
RuntimeException rtex = Throwables2.getFirstThrowableOfType(ex, RuntimeException.class); RuntimeException rtex = Throwables2.getFirstThrowableOfType(ex, RuntimeException.class);

View File

@ -36,13 +36,10 @@
<properties> <properties>
<test.vcloud.endpoint>FIXME</test.vcloud.endpoint> <test.vcloud.endpoint>FIXME</test.vcloud.endpoint>
<test.vcloud.api-version>1.0</test.vcloud.api-version> <test.vcloud.api-version>1.0</test.vcloud.api-version>
<test.vcloud.build-version /> <test.vcloud.build-version></test.vcloud.build-version>
<test.vcloud.identity>FIXME</test.vcloud.identity> <test.vcloud.identity>FIXME</test.vcloud.identity>
<test.vcloud.credential>FIXME</test.vcloud.credential> <test.vcloud.credential>FIXME</test.vcloud.credential>
<test.vcloud.image-id /> <test.vcloud.template></test.vcloud.template>
<test.vcloud.image.login-user />
<test.vcloud.image.authenticate-sudo />
<jclouds.osgi.export>org.jclouds.vcloud*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.vcloud*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}", org.jclouds.compute.internal;version="${project.version}",
@ -118,9 +115,7 @@
<test.vcloud.build-version>${test.vcloud.build-version}</test.vcloud.build-version> <test.vcloud.build-version>${test.vcloud.build-version}</test.vcloud.build-version>
<test.vcloud.identity>${test.vcloud.identity}</test.vcloud.identity> <test.vcloud.identity>${test.vcloud.identity}</test.vcloud.identity>
<test.vcloud.credential>${test.vcloud.credential}</test.vcloud.credential> <test.vcloud.credential>${test.vcloud.credential}</test.vcloud.credential>
<test.vcloud.image-id>${test.vcloud.image-id}</test.vcloud.image-id> <test.vcloud.template>${test.vcloud.template}</test.vcloud.template>
<test.vcloud.image.login-user>${test.vcloud.image.login-user}</test.vcloud.image.login-user>
<test.vcloud.image.authenticate-sudo>${test.vcloud.image.authenticate-sudo}</test.vcloud.image.authenticate-sudo>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -139,7 +139,7 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
public void testListRootUsesDelimiter() throws InterruptedException { public void testListRootUsesDelimiter() throws InterruptedException {
String containerName = getContainerName(); String containerName = getContainerName();
try { try {
String prefix = "rootdelimeter"; String prefix = "rootdelimiter";
addTenObjectsUnderPrefix(containerName, prefix); addTenObjectsUnderPrefix(containerName, prefix);
add15UnderRoot(containerName); add15UnderRoot(containerName);
PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName);

View File

@ -21,10 +21,8 @@ package org.jclouds.aws.config;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
@ -59,9 +57,8 @@ public abstract class FormSigningRestClientModule<S, A> extends AWSRestClientMod
@Provides @Provides
@TimeStamp @TimeStamp
protected String provideTimeStamp(final DateService dateService, protected String provideTimeStamp(DateService dateService) {
@Named(Constants.PROPERTY_SESSION_INTERVAL) final int expiration) { return dateService.iso8601DateFormat(new Date(System.currentTimeMillis()));
return dateService.iso8601DateFormat(new Date(System.currentTimeMillis() + (expiration * 1000)));
} }
@Provides @Provides

View File

@ -112,7 +112,7 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
".InUse"))) ".InUse")))
|| (message != null && (message.indexOf("already exists") != -1 || message.indexOf("is in use") != -1))) || (message != null && (message.indexOf("already exists") != -1 || message.indexOf("is in use") != -1)))
exception = new IllegalStateException(message, exception); exception = new IllegalStateException(message, exception);
else if ("AuthFailure".equals(errorCode)) else if (errorCode != null && errorCode.indexOf("AuthFailure") != -1)
exception = new AuthorizationException(message, exception); exception = new AuthorizationException(message, exception);
else if (message != null else if (message != null
&& (message.indexOf("Invalid id") != -1 || message.indexOf("Failed to bind") != -1)) && (message.indexOf("Invalid id") != -1 || message.indexOf("Failed to bind") != -1))

View File

@ -56,7 +56,13 @@ public class ParseAWSErrorFromXmlContentTest {
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "", assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
"<Error><Code>Monster.NotFound</Code></Error>", ResourceNotFoundException.class); "<Error><Code>Monster.NotFound</Code></Error>", ResourceNotFoundException.class);
} }
@Test
public void test400WithCloudBridgeNotFoundSetsResourceNotFoundException() {
assertCodeMakes("POST", URI.create("https://api.greenqloud.com/"), 400, "",
"<Error><Code>Client.InvalidInstanceID.NotFound</Code></Error>", ResourceNotFoundException.class);
}
@Test @Test
public void test400WithInvalidIdIllegalArgumentException() { public void test400WithInvalidIdIllegalArgumentException() {
assertCodeMakes("POST", URI.create("https://ec2.us-east-1.amazonaws.com"), 400, "HTTP/1.1 400", "", assertCodeMakes("POST", URI.create("https://ec2.us-east-1.amazonaws.com"), 400, "HTTP/1.1 400", "",
@ -164,6 +170,12 @@ public class ParseAWSErrorFromXmlContentTest {
"<Error><Code>AuthFailure</Code></Error>", AuthorizationException.class); "<Error><Code>AuthFailure</Code></Error>", AuthorizationException.class);
} }
@Test
public void test400WithCloudBridgeAuthFailureSetsAuthorizationException() {
assertCodeMakes("POST", URI.create("https://api.greenqloud.com/"), 400, "",
"<Error><Code>Client.AuthFailure</Code></Error>", AuthorizationException.class);
}
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
Class<? extends Exception> expected) { Class<? extends Exception> expected) {
assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected); assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);

View File

@ -35,18 +35,7 @@
<packaging>bundle</packaging> <packaging>bundle</packaging>
<properties> <properties>
<jclouds.osgi.export>org.jclouds.openstack.config*;version="${project.version}", <jclouds.osgi.export>org.jclouds.openstack*;version="${project.version}";-noimport:=true</jclouds.osgi.export>
org.jclouds.openstack.domain*;version="${project.version}"
org.jclouds.openstack.filters*;version="${project.version}"
org.jclouds.openstack.functions*;version="${project.version}"
org.jclouds.openstack.handlers*;version="${project.version}"
org.jclouds.openstack.internal*;version="${project.version}"
org.jclouds.openstack.keystone.v1_1*;version="${project.version}"
org.jclouds.openstack.options*;version="${project.version}"
org.jclouds.openstack.predicates*;version="${project.version}"
org.jclouds.openstack.reference*;version="${project.version}"
org.jclouds.openstack.services*;version="${project.version}"
</jclouds.osgi.export>
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import> <jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
</properties> </properties>

View File

@ -119,7 +119,7 @@ public class RunScriptOnNodeAsInitScriptUsingSsh extends SudoAwareInitManager im
ssh.connect(); ssh.connect();
ssh.exec("rm " + initFile); ssh.exec("rm " + initFile);
ssh.exec(Statements.appendFile(initFile, Splitter.on('\n').split(init.render(OsFamily.UNIX)), ssh.exec(Statements.appendFile(initFile, Splitter.on('\n').split(init.render(OsFamily.UNIX)),
AppendFile.DELIMETER + "_" + init.getInstanceName()).render(OsFamily.UNIX)); AppendFile.DELIMITER + "_" + init.getInstanceName()).render(OsFamily.UNIX));
} }
ssh.exec("chmod 755 " + initFile); ssh.exec("chmod 755 " + initFile);

View File

@ -90,7 +90,7 @@ public class SudoAwareInitManager {
String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action)) ? execScriptAsRoot(action) String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action)) ? execScriptAsRoot(action)
: execScriptAsDefaultUser(action); : execScriptAsDefaultUser(action);
returnVal = runCommand(command); returnVal = runCommand(command);
if ("status".equals(action)) if (ImmutableSet.of("status", "stdout", "stderr").contains(action))
logger.trace("<< %s(%d)", action, returnVal.getExitStatus()); logger.trace("<< %s(%d)", action, returnVal.getExitStatus());
else if (computeLogger.isTraceEnabled()) else if (computeLogger.isTraceEnabled())
computeLogger.trace("<< %s[%s]", action, returnVal); computeLogger.trace("<< %s[%s]", action, returnVal);
@ -103,8 +103,8 @@ public class SudoAwareInitManager {
String statement = String.format("[%s] as %s@%s", command.replace( String statement = String.format("[%s] as %s@%s", command.replace(
node.getCredentials().getPassword() != null ? node.getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh node.getCredentials().getPassword() != null ? node.getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh
.getUsername(), ssh.getHostAddress()); .getUsername(), ssh.getHostAddress());
if (command.endsWith("status")) if (command.endsWith("status") || command.endsWith("stdout") || command.endsWith("stderr"))
logger.trace(">> running " + statement); logger.trace(">> running %s", statement);
else else
computeLogger.debug(">> running " + statement); computeLogger.debug(">> running " + statement);
ExecResponse returnVal = ssh.exec(command); ExecResponse returnVal = ssh.exec(command);

View File

@ -47,4 +47,11 @@ public interface Template extends Cloneable {
* options for launching this template, like run scripts or inbound ports * options for launching this template, like run scripts or inbound ports
*/ */
TemplateOptions getOptions(); TemplateOptions getOptions();
/**
* clone this template
*
* @see Object#clone
*/
Template clone();
} }

View File

@ -152,7 +152,7 @@ public class TemplateBuilderSpec implements Serializable {
.put("authenticateSudo", new AuthenticateSudoParser()) .put("authenticateSudo", new AuthenticateSudoParser())
.put("locationId", new LocationIdParser()) .put("locationId", new LocationIdParser())
.build(); .build();
@VisibleForTesting @VisibleForTesting
String hardwareId; String hardwareId;
@VisibleForTesting @VisibleForTesting
@ -553,4 +553,63 @@ public class TemplateBuilderSpec implements Serializable {
} }
} }
public String getHardwareId() {
return hardwareId;
}
public Double getMinCores() {
return minCores;
}
public Integer getMinRam() {
return minRam;
}
public String getHypervisorMatches() {
return hypervisorMatches;
}
public String getImageId() {
return imageId;
}
public String getImageNameMatches() {
return imageNameMatches;
}
public OsFamily getOsFamily() {
return osFamily;
}
public String getOsVersionMatches() {
return osVersionMatches;
}
public Boolean getOs64Bit() {
return os64Bit;
}
public String getOsArchMatches() {
return osArchMatches;
}
public String getOsDescriptionMatches() {
return osDescriptionMatches;
}
public String getLoginUser() {
return loginUser;
}
public Boolean getAuthenticateSudo() {
return authenticateSudo;
}
public String getLocationId() {
return locationId;
}
public String getSpecification() {
return specification;
}
} }

View File

@ -24,6 +24,7 @@ import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.size; import static com.google.common.collect.Iterables.size;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;
import static java.lang.String.format; import static java.lang.String.format;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
@ -57,6 +58,8 @@ import org.jclouds.util.Lists2;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -403,27 +406,23 @@ public class TemplateBuilderImpl implements TemplateBuilder {
private Predicate<Hardware> buildHardwarePredicate() { private Predicate<Hardware> buildHardwarePredicate() {
List<Predicate<Hardware>> predicates = newArrayList(); List<Predicate<Hardware>> predicates = newArrayList();
if (hardwareId != null) { if (location != null)
predicates.add(hardwareIdPredicate); predicates.add(new Predicate<Hardware>() {
} else {
if (location != null)
predicates.add(new Predicate<Hardware>() {
@Override @Override
public boolean apply(Hardware input) { public boolean apply(Hardware input) {
return locationPredicate.apply(input); return locationPredicate.apply(input);
} }
@Override @Override
public String toString() { public String toString() {
return locationPredicate.toString(); return locationPredicate.toString();
} }
}); });
if (hypervisor != null) if (hypervisor != null)
predicates.add(hypervisorPredicate); predicates.add(hypervisorPredicate);
predicates.add(hardwareCoresPredicate); predicates.add(hardwareCoresPredicate);
predicates.add(hardwareRamPredicate); predicates.add(hardwareRamPredicate);
}
// looks verbose, but explicit <Hardware> type needed for this to compile // looks verbose, but explicit <Hardware> type needed for this to compile
// properly // properly
@ -612,35 +611,87 @@ public class TemplateBuilderImpl implements TemplateBuilder {
options = optionsProvider.get(); options = optionsProvider.get();
logger.debug(">> searching params(%s)", this); logger.debug(">> searching params(%s)", this);
Set<? extends Image> images = getImages(); Set<? extends Image> images = getImages();
Set<? extends Hardware> hardwaresToSearch = hardwares.get();
Image image = null;
if (imageId != null) {
image = findImageWithId(images);
if (currentLocationWiderThan(image.getLocation()))
this.location = image.getLocation();
}
Hardware hardware = null;
if (hardwareId != null) {
hardware = findHardwareWithId(hardwaresToSearch);
if (currentLocationWiderThan(hardware.getLocation()))
this.location = hardware.getLocation();
}
// if the user hasn't specified a location id, or an image or hardware
// with location, let's search scoped to the implicit one
if (location == null) if (location == null)
location = defaultLocation.get(); location = defaultLocation.get();
Predicate<Image> imagePredicate = buildImagePredicate(); if (image == null) {
Iterable<? extends Image> supportedImages = filter(images, imagePredicate); Iterable<? extends Image> supportedImages = findSupportedImages(images);
if (size(supportedImages) == 0) { if (hardware == null)
if (imagePredicate == idPredicate) { hardware = resolveHardware(hardwaresToSearch, supportedImages);
throwNoSuchElementExceptionAfterLoggingImageIds(format("%s not found", idPredicate), images); image = resolveImage(hardware, supportedImages);
} else { } else {
throwNoSuchElementExceptionAfterLoggingImageIds(format("no image matched predicate: %s", imagePredicate), if (hardware == null)
images); hardware = resolveHardware(hardwaresToSearch, ImmutableSet.of(image));
}
} }
Hardware hardware = resolveHardware(hardwareSorter(), supportedImages); logger.debug("<< matched image(%s) hardware(%s) location(%s)", image.getId(), hardware.getId(),
Image image = resolveImage(hardware, supportedImages); location.getId());
logger.debug("<< matched image(%s)", image.getId());
return new TemplateImpl(image, hardware, location, options); return new TemplateImpl(image, hardware, location, options);
} }
protected void throwNoSuchElementExceptionAfterLoggingImageIds(String message, Iterable<? extends Image> images) { private Iterable<? extends Image> findSupportedImages(Set<? extends Image> images) {
Predicate<Image> imagePredicate = buildImagePredicate();
Iterable<? extends Image> supportedImages = filter(images, imagePredicate);
if (size(supportedImages) == 0) {
throw throwNoSuchElementExceptionAfterLoggingImageIds(
format("no image matched predicate: %s", imagePredicate), images);
}
return supportedImages;
}
private Image findImageWithId(Set<? extends Image> images) {
Image image;
// TODO: switch to GetImageStrategy in version 1.5
image = tryFind(images, idPredicate).orNull();
if (image == null)
throwNoSuchElementExceptionAfterLoggingImageIds(format("%s not found", idPredicate), images);
return image;
}
private Hardware findHardwareWithId(Set<? extends Hardware> hardwaresToSearch) {
Hardware hardware;
// TODO: switch to GetHardwareStrategy in version 1.5
hardware = tryFind(hardwaresToSearch, hardwareIdPredicate).orNull();
if (hardware == null)
throw throwNoSuchElementExceptionAfterLoggingHardwareIds(format("%s not found", hardwareIdPredicate),
hardwaresToSearch);
return hardware;
}
protected NoSuchElementException throwNoSuchElementExceptionAfterLoggingImageIds(String message, Iterable<? extends Image> images) {
NoSuchElementException exception = new NoSuchElementException(message); NoSuchElementException exception = new NoSuchElementException(message);
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
logger.warn(exception, "image ids that didn't match: %s", transform(images, imageToId)); logger.warn(exception, "image ids that didn't match: %s", transform(images, imageToId));
throw exception; throw exception;
} }
protected Hardware resolveHardware(Ordering<Hardware> hardwareOrdering, final Iterable<? extends Image> images) { protected NoSuchElementException throwNoSuchElementExceptionAfterLoggingHardwareIds(String message, Iterable<? extends Hardware> hardwares) {
Set<? extends Hardware> hardwarel = hardwares.get(); NoSuchElementException exception = new NoSuchElementException(message);
if (logger.isTraceEnabled())
logger.warn(exception, "hardware ids that didn't match: %s", transform(hardwares, hardwareToId));
throw exception;
}
protected Hardware resolveHardware(Set<? extends Hardware> hardwarel, final Iterable<? extends Image> images) {
Ordering<Hardware> hardwareOrdering = hardwareSorter();
Iterable<? extends Hardware> hardwaresThatAreCompatibleWithOurImages = ImmutableSet.of(); Iterable<? extends Hardware> hardwaresThatAreCompatibleWithOurImages = ImmutableSet.of();
try { try {
hardwaresThatAreCompatibleWithOurImages = filter(hardwarel, new Predicate<Hardware>() { hardwaresThatAreCompatibleWithOurImages = filter(hardwarel, new Predicate<Hardware>() {
@ -667,11 +718,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
} }
if (size(hardwaresThatAreCompatibleWithOurImages) == 0) { if (size(hardwaresThatAreCompatibleWithOurImages) == 0) {
String message = format("no hardware profiles support images matching params: %s", toString()); String message = format("no hardware profiles support images matching params: %s", toString());
NoSuchElementException exception = new NoSuchElementException(message); throw throwNoSuchElementExceptionAfterLoggingHardwareIds(message, hardwaresThatAreCompatibleWithOurImages);
if (logger.isTraceEnabled())
logger.warn(exception, "hardware profiles %s\nimage ids %s", transform(hardwarel, hardwareToId), transform(
images, imageToId));
throw exception;
} }
Predicate<Hardware> hardwarePredicate = buildHardwarePredicate(); Predicate<Hardware> hardwarePredicate = buildHardwarePredicate();
Hardware hardware; Hardware hardware;
@ -679,13 +726,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
hardware = hardwareOrdering.max(filter(hardwaresThatAreCompatibleWithOurImages, hardwarePredicate)); hardware = hardwareOrdering.max(filter(hardwaresThatAreCompatibleWithOurImages, hardwarePredicate));
} catch (NoSuchElementException exception) { } catch (NoSuchElementException exception) {
String message = format("no hardware profiles match params: %s", hardwarePredicate); String message = format("no hardware profiles match params: %s", hardwarePredicate);
exception = new NoSuchElementException(message); throw throwNoSuchElementExceptionAfterLoggingHardwareIds(message, hardwaresThatAreCompatibleWithOurImages);
if (logger.isTraceEnabled())
logger.warn(exception, "hardware profiles %s", transform(hardwaresThatAreCompatibleWithOurImages,
hardwareToId));
throw exception;
} }
logger.debug("<< matched hardware(%s)", hardware.getId()); logger.trace("<< matched hardware(%s)", hardware.getId());
return hardware; return hardware;
} }
@ -741,59 +784,55 @@ public class TemplateBuilderImpl implements TemplateBuilder {
private Predicate<Image> buildImagePredicate() { private Predicate<Image> buildImagePredicate() {
List<Predicate<Image>> predicates = newArrayList(); List<Predicate<Image>> predicates = newArrayList();
if (imageId != null) { if (location != null)
predicates.add(idPredicate); predicates.add(new Predicate<Image>() {
} else {
if (location != null)
predicates.add(new Predicate<Image>() {
@Override @Override
public boolean apply(Image input) { public boolean apply(Image input) {
return locationPredicate.apply(input); return locationPredicate.apply(input);
} }
@Override @Override
public String toString() { public String toString() {
return locationPredicate.toString(); return locationPredicate.toString();
} }
}); });
final List<Predicate<OperatingSystem>> osPredicates = newArrayList(); final List<Predicate<OperatingSystem>> osPredicates = newArrayList();
if (osFamily != null) if (osFamily != null)
osPredicates.add(osFamilyPredicate); osPredicates.add(osFamilyPredicate);
if (osName != null) if (osName != null)
osPredicates.add(osNamePredicate); osPredicates.add(osNamePredicate);
if (osDescription != null) if (osDescription != null)
osPredicates.add(osDescriptionPredicate); osPredicates.add(osDescriptionPredicate);
if (osVersion != null) if (osVersion != null)
osPredicates.add(osVersionPredicate); osPredicates.add(osVersionPredicate);
if (os64Bit != null) if (os64Bit != null)
osPredicates.add(os64BitPredicate); osPredicates.add(os64BitPredicate);
if (osArch != null) if (osArch != null)
osPredicates.add(osArchPredicate); osPredicates.add(osArchPredicate);
if (osPredicates.size() > 0) if (osPredicates.size() > 0)
predicates.add(new Predicate<Image>() { predicates.add(new Predicate<Image>() {
@Override @Override
public boolean apply(Image input) { public boolean apply(Image input) {
return and(osPredicates).apply(input.getOperatingSystem()); return and(osPredicates).apply(input.getOperatingSystem());
} }
@Override @Override
public String toString() { public String toString() {
return and(osPredicates).toString(); return and(osPredicates).toString();
} }
}); });
if (imageVersion != null) if (imageVersion != null)
predicates.add(imageVersionPredicate); predicates.add(imageVersionPredicate);
if (imageName != null) if (imageName != null)
predicates.add(imageNamePredicate); predicates.add(imageNamePredicate);
if (imageDescription != null) if (imageDescription != null)
predicates.add(imageDescriptionPredicate); predicates.add(imageDescriptionPredicate);
if (imagePredicate != null) if (imagePredicate != null)
predicates.add(imagePredicate); predicates.add(imagePredicate);
}
// looks verbose, but explicit <Image> type needed for this to compile // looks verbose, but explicit <Image> type needed for this to compile
// properly // properly
@ -958,11 +997,40 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Override @Override
public String toString() { public String toString() {
return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription=" return string().toString();
+ imageDescription + ", imageId=" + imageId + ", imagePredicate=" + imagePredicate + ", imageVersion=" + imageVersion + ", location=" + location }
+ ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" + osName
+ ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch + ", os64Bit=" /**
+ os64Bit + ", hardwareId=" + hardwareId + ", hypervisor=" + hypervisor + "]"; * @since 1.5
*/
protected ToStringHelper string() {
ToStringHelper toString = Objects.toStringHelper("").omitNullValues();
if (biggest)
toString.add("biggest", biggest);
if (fastest)
toString.add("fastest", fastest);
toString.add("imageName", imageName);
toString.add("imageDescription", imageDescription);
toString.add("imageId", imageId);
toString.add("imagePredicate", imagePredicate);
toString.add("imageVersion", imageVersion);
if (location != null)
toString.add("locationId", location.getId());
if (minCores >0) //TODO: make non-primitive
toString.add("minCores", minCores);
if (minRam >0) //TODO: make non-primitive
toString.add("minRam", minRam);
if (minRam >0) //TODO: make non-primitive
toString.add("minRam", minRam);
toString.add("osFamily", osFamily);
toString.add("osName", osName);
toString.add("osDescription", osDescription);
toString.add("osVersion", osVersion);
toString.add("osArch", osArch);
toString.add("os64Bit", os64Bit);
toString.add("hardwareId", hardwareId);
toString.add("hypervisor", hypervisor);
return toString;
} }
@Override @Override

View File

@ -129,8 +129,8 @@ public class TemplateImpl implements Template {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected Object clone() throws CloneNotSupportedException { public Template clone() {
return new TemplateImpl(image, size, location, options); return new TemplateImpl(image, size, location, options.clone());
} }
} }

View File

@ -338,9 +338,9 @@ public class BaseComputeService implements ComputeService {
*/ */
@Override @Override
public Set<ComputeMetadata> listNodes() { public Set<ComputeMetadata> listNodes() {
logger.debug(">> listing nodes"); logger.trace(">> listing nodes");
Set<ComputeMetadata> set = newLinkedHashSet(listNodesStrategy.listNodes()); Set<ComputeMetadata> set = newLinkedHashSet(listNodesStrategy.listNodes());
logger.debug("<< list(%d)", set.size()); logger.trace("<< list(%d)", set.size());
return set; return set;
} }
@ -350,9 +350,9 @@ public class BaseComputeService implements ComputeService {
@Override @Override
public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter) { public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter) {
checkNotNull(filter, "filter"); checkNotNull(filter, "filter");
logger.debug(">> listing node details matching(%s)", filter); logger.trace(">> listing node details matching(%s)", filter);
Set<NodeMetadata> set = newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(filter)); Set<NodeMetadata> set = newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(filter));
logger.debug("<< list(%d)", set.size()); logger.trace("<< list(%d)", set.size());
return set; return set;
} }

View File

@ -455,11 +455,23 @@ public class RunScriptOptions {
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("").add("loginUser", loginUser) ToStringHelper toString = Objects.toStringHelper("").omitNullValues();
.add("loginPasswordPresent", (loginPassword != null)) toString.add("loginUser", loginUser);
.add("loginPrivateKeyPresent", (loginPrivateKey != null)).add("authenticateSudo", authenticateSudo) if (loginPassword != null)
.add("port:seconds", port + ":" + seconds).add("taskName", taskName).add("runAsRoot", runAsRoot) toString.add("loginPasswordPresent", true);
.add("blockOnComplete", blockOnComplete).add("wrapInInitScript", wrapInInitScript); if (loginPrivateKey != null)
toString.add("loginPrivateKeyPresent", true);
toString.add("authenticateSudo", authenticateSudo);
if (port != -1 && seconds != -1) // TODO: not primitives
toString.add("blockOnPort:seconds", port + ":" + seconds);
toString.add("taskName", taskName);
if (!runAsRoot)
toString.add("runAsRoot", runAsRoot);
if (!blockOnComplete)
toString.add("blockOnComplete", blockOnComplete);
if (!wrapInInitScript)
toString.add("wrapInInitScript", wrapInInitScript);
return toString;
} }
} }

View File

@ -317,7 +317,9 @@ public class TemplateOptions extends RunScriptOptions implements Cloneable {
} }
protected Set<Integer> inboundPorts = ImmutableSet.of(22); private final static Set<Integer> DEFAULT_INBOUND_PORTS = ImmutableSet.of(22);
protected Set<Integer> inboundPorts = DEFAULT_INBOUND_PORTS;
protected Statement script; protected Statement script;
@ -352,11 +354,24 @@ public class TemplateOptions extends RunScriptOptions implements Cloneable {
@Override @Override
public ToStringHelper string() { public ToStringHelper string() {
return super.string().add("inboundPorts", inboundPorts).add("scriptPresent", script != null) ToStringHelper toString = super.string();
.add("publicKeyPresent", publicKey != null).add("privateKeyPresent", privateKey != null).add("tags", tags) if (!DEFAULT_INBOUND_PORTS.equals(inboundPorts))
.add("blockUntilRunning", blockUntilRunning).add("tags", tags).add("userMetadata", userMetadata); toString.add("inboundPorts", inboundPorts);
if (script != null)
toString.add("scriptPresent", true);
if (publicKey != null)
toString.add("publicKeyPresent", true);
if (privateKey != null)
toString.add("privateKeyPresent", true);
if (!blockUntilRunning)
toString.add("blockUntilRunning", blockUntilRunning);
if (tags.size() != 0)
toString.add("tags", tags);
if (userMetadata.size() != 0)
toString.add("userMetadata", userMetadata);
return toString;
} }
public int[] getInboundPorts() { public int[] getInboundPorts() {
return Ints.toArray(inboundPorts); return Ints.toArray(inboundPorts);
} }

View File

@ -75,7 +75,7 @@ public class RunScriptData {
return InitScript.builder() return InitScript.builder()
.name("jboss") .name("jboss")
.home(JBOSS_HOME) .home(JBOSS_HOME)
.exportVariables(ImmutableMap.of("jbossHome", JBOSS_HOME)) .exportVariables(ImmutableMap.of("JBOSS_HOME", JBOSS_HOME))
.init(appendFile(JBOSS_HOME + "/standalone/configuration/standalone-custom.xml", Splitter.on('\n').split(configuration))) .init(appendFile(JBOSS_HOME + "/standalone/configuration/standalone-custom.xml", Splitter.on('\n').split(configuration)))
.run(interpret(new StringBuilder().append("java ").append(' ') .run(interpret(new StringBuilder().append("java ").append(' ')
.append("-server -Xms128m -Xmx128m -XX:MaxPermSize=128m -Djava.net.preferIPv4Stack=true -XX:+UseFastAccessorMethods -XX:+TieredCompilation -Xverify:none -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000").append(' ') .append("-server -Xms128m -Xmx128m -XX:MaxPermSize=128m -Djava.net.preferIPv4Stack=true -XX:+UseFastAccessorMethods -XX:+TieredCompilation -Xverify:none -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000").append(' ')

View File

@ -63,6 +63,9 @@ public class TemplateBuilderImplTest {
protected Location region = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description("us-east-1") protected Location region = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description("us-east-1")
.parent(provider).build(); .parent(provider).build();
protected Location region2 = new LocationBuilder().scope(LocationScope.REGION).id("us-east-2").description("us-east-2")
.parent(provider).build();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testLocationPredicateWhenComputeMetadataIsNotLocationBound() { public void testLocationPredicateWhenComputeMetadataIsNotLocationBound() {
Image image = createMock(Image.class); Image image = createMock(Image.class);
@ -371,7 +374,7 @@ public class TemplateBuilderImplTest {
// make sure big data is not in the exception message // make sure big data is not in the exception message
assertEquals( assertEquals(
e.getMessage(), e.getMessage(),
"no hardware profiles support images matching params: [biggest=false, fastest=false, imageName=null, imageDescription=null, imageId=us-east-1/imageId, imagePredicate=null, imageVersion=null, location=[id=us-east-1, scope=REGION, description=us-east-1, parent=aws-ec2, iso3166Codes=[], metadata={}], minCores=0.0, minRam=0, osFamily=null, osName=null, osDescription=null, osVersion=null, osArch=null, os64Bit=false, hardwareId=null, hypervisor=null]"); "no hardware profiles support images matching params: {imageId=us-east-1/imageId, locationId=us-east-1, os64Bit=false}");
verify(image); verify(image);
verify(os); verify(os);
verify(defaultTemplate); verify(defaultTemplate);
@ -849,9 +852,63 @@ public class TemplateBuilderImplTest {
TemplateBuilder templateBuilder = templateBuilderProvider.get().minRam(512).osFamily(OsFamily.UBUNTU) TemplateBuilder templateBuilder = templateBuilderProvider.get().minRam(512).osFamily(OsFamily.UBUNTU)
.hypervisorMatches("OpenVZ").osVersionMatches("1[10].[10][04]").os64Bit(true); .hypervisorMatches("OpenVZ").osVersionMatches("1[10].[10][04]").os64Bit(true);
assertEquals(templateBuilder.toString(), "{minRam=512, minRam=512, osFamily=ubuntu, osVersion=1[10].[10][04], os64Bit=true, hypervisor=OpenVZ}");
Template template = templateBuilder.build(); Template template = templateBuilder.build();
assertEquals(template.getHardware().getHypervisor(), "OpenVZ"); assertEquals(template.getHardware().getHypervisor(), "OpenVZ");
assertEquals(template.getImage().getId(), "Ubuntu 11.04 64-bit"); assertEquals(template.getImage().getId(), "Ubuntu 11.04 64-bit");
} }
@Test
public void testImageLocationNonDefault() {
final Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(region));
final Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
.<Image> of(
new ImageBuilder()
.id("us-east-2/ami-ffff")
.providerId("ami-ffff")
.name("Ubuntu 11.04 x64")
.description("Ubuntu 11.04 x64")
.location(region2)
.status(Status.AVAILABLE)
.operatingSystem(
OperatingSystem.builder().name("Ubuntu 11.04 x64").description("Ubuntu 11.04 x64")
.is64Bit(true).version("11.04").family(OsFamily.UBUNTU).build()).build()));
final Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(
new HardwareBuilder()
.ids("m1.small").ram(512)
.processors(ImmutableList.of(new Processor(1, 1.0)))
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) 5, true, true))).build()));
final Provider<TemplateOptions> optionsProvider = new Provider<TemplateOptions>() {
@Override
public TemplateOptions get() {
return new TemplateOptions();
}
};
Provider<TemplateBuilder> templateBuilderProvider = new Provider<TemplateBuilder>() {
@Override
public TemplateBuilder get() {
return createTemplateBuilder(null, locations, images, hardwares, region, optionsProvider, this);
}
};
TemplateBuilder templateBuilder = templateBuilderProvider.get().hardwareId("m1.small").imageId("us-east-2/ami-ffff");
assertEquals(templateBuilder.toString(), "{imageId=us-east-2/ami-ffff, hardwareId=m1.small}");
Template template = templateBuilder.build();
assertEquals(template.getLocation().getId(), "us-east-2");
}
} }

View File

@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.jclouds.apis.BaseViewLiveTest; import org.jclouds.apis.BaseViewLiveTest;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.TemplateBuilderSpec;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.domain.LoginCredentials.Builder; import org.jclouds.domain.LoginCredentials.Builder;
import org.jclouds.io.CopyInputStreamInputSupplierMap; import org.jclouds.io.CopyInputStreamInputSupplierMap;
@ -41,9 +42,7 @@ import com.google.inject.util.Modules;
*/ */
public abstract class BaseGenericComputeServiceContextLiveTest<W extends ComputeServiceContext> extends BaseViewLiveTest<W> { public abstract class BaseGenericComputeServiceContextLiveTest<W extends ComputeServiceContext> extends BaseViewLiveTest<W> {
protected String imageId; protected TemplateBuilderSpec template;
protected String loginUser;
protected String authenticateSudo;
protected LoginCredentials loginCredentials = LoginCredentials.builder().user("root").build(); protected LoginCredentials loginCredentials = LoginCredentials.builder().user("root").build();
// isolate tests from eachother, as default credentialStore is static // isolate tests from eachother, as default credentialStore is static
@ -53,19 +52,19 @@ public abstract class BaseGenericComputeServiceContextLiveTest<W extends Compute
@Override @Override
protected Properties setupProperties() { protected Properties setupProperties() {
Properties overrides = super.setupProperties(); Properties overrides = super.setupProperties();
imageId = setIfTestSystemPropertyPresent(overrides, provider + ".image-id"); String spec = setIfTestSystemPropertyPresent(overrides, provider + ".template");
loginUser = setIfTestSystemPropertyPresent(overrides, provider + ".image.login-user"); if (spec != null) {
authenticateSudo = setIfTestSystemPropertyPresent(overrides, provider + ".image.authenticate-sudo"); template = TemplateBuilderSpec.parse(spec);
if (template.getLoginUser() != null) {
if (loginUser != null) { Iterable<String> userPass = Splitter.on(':').split(template.getLoginUser());
Iterable<String> userPass = Splitter.on(':').split(loginUser); Builder loginCredentialsBuilder = LoginCredentials.builder();
Builder loginCredentialsBuilder = LoginCredentials.builder(); loginCredentialsBuilder.user(Iterables.get(userPass, 0));
loginCredentialsBuilder.user(Iterables.get(userPass, 0)); if (Iterables.size(userPass) == 2)
if (Iterables.size(userPass) == 2) loginCredentialsBuilder.password(Iterables.get(userPass, 1));
loginCredentialsBuilder.password(Iterables.get(userPass, 1)); if (template.getAuthenticateSudo() != null)
if (authenticateSudo != null) loginCredentialsBuilder.authenticateSudo(template.getAuthenticateSudo());
loginCredentialsBuilder.authenticateSudo(Boolean.valueOf(authenticateSudo)); loginCredentials = loginCredentialsBuilder.build();
loginCredentials = loginCredentialsBuilder.build(); }
} }
return overrides; return overrides;
} }

View File

@ -261,9 +261,9 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseComputeServiceCont
ComputeServiceContext context = null; ComputeServiceContext context = null;
try { try {
Properties overrides = setupProperties(); Properties overrides = setupProperties();
String login = loginUser != null ? loginUser : "foo:bar"; String login = template != null && template.getLoginUser() != null ? template.getLoginUser() : "foo:bar";
overrides.setProperty(propertyKey + ".image.login-user", login); overrides.setProperty(propertyKey + ".image.login-user", login);
boolean auth = authenticateSudo != null ? Boolean.valueOf(authenticateSudo) : true; boolean auth = template != null && template.getAuthenticateSudo() != null ? template.getAuthenticateSudo() : true;
overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + ""); overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + "");
context = createView(overrides, ImmutableSet.<Module>of(credentialStoreModule)); context = createView(overrides, ImmutableSet.<Module>of(credentialStoreModule));

View File

@ -45,6 +45,7 @@ public class TemplateOptionsTest {
public void testinstallPrivateKey() throws IOException { public void testinstallPrivateKey() throws IOException {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
assertEquals(options.toString(), "{privateKeyPresent=true}");
assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----"); assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
} }
@ -75,6 +76,7 @@ public class TemplateOptionsTest {
public void testauthorizePublicKey() throws IOException { public void testauthorizePublicKey() throws IOException {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
options.authorizePublicKey("ssh-rsa"); options.authorizePublicKey("ssh-rsa");
assertEquals(options.toString(), "{publicKeyPresent=true}");
assertEquals(options.getPublicKey(), "ssh-rsa"); assertEquals(options.getPublicKey(), "ssh-rsa");
} }
@ -105,6 +107,7 @@ public class TemplateOptionsTest {
public void testblockOnPort() { public void testblockOnPort() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
options.blockOnPort(22, 30); options.blockOnPort(22, 30);
assertEquals(options.toString(), "{blockOnPort:seconds=22:30}");
assertEquals(options.getPort(), 22); assertEquals(options.getPort(), 22);
assertEquals(options.getSeconds(), 30); assertEquals(options.getSeconds(), 30);
@ -148,6 +151,7 @@ public class TemplateOptionsTest {
@Test @Test
public void testinboundPortsStatic() { public void testinboundPortsStatic() {
TemplateOptions options = inboundPorts(22, 30); TemplateOptions options = inboundPorts(22, 30);
assertEquals(options.toString(), "{inboundPorts=[22, 30]}");
assertEquals(options.getInboundPorts()[0], 22); assertEquals(options.getInboundPorts()[0], 22);
assertEquals(options.getInboundPorts()[1], 30); assertEquals(options.getInboundPorts()[1], 30);
} }
@ -155,6 +159,7 @@ public class TemplateOptionsTest {
@Test @Test
public void testblockUntilRunningDefault() { public void testblockUntilRunningDefault() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
assertEquals(options.toString(), "{}");
assertEquals(options.shouldBlockUntilRunning(), true); assertEquals(options.shouldBlockUntilRunning(), true);
} }
@ -162,6 +167,7 @@ public class TemplateOptionsTest {
public void testblockUntilRunning() { public void testblockUntilRunning() {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
options.blockUntilRunning(false); options.blockUntilRunning(false);
assertEquals(options.toString(), "{blockUntilRunning=false}");
assertEquals(options.shouldBlockUntilRunning(), false); assertEquals(options.shouldBlockUntilRunning(), false);
} }

View File

@ -33,6 +33,7 @@ import com.google.common.annotations.VisibleForTesting;
/** /**
* @author Andrew Phillips * @author Andrew Phillips
* @author Adrian Cole
*/ */
public class JcloudsVersion { public class JcloudsVersion {
@VisibleForTesting @VisibleForTesting
@ -105,10 +106,10 @@ public class JcloudsVersion {
String alphaOrBetaOrReleaseCandidateVersionIfPresent = versionMatcher.group(4); String alphaOrBetaOrReleaseCandidateVersionIfPresent = versionMatcher.group(4);
if (alphaOrBetaOrReleaseCandidateVersionIfPresent != null) { if (alphaOrBetaOrReleaseCandidateVersionIfPresent != null) {
Integer alphaOrReleaseCandidateVersion = Integer.valueOf(versionMatcher.group(5)); Integer alphaOrBetaOrReleaseCandidateVersion = Integer.valueOf(versionMatcher.group(5));
if (alphaOrBetaOrReleaseCandidateVersionIfPresent.equals(ALPHA_VERSION_IDENTIFIER)) { if (alphaOrBetaOrReleaseCandidateVersionIfPresent.equals(ALPHA_VERSION_IDENTIFIER)) {
alpha = true; alpha = true;
alphaVersion = alphaOrReleaseCandidateVersion; alphaVersion = alphaOrBetaOrReleaseCandidateVersion;
beta = false; beta = false;
betaVersion = null; betaVersion = null;
releaseCandidate = false; releaseCandidate = false;
@ -117,7 +118,7 @@ public class JcloudsVersion {
alpha = false; alpha = false;
alphaVersion = null; alphaVersion = null;
beta = true; beta = true;
betaVersion = alphaOrReleaseCandidateVersion; betaVersion = alphaOrBetaOrReleaseCandidateVersion;
releaseCandidate = false; releaseCandidate = false;
releaseCandidateVersion = null; releaseCandidateVersion = null;
} else { } else {
@ -126,7 +127,7 @@ public class JcloudsVersion {
beta = false; beta = false;
betaVersion = null; betaVersion = null;
releaseCandidate = true; releaseCandidate = true;
releaseCandidateVersion = alphaOrReleaseCandidateVersion; releaseCandidateVersion = alphaOrBetaOrReleaseCandidateVersion;
} }
} else { } else {
alpha = false; alpha = false;

View File

@ -0,0 +1,46 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.apis;
import java.util.HashSet;
import java.util.Set;
/**
* A registry for holding {@link org.jclouds.apis.ApiMetadata}.
*/
public class ApiRegistry {
private static final Set<ApiMetadata> apis = new HashSet<ApiMetadata>();
public static void registerApi(ApiMetadata api) {
apis.add(api);
}
public static void unRegisterApi(ApiMetadata api) {
apis.remove(api);
}
public static Iterable<ApiMetadata> fromRegistry() {
return Iterable.class.cast(apis);
}
public static void clear() {
apis.clear();
}
}

View File

@ -69,7 +69,7 @@ public class Apis {
* @return all available apis * @return all available apis
*/ */
public static Iterable<ApiMetadata> all() { public static Iterable<ApiMetadata> all() {
return fromServiceLoader(); return Iterables.concat(fromServiceLoader(), ApiRegistry.fromRegistry());
} }
/** /**

View File

@ -124,13 +124,14 @@ public class SshKeys {
/** /**
* *
* @param used * @param generator
* to generate RSA key pairs * to generate RSA key pairs
* @param rand
* for initializing {@code generator}
* @return new 2048 bit keyPair * @return new 2048 bit keyPair
* @see Crypto#rsaKeyPairGenerator() * @see Crypto#rsaKeyPairGenerator()
*/ */
public static KeyPair generateRsaKeyPair(KeyPairGenerator generator) { public static KeyPair generateRsaKeyPair(KeyPairGenerator generator, SecureRandom rand) {
SecureRandom rand = new SecureRandom();
generator.initialize(2048, rand); generator.initialize(2048, rand);
return generator.genKeyPair(); return generator.genKeyPair();
} }
@ -140,15 +141,15 @@ public class SshKeys {
*/ */
public static Map<String, String> generate() { public static Map<String, String> generate() {
try { try {
return generate(KeyPairGenerator.getInstance("RSA")); return generate(KeyPairGenerator.getInstance("RSA"), new SecureRandom());
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
propagate(e); propagate(e);
return null; return null;
} }
} }
public static Map<String, String> generate(KeyPairGenerator generator) { public static Map<String, String> generate(KeyPairGenerator generator, SecureRandom rand) {
KeyPair pair = generateRsaKeyPair(generator); KeyPair pair = generateRsaKeyPair(generator, rand);
Builder<String, String> builder = ImmutableMap.builder(); Builder<String, String> builder = ImmutableMap.builder();
builder.put("public", encodeAsOpenSSH(RSAPublicKey.class.cast(pair.getPublic()))); builder.put("public", encodeAsOpenSSH(RSAPublicKey.class.cast(pair.getPublic())));
builder.put("private", encodeAsPem(RSAPrivateKey.class.cast(pair.getPrivate()))); builder.put("private", encodeAsPem(RSAPrivateKey.class.cast(pair.getPrivate())));

View File

@ -47,6 +47,6 @@ public class DeadEventLoggingHandler
*/ */
@Subscribe @Subscribe
public final void handleDeadEvent(DeadEvent deadEvent) { public final void handleDeadEvent(DeadEvent deadEvent) {
logger.warn("detected dead event %s", deadEvent.getEvent()); logger.trace("detected dead event %s", deadEvent.getEvent());
} }
} }

View File

@ -60,7 +60,7 @@ public abstract class BasePayload<V> implements Payload {
*/ */
@Override @Override
public void writeTo(OutputStream outstream) throws IOException { public void writeTo(OutputStream outstream) throws IOException {
checkState(!written || isRepeatable(), "can only be writted to an outputstream once"); checkState(!written || isRepeatable(), "can only write to an outputStream once");
written = true; written = true;
InputStream in = getInput(); InputStream in = getInput();
try { try {

View File

@ -56,10 +56,15 @@ public class RegionToEndpointOrProviderIfNull implements Function<Object, URI> {
@Override @Override
public URI apply(@Nullable Object from) { public URI apply(@Nullable Object from) {
if (from == null || from.equals(defaultProvider)) if (from == null)
return defaultUri.get(); return defaultUri.get();
checkArgument(from instanceof String, "region is a String argument"); checkArgument(from instanceof String, "region is a String argument");
Map<String, Supplier<URI>> regionToEndpoint = regionToEndpointSupplier.get(); Map<String, Supplier<URI>> regionToEndpoint = regionToEndpointSupplier.get();
if (from.equals(defaultProvider)){
if (regionToEndpoint.containsKey(from))
return regionToEndpoint.get(from).get();
return defaultUri.get();
}
checkArgument(regionToEndpoint.containsKey(from), checkArgument(regionToEndpoint.containsKey(from),
"requested location %s, which is not in the configured locations: %s", from, regionToEndpoint); "requested location %s, which is not in the configured locations: %s", from, regionToEndpoint);
return regionToEndpoint.get(from).get(); return regionToEndpoint.get(from).get();

View File

@ -0,0 +1,64 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.location.suppliers.derived;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.location.Region;
import org.jclouds.location.Zone;
import org.jclouds.location.suppliers.ZoneIdToURISupplier;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
/**
*
*/
@Singleton
public class ZoneIdToURIFromJoinOnRegionIdToURI implements ZoneIdToURISupplier {
private final Supplier<Map<String, Supplier<URI>>> regionIdToURISupplier;
private final Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIdsSupplier;
@Inject
protected ZoneIdToURIFromJoinOnRegionIdToURI(@Region Supplier<Map<String, Supplier<URI>>> regionIdToURISupplier,
@Zone Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIdsSupplier) {
this.regionIdToURISupplier = regionIdToURISupplier;
this.regionIdToZoneIdsSupplier = regionIdToZoneIdsSupplier;
}
@Override
public Map<String, Supplier<URI>> get() {
Builder<String, Supplier<URI>> builder = ImmutableMap.<String, Supplier<URI>> builder();
for (Entry<String, Supplier<URI>> regionToURI : regionIdToURISupplier.get().entrySet()) {
for (String zone : regionIdToZoneIdsSupplier.get().get(regionToURI.getKey()).get()) {
builder.put(zone, regionToURI.getValue());
}
}
return builder.build();
}
}

View File

@ -18,13 +18,14 @@
*/ */
package org.jclouds.osgi; package org.jclouds.osgi;
import org.jclouds.apis.ApiRegistry;
import org.jclouds.providers.ProviderRegistry; import org.jclouds.providers.ProviderRegistry;
import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator { public class Activator implements BundleActivator {
ProviderBundleListener bundleListener = new ProviderBundleListener(); MetadataBundleListener bundleListener = new MetadataBundleListener();
/** /**
* Called when this bundle is started so the Framework can perform the * Called when this bundle is started so the Framework can perform the
@ -43,6 +44,7 @@ public class Activator implements BundleActivator {
*/ */
@Override @Override
public void start(BundleContext context) throws Exception { public void start(BundleContext context) throws Exception {
bundleListener.start(context);
context.addBundleListener(bundleListener); context.addBundleListener(bundleListener);
} }
@ -65,7 +67,9 @@ public class Activator implements BundleActivator {
*/ */
@Override @Override
public void stop(BundleContext context) throws Exception { public void stop(BundleContext context) throws Exception {
bundleListener.stop(context);
context.removeBundleListener(bundleListener); context.removeBundleListener(bundleListener);
ProviderRegistry.clear(); ProviderRegistry.clear();
ApiRegistry.clear();
} }
} }

View File

@ -0,0 +1,208 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.osgi;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.apis.ApiRegistry;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.ProviderRegistry;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
/**
* A {@link BundleListener} that listens for {@link BundleEvent} and searches for {@link org.jclouds.providers.ProviderMetadata} and {@ling org.jclouds.apis.ApiMetadata} in newly
* installed Bundles. This is used as a workaround for OSGi environments where the ServiceLoader cannot cross bundle
* boundaries.
*/
public class MetadataBundleListener implements BundleListener {
private Map<Long, ProviderMetadata> providerMetadataMap = new HashMap<Long, ProviderMetadata>();
private Map<Long, ApiMetadata> apiMetadataMap = new HashMap<Long, ApiMetadata>();
public void start(BundleContext bundleContext) {
bundleContext.addBundleListener(this);
for (Bundle bundle : bundleContext.getBundles()) {
if (bundle.getState() == Bundle.ACTIVE) {
ProviderMetadata providerMetadata = getProviderMetadata(bundle);
ApiMetadata apiMetadata = getApiMetadata(bundle);
if (providerMetadata != null) {
ProviderRegistry.registerProvider(providerMetadata);
providerMetadataMap.put(bundle.getBundleId(), providerMetadata);
}
if (apiMetadata != null) {
ApiRegistry.registerApi(apiMetadata);
apiMetadataMap.put(bundle.getBundleId(), apiMetadata);
}
}
}
}
public void stop(BundleContext bundleContext) {
providerMetadataMap.clear();
apiMetadataMap.clear();
}
@Override
public void bundleChanged(BundleEvent event) {
ProviderMetadata providerMetadata;
ApiMetadata apiMetadata;
switch (event.getType()) {
case BundleEvent.STARTED:
providerMetadata = getProviderMetadata(event.getBundle());
apiMetadata = getApiMetadata(event.getBundle());
if (providerMetadata != null) {
ProviderRegistry.registerProvider(providerMetadata);
providerMetadataMap.put(event.getBundle().getBundleId(), providerMetadata);
}
if (apiMetadata != null) {
ApiRegistry.registerApi(apiMetadata);
apiMetadataMap.put(event.getBundle().getBundleId(), apiMetadata);
}
break;
case BundleEvent.STOPPING:
case BundleEvent.STOPPED:
providerMetadata = providerMetadataMap.get(event.getBundle().getBundleId());
apiMetadata = apiMetadataMap.get(event.getBundle().getBundleId());
if (providerMetadata != null) {
ProviderRegistry.uRegisterProvider(providerMetadata);
}
if (apiMetadata != null) {
ApiRegistry.unRegisterApi(apiMetadata);
}
break;
}
}
/**
* Creates an instance of {@link ProviderMetadata} from the {@link Bundle}.
*
* @param bundle
* @return
*/
public ProviderMetadata getProviderMetadata(Bundle bundle) {
ProviderMetadata metadata = null;
String className = getProviderMetadataClassName(bundle);
if (className != null && !className.isEmpty()) {
try {
Class<? extends ProviderMetadata> providerMetadataClass = bundle.loadClass(className);
metadata = providerMetadataClass.newInstance();
} catch (ClassNotFoundException e) {
// ignore
} catch (InstantiationException e) {
// ignore
} catch (IllegalAccessException e) {
// ignore
}
}
return metadata;
}
/**
* Creates an instance of {@link ApiMetadata} from the {@link Bundle}.
*
* @param bundle
* @return
*/
public ApiMetadata getApiMetadata(Bundle bundle) {
ApiMetadata metadata = null;
String className = getApiMetadataClassName(bundle);
if (className != null && !className.isEmpty()) {
try {
Class<? extends ApiMetadata> apiMetadataClass = bundle.loadClass(className);
metadata = apiMetadataClass.newInstance();
} catch (ClassNotFoundException e) {
// ignore
} catch (InstantiationException e) {
// ignore
} catch (IllegalAccessException e) {
// ignore
}
}
return metadata;
}
public String getMetadataClassName(Bundle bundle, String pathToMetadata) {
URL resource = bundle.getEntry(pathToMetadata);
InputStream is = null;
InputStreamReader reader = null;
BufferedReader bufferedReader = null;
StringBuilder sb = new StringBuilder();
try {
is = resource.openStream();
reader = new InputStreamReader(is, "UTF-8");
bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line).append("\n");
}
} catch (Throwable e) {
} finally {
try {
if (reader != null)
reader.close();
} catch (Throwable e) {
}
try {
if (bufferedReader != null)
bufferedReader.close();
} catch (Throwable e) {
}
try {
is.close();
} catch (Throwable e) {
}
}
return sb.toString().trim();
}
/**
* Retrieves the {@link ProviderMetadata} class name for the bundle if it exists.
*
* @param bundle
* @return
*/
public String getProviderMetadataClassName(Bundle bundle) {
return getMetadataClassName(bundle, "/META-INF/services/org.jclouds.providers.ProviderMetadata");
}
/**
* Retrieves the {@link ProviderMetadata} class name for the bundle if it exists.
*
* @param bundle
* @return
*/
public String getApiMetadataClassName(Bundle bundle) {
return getMetadataClassName(bundle, "/META-INF/services/org.jclouds.apis.ApiMetadata");
}
}

View File

@ -1,129 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.osgi;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.ProviderRegistry;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
/**
* A {@link BundleListener} that listens for {@link BundleEvent} and searches for {@link org.jclouds.providers.ProviderMetadata} in newly
* installed Bundles. This is used as a workaround for OSGi environments where the ServiceLoader cannot cross bundle
* boundaries.
*/
public class ProviderBundleListener implements BundleListener {
private Map<Long, ProviderMetadata> bundleMetadataMap = new HashMap<Long, ProviderMetadata>();
@Override
public void bundleChanged(BundleEvent event) {
ProviderMetadata metadata;
switch (event.getType()) {
case BundleEvent.STARTED:
metadata = getProviderMetadata(event.getBundle());
if (metadata != null) {
ProviderRegistry.registerProvider(metadata);
bundleMetadataMap.put(event.getBundle().getBundleId(), metadata);
}
break;
case BundleEvent.STOPPING:
case BundleEvent.STOPPED:
metadata = bundleMetadataMap.get(event.getBundle().getBundleId());
if (metadata != null) {
ProviderRegistry.uRegisterProvider(metadata);
}
break;
}
}
/**
* Creates an instance of {@link ProviderMetadata} from the {@link Bundle}.
*
* @param bundle
* @return
*/
public ProviderMetadata getProviderMetadata(Bundle bundle) {
ProviderMetadata metadata = null;
String className = getProviderMetadataClassName(bundle);
if (className != null && !className.isEmpty()) {
try {
Class<? extends ProviderMetadata> provideClass = bundle.loadClass(className);
metadata = provideClass.newInstance();
} catch (ClassNotFoundException e) {
// ignore
} catch (InstantiationException e) {
// ignore
} catch (IllegalAccessException e) {
// ignore
}
}
return metadata;
}
/**
* Retrieves the {@link ProviderMetadata} class name for the bundle if it exists.
*
* @param bundle
* @return
*/
public String getProviderMetadataClassName(Bundle bundle) {
URL resource = bundle.getEntry("/META-INF/services/org.jclouds.providers.ProviderMetadata");
InputStream is = null;
InputStreamReader reader = null;
BufferedReader bufferedReader = null;
StringBuilder sb = new StringBuilder();
try {
is = resource.openStream();
reader = new InputStreamReader(is, "UTF-8");
bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line).append("\n");
}
} catch (Throwable e) {
} finally {
try {
if (reader != null)
reader.close();
} catch (Throwable e) {
}
try {
if (bufferedReader != null)
bufferedReader.close();
} catch (Throwable e) {
}
try {
is.close();
} catch (Throwable e) {
}
}
return sb.toString().trim();
}
}

View File

@ -43,7 +43,7 @@ public class ApisTest {
ApiMetadata apiMetadata; ApiMetadata apiMetadata;
try { try {
apiMetadata = Apis.withId("fake-id"); apiMetadata = Apis.withId("fake-id");
fail("Looking for a api with an id that doesn't exist should " + "throw an exceptoin."); fail("Looking for a api with an id that doesn't exist should " + "throw an exception.");
} catch (NoSuchElementException nsee) { } catch (NoSuchElementException nsee) {
; // Expected ; // Expected
} }

View File

@ -38,6 +38,13 @@ import com.google.common.collect.ImmutableMap;
@Test(groups = "unit", testName = "RegionToEndpointOrProviderIfNullTest") @Test(groups = "unit", testName = "RegionToEndpointOrProviderIfNullTest")
public class RegionToEndpointOrProviderIfNullTest { public class RegionToEndpointOrProviderIfNullTest {
@Test
public void testWhenRegionNameIsSameAsProviderName() throws SecurityException, NoSuchMethodException {
RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI
.create("http://leader")), Suppliers.<Map<String, Supplier<URI>>>ofInstance(ImmutableMap.of("leader", Suppliers.ofInstance(URI.create("http://leaderregion")))));
assertEquals(fn.apply("leader"), URI.create("http://leaderregion"));
}
@Test @Test
public void testWhenFindsRegion() throws SecurityException, NoSuchMethodException { public void testWhenFindsRegion() throws SecurityException, NoSuchMethodException {
RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI

View File

@ -49,7 +49,7 @@ public class ProvidersTest {
try { try {
providerMetadata = Providers.withId("fake-id"); providerMetadata = Providers.withId("fake-id");
fail("Looking for a provider with an id that doesn't exist should " + "throw an exceptoin."); fail("Looking for a provider with an id that doesn't exist should " + "throw an exception.");
} catch (NoSuchElementException nsee) { } catch (NoSuchElementException nsee) {
; // Expected ; // Expected
} }

View File

@ -96,7 +96,7 @@ public class AsyncGaeHttpCommandExecutorService implements HttpCommandExecutorSe
request = filter.filter(request); request = filter.filter(request);
} }
checkRequestHasContentLengthOrChunkedEncoding(request, checkRequestHasContentLengthOrChunkedEncoding(request,
"After filtering, the request has niether chunked encoding nor content length: " + request); "After filtering, the request has neither chunked encoding nor content length: " + request);
logger.debug("Sending request %s: %s", request.hashCode(), request.getRequestLine()); logger.debug("Sending request %s: %s", request.hashCode(), request.getRequestLine());
wirePayloadIfEnabled(wire, request); wirePayloadIfEnabled(wire, request);
HTTPRequest nativeRequest = convertToGaeRequest.apply(request); HTTPRequest nativeRequest = convertToGaeRequest.apply(request);

View File

@ -36,16 +36,16 @@
<properties> <properties>
<test.aws-elb.endpoint>https://elasticloadbalancing.us-east-1.amazonaws.com</test.aws-elb.endpoint> <test.aws-elb.endpoint>https://elasticloadbalancing.us-east-1.amazonaws.com</test.aws-elb.endpoint>
<test.aws-elb.api-version>2010-07-01</test.aws-elb.api-version> <test.aws-elb.api-version>2010-07-01</test.aws-elb.api-version>
<test.aws-elb.build-version /> <test.aws-elb.build-version></test.aws-elb.build-version>
<test.aws-elb.identity>${test.aws.identity}</test.aws-elb.identity> <test.aws-elb.identity>${test.aws.identity}</test.aws-elb.identity>
<test.aws-elb.credential>${test.aws.credential}</test.aws-elb.credential> <test.aws-elb.credential>${test.aws.credential}</test.aws-elb.credential>
<test.aws-elb.compute.provider>aws-ec2</test.aws-elb.compute.provider> <test.aws-elb.compute.provider>aws-ec2</test.aws-elb.compute.provider>
<test.aws-elb.compute.endpoint>https://ec2.us-east-1.amazonaws.com</test.aws-elb.compute.endpoint> <test.aws-elb.compute.endpoint>https://ec2.us-east-1.amazonaws.com</test.aws-elb.compute.endpoint>
<test.aws-elb.compute.api-version>2010-06-15</test.aws-elb.compute.api-version> <test.aws-elb.compute.api-version>2010-06-15</test.aws-elb.compute.api-version>
<test.aws-elb.compute.build-version /> <test.aws-elb.compute.build-version></test.aws-elb.compute.build-version>
<test.aws-elb.compute.identity>${test.aws.identity}</test.aws-elb.compute.identity> <test.aws-elb.compute.identity>${test.aws.identity}</test.aws-elb.compute.identity>
<test.aws-elb.compute.credential>${test.aws.credential}</test.aws-elb.compute.credential> <test.aws-elb.compute.credential>${test.aws.credential}</test.aws-elb.compute.credential>
<test.aws-elb.compute.image-id /> <test.aws-elb.compute.template></test.aws-elb.compute.template>
<jclouds.osgi.export>org.jclouds.aws.elb*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.aws.elb*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import> <jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
@ -134,7 +134,7 @@
<test.aws-elb.compute.api-version>${test.aws-elb.compute.api-version}</test.aws-elb.compute.api-version> <test.aws-elb.compute.api-version>${test.aws-elb.compute.api-version}</test.aws-elb.compute.api-version>
<test.aws-elb.compute.identity>${test.aws-elb.compute.identity}</test.aws-elb.compute.identity> <test.aws-elb.compute.identity>${test.aws-elb.compute.identity}</test.aws-elb.compute.identity>
<test.aws-elb.compute.credential>${test.aws-elb.compute.credential}</test.aws-elb.compute.credential> <test.aws-elb.compute.credential>${test.aws-elb.compute.credential}</test.aws-elb.compute.credential>
<test.aws-elb.compute.image-id>${test.aws-elb.compute.image-id}</test.aws-elb.compute.image-id> <test.aws-elb.compute.template>${test.aws-elb.compute.template}</test.aws-elb.compute.template>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>

View File

@ -39,15 +39,13 @@
<test.carrenza-vcloud-director.build-version>464915</test.carrenza-vcloud-director.build-version> <test.carrenza-vcloud-director.build-version>464915</test.carrenza-vcloud-director.build-version>
<test.carrenza-vcloud-director.identity>FIXME_IDENTITY</test.carrenza-vcloud-director.identity> <test.carrenza-vcloud-director.identity>FIXME_IDENTITY</test.carrenza-vcloud-director.identity>
<test.carrenza-vcloud-director.credential>FIXME_CREDENTIAL</test.carrenza-vcloud-director.credential> <test.carrenza-vcloud-director.credential>FIXME_CREDENTIAL</test.carrenza-vcloud-director.credential>
<test.carrenza-vcloud-director.image-id /> <test.carrenza-vcloud-director.template></test.carrenza-vcloud-director.template>
<test.carrenza-vcloud-director.image.login-user /> <test.carrenza-vcloud-director.catalog-id></test.carrenza-vcloud-director.catalog-id>
<test.carrenza-vcloud-director.image.authenticate-sudo /> <test.carrenza-vcloud-director.media-id></test.carrenza-vcloud-director.media-id>
<test.carrenza-vcloud-director.catalog-id /> <test.carrenza-vcloud-director.vapptemplate-id></test.carrenza-vcloud-director.vapptemplate-id>
<test.carrenza-vcloud-director.media-id /> <test.carrenza-vcloud-director.network-name></test.carrenza-vcloud-director.network-name>
<test.carrenza-vcloud-director.vapptemplate-id /> <test.carrenza-vcloud-director.network-id></test.carrenza-vcloud-director.network-id>
<test.carrenza-vcloud-director.network-name /> <test.carrenza-vcloud-director.vdc-id></test.carrenza-vcloud-director.vdc-id>
<test.carrenza-vcloud-director.network-id />
<test.carrenza-vcloud-director.vdc-id />
<jclouds.osgi.export>org.jclouds.carrenza.vcloud.director*;version="${project.version}"</jclouds.osgi.export> <jclouds.osgi.export>org.jclouds.carrenza.vcloud.director*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import> <jclouds.osgi.import>
@ -121,9 +119,7 @@
<test.carrenza-vcloud-director.build-version>${test.carrenza-vcloud-director.build-version}</test.carrenza-vcloud-director.build-version> <test.carrenza-vcloud-director.build-version>${test.carrenza-vcloud-director.build-version}</test.carrenza-vcloud-director.build-version>
<test.carrenza-vcloud-director.identity>${test.carrenza-vcloud-director.identity}</test.carrenza-vcloud-director.identity> <test.carrenza-vcloud-director.identity>${test.carrenza-vcloud-director.identity}</test.carrenza-vcloud-director.identity>
<test.carrenza-vcloud-director.credential>${test.carrenza-vcloud-director.credential}</test.carrenza-vcloud-director.credential> <test.carrenza-vcloud-director.credential>${test.carrenza-vcloud-director.credential}</test.carrenza-vcloud-director.credential>
<test.carrenza-vcloud-director.image-id>${test.carrenza-vcloud-director.image-id}</test.carrenza-vcloud-director.image-id> <test.carrenza-vcloud-director.template>${test.carrenza-vcloud-director.template}</test.carrenza-vcloud-director.template>
<test.carrenza-vcloud-director.image.login-user>${test.carrenza-vcloud-director.image.login-user}</test.carrenza-vcloud-director.image.login-user>
<test.carrenza-vcloud-director.image.authenticate-sudo>${test.carrenza-vcloud-director.image.authenticate-sudo}</test.carrenza-vcloud-director.image.authenticate-sudo>
<test.carrenza-vcloud-director.catalog-id>${test.carrenza-vcloud-director.catalog-id}</test.carrenza-vcloud-director.catalog-id> <test.carrenza-vcloud-director.catalog-id>${test.carrenza-vcloud-director.catalog-id}</test.carrenza-vcloud-director.catalog-id>
<test.carrenza-vcloud-director.media-id>${test.carrenza-vcloud-director.media-id}</test.carrenza-vcloud-director.media-id> <test.carrenza-vcloud-director.media-id>${test.carrenza-vcloud-director.media-id}</test.carrenza-vcloud-director.media-id>
<test.carrenza-vcloud-director.vapptemplate-id>${test.carrenza-vcloud-director.vapptemplate-id}</test.carrenza-vcloud-director.vapptemplate-id> <test.carrenza-vcloud-director.vapptemplate-id>${test.carrenza-vcloud-director.vapptemplate-id}</test.carrenza-vcloud-director.vapptemplate-id>

View File

@ -29,137 +29,144 @@ import com.google.common.base.Objects.ToStringHelper;
/** /**
* The base type for all objects in the CDMI model. * The base type for all objects in the CDMI model.
* *
* @author Adrian Cole * @author Kenneth Nagin
*/ */
public class CDMIObject { public class CDMIObject {
public static Builder<?> builder() { public static Builder<?> builder() {
return new ConcreteBuilder(); return new ConcreteBuilder();
} }
public Builder<?> toBuilder() { public Builder<?> toBuilder() {
return builder().fromCDMIObject(this); return builder().fromCDMIObject(this);
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
} }
public static abstract class Builder<B extends Builder<B>> { public static abstract class Builder<B extends Builder<B>> {
private String objectID; private String objectID;
private String objectType; private String objectType;
private String objectName; private String objectName;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected B self() { protected B self() {
return (B) this; return (B) this;
} }
/** /**
* @see CDMIObject#getObjectID() * @see CDMIObject#getObjectID()
*/ */
public B objectID(String objectID) { public B objectID(String objectID) {
this.objectID = objectID; this.objectID = objectID;
return self(); return self();
} }
/** /**
* @see CDMIObject#getObjectType() * @see CDMIObject#getObjectType()
*/ */
public B objectType(String objectType) { public B objectType(String objectType) {
this.objectType = objectType; this.objectType = objectType;
return self(); return self();
} }
/** /**
* @see CDMIObject#getObjectName() * @see CDMIObject#getObjectName()
*/ */
public B objectName(String objectName) { public B objectName(String objectName) {
this.objectName = objectName; this.objectName = objectName;
return self(); return self();
} }
public CDMIObject build() { public CDMIObject build() {
return new CDMIObject(this); return new CDMIObject(this);
} }
protected B fromCDMIObject(CDMIObject in) { protected B fromCDMIObject(CDMIObject in) {
return objectID(in.getObjectID()).objectType(in.getObjectType()).objectName(in.getObjectName()); return objectID(in.getObjectID()).objectType(in.getObjectType())
} .objectName(in.getObjectName());
} }
}
private final String objectID; private final String objectID;
private final String objectType; private final String objectType;
private final String objectName; private final String objectName;
protected CDMIObject(Builder<?> builder) { protected CDMIObject(Builder<?> builder) {
this.objectID = checkNotNull(builder.objectID, "objectID"); this.objectID = checkNotNull(builder.objectID, "objectID");
this.objectType = checkNotNull(builder.objectType, "objectType"); this.objectType = checkNotNull(builder.objectType, "objectType");
this.objectName = builder.objectName; this.objectName = builder.objectName;
} }
/** /**
* Object ID of the object <br/> * Object ID of the object <br/>
* Every object stored within a CDMI-compliant system shall have a globally unique object * Every object stored within a CDMI-compliant system shall have a globally
* identifier (ID) assigned at creation time. The CDMI object ID is a string with requirements * unique object identifier (ID) assigned at creation time. The CDMI object
* for how it is generated and how it obtains its uniqueness. Each offering that implements CDMI * ID is a string with requirements for how it is generated and how it
* is able to produce these identifiers without conflicting with other offerings. * obtains its uniqueness. Each offering that implements CDMI is able to
*/ * produce these identifiers without conflicting with other offerings.
public String getObjectID() { *
return objectID; * note: CDMI Servers do not always support ObjectID tags, however
} * downstream jclouds code does not handle null so we return a empty String
* instead.
*/
public String getObjectID() {
return (objectID == null) ? "" : objectID;
}
/** /**
* *
* type of the object * type of the object
*/ */
public String getObjectType() { public String getObjectType() {
return objectType; return objectType;
} }
/** /**
* For objects in a container, the objectName field shall be returned. For objects not in a * For objects in a container, the objectName field shall be returned. For
* container (objects that are only accessible by ID), the objectName field shall not be * objects not in a container (objects that are only accessible by ID), the
* returned. * objectName field shall not be returned.
* *
* Name of the object * Name of the object
*/ */
@Nullable @Nullable
public String getObjectName() { public String getObjectName() {
return objectName; return (objectName == null) ? "" : objectName;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) if (this == o)
return true; return true;
if (o == null || getClass() != o.getClass()) if (o == null || getClass() != o.getClass())
return false; return false;
CDMIObject that = CDMIObject.class.cast(o); CDMIObject that = CDMIObject.class.cast(o);
return equal(this.objectID, that.objectID) && equal(this.objectName, that.objectName) return equal(this.objectID, that.objectID)
&& equal(this.objectType, that.objectType); && equal(this.objectName, that.objectName)
} && equal(this.objectType, that.objectType);
}
public boolean clone(Object o) { public boolean clone(Object o) {
if (this == o) if (this == o)
return false; return false;
if (o == null || getClass() != o.getClass()) if (o == null || getClass() != o.getClass())
return false; return false;
CDMIObject that = CDMIObject.class.cast(o); CDMIObject that = CDMIObject.class.cast(o);
return equal(this.objectType, that.objectType); return equal(this.objectType, that.objectType);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(objectID, objectName, objectType); return Objects.hashCode(objectID, objectName, objectType);
} }
@Override @Override
public String toString() { public String toString() {
return string().toString(); return string().toString();
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("").add("objectID", objectID).add("objectName", objectName).add("objectType", return Objects.toStringHelper("").add("objectID", objectID)
objectType); .add("objectName", objectName).add("objectType", objectType);
} }
} }

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