mirror of https://github.com/apache/jclouds.git
refactored compute provider implementation
This commit is contained in:
parent
7f02bd8929
commit
49b88183d2
|
@ -53,6 +53,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
|
||||||
import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.concurrent.Futures;
|
import org.jclouds.concurrent.Futures;
|
||||||
import org.jclouds.crypto.Crypto;
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
@ -81,9 +82,9 @@ public class AtmosAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
@Inject
|
@Inject
|
||||||
AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
AtmosAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||||
Supplier<Set<? extends Location>> locations, AtmosStorageAsyncClient async, AtmosStorageClient sync,
|
@Memoized Supplier<Set<? extends Location>> locations, AtmosStorageAsyncClient async,
|
||||||
ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
|
AtmosStorageClient sync, ObjectToBlob object2Blob, ObjectToBlobMetadata object2BlobMd,
|
||||||
BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
BlobToObject blob2Object, BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
||||||
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
|
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
|
||||||
BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
||||||
super(context, blobUtils, service, defaultLocation, locations);
|
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.internal.BaseBlobStore;
|
||||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.crypto.Crypto;
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
@ -68,7 +69,7 @@ public class AtmosBlobStore extends BaseBlobStore {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AtmosBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
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,
|
ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
|
||||||
BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
BlobStoreListOptionsToListOptions container2ContainerListOptions,
|
||||||
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
|
DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
|
@ -72,6 +73,7 @@ public class AtmosBlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Memoized
|
||||||
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
||||||
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ import static org.jclouds.aws.ec2.util.EC2Utils.parseHandle;
|
||||||
import static org.jclouds.util.Utils.checkNotEmpty;
|
import static org.jclouds.util.Utils.checkNotEmpty;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -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.KeyPair;
|
||||||
import org.jclouds.aws.ec2.domain.PlacementGroup;
|
import org.jclouds.aws.ec2.domain.PlacementGroup;
|
||||||
import org.jclouds.aws.ec2.domain.PlacementGroup.State;
|
import org.jclouds.aws.ec2.domain.PlacementGroup.State;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -77,8 +78,8 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected EC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
protected EC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||||
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> sizes,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||||
Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
||||||
|
@ -106,8 +107,8 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
logger.debug(">> deleting placementGroup(%s)", group);
|
logger.debug(">> deleting placementGroup(%s)", group);
|
||||||
try {
|
try {
|
||||||
ec2Client.getPlacementGroupServices().deletePlacementGroupInRegion(region, group);
|
ec2Client.getPlacementGroupServices().deletePlacementGroupInRegion(region, group);
|
||||||
checkState(placementGroupDeleted.apply(new PlacementGroup(region, group, "cluster", State.PENDING)),
|
checkState(placementGroupDeleted.apply(new PlacementGroup(region, group, "cluster", State.PENDING)), String
|
||||||
String.format("placementGroup region(%s) name(%s) failed to delete", region, group));
|
.format("placementGroup region(%s) name(%s) failed to delete", region, group));
|
||||||
placementGroupMap.remove(new RegionAndName(region, tag));
|
placementGroupMap.remove(new RegionAndName(region, tag));
|
||||||
logger.debug("<< deleted placementGroup(%s)", group);
|
logger.debug("<< deleted placementGroup(%s)", group);
|
||||||
} catch (AWSResponseException e) {
|
} catch (AWSResponseException e) {
|
||||||
|
|
|
@ -19,35 +19,19 @@
|
||||||
|
|
||||||
package org.jclouds.aws.ec2.compute.config;
|
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.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.AMZN_LINUX;
|
||||||
import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
||||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
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.EC2ComputeService;
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
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.compute.strategy.EC2DestroyLoadBalancerStrategy;
|
import org.jclouds.aws.ec2.compute.strategy.EC2DestroyLoadBalancerStrategy;
|
||||||
import org.jclouds.aws.ec2.compute.strategy.EC2DestroyNodeStrategy;
|
import org.jclouds.aws.ec2.compute.strategy.EC2DestroyNodeStrategy;
|
||||||
import org.jclouds.aws.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
|
import org.jclouds.aws.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
|
||||||
|
@ -56,27 +40,15 @@ import org.jclouds.aws.ec2.compute.strategy.EC2LoadBalanceNodesStrategy;
|
||||||
import org.jclouds.aws.ec2.compute.strategy.EC2RebootNodeStrategy;
|
import org.jclouds.aws.ec2.compute.strategy.EC2RebootNodeStrategy;
|
||||||
import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy;
|
import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy;
|
||||||
import org.jclouds.aws.ec2.compute.suppliers.EC2HardwareSupplier;
|
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.aws.ec2.compute.suppliers.EC2LocationSupplier;
|
||||||
import org.jclouds.aws.ec2.compute.suppliers.RegionAndNameToImageSupplier;
|
import org.jclouds.aws.ec2.compute.suppliers.RegionAndNameToImageSupplier;
|
||||||
import org.jclouds.aws.ec2.domain.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.aws.suppliers.DefaultLocationSupplier;
|
|
||||||
import org.jclouds.compute.ComputeService;
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
|
||||||
import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy;
|
import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
|
@ -84,27 +56,14 @@ import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
import org.jclouds.compute.strategy.LoadBalanceNodesStrategy;
|
import org.jclouds.compute.strategy.LoadBalanceNodesStrategy;
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||||
import org.jclouds.domain.Credentials;
|
|
||||||
import org.jclouds.domain.Location;
|
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.annotations.Provider;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
|
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.Supplier;
|
||||||
import com.google.common.base.Suppliers;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.MapMaker;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Scopes;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link ComputeServiceContext}; requires {@link EC2ComputeService} bound.
|
* Configures the {@link ComputeServiceContext}; requires {@link EC2ComputeService} bound.
|
||||||
|
@ -112,78 +71,10 @@ import com.google.inject.TypeLiteral;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class EC2ComputeServiceContextModule extends BaseComputeServiceContextModule {
|
public class EC2ComputeServiceContextModule extends BaseComputeServiceContextModule {
|
||||||
|
|
||||||
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
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new ComputeServiceTimeoutsModule());
|
install(new EC2ComputeServiceDependenciesModule());
|
||||||
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
|
super.configure();
|
||||||
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);
|
|
||||||
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) + "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -197,56 +88,6 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
|
||||||
return template.osFamily(AMZN_LINUX).os64Bit(true);
|
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 Map<RegionAndName, Image> provideImageMap(RegionAndIdToImage regionAndIdToImage) {
|
|
||||||
return new MapMaker().makeComputingMap(regionAndIdToImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Supplier<Map<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
|
protected Supplier<Map<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
|
||||||
|
@ -261,30 +102,68 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
|
protected void bindLoadBalancerService() {
|
||||||
Supplier<Map<RegionAndName, ? extends Image>> map = injector.getInstance(Key
|
bind(LoadBalanceNodesStrategy.class).to(EC2LoadBalanceNodesStrategy.class);
|
||||||
.get(new TypeLiteral<Supplier<Map<RegionAndName, ? extends Image>>>() {
|
bind(DestroyLoadBalancerStrategy.class).to(EC2DestroyLoadBalancerStrategy.class);
|
||||||
}));
|
|
||||||
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
|
@Override
|
||||||
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
|
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() {
|
||||||
return injector.getInstance(EC2LocationSupplier.class);
|
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
|
@Override
|
||||||
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
|
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||||
return injector.getInstance(EC2HardwareSupplier.class);
|
return EC2DestroyNodeStrategy.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Location> supplyDefaultLocation(Injector injector, Supplier<Set<? extends Location>> locations) {
|
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||||
return injector.getInstance(DefaultLocationSupplier.class);
|
return EC2GetNodeMetadataStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 ListNodesStrategy> defineListNodesStrategy() {
|
||||||
|
return EC2ListNodesStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||||
|
return EC2RebootNodeStrategy.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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -35,6 +35,7 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.Image.Architecture;
|
import org.jclouds.aws.ec2.domain.Image.Architecture;
|
||||||
import org.jclouds.aws.ec2.domain.Image.ImageType;
|
import org.jclouds.aws.ec2.domain.Image.ImageType;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.ImageBuilder;
|
import org.jclouds.compute.domain.ImageBuilder;
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
|
@ -91,7 +92,8 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
|
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.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
|
||||||
this.locations = checkNotNull(locations, "locations");
|
this.locations = checkNotNull(locations, "locations");
|
||||||
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
|
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
|
||||||
|
|
|
@ -24,9 +24,9 @@ import static org.jclouds.util.Utils.nullSafeSet;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -37,6 +37,7 @@ import org.jclouds.aws.ec2.domain.InstanceState;
|
||||||
import org.jclouds.aws.ec2.domain.RootDeviceType;
|
import org.jclouds.aws.ec2.domain.RootDeviceType;
|
||||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||||
import org.jclouds.aws.ec2.domain.RunningInstance.EbsBlockDevice;
|
import org.jclouds.aws.ec2.domain.RunningInstance.EbsBlockDevice;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.HardwareBuilder;
|
import org.jclouds.compute.domain.HardwareBuilder;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -74,7 +75,7 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
||||||
@Inject
|
@Inject
|
||||||
RunningInstanceToNodeMetadata(Map<InstanceState, NodeState> instanceToNodeState,
|
RunningInstanceToNodeMetadata(Map<InstanceState, NodeState> instanceToNodeState,
|
||||||
Map<String, Credentials> credentialStore, Map<RegionAndName, Image> instanceToImage,
|
Map<String, Credentials> credentialStore, Map<RegionAndName, Image> instanceToImage,
|
||||||
Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Hardware>> hardware) {
|
@Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Hardware>> hardware) {
|
||||||
this.locations = checkNotNull(locations, "locations");
|
this.locations = checkNotNull(locations, "locations");
|
||||||
this.hardware = checkNotNull(hardware, "hardware");
|
this.hardware = checkNotNull(hardware, "hardware");
|
||||||
this.instanceToImage = checkNotNull(instanceToImage, "instanceToImage");
|
this.instanceToImage = checkNotNull(instanceToImage, "instanceToImage");
|
||||||
|
@ -123,8 +124,9 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Volume apply(Entry<String, EbsBlockDevice> from) {
|
public Volume apply(Entry<String, EbsBlockDevice> from) {
|
||||||
return new VolumeImpl(from.getValue().getVolumeId(), Volume.Type.SAN, null, from.getKey(), instance
|
return new VolumeImpl(from.getValue().getVolumeId(), Volume.Type.SAN, null, from.getKey(),
|
||||||
.getRootDeviceName() != null && instance.getRootDeviceName().equals(from.getKey()), true);
|
instance.getRootDeviceName() != null
|
||||||
|
&& instance.getRootDeviceName().equals(from.getKey()), true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -158,7 +160,9 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
logger.debug("no tag parsed from %s's groups: %s", instance.getId(), instance.getGroupIds());
|
logger.debug("no tag parsed from %s's groups: %s", instance.getId(), instance.getGroupIds());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
logger.debug("too many groups match %s; %s's groups: %s", "jclouds#", instance.getId(), instance.getGroupIds());
|
logger
|
||||||
|
.debug("too many groups match %s; %s's groups: %s", "jclouds#", instance.getId(), instance
|
||||||
|
.getGroupIds());
|
||||||
}
|
}
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||||
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
|
@ -50,9 +51,9 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
||||||
private final Map<RegionAndName, Image> imageMap;
|
private final Map<RegionAndName, Image> imageMap;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected EC2TemplateBuilderImpl(Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
|
protected EC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
|
||||||
Supplier<Set<? extends Hardware>> sizes, Supplier<Location> defaultLocation,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||||
Provider<TemplateOptions> optionsProvider,
|
Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider,
|
||||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Map<RegionAndName, Image> imageMap) {
|
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Map<RegionAndName, Image> imageMap) {
|
||||||
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
|
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
|
||||||
this.imageMap = imageMap;
|
this.imageMap = imageMap;
|
||||||
|
@ -86,7 +87,8 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
||||||
if (imageId != null) {
|
if (imageId != null) {
|
||||||
String[] regionName = imageId.split("/");
|
String[] regionName = imageId.split("/");
|
||||||
checkArgument(regionName.length == 2,
|
checkArgument(regionName.length == 2,
|
||||||
"amazon image ids must include the region ( ex. us-east-1/ami-7ea24a17 ) you specified: " + imageId);
|
"amazon image ids must include the region ( ex. us-east-1/ami-7ea24a17 ) you specified: "
|
||||||
|
+ imageId);
|
||||||
RegionAndName key = new RegionAndName(regionName[0], regionName[1]);
|
RegionAndName key = new RegionAndName(regionName[0], regionName[1]);
|
||||||
try {
|
try {
|
||||||
return imageMap.get(key);
|
return imageMap.get(key);
|
||||||
|
|
|
@ -41,6 +41,7 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
@ -66,7 +67,7 @@ public class EC2HardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
||||||
private final String providerName;
|
private final String providerName;
|
||||||
|
|
||||||
@Inject
|
@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) {
|
@Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) {
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
this.ccAmis = ccAmis;
|
this.ccAmis = ccAmis;
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -55,6 +55,7 @@ import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.concurrent.Futures;
|
import org.jclouds.concurrent.Futures;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
@ -85,7 +86,7 @@ public class S3AsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
@Inject
|
@Inject
|
||||||
S3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
S3AsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||||
Supplier<Set<? extends Location>> locations, S3AsyncClient async, S3Client sync,
|
@Memoized Supplier<Set<? extends Location>> locations, S3AsyncClient async, S3Client sync,
|
||||||
BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions,
|
BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions,
|
||||||
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
|
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
|
||||||
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
|
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
|
||||||
|
|
|
@ -49,6 +49,7 @@ import org.jclouds.blobstore.internal.BaseBlobStore;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
@ -75,10 +76,11 @@ public class S3BlobStore extends BaseBlobStore {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
S3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
S3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
||||||
Supplier<Set<? extends Location>> locations, S3Client sync, BucketToResourceMetadata bucket2ResourceMd,
|
@Memoized Supplier<Set<? extends Location>> locations, S3Client sync,
|
||||||
ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList,
|
BucketToResourceMetadata bucket2ResourceMd, ContainerToBucketListOptions container2BucketListOptions,
|
||||||
ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
|
BucketToResourceList bucket2ResourceList, ObjectToBlob object2Blob,
|
||||||
ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd,
|
||||||
|
Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
||||||
super(context, blobUtils, defaultLocation, locations);
|
super(context, blobUtils, defaultLocation, locations);
|
||||||
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
||||||
this.sync = checkNotNull(sync, "sync");
|
this.sync = checkNotNull(sync, "sync");
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
|
@ -73,6 +74,7 @@ public class S3BlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Memoized
|
||||||
Supplier<Set<? extends Location>> provideLocations(@Region Set<String> regions, @Provider String providerName) {
|
Supplier<Set<? extends Location>> provideLocations(@Region Set<String> regions, @Provider String providerName) {
|
||||||
Set<Location> locations = Sets.newHashSet();
|
Set<Location> locations = Sets.newHashSet();
|
||||||
Location s3 = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
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.StorageMetadata;
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
import org.jclouds.blobstore.domain.StorageType;
|
||||||
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
|
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ public class BucketToResourceMetadata implements Function<BucketMetadata, Storag
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BucketToResourceMetadata(S3Client client, Supplier<Set<? extends Location>> locations) {
|
BucketToResourceMetadata(S3Client client, @Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.onlyLocation = locations.get().size() == 1 ? Iterables.get(locations.get(), 0) : null;
|
this.onlyLocation = locations.get().size() == 1 ? Iterables.get(locations.get(), 0) : null;
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
|
|
|
@ -26,6 +26,7 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.aws.Region;
|
import org.jclouds.aws.Region;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ public class DefaultLocationSupplier implements Supplier<Location> {
|
||||||
private final Supplier<Set<? extends Location>> set;
|
private final Supplier<Set<? extends Location>> set;
|
||||||
|
|
||||||
@Inject
|
@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.region = region;
|
||||||
this.set = set;
|
this.set = set;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ 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_4xlarge;
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_xlarge;
|
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.compute.domain.EC2HardwareBuilder.t1_micro;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -58,7 +59,6 @@ import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests compute service specifically to EC2.
|
* Tests compute service specifically to EC2.
|
||||||
|
@ -99,8 +99,8 @@ public class EC2ComputeServiceTest {
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
assert CC1_4XLARGE.equals(template.getHardware()) : format(
|
assert CC1_4XLARGE.equals(template.getHardware()) : format(
|
||||||
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(),
|
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), String
|
||||||
String.valueOf(template.getHardware()));
|
.valueOf(template.getHardware()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,13 +111,13 @@ public class EC2ComputeServiceTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTemplateChoiceForInstanceByAttributes() throws Exception {
|
public void testTemplateChoiceForInstanceByAttributes() throws Exception {
|
||||||
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest()
|
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest().locationId(
|
||||||
.locationId("us-east-1").build();
|
"us-east-1").build();
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
assert CC1_4XLARGE.equals(template.getHardware()) : format(
|
assert CC1_4XLARGE.equals(template.getHardware()) : format(
|
||||||
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE,
|
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE, String
|
||||||
String.valueOf(template.getHardware()));
|
.valueOf(template.getHardware()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,13 +130,13 @@ public class EC2ComputeServiceTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception {
|
public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception {
|
||||||
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest()
|
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest().locationId(
|
||||||
.locationId("us-east-1").build();
|
"us-east-1").build();
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
assert !m2_xlarge().build().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",
|
"Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", String
|
||||||
String.valueOf(template.getHardware()));
|
.valueOf(template.getHardware()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -148,10 +148,9 @@ public class EC2ComputeServiceTest {
|
||||||
|
|
||||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||||
|
|
||||||
Image image = new ImageBuilder().providerId("cc-image").name("image").id("us-east-1/cc-image")
|
Image image = new ImageBuilder().providerId("cc-image").name("image").id("us-east-1/cc-image").location(location)
|
||||||
.location(location)
|
.operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true)).description(
|
||||||
.operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true))
|
"description").version("1.0").defaultCredentials(new Credentials("root", null)).build();
|
||||||
.description("description").version("1.0").defaultCredentials(new Credentials("root", null)).build();
|
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
|
@ -159,9 +158,9 @@ public class EC2ComputeServiceTest {
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
||||||
.<Image> of(image));
|
.<Image> of(image));
|
||||||
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
.<Hardware> of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large().build(), m1_small()
|
.<Hardware> of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large().build(),
|
||||||
.build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(), m2_4xlarge().build(),
|
m1_small().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(),
|
||||||
CC1_4XLARGE));
|
m2_4xlarge().build(), CC1_4XLARGE));
|
||||||
|
|
||||||
return new TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(location), optionsProvider,
|
return new TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(location), optionsProvider,
|
||||||
templateBuilderProvider) {
|
templateBuilderProvider) {
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m1_small().build()));
|
// .<Hardware> of(m1_small().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -97,7 +97,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
//
|
//
|
||||||
|
@ -180,7 +180,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m1_small().build()));
|
// .<Hardware> of(m1_small().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -192,7 +192,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(region));
|
// .<Location> of(region));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
//
|
//
|
||||||
|
@ -264,7 +264,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m1_small().build()));
|
// .<Hardware> of(m1_small().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -276,7 +276,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(region));
|
// .<Location> of(region));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
//
|
//
|
||||||
|
@ -339,7 +339,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m1_small().build()));
|
// .<Hardware> of(m1_small().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -350,7 +350,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(region));
|
// .<Location> of(region));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
//
|
//
|
||||||
|
@ -426,9 +426,9 @@ public class CredentialsForInstanceTest {
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -487,9 +487,9 @@ public class CredentialsForInstanceTest {
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -549,9 +549,9 @@ public class CredentialsForInstanceTest {
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -616,9 +616,9 @@ public class CredentialsForInstanceTest {
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -677,9 +677,9 @@ public class CredentialsForInstanceTest {
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -736,7 +736,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -748,7 +748,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
//
|
//
|
||||||
|
@ -810,7 +810,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap = createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||||
// RunningInstance instance = createMock(RunningInstance.class);
|
// RunningInstance instance = createMock(RunningInstance.class);
|
||||||
|
@ -822,7 +822,7 @@ public class CredentialsForInstanceTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
//
|
//
|
||||||
|
|
|
@ -26,7 +26,7 @@ import java.net.UnknownHostException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule;
|
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceDependenciesModule;
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||||
import org.jclouds.aws.ec2.domain.InstanceState;
|
import org.jclouds.aws.ec2.domain.InstanceState;
|
||||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
import org.jclouds.aws.ec2.domain.RunningInstance;
|
||||||
|
@ -61,7 +61,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
public void testAllStatesCovered() {
|
public void testAllStatesCovered() {
|
||||||
|
|
||||||
for (InstanceState state : InstanceState.values()) {
|
for (InstanceState state : InstanceState.values()) {
|
||||||
assert EC2ComputeServiceContextModule.instanceToNodeState.containsKey(state) : state;
|
assert EC2ComputeServiceDependenciesModule.instanceToNodeState.containsKey(state) : state;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,29 +73,27 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
throws UnknownHostException {
|
throws UnknownHostException {
|
||||||
Credentials creds = new Credentials("root", "abdce");
|
Credentials creds = new Credentials("root", "abdce");
|
||||||
|
|
||||||
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(),
|
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet
|
||||||
ImmutableSet.<Location> of(), ImmutableSet.<Image> of(),
|
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of(
|
||||||
ImmutableMap.<String, Credentials> of("us-east-1/i-9slweygo", creds));
|
"us-east-1/i-9slweygo", creds));
|
||||||
|
|
||||||
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
||||||
|
|
||||||
assertEquals(parser.apply(server),
|
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).publicAddresses(
|
||||||
new NodeMetadataBuilder().state(NodeState.TERMINATED).publicAddresses(ImmutableSet.<String> of())
|
ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.128.207.5")).tag("NOTAG-i-9slweygo")
|
||||||
.privateAddresses(ImmutableSet.of("10.128.207.5")).tag("NOTAG-i-9slweygo").credentials(creds)
|
.credentials(creds).imageId("us-east-1/ami-25CB1213").id("us-east-1/i-9slweygo")
|
||||||
.imageId("us-east-1/ami-25CB1213").id("us-east-1/i-9slweygo").providerId("i-9slweygo").build());
|
.providerId("i-9slweygo").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationNotFound() throws UnknownHostException {
|
public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationNotFound() throws UnknownHostException {
|
||||||
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(),
|
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet
|
||||||
ImmutableSet.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
|
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
|
||||||
|
|
||||||
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).publicAddresses(
|
||||||
parser.apply(server),
|
ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.128.207.5")).tag("NOTAG-i-9slweygo")
|
||||||
new NodeMetadataBuilder().state(NodeState.TERMINATED).publicAddresses(ImmutableSet.<String> of())
|
|
||||||
.privateAddresses(ImmutableSet.of("10.128.207.5")).tag("NOTAG-i-9slweygo")
|
|
||||||
.imageId("us-east-1/ami-25CB1213").id("us-east-1/i-9slweygo").providerId("i-9slweygo").build());
|
.imageId("us-east-1/ami-25CB1213").id("us-east-1/i-9slweygo").providerId("i-9slweygo").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,11 +104,9 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
|
|
||||||
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).privateAddresses(
|
||||||
parser.apply(server),
|
ImmutableSet.of("10.128.207.5")).tag("NOTAG-i-9slweygo").imageId("us-east-1/ami-25CB1213").id(
|
||||||
new NodeMetadataBuilder().state(NodeState.TERMINATED).privateAddresses(ImmutableSet.of("10.128.207.5"))
|
"us-east-1/i-9slweygo").providerId("i-9slweygo").location(provider).build());
|
||||||
.tag("NOTAG-i-9slweygo").imageId("us-east-1/ami-25CB1213").id("us-east-1/i-9slweygo")
|
|
||||||
.providerId("i-9slweygo").location(provider).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -120,13 +116,8 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
|
|
||||||
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).privateAddresses(
|
||||||
parser.apply(server),
|
ImmutableSet.of("10.128.207.5")).tag("NOTAG-i-9slweygo").imageId("us-east-1/ami-25CB1213")
|
||||||
new NodeMetadataBuilder()
|
|
||||||
.state(NodeState.TERMINATED)
|
|
||||||
.privateAddresses(ImmutableSet.of("10.128.207.5"))
|
|
||||||
.tag("NOTAG-i-9slweygo")
|
|
||||||
.imageId("us-east-1/ami-25CB1213")
|
|
||||||
.operatingSystem(
|
.operatingSystem(
|
||||||
new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("9.10").arch("paravirtual")
|
new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("9.10").arch("paravirtual")
|
||||||
.description("nebula/ubuntu-karmic").is64Bit(true).build()).id("us-east-1/i-9slweygo")
|
.description("nebula/ubuntu-karmic").is64Bit(true).build()).id("us-east-1/i-9slweygo")
|
||||||
|
@ -135,36 +126,30 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationFound() throws UnknownHostException {
|
public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationFound() throws UnknownHostException {
|
||||||
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()),
|
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet
|
||||||
ImmutableSet.of(provider), ImageParserTest.convertImages("/ec2/nova_images.xml"),
|
.of(provider), ImageParserTest.convertImages("/ec2/nova_images.xml"), ImmutableMap
|
||||||
ImmutableMap.<String, Credentials> of());
|
.<String, Credentials> of());
|
||||||
|
|
||||||
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
RunningInstance server = firstInstanceFromResource("/ec2/describe_instances_nova.xml");
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).privateAddresses(
|
||||||
parser.apply(server),
|
ImmutableSet.of("10.128.207.5")).tag("NOTAG-i-9slweygo").imageId("us-east-1/ami-25CB1213").hardware(
|
||||||
new NodeMetadataBuilder()
|
m1_small().build()).operatingSystem(
|
||||||
.state(NodeState.TERMINATED)
|
new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("9.10").arch("paravirtual").description(
|
||||||
.privateAddresses(ImmutableSet.of("10.128.207.5"))
|
"nebula/ubuntu-karmic").is64Bit(true).build()).id("us-east-1/i-9slweygo").providerId(
|
||||||
.tag("NOTAG-i-9slweygo")
|
"i-9slweygo").location(provider).build());
|
||||||
.imageId("us-east-1/ami-25CB1213")
|
|
||||||
.hardware(m1_small().build())
|
|
||||||
.operatingSystem(
|
|
||||||
new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("9.10").arch("paravirtual")
|
|
||||||
.description("nebula/ubuntu-karmic").is64Bit(true).build()).id("us-east-1/i-9slweygo")
|
|
||||||
.providerId("i-9slweygo").location(provider).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RunningInstance firstInstanceFromResource(String resource) {
|
protected RunningInstance firstInstanceFromResource(String resource) {
|
||||||
RunningInstance server = Iterables.get(
|
RunningInstance server = Iterables.get(Iterables.get(DescribeInstancesResponseHandlerTest
|
||||||
Iterables.get(DescribeInstancesResponseHandlerTest.parseRunningInstances(resource), 0), 0);
|
.parseRunningInstances(resource), 0), 0);
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,
|
protected RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,
|
||||||
final ImmutableSet<Location> locations, Set<org.jclouds.compute.domain.Image> images,
|
final ImmutableSet<Location> locations, Set<org.jclouds.compute.domain.Image> images,
|
||||||
Map<String, Credentials> credentialStore) {
|
Map<String, Credentials> credentialStore) {
|
||||||
Map<InstanceState, NodeState> instanceToNodeState = EC2ComputeServiceContextModule.instanceToNodeState;
|
Map<InstanceState, NodeState> instanceToNodeState = EC2ComputeServiceDependenciesModule.instanceToNodeState;
|
||||||
|
|
||||||
Map<RegionAndName, Image> instanceToImage = Maps.uniqueIndex(images, new Function<Image, RegionAndName>() {
|
Map<RegionAndName, Image> instanceToImage = Maps.uniqueIndex(images, new Function<Image, RegionAndName>() {
|
||||||
|
|
||||||
|
@ -207,7 +192,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m1_small().build()));
|
// .<Hardware> of(m1_small().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -221,7 +206,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
|
@ -313,7 +298,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m1_small().build()));
|
// .<Hardware> of(m1_small().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -327,7 +312,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(region));
|
// .<Location> of(region));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
|
@ -406,7 +391,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m1_small().build()));
|
// .<Hardware> of(m1_small().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -420,7 +405,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(region));
|
// .<Location> of(region));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
|
@ -489,7 +474,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m1_small().build()));
|
// .<Hardware> of(m1_small().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -502,7 +487,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
// Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(region));
|
// .<Location> of(region));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
|
@ -585,10 +570,10 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -651,10 +636,10 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -719,10 +704,10 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -794,10 +779,10 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -861,10 +846,10 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -926,7 +911,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -940,7 +925,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
|
@ -1006,7 +991,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
// Map<RegionAndName, KeyPair> credentialsMap = createMock(Map.class);
|
||||||
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
// ConcurrentMap<RegionAndName, org.jclouds.compute.domain.Image> imageMap =
|
||||||
// createMock(ConcurrentMap.class);
|
// createMock(ConcurrentMap.class);
|
||||||
// Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
// @Memoized Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Hardware> of(m2_4xlarge().build()));
|
// .<Hardware> of(m2_4xlarge().build()));
|
||||||
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider =
|
||||||
|
@ -1021,7 +1006,7 @@ public class RunningInstanceToNodeMetadataTest {
|
||||||
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||||
//
|
//
|
||||||
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||||
// Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
// @Memoized Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>
|
||||||
// ofInstance(ImmutableSet
|
// ofInstance(ImmutableSet
|
||||||
// .<Location> of(location));
|
// .<Location> of(location));
|
||||||
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||||
|
|
|
@ -34,6 +34,7 @@ import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||||
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
|
@ -67,9 +68,9 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EC2TemplateBuilderImpl createTemplateBuilder(final Image knownImage,
|
protected EC2TemplateBuilderImpl createTemplateBuilder(final Image knownImage,
|
||||||
Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
|
@Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Image>> images,
|
||||||
Supplier<Set<? extends Hardware>> sizes, Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
@Memoized Supplier<Set<? extends Hardware>> sizes, Location defaultLocation,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider) {
|
Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) {
|
||||||
final RegionAndName knownRegionAndName = new RegionAndName("region", "ami");
|
final RegionAndName knownRegionAndName = new RegionAndName("region", "ami");
|
||||||
|
|
||||||
ConcurrentMap<RegionAndName, Image> imageMap = new MapMaker()
|
ConcurrentMap<RegionAndName, Image> imageMap = new MapMaker()
|
||||||
|
|
|
@ -53,6 +53,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
|
||||||
import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.concurrent.Futures;
|
import org.jclouds.concurrent.Futures;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
@ -79,7 +80,7 @@ public class AzureAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
@Inject
|
@Inject
|
||||||
AzureAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
AzureAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||||
Supplier<Set<? extends Location>> locations, AzureBlobAsyncClient async,
|
@Memoized Supplier<Set<? extends Location>> locations, AzureBlobAsyncClient async,
|
||||||
ContainerToResourceMetadata container2ResourceMd,
|
ContainerToResourceMetadata container2ResourceMd,
|
||||||
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
||||||
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
|
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
|
||||||
|
|
|
@ -47,6 +47,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
|
||||||
import org.jclouds.blobstore.internal.BaseBlobStore;
|
import org.jclouds.blobstore.internal.BaseBlobStore;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ public class AzureBlobStore extends BaseBlobStore {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AzureBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
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,
|
ContainerToResourceMetadata container2ResourceMd,
|
||||||
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
ListOptionsToListBlobsOptions blobStore2AzureContainerListOptions,
|
||||||
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
|
ListBlobsResponseToResourceList azure2BlobStoreResourceList, AzureBlobToBlob azureBlob2Blob,
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
|
@ -71,6 +72,7 @@ public class AzureBlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Memoized
|
||||||
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
||||||
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ import org.jclouds.blobstore.options.GetOptions;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
|
import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.crypto.Crypto;
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
|
@ -127,7 +128,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
||||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobUtils blobUtils,
|
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||||
Supplier<Set<? extends Location>> locations) {
|
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
super(context, blobUtils, service, defaultLocation, locations);
|
super(context, blobUtils, service, defaultLocation, locations);
|
||||||
this.blobFactory = blobFactory;
|
this.blobFactory = blobFactory;
|
||||||
this.dateService = dateService;
|
this.dateService = dateService;
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.jclouds.blobstore.TransientBlobRequestSigner;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
|
@ -81,6 +82,7 @@ public class TransientBlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Memoized
|
||||||
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
||||||
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
|
import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
|
||||||
@Inject
|
@Inject
|
||||||
protected BaseAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
protected BaseAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||||
Supplier<Set<? extends Location>> locations) {
|
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
this.context = checkNotNull(context, "context");
|
this.context = checkNotNull(context, "context");
|
||||||
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
||||||
this.service = checkNotNull(service, "service");
|
this.service = checkNotNull(service, "service");
|
||||||
|
@ -267,5 +268,4 @@ public abstract class BaseAsyncBlobStore implements AsyncBlobStore {
|
||||||
|
|
||||||
protected abstract boolean deleteAndVerifyContainerGone(String container);
|
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.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
|
import org.jclouds.blobstore.util.internal.BlobUtilsImpl;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ public abstract class BaseBlobStore implements BlobStore {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected BaseBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
protected BaseBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
||||||
Supplier<Set<? extends Location>> locations) {
|
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
this.context = checkNotNull(context, "context");
|
this.context = checkNotNull(context, "context");
|
||||||
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
this.blobUtils = checkNotNull(blobUtils, "blobUtils");
|
||||||
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
|
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
|
||||||
|
|
|
@ -26,9 +26,12 @@ import java.util.Properties;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.jclouds.PropertiesBuilder;
|
||||||
|
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,8 +44,8 @@ public class ComputeServiceContextFactory {
|
||||||
private final RestContextFactory contextFactory;
|
private final RestContextFactory contextFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes with the default properties built-in to jclouds. This is
|
* Initializes with the default properties built-in to jclouds. This is typically stored in the
|
||||||
* typically stored in the classpath resource {@code rest.properties}
|
* classpath resource {@code rest.properties}
|
||||||
*
|
*
|
||||||
* @see RestContextFactory#getPropertiesFromResource
|
* @see RestContextFactory#getPropertiesFromResource
|
||||||
*/
|
*/
|
||||||
|
@ -59,8 +62,7 @@ public class ComputeServiceContextFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Uses the supplied RestContextFactory to create
|
* Uses the supplied RestContextFactory to create {@link ComputeServiceContext}s
|
||||||
* {@link ComputeServiceContext}s
|
|
||||||
*/
|
*/
|
||||||
public ComputeServiceContextFactory(RestContextFactory restContextFactory) {
|
public ComputeServiceContextFactory(RestContextFactory restContextFactory) {
|
||||||
this.contextFactory = restContextFactory;
|
this.contextFactory = restContextFactory;
|
||||||
|
@ -104,8 +106,7 @@ public class ComputeServiceContextFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see RestContextFactory#createContextBuilder(String, String,String,
|
* @see RestContextFactory#createContextBuilder(String, String,String, Iterable)
|
||||||
* Iterable)
|
|
||||||
*/
|
*/
|
||||||
public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential,
|
public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential,
|
||||||
Iterable<? extends Module> modules) {
|
Iterable<? extends Module> modules) {
|
||||||
|
@ -115,8 +116,7 @@ public class ComputeServiceContextFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see RestContextFactory#createContextBuilder(String, String,String,
|
* @see RestContextFactory#createContextBuilder(String, String,String, Iterable, Properties)
|
||||||
* Iterable, Properties)
|
|
||||||
*/
|
*/
|
||||||
public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential,
|
public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential,
|
||||||
Iterable<? extends Module> modules, Properties overrides) {
|
Iterable<? extends Module> modules, Properties overrides) {
|
||||||
|
@ -144,4 +144,17 @@ public class ComputeServiceContextFactory {
|
||||||
return buildContextUnwrappingExceptions(builder);
|
return buildContextUnwrappingExceptions(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ComputeServiceContext createStandaloneContext(StandaloneComputeServiceContextModule contextModule) {
|
||||||
|
return createStandaloneContext(contextModule, ImmutableSet.<Module> of());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static ComputeServiceContext createStandaloneContext(StandaloneComputeServiceContextModule contextModule,
|
||||||
|
Iterable<Module> modules) {
|
||||||
|
return new ComputeServiceContextFactory().createContext(RestContextFactory
|
||||||
|
.<ComputeService, ComputeService> contextSpec("standalone", "standalone", "1", "standalone", null,
|
||||||
|
(Class) null, (Class) null, PropertiesBuilder.class,
|
||||||
|
(Class) StandaloneComputeServiceContextBuilder.class, ImmutableSet.<Module> builder().add(
|
||||||
|
contextModule).addAll(modules).build()));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -17,41 +17,39 @@
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jclouds.compute.stub;
|
package org.jclouds.compute;
|
||||||
|
|
||||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.jclouds.PropertiesBuilder;
|
import org.jclouds.compute.config.StandaloneComputeServiceClientModule;
|
||||||
|
|
||||||
|
import com.google.inject.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds properties used in stub compute services
|
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class StubComputeServicePropertiesBuilder extends PropertiesBuilder {
|
public class StandaloneComputeServiceContextBuilder extends
|
||||||
@Override
|
ComputeServiceContextBuilder<ComputeService, ComputeService> {
|
||||||
protected Properties defaultProperties() {
|
|
||||||
Properties properties = super.defaultProperties();
|
public StandaloneComputeServiceContextBuilder(Properties props) {
|
||||||
properties.setProperty(PROPERTY_ENDPOINT, "http://localhost/stub");
|
super(ComputeService.class, ComputeService.class, props);
|
||||||
|
if (!properties.containsKey(PROPERTY_ENDPOINT))
|
||||||
|
properties.setProperty(PROPERTY_ENDPOINT, "standalone");
|
||||||
|
if (!properties.containsKey(PROPERTY_API_VERSION))
|
||||||
properties.setProperty(PROPERTY_API_VERSION, "1");
|
properties.setProperty(PROPERTY_API_VERSION, "1");
|
||||||
|
if (!properties.containsKey(PROPERTY_IDENTITY))
|
||||||
properties.setProperty(PROPERTY_IDENTITY, System.getProperty("user.name"));
|
properties.setProperty(PROPERTY_IDENTITY, System.getProperty("user.name"));
|
||||||
return properties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StubComputeServicePropertiesBuilder(Properties properties) {
|
@Override
|
||||||
super(properties);
|
protected void addClientModule(List<Module> modules) {
|
||||||
|
modules.add(new StandaloneComputeServiceClientModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
public StubComputeServicePropertiesBuilder withCredentials(String id, String secret) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StubComputeServicePropertiesBuilder withEndpoint(URI endpoint) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -26,13 +26,23 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
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.ComputeMetadata;
|
||||||
import org.jclouds.compute.domain.Image;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
|
import org.jclouds.compute.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 org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
|
@ -46,27 +56,152 @@ import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.Scopes;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.util.Providers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
install(new ComputeServiceTimeoutsModule());
|
||||||
|
bindRunNodesAndAddToSetStrategy(defineRunNodesAndAddToSetStrategy());
|
||||||
|
bindAddNodeWithTagStrategy(defineAddNodeWithTagStrategy());
|
||||||
|
bindListNodesStrategy(defineListNodesStrategy());
|
||||||
|
bindGetNodeMetadataStrategy(defineGetNodeMetadataStrategy());
|
||||||
|
bindRebootNodeStrategy(defineRebootNodeStrategy());
|
||||||
|
bindDestroyNodeStrategy(defineDestroyNodeStrategy());
|
||||||
|
bindImageSupplier(defineImageSupplier());
|
||||||
|
bindLocationSupplier(defineLocationSupplier());
|
||||||
|
bindHardwareSupplier(defineHardwareSupplier());
|
||||||
|
bindDefaultLocationSupplier(defineDefaultLocationSupplier());
|
||||||
|
bindLoadBalancerService();
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector);
|
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() {
|
||||||
|
return EncodeTagIntoNameRunNodesAndAddToSetStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector);
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
|
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 bindLoadBalancerService() {
|
||||||
|
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null)).in(Scopes.SINGLETON);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By default allows you to use a static set of locations bound to Set<? extends Location>
|
* By default allows you to use a static set of locations bound to Set<? extends Location>
|
||||||
*/
|
*/
|
||||||
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
|
@Singleton
|
||||||
Set<? extends Location> locations = injector.getInstance(Key.get(new TypeLiteral<Set<? extends Location>>() {
|
public static class LocationSupplier implements Supplier<Set<? extends Location>> {
|
||||||
}));
|
private final Set<? extends Location> locations;
|
||||||
return Suppliers.<Set<? extends Location>> ofInstance(locations);
|
|
||||||
|
@Inject
|
||||||
|
LocationSupplier(Set<? extends Location> locations) {
|
||||||
|
this.locations = locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<? extends Location> get() {
|
||||||
|
return locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class DefaultLocationSupplier implements Supplier<Location> {
|
||||||
|
private final Supplier<Set<? extends Location>> locations;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
DefaultLocationSupplier(@Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
|
this.locations = locations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location get() {
|
||||||
|
return Iterables.find(locations.get(), new Predicate<Location>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Location input) {
|
||||||
|
return input.getScope() == LocationScope.ZONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -86,7 +221,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@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>>() {
|
return Suppliers.compose(new Function<Set<? extends Image>, Map<String, ? extends Image>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,20 +241,22 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Memoized
|
||||||
protected Supplier<Set<? extends Image>> supplyImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
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,
|
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Image>>(authException, seconds,
|
||||||
new Supplier<Set<? extends Image>>() {
|
new Supplier<Set<? extends Image>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends Image> get() {
|
public Set<? extends Image> get() {
|
||||||
return getSourceImageSupplier(injector).get();
|
return imageSupplier.get();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@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>>() {
|
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, ? extends Location>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,20 +276,21 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Memoized
|
||||||
protected Supplier<Set<? extends Location>> supplyLocationCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
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,
|
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Location>>(authException, seconds,
|
||||||
new Supplier<Set<? extends Location>>() {
|
new Supplier<Set<? extends Location>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends Location> get() {
|
public Set<? extends Location> get() {
|
||||||
return getSourceLocationSupplier(injector).get();
|
return locationSupplier.get();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@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>>() {
|
return Suppliers.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -172,13 +310,14 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Memoized
|
||||||
protected Supplier<Set<? extends Hardware>> supplySizeCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
|
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,
|
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Hardware>>(authException, seconds,
|
||||||
new Supplier<Set<? extends Hardware>>() {
|
new Supplier<Set<? extends Hardware>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends Hardware> get() {
|
public Set<? extends Hardware> get() {
|
||||||
return getSourceSizeSupplier(injector).get();
|
return hardwareSupplier.get();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -194,25 +333,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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -17,21 +17,19 @@
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jclouds.compute.stub.config;
|
package org.jclouds.compute.config;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeService;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
@RequiresHttp
|
@RequiresHttp
|
||||||
public class StubComputeServiceClientModule extends RestClientModule<ConcurrentMap, ConcurrentMap> {
|
public class StandaloneComputeServiceClientModule extends RestClientModule<ComputeService, ComputeService> {
|
||||||
|
|
||||||
public StubComputeServiceClientModule() {
|
public StandaloneComputeServiceClientModule() {
|
||||||
super(ConcurrentMap.class, ConcurrentMap.class);
|
super(ComputeService.class, ComputeService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -0,0 +1,40 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.ComputeService;
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
|
|
||||||
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public abstract class StandaloneComputeServiceContextModule extends BaseComputeServiceContextModule {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
super.configure();
|
||||||
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
|
}).to(new TypeLiteral<ComputeServiceContextImpl<ComputeService, ComputeService>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,6 +38,7 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -114,9 +115,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
protected TemplateOptions options;
|
protected TemplateOptions options;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected TemplateBuilderImpl(Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
|
protected TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
|
||||||
Supplier<Set<? extends Hardware>> hardwares, Supplier<Location> defaultLocation2,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
|
||||||
Provider<TemplateOptions> optionsProvider, @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
Supplier<Location> defaultLocation2, Provider<TemplateOptions> optionsProvider,
|
||||||
|
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
this.images = images;
|
this.images = images;
|
||||||
this.hardwares = hardwares;
|
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
|
* If the current location id is null, then we don't care where to launch a node.
|
||||||
* node.
|
|
||||||
*
|
*
|
||||||
* If the input location is null, then the data isn't location sensitive
|
* 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
|
* If the input location is a parent of the specified location, then we are ok.
|
||||||
* ok.
|
|
||||||
*/
|
*/
|
||||||
private final Predicate<ComputeMetadata> locationPredicate = new Predicate<ComputeMetadata>() {
|
private final Predicate<ComputeMetadata> locationPredicate = new Predicate<ComputeMetadata>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -395,16 +395,16 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
};
|
};
|
||||||
static final Ordering<Image> DEFAULT_IMAGE_ORDERING = new Ordering<Image>() {
|
static final Ordering<Image> DEFAULT_IMAGE_ORDERING = new Ordering<Image>() {
|
||||||
public int compare(Image left, Image right) {
|
public int compare(Image left, Image right) {
|
||||||
return ComparisonChain.start()
|
return ComparisonChain.start().compare(left.getName(), right.getName(),
|
||||||
.compare(left.getName(), right.getName(), Ordering.<String> natural().nullsLast())
|
Ordering.<String> natural().nullsLast()).compare(left.getVersion(), right.getVersion(),
|
||||||
.compare(left.getVersion(), right.getVersion(), Ordering.<String> natural().nullsLast())
|
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getName(),
|
||||||
.compare(left.getOperatingSystem().getName(), right.getOperatingSystem().getName(),//
|
right.getOperatingSystem().getName(),//
|
||||||
Ordering.<String> natural().nullsLast())
|
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getVersion(),
|
||||||
.compare(left.getOperatingSystem().getVersion(), right.getOperatingSystem().getVersion(),//
|
right.getOperatingSystem().getVersion(),//
|
||||||
Ordering.<String> natural().nullsLast())
|
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getDescription(),
|
||||||
.compare(left.getOperatingSystem().getDescription(), right.getOperatingSystem().getDescription(),//
|
right.getOperatingSystem().getDescription(),//
|
||||||
Ordering.<String> natural().nullsLast())
|
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getArch(),
|
||||||
.compare(left.getOperatingSystem().getArch(), right.getOperatingSystem().getArch()).result();
|
right.getOperatingSystem().getArch()).result();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -826,8 +826,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean nothingChangedExceptOptions() {
|
boolean nothingChangedExceptOptions() {
|
||||||
return osFamily == null && location == null && imageId == null && hardwareId == null && osName == null
|
return osFamily == null && location == null && imageId == null && hardwareId == null && osName == null
|
||||||
&& osDescription == null && imageVersion == null && osVersion == null && osArch == null && os64Bit == null
|
&& osDescription == null && imageVersion == null && osVersion == null && osArch == null
|
||||||
&& imageName == null && imageDescription == null && minCores == 0 && minRam == 0 && !biggest && !fastest;
|
&& os64Bit == null && imageName == null && imageDescription == null && minCores == 0 && minRam == 0
|
||||||
|
&& !biggest && !fastest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -841,10 +842,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription="
|
return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription="
|
||||||
+ imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion + ", location=" + location
|
+ imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion + ", location="
|
||||||
+ ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" + osName
|
+ location + ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName="
|
||||||
+ ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch + ", os64Bit="
|
+ osName + ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch
|
||||||
+ os64Bit + ", hardwareId=" + hardwareId + "]";
|
+ ", os64Bit=" + os64Bit + ", hardwareId=" + hardwareId + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -54,6 +54,7 @@ import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.ComputeService;
|
import org.jclouds.compute.ComputeService;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.RunNodesException;
|
import org.jclouds.compute.RunNodesException;
|
||||||
|
@ -120,8 +121,9 @@ public class BaseComputeService implements ComputeService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected BaseComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
protected BaseComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||||
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> hardwareProfiles,
|
@Memoized Supplier<Set<? extends Image>> images,
|
||||||
Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
||||||
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
||||||
|
@ -390,8 +392,8 @@ public class BaseComputeService implements ComputeService {
|
||||||
@Override
|
@Override
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
try {
|
try {
|
||||||
ExecResponse response = utils.runScriptOnNode(node,
|
ExecResponse response = utils.runScriptOnNode(node, Statements.exec(Utils.toStringAndClose(runScript
|
||||||
Statements.exec(Utils.toStringAndClose(runScript.getInput())), options);
|
.getInput())), options);
|
||||||
if (response != null)
|
if (response != null)
|
||||||
execs.put(node, response);
|
execs.put(node, response);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -21,10 +21,8 @@ package org.jclouds.compute.stub;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContextBuilder;
|
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
|
||||||
import org.jclouds.compute.stub.config.StubComputeServiceClientModule;
|
|
||||||
import org.jclouds.compute.stub.config.StubComputeServiceContextModule;
|
import org.jclouds.compute.stub.config.StubComputeServiceContextModule;
|
||||||
|
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
@ -33,11 +31,10 @@ import com.google.inject.Module;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
public class StubComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder {
|
||||||
public class StubComputeServiceContextBuilder extends ComputeServiceContextBuilder<ConcurrentMap, ConcurrentMap> {
|
|
||||||
|
|
||||||
public StubComputeServiceContextBuilder(Properties props) {
|
public StubComputeServiceContextBuilder(Properties props) {
|
||||||
super(ConcurrentMap.class, ConcurrentMap.class, props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -45,9 +42,4 @@ public class StubComputeServiceContextBuilder extends ComputeServiceContextBuild
|
||||||
modules.add(new StubComputeServiceContextModule());
|
modules.add(new StubComputeServiceContextModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void addClientModule(List<Module> modules) {
|
|
||||||
modules.add(new StubComputeServiceClientModule());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,381 +19,72 @@
|
||||||
|
|
||||||
package org.jclouds.compute.stub.config;
|
package org.jclouds.compute.stub.config;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Provider;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
|
||||||
import org.jclouds.compute.LoadBalancerService;
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
|
||||||
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
|
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.ImageBuilder;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
|
||||||
import org.jclouds.compute.domain.Processor;
|
|
||||||
import org.jclouds.compute.domain.Template;
|
|
||||||
import org.jclouds.compute.domain.Volume;
|
|
||||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
|
||||||
import org.jclouds.compute.predicates.NodePredicates;
|
|
||||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
|
import org.jclouds.compute.stub.config.StubComputeServiceDependenciesModule.StubAddNodeWithTagStrategy;
|
||||||
|
import org.jclouds.compute.stub.config.StubComputeServiceDependenciesModule.StubDestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.stub.config.StubComputeServiceDependenciesModule.StubGetNodeMetadataStrategy;
|
||||||
|
import org.jclouds.compute.stub.config.StubComputeServiceDependenciesModule.StubHardwareSupplier;
|
||||||
|
import org.jclouds.compute.stub.config.StubComputeServiceDependenciesModule.StubImageSupplier;
|
||||||
|
import org.jclouds.compute.stub.config.StubComputeServiceDependenciesModule.StubListNodesStrategy;
|
||||||
|
import org.jclouds.compute.stub.config.StubComputeServiceDependenciesModule.StubRebootNodeStrategy;
|
||||||
import org.jclouds.concurrent.SingleThreaded;
|
import org.jclouds.concurrent.SingleThreaded;
|
||||||
import org.jclouds.domain.Credentials;
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.domain.LocationScope;
|
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
|
||||||
import org.jclouds.net.IPSocket;
|
|
||||||
import org.jclouds.predicates.SocketOpen;
|
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Suppliers;
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
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;
|
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@SingleThreaded
|
@SingleThreaded
|
||||||
public class StubComputeServiceContextModule extends BaseComputeServiceContextModule {
|
public class StubComputeServiceContextModule extends StandaloneComputeServiceContextModule {
|
||||||
// STUB STUFF STATIC SO MULTIPLE CONTEXTS CAN SEE IT
|
|
||||||
private static final AtomicInteger nodeIds = new AtomicInteger(0);
|
|
||||||
private static final ConcurrentMap<String, NodeMetadata> nodes = new ConcurrentHashMap<String, NodeMetadata>();
|
|
||||||
private static final ExecutorService service = Executors.newCachedThreadPool();
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
ConcurrentMap<String, NodeMetadata> provideNodes() {
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Named("NODE_ID")
|
|
||||||
Integer provideNodeId() {
|
|
||||||
return nodeIds.incrementAndGet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
@Named("PUBLIC_IP_PREFIX")
|
|
||||||
String publicIpPrefix() {
|
|
||||||
return "144.175.1.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
@Named("PRIVATE_IP_PREFIX")
|
|
||||||
String privateIpPrefix() {
|
|
||||||
return "10.1.1.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
@Named("PASSWORD_PREFIX")
|
|
||||||
String passwordPrefix() {
|
|
||||||
return "password";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
SocketOpen socketOpen(StubSocketOpen in) {
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public static class StubSocketOpen implements SocketOpen {
|
|
||||||
private final ConcurrentMap<String, NodeMetadata> nodes;
|
|
||||||
private final String publicIpPrefix;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public StubSocketOpen(ConcurrentMap<String, NodeMetadata> nodes, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix) {
|
|
||||||
this.nodes = nodes;
|
|
||||||
this.publicIpPrefix = publicIpPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(IPSocket input) {
|
|
||||||
if (input.getAddress().indexOf(publicIpPrefix) == -1)
|
|
||||||
return false;
|
|
||||||
String id = input.getAddress().replace(publicIpPrefix, "");
|
|
||||||
NodeMetadata node = nodes.get(id);
|
|
||||||
return node != null && node.getState() == NodeState.RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
install(new StubComputeServiceDependenciesModule());
|
||||||
}).to(new TypeLiteral<ComputeServiceContextImpl<ConcurrentMap, ConcurrentMap>>() {
|
super.configure();
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
install(new ComputeServiceTimeoutsModule());
|
|
||||||
bind(ConcurrentMap.class).toInstance(nodes);
|
|
||||||
bind(AddNodeWithTagStrategy.class).to(StubAddNodeWithTagStrategy.class);
|
|
||||||
bind(ListNodesStrategy.class).to(StubListNodesStrategy.class);
|
|
||||||
bind(GetNodeMetadataStrategy.class).to(StubGetNodeMetadataStrategy.class);
|
|
||||||
bind(RebootNodeStrategy.class).to(StubRebootNodeStrategy.class);
|
|
||||||
bind(DestroyNodeStrategy.class).to(StubDestroyNodeStrategy.class);
|
|
||||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public static class StubAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
|
|
||||||
private final Supplier<Location> location;
|
|
||||||
private final ConcurrentMap<String, NodeMetadata> nodes;
|
|
||||||
private final Provider<Integer> idProvider;
|
|
||||||
private final String publicIpPrefix;
|
|
||||||
private final String privateIpPrefix;
|
|
||||||
private final String passwordPrefix;
|
|
||||||
private final Map<String, Credentials> credentialStore;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public StubAddNodeWithTagStrategy(ConcurrentMap<String, NodeMetadata> nodes, Supplier<Location> location,
|
|
||||||
@Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix,
|
|
||||||
@Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix,
|
|
||||||
Map<String, Credentials> credentialStore) {
|
|
||||||
this.nodes = nodes;
|
|
||||||
this.location = location;
|
|
||||||
this.idProvider = idProvider;
|
|
||||||
this.publicIpPrefix = publicIpPrefix;
|
|
||||||
this.privateIpPrefix = privateIpPrefix;
|
|
||||||
this.passwordPrefix = passwordPrefix;
|
|
||||||
this.credentialStore = credentialStore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata execute(String tag, String name, Template template) {
|
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
|
||||||
checkArgument(location.get().equals(template.getLocation()), "invalid location: " + template.getLocation());
|
return StubAddNodeWithTagStrategy.class;
|
||||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
|
||||||
String id = idProvider.get() + "";
|
|
||||||
builder.ids(id);
|
|
||||||
builder.name(name);
|
|
||||||
builder.tag(tag);
|
|
||||||
builder.location(location.get());
|
|
||||||
builder.imageId(template.getImage().getId());
|
|
||||||
builder.operatingSystem(template.getImage().getOperatingSystem());
|
|
||||||
builder.state(NodeState.PENDING);
|
|
||||||
builder.publicAddresses(ImmutableSet.<String> of(publicIpPrefix + id));
|
|
||||||
builder.privateAddresses(ImmutableSet.<String> of(privateIpPrefix + id));
|
|
||||||
builder.credentials(new Credentials("root", passwordPrefix + id));
|
|
||||||
NodeMetadata node = builder.build();
|
|
||||||
nodes.put(node.getId(), node);
|
|
||||||
credentialStore.put(node.getId(), node.getCredentials());
|
|
||||||
setState(node, NodeState.RUNNING, 100);
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void nodeWithState(NodeMetadata node, NodeState state) {
|
|
||||||
nodes.put(node.getId(), NodeMetadataBuilder.fromNodeMetadata(node).state(state).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setState(final NodeMetadata node, final NodeState state, final long millis) {
|
|
||||||
if (millis == 0l)
|
|
||||||
nodeWithState(node, state);
|
|
||||||
else
|
|
||||||
service.execute(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(millis);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
nodeWithState(node, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public static class StubGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
|
|
||||||
private final ConcurrentMap<String, NodeMetadata> nodes;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected StubGetNodeMetadataStrategy(ConcurrentMap<String, NodeMetadata> nodes) {
|
|
||||||
this.nodes = nodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata execute(String id) {
|
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||||
return nodes.get(id);
|
return StubDestroyNodeStrategy.class;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public static class StubListNodesStrategy implements ListNodesStrategy {
|
|
||||||
private final ConcurrentMap<String, NodeMetadata> nodes;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected StubListNodesStrategy(ConcurrentMap<String, NodeMetadata> nodes) {
|
|
||||||
this.nodes = nodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends ComputeMetadata> list() {
|
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||||
return listDetailsOnNodesMatching(NodePredicates.all());
|
return StubGetNodeMetadataStrategy.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||||
return Iterables.filter(nodes.values(), filter);
|
return StubListNodesStrategy.class;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public static class StubRebootNodeStrategy implements RebootNodeStrategy {
|
|
||||||
private final ConcurrentMap<String, NodeMetadata> nodes;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected StubRebootNodeStrategy(ConcurrentMap<String, NodeMetadata> nodes) {
|
|
||||||
this.nodes = nodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata execute(String id) {
|
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||||
NodeMetadata node = nodes.get(id);
|
return StubRebootNodeStrategy.class;
|
||||||
if (node == null)
|
|
||||||
throw new ResourceNotFoundException("node not found: " + id);
|
|
||||||
setState(node, NodeState.PENDING, 0);
|
|
||||||
setState(node, NodeState.RUNNING, 50);
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public static class StubDestroyNodeStrategy implements DestroyNodeStrategy {
|
|
||||||
private final ConcurrentMap<String, NodeMetadata> nodes;
|
|
||||||
private final ExecutorService service;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected StubDestroyNodeStrategy(ConcurrentMap<String, NodeMetadata> nodes,
|
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) {
|
|
||||||
this.nodes = nodes;
|
|
||||||
this.service = service;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata execute(final String id) {
|
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||||
NodeMetadata node = nodes.get(id);
|
return StubHardwareSupplier.class;
|
||||||
if (node == null)
|
|
||||||
return node;
|
|
||||||
setState(node, NodeState.PENDING, 0);
|
|
||||||
setState(node, NodeState.TERMINATED, 50);
|
|
||||||
service.execute(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(200);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
} finally {
|
|
||||||
nodes.remove(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
|
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||||
Supplier<Location> defaultLocation = injector.getInstance(Key.get(new TypeLiteral<Supplier<Location>>() {
|
return StubImageSupplier.class;
|
||||||
}));
|
|
||||||
Location zone = defaultLocation.get().getParent();
|
|
||||||
String parentId = zone.getId();
|
|
||||||
Credentials defaultCredentials = new Credentials("root", null);
|
|
||||||
return Suppliers
|
|
||||||
.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
|
|
||||||
//
|
|
||||||
new ImageBuilder()
|
|
||||||
.providerId("1")
|
|
||||||
.name(OsFamily.UBUNTU.name())
|
|
||||||
.id(parentId + "/1")
|
|
||||||
.location(zone)
|
|
||||||
.operatingSystem(
|
|
||||||
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false))
|
|
||||||
.description("stub ubuntu 32").defaultCredentials(defaultCredentials).build(), //
|
|
||||||
new ImageBuilder()
|
|
||||||
.providerId("2")
|
|
||||||
.name(OsFamily.UBUNTU.name())
|
|
||||||
.id(parentId + "/2")
|
|
||||||
.location(zone)
|
|
||||||
.operatingSystem(
|
|
||||||
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true))
|
|
||||||
.description("stub ubuntu 64").defaultCredentials(defaultCredentials).build(), //
|
|
||||||
new ImageBuilder()
|
|
||||||
.providerId("3")
|
|
||||||
.name(OsFamily.CENTOS.name())
|
|
||||||
.id(parentId + "/3")
|
|
||||||
.location(zone)
|
|
||||||
.operatingSystem(
|
|
||||||
new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true))
|
|
||||||
.description("stub centos 64").defaultCredentials(defaultCredentials).build() //
|
|
||||||
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected Set<? extends Location> provideLocations(@org.jclouds.rest.annotations.Provider String providerName) {
|
|
||||||
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
|
||||||
Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region",
|
|
||||||
provider);
|
|
||||||
return ImmutableSet
|
|
||||||
.of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName + "zone", region));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
|
|
||||||
return Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of(
|
|
||||||
StubHardware.stub("small", 1, 1740, 160), StubHardware.stub("medium", 4, 7680, 850),
|
|
||||||
StubHardware.stub("large", 8, 15360, 1690)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class StubHardware {
|
|
||||||
|
|
||||||
static Hardware stub(String type, int cores, int ram, float disk) {
|
|
||||||
return new org.jclouds.compute.domain.HardwareBuilder().id(type).providerId(type).name(type)
|
|
||||||
.processors(ImmutableList.of(new Processor(cores, 1.0))).ram(ram)
|
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(disk, true, false))).build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,377 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.stub.config;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.Constants;
|
||||||
|
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.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||||
|
import org.jclouds.compute.domain.NodeState;
|
||||||
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
|
import org.jclouds.compute.domain.Processor;
|
||||||
|
import org.jclouds.compute.domain.Template;
|
||||||
|
import org.jclouds.compute.domain.Volume;
|
||||||
|
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||||
|
import org.jclouds.compute.predicates.NodePredicates;
|
||||||
|
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.domain.Location;
|
||||||
|
import org.jclouds.domain.LocationScope;
|
||||||
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
|
import org.jclouds.net.IPSocket;
|
||||||
|
import org.jclouds.predicates.SocketOpen;
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class StubComputeServiceDependenciesModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final ConcurrentMap<String, NodeMetadata> backing = new ConcurrentHashMap<String, NodeMetadata>();
|
||||||
|
|
||||||
|
// implementation details below
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ConcurrentMap<String, NodeMetadata> provideNodes() {
|
||||||
|
return backing;
|
||||||
|
}
|
||||||
|
|
||||||
|
// STUB STUFF STATIC SO MULTIPLE CONTEXTS CAN SEE IT
|
||||||
|
private static final AtomicInteger nodeIds = new AtomicInteger(0);
|
||||||
|
private static final ExecutorService service = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Named("NODE_ID")
|
||||||
|
Integer provideNodeId() {
|
||||||
|
return nodeIds.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
@Named("PUBLIC_IP_PREFIX")
|
||||||
|
String publicIpPrefix() {
|
||||||
|
return "144.175.1.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
@Named("PRIVATE_IP_PREFIX")
|
||||||
|
String privateIpPrefix() {
|
||||||
|
return "10.1.1.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
@Named("PASSWORD_PREFIX")
|
||||||
|
String passwordPrefix() {
|
||||||
|
return "password";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
SocketOpen socketOpen(StubSocketOpen in) {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class StubSocketOpen implements SocketOpen {
|
||||||
|
private final ConcurrentMap<String, NodeMetadata> nodes;
|
||||||
|
private final String publicIpPrefix;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public StubSocketOpen(ConcurrentMap<String, NodeMetadata> nodes, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix) {
|
||||||
|
this.nodes = nodes;
|
||||||
|
this.publicIpPrefix = publicIpPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(IPSocket input) {
|
||||||
|
if (input.getAddress().indexOf(publicIpPrefix) == -1)
|
||||||
|
return false;
|
||||||
|
String id = input.getAddress().replace(publicIpPrefix, "");
|
||||||
|
NodeMetadata node = nodes.get(id);
|
||||||
|
return node != null && node.getState() == NodeState.RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class StubAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
|
||||||
|
private final Supplier<Location> location;
|
||||||
|
private final ConcurrentMap<String, NodeMetadata> nodes;
|
||||||
|
private final Provider<Integer> idProvider;
|
||||||
|
private final String publicIpPrefix;
|
||||||
|
private final String privateIpPrefix;
|
||||||
|
private final String passwordPrefix;
|
||||||
|
private final Map<String, Credentials> credentialStore;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public StubAddNodeWithTagStrategy(ConcurrentMap<String, NodeMetadata> nodes, Supplier<Location> location,
|
||||||
|
@Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix,
|
||||||
|
@Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix,
|
||||||
|
Map<String, Credentials> credentialStore) {
|
||||||
|
this.nodes = nodes;
|
||||||
|
this.location = location;
|
||||||
|
this.idProvider = idProvider;
|
||||||
|
this.publicIpPrefix = publicIpPrefix;
|
||||||
|
this.privateIpPrefix = privateIpPrefix;
|
||||||
|
this.passwordPrefix = passwordPrefix;
|
||||||
|
this.credentialStore = credentialStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMetadata execute(String tag, String name, Template template) {
|
||||||
|
checkArgument(location.get().equals(template.getLocation()), "invalid location: " + template.getLocation());
|
||||||
|
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||||
|
String id = idProvider.get() + "";
|
||||||
|
builder.ids(id);
|
||||||
|
builder.name(name);
|
||||||
|
builder.tag(tag);
|
||||||
|
builder.location(location.get());
|
||||||
|
builder.imageId(template.getImage().getId());
|
||||||
|
builder.operatingSystem(template.getImage().getOperatingSystem());
|
||||||
|
builder.state(NodeState.PENDING);
|
||||||
|
builder.publicAddresses(ImmutableSet.<String> of(publicIpPrefix + id));
|
||||||
|
builder.privateAddresses(ImmutableSet.<String> of(privateIpPrefix + id));
|
||||||
|
builder.credentials(new Credentials("root", passwordPrefix + id));
|
||||||
|
NodeMetadata node = builder.build();
|
||||||
|
nodes.put(node.getId(), node);
|
||||||
|
credentialStore.put(node.getId(), node.getCredentials());
|
||||||
|
setState(node, NodeState.RUNNING, 100);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void nodeWithState(NodeMetadata node, NodeState state) {
|
||||||
|
backing.put(node.getId(), NodeMetadataBuilder.fromNodeMetadata(node).state(state).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setState(final NodeMetadata node, final NodeState state, final long millis) {
|
||||||
|
if (millis == 0l)
|
||||||
|
nodeWithState(node, state);
|
||||||
|
else
|
||||||
|
service.execute(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(millis);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
}
|
||||||
|
nodeWithState(node, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class StubGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
|
||||||
|
private final ConcurrentMap<String, NodeMetadata> nodes;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected StubGetNodeMetadataStrategy(ConcurrentMap<String, NodeMetadata> nodes) {
|
||||||
|
this.nodes = nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMetadata execute(String id) {
|
||||||
|
return nodes.get(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class StubListNodesStrategy implements ListNodesStrategy {
|
||||||
|
private final ConcurrentMap<String, NodeMetadata> nodes;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected StubListNodesStrategy(ConcurrentMap<String, NodeMetadata> nodes) {
|
||||||
|
this.nodes = nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<? extends ComputeMetadata> list() {
|
||||||
|
return listDetailsOnNodesMatching(NodePredicates.all());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||||
|
return Iterables.filter(nodes.values(), filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class StubRebootNodeStrategy implements RebootNodeStrategy {
|
||||||
|
private final ConcurrentMap<String, NodeMetadata> nodes;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected StubRebootNodeStrategy(ConcurrentMap<String, NodeMetadata> nodes) {
|
||||||
|
this.nodes = nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMetadata execute(String id) {
|
||||||
|
NodeMetadata node = nodes.get(id);
|
||||||
|
if (node == null)
|
||||||
|
throw new ResourceNotFoundException("node not found: " + id);
|
||||||
|
setState(node, NodeState.PENDING, 0);
|
||||||
|
setState(node, NodeState.RUNNING, 50);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class StubDestroyNodeStrategy implements DestroyNodeStrategy {
|
||||||
|
private final ConcurrentMap<String, NodeMetadata> nodes;
|
||||||
|
private final ExecutorService service;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected StubDestroyNodeStrategy(ConcurrentMap<String, NodeMetadata> nodes,
|
||||||
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) {
|
||||||
|
this.nodes = nodes;
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMetadata execute(final String id) {
|
||||||
|
NodeMetadata node = nodes.get(id);
|
||||||
|
if (node == null)
|
||||||
|
return node;
|
||||||
|
setState(node, NodeState.PENDING, 0);
|
||||||
|
setState(node, NodeState.TERMINATED, 50);
|
||||||
|
service.execute(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
} finally {
|
||||||
|
nodes.remove(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
static class StubImageSupplier implements Supplier<Set<? extends Image>> {
|
||||||
|
private final Supplier<Location> defaultLocation;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
StubImageSupplier(Supplier<Location> defaultLocation) {
|
||||||
|
this.defaultLocation = defaultLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<? extends Image> get() {
|
||||||
|
Location zone = defaultLocation.get().getParent();
|
||||||
|
String parentId = zone.getId();
|
||||||
|
Credentials defaultCredentials = new Credentials("root", null);
|
||||||
|
return ImmutableSet
|
||||||
|
.<Image> of(new ImageBuilder().providerId("1").name(OsFamily.UBUNTU.name()).id(parentId + "/1")
|
||||||
|
.location(zone).operatingSystem(
|
||||||
|
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32",
|
||||||
|
false)).description("stub ubuntu 32").defaultCredentials(
|
||||||
|
defaultCredentials).build(), //
|
||||||
|
new ImageBuilder().providerId("2").name(OsFamily.UBUNTU.name()).id(parentId + "/2")
|
||||||
|
.location(zone).operatingSystem(
|
||||||
|
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64",
|
||||||
|
"ubuntu 64", true)).description("stub ubuntu 64")
|
||||||
|
.defaultCredentials(defaultCredentials).build(), //
|
||||||
|
new ImageBuilder().providerId("3").name(OsFamily.CENTOS.name()).id(parentId + "/3")
|
||||||
|
.location(zone).operatingSystem(
|
||||||
|
new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64",
|
||||||
|
"centos 64", true)).description("stub centos 64")
|
||||||
|
.defaultCredentials(defaultCredentials).build() //
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
protected Set<? extends Location> provideLocations(@org.jclouds.rest.annotations.Provider String providerName) {
|
||||||
|
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
||||||
|
Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region",
|
||||||
|
provider);
|
||||||
|
return ImmutableSet
|
||||||
|
.of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName + "zone", region));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
static class StubHardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
||||||
|
|
||||||
|
static Hardware stub(String type, int cores, int ram, float disk) {
|
||||||
|
return new org.jclouds.compute.domain.HardwareBuilder().id(type).providerId(type).name(type).processors(
|
||||||
|
ImmutableList.of(new Processor(cores, 1.0))).ram(ram).volumes(
|
||||||
|
ImmutableList.<Volume> of(new VolumeImpl(disk, true, false))).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<? extends Hardware> get() {
|
||||||
|
return ImmutableSet.<Hardware> of(stub("small", 1, 1740, 160), stub("medium", 4, 7680, 850), stub("large", 8,
|
||||||
|
15360, 1690));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.compute.stub.config.StubComputeServiceContextModule;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit")
|
||||||
|
public class ComputeServiceContextFactoryTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStandalone() {
|
||||||
|
ComputeServiceContext context = ComputeServiceContextFactory.createStandaloneContext(new StubComputeServiceContextModule());
|
||||||
|
context.getComputeService().listNodes();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -174,8 +174,8 @@ public class TemplateBuilderImplTest {
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
OperatingSystem os = createMock(OperatingSystem.class);
|
OperatingSystem os = createMock(OperatingSystem.class);
|
||||||
|
|
||||||
Hardware hardware = new HardwareBuilder().id("hardwareId")
|
Hardware hardware = new HardwareBuilder().id("hardwareId").supportsImage(ImagePredicates.idEquals("imageId"))
|
||||||
.supportsImage(ImagePredicates.idEquals("imageId")).build();
|
.build();
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(defaultLocation));
|
||||||
|
@ -229,8 +229,8 @@ public class TemplateBuilderImplTest {
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
OperatingSystem os = createMock(OperatingSystem.class);
|
OperatingSystem os = createMock(OperatingSystem.class);
|
||||||
|
|
||||||
Hardware hardware = new HardwareBuilder().id("hardwareId")
|
Hardware hardware = new HardwareBuilder().id("hardwareId").supportsImage(ImagePredicates.idEquals("imageId"))
|
||||||
.supportsImage(ImagePredicates.idEquals("imageId")).build();
|
.build();
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(defaultLocation));
|
||||||
|
@ -351,10 +351,11 @@ public class TemplateBuilderImplTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TemplateBuilderImpl createTemplateBuilder(Image knownImage, Supplier<Set<? extends Location>> locations,
|
protected TemplateBuilderImpl createTemplateBuilder(Image knownImage, Supplier<Set<? extends Location>> locations,
|
||||||
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> hardwares, Location defaultLocation,
|
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> hardwares,
|
||||||
Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) {
|
Location defaultLocation, Provider<TemplateOptions> optionsProvider,
|
||||||
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, hardwares,
|
Provider<TemplateBuilder> templateBuilderProvider) {
|
||||||
Suppliers.ofInstance(defaultLocation), optionsProvider, templateBuilderProvider);
|
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, hardwares, Suppliers
|
||||||
|
.ofInstance(defaultLocation), optionsProvider, templateBuilderProvider);
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.collect;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.ElementType.PARAMETER;
|
||||||
|
import static java.lang.annotation.ElementType.TYPE;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Designates that this object is going to return cached results
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Target( { TYPE, METHOD, PARAMETER })
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@Qualifier
|
||||||
|
public @interface Memoized {
|
||||||
|
|
||||||
|
}
|
|
@ -92,7 +92,6 @@ gogrid.contextbuilder=org.jclouds.gogrid.GoGridContextBuilder
|
||||||
ibmdev.propertiesbuilder=org.jclouds.ibmdev.IBMDeveloperCloudPropertiesBuilder
|
ibmdev.propertiesbuilder=org.jclouds.ibmdev.IBMDeveloperCloudPropertiesBuilder
|
||||||
ibmdev.contextbuilder=org.jclouds.ibmdev.IBMDeveloperCloudContextBuilder
|
ibmdev.contextbuilder=org.jclouds.ibmdev.IBMDeveloperCloudContextBuilder
|
||||||
|
|
||||||
stub.propertiesbuilder=org.jclouds.compute.stub.StubComputeServicePropertiesBuilder
|
|
||||||
stub.contextbuilder=org.jclouds.compute.stub.StubComputeServiceContextBuilder
|
stub.contextbuilder=org.jclouds.compute.stub.StubComputeServiceContextBuilder
|
||||||
# example of where to change your endpoint
|
# example of where to change your endpoint
|
||||||
# bluelock.endpoint=https://express3.bluelock.com/api
|
# bluelock.endpoint=https://express3.bluelock.com/api
|
||||||
|
|
|
@ -38,12 +38,12 @@ import static com.google.common.util.concurrent.Futures.immediateFuture;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInput;
|
import java.io.ObjectInput;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -55,10 +55,16 @@ import java.util.TreeSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
|
@ -67,6 +73,7 @@ import org.jclouds.blobstore.domain.PageSet;
|
||||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
import org.jclouds.blobstore.domain.StorageType;
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
import org.jclouds.blobstore.domain.Blob.Factory;
|
||||||
|
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
||||||
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
|
import org.jclouds.blobstore.domain.internal.MutableStorageMetadataImpl;
|
||||||
import org.jclouds.blobstore.domain.internal.PageSetImpl;
|
import org.jclouds.blobstore.domain.internal.PageSetImpl;
|
||||||
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
|
||||||
|
@ -75,17 +82,23 @@ import org.jclouds.blobstore.options.GetOptions;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
|
import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.crypto.Crypto;
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||||
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||||
import org.jclouds.http.HttpCommand;
|
import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.http.options.HttpRequestOptions;
|
import org.jclouds.http.options.HttpRequestOptions;
|
||||||
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
|
import org.jclouds.io.payloads.FilePayload;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.rest.annotations.ParamValidators;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -95,23 +108,10 @@ import com.google.common.collect.Iterables;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.inject.internal.Nullable;
|
import com.google.inject.internal.Nullable;
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
|
||||||
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
|
||||||
import org.jclouds.io.Payload;
|
|
||||||
import org.jclouds.io.payloads.FilePayload;
|
|
||||||
import org.jclouds.logging.Logger;
|
|
||||||
import org.jclouds.rest.annotations.ParamValidators;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Preconditions:
|
* Preconditions: Blob name cannot start with / char (or \ under windows)
|
||||||
* Blob name cannot start with / char (or \ under windows)
|
|
||||||
*
|
*
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
* @author Alfredo "Rainbowbreeze" Morresi
|
||||||
*/
|
*/
|
||||||
|
@ -127,15 +127,12 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
protected final Factory blobFactory;
|
protected final Factory blobFactory;
|
||||||
protected final FilesystemStorageStrategy storageStrategy;
|
protected final FilesystemStorageStrategy storageStrategy;
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FilesystemAsyncBlobStore(BlobStoreContext context, DateService dateService, Crypto crypto,
|
protected FilesystemAsyncBlobStore(BlobStoreContext context, DateService dateService, Crypto crypto,
|
||||||
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
HttpGetOptionsListToGetOptions httpGetOptionsConverter,
|
||||||
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobUtils blobUtils,
|
IfDirectoryReturnNameStrategy ifDirectoryReturnName, Blob.Factory blobFactory, BlobUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||||
Supplier<Location> defaultLocation,
|
@Memoized Supplier<Set<? extends Location>> locations, FilesystemStorageStrategy storageStrategy) {
|
||||||
Supplier<Set<? extends Location>> locations,
|
|
||||||
FilesystemStorageStrategy storageStrategy) {
|
|
||||||
super(context, blobUtils, service, defaultLocation, locations);
|
super(context, blobUtils, service, defaultLocation, locations);
|
||||||
// super(context, blobUtils, service, null, null);
|
// super(context, blobUtils, service, null, null);
|
||||||
this.blobFactory = blobFactory;
|
this.blobFactory = blobFactory;
|
||||||
|
@ -162,13 +159,10 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
try {
|
try {
|
||||||
blobBelongingToContainer = storageStrategy.getBlobKeysInsideContainer(container);
|
blobBelongingToContainer = storageStrategy.getBlobKeysInsideContainer(container);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e,
|
logger.error(e, "An error occurred loading blobs contained into container %s", container);
|
||||||
"An error occurred loading blobs contained into container %s",
|
|
||||||
container);
|
|
||||||
Throwables.propagate(e);
|
Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SortedSet<StorageMetadata> contents = newTreeSet(transform(blobBelongingToContainer,
|
SortedSet<StorageMetadata> contents = newTreeSet(transform(blobBelongingToContainer,
|
||||||
new Function<String, StorageMetadata>() {
|
new Function<String, StorageMetadata>() {
|
||||||
public StorageMetadata apply(String key) {
|
public StorageMetadata apply(String key) {
|
||||||
|
@ -224,7 +218,8 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
final String delimiter = options.isRecursive() ? null : File.separator;
|
final String delimiter = options.isRecursive() ? null : File.separator;
|
||||||
if (delimiter != null) {
|
if (delimiter != null) {
|
||||||
SortedSet<String> commonPrefixes = null;
|
SortedSet<String> commonPrefixes = null;
|
||||||
Iterable<String> iterable = transform(contents, new CommonPrefixes(prefix != null ? prefix : null, delimiter));
|
Iterable<String> iterable = transform(contents, new CommonPrefixes(prefix != null ? prefix : null,
|
||||||
|
delimiter));
|
||||||
commonPrefixes = iterable != null ? newTreeSet(iterable) : new TreeSet<String>();
|
commonPrefixes = iterable != null ? newTreeSet(iterable) : new TreeSet<String>();
|
||||||
commonPrefixes.remove(CommonPrefixes.NO_PREFIX);
|
commonPrefixes.remove(CommonPrefixes.NO_PREFIX);
|
||||||
|
|
||||||
|
@ -254,7 +249,6 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ContainerNotFoundException cnfe(final String name) {
|
private ContainerNotFoundException cnfe(final String name) {
|
||||||
return new ContainerNotFoundException(name, String.format("container %s not in filesystem", name));
|
return new ContainerNotFoundException(name, String.format("container %s not in filesystem", name));
|
||||||
}
|
}
|
||||||
|
@ -299,7 +293,6 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
return immediateFuture(null);
|
return immediateFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -336,8 +329,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
*/
|
*/
|
||||||
@Path("{container}")
|
@Path("{container}")
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Boolean> createContainerInLocation(
|
public ListenableFuture<Boolean> createContainerInLocation(final Location location,
|
||||||
final Location location,
|
|
||||||
@PathParam("container") @ParamValidators( { FilesystemContainerNameValidator.class }) String name) {
|
@PathParam("container") @ParamValidators( { FilesystemContainerNameValidator.class }) String name) {
|
||||||
boolean result = storageStrategy.createContainer(name);
|
boolean result = storageStrategy.createContainer(name);
|
||||||
return immediateFuture(result);
|
return immediateFuture(result);
|
||||||
|
@ -351,12 +343,14 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the blob with the given key belonging to the container with the given
|
* Load the blob with the given key belonging to the container with the given name. There must
|
||||||
* name. There must exist a resource on the file system whose complete name
|
* exist a resource on the file system whose complete name is given concatenating the container
|
||||||
* is given concatenating the container name and the key
|
* name and the key
|
||||||
*
|
*
|
||||||
* @param container it's the name of the container the blob belongs to
|
* @param container
|
||||||
* @param key it's the key of the blob
|
* it's the name of the container the blob belongs to
|
||||||
|
* @param key
|
||||||
|
* it's the key of the blob
|
||||||
*
|
*
|
||||||
* @return the blob belonging to the given container with the given key
|
* @return the blob belonging to the given container with the given key
|
||||||
*/
|
*/
|
||||||
|
@ -387,8 +381,6 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected static class DelimiterFilter implements Predicate<StorageMetadata> {
|
protected static class DelimiterFilter implements Predicate<StorageMetadata> {
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
private final String delimiter;
|
private final String delimiter;
|
||||||
|
@ -501,8 +493,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
|
|
||||||
storageStrategy.writePayloadOnFile(containerName, blobKey, object.getPayload());
|
storageStrategy.writePayloadOnFile(containerName, blobKey, object.getPayload());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e, "An error occurred storing the new object with name [%s] to container [%s].",
|
logger.error(e, "An error occurred storing the new object with name [%s] to container [%s].", blobKey,
|
||||||
blobKey,
|
|
||||||
containerName);
|
containerName);
|
||||||
Throwables.propagate(e);
|
Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
|
@ -618,11 +609,10 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
return containerExistsSyncImpl(container);
|
return containerExistsSyncImpl(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override parent method because it uses strange futures and listenables
|
* Override parent method because it uses strange futures and listenables that creates problem in
|
||||||
* that creates problem in the test if more than one test that deletes the
|
* the test if more than one test that deletes the container is executed
|
||||||
* container is executed
|
*
|
||||||
* @param container
|
* @param container
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -632,10 +622,10 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
return immediateFuture(null);
|
return immediateFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Each container is a directory, so in order to check if a container exists
|
* Each container is a directory, so in order to check if a container exists the corresponding
|
||||||
* the corresponding directory must exists. Synchronous implementation
|
* directory must exists. Synchronous implementation
|
||||||
|
*
|
||||||
* @param containerName
|
* @param containerName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -643,11 +633,10 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
return storageStrategy.containerExists(containerName);
|
return storageStrategy.containerExists(containerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Calculates the object MD5 and returns it as eTag
|
* Calculates the object MD5 and returns it as eTag
|
||||||
|
*
|
||||||
* @param object
|
* @param object
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -655,8 +644,7 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
try {
|
try {
|
||||||
Payloads.calculateMD5(object, crypto.md5());
|
Payloads.calculateMD5(object, crypto.md5());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error(ex, "An error occurred calculating MD5 for object with name %s.",
|
logger.error(ex, "An error occurred calculating MD5 for object with name %s.", object.getMetadata().getName());
|
||||||
object.getMetadata().getName());
|
|
||||||
Throwables.propagate(ex);
|
Throwables.propagate(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,15 +19,8 @@
|
||||||
|
|
||||||
package org.jclouds.filesystem.config;
|
package org.jclouds.filesystem.config;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.base.Suppliers;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import com.google.inject.Scopes;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
|
@ -36,6 +29,7 @@ import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
|
@ -48,6 +42,15 @@ import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
|
||||||
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
|
import org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl;
|
||||||
import org.jclouds.filesystem.util.internal.FileSystemBlobUtilsImpl;
|
import org.jclouds.filesystem.util.internal.FileSystemBlobUtilsImpl;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Alfredo "Rainbowbreeze" Morresi
|
* @author Alfredo "Rainbowbreeze" Morresi
|
||||||
|
@ -76,6 +79,7 @@ public class FilesystemBlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@Memoized
|
||||||
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
Supplier<Set<? extends Location>> provideLocations(Supplier<Location> defaultLocation) {
|
||||||
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
return Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(defaultLocation.get()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,61 +20,32 @@
|
||||||
package org.jclouds.gogrid.compute.config;
|
package org.jclouds.gogrid.compute.config;
|
||||||
|
|
||||||
import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
|
|
||||||
import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
|
||||||
import org.jclouds.compute.LoadBalancerService;
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
|
||||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.gogrid.GoGridAsyncClient;
|
|
||||||
import org.jclouds.gogrid.GoGridClient;
|
|
||||||
import org.jclouds.gogrid.compute.functions.ServerToNodeMetadata;
|
|
||||||
import org.jclouds.gogrid.compute.strategy.GoGridAddNodeWithTagStrategy;
|
import org.jclouds.gogrid.compute.strategy.GoGridAddNodeWithTagStrategy;
|
||||||
import org.jclouds.gogrid.compute.strategy.GoGridDestroyNodeStrategy;
|
import org.jclouds.gogrid.compute.strategy.GoGridDestroyNodeStrategy;
|
||||||
import org.jclouds.gogrid.compute.strategy.GoGridGetNodeMetadataStrategy;
|
import org.jclouds.gogrid.compute.strategy.GoGridGetNodeMetadataStrategy;
|
||||||
import org.jclouds.gogrid.compute.strategy.GoGridListNodesStrategy;
|
import org.jclouds.gogrid.compute.strategy.GoGridListNodesStrategy;
|
||||||
import org.jclouds.gogrid.compute.strategy.GoGridRebootNodeStrategy;
|
import org.jclouds.gogrid.compute.strategy.GoGridRebootNodeStrategy;
|
||||||
|
import org.jclouds.gogrid.compute.suppliers.GoGridDefaultLocationSupplier;
|
||||||
import org.jclouds.gogrid.compute.suppliers.GoGridHardwareSupplier;
|
import org.jclouds.gogrid.compute.suppliers.GoGridHardwareSupplier;
|
||||||
import org.jclouds.gogrid.compute.suppliers.GoGridImageSupplier;
|
import org.jclouds.gogrid.compute.suppliers.GoGridImageSupplier;
|
||||||
import org.jclouds.gogrid.compute.suppliers.GoGridLocationSupplier;
|
import org.jclouds.gogrid.compute.suppliers.GoGridLocationSupplier;
|
||||||
import org.jclouds.gogrid.domain.Server;
|
|
||||||
import org.jclouds.gogrid.domain.ServerState;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
|
|
||||||
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.base.Supplier;
|
||||||
import com.google.common.base.Suppliers;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.inject.Injector;
|
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;
|
|
||||||
import com.google.inject.name.Names;
|
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
|
@ -84,21 +55,8 @@ public class GoGridComputeServiceContextModule extends BaseComputeServiceContext
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new ComputeServiceTimeoutsModule());
|
install(new GoGridComputeServiceDependenciesModule());
|
||||||
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
super.configure();
|
||||||
}).to(ServerToNodeMetadata.class);
|
|
||||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
|
||||||
}).to(new TypeLiteral<ComputeServiceContextImpl<GoGridClient, GoGridAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
bind(new TypeLiteral<RestContext<GoGridClient, GoGridAsyncClient>>() {
|
|
||||||
}).to(new TypeLiteral<RestContextImpl<GoGridClient, GoGridAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
bind(AddNodeWithTagStrategy.class).to(GoGridAddNodeWithTagStrategy.class);
|
|
||||||
bind(ListNodesStrategy.class).to(GoGridListNodesStrategy.class);
|
|
||||||
bind(GetNodeMetadataStrategy.class).to(GoGridGetNodeMetadataStrategy.class);
|
|
||||||
bind(RebootNodeStrategy.class).to(GoGridRebootNodeStrategy.class);
|
|
||||||
bind(DestroyNodeStrategy.class).to(GoGridDestroyNodeStrategy.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,85 +64,48 @@ public class GoGridComputeServiceContextModule extends BaseComputeServiceContext
|
||||||
return template.osFamily(CENTOS).imageNameMatches(".*w/ None.*");
|
return template.osFamily(CENTOS).imageNameMatches(".*w/ None.*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final Map<ServerState, NodeState> serverStateToNodeState = ImmutableMap.<ServerState, NodeState> builder()
|
|
||||||
.put(ServerState.ON, NodeState.RUNNING)//
|
|
||||||
.put(ServerState.STARTING, NodeState.PENDING)//
|
|
||||||
.put(ServerState.OFF, NodeState.SUSPENDED)//
|
|
||||||
.put(ServerState.STOPPING, NodeState.PENDING)//
|
|
||||||
.put(ServerState.RESTARTING, NodeState.PENDING)//
|
|
||||||
.put(ServerState.SAVING, NodeState.PENDING)//
|
|
||||||
.put(ServerState.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
|
||||||
.put(ServerState.RESTORING, NodeState.PENDING)//
|
|
||||||
.put(ServerState.UPDATING, NodeState.PENDING).build();
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
Map<ServerState, NodeState> provideServerToNodeState() {
|
|
||||||
return serverStateToNodeState;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds matches to required configurations. GoGrid's documentation only specifies how much RAM
|
|
||||||
* one can get with different instance types. The # of cores and disk sizes are purely empyrical
|
|
||||||
* and aren't guaranteed. However, these are the matches found: Ram: 512MB, CPU: 1 core, HDD: 28
|
|
||||||
* GB Ram: 1GB, CPU: 1 core, HDD: 57 GB Ram: 2GB, CPU: 1 core, HDD: 113 GB Ram: 4GB, CPU: 3
|
|
||||||
* cores, HDD: 233 GB Ram: 8GB, CPU: 6 cores, HDD: 462 GB (as of March 2010)
|
|
||||||
*
|
|
||||||
* @return matched size
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
Function<Hardware, String> provideSizeToRam() {
|
|
||||||
return new Function<Hardware, String>() {
|
|
||||||
@Override
|
@Override
|
||||||
public String apply(Hardware hardware) {
|
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
|
||||||
if (hardware.getRam() >= 8 * 1024 || getCores(hardware) >= 6 || getSpace(hardware) >= 450)
|
return GoGridAddNodeWithTagStrategy.class;
|
||||||
return "8GB";
|
|
||||||
if (hardware.getRam() >= 4 * 1024 || getCores(hardware) >= 3 || getSpace(hardware) >= 230)
|
|
||||||
return "4GB";
|
|
||||||
if (hardware.getRam() >= 2 * 1024 || getSpace(hardware) >= 110)
|
|
||||||
return "2GB";
|
|
||||||
if (hardware.getRam() >= 1024 || getSpace(hardware) >= 55)
|
|
||||||
return "1GB";
|
|
||||||
return "512MB"; /* smallest */
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Location> supplyDefaultLocation(Injector injector, Supplier<Set<? extends Location>> locations) {
|
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||||
final String defaultDC = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_GOGRID_DEFAULT_DC)));
|
return GoGridDestroyNodeStrategy.class;
|
||||||
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.getId().equals(defaultDC);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}, locations);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
|
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||||
return injector.getInstance(GoGridImageSupplier.class);
|
return GoGridGetNodeMetadataStrategy.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
|
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||||
return injector.getInstance(GoGridLocationSupplier.class);
|
return GoGridHardwareSupplier.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
|
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||||
return injector.getInstance(GoGridHardwareSupplier.class);
|
return GoGridImageSupplier.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||||
|
return GoGridListNodesStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||||
|
return GoGridRebootNodeStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
|
||||||
|
return GoGridDefaultLocationSupplier.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||||
|
return GoGridLocationSupplier.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.gogrid.compute.config;
|
||||||
|
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.NodeState;
|
||||||
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
|
import org.jclouds.gogrid.GoGridAsyncClient;
|
||||||
|
import org.jclouds.gogrid.GoGridClient;
|
||||||
|
import org.jclouds.gogrid.compute.functions.ServerToNodeMetadata;
|
||||||
|
import org.jclouds.gogrid.domain.Server;
|
||||||
|
import org.jclouds.gogrid.domain.ServerState;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class GoGridComputeServiceDependenciesModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
||||||
|
}).to(ServerToNodeMetadata.class);
|
||||||
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
|
}).to(new TypeLiteral<ComputeServiceContextImpl<GoGridClient, GoGridAsyncClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
|
bind(new TypeLiteral<RestContext<GoGridClient, GoGridAsyncClient>>() {
|
||||||
|
}).to(new TypeLiteral<RestContextImpl<GoGridClient, GoGridAsyncClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final Map<ServerState, NodeState> serverStateToNodeState = ImmutableMap.<ServerState, NodeState> builder()
|
||||||
|
.put(ServerState.ON, NodeState.RUNNING)//
|
||||||
|
.put(ServerState.STARTING, NodeState.PENDING)//
|
||||||
|
.put(ServerState.OFF, NodeState.SUSPENDED)//
|
||||||
|
.put(ServerState.STOPPING, NodeState.PENDING)//
|
||||||
|
.put(ServerState.RESTARTING, NodeState.PENDING)//
|
||||||
|
.put(ServerState.SAVING, NodeState.PENDING)//
|
||||||
|
.put(ServerState.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
||||||
|
.put(ServerState.RESTORING, NodeState.PENDING)//
|
||||||
|
.put(ServerState.UPDATING, NodeState.PENDING).build();
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Map<ServerState, NodeState> provideServerToNodeState() {
|
||||||
|
return serverStateToNodeState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds matches to required configurations. GoGrid's documentation only specifies how much RAM
|
||||||
|
* one can get with different instance types. The # of cores and disk sizes are purely empyrical
|
||||||
|
* and aren't guaranteed. However, these are the matches found: Ram: 512MB, CPU: 1 core, HDD: 28
|
||||||
|
* GB Ram: 1GB, CPU: 1 core, HDD: 57 GB Ram: 2GB, CPU: 1 core, HDD: 113 GB Ram: 4GB, CPU: 3
|
||||||
|
* cores, HDD: 233 GB Ram: 8GB, CPU: 6 cores, HDD: 462 GB (as of March 2010)
|
||||||
|
*
|
||||||
|
* @return matched size
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Function<Hardware, String> provideSizeToRam() {
|
||||||
|
return new Function<Hardware, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(Hardware hardware) {
|
||||||
|
if (hardware.getRam() >= 8 * 1024 || getCores(hardware) >= 6 || getSpace(hardware) >= 450)
|
||||||
|
return "8GB";
|
||||||
|
if (hardware.getRam() >= 4 * 1024 || getCores(hardware) >= 3 || getSpace(hardware) >= 230)
|
||||||
|
return "4GB";
|
||||||
|
if (hardware.getRam() >= 2 * 1024 || getSpace(hardware) >= 110)
|
||||||
|
return "2GB";
|
||||||
|
if (hardware.getRam() >= 1024 || getSpace(hardware) >= 55)
|
||||||
|
return "1GB";
|
||||||
|
return "512MB"; /* smallest */
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
@ -72,8 +73,8 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
return input.getProviderId().equals(instance.getImage().getId() + "")
|
return input.getProviderId().equals(instance.getImage().getId() + "")
|
||||||
&& (input.getLocation() == null || input.getLocation().getId()
|
&& (input.getLocation() == null || input.getLocation().getId().equals(
|
||||||
.equals(instance.getDatacenter().getId() + ""));
|
instance.getDatacenter().getId() + ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +94,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, GoGridClient client,
|
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, GoGridClient client,
|
||||||
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> hardwares,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
|
||||||
Supplier<Map<String, ? extends Location>> locations) {
|
Supplier<Map<String, ? extends Location>> locations) {
|
||||||
this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
||||||
this.client = checkNotNull(client, "client");
|
this.client = checkNotNull(client, "client");
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.gogrid.compute.suppliers;
|
||||||
|
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class GoGridDefaultLocationSupplier implements Supplier<Location> {
|
||||||
|
private final Supplier<Set<? extends Location>> locations;
|
||||||
|
private final String defaultDC;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
GoGridDefaultLocationSupplier(@Memoized Supplier<Set<? extends Location>> locations,
|
||||||
|
@Named(PROPERTY_GOGRID_DEFAULT_DC) String defaultDC) {
|
||||||
|
this.locations = locations;
|
||||||
|
this.defaultDC = defaultDC;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location get() {
|
||||||
|
return Iterables.find(locations.get(), new Predicate<Location>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Location input) {
|
||||||
|
return input.getId().equals(defaultDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,21 +40,21 @@ import com.google.common.collect.ImmutableSet;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class GoGridHardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
public class GoGridHardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
||||||
|
|
||||||
public static final Hardware H8192 = new HardwareBuilder().ids("5").ram(8192)
|
public static final Hardware H8192 = new HardwareBuilder().ids("5").ram(8192).processors(
|
||||||
.processors(ImmutableList.of(new Processor(8, 1.0)))
|
ImmutableList.of(new Processor(8, 1.0))).volumes(
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(480.0f, true, true))).build();
|
ImmutableList.<Volume> of(new VolumeImpl(480.0f, true, true))).build();
|
||||||
public static final Hardware H4096 = new HardwareBuilder().ids("4").ram(4096)
|
public static final Hardware H4096 = new HardwareBuilder().ids("4").ram(4096).processors(
|
||||||
.processors(ImmutableList.of(new Processor(4, 1.0)))
|
ImmutableList.of(new Processor(4, 1.0))).volumes(
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(240.0f, true, true))).build();
|
ImmutableList.<Volume> of(new VolumeImpl(240.0f, true, true))).build();
|
||||||
public static final Hardware H2048 = new HardwareBuilder().ids("3").ram(2048)
|
public static final Hardware H2048 = new HardwareBuilder().ids("3").ram(2048).processors(
|
||||||
.processors(ImmutableList.of(new Processor(2, 1.0)))
|
ImmutableList.of(new Processor(2, 1.0))).volumes(
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(120.0f, true, true))).build();
|
ImmutableList.<Volume> of(new VolumeImpl(120.0f, true, true))).build();
|
||||||
public static final Hardware H1024 = new HardwareBuilder().ids("2").ram(1024)
|
public static final Hardware H1024 = new HardwareBuilder().ids("2").ram(1024).processors(
|
||||||
.processors(ImmutableList.of(new Processor(1, 1.0)))
|
ImmutableList.of(new Processor(1, 1.0))).volumes(
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(60.0f, true, true))).build();
|
ImmutableList.<Volume> of(new VolumeImpl(60.0f, true, true))).build();
|
||||||
public static final Hardware H512 = new HardwareBuilder().ids("1").ram(512)
|
public static final Hardware H512 = new HardwareBuilder().ids("1").ram(512).processors(
|
||||||
.processors(ImmutableList.of(new Processor(0.5, 1.0)))
|
ImmutableList.of(new Processor(0.5, 1.0))).volumes(
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(30.0f, true, true))).build();
|
ImmutableList.<Volume> of(new VolumeImpl(30.0f, true, true))).build();
|
||||||
|
|
||||||
public static final ImmutableSet<Hardware> H_ALL = ImmutableSet.of(H512, H1024, H2048, H4096, H8192);
|
public static final ImmutableSet<Hardware> H_ALL = ImmutableSet.of(H512, H1024, H2048, H4096, H8192);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class GoGridComputeServiceContextModuleTest {
|
||||||
public void testAllStatusCovered() {
|
public void testAllStatusCovered() {
|
||||||
|
|
||||||
for (ServerState state : ServerState.values()) {
|
for (ServerState state : ServerState.values()) {
|
||||||
assert GoGridComputeServiceContextModule.serverStateToNodeState.containsKey(state) : state;
|
assert GoGridComputeServiceDependenciesModule.serverStateToNodeState.containsKey(state) : state;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.jclouds.blobstore.internal.BaseAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.concurrent.Futures;
|
import org.jclouds.concurrent.Futures;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
|
@ -83,7 +84,7 @@ public class CloudFilesAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
@Inject
|
@Inject
|
||||||
CloudFilesAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
CloudFilesAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier<Location> defaultLocation,
|
||||||
Supplier<Set<? extends Location>> locations, CloudFilesClient sync, CloudFilesAsyncClient async,
|
@Memoized Supplier<Set<? extends Location>> locations, CloudFilesClient sync, CloudFilesAsyncClient async,
|
||||||
ContainerToResourceMetadata container2ResourceMd,
|
ContainerToResourceMetadata container2ResourceMd,
|
||||||
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
||||||
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.jclouds.blobstore.internal.BaseBlobStore;
|
||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
|
||||||
import org.jclouds.blobstore.util.BlobUtils;
|
import org.jclouds.blobstore.util.BlobUtils;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
|
||||||
|
@ -72,7 +73,7 @@ public class CloudFilesBlobStore extends BaseBlobStore {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CloudFilesBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
CloudFilesBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
||||||
Supplier<Set<? extends Location>> locations, CloudFilesClient sync,
|
@Memoized Supplier<Set<? extends Location>> locations, CloudFilesClient sync,
|
||||||
ContainerToResourceMetadata container2ResourceMd,
|
ContainerToResourceMetadata container2ResourceMd,
|
||||||
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
||||||
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||||
|
|
|
@ -30,13 +30,14 @@ import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.attr.ConsistencyModel;
|
import org.jclouds.blobstore.attr.ConsistencyModel;
|
||||||
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
import org.jclouds.blobstore.config.BlobStoreMapModule;
|
||||||
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesAsyncBlobStore;
|
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesAsyncBlobStore;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobRequestSigner;
|
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobRequestSigner;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStore;
|
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStore;
|
||||||
import org.jclouds.rackspace.config.RackspaceLocationsModule;
|
import org.jclouds.rackspace.config.RackspaceLocationsSupplier;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
|
@ -56,8 +57,11 @@ public class CloudFilesBlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new RackspaceLocationsModule());
|
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
|
bind(new TypeLiteral<Supplier<Set<? extends Location>>>() {
|
||||||
|
}).annotatedWith(Memoized.class).to(new TypeLiteral<RackspaceLocationsSupplier>() {
|
||||||
|
});
|
||||||
|
|
||||||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||||
bind(AsyncBlobStore.class).to(CloudFilesAsyncBlobStore.class).in(Scopes.SINGLETON);
|
bind(AsyncBlobStore.class).to(CloudFilesAsyncBlobStore.class).in(Scopes.SINGLETON);
|
||||||
bind(BlobStore.class).to(CloudFilesBlobStore.class).in(Scopes.SINGLETON);
|
bind(BlobStore.class).to(CloudFilesBlobStore.class).in(Scopes.SINGLETON);
|
||||||
|
@ -68,14 +72,8 @@ public class CloudFilesBlobStoreContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Set<? extends Location> locations) {
|
protected Supplier<Location> getLocation(@Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
return Suppliers.<Set<? extends Location>> ofInstance(locations);
|
return Suppliers.<Location> ofInstance(Iterables.get(locations.get(), 0));
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected Supplier<Location> getLocation(Set<? extends Location> locations) {
|
|
||||||
return Suppliers.<Location> ofInstance(Iterables.get(locations, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,34 +21,19 @@ package org.jclouds.rackspace.cloudservers.compute.config;
|
||||||
|
|
||||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
|
||||||
import org.jclouds.compute.LoadBalancerService;
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
|
||||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.rackspace.cloudservers.CloudServersClient;
|
|
||||||
import org.jclouds.rackspace.cloudservers.compute.functions.CloudServersImageToImage;
|
|
||||||
import org.jclouds.rackspace.cloudservers.compute.functions.CloudServersImageToOperatingSystem;
|
|
||||||
import org.jclouds.rackspace.cloudservers.compute.functions.FlavorToHardware;
|
|
||||||
import org.jclouds.rackspace.cloudservers.compute.functions.ServerToNodeMetadata;
|
|
||||||
import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersAddNodeWithTagStrategy;
|
import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersAddNodeWithTagStrategy;
|
||||||
import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersDestroyNodeStrategy;
|
import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersDestroyNodeStrategy;
|
||||||
import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersGetNodeMetadataStrategy;
|
import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersGetNodeMetadataStrategy;
|
||||||
|
@ -56,22 +41,10 @@ import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersListNodes
|
||||||
import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersRebootNodeStrategy;
|
import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersRebootNodeStrategy;
|
||||||
import org.jclouds.rackspace.cloudservers.compute.suppliers.CloudServersHardwareSupplier;
|
import org.jclouds.rackspace.cloudservers.compute.suppliers.CloudServersHardwareSupplier;
|
||||||
import org.jclouds.rackspace.cloudservers.compute.suppliers.CloudServersImageSupplier;
|
import org.jclouds.rackspace.cloudservers.compute.suppliers.CloudServersImageSupplier;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.Flavor;
|
import org.jclouds.rackspace.config.RackspaceLocationsSupplier;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.Server;
|
|
||||||
import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
|
|
||||||
import org.jclouds.rackspace.config.RackspaceLocationsModule;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Provides;
|
|
||||||
import com.google.inject.Scopes;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link CloudServersComputeServiceContext}; requires {@link BaseComputeService}
|
* Configures the {@link CloudServersComputeServiceContext}; requires {@link BaseComputeService}
|
||||||
|
@ -83,32 +56,8 @@ public class CloudServersComputeServiceContextModule extends BaseComputeServiceC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new ComputeServiceTimeoutsModule());
|
install(new CloudServersComputeServiceDependenciesModule());
|
||||||
install(new RackspaceLocationsModule());
|
super.configure();
|
||||||
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
|
||||||
}).to(ServerToNodeMetadata.class);
|
|
||||||
|
|
||||||
bind(new TypeLiteral<Function<org.jclouds.rackspace.cloudservers.domain.Image, Image>>() {
|
|
||||||
}).to(CloudServersImageToImage.class);
|
|
||||||
|
|
||||||
bind(new TypeLiteral<Function<org.jclouds.rackspace.cloudservers.domain.Image, OperatingSystem>>() {
|
|
||||||
}).to(CloudServersImageToOperatingSystem.class);
|
|
||||||
|
|
||||||
bind(new TypeLiteral<Function<Flavor, Hardware>>() {
|
|
||||||
}).to(FlavorToHardware.class);
|
|
||||||
|
|
||||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
|
||||||
}).to(new TypeLiteral<ComputeServiceContextImpl<CloudServersClient, CloudServersAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
bind(new TypeLiteral<RestContext<CloudServersClient, CloudServersAsyncClient>>() {
|
|
||||||
}).to(new TypeLiteral<RestContextImpl<CloudServersClient, CloudServersAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
bind(AddNodeWithTagStrategy.class).to(CloudServersAddNodeWithTagStrategy.class);
|
|
||||||
bind(ListNodesStrategy.class).to(CloudServersListNodesStrategy.class);
|
|
||||||
bind(GetNodeMetadataStrategy.class).to(CloudServersGetNodeMetadataStrategy.class);
|
|
||||||
bind(RebootNodeStrategy.class).to(CloudServersRebootNodeStrategy.class);
|
|
||||||
bind(DestroyNodeStrategy.class).to(CloudServersDestroyNodeStrategy.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -116,46 +65,43 @@ public class CloudServersComputeServiceContextModule extends BaseComputeServiceC
|
||||||
return template.osFamily(UBUNTU).imageNameMatches(".*10\\.?04.*");
|
return template.osFamily(UBUNTU).imageNameMatches(".*10\\.?04.*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@Override
|
||||||
public static final Map<ServerStatus, NodeState> serverToNodeState = ImmutableMap
|
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
|
||||||
.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)//
|
return CloudServersAddNodeWithTagStrategy.class;
|
||||||
.put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)//
|
|
||||||
.put(ServerStatus.DELETED, NodeState.TERMINATED)//
|
|
||||||
.put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.PREP_RESIZE, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.RESIZE, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.PREP_MOVE, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.MOVE, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.RESCUE, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.ERROR, NodeState.ERROR)//
|
|
||||||
.put(ServerStatus.BUILD, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.RESTORING, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.PASSWORD, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.REBUILD, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.DELETE_IP, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.SHARE_IP, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.REBOOT, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.HARD_REBOOT, NodeState.PENDING)//
|
|
||||||
.put(ServerStatus.UNKNOWN, NodeState.UNRECOGNIZED)//
|
|
||||||
.put(ServerStatus.UNRECOGNIZED, NodeState.UNRECOGNIZED).build();
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
Map<ServerStatus, NodeState> provideServerToNodeState() {
|
|
||||||
return serverToNodeState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
|
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||||
return injector.getInstance(CloudServersImageSupplier.class);
|
return CloudServersDestroyNodeStrategy.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
|
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||||
return injector.getInstance(CloudServersHardwareSupplier.class);
|
return CloudServersGetNodeMetadataStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||||
|
return CloudServersHardwareSupplier.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||||
|
return CloudServersImageSupplier.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||||
|
return CloudServersListNodesStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||||
|
return CloudServersRebootNodeStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||||
|
return RackspaceLocationsSupplier.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.rackspace.cloudservers.compute.config;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.NodeState;
|
||||||
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
|
import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient;
|
||||||
|
import org.jclouds.rackspace.cloudservers.CloudServersClient;
|
||||||
|
import org.jclouds.rackspace.cloudservers.compute.functions.CloudServersImageToImage;
|
||||||
|
import org.jclouds.rackspace.cloudservers.compute.functions.CloudServersImageToOperatingSystem;
|
||||||
|
import org.jclouds.rackspace.cloudservers.compute.functions.FlavorToHardware;
|
||||||
|
import org.jclouds.rackspace.cloudservers.compute.functions.ServerToNodeMetadata;
|
||||||
|
import org.jclouds.rackspace.cloudservers.domain.Flavor;
|
||||||
|
import org.jclouds.rackspace.cloudservers.domain.Server;
|
||||||
|
import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the {@link CloudServersComputeServiceContext}; requires {@link BaseComputeService}
|
||||||
|
* bound.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class CloudServersComputeServiceDependenciesModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
||||||
|
}).to(ServerToNodeMetadata.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<org.jclouds.rackspace.cloudservers.domain.Image, Image>>() {
|
||||||
|
}).to(CloudServersImageToImage.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<org.jclouds.rackspace.cloudservers.domain.Image, OperatingSystem>>() {
|
||||||
|
}).to(CloudServersImageToOperatingSystem.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<Flavor, Hardware>>() {
|
||||||
|
}).to(FlavorToHardware.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
|
}).to(new TypeLiteral<ComputeServiceContextImpl<CloudServersClient, CloudServersAsyncClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
|
bind(new TypeLiteral<RestContext<CloudServersClient, CloudServersAsyncClient>>() {
|
||||||
|
}).to(new TypeLiteral<RestContextImpl<CloudServersClient, CloudServersAsyncClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public static final Map<ServerStatus, NodeState> serverToNodeState = ImmutableMap
|
||||||
|
.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)//
|
||||||
|
.put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)//
|
||||||
|
.put(ServerStatus.DELETED, NodeState.TERMINATED)//
|
||||||
|
.put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.PREP_RESIZE, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.RESIZE, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.PREP_MOVE, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.MOVE, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.RESCUE, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.ERROR, NodeState.ERROR)//
|
||||||
|
.put(ServerStatus.BUILD, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.RESTORING, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.PASSWORD, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.REBUILD, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.DELETE_IP, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.SHARE_IP, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.REBOOT, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.HARD_REBOOT, NodeState.PENDING)//
|
||||||
|
.put(ServerStatus.UNKNOWN, NodeState.UNRECOGNIZED)//
|
||||||
|
.put(ServerStatus.UNRECOGNIZED, NodeState.UNRECOGNIZED).build();
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Map<ServerStatus, NodeState> provideServerToNodeState() {
|
||||||
|
return serverToNodeState;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
@ -91,7 +92,8 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ServerToNodeMetadata(Map<ServerStatus, NodeState> serverStateToNodeState, Map<String, Credentials> credentialStore,
|
ServerToNodeMetadata(Map<ServerStatus, NodeState> serverStateToNodeState, Map<String, Credentials> credentialStore,
|
||||||
Supplier<Set<? extends Image>> images, Supplier<Location> location, Supplier<Set<? extends Hardware>> hardwares) {
|
@Memoized Supplier<Set<? extends Image>> images, Supplier<Location> location,
|
||||||
|
@Memoized Supplier<Set<? extends Hardware>> hardwares) {
|
||||||
this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
this.serverToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
||||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
|
|
|
@ -21,31 +21,32 @@ package org.jclouds.rackspace.config;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
import org.jclouds.rest.annotations.Provider;
|
import org.jclouds.rest.annotations.Provider;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the locations used in Rackspace services
|
* Configures the locations used in Rackspace services
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class RackspaceLocationsModule extends AbstractModule {
|
public class RackspaceLocationsSupplier implements Supplier<Set<? extends Location>> {
|
||||||
|
|
||||||
@Override
|
private final String providerName;
|
||||||
protected void configure() {
|
|
||||||
|
@Inject
|
||||||
|
RackspaceLocationsSupplier(@Provider String providerName) {
|
||||||
|
this.providerName = providerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Override
|
||||||
@Singleton
|
public Set<? extends Location> get() {
|
||||||
Set<? extends Location> provideLocations(@Provider String providerName) {
|
|
||||||
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
||||||
return ImmutableSet.of(new LocationImpl(LocationScope.ZONE, "DFW1", "Dallas, TX", provider));
|
return ImmutableSet.of(new LocationImpl(LocationScope.ZONE, "DFW1", "Dallas, TX", provider));
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ public class CloudServersComputeServiceContextModuleTest {
|
||||||
public void testAllStatusCovered() {
|
public void testAllStatusCovered() {
|
||||||
|
|
||||||
for (ServerStatus state : ServerStatus.values()) {
|
for (ServerStatus state : ServerStatus.values()) {
|
||||||
assert CloudServersComputeServiceContextModule.serverToNodeState.containsKey(state) : state;
|
assert CloudServersComputeServiceDependenciesModule.serverToNodeState.containsKey(state) : state;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
import org.jclouds.rackspace.cloudservers.compute.config.CloudServersComputeServiceContextModule;
|
import org.jclouds.rackspace.cloudservers.compute.config.CloudServersComputeServiceDependenciesModule;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.Server;
|
import org.jclouds.rackspace.cloudservers.domain.Server;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
|
import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
|
||||||
import org.jclouds.rackspace.cloudservers.functions.ParseServerFromJsonResponseTest;
|
import org.jclouds.rackspace.cloudservers.functions.ParseServerFromJsonResponseTest;
|
||||||
|
@ -59,148 +59,104 @@ public class ServerToNodeMetadataTest {
|
||||||
Location provider = new LocationImpl(LocationScope.ZONE, "dallas", "description", null);
|
Location provider = new LocationImpl(LocationScope.ZONE, "dallas", "description", null);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound()
|
public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound() throws UnknownHostException {
|
||||||
throws UnknownHostException {
|
|
||||||
Credentials creds = new Credentials("root", "abdce");
|
Credentials creds = new Credentials("root", "abdce");
|
||||||
|
|
||||||
Map<ServerStatus, NodeState> serverStateToNodeState = CloudServersComputeServiceContextModule.serverToNodeState;
|
Map<ServerStatus, NodeState> serverStateToNodeState = CloudServersComputeServiceDependenciesModule.serverToNodeState;
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||||
Server server = ParseServerFromJsonResponseTest.parseServer();
|
Server server = ParseServerFromJsonResponseTest.parseServer();
|
||||||
|
|
||||||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState,
|
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
||||||
ImmutableMap.<String, Credentials> of("1234", creds), Suppliers.<Set<? extends Image>> ofInstance(images),
|
.<String, Credentials> of("1234", creds), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||||
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(server);
|
NodeMetadata metadata = parser.apply(server);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||||
metadata,
|
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")).tag(
|
||||||
new NodeMetadataBuilder()
|
"NOTAG-sample-server").imageId("2").id("1234").providerId("1234").name("sample-server").credentials(
|
||||||
.state(NodeState.PENDING)
|
creds).location(
|
||||||
.publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131"))
|
|
||||||
.privateAddresses(ImmutableSet.of("10.176.42.16"))
|
|
||||||
.tag("NOTAG-sample-server")
|
|
||||||
.imageId("2")
|
|
||||||
.id("1234")
|
|
||||||
.providerId("1234")
|
|
||||||
.name("sample-server")
|
|
||||||
.credentials(creds)
|
|
||||||
.location(
|
|
||||||
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
|
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
|
||||||
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
|
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
|
||||||
"description", null)))
|
"description", null))).userMetadata(
|
||||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException {
|
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException {
|
||||||
Map<ServerStatus, NodeState> serverStateToNodeState = CloudServersComputeServiceContextModule.serverToNodeState;
|
Map<ServerStatus, NodeState> serverStateToNodeState = CloudServersComputeServiceDependenciesModule.serverToNodeState;
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||||
Server server = ParseServerFromJsonResponseTest.parseServer();
|
Server server = ParseServerFromJsonResponseTest.parseServer();
|
||||||
|
|
||||||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState,
|
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
||||||
ImmutableMap.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images),
|
.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||||
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(server);
|
NodeMetadata metadata = parser.apply(server);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||||
metadata,
|
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")).tag(
|
||||||
new NodeMetadataBuilder()
|
"NOTAG-sample-server").imageId("2").id("1234").providerId("1234").name("sample-server").location(
|
||||||
.state(NodeState.PENDING)
|
|
||||||
.publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131"))
|
|
||||||
.privateAddresses(ImmutableSet.of("10.176.42.16"))
|
|
||||||
.tag("NOTAG-sample-server")
|
|
||||||
.imageId("2")
|
|
||||||
.id("1234")
|
|
||||||
.providerId("1234")
|
|
||||||
.name("sample-server")
|
|
||||||
.location(
|
|
||||||
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
|
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
|
||||||
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
|
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
|
||||||
"description", null)))
|
"description", null))).userMetadata(
|
||||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException {
|
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException {
|
||||||
Map<ServerStatus, NodeState> serverStateToNodeState = CloudServersComputeServiceContextModule.serverToNodeState;
|
Map<ServerStatus, NodeState> serverStateToNodeState = CloudServersComputeServiceDependenciesModule.serverToNodeState;
|
||||||
org.jclouds.compute.domain.Image jcImage = CloudServersImageToImageTest.convertImage();
|
org.jclouds.compute.domain.Image jcImage = CloudServersImageToImageTest.convertImage();
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||||
Server server = ParseServerFromJsonResponseTest.parseServer();
|
Server server = ParseServerFromJsonResponseTest.parseServer();
|
||||||
|
|
||||||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState,
|
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
||||||
ImmutableMap.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images),
|
.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||||
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(server);
|
NodeMetadata metadata = parser.apply(server);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||||
metadata,
|
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")).tag(
|
||||||
new NodeMetadataBuilder()
|
"NOTAG-sample-server").imageId("2").operatingSystem(
|
||||||
.state(NodeState.PENDING)
|
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true).build())
|
||||||
.publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131"))
|
.id("1234").providerId("1234").name("sample-server").location(
|
||||||
.privateAddresses(ImmutableSet.of("10.176.42.16"))
|
|
||||||
.tag("NOTAG-sample-server")
|
|
||||||
.imageId("2")
|
|
||||||
.operatingSystem(
|
|
||||||
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true)
|
|
||||||
.build())
|
|
||||||
.id("1234")
|
|
||||||
.providerId("1234")
|
|
||||||
.name("sample-server")
|
|
||||||
.location(
|
|
||||||
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
|
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
|
||||||
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
|
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
|
||||||
"description", null)))
|
"description", null))).userMetadata(
|
||||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException {
|
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException {
|
||||||
Map<ServerStatus, NodeState> serverStateToNodeState = CloudServersComputeServiceContextModule.serverToNodeState;
|
Map<ServerStatus, NodeState> serverStateToNodeState = CloudServersComputeServiceDependenciesModule.serverToNodeState;
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(CloudServersImageToImageTest.convertImage());
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(CloudServersImageToImageTest.convertImage());
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
|
||||||
Server server = ParseServerFromJsonResponseTest.parseServer();
|
Server server = ParseServerFromJsonResponseTest.parseServer();
|
||||||
|
|
||||||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState,
|
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, ImmutableMap
|
||||||
ImmutableMap.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images),
|
.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||||
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(server);
|
NodeMetadata metadata = parser.apply(server);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||||
metadata,
|
ImmutableSet.of("67.23.10.132", "67.23.10.131")).privateAddresses(ImmutableSet.of("10.176.42.16")).tag(
|
||||||
new NodeMetadataBuilder()
|
"NOTAG-sample-server").imageId("2").hardware(
|
||||||
.state(NodeState.PENDING)
|
new HardwareBuilder().ids("1").name("256 MB Server").processors(
|
||||||
.publicAddresses(ImmutableSet.of("67.23.10.132", "67.23.10.131"))
|
ImmutableList.of(new Processor(1.0, 1.0))).ram(256).volumes(
|
||||||
.privateAddresses(ImmutableSet.of("10.176.42.16"))
|
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true)
|
||||||
.tag("NOTAG-sample-server")
|
.bootDevice(true).build())).build()).operatingSystem(
|
||||||
.imageId("2")
|
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true).build())
|
||||||
.hardware(
|
.id("1234").providerId("1234").name("sample-server").location(
|
||||||
new HardwareBuilder()
|
|
||||||
.ids("1")
|
|
||||||
.name("256 MB Server")
|
|
||||||
.processors(ImmutableList.of(new Processor(1.0, 1.0)))
|
|
||||||
.ram(256)
|
|
||||||
.volumes(
|
|
||||||
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f)
|
|
||||||
.durable(true).bootDevice(true).build())).build())
|
|
||||||
.operatingSystem(
|
|
||||||
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true)
|
|
||||||
.build())
|
|
||||||
.id("1234")
|
|
||||||
.providerId("1234")
|
|
||||||
.name("sample-server")
|
|
||||||
.location(
|
|
||||||
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
|
new LocationImpl(LocationScope.HOST, "e4d909c290d0fb1ca068ffaddf22cbd0",
|
||||||
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
|
"e4d909c290d0fb1ca068ffaddf22cbd0", new LocationImpl(LocationScope.ZONE, "dallas",
|
||||||
"description", null)))
|
"description", null))).userMetadata(
|
||||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,61 +20,31 @@
|
||||||
package org.jclouds.rimuhosting.miro.compute.config;
|
package org.jclouds.rimuhosting.miro.compute.config;
|
||||||
|
|
||||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||||
import static org.jclouds.rimuhosting.miro.reference.RimuHostingConstants.PROPERTY_RIMUHOSTING_DEFAULT_DC;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
|
||||||
import org.jclouds.compute.LoadBalancerService;
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
|
||||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.jclouds.rimuhosting.miro.RimuHostingAsyncClient;
|
|
||||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
|
||||||
import org.jclouds.rimuhosting.miro.compute.functions.ServerToNodeMetadata;
|
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingAddNodeWithTagStrategy;
|
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingAddNodeWithTagStrategy;
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingDestroyNodeStrategy;
|
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingDestroyNodeStrategy;
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingGetNodeMetadataStrategy;
|
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingGetNodeMetadataStrategy;
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingListNodesStrategy;
|
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingListNodesStrategy;
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingRebootNodeStrategy;
|
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingRebootNodeStrategy;
|
||||||
|
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingDefaultLocationSupplier;
|
||||||
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingHardwareSupplier;
|
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingHardwareSupplier;
|
||||||
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingImageSupplier;
|
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingImageSupplier;
|
||||||
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingLocationSupplier;
|
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingLocationSupplier;
|
||||||
import org.jclouds.rimuhosting.miro.domain.Server;
|
|
||||||
import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
|
|
||||||
|
|
||||||
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.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.Iterables;
|
|
||||||
import com.google.inject.Injector;
|
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;
|
|
||||||
import com.google.inject.name.Names;
|
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link RimuHostingComputeServiceContext}; requires
|
* Configures the {@link RimuHostingComputeServiceContext}; requires
|
||||||
|
@ -86,23 +56,8 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new ComputeServiceTimeoutsModule());
|
install(new RimuHostingComputeServiceDependenciesModule());
|
||||||
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
super.configure();
|
||||||
}).to(ServerToNodeMetadata.class);
|
|
||||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
|
||||||
}).to(new TypeLiteral<ComputeServiceContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
bind(new TypeLiteral<RestContext<RimuHostingClient, RimuHostingAsyncClient>>() {
|
|
||||||
}).to(new TypeLiteral<RestContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
bind(new TypeLiteral<Function<Server, Iterable<String>>>() {
|
|
||||||
}).to(ServerToPublicAddresses.class);
|
|
||||||
bind(AddNodeWithTagStrategy.class).to(RimuHostingAddNodeWithTagStrategy.class);
|
|
||||||
bind(ListNodesStrategy.class).to(RimuHostingListNodesStrategy.class);
|
|
||||||
bind(GetNodeMetadataStrategy.class).to(RimuHostingGetNodeMetadataStrategy.class);
|
|
||||||
bind(RebootNodeStrategy.class).to(RimuHostingRebootNodeStrategy.class);
|
|
||||||
bind(DestroyNodeStrategy.class).to(RimuHostingDestroyNodeStrategy.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -110,64 +65,49 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo
|
||||||
return template.hardwareId("MIRO1B").osFamily(UBUNTU).os64Bit(false).imageNameMatches(".*10\\.?04.*");
|
return template.hardwareId("MIRO1B").osFamily(UBUNTU).os64Bit(false).imageNameMatches(".*10\\.?04.*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final Map<RunningState, NodeState> runningStateToNodeState = ImmutableMap.<RunningState, NodeState> builder()
|
|
||||||
.put(RunningState.RUNNING, NodeState.RUNNING)//
|
|
||||||
.put(RunningState.NOTRUNNING, NodeState.SUSPENDED)//
|
|
||||||
.put(RunningState.POWERCYCLING, NodeState.PENDING)//
|
|
||||||
.put(RunningState.RESTARTING, NodeState.PENDING)//
|
|
||||||
.put(RunningState.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
|
||||||
.build();
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
Map<RunningState, NodeState> provideServerToNodeState() {
|
|
||||||
return runningStateToNodeState;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
private static class ServerToPublicAddresses implements Function<Server, Iterable<String>> {
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<String> apply(Server server) {
|
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
|
||||||
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(ImmutableList.of(server
|
return RimuHostingAddNodeWithTagStrategy.class;
|
||||||
.getIpAddresses().getPrimaryIp()), server.getIpAddresses().getSecondaryIps());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Location> supplyDefaultLocation(Injector injector, Supplier<Set<? extends Location>> locations) {
|
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||||
final String defaultDC = injector
|
return RimuHostingDestroyNodeStrategy.class;
|
||||||
.getInstance(Key.get(String.class, Names.named(PROPERTY_RIMUHOSTING_DEFAULT_DC)));
|
|
||||||
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.getId().equals(defaultDC);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}, locations);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
|
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||||
return injector.getInstance(RimuHostingImageSupplier.class);
|
return RimuHostingGetNodeMetadataStrategy.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
|
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||||
return injector.getInstance(RimuHostingLocationSupplier.class);
|
return RimuHostingHardwareSupplier.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
|
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||||
return injector.getInstance(RimuHostingHardwareSupplier.class);
|
return RimuHostingImageSupplier.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||||
|
return RimuHostingListNodesStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||||
|
return RimuHostingRebootNodeStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||||
|
return RimuHostingLocationSupplier.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
|
||||||
|
return RimuHostingDefaultLocationSupplier.class;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.rimuhosting.miro.compute.config;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.NodeState;
|
||||||
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
import org.jclouds.rimuhosting.miro.RimuHostingAsyncClient;
|
||||||
|
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
||||||
|
import org.jclouds.rimuhosting.miro.compute.functions.ServerToNodeMetadata;
|
||||||
|
import org.jclouds.rimuhosting.miro.domain.Server;
|
||||||
|
import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the {@link RimuHostingComputeServiceContext}; requires
|
||||||
|
* {@link RimuHostingComputeService} bound.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class RimuHostingComputeServiceDependenciesModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
||||||
|
}).to(ServerToNodeMetadata.class);
|
||||||
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
|
}).to(new TypeLiteral<ComputeServiceContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
|
bind(new TypeLiteral<RestContext<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||||
|
}).to(new TypeLiteral<RestContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
|
bind(new TypeLiteral<Function<Server, Iterable<String>>>() {
|
||||||
|
}).to(ServerToPublicAddresses.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final Map<RunningState, NodeState> runningStateToNodeState = ImmutableMap.<RunningState, NodeState> builder()
|
||||||
|
.put(RunningState.RUNNING, NodeState.RUNNING)//
|
||||||
|
.put(RunningState.NOTRUNNING, NodeState.SUSPENDED)//
|
||||||
|
.put(RunningState.POWERCYCLING, NodeState.PENDING)//
|
||||||
|
.put(RunningState.RESTARTING, NodeState.PENDING)//
|
||||||
|
.put(RunningState.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
||||||
|
.build();
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Map<RunningState, NodeState> provideServerToNodeState() {
|
||||||
|
return runningStateToNodeState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
private static class ServerToPublicAddresses implements Function<Server, Iterable<String>> {
|
||||||
|
@Override
|
||||||
|
public Iterable<String> apply(Server server) {
|
||||||
|
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(ImmutableList.of(server
|
||||||
|
.getIpAddresses().getPrimaryIp()), server.getIpAddresses().getSecondaryIps());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||||
|
@ -74,15 +75,15 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
return input.getProviderId().equals(instance.getImageId())
|
return input.getProviderId().equals(instance.getImageId())
|
||||||
&& (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation().equals(
|
&& (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation()
|
||||||
location.getParent()));
|
.equals(location.getParent()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ServerToNodeMetadata(Function<Server, Iterable<String>> getPublicAddresses,
|
ServerToNodeMetadata(Function<Server, Iterable<String>> getPublicAddresses,
|
||||||
Map<String, Credentials> credentialStore, Map<RunningState, NodeState> runningStateToNodeState,
|
Map<String, Credentials> credentialStore, Map<RunningState, NodeState> runningStateToNodeState,
|
||||||
Supplier<Set<? extends Image>> images) {
|
@Memoized Supplier<Set<? extends Image>> images) {
|
||||||
this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState");
|
this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState");
|
||||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||||
this.runningStateToNodeState = checkNotNull(runningStateToNodeState, "serverStateToNodeState");
|
this.runningStateToNodeState = checkNotNull(runningStateToNodeState, "serverStateToNodeState");
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.rimuhosting.miro.compute.suppliers;
|
||||||
|
|
||||||
|
import static org.jclouds.rimuhosting.miro.reference.RimuHostingConstants.PROPERTY_RIMUHOSTING_DEFAULT_DC;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class RimuHostingDefaultLocationSupplier implements Supplier<Location> {
|
||||||
|
private final Supplier<Set<? extends Location>> locations;
|
||||||
|
private final String defaultDC;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RimuHostingDefaultLocationSupplier(@Memoized Supplier<Set<? extends Location>> locations,
|
||||||
|
@Named(PROPERTY_RIMUHOSTING_DEFAULT_DC) String defaultDC) {
|
||||||
|
this.locations = locations;
|
||||||
|
this.defaultDC = defaultDC;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location get() {
|
||||||
|
return Iterables.find(locations.get(), new Predicate<Location>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Location input) {
|
||||||
|
return input.getId().equals(defaultDC);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.HardwareBuilder;
|
import org.jclouds.compute.domain.HardwareBuilder;
|
||||||
import org.jclouds.compute.domain.Processor;
|
import org.jclouds.compute.domain.Processor;
|
||||||
|
@ -53,11 +54,12 @@ public class RimuHostingHardwareSupplier implements Supplier<Set<? extends Hardw
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
private RimuHostingClient sync;
|
|
||||||
private Supplier<Set<? extends Location>> locations;
|
private final RimuHostingClient sync;
|
||||||
|
private final Supplier<Set<? extends Location>> locations;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RimuHostingHardwareSupplier(RimuHostingClient sync, Supplier<Set<? extends Location>> locations) {
|
RimuHostingHardwareSupplier(RimuHostingClient sync, @Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
this.sync = sync;
|
this.sync = sync;
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
}
|
}
|
||||||
|
@ -77,9 +79,9 @@ public class RimuHostingHardwareSupplier implements Supplier<Set<? extends Hardw
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
sizes.add(new HardwareBuilder().ids(from.getId()).location(location)
|
sizes.add(new HardwareBuilder().ids(from.getId()).location(location).processors(
|
||||||
.processors(ImmutableList.of(new Processor(1, 1.0))).ram(from.getRam())
|
ImmutableList.of(new Processor(1, 1.0))).ram(from.getRam()).volumes(
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSize(), true, true))).build());
|
ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSize(), true, true))).build());
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
logger.warn("datacenter not present in " + from.getId());
|
logger.warn("datacenter not present in " + from.getId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,11 +46,11 @@ import com.google.common.collect.Sets;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class RimuHostingImageSupplier implements Supplier<Set<? extends Image>> {
|
public class RimuHostingImageSupplier implements Supplier<Set<? extends Image>> {
|
||||||
private RimuHostingClient sync;
|
|
||||||
public static final Pattern RIMU_PATTERN = Pattern.compile("([^0-9]*)(.*)");
|
public static final Pattern RIMU_PATTERN = Pattern.compile("([^0-9]*)(.*)");
|
||||||
|
private final RimuHostingClient sync;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RimuHostingImageSupplier(final RimuHostingClient sync) {
|
RimuHostingImageSupplier(RimuHostingClient sync) {
|
||||||
this.sync = sync;
|
this.sync = sync;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ public class RimuHostingLocationSupplier implements Supplier<Set<? extends Locat
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
private RimuHostingClient sync;
|
private final RimuHostingClient sync;
|
||||||
private String providerName;
|
private final String providerName;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RimuHostingLocationSupplier(RimuHostingClient sync, @Provider String providerName) {
|
RimuHostingLocationSupplier(RimuHostingClient sync, @Provider String providerName) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class RimuHostingComputeServiceContextModuleTest {
|
||||||
public void testAllStatusCovered() {
|
public void testAllStatusCovered() {
|
||||||
|
|
||||||
for (RunningState state : RunningState.values()) {
|
for (RunningState state : RunningState.values()) {
|
||||||
assert RimuHostingComputeServiceContextModule.runningStateToNodeState.containsKey(state) : state;
|
assert RimuHostingComputeServiceDependenciesModule.runningStateToNodeState.containsKey(state) : state;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,25 +19,14 @@
|
||||||
|
|
||||||
package org.jclouds.slicehost.compute.config;
|
package org.jclouds.slicehost.compute.config;
|
||||||
|
|
||||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
|
||||||
import org.jclouds.compute.LoadBalancerService;
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
|
||||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
|
@ -46,15 +35,7 @@ import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.annotations.Provider;
|
import org.jclouds.rest.annotations.Provider;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.jclouds.slicehost.SlicehostAsyncClient;
|
|
||||||
import org.jclouds.slicehost.SlicehostClient;
|
|
||||||
import org.jclouds.slicehost.compute.functions.FlavorToHardware;
|
|
||||||
import org.jclouds.slicehost.compute.functions.SliceToNodeMetadata;
|
|
||||||
import org.jclouds.slicehost.compute.functions.SlicehostImageToImage;
|
|
||||||
import org.jclouds.slicehost.compute.functions.SlicehostImageToOperatingSystem;
|
|
||||||
import org.jclouds.slicehost.compute.strategy.SlicehostAddNodeWithTagStrategy;
|
import org.jclouds.slicehost.compute.strategy.SlicehostAddNodeWithTagStrategy;
|
||||||
import org.jclouds.slicehost.compute.strategy.SlicehostDestroyNodeStrategy;
|
import org.jclouds.slicehost.compute.strategy.SlicehostDestroyNodeStrategy;
|
||||||
import org.jclouds.slicehost.compute.strategy.SlicehostGetNodeMetadataStrategy;
|
import org.jclouds.slicehost.compute.strategy.SlicehostGetNodeMetadataStrategy;
|
||||||
|
@ -62,19 +43,10 @@ import org.jclouds.slicehost.compute.strategy.SlicehostListNodesStrategy;
|
||||||
import org.jclouds.slicehost.compute.strategy.SlicehostRebootNodeStrategy;
|
import org.jclouds.slicehost.compute.strategy.SlicehostRebootNodeStrategy;
|
||||||
import org.jclouds.slicehost.compute.suppliers.SlicehostHardwareSupplier;
|
import org.jclouds.slicehost.compute.suppliers.SlicehostHardwareSupplier;
|
||||||
import org.jclouds.slicehost.compute.suppliers.SlicehostImageSupplier;
|
import org.jclouds.slicehost.compute.suppliers.SlicehostImageSupplier;
|
||||||
import org.jclouds.slicehost.domain.Flavor;
|
|
||||||
import org.jclouds.slicehost.domain.Slice;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Scopes;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link SlicehostComputeServiceContext}; requires {@link BaseComputeService} bound.
|
* Configures the {@link SlicehostComputeServiceContext}; requires {@link BaseComputeService} bound.
|
||||||
|
@ -83,55 +55,6 @@ import com.google.inject.util.Providers;
|
||||||
*/
|
*/
|
||||||
public class SlicehostComputeServiceContextModule extends BaseComputeServiceContextModule {
|
public class SlicehostComputeServiceContextModule extends BaseComputeServiceContextModule {
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
install(new ComputeServiceTimeoutsModule());
|
|
||||||
bind(new TypeLiteral<Function<Slice, NodeMetadata>>() {
|
|
||||||
}).to(SliceToNodeMetadata.class);
|
|
||||||
|
|
||||||
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, Image>>() {
|
|
||||||
}).to(SlicehostImageToImage.class);
|
|
||||||
|
|
||||||
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, OperatingSystem>>() {
|
|
||||||
}).to(SlicehostImageToOperatingSystem.class);
|
|
||||||
bind(new TypeLiteral<Function<Flavor, Hardware>>() {
|
|
||||||
}).to(FlavorToHardware.class);
|
|
||||||
|
|
||||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
|
||||||
}).to(new TypeLiteral<ComputeServiceContextImpl<SlicehostClient, SlicehostAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
bind(new TypeLiteral<RestContext<SlicehostClient, SlicehostAsyncClient>>() {
|
|
||||||
}).to(new TypeLiteral<RestContextImpl<SlicehostClient, SlicehostAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
bind(AddNodeWithTagStrategy.class).to(SlicehostAddNodeWithTagStrategy.class);
|
|
||||||
bind(ListNodesStrategy.class).to(SlicehostListNodesStrategy.class);
|
|
||||||
bind(GetNodeMetadataStrategy.class).to(SlicehostGetNodeMetadataStrategy.class);
|
|
||||||
bind(RebootNodeStrategy.class).to(SlicehostRebootNodeStrategy.class);
|
|
||||||
bind(DestroyNodeStrategy.class).to(SlicehostDestroyNodeStrategy.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
|
||||||
return template.osFamily(UBUNTU).imageNameMatches(".*10\\.?04.*");
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public static final Map<Slice.Status, NodeState> sliceStatusToNodeState = ImmutableMap
|
|
||||||
.<Slice.Status, NodeState> builder().put(Slice.Status.ACTIVE, NodeState.RUNNING)//
|
|
||||||
.put(Slice.Status.BUILD, NodeState.PENDING)//
|
|
||||||
.put(Slice.Status.REBOOT, NodeState.PENDING)//
|
|
||||||
.put(Slice.Status.HARD_REBOOT, NodeState.PENDING)//
|
|
||||||
.put(Slice.Status.TERMINATED, NodeState.TERMINATED)//
|
|
||||||
.put(Slice.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
|
||||||
.build();
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
Map<Slice.Status, NodeState> provideSliceToNodeState() {
|
|
||||||
return sliceStatusToNodeState;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Location getLocation(@Provider String providerName) {
|
Location getLocation(@Provider String providerName) {
|
||||||
|
@ -146,12 +69,43 @@ public class SlicehostComputeServiceContextModule extends BaseComputeServiceCont
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
|
protected void configure() {
|
||||||
return injector.getInstance(SlicehostImageSupplier.class);
|
install(new SlicehostComputeServiceDependenciesModule());
|
||||||
|
super.configure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
|
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
|
||||||
return injector.getInstance(SlicehostHardwareSupplier.class);
|
return SlicehostAddNodeWithTagStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||||
|
return SlicehostDestroyNodeStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||||
|
return SlicehostGetNodeMetadataStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||||
|
return SlicehostHardwareSupplier.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||||
|
return SlicehostImageSupplier.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||||
|
return SlicehostListNodesStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||||
|
return SlicehostRebootNodeStrategy.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.slicehost.compute.config;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.NodeState;
|
||||||
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
import org.jclouds.slicehost.SlicehostAsyncClient;
|
||||||
|
import org.jclouds.slicehost.SlicehostClient;
|
||||||
|
import org.jclouds.slicehost.compute.functions.FlavorToHardware;
|
||||||
|
import org.jclouds.slicehost.compute.functions.SliceToNodeMetadata;
|
||||||
|
import org.jclouds.slicehost.compute.functions.SlicehostImageToImage;
|
||||||
|
import org.jclouds.slicehost.compute.functions.SlicehostImageToOperatingSystem;
|
||||||
|
import org.jclouds.slicehost.domain.Flavor;
|
||||||
|
import org.jclouds.slicehost.domain.Slice;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the {@link SlicehostComputeServiceContext}; requires {@link BaseComputeService} bound.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class SlicehostComputeServiceDependenciesModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(new TypeLiteral<Function<Slice, NodeMetadata>>() {
|
||||||
|
}).to(SliceToNodeMetadata.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, Image>>() {
|
||||||
|
}).to(SlicehostImageToImage.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<org.jclouds.slicehost.domain.Image, OperatingSystem>>() {
|
||||||
|
}).to(SlicehostImageToOperatingSystem.class);
|
||||||
|
bind(new TypeLiteral<Function<Flavor, Hardware>>() {
|
||||||
|
}).to(FlavorToHardware.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
|
}).to(new TypeLiteral<ComputeServiceContextImpl<SlicehostClient, SlicehostAsyncClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
|
bind(new TypeLiteral<RestContext<SlicehostClient, SlicehostAsyncClient>>() {
|
||||||
|
}).to(new TypeLiteral<RestContextImpl<SlicehostClient, SlicehostAsyncClient>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
public static final Map<Slice.Status, NodeState> sliceStatusToNodeState = ImmutableMap
|
||||||
|
.<Slice.Status, NodeState> builder().put(Slice.Status.ACTIVE, NodeState.RUNNING)//
|
||||||
|
.put(Slice.Status.BUILD, NodeState.PENDING)//
|
||||||
|
.put(Slice.Status.REBOOT, NodeState.PENDING)//
|
||||||
|
.put(Slice.Status.HARD_REBOOT, NodeState.PENDING)//
|
||||||
|
.put(Slice.Status.TERMINATED, NodeState.TERMINATED)//
|
||||||
|
.put(Slice.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
|
||||||
|
.build();
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Map<Slice.Status, NodeState> provideSliceToNodeState() {
|
||||||
|
return sliceStatusToNodeState;
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,9 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
@ -48,6 +50,7 @@ import com.google.common.collect.Iterables;
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
|
public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
|
||||||
protected final Supplier<Location> location;
|
protected final Supplier<Location> location;
|
||||||
protected final Map<Slice.Status, NodeState> sliceToNodeState;
|
protected final Map<Slice.Status, NodeState> sliceToNodeState;
|
||||||
|
@ -86,7 +89,8 @@ public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SliceToNodeMetadata(Map<Slice.Status, NodeState> sliceStateToNodeState, Map<String, Credentials> credentialStore,
|
SliceToNodeMetadata(Map<Slice.Status, NodeState> sliceStateToNodeState, Map<String, Credentials> credentialStore,
|
||||||
Supplier<Set<? extends Image>> images, Supplier<Location> location, Supplier<Set<? extends Hardware>> hardwares) {
|
@Memoized Supplier<Set<? extends Image>> images, Supplier<Location> location,
|
||||||
|
@Memoized Supplier<Set<? extends Hardware>> hardwares) {
|
||||||
this.sliceToNodeState = checkNotNull(sliceStateToNodeState, "sliceStateToNodeState");
|
this.sliceToNodeState = checkNotNull(sliceStateToNodeState, "sliceStateToNodeState");
|
||||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class SlicehostComputeServiceContextModuleTest {
|
||||||
public void testAllStatusCovered() {
|
public void testAllStatusCovered() {
|
||||||
|
|
||||||
for (Slice.Status state : Slice.Status.values()) {
|
for (Slice.Status state : Slice.Status.values()) {
|
||||||
assert SlicehostComputeServiceContextModule.sliceStatusToNodeState.containsKey(state) : state;
|
assert SlicehostComputeServiceDependenciesModule.sliceStatusToNodeState.containsKey(state) : state;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
import org.jclouds.slicehost.compute.config.SlicehostComputeServiceContextModule;
|
import org.jclouds.slicehost.compute.config.SlicehostComputeServiceDependenciesModule;
|
||||||
import org.jclouds.slicehost.domain.Slice;
|
import org.jclouds.slicehost.domain.Slice;
|
||||||
import org.jclouds.slicehost.xml.SliceHandlerTest;
|
import org.jclouds.slicehost.xml.SliceHandlerTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -60,105 +60,84 @@ public class SliceToNodeMetadataTest {
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound() throws UnknownHostException {
|
public void testApplyWhereImageAndHardwareNotFoundButCredentialsFound() throws UnknownHostException {
|
||||||
Credentials creds = new Credentials("root", "abdce");
|
Credentials creds = new Credentials("root", "abdce");
|
||||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceContextModule.sliceStatusToNodeState;
|
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceDependenciesModule.sliceStatusToNodeState;
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||||
Slice slice = SliceHandlerTest.parseSlice();
|
Slice slice = SliceHandlerTest.parseSlice();
|
||||||
|
|
||||||
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState,
|
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState, ImmutableMap
|
||||||
ImmutableMap.<String, Credentials> of("1", creds), Suppliers.<Set<? extends Image>> ofInstance(images),
|
.<String, Credentials> of("1", creds), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||||
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(slice);
|
NodeMetadata metadata = parser.apply(slice);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||||
metadata,
|
ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).tag("jclouds")
|
||||||
new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(ImmutableSet.of("174.143.212.229"))
|
.imageId("2").id("1").providerId("1").name("jclouds-foo").location(provider).credentials(creds)
|
||||||
.privateAddresses(ImmutableSet.of("10.176.164.199")).tag("jclouds").imageId("2").id("1")
|
|
||||||
.providerId("1").name("jclouds-foo").location(provider).credentials(creds)
|
|
||||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException {
|
public void testApplyWhereImageAndHardwareNotFound() throws UnknownHostException {
|
||||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceContextModule.sliceStatusToNodeState;
|
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceDependenciesModule.sliceStatusToNodeState;
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of();
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||||
Slice slice = SliceHandlerTest.parseSlice();
|
Slice slice = SliceHandlerTest.parseSlice();
|
||||||
|
|
||||||
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState,
|
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState, ImmutableMap
|
||||||
ImmutableMap.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images),
|
.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||||
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(slice);
|
NodeMetadata metadata = parser.apply(slice);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||||
metadata,
|
ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).tag("jclouds")
|
||||||
new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(ImmutableSet.of("174.143.212.229"))
|
.imageId("2").id("1").providerId("1").name("jclouds-foo").location(provider).userMetadata(
|
||||||
.privateAddresses(ImmutableSet.of("10.176.164.199")).tag("jclouds").imageId("2").id("1")
|
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||||
.providerId("1").name("jclouds-foo").location(provider)
|
|
||||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException {
|
public void testApplyWhereImageFoundAndHardwareNotFound() throws UnknownHostException {
|
||||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceContextModule.sliceStatusToNodeState;
|
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceDependenciesModule.sliceStatusToNodeState;
|
||||||
org.jclouds.compute.domain.Image jcImage = SlicehostImageToImageTest.convertImage();
|
org.jclouds.compute.domain.Image jcImage = SlicehostImageToImageTest.convertImage();
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage);
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
|
||||||
Slice slice = SliceHandlerTest.parseSlice();
|
Slice slice = SliceHandlerTest.parseSlice();
|
||||||
|
|
||||||
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState,
|
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState, ImmutableMap
|
||||||
ImmutableMap.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images),
|
.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||||
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(slice);
|
NodeMetadata metadata = parser.apply(slice);
|
||||||
assertEquals(
|
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||||
metadata,
|
ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).tag("jclouds")
|
||||||
new NodeMetadataBuilder()
|
.imageId("2").operatingSystem(
|
||||||
.state(NodeState.PENDING)
|
|
||||||
.publicAddresses(ImmutableSet.of("174.143.212.229"))
|
|
||||||
.privateAddresses(ImmutableSet.of("10.176.164.199"))
|
|
||||||
.tag("jclouds")
|
|
||||||
.imageId("2")
|
|
||||||
.operatingSystem(
|
|
||||||
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true)
|
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true)
|
||||||
.build()).id("1").providerId("1").name("jclouds-foo").location(provider)
|
.build()).id("1").providerId("1").name("jclouds-foo").location(provider).userMetadata(
|
||||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException {
|
public void testApplyWhereImageAndHardwareFound() throws UnknownHostException {
|
||||||
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceContextModule.sliceStatusToNodeState;
|
Map<Slice.Status, NodeState> sliceStateToNodeState = SlicehostComputeServiceDependenciesModule.sliceStatusToNodeState;
|
||||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(SlicehostImageToImageTest.convertImage());
|
Set<org.jclouds.compute.domain.Image> images = ImmutableSet.of(SlicehostImageToImageTest.convertImage());
|
||||||
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
|
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of(FlavorToHardwareTest.convertFlavor());
|
||||||
Slice slice = SliceHandlerTest.parseSlice();
|
Slice slice = SliceHandlerTest.parseSlice();
|
||||||
|
|
||||||
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState,
|
SliceToNodeMetadata parser = new SliceToNodeMetadata(sliceStateToNodeState, ImmutableMap
|
||||||
ImmutableMap.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images),
|
.<String, Credentials> of(), Suppliers.<Set<? extends Image>> ofInstance(images), Suppliers
|
||||||
Suppliers.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
.ofInstance(provider), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares));
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(slice);
|
NodeMetadata metadata = parser.apply(slice);
|
||||||
assertEquals(
|
assertEquals(metadata, new NodeMetadataBuilder().state(NodeState.PENDING).publicAddresses(
|
||||||
metadata,
|
ImmutableSet.of("174.143.212.229")).privateAddresses(ImmutableSet.of("10.176.164.199")).tag("jclouds")
|
||||||
new NodeMetadataBuilder()
|
.imageId("2").hardware(
|
||||||
.state(NodeState.PENDING)
|
new HardwareBuilder().ids("1").name("256 slice").processors(
|
||||||
.publicAddresses(ImmutableSet.of("174.143.212.229"))
|
ImmutableList.of(new Processor(0.25, 1.0))).ram(256).volumes(
|
||||||
.privateAddresses(ImmutableSet.of("10.176.164.199"))
|
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(1.0f).durable(true)
|
||||||
.tag("jclouds")
|
.bootDevice(true).build())).build()).operatingSystem(
|
||||||
.imageId("2")
|
|
||||||
.hardware(
|
|
||||||
new HardwareBuilder()
|
|
||||||
.ids("1")
|
|
||||||
.name("256 slice")
|
|
||||||
.processors(ImmutableList.of(new Processor(0.25, 1.0)))
|
|
||||||
.ram(256)
|
|
||||||
.volumes(
|
|
||||||
ImmutableList.of(new VolumeBuilder().type(Volume.Type.LOCAL).size(1.0f)
|
|
||||||
.durable(true).bootDevice(true).build())).build())
|
|
||||||
.operatingSystem(
|
|
||||||
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true)
|
new OperatingSystemBuilder().family(OsFamily.CENTOS).description("CentOS 5.2").is64Bit(true)
|
||||||
.build()).id("1").providerId("1").name("jclouds-foo").location(provider)
|
.build()).id("1").providerId("1").name("jclouds-foo").location(provider).userMetadata(
|
||||||
.userMetadata(ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
ImmutableMap.of("Server Label", "Web Head 1", "Image Version", "2.1")).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,9 +24,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.compute.LoadBalancerService;
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeState;
|
import org.jclouds.compute.domain.NodeState;
|
||||||
|
@ -41,9 +39,7 @@ import org.jclouds.vcloud.domain.Status;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
|
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
|
||||||
|
@ -70,28 +66,26 @@ public abstract class CommonVCloudComputeServiceContextModule extends BaseComput
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new ComputeServiceTimeoutsModule());
|
super.configure();
|
||||||
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
|
|
||||||
bindLoadBalancer();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void bindLoadBalancer() {
|
|
||||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
|
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() {
|
||||||
return injector.getInstance(StaticHardwareSupplier.class);
|
return EncodeTagIntoNameRunNodesAndAddToSetStrategy.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
|
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||||
return injector.getInstance(OrgAndVDCToLocationSupplier.class);
|
return StaticHardwareSupplier.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
|
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||||
return injector.getInstance(VCloudImageSupplier.class);
|
return VCloudImageSupplier.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
|
||||||
|
return OrgAndVDCToLocationSupplier.class;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,6 @@ import org.jclouds.vcloud.domain.VApp;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
@ -74,11 +73,9 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic
|
||||||
}).to(VAppToNodeMetadata.class);
|
}).to(VAppToNodeMetadata.class);
|
||||||
bind(TemplateOptions.class).to(VCloudTemplateOptions.class);
|
bind(TemplateOptions.class).to(VCloudTemplateOptions.class);
|
||||||
bind(TemplateBuilder.class).to(VCloudTemplateBuilderImpl.class);
|
bind(TemplateBuilder.class).to(VCloudTemplateBuilderImpl.class);
|
||||||
bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class);
|
|
||||||
bind(new TypeLiteral<Function<VApp, Hardware>>() {
|
bind(new TypeLiteral<Function<VApp, Hardware>>() {
|
||||||
}).to(new TypeLiteral<HardwareForVApp>() {
|
}).to(new TypeLiteral<HardwareForVApp>() {
|
||||||
});
|
});
|
||||||
bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class);
|
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudClient, VCloudClient>>() {
|
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudClient, VCloudClient>>() {
|
||||||
}).in(Scopes.SINGLETON);
|
}).in(Scopes.SINGLETON);
|
||||||
|
@ -91,15 +88,36 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic
|
||||||
bind(new TypeLiteral<Function<Org, Iterable<? extends Hardware>>>() {
|
bind(new TypeLiteral<Function<Org, Iterable<? extends Hardware>>>() {
|
||||||
}).to(new TypeLiteral<HardwareInOrg>() {
|
}).to(new TypeLiteral<HardwareInOrg>() {
|
||||||
});
|
});
|
||||||
bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class);
|
|
||||||
bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class);
|
|
||||||
bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(GetLoginCredentialsFromGuestConfiguration.class);
|
bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(GetLoginCredentialsFromGuestConfiguration.class);
|
||||||
bind(DestroyNodeStrategy.class).to(VCloudDestroyNodeStrategy.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
|
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
||||||
return injector.getInstance(VCloudHardwareSupplier.class);
|
return VCloudHardwareSupplier.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
|
||||||
|
return VCloudAddNodeWithTagStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||||
|
return VCloudDestroyNodeStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||||
|
return VCloudGetNodeMetadataStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||||
|
return VCloudListNodesStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||||
|
return VCloudRebootNodeStrategy.class;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,10 +62,7 @@ public class VCloudExpressComputeServiceContextModule extends CommonVCloudComput
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
bind(RebootNodeStrategy.class).to(VCloudExpressRebootNodeStrategy.class);
|
bindVAppConverter();
|
||||||
bind(GetNodeMetadataStrategy.class).to(VCloudExpressGetNodeMetadataStrategy.class);
|
|
||||||
bind(new TypeLiteral<Function<VCloudExpressVApp, NodeMetadata>>() {
|
|
||||||
}).to(VCloudExpressVAppToNodeMetadata.class);
|
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudExpressClient, VCloudExpressClient>>() {
|
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudExpressClient, VCloudExpressClient>>() {
|
||||||
}).in(Scopes.SINGLETON);
|
}).in(Scopes.SINGLETON);
|
||||||
|
@ -75,9 +72,11 @@ public class VCloudExpressComputeServiceContextModule extends CommonVCloudComput
|
||||||
bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() {
|
bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() {
|
||||||
}).to(new TypeLiteral<ImagesInVCloudExpressOrg>() {
|
}).to(new TypeLiteral<ImagesInVCloudExpressOrg>() {
|
||||||
});
|
});
|
||||||
bind(AddNodeWithTagStrategy.class).to(VCloudExpressAddNodeWithTagStrategy.class);
|
}
|
||||||
bind(ListNodesStrategy.class).to(VCloudExpressListNodesStrategy.class);
|
|
||||||
bind(DestroyNodeStrategy.class).to(VCloudExpressDestroyNodeStrategy.class);
|
protected void bindVAppConverter() {
|
||||||
|
bind(new TypeLiteral<Function<VCloudExpressVApp, NodeMetadata>>() {
|
||||||
|
}).to(VCloudExpressVAppToNodeMetadata.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -85,4 +84,29 @@ public class VCloudExpressComputeServiceContextModule extends CommonVCloudComput
|
||||||
CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudExpressComputeClient in) {
|
CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudExpressComputeClient in) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
|
||||||
|
return VCloudExpressAddNodeWithTagStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
||||||
|
return VCloudExpressDestroyNodeStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
||||||
|
return VCloudExpressGetNodeMetadataStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||||
|
return VCloudExpressListNodesStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
||||||
|
return VCloudExpressRebootNodeStrategy.class;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.vcloud.domain.ReferenceType;
|
import org.jclouds.vcloud.domain.ReferenceType;
|
||||||
|
@ -45,7 +46,7 @@ public class FindLocationForResource {
|
||||||
final Supplier<Set<? extends Location>> locations;
|
final Supplier<Set<? extends Location>> locations;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FindLocationForResource(Supplier<Set<? extends Location>> locations) {
|
public FindLocationForResource(@Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Set;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||||
|
@ -58,7 +59,7 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
|
||||||
protected VCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
|
protected VCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
|
||||||
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
|
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
|
||||||
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
|
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
|
||||||
FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images) {
|
FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images) {
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp");
|
this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp");
|
||||||
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
|
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
|
||||||
|
|
|
@ -25,8 +25,9 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
|
import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
|
@ -42,8 +43,8 @@ import com.google.common.base.Supplier;
|
||||||
public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl {
|
public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected VCloudTemplateBuilderImpl(Supplier<Set<? extends Location>> locations,
|
protected VCloudTemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
|
||||||
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> sizes,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||||
Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider,
|
Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider,
|
||||||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||||
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
|
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
|
||||||
|
|
|
@ -45,8 +45,7 @@ public class StaticHardwareSupplier implements Supplier<Set<? extends Hardware>>
|
||||||
for (int cpus : new int[] { 1, 2, 4, 8 })
|
for (int cpus : new int[] { 1, 2, 4, 8 })
|
||||||
for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) {
|
for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) {
|
||||||
String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10);
|
String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10);
|
||||||
hardware.add(new HardwareBuilder().ids(id).ram(ram)
|
hardware.add(new HardwareBuilder().ids(id).ram(ram).processors(ImmutableList.of(new Processor(cpus, 1.0)))
|
||||||
.processors(ImmutableList.of(new Processor(cpus, 1.0)))
|
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl(10f, true, true))).build());
|
.volumes(ImmutableList.<Volume> of(new VolumeImpl(10f, true, true))).build());
|
||||||
}
|
}
|
||||||
return hardware;
|
return hardware;
|
||||||
|
|
|
@ -30,6 +30,7 @@ import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -64,8 +65,8 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected TerremarkVCloudComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
protected TerremarkVCloudComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||||
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> sizes,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||||
Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
||||||
|
|
|
@ -28,27 +28,14 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeService;
|
import org.jclouds.compute.ComputeService;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
|
||||||
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
|
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
|
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.PopulateDefaultLoginCredentialsForImageStrategy;
|
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
|
||||||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||||
import org.jclouds.vcloud.VCloudExpressAsyncClient;
|
|
||||||
import org.jclouds.vcloud.VCloudExpressClient;
|
|
||||||
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
|
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
|
||||||
import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule;
|
import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule;
|
||||||
import org.jclouds.vcloud.compute.strategy.VCloudExpressDestroyNodeStrategy;
|
|
||||||
import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy;
|
|
||||||
import org.jclouds.vcloud.compute.strategy.VCloudExpressListNodesStrategy;
|
|
||||||
import org.jclouds.vcloud.compute.strategy.VCloudExpressRebootNodeStrategy;
|
|
||||||
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
||||||
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient;
|
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient;
|
||||||
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeService;
|
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeService;
|
||||||
|
@ -64,9 +51,7 @@ import org.jclouds.vcloud.terremark.compute.suppliers.VAppTemplatesInOrgs;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Scopes;
|
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,23 +76,7 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudExpressCom
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new ComputeServiceTimeoutsModule());
|
super.configure();
|
||||||
// NOTE
|
|
||||||
bind(AddNodeWithTagStrategy.class).to(TerremarkVCloudAddNodeWithTagStrategy.class);
|
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
|
||||||
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudExpressClient, VCloudExpressAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
|
||||||
// NOTE
|
|
||||||
bind(RunNodesAndAddToSetStrategy.class).to(TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
|
|
||||||
bind(ListNodesStrategy.class).to(VCloudExpressListNodesStrategy.class);
|
|
||||||
// NOTE
|
|
||||||
bind(new TypeLiteral<Function<VCloudExpressVApp, NodeMetadata>>() {
|
|
||||||
}).to(TerremarkVCloudExpressVAppToNodeMetadata.class);
|
|
||||||
bind(GetNodeMetadataStrategy.class).to(VCloudExpressGetNodeMetadataStrategy.class);
|
|
||||||
bind(RebootNodeStrategy.class).to(VCloudExpressRebootNodeStrategy.class);
|
|
||||||
bind(DestroyNodeStrategy.class).to(VCloudExpressDestroyNodeStrategy.class);
|
|
||||||
bindLoadBalancer();
|
|
||||||
// MORE specifics...
|
|
||||||
bind(new TypeLiteral<Function<NodeMetadata, OrgAndName>>() {
|
bind(new TypeLiteral<Function<NodeMetadata, OrgAndName>>() {
|
||||||
}).to(new TypeLiteral<NodeMetadataToOrgAndName>() {
|
}).to(new TypeLiteral<NodeMetadataToOrgAndName>() {
|
||||||
});
|
});
|
||||||
|
@ -119,6 +88,22 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudExpressCom
|
||||||
bind(SecureRandom.class).toInstance(new SecureRandom());
|
bind(SecureRandom.class).toInstance(new SecureRandom());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void bindVAppConverter() {
|
||||||
|
bind(new TypeLiteral<Function<VCloudExpressVApp, NodeMetadata>>() {
|
||||||
|
}).to(TerremarkVCloudExpressVAppToNodeMetadata.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends RunNodesAndAddToSetStrategy> defineRunNodesAndAddToSetStrategy() {
|
||||||
|
return TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends AddNodeWithTagStrategy> defineAddNodeWithTagStrategy() {
|
||||||
|
return TerremarkVCloudAddNodeWithTagStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap() {
|
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap() {
|
||||||
|
@ -140,8 +125,7 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudExpressCom
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
|
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
||||||
return injector.getInstance(VAppTemplatesInOrgs.class);
|
return VAppTemplatesInOrgs.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||||
|
@ -56,12 +57,11 @@ public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppT
|
||||||
public TerremarkVCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
|
public TerremarkVCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
|
||||||
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
|
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
|
||||||
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
|
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
|
||||||
FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images,
|
FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images,
|
||||||
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
|
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
|
||||||
super(computeClient, credentialStore, vAppStatusToNodeState, hardwareForVCloudExpressVApp,
|
super(computeClient, credentialStore, vAppStatusToNodeState, hardwareForVCloudExpressVApp,
|
||||||
findLocationForResourceInVDC, images);
|
findLocationForResourceInVDC, images);
|
||||||
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
|
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,6 +28,7 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
@ -54,7 +55,7 @@ public class VAppTemplatesInOrgs implements Supplier<Set<? extends Image>> {
|
||||||
private final ImagesInVCloudExpressOrg imagesInOrg;
|
private final ImagesInVCloudExpressOrg imagesInOrg;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
VAppTemplatesInOrgs(Supplier<Set<? extends Location>> locations,
|
VAppTemplatesInOrgs(@Memoized Supplier<Set<? extends Location>> locations,
|
||||||
Function<Iterable<? extends Location>, Iterable<? extends Org>> organizatonsForLocations,
|
Function<Iterable<? extends Location>, Iterable<? extends Org>> organizatonsForLocations,
|
||||||
ImagesInVCloudExpressOrg imagesInOrg) {
|
ImagesInVCloudExpressOrg imagesInOrg) {
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
|
|
Loading…
Reference in New Issue