added volume to hardware object, added signed blob support, added example of how to use signed blobs with computeservice

This commit is contained in:
Adrian Cole 2010-09-12 02:27:42 -07:00
parent 59aea16b07
commit 198eeec3d9
96 changed files with 2397 additions and 1182 deletions

View File

@ -51,6 +51,7 @@ import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.concurrent.Futures; import org.jclouds.concurrent.Futures;
@ -85,8 +86,9 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object, ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
BlobStoreListOptionsToListOptions container2ContainerListOptions, BlobStoreListOptionsToListOptions container2ContainerListOptions,
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto, DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider) { BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
super(context, blobUtils, service, defaultLocation, locations); SignRequestForBlobStrategy signRequestForBlob) {
super(context, blobUtils, service, defaultLocation, locations, signRequestForBlob);
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.sync = checkNotNull(sync, "sync"); this.sync = checkNotNull(sync, "sync");
this.async = checkNotNull(async, "async"); this.async = checkNotNull(async, "async");

View File

@ -43,6 +43,7 @@ import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.internal.BaseBlobStore;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.crypto.Crypto; import org.jclouds.crypto.Crypto;
@ -72,8 +73,9 @@ public class AtmosBlobStore extends BaseBlobStore {
ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
BlobStoreListOptionsToListOptions container2ContainerListOptions, BlobStoreListOptionsToListOptions container2ContainerListOptions,
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto, DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider) { BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
super(context, blobUtils, defaultLocation, locations); SignRequestForBlobStrategy signRequestForBlob) {
super(context, blobUtils, defaultLocation, locations, signRequestForBlob);
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.sync = checkNotNull(sync, "sync"); this.sync = checkNotNull(sync, "sync");
this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions, this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions,

View File

@ -28,6 +28,7 @@ import org.jclouds.atmosonline.saas.AtmosStorageClient;
import org.jclouds.atmosonline.saas.blobstore.AtmosAsyncBlobStore; import org.jclouds.atmosonline.saas.blobstore.AtmosAsyncBlobStore;
import org.jclouds.atmosonline.saas.blobstore.AtmosBlobStore; import org.jclouds.atmosonline.saas.blobstore.AtmosBlobStore;
import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata; import org.jclouds.atmosonline.saas.blobstore.strategy.FindMD5InUserMetadata;
import org.jclouds.atmosonline.saas.blobstore.strategy.SignReadFile;
import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
@ -35,6 +36,7 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule; import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
@ -65,6 +67,7 @@ public class AtmosBlobStoreContextModule extends AbstractModule {
new TypeLiteral<BlobStoreContextImpl<AtmosStorageClient, AtmosStorageAsyncClient>>() { new TypeLiteral<BlobStoreContextImpl<AtmosStorageClient, AtmosStorageAsyncClient>>() {
}).in(Scopes.SINGLETON); }).in(Scopes.SINGLETON);
bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class); bind(ContainsValueInListStrategy.class).to(FindMD5InUserMetadata.class);
bind(SignRequestForBlobStrategy.class).to(SignReadFile.class);
} }
@Provides @Provides

View File

@ -0,0 +1,66 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.atmosonline.saas.blobstore.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.lang.reflect.Method;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.common.collect.ImmutableMultimap;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SignReadFile implements SignRequestForBlobStrategy {
private final RestAnnotationProcessor<AtmosStorageAsyncClient> processor;
private final Method method;
@Inject
public SignReadFile(RestAnnotationProcessor<AtmosStorageAsyncClient> processor) throws SecurityException,
NoSuchMethodException {
this.processor = checkNotNull(processor, "processor");
this.method = AtmosStorageAsyncClient.class.getMethod("readFile", String.class, GetOptions[].class);
}
@Override
public HttpRequest apply(String container, String name) {
GeneratedHttpRequest<AtmosStorageAsyncClient> returnVal = processor.createRequest(method, checkNotNull(container,
"container")
+ "/" + checkNotNull(name, "name"));
for (HttpRequestFilter filter : returnVal.getFilters())
filter.filter(returnVal);
return new HttpRequest(returnVal.getMethod(), returnVal.getEndpoint(), ImmutableMultimap.copyOf(returnVal
.getHeaders()));
}
}

View File

@ -182,8 +182,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
} }
public void testReadFile() throws SecurityException, NoSuchMethodException, IOException { public void testReadFile() throws SecurityException, NoSuchMethodException, IOException {
Method method = AtmosStorageAsyncClient.class.getMethod("readFile", String.class, Array.newInstance( Method method = AtmosStorageAsyncClient.class.getMethod("readFile", String.class, GetOptions[].class);
GetOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "dir/file"); HttpRequest request = processor.createRequest(method, "dir/file");
assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1"); assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");

View File

@ -0,0 +1,97 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.atmosonline.saas.blobstore.integration;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.atmosonline.saas.AtmosStorageAsyncClient;
import org.jclouds.atmosonline.saas.blobstore.strategy.SignReadFile;
import org.jclouds.atmosonline.saas.config.AtmosStorageRestClientModule;
import org.jclouds.atmosonline.saas.filters.SignRequest;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "emcsaas.SignReadFileTest")
public class SignReadFileTest extends RestClientTest<AtmosStorageAsyncClient> {
public void testSignReadFile() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
HttpRequest request = new SignReadFile(processor).apply("container", "name");
assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/container/name HTTP/1.1");
assertNonPayloadHeadersEqual(
request,
"Accept: */*\nDate: Thu, 05 Jun 2008 16:38:19 GMT\nx-emc-signature: Mhe5tqaKv04BlMvEjreNKkHHxzk=\nx-emc-uid: identity\n");
assertPayloadEquals(request, null, null, false);
assertEquals(request.getFilters().size(), 0);
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), SignRequest.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<AtmosStorageAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<AtmosStorageAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new TestAtmosStorageRestClientModule();
}
@RequiresHttp
@ConfiguresRestClient
private static final class TestAtmosStorageRestClientModule extends AtmosStorageRestClientModule {
@Override
protected void configure() {
super.configure();
}
@Override
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return "Thu, 05 Jun 2008 16:38:19 GMT";
}
}
@Override
public ContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("atmosonline", "identity", "credential", new Properties());
}
}

View File

@ -54,13 +54,12 @@ import org.jclouds.aws.ec2.compute.strategy.EC2ListNodesStrategy;
import org.jclouds.aws.ec2.compute.strategy.EC2LoadBalanceNodesStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2LoadBalanceNodesStrategy;
import org.jclouds.aws.ec2.compute.strategy.EC2RebootNodeStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2RebootNodeStrategy;
import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy;
import org.jclouds.aws.ec2.compute.suppliers.EC2LocationSupplier;
import org.jclouds.aws.ec2.compute.suppliers.EC2HardwareSupplier; import org.jclouds.aws.ec2.compute.suppliers.EC2HardwareSupplier;
import org.jclouds.aws.ec2.compute.suppliers.EC2LocationSupplier;
import org.jclouds.aws.ec2.compute.suppliers.RegionAndNameToImageSupplier; import org.jclouds.aws.ec2.compute.suppliers.RegionAndNameToImageSupplier;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.PlacementGroup; import org.jclouds.aws.ec2.domain.PlacementGroup;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.functions.RunningInstanceToStorageMappingUnix;
import org.jclouds.aws.ec2.predicates.InstancePresent; import org.jclouds.aws.ec2.predicates.InstancePresent;
import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable; import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable;
import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted; import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted;
@ -69,8 +68,8 @@ import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -99,7 +98,6 @@ import com.google.inject.Key;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Scopes; import com.google.inject.Scopes;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
/** /**
* Configures the {@link ComputeServiceContext}; requires {@link EC2ComputeService} bound. * Configures the {@link ComputeServiceContext}; requires {@link EC2ComputeService} bound.
@ -148,8 +146,6 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
bind(GetNodeMetadataStrategy.class).to(EC2GetNodeMetadataStrategy.class); bind(GetNodeMetadataStrategy.class).to(EC2GetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class); bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class); bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class);
bind(new TypeLiteral<Function<RunningInstance, Map<String, String>>>() {
}).annotatedWith(Names.named("volumeMapping")).to(RunningInstanceToStorageMappingUnix.class).in(Scopes.SINGLETON);
} }
@Provides @Provides
@ -169,8 +165,8 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
@Override @Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
String region = injector.getInstance(Key.get(String.class, Region.class)); String region = injector.getInstance(Key.get(String.class, Region.class));
return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest() : template.osFamily( return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest() : template.osFamily(UBUNTU)
UBUNTU).osVersionMatches("10.04").os64Bit(true).osDescriptionMatches(".*ubuntu-images.*"); .osVersionMatches("10.04").os64Bit(true).osDescriptionMatches(".*ubuntu-images.*");
} }
@Provides @Provides

View File

@ -30,7 +30,9 @@ import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.RootDeviceType;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -40,6 +42,9 @@ import com.google.common.collect.ImmutableMap;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
* @see <a
* href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html"
* />
*/ */
public class EC2Hardware extends HardwareImpl { public class EC2Hardware extends HardwareImpl {
/** The serialVersionUID */ /** The serialVersionUID */
@ -68,23 +73,24 @@ public class EC2Hardware extends HardwareImpl {
}; };
} }
EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram, Integer disk, EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram,
RootDeviceType rootDeviceType) { Iterable<? extends Volume> volumes, RootDeviceType rootDeviceType) {
super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), processors, ram, super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), processors, ram,
disk, hasRootDeviceType(rootDeviceType)); volumes, hasRootDeviceType(rootDeviceType));
this.instanceType = instanceType; this.instanceType = instanceType;
} }
EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram, Integer disk, boolean is64Bit) { EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram,
Iterable<? extends Volume> volumes, boolean is64Bit) {
super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), processors, ram, super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), processors, ram,
disk, is64Bit ? is64Bit() : not(is64Bit())); volumes, is64Bit ? is64Bit() : not(is64Bit()));
this.instanceType = instanceType; this.instanceType = instanceType;
} }
public EC2Hardware(Location location, String instanceType, Iterable<? extends Processor> processors, Integer ram, public EC2Hardware(Location location, String instanceType, Iterable<? extends Processor> processors, Integer ram,
Integer disk, String[] ids) { Iterable<? extends Volume> volumes, String[] ids) {
super(instanceType, instanceType, instanceType, location, null, ImmutableMap.<String, String> of(), processors, super(instanceType, instanceType, instanceType, location, null, ImmutableMap.<String, String> of(), processors,
ram, disk, (ids.length == 0 ? is64Bit() : idIn(Arrays.asList(ids)))); ram, volumes, (ids.length == 0 ? is64Bit() : idIn(Arrays.asList(ids))));
this.instanceType = instanceType; this.instanceType = instanceType;
} }
@ -99,48 +105,59 @@ public class EC2Hardware extends HardwareImpl {
* @see InstanceType#M1_SMALL * @see InstanceType#M1_SMALL
*/ */
public static final EC2Hardware M1_SMALL = new EC2Hardware(InstanceType.M1_SMALL, ImmutableList.of(new Processor( public static final EC2Hardware M1_SMALL = new EC2Hardware(InstanceType.M1_SMALL, ImmutableList.of(new Processor(
1.0, 1.0)), 1740, 160, false); 1.0, 1.0)), 1740, ImmutableList.of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(150.0f,
"/dev/sda2", false, false)), false);
/** /**
* @see InstanceType#T1_MICRO * @see InstanceType#T1_MICRO
*/ */
public static final EC2Hardware T1_MICRO = new EC2Hardware(InstanceType.T1_MICRO, ImmutableList.of(new Processor( public static final EC2Hardware T1_MICRO = new EC2Hardware(InstanceType.T1_MICRO, ImmutableList.of(new Processor(
1.0, 1.0)), 630, 0, RootDeviceType.EBS); 1.0, 1.0)), 630, ImmutableList.<Volume> of(), RootDeviceType.EBS);
/** /**
* @see InstanceType#M1_LARGE * @see InstanceType#M1_LARGE
*/ */
public static final EC2Hardware M1_LARGE = new EC2Hardware(InstanceType.M1_LARGE, ImmutableList.of(new Processor( public static final EC2Hardware M1_LARGE = new EC2Hardware(InstanceType.M1_LARGE, ImmutableList.of(new Processor(
2.0, 2.0)), 7680, 850, true); 2.0, 2.0)), 7680, ImmutableList.of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(420.0f,
"/dev/sdb", false, false), new VolumeImpl(420.0f, "/dev/sdc", false, false)), true);
/** /**
* @see InstanceType#M1_XLARGE * @see InstanceType#M1_XLARGE
*/ */
public static final EC2Hardware M1_XLARGE = new EC2Hardware(InstanceType.M1_XLARGE, ImmutableList.of(new Processor( public static final EC2Hardware M1_XLARGE = new EC2Hardware(InstanceType.M1_XLARGE, ImmutableList.of(new Processor(
4.0, 2.0)), 15360, 1690, true); 4.0, 2.0)), 15360, ImmutableList.of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(420.0f,
"/dev/sdb", false, false), new VolumeImpl(420.0f, "/dev/sdc", false, false), new VolumeImpl(420.0f,
"/dev/sdd", false, false), new VolumeImpl(420.0f, "/dev/sde", false, false)), true);
/** /**
* @see InstanceType#M2_XLARGE * @see InstanceType#M2_XLARGE
*/ */
public static final EC2Hardware M2_XLARGE = new EC2Hardware(InstanceType.M2_XLARGE, ImmutableList.of(new Processor( public static final EC2Hardware M2_XLARGE = new EC2Hardware(InstanceType.M2_XLARGE, ImmutableList.of(new Processor(
2.0, 3.25)), 17510, 420, true); 2.0, 3.25)), 17510, ImmutableList.of(new VolumeImpl(420.0f, "/dev/sda1", true, false)), true);
/** /**
* @see InstanceType#M2_2XLARGE * @see InstanceType#M2_2XLARGE
*/ */
public static final EC2Hardware M2_2XLARGE = new EC2Hardware(InstanceType.M2_2XLARGE, ImmutableList.of(new Processor( public static final EC2Hardware M2_2XLARGE = new EC2Hardware(InstanceType.M2_2XLARGE, ImmutableList
4.0, 3.25)), 35020, 850, true); .of(new Processor(4.0, 3.25)), 35020, ImmutableList.of(new VolumeImpl(10.0f, "/dev/sda1", true, false),
new VolumeImpl(840.0f, "/dev/sdb", false, false)), true);
/** /**
* @see InstanceType#M2_4XLARGE * @see InstanceType#M2_4XLARGE
*/ */
public static final EC2Hardware M2_4XLARGE = new EC2Hardware(InstanceType.M2_4XLARGE,ImmutableList.of(new Processor( public static final EC2Hardware M2_4XLARGE = new EC2Hardware(InstanceType.M2_4XLARGE, ImmutableList
8.0, 3.25)), 70041, 1690, true); .of(new Processor(8.0, 3.25)), 70041, ImmutableList.of(new VolumeImpl(10.0f, "/dev/sda1", true, false),
new VolumeImpl(840.0f, "/dev/sdb", false, false), new VolumeImpl(840.0f, "/dev/sdc", false, false)), true);
/** /**
* @see InstanceType#C1_MEDIUM * @see InstanceType#C1_MEDIUM
*/ */
public static final EC2Hardware C1_MEDIUM = new EC2Hardware(InstanceType.C1_MEDIUM, ImmutableList.of(new Processor( public static final EC2Hardware C1_MEDIUM = new EC2Hardware(InstanceType.C1_MEDIUM, ImmutableList.of(new Processor(
2.0, 2.5)), 1740, 350, false); 2.0, 2.5)), 1740, ImmutableList.of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(340.0f,
"/dev/sda2", false, false)), false);
/** /**
* @see InstanceType#C1_XLARGE * @see InstanceType#C1_XLARGE
*/ */
public static final EC2Hardware C1_XLARGE = new EC2Hardware(InstanceType.C1_XLARGE, ImmutableList.of(new Processor( public static final EC2Hardware C1_XLARGE = new EC2Hardware(InstanceType.C1_XLARGE, ImmutableList.of(new Processor(
8.0, 2.5)), 7168, 1690, true); 8.0, 2.5)), 7168, ImmutableList.of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(420.0f,
"/dev/sdb", false, false), new VolumeImpl(420.0f, "/dev/sdc", false, false), new VolumeImpl(420.0f,
"/dev/sdd", false, false), new VolumeImpl(420.0f, "/dev/sde", false, false)), true);
@Override @Override
public int hashCode() { public int hashCode() {

View File

@ -26,24 +26,30 @@ import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.RootDeviceType;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.domain.RunningInstance.EbsBlockDevice;
import org.jclouds.aws.ec2.options.DescribeImagesOptions; import org.jclouds.aws.ec2.options.DescribeImagesOptions;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -54,7 +60,6 @@ import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -76,19 +81,19 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
private final Map<RegionAndName, KeyPair> credentialsMap; private final Map<RegionAndName, KeyPair> credentialsMap;
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider; private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
private final Supplier<Set<? extends Location>> locations; private final Supplier<Set<? extends Location>> locations;
private final Function<RunningInstance, Map<String, String>> instanceToStorageMapping; private final Supplier<Set<? extends Hardware>> hardware;
private final ConcurrentMap<RegionAndName, Image> imageMap; private final ConcurrentMap<RegionAndName, Image> imageMap;
@Inject @Inject
RunningInstanceToNodeMetadata(EC2Client client, Map<RegionAndName, KeyPair> credentialsMap, RunningInstanceToNodeMetadata(EC2Client client, Map<RegionAndName, KeyPair> credentialsMap,
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
ConcurrentMap<RegionAndName, Image> imageMap, Supplier<Set<? extends Location>> locations, ConcurrentMap<RegionAndName, Image> imageMap, Supplier<Set<? extends Location>> locations,
@Named("volumeMapping") Function<RunningInstance, Map<String, String>> instanceToStorageMapping) { Supplier<Set<? extends Hardware>> hardware) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider"); this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
this.instanceToStorageMapping = checkNotNull(instanceToStorageMapping, "instanceToStorageMapping"); this.hardware = checkNotNull(hardware, "hardware");
this.imageMap = checkNotNull(imageMap, "imageMap"); this.imageMap = checkNotNull(imageMap, "imageMap");
} }
@ -110,15 +115,46 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
Set<String> publicAddresses = nullSafeSet(instance.getIpAddress()); Set<String> publicAddresses = nullSafeSet(instance.getIpAddress());
Set<String> privateAddresses = nullSafeSet(instance.getPrivateIpAddress()); Set<String> privateAddresses = nullSafeSet(instance.getPrivateIpAddress());
Map<String, String> extra = getExtra(instance); Hardware hardware = getHardwareForInstance(instance);
if (hardware != null) {
hardware = ComputeServiceUtils.replacesVolumes(hardware, addEBS(instance, hardware.getVolumes()));
}
Location location = getLocationForAvailabilityZone(instance); Location location = getLocationForAvailabilityZone(instance);
Image image = resolveImageForInstanceInLocation(instance, location); Image image = resolveImageForInstanceInLocation(instance, location);
return new NodeMetadataImpl(id, name, instance.getRegion() + "/" + instance.getId(), location, uri, userMetadata, return new NodeMetadataImpl(id, name, instance.getRegion() + "/" + instance.getId(), location, uri, userMetadata,
tag, instance.getRegion() + "/" + instance.getImageId(), image != null ? image.getOperatingSystem() tag, hardware, instance.getRegion() + "/" + instance.getImageId(), image != null ? image
: null, state, publicAddresses, privateAddresses, extra, credentials); .getOperatingSystem() : null, state, publicAddresses, privateAddresses, credentials);
}
@VisibleForTesting
static Iterable<? extends Volume> addEBS(final RunningInstance instance, Iterable<? extends Volume> volumes) {
Iterable<Volume> ebsVolumes = Iterables.transform(instance.getEbsBlockDevices().entrySet(),
new Function<Entry<String, EbsBlockDevice>, Volume>() {
@Override
public Volume apply(Entry<String, EbsBlockDevice> from) {
return new VolumeImpl(from.getValue().getVolumeId(), Volume.Type.SAN, null, from.getKey(),
instance.getRootDeviceName().equals(from.getKey()), true);
}
});
if (instance.getRootDeviceType() == RootDeviceType.EBS) {
volumes = Iterables.filter(volumes, new Predicate<Volume>() {
@Override
public boolean apply(Volume input) {
return !input.isBootDevice();
}
});
}
return Iterables.concat(volumes, ebsVolumes);
} }
private Credentials getCredentialsForInstanceWithTag(final RunningInstance instance, String tag) { private Credentials getCredentialsForInstanceWithTag(final RunningInstance instance, String tag) {
@ -152,6 +188,23 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
return tag; return tag;
} }
@VisibleForTesting
Hardware getHardwareForInstance(final RunningInstance instance) {
try {
return Iterables.find(hardware.get(), new Predicate<Hardware>() {
@Override
public boolean apply(Hardware input) {
return input.getId().equals(instance.getInstanceType());
}
});
} catch (NoSuchElementException e) {
logger.debug("couldn't match instance type %s in: %s", instance.getInstanceType(), hardware.get());
return null;
}
}
private Location getLocationForAvailabilityZone(final RunningInstance instance) { private Location getLocationForAvailabilityZone(final RunningInstance instance) {
final String locationId = instance.getAvailabilityZone(); final String locationId = instance.getAvailabilityZone();
@ -178,30 +231,6 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
return image; return image;
} }
/**
* Set extras for the node.
*
* Extras are derived from either additional API calls or hard-coded values.
*
* @param instance
* instance for which the extras are retrieved
* @return map with extras
*/
@VisibleForTesting
Map<String, String> getExtra(RunningInstance instance) {
Map<String, String> extra = Maps.newHashMap();
extra.put("virtualizationType", instance.getVirtualizationType());
if (instance.getPlacementGroup() != null)
extra.put("placementGroup", instance.getPlacementGroup());
if (instance.getSubnetId() != null)
extra.put("subnetId", instance.getSubnetId());
// put storage info
/* TODO: only valid for UNIX */
extra.putAll(instanceToStorageMapping.apply(instance));
return extra;
}
@VisibleForTesting @VisibleForTesting
String getPrivateKeyOrNull(RunningInstance instance, String tag) { String getPrivateKeyOrNull(RunningInstance instance, String tag) {
KeyPair keyPair = credentialsMap.get(new RegionAndName(instance.getRegion(), instance.getKeyName())); KeyPair keyPair = credentialsMap.get(new RegionAndName(instance.getRegion(), instance.getKeyName()));

View File

@ -34,6 +34,7 @@ import org.jclouds.aws.ec2.compute.domain.EC2Hardware;
import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.VolumeImpl;
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.LocationScope; import org.jclouds.domain.LocationScope;
@ -76,7 +77,9 @@ public class EC2HardwareSupplier implements Supplier<Set<? extends Hardware>> {
}); });
sizes.add(new EC2Hardware(location, InstanceType.CC1_4XLARGE, ImmutableList.of(new Processor(4.0, 4.0), sizes.add(new EC2Hardware(location, InstanceType.CC1_4XLARGE, ImmutableList.of(new Processor(4.0, 4.0),
new Processor(4.0, 4.0)), 23 * 1024, 1690, ccAmis)); new Processor(4.0, 4.0)), 23 * 1024, ImmutableList.of(
new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(840.0f, "/dev/sdb", false, false),
new VolumeImpl(840.0f, "/dev/sdc", false, false)), ccAmis));
} }
sizes.addAll(ImmutableSet.<Hardware> of(EC2Hardware.T1_MICRO, EC2Hardware.C1_MEDIUM, EC2Hardware.C1_XLARGE, sizes.addAll(ImmutableSet.<Hardware> of(EC2Hardware.T1_MICRO, EC2Hardware.C1_MEDIUM, EC2Hardware.C1_XLARGE,
EC2Hardware.M1_LARGE, EC2Hardware.M1_SMALL, EC2Hardware.M1_XLARGE, EC2Hardware.M2_XLARGE, EC2Hardware.M1_LARGE, EC2Hardware.M1_SMALL, EC2Hardware.M1_XLARGE, EC2Hardware.M2_XLARGE,

View File

@ -1,180 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.functions;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.RunningInstance;
import java.util.Map;
import static org.jclouds.compute.reference.ComputeServiceConstants.LOCAL_PARTITION_GB_PATTERN;
/**
* Map the instance to storage information known about it. This information is statically set as
* described by Amazon.
*
* Note that having the partitions available doesn't mean they're formatted/mounted by default. The
* links below describe what partitions are formatted initially. To format/mount an available
* device, refer to <a href="http://meinit.nl/howto-use-amazon-elastic-compute-cloud-ec2">this
* article</a>.
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/2010-06-15/UserGuide/index.html?instance-storage-concepts.html"
* />
* @see <a
* href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html"
* />
*
* @author Oleksiy Yarmula
*/
public class RunningInstanceToStorageMappingUnix implements Function<RunningInstance, Map<String, String>> {
public final static String ROOT_PARTITION_NAME_UNIX = "/dev/sda1";
@Override
public Map<String, String> apply(RunningInstance instance) {
final String instanceType = instance.getInstanceType();
Map<String, String> mapping = Maps.newHashMap();
// root partition
mapping.put(String.format(LOCAL_PARTITION_GB_PATTERN, ROOT_PARTITION_NAME_UNIX),
getRootPartitionSizeForInstanceType(instanceType) + "");
// primary partition (always formatted/mounted)
mapping.put(String.format(LOCAL_PARTITION_GB_PATTERN, getPrimaryPartitionDeviceName(instanceType)),
getPrimaryPartitionSizeForInstanceType(instanceType) + "");
// additional partitions if any
for (Map.Entry<String, Integer> entry : getAdditionalPartitionsMapping(instanceType).entrySet()) {
mapping.put(String.format(LOCAL_PARTITION_GB_PATTERN, entry.getKey()), entry.getValue() + "");
}
return mapping;
}
/**
* Retrieve the root partition size. Note, this is usually a rather small partition. Refer to
* {@link #getPrimaryPartitionSizeForInstanceType} to determine the size of the primary (usually,
* biggest) partition. In some cases, for large instances there are several partitions of the
* size of primary partition.
*
* @param instanceType
* for which the root partition size is to be determined
* @return size in GB
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/2010-06-15/UserGuide/index.html?instance-storage-concepts.html"
* />
* @see <a href=
* "http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html"
* />
*/
public int getRootPartitionSizeForInstanceType(String instanceType) {
/*
* per documentation at
* http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html M2
* XLARGE doesn't have the root partition TODO verify
*/
if (InstanceType.M2_XLARGE.equals(instanceType))
return 0;
// other types have 10 GB root partition
return 10;
}
public static String getPrimaryPartitionDeviceName(String instanceType) {
if (InstanceType.M1_SMALL.equals(instanceType) || InstanceType.C1_MEDIUM.equals(instanceType))
return "/dev/sda2";
return "/dev/sdb";
}
/**
* Retrieve the primary partition size.
*
* This is usually the biggest partition. In some cases, for large instances there are several
* partitions of the size of primary partition.
*
* @param instanceType
* for which the primary partition size is to be determined
* @return size in GB
*/
public static int getPrimaryPartitionSizeForInstanceType(String instanceType) {
if (InstanceType.M1_SMALL.equals(instanceType)) {
return 150;
} else if (InstanceType.C1_MEDIUM.equals(instanceType)) {
return 340;
} else if (InstanceType.M1_LARGE.equals(instanceType)) {
return 420;
} else if (InstanceType.M1_XLARGE.equals(instanceType)) {
return 420;
} else if (InstanceType.C1_XLARGE.equals(instanceType)) {
return 420;
} else if (InstanceType.M2_XLARGE.equals(instanceType)) {
return 420;
} else if (InstanceType.M2_2XLARGE.equals(instanceType)) {
return 840;
} else if (InstanceType.M2_4XLARGE.equals(instanceType)) {
return 840;
} else if (InstanceType.CC1_4XLARGE.equals(instanceType))
return 840;
return 150;// TODO make this more graceful
}
/**
* Retrieve additional devices mapping (non-root and non-primary) for the instance type.
*
* @param instanceType
* @return map with device name(s) and size(s) or empty map if the instance doesn't have any
* additional
*
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?concepts-amis-and-instances.html#instance-types"
* />
*/
public static Map<String, Integer> getAdditionalPartitionsMapping(String instanceType) {
Map<String, Integer> mapping = Maps.newHashMap();
int size = 0;
if (InstanceType.M1_LARGE.equals(instanceType) || InstanceType.M1_XLARGE.equals(instanceType)
|| InstanceType.C1_XLARGE.equals(instanceType)) {
size = 420;
} else if (InstanceType.M2_4XLARGE.equals(instanceType) || instanceType.startsWith("cc")) {
size = 840;
}
// m1.large, m1.xlarge, and c1.xlarge
if (InstanceType.M1_LARGE.equals(instanceType) || InstanceType.M1_XLARGE.equals(instanceType)
|| InstanceType.C1_XLARGE.equals(instanceType) || InstanceType.M2_4XLARGE.equals(instanceType)
|| instanceType.startsWith("cc")) {
mapping.put("/dev/sdc", size);
}
if (InstanceType.M1_XLARGE.equals(instanceType) || InstanceType.C1_XLARGE.equals(instanceType)) {
mapping.put("/dev/sdd", size);
}
if (InstanceType.M1_XLARGE.equals(instanceType) || InstanceType.C1_XLARGE.equals(instanceType)) {
mapping.put("/dev/sde", size);
}
return mapping;
}
}

View File

@ -53,6 +53,7 @@ import org.jclouds.blobstore.domain.internal.PageSetImpl;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.concurrent.Futures; import org.jclouds.concurrent.Futures;
@ -89,8 +90,8 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions,
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob, BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider) { Provider<FetchBlobMetadata> fetchBlobMetadataProvider, SignRequestForBlobStrategy signRequestForBlob) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, service, defaultLocation, locations, signRequestForBlob);
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.async = checkNotNull(async, "async"); this.async = checkNotNull(async, "async");
this.sync = checkNotNull(sync, "sync"); this.sync = checkNotNull(sync, "sync");

View File

@ -47,6 +47,7 @@ import org.jclouds.blobstore.domain.internal.PageSetImpl;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.internal.BaseBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -78,8 +79,8 @@ public class S3BlobStore extends BaseBlobStore {
Supplier<Set<? extends Location>> locations, S3Client sync, BucketToResourceMetadata bucket2ResourceMd, Supplier<Set<? extends Location>> locations, S3Client sync, BucketToResourceMetadata bucket2ResourceMd,
ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList, ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList,
ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider) { ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider, SignRequestForBlobStrategy signRequestForBlob) {
super(context, blobUtils, defaultLocation, locations); super(context, blobUtils, defaultLocation, locations, signRequestForBlob);
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
this.sync = checkNotNull(sync, "sync"); this.sync = checkNotNull(sync, "sync");
this.bucket2ResourceMd = checkNotNull(bucket2ResourceMd, "bucket2ResourceMd"); this.bucket2ResourceMd = checkNotNull(bucket2ResourceMd, "bucket2ResourceMd");

View File

@ -28,6 +28,7 @@ import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.aws.s3.S3Client; import org.jclouds.aws.s3.S3Client;
import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore; import org.jclouds.aws.s3.blobstore.S3AsyncBlobStore;
import org.jclouds.aws.s3.blobstore.S3BlobStore; import org.jclouds.aws.s3.blobstore.S3BlobStore;
import org.jclouds.aws.s3.blobstore.strategy.SignGetObject;
import org.jclouds.aws.suppliers.DefaultLocationSupplier; import org.jclouds.aws.suppliers.DefaultLocationSupplier;
import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
@ -35,6 +36,7 @@ import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule; import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
@ -66,6 +68,7 @@ public class S3BlobStoreContextModule extends AbstractModule {
bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON);
bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<S3Client, S3AsyncClient>>() { bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<S3Client, S3AsyncClient>>() {
}).in(Scopes.SINGLETON); }).in(Scopes.SINGLETON);
bind(SignRequestForBlobStrategy.class).to(SignGetObject.class);
} }
@Provides @Provides

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.s3.blobstore.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.lang.reflect.Method;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.s3.S3AsyncClient;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.common.collect.ImmutableMultimap;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SignGetObject implements SignRequestForBlobStrategy {
private final RestAnnotationProcessor<S3AsyncClient> processor;
private final Method method;
@Inject
public SignGetObject(RestAnnotationProcessor<S3AsyncClient> processor) throws SecurityException,
NoSuchMethodException {
this.processor = checkNotNull(processor, "processor");
this.method = S3AsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class);
}
@Override
public HttpRequest apply(String container, String name) {
GeneratedHttpRequest<S3AsyncClient> returnVal = processor.createRequest(method, checkNotNull(container,
"container"), checkNotNull(name, "name"));
for (HttpRequestFilter filter : returnVal.getFilters())
filter.filter(returnVal);
return new HttpRequest(returnVal.getMethod(), returnVal.getEndpoint(), ImmutableMultimap.copyOf(returnVal
.getHeaders()));
}
}

View File

@ -0,0 +1,93 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws;
import static org.jclouds.compute.BaseComputeServiceLiveTest.buildScript;
import static org.jclouds.compute.options.TemplateOptions.Builder.runScript;
import static org.jclouds.compute.util.ComputeServiceUtils.buildCurlsh;
import static org.jclouds.io.Payloads.newStringPayload;
import org.jclouds.aws.ec2.compute.BlobStoreAndComputeServiceLiveTest;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.http.HttpRequest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "jclouds.ComputeAndBlobStoreTogetherHappilyLiveTest")
public class ComputeAndBlobStoreTogetherHappilyLiveTest extends BlobStoreAndComputeServiceLiveTest {
protected void setupCredentials() {
blobStoreProvider = "s3";
computeServiceProvider = "ec2";
super.setupCredentials();
}
/**
* This test generates a bootstrap script based on the default operating system of the compute
* provider.
* <p/>
* It then uploads this to a blobstore, in a private location. Now, we want the bootstrap of the
* server to be able to load from this location without sending credentials to the starting
* machine. Accordingly, we send a signed url instead.
* <p/>
* Using the {@link BlobStore} api, we get a signed url corresponding to the bootstrap script. We
* next convert this into something that can be invoked via the commandline. Looking around, it
* seems like alestic runurl is pretty close. However, it is limited as it only works on requests
* that can be fully specified without headers (ex. Amazon S3). Instead, we use a variant
* (curlsh).
* <p/>
* curlsh simply assembles an http request, headers and all, and passes it to bash
* <p/>
* With this script ready, any node or nodes will take instructions from the blobstore when it
* boots up. we verify this with an assertion.
*
*/
@Test
public void testWeCanIndirectBootstrapInstructionsToAnArbitraryAndPrivateBlobStore() throws RunNodesException {
OperatingSystem defaultOperatingSystem = computeContext.getComputeService().templateBuilder().build().getImage()
.getOperatingSystem();
// using jclouds ability to detect operating systems before we launch them, we can avoid
// the bad practice of assuming everything is ubuntu.
uploadBlob(tag, "openjdk/install", buildScript(defaultOperatingSystem));
// instead of hard-coding to amazon s3, we can use any blobstore, conceding this test is
// configured for amz. Note we are getting temporary access to a private blob.
HttpRequest signedRequestOfInstallScript = blobContext.getBlobStore().signRequestForBlob(tag, "openjdk/install");
// instruct the bootstrap to pull the script from the blobstore and invoke it directly with bash.
TemplateOptions runOpenJDKInstallDirectlyFromBlobStore = runScript(newStringPayload(buildCurlsh(signedRequestOfInstallScript)));
// now that we have the correct instructions, kick-off the provisioner
Iterable<? extends NodeMetadata> nodes = computeContext.getComputeService().runNodesWithTag(tag, 1,
runOpenJDKInstallDirectlyFromBlobStore);
// ensure the bootstrap operated by checking for a known signature of success.
assertSshOutputOfCommandContains(nodes, "openjdk -version", "OpenJDK");
}
}

View File

@ -0,0 +1,112 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.get;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class BlobStoreAndComputeServiceLiveTest {
protected ComputeServiceContext computeContext;
protected BlobStoreContext blobContext;
protected String tag = System.getProperty("user.name") + "happy";
protected String identity;
protected String credential;
protected String blobStoreProvider;
protected String computeServiceProvider;
protected void setupCredentials() {
tag = System.getProperty("user.name") + "happy";
identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
computeContext = new ComputeServiceContextFactory().createContext(computeServiceProvider, identity, credential,
ImmutableSet.of(new Log4JLoggingModule(), new JschSshClientModule()));
blobContext = new BlobStoreContextFactory().createContext(blobStoreProvider, identity, credential,
ImmutableSet.of(new Log4JLoggingModule()));
blobContext.getAsyncBlobStore().createContainerInLocation(null, tag);
computeContext.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
}
protected void assertSshOutputOfCommandContains(Iterable<? extends NodeMetadata> nodes, String cmd, String expects) {
IPSocket socket = new IPSocket(get(get(nodes, 0).getPublicAddresses(), 0), 22);
SshClient ssh = computeContext.utils().sshFactory().create(socket, get(nodes, 0).getCredentials().identity,
get(nodes, 0).getCredentials().credential.getBytes());
try {
ssh.connect();
;
ExecResponse exec = ssh.exec(cmd);
assert exec.getOutput().indexOf(expects) != -1 || exec.getError().indexOf(expects) != -1 : exec;
} finally {
if (ssh != null)
ssh.disconnect();
}
}
protected void uploadBlob(String container, String name, String script) {
Blob blob = blobContext.getBlobStore().newBlob(name);
blob.setPayload(script);
blob.getPayload().setContentType("text/plain");
blobContext.getBlobStore().putBlob(container, blob);
}
@AfterGroups(groups = { "live" })
public void teardownCompute() {
if (computeContext != null) {
computeContext.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
computeContext.close();
}
}
@AfterGroups(groups = { "live" })
public void teardownBlobStore() {
if (blobContext != null) {
blobContext.getAsyncBlobStore().deleteContainer(tag);
blobContext.close();
}
}
}

View File

@ -282,7 +282,6 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
RunningInstance instance = getInstance(instanceClient, startedId); RunningInstance instance = getInstance(instanceClient, startedId);
assertEquals(instance.getSubnetId(), subnetId); assertEquals(instance.getSubnetId(), subnetId);
assertEquals(instance.getSubnetId(), Iterables.getOnlyElement(nodes).getExtra().get("subnetId"));
} finally { } finally {
if (nodeId != null) if (nodeId != null)

View File

@ -40,6 +40,7 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.compute.domain.internal.TemplateBuilderImpl; import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -57,8 +58,8 @@ import com.google.common.collect.Maps;
/** /**
* Tests compute service specifically to EC2. * Tests compute service specifically to EC2.
* *
* These tests are designed to verify the local functionality of jclouds, rather * These tests are designed to verify the local functionality of jclouds, rather than the
* than the interaction with Amazon Web Services. * interaction with Amazon Web Services.
* *
* @see EC2ComputeServiceLiveTest * @see EC2ComputeServiceLiveTest
* *
@ -68,12 +69,13 @@ public class EC2ComputeServiceTest {
private static final Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null); private static final Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null);
public static final EC2Hardware CC1_4XLARGE = new EC2Hardware(location, InstanceType.CC1_4XLARGE, ImmutableList.of( public static final EC2Hardware CC1_4XLARGE = new EC2Hardware(location, InstanceType.CC1_4XLARGE, ImmutableList.of(
new Processor(4.0, 4.0), new Processor(4.0, 4.0)), 23 * 1024, 1690, new String[] { "us-east-1/cc-image" }); new Processor(4.0, 4.0), new Processor(4.0, 4.0)), 23 * 1024, ImmutableList.of(new VolumeImpl(10.0f,
"/dev/sda1", true, false), new VolumeImpl(840.0f, "/dev/sdb", false, false), new VolumeImpl(840.0f,
"/dev/sdc", false, false)), new String[] { "us-east-1/cc-image" });
/** /**
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of * Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
* the instance, based on {@link org.jclouds.compute.domain.Hardware} from * on {@link org.jclouds.compute.domain.Hardware} from {@link EC2Hardware}.
* {@link EC2Hardware}.
* *
* Expected size: m2.xlarge * Expected size: m2.xlarge
*/ */
@ -83,8 +85,8 @@ public class EC2ComputeServiceTest {
assert template != null : "The returned template was null, but it should have a value."; assert template != null : "The returned template was null, but it should have a value.";
assert EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format( assert EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge", "Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge", String
String.valueOf(template.getHardware())); .valueOf(template.getHardware()));
} }
@Test @Test
@ -93,46 +95,44 @@ public class EC2ComputeServiceTest {
assert template != null : "The returned template was null, but it should have a value."; assert template != null : "The returned template was null, but it should have a value.";
assert CC1_4XLARGE.equals(template.getHardware()) : format( assert CC1_4XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), "Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), String
String.valueOf(template.getHardware())); .valueOf(template.getHardware()));
} }
/** /**
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of * Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
* the instance, based on physical attributes (# of cores, ram, etc). * on physical attributes (# of cores, ram, etc).
* *
* Expected size: m2.xlarge * Expected size: m2.xlarge
*/ */
@Test @Test
public void testTemplateChoiceForInstanceByAttributes() throws Exception { public void testTemplateChoiceForInstanceByAttributes() throws Exception {
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest() Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest().locationId(
.locationId("us-east-1").build(); "us-east-1").build();
assert template != null : "The returned template was null, but it should have a value."; assert template != null : "The returned template was null, but it should have a value.";
assert CC1_4XLARGE.equals(template.getHardware()) : format( assert CC1_4XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE, "Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE, String
String.valueOf(template.getHardware())); .valueOf(template.getHardware()));
} }
/** /**
* Negative test version of * Negative test version of {@link #testTemplateChoiceForInstanceByAttributes}.
* {@link #testTemplateChoiceForInstanceByAttributes}.
* *
* Verifies that {@link TemplateBuilderImpl} would not choose the * Verifies that {@link TemplateBuilderImpl} would not choose the insufficient size of the
* insufficient size of the instance, based on physical attributes (# of * instance, based on physical attributes (# of cores, ram, etc).
* cores, ram, etc).
* *
* Expected size: anything but m2.xlarge * Expected size: anything but m2.xlarge
*/ */
@Test @Test
public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception { public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception {
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest() Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest().locationId(
.locationId("us-east-1").build(); "us-east-1").build();
assert template != null : "The returned template was null, but it should have a value."; assert template != null : "The returned template was null, but it should have a value.";
assert !EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format( assert !EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", "Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", String
String.valueOf(template.getHardware())); .valueOf(template.getHardware()));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -144,10 +144,9 @@ public class EC2ComputeServiceTest {
expect(optionsProvider.get()).andReturn(defaultOptions); expect(optionsProvider.get()).andReturn(defaultOptions);
Image image = new ImageImpl("cc-image", "image", "us-east-1/cc-image", location, null, Image image = new ImageImpl("cc-image", "image", "us-east-1/cc-image", location, null, Maps
Maps.<String, String> newHashMap(), .<String, String> newHashMap(), new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true),
new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true), "description", "1.0", "description", "1.0", new Credentials("root", null));
new Credentials("root", null));
replay(optionsProvider); replay(optionsProvider);
replay(templateBuilderProvider); replay(templateBuilderProvider);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet

View File

@ -33,6 +33,7 @@ import java.util.concurrent.ConcurrentMap;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.EC2Hardware;
import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.domain.Image;
@ -40,8 +41,8 @@ import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.functions.RunningInstanceToStorageMappingUnix;
import org.jclouds.aws.ec2.services.AMIClient; import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
@ -83,6 +84,8 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -90,9 +93,6 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
expect(instance.getKeyName()).andReturn(null).atLeastOnce(); expect(instance.getKeyName()).andReturn(null).atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
expect(instance.getVirtualizationType()).andReturn("paravirtual");
expect(instance.getPlacementGroup()).andReturn(null);
expect(instance.getSubnetId()).andReturn(null);
expect(instance.getIpAddress()).andReturn("127.0.0.1"); expect(instance.getIpAddress()).andReturn("127.0.0.1");
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
@ -115,7 +115,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, new RunningInstanceToStorageMappingUnix()); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -145,6 +145,8 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -152,9 +154,6 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
expect(instance.getKeyName()).andReturn(null).atLeastOnce(); expect(instance.getKeyName()).andReturn(null).atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
expect(instance.getVirtualizationType()).andReturn("paravirtual");
expect(instance.getPlacementGroup()).andReturn(null);
expect(instance.getSubnetId()).andReturn(null);
expect(instance.getIpAddress()).andReturn("127.0.0.1"); expect(instance.getIpAddress()).andReturn("127.0.0.1");
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
@ -178,7 +177,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, new RunningInstanceToStorageMappingUnix()); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -208,6 +207,8 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -215,9 +216,6 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
expect(instance.getKeyName()).andReturn(null).atLeastOnce(); expect(instance.getKeyName()).andReturn(null).atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
expect(instance.getVirtualizationType()).andReturn("paravirtual");
expect(instance.getPlacementGroup()).andReturn(null);
expect(instance.getSubnetId()).andReturn(null);
expect(instance.getIpAddress()).andReturn("127.0.0.1"); expect(instance.getIpAddress()).andReturn("127.0.0.1");
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
@ -245,7 +243,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, new RunningInstanceToStorageMappingUnix()); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -276,6 +274,8 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -284,9 +284,6 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
expect(instance.getKeyName()).andReturn(null).atLeastOnce(); expect(instance.getKeyName()).andReturn(null).atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
expect(instance.getVirtualizationType()).andReturn("paravirtual");
expect(instance.getPlacementGroup()).andReturn(null);
expect(instance.getSubnetId()).andReturn(null);
expect(instance.getIpAddress()).andReturn("127.0.0.1"); expect(instance.getIpAddress()).andReturn("127.0.0.1");
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
@ -309,7 +306,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, new RunningInstanceToStorageMappingUnix()); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -338,6 +335,8 @@ public class RunningInstanceToNodeMetadataTest {
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
@ -346,9 +345,6 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag#us-east-1")).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag#us-east-1")).atLeastOnce();
expect(instance.getKeyName()).andReturn(null).atLeastOnce(); expect(instance.getKeyName()).andReturn(null).atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
expect(instance.getVirtualizationType()).andReturn("paravirtual");
expect(instance.getPlacementGroup()).andReturn(null);
expect(instance.getSubnetId()).andReturn(null);
expect(instance.getIpAddress()).andReturn("127.0.0.1"); expect(instance.getIpAddress()).andReturn("127.0.0.1");
expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
@ -371,7 +367,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(instance); replay(instance);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, new RunningInstanceToStorageMappingUnix()); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getLocation(), locations.get().iterator().next()); assertEquals(metadata.getLocation(), locations.get().iterator().next());
@ -396,7 +392,8 @@ public class RunningInstanceToNodeMetadataTest {
expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class); ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
Image image = createMock(Image.class); Image image = createMock(Image.class);
@ -405,9 +402,6 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag#us-east-1")).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag#us-east-1")).atLeastOnce();
expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce(); expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
expect(instance.getVirtualizationType()).andReturn("paravirtual");
expect(instance.getPlacementGroup()).andReturn(null);
expect(instance.getSubnetId()).andReturn(null);
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
@ -445,7 +439,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(jcImage); replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, new RunningInstanceToStorageMappingUnix()); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);
assertEquals(metadata.getTag(), "tag"); assertEquals(metadata.getTag(), "tag");
@ -472,7 +466,8 @@ public class RunningInstanceToNodeMetadataTest {
expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class); Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class); ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(EC2Hardware.M2_4XLARGE));
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
Image image = createMock(Image.class); Image image = createMock(Image.class);
@ -481,9 +476,6 @@ public class RunningInstanceToNodeMetadataTest {
expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds1", "jclouds2")).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds1", "jclouds2")).atLeastOnce();
expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce(); expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
expect(instance.getVirtualizationType()).andReturn("paravirtual");
expect(instance.getPlacementGroup()).andReturn(null);
expect(instance.getSubnetId()).andReturn(null);
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
@ -521,7 +513,7 @@ public class RunningInstanceToNodeMetadataTest {
replay(jcImage); replay(jcImage);
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap,
credentialProvider, imageMap, locations, new RunningInstanceToStorageMappingUnix()); credentialProvider, imageMap, locations, hardwares);
NodeMetadata metadata = parser.apply(instance); NodeMetadata metadata = parser.apply(instance);

View File

@ -33,11 +33,12 @@ import javax.inject.Provider;
import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions; import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.domain.internal.TemplateBuilderImpl; import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.domain.internal.TemplateBuilderImplTest; import org.jclouds.compute.domain.internal.TemplateBuilderImplTest;
@ -72,8 +73,8 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
@Override @Override
protected EC2TemplateBuilderImpl createTemplateBuilder(final Image knownImage, protected EC2TemplateBuilderImpl createTemplateBuilder(final Image knownImage,
Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images, Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
Supplier<Set<? extends Hardware>> sizes, Location defaultLocation, Provider<TemplateOptions> optionsProvider, Supplier<Set<? extends Hardware>> sizes, Location defaultLocation,
Provider<TemplateBuilder> templateBuilderProvider) { Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) {
final RegionAndName knownRegionAndName = new RegionAndName("region", "ami"); final RegionAndName knownRegionAndName = new RegionAndName("region", "ami");
ConcurrentMap<RegionAndName, Image> imageMap = new MapMaker() ConcurrentMap<RegionAndName, Image> imageMap = new MapMaker()
@ -99,8 +100,9 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(Sets Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(Sets
.<Image> newLinkedHashSet()); .<Image> newLinkedHashSet());
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(new HardwareImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(), .<Hardware> of(new HardwareImpl("1", "1", "region/1", location, null,
ImmutableList.of(new Processor(1, 1.0)), 1, 1, ImagePredicates.any()))); ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1, 1.0)), 1, ImmutableList
.<Volume> of(), ImagePredicates.any())));
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
@ -152,8 +154,9 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(new HardwareImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(), .<Hardware> of(new HardwareImpl("1", "1", "region/1", location, null,
ImmutableList.of(new Processor(1, 1.0)), 1, 1, ImagePredicates.any()))); ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1, 1.0)), 1, ImmutableList
.<Volume> of(), ImagePredicates.any())));
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
@ -190,8 +193,9 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(new HardwareImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(), .<Hardware> of(new HardwareImpl("1", "1", "region/1", location, null,
ImmutableList.of(new Processor(1, 1.0)), 1, 1, ImagePredicates.any()))); ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1, 1.0)), 1, ImmutableList
.<Volume> of(), ImagePredicates.any())));
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);

View File

@ -1,71 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.functions;
import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.testng.annotations.Test;
import java.util.Map;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
/**
* @author Oleksiy Yarmula
*/
public class RunningInstanceToStorageMappingUnixTest {
@Test
public void testMappingForM1LargeInstance() {
RunningInstanceToStorageMappingUnix volumeMapping = new RunningInstanceToStorageMappingUnix();
RunningInstance instance = createMock(RunningInstance.class);
expect(instance.getInstanceType()).andStubReturn(InstanceType.M1_LARGE);
replay(instance);
Map<String, String> mappingReturned = volumeMapping.apply(instance);
assert mappingReturned.size() == 3 : String.format(
"Expected size of mapping devices: %d. Found: %d", 3, mappingReturned.size());
assert mappingReturned.containsKey("disk_drive//dev/sda1/gb");
assert mappingReturned.containsKey("disk_drive//dev/sdb/gb");
assert mappingReturned.containsKey("disk_drive//dev/sdc/gb");
}
@Test
public void testMappingForM1XLargeInstance() {
RunningInstanceToStorageMappingUnix volumeMapping = new RunningInstanceToStorageMappingUnix();
RunningInstance instance = createMock(RunningInstance.class);
expect(instance.getInstanceType()).andStubReturn(InstanceType.M1_XLARGE);
replay(instance);
Map<String, String> mappingReturned = volumeMapping.apply(instance);
assert mappingReturned.size() == 5 : String.format(
"Expected size of mapping devices: %d. Found: %d", 5, mappingReturned.size());
assert mappingReturned.containsKey("disk_drive//dev/sda1/gb");
assert mappingReturned.containsKey("disk_drive//dev/sdb/gb");
assert mappingReturned.containsKey("disk_drive//dev/sdc/gb");
assert mappingReturned.containsKey("disk_drive//dev/sdd/gb");
assert mappingReturned.containsKey("disk_drive//dev/sde/gb");
}
}

View File

@ -35,7 +35,6 @@ import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.PlacementGroup; import org.jclouds.aws.ec2.domain.PlacementGroup;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.domain.PlacementGroup.State; import org.jclouds.aws.ec2.domain.PlacementGroup.State;
import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable; import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable;
import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted; import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted;
@ -43,9 +42,9 @@ import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.RunNodesException; import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
@ -176,10 +175,8 @@ public class PlacementGroupClientLiveTest {
Set<? extends NodeMetadata> nodes = context.getComputeService().runNodesWithTag(tag, 1, template); Set<? extends NodeMetadata> nodes = context.getComputeService().runNodesWithTag(tag, 1, template);
NodeMetadata node = Iterables.getOnlyElement(nodes); NodeMetadata node = Iterables.getOnlyElement(nodes);
RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices() Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null,
.describeInstancesInRegion(null, node.getProviderId()))); node.getProviderId())));
assertEquals(instance.getVirtualizationType(), node.getExtra().get("virtualizationType"));
assertEquals(instance.getPlacementGroup(), node.getExtra().get("placementGroup"));
} catch (RunNodesException e) { } catch (RunNodesException e) {
System.err.println(e.getNodeErrors().keySet()); System.err.println(e.getNodeErrors().keySet());

View File

@ -270,8 +270,7 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
public void testGetObject() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException, public void testGetObject() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = S3AsyncClient.class.getMethod("getObject", String.class, String.class, Array.newInstance( Method method = S3AsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class);
GetOptions.class, 0).getClass());
HttpRequest request = processor.createRequest(method, "bucket", "object"); HttpRequest request = processor.createRequest(method, "bucket", "object");
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1");

View File

@ -0,0 +1,76 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.aws.s3.blobstore.strategy;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.aws.s3.BaseS3AsyncClientTest;
import org.jclouds.aws.s3.config.S3RestClientModule;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.Module;
/**
* Tests behavior of {@code SignGetObject}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "s3.SignGetObjectTest")
public class SignGetObjectTest extends BaseS3AsyncClientTest {
public void testSignGetObject() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
HttpRequest request = new SignGetObject(processor).apply( "bucket", "object");
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Authorization: AWS identity:1UqxCBECNncBHUhxJ3Y/Q1O3IiA=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(request, null, null, false);
assertEquals(request.getFilters().size(), 0);
}
@RequiresHttp
@ConfiguresRestClient
protected static final class TestS3RestClientModule extends S3RestClientModule {
@Override
protected void configure() {
super.configure();
}
@Override
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return "2009-11-08T15:54:08.897Z";
}
}
@Override
protected Module createModule() {
return new TestS3RestClientModule();
}
}

View File

@ -52,6 +52,7 @@ import org.jclouds.blobstore.domain.internal.PageSetImpl;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.concurrent.Futures; import org.jclouds.concurrent.Futures;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -84,8 +85,8 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions, ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob, ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
BlobToAzureBlob blob2AzureBlob, BlobPropertiesToBlobMetadata blob2BlobMd, BlobToAzureBlob blob2AzureBlob, BlobPropertiesToBlobMetadata blob2BlobMd,
BlobToHttpGetOptions blob2ObjectGetOptions) { BlobToHttpGetOptions blob2ObjectGetOptions, SignRequestForBlobStrategy signRequestForBlob) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, service, defaultLocation, locations, signRequestForBlob);
this.async = checkNotNull(async, "async"); this.async = checkNotNull(async, "async");
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd"); this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions, this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions,

View File

@ -46,6 +46,7 @@ import org.jclouds.blobstore.domain.internal.PageSetImpl;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.internal.BaseBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
@ -75,8 +76,8 @@ public class AzureBlobStore extends BaseBlobStore {
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions, ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob, ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
BlobToAzureBlob blob2AzureBlob, BlobPropertiesToBlobMetadata blob2BlobMd, BlobToAzureBlob blob2AzureBlob, BlobPropertiesToBlobMetadata blob2BlobMd,
BlobToHttpGetOptions blob2ObjectGetOptions) { BlobToHttpGetOptions blob2ObjectGetOptions, SignRequestForBlobStrategy signRequestForBlob) {
super(context, blobUtils, defaultLocation, locations); super(context, blobUtils, defaultLocation, locations, signRequestForBlob);
this.sync = checkNotNull(sync, "sync"); this.sync = checkNotNull(sync, "sync");
this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd"); this.container2ResourceMd = checkNotNull(container2ResourceMd, "container2ResourceMd");
this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions, this.blobStore2AzureContainerListOptions = checkNotNull(blobStore2AzureContainerListOptions,

View File

@ -28,6 +28,7 @@ import org.jclouds.azure.storage.blob.AzureBlobClient;
import org.jclouds.azure.storage.blob.blobstore.AzureAsyncBlobStore; import org.jclouds.azure.storage.blob.blobstore.AzureAsyncBlobStore;
import org.jclouds.azure.storage.blob.blobstore.AzureBlobStore; import org.jclouds.azure.storage.blob.blobstore.AzureBlobStore;
import org.jclouds.azure.storage.blob.blobstore.strategy.FindMD5InBlobProperties; import org.jclouds.azure.storage.blob.blobstore.strategy.FindMD5InBlobProperties;
import org.jclouds.azure.storage.blob.blobstore.strategy.SignGetBlob;
import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
@ -35,6 +36,7 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule; import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy; import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
@ -64,6 +66,7 @@ public class AzureBlobStoreContextModule extends AbstractModule {
bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<AzureBlobClient, AzureBlobAsyncClient>>() { bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<AzureBlobClient, AzureBlobAsyncClient>>() {
}).in(Scopes.SINGLETON); }).in(Scopes.SINGLETON);
bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class); bind(ContainsValueInListStrategy.class).to(FindMD5InBlobProperties.class);
bind(SignRequestForBlobStrategy.class).to(SignGetBlob.class);
} }
@Provides @Provides

View File

@ -0,0 +1,64 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.azure.storage.blob.blobstore.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.lang.reflect.Method;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.common.collect.ImmutableMultimap;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SignGetBlob implements SignRequestForBlobStrategy {
private final RestAnnotationProcessor<AzureBlobAsyncClient> processor;
private final Method method;
@Inject
public SignGetBlob(RestAnnotationProcessor<AzureBlobAsyncClient> processor) throws SecurityException,
NoSuchMethodException {
this.processor = checkNotNull(processor, "processor");
this.method = AzureBlobAsyncClient.class.getMethod("getBlob", String.class, String.class, GetOptions[].class);
}
@Override
public HttpRequest apply(String container, String name) {
HttpRequest returnVal = processor.createRequest(method, checkNotNull(container,
"container"), checkNotNull(name, "name"));
for (HttpRequestFilter filter : returnVal.getFilters())
filter.filter(returnVal);
returnVal.getFilters().clear();
return new HttpRequest(returnVal.getMethod(), returnVal.getEndpoint(), ImmutableMultimap.copyOf(returnVal.getHeaders()));
}
}

View File

@ -28,6 +28,7 @@ import java.lang.reflect.Method;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.jclouds.azure.storage.blob.functions.ParseBlobFromHeadersAndHttpContent;
import org.jclouds.azure.storage.blob.functions.ParseContainerPropertiesFromHeaders; import org.jclouds.azure.storage.blob.functions.ParseContainerPropertiesFromHeaders;
import org.jclouds.azure.storage.blob.functions.ReturnFalseIfContainerAlreadyExists; import org.jclouds.azure.storage.blob.functions.ReturnFalseIfContainerAlreadyExists;
import org.jclouds.azure.storage.blob.options.CreateContainerOptions; import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
@ -37,11 +38,13 @@ import org.jclouds.azure.storage.blob.xml.ContainerNameEnumerationResultsHandler
import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication; import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
import org.jclouds.azure.storage.options.ListOptions; import org.jclouds.azure.storage.options.ListOptions;
import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound; import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound;
import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.ReturnTrueOn404; import org.jclouds.http.functions.ReturnTrueOn404;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec; import org.jclouds.rest.RestContextFactory.ContextSpec;
@ -153,8 +156,7 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
Method method = AzureBlobAsyncClient.class.getMethod("deleteRootContainer"); Method method = AzureBlobAsyncClient.class.getMethod("deleteRootContainer");
HttpRequest request = processor.createRequest(method); HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, assertRequestLineEquals(request, "DELETE https://identity.blob.core.windows.net/$root?restype=container HTTP/1.1");
"DELETE https://identity.blob.core.windows.net/$root?restype=container HTTP/1.1");
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n"); assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
@ -235,6 +237,19 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
} }
public void testGetBlob() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureBlobAsyncClient.class.getMethod("getBlob", String.class, String.class, GetOptions[].class);
HttpRequest request = processor.createRequest(method, "container", "blob");
assertRequestLineEquals(request, "GET https://identity.blob.core.windows.net/container/blob HTTP/1.1");
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseBlobFromHeadersAndHttpContent.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class);
}
public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException, IOException { public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException, IOException {
Method method = AzureBlobAsyncClient.class.getMethod("setBlobMetadata", String.class, String.class, Map.class); Method method = AzureBlobAsyncClient.class.getMethod("setBlobMetadata", String.class, String.class, Map.class);
HttpRequest request = processor.createRequest(method, "container", "blob", ImmutableMap.of("key", "value")); HttpRequest request = processor.createRequest(method, "container", "blob", ImmutableMap.of("key", "value"));

View File

@ -0,0 +1,102 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.azure.storage.blob.blobstore.config;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.azure.storage.blob.AzureBlobAsyncClient;
import org.jclouds.azure.storage.blob.blobstore.strategy.SignGetBlob;
import org.jclouds.azure.storage.blob.config.AzureBlobRestClientModule;
import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code SignGetBlob}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "azureblob.SignGetBlobTest")
public class SignGetBlobTest extends RestClientTest<AzureBlobAsyncClient> {
public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
HttpRequest request = new SignGetBlob(processor).apply("container", "blob");
assertRequestLineEquals(request, "GET https://identity.blob.core.windows.net/container/blob HTTP/1.1");
assertNonPayloadHeadersEqual(
request,
"Authorization: SharedKeyLite identity:bX3fHsuXQQEzvLey2TD76FcDDvDIHZpgSX2j5oH4Iy8=\nDate: 2009-11-08T15:54:08.897Z\nx-ms-version: 2009-09-19\n");
assertPayloadEquals(request, null, null, false);
assertEquals(request.getFilters().size(), 0);
}
@RequiresHttp
@ConfiguresRestClient
protected static final class TestAzureBlobRestClientModule extends AzureBlobRestClientModule {
@Override
protected void configure() {
super.configure();
}
@Override
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return "2009-11-08T15:54:08.897Z";
}
}
@Override
protected Module createModule() {
return new TestAzureBlobRestClientModule();
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<AzureBlobAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<AzureBlobAsyncClient>>() {
};
}
@Override
public ContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("azureblob", "identity", "credential", new Properties());
}
}

View File

@ -238,6 +238,14 @@ Options can also be specified for extension modules
([container-name path #^BlobStore blobstore] ([container-name path #^BlobStore blobstore]
(.getBlob blobstore container-name path))) (.getBlob blobstore container-name path)))
(defn sign-blob-request
"Get a signed http request for a blob, so that you can retrieve it
in another application. ex. curl"
([container-name path]
(sign-blob-request container-name path *blobstore*))
([container-name path #^BlobStore blobstore]
(.signRequestForBlob blobstore container-name path)))
(defn get-blob-stream (defn get-blob-stream
"Get an inputstream from the blob at a given path" "Get an inputstream from the blob at a given path"
([container-name path] ([container-name path]

View File

@ -31,6 +31,7 @@ import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.GetOptions; import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.HttpRequest;
/** /**
* Provides hooks needed to run a blob store asynchronously * Provides hooks needed to run a blob store asynchronously
@ -48,6 +49,11 @@ public interface AsyncBlobStore {
*/ */
Blob newBlob(String name); Blob newBlob(String name);
/**
* @see BlobStore#signRequestForBlob
*/
HttpRequest signRequestForBlob(String container, String name);
/** /**
* @see BlobStore#listAssignableLocations * @see BlobStore#listAssignableLocations
*/ */

View File

@ -30,6 +30,7 @@ import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.GetOptions; import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.HttpRequest;
/** /**
* Synchronous access to a BlobStore such as Amazon S3 * Synchronous access to a BlobStore such as Amazon S3
@ -50,6 +51,19 @@ public interface BlobStore {
*/ */
Blob newBlob(String name); Blob newBlob(String name);
/**
* gets a signed request, including headers as necessary, to access a blob from an external
* client.
*
* @param container
* container where the blob resides
* @param directory
* full path to the blob
* @throws UnsupportedOperationException
* if not supported by the provider
*/
HttpRequest signRequestForBlob(String container, String name);
/** /**
* The get locations command returns all the valid locations for containers. A location has a * The get locations command returns all the valid locations for containers. A location has a
* scope, which is typically region or zone. A region is a general area, like eu-west, where a * scope, which is typically region or zone. A region is a general area, like eu-west, where a

View File

@ -77,6 +77,7 @@ import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
import org.jclouds.blobstore.options.GetOptions; import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy; import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.crypto.Crypto; import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.CryptoStreams; import org.jclouds.crypto.CryptoStreams;
@ -124,8 +125,8 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
HttpGetOptionsListToGetOptions httpGetOptionsConverter, HttpGetOptionsListToGetOptions httpGetOptionsConverter,
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobUtils blobUtils, IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
Supplier<Set<? extends Location>> locations) { Supplier<Set<? extends Location>> locations, SignRequestForBlobStrategy signRequestForBlob) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, service, defaultLocation, locations, signRequestForBlob);
this.blobFactory = blobFactory; this.blobFactory = blobFactory;
this.dateService = dateService; this.dateService = dateService;
this.crypto = crypto; this.crypto = crypto;

View File

@ -37,9 +37,11 @@ import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.PageSet; import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.blobstore.util.internal.BlobUtilsImpl; import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.HttpRequest;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -57,16 +59,18 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
protected final ExecutorService service; protected final ExecutorService service;
protected final Supplier<Location> defaultLocation; protected final Supplier<Location> defaultLocation;
protected final Supplier<Set<? extends Location>> locations; protected final Supplier<Set<? extends Location>> locations;
protected final SignRequestForBlobStrategy signRequestForBlob;
@Inject @Inject
protected BaseAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, protected BaseAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
Supplier<Set<? extends Location>> locations) { Supplier<Set<? extends Location>> locations, SignRequestForBlobStrategy signRequestForBlob) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.blobUtils = checkNotNull(blobUtils, "blobUtils"); this.blobUtils = checkNotNull(blobUtils, "blobUtils");
this.service = checkNotNull(service, "service"); this.service = checkNotNull(service, "service");
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
this.signRequestForBlob = checkNotNull(signRequestForBlob, "signRequestForBlob");
} }
@Override @Override
@ -266,4 +270,9 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
} }
protected abstract boolean deleteAndVerifyContainerGone(String container); protected abstract boolean deleteAndVerifyContainerGone(String container);
@Override
public HttpRequest signRequestForBlob(String container, String name) {
return signRequestForBlob.apply(container, name);
}
} }

View File

@ -33,9 +33,11 @@ import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.PageSet; import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.blobstore.util.internal.BlobUtilsImpl; import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.http.HttpRequest;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -50,14 +52,16 @@ public abstract class BaseBlobStore implements BlobStore {
protected final BlobUtils blobUtils; protected final BlobUtils blobUtils;
protected final Supplier<Location> defaultLocation; protected final Supplier<Location> defaultLocation;
protected final Supplier<Set<? extends Location>> locations; protected final Supplier<Set<? extends Location>> locations;
protected final SignRequestForBlobStrategy signRequestForBlob;
@Inject @Inject
protected BaseBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation, protected BaseBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
Supplier<Set<? extends Location>> locations) { Supplier<Set<? extends Location>> locations, SignRequestForBlobStrategy signRequestForBlob) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.blobUtils = checkNotNull(blobUtils, "blobUtils"); this.blobUtils = checkNotNull(blobUtils, "blobUtils");
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
this.signRequestForBlob = checkNotNull(signRequestForBlob, "signRequestForBlob");
} }
@Override @Override
@ -219,4 +223,9 @@ public abstract class BaseBlobStore implements BlobStore {
} }
protected abstract boolean deleteAndVerifyContainerGone(String container); protected abstract boolean deleteAndVerifyContainerGone(String container);
@Override
public HttpRequest signRequestForBlob(String container, String name) {
return signRequestForBlob.apply(container, name);
}
} }

View File

@ -0,0 +1,34 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.blobstore.strategy;
import org.jclouds.blobstore.strategy.internal.SignRequestForBlobUnsupported;
import org.jclouds.http.HttpRequest;
import com.google.inject.ImplementedBy;
/**
*
* @author Adrian Cole
*/
@ImplementedBy(SignRequestForBlobUnsupported.class)
public interface SignRequestForBlobStrategy {
HttpRequest apply(String container, String name);
}

View File

@ -0,0 +1,37 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.blobstore.strategy.internal;
import javax.inject.Singleton;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.http.HttpRequest;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SignRequestForBlobUnsupported implements SignRequestForBlobStrategy {
@Override
public HttpRequest apply(String container, String name) {
throw new UnsupportedOperationException();
}
}

View File

@ -28,6 +28,8 @@ import java.net.URLConnection;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.crypto.CryptoStreams; import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.HttpRequest;
import org.jclouds.util.Utils;
import org.testng.annotations.Optional; import org.testng.annotations.Optional;
import org.testng.annotations.Parameters; import org.testng.annotations.Parameters;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -52,7 +54,7 @@ public class BaseBlobLiveTest extends BaseBlobStoreIntegrationTest {
httpStreamETag = checkNotNull(httpStreamETag != null ? httpStreamETag : sysHttpStreamETag, "httpStreamMd5"); httpStreamETag = checkNotNull(httpStreamETag != null ? httpStreamETag : sysHttpStreamETag, "httpStreamMd5");
String key = "hello"; String name = "hello";
URL url = new URL(httpStreamUrl); URL url = new URL(httpStreamUrl);
byte[] md5 = CryptoStreams.hex(httpStreamETag); byte[] md5 = CryptoStreams.hex(httpStreamETag);
@ -61,16 +63,39 @@ public class BaseBlobLiveTest extends BaseBlobStoreIntegrationTest {
long length = connection.getContentLength(); long length = connection.getContentLength();
InputStream input = connection.getInputStream(); InputStream input = connection.getInputStream();
Blob object = context.getBlobStore().newBlob(key); Blob blob = context.getBlobStore().newBlob(name);
object.setPayload(input); blob.setPayload(input);
object.getPayload().setContentLength(length); blob.getPayload().setContentLength(length);
object.getPayload().setContentMD5(md5); blob.getPayload().setContentMD5(md5);
String bucketName = getContainerName(); String container = getContainerName();
try { try {
context.getBlobStore().putBlob(bucketName, object); context.getBlobStore().putBlob(container, blob);
assertEquals(context.getBlobStore().blobMetadata(bucketName, key).getContentMD5(), md5); assertEquals(context.getBlobStore().blobMetadata(container, name).getContentMD5(), md5);
} finally { } finally {
returnContainer(bucketName); returnContainer(container);
} }
} }
@Test
public void testSignUrl() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = context.getBlobStore().newBlob(name);
blob.setPayload(text);
blob.getPayload().setContentType("text/plain");
String container = getContainerName();
try {
context.getBlobStore().putBlob(container, blob);
HttpRequest request = context.getBlobStore().signRequestForBlob(container, name);
assertEquals(request.getFilters().size(), 0);
assertEquals(Utils.toStringAndClose(context.utils().http().get(request)), text);
request = context.getAsyncBlobStore().signRequestForBlob(container, name);
assertEquals(request.getFilters().size(), 0);
assertEquals(Utils.toStringAndClose(context.utils().http().get(request)), text);
} finally {
returnContainer(container);
}
}
} }

View File

@ -312,8 +312,8 @@ See http://code.google.com/p/jclouds for details."
(define-accessors Template image hardware location options) (define-accessors Template image hardware location options)
(define-accessors Image version os-family os-description architecture) (define-accessors Image version os-family os-description architecture)
(define-accessors Hardware processors ram disk) (define-accessors Hardware processors ram volumes)
(define-accessors NodeMetadata "node" credentials extra state tag) (define-accessors NodeMetadata "node" credentials hardware state tag)
(defn builder-options [builder] (defn builder-options [builder]
(or (get-field org.jclouds.compute.domain.internal.TemplateBuilderImpl :options builder) (or (get-field org.jclouds.compute.domain.internal.TemplateBuilderImpl :options builder)

View File

@ -25,6 +25,6 @@ package org.jclouds.compute.domain;
*/ */
public enum ComputeType { public enum ComputeType {
NODE, IMAGE, SIZE; NODE, IMAGE, HARDWARE;
} }

View File

@ -23,6 +23,7 @@ import java.util.List;
import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.HardwareImpl;
import com.google.common.base.Predicate;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
/** /**
@ -44,12 +45,13 @@ public interface Hardware extends ComputeMetadata {
int getRam(); int getRam();
/** /**
* Amount of boot disk provided in GB (200) * volumes associated with this.
*/ */
int getDisk(); List<? extends Volume> getVolumes();
/** /**
* Determines whether this size can run an image. * Determines whether this size can run an image.
*/ */
boolean supportsImage(Image image); Predicate<Image> supportsImage();
} }

View File

@ -19,7 +19,6 @@
package org.jclouds.compute.domain; package org.jclouds.compute.domain;
import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -45,6 +44,13 @@ public interface NodeMetadata extends ComputeMetadata {
*/ */
String getTag(); String getTag();
/**
*
* The harware this node is running, if possible to determine.
*/
@Nullable
Hardware getHardware();
/** /**
* *
* The id of the image this node was created from, if possible to correlate. * The id of the image this node was created from, if possible to correlate.
@ -80,8 +86,4 @@ public interface NodeMetadata extends ComputeMetadata {
*/ */
Credentials getCredentials(); Credentials getCredentials();
/**
* Other variables present that the provider supports
*/
Map<String, String> getExtra();
} }

View File

@ -0,0 +1,94 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.compute.domain;
import javax.annotation.Nullable;
import org.jclouds.compute.domain.internal.VolumeImpl;
import com.google.inject.ImplementedBy;
/**
* Describes what appears as a disk to an {@link OperatingSystem}
*
* @author Adrian Cole
*/
@ImplementedBy(VolumeImpl.class)
public interface Volume {
/**
* Describes the cardinal type of a volume; used to determine scope and exclusivity.
*/
public enum Type {
/**
* scoped to a node cannot be remounted onto another node.
*/
LOCAL,
/**
* shared mount, non-exclusive by nature, although may happen to be exclusive.
*/
NAS,
/**
* network storage; exclusive by nature, remountable onto other machines.
*/
SAN;
}
/**
* Unique identifier. If set, can be used to reference the volume for reorganizing within
* {@link Hardware} or external commands such as backups.
*
*/
@Nullable
String getId();
/**
* Describes the cardinal type of a volume; used to determine scope and exclusivity.
*/
Type getType();
/**
* @return capacity in gigabytes, if available
*
*/
@Nullable
Float getSize();
/**
*
* @return device this volume relates to on an operating system, if available
*/
@Nullable
String getDevice();
/**
*
* @return true if this survives restarts
*/
boolean isDurable();
/**
*
* @return true if this is the boot device
*/
boolean isBootDevice();
}

View File

@ -19,6 +19,10 @@
package org.jclouds.compute.domain.internal; package org.jclouds.compute.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed;
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -29,6 +33,7 @@ import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.ResourceMetadata; import org.jclouds.domain.ResourceMetadata;
@ -45,17 +50,17 @@ public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
private static final long serialVersionUID = 8994255275911717567L; private static final long serialVersionUID = 8994255275911717567L;
private final List<Processor> processors = Lists.newArrayList(); private final List<Processor> processors = Lists.newArrayList();
private final int ram; private final int ram;
private final int disk; private final List<Volume> volumes = Lists.newArrayList();
private Predicate<Image> supportsImage; private Predicate<Image> supportsImage;
public HardwareImpl(String providerId, String name, String id, @Nullable Location location, URI uri, public HardwareImpl(String providerId, String name, String id, @Nullable Location location, URI uri,
Map<String, String> userMetadata, Iterable<? extends Processor> processors, int ram, int disk, Map<String, String> userMetadata, Iterable<? extends Processor> processors, int ram,
Predicate<Image> supportsImage) { Iterable<? extends Volume> volumes, Predicate<Image> supportsImage) {
super(ComputeType.SIZE, providerId, name, id, location, uri, userMetadata); super(ComputeType.HARDWARE, providerId, name, id, location, uri, userMetadata);
Iterables.addAll(this.processors, processors); Iterables.addAll(this.processors, checkNotNull(processors, "processors"));
this.ram = ram; this.ram = ram;
this.disk = disk; Iterables.addAll(this.volumes, checkNotNull(volumes, "volumes"));
this.supportsImage = supportsImage; this.supportsImage = supportsImage;
} }
@ -79,8 +84,8 @@ public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public int getDisk() { public List<? extends Volume> getVolumes() {
return disk; return volumes;
} }
/** /**
@ -90,46 +95,38 @@ public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
public int compareTo(ResourceMetadata<ComputeType> that) { public int compareTo(ResourceMetadata<ComputeType> that) {
if (that instanceof Hardware) { if (that instanceof Hardware) {
Hardware thatHardware = Hardware.class.cast(that); Hardware thatHardware = Hardware.class.cast(that);
return ComparisonChain.start() return ComparisonChain.start().compare(getCoresAndSpeed(this), getCoresAndSpeed(thatHardware)).compare(
.compare(sumProcessors(this.getProcessors()), sumProcessors(thatHardware.getProcessors())) this.getRam(), thatHardware.getRam()).compare(getSpace(this), getSpace(thatHardware)).result();
.compare(this.getRam(), thatHardware.getRam()).compare(this.getDisk(), thatHardware.getDisk()).result();
} else { } else {
return super.compareTo(that); return super.compareTo(that);
} }
} }
static double sumProcessors(List<? extends Processor> in) {
double returnVal = 0;
for (Processor processor : in)
returnVal = processor.getCores() * processor.getSpeed();
return returnVal;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String toString() { public String toString() {
return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() + ", processors=" return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() + ", processors="
+ processors + ", ram=" + ram + ", disk=" + disk + ", supportsImage=" + supportsImage + "]"; + processors + ", ram=" + ram + ", volumes=" + volumes + ", supportsImage=" + supportsImage + "]";
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean supportsImage(Image image) { public Predicate<Image> supportsImage() {
return supportsImage.apply(image); return supportsImage;
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
result = prime * result + disk;
result = prime * result + ((processors == null) ? 0 : processors.hashCode()); result = prime * result + ((processors == null) ? 0 : processors.hashCode());
result = prime * result + ram; result = prime * result + ram;
result = prime * result + ((supportsImage == null) ? 0 : supportsImage.hashCode()); result = prime * result + ((supportsImage == null) ? 0 : supportsImage.hashCode());
result = prime * result + ((volumes == null) ? 0 : volumes.hashCode());
return result; return result;
} }
@ -142,8 +139,6 @@ public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
HardwareImpl other = (HardwareImpl) obj; HardwareImpl other = (HardwareImpl) obj;
if (disk != other.disk)
return false;
if (processors == null) { if (processors == null) {
if (other.processors != null) if (other.processors != null)
return false; return false;
@ -156,6 +151,11 @@ public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
return false; return false;
} else if (!supportsImage.equals(other.supportsImage)) } else if (!supportsImage.equals(other.supportsImage))
return false; return false;
if (volumes == null) {
if (other.volumes != null)
return false;
} else if (!volumes.equals(other.volumes))
return false;
return true; return true;
} }
} }

View File

@ -28,6 +28,7 @@ import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
@ -35,7 +36,6 @@ import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -49,24 +49,25 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
private final NodeState state; private final NodeState state;
private final Set<String> publicAddresses = Sets.newLinkedHashSet(); private final Set<String> publicAddresses = Sets.newLinkedHashSet();
private final Set<String> privateAddresses = Sets.newLinkedHashSet(); private final Set<String> privateAddresses = Sets.newLinkedHashSet();
private final Map<String, String> extra = Maps.newLinkedHashMap();
private final Credentials credentials; private final Credentials credentials;
private final String tag; private final String tag;
private final String imageId; private final String imageId;
@Nullable
private final Hardware hardware;
private final OperatingSystem os; private final OperatingSystem os;
public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri, public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri,
Map<String, String> userMetadata, @Nullable String tag, @Nullable String imageId, Map<String, String> userMetadata, @Nullable String tag, @Nullable Hardware hardware,
@Nullable OperatingSystem os, NodeState state, Iterable<String> publicAddresses, @Nullable String imageId, @Nullable OperatingSystem os, NodeState state, Iterable<String> publicAddresses,
Iterable<String> privateAddresses, Map<String, String> extra, @Nullable Credentials credentials) { Iterable<String> privateAddresses, @Nullable Credentials credentials) {
super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata); super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata);
this.tag = tag; this.tag = tag;
this.hardware = hardware;
this.imageId = imageId; this.imageId = imageId;
this.os = os; this.os = os;
this.state = checkNotNull(state, "state"); this.state = checkNotNull(state, "state");
Iterables.addAll(this.publicAddresses, checkNotNull(publicAddresses, "publicAddresses")); Iterables.addAll(this.publicAddresses, checkNotNull(publicAddresses, "publicAddresses"));
Iterables.addAll(this.privateAddresses, checkNotNull(privateAddresses, "privateAddresses")); Iterables.addAll(this.privateAddresses, checkNotNull(privateAddresses, "privateAddresses"));
this.extra.putAll(checkNotNull(extra, "extra"));
this.credentials = credentials; this.credentials = credentials;
} }
@ -78,6 +79,14 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
return tag; return tag;
} }
/**
* {@inheritDoc}
*/
@Override
public Hardware getHardware() {
return hardware;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -114,8 +123,16 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Map<String, String> getExtra() { public String getImageId() {
return extra; return imageId;
}
/**
* {@inheritDoc}
*/
@Override
public OperatingSystem getOperatingSystem() {
return os;
} }
@Override @Override
@ -123,8 +140,8 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
return "[id=" + getId() + ", providerId=" + getProviderId() + ", tag=" + getTag() + ", name=" + getName() return "[id=" + getId() + ", providerId=" + getProviderId() + ", tag=" + getTag() + ", name=" + getName()
+ ", location=" + getLocation() + ", uri=" + getUri() + ", imageId=" + getImageId() + ", os=" + ", location=" + getLocation() + ", uri=" + getUri() + ", imageId=" + getImageId() + ", os="
+ getOperatingSystem() + ", userMetadata=" + getUserMetadata() + ", state=" + getState() + getOperatingSystem() + ", userMetadata=" + getUserMetadata() + ", state=" + getState()
+ ", privateAddresses=" + privateAddresses + ", publicAddresses=" + publicAddresses + ", extra=" + ", privateAddresses=" + privateAddresses + ", publicAddresses=" + publicAddresses + ", hardware="
+ getExtra() + "]"; + getHardware() + "]";
} }
@Override @Override
@ -135,6 +152,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode()); result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
result = prime * result + ((tag == null) ? 0 : tag.hashCode()); result = prime * result + ((tag == null) ? 0 : tag.hashCode());
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode()); result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
result = prime * result + ((hardware == null) ? 0 : hardware.hashCode());
result = prime * result + ((os == null) ? 0 : os.hashCode()); result = prime * result + ((os == null) ? 0 : os.hashCode());
return result; return result;
} }
@ -168,6 +186,11 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
return false; return false;
} else if (!imageId.equals(other.imageId)) } else if (!imageId.equals(other.imageId))
return false; return false;
if (hardware == null) {
if (other.hardware != null)
return false;
} else if (!hardware.equals(other.hardware))
return false;
if (os == null) { if (os == null) {
if (other.os != null) if (other.os != null)
return false; return false;
@ -176,14 +199,4 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
return true; return true;
} }
@Override
public String getImageId() {
return imageId;
}
@Override
public OperatingSystem getOperatingSystem() {
return os;
}
} }

View File

@ -25,6 +25,7 @@ import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed; import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed;
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
import static org.jclouds.util.Utils.multiMax; import static org.jclouds.util.Utils.multiMax;
import java.util.Arrays; import java.util.Arrays;
@ -384,7 +385,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
static final Ordering<Hardware> DEFAULT_SIZE_ORDERING = new Ordering<Hardware>() { static final Ordering<Hardware> DEFAULT_SIZE_ORDERING = new Ordering<Hardware>() {
public int compare(Hardware left, Hardware right) { public int compare(Hardware left, Hardware right) {
return ComparisonChain.start().compare(getCores(left), getCores(right)).compare(left.getRam(), right.getRam()) return ComparisonChain.start().compare(getCores(left), getCores(right)).compare(left.getRam(), right.getRam())
.compare(left.getDisk(), right.getDisk()).result(); .compare(getSpace(left), getSpace(right)).result();
} }
}; };
static final Ordering<Hardware> BY_CORES_ORDERING = new Ordering<Hardware>() { static final Ordering<Hardware> BY_CORES_ORDERING = new Ordering<Hardware>() {
@ -554,7 +555,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Override @Override
public boolean apply(Image input) { public boolean apply(Image input) {
return hardware.supportsImage(input); return hardware.supportsImage().apply(input);
} }
@Override @Override
@ -596,7 +597,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Override @Override
public boolean apply(Image arg0) { public boolean apply(Image arg0) {
return hardware.supportsImage(arg0); return hardware.supportsImage().apply(arg0);
} }
@Override @Override

View File

@ -0,0 +1,159 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.compute.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
import org.jclouds.compute.domain.Volume;
/**
* @author Adrian Cole
*/
public class VolumeImpl implements Volume {
/** The serialVersionUID */
private static final long serialVersionUID = -3306004212804159093L;
private final String id;
private final Volume.Type type;
private final @Nullable
Float size;
private final @Nullable
String device;
private final boolean bootDevice;
private final boolean durable;
public VolumeImpl(@Nullable String id, Volume.Type type, @Nullable Float size, @Nullable String device,
boolean bootDevice, boolean durable) {
this.id = id;
this.type = checkNotNull(type, "type");
this.size = size;
this.device = device;
this.bootDevice = bootDevice;
this.durable = durable;
}
public VolumeImpl(@Nullable Float size, boolean bootDevice, boolean durable) {
this(null, Volume.Type.LOCAL, size, null, bootDevice, durable);
}
public VolumeImpl(@Nullable Float size, @Nullable String device, boolean bootDevice, boolean durable) {
this(null, Volume.Type.LOCAL, size, device, bootDevice, durable);
}
/**
* {@inheritDoc}
*/
@Override
public String getId() {
return id;
}
/**
* {@inheritDoc}
*/
@Override
public Volume.Type getType() {
return type;
}
/**
* {@inheritDoc}
*/
@Override
public Float getSize() {
return size;
}
/**
* {@inheritDoc}
*/
@Override
public String getDevice() {
return device;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isDurable() {
return durable;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isBootDevice() {
return bootDevice;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "[id=" + getId() + ", type=" + type + ", size=" + size + ", device=" + device + ", durable=" + durable
+ ", isBootDevice=" + bootDevice + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((device == null) ? 0 : device.hashCode());
result = prime * result + (durable ? 1231 : 1237);
result = prime * result + ((size == null) ? 0 : size.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VolumeImpl other = (VolumeImpl) obj;
if (device == null) {
if (other.device != null)
return false;
} else if (!device.equals(other.device))
return false;
if (durable != other.durable)
return false;
if (size == null) {
if (other.size != null)
return false;
} else if (!size.equals(other.size))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
}

View File

@ -31,6 +31,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
@ -52,6 +53,7 @@ import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
@ -180,11 +182,11 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
private final ExecutorService service; private final ExecutorService service;
public StubNodeMetadata(String providerId, String name, String id, Location location, URI uri, public StubNodeMetadata(String providerId, String name, String id, Location location, URI uri,
Map<String, String> userMetadata, String tag, String imageId, Image image, OperatingSystem os, Map<String, String> userMetadata, String tag, @Nullable Hardware hardware, String imageId, Image image,
NodeState state, Iterable<String> publicAddresses, Iterable<String> privateAddresses, OperatingSystem os, NodeState state, Iterable<String> publicAddresses,
Map<String, String> extra, Credentials credentials, ExecutorService service) { Iterable<String> privateAddresses, Credentials credentials, ExecutorService service) {
super(providerId, name, id, location, uri, userMetadata, tag, imageId, os, state, publicAddresses, super(providerId, name, id, location, uri, userMetadata, tag, hardware, imageId, os, state, publicAddresses,
privateAddresses, extra, credentials); privateAddresses, credentials);
this.setState(state, 0); this.setState(state, 0);
this.service = service; this.service = service;
} }
@ -243,11 +245,10 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
checkArgument(location.get().equals(template.getLocation()), "invalid location: " + template.getLocation()); checkArgument(location.get().equals(template.getLocation()), "invalid location: " + template.getLocation());
int id = idProvider.get(); int id = idProvider.get();
StubNodeMetadata node = new StubNodeMetadata(id + "", name, id + "", location.get(), null, StubNodeMetadata node = new StubNodeMetadata(id + "", name, id + "", location.get(), null, ImmutableMap
ImmutableMap.<String, String> of(), tag, template.getImage().getId(), template.getImage(), template .<String, String> of(), tag, null, template.getImage().getId(), template.getImage(), template
.getImage().getOperatingSystem(), NodeState.PENDING, .getImage().getOperatingSystem(), NodeState.PENDING, ImmutableSet.<String> of(publicIpPrefix + id),
ImmutableSet.<String> of(publicIpPrefix + id), ImmutableSet.<String> of(privateIpPrefix + id), ImmutableSet.<String> of(privateIpPrefix + id), new Credentials("root", passwordPrefix + id), service);
ImmutableMap.<String, String> of(), new Credentials("root", passwordPrefix + id), service);
nodes.put(id, node); nodes.put(id, node);
node.setState(NodeState.RUNNING, 100); node.setState(NodeState.RUNNING, 100);
return node; return node;
@ -389,9 +390,9 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = -1842135761654973637L; private static final long serialVersionUID = -1842135761654973637L;
StubHardware(String type, int cores, int ram, int disk) { StubHardware(String type, int cores, int ram, float disk) {
super(type, type, type, null, null, ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(cores, super(type, type, type, null, null, ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(cores,
1.0)), ram, disk, any()); 1.0)), ram, ImmutableList.of(new VolumeImpl(disk, true, false)), any());
} }
} }

View File

@ -21,8 +21,8 @@ package org.jclouds.compute.util;
import java.util.Formatter; import java.util.Formatter;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Map.Entry;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -32,12 +32,17 @@ import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpRequest;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -50,6 +55,24 @@ import com.google.common.collect.Iterables;
public class ComputeServiceUtils { public class ComputeServiceUtils {
public static final Pattern DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+"); public static final Pattern DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX = Pattern.compile("([^-]+)-[0-9a-f]+");
/**
* build a shell script that invokes the contents of the http request in bash.
*
* @return a shell script that will invoke the http request
*/
public static String buildCurlsh(HttpRequest request) {
String headers = Joiner.on(' ').join(
Iterables.transform(request.getHeaders().entries(), new Function<Entry<String, String>, String>() {
@Override
public String apply(Entry<String, String> from) {
return String.format("-H \"%s: %s\"", from.getKey(), from.getValue());
}
}));
return String.format("curl -s --retry 20 %s %s |bash\n", headers, request.getEndpoint().toASCIIString());
}
public static String parseTagFromName(String from) { public static String parseTagFromName(String from) {
Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from); Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from);
return matcher.find() ? matcher.group(1) : "NOTAG-" + from; return matcher.find() ? matcher.group(1) : "NOTAG-" + from;
@ -69,15 +92,21 @@ public class ComputeServiceUtils {
return total; return total;
} }
public static double getSpace(Hardware input) {
double total = 0;
for (Volume volume : input.getVolumes())
total += volume.getSize() != null ? volume.getSize() : 0;
return total;
}
public static final Map<org.jclouds.compute.domain.OsFamily, Map<String, String>> NAME_VERSION_MAP = ImmutableMap public static final Map<org.jclouds.compute.domain.OsFamily, Map<String, String>> NAME_VERSION_MAP = ImmutableMap
.<org.jclouds.compute.domain.OsFamily, Map<String, String>> of( .<org.jclouds.compute.domain.OsFamily, Map<String, String>> of(org.jclouds.compute.domain.OsFamily.CENTOS,
org.jclouds.compute.domain.OsFamily.CENTOS, ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5")
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5").build(), .build(), org.jclouds.compute.domain.OsFamily.RHEL,
org.jclouds.compute.domain.OsFamily.RHEL, ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5")
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5").build(), .build(), org.jclouds.compute.domain.OsFamily.UBUNTU, ImmutableMap
org.jclouds.compute.domain.OsFamily.UBUNTU, .<String, String> builder().put("hardy", "8.04").put("intrepid", "8.10").put("jaunty",
ImmutableMap.<String, String> builder().put("hardy", "8.04").put("intrepid", "8.10") "9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10")
.put("jaunty", "9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10")
.build()); .build());
public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in) { public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in) {
@ -110,8 +139,8 @@ public class ComputeServiceUtils {
Formatter fmt = new Formatter().format("Execution failures:%n%n"); Formatter fmt = new Formatter().format("Execution failures:%n%n");
int index = 1; int index = 1;
for (Entry<?, Exception> errorMessage : executionExceptions.entrySet()) { for (Entry<?, Exception> errorMessage : executionExceptions.entrySet()) {
fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), errorMessage
errorMessage.getKey(), Throwables.getStackTraceAsString(errorMessage.getValue())); .getKey(), Throwables.getStackTraceAsString(errorMessage.getValue()));
} }
return fmt.format("%s error[s]", executionExceptions.size()).toString(); return fmt.format("%s error[s]", executionExceptions.size()).toString();
} }
@ -161,14 +190,24 @@ public class ComputeServiceUtils {
} }
/** /**
* Given the instances of {@link NodeMetadata} (immutable) and * Given the instances of {@link NodeMetadata} (immutable) and {@link Credentials} (immutable),
* {@link Credentials} (immutable), returns a new instance of * returns a new instance of {@link NodeMetadata} that has new credentials
* {@link NodeMetadata} that has new credentials
*/ */
public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) { public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) {
return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node.getLocation(), return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node.getLocation(),
node.getUri(), node.getUserMetadata(), node.getTag(), node.getImageId(), node.getOperatingSystem(), node.getUri(), node.getUserMetadata(), node.getTag(), node.getHardware(), node.getImageId(), node
node.getState(), node.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), newCredentials); .getOperatingSystem(), node.getState(), node.getPublicAddresses(), node.getPrivateAddresses(),
newCredentials);
}
/**
* Given the instances of {@link Hardware} (immutable) and {@link Iterable<? extends Volume>}
* (immutable), returns a new instance of {@link Hardware} with the new volumes
*/
public static Hardware replacesVolumes(Hardware hardware, Iterable<? extends Volume> volumes) {
return new HardwareImpl(hardware.getProviderId(), hardware.getName(), hardware.getId(), hardware.getLocation(),
hardware.getUri(), hardware.getUserMetadata(), hardware.getProcessors(), hardware.getRam(), volumes,
hardware.supportsImage());
} }
public static Iterable<String> getSupportedProviders() { public static Iterable<String> getSupportedProviders() {

View File

@ -55,11 +55,11 @@ import java.util.concurrent.TimeoutException;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -85,7 +85,6 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
/** /**
@ -125,7 +124,6 @@ public abstract class BaseComputeServiceLiveTest {
abstract public void setServiceDefaults(); abstract public void setServiceDefaults();
protected String provider; protected String provider;
protected SshClient.Factory sshFactory;
protected String tag; protected String tag;
protected RetryablePredicate<IPSocket> socketTester; protected RetryablePredicate<IPSocket> socketTester;
@ -145,12 +143,12 @@ public abstract class BaseComputeServiceLiveTest {
setupCredentials(); setupCredentials();
setupKeyPairForTest(); setupKeyPairForTest();
initializeContextAndClient(); initializeContextAndClient();
buildSocketTester();
}
Injector injector = createSshClientInjector(); protected void buildSocketTester() {
sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = Guice.createInjector(getSshModule()).getInstance(SocketOpen.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 60, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<IPSocket>(socketOpen, 60, 1, TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger
} }
protected void setupKeyPairForTest() throws FileNotFoundException, IOException { protected void setupKeyPairForTest() throws FileNotFoundException, IOException {
@ -167,8 +165,8 @@ public abstract class BaseComputeServiceLiveTest {
checkSecretKeyFile(secretKeyFile); checkSecretKeyFile(secretKeyFile);
String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8); String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8);
assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret; assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret;
return ImmutableMap.<String, String> of("private", secret, "public", return ImmutableMap.<String, String> of("private", secret, "public", Files.toString(new File(secretKeyFile
Files.toString(new File(secretKeyFile + ".pub"), Charsets.UTF_8)); + ".pub"), Charsets.UTF_8));
} }
protected void setupCredentials() { protected void setupCredentials() {
@ -176,18 +174,14 @@ public abstract class BaseComputeServiceLiveTest {
credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
} }
protected Injector createSshClientInjector() {
return Guice.createInjector(getSshModule());
}
private void initializeContextAndClient() throws IOException { private void initializeContextAndClient() throws IOException {
if (context != null) if (context != null)
context.close(); context.close();
Properties props = new Properties(); Properties props = new Properties();
props.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); props.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
props.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); props.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
context = new ComputeServiceContextFactory().createContext(provider, identity, credential, context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet.of(
ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), props); new Log4JLoggingModule(), getSshModule()), props);
client = context.getComputeService(); client = context.getComputeService();
} }
@ -205,8 +199,8 @@ public abstract class BaseComputeServiceLiveTest {
public void testCorrectAuthException() throws Exception { public void testCorrectAuthException() throws Exception {
ComputeServiceContext context = null; ComputeServiceContext context = null;
try { try {
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet
ImmutableSet.<Module> of(new Log4JLoggingModule())); .<Module> of(new Log4JLoggingModule()));
context.getComputeService().listNodes(); context.getComputeService().listNodes();
} finally { } finally {
if (context != null) if (context != null)
@ -299,9 +293,9 @@ public abstract class BaseComputeServiceLiveTest {
private void refreshTemplate() { private void refreshTemplate() {
template = buildTemplate(client.templateBuilder()); template = buildTemplate(client.templateBuilder());
template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))) template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey(
.authorizePublicKey(newStringPayload(keyPair.get("public"))) newStringPayload(keyPair.get("public"))).runScript(
.runScript(newStringPayload(buildScript(template.getImage().getOperatingSystem()))); newStringPayload(buildScript(template.getImage().getOperatingSystem())));
} }
protected void checkImageIdMatchesTemplate(NodeMetadata node) { protected void checkImageIdMatchesTemplate(NodeMetadata node) {
@ -312,8 +306,8 @@ public abstract class BaseComputeServiceLiveTest {
protected void checkOsMatchesTemplate(NodeMetadata node) { protected void checkOsMatchesTemplate(NodeMetadata node) {
if (node.getOperatingSystem() != null) if (node.getOperatingSystem() != null)
assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String
.format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), .format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), node
node.getOperatingSystem()); .getOperatingSystem());
} }
void assertLocationSameOrChild(Location test, Location expected) { void assertLocationSameOrChild(Location test, Location expected) {
@ -353,8 +347,7 @@ public abstract class BaseComputeServiceLiveTest {
assertNotNull(node.getTag()); assertNotNull(node.getTag());
assertEquals(node.getTag(), tag); assertEquals(node.getTag(), tag);
assertEquals(node.getState(), NodeState.RUNNING); assertEquals(node.getState(), NodeState.RUNNING);
assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + node;
+ node;
assertNotNull(node.getCredentials()); assertNotNull(node.getCredentials());
if (node.getCredentials().identity != null) { if (node.getCredentials().identity != null) {
assertNotNull(node.getCredentials().identity); assertNotNull(node.getCredentials().identity);
@ -439,8 +432,7 @@ public abstract class BaseComputeServiceLiveTest {
// assert nodeMetadata.getName() != null : nodeMetadata; // assert nodeMetadata.getName() != null : nodeMetadata;
if (nodeMetadata.getState() == NodeState.RUNNING) { if (nodeMetadata.getState() == NodeState.RUNNING) {
assert nodeMetadata.getPublicAddresses() != null : nodeMetadata; assert nodeMetadata.getPublicAddresses() != null : nodeMetadata;
assert nodeMetadata.getPublicAddresses().size() > 0 assert nodeMetadata.getPublicAddresses().size() > 0 || nodeMetadata.getPrivateAddresses().size() > 0 : nodeMetadata;
|| nodeMetadata.getPrivateAddresses().size() > 0 : nodeMetadata;
assertNotNull(nodeMetadata.getPrivateAddresses()); assertNotNull(nodeMetadata.getPrivateAddresses());
} }
} }
@ -517,9 +509,9 @@ public abstract class BaseComputeServiceLiveTest {
for (Hardware hardware : client.listHardwareProfiles()) { for (Hardware hardware : client.listHardwareProfiles()) {
assert hardware.getProviderId() != null; assert hardware.getProviderId() != null;
assert getCores(hardware) > 0; assert getCores(hardware) > 0;
assert hardware.getDisk() >= 0; assert hardware.getVolumes().size() >= 0;
assert hardware.getRam() > 0; assert hardware.getRam() > 0;
assertEquals(hardware.getType(), ComputeType.SIZE); assertEquals(hardware.getType(), ComputeType.HARDWARE);
} }
} }
@ -567,7 +559,13 @@ public abstract class BaseComputeServiceLiveTest {
socketTester.apply(socket); // TODO add transitionTo option that accepts socketTester.apply(socket); // TODO add transitionTo option that accepts
// a socket conection // a socket conection
// state. // state.
SshClient ssh = sshFactory.create(socket, node.getCredentials().identity, keyPair.get("private").getBytes()); SshClient ssh = (node.getCredentials().credential != null && !node.getCredentials().credential
.startsWith("-----BEGIN RSA PRIVATE KEY-----")) ? context.utils().sshFactory().create(socket,
node.getCredentials().identity, node.getCredentials().credential) : context.utils().sshFactory().create(
socket,
node.getCredentials().identity,
node.getCredentials().credential != null ? node.getCredentials().credential.getBytes() : keyPair.get(
"private").getBytes());
try { try {
ssh.connect(); ssh.connect();
ExecResponse hello = ssh.exec("echo hello"); ExecResponse hello = ssh.exec("echo hello");

View File

@ -26,6 +26,7 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.reportMatcher; import static org.easymock.EasyMock.reportMatcher;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.replay;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -34,6 +35,7 @@ import java.io.Serializable;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.easymock.IArgumentMatcher; import org.easymock.IArgumentMatcher;
@ -43,6 +45,7 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.stub.config.StubComputeServiceContextModule.StubNodeMetadata; import org.jclouds.compute.stub.config.StubComputeServiceContextModule.StubNodeMetadata;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.scriptbuilder.InitBuilder; import org.jclouds.scriptbuilder.InitBuilder;
@ -61,10 +64,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
/** /**
* *
@ -96,64 +96,17 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
@Override protected void buildSocketTester() {
protected Injector createSshClientInjector() { SocketOpen socketOpen = createMock(SocketOpen.class);
return Guice.createInjector(new AbstractModule() {
@Override expect(socketOpen.apply(new IPSocket("144.175.1.1", 22))).andReturn(true);
protected void configure() { expect(socketOpen.apply(new IPSocket("144.175.1.2", 22))).andReturn(true);
SshClient.Factory factory = createMock(SshClient.Factory.class); expect(socketOpen.apply(new IPSocket("144.175.1.3", 22))).andReturn(true);
SocketOpen open = createMock(SocketOpen.class); expect(socketOpen.apply(new IPSocket("144.175.1.4", 22))).andReturn(true);
SshClient client1 = createMock(SshClient.class);
SshClient client2 = createMock(SshClient.class);
SshClient client3 = createMock(SshClient.class);
SshClient client4 = createMock(SshClient.class);
expect(open.apply(new IPSocket("144.175.1.1", 22))).andReturn(true); replay(socketOpen);
expect(open.apply(new IPSocket("144.175.1.2", 22))).andReturn(true);
expect(open.apply(new IPSocket("144.175.1.3", 22))).andReturn(true);
expect(open.apply(new IPSocket("144.175.1.4", 22))).andReturn(true);
expect( socketTester = new RetryablePredicate<IPSocket>(socketOpen, 60, 1, TimeUnit.SECONDS);
factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client1).atLeastOnce();
expect(
factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client2).atLeastOnce();
expect(
factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client3).atLeastOnce();
expect(
factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client4).atLeastOnce();
helloAndJava(client1);
helloAndJava(client2);
helloAndJava(client3);
helloAndJava(client4);
replay(open);
replay(factory);
replay(client1);
replay(client2);
replay(client3);
replay(client4);
bind(SshClient.Factory.class).toInstance(factory);
bind(SocketOpen.class).toInstance(open);
}
private void helloAndJava(SshClient client) {
client.connect();
expect(client.exec("echo hello")).andReturn(new ExecResponse("hello", "", 0));
expect(client.exec("java -version")).andReturn(new ExecResponse("", "OpenJDK", 0));
client.disconnect();
}
});
} }
@Override @Override
@ -188,6 +141,24 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
runScriptAndInstallSsh(client3, "runscript", 3); runScriptAndInstallSsh(client3, "runscript", 3);
runScriptAndInstallSsh(client4, "runscript", 4); runScriptAndInstallSsh(client4, "runscript", 4);
expect(
factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client1).atLeastOnce();
expect(
factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client2).atLeastOnce();
expect(
factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client3).atLeastOnce();
expect(
factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client4).atLeastOnce();
helloAndJava(client1);
helloAndJava(client2);
helloAndJava(client3);
helloAndJava(client4);
replay(factory); replay(factory);
replay(client1); replay(client1);
replay(client2); replay(client2);
@ -212,13 +183,12 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
expect(client.exec("chmod 600 .ssh/id_rsa")).andReturn(EXEC_GOOD); expect(client.exec("chmod 600 .ssh/id_rsa")).andReturn(EXEC_GOOD);
client.disconnect(); client.disconnect();
client.disconnect();
} }
private void runScript(SshClient client, String scriptName, int nodeId) { private void runScript(SshClient client, String scriptName, int nodeId) {
client.put(eq("" + scriptName + ""), client.put(eq("" + scriptName + ""), payloadEq(initScript(scriptName,
payloadEq(initScript(scriptName, BaseComputeServiceLiveTest.APT_RUN_SCRIPT))); BaseComputeServiceLiveTest.APT_RUN_SCRIPT)));
expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD); expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD);
expect(client.getUsername()).andReturn("root").atLeastOnce(); expect(client.getUsername()).andReturn("root").atLeastOnce();
expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce(); expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce();
@ -231,6 +201,15 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
expect(client.exec("./" + scriptName + " tailerr")).andReturn(EXEC_GOOD); expect(client.exec("./" + scriptName + " tailerr")).andReturn(EXEC_GOOD);
} }
private void helloAndJava(SshClient client) {
client.connect();
expect(client.exec("echo hello")).andReturn(new ExecResponse("hello", "", 0));
expect(client.exec("java -version")).andReturn(new ExecResponse("", "OpenJDK", 0));
client.disconnect();
}
}; };
} }

View File

@ -36,6 +36,7 @@ import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -63,8 +64,9 @@ public class TemplateBuilderImplTest {
Image image2 = createMock(Image.class); Image image2 = createMock(Image.class);
OperatingSystem os2 = createMock(OperatingSystem.class); OperatingSystem os2 = createMock(OperatingSystem.class);
Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, ImmutableMap
ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, ImagePredicates.any()); .<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, ImmutableList.<Volume> of(),
ImagePredicates.any());
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(defaultLocation)); .<Location> of(defaultLocation));
@ -124,8 +126,9 @@ public class TemplateBuilderImplTest {
OperatingSystem os = createMock(OperatingSystem.class); OperatingSystem os = createMock(OperatingSystem.class);
OperatingSystem os2 = createMock(OperatingSystem.class); OperatingSystem os2 = createMock(OperatingSystem.class);
Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, ImmutableMap
ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, ImagePredicates.any()); .<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, ImmutableList.<Volume> of(),
ImagePredicates.any());
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(defaultLocation)); .<Location> of(defaultLocation));
@ -178,8 +181,8 @@ public class TemplateBuilderImplTest {
Image image = createMock(Image.class); Image image = createMock(Image.class);
OperatingSystem os = createMock(OperatingSystem.class); OperatingSystem os = createMock(OperatingSystem.class);
Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, ImmutableMap
ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, .<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, ImmutableList.<Volume> of(),
ImagePredicates.idEquals("imageId")); ImagePredicates.idEquals("imageId"));
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
@ -234,8 +237,8 @@ public class TemplateBuilderImplTest {
Image image = createMock(Image.class); Image image = createMock(Image.class);
OperatingSystem os = createMock(OperatingSystem.class); OperatingSystem os = createMock(OperatingSystem.class);
Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, ImmutableMap
ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, .<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, ImmutableList.<Volume> of(),
ImagePredicates.idEquals("imageId")); ImagePredicates.idEquals("imageId"));
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
@ -359,8 +362,8 @@ public class TemplateBuilderImplTest {
protected TemplateBuilderImpl createTemplateBuilder(Image knownImage, Supplier<Set<? extends Location>> locations, protected TemplateBuilderImpl createTemplateBuilder(Image knownImage, Supplier<Set<? extends Location>> locations,
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> sizes, Location defaultLocation, Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> sizes, Location defaultLocation,
Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) { Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) {
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, sizes, TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, sizes, Suppliers
Suppliers.ofInstance(defaultLocation), optionsProvider, templateBuilderProvider); .ofInstance(defaultLocation), optionsProvider, templateBuilderProvider);
return template; return template;
} }

View File

@ -19,10 +19,14 @@
package org.jclouds.compute.util; package org.jclouds.compute.util;
import org.jclouds.util.Utils; import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.HttpRequest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables; import com.google.common.collect.ImmutableMultimap;
/** /**
* Test the compute utils. * Test the compute utils.
@ -34,14 +38,14 @@ import com.google.common.collect.Iterables;
public class ComputeServiceUtilsTest { public class ComputeServiceUtilsTest {
@Test @Test
public void testSupportedComputeServiceProviders() { public void testCurlSh() {
Iterable<String> providers = ComputeServiceUtils.getSupportedProviders(); HttpRequest request = new HttpRequest("GET", URI.create("https://adriancolehappy.s3.amazonaws.com/java/install"),
assert Iterables.contains(providers, "stub") : providers; ImmutableMultimap.of("Host", "adriancolehappy.s3.amazonaws.com", "Date",
} "Sun, 12 Sep 2010 08:25:19 GMT", "Authorization", "AWS 0ASHDJAS82:JASHFDA="));
assertEquals(
ComputeServiceUtils.buildCurlsh(request),
"curl -s --retry 20 -H \"Host: adriancolehappy.s3.amazonaws.com\" -H \"Date: Sun, 12 Sep 2010 08:25:19 GMT\" -H \"Authorization: AWS 0ASHDJAS82:JASHFDA=\" https://adriancolehappy.s3.amazonaws.com/java/install |bash\n");
@Test
public void testSupportedProviders() {
Iterable<String> providers = Utils.getSupportedProviders();
assert Iterables.contains(providers, "stub") : providers;
} }
} }

View File

@ -29,6 +29,7 @@ import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseETagHeader; import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
@ -88,6 +89,12 @@ public interface HttpAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<InputStream> get(@EndpointParam URI location); ListenableFuture<InputStream> get(@EndpointParam URI location);
/**
* @see HttpClient#get
*/
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<InputStream> get(HttpRequest location);
@GET @GET
@Path("") @Path("")
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)

View File

@ -24,6 +24,7 @@ import java.net.URI;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
@ -62,6 +63,11 @@ public interface HttpClient {
*/ */
InputStream get(URI location); InputStream get(URI location);
/**
* @return null if the resource didn't exist.
*/
InputStream get(HttpRequest location);
InputStream get(URI location, HttpRequestOptions options); InputStream get(URI location, HttpRequestOptions options);
/** /**

View File

@ -109,10 +109,11 @@ public class AsyncRestClientProxy<T> implements InvocationHandler {
if (exceptionParser instanceof InvocationContext) { if (exceptionParser instanceof InvocationContext) {
((InvocationContext) exceptionParser).setContext(null); ((InvocationContext) exceptionParser).setContext(null);
} }
HttpRequest request; HttpRequest request = RestAnnotationProcessor.findHttpRequestInArgs(args);
if (request == null) {
try { try {
request = annotationProcessor.createRequest(method, args); request = annotationProcessor.createRequest(method, args);
if (exceptionParser instanceof InvocationContext) { if (exceptionParser instanceof InvocationContext && request instanceof GeneratedHttpRequest) {
((InvocationContext) exceptionParser).setContext((GeneratedHttpRequest<T>) request); ((InvocationContext) exceptionParser).setContext((GeneratedHttpRequest<T>) request);
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
@ -125,6 +126,7 @@ public class AsyncRestClientProxy<T> implements InvocationHandler {
} }
return Futures.immediateFailedFuture(e); return Futures.immediateFailedFuture(e);
} }
}
logger.trace("Converted %s.%s to %s", declaring.getSimpleName(), method.getName(), request.getRequestLine()); logger.trace("Converted %s.%s to %s", declaring.getSimpleName(), method.getName(), request.getRequestLine());
Function<HttpResponse, ?> transformer = annotationProcessor.createResponseParser(method, request); Function<HttpResponse, ?> transformer = annotationProcessor.createResponseParser(method, request);

View File

@ -1010,7 +1010,16 @@ public class RestAnnotationProcessor<T> {
return parts; return parts;
} }
Payload findPayloadInArgs(Object[] args) { public static HttpRequest findHttpRequestInArgs(Object[] args) {
if (args == null)
return null;
for (int i = 0; i < args.length; i++)
if (args[i] instanceof HttpRequest)
return HttpRequest.class.cast(args[i]);
return null;
}
public static Payload findPayloadInArgs(Object[] args) {
if (args == null) if (args == null)
return null; return null;
for (int i = 0; i < args.length; i++) for (int i = 0; i < args.length; i++)

View File

@ -21,6 +21,7 @@ package org.jclouds.gogrid.compute.config;
import static org.jclouds.compute.domain.OsFamily.CENTOS; import static org.jclouds.compute.domain.OsFamily.CENTOS;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC; import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC;
import java.util.Map; import java.util.Map;
@ -32,10 +33,10 @@ import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.LoadBalancerService; import org.jclouds.compute.LoadBalancerService;
import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
@ -52,9 +53,9 @@ import org.jclouds.gogrid.compute.strategy.GoGridDestroyNodeStrategy;
import org.jclouds.gogrid.compute.strategy.GoGridGetNodeMetadataStrategy; import org.jclouds.gogrid.compute.strategy.GoGridGetNodeMetadataStrategy;
import org.jclouds.gogrid.compute.strategy.GoGridListNodesStrategy; import org.jclouds.gogrid.compute.strategy.GoGridListNodesStrategy;
import org.jclouds.gogrid.compute.strategy.GoGridRebootNodeStrategy; import org.jclouds.gogrid.compute.strategy.GoGridRebootNodeStrategy;
import org.jclouds.gogrid.compute.suppliers.GoGridHardwareSupplier;
import org.jclouds.gogrid.compute.suppliers.GoGridImageSupplier; import org.jclouds.gogrid.compute.suppliers.GoGridImageSupplier;
import org.jclouds.gogrid.compute.suppliers.GoGridLocationSupplier; import org.jclouds.gogrid.compute.suppliers.GoGridLocationSupplier;
import org.jclouds.gogrid.compute.suppliers.GoGridHardwareSupplier;
import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.domain.ServerState; import org.jclouds.gogrid.domain.ServerState;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
@ -137,13 +138,13 @@ public class GoGridComputeServiceContextModule extends BaseComputeServiceContext
return new Function<Hardware, String>() { return new Function<Hardware, String>() {
@Override @Override
public String apply(Hardware hardware) { public String apply(Hardware hardware) {
if (hardware.getRam() >= 8 * 1024 || getCores(hardware) >= 6 || hardware.getDisk() >= 450) if (hardware.getRam() >= 8 * 1024 || getCores(hardware) >= 6 || getSpace(hardware) >= 450)
return "8GB"; return "8GB";
if (hardware.getRam() >= 4 * 1024 || getCores(hardware) >= 3 || hardware.getDisk() >= 230) if (hardware.getRam() >= 4 * 1024 || getCores(hardware) >= 3 || getSpace(hardware) >= 230)
return "4GB"; return "4GB";
if (hardware.getRam() >= 2 * 1024 || hardware.getDisk() >= 110) if (hardware.getRam() >= 2 * 1024 || getSpace(hardware) >= 110)
return "2GB"; return "2GB";
if (hardware.getRam() >= 1024 || hardware.getDisk() >= 55) if (hardware.getRam() >= 1024 || getSpace(hardware) >= 55)
return "1GB"; return "1GB";
return "512MB"; /* smallest */ return "512MB"; /* smallest */
} }

View File

@ -30,6 +30,7 @@ import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
@ -60,9 +61,10 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
private final Map<ServerState, NodeState> serverStateToNodeState; private final Map<ServerState, NodeState> serverStateToNodeState;
private final GoGridClient client; private final GoGridClient client;
private final Supplier<Set<? extends Image>> images; private final Supplier<Set<? extends Image>> images;
private final Supplier<Set<? extends Hardware>> hardwares;
private final Supplier<Map<String, ? extends Location>> locations; private final Supplier<Map<String, ? extends Location>> locations;
private static class FindImageForServer implements Predicate<Image> { static class FindImageForServer implements Predicate<Image> {
private final Server instance; private final Server instance;
@Inject @Inject
@ -78,12 +80,28 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
} }
} }
static class FindHardwareForServer implements Predicate<Hardware> {
private final Server instance;
@Inject
private FindHardwareForServer(Server instance) {
this.instance = instance;
}
@Override
public boolean apply(Hardware input) {
return input.getRam() == Integer.parseInt(instance.getRam().getName().replaceAll("[^0-9]", ""));
}
}
@Inject @Inject
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, GoGridClient client, ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, GoGridClient client,
Supplier<Set<? extends Image>> images, Supplier<Map<String, ? extends Location>> locations) { Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> hardwares,
Supplier<Map<String, ? extends Location>> locations) {
this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState"); this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
this.hardwares = checkNotNull(hardwares, "hardwares");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
} }
@ -99,10 +117,18 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
logger.warn("could not find a matching image for server %s", from); logger.warn("could not find a matching image for server %s", from);
} }
Hardware hardware = null;
try {
hardware = Iterables.find(hardwares.get(), new FindHardwareForServer(from));
} catch (NoSuchElementException e) {
logger.warn("could not find a matching hardware for server %s", from);
}
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get().get( return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get().get(
from.getDatacenter().getId() + ""), null, ImmutableMap.<String, String> of(), tag, from.getImage() from.getDatacenter().getId() + ""), null, ImmutableMap.<String, String> of(), tag, hardware, from
.getId() .getImage().getId()
+ "", image != null ? image.getOperatingSystem() : null, state, ipSet, ImmutableList.<String> of(), + "", image != null ? image.getOperatingSystem() : null, state, ipSet, ImmutableList.<String> of(),
ImmutableMap.<String, String> of(), creds); creds);
} }
} }

View File

@ -28,11 +28,12 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.domain.internal.VolumeImpl;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets; import com.google.common.collect.ImmutableSet;
/** /**
* *
@ -41,20 +42,26 @@ import com.google.common.collect.Sets;
@Singleton @Singleton
public class GoGridHardwareSupplier implements Supplier<Set<? extends Hardware>> { public class GoGridHardwareSupplier implements Supplier<Set<? extends Hardware>> {
public static final HardwareImpl H8192 = new HardwareImpl("5", "5", "5", null, null, ImmutableMap
.<String, String> of(), ImmutableList.of(new Processor(8, 1.0)), 8192, ImmutableList.of(new VolumeImpl(
480.0f, true, true)), any());
public static final HardwareImpl H4096 = new HardwareImpl("4", "4", "4", null, null, ImmutableMap
.<String, String> of(), ImmutableList.of(new Processor(4, 1.0)), 4096, ImmutableList.of(new VolumeImpl(
240.0f, true, true)), any());
public static final HardwareImpl H2048 = new HardwareImpl("3", "3", "3", null, null, ImmutableMap
.<String, String> of(), ImmutableList.of(new Processor(2, 1.0)), 2048, ImmutableList.of(new VolumeImpl(
120.0f, true, true)), any());
public static final HardwareImpl H1024 = new HardwareImpl("2", "2", "2", null, null, ImmutableMap
.<String, String> of(), ImmutableList.of(new Processor(1, 1.0)), 1024, ImmutableList.of(new VolumeImpl(
60.0f, true, true)), any());
public static final HardwareImpl H512 = new HardwareImpl("1", "1", "1", null, null, ImmutableMap
.<String, String> of(), ImmutableList.of(new Processor(0.5, 1.0)), 512, ImmutableList.of(new VolumeImpl(
30.0f, true, true)), any());
public static final ImmutableSet<HardwareImpl> H_ALL = ImmutableSet.of(H512, H1024, H2048, H4096, H8192);
@Override @Override
public Set<? extends Hardware> get() { public Set<? extends Hardware> get() {
final Set<Hardware> sizes = Sets.newHashSet(); return H_ALL;
sizes.add(new HardwareImpl("1", "1", "1", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(0.5, 1.0)), 512, 30, any()));
sizes.add(new HardwareImpl("2", "2", "2", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(1, 1.0)), 1024, 60, any()));
sizes.add(new HardwareImpl("3", "3", "3", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(2, 1.0)), 2048, 120, any()));
sizes.add(new HardwareImpl("4", "4", "4", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(4, 1.0)), 4096, 240, any()));
sizes.add(new HardwareImpl("5", "5", "5", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(8, 1.0)), 8192, 480, any()));
return sizes;
} }
} }

View File

@ -29,6 +29,7 @@ import java.net.UnknownHostException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
@ -38,6 +39,7 @@ import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.compute.suppliers.GoGridHardwareSupplier;
import org.jclouds.gogrid.domain.Ip; import org.jclouds.gogrid.domain.Ip;
import org.jclouds.gogrid.domain.Option; import org.jclouds.gogrid.domain.Option;
import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.Server;
@ -65,6 +67,7 @@ public class ServerToNodeMetadataTest {
Map<ServerState, NodeState> serverStateToNodeState = createMock(Map.class); Map<ServerState, NodeState> serverStateToNodeState = createMock(Map.class);
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter"); Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter");
Option ram = new Option(1l, "512MB", "Server with 512MB RAM");
Set<? extends org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage); Set<? extends org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
Server server = createMock(Server.class); Server server = createMock(Server.class);
@ -85,6 +88,7 @@ public class ServerToNodeMetadataTest {
ServerImage image = createMock(ServerImage.class); ServerImage image = createMock(ServerImage.class);
expect(server.getImage()).andReturn(image).atLeastOnce(); expect(server.getImage()).andReturn(image).atLeastOnce();
expect(server.getRam()).andReturn(ram).atLeastOnce();
expect(server.getDatacenter()).andReturn(dc).atLeastOnce(); expect(server.getDatacenter()).andReturn(dc).atLeastOnce();
expect(image.getId()).andReturn(2000l).atLeastOnce(); expect(image.getId()).andReturn(2000l).atLeastOnce();
expect(jcImage.getProviderId()).andReturn("2000").atLeastOnce(); expect(jcImage.getProviderId()).andReturn("2000").atLeastOnce();
@ -101,6 +105,7 @@ public class ServerToNodeMetadataTest {
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, caller, Suppliers ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, caller, Suppliers
.<Set<? extends Image>> ofInstance(images), Suppliers .<Set<? extends Image>> ofInstance(images), Suppliers
.<Set< ? extends Hardware>> ofInstance(GoGridHardwareSupplier.H_ALL), Suppliers
.<Map<String, ? extends Location>> ofInstance(locations)); .<Map<String, ? extends Location>> ofInstance(locations));
NodeMetadata metadata = parser.apply(server); NodeMetadata metadata = parser.apply(server);

View File

@ -40,6 +40,7 @@ import org.jclouds.blobstore.domain.internal.PageSetImpl;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseAsyncBlobStore; import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.concurrent.Futures; import org.jclouds.concurrent.Futures;
@ -88,8 +89,8 @@ public class CloudFilesAsyncBlobStore extends BaseAsyncBlobStore {
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider) { Provider<FetchBlobMetadata> fetchBlobMetadataProvider, SignRequestForBlobStrategy signRequestForBlob) {
super(context, blobUtils, service, defaultLocation, locations); super(context, blobUtils, service, defaultLocation, locations, signRequestForBlob);
this.sync = sync; this.sync = sync;
this.async = async; this.async = async;
this.container2ResourceMd = container2ResourceMd; this.container2ResourceMd = container2ResourceMd;

View File

@ -37,6 +37,7 @@ import org.jclouds.blobstore.domain.internal.PageSetImpl;
import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.blobstore.internal.BaseBlobStore; import org.jclouds.blobstore.internal.BaseBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
import org.jclouds.blobstore.util.BlobUtils; import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -77,8 +78,8 @@ public class CloudFilesBlobStore extends BaseBlobStore {
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider) { Provider<FetchBlobMetadata> fetchBlobMetadataProvider, SignRequestForBlobStrategy signRequestForBlob) {
super(context, blobUtils, defaultLocation, locations); super(context, blobUtils, defaultLocation, locations, signRequestForBlob);
this.sync = sync; this.sync = sync;
this.container2ResourceMd = container2ResourceMd; this.container2ResourceMd = container2ResourceMd;
this.container2ContainerListOptions = container2ContainerListOptions; this.container2ContainerListOptions = container2ContainerListOptions;

View File

@ -29,11 +29,13 @@ import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule; import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient; import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
import org.jclouds.rackspace.cloudfiles.CloudFilesClient; import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesAsyncBlobStore; import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesAsyncBlobStore;
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStore; import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStore;
import org.jclouds.rackspace.cloudfiles.blobstore.strategy.SignGetObject;
import org.jclouds.rackspace.config.RackspaceLocationsModule; import org.jclouds.rackspace.config.RackspaceLocationsModule;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -61,6 +63,7 @@ public class CloudFilesBlobStoreContextModule extends AbstractModule {
bind(BlobStore.class).to(CloudFilesBlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(CloudFilesBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<CloudFilesClient, CloudFilesAsyncClient>>() { bind(BlobStoreContext.class).to(new TypeLiteral<BlobStoreContextImpl<CloudFilesClient, CloudFilesAsyncClient>>() {
}).in(Scopes.SINGLETON); }).in(Scopes.SINGLETON);
bind(SignRequestForBlobStrategy.class).to(SignGetObject.class);
} }
@Provides @Provides

View File

@ -0,0 +1,64 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudfiles.blobstore.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.lang.reflect.Method;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.blobstore.strategy.SignRequestForBlobStrategy;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import com.google.common.collect.ImmutableMultimap;
/**
*
* @author Adrian Cole
*/
@Singleton
public class SignGetObject implements SignRequestForBlobStrategy {
private final RestAnnotationProcessor<CloudFilesAsyncClient> processor;
private final Method method;
@Inject
public SignGetObject(RestAnnotationProcessor<CloudFilesAsyncClient> processor) throws SecurityException,
NoSuchMethodException {
this.processor = checkNotNull(processor, "processor");
this.method = CloudFilesAsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class);
}
@Override
public HttpRequest apply(String container, String name) {
HttpRequest returnVal = processor.createRequest(method, checkNotNull(container,
"container"), checkNotNull(name, "name"));
for (HttpRequestFilter filter : returnVal.getFilters())
filter.filter(returnVal);
returnVal.getFilters().clear();
return new HttpRequest(returnVal.getMethod(), returnVal.getEndpoint(), ImmutableMultimap.copyOf(returnVal.getHeaders()));
}
}

View File

@ -30,6 +30,7 @@ import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
@ -44,7 +45,6 @@ import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
@ -55,6 +55,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
private final Supplier<Location> location; private final Supplier<Location> location;
private final Map<ServerStatus, NodeState> serverToNodeState; private final Map<ServerStatus, NodeState> serverToNodeState;
private final Supplier<Set<? extends Image>> images; private final Supplier<Set<? extends Image>> images;
private final Supplier<Set<? extends Hardware>> hardwares;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -75,12 +76,26 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
} }
} }
private static class FindHardwareForServer implements Predicate<Hardware> {
private final Server instance;
private FindHardwareForServer(Server instance) {
this.instance = instance;
}
@Override
public boolean apply(Hardware input) {
return input.getProviderId().equals(instance.getFlavorId() + "");
}
}
@Inject @Inject
ServerToNodeMetadata(Map<ServerStatus, NodeState> serverStateToNodeState, Supplier<Set<? extends Image>> images, ServerToNodeMetadata(Map<ServerStatus, NodeState> serverStateToNodeState, Supplier<Set<? extends Image>> images,
Supplier<Location> location) { Supplier<Location> location, Supplier<Set<? extends Hardware>> hardwares) {
this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState"); this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
this.location = checkNotNull(location, "location"); this.location = checkNotNull(location, "location");
this.hardwares = checkNotNull(hardwares, "hardwares");
} }
@Override @Override
@ -93,10 +108,16 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
logger.warn("could not find a matching image for server %s in location %s", from, location); logger.warn("could not find a matching image for server %s in location %s", from, location);
} }
Hardware hardware = null;
try {
hardware = Iterables.find(hardwares.get(), new FindHardwareForServer(from));
} catch (NoSuchElementException e) {
logger.warn("could not find a matching hardware for server %s", from);
}
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", host, null, from.getMetadata(), return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", host, null, from.getMetadata(),
tag, from.getImageId() + "", image != null ? image.getOperatingSystem() : null, serverToNodeState tag, hardware, from.getImageId() + "", image != null ? image.getOperatingSystem() : null,
.get(from.getStatus()), from.getAddresses().getPublicAddresses(), from.getAddresses() serverToNodeState.get(from.getStatus()), from.getAddresses().getPublicAddresses(), from.getAddresses()
.getPrivateAddresses(), ImmutableMap.<String, String> of(), null); .getPrivateAddresses(), null);
} }
} }

View File

@ -35,8 +35,6 @@ import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.rackspace.cloudservers.CloudServersClient; import org.jclouds.rackspace.cloudservers.CloudServersClient;
import org.jclouds.rackspace.cloudservers.domain.Server; import org.jclouds.rackspace.cloudservers.domain.Server;
import com.google.common.collect.ImmutableMap;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -55,9 +53,9 @@ public class CloudServersAddNodeWithTagStrategy implements AddNodeWithTagStrateg
.parseInt(template.getHardware().getProviderId())); .parseInt(template.getHardware().getProviderId()));
return new NodeMetadataImpl(server.getId() + "", name, server.getId() + "", new LocationImpl(LocationScope.HOST, return new NodeMetadataImpl(server.getId() + "", name, server.getId() + "", new LocationImpl(LocationScope.HOST,
server.getHostId(), server.getHostId(), template.getLocation()), null, server.getMetadata(), tag, server.getHostId(), server.getHostId(), template.getLocation()), null, server.getMetadata(), tag,
template.getImage().getId(), template.getImage().getOperatingSystem(), NodeState.PENDING, server template.getHardware(), template.getImage().getId(), template.getImage().getOperatingSystem(),
.getAddresses().getPublicAddresses(), server.getAddresses().getPrivateAddresses(), ImmutableMap NodeState.PENDING, server.getAddresses().getPublicAddresses(), server.getAddresses()
.<String, String> of(), new Credentials("root", server.getAdminPass())); .getPrivateAddresses(), new Credentials("root", server.getAdminPass()));
} }
} }

View File

@ -30,6 +30,7 @@ import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -70,7 +71,8 @@ public class CloudServersHardwareSupplier implements Supplier<Set<? extends Hard
for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) { for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) {
sizes.add(new HardwareImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null, sizes.add(new HardwareImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null,
ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(from.getDisk() / 10.0, 1.0)), from ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(from.getDisk() / 10.0, 1.0)), from
.getRam(), from.getDisk(), ImagePredicates.any())); .getRam(), ImmutableList.of(new VolumeImpl((float) from.getDisk(), true, true)),
ImagePredicates.any()));
} }
logger.debug("<< sizes(%d)", sizes.size()); logger.debug("<< sizes(%d)", sizes.size());
return sizes; return sizes;

View File

@ -69,6 +69,8 @@ public class ParseCloudServersErrorFromHttpResponse implements HttpErrorHandler
exception = new ResourceNotFoundException(message); exception = new ResourceNotFoundException(message);
} }
break; break;
case 409:
exception = new IllegalStateException(content);
default: default:
exception = new HttpResponseException(command, response, content); exception = new HttpResponseException(command, response, content);
} }

View File

@ -0,0 +1,60 @@
package org.jclouds.rackspace.cloudfiles.blobstore.strategy;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.http.HttpRequest;
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
import org.jclouds.rackspace.cloudfiles.config.CloudFilesRestClientModule;
import org.jclouds.rackspace.cloudservers.TestRackspaceAuthenticationRestClientModule;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextFactory.ContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code SignGetBlob}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "cloudfiles.SignGetBlobTest")
public class SignGetBlobTest extends RestClientTest<CloudFilesAsyncClient> {
public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
HttpRequest request = new SignGetObject(processor).apply("container", "blob");
assertRequestLineEquals(request, "GET http://storageUrl/container/blob HTTP/1.1");
assertNonPayloadHeadersEqual(request, "X-Auth-Token: testtoken\n");
assertPayloadEquals(request, null, null, false);
assertEquals(request.getFilters().size(), 0);
}
protected Module createModule() {
return new CloudFilesRestClientModule(new TestRackspaceAuthenticationRestClientModule());
}
@Override
protected void checkFilters(HttpRequest request) {
}
@Override
protected TypeLiteral<RestAnnotationProcessor<CloudFilesAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<CloudFilesAsyncClient>>() {
};
}
@Override
public ContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("cloudfiles", "identity", "credential", new Properties());
}
}

View File

@ -30,23 +30,21 @@ import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@RequiresHttp @RequiresHttp
@ConfiguresRestClient class TestRackspaceAuthenticationRestClientModule extends @ConfiguresRestClient
RackspaceAuthenticationRestModule { public class TestRackspaceAuthenticationRestClientModule extends RackspaceAuthenticationRestModule {
@Override @Override
protected void configure() { protected void configure() {
super.configure(); super.configure();
} }
@Override @Override
protected AuthenticationResponse provideAuthenticationResponse( protected AuthenticationResponse provideAuthenticationResponse(Supplier<AuthenticationResponse> supplier) {
Supplier<AuthenticationResponse> supplier) { return new AuthenticationResponseImpl("authToken", "http://CDNManagementUrl", "http://serverManagementUrl",
return new AuthenticationResponseImpl("authToken", "http://CDNManagementUrl", "http://storageUrl");
"http://serverManagementUrl", "http://storageUrl");
} }
@Override @Override
public Supplier<String> provideAuthenticationTokenCache( public Supplier<String> provideAuthenticationTokenCache(Supplier<AuthenticationResponse> supplier) {
Supplier<AuthenticationResponse> supplier) {
return new Supplier<String>() { return new Supplier<String>() {
public String get() { public String get() {
return "testtoken"; return "testtoken";

View File

@ -29,6 +29,7 @@ import java.net.UnknownHostException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
@ -58,6 +59,11 @@ public class ServerToNodeMetadataTest {
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage); Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
org.jclouds.compute.domain.Hardware jcHardware = createMock(org.jclouds.compute.domain.Hardware.class);
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(jcHardware);
Server server = createMock(Server.class); Server server = createMock(Server.class);
expect(server.getId()).andReturn(10000).atLeastOnce(); expect(server.getId()).andReturn(10000).atLeastOnce();
@ -81,17 +87,23 @@ public class ServerToNodeMetadataTest {
expect(addresses.getPrivateAddresses()).andReturn(privateAddresses); expect(addresses.getPrivateAddresses()).andReturn(privateAddresses);
expect(server.getImageId()).andReturn(2000).atLeastOnce(); expect(server.getImageId()).andReturn(2000).atLeastOnce();
expect(jcImage.getProviderId()).andReturn("2000").atLeastOnce(); expect(jcImage.getProviderId()).andReturn("2000").atLeastOnce();
expect(jcHardware.getProviderId()).andReturn("1000").atLeastOnce();
expect(server.getFlavorId()).andReturn(1000).atLeastOnce();
expect(jcImage.getLocation()).andReturn(provider).atLeastOnce(); expect(jcImage.getLocation()).andReturn(provider).atLeastOnce();
expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
replay(addresses); replay(addresses);
replay(jcImage); replay(jcImage);
replay(jcHardware);
replay(serverStateToNodeState); replay(serverStateToNodeState);
replay(server); replay(server);
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, Suppliers ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, Suppliers
.<Set<? extends Image>> ofInstance(images), Suppliers.ofInstance(provider)); .<Set<? extends Image>> ofInstance(images), Suppliers.ofInstance(provider), Suppliers
.<Set<? extends Hardware>> ofInstance(hardwares));
NodeMetadata metadata = parser.apply(server); NodeMetadata metadata = parser.apply(server);
assertEquals(metadata.getLocation(), location); assertEquals(metadata.getLocation(), location);
@ -107,6 +119,8 @@ public class ServerToNodeMetadataTest {
verify(serverStateToNodeState); verify(serverStateToNodeState);
verify(server); verify(server);
verify(jcImage); verify(jcImage);
verify(jcHardware);
} }
} }

View File

@ -61,8 +61,6 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
private final Function<Server, Iterable<String>> getPublicAddresses; private final Function<Server, Iterable<String>> getPublicAddresses;
private final Map<RunningState, NodeState> runningStateToNodeState; private final Map<RunningState, NodeState> runningStateToNodeState;
private final Supplier<Set<? extends Image>> images; private final Supplier<Set<? extends Image>> images;
@SuppressWarnings("unused")
private final Supplier<Set<? extends Location>> locations;
private static class FindImageForServer implements Predicate<Image> { private static class FindImageForServer implements Predicate<Image> {
private final Location location; private final Location location;
@ -83,12 +81,10 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
@Inject @Inject
ServerToNodeMetadata(Function<Server, Iterable<String>> getPublicAddresses, ServerToNodeMetadata(Function<Server, Iterable<String>> getPublicAddresses,
Map<RunningState, NodeState> runningStateToNodeState, Supplier<Set<? extends Image>> images, Map<RunningState, NodeState> runningStateToNodeState, Supplier<Set<? extends Image>> images) {
Supplier<Set<? extends Location>> locations) {
this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState"); this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState");
this.runningStateToNodeState = checkNotNull(runningStateToNodeState, "serverStateToNodeState"); this.runningStateToNodeState = checkNotNull(runningStateToNodeState, "serverStateToNodeState");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
this.locations = checkNotNull(locations, "locations");
} }
@Override @Override
@ -105,11 +101,11 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
logger.warn("could not find a matching image for server %s in location %s", from, location); logger.warn("could not find a matching image for server %s in location %s", from, location);
} }
NodeState state = runningStateToNodeState.get(from.getState()); NodeState state = runningStateToNodeState.get(from.getState());
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
.<String, String> of(), tag, from.getImageId(), image != null ? image.getOperatingSystem() : null, .<String, String> of(), tag, null, from.getImageId(), image != null ? image.getOperatingSystem() : null,
state, getPublicAddresses.apply(from), ImmutableList.<String> of(), ImmutableMap.<String, String> of(), state, getPublicAddresses.apply(from), ImmutableList.<String> of(), creds);
creds);
} }
} }

View File

@ -65,9 +65,9 @@ public class RimuHostingAddNodeWithTagStrategy implements AddNodeWithTagStrategy
"imageId"), checkNotNull(template.getHardware().getProviderId(), "hardwareId")); "imageId"), checkNotNull(template.getHardware().getProviderId(), "hardwareId"));
Server server = client.getServer(serverResponse.getServer().getId()); Server server = client.getServer(serverResponse.getServer().getId());
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template
.getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getImage().getId(), template .getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getHardware(), template
.getImage().getOperatingSystem(), runningStateToNodeState.get(server.getState()), getPublicAddresses .getImage().getId(), template.getImage().getOperatingSystem(), runningStateToNodeState.get(server
.apply(server), ImmutableList.<String> of(), ImmutableMap.<String, String> of(), new Credentials("root", .getState()), getPublicAddresses.apply(server), ImmutableList.<String> of(), new Credentials("root",
serverResponse.getNewInstanceRequest().getCreateOptions().getPassword())); serverResponse.getNewInstanceRequest().getCreateOptions().getPassword()));
return node; return node;
} }

View File

@ -29,6 +29,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -78,8 +79,8 @@ public class RimuHostingHardwareSupplier implements Supplier<Set<? extends Hardw
}); });
sizes.add(new HardwareImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap sizes.add(new HardwareImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap
.<String, String> of(), ImmutableList.of(new Processor(1, 1.0)), from.getRam(), from.getDiskSize(), .<String, String> of(), ImmutableList.of(new Processor(1, 1.0)), from.getRam(), ImmutableList
ImagePredicates.any())); .of(new VolumeImpl((float) from.getDiskSize(), true, true)), ImagePredicates.any()));
} catch (NullPointerException e) { } catch (NullPointerException e) {
logger.warn("datacenter not present in " + from.getId()); logger.warn("datacenter not present in " + from.getId());
} }

View File

@ -29,6 +29,7 @@ import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
@ -50,6 +51,7 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
private final Supplier<Location> location; private final Supplier<Location> location;
private final Map<Slice.Status, NodeState> sliceToNodeState; private final Map<Slice.Status, NodeState> sliceToNodeState;
private final Supplier<Set<? extends Image>> images; private final Supplier<Set<? extends Image>> images;
private final Supplier<Set<? extends Hardware>> hardwares;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -67,12 +69,26 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
} }
} }
private static class FindHardwareForSlice implements Predicate<Hardware> {
private final Slice slice;
private FindHardwareForSlice(Slice slice) {
this.slice = slice;
}
@Override
public boolean apply(Hardware input) {
return input.getProviderId().equals(slice.getFlavorId() + "");
}
}
@Inject @Inject
SliceToNodeMetadata(Map<Slice.Status, NodeState> sliceStateToNodeState, Supplier<Set<? extends Image>> images, SliceToNodeMetadata(Map<Slice.Status, NodeState> sliceStateToNodeState, Supplier<Set<? extends Image>> images,
Supplier<Location> location) { Supplier<Location> location, Supplier<Set<? extends Hardware>> hardwares) {
this.sliceToNodeState = checkNotNull(sliceStateToNodeState, "sliceStateToNodeState"); this.sliceToNodeState = checkNotNull(sliceStateToNodeState, "sliceStateToNodeState");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
this.location = checkNotNull(location, "location"); this.location = checkNotNull(location, "location");
this.hardwares = checkNotNull(hardwares, "hardwares");
} }
@Override @Override
@ -84,9 +100,14 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
logger.warn("could not find a matching image for slice %s in location %s", from, location); logger.warn("could not find a matching image for slice %s in location %s", from, location);
} }
Hardware hardware = null;
try {
hardware = Iterables.find(hardwares.get(), new FindHardwareForSlice(from));
} catch (NoSuchElementException e) {
logger.warn("could not find a matching hardware for slice %s", from);
}
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null, return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null,
ImmutableMap.<String, String> of(), tag, from.getImageId() + "", image != null ? image ImmutableMap.<String, String> of(), tag, hardware, from.getImageId() + "", image != null ? image
.getOperatingSystem() : null, sliceToNodeState.get(from.getStatus()), Iterables.filter(from .getOperatingSystem() : null, sliceToNodeState.get(from.getStatus()), Iterables.filter(from
.getAddresses(), new Predicate<String>() { .getAddresses(), new Predicate<String>() {
@ -102,6 +123,6 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
return input.startsWith("10."); return input.startsWith("10.");
} }
}), ImmutableMap.<String, String> of(), null); }), null);
} }
} }

View File

@ -55,8 +55,8 @@ public class SlicehostAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
Slice slice = client.createSlice(name, Integer.parseInt(template.getImage().getProviderId()), Integer Slice slice = client.createSlice(name, Integer.parseInt(template.getImage().getProviderId()), Integer
.parseInt(template.getHardware().getProviderId())); .parseInt(template.getHardware().getProviderId()));
return new NodeMetadataImpl(slice.getId() + "", name, slice.getId() + "", template.getLocation(), null, return new NodeMetadataImpl(slice.getId() + "", name, slice.getId() + "", template.getLocation(), null,
ImmutableMap.<String, String> of(), tag, template.getImage().getId(), template.getImage() ImmutableMap.<String, String> of(), tag, template.getHardware(), template.getImage().getId(), template
.getOperatingSystem(), NodeState.PENDING, Iterables.filter(slice.getAddresses(), .getImage().getOperatingSystem(), NodeState.PENDING, Iterables.filter(slice.getAddresses(),
new Predicate<String>() { new Predicate<String>() {
@Override @Override
@ -71,7 +71,7 @@ public class SlicehostAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
return input.startsWith("10."); return input.startsWith("10.");
} }
}), ImmutableMap.<String, String> of(), new Credentials("root", slice.getRootPassword())); }), new Credentials("root", slice.getRootPassword()));
} }
} }

View File

@ -29,6 +29,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -66,8 +67,9 @@ public class SlicehostHardwareSupplier implements Supplier<Set<? extends Hardwar
logger.debug(">> providing sizes"); logger.debug(">> providing sizes");
for (final Flavor from : sync.listFlavors()) { for (final Flavor from : sync.listFlavors()) {
sizes.add(new HardwareImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null, sizes.add(new HardwareImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null,
ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(from.getRam() / 1024.0, 1.0)), from ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(from.getRam() / 1024.0, 1.0)),
.getRam(), (from.getRam() * 4) / 1024, ImagePredicates.any())); from.getRam(), ImmutableList.of(new VolumeImpl((from.getRam() * 4) / 1024.0f, true, true)),
ImagePredicates.any()));
} }
logger.debug("<< sizes(%d)", sizes.size()); logger.debug("<< sizes(%d)", sizes.size());
return sizes; return sizes;

View File

@ -171,8 +171,8 @@ public class ComputeTask extends Task {
private void listHardwares(ComputeService computeService) { private void listHardwares(ComputeService computeService) {
log("list hardwares"); log("list hardwares");
for (Hardware hardware : computeService.listHardwareProfiles()) {// TODO for (Hardware hardware : computeService.listHardwareProfiles()) {// TODO
log(String.format(" hardware id=%s, cores=%s, ram=%s, disk=%s", hardware.getProviderId(), getCores(hardware), hardware log(String.format(" hardware id=%s, cores=%s, ram=%s, volumes=%s", hardware.getProviderId(), getCores(hardware), hardware
.getRam(), hardware.getDisk())); .getRam(), hardware.getVolumes()));
} }
} }
@ -252,10 +252,10 @@ public class ComputeTask extends Task {
private void logDetails(ComputeService computeService, ComputeMetadata node) { private void logDetails(ComputeService computeService, ComputeMetadata node) {
NodeMetadata metadata = node instanceof NodeMetadata ? NodeMetadata.class.cast(node) : computeService NodeMetadata metadata = node instanceof NodeMetadata ? NodeMetadata.class.cast(node) : computeService
.getNodeMetadata(node.getId()); .getNodeMetadata(node.getId());
log(String.format(" node id=%s, name=%s, tag=%s, location=%s, state=%s, publicIp=%s, privateIp=%s, extra=%s", log(String.format(" node id=%s, name=%s, tag=%s, location=%s, state=%s, publicIp=%s, privateIp=%s, hardware=%s",
metadata.getProviderId(), metadata.getName(), metadata.getTag(), metadata.getLocation(), metadata metadata.getProviderId(), metadata.getName(), metadata.getTag(), metadata.getLocation(), metadata
.getState(), ComputeTaskUtils.ipOrEmptyString(metadata.getPublicAddresses()), .getState(), ComputeTaskUtils.ipOrEmptyString(metadata.getPublicAddresses()),
ipOrEmptyString(metadata.getPrivateAddresses()), metadata.getExtra())); ipOrEmptyString(metadata.getPrivateAddresses()), metadata.getHardware()));
} }
/** /**

View File

@ -1,56 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.functions;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.VApp;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
@Singleton
public class GetExtraFromVApp implements Function<VApp, Map<String, String>> {
private final GetExtraFromVm getExtraFromVm;
@Inject
GetExtraFromVApp(GetExtraFromVm getExtraFromVm) {
this.getExtraFromVm = getExtraFromVm;
}
@Resource
protected Logger logger = Logger.NULL;
public Map<String, String> apply(VApp vApp) {
// TODO make this work with composite vApps
return vApp.getChildren().size() == 0 ? ImmutableMap.<String, String> of() : getExtraFromVm.apply(Iterables.get(
vApp.getChildren(), 0));
}
}

View File

@ -1,74 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.functions;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Maps.newHashMap;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import com.google.common.base.Function;
/**
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link VCloudExpressComputeClientImpl} bound.
*
* @author Adrian Cole
*/
@Singleton
public class GetExtraFromVCloudExpressVApp implements Function<VCloudExpressVApp, Map<String, String>> {
@Resource
protected Logger logger = Logger.NULL;
public Map<String, String> apply(VCloudExpressVApp vApp) {
Map<String, String> extra = newHashMap();
try {
extra.put("memory/mb", find(vApp.getResourceAllocations(), resourceType(ResourceType.MEMORY))
.getVirtualQuantity()
+ "");
extra.put("processor/count", find(vApp.getResourceAllocations(), resourceType(ResourceType.PROCESSOR))
.getVirtualQuantity()
+ "");
for (ResourceAllocation disk : filter(vApp.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE))) {
extra.put(String.format("disk_drive/%s/kb", disk.getAddressOnParent()), disk.getVirtualQuantity() + "");
}
for (Entry<String, String> net : vApp.getNetworkToAddresses().entries()) {
extra.put(String.format("network/%s/ip", net.getKey()), net.getValue());
}
} catch (Exception e) {
logger.error(e, "error getting extra data for vApp: %s", vApp);
}
return extra;
}
}

View File

@ -1,81 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.functions;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Maps.newHashMap;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class GetExtraFromVm implements Function<Vm, Map<String, String>> {
@Resource
protected Logger logger = Logger.NULL;
public Map<String, String> apply(Vm vm) {
Map<String, String> extra = newHashMap();
try {
extra.put("memory/mb", find(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.MEMORY)).getVirtualQuantity()
+ "");
extra.put("processor/count", find(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.PROCESSOR)).getVirtualQuantity()
+ "");
for (ResourceAllocation disk : filter(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.DISK_DRIVE))) {
if (disk instanceof VCloudHardDisk) {
VCloudHardDisk vDisk = VCloudHardDisk.class.cast(disk);
extra.put(String.format("disk_drive/%s/mb", disk.getAddressOnParent()), vDisk.getCapacity() + "");
} else {
extra.put(String.format("disk_drive/%s/kb", disk.getAddressOnParent()), disk.getVirtualQuantity() + "");
}
}
for (ResourceAllocation net : filter(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.ETHERNET_ADAPTER))) {
if (net instanceof VCloudNetworkAdapter) {
VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net);
extra.put(String.format("network/%s/ip", net.getAddressOnParent()), vNet.getIpAddress());
}
}
} catch (Exception e) {
logger.error(e, "error getting extra data for vm: %s", vm);
}
return extra;
}
}

View File

@ -0,0 +1,97 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import java.util.List;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* @author Adrian Cole
*/
public class HardwareForVApp implements Function<VApp, Hardware> {
@Resource
protected Logger logger = Logger.NULL;
private final FindLocationForResource findLocationForResource;
private final ResourceAllocationsToVolumes resourceAllocationsToVolumes;
@Inject
protected HardwareForVApp(FindLocationForResource findLocationForResource,
ResourceAllocationsToVolumes resourceAllocationsToVolumes) {
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.resourceAllocationsToVolumes = checkNotNull(resourceAllocationsToVolumes, "resourceAllocationsToVolumes");
}
@Override
public Hardware apply(VApp from) {
checkNotNull(from, "VApp");
// TODO make this work with composite vApps
Vm vm = from.getChildren().size() == 0 ? null : Iterables.get(from.getChildren(), 0);
if (vm == null)
return null;
Location location = findLocationForResource.apply(checkNotNull(from, "from").getVDC());
VirtualHardwareSection hardware = vm.getVirtualHardwareSection();
int ram = (int) find(hardware.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity();
List<Processor> processors = Lists.newArrayList(transform(filter(hardware.getResourceAllocations(),
resourceType(ResourceType.PROCESSOR)), new Function<ResourceAllocation, Processor>() {
@Override
public Processor apply(ResourceAllocation arg0) {
return new Processor(arg0.getVirtualQuantity(), 1);
}
}));
Iterable<? extends Volume> volumes = resourceAllocationsToVolumes.apply(hardware.getResourceAllocations());
return new HardwareImpl(from.getHref().toASCIIString(), from.getName()
+ String.format(": vpus(%s), ram(%d), volumes(%s)", processors, ram, volumes), from.getHref()
.toASCIIString(), location, null, ImmutableMap.<String, String> of(), processors, ram, volumes,
ImagePredicates.idEquals(from.getHref().toASCIIString()));
}
}

View File

@ -32,6 +32,7 @@ import javax.inject.Inject;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -42,7 +43,6 @@ import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.ovf.OvfEnvelope; import org.jclouds.vcloud.domain.ovf.OvfEnvelope;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation; import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection; import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -60,12 +60,16 @@ public class HardwareForVAppTemplate implements Function<VAppTemplate, Hardware>
private final VCloudClient client; private final VCloudClient client;
private final FindLocationForResource findLocationForResource; private final FindLocationForResource findLocationForResource;
private final ResourceAllocationsToVolumes resourceAllocationsToVolumes;
private ReferenceType parent; private ReferenceType parent;
@Inject @Inject
protected HardwareForVAppTemplate(VCloudClient client, FindLocationForResource findLocationForResource) { protected HardwareForVAppTemplate(VCloudClient client, FindLocationForResource findLocationForResource,
ResourceAllocationsToVolumes resourceAllocationsToVolumes) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.resourceAllocationsToVolumes = checkNotNull(resourceAllocationsToVolumes, "resourceAllocationsToVolumes");
} }
public HardwareForVAppTemplate withParent(ReferenceType parent) { public HardwareForVAppTemplate withParent(ReferenceType parent) {
@ -99,11 +103,9 @@ public class HardwareForVAppTemplate implements Function<VAppTemplate, Hardware>
VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getHardware(), 0); VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getHardware(), 0);
int ram = (int) find(hardware.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity(); int ram = (int) find(hardware.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity();
ResourceAllocation diskR = find(hardware.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE));
int disk = (int) (((diskR instanceof VCloudHardDisk) ? VCloudHardDisk.class.cast(diskR).getCapacity() : diskR
.getVirtualQuantity()) / 1024l);
List<Processor> processors = Lists.newArrayList(transform(filter(hardware.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)), new Function<ResourceAllocation, Processor>(){ List<Processor> processors = Lists.newArrayList(transform(filter(hardware.getResourceAllocations(),
resourceType(ResourceType.PROCESSOR)), new Function<ResourceAllocation, Processor>() {
@Override @Override
public Processor apply(ResourceAllocation arg0) { public Processor apply(ResourceAllocation arg0) {
@ -111,11 +113,11 @@ public class HardwareForVAppTemplate implements Function<VAppTemplate, Hardware>
} }
})); }));
Iterable<? extends Volume> volumes = resourceAllocationsToVolumes.apply(hardware.getResourceAllocations());
return new HardwareImpl(from.getHref().toASCIIString(), from.getName() return new HardwareImpl(from.getHref().toASCIIString(), from.getName()
+ String.format(": vpus(%s), ram(%d), disk(%d)", processors, ram, disk), from.getHref().toASCIIString(), + String.format(": vpus(%s), ram(%d), volumes(%s)", processors, ram, volumes), from.getHref()
location, null, ImmutableMap.<String, String> of(), processors, ram, disk, ImagePredicates.idEquals(from .toASCIIString(), location, null, ImmutableMap.<String, String> of(), processors, ram, volumes,
.getHref().toASCIIString())); ImagePredicates.idEquals(from.getHref().toASCIIString()));
} }

View File

@ -0,0 +1,88 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import java.util.List;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
/**
* @author Adrian Cole
*/
public class HardwareForVCloudExpressVApp implements Function<VCloudExpressVApp, Hardware> {
@Resource
protected Logger logger = Logger.NULL;
private final FindLocationForResource findLocationForResource;
private final ResourceAllocationsToVolumes resourceAllocationsToVolumes;
@Inject
protected HardwareForVCloudExpressVApp(FindLocationForResource findLocationForResource,
ResourceAllocationsToVolumes resourceAllocationsToVolumes) {
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.resourceAllocationsToVolumes = checkNotNull(resourceAllocationsToVolumes, "resourceAllocationsToVolumes");
}
@Override
public Hardware apply(VCloudExpressVApp from) {
checkNotNull(from, "VApp");
Location location = findLocationForResource.apply(checkNotNull(from, "from").getVDC());
int ram = (int) find(from.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity();
List<Processor> processors = Lists.newArrayList(transform(filter(from.getResourceAllocations(),
resourceType(ResourceType.PROCESSOR)), new Function<ResourceAllocation, Processor>() {
@Override
public Processor apply(ResourceAllocation arg0) {
return new Processor(arg0.getVirtualQuantity(), 1);
}
}));
Iterable<? extends Volume> volumes = resourceAllocationsToVolumes.apply(from.getResourceAllocations());
return new HardwareImpl(from.getHref().toASCIIString(), from.getName()
+ String.format(": vpus(%s), ram(%d), volumes(%s)", processors, ram, volumes), from.getHref()
.toASCIIString(), location, null, ImmutableMap.<String, String> of(), processors, ram, volumes,
ImagePredicates.idEquals(from.getHref().toASCIIString()));
}
}

View File

@ -0,0 +1,62 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.functions;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class ResourceAllocationsToVolumes implements
Function<Iterable<? extends ResourceAllocation>, Iterable<? extends Volume>> {
@Override
public Iterable<? extends Volume> apply(Iterable<? extends ResourceAllocation> resourceAllocations) {
Iterable<Volume> volumes = transform(filter(resourceAllocations, resourceType(ResourceType.DISK_DRIVE)),
new Function<ResourceAllocation, Volume>() {
@Override
public Volume apply(ResourceAllocation from) {
if (from instanceof VCloudHardDisk) {
VCloudHardDisk vDisk = VCloudHardDisk.class.cast(from);
return new VolumeImpl(from.getAddressOnParent() + "", Volume.Type.LOCAL,
vDisk.getCapacity() * 1024f, null, from.getAddressOnParent() == 0, true);
} else {
return new VolumeImpl(from.getAddressOnParent() + "", Volume.Type.LOCAL, from
.getVirtualQuantity() * 1024 * 1024f, null, from.getAddressOnParent() == 0, true);
}
}
});
return volumes;
}
}

View File

@ -70,7 +70,8 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
@Override @Override
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory( InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory(
template.getHardware().getRam()).disk(template.getHardware().getDisk() * 1024 * 1024l); template.getHardware().getRam()).disk(
(long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l));
String customizationScript = null; String customizationScript = null;
if (template.getOptions() instanceof VCloudTemplateOptions) { if (template.getOptions() instanceof VCloudTemplateOptions) {
@ -99,8 +100,8 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task); return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task);
} else { } else {
if (!successTester.apply(task.getHref())) { if (!successTester.apply(task.getHref())) {
throw new RuntimeException( throw new RuntimeException(String
String.format("failed to %s %s: %s", "instantiate", vAppResponse.getName(), task)); .format("failed to %s %s: %s", "instantiate", vAppResponse.getName(), task));
} }
Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0); Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0);
GuestCustomizationSection guestConfiguration = vm.getGuestCustomizationSection(); GuestCustomizationSection guestConfiguration = vm.getGuestCustomizationSection();
@ -113,8 +114,8 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
guestConfiguration.setCustomizationScript(customizationScript); guestConfiguration.setCustomizationScript(customizationScript);
task = client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration); task = client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration);
if (!successTester.apply(task.getHref())) { if (!successTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "updateGuestCustomizationOfVm", throw new RuntimeException(String.format("failed to %s %s: %s", "updateGuestCustomizationOfVm", vm
vm.getName(), task)); .getName(), task));
} }
task = client.deployAndPowerOnVAppOrVm(vAppResponse.getHref()); task = client.deployAndPowerOnVAppOrVm(vAppResponse.getHref());
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task); return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task);
@ -126,8 +127,8 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
Task task) { Task task) {
if (options.shouldBlock()) { if (options.shouldBlock()) {
if (!successTester.apply(task.getHref())) { if (!successTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on", throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on", vAppResponse
vAppResponse.getName(), task)); .getName(), task));
} }
logger.debug("<< ready vApp(%s)", vAppResponse.getName()); logger.debug("<< ready vApp(%s)", vAppResponse.getName());
} }

View File

@ -64,11 +64,12 @@ public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrate
@Override @Override
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory( InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory(
template.getHardware().getRam()).disk(template.getHardware().getDisk() * 1024 * 1024l); template.getHardware().getRam()).disk(
(long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l));
if (!template.getOptions().shouldBlockUntilRunning()) if (!template.getOptions().shouldBlockUntilRunning())
options.block(false); options.block(false);
Map<String, String> metaMap = computeClient.start(URI.create(template.getLocation().getId()), Map<String, String> metaMap = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template
URI.create(template.getImage().getId()), name, options, template.getOptions().getInboundPorts()); .getImage().getId()), name, options, template.getOptions().getInboundPorts());
VCloudExpressVApp vApp = client.getVApp(URI.create(metaMap.get("id"))); VCloudExpressVApp vApp = client.getVApp(URI.create(metaMap.get("id")));
return newCreateNodeResponse(tag, template, metaMap, vApp); return newCreateNodeResponse(tag, template, metaMap, vApp);
} }
@ -76,11 +77,11 @@ public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrate
protected NodeMetadata newCreateNodeResponse(String tag, Template template, Map<String, String> metaMap, protected NodeMetadata newCreateNodeResponse(String tag, Template template, Map<String, String> metaMap,
VCloudExpressVApp vApp) { VCloudExpressVApp vApp) {
return new NodeMetadataImpl(vApp.getHref().toASCIIString(), vApp.getName(), vApp.getHref().toASCIIString(), return new NodeMetadataImpl(vApp.getHref().toASCIIString(), vApp.getName(), vApp.getHref().toASCIIString(),
template.getLocation(), vApp.getHref(), ImmutableMap.<String, String> of(), tag, template.getImage() template.getLocation(), vApp.getHref(), ImmutableMap.<String, String> of(), tag, template.getHardware(),
.getId(), getOperatingSystemForVAppOrDefaultTo(vApp, template.getImage().getOperatingSystem()), template.getImage().getId(), getOperatingSystemForVAppOrDefaultTo(vApp, template.getImage()
vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(vApp.getHref()), .getOperatingSystem()), vAppStatusToNodeState.get(vApp.getStatus()), computeClient
computeClient.getPrivateAddresses(vApp.getHref()), ImmutableMap.<String, String> of(), new Credentials( .getPublicAddresses(vApp.getHref()), computeClient.getPrivateAddresses(vApp.getHref()),
metaMap.get("username"), metaMap.get("password"))); new Credentials(metaMap.get("username"), metaMap.get("password")));
} }
private OperatingSystem getOperatingSystemForVAppOrDefaultTo(VCloudExpressVApp vApp, OperatingSystem operatingSystem) { private OperatingSystem getOperatingSystemForVAppOrDefaultTo(VCloudExpressVApp vApp, OperatingSystem operatingSystem) {

View File

@ -31,6 +31,7 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
@ -43,7 +44,7 @@ import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient; import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResource; import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.GetExtraFromVCloudExpressVApp; import org.jclouds.vcloud.compute.functions.HardwareForVCloudExpressVApp;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.VCloudExpressVApp;
@ -62,16 +63,16 @@ public class VCloudExpressGetNodeMetadataStrategy implements GetNodeMetadataStra
protected final VCloudExpressComputeClient computeClient; protected final VCloudExpressComputeClient computeClient;
protected final Supplier<Set<? extends Image>> images; protected final Supplier<Set<? extends Image>> images;
protected final FindLocationForResource findLocationForResourceInVDC; protected final FindLocationForResource findLocationForResourceInVDC;
protected final GetExtraFromVCloudExpressVApp getExtra; protected final HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp;
protected final Map<Status, NodeState> vAppStatusToNodeState; protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject @Inject
protected VCloudExpressGetNodeMetadataStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient, protected VCloudExpressGetNodeMetadataStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient,
Map<Status, NodeState> vAppStatusToNodeState, GetExtraFromVCloudExpressVApp getExtra, Map<Status, NodeState> vAppStatusToNodeState, HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images) { FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
this.getExtra = checkNotNull(getExtra, "getExtra"); this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC"); this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
this.computeClient = checkNotNull(computeClient, "computeClient"); this.computeClient = checkNotNull(computeClient, "computeClient");
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState"); this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
@ -84,11 +85,12 @@ public class VCloudExpressGetNodeMetadataStrategy implements GetNodeMetadataStra
return null; return null;
String tag = parseTagFromName(from.getName()); String tag = parseTagFromName(from.getName());
Location location = findLocationForResourceInVDC.apply(from.getVDC()); Location location = findLocationForResourceInVDC.apply(from.getVDC());
Hardware hardware = hardwareForVCloudExpressVApp.apply(from);
return new NodeMetadataImpl(in, from.getName(), in, location, from.getHref(), ImmutableMap.<String, String> of(), return new NodeMetadataImpl(in, from.getName(), in, location, from.getHref(), ImmutableMap.<String, String> of(),
tag, null, from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(from tag, hardware, null, from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType
.getOsType()), null, null, from.getOperatingSystemDescription()) : null, vAppStatusToNodeState .fromValue(from.getOsType()), null, null, from.getOperatingSystemDescription()) : null,
.get(from.getStatus()), computeClient.getPublicAddresses(id), computeClient vAppStatusToNodeState.get(from.getStatus()), computeClient.getPublicAddresses(id), computeClient
.getPrivateAddresses(id), getExtra.apply(from), null); .getPrivateAddresses(id), null);
} }
} }

View File

@ -35,6 +35,7 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
@ -45,7 +46,7 @@ import org.jclouds.domain.Location;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResource; import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.GetExtraFromVApp; import org.jclouds.vcloud.compute.functions.HardwareForVApp;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
@ -63,16 +64,16 @@ public class VCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
protected final VCloudClient client; protected final VCloudClient client;
protected final Supplier<Set<? extends Image>> images; protected final Supplier<Set<? extends Image>> images;
protected final FindLocationForResource findLocationForResourceInVDC; protected final FindLocationForResource findLocationForResourceInVDC;
protected final GetExtraFromVApp getExtra; protected final HardwareForVApp hardwareForVApp;
protected final Map<Status, NodeState> vAppStatusToNodeState; protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject @Inject
protected VCloudGetNodeMetadataStrategy(VCloudClient client, Map<Status, NodeState> vAppStatusToNodeState, protected VCloudGetNodeMetadataStrategy(VCloudClient client, Map<Status, NodeState> vAppStatusToNodeState,
GetExtraFromVApp getExtra, FindLocationForResource findLocationForResourceInVDC, HardwareForVApp hardwareForVApp, FindLocationForResource findLocationForResourceInVDC,
Supplier<Set<? extends Image>> images) { Supplier<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
this.getExtra = checkNotNull(getExtra, "getExtra"); this.hardwareForVApp = checkNotNull(hardwareForVApp, "hardwareForVApp");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC"); this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState"); this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
} }
@ -84,8 +85,9 @@ public class VCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
return null; return null;
String tag = parseTagFromName(from.getName()); String tag = parseTagFromName(from.getName());
Location location = findLocationForResourceInVDC.apply(from.getVDC()); Location location = findLocationForResourceInVDC.apply(from.getVDC());
Hardware hardware = hardwareForVApp.apply(from);
return new NodeMetadataImpl(in, from.getName(), in, location, from.getHref(), ImmutableMap.<String, String> of(), return new NodeMetadataImpl(in, from.getName(), in, location, from.getHref(), ImmutableMap.<String, String> of(),
tag, null, toComputeOs(from, null), vAppStatusToNodeState.get(from.getStatus()), tag, hardware, null, toComputeOs(from, null), vAppStatusToNodeState.get(from.getStatus()),
getPublicIpsFromVApp(from), getPrivateIpsFromVApp(from), getExtra.apply(from), getCredentialsFrom(from)); getPublicIpsFromVApp(from), getPrivateIpsFromVApp(from), getCredentialsFrom(from));
} }
} }

View File

@ -26,6 +26,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -46,7 +47,8 @@ public class StaticHardwareSupplier implements Supplier<Set<? extends Hardware>>
for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) { for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) {
String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10); String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10);
sizes.add(new HardwareImpl(id, null, id, null, null, ImmutableMap.<String, String> of(), ImmutableList sizes.add(new HardwareImpl(id, null, id, null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(cpus, 1.0)), ram, 10, ImagePredicates.any())); .of(new Processor(cpus, 1.0)), ram, ImmutableList.of(new VolumeImpl(10f, true, true)),
ImagePredicates.any()));
} }
return sizes; return sizes;
} }

View File

@ -70,10 +70,7 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assert node.getLocation() != null; assert node.getLocation() != null;
assertEquals(node.getType(), ComputeType.NODE); assertEquals(node.getType(), ComputeType.NODE);
NodeMetadata allData = client.getNodeMetadata(node.getId()); NodeMetadata allData = client.getNodeMetadata(node.getId());
assert allData.getExtra().get("processor/count") != null : allData.getExtra(); System.out.println(allData.getHardware());
assert allData.getExtra().get("disk_drive/0/kb") != null : allData.getExtra();
assert allData.getExtra().get("memory/mb") != null : allData.getExtra();
System.out.println(allData.getExtra());
} }
} }
} }

View File

@ -70,10 +70,7 @@ public class VCloudExpressComputeServiceLiveTest extends BaseComputeServiceLiveT
assert node.getLocation() != null; assert node.getLocation() != null;
assertEquals(node.getType(), ComputeType.NODE); assertEquals(node.getType(), ComputeType.NODE);
NodeMetadata allData = client.getNodeMetadata(node.getId()); NodeMetadata allData = client.getNodeMetadata(node.getId());
assert allData.getExtra().get("processor/count") != null : allData.getExtra(); System.out.println(allData.getHardware());
assert allData.getExtra().get("disk_drive/0/kb") != null : allData.getExtra();
assert allData.getExtra().get("memory/mb") != null : allData.getExtra();
System.out.println(allData.getExtra());
} }
} }

View File

@ -42,7 +42,7 @@ import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient; import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.compute.domain.VCloudLocation; import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.compute.functions.FindLocationForResource; import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.GetExtraFromVCloudExpressVApp; import org.jclouds.vcloud.compute.functions.HardwareForVCloudExpressVApp;
import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy; import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.terremark.compute.domain.KeyPairCredentials; import org.jclouds.vcloud.terremark.compute.domain.KeyPairCredentials;
@ -64,7 +64,7 @@ public class TerremarkVCloudGetNodeMetadataStrategy extends VCloudExpressGetNode
@Inject @Inject
protected TerremarkVCloudGetNodeMetadataStrategy(VCloudExpressClient client, protected TerremarkVCloudGetNodeMetadataStrategy(VCloudExpressClient client,
VCloudExpressComputeClient computeClient, Map<Status, NodeState> vAppStatusToNodeState, VCloudExpressComputeClient computeClient, Map<Status, NodeState> vAppStatusToNodeState,
GetExtraFromVCloudExpressVApp getExtra, FindLocationForResource findLocationForResourceInVDC, HardwareForVCloudExpressVApp getExtra, FindLocationForResource findLocationForResourceInVDC,
Supplier<Set<? extends Image>> images, ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) { Supplier<Set<? extends Image>> images, ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
super(client, computeClient, vAppStatusToNodeState, getExtra, findLocationForResourceInVDC, images); super(client, computeClient, vAppStatusToNodeState, getExtra, findLocationForResourceInVDC, images);
this.credentialsMap = credentialsMap; this.credentialsMap = credentialsMap;