mirror of https://github.com/apache/jclouds.git
Merge remote branch 'origin'
Conflicts: core/src/main/resources/rest.properties
This commit is contained in:
commit
a4e3d7ead3
|
@ -53,6 +53,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
|
|||
import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.concurrent.Futures;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.domain.Location;
|
||||
|
@ -81,9 +82,9 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
@Inject
|
||||
AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||
Supplier<Set<? extends Location>> locations, AtmosStorageAsyncClient async, AtmosStorageClient sync,
|
||||
ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
|
||||
BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, AtmosStorageAsyncClient async,
|
||||
AtmosStorageClient sync, ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd,
|
||||
BlobToObject blob2Object, BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
||||
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
|
||||
BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
||||
super(context, blobUtils, service, defaultLocation, locations);
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
|
|||
import org.jclouds.blobstore.internal.BaseBlobStore;
|
||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
|
@ -68,7 +69,7 @@ public class AtmosBlobStore extends BaseBlobStore {
|
|||
|
||||
@Inject
|
||||
AtmosBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
||||
Supplier<Set<? extends Location>> locations, AtmosStorageClient sync, ObjectToBlob object2Blob,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, AtmosStorageClient sync, ObjectToBlob object2Blob,
|
||||
ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
|
||||
BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
||||
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
|
|||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.internal.LocationImpl;
|
||||
|
@ -72,6 +73,7 @@ public class AtmosBlobStoreContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
||||
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ import org.jclouds.http.options.GetOptions;
|
|||
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.RestContextSpec;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
|
@ -270,7 +270,7 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("atmosonline", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ 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.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -139,7 +139,7 @@ public class AtmosBlobRequestSignerTest extends RestClientTest<AtmosStorageAsync
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("atmosonline", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,16 @@
|
|||
|
||||
package org.jclouds.aws.config;
|
||||
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Iterables.get;
|
||||
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
@ -39,14 +43,13 @@ import org.jclouds.http.RequiresHttp;
|
|||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.annotations.Provider;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -61,8 +64,7 @@ import com.google.inject.name.Names;
|
|||
@RequiresHttp
|
||||
public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
|
||||
|
||||
public AWSRestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
|
||||
Map<Class<?>, Class<?>> delegates) {
|
||||
public AWSRestClientModule(Class<S> syncClientType, Class<A> asyncClientType, Map<Class<?>, Class<?>> delegates) {
|
||||
super(syncClientType, asyncClientType, delegates);
|
||||
}
|
||||
|
||||
|
@ -74,12 +76,13 @@ public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
|
|||
@Singleton
|
||||
@Region
|
||||
protected Map<String, URI> provideRegions(Injector injector) {
|
||||
String regionString = injector.getInstance(Key.get(String.class, Names
|
||||
.named(PROPERTY_REGIONS)));
|
||||
Map<String, URI> regions = Maps.newLinkedHashMap();
|
||||
String regionString = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGIONS)));
|
||||
Map<String, URI> regions = newLinkedHashMap();
|
||||
for (String region : Splitter.on(',').split(regionString)) {
|
||||
regions.put(region, URI.create(injector.getInstance(Key.get(String.class, Names
|
||||
.named(Constants.PROPERTY_ENDPOINT + "." + region)))));
|
||||
regions.put(
|
||||
region,
|
||||
URI.create(injector.getInstance(Key.get(String.class,
|
||||
Names.named(Constants.PROPERTY_ENDPOINT + "." + region)))));
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
@ -94,33 +97,35 @@ public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
|
|||
@Provides
|
||||
@Singleton
|
||||
@Region
|
||||
protected String getDefaultRegion(@Provider final URI uri, @Region Map<String, URI> map) {
|
||||
return Iterables.find(map.entrySet(), new Predicate<Entry<String, URI>>() {
|
||||
protected String getDefaultRegion(@Provider final URI uri, @Region Map<String, URI> map, LoggerFactory logFactory) {
|
||||
try {
|
||||
return find(map.entrySet(), new Predicate<Entry<String, URI>>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Entry<String, URI> input) {
|
||||
return input.getValue().equals(uri);
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Entry<String, URI> input) {
|
||||
return input.getValue().equals(uri);
|
||||
}
|
||||
|
||||
}).getKey();
|
||||
}).getKey();
|
||||
} catch (NoSuchElementException e) {
|
||||
String region = get(map.keySet(), 0);
|
||||
logFactory.getLogger("jclouds.compute").warn(
|
||||
"failed to find region for current endpoint %s in %s; choosing first: %s", uri, map, region);
|
||||
return region;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindErrorHandlers() {
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
|
||||
ParseAWSErrorFromXmlContent.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
|
||||
ParseAWSErrorFromXmlContent.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
|
||||
ParseAWSErrorFromXmlContent.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseAWSErrorFromXmlContent.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseAWSErrorFromXmlContent.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseAWSErrorFromXmlContent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindRetryHandlers() {
|
||||
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
|
||||
AWSRedirectionRetryHandler.class);
|
||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
|
||||
AWSClientErrorRetryHandler.class);
|
||||
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(AWSRedirectionRetryHandler.class);
|
||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(AWSClientErrorRetryHandler.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -42,6 +42,7 @@ import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
|||
import org.jclouds.aws.ec2.domain.KeyPair;
|
||||
import org.jclouds.aws.ec2.domain.PlacementGroup;
|
||||
import org.jclouds.aws.ec2.domain.PlacementGroup.State;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
|
@ -56,6 +57,7 @@ import org.jclouds.compute.strategy.ListNodesStrategy;
|
|||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||
import org.jclouds.compute.util.ComputeUtils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -75,21 +77,21 @@ public class EC2ComputeService extends BaseComputeService {
|
|||
private final Predicate<PlacementGroup> placementGroupDeleted;
|
||||
|
||||
@Inject
|
||||
protected EC2ComputeService(ComputeServiceContext context, Supplier<Set<? extends Image>> images,
|
||||
Supplier<Set<? extends Hardware>> sizes, Supplier<Set<? extends Location>> locations,
|
||||
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||
DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||
Provider<TemplateOptions> templateOptionsProvider,
|
||||
protected EC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
||||
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
|
||||
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated, ComputeUtils utils, Timeouts timeouts,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client,
|
||||
Map<RegionAndName, KeyPair> credentialsMap, @Named("SECURITY") Map<RegionAndName, String> securityGroupMap,
|
||||
@Named("PLACEMENT") Map<RegionAndName, String> placementGroupMap,
|
||||
@Named("DELETED") Predicate<PlacementGroup> placementGroupDeleted) {
|
||||
super(context, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy,
|
||||
rebootNodeStrategy, destroyNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
|
||||
nodeTerminated, utils, timeouts, executor);
|
||||
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, templateBuilderProvider,
|
||||
templateOptionsProvider, nodeRunning, nodeTerminated, utils, timeouts, executor);
|
||||
this.ec2Client = ec2Client;
|
||||
this.credentialsMap = credentialsMap;
|
||||
this.securityGroupMap = securityGroupMap;
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
*
|
||||
* 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.config;
|
||||
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2DestroyNodeStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2ListNodesStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2RebootNodeStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy;
|
||||
import org.jclouds.compute.config.BindComputeStrategiesByClass;
|
||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class EC2BindComputeStrategiesByClass extends BindComputeStrategiesByClass {
|
||||
@Override
|
||||
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() {
|
||||
return EC2RunNodesAndAddToSetStrategy.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* not needed, as {@link EC2RunNodesAndAddToSetStrategy} is used and is already set-based.
|
||||
*/
|
||||
@Override
|
||||
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* not needed, as {@link EC2RunNodesAndAddToSetStrategy} is used and is already set-based.
|
||||
*/
|
||||
@Override
|
||||
protected void bindAddNodeWithTagStrategy(Class<? extends AddNodeWithTagStrategy> clazz) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||
return EC2DestroyNodeStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||
return EC2GetNodeMetadataStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||
return EC2ListNodesStrategy.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||
return EC2RebootNodeStrategy.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
*
|
||||
* 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.config;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.aws.ec2.compute.suppliers.EC2HardwareSupplier;
|
||||
import org.jclouds.aws.ec2.compute.suppliers.EC2ImageSupplier;
|
||||
import org.jclouds.aws.ec2.compute.suppliers.EC2LocationSupplier;
|
||||
import org.jclouds.compute.config.BindComputeSuppliersByClass;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class EC2BindComputeSuppliersByClass extends BindComputeSuppliersByClass {
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||
return EC2HardwareSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||
return EC2ImageSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
|
||||
return org.jclouds.aws.suppliers.DefaultLocationSupplier.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||
return EC2LocationSupplier.class;
|
||||
}
|
||||
}
|
|
@ -19,86 +19,34 @@
|
|||
|
||||
package org.jclouds.aws.ec2.compute.config;
|
||||
|
||||
import static com.google.common.collect.Iterables.toArray;
|
||||
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_CC_AMIs;
|
||||
import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX;
|
||||
import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.EC2AsyncClient;
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.aws.ec2.compute.EC2ComputeService;
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded;
|
||||
import org.jclouds.aws.ec2.compute.functions.CreateSecurityGroupIfNeeded;
|
||||
import org.jclouds.aws.ec2.compute.functions.CreateUniqueKeyPair;
|
||||
import org.jclouds.aws.ec2.compute.functions.RegionAndIdToImage;
|
||||
import org.jclouds.aws.ec2.compute.internal.EC2TemplateBuilderImpl;
|
||||
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2DestroyLoadBalancerStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2DestroyNodeStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2ListNodesStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2LoadBalanceNodesStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2RebootNodeStrategy;
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy;
|
||||
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.domain.KeyPair;
|
||||
import org.jclouds.aws.ec2.domain.PlacementGroup;
|
||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||
import org.jclouds.aws.ec2.predicates.InstancePresent;
|
||||
import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable;
|
||||
import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted;
|
||||
import org.jclouds.aws.suppliers.DefaultLocationSupplier;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.LoadBalanceNodesStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.annotations.Provider;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Configures the {@link ComputeServiceContext}; requires {@link EC2ComputeService} bound.
|
||||
|
@ -106,61 +54,12 @@ import com.google.inject.TypeLiteral;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class EC2ComputeServiceContextModule extends BaseComputeServiceContextModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("PRESENT")
|
||||
protected Predicate<RunningInstance> instancePresent(InstancePresent present) {
|
||||
return new RetryablePredicate<RunningInstance>(present, 5000, 200, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("AVAILABLE")
|
||||
protected Predicate<PlacementGroup> placementGroupAvailable(PlacementGroupAvailable available) {
|
||||
return new RetryablePredicate<PlacementGroup>(available, 60, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("DELETED")
|
||||
protected Predicate<PlacementGroup> placementGroupDeleted(PlacementGroupDeleted deleted) {
|
||||
return new RetryablePredicate<PlacementGroup>(deleted, 60, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new ComputeServiceTimeoutsModule());
|
||||
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
|
||||
bind(TemplateOptions.class).to(EC2TemplateOptions.class);
|
||||
bind(ComputeService.class).to(EC2ComputeService.class);
|
||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||
}).to(new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
bind(new TypeLiteral<RestContext<EC2Client, EC2AsyncClient>>() {
|
||||
}).to(new TypeLiteral<RestContextImpl<EC2Client, EC2AsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
bind(LoadBalanceNodesStrategy.class).to(EC2LoadBalanceNodesStrategy.class);
|
||||
bind(DestroyLoadBalancerStrategy.class).to(EC2DestroyLoadBalancerStrategy.class);
|
||||
bind(RunNodesAndAddToSetStrategy.class).to(EC2RunNodesAndAddToSetStrategy.class);
|
||||
bind(ListNodesStrategy.class).to(EC2ListNodesStrategy.class);
|
||||
bind(GetNodeMetadataStrategy.class).to(EC2GetNodeMetadataStrategy.class);
|
||||
bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class);
|
||||
bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Supplier<String> provideSuffix() {
|
||||
return new Supplier<String>() {
|
||||
final SecureRandom random = new SecureRandom();
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return random.nextInt(100) + "";
|
||||
}
|
||||
};
|
||||
|
||||
install(new EC2ComputeServiceDependenciesModule());
|
||||
install(new EC2BindComputeStrategiesByClass());
|
||||
install(new EC2BindComputeSuppliersByClass());
|
||||
super.configure();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,94 +73,22 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
|
|||
return template.osFamily(AMZN_LINUX).os64Bit(true);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected final Map<RegionAndName, KeyPair> credentialsMap(CreateUniqueKeyPair in) {
|
||||
// doesn't seem to clear when someone issues remove(key)
|
||||
// return new MapMaker().makeComputingMap(in);
|
||||
return newLinkedHashMap();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("SECURITY")
|
||||
protected final Map<RegionAndName, String> securityGroupMap(CreateSecurityGroupIfNeeded in) {
|
||||
// doesn't seem to clear when someone issues remove(key)
|
||||
// return new MapMaker().makeComputingMap(in);
|
||||
return newLinkedHashMap();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("PLACEMENT")
|
||||
protected final Map<RegionAndName, String> placementGroupMap(CreatePlacementGroupIfNeeded in) {
|
||||
// doesn't seem to clear when someone issues remove(key)
|
||||
// return new MapMaker().makeComputingMap(in);
|
||||
return newLinkedHashMap();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named(PROPERTY_EC2_AMI_OWNERS)
|
||||
String[] amiOwners(@Named(PROPERTY_EC2_AMI_OWNERS) String amiOwners) {
|
||||
if (amiOwners.trim().equals(""))
|
||||
return new String[] {};
|
||||
return toArray(Splitter.on(',').split(amiOwners), String.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named(PROPERTY_EC2_CC_AMIs)
|
||||
String[] ccAmis(@Named(PROPERTY_EC2_CC_AMIs) String ccAmis) {
|
||||
if (ccAmis.trim().equals(""))
|
||||
return new String[] {};
|
||||
return toArray(Splitter.on(',').split(ccAmis), String.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected ConcurrentMap<RegionAndName, Image> provideImageMap(RegionAndIdToImage regionAndIdToImage) {
|
||||
return new MapMaker().makeComputingMap(regionAndIdToImage);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final RegionAndNameToImageSupplier supplier) {
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final RegionAndNameToImageSupplier supplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<RegionAndName, ? extends Image>>(
|
||||
authException, seconds, new Supplier<Map<RegionAndName, ? extends Image>>() {
|
||||
@Override
|
||||
public Map<RegionAndName, ? extends Image> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
authException, seconds, new Supplier<Map<RegionAndName, ? extends Image>>() {
|
||||
@Override
|
||||
public Map<RegionAndName, ? extends Image> get() {
|
||||
return supplier.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
|
||||
Supplier<Map<RegionAndName, ? extends Image>> map = injector.getInstance(Key
|
||||
.get(new TypeLiteral<Supplier<Map<RegionAndName, ? extends Image>>>() {
|
||||
}));
|
||||
return Suppliers.compose(new Function<Map<RegionAndName, ? extends Image>, Set<? extends Image>>() {
|
||||
@Override
|
||||
public Set<? extends Image> apply(Map<RegionAndName, ? extends Image> from) {
|
||||
return Sets.newLinkedHashSet(from.values());
|
||||
}
|
||||
}, map);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
|
||||
return injector.getInstance(EC2LocationSupplier.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
|
||||
return injector.getInstance(EC2HardwareSupplier.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Supplier<Location> supplyDefaultLocation(Injector injector, Supplier<Set<? extends Location>> locations) {
|
||||
return injector.getInstance(DefaultLocationSupplier.class);
|
||||
protected void bindLoadBalancerService() {
|
||||
bind(LoadBalanceNodesStrategy.class).to(EC2LoadBalanceNodesStrategy.class);
|
||||
bind(DestroyLoadBalancerStrategy.class).to(EC2DestroyLoadBalancerStrategy.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,198 @@
|
|||
/**
|
||||
*
|
||||
* 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.config;
|
||||
|
||||
import static com.google.common.collect.Iterables.toArray;
|
||||
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_CC_AMIs;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.EC2AsyncClient;
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.aws.ec2.compute.EC2ComputeService;
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded;
|
||||
import org.jclouds.aws.ec2.compute.functions.CreateSecurityGroupIfNeeded;
|
||||
import org.jclouds.aws.ec2.compute.functions.CreateUniqueKeyPair;
|
||||
import org.jclouds.aws.ec2.compute.functions.CredentialsForInstance;
|
||||
import org.jclouds.aws.ec2.compute.functions.RegionAndIdToImage;
|
||||
import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
|
||||
import org.jclouds.aws.ec2.compute.internal.EC2TemplateBuilderImpl;
|
||||
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||
import org.jclouds.aws.ec2.domain.InstanceState;
|
||||
import org.jclouds.aws.ec2.domain.KeyPair;
|
||||
import org.jclouds.aws.ec2.domain.PlacementGroup;
|
||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||
import org.jclouds.aws.ec2.predicates.InstancePresent;
|
||||
import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable;
|
||||
import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class EC2ComputeServiceDependenciesModule extends AbstractModule {
|
||||
|
||||
public static final Map<InstanceState, NodeState> instanceToNodeState = ImmutableMap
|
||||
.<InstanceState, NodeState> builder().put(InstanceState.PENDING, NodeState.PENDING).put(
|
||||
InstanceState.RUNNING, NodeState.RUNNING).put(InstanceState.SHUTTING_DOWN, NodeState.PENDING).put(
|
||||
InstanceState.TERMINATED, NodeState.TERMINATED).put(InstanceState.STOPPING, NodeState.PENDING)
|
||||
.put(InstanceState.STOPPED, NodeState.SUSPENDED).put(InstanceState.UNRECOGNIZED, NodeState.UNRECOGNIZED)
|
||||
.build();
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<InstanceState, NodeState> provideServerToNodeState() {
|
||||
return instanceToNodeState;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("PRESENT")
|
||||
protected Predicate<RunningInstance> instancePresent(InstancePresent present) {
|
||||
return new RetryablePredicate<RunningInstance>(present, 5000, 200, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("AVAILABLE")
|
||||
protected Predicate<PlacementGroup> placementGroupAvailable(PlacementGroupAvailable available) {
|
||||
return new RetryablePredicate<PlacementGroup>(available, 60, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("DELETED")
|
||||
protected Predicate<PlacementGroup> placementGroupDeleted(PlacementGroupDeleted deleted) {
|
||||
return new RetryablePredicate<PlacementGroup>(deleted, 60, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
|
||||
bind(TemplateOptions.class).to(EC2TemplateOptions.class);
|
||||
bind(ComputeService.class).to(EC2ComputeService.class);
|
||||
bind(new TypeLiteral<Function<RunningInstance, NodeMetadata>>() {
|
||||
}).to(RunningInstanceToNodeMetadata.class);
|
||||
bind(new TypeLiteral<Function<RunningInstance, Credentials>>() {
|
||||
}).to(CredentialsForInstance.class);
|
||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||
}).to(new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
bind(new TypeLiteral<RestContext<EC2Client, EC2AsyncClient>>() {
|
||||
}).to(new TypeLiteral<RestContextImpl<EC2Client, EC2AsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Supplier<String> provideSuffix() {
|
||||
return new Supplier<String>() {
|
||||
final SecureRandom random = new SecureRandom();
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return random.nextInt(100) + "";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected final Map<RegionAndName, KeyPair> credentialsMap(CreateUniqueKeyPair in) {
|
||||
// doesn't seem to clear when someone issues remove(key)
|
||||
// return new MapMaker().makeComputingMap(in);
|
||||
return newLinkedHashMap();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("SECURITY")
|
||||
protected final Map<RegionAndName, String> securityGroupMap(CreateSecurityGroupIfNeeded in) {
|
||||
// doesn't seem to clear when someone issues remove(key)
|
||||
// return new MapMaker().makeComputingMap(in);
|
||||
return newLinkedHashMap();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("PLACEMENT")
|
||||
protected final Map<RegionAndName, String> placementGroupMap(CreatePlacementGroupIfNeeded in) {
|
||||
// doesn't seem to clear when someone issues remove(key)
|
||||
// return new MapMaker().makeComputingMap(in);
|
||||
return newLinkedHashMap();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named(PROPERTY_EC2_AMI_OWNERS)
|
||||
String[] amiOwners(@Named(PROPERTY_EC2_AMI_OWNERS) String amiOwners) {
|
||||
if (amiOwners.trim().equals(""))
|
||||
return new String[] {};
|
||||
return toArray(Splitter.on(',').split(amiOwners), String.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named(PROPERTY_EC2_CC_AMIs)
|
||||
String[] ccAmis(@Named(PROPERTY_EC2_CC_AMIs) String ccAmis) {
|
||||
if (ccAmis.trim().equals(""))
|
||||
return new String[] {};
|
||||
return toArray(Splitter.on(',').split(ccAmis), String.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Map<RegionAndName, Image> provideImageMap(RegionAndIdToImage regionAndIdToImage) {
|
||||
return new MapMaker().makeComputingMap(regionAndIdToImage);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,197 +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.compute.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static org.jclouds.compute.predicates.ImagePredicates.any;
|
||||
import static org.jclouds.compute.predicates.ImagePredicates.idIn;
|
||||
import static org.jclouds.compute.predicates.ImagePredicates.is64Bit;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jclouds.aws.ec2.domain.InstanceType;
|
||||
import org.jclouds.aws.ec2.domain.RootDeviceType;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
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.VolumeImpl;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a
|
||||
* href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html"
|
||||
* />
|
||||
*/
|
||||
public class EC2Hardware extends HardwareImpl {
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8605688733788974797L;
|
||||
private final String instanceType;
|
||||
|
||||
/**
|
||||
* evaluates true if the Image has the following rootDeviceType
|
||||
*
|
||||
* @param type
|
||||
* rootDeviceType of the image
|
||||
* @return predicate
|
||||
*/
|
||||
public static Predicate<Image> hasRootDeviceType(final RootDeviceType type) {
|
||||
checkNotNull(type, "type must be defined");
|
||||
return new Predicate<Image>() {
|
||||
@Override
|
||||
public boolean apply(Image image) {
|
||||
return type.toString().equals(image.getUserMetadata().get("rootDeviceType"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "hasRootDeviceType(" + type + ")";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram,
|
||||
Iterable<? extends Volume> volumes, RootDeviceType rootDeviceType) {
|
||||
this(null, instanceType, processors, ram, volumes, hasRootDeviceType(rootDeviceType));
|
||||
}
|
||||
|
||||
EC2Hardware(Location location, String instanceType, Iterable<? extends Processor> processors, Integer ram,
|
||||
Iterable<? extends Volume> volumes, Predicate<Image> supportsImage) {
|
||||
super(instanceType, instanceType, instanceType, location, null, ImmutableMap.<String, String> of(), processors,
|
||||
ram, volumes, supportsImage);
|
||||
this.instanceType = instanceType;
|
||||
}
|
||||
|
||||
EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram,
|
||||
Iterable<? extends Volume> volumes, boolean is64Bit) {
|
||||
this(null, instanceType, processors, ram, volumes, is64Bit ? is64Bit() : not(is64Bit()));
|
||||
}
|
||||
|
||||
public EC2Hardware(Location location, String instanceType, Iterable<? extends Processor> processors, Integer ram,
|
||||
Iterable<? extends Volume> volumes, String[] ids) {
|
||||
this(location, instanceType, processors, ram, volumes, (ids.length == 0 ? is64Bit() : idIn(Arrays.asList(ids))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the EC2 InstanceType associated with this size.
|
||||
*/
|
||||
public String getInstanceType() {
|
||||
return instanceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#M1_SMALL
|
||||
*/
|
||||
public static final EC2Hardware M1_SMALL = new EC2Hardware(InstanceType.M1_SMALL, ImmutableList.of(new Processor(
|
||||
1.0, 1.0)), 1740, ImmutableList.of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(150.0f,
|
||||
"/dev/sda2", false, false)), false);
|
||||
/**
|
||||
* In Nova, m1.small can run 64bit images.
|
||||
*
|
||||
* @see InstanceType#M1_SMALL
|
||||
*/
|
||||
public static final EC2Hardware M1_SMALL_NOVA = new EC2Hardware(null, InstanceType.M1_SMALL, ImmutableList
|
||||
.of(new Processor(1.0, 1.0)), 1740, ImmutableList.of(new VolumeImpl(10.0f, "/dev/sda1", true, false),
|
||||
new VolumeImpl(150.0f, "/dev/sda2", false, false)), any());
|
||||
|
||||
/**
|
||||
* @see InstanceType#T1_MICRO
|
||||
*/
|
||||
public static final EC2Hardware T1_MICRO = new EC2Hardware(InstanceType.T1_MICRO, ImmutableList.of(new Processor(
|
||||
1.0, 1.0)), 630, ImmutableList.<Volume> of(), RootDeviceType.EBS);
|
||||
/**
|
||||
* @see InstanceType#M1_LARGE
|
||||
*/
|
||||
public static final EC2Hardware M1_LARGE = new EC2Hardware(InstanceType.M1_LARGE, ImmutableList.of(new Processor(
|
||||
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
|
||||
*/
|
||||
public static final EC2Hardware M1_XLARGE = new EC2Hardware(InstanceType.M1_XLARGE, ImmutableList.of(new Processor(
|
||||
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
|
||||
*/
|
||||
public static final EC2Hardware M2_XLARGE = new EC2Hardware(InstanceType.M2_XLARGE, ImmutableList.of(new Processor(
|
||||
2.0, 3.25)), 17510, ImmutableList.of(new VolumeImpl(420.0f, "/dev/sda1", true, false)), true);
|
||||
/**
|
||||
* @see InstanceType#M2_2XLARGE
|
||||
*/
|
||||
public static final EC2Hardware M2_2XLARGE = new EC2Hardware(InstanceType.M2_2XLARGE, ImmutableList
|
||||
.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
|
||||
*/
|
||||
public static final EC2Hardware M2_4XLARGE = new EC2Hardware(InstanceType.M2_4XLARGE, ImmutableList
|
||||
.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
|
||||
*/
|
||||
public static final EC2Hardware C1_MEDIUM = new EC2Hardware(InstanceType.C1_MEDIUM, ImmutableList.of(new Processor(
|
||||
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
|
||||
*/
|
||||
public static final EC2Hardware C1_XLARGE = new EC2Hardware(InstanceType.C1_XLARGE, ImmutableList.of(new Processor(
|
||||
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
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((instanceType == null) ? 0 : instanceType.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;
|
||||
EC2Hardware other = (EC2Hardware) obj;
|
||||
if (instanceType == null) {
|
||||
if (other.instanceType != null)
|
||||
return false;
|
||||
} else if (!instanceType.equals(other.instanceType))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,262 @@
|
|||
/**
|
||||
*
|
||||
* 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.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.predicates.ImagePredicates.idIn;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.aws.ec2.domain.InstanceType;
|
||||
import org.jclouds.aws.ec2.domain.RootDeviceType;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.Volume;
|
||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a
|
||||
* href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html"
|
||||
* />
|
||||
*/
|
||||
public class EC2HardwareBuilder extends HardwareBuilder {
|
||||
|
||||
/**
|
||||
* evaluates true if the Image has the following rootDeviceType
|
||||
*
|
||||
* @param type
|
||||
* rootDeviceType of the image
|
||||
* @return predicate
|
||||
*/
|
||||
public static class HasRootDeviceType implements Predicate<Image> {
|
||||
final RootDeviceType type;
|
||||
|
||||
public HasRootDeviceType(final RootDeviceType type) {
|
||||
|
||||
this.type = checkNotNull(type, "type must be defined");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Image image) {
|
||||
return type.toString().equals(image.getUserMetadata().get("rootDeviceType"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "hasRootDeviceType(" + type + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder(String instanceType) {
|
||||
super();
|
||||
ids(instanceType);
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder rootDeviceType(RootDeviceType rootDeviceType) {
|
||||
supportsImage(new HasRootDeviceType(rootDeviceType));
|
||||
return this;
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder supportsImageIds(String... ids) {
|
||||
checkArgument(ids != null && ids.length > 0, "ids must be specified");
|
||||
supportsImage(idIn(Arrays.asList(ids)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder ids(String id) {
|
||||
return EC2HardwareBuilder.class.cast(super.ids(id));
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder ram(int ram) {
|
||||
return EC2HardwareBuilder.class.cast(super.ram(ram));
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder processors(List<Processor> processors) {
|
||||
return EC2HardwareBuilder.class.cast(super.processors(processors));
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder volumes(List<Volume> volumes) {
|
||||
return EC2HardwareBuilder.class.cast(super.volumes(volumes));
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder supportsImage(Predicate<Image> supportsImage) {
|
||||
return EC2HardwareBuilder.class.cast(super.supportsImage(supportsImage));
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder is64Bit(boolean is64Bit) {
|
||||
return EC2HardwareBuilder.class.cast(super.is64Bit(is64Bit));
|
||||
}
|
||||
|
||||
public EC2HardwareBuilder id(String id) {
|
||||
return EC2HardwareBuilder.class.cast(super.id(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EC2HardwareBuilder providerId(String providerId) {
|
||||
return EC2HardwareBuilder.class.cast(super.providerId(providerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EC2HardwareBuilder name(String name) {
|
||||
return EC2HardwareBuilder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EC2HardwareBuilder location(Location location) {
|
||||
return EC2HardwareBuilder.class.cast(super.location(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EC2HardwareBuilder uri(URI uri) {
|
||||
return EC2HardwareBuilder.class.cast(super.uri(uri));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EC2HardwareBuilder userMetadata(Map<String, String> userMetadata) {
|
||||
return EC2HardwareBuilder.class.cast(super.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#M1_SMALL
|
||||
*/
|
||||
public static EC2HardwareBuilder m1_small() {
|
||||
return new EC2HardwareBuilder(InstanceType.M1_SMALL)
|
||||
.ram(1740)
|
||||
.processors(ImmutableList.of(new Processor(1.0, 1.0)))
|
||||
.volumes(
|
||||
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(150.0f,
|
||||
"/dev/sda2", false, false))).is64Bit(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#T1_MICRO
|
||||
*/
|
||||
public static EC2HardwareBuilder t1_micro() {
|
||||
return new EC2HardwareBuilder(InstanceType.T1_MICRO).ram(630)
|
||||
.processors(ImmutableList.of(new Processor(1.0, 1.0))).rootDeviceType(RootDeviceType.EBS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#M1_LARGE
|
||||
*/
|
||||
public static EC2HardwareBuilder m1_large() {
|
||||
return new EC2HardwareBuilder(InstanceType.M1_LARGE)
|
||||
.ram(7680)
|
||||
.processors(ImmutableList.of(new Processor(2.0, 2.0)))
|
||||
.volumes(
|
||||
ImmutableList.<Volume> 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))).is64Bit(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#M1_XLARGE
|
||||
*/
|
||||
public static EC2HardwareBuilder m1_xlarge() {
|
||||
return new EC2HardwareBuilder(InstanceType.M1_XLARGE)
|
||||
.ram(15360)
|
||||
.processors(ImmutableList.of(new Processor(4.0, 2.0)))
|
||||
.volumes(
|
||||
ImmutableList.<Volume> 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)))
|
||||
.is64Bit(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#M2_XLARGE
|
||||
*/
|
||||
public static EC2HardwareBuilder m2_xlarge() {
|
||||
return new EC2HardwareBuilder(InstanceType.M2_XLARGE).ram(17510)
|
||||
.processors(ImmutableList.of(new Processor(2.0, 3.25)))
|
||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(420.0f, "/dev/sda1", true, false))).is64Bit(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#M2_2XLARGE
|
||||
*/
|
||||
public static EC2HardwareBuilder m2_2xlarge() {
|
||||
return new EC2HardwareBuilder(InstanceType.M2_2XLARGE)
|
||||
.ram(35020)
|
||||
.processors(ImmutableList.of(new Processor(4.0, 3.25)))
|
||||
.volumes(
|
||||
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(840.0f,
|
||||
"/dev/sdb", false, false))).is64Bit(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#M2_4XLARGE
|
||||
*/
|
||||
public static EC2HardwareBuilder m2_4xlarge() {
|
||||
return new EC2HardwareBuilder(InstanceType.M2_4XLARGE)
|
||||
.ram(70041)
|
||||
.processors(ImmutableList.of(new Processor(8.0, 3.25)))
|
||||
.volumes(
|
||||
ImmutableList.<Volume> 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))).is64Bit(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#C1_MEDIUM
|
||||
*/
|
||||
public static EC2HardwareBuilder c1_medium() {
|
||||
return new EC2HardwareBuilder(InstanceType.C1_MEDIUM)
|
||||
.ram(1740)
|
||||
.processors(ImmutableList.of(new Processor(2.0, 2.5)))
|
||||
.volumes(
|
||||
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(340.0f,
|
||||
"/dev/sda2", false, false))).is64Bit(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstanceType#C1_XLARGE
|
||||
*/
|
||||
public static EC2HardwareBuilder c1_xlarge() {
|
||||
return new EC2HardwareBuilder(InstanceType.C1_XLARGE)
|
||||
.ram(7168)
|
||||
.processors(ImmutableList.of(new Processor(8.0, 2.5)))
|
||||
.volumes(
|
||||
ImmutableList.<Volume> 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)))
|
||||
.is64Bit(true);
|
||||
}
|
||||
|
||||
public static EC2HardwareBuilder cc1_4xlarge() {
|
||||
return new EC2HardwareBuilder(InstanceType.CC1_4XLARGE)
|
||||
.ram(23 * 1024)
|
||||
.processors(ImmutableList.of(new Processor(4.0, 4.0), new Processor(4.0, 4.0)))
|
||||
.volumes(
|
||||
ImmutableList.<Volume> 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)));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
*
|
||||
* 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.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.aws.ec2.domain.KeyPair;
|
||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||
import org.jclouds.domain.Credentials;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class CredentialsForInstance implements Function<RunningInstance, Credentials> {
|
||||
private final Map<RegionAndName, KeyPair> credentialsMap;
|
||||
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
|
||||
private final Map<RegionAndName, Image> imageForInstance;
|
||||
|
||||
@Inject
|
||||
CredentialsForInstance(Map<RegionAndName, KeyPair> credentialsMap,
|
||||
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, Map<RegionAndName, Image> imageForInstance) {
|
||||
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
|
||||
this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
|
||||
this.imageForInstance = imageForInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Credentials apply(RunningInstance instance) {
|
||||
Credentials credentials = null;// default if no keypair exists
|
||||
|
||||
if (instance.getKeyName() != null) {
|
||||
credentials = new Credentials(getLoginAccountFor(instance), getPrivateKeyOrNull(instance));
|
||||
}
|
||||
return credentials;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getPrivateKeyOrNull(RunningInstance instance) {
|
||||
KeyPair keyPair = credentialsMap.get(new RegionAndName(instance.getRegion(), instance.getKeyName()));
|
||||
return keyPair != null ? keyPair.getKeyMaterial() : null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getLoginAccountFor(RunningInstance from) {
|
||||
return checkNotNull(
|
||||
credentialProvider.execute(imageForInstance.get(new RegionAndName(from.getRegion(), from.getImageId()))),
|
||||
"login from image: " + from.getImageId()).identity;
|
||||
}
|
||||
}
|
|
@ -35,13 +35,13 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.aws.ec2.domain.Image.Architecture;
|
||||
import org.jclouds.aws.ec2.domain.Image.ImageType;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.internal.ImageImpl;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.internal.LocationImpl;
|
||||
|
@ -92,7 +92,8 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
|
|||
|
||||
@Inject
|
||||
ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
|
||||
Supplier<Set<? extends Location>> locations, Supplier<Location> defaultLocation, @Provider String provider) {
|
||||
@Memoized Supplier<Set<? extends Location>> locations, Supplier<Location> defaultLocation,
|
||||
@Provider String provider) {
|
||||
this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
|
||||
this.locations = checkNotNull(locations, "locations");
|
||||
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
|
||||
|
@ -105,9 +106,12 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
|
|||
logger.trace("skipping as not a machine image(%s)", from.getId());
|
||||
return null;
|
||||
}
|
||||
String name = null;
|
||||
String description = from.getDescription() != null ? from.getDescription() : from.getImageLocation();
|
||||
String version = null;
|
||||
ImageBuilder builder = new ImageBuilder();
|
||||
builder.providerId(from.getId());
|
||||
builder.id(from.getRegion() + "/" + from.getId());
|
||||
builder.description(from.getDescription() != null ? from.getDescription() : from.getImageLocation());
|
||||
builder.userMetadata(ImmutableMap.<String, String> of("owner", from.getImageOwnerId(), "rootDeviceType", from
|
||||
.getRootDeviceType().toString()));
|
||||
|
||||
OsFamily osFamily = parseOsFamilyOrNull(provider, from.getImageLocation());
|
||||
String osName = null;
|
||||
|
@ -119,13 +123,14 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
|
|||
Matcher matcher = getMatcherAndFind(from.getImageLocation());
|
||||
if (matcher.pattern() == AMZN_PATTERN) {
|
||||
osFamily = OsFamily.AMZN_LINUX;
|
||||
version = osVersion = matcher.group(1);
|
||||
osVersion = matcher.group(1);
|
||||
builder.version(osVersion);
|
||||
} else if (matcher.pattern() == NEBULA_PATTERN) {
|
||||
osVersion = parseVersionOrReturnEmptyString(osFamily, matcher.group(2));
|
||||
} else {
|
||||
osFamily = OsFamily.fromValue(matcher.group(1));
|
||||
osVersion = parseVersionOrReturnEmptyString(osFamily, matcher.group(2));
|
||||
version = matcher.group(3).replace(".manifest.xml", "");
|
||||
builder.version(matcher.group(3).replace(".manifest.xml", ""));
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.debug("<< didn't match os(%s)", from.getImageLocation());
|
||||
|
@ -133,28 +138,24 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
|
|||
logger.debug("<< didn't match at all(%s)", from.getImageLocation());
|
||||
}
|
||||
|
||||
Credentials defaultCredentials = credentialProvider.execute(from);
|
||||
builder.defaultCredentials(credentialProvider.execute(from));
|
||||
|
||||
Location location = null;
|
||||
try {
|
||||
location = Iterables.find(locations.get(), new Predicate<Location>() {
|
||||
builder.location(Iterables.find(locations.get(), new Predicate<Location>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getId().equals(from.getRegion());
|
||||
}
|
||||
|
||||
});
|
||||
}));
|
||||
} catch (NoSuchElementException e) {
|
||||
System.err.printf("unknown region %s for image %s; not in %s", from.getRegion(), from.getId(), locations);
|
||||
location = new LocationImpl(LocationScope.REGION, from.getRegion(), from.getRegion(), defaultLocation.get()
|
||||
.getParent());
|
||||
builder.location(new LocationImpl(LocationScope.REGION, from.getRegion(), from.getRegion(), defaultLocation
|
||||
.get().getParent()));
|
||||
}
|
||||
OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
|
||||
return new ImageImpl(from.getId(), name, from.getRegion() + "/" + from.getId(), location, null, ImmutableMap
|
||||
.<String, String> of("owner", from.getImageOwnerId(), "rootDeviceType", from.getRootDeviceType()
|
||||
.toString()), os, description, version, defaultCredentials);
|
||||
|
||||
builder.operatingSystem(new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,34 +22,30 @@ package org.jclouds.aws.ec2.compute.functions;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.util.Utils.nullSafeSet;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.aws.ec2.domain.InstanceState;
|
||||
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.EbsBlockDevice;
|
||||
import org.jclouds.aws.ec2.options.DescribeImagesOptions;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
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.VolumeImpl;
|
||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||
import org.jclouds.compute.util.ComputeServiceUtils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
@ -58,9 +54,8 @@ import com.google.common.annotations.VisibleForTesting;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ComputationException;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -71,69 +66,59 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@VisibleForTesting
|
||||
static final Map<InstanceState, NodeState> instanceToNodeState = ImmutableMap.<InstanceState, NodeState> builder()
|
||||
.put(InstanceState.PENDING, NodeState.PENDING).put(InstanceState.RUNNING, NodeState.RUNNING).put(
|
||||
InstanceState.SHUTTING_DOWN, NodeState.PENDING)
|
||||
.put(InstanceState.TERMINATED, NodeState.TERMINATED).put(InstanceState.STOPPING, NodeState.PENDING).put(
|
||||
InstanceState.STOPPED, NodeState.SUSPENDED)
|
||||
.put(InstanceState.UNRECOGNIZED, NodeState.UNRECOGNIZED).build();
|
||||
|
||||
private final EC2Client client;
|
||||
private final Map<RegionAndName, KeyPair> credentialsMap;
|
||||
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
|
||||
private final Supplier<Set<? extends Location>> locations;
|
||||
private final Supplier<Set<? extends Hardware>> hardware;
|
||||
private final ConcurrentMap<RegionAndName, Image> imageMap;
|
||||
protected final Supplier<Set<? extends Location>> locations;
|
||||
protected final Supplier<Set<? extends Hardware>> hardware;
|
||||
protected final Map<RegionAndName, Image> instanceToImage;
|
||||
protected final Map<String, Credentials> credentialStore;
|
||||
protected final Map<InstanceState, NodeState> instanceToNodeState;
|
||||
|
||||
@Inject
|
||||
RunningInstanceToNodeMetadata(EC2Client client, Map<RegionAndName, KeyPair> credentialsMap,
|
||||
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
|
||||
ConcurrentMap<RegionAndName, Image> imageMap, Supplier<Set<? extends Location>> locations,
|
||||
Supplier<Set<? extends Hardware>> hardware) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
|
||||
this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
|
||||
RunningInstanceToNodeMetadata(Map<InstanceState, NodeState> instanceToNodeState,
|
||||
Map<String, Credentials> credentialStore, Map<RegionAndName, Image> instanceToImage,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Hardware>> hardware) {
|
||||
this.locations = checkNotNull(locations, "locations");
|
||||
this.hardware = checkNotNull(hardware, "hardware");
|
||||
this.imageMap = checkNotNull(imageMap, "imageMap");
|
||||
this.instanceToImage = checkNotNull(instanceToImage, "instanceToImage");
|
||||
this.instanceToNodeState = checkNotNull(instanceToNodeState, "instanceToNodeState");
|
||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(final RunningInstance instance) {
|
||||
String id = checkNotNull(instance, "instance").getId();
|
||||
|
||||
String name = null; // user doesn't determine a node name;
|
||||
URI uri = null; // no uri to get rest access to host info
|
||||
|
||||
public NodeMetadata apply(RunningInstance instance) {
|
||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||
String providerId = checkNotNull(instance, "instance").getId();
|
||||
builder.providerId(providerId);
|
||||
builder.id(instance.getRegion() + "/" + providerId);
|
||||
String tag = getTagForInstance(instance);
|
||||
builder.tag(tag);
|
||||
builder.credentials(credentialStore.get(instance.getRegion() + "/" + providerId));
|
||||
builder.state(instanceToNodeState.get(instance.getInstanceState()));
|
||||
builder.publicAddresses(nullSafeSet(instance.getIpAddress()));
|
||||
builder.privateAddresses(nullSafeSet(instance.getPrivateIpAddress()));
|
||||
builder.hardware(parseHardware(instance));
|
||||
Location location = getLocationForAvailabilityZoneOrRegion(instance);
|
||||
builder.location(location);
|
||||
builder.imageId(instance.getRegion() + "/" + instance.getImageId());
|
||||
|
||||
Credentials credentials = getCredentialsForInstanceWithTag(instance, tag);
|
||||
// extract the operating system from the image
|
||||
Image image = instanceToImage.get(new RegionAndName(instance.getRegion(), instance.getImageId()));
|
||||
if (image != null)
|
||||
builder.operatingSystem(image.getOperatingSystem());
|
||||
|
||||
Map<String, String> userMetadata = ImmutableMap.<String, String> of();
|
||||
|
||||
NodeState state = instanceToNodeState.get(instance.getInstanceState());
|
||||
|
||||
Set<String> publicAddresses = nullSafeSet(instance.getIpAddress());
|
||||
Set<String> privateAddresses = nullSafeSet(instance.getPrivateIpAddress());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected Hardware parseHardware(final RunningInstance instance) {
|
||||
Hardware hardware = getHardwareForInstance(instance);
|
||||
|
||||
if (hardware != null) {
|
||||
hardware = ComputeServiceUtils.replacesVolumes(hardware, addEBS(instance, hardware.getVolumes()));
|
||||
hardware = HardwareBuilder.fromHardware(hardware).volumes(addEBS(instance, hardware.getVolumes())).build();
|
||||
}
|
||||
|
||||
Location location = getLocationForAvailabilityZoneOrRegion(instance);
|
||||
|
||||
Image image = resolveImageForInstanceInLocation(instance, location);
|
||||
|
||||
return new NodeMetadataImpl(id, name, instance.getRegion() + "/" + instance.getId(), location, uri, userMetadata,
|
||||
tag, hardware, instance.getRegion() + "/" + instance.getImageId(), image != null ? image
|
||||
.getOperatingSystem() : null, state, publicAddresses, privateAddresses, credentials);
|
||||
return hardware;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static Iterable<? extends Volume> addEBS(final RunningInstance instance, Iterable<? extends Volume> volumes) {
|
||||
static List<Volume> addEBS(final RunningInstance instance, Iterable<? extends Volume> volumes) {
|
||||
Iterable<Volume> ebsVolumes = Iterables.transform(instance.getEbsBlockDevices().entrySet(),
|
||||
new Function<Entry<String, EbsBlockDevice>, Volume>() {
|
||||
|
||||
|
@ -156,19 +141,10 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
});
|
||||
|
||||
}
|
||||
return Iterables.concat(volumes, ebsVolumes);
|
||||
return Lists.newArrayList(Iterables.concat(volumes, ebsVolumes));
|
||||
|
||||
}
|
||||
|
||||
private Credentials getCredentialsForInstanceWithTag(final RunningInstance instance, String tag) {
|
||||
Credentials credentials = null;// default if no keypair exists
|
||||
|
||||
if (instance.getKeyName() != null) {
|
||||
credentials = new Credentials(getLoginAccountFor(instance), getPrivateKeyOrNull(instance, tag));
|
||||
}
|
||||
return credentials;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getTagForInstance(final RunningInstance instance) {
|
||||
String tag = String.format("NOTAG-%s", instance.getId());// default
|
||||
|
@ -233,36 +209,4 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Image resolveImageForInstanceInLocation(final RunningInstance instance, final Location location) {
|
||||
Image image = null;
|
||||
RegionAndName key = new RegionAndName(instance.getRegion(), instance.getImageId());
|
||||
try {
|
||||
image = imageMap.get(key);
|
||||
} catch (NullPointerException nex) {
|
||||
logger.debug("could not find a matching image for instance %s in location %s", instance, location);
|
||||
} catch (ComputationException nex) {
|
||||
logger.debug("could not find a matching image for instance %s in location %s", instance, location);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getPrivateKeyOrNull(RunningInstance instance, String tag) {
|
||||
KeyPair keyPair = credentialsMap.get(new RegionAndName(instance.getRegion(), instance.getKeyName()));
|
||||
return keyPair != null ? keyPair.getKeyMaterial() : null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String getLoginAccountFor(RunningInstance from) {
|
||||
org.jclouds.aws.ec2.domain.Image image = null;
|
||||
try {
|
||||
image = Iterables.getOnlyElement(client.getAMIServices().describeImagesInRegion(from.getRegion(),
|
||||
DescribeImagesOptions.Builder.imageIds(from.getImageId())));
|
||||
} catch (NoSuchElementException e) {
|
||||
logger.debug("couldn't find image %s/%s", from.getRegion(), from.getImageId());
|
||||
}
|
||||
return checkNotNull(credentialProvider.execute(image), "login from image: " + from.getImageId()).identity;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,9 +21,9 @@ package org.jclouds.aws.ec2.compute.internal;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -31,6 +31,7 @@ import javax.inject.Provider;
|
|||
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
|
@ -47,14 +48,13 @@ import com.google.common.collect.ComputationException;
|
|||
*/
|
||||
public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
||||
|
||||
private final ConcurrentMap<RegionAndName, Image> imageMap;
|
||||
private final Map<RegionAndName, Image> imageMap;
|
||||
|
||||
@Inject
|
||||
protected EC2TemplateBuilderImpl(Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
|
||||
Supplier<Set<? extends Hardware>> sizes, Supplier<Location> defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider,
|
||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider,
|
||||
ConcurrentMap<RegionAndName, Image> imageMap) {
|
||||
protected EC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
|
||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||
Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider,
|
||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Map<RegionAndName, Image> imageMap) {
|
||||
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
|
||||
this.imageMap = imageMap;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.jclouds.aws.ec2.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static org.jclouds.aws.ec2.options.RunInstancesOptions.Builder.asType;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -30,7 +29,6 @@ import javax.inject.Inject;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.compute.domain.EC2Hardware;
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules;
|
||||
import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded;
|
||||
|
@ -66,10 +64,10 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions
|
|||
|
||||
@Inject
|
||||
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions(Map<RegionAndName, KeyPair> credentialsMap,
|
||||
@Named("SECURITY") Map<RegionAndName, String> securityGroupMap,
|
||||
@Named("PLACEMENT") Map<RegionAndName, String> placementGroupMap, CreateUniqueKeyPair createUniqueKeyPair,
|
||||
CreateSecurityGroupIfNeeded createSecurityGroupIfNeeded,
|
||||
CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded) {
|
||||
@Named("SECURITY") Map<RegionAndName, String> securityGroupMap,
|
||||
@Named("PLACEMENT") Map<RegionAndName, String> placementGroupMap, CreateUniqueKeyPair createUniqueKeyPair,
|
||||
CreateSecurityGroupIfNeeded createSecurityGroupIfNeeded,
|
||||
CreatePlacementGroupIfNeeded createPlacementGroupIfNeeded) {
|
||||
this.credentialsMap = credentialsMap;
|
||||
this.securityGroupMap = securityGroupMap;
|
||||
this.placementGroupMap = placementGroupMap;
|
||||
|
@ -79,17 +77,13 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions
|
|||
}
|
||||
|
||||
public RunInstancesOptions execute(String region, String tag, Template template) {
|
||||
checkArgument(template.getHardware() instanceof EC2Hardware, "unexpected image type. should be EC2Size, was: "
|
||||
+ template.getHardware().getClass());
|
||||
EC2Hardware ec2Size = EC2Hardware.class.cast(template.getHardware());
|
||||
|
||||
RunInstancesOptions instanceOptions = asType(ec2Size.getInstanceType()).withAdditionalInfo(tag);
|
||||
RunInstancesOptions instanceOptions = asType(template.getHardware().getId()).withAdditionalInfo(tag);
|
||||
|
||||
String keyPairName = createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, template.getOptions());
|
||||
|
||||
String placementGroupName = ec2Size.getId().startsWith("cc") ? createNewPlacementGroupUnlessUserSpecifiedOtherwise(
|
||||
region, tag, template.getOptions())
|
||||
: null;
|
||||
String placementGroupName = template.getHardware().getId().startsWith("cc") ? createNewPlacementGroupUnlessUserSpecifiedOtherwise(
|
||||
region, tag, template.getOptions()) : null;
|
||||
|
||||
String subnetId = EC2TemplateOptions.class.cast(template.getOptions()).getSubnetId();
|
||||
|
||||
|
@ -122,7 +116,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions
|
|||
keyPairName = EC2TemplateOptions.class.cast(options).getKeyPair();
|
||||
if (keyPairName == null)
|
||||
shouldAutomaticallyCreateKeyPair = EC2TemplateOptions.class.cast(options)
|
||||
.shouldAutomaticallyCreateKeyPair();
|
||||
.shouldAutomaticallyCreateKeyPair();
|
||||
}
|
||||
if (keyPairName == null && shouldAutomaticallyCreateKeyPair) {
|
||||
RegionAndName regionAndName = new RegionAndName(region, tag);
|
||||
|
@ -147,7 +141,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions
|
|||
placementGroupName = EC2TemplateOptions.class.cast(options).getPlacementGroup();
|
||||
if (placementGroupName == null)
|
||||
shouldAutomaticallyCreatePlacementGroup = EC2TemplateOptions.class.cast(options)
|
||||
.shouldAutomaticallyCreatePlacementGroup();
|
||||
.shouldAutomaticallyCreatePlacementGroup();
|
||||
}
|
||||
if (placementGroupName == null && shouldAutomaticallyCreatePlacementGroup) {
|
||||
placementGroupName = String.format("jclouds#%s#%s", tag, region);
|
||||
|
@ -171,17 +165,17 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions
|
|||
|
||||
if (options instanceof EC2TemplateOptions && EC2TemplateOptions.class.cast(options).getGroupIds().size() > 0) {
|
||||
regionNameAndIngessRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, new int[] {},
|
||||
false);
|
||||
false);
|
||||
groups.addAll(EC2TemplateOptions.class.cast(options).getGroupIds());
|
||||
|
||||
} else {
|
||||
regionNameAndIngessRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup, options
|
||||
.getInboundPorts(), true);
|
||||
regionNameAndIngessRulesForMarkerGroup = new RegionNameAndIngressRules(region, markerGroup,
|
||||
options.getInboundPorts(), true);
|
||||
}
|
||||
|
||||
if (!securityGroupMap.containsKey(regionNameAndIngessRulesForMarkerGroup)) {
|
||||
securityGroupMap.put(regionNameAndIngessRulesForMarkerGroup, createSecurityGroupIfNeeded
|
||||
.apply(regionNameAndIngessRulesForMarkerGroup));
|
||||
securityGroupMap.put(regionNameAndIngessRulesForMarkerGroup,
|
||||
createSecurityGroupIfNeeded.apply(regionNameAndIngessRulesForMarkerGroup));
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
|
|
|
@ -53,12 +53,12 @@ public class EC2DestroyNodeStrategy implements DestroyNodeStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata execute(String id) {
|
||||
public NodeMetadata destroyNode(String id) {
|
||||
String[] parts = parseHandle(id);
|
||||
String region = parts[0];
|
||||
String instanceId = parts[1];
|
||||
ec2Client.getInstanceServices().terminateInstancesInRegion(region,
|
||||
instanceId);
|
||||
return getNode.execute(id);
|
||||
return getNode.getNode(id);
|
||||
}
|
||||
}
|
|
@ -29,11 +29,12 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
|
||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
|
@ -42,22 +43,23 @@ import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
|||
public class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy {
|
||||
|
||||
private final EC2Client client;
|
||||
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
|
||||
private final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
|
||||
|
||||
@Inject
|
||||
protected EC2GetNodeMetadataStrategy(EC2Client client, RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) {
|
||||
protected EC2GetNodeMetadataStrategy(EC2Client client,
|
||||
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata) {
|
||||
this.client = client;
|
||||
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata execute(String id) {
|
||||
public NodeMetadata getNode(String id) {
|
||||
String[] parts = parseHandle(id);
|
||||
String region = parts[0];
|
||||
String instanceId = parts[1];
|
||||
try {
|
||||
RunningInstance runningInstance = getOnlyElement(getAllRunningInstancesInRegion(client.getInstanceServices(),
|
||||
region, instanceId));
|
||||
region, instanceId));
|
||||
return runningInstanceToNodeMetadata.apply(runningInstance);
|
||||
} catch (NoSuchElementException e) {
|
||||
return null;
|
||||
|
|
|
@ -39,7 +39,6 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.Constants;
|
||||
import org.jclouds.aws.Region;
|
||||
import org.jclouds.aws.ec2.EC2AsyncClient;
|
||||
import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
|
||||
import org.jclouds.aws.ec2.domain.Reservation;
|
||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
|
@ -64,13 +63,13 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
|
|||
|
||||
private final EC2AsyncClient client;
|
||||
private final Map<String, URI> regionMap;
|
||||
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
|
||||
private final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
|
||||
private final ExecutorService executor;
|
||||
|
||||
@Inject
|
||||
protected EC2ListNodesStrategy(EC2AsyncClient client, @Region Map<String, URI> regionMap,
|
||||
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
this.client = client;
|
||||
this.regionMap = regionMap;
|
||||
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
|
||||
|
@ -78,21 +77,21 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends ComputeMetadata> list() {
|
||||
public Set<? extends ComputeMetadata> listNodes() {
|
||||
return listDetailsOnNodesMatching(NodePredicates.all());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
Iterable<Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel(regionMap
|
||||
.keySet(), new Function<String, Future<Set<? extends Reservation<? extends RunningInstance>>>>() {
|
||||
Iterable<Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel(
|
||||
regionMap.keySet(), new Function<String, Future<Set<? extends Reservation<? extends RunningInstance>>>>() {
|
||||
|
||||
@Override
|
||||
public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
|
||||
return client.getInstanceServices().describeInstancesInRegion(from);
|
||||
}
|
||||
@Override
|
||||
public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
|
||||
return client.getInstanceServices().describeInstancesInRegion(from);
|
||||
}
|
||||
|
||||
}, executor, null, logger, "reservations");
|
||||
}, executor, null, logger, "reservations");
|
||||
|
||||
Iterable<? extends RunningInstance> instances = concat(concat(reservations));
|
||||
Iterable<? extends NodeMetadata> nodes = filter(transform(instances, runningInstanceToNodeMetadata), filter);
|
||||
|
|
|
@ -32,19 +32,24 @@ import org.jclouds.domain.Credentials;
|
|||
*/
|
||||
@Singleton
|
||||
public class EC2PopulateDefaultLoginCredentialsForImageStrategy implements
|
||||
PopulateDefaultLoginCredentialsForImageStrategy {
|
||||
PopulateDefaultLoginCredentialsForImageStrategy {
|
||||
|
||||
@Override
|
||||
public Credentials execute(Object resourceToAuthenticate) {
|
||||
Credentials credentials = new Credentials("root", null);
|
||||
if (resourceToAuthenticate != null) {
|
||||
checkArgument(resourceToAuthenticate instanceof Image, "Resource must be an image (for EC2)");
|
||||
Image image = (Image) resourceToAuthenticate;
|
||||
String owner = null;
|
||||
if (resourceToAuthenticate instanceof Image) {
|
||||
owner = Image.class.cast(resourceToAuthenticate).getImageOwnerId();
|
||||
} else if (resourceToAuthenticate instanceof org.jclouds.compute.domain.Image) {
|
||||
owner = org.jclouds.compute.domain.Image.class.cast(resourceToAuthenticate).getUserMetadata().get("owner");
|
||||
}
|
||||
checkArgument(owner != null, "Resource must be an image (for EC2)");
|
||||
// canonical/alestic images use the ubuntu user to login
|
||||
if (image.getImageOwnerId().matches("063491364108|099720109477")) {
|
||||
if (owner.matches("063491364108|099720109477")) {
|
||||
credentials = new Credentials("ubuntu", null);
|
||||
// http://aws.typepad.com/aws/2010/09/introducing-amazon-linux-ami.html
|
||||
} else if (image.getImageOwnerId().equals("137112412989")) {
|
||||
} else if (owner.equals("137112412989")) {
|
||||
credentials = new Credentials("ec2-user", null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,12 +46,12 @@ public class EC2RebootNodeStrategy implements RebootNodeStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata execute(String id) {
|
||||
public NodeMetadata rebootNode(String id) {
|
||||
String[] parts = parseHandle(id);
|
||||
String region = parts[0];
|
||||
String instanceId = parts[1];
|
||||
client.rebootInstancesInRegion(region, instanceId);
|
||||
return getNode.execute(id);
|
||||
return getNode.getNode(id);
|
||||
}
|
||||
|
||||
}
|
|
@ -35,7 +35,6 @@ import javax.inject.Named;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
|
||||
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||
import org.jclouds.aws.ec2.domain.Reservation;
|
||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||
|
@ -45,11 +44,14 @@ import org.jclouds.compute.domain.Template;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||
import org.jclouds.compute.util.ComputeUtils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* creates futures that correlate to
|
||||
|
@ -68,62 +70,77 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
|
|||
@VisibleForTesting
|
||||
final CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions;
|
||||
@VisibleForTesting
|
||||
final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
|
||||
final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
|
||||
@VisibleForTesting
|
||||
final ComputeUtils utils;
|
||||
|
||||
final Predicate<RunningInstance> instancePresent;
|
||||
final Function<RunningInstance, Credentials> instanceToCredentials;
|
||||
final Map<String, Credentials> credentialStore;
|
||||
|
||||
@Inject
|
||||
EC2RunNodesAndAddToSetStrategy(
|
||||
EC2Client client,
|
||||
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions,
|
||||
@Named("PRESENT") Predicate<RunningInstance> instancePresent,
|
||||
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata, ComputeUtils utils) {
|
||||
EC2Client client,
|
||||
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions,
|
||||
@Named("PRESENT") Predicate<RunningInstance> instancePresent,
|
||||
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
|
||||
Function<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore,
|
||||
ComputeUtils utils) {
|
||||
this.client = client;
|
||||
this.instancePresent = instancePresent;
|
||||
this.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions;
|
||||
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
|
||||
this.instanceToCredentials = instanceToCredentials;
|
||||
this.credentialStore = credentialStore;
|
||||
this.utils = utils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes,
|
||||
Map<NodeMetadata, Exception> badNodes) {
|
||||
Map<NodeMetadata, Exception> badNodes) {
|
||||
|
||||
Reservation<? extends RunningInstance> reservation = createKeyPairAndSecurityGroupsAsNeededThenRunInstances(tag,
|
||||
count, template);
|
||||
count, template);
|
||||
|
||||
Iterable<String> ids = transform(reservation, instanceToId);
|
||||
|
||||
String idsString = Joiner.on(',').join(ids);
|
||||
if (Iterables.size(ids) > 0) {
|
||||
logger.debug("<< started instances(%s)", idsString);
|
||||
all(reservation, instancePresent);
|
||||
logger.debug("<< present instances(%s)", idsString);
|
||||
populateCredentials(reservation);
|
||||
}
|
||||
|
||||
logger.debug("<< started instances(%s)", idsString);
|
||||
all(reservation, instancePresent);
|
||||
logger.debug("<< present instances(%s)", idsString);
|
||||
return utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(template.getOptions(),
|
||||
transform(reservation, runningInstanceToNodeMetadata), goodNodes, badNodes);
|
||||
}
|
||||
|
||||
return utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(template.getOptions(), transform(
|
||||
reservation, runningInstanceToNodeMetadata), goodNodes, badNodes);
|
||||
protected void populateCredentials(Reservation<? extends RunningInstance> reservation) {
|
||||
RunningInstance instance1 = Iterables.get(reservation, 0);
|
||||
Credentials credentials = instanceToCredentials.apply(instance1);
|
||||
if (credentials != null)
|
||||
for (RunningInstance instance : reservation)
|
||||
credentialStore.put(instance.getRegion() + "/" + instance.getId(), credentials);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Reservation<? extends RunningInstance> createKeyPairAndSecurityGroupsAsNeededThenRunInstances(String tag, int count,
|
||||
Template template) {
|
||||
Template template) {
|
||||
String region = getRegionFromLocationOrNull(template.getLocation());
|
||||
String zone = getZoneFromLocationOrNull(template.getLocation());
|
||||
|
||||
RunInstancesOptions instanceOptions = createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region,
|
||||
tag, template);
|
||||
tag, template);
|
||||
|
||||
if (EC2TemplateOptions.class.cast(template.getOptions()).isMonitoringEnabled())
|
||||
instanceOptions.enableMonitoring();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug(">> running %d instance region(%s) zone(%s) ami(%s) params(%s)", count, region, zone, template
|
||||
.getImage().getProviderId(), instanceOptions.buildFormParameters());
|
||||
.getImage().getProviderId(), instanceOptions.buildFormParameters());
|
||||
|
||||
return client.getInstanceServices().runInstancesInRegion(region, zone, template.getImage().getProviderId(), 1,
|
||||
count, instanceOptions);
|
||||
count, instanceOptions);
|
||||
}
|
||||
|
||||
}
|
|
@ -20,8 +20,19 @@
|
|||
package org.jclouds.aws.ec2.compute.suppliers;
|
||||
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static com.google.common.collect.Sets.newLinkedHashSet;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.c1_medium;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.c1_xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.cc1_4xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_large;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_small;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_2xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_4xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.t1_micro;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_CC_AMIs;
|
||||
import static org.jclouds.compute.predicates.ImagePredicates.any;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -30,11 +41,8 @@ import javax.inject.Inject;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.compute.domain.EC2Hardware;
|
||||
import org.jclouds.aws.ec2.domain.InstanceType;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
|
@ -43,7 +51,6 @@ import org.jclouds.rest.annotations.Provider;
|
|||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
|
@ -60,7 +67,7 @@ public class EC2HardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
|||
private final String providerName;
|
||||
|
||||
@Inject
|
||||
EC2HardwareSupplier(Supplier<Set<? extends Location>> locations, @Provider String providerName,
|
||||
EC2HardwareSupplier(@Memoized Supplier<Set<? extends Location>> locations, @Provider String providerName,
|
||||
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) {
|
||||
this.locations = locations;
|
||||
this.ccAmis = ccAmis;
|
||||
|
@ -69,7 +76,7 @@ public class EC2HardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
|||
|
||||
@Override
|
||||
public Set<? extends Hardware> get() {
|
||||
Set<Hardware> sizes = newHashSet();
|
||||
Set<Hardware> sizes = newLinkedHashSet();
|
||||
for (String ccAmi : ccAmis) {
|
||||
final String region = ccAmi.split("/")[0];
|
||||
Location location = find(locations.get(), new Predicate<Location>() {
|
||||
|
@ -80,14 +87,11 @@ public class EC2HardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
|||
}
|
||||
|
||||
});
|
||||
sizes.add(new EC2Hardware(location, InstanceType.CC1_4XLARGE, ImmutableList.of(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)), ccAmis));
|
||||
sizes.add(cc1_4xlarge().location(location).supportsImageIds(ccAmi).build());
|
||||
}
|
||||
sizes.addAll(ImmutableSet.<Hardware> of(EC2Hardware.T1_MICRO, EC2Hardware.C1_MEDIUM, EC2Hardware.C1_XLARGE,
|
||||
EC2Hardware.M1_LARGE, "nova".equals(providerName) ? EC2Hardware.M1_SMALL_NOVA : EC2Hardware.M1_SMALL,
|
||||
EC2Hardware.M1_XLARGE, EC2Hardware.M2_XLARGE, EC2Hardware.M2_2XLARGE, EC2Hardware.M2_4XLARGE));
|
||||
sizes.addAll(ImmutableSet.<Hardware> of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large()
|
||||
.build(), "nova".equals(providerName) ? m1_small().supportsImage(any()).build() : m1_small().build(),
|
||||
m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(), m2_4xlarge().build()));
|
||||
return sizes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
*
|
||||
* 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.suppliers;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class EC2ImageSupplier implements Supplier<Set<? extends Image>> {
|
||||
private final Supplier<Map<RegionAndName, ? extends Image>> map;
|
||||
|
||||
@Inject
|
||||
EC2ImageSupplier(Supplier<Map<RegionAndName, ? extends Image>> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends Image> get() {
|
||||
return Sets.newLinkedHashSet(map.get().values());
|
||||
}
|
||||
|
||||
}
|
|
@ -52,7 +52,6 @@ import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_CC_AMIs;
|
|||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
@ -87,12 +86,12 @@ public class RegionAndNameToImageSupplier implements Supplier<Map<RegionAndName,
|
|||
private final String[] ccAmis;
|
||||
private final String[] amiOwners;
|
||||
private final ImageParser parser;
|
||||
private final ConcurrentMap<RegionAndName, Image> images;
|
||||
private final Map<RegionAndName, Image> images;
|
||||
|
||||
@Inject
|
||||
RegionAndNameToImageSupplier(@Region Map<String, URI> regionMap, DescribeImagesParallel describer,
|
||||
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis, @Named(PROPERTY_EC2_AMI_OWNERS) final String[] amiOwners,
|
||||
final ImageParser parser, final ConcurrentMap<RegionAndName, Image> images) {
|
||||
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis, @Named(PROPERTY_EC2_AMI_OWNERS) final String[] amiOwners,
|
||||
final ImageParser parser, final Map<RegionAndName, Image> images) {
|
||||
this.regionMap = regionMap;
|
||||
this.describer = describer;
|
||||
this.ccAmis = ccAmis;
|
||||
|
@ -108,11 +107,12 @@ public class RegionAndNameToImageSupplier implements Supplier<Map<RegionAndName,
|
|||
} else {
|
||||
logger.debug(">> providing images");
|
||||
|
||||
Iterable<Entry<String, DescribeImagesOptions>> queries = concat(getDescribeQueriesForOwnersInRegions(
|
||||
regionMap, amiOwners).entrySet(), ccAmisToDescribeQueries(ccAmis).entrySet());
|
||||
Iterable<Entry<String, DescribeImagesOptions>> queries = concat(
|
||||
getDescribeQueriesForOwnersInRegions(regionMap, amiOwners).entrySet(), ccAmisToDescribeQueries(ccAmis)
|
||||
.entrySet());
|
||||
|
||||
Iterable<? extends Image> parsedImages = filter(transform(describer.apply(queries), parser), Predicates
|
||||
.notNull());
|
||||
Iterable<? extends Image> parsedImages = filter(transform(describer.apply(queries), parser),
|
||||
Predicates.notNull());
|
||||
|
||||
images.putAll(uniqueIndex(parsedImages, new Function<Image, RegionAndName>() {
|
||||
|
||||
|
@ -137,7 +137,7 @@ public class RegionAndNameToImageSupplier implements Supplier<Map<RegionAndName,
|
|||
}
|
||||
|
||||
private static Map<String, DescribeImagesOptions> getDescribeQueriesForOwnersInRegions(Map<String, URI> regionMap,
|
||||
final String[] amiOwners) {
|
||||
final String[] amiOwners) {
|
||||
final DescribeImagesOptions options = getOptionsForOwners(amiOwners);
|
||||
|
||||
return transformValues(regionMap, new Function<URI, DescribeImagesOptions>() {
|
||||
|
|
|
@ -230,14 +230,14 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
|
|||
protected void inItem() {
|
||||
if (inBlockDeviceMapping) {
|
||||
ebsBlockDevices.put(deviceName, new RunningInstance.EbsBlockDevice(volumeId, attachmentStatus, attachTime,
|
||||
deleteOnTermination));
|
||||
deleteOnTermination));
|
||||
this.deviceName = null;
|
||||
this.volumeId = null;
|
||||
this.attachmentStatus = null;
|
||||
this.attachTime = null;
|
||||
this.deleteOnTermination = true;
|
||||
} else if (inInstances && !inProductCodes && !inBlockDeviceMapping) {
|
||||
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
|
||||
String region = getRequest() != null ? EC2Utils.findRegionInArgsOrNull(getRequest()) : null;
|
||||
|
||||
// Eucalyptus
|
||||
if (ipAddress == null && dnsName != null && dnsName.matches(".*[0-9]$")) {
|
||||
|
@ -252,10 +252,10 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
|
|||
if (region == null)
|
||||
region = defaultRegion;
|
||||
instances.add(new RunningInstance(region, groupIds, amiLaunchIndex, dnsName, imageId, instanceId,
|
||||
instanceState, instanceType, ipAddress, kernelId, keyName, launchTime, monitoringState,
|
||||
availabilityZone, placementGroup, virtualizationType, platform, privateDnsName, privateIpAddress,
|
||||
productCodes, ramdiskId, reason, subnetId, spotInstanceRequestId, vpcId, rootDeviceType,
|
||||
rootDeviceName, ebsBlockDevices));
|
||||
instanceState, instanceType, ipAddress, kernelId, keyName, launchTime, monitoringState,
|
||||
availabilityZone, placementGroup, virtualizationType, platform, privateDnsName, privateIpAddress,
|
||||
productCodes, ramdiskId, reason, subnetId, spotInstanceRequestId, vpcId, rootDeviceType, rootDeviceName,
|
||||
ebsBlockDevices));
|
||||
this.amiLaunchIndex = null;
|
||||
this.dnsName = null;
|
||||
this.imageId = null;
|
||||
|
@ -290,11 +290,11 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
|
|||
}
|
||||
|
||||
protected Reservation<? extends RunningInstance> newReservation() {
|
||||
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
|
||||
String region = getRequest() != null ? EC2Utils.findRegionInArgsOrNull(getRequest()) : null;
|
||||
if (region == null)
|
||||
region = defaultRegion;
|
||||
Reservation<? extends RunningInstance> info = new Reservation<RunningInstance>(region, groupIds, instances,
|
||||
ownerId, requesterId, reservationId);
|
||||
ownerId, requesterId, reservationId);
|
||||
this.groupIds = Sets.newLinkedHashSet();
|
||||
this.instances = Sets.newLinkedHashSet();
|
||||
this.ownerId = null;
|
||||
|
|
|
@ -46,7 +46,8 @@ import com.google.common.collect.Sets;
|
|||
* DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/"
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html"
|
||||
* @see <a href=
|
||||
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html"
|
||||
* />
|
||||
*/
|
||||
public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Set<Image>> {
|
||||
|
@ -159,12 +160,12 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
|
|||
this.deleteOnTermination = true;
|
||||
} else if (!inProductCodes) {
|
||||
try {
|
||||
String region = EC2Utils.findRegionInArgsOrNull(getRequest());
|
||||
String region = getRequest() != null ? EC2Utils.findRegionInArgsOrNull(getRequest()) : null;
|
||||
if (region == null)
|
||||
region = defaultRegion;
|
||||
contents.add(new Image(region, architecture, this.name, description, imageId, imageLocation,
|
||||
imageOwnerId, imageState, imageType, isPublic, productCodes, kernelId, platform, ramdiskId,
|
||||
rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType));
|
||||
imageOwnerId, imageState, imageType, isPublic, productCodes, kernelId, platform, ramdiskId,
|
||||
rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType));
|
||||
} catch (NullPointerException e) {
|
||||
logger.warn(e, "malformed image: %s", imageId);
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
|||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.concurrent.Futures;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
|
@ -85,7 +86,7 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
|
|||
@Inject
|
||||
S3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||
Supplier<Set<? extends Location>> locations, S3AsyncClient async, S3Client sync,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, S3AsyncClient async, S3Client sync,
|
||||
BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions,
|
||||
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
|
||||
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.jclouds.blobstore.internal.BaseBlobStore;
|
|||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
import org.jclouds.util.Utils;
|
||||
|
@ -75,10 +76,11 @@ public class S3BlobStore extends BaseBlobStore {
|
|||
|
||||
@Inject
|
||||
S3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
||||
Supplier<Set<? extends Location>> locations, S3Client sync, BucketToResourceMetadata bucket2ResourceMd,
|
||||
ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList,
|
||||
ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
|
||||
ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
||||
@Memoized Supplier<Set<? extends Location>> locations, S3Client sync,
|
||||
BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions,
|
||||
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
|
||||
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
|
||||
Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
||||
super(context, blobUtils, defaultLocation, locations);
|
||||
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
||||
this.sync = checkNotNull(sync, "sync");
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.blobstore.BlobStoreContext;
|
|||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.internal.LocationImpl;
|
||||
|
@ -73,6 +74,7 @@ public class S3BlobStoreContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
Supplier<Set<? extends Location>> provideLocations(@Region Set<String> regions, @Provider String providerName) {
|
||||
Set<Location> locations = Sets.newHashSet();
|
||||
Location s3 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.blobstore.domain.MutableStorageMetadata;
|
|||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.domain.StorageType;
|
||||
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
|
@ -54,7 +55,7 @@ public class BucketToResourceMetadata implements Function<BucketMetadata, Storag
|
|||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
BucketToResourceMetadata(S3Client client, Supplier<Set<? extends Location>> locations) {
|
||||
BucketToResourceMetadata(S3Client client, @Memoized Supplier<Set<? extends Location>> locations) {
|
||||
this.client = client;
|
||||
this.onlyLocation = locations.get().size() == 1 ? Iterables.get(locations.get(), 0) : null;
|
||||
this.locations = locations;
|
||||
|
|
|
@ -26,6 +26,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.aws.Region;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
|
||||
|
@ -42,7 +43,7 @@ public class DefaultLocationSupplier implements Supplier<Location> {
|
|||
private final Supplier<Set<? extends Location>> set;
|
||||
|
||||
@Inject
|
||||
DefaultLocationSupplier(@Region final String region, Supplier<Set<? extends Location>> set) {
|
||||
DefaultLocationSupplier(@Region final String region, @Memoized Supplier<Set<? extends Location>> set) {
|
||||
this.region = region;
|
||||
this.set = set;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@ import org.testng.annotations.Test;
|
|||
|
||||
/**
|
||||
* This test helps us understand how we can use the power of blobstores to our favor.
|
||||
* <p/>
|
||||
* This test is in aws only because it happens to have both blobstore and compute
|
||||
*
|
||||
* TODO create a blobstore and compute integration module
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
|
|
@ -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.aws;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.blobstore.BlobStoreContextFactory;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.compute.RunNodesException;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.rest.config.CredentialStoreModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests that credentials stored in the blobstore can be reused across compute contexts.
|
||||
* <p/>
|
||||
* This test is in aws only because it happens to have both blobstore and compute
|
||||
*
|
||||
* TODO create a blobstore and compute integration module
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(testName = "jclouds.CredentialsStoredInBlobStoreTest")
|
||||
public class CredentialsStoredInBlobStoreTest {
|
||||
|
||||
private BlobStoreContext blobContext;
|
||||
private Map<String, InputStream> credentialsMap;
|
||||
|
||||
@BeforeTest
|
||||
void setupCredentialContainerAndMap() {
|
||||
blobContext = new BlobStoreContextFactory().createContext("transient", "foo", "bar");
|
||||
blobContext.getBlobStore().createContainerInLocation(null, "credentials");
|
||||
credentialsMap = blobContext.createInputStreamMap("credentials");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWeCanUseBlobStoreToStoreCredentialsAcrossContexts() throws RunNodesException, IOException {
|
||||
|
||||
ComputeServiceContext computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar",
|
||||
ImmutableSet.of(new CredentialStoreModule(credentialsMap)));
|
||||
|
||||
Set<? extends NodeMetadata> nodes = computeContext.getComputeService().runNodesWithTag("foo", 10);
|
||||
|
||||
verifyCredentialsFromNodesAreInContext(nodes, computeContext);
|
||||
computeContext.close();
|
||||
|
||||
// recreate the compute context with the same map and ensure it still works!
|
||||
computeContext = new ComputeServiceContextFactory().createContext("stub", "foo", "bar",
|
||||
Collections.singleton(new CredentialStoreModule(credentialsMap)));
|
||||
|
||||
verifyCredentialsFromNodesAreInContext(nodes, computeContext);
|
||||
|
||||
}
|
||||
|
||||
protected void verifyCredentialsFromNodesAreInContext(Set<? extends NodeMetadata> nodes,
|
||||
ComputeServiceContext computeContext) throws IOException {
|
||||
// verify each node's credential is in the map.
|
||||
assertEquals(computeContext.credentialStore().size(), 10);
|
||||
for (NodeMetadata node : nodes) {
|
||||
assertEquals(computeContext.credentialStore().get(node.getId()), node.getCredentials());
|
||||
}
|
||||
|
||||
// verify the credentials are in the backing store and of a known json format
|
||||
assertEquals(credentialsMap.size(), 10);
|
||||
for (Entry<String, InputStream> entry : credentialsMap.entrySet()) {
|
||||
Credentials credentials = computeContext.credentialStore().get(entry.getKey());
|
||||
assertEquals(Utils.toStringAndClose(entry.getValue()), String.format(
|
||||
"{\"identity\":\"%s\",\"credential\":\"%s\"}", credentials.identity, credentials.credential));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ import org.jclouds.http.functions.ParseSax;
|
|||
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.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class CloudWatchAsyncClientTest extends RestClientTest<CloudWatchAsyncCli
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("cloudwatch", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
*
|
||||
* 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.config;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.aws.ec2.EC2AsyncClient;
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.logging.jdk.JDKLogger;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(sequential = true, groups = { "unit" }, testName = "aws.AWSRestClientModuleTest")
|
||||
public class AWSRestClientModuleTest {
|
||||
|
||||
@Test
|
||||
public void testDefaultRegionWhenThereIsAMatch() {
|
||||
AWSRestClientModule<EC2Client, EC2AsyncClient> module = new AWSRestClientModule<EC2Client, EC2AsyncClient>(
|
||||
EC2Client.class, EC2AsyncClient.class);
|
||||
|
||||
URI currentEndpoint = URI.create("http://region1");
|
||||
Map<String, URI> map = ImmutableMap.of("region1", currentEndpoint, "region2", URI.create("http://region2"));
|
||||
|
||||
assertEquals("region1", module.getDefaultRegion(currentEndpoint, map, new JDKLogger.JDKLoggerFactory()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultRegionWhenThereIsNoMatch() {
|
||||
AWSRestClientModule<EC2Client, EC2AsyncClient> module = new AWSRestClientModule<EC2Client, EC2AsyncClient>(
|
||||
EC2Client.class, EC2AsyncClient.class);
|
||||
|
||||
URI currentEndpoint = URI.create("http://region3");
|
||||
Map<String, URI> map = ImmutableMap.of("region1", currentEndpoint, "region2", URI.create("http://region2"));
|
||||
|
||||
assertEquals("region1", module.getDefaultRegion(currentEndpoint, map, new JDKLogger.JDKLoggerFactory()));
|
||||
}
|
||||
|
||||
}
|
|
@ -23,24 +23,31 @@ import static java.lang.String.format;
|
|||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.c1_medium;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.c1_xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.cc1_4xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_large;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_small;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_2xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_4xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_xlarge;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.t1_micro;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
import org.jclouds.aws.ec2.compute.domain.EC2Hardware;
|
||||
import org.jclouds.aws.ec2.domain.InstanceType;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.domain.internal.ImageImpl;
|
||||
import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
|
||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
|
@ -51,9 +58,7 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* Tests compute service specifically to EC2.
|
||||
|
@ -68,10 +73,8 @@ import com.google.common.collect.Maps;
|
|||
public class EC2ComputeServiceTest {
|
||||
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(
|
||||
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" });
|
||||
public static final Hardware CC1_4XLARGE = cc1_4xlarge().location(location).supportsImageIds("us-east-1/cc-image")
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
|
||||
|
@ -84,9 +87,10 @@ public class EC2ComputeServiceTest {
|
|||
Template template = newTemplateBuilder().os64Bit(true).hardwareId("m2.xlarge").locationId("us-east-1").build();
|
||||
|
||||
assert template != null : "The returned template was null, but it should have a value.";
|
||||
assert EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format(
|
||||
"Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge", String
|
||||
.valueOf(template.getHardware()));
|
||||
// assert m2_xlarge().build().equals(template.getHardware()) : format(
|
||||
// "Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge",
|
||||
// String.valueOf(template.getHardware()));
|
||||
assertEquals(m2_xlarge().build(), template.getHardware());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -130,7 +134,7 @@ public class EC2ComputeServiceTest {
|
|||
"us-east-1").build();
|
||||
|
||||
assert template != null : "The returned template was null, but it should have a value.";
|
||||
assert !EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format(
|
||||
assert !m2_xlarge().build().equals(template.getHardware()) : format(
|
||||
"Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", String
|
||||
.valueOf(template.getHardware()));
|
||||
}
|
||||
|
@ -144,9 +148,9 @@ public class EC2ComputeServiceTest {
|
|||
|
||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||
|
||||
Image image = new ImageImpl("cc-image", "image", "us-east-1/cc-image", location, null, Maps
|
||||
.<String, String> newHashMap(), new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true),
|
||||
"description", "1.0", new Credentials("root", null));
|
||||
Image image = new ImageBuilder().providerId("cc-image").name("image").id("us-east-1/cc-image").location(location)
|
||||
.operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true)).description(
|
||||
"description").version("1.0").defaultCredentials(new Credentials("root", null)).build();
|
||||
replay(optionsProvider);
|
||||
replay(templateBuilderProvider);
|
||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
|
@ -154,9 +158,9 @@ public class EC2ComputeServiceTest {
|
|||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
||||
.<Image> of(image));
|
||||
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(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.M2_2XLARGE,
|
||||
EC2Hardware.M2_4XLARGE, CC1_4XLARGE));
|
||||
.<Hardware> of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large().build(),
|
||||
m1_small().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(),
|
||||
m2_4xlarge().build(), CC1_4XLARGE));
|
||||
|
||||
return new TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(location), optionsProvider,
|
||||
templateBuilderProvider) {
|
||||
|
|
|
@ -0,0 +1,879 @@
|
|||
/**
|
||||
*
|
||||
* 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.functions;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_small;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_4xlarge;
|
||||
import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.imageIds;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.jclouds.aws.domain.Region;
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.aws.ec2.domain.Attachment;
|
||||
import org.jclouds.aws.ec2.domain.AvailabilityZone;
|
||||
import org.jclouds.aws.ec2.domain.Image;
|
||||
import org.jclouds.aws.ec2.domain.InstanceState;
|
||||
import org.jclouds.aws.ec2.domain.InstanceType;
|
||||
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.EbsBlockDevice;
|
||||
import org.jclouds.aws.ec2.services.AMIClient;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.Volume;
|
||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.internal.LocationImpl;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ec2.CredentialsForInstanceTest")
|
||||
public class CredentialsForInstanceTest {
|
||||
|
||||
DateService dateService = new SimpleDateFormatDateService();
|
||||
|
||||
// @SuppressWarnings({ "unchecked" })
|
||||
// @Test
|
||||
// public void testApplyWithEBSWhenBootIsInstanceStoreAndAvailabilityZoneNotFound() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m1_small().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
// Image image = createMock(Image.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.of("default")).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(location));
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn("174.129.1.50");
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
|
||||
//
|
||||
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
//
|
||||
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
|
||||
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
|
||||
//
|
||||
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
|
||||
// (Set) ImmutableSet.<Image> of(image));
|
||||
//
|
||||
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
|
||||
//
|
||||
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
|
||||
// new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
|
||||
// expect(instance.getEbsBlockDevices()).andReturn(
|
||||
// ImmutableMap.<String, EbsBlockDevice> of(
|
||||
// "/dev/sdg",
|
||||
// new EbsBlockDevice("vol-1f20d376", Attachment.Status.ATTACHED, dateService
|
||||
// .iso8601DateParse("2009-12-11T16:32:46.000Z"), false),
|
||||
// "/dev/sdj",
|
||||
// new EbsBlockDevice("vol-c0eb78aa", Attachment.Status.ATTACHED, dateService
|
||||
// .iso8601DateParse("2010-06-17T10:43:28.000Z"), false)));
|
||||
// expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
|
||||
// expect(instance.getRootDeviceName()).andReturn(null).atLeastOnce();
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
// replay(jcImage);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
//
|
||||
// assertEquals(metadata.getTag(), "NOTAG-i-3d640055");
|
||||
// assertEquals(metadata.getLocation(), null);
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
|
||||
// assertEquals(metadata.getHardware().getId(), "m1.small");
|
||||
// assertEquals(metadata.getHardware().getName(), "m1.small");
|
||||
// assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
||||
// assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
||||
// assertEquals(metadata.getHardware().getRam(), 1740);
|
||||
// assertEquals(metadata.getHardware().getVolumes(),
|
||||
// ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
||||
// new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false),//
|
||||
// new VolumeImpl("vol-1f20d376", Volume.Type.SAN, null, "/dev/sdg", false, true),//
|
||||
// new VolumeImpl("vol-c0eb78aa", Volume.Type.SAN, null, "/dev/sdj", false, true)));
|
||||
//
|
||||
// assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings({ "unchecked" })
|
||||
// @Test
|
||||
// public void testApplyForNovaWhereNullAvailabilityZoneIpAddressNoGroups() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m1_small().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
// Image image = createMock(Image.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(region));
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn(null);
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
|
||||
//
|
||||
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
//
|
||||
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
|
||||
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
|
||||
//
|
||||
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
|
||||
// (Set) ImmutableSet.<Image> of(image));
|
||||
//
|
||||
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
|
||||
//
|
||||
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null);
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
|
||||
// expect(instance.getEbsBlockDevices()).andReturn(Maps.<String, EbsBlockDevice> newHashMap());
|
||||
// expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
// replay(jcImage);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
//
|
||||
// assertEquals(metadata.getTag(), "NOTAG-i-3d640055");
|
||||
// assertEquals(metadata.getLocation(), region);
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
|
||||
// assertEquals(metadata.getHardware().getId(), "m1.small");
|
||||
// assertEquals(metadata.getHardware().getName(), "m1.small");
|
||||
// assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
||||
// assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
||||
// assertEquals(metadata.getHardware().getRam(), 1740);
|
||||
// assertEquals(metadata.getHardware().getVolumes(),
|
||||
// ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
||||
// new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
|
||||
//
|
||||
// assertEquals(metadata.getCredentials(), new Credentials("user", null));
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings({ "unchecked" })
|
||||
// @Test
|
||||
// public void testApplyWhereUnknownInstanceType() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m1_small().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
// Image image = createMock(Image.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(region));
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn(null);
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
|
||||
//
|
||||
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
//
|
||||
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
|
||||
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
|
||||
//
|
||||
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
|
||||
// (Set) ImmutableSet.<Image> of(image));
|
||||
//
|
||||
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
|
||||
//
|
||||
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null);
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn("hhttpp").atLeastOnce();
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
// replay(jcImage);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
//
|
||||
// assertEquals(metadata.getTag(), "NOTAG-i-3d640055");
|
||||
// assertEquals(metadata.getLocation(), region);
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
|
||||
// assertEquals(metadata.getHardware(), null);
|
||||
//
|
||||
// assertEquals(metadata.getCredentials(), new Credentials("user", null));
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings({ "unchecked" })
|
||||
// @Test
|
||||
// public void testApplyForNovaWhereImageNotFound() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m1_small().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(region));
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn(null);
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
|
||||
//
|
||||
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
//
|
||||
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
|
||||
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
|
||||
//
|
||||
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
|
||||
// (Set) ImmutableSet.<Image> of());
|
||||
//
|
||||
// expect(credentialProvider.execute(null)).andReturn(new Credentials("root", null));
|
||||
//
|
||||
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "nebulatanimislam"))).andReturn(null);
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
|
||||
// expect(instance.getEbsBlockDevices()).andReturn(Maps.<String, EbsBlockDevice> newHashMap());
|
||||
// expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
// replay(jcImage);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
//
|
||||
// assertEquals(metadata.getTag(), "NOTAG-i-3d640055");
|
||||
// assertEquals(metadata.getLocation(), region);
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
|
||||
// assertEquals(metadata.getHardware().getId(), "m1.small");
|
||||
// assertEquals(metadata.getHardware().getName(), "m1.small");
|
||||
// assertEquals(metadata.getHardware().getProviderId(), "m1.small");
|
||||
// assertEquals(metadata.getHardware().getProcessors(), ImmutableList.<Processor> of(new Processor(1.0, 1.0)));
|
||||
// assertEquals(metadata.getHardware().getRam(), 1740);
|
||||
// assertEquals(metadata.getHardware().getVolumes(),
|
||||
// ImmutableList.<Volume> of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
|
||||
// new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false)));
|
||||
//
|
||||
// assertEquals(metadata.getCredentials(), new Credentials("root", null));
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// @Test
|
||||
// public void testImageNotFoundAndLazyReturnsNull() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
//
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
//
|
||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(location));
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m2_4xlarge().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
|
||||
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
|
||||
//
|
||||
// expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andReturn(null);
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(jcImage);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
|
||||
// assertEquals(metadata.getTag(), "NOTAG-id");
|
||||
// assertEquals(metadata.getCredentials(), null);
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// @Test
|
||||
// public void testImageNotFoundStillSetsImageId() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
//
|
||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(location));
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m2_4xlarge().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
|
||||
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
|
||||
//
|
||||
// expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andThrow(new NullPointerException())
|
||||
// .atLeastOnce();
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(jcImage);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
|
||||
// assertEquals(metadata.getTag(), "NOTAG-id");
|
||||
// assertEquals(metadata.getCredentials(), null);
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// @Test
|
||||
// public void testImageNotFoundAndLazySucceeds() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
//
|
||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(location));
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m2_4xlarge().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
|
||||
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
|
||||
//
|
||||
// org.jclouds.compute.domain.Image lateImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andReturn(lateImage).atLeastOnce();
|
||||
// expect(lateImage.getId()).andReturn("us-east-1/imageId").atLeastOnce();
|
||||
// expect(lateImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
|
||||
//
|
||||
// replay(lateImage);
|
||||
// replay(imageMap);
|
||||
// replay(jcImage);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
|
||||
// assertEquals(metadata.getImageId(), lateImage.getId());
|
||||
// assertEquals(metadata.getTag(), "NOTAG-id");
|
||||
// assertEquals(metadata.getCredentials(), null);
|
||||
//
|
||||
// verify(lateImage);
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// @Test
|
||||
// public void testApplyWithNoSecurityGroupCreatesTagOfIdPrefixedByTagAndNullCredentials() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
//
|
||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(location));
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m2_4xlarge().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
//
|
||||
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
|
||||
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(jcImage);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
|
||||
// assertEquals(metadata.getTag(), "NOTAG-id");
|
||||
// assertEquals(metadata.getCredentials(), null);
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// @Test
|
||||
// public void testApplyWithNoKeyPairCreatesTagOfParsedSecurityGroupAndNullCredentials() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
//
|
||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(location));
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m2_4xlarge().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
// expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag#us-east-1")).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
//
|
||||
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
|
||||
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(jcImage);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
// assertEquals(metadata.getLocation(), locations.get().iterator().next());
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
|
||||
// assertEquals(metadata.getTag(), "tag");
|
||||
// assertEquals(metadata.getCredentials(), null);
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings({ "unchecked" })
|
||||
// @Test
|
||||
// public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m2_4xlarge().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
// Image image = createMock(Image.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("id").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.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(location));
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
//
|
||||
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
//
|
||||
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
|
||||
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
|
||||
//
|
||||
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn(
|
||||
// (Set) ImmutableSet.<Image> of(image));
|
||||
//
|
||||
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
|
||||
//
|
||||
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
|
||||
// new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
// replay(jcImage);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
//
|
||||
// assertEquals(metadata.getTag(), "tag");
|
||||
// assertEquals(metadata.getLocation(), location);
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
|
||||
//
|
||||
// assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings({ "unchecked" })
|
||||
// @Test
|
||||
// public void testApplyWithTwoSecurityGroups() throws UnknownHostException {
|
||||
// EC2Client client = createMock(EC2Client.class);
|
||||
// AMIClient amiClient = createMock(AMIClient.class);
|
||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||
// .<Hardware> of(m2_4xlarge().build()));
|
||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
// RunningInstance instance = createMock(RunningInstance.class);
|
||||
// Image image = createMock(Image.class);
|
||||
//
|
||||
// expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
// expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds1", "jclouds2")).atLeastOnce();
|
||||
// expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce();
|
||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
//
|
||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||
// .<Location> of(location));
|
||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
//
|
||||
// expect(instance.getIpAddress()).andReturn("127.0.0.1");
|
||||
// expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1");
|
||||
//
|
||||
// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
//
|
||||
// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
|
||||
// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage);
|
||||
//
|
||||
// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn(
|
||||
// (Set) ImmutableSet.<Image> of(image));
|
||||
//
|
||||
// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
|
||||
//
|
||||
// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
|
||||
// new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
|
||||
//
|
||||
// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
//
|
||||
// expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
|
||||
//
|
||||
// replay(imageMap);
|
||||
// replay(client);
|
||||
// replay(amiClient);
|
||||
// replay(credentialsMap);
|
||||
// replay(credentialProvider);
|
||||
// replay(instance);
|
||||
// replay(jcImage);
|
||||
//
|
||||
// Function<RunningInstance, NodeMetadata> parser = new CredentialsForInstance(client, credentialsMap,
|
||||
// credentialProvider, imageMap, locations, hardwares);
|
||||
//
|
||||
// NodeMetadata metadata = parser.apply(instance);
|
||||
//
|
||||
// assertEquals(metadata.getTag(), "NOTAG-id");
|
||||
// assertEquals(metadata.getLocation(), location);
|
||||
// assertEquals(metadata.getImageId(), "us-east-1/imageId");
|
||||
//
|
||||
// assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
|
||||
//
|
||||
// verify(imageMap);
|
||||
// verify(jcImage);
|
||||
// verify(client);
|
||||
// verify(amiClient);
|
||||
// verify(credentialsMap);
|
||||
// verify(credentialProvider);
|
||||
// verify(instance);
|
||||
//
|
||||
// }
|
||||
}
|
|
@ -19,648 +19,200 @@
|
|||
|
||||
package org.jclouds.aws.ec2.compute.functions;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.aws.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
|
||||
import org.jclouds.aws.ec2.domain.Image;
|
||||
import org.jclouds.aws.ec2.xml.BaseEC2HandlerTest;
|
||||
import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandler;
|
||||
import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandlerTest;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystemBuilder;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.internal.LocationImpl;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "compute.ImageParserTest")
|
||||
public class ImageParserTest extends BaseEC2HandlerTest {
|
||||
|
||||
public class ImageParserTest {
|
||||
public void testParseAlesticCanonicalImage() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/alestic_canonical.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
assertEquals(result.size(), 8);
|
||||
Set<org.jclouds.compute.domain.Image> result = convertImages("/ec2/alestic_canonical.xml");
|
||||
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), Suppliers
|
||||
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
|
||||
.ofInstance(defaultLocation), "ec2");
|
||||
org.jclouds.compute.domain.Image ubuntuHardy = parser.apply(Iterables.get(result, 0));
|
||||
assertEquals(
|
||||
Iterables.get(result, 0),
|
||||
new ImageBuilder()
|
||||
.operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04")
|
||||
.description("ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml")
|
||||
.is64Bit(false).build())
|
||||
.description("ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml")
|
||||
.defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-7e28ca17")
|
||||
.providerId("ami-7e28ca17").location(defaultLocation).version("20091130")
|
||||
.userMetadata(ImmutableMap.of("owner", "099720109477", "rootDeviceType", "instance-store")).build());
|
||||
|
||||
assertEquals(ubuntuHardy.getDescription(), "ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml");
|
||||
assertEquals(ubuntuHardy.getId(), "us-east-1/ami-7e28ca17");
|
||||
assertEquals(ubuntuHardy.getProviderId(), "ami-7e28ca17");
|
||||
assertEquals(ubuntuHardy.getLocation(), defaultLocation);
|
||||
assertEquals(ubuntuHardy.getName(), null);
|
||||
assertEquals(ubuntuHardy.getOperatingSystem().getName(), null);
|
||||
assertEquals(ubuntuHardy.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(ubuntuHardy.getOperatingSystem().getVersion(), "8.04");
|
||||
assertEquals(ubuntuHardy.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(ubuntuHardy.getOperatingSystem().getDescription(),
|
||||
"ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml");
|
||||
assertEquals(ubuntuHardy.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(ubuntuHardy.getUserMetadata(), ImmutableMap.<String, String> of("owner", "099720109477",
|
||||
"rootDeviceType", "instance-store"));
|
||||
assertEquals(ubuntuHardy.getVersion(), "20091130");
|
||||
assertEquals(
|
||||
Iterables.get(result, 4),
|
||||
new ImageBuilder()
|
||||
.operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04")
|
||||
.description("alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml").is64Bit(false)
|
||||
.build()).description("alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml")
|
||||
.defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-c0fa1ea9")
|
||||
.providerId("ami-c0fa1ea9").location(defaultLocation).version("20080905")
|
||||
.userMetadata(ImmutableMap.of("owner", "063491364108", "rootDeviceType", "instance-store")).build());
|
||||
|
||||
org.jclouds.compute.domain.Image alesticKarmic = parser.apply(Iterables.get(result, 1));
|
||||
|
||||
assertEquals(alesticKarmic.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(alesticKarmic.getDescription(), "alestic/ubuntu-9.10-karmic-base-20090623.manifest.xml");
|
||||
assertEquals(alesticKarmic.getId(), "us-east-1/ami-19a34270");
|
||||
assertEquals(alesticKarmic.getProviderId(), "ami-19a34270");
|
||||
assertEquals(alesticKarmic.getLocation(), defaultLocation);
|
||||
assertEquals(alesticKarmic.getName(), null);
|
||||
assertEquals(alesticKarmic.getOperatingSystem().getName(), null);
|
||||
assertEquals(alesticKarmic.getOperatingSystem().getVersion(), "9.10");
|
||||
assertEquals(alesticKarmic.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(alesticKarmic.getOperatingSystem().getDescription(),
|
||||
"alestic/ubuntu-9.10-karmic-base-20090623.manifest.xml");
|
||||
assertEquals(alesticKarmic.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(alesticKarmic.getUserMetadata(), ImmutableMap.<String, String> of("owner", "063491364108",
|
||||
"rootDeviceType", "instance-store"));
|
||||
assertEquals(alesticKarmic.getVersion(), "20090623");
|
||||
|
||||
org.jclouds.compute.domain.Image ubuntuKarmic = parser.apply(Iterables.get(result, 2));
|
||||
|
||||
assertEquals(ubuntuKarmic.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(ubuntuKarmic.getDescription(),
|
||||
"ubuntu-images-us/ubuntu-karmic-9.10-i386-server-20100121.manifest.xml");
|
||||
assertEquals(ubuntuKarmic.getId(), "us-east-1/ami-bb709dd2");
|
||||
assertEquals(ubuntuKarmic.getProviderId(), "ami-bb709dd2");
|
||||
assertEquals(ubuntuKarmic.getLocation(), defaultLocation);
|
||||
assertEquals(ubuntuKarmic.getName(), null);
|
||||
assertEquals(ubuntuKarmic.getOperatingSystem().getName(), null);
|
||||
assertEquals(ubuntuKarmic.getOperatingSystem().getVersion(), "9.10");
|
||||
assertEquals(ubuntuKarmic.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(ubuntuKarmic.getOperatingSystem().getDescription(),
|
||||
"ubuntu-images-us/ubuntu-karmic-9.10-i386-server-20100121.manifest.xml");
|
||||
assertEquals(ubuntuKarmic.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(ubuntuKarmic.getUserMetadata(), ImmutableMap.<String, String> of("owner", "099720109477",
|
||||
"rootDeviceType", "instance-store"));
|
||||
assertEquals(ubuntuKarmic.getVersion(), "20100121");
|
||||
|
||||
org.jclouds.compute.domain.Image testing = parser.apply(Iterables.get(result, 3));
|
||||
|
||||
assertEquals(testing.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(testing.getDescription(),
|
||||
"ubuntu-images-testing-us/ubuntu-lucid-daily-amd64-desktop-20100317.manifest.xml");
|
||||
assertEquals(testing.getId(), "us-east-1/ami-190fe070");
|
||||
assertEquals(testing.getProviderId(), "ami-190fe070");
|
||||
assertEquals(testing.getLocation(), defaultLocation);
|
||||
assertEquals(testing.getName(), null);
|
||||
assertEquals(testing.getOperatingSystem().getName(), null);
|
||||
assertEquals(testing.getOperatingSystem().getVersion(), "10.04");
|
||||
assertEquals(testing.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(testing.getOperatingSystem().getDescription(),
|
||||
"ubuntu-images-testing-us/ubuntu-lucid-daily-amd64-desktop-20100317.manifest.xml");
|
||||
assertEquals(testing.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(testing.getUserMetadata(), ImmutableMap.<String, String> of("owner", "099720109477",
|
||||
"rootDeviceType", "instance-store"));
|
||||
assertEquals(testing.getVersion(), "20100317");
|
||||
|
||||
org.jclouds.compute.domain.Image alesticHardy = parser.apply(Iterables.get(result, 4));
|
||||
|
||||
assertEquals(alesticHardy.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(alesticHardy.getDescription(), "alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml");
|
||||
assertEquals(alesticHardy.getId(), "us-east-1/ami-c0fa1ea9");
|
||||
assertEquals(alesticHardy.getProviderId(), "ami-c0fa1ea9");
|
||||
assertEquals(alesticHardy.getLocation(), defaultLocation);
|
||||
assertEquals(alesticHardy.getName(), null);
|
||||
assertEquals(alesticHardy.getOperatingSystem().getName(), null);
|
||||
assertEquals(alesticHardy.getOperatingSystem().getVersion(), "8.04");
|
||||
assertEquals(alesticHardy.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(alesticHardy.getOperatingSystem().getDescription(),
|
||||
"alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml");
|
||||
assertEquals(alesticHardy.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(alesticHardy.getUserMetadata(), ImmutableMap.<String, String> of("owner", "063491364108",
|
||||
"rootDeviceType", "instance-store"));
|
||||
assertEquals(alesticHardy.getVersion(), "20080905");
|
||||
|
||||
org.jclouds.compute.domain.Image ubuntuLucid = parser.apply(Iterables.get(result, 5));
|
||||
|
||||
assertEquals(ubuntuLucid.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(ubuntuLucid.getDescription(),
|
||||
"ubuntu-images-us-west-1/ubuntu-lucid-10.04-i386-server-20100427.1.manifest.xml");
|
||||
assertEquals(ubuntuLucid.getId(), "us-east-1/ami-c597c680");
|
||||
assertEquals(ubuntuLucid.getProviderId(), "ami-c597c680");
|
||||
assertEquals(ubuntuLucid.getLocation(), defaultLocation);
|
||||
assertEquals(ubuntuLucid.getName(), null);
|
||||
assertEquals(ubuntuLucid.getOperatingSystem().getName(), null);
|
||||
assertEquals(ubuntuLucid.getOperatingSystem().getVersion(), "10.04");
|
||||
assertEquals(ubuntuLucid.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(ubuntuLucid.getOperatingSystem().getDescription(),
|
||||
"ubuntu-images-us-west-1/ubuntu-lucid-10.04-i386-server-20100427.1.manifest.xml");
|
||||
assertEquals(ubuntuLucid.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(ubuntuLucid.getUserMetadata(), ImmutableMap.<String, String> of("owner", "099720109477",
|
||||
"rootDeviceType", "instance-store"));
|
||||
assertEquals(ubuntuLucid.getVersion(), "20100427.1");
|
||||
|
||||
// should skip kernel
|
||||
assert parser.apply(Iterables.get(result, 6)) == null;
|
||||
|
||||
org.jclouds.compute.domain.Image ubuntuEbs = parser.apply(Iterables.get(result, 7));
|
||||
|
||||
assertEquals(ubuntuEbs.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(ubuntuEbs.getDescription(), "099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827");
|
||||
assertEquals(ubuntuEbs.getId(), "us-east-1/ami-10f3a255");
|
||||
assertEquals(ubuntuEbs.getProviderId(), "ami-10f3a255");
|
||||
assertEquals(ubuntuEbs.getLocation(), defaultLocation);
|
||||
assertEquals(ubuntuEbs.getName(), null);
|
||||
assertEquals(ubuntuEbs.getOperatingSystem().getName(), null);
|
||||
assertEquals(ubuntuEbs.getOperatingSystem().getVersion(), "10.04");
|
||||
assertEquals(ubuntuEbs.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(ubuntuEbs.getOperatingSystem().getDescription(),
|
||||
"099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827");
|
||||
assertEquals(ubuntuEbs.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(ubuntuEbs.getUserMetadata(), ImmutableMap.<String, String> of("owner", "099720109477",
|
||||
"rootDeviceType", "ebs"));
|
||||
assertEquals(ubuntuEbs.getVersion(), "20100827");
|
||||
assertEquals(
|
||||
Iterables.get(result, 6),
|
||||
new ImageBuilder()
|
||||
.operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.04")
|
||||
.description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827")
|
||||
.is64Bit(false).build())
|
||||
.description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827")
|
||||
.defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-10f3a255")
|
||||
.providerId("ami-10f3a255").location(defaultLocation).version("20100827")
|
||||
.userMetadata(ImmutableMap.of("owner", "099720109477", "rootDeviceType", "ebs")).build());
|
||||
|
||||
}
|
||||
|
||||
private Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
|
||||
|
||||
public void testParseVostokImage() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/vostok.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
Set<org.jclouds.compute.domain.Image> result = convertImages("/ec2/vostok.xml");
|
||||
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), Suppliers
|
||||
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
|
||||
.ofInstance(defaultLocation), "ec2");
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(image.getDescription(), "vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml");
|
||||
assertEquals(image.getId(), "us-east-1/ami-870de2ee");
|
||||
assertEquals(image.getProviderId(), "ami-870de2ee");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(),
|
||||
"vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UNRECOGNIZED);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "133804938231", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), "5622");
|
||||
assertEquals(
|
||||
Iterables.get(result, 0),
|
||||
new ImageBuilder()
|
||||
.operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("")
|
||||
.description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml")
|
||||
.is64Bit(false).build())
|
||||
.description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml")
|
||||
.defaultCredentials(new Credentials("root", null)).id("us-east-1/ami-870de2ee")
|
||||
.providerId("ami-870de2ee").location(defaultLocation).version("5622")
|
||||
.userMetadata(ImmutableMap.of("owner", "133804938231", "rootDeviceType", "instance-store")).build());
|
||||
|
||||
}
|
||||
|
||||
public void testParseCCImage() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_images_cc.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
Set<org.jclouds.compute.domain.Image> result = convertImages("/ec2/describe_images_cc.xml");
|
||||
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), Suppliers
|
||||
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
|
||||
.ofInstance(defaultLocation), "ec2");
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "EC2 CentOS 5.4 HVM AMI");
|
||||
assertEquals(image.getId(), "us-east-1/ami-7ea24a17");
|
||||
assertEquals(image.getProviderId(), "ami-7ea24a17");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "5.4");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "hvm");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "amazon/EC2 CentOS 5.4 HVM AMI");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.CENTOS);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "206029621532", "rootDeviceType",
|
||||
"ebs"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
assertEquals(
|
||||
Iterables.get(result, 0),
|
||||
new ImageBuilder()
|
||||
.operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("hvm").version("5.4")
|
||||
.description("amazon/EC2 CentOS 5.4 HVM AMI").is64Bit(true).build())
|
||||
.description("EC2 CentOS 5.4 HVM AMI").defaultCredentials(new Credentials("root", null))
|
||||
.id("us-east-1/ami-7ea24a17").providerId("ami-7ea24a17").location(defaultLocation)
|
||||
.userMetadata(ImmutableMap.of("owner", "206029621532", "rootDeviceType", "ebs")).build());
|
||||
|
||||
}
|
||||
|
||||
public void testParseRightScaleImage() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/rightscale_images.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
Set<org.jclouds.compute.domain.Image> result = convertImages("/ec2/rightscale_images.xml");
|
||||
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), Suppliers
|
||||
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
|
||||
.ofInstance(defaultLocation), "ec2");
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml");
|
||||
assertEquals(image.getId(), "us-east-1/ami-ccb35ea5");
|
||||
assertEquals(image.getProviderId(), "ami-ccb35ea5");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "5.4");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(),
|
||||
"rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.CENTOS);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "411009282317", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), "4.4.10");
|
||||
|
||||
image = parser.apply(Iterables.get(result, 1));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha");
|
||||
assertEquals(image.getId(), "us-east-1/ami-c19db6b5");
|
||||
assertEquals(image.getProviderId(), "ami-c19db6b5");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "9.10");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(),
|
||||
"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "411009282317", "rootDeviceType",
|
||||
"ebs"));
|
||||
assertEquals(image.getVersion(), "4.5.3_EBS_Alpha");
|
||||
assertEquals(
|
||||
Iterables.get(result, 0),
|
||||
new ImageBuilder()
|
||||
.operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.4")
|
||||
.description("rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml").is64Bit(true)
|
||||
.build()).description("rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml")
|
||||
.defaultCredentials(new Credentials("root", null)).id("us-east-1/ami-ccb35ea5")
|
||||
.providerId("ami-ccb35ea5").location(defaultLocation).version("4.4.10")
|
||||
.userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build());
|
||||
|
||||
assertEquals(
|
||||
new Gson().toJson(Iterables.get(result, 1)),
|
||||
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
|
||||
}
|
||||
|
||||
public void testParseEucalyptusImage() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/eucalyptus_images.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
assertEquals(result.size(), 4);
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), Suppliers
|
||||
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
|
||||
.ofInstance(defaultLocation), "ec2");
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml");
|
||||
assertEquals(image.getId(), "us-east-1/emi-9ACB1363");
|
||||
assertEquals(image.getProviderId(), "emi-9ACB1363");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "5.3");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.CENTOS);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "admin", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
Set<org.jclouds.compute.domain.Image> result = convertImages("/ec2/eucalyptus_images.xml");
|
||||
|
||||
assertEquals(
|
||||
Iterables.get(result, 0),
|
||||
new ImageBuilder()
|
||||
.operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.3")
|
||||
.description("centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml").is64Bit(true)
|
||||
.build()).description("centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml")
|
||||
.defaultCredentials(new Credentials("root", null)).id("us-east-1/emi-9ACB1363")
|
||||
.providerId("emi-9ACB1363").location(defaultLocation)
|
||||
.userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build());
|
||||
}
|
||||
|
||||
public void testParseAmznmage() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/amzn_images.xml");
|
||||
public void testParseAmznImage() {
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
assertEquals(result.size(), 4);
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), Suppliers
|
||||
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
|
||||
.ofInstance(defaultLocation), "ec2");
|
||||
Set<org.jclouds.compute.domain.Image> result = convertImages("/ec2/amzn_images.xml");
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(image.getDescription(), "Amazon");
|
||||
assertEquals(image.getId(), "us-east-1/ami-82e4b5c7");
|
||||
assertEquals(image.getProviderId(), "ami-82e4b5c7");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "0.9.7-beta");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "137112412989/amzn-ami-0.9.7-beta.i386-ebs");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "137112412989", "rootDeviceType",
|
||||
"ebs"));
|
||||
assertEquals(image.getVersion(), "0.9.7-beta");
|
||||
|
||||
image = parser.apply(Iterables.get(result, 1));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "Amazon");
|
||||
assertEquals(image.getId(), "us-east-1/ami-8ce4b5c9");
|
||||
assertEquals(image.getProviderId(), "ami-8ce4b5c9");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "0.9.7-beta");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "137112412989/amzn-ami-0.9.7-beta.x86_64-ebs");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "137112412989", "rootDeviceType",
|
||||
"ebs"));
|
||||
assertEquals(image.getVersion(), "0.9.7-beta");
|
||||
|
||||
image = parser.apply(Iterables.get(result, 2));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(image.getDescription(), "Amazon Linux AMI i386 S3");
|
||||
assertEquals(image.getId(), "us-east-1/ami-f0e4b5b5");
|
||||
assertEquals(image.getProviderId(), "ami-f0e4b5b5");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "0.9.7-beta");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(),
|
||||
"amzn-ami-us-west-1/amzn-ami-0.9.7-beta.i386.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "137112412989", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), "0.9.7-beta");
|
||||
|
||||
image = parser.apply(Iterables.get(result, 3));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "Amazon Linux AMI x86_64 S3");
|
||||
assertEquals(image.getId(), "us-east-1/ami-f2e4b5b7");
|
||||
assertEquals(image.getProviderId(), "ami-f2e4b5b7");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "0.9.7-beta");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(),
|
||||
"amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "137112412989", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), "0.9.7-beta");
|
||||
assertEquals(
|
||||
Iterables.get(result, 0),
|
||||
new ImageBuilder()
|
||||
.operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual")
|
||||
.version("0.9.7-beta").description("137112412989/amzn-ami-0.9.7-beta.i386-ebs")
|
||||
.is64Bit(false).build()).description("Amazon")
|
||||
.defaultCredentials(new Credentials("ec2-user", null)).id("us-east-1/ami-82e4b5c7")
|
||||
.providerId("ami-82e4b5c7").location(defaultLocation).version("0.9.7-beta")
|
||||
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
|
||||
|
||||
assertEquals(
|
||||
Iterables.get(result, 3),
|
||||
new ImageBuilder()
|
||||
.operatingSystem(
|
||||
new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual")
|
||||
.version("0.9.7-beta")
|
||||
.description("amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml").is64Bit(true)
|
||||
.build()).description("Amazon Linux AMI x86_64 S3")
|
||||
.defaultCredentials(new Credentials("ec2-user", null)).id("us-east-1/ami-f2e4b5b7")
|
||||
.providerId("ami-f2e4b5b7").location(defaultLocation).version("0.9.7-beta")
|
||||
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build());
|
||||
}
|
||||
|
||||
public void testParseNovaImage() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/nova_images.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
assertEquals(result.size(), 19);
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), Suppliers
|
||||
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
|
||||
.ofInstance(defaultLocation), "nebula");
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "nasacms/image.manifest.xml");
|
||||
assertEquals(image.getId(), "us-east-1/ami-h30p5im0");
|
||||
assertEquals(image.getProviderId(), "ami-h30p5im0");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "nasacms/image.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "foo", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
assertEquals(parser.apply(Iterables.get(result, 1)), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 2));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "nebula/tiny");
|
||||
assertEquals(image.getId(), "us-east-1/ami-tiny");
|
||||
assertEquals(image.getProviderId(), "ami-tiny");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "nebula/tiny");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "vishvananda", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 3));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "demos/mediawiki");
|
||||
assertEquals(image.getId(), "us-east-1/ami-630A130F");
|
||||
assertEquals(image.getProviderId(), "ami-630A130F");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "demos/mediawiki");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "admin", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
assertEquals(parser.apply(Iterables.get(result, 4)), null);
|
||||
assertEquals(parser.apply(Iterables.get(result, 5)), null);
|
||||
assertEquals(parser.apply(Iterables.get(result, 6)), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 7));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "pinglet/instances");
|
||||
assertEquals(image.getId(), "us-east-1/ami-pinginst");
|
||||
assertEquals(image.getProviderId(), "ami-pinginst");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "pinglet/instances");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "admin", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 8));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "bucket/testbuntu.manifest.xml");
|
||||
assertEquals(image.getId(), "us-east-1/ami-alqbihe2");
|
||||
assertEquals(image.getProviderId(), "ami-alqbihe2");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "bucket/testbuntu.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "rkumar2", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 9));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "gfortran-bucket/gfortran.manifest.xml");
|
||||
assertEquals(image.getId(), "us-east-1/ami-i0aemtfp");
|
||||
assertEquals(image.getProviderId(), "ami-i0aemtfp");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "gfortran-bucket/gfortran.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "ykliu", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
assertEquals(parser.apply(Iterables.get(result, 10)), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 11));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "grinder/grinder-analyzer.manifest.xml");
|
||||
assertEquals(image.getId(), "us-east-1/ami-2ig7w1bh");
|
||||
assertEquals(image.getProviderId(), "ami-2ig7w1bh");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "grinder/grinder-analyzer.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "foo", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
assertEquals(parser.apply(Iterables.get(result, 12)), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 13));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "nebula/lucid");
|
||||
assertEquals(image.getId(), "us-east-1/ami-lucid");
|
||||
assertEquals(image.getProviderId(), "ami-lucid");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "10.04");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "nebula/lucid");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "vishvananda", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 14));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "nebula/karmic-large");
|
||||
assertEquals(image.getId(), "us-east-1/ami-karmiclg");
|
||||
assertEquals(image.getProviderId(), "ami-karmiclg");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "9.10");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "nebula/karmic-large");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "admin", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 15));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "jo/qa-grinder.manifest.xml");
|
||||
assertEquals(image.getId(), "us-east-1/ami-8jen8kdn");
|
||||
assertEquals(image.getProviderId(), "ami-8jen8kdn");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "jo/qa-grinder.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "jyothi", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 16));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "nebula/lucid-large");
|
||||
assertEquals(image.getId(), "us-east-1/ami-lucidlg");
|
||||
assertEquals(image.getProviderId(), "ami-lucidlg");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "10.04");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "nebula/lucid-large");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "vishvananda", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 17));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "demos/wordpress");
|
||||
assertEquals(image.getId(), "us-east-1/ami-6CD61336");
|
||||
assertEquals(image.getProviderId(), "ami-6CD61336");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "demos/wordpress");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "admin", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
|
||||
image = parser.apply(Iterables.get(result, 18));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "nebula/ubuntu-karmic");
|
||||
assertEquals(image.getId(), "us-east-1/ami-25CB1213");
|
||||
assertEquals(image.getProviderId(), "ami-25CB1213");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "9.10");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "nebula/ubuntu-karmic");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "admin", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), null);
|
||||
Set<org.jclouds.compute.domain.Image> result = convertImages("/ec2/nova_images.xml");
|
||||
|
||||
assertEquals(
|
||||
new Gson().toJson(Iterables.get(result, 0)),
|
||||
"{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"nasacms/image.manifest.xml\",\"is64Bit\":true},\"description\":\"nasacms/image.manifest.xml\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-h30p5im0\",\"type\":\"IMAGE\",\"providerId\":\"ami-h30p5im0\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"foo\",\"rootDeviceType\":\"instance-store\"}}");
|
||||
assertEquals(
|
||||
new Gson().toJson(Iterables.get(result, 1)),
|
||||
"{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"nebula/tiny\",\"is64Bit\":true},\"description\":\"nebula/tiny\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-tiny\",\"type\":\"IMAGE\",\"providerId\":\"ami-tiny\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"vishvananda\",\"rootDeviceType\":\"instance-store\"}}");
|
||||
assertEquals(
|
||||
new Gson().toJson(Iterables.get(result, 2)),
|
||||
"{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"demos/mediawiki\",\"is64Bit\":true},\"description\":\"demos/mediawiki\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-630A130F\",\"type\":\"IMAGE\",\"providerId\":\"ami-630A130F\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"admin\",\"rootDeviceType\":\"instance-store\"}}");
|
||||
assertEquals(
|
||||
new Gson().toJson(Iterables.get(result, 3)),
|
||||
"{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"pinglet/instances\",\"is64Bit\":true},\"description\":\"pinglet/instances\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-pinginst\",\"type\":\"IMAGE\",\"providerId\":\"ami-pinginst\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"admin\",\"rootDeviceType\":\"instance-store\"}}");
|
||||
}
|
||||
|
||||
private Set<Image> parseImages(InputStream is) {
|
||||
DescribeImagesResponseHandler handler = injector.getInstance(DescribeImagesResponseHandler.class);
|
||||
addDefaultRegionToHandler(handler);
|
||||
Set<Image> result = factory.create(handler).parse(is);
|
||||
return result;
|
||||
static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
|
||||
|
||||
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {
|
||||
Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(),
|
||||
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)),
|
||||
Suppliers.ofInstance(defaultLocation), "ec2");
|
||||
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));
|
||||
}
|
||||
|
||||
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce();
|
||||
replay(request);
|
||||
handler.setContext(request);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,6 +23,7 @@ import static org.easymock.EasyMock.expect;
|
|||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.c1_medium;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
@ -33,17 +34,14 @@ import javax.inject.Provider;
|
|||
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.Processor;
|
||||
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.TemplateBuilderImpl;
|
||||
import org.jclouds.compute.domain.internal.TemplateBuilderImplTest;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.predicates.ImagePredicates;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.internal.LocationImpl;
|
||||
|
@ -52,8 +50,6 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.google.common.collect.Sets;
|
||||
|
@ -72,8 +68,8 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
|
||||
@Override
|
||||
protected EC2TemplateBuilderImpl createTemplateBuilder(final Image knownImage,
|
||||
Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
|
||||
Supplier<Set<? extends Hardware>> sizes, Location defaultLocation,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Image>> images,
|
||||
@Memoized Supplier<Set<? extends Hardware>> sizes, Location defaultLocation,
|
||||
Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) {
|
||||
final RegionAndName knownRegionAndName = new RegionAndName("region", "ami");
|
||||
|
||||
|
@ -100,9 +96,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(Sets
|
||||
.<Image> newLinkedHashSet());
|
||||
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(), ImmutableList.of(new Processor(1, 1.0)), 1, ImmutableList
|
||||
.<Volume> of(), ImagePredicates.any())));
|
||||
.<Hardware> of(c1_medium().build()));
|
||||
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -154,9 +148,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
.<Location> of(location));
|
||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
|
||||
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(), ImmutableList.of(new Processor(1, 1.0)), 1, ImmutableList
|
||||
.<Volume> of(), ImagePredicates.any())));
|
||||
.<Hardware> of(c1_medium().build()));
|
||||
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||
|
@ -193,9 +185,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
|||
.<Location> of(location));
|
||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
|
||||
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(), ImmutableList.of(new Processor(1, 1.0)), 1, ImmutableList
|
||||
.<Volume> of(), ImagePredicates.any())));
|
||||
.<Hardware> of(c1_medium().build()));
|
||||
|
||||
Location defaultLocation = createMock(Location.class);
|
||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.Set;
|
|||
|
||||
import org.jclouds.aws.domain.Region;
|
||||
import org.jclouds.aws.ec2.compute.EC2ComputeServiceTest;
|
||||
import org.jclouds.aws.ec2.compute.domain.EC2Hardware;
|
||||
import org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder;
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules;
|
||||
import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded;
|
||||
|
@ -41,6 +41,7 @@ import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
|||
import org.jclouds.aws.ec2.domain.KeyPair;
|
||||
import org.jclouds.aws.ec2.domain.PlacementGroup;
|
||||
import org.jclouds.aws.ec2.options.RunInstancesOptions;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.encryption.internal.Base64;
|
||||
|
@ -59,7 +60,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
// setup constants
|
||||
String region = Region.AP_SOUTHEAST_1;
|
||||
String tag = "tag";
|
||||
EC2Hardware size = EC2Hardware.M1_SMALL;
|
||||
Hardware size = EC2HardwareBuilder.m1_small().build();
|
||||
String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
|
||||
String generatedGroup = "group";
|
||||
Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
|
||||
|
@ -115,7 +116,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
// setup constants
|
||||
String region = Region.US_EAST_1;
|
||||
String tag = "tag";
|
||||
EC2Hardware size = EC2ComputeServiceTest.CC1_4XLARGE;
|
||||
Hardware size = EC2ComputeServiceTest.CC1_4XLARGE;
|
||||
String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
|
||||
String generatedGroup = "group";
|
||||
Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
|
||||
|
@ -174,7 +175,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
// setup constants
|
||||
String region = Region.US_EAST_1;
|
||||
String tag = "tag";
|
||||
EC2Hardware size = EC2ComputeServiceTest.CC1_4XLARGE;
|
||||
Hardware size = EC2ComputeServiceTest.CC1_4XLARGE;
|
||||
String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
|
||||
String generatedGroup = "group";
|
||||
Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
|
||||
|
@ -233,7 +234,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
// setup constants
|
||||
String region = Region.AP_SOUTHEAST_1;
|
||||
String tag = "tag";
|
||||
EC2Hardware size = EC2Hardware.M1_SMALL;
|
||||
Hardware size = EC2HardwareBuilder.m1_small().build();
|
||||
String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
|
||||
|
||||
// create mocks
|
||||
|
@ -286,7 +287,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
// setup constants
|
||||
String region = Region.AP_SOUTHEAST_1;
|
||||
String tag = "tag";
|
||||
EC2Hardware size = EC2Hardware.M1_SMALL;
|
||||
Hardware size = EC2HardwareBuilder.m1_small().build();
|
||||
String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
|
||||
String generatedGroup = "group";
|
||||
Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.util.Set;
|
|||
import org.easymock.IArgumentMatcher;
|
||||
import org.jclouds.aws.domain.Region;
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.aws.ec2.compute.domain.EC2Hardware;
|
||||
import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
|
||||
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||
import org.jclouds.aws.ec2.domain.AvailabilityZone;
|
||||
|
@ -40,15 +39,18 @@ import org.jclouds.aws.ec2.domain.Reservation;
|
|||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||
import org.jclouds.aws.ec2.options.RunInstancesOptions;
|
||||
import org.jclouds.aws.ec2.services.InstanceClient;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.util.ComputeUtils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.internal.LocationImpl;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
@ -90,7 +92,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
|||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked"})
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
private void assertRegionAndZoneForLocation(Location location, String region, String zone) {
|
||||
String imageId = "ami1";
|
||||
String instanceCreatedId = "instance1";
|
||||
|
@ -100,29 +102,36 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
|||
InstanceClient instanceClient = createMock(InstanceClient.class);
|
||||
RunInstancesOptions ec2Options = createMock(RunInstancesOptions.class);
|
||||
RunningInstance instance = createMock(RunningInstance.class);
|
||||
Reservation<? extends RunningInstance> reservation = new Reservation<RunningInstance>(region, ImmutableSet
|
||||
.<String> of(), ImmutableSet.<RunningInstance> of(instance), "ownerId", "requesterId", "reservationId");
|
||||
Reservation<? extends RunningInstance> reservation = new Reservation<RunningInstance>(region,
|
||||
ImmutableSet.<String> of(), ImmutableSet.<RunningInstance> of(instance), "ownerId", "requesterId",
|
||||
"reservationId");
|
||||
NodeMetadata nodeMetadata = createMock(NodeMetadata.class);
|
||||
|
||||
// setup expectations
|
||||
expect(strategy.client.getInstanceServices()).andReturn(instanceClient).atLeastOnce();
|
||||
expect(
|
||||
strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region, input.tag,
|
||||
input.template)).andReturn(ec2Options);
|
||||
strategy.createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.execute(region, input.tag,
|
||||
input.template)).andReturn(ec2Options);
|
||||
expect(input.template.getLocation()).andReturn(input.location).atLeastOnce();
|
||||
expect(input.template.getImage()).andReturn(input.image).atLeastOnce();
|
||||
expect(input.image.getProviderId()).andReturn(imageId).atLeastOnce();
|
||||
expect(instanceClient.runInstancesInRegion(region, zone, imageId, 1, input.count, ec2Options)).andReturn(
|
||||
(Reservation) reservation);
|
||||
(Reservation) reservation);
|
||||
expect(instance.getId()).andReturn(instanceCreatedId).atLeastOnce();
|
||||
// simulate a lazy credentials fetch
|
||||
Credentials creds = new Credentials("foo","bar");
|
||||
expect(strategy.instanceToCredentials.apply(instance)).andReturn(creds);
|
||||
expect(instance.getRegion()).andReturn(region);
|
||||
expect(strategy.credentialStore.put(region + "/" + instanceCreatedId, creds)).andReturn(null);
|
||||
|
||||
expect(strategy.instancePresent.apply(instance)).andReturn(true);
|
||||
expect(input.template.getOptions()).andReturn(input.options).atLeastOnce();
|
||||
expect(input.options.isMonitoringEnabled()).andReturn(false);
|
||||
|
||||
expect(strategy.runningInstanceToNodeMetadata.apply(instance)).andReturn(nodeMetadata);
|
||||
expect(
|
||||
strategy.utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(eq(input.options),
|
||||
containsNodeMetadata(nodeMetadata), eq(input.nodes), eq(input.badNodes))).andReturn(null);
|
||||
strategy.utils.runOptionsOnNodesAndAddToGoodSetOrPutExceptionIntoBadMap(eq(input.options),
|
||||
containsNodeMetadata(nodeMetadata), eq(input.nodes), eq(input.badNodes))).andReturn(null);
|
||||
|
||||
// replay mocks
|
||||
replay(instanceClient);
|
||||
|
@ -145,9 +154,9 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
|||
}
|
||||
|
||||
private static final Location REGION_AP_SOUTHEAST_1 = new LocationImpl(LocationScope.REGION, Region.AP_SOUTHEAST_1,
|
||||
Region.AP_SOUTHEAST_1, new LocationImpl(LocationScope.PROVIDER, "ec2", "ec2", null));
|
||||
Region.AP_SOUTHEAST_1, new LocationImpl(LocationScope.PROVIDER, "ec2", "ec2", null));
|
||||
private static final Location ZONE_AP_SOUTHEAST_1A = new LocationImpl(LocationScope.ZONE,
|
||||
AvailabilityZone.AP_SOUTHEAST_1A, AvailabilityZone.AP_SOUTHEAST_1A, REGION_AP_SOUTHEAST_1);
|
||||
AvailabilityZone.AP_SOUTHEAST_1A, AvailabilityZone.AP_SOUTHEAST_1A, REGION_AP_SOUTHEAST_1);
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -157,7 +166,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
|||
Template template = createMock(Template.class);
|
||||
Set<NodeMetadata> nodes = createMock(Set.class);
|
||||
Map<NodeMetadata, Exception> badNodes = createMock(Map.class);
|
||||
EC2Hardware size = createMock(EC2Hardware.class);
|
||||
Hardware hardware = createMock(Hardware.class);
|
||||
Image image = createMock(Image.class);
|
||||
final Location location;
|
||||
EC2TemplateOptions options = createMock(EC2TemplateOptions.class);
|
||||
|
@ -168,7 +177,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
|||
|
||||
void replayMe() {
|
||||
replay(template);
|
||||
replay(size);
|
||||
replay(hardware);
|
||||
replay(image);
|
||||
replay(nodes);
|
||||
replay(badNodes);
|
||||
|
@ -177,7 +186,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
|||
|
||||
void verifyMe() {
|
||||
verify(template);
|
||||
verify(size);
|
||||
verify(hardware);
|
||||
verify(image);
|
||||
verify(nodes);
|
||||
verify(badNodes);
|
||||
|
@ -190,6 +199,8 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
|||
verify(strategy.client);
|
||||
verify(strategy.instancePresent);
|
||||
verify(strategy.runningInstanceToNodeMetadata);
|
||||
verify(strategy.instanceToCredentials);
|
||||
verify(strategy.credentialStore);
|
||||
verify(strategy.utils);
|
||||
}
|
||||
|
||||
|
@ -199,9 +210,11 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
|||
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions = createMock(CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class);
|
||||
Predicate<RunningInstance> instanceStateRunning = createMock(Predicate.class);
|
||||
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata = createMock(RunningInstanceToNodeMetadata.class);
|
||||
Function<RunningInstance, Credentials> instanceToCredentials = createMock(Function.class);
|
||||
Map<String, Credentials> credentialStore = createMock(Map.class);
|
||||
ComputeUtils utils = createMock(ComputeUtils.class);
|
||||
return new EC2RunNodesAndAddToSetStrategy(client, createKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions,
|
||||
instanceStateRunning, runningInstanceToNodeMetadata, utils);
|
||||
instanceStateRunning, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils);
|
||||
}
|
||||
|
||||
private void replayStrategy(EC2RunNodesAndAddToSetStrategy strategy) {
|
||||
|
@ -209,6 +222,8 @@ public class EC2RunNodesAndAddToSetStrategyTest {
|
|||
replay(strategy.client);
|
||||
replay(strategy.instancePresent);
|
||||
replay(strategy.runningInstanceToNodeMetadata);
|
||||
replay(strategy.instanceToCredentials);
|
||||
replay(strategy.credentialStore);
|
||||
replay(strategy.utils);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ 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.RestContextSpec;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -102,7 +102,7 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("ec2", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,26 +19,29 @@
|
|||
|
||||
package org.jclouds.aws.ec2.xml;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.aws.Region;
|
||||
import org.jclouds.aws.ec2.compute.functions.ImageParserTest;
|
||||
import org.jclouds.aws.ec2.domain.Image;
|
||||
import org.jclouds.aws.ec2.domain.RootDeviceType;
|
||||
import org.jclouds.aws.ec2.domain.Image.Architecture;
|
||||
import org.jclouds.aws.ec2.domain.Image.EbsBlockDevice;
|
||||
import org.jclouds.aws.ec2.domain.Image.ImageState;
|
||||
import org.jclouds.aws.ec2.domain.Image.ImageType;
|
||||
import org.jclouds.aws.ec2.domain.RootDeviceType;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.http.functions.config.SaxParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code DescribeImagesResponseHandler}
|
||||
|
@ -46,67 +49,58 @@ import com.google.common.collect.Sets;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ec2.DescribeImagesResponseHandlerTest")
|
||||
public class DescribeImagesResponseHandlerTest extends BaseEC2HandlerTest {
|
||||
public class DescribeImagesResponseHandlerTest {
|
||||
|
||||
public void testUNIX() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_images.xml");
|
||||
Set<Image> contents = Sets.newLinkedHashSet();
|
||||
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.I386, null, null, "ami-be3adfd7",
|
||||
"ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml", "206029621532", ImageState.AVAILABLE,
|
||||
ImageType.MACHINE, false, Sets.<String> newHashSet("9961934F"), "aki-4438dd2d", null, "ari-4538dd2c",
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(), "paravirtual"));
|
||||
|
||||
contents.add(new Image(defaultRegion, Architecture.I386, null, null, "ami-be3adfd7",
|
||||
"ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml", "206029621532",
|
||||
ImageState.AVAILABLE, ImageType.MACHINE, false,
|
||||
Sets.<String> newHashSet("9961934F"), "aki-4438dd2d", null, "ari-4538dd2c",
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(),"paravirtual"));
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
Set<Image> result = parseImages("/ec2/describe_images.xml");
|
||||
|
||||
assertEquals(result, contents);
|
||||
}
|
||||
|
||||
public void testWindows() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_images_windows.xml");
|
||||
Set<Image> contents = Sets.newLinkedHashSet();
|
||||
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.X86_64, null, null, "ami-02eb086b",
|
||||
"aws-solutions-amis/SqlSvrStd2003r2-x86_64-Win_SFWBasic5.1-v1.0.manifest.xml", "771350841976",
|
||||
ImageState.AVAILABLE, ImageType.MACHINE, true, Sets.<String> newHashSet("5771E9A6"), null, "windows", null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(), "paravirtual"));
|
||||
|
||||
contents.add(new Image(defaultRegion, Architecture.X86_64, null, null, "ami-02eb086b",
|
||||
"aws-solutions-amis/SqlSvrStd2003r2-x86_64-Win_SFWBasic5.1-v1.0.manifest.xml",
|
||||
"771350841976", ImageState.AVAILABLE, ImageType.MACHINE, true, Sets
|
||||
.<String> newHashSet("5771E9A6"), null, "windows", null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(),"paravirtual"));
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
Set<Image> result = parseImages("/ec2/describe_images_windows.xml");
|
||||
|
||||
assertEquals(result, contents);
|
||||
}
|
||||
|
||||
public void testEBS() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_images_ebs.xml");
|
||||
Set<Image> contents = Sets.newLinkedHashSet();
|
||||
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.I386, "websrv_2009-12-10",
|
||||
"Web Server AMI", "ami-246f8d4d", "706093390852/websrv_2009-12-10", "706093390852", ImageState.AVAILABLE,
|
||||
ImageType.MACHINE, true, Sets.<String> newHashSet(), null, "windows", null, RootDeviceType.EBS,
|
||||
"/dev/sda1", ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1", new EbsBlockDevice("snap-d01272b9", 30,
|
||||
true), "xvdf", new EbsBlockDevice("snap-d31272ba", 250, false)), "hvm"));
|
||||
|
||||
contents.add(new Image(defaultRegion, Architecture.I386, "websrv_2009-12-10",
|
||||
"Web Server AMI", "ami-246f8d4d", "706093390852/websrv_2009-12-10", "706093390852",
|
||||
ImageState.AVAILABLE, ImageType.MACHINE, true, Sets.<String> newHashSet(), null,
|
||||
"windows", null, RootDeviceType.EBS, "/dev/sda1", ImmutableMap
|
||||
.<String, EbsBlockDevice> of("/dev/sda1", new EbsBlockDevice(
|
||||
"snap-d01272b9", 30, true), "xvdf", new EbsBlockDevice(
|
||||
"snap-d31272ba", 250, false)),"hvm"));
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
Set<Image> result = parseImages("/ec2/describe_images_ebs.xml");
|
||||
|
||||
assertEquals(result, contents);
|
||||
}
|
||||
|
||||
private Set<Image> parseImages(InputStream is) {
|
||||
DescribeImagesResponseHandler handler = injector
|
||||
.getInstance(DescribeImagesResponseHandler.class);
|
||||
addDefaultRegionToHandler(handler);
|
||||
Set<Image> result = factory.create(handler).parse(is);
|
||||
return result;
|
||||
static ParseSax<Set<Image>> createParser() {
|
||||
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(String.class).annotatedWith(Region.class).toInstance("us-east-1");
|
||||
}
|
||||
|
||||
});
|
||||
ParseSax<Set<Image>> parser = (ParseSax<Set<Image>>) injector.getInstance(ParseSax.Factory.class).create(
|
||||
injector.getInstance(DescribeImagesResponseHandler.class));
|
||||
return parser;
|
||||
}
|
||||
|
||||
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
expect(request.getArgs()).andReturn(new Object[] { null });
|
||||
replay(request);
|
||||
handler.setContext(request);
|
||||
public static Set<Image> parseImages(String resource) {
|
||||
InputStream is = ImageParserTest.class.getResourceAsStream(resource);
|
||||
return createParser().parse(is);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,15 +19,13 @@
|
|||
|
||||
package org.jclouds.aws.ec2.xml;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.aws.Region;
|
||||
import org.jclouds.aws.ec2.domain.Attachment;
|
||||
import org.jclouds.aws.ec2.domain.AvailabilityZone;
|
||||
import org.jclouds.aws.ec2.domain.InstanceState;
|
||||
|
@ -39,13 +37,16 @@ import org.jclouds.aws.ec2.domain.RunningInstance;
|
|||
import org.jclouds.aws.ec2.domain.RunningInstance.EbsBlockDevice;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.http.functions.config.SaxParserModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code DescribeInstancesResponseHandler}
|
||||
|
@ -67,47 +68,45 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
|
||||
public void testWhenRunning() throws UnknownHostException {
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_instances_running.xml");
|
||||
Set<Reservation<? extends RunningInstance>> contents = Sets.newLinkedHashSet();
|
||||
|
||||
contents.add(new Reservation<RunningInstance>(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"),
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"), "0",
|
||||
"ec2-174-129-81-68.compute-1.amazonaws.com", "ami-1fd73376", "i-0799056f",
|
||||
InstanceState.RUNNING, InstanceType.M1_SMALL, "174.129.81.68", "aki-a71cf9ce",
|
||||
"adriancole.ec21", dateService.iso8601DateParse("2009-11-09T03:00:34.000Z"),
|
||||
MonitoringState.DISABLED, AvailabilityZone.US_EAST_1C, null, "paravirtual", null,
|
||||
"ip-10-243-42-70.ec2.internal", "10.243.42.70", ImmutableSet.<String> of(), "ari-a51cf9cc",
|
||||
null, null, null, null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of())), "993194456877", null, "r-a3c508cb"));
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"), "0",
|
||||
"ec2-174-129-81-68.compute-1.amazonaws.com", "ami-1fd73376", "i-0799056f", InstanceState.RUNNING,
|
||||
InstanceType.M1_SMALL, "174.129.81.68", "aki-a71cf9ce", "adriancole.ec21", dateService
|
||||
.iso8601DateParse("2009-11-09T03:00:34.000Z"), MonitoringState.DISABLED,
|
||||
AvailabilityZone.US_EAST_1C, null, "paravirtual", null, "ip-10-243-42-70.ec2.internal",
|
||||
"10.243.42.70", ImmutableSet.<String> of(), "ari-a51cf9cc", null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of())), "993194456877",
|
||||
null, "r-a3c508cb"));
|
||||
|
||||
Set<Reservation<? extends RunningInstance>> result = getReservations(is);
|
||||
Set<Reservation<? extends RunningInstance>> result = parseRunningInstances("/ec2/describe_instances_running.xml");
|
||||
|
||||
assertEquals(result, contents);
|
||||
}
|
||||
|
||||
public void testApplyInputStream() {
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_instances.xml");
|
||||
Set<Reservation<? extends RunningInstance>> contents = Sets.newLinkedHashSet();
|
||||
|
||||
contents.add(new Reservation<RunningInstance>(defaultRegion, ImmutableSet.of("default"), ImmutableSet.of(
|
||||
new RunningInstance(defaultRegion, ImmutableSet.of("default"), "23",
|
||||
"ec2-72-44-33-4.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64341", InstanceState.RUNNING,
|
||||
InstanceType.M1_LARGE, (String) null, "aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), MonitoringState.DISABLED,
|
||||
AvailabilityZone.US_EAST_1B, null, "paravirtual", null, "10-251-50-132.ec2.internal", null,
|
||||
ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of()),
|
||||
new RunningInstance(defaultRegion, ImmutableSet.of("default"), "23",
|
||||
"ec2-72-44-33-6.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64435", InstanceState.RUNNING,
|
||||
InstanceType.M1_LARGE, (String) null, "aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), MonitoringState.DISABLED,
|
||||
AvailabilityZone.US_EAST_1B, null, "paravirtual", null, "10-251-50-134.ec2.internal", null,
|
||||
ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of())),
|
||||
"UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", null, "r-44a5402d"));
|
||||
new RunningInstance(defaultRegion, ImmutableSet.of("default"), "23",
|
||||
"ec2-72-44-33-4.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64341", InstanceState.RUNNING,
|
||||
InstanceType.M1_LARGE, (String) null, "aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), MonitoringState.DISABLED,
|
||||
AvailabilityZone.US_EAST_1B, null, "paravirtual", null, "10-251-50-132.ec2.internal", null,
|
||||
ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null, null, RootDeviceType.INSTANCE_STORE,
|
||||
null, ImmutableMap.<String, EbsBlockDevice> of()),
|
||||
new RunningInstance(defaultRegion, ImmutableSet.of("default"), "23",
|
||||
"ec2-72-44-33-6.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64435", InstanceState.RUNNING,
|
||||
InstanceType.M1_LARGE, (String) null, "aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), MonitoringState.DISABLED,
|
||||
AvailabilityZone.US_EAST_1B, null, "paravirtual", null, "10-251-50-134.ec2.internal", null,
|
||||
ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null, null, RootDeviceType.INSTANCE_STORE,
|
||||
null, ImmutableMap.<String, EbsBlockDevice> of())), "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", null,
|
||||
"r-44a5402d"));
|
||||
|
||||
Set<Reservation<? extends RunningInstance>> result = getReservations(is);
|
||||
Set<Reservation<? extends RunningInstance>> result = parseRunningInstances("/ec2/describe_instances.xml");
|
||||
|
||||
assertEquals(result, contents);
|
||||
}
|
||||
|
@ -116,73 +115,75 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
// TODO not sure why equals fails
|
||||
public void testApplyInputStreamEuc() {
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_instances_euc.xml");
|
||||
Set<Reservation<? extends RunningInstance>> contents = Sets.newLinkedHashSet();
|
||||
|
||||
contents.add(new Reservation<RunningInstance>(defaultRegion, ImmutableSet.of("default"), ImmutableSet
|
||||
.of(new RunningInstance(defaultRegion, ImmutableSet.of("jclouds#euc"), "1", null, "emi-9ACB1363",
|
||||
"i-3FFA0762", InstanceState.SHUTTING_DOWN, InstanceType.M1_LARGE, null, "eki-6CBD12F2",
|
||||
"jclouds#euc-17", dateService.iso8601DateParse("2010-06-16T03:06:19.000Z"),
|
||||
MonitoringState.DISABLED, "open", null, "paravirtual", null, "10.7.0.179", null, ImmutableSet
|
||||
.<String> of(), "eri-A97113E4", null, null, null, null, RootDeviceType.INSTANCE_STORE,
|
||||
null, ImmutableMap.<String, EbsBlockDevice> of())), "jclouds", null, "r-4D2A08AD"));
|
||||
.of(new RunningInstance(defaultRegion, ImmutableSet.of("jclouds#euc"), "1", null, "emi-9ACB1363",
|
||||
"i-3FFA0762", InstanceState.SHUTTING_DOWN, InstanceType.M1_LARGE, null, "eki-6CBD12F2",
|
||||
"jclouds#euc-17", dateService.iso8601DateParse("2010-06-16T03:06:19.000Z"), MonitoringState.DISABLED,
|
||||
"open", null, "paravirtual", null, "10.7.0.179", null, ImmutableSet.<String> of(), "eri-A97113E4",
|
||||
null, null, null, null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of())), "jclouds", null, "r-4D2A08AD"));
|
||||
|
||||
Set<Reservation<? extends RunningInstance>> result = getReservations(is);
|
||||
Set<Reservation<? extends RunningInstance>> result = parseRunningInstances("/ec2/describe_instances_euc.xml");
|
||||
|
||||
assertEquals(result, contents);
|
||||
}
|
||||
|
||||
public void testApplyInputStreamNovaNoAvailabilityZone() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_instances_nova.xml");
|
||||
Set<Reservation<? extends RunningInstance>> contents = Sets.newLinkedHashSet();
|
||||
|
||||
contents.add(new Reservation<RunningInstance>(defaultRegion, ImmutableSet.of("default"), ImmutableSet
|
||||
.of(new RunningInstance(defaultRegion, ImmutableSet.<String> of(), "0", null, "ami-h30p5im0",
|
||||
"i-9slweygo", InstanceState.TERMINATED, InstanceType.M1_SMALL, null, null, "nebulatanimislam",
|
||||
dateService.iso8601SecondsDateParse("2010-09-09T18:09:42Z"), null, null, null, "paravirtual",
|
||||
null, null, "10.128.207.5", ImmutableSet.<String> of("None"), null, null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of())), "tislam1",
|
||||
null, "r-opqeylmj"));
|
||||
.of(new RunningInstance(defaultRegion, ImmutableSet.<String> of(), "0", null, "ami-25CB1213", "i-9slweygo",
|
||||
InstanceState.TERMINATED, InstanceType.M1_SMALL, null, null, "nebulatanimislam", dateService
|
||||
.iso8601SecondsDateParse("2010-09-09T18:09:42Z"), null, null, null, "paravirtual", null, null,
|
||||
"10.128.207.5", ImmutableSet.<String> of("None"), null, null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of())), "tislam1", null,
|
||||
"r-opqeylmj"));
|
||||
|
||||
Set<Reservation<? extends RunningInstance>> result = getReservations(is);
|
||||
Set<Reservation<? extends RunningInstance>> result = parseRunningInstances("/ec2/describe_instances_nova.xml");
|
||||
|
||||
assertEquals(result, contents);
|
||||
}
|
||||
|
||||
public void testEBS() throws UnknownHostException {
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/describe_instances_ebs.xml");
|
||||
Set<Reservation<? extends RunningInstance>> contents = Sets.newLinkedHashSet();
|
||||
|
||||
contents.add(new Reservation<RunningInstance>(defaultRegion, ImmutableSet.of("adriancole.ec2ebsingress"),
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSet.of("adriancole.ec2ebsingress"), "0",
|
||||
"ec2-75-101-203-146.compute-1.amazonaws.com", "ami-849875ed", "i-e564438d",
|
||||
InstanceState.RUNNING, InstanceType.M1_SMALL, "75.101.203.146", "aki-a71cf9ce",
|
||||
"adriancole.ec2ebs1", dateService.iso8601DateParse("2009-12-30T04:06:23.000Z"),
|
||||
MonitoringState.DISABLED, AvailabilityZone.US_EAST_1B, "placement", "hvm", null,
|
||||
"domU-12-31-39-09-CE-53.compute-1.internal", "10.210.209.157", ImmutableSet.<String> of(),
|
||||
"ari-a51cf9cc", null, null, null, null, RootDeviceType.EBS, "/dev/sda1", ImmutableMap
|
||||
.<String, EbsBlockDevice> of("/dev/sda1", new EbsBlockDevice("vol-dc6ca8b5",
|
||||
Attachment.Status.ATTACHED, dateService
|
||||
.iso8601DateParse("2009-12-30T04:06:29.000Z"), true)))),
|
||||
"993194456877", null, "r-596dd731"));
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSet.of("adriancole.ec2ebsingress"), "0",
|
||||
"ec2-75-101-203-146.compute-1.amazonaws.com", "ami-849875ed", "i-e564438d", InstanceState.RUNNING,
|
||||
InstanceType.M1_SMALL, "75.101.203.146", "aki-a71cf9ce", "adriancole.ec2ebs1", dateService
|
||||
.iso8601DateParse("2009-12-30T04:06:23.000Z"), MonitoringState.DISABLED,
|
||||
AvailabilityZone.US_EAST_1B, "placement", "hvm", null, "domU-12-31-39-09-CE-53.compute-1.internal",
|
||||
"10.210.209.157", ImmutableSet.<String> of(), "ari-a51cf9cc", null, null, null, null,
|
||||
RootDeviceType.EBS, "/dev/sda1", ImmutableMap.<String, EbsBlockDevice> of(
|
||||
"/dev/sda1",
|
||||
new EbsBlockDevice("vol-dc6ca8b5", Attachment.Status.ATTACHED, dateService
|
||||
.iso8601DateParse("2009-12-30T04:06:29.000Z"), true)))), "993194456877", null,
|
||||
"r-596dd731"));
|
||||
|
||||
Set<Reservation<? extends RunningInstance>> result = getReservations(is);
|
||||
Set<Reservation<? extends RunningInstance>> result = parseRunningInstances("/ec2/describe_instances_ebs.xml");
|
||||
|
||||
assertEquals(result, contents);
|
||||
}
|
||||
|
||||
private Set<Reservation<? extends RunningInstance>> getReservations(InputStream is) {
|
||||
DescribeInstancesResponseHandler handler = injector.getInstance(DescribeInstancesResponseHandler.class);
|
||||
addDefaultRegionToHandler(handler);
|
||||
Set<Reservation<? extends RunningInstance>> result = factory.create(handler).parse(is);
|
||||
return result;
|
||||
static ParseSax<Set<Reservation<? extends RunningInstance>>> createParser() {
|
||||
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(String.class).annotatedWith(Region.class).toInstance("us-east-1");
|
||||
}
|
||||
|
||||
});
|
||||
ParseSax<Set<Reservation<? extends RunningInstance>>> parser = (ParseSax<Set<Reservation<? extends RunningInstance>>>) injector
|
||||
.getInstance(ParseSax.Factory.class).create(injector.getInstance(DescribeInstancesResponseHandler.class));
|
||||
return parser;
|
||||
}
|
||||
|
||||
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
expect(request.getArgs()).andReturn(new Object[] { null }).atLeastOnce();
|
||||
replay(request);
|
||||
handler.setContext(request);
|
||||
public static Set<Reservation<? extends RunningInstance>> parseRunningInstances(String resource) {
|
||||
InputStream is = DescribeInstancesResponseHandlerTest.class.getResourceAsStream(resource);
|
||||
return createParser().parse(is);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.jclouds.http.functions.ParseSax;
|
|||
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.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("elb", "identity", "credential",
|
||||
new Properties());
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.jclouds.aws.s3.filters.RequestAuthorizeSignature;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
|
@ -65,7 +65,7 @@ public abstract class BaseS3AsyncClientTest extends RestClientTest<S3AsyncClient
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("s3", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.jclouds.io.payloads.PhantomPayload;
|
|||
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.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -135,7 +135,7 @@ public class S3BlobRequestSignerTest extends RestClientTest<S3AsyncClient> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("s3", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ 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.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -170,7 +170,7 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("sqs", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<dnsName />
|
||||
<launchTime>2010-09-09T18:09:42Z</launchTime>
|
||||
<instanceId>i-9slweygo</instanceId>
|
||||
<imageId>ami-h30p5im0</imageId>
|
||||
<imageId>ami-25CB1213</imageId>
|
||||
<instanceState>
|
||||
<code>1</code>
|
||||
<name>shutdown</name>
|
||||
|
|
|
@ -53,6 +53,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
|
|||
import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.concurrent.Futures;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
|
@ -79,7 +80,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
@Inject
|
||||
AzureAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||
Supplier<Set<? extends Location>> locations, AzureBlobAsyncClient async,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, AzureBlobAsyncClient async,
|
||||
ContainerToResourceMetadata container2ResourceMd,
|
||||
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
||||
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
|
|||
import org.jclouds.blobstore.internal.BaseBlobStore;
|
||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
|
||||
|
@ -70,7 +71,7 @@ public class AzureBlobStore extends BaseBlobStore {
|
|||
|
||||
@Inject
|
||||
AzureBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
||||
Supplier<Set<? extends Location>> locations, AzureBlobClient sync,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, AzureBlobClient sync,
|
||||
ContainerToResourceMetadata container2ResourceMd,
|
||||
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
||||
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
|
|||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.internal.LocationImpl;
|
||||
|
@ -71,6 +72,7 @@ public class AzureBlobStoreContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
||||
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ import org.jclouds.http.functions.ReturnTrueOn404;
|
|||
import org.jclouds.http.options.GetOptions;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -277,7 +277,7 @@ public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClien
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("azureblob", "identity", "credential", new Properties());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ 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.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -133,7 +133,7 @@ public class AzureBlobRequestSignerTest extends RestClientTest<AzureBlobAsyncCli
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("azureblob", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
|||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -233,7 +233,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("azurequeue", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ public abstract class BlobStoreContextBuilder<S, A> extends RestContextBuilder<S
|
|||
|
||||
public BlobStoreContextBuilder(Class<S> syncClientType, Class<A> asyncClientType, Properties properties) {
|
||||
super(syncClientType, asyncClientType, properties);
|
||||
|
||||
}
|
||||
|
||||
public BlobStoreContext buildBlobStoreContext() {
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.Properties;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
|
||||
import com.google.inject.Module;
|
||||
|
||||
|
@ -124,18 +124,18 @@ public class BlobStoreContextFactory {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see RestContextFactory#createContextBuilder(ContextSpec)
|
||||
* @see RestContextFactory#createContextBuilder(RestContextSpec)
|
||||
*/
|
||||
public <S, A> BlobStoreContext createContext(ContextSpec<S, A> contextSpec) {
|
||||
public <S, A> BlobStoreContext createContext(RestContextSpec<S, A> contextSpec) {
|
||||
BlobStoreContextBuilder<?, ?> builder = BlobStoreContextBuilder.class.cast(createContextBuilder(contextSpec));
|
||||
return buildContextUnwrappingExceptions(builder);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RestContextFactory#createContextBuilder(ContextSpec, Properties)
|
||||
* @see RestContextFactory#createContextBuilder(RestContextSpec, Properties)
|
||||
*/
|
||||
public <S, A> BlobStoreContext createContext(ContextSpec<S, A> contextSpec, Properties overrides) {
|
||||
public <S, A> BlobStoreContext createContext(RestContextSpec<S, A> contextSpec, Properties overrides) {
|
||||
BlobStoreContextBuilder<?, ?> builder = BlobStoreContextBuilder.class.cast(createContextBuilder(contextSpec,
|
||||
overrides));
|
||||
return buildContextUnwrappingExceptions(builder);
|
||||
|
|
|
@ -78,6 +78,7 @@ import org.jclouds.blobstore.options.GetOptions;
|
|||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.crypto.CryptoStreams;
|
||||
import org.jclouds.date.DateService;
|
||||
|
@ -127,7 +128,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobUtils blobUtils,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||
Supplier<Set<? extends Location>> locations) {
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
super(context, blobUtils, service, defaultLocation, locations);
|
||||
this.blobFactory = blobFactory;
|
||||
this.dateService = dateService;
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.jclouds.blobstore.TransientBlobRequestSigner;
|
|||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.domain.internal.LocationImpl;
|
||||
|
@ -81,6 +82,7 @@ public class TransientBlobStoreContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
||||
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.jclouds.blobstore.domain.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
@ -47,12 +49,57 @@ public class StorageMetadataImpl extends ResourceMetadataImpl<StorageType> imple
|
|||
@Nullable
|
||||
private final Date lastModified;
|
||||
|
||||
private final StorageType type;
|
||||
|
||||
public StorageMetadataImpl(StorageType type, @Nullable String id, @Nullable String name,
|
||||
@Nullable Location location, @Nullable URI uri, @Nullable String eTag, @Nullable Date lastModified,
|
||||
Map<String, String> userMetadata) {
|
||||
super(type, id, name, location, uri, userMetadata);
|
||||
@Nullable Location location, @Nullable URI uri, @Nullable String eTag, @Nullable Date lastModified,
|
||||
Map<String, String> userMetadata) {
|
||||
super(id, name, location, uri, userMetadata);
|
||||
this.eTag = eTag;
|
||||
this.lastModified = lastModified;
|
||||
this.type = checkNotNull(type, "type");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public StorageType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((eTag == null) ? 0 : eTag.hashCode());
|
||||
result = prime * result + ((lastModified == null) ? 0 : lastModified.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;
|
||||
StorageMetadataImpl other = (StorageMetadataImpl) obj;
|
||||
if (eTag == null) {
|
||||
if (other.eTag != null)
|
||||
return false;
|
||||
} else if (!eTag.equals(other.eTag))
|
||||
return false;
|
||||
if (lastModified == null) {
|
||||
if (other.lastModified != null)
|
||||
return false;
|
||||
} else if (!lastModified.equals(other.lastModified))
|
||||
return false;
|
||||
if (type != other.type)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.jclouds.blobstore.domain.StorageMetadata;
|
|||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.util.Utils;
|
||||
|
||||
|
@ -61,7 +62,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
|
|||
@Inject
|
||||
protected BaseAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||
Supplier<Set<? extends Location>> locations) {
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
this.context = checkNotNull(context, "context");
|
||||
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
||||
this.service = checkNotNull(service, "service");
|
||||
|
@ -267,5 +268,4 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
|
|||
|
||||
protected abstract boolean deleteAndVerifyContainerGone(String container);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.jclouds.blobstore.domain.StorageMetadata;
|
|||
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||
import org.jclouds.blobstore.util.BlobUtils;
|
||||
import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.util.Utils;
|
||||
|
||||
|
@ -53,7 +54,7 @@ public abstract class BaseBlobStore implements BlobStore {
|
|||
|
||||
@Inject
|
||||
protected BaseBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
||||
Supplier<Set<? extends Location>> locations) {
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
this.context = checkNotNull(context, "context");
|
||||
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
||||
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.io.payloads.PhantomPayload;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -97,7 +97,7 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContextSpec<?, ?> createContextSpec() {
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("transient", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
;
|
||||
;
|
||||
; 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.
|
||||
; ====================================================================
|
||||
;
|
||||
(ns org.jclouds.modules
|
||||
(:require
|
||||
[clojure.contrib.logging :as logging])
|
||||
(:import
|
||||
[org.jclouds.ssh SshClient ExecResponse]
|
||||
com.google.inject.Module
|
||||
com.google.common.collect.ImmutableSet
|
||||
org.jclouds.net.IPSocket
|
||||
[org.jclouds.compute ComputeService ComputeServiceContextFactory StandaloneComputeServiceContextSpec]
|
||||
[java.util Set Map]
|
||||
[org.jclouds.compute.domain NodeMetadata Template]
|
||||
[com.google.common.base Supplier Predicate]
|
||||
org.jclouds.compute.domain.NodeMetadataBuilder))
|
||||
|
||||
|
||||
(defn compute-module
|
||||
[]
|
||||
(org.jclouds.compute.config.JCloudsNativeStandaloneComputeServiceContextModule
|
||||
(defrecord ClojureComputeServiceAdapter []
|
||||
org.jclouds.compute.JCloudsNativeComputeServiceAdapter
|
||||
(^NodeMetadata runNodeWithTagAndNameAndStoreCredentials [this ^String tag ^String name ^Template template ^Map credentialStore]
|
||||
())
|
||||
(^Iterable listNodes [this ]
|
||||
())
|
||||
(^Iterable listImages [this ]
|
||||
())
|
||||
(^Iterable listHardwareProfiles [this ]
|
||||
())
|
||||
(^Iterable listLocations [this ]
|
||||
())
|
||||
(^NodeMetadata getNode [this ^String id]
|
||||
())
|
||||
(^void destroyNode [this ^String id]
|
||||
())
|
||||
(^void rebootNode [this ^String id]
|
||||
()))))
|
||||
|
||||
(defn compute-context [^RestContextSpec spec]
|
||||
(.createContext (ComputeServiceContextFactory.) spec))
|
||||
|
||||
(^RestContextSpec defn context-spec [^StandaloneComputeServiceContextModule module]
|
||||
(StandaloneComputeServiceContextSpec. "servermanager", "http://host", "1", "identity", "credential", module, (ImmutableSet/of)))
|
||||
|
||||
(defrecord NodeListComputeService
|
||||
[node-list]
|
||||
org.jclouds.compute.ComputeService
|
||||
(listNodes [_] node-list)
|
||||
(getNodeMetadata
|
||||
[_ id]
|
||||
(some #(= (.getId %) id) node-list))
|
||||
(listNodesDetailsMatching
|
||||
[_ predicate]
|
||||
(filter #(.apply predicate %) node-list)))
|
||||
|
||||
(defn ssh-client-factory
|
||||
"Pass in a function that reifies org.jclouds.ssh.SshClient"
|
||||
[ctor]
|
||||
(reify
|
||||
org.jclouds.ssh.SshClient$Factory
|
||||
(^org.jclouds.ssh.SshClient create
|
||||
[_ ^IPSocket socket ^String username ^String password-or-key]
|
||||
(ctor socket username password-or-key))
|
||||
(^org.jclouds.ssh.SshClient create
|
||||
[_ ^IPSocket socket ^String username ^bytes password-or-key]
|
||||
(ctor socket username password-or-key))))
|
||||
|
||||
(defn ssh-module
|
||||
"Create a module that specifies the factory for creating an ssh service"
|
||||
[^org.jclouds.ssh.SshClient$Factory factory]
|
||||
(let [binder (atom nil)]
|
||||
(reify
|
||||
com.google.inject.Module
|
||||
(configure
|
||||
[this abinder]
|
||||
(reset! binder abinder)
|
||||
(.. @binder (bind org.jclouds.ssh.SshClient$Factory)
|
||||
(toInstance factory))))))
|
|
@ -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.compute;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.domain.Credentials;
|
||||
|
||||
/**
|
||||
* A means of specifying the interface between the {@link ComputeServices} and a concrete compute
|
||||
* cloud implementation, jclouds or otherwise.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public interface ComputeServiceAdapter<N, H, I, L> {
|
||||
|
||||
/**
|
||||
* {@link ComputeService#runNodesWithTag(String, int, Template)} generates the parameters passed
|
||||
* into this method such that each node in the set has a unique name.
|
||||
* <p/>
|
||||
* Your responsibility is to create a node with the underlying library and return after storing
|
||||
* its credentials in the supplied map.
|
||||
* <p/>
|
||||
* Note that it is intentional to return the library native node object, as generic type
|
||||
* {@code N}. If you are not using library-native objects (such as libvirt {@code Domain}) use
|
||||
* {@link JCloudsNativeComputeServiceAdapter} instead.
|
||||
*
|
||||
* @param tag
|
||||
* used to aggregate nodes with identical configuration
|
||||
* @param name
|
||||
* unique supplied name for the node, which has the tag encoded into it.
|
||||
* @param template
|
||||
* includes {@code imageId}, {@code locationId}, and {@code hardwareId} used to start
|
||||
* the instance.
|
||||
* @param credentialStore
|
||||
* once the node is started, its login user and password will be encoded based on the
|
||||
* node {@code id}
|
||||
* @return library-native representation of a node.
|
||||
*
|
||||
* @see ComputeService#runNodesWithTag(String, int, Template)
|
||||
*/
|
||||
N runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template,
|
||||
Map<String, Credentials> credentialStore);
|
||||
|
||||
/**
|
||||
* Hardware profiles describe available cpu, memory, and disk configurations that can be used to
|
||||
* run a node.
|
||||
* <p/>
|
||||
* To implement this method, return the library native hardware profiles available to the user.
|
||||
* These will be used to launch nodes as a part of the template.
|
||||
*
|
||||
* @return a non-null iterable of available hardware profiles.
|
||||
* @see ComputeService#listHardwareProfiles()
|
||||
*/
|
||||
Iterable<H> listHardwareProfiles();
|
||||
|
||||
/**
|
||||
* Images are the available configured operating systems that someone can run a node with. *
|
||||
* <p/>
|
||||
* To implement this method, return the library native images available to the user. These will
|
||||
* be used to launch nodes as a part of the template.
|
||||
*
|
||||
* @return a non-null iterable of available images.
|
||||
* @see ComputeService#listImages()
|
||||
*/
|
||||
Iterable<I> listImages();
|
||||
|
||||
Iterable<L> listLocations();
|
||||
|
||||
N getNode(String id);
|
||||
|
||||
void destroyNode(String id);
|
||||
|
||||
void rebootNode(String id);
|
||||
|
||||
Iterable<N> listNodes();
|
||||
|
||||
}
|
|
@ -19,9 +19,13 @@
|
|||
|
||||
package org.jclouds.compute;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
|
@ -44,6 +48,18 @@ public interface ComputeServiceContext {
|
|||
|
||||
<S, A> RestContext<S, A> getProviderSpecificContext();
|
||||
|
||||
/**
|
||||
* retrieves a list of credentials for resources created within this context, keyed on {@code id}
|
||||
* of the resource. We are testing this approach for resources such as compute nodes, where you
|
||||
* could access this externally.
|
||||
*
|
||||
*/
|
||||
@Beta
|
||||
Map<String, Credentials> getCredentialStore();
|
||||
|
||||
@Beta
|
||||
Map<String, Credentials> credentialStore();
|
||||
|
||||
Utils getUtils();
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.Properties;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
|
||||
import com.google.inject.Module;
|
||||
|
||||
|
@ -41,8 +41,8 @@ public class ComputeServiceContextFactory {
|
|||
private final RestContextFactory contextFactory;
|
||||
|
||||
/**
|
||||
* Initializes with the default properties built-in to jclouds. This is
|
||||
* typically stored in the classpath resource {@code rest.properties}
|
||||
* Initializes with the default properties built-in to jclouds. This is typically stored in the
|
||||
* classpath resource {@code rest.properties}
|
||||
*
|
||||
* @see RestContextFactory#getPropertiesFromResource
|
||||
*/
|
||||
|
@ -59,8 +59,7 @@ public class ComputeServiceContextFactory {
|
|||
|
||||
/**
|
||||
*
|
||||
* Uses the supplied RestContextFactory to create
|
||||
* {@link ComputeServiceContext}s
|
||||
* Uses the supplied RestContextFactory to create {@link ComputeServiceContext}s
|
||||
*/
|
||||
public ComputeServiceContextFactory(RestContextFactory restContextFactory) {
|
||||
this.contextFactory = restContextFactory;
|
||||
|
@ -104,8 +103,7 @@ public class ComputeServiceContextFactory {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see RestContextFactory#createContextBuilder(String, String,String,
|
||||
* Iterable)
|
||||
* @see RestContextFactory#createContextBuilder(String, String,String, Iterable)
|
||||
*/
|
||||
public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential,
|
||||
Iterable<? extends Module> modules) {
|
||||
|
@ -115,8 +113,7 @@ public class ComputeServiceContextFactory {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see RestContextFactory#createContextBuilder(String, String,String,
|
||||
* Iterable, Properties)
|
||||
* @see RestContextFactory#createContextBuilder(String, String,String, Iterable, Properties)
|
||||
*/
|
||||
public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential,
|
||||
Iterable<? extends Module> modules, Properties overrides) {
|
||||
|
@ -126,9 +123,9 @@ public class ComputeServiceContextFactory {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see RestContextFactory#createContextBuilder(ContextSpec)
|
||||
* @see RestContextFactory#createContextBuilder(RestContextSpec)
|
||||
*/
|
||||
public <S, A> ComputeServiceContext createContext(ContextSpec<S, A> contextSpec) {
|
||||
public <S, A> ComputeServiceContext createContext(RestContextSpec<S, A> contextSpec) {
|
||||
ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class
|
||||
.cast(createContextBuilder(contextSpec));
|
||||
return buildContextUnwrappingExceptions(builder);
|
||||
|
@ -136,12 +133,22 @@ public class ComputeServiceContextFactory {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see RestContextFactory#createContextBuilder(ContextSpec, Properties)
|
||||
* @see RestContextFactory#createContextBuilder(RestContextSpec, Properties)
|
||||
*/
|
||||
public <S, A> ComputeServiceContext createContext(ContextSpec<S, A> contextSpec, Properties overrides) {
|
||||
public <S, A> ComputeServiceContext createContext(RestContextSpec<S, A> contextSpec, Properties overrides) {
|
||||
ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class.cast(createContextBuilder(
|
||||
contextSpec, overrides));
|
||||
return buildContextUnwrappingExceptions(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RestContextFactory#createContextBuilder(RestContextSpec, Iterable, Properties)
|
||||
*/
|
||||
public <S, A> ComputeServiceContext createContext(RestContextSpec<S, A> contextSpec, Iterable<Module> modules,
|
||||
Properties overrides) {
|
||||
ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class.cast(createContextBuilder(
|
||||
contextSpec, modules, overrides));
|
||||
return buildContextUnwrappingExceptions(builder);
|
||||
}
|
||||
|
||||
}
|
|
@ -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.compute;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
/**
|
||||
* A means of specifying the implementation of a service that uses jclouds types.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public interface JCloudsNativeComputeServiceAdapter extends
|
||||
ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template,
|
||||
Map<String, Credentials> credentialStore);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Iterable<NodeMetadata> listNodes();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Iterable<Image> listImages();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Iterable<Hardware> listHardwareProfiles();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Iterable<Location> listLocations();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
NodeMetadata getNode(String id);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
void destroyNode(String id);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
void rebootNode(String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
*
|
||||
* 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;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
import org.jclouds.compute.config.StandaloneComputeServiceClientModule;
|
||||
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class StandaloneComputeServiceContextBuilder extends
|
||||
ComputeServiceContextBuilder<ComputeService, ComputeService> {
|
||||
|
||||
public StandaloneComputeServiceContextBuilder(Properties props) {
|
||||
super(ComputeService.class, ComputeService.class, props);
|
||||
if (properties.size() == 0)
|
||||
properties.putAll(new PropertiesBuilder().build());
|
||||
if (!properties.containsKey("jclouds.provider"))
|
||||
properties.setProperty("jclouds.provider", "standalone");
|
||||
if (!properties.containsKey(PROPERTY_ENDPOINT))
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "standalone");
|
||||
if (!properties.containsKey(PROPERTY_API_VERSION))
|
||||
properties.setProperty(PROPERTY_API_VERSION, "1");
|
||||
if (!properties.containsKey(PROPERTY_IDENTITY))
|
||||
properties.setProperty(PROPERTY_IDENTITY, System.getProperty("user.name"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new StandaloneComputeServiceClientModule<ComputeService>(ComputeService.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
*
|
||||
* 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;
|
||||
|
||||
import org.jclouds.PropertiesBuilder;
|
||||
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class StandaloneComputeServiceContextSpec<N, H, I, L> extends RestContextSpec<ComputeService, ComputeService> {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String identity,
|
||||
String credential, StandaloneComputeServiceContextModule<N, H, I, L> contextModule, Iterable<Module> modules) {
|
||||
super(provider, endpoint, apiVersion, identity, credential, ComputeService.class, ComputeService.class,
|
||||
PropertiesBuilder.class, (Class) StandaloneComputeServiceContextBuilder.class, Iterables.concat(
|
||||
ImmutableSet.of(contextModule), modules));
|
||||
}
|
||||
|
||||
}
|
|
@ -29,52 +29,54 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.LoadBalancerService;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
||||
|
||||
protected abstract Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector);
|
||||
|
||||
protected abstract Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector);
|
||||
|
||||
/**
|
||||
* By default allows you to use a static set of locations bound to Set<? extends Location>
|
||||
*/
|
||||
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
|
||||
Set<? extends Location> locations = injector.getInstance(Key.get(new TypeLiteral<Set<? extends Location>>() {
|
||||
}));
|
||||
return Suppliers.<Set<? extends Location>> ofInstance(locations);
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new ComputeServiceTimeoutsModule());
|
||||
bindLoadBalancerService();
|
||||
}
|
||||
|
||||
protected void bindLoadBalancerService() {
|
||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null)).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
/**
|
||||
* The default template if none is provided.
|
||||
*/
|
||||
@Provides
|
||||
@Named("DEFAULT")
|
||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||
return template.osFamily(UBUNTU);
|
||||
}
|
||||
|
||||
/**
|
||||
* supplies how the tag is encoded into the name. A string of hex characters is the last argument
|
||||
* and tag is the first
|
||||
*/
|
||||
@Provides
|
||||
@Named("NAMING_CONVENTION")
|
||||
@Singleton
|
||||
|
@ -86,7 +88,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Image>> provideImageMap(Supplier<Set<? extends Image>> images) {
|
||||
protected Supplier<Map<String, ? extends Image>> provideImageMap(@Memoized Supplier<Set<? extends Image>> images) {
|
||||
return Suppliers.compose(new Function<Set<? extends Image>, Map<String, ? extends Image>>() {
|
||||
|
||||
@Override
|
||||
|
@ -106,20 +108,22 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
protected Supplier<Set<? extends Image>> supplyImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final Injector injector) {
|
||||
final Supplier<Set<? extends Image>> imageSupplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Image>>(authException, seconds,
|
||||
new Supplier<Set<? extends Image>>() {
|
||||
@Override
|
||||
public Set<? extends Image> get() {
|
||||
return getSourceImageSupplier(injector).get();
|
||||
}
|
||||
});
|
||||
new Supplier<Set<? extends Image>>() {
|
||||
@Override
|
||||
public Set<? extends Image> get() {
|
||||
return imageSupplier.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Location>> provideLocationMap(Supplier<Set<? extends Location>> locations) {
|
||||
protected Supplier<Map<String, ? extends Location>> provideLocationMap(
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, ? extends Location>>() {
|
||||
|
||||
@Override
|
||||
|
@ -139,20 +143,21 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
protected Supplier<Set<? extends Location>> supplyLocationCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final Injector injector) {
|
||||
final Supplier<Set<? extends Location>> locationSupplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Location>>(authException, seconds,
|
||||
new Supplier<Set<? extends Location>>() {
|
||||
@Override
|
||||
public Set<? extends Location> get() {
|
||||
return getSourceLocationSupplier(injector).get();
|
||||
}
|
||||
});
|
||||
new Supplier<Set<? extends Location>>() {
|
||||
@Override
|
||||
public Set<? extends Location> get() {
|
||||
return locationSupplier.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(Supplier<Set<? extends Hardware>> sizes) {
|
||||
protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(@Memoized Supplier<Set<? extends Hardware>> sizes) {
|
||||
return Suppliers.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
|
||||
|
||||
@Override
|
||||
|
@ -172,15 +177,16 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Memoized
|
||||
protected Supplier<Set<? extends Hardware>> supplySizeCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
||||
final Injector injector) {
|
||||
final Supplier<Set<? extends Hardware>> hardwareSupplier) {
|
||||
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Hardware>>(authException, seconds,
|
||||
new Supplier<Set<? extends Hardware>>() {
|
||||
@Override
|
||||
public Set<? extends Hardware> get() {
|
||||
return getSourceSizeSupplier(injector).get();
|
||||
}
|
||||
});
|
||||
new Supplier<Set<? extends Hardware>>() {
|
||||
@Override
|
||||
public Set<? extends Hardware> get() {
|
||||
return hardwareSupplier.get();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -194,25 +200,4 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
|||
};
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Location> supplyDefaultLocation(Injector injector, Supplier<Set<? extends Location>> locations) {
|
||||
return Suppliers.compose(new Function<Set<? extends Location>, Location>() {
|
||||
|
||||
@Override
|
||||
public Location apply(Set<? extends Location> from) {
|
||||
return Iterables.find(from, new Predicate<Location>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Location input) {
|
||||
return input.getScope() == LocationScope.ZONE;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}, locations);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
*
|
||||
* 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.config;
|
||||
|
||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public abstract class BindComputeStrategiesByClass extends AbstractModule {
|
||||
protected void configure() {
|
||||
bindRunNodesAndAddToSetStrategy(defineRunNodesAndAddToSetStrategy());
|
||||
bindAddNodeWithTagStrategy(defineAddNodeWithTagStrategy());
|
||||
bindListNodesStrategy(defineListNodesStrategy());
|
||||
bindGetNodeMetadataStrategy(defineGetNodeMetadataStrategy());
|
||||
bindRebootNodeStrategy(defineRebootNodeStrategy());
|
||||
bindDestroyNodeStrategy(defineDestroyNodeStrategy());
|
||||
}
|
||||
|
||||
protected void bindRunNodesAndAddToSetStrategy(Class<? extends RunNodesAndAddToSetStrategy> clazz) {
|
||||
bind(RunNodesAndAddToSetStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
/**
|
||||
* needed, if {@link RunNodesAndAddToSetStrategy} requires it
|
||||
*/
|
||||
protected void bindAddNodeWithTagStrategy(Class<? extends AddNodeWithTagStrategy> clazz) {
|
||||
bind(AddNodeWithTagStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
protected void bindDestroyNodeStrategy(Class<? extends DestroyNodeStrategy> clazz) {
|
||||
bind(DestroyNodeStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
protected void bindRebootNodeStrategy(Class<? extends RebootNodeStrategy> clazz) {
|
||||
bind(RebootNodeStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
protected void bindGetNodeMetadataStrategy(Class<? extends GetNodeMetadataStrategy> clazz) {
|
||||
bind(GetNodeMetadataStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
protected void bindListNodesStrategy(Class<? extends ListNodesStrategy> clazz) {
|
||||
bind(ListNodesStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() {
|
||||
return EncodeTagIntoNameRunNodesAndAddToSetStrategy.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* needed, if {@link RunNodesAndAddToSetStrategy} requires it
|
||||
*/
|
||||
protected abstract Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy();
|
||||
|
||||
protected abstract Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy();
|
||||
|
||||
protected abstract Class<? extends RebootNodeStrategy> defineRebootNodeStrategy();
|
||||
|
||||
protected abstract Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy();
|
||||
|
||||
protected abstract Class<? extends ListNodesStrategy> defineListNodesStrategy();
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
*
|
||||
* 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.config;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
|
||||
import org.jclouds.compute.suppliers.LocationSupplier;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public abstract class BindComputeSuppliersByClass extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindImageSupplier(defineImageSupplier());
|
||||
bindLocationSupplier(defineLocationSupplier());
|
||||
bindHardwareSupplier(defineHardwareSupplier());
|
||||
bindDefaultLocationSupplier(defineDefaultLocationSupplier());
|
||||
}
|
||||
|
||||
protected abstract Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier();
|
||||
|
||||
protected abstract Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier();
|
||||
|
||||
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||
return LocationSupplier.class;
|
||||
}
|
||||
|
||||
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
|
||||
return DefaultLocationSupplier.class;
|
||||
}
|
||||
|
||||
protected void bindImageSupplier(Class<? extends Supplier<Set<? extends Image>>> clazz) {
|
||||
bind(new TypeLiteral<Supplier<Set<? extends Image>>>() {
|
||||
}).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
protected void bindLocationSupplier(Class<? extends Supplier<Set<? extends Location>>> clazz) {
|
||||
bind(new TypeLiteral<Supplier<Set<? extends Location>>>() {
|
||||
}).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
protected void bindDefaultLocationSupplier(Class<? extends Supplier<Location>> clazz) {
|
||||
bind(new TypeLiteral<Supplier<Location>>() {
|
||||
}).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
protected void bindHardwareSupplier(Class<? extends Supplier<Set<? extends Hardware>>> clazz) {
|
||||
bind(new TypeLiteral<Supplier<Set<? extends Hardware>>>() {
|
||||
}).to(clazz).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package org.jclouds.compute.config;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
public class JCloudsNativeStandaloneComputeServiceContextModule extends
|
||||
StandaloneComputeServiceContextModule<NodeMetadata, Hardware, Image, Location> {
|
||||
private final Class<? extends ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location>> adapter;
|
||||
|
||||
public JCloudsNativeStandaloneComputeServiceContextModule(
|
||||
Class<? extends ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location>> adapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* This binds the converters to {@link IdentityFunction} as that ensure the same value is
|
||||
* returned.
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location>>() {
|
||||
}).to(adapter);
|
||||
bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE);
|
||||
bind(new TypeLiteral<Function<NodeMetadata, NodeMetadata>>() {
|
||||
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
|
||||
bind(new TypeLiteral<Function<Image, Image>>() {
|
||||
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
|
||||
bind(new TypeLiteral<Function<Hardware, Hardware>>() {
|
||||
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
|
||||
bind(new TypeLiteral<Function<Location, Location>>() {
|
||||
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
}
|
|
@ -17,21 +17,18 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.compute.stub.config;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
package org.jclouds.compute.config;
|
||||
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.config.RestClientModule;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ConfiguresRestClient
|
||||
@RequiresHttp
|
||||
public class StubComputeServiceClientModule extends RestClientModule<ConcurrentMap, ConcurrentMap> {
|
||||
public class StandaloneComputeServiceClientModule<C> extends RestClientModule<C, C> {
|
||||
|
||||
public StubComputeServiceClientModule() {
|
||||
super(ConcurrentMap.class, ConcurrentMap.class);
|
||||
public StandaloneComputeServiceClientModule(Class<C> clazz) {
|
||||
super(clazz, clazz);
|
||||
}
|
||||
|
||||
@Override
|
|
@ -0,0 +1,173 @@
|
|||
/**
|
||||
*
|
||||
* 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.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.compute.strategy.impl.AdaptingComputeServiceStrategies;
|
||||
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class StandaloneComputeServiceContextModule<N, H, I, L> extends BaseComputeServiceContextModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bindDefaultLocation();
|
||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||
}).to(new TypeLiteral<ComputeServiceContextImpl<ComputeService, ComputeService>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>> {
|
||||
private final Supplier<Iterable<F>> backingSupplier;
|
||||
private final Function<F, T> converter;
|
||||
|
||||
public TransformingSetSupplier(Supplier<Iterable<F>> backingSupplier, Function<F, T> converter) {
|
||||
this.backingSupplier = checkNotNull(backingSupplier, "backingSupplier");
|
||||
this.converter = checkNotNull(converter, "converter");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<? extends T> get() {
|
||||
return newHashSet(transform(backingSupplier.get(), converter));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Set<? extends Hardware>> provideHardware(final ComputeServiceAdapter<N, H, I, L> adapter,
|
||||
Function<H, Hardware> transformer) {
|
||||
return new TransformingSetSupplier<H, Hardware>(new Supplier<Iterable<H>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<H> get() {
|
||||
return adapter.listHardwareProfiles();
|
||||
}
|
||||
|
||||
}, transformer);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Set<? extends Image>> provideImages(final ComputeServiceAdapter<N, H, I, L> adapter,
|
||||
Function<I, Image> transformer) {
|
||||
return new TransformingSetSupplier<I, Image>(new Supplier<Iterable<I>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<I> get() {
|
||||
return adapter.listImages();
|
||||
}
|
||||
|
||||
}, transformer);
|
||||
}
|
||||
|
||||
protected void bindDefaultLocation() {
|
||||
bind(new TypeLiteral<Supplier<Location>>() {
|
||||
}).to(DefaultLocationSupplier.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Set<? extends Location>> provideLocations(final ComputeServiceAdapter<N, H, I, L> adapter,
|
||||
Function<L, Location> transformer) {
|
||||
return new TransformingSetSupplier<L, Location>(new Supplier<Iterable<L>>() {
|
||||
|
||||
@Override
|
||||
public Iterable<L> get() {
|
||||
return adapter.listLocations();
|
||||
}
|
||||
|
||||
}, transformer);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected AddNodeWithTagStrategy defineAddNodeWithTagStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected DestroyNodeStrategy defineDestroyNodeStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GetNodeMetadataStrategy defineGetNodeMetadataStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected ListNodesStrategy defineListNodesStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected RebootNodeStrategy defineRebootNodeStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
// enum singleton pattern
|
||||
public static enum IdentityFunction implements Function<Object, Object> {
|
||||
INSTANCE;
|
||||
|
||||
public Object apply(Object o) {
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "identity";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
*
|
||||
* 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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.domain.internal.ComputeMetadataImpl;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.ResourceMetadataBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ComputeMetadataBuilder extends ResourceMetadataBuilder<ComputeType> {
|
||||
protected String id;
|
||||
protected ComputeType type;
|
||||
|
||||
public ComputeMetadataBuilder(ComputeType type) {
|
||||
super();
|
||||
this.type = checkNotNull(type, "type");
|
||||
}
|
||||
|
||||
public ComputeMetadataBuilder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* set id and providerId to the same value;
|
||||
*/
|
||||
public ComputeMetadataBuilder ids(String id) {
|
||||
id(id).providerId(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputeMetadataBuilder providerId(String providerId) {
|
||||
return ComputeMetadataBuilder.class.cast(super.providerId(providerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputeMetadataBuilder name(String name) {
|
||||
return ComputeMetadataBuilder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputeMetadataBuilder location(Location location) {
|
||||
return ComputeMetadataBuilder.class.cast(super.location(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputeMetadataBuilder uri(URI uri) {
|
||||
return ComputeMetadataBuilder.class.cast(super.uri(uri));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputeMetadataBuilder userMetadata(Map<String, String> userMetadata) {
|
||||
return ComputeMetadataBuilder.class.cast(super.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
public ComputeMetadata build() {
|
||||
return new ComputeMetadataImpl(type, providerId, name, id, location, uri, userMetadata);
|
||||
}
|
||||
|
||||
public static ComputeMetadataBuilder fromComputeMetadata(ComputeMetadata in) {
|
||||
return new ComputeMetadataBuilder(in.getType()).id(in.getId()).location(in.getLocation()).name(in.getName())
|
||||
.uri(in.getUri()).userMetadata(in.getUserMetadata());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
/**
|
||||
*
|
||||
* 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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static org.jclouds.compute.predicates.ImagePredicates.any;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.domain.internal.HardwareImpl;
|
||||
import org.jclouds.compute.predicates.ImagePredicates;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class HardwareBuilder extends ComputeMetadataBuilder {
|
||||
private List<Processor> processors = Lists.newArrayList();
|
||||
private int ram;
|
||||
private List<Volume> volumes = Lists.newArrayList();
|
||||
private Predicate<Image> supportsImage = any();
|
||||
|
||||
public HardwareBuilder() {
|
||||
super(ComputeType.HARDWARE);
|
||||
}
|
||||
|
||||
public HardwareBuilder processors(List<Processor> processors) {
|
||||
this.processors = checkNotNull(processors, "processors");
|
||||
return this;
|
||||
}
|
||||
|
||||
public HardwareBuilder ram(int ram) {
|
||||
this.ram = ram;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HardwareBuilder volumes(List<Volume> volumes) {
|
||||
this.volumes = checkNotNull(volumes, "volumes");
|
||||
return this;
|
||||
}
|
||||
|
||||
public HardwareBuilder supportsImage(Predicate<Image> supportsImage) {
|
||||
this.supportsImage = checkNotNull(supportsImage, "supportsImage");
|
||||
return this;
|
||||
}
|
||||
|
||||
public HardwareBuilder is64Bit(boolean is64Bit) {
|
||||
supportsImage(is64Bit ? ImagePredicates.is64Bit() : not(ImagePredicates.is64Bit()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareBuilder id(String id) {
|
||||
return HardwareBuilder.class.cast(super.id(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareBuilder ids(String id) {
|
||||
return HardwareBuilder.class.cast(super.ids(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareBuilder providerId(String providerId) {
|
||||
return HardwareBuilder.class.cast(super.providerId(providerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareBuilder name(String name) {
|
||||
return HardwareBuilder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareBuilder location(Location location) {
|
||||
return HardwareBuilder.class.cast(super.location(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareBuilder uri(URI uri) {
|
||||
return HardwareBuilder.class.cast(super.uri(uri));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareBuilder userMetadata(Map<String, String> userMetadata) {
|
||||
return HardwareBuilder.class.cast(super.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hardware build() {
|
||||
return new HardwareImpl(providerId, name, id, location, uri, userMetadata, processors, ram, volumes,
|
||||
supportsImage);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static HardwareBuilder fromHardware(Hardware in) {
|
||||
return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation())
|
||||
.name(in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata())
|
||||
.processors(List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes()))
|
||||
.supportsImage(in.supportsImage());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
*
|
||||
* 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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.compute.domain.internal.ImageImpl;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ImageBuilder extends ComputeMetadataBuilder {
|
||||
private OperatingSystem operatingSystem;
|
||||
private String version;
|
||||
private String description;
|
||||
private Credentials defaultCredentials;
|
||||
|
||||
public ImageBuilder() {
|
||||
super(ComputeType.IMAGE);
|
||||
}
|
||||
|
||||
public ImageBuilder operatingSystem(OperatingSystem operatingSystem) {
|
||||
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem");
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImageBuilder version(@Nullable String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImageBuilder description(String description) {
|
||||
this.description = checkNotNull(description, "description");
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImageBuilder defaultCredentials(@Nullable Credentials defaultCredentials) {
|
||||
this.defaultCredentials = defaultCredentials;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageBuilder id(String id) {
|
||||
return ImageBuilder.class.cast(super.id(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageBuilder ids(String id) {
|
||||
return ImageBuilder.class.cast(super.ids(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageBuilder providerId(String providerId) {
|
||||
return ImageBuilder.class.cast(super.providerId(providerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageBuilder name(String name) {
|
||||
return ImageBuilder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageBuilder location(Location location) {
|
||||
return ImageBuilder.class.cast(super.location(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageBuilder uri(URI uri) {
|
||||
return ImageBuilder.class.cast(super.uri(uri));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageBuilder userMetadata(Map<String, String> userMetadata) {
|
||||
return ImageBuilder.class.cast(super.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image build() {
|
||||
return new ImageImpl(providerId, name, id, location, uri, userMetadata, operatingSystem, description, version,
|
||||
defaultCredentials);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
/**
|
||||
*
|
||||
* 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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class NodeMetadataBuilder extends ComputeMetadataBuilder {
|
||||
private NodeState state;
|
||||
private Set<String> publicAddresses = Sets.newLinkedHashSet();
|
||||
private Set<String> privateAddresses = Sets.newLinkedHashSet();
|
||||
@Nullable
|
||||
private Credentials credentials;
|
||||
@Nullable
|
||||
private String tag;
|
||||
@Nullable
|
||||
private String imageId;
|
||||
@Nullable
|
||||
private Hardware hardware;
|
||||
@Nullable
|
||||
private OperatingSystem os;
|
||||
|
||||
public NodeMetadataBuilder() {
|
||||
super(ComputeType.NODE);
|
||||
}
|
||||
|
||||
public NodeMetadataBuilder state(NodeState state) {
|
||||
this.state = checkNotNull(state, "state");
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeMetadataBuilder publicAddresses(Iterable<String> publicAddresses) {
|
||||
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeMetadataBuilder privateAddresses(Iterable<String> privateAddresses) {
|
||||
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeMetadataBuilder credentials(@Nullable Credentials credentials) {
|
||||
this.credentials = credentials;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeMetadataBuilder tag(@Nullable String tag) {
|
||||
this.tag = tag;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeMetadataBuilder imageId(@Nullable String imageId) {
|
||||
this.imageId = imageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeMetadataBuilder hardware(@Nullable Hardware hardware) {
|
||||
this.hardware = hardware;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeMetadataBuilder operatingSystem(@Nullable OperatingSystem os) {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadataBuilder id(String id) {
|
||||
return NodeMetadataBuilder.class.cast(super.id(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadataBuilder ids(String id) {
|
||||
return NodeMetadataBuilder.class.cast(super.ids(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadataBuilder providerId(String providerId) {
|
||||
return NodeMetadataBuilder.class.cast(super.providerId(providerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadataBuilder name(String name) {
|
||||
return NodeMetadataBuilder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadataBuilder location(Location location) {
|
||||
return NodeMetadataBuilder.class.cast(super.location(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadataBuilder uri(URI uri) {
|
||||
return NodeMetadataBuilder.class.cast(super.uri(uri));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadataBuilder userMetadata(Map<String, String> userMetadata) {
|
||||
return NodeMetadataBuilder.class.cast(super.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata build() {
|
||||
return new NodeMetadataImpl(providerId, name, id, location, uri, userMetadata, tag, hardware, imageId, os, state,
|
||||
publicAddresses, privateAddresses, credentials);
|
||||
}
|
||||
|
||||
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) {
|
||||
return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId())
|
||||
.location(node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tag(node.getTag())
|
||||
.hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem(node.getOperatingSystem())
|
||||
.state(node.getState()).publicAddresses(node.getPublicAddresses())
|
||||
.privateAddresses(node.getPrivateAddresses()).credentials(node.getCredentials());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
*
|
||||
* 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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class OperatingSystemBuilder {
|
||||
@Nullable
|
||||
private OsFamily family;
|
||||
@Nullable
|
||||
private String name;
|
||||
@Nullable
|
||||
private String arch;
|
||||
@Nullable
|
||||
private String version;
|
||||
private String description;
|
||||
private boolean is64Bit;
|
||||
|
||||
public OperatingSystemBuilder family(@Nullable OsFamily family) {
|
||||
this.family = family;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OperatingSystemBuilder name(@Nullable String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OperatingSystemBuilder arch(@Nullable String arch) {
|
||||
this.arch = arch;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OperatingSystemBuilder version(@Nullable String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OperatingSystemBuilder description(String description) {
|
||||
this.description = checkNotNull(description, "description");
|
||||
return this;
|
||||
}
|
||||
|
||||
public OperatingSystemBuilder is64Bit(boolean is64Bit) {
|
||||
this.is64Bit = is64Bit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public OperatingSystem build() {
|
||||
return new OperatingSystem(family, name, version, arch, description, is64Bit);
|
||||
}
|
||||
|
||||
public static OperatingSystem fromOperatingSystem(OperatingSystem in) {
|
||||
return new OperatingSystem(in.getFamily(), in.getName(), in.getVersion(), in.getArch(), in.getDescription(),
|
||||
in.is64Bit());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
*
|
||||
* 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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class VolumeBuilder {
|
||||
|
||||
private Volume.Type type;
|
||||
private String id;
|
||||
@Nullable
|
||||
private Float size;
|
||||
@Nullable
|
||||
private String device;
|
||||
private boolean bootDevice;
|
||||
private boolean durable;
|
||||
|
||||
public VolumeBuilder type(Volume.Type type) {
|
||||
this.type = checkNotNull(type, "type");
|
||||
return this;
|
||||
}
|
||||
|
||||
public VolumeBuilder id(String id) {
|
||||
this.id = checkNotNull(id, "id");
|
||||
return this;
|
||||
}
|
||||
|
||||
public VolumeBuilder size(@Nullable Float size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VolumeBuilder device(@Nullable String device) {
|
||||
this.device = device;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VolumeBuilder bootDevice(boolean bootDevice) {
|
||||
this.bootDevice = bootDevice;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VolumeBuilder durable(boolean durable) {
|
||||
this.durable = durable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Volume build() {
|
||||
return new VolumeImpl(id, type, size, device, bootDevice, durable);
|
||||
}
|
||||
|
||||
public static Volume fromVolume(Volume in) {
|
||||
return new VolumeImpl(in.getId(), in.getType(), in.getSize(), in.getDevice(), in.isBootDevice(), in.isDurable());
|
||||
}
|
||||
}
|
|
@ -33,17 +33,25 @@ import org.jclouds.domain.internal.ResourceMetadataImpl;
|
|||
* @author Adrian Cole
|
||||
* @author Ivan Meredith
|
||||
*/
|
||||
public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> implements
|
||||
ComputeMetadata {
|
||||
|
||||
public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> implements ComputeMetadata {
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 7374704415964898694L;
|
||||
private final String id;
|
||||
private final ComputeType type;
|
||||
|
||||
public ComputeMetadataImpl(ComputeType type, String providerId, String name, String id,
|
||||
Location location, URI uri, Map<String, String> userMetadata) {
|
||||
super(type, providerId, name, location, uri, userMetadata);
|
||||
public ComputeMetadataImpl(ComputeType type, String providerId, String name, String id, Location location, URI uri,
|
||||
Map<String, String> userMetadata) {
|
||||
super(providerId, name, location, uri, userMetadata);
|
||||
this.id = checkNotNull(id, "id");
|
||||
this.type = checkNotNull(type, "type");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ComputeType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,6 +67,7 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
|
|||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -76,6 +85,8 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
|
|||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (type != other.type)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,28 +39,27 @@ import org.jclouds.domain.ResourceMetadata;
|
|||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8994255275911717567L;
|
||||
private final List<Processor> processors = Lists.newArrayList();
|
||||
private final List<Processor> processors;
|
||||
private final int ram;
|
||||
private final List<Volume> volumes = Lists.newArrayList();
|
||||
|
||||
private Predicate<Image> supportsImage;
|
||||
private final List<Volume> volumes;
|
||||
private final Predicate<Image> supportsImage;
|
||||
|
||||
public HardwareImpl(String providerId, String name, String id, @Nullable Location location, URI uri,
|
||||
Map<String, String> userMetadata, Iterable<? extends Processor> processors, int ram,
|
||||
Iterable<? extends Volume> volumes, Predicate<Image> supportsImage) {
|
||||
Map<String, String> userMetadata, Iterable<? extends Processor> processors, int ram,
|
||||
Iterable<? extends Volume> volumes, Predicate<Image> supportsImage) {
|
||||
super(ComputeType.HARDWARE, providerId, name, id, location, uri, userMetadata);
|
||||
Iterables.addAll(this.processors, checkNotNull(processors, "processors"));
|
||||
this.processors = ImmutableList.copyOf(checkNotNull(processors, "processors"));
|
||||
this.ram = ram;
|
||||
Iterables.addAll(this.volumes, checkNotNull(volumes, "volumes"));
|
||||
this.volumes = ImmutableList.copyOf(checkNotNull(volumes, "volumes"));
|
||||
this.supportsImage = supportsImage;
|
||||
}
|
||||
|
||||
|
@ -95,8 +94,8 @@ public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
|
|||
public int compareTo(ResourceMetadata<ComputeType> that) {
|
||||
if (that instanceof Hardware) {
|
||||
Hardware thatHardware = Hardware.class.cast(that);
|
||||
return ComparisonChain.start().compare(getCoresAndSpeed(this), getCoresAndSpeed(thatHardware)).compare(
|
||||
this.getRam(), thatHardware.getRam()).compare(getSpace(this), getSpace(thatHardware)).result();
|
||||
return ComparisonChain.start().compare(getCoresAndSpeed(this), getCoresAndSpeed(thatHardware))
|
||||
.compare(this.getRam(), thatHardware.getRam()).compare(getSpace(this), getSpace(thatHardware)).result();
|
||||
} else {
|
||||
return super.compareTo(that);
|
||||
}
|
||||
|
@ -108,7 +107,7 @@ public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() + ", processors="
|
||||
+ processors + ", ram=" + ram + ", volumes=" + volumes + ", supportsImage=" + supportsImage + "]";
|
||||
+ processors + ", ram=" + ram + ", volumes=" + volumes + ", supportsImage=" + supportsImage + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,14 +41,13 @@ public class ImageImpl extends ComputeMetadataImpl implements Image {
|
|||
private static final long serialVersionUID = 7856744554191025307L;
|
||||
|
||||
private final OperatingSystem operatingSystem;
|
||||
|
||||
private final String version;
|
||||
private final String description;
|
||||
private final Credentials defaultCredentials;
|
||||
|
||||
public ImageImpl(String providerId, String name, String id, Location location, URI uri,
|
||||
Map<String, String> userMetadata, OperatingSystem operatingSystem, String description,
|
||||
@Nullable String version, @Nullable Credentials defaultCredentials) {
|
||||
Map<String, String> userMetadata, OperatingSystem operatingSystem, String description,
|
||||
@Nullable String version, @Nullable Credentials defaultCredentials) {
|
||||
super(ComputeType.IMAGE, providerId, name, id, location, uri, userMetadata);
|
||||
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem");
|
||||
this.version = version;
|
||||
|
@ -91,7 +90,9 @@ public class ImageImpl extends ComputeMetadataImpl implements Image {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getId() + ", name=" + getName() + ", operatingSystem=" + operatingSystem + ", description="
|
||||
+ description + ", version=" + version + ", location=" + getLocation() + "]";
|
||||
+ description + ", version=" + version + ", location=" + getLocation() + ", loginUser="
|
||||
+ ((defaultCredentials != null) ? defaultCredentials.identity : null) + ", userMetadata="
|
||||
+ getUserMetadata() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,39 +35,43 @@ import org.jclouds.compute.domain.OperatingSystem;
|
|||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.domain.Location;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
* @author Ivan Meredith
|
||||
*/
|
||||
public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadata {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 7924307572338157887L;
|
||||
|
||||
private final NodeState state;
|
||||
private final Set<String> publicAddresses = Sets.newLinkedHashSet();
|
||||
private final Set<String> privateAddresses = Sets.newLinkedHashSet();
|
||||
private final Set<String> publicAddresses;
|
||||
private final Set<String> privateAddresses;
|
||||
@Nullable
|
||||
private final Credentials credentials;
|
||||
@Nullable
|
||||
private final String tag;
|
||||
@Nullable
|
||||
private final String imageId;
|
||||
@Nullable
|
||||
private final Hardware hardware;
|
||||
@Nullable
|
||||
private final OperatingSystem os;
|
||||
|
||||
public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri,
|
||||
Map<String, String> userMetadata, @Nullable String tag, @Nullable Hardware hardware,
|
||||
@Nullable String imageId, @Nullable OperatingSystem os, NodeState state, Iterable<String> publicAddresses,
|
||||
Iterable<String> privateAddresses, @Nullable Credentials credentials) {
|
||||
Map<String, String> userMetadata, @Nullable String tag, @Nullable Hardware hardware, @Nullable String imageId,
|
||||
@Nullable OperatingSystem os, NodeState state, Iterable<String> publicAddresses,
|
||||
Iterable<String> privateAddresses, @Nullable Credentials credentials) {
|
||||
super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata);
|
||||
this.tag = tag;
|
||||
this.hardware = hardware;
|
||||
this.imageId = imageId;
|
||||
this.os = os;
|
||||
this.state = checkNotNull(state, "state");
|
||||
Iterables.addAll(this.publicAddresses, checkNotNull(publicAddresses, "publicAddresses"));
|
||||
Iterables.addAll(this.privateAddresses, checkNotNull(privateAddresses, "privateAddresses"));
|
||||
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
|
||||
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
|
||||
this.credentials = credentials;
|
||||
}
|
||||
|
||||
|
@ -138,10 +142,10 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + getId() + ", providerId=" + getProviderId() + ", tag=" + getTag() + ", name=" + getName()
|
||||
+ ", location=" + getLocation() + ", uri=" + getUri() + ", imageId=" + getImageId() + ", os="
|
||||
+ getOperatingSystem() + ", userMetadata=" + getUserMetadata() + ", state=" + getState()
|
||||
+ ", privateAddresses=" + privateAddresses + ", publicAddresses=" + publicAddresses + ", hardware="
|
||||
+ getHardware() + "]";
|
||||
+ ", location=" + getLocation() + ", uri=" + getUri() + ", imageId=" + getImageId() + ", os="
|
||||
+ getOperatingSystem() + ", state=" + getState() + ", privateAddresses=" + privateAddresses
|
||||
+ ", publicAddresses=" + publicAddresses + ", hardware=" + getHardware() + ", loginUser="
|
||||
+ ((credentials != null) ? credentials.identity : null) + ", userMetadata=" + getUserMetadata() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -154,6 +158,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
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 + ((credentials == null) ? 0 : credentials.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -196,6 +201,11 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
|
|||
return false;
|
||||
} else if (!os.equals(other.os))
|
||||
return false;
|
||||
if (credentials == null) {
|
||||
if (other.credentials != null)
|
||||
return false;
|
||||
} else if (!credentials.equals(other.credentials))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
|
@ -114,9 +115,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
protected TemplateOptions options;
|
||||
|
||||
@Inject
|
||||
protected TemplateBuilderImpl(Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
|
||||
Supplier<Set<? extends Hardware>> hardwares, Supplier<Location> defaultLocation2,
|
||||
Provider<TemplateOptions> optionsProvider, @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||
protected TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
|
||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
|
||||
Supplier<Location> defaultLocation2, Provider<TemplateOptions> optionsProvider,
|
||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||
this.locations = locations;
|
||||
this.images = images;
|
||||
this.hardwares = hardwares;
|
||||
|
@ -126,13 +128,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
}
|
||||
|
||||
/**
|
||||
* If the current location id is null, then we don't care where to launch a
|
||||
* node.
|
||||
* If the current location id is null, then we don't care where to launch a node.
|
||||
*
|
||||
* If the input location is null, then the data isn't location sensitive
|
||||
*
|
||||
* If the input location is a parent of the specified location, then we are
|
||||
* ok.
|
||||
* If the input location is a parent of the specified location, then we are ok.
|
||||
*/
|
||||
private final Predicate<ComputeMetadata> locationPredicate = new Predicate<ComputeMetadata>() {
|
||||
@Override
|
||||
|
@ -180,6 +180,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
return returnVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "osFamily(" + osFamily + ")";
|
||||
}
|
||||
};
|
||||
|
||||
private final Predicate<OperatingSystem> osNamePredicate = new Predicate<OperatingSystem>() {
|
||||
|
@ -637,7 +641,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return locationPredicate.toString();
|
||||
return "location(" + location + ")";
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -21,7 +21,20 @@ package org.jclouds.compute.internal;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.installNewCredentials;
|
||||
import static com.google.common.base.Predicates.and;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.collect.Iterables.concat;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.transform;
|
||||
import static com.google.common.collect.Maps.newHashMap;
|
||||
import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||
import static com.google.common.collect.Sets.filter;
|
||||
import static com.google.common.collect.Sets.newHashSet;
|
||||
import static com.google.common.collect.Sets.newLinkedHashSet;
|
||||
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
||||
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
||||
import static org.jclouds.compute.predicates.NodePredicates.all;
|
||||
import static org.jclouds.concurrent.FutureIterables.awaitCompletion;
|
||||
import static org.jclouds.concurrent.FutureIterables.transformParallel;
|
||||
|
||||
|
@ -41,6 +54,7 @@ import javax.inject.Provider;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.RunNodesException;
|
||||
|
@ -49,11 +63,11 @@ import org.jclouds.compute.domain.ComputeMetadata;
|
|||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.options.RunScriptOptions;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.predicates.NodePredicates;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
|
@ -74,12 +88,7 @@ import org.jclouds.util.Utils;
|
|||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -93,6 +102,7 @@ public class BaseComputeService implements ComputeService {
|
|||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected final ComputeServiceContext context;
|
||||
protected final Map<String, Credentials> credentialStore;
|
||||
protected final Supplier<Set<? extends Image>> images;
|
||||
protected final Supplier<Set<? extends Hardware>> hardwareProfiles;
|
||||
protected final Supplier<Set<? extends Location>> locations;
|
||||
|
@ -110,16 +120,18 @@ public class BaseComputeService implements ComputeService {
|
|||
protected final ExecutorService executor;
|
||||
|
||||
@Inject
|
||||
protected BaseComputeService(ComputeServiceContext context, Supplier<Set<? extends Image>> images,
|
||||
Supplier<Set<? extends Hardware>> hardwareProfiles, Supplier<Set<? extends Location>> locations,
|
||||
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||
DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||
Provider<TemplateOptions> templateOptionsProvider,
|
||||
protected BaseComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||
@Memoized Supplier<Set<? extends Image>> images,
|
||||
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
||||
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
|
||||
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated, ComputeUtils utils, Timeouts timeouts,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||
this.context = checkNotNull(context, "context");
|
||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||
this.images = checkNotNull(images, "images");
|
||||
this.hardwareProfiles = checkNotNull(hardwareProfiles, "hardwareProfiles");
|
||||
this.locations = checkNotNull(locations, "locations");
|
||||
|
@ -159,10 +171,13 @@ public class BaseComputeService implements ComputeService {
|
|||
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) hardwareProfile(%s) options(%s)", count,
|
||||
count > 1 ? "s" : "", tag, template.getLocation().getId(), template.getImage().getId(), template
|
||||
.getHardware().getId(), template.getOptions());
|
||||
Set<NodeMetadata> nodes = Sets.newHashSet();
|
||||
Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
|
||||
Set<NodeMetadata> nodes = newHashSet();
|
||||
Map<NodeMetadata, Exception> badNodes = newLinkedHashMap();
|
||||
Map<?, Future<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count, template, nodes, badNodes);
|
||||
Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger, "starting nodes");
|
||||
for (NodeMetadata node : concat(nodes, badNodes.keySet()))
|
||||
if (node.getCredentials() != null)
|
||||
credentialStore.put("node/" + node.getId(), node.getCredentials());
|
||||
if (executionExceptions.size() > 0 || badNodes.size() > 0) {
|
||||
throw new RunNodesException(tag, count, template, nodes, executionExceptions, badNodes);
|
||||
}
|
||||
|
@ -199,7 +214,7 @@ public class BaseComputeService implements ComputeService {
|
|||
@Override
|
||||
public boolean apply(String input) {
|
||||
try {
|
||||
NodeMetadata md = destroyNodeStrategy.execute(id);
|
||||
NodeMetadata md = destroyNodeStrategy.destroyNode(id);
|
||||
if (md != null)
|
||||
node.set(md);
|
||||
return true;
|
||||
|
@ -211,6 +226,8 @@ public class BaseComputeService implements ComputeService {
|
|||
|
||||
}, timeouts.nodeRunning, 1000, TimeUnit.MILLISECONDS);
|
||||
boolean successful = tester.apply(id) && (node.get() == null || nodeTerminated.apply(node.get()));
|
||||
if (successful)
|
||||
credentialStore.remove("node/" + id);
|
||||
logger.debug("<< destroyed node(%s) success(%s)", id, successful);
|
||||
}
|
||||
|
||||
|
@ -220,7 +237,7 @@ public class BaseComputeService implements ComputeService {
|
|||
@Override
|
||||
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
|
||||
logger.debug(">> destroying nodes matching(%s)", filter);
|
||||
Set<NodeMetadata> set = Sets.newLinkedHashSet(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
|
||||
Set<NodeMetadata> set = newLinkedHashSet(transformParallel(nodesMatchingFilterAndNotTerminated(filter),
|
||||
new Function<NodeMetadata, Future<NodeMetadata>>() {
|
||||
|
||||
// TODO make an async interface instead of re-wrapping
|
||||
|
@ -243,7 +260,7 @@ public class BaseComputeService implements ComputeService {
|
|||
}
|
||||
|
||||
private Iterable<? extends NodeMetadata> nodesMatchingFilterAndNotTerminated(Predicate<NodeMetadata> filter) {
|
||||
return Iterables.filter(detailsOnAllNodes(), Predicates.and(filter, Predicates.not(NodePredicates.TERMINATED)));
|
||||
return filter(detailsOnAllNodes(), and(filter, not(TERMINATED)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,7 +269,7 @@ public class BaseComputeService implements ComputeService {
|
|||
@Override
|
||||
public Set<ComputeMetadata> listNodes() {
|
||||
logger.debug(">> listing nodes");
|
||||
Set<ComputeMetadata> set = Sets.newLinkedHashSet(listNodesStrategy.list());
|
||||
Set<ComputeMetadata> set = newLinkedHashSet(listNodesStrategy.listNodes());
|
||||
logger.debug("<< list(%d)", set.size());
|
||||
return set;
|
||||
}
|
||||
|
@ -264,7 +281,7 @@ public class BaseComputeService implements ComputeService {
|
|||
public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter) {
|
||||
checkNotNull(filter, "filter");
|
||||
logger.debug(">> listing node details matching(%s)", filter);
|
||||
Set<NodeMetadata> set = Sets.newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(filter));
|
||||
Set<NodeMetadata> set = newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(filter));
|
||||
logger.debug("<< list(%d)", set.size());
|
||||
return set;
|
||||
}
|
||||
|
@ -307,7 +324,7 @@ public class BaseComputeService implements ComputeService {
|
|||
@Override
|
||||
public NodeMetadata getNodeMetadata(String id) {
|
||||
checkNotNull(id, "id");
|
||||
return getNodeMetadataStrategy.execute(id);
|
||||
return getNodeMetadataStrategy.getNode(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -317,7 +334,7 @@ public class BaseComputeService implements ComputeService {
|
|||
public void rebootNode(String id) {
|
||||
checkNotNull(id, "id");
|
||||
logger.debug(">> rebooting node(%s)", id);
|
||||
NodeMetadata node = rebootNodeStrategy.execute(id);
|
||||
NodeMetadata node = rebootNodeStrategy.rebootNode(id);
|
||||
boolean successful = nodeRunning.apply(node);
|
||||
logger.debug("<< rebooted node(%s) success(%s)", id, successful);
|
||||
}
|
||||
|
@ -333,7 +350,7 @@ public class BaseComputeService implements ComputeService {
|
|||
@Override
|
||||
public Future<Void> apply(NodeMetadata from) {
|
||||
rebootNode(from.getId());
|
||||
return Futures.immediateFuture(null);
|
||||
return immediateFuture(null);
|
||||
}
|
||||
|
||||
}, executor, null, logger, "rebooting nodes");
|
||||
|
@ -362,11 +379,11 @@ public class BaseComputeService implements ComputeService {
|
|||
if (options.getTaskName() == null)
|
||||
options.nameTask("jclouds-script-" + System.currentTimeMillis());
|
||||
|
||||
Iterable<? extends NodeMetadata> nodes = Iterables.filter(detailsOnAllNodes(), filter);
|
||||
Iterable<? extends NodeMetadata> nodes = filter(detailsOnAllNodes(), filter);
|
||||
|
||||
final Map<NodeMetadata, ExecResponse> execs = Maps.newHashMap();
|
||||
final Map<NodeMetadata, Future<Void>> responses = Maps.newHashMap();
|
||||
final Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
|
||||
final Map<NodeMetadata, ExecResponse> execs = newHashMap();
|
||||
final Map<NodeMetadata, Future<Void>> responses = newHashMap();
|
||||
final Map<NodeMetadata, Exception> badNodes = newLinkedHashMap();
|
||||
nodes = filterNodesWhoCanRunScripts(nodes, badNodes, options.getOverrideCredentials());
|
||||
|
||||
for (final NodeMetadata node : nodes) {
|
||||
|
@ -399,14 +416,14 @@ public class BaseComputeService implements ComputeService {
|
|||
|
||||
private Iterable<? extends NodeMetadata> filterNodesWhoCanRunScripts(Iterable<? extends NodeMetadata> nodes,
|
||||
final Map<NodeMetadata, Exception> badNodes, final @Nullable Credentials overridingCredentials) {
|
||||
nodes = Iterables.filter(Iterables.transform(nodes, new Function<NodeMetadata, NodeMetadata>() {
|
||||
nodes = filter(transform(nodes, new Function<NodeMetadata, NodeMetadata>() {
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(NodeMetadata node) {
|
||||
try {
|
||||
checkArgument(node.getPublicAddresses().size() > 0, "no public ip addresses on node: " + node);
|
||||
if (overridingCredentials != null) {
|
||||
node = installNewCredentials(node, overridingCredentials);
|
||||
node = NodeMetadataBuilder.fromNodeMetadata(node).credentials(overridingCredentials).build();
|
||||
} else {
|
||||
checkNotNull(node.getCredentials(), "If the default credentials need to be used, they can't be null");
|
||||
checkNotNull(node.getCredentials().identity, "Account name for ssh authentication must be "
|
||||
|
@ -420,12 +437,12 @@ public class BaseComputeService implements ComputeService {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
}), Predicates.notNull());
|
||||
}), notNull());
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private Set<? extends NodeMetadata> detailsOnAllNodes() {
|
||||
return Sets.newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(NodePredicates.all()));
|
||||
return newLinkedHashSet(listNodesStrategy.listDetailsOnNodesMatching(all()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.jclouds.compute.internal;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
@ -29,6 +31,7 @@ import org.jclouds.compute.ComputeService;
|
|||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.LoadBalancerService;
|
||||
import org.jclouds.compute.Utils;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
||||
/**
|
||||
|
@ -40,11 +43,13 @@ public class ComputeServiceContextImpl<S, A> implements ComputeServiceContext {
|
|||
private final LoadBalancerService loadBalancerService;
|
||||
private final RestContext<S, A> providerSpecificContext;
|
||||
private final Utils utils;
|
||||
private final Map<String, Credentials> credentialStore;
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@Inject
|
||||
public ComputeServiceContextImpl(ComputeService computeService, Utils utils,
|
||||
@Nullable LoadBalancerService loadBalancerService, RestContext providerSpecificContext) {
|
||||
public ComputeServiceContextImpl(ComputeService computeService, Map<String, Credentials> credentialStore,
|
||||
Utils utils, @Nullable LoadBalancerService loadBalancerService, RestContext providerSpecificContext) {
|
||||
this.credentialStore = credentialStore;
|
||||
this.utils = utils;
|
||||
this.providerSpecificContext = providerSpecificContext;
|
||||
this.computeService = checkNotNull(computeService, "computeService");
|
||||
|
@ -55,7 +60,7 @@ public class ComputeServiceContextImpl<S, A> implements ComputeServiceContext {
|
|||
return computeService;
|
||||
}
|
||||
|
||||
@SuppressWarnings( { "unchecked", "hiding" })
|
||||
@SuppressWarnings({ "unchecked", "hiding" })
|
||||
@Override
|
||||
public <S, A> RestContext<S, A> getProviderSpecificContext() {
|
||||
return (RestContext<S, A>) providerSpecificContext;
|
||||
|
@ -94,4 +99,14 @@ public class ComputeServiceContextImpl<S, A> implements ComputeServiceContext {
|
|||
public boolean equals(Object obj) {
|
||||
return providerSpecificContext.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Credentials> getCredentialStore() {
|
||||
return credentialStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Credentials> credentialStore() {
|
||||
return credentialStore;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.compute.domain.Image;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -38,6 +40,24 @@ import com.google.common.collect.Sets;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class ImagePredicates {
|
||||
private static final class Is64BitPredicate implements Predicate<Image> {
|
||||
@Override
|
||||
public boolean apply(Image image) {
|
||||
return image.getOperatingSystem().is64Bit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "is64Bit()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return (obj instanceof Is64BitPredicate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* evaluates true if the Image
|
||||
*
|
||||
|
@ -87,17 +107,7 @@ public class ImagePredicates {
|
|||
* return true if this is a 64bit image.
|
||||
*/
|
||||
public static Predicate<Image> is64Bit() {
|
||||
return new Predicate<Image>() {
|
||||
@Override
|
||||
public boolean apply(Image image) {
|
||||
return image.getOperatingSystem().is64Bit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "is64Bit()";
|
||||
}
|
||||
};
|
||||
return new Is64BitPredicate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,19 @@ import org.jclouds.compute.domain.Template;
|
|||
*/
|
||||
public interface AddNodeWithTagStrategy {
|
||||
|
||||
NodeMetadata execute(String tag, String name, Template template);
|
||||
/**
|
||||
* create a node given the name and template parameters such as imageid, hardwareid, and
|
||||
* locationid.
|
||||
*
|
||||
* @param tag
|
||||
* tag supplied by the user
|
||||
* @param name
|
||||
* supplied by {@link RunNodesAndAddToSetStrategy } and must have the tag encoded into
|
||||
* it.
|
||||
* @param template
|
||||
* supplied by the user
|
||||
* @return NodeMetadata from the new object, most likely in some pending state.
|
||||
*/
|
||||
NodeMetadata addNodeWithTag(String tag, String name, Template template);
|
||||
|
||||
}
|
|
@ -32,6 +32,6 @@ public interface DestroyNodeStrategy {
|
|||
*
|
||||
* @return null if the node wasn't found
|
||||
*/
|
||||
NodeMetadata execute(String id);
|
||||
NodeMetadata destroyNode(String id);
|
||||
|
||||
}
|
|
@ -28,6 +28,6 @@ import org.jclouds.compute.domain.NodeMetadata;
|
|||
*/
|
||||
public interface GetNodeMetadataStrategy {
|
||||
|
||||
NodeMetadata execute(String id);
|
||||
NodeMetadata getNode(String id);
|
||||
|
||||
}
|
|
@ -30,7 +30,7 @@ import com.google.common.base.Predicate;
|
|||
*/
|
||||
public interface ListNodesStrategy {
|
||||
|
||||
Iterable<? extends ComputeMetadata> list();
|
||||
Iterable<? extends ComputeMetadata> listNodes();
|
||||
|
||||
Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter);
|
||||
|
||||
|
|
|
@ -28,6 +28,6 @@ import org.jclouds.compute.domain.NodeMetadata;
|
|||
*/
|
||||
public interface RebootNodeStrategy {
|
||||
|
||||
NodeMetadata execute(String id);
|
||||
NodeMetadata rebootNode(String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
/**
|
||||
*
|
||||
* 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.strategy.impl;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.predicates.NodePredicates;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class AdaptingComputeServiceStrategies<N, H, I, L> implements AddNodeWithTagStrategy, DestroyNodeStrategy,
|
||||
GetNodeMetadataStrategy, ListNodesStrategy, RebootNodeStrategy {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Map<String, Credentials> credentialStore;
|
||||
private final ComputeServiceAdapter<N, H, I, L> client;
|
||||
private final Function<N, NodeMetadata> nodeMetadataAdapter;
|
||||
|
||||
@Inject
|
||||
public AdaptingComputeServiceStrategies(Map<String, Credentials> credentialStore,
|
||||
ComputeServiceAdapter<N, H, I, L> client, Function<N, NodeMetadata> nodeMetadataAdapter) {
|
||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.nodeMetadataAdapter = checkNotNull(nodeMetadataAdapter, "nodeMetadataAdapter");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends ComputeMetadata> listNodes() {
|
||||
return listDetailsOnNodesMatching(NodePredicates.all());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
return Iterables.filter(Iterables.transform(client.listNodes(), nodeMetadataAdapter), filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata getNode(String id) {
|
||||
N node = client.getNode(id);
|
||||
return node == null ? null : nodeMetadataAdapter.apply(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata rebootNode(String id) {
|
||||
|
||||
NodeMetadata node = getNode(id);
|
||||
if (node == null || node.getState() == NodeState.TERMINATED)
|
||||
return node;
|
||||
|
||||
logger.debug(">> rebooting node(%s)", id);
|
||||
client.rebootNode(id);
|
||||
logger.debug("<< rebooted node(%s)", id);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata destroyNode(String id) {
|
||||
|
||||
NodeMetadata node = getNode(id);
|
||||
if (node == null)
|
||||
return node;
|
||||
|
||||
logger.debug(">> destroying node(%s)", id);
|
||||
client.destroyNode(id);
|
||||
logger.debug("<< destroyed node(%s)", id);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public NodeMetadata addNodeWithTag(String tag, String name, Template template) {
|
||||
checkState(tag != null, "tag (that which groups identical nodes together) must be specified");
|
||||
checkState(name != null && name.indexOf(tag) != -1, "name should have %s encoded into it", tag);
|
||||
|
||||
logger.debug(">> instantiating node location(%s) name(%s) image(%s) hardware(%s)",
|
||||
template.getLocation().getId(), name, template.getImage().getProviderId(), template.getHardware()
|
||||
.getProviderId());
|
||||
|
||||
N from = client.runNodeWithTagAndNameAndStoreCredentials(tag, name, template, credentialStore);
|
||||
NodeMetadata node = nodeMetadataAdapter.apply(from);
|
||||
logger.debug("<< instantiated node(%s)", node.getId());
|
||||
return node;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue