mirror of https://github.com/apache/jclouds.git
Issue 956:add getImage by id to ComputeService
This commit is contained in:
parent
ef31f5114d
commit
bcd3d50ad6
|
@ -45,7 +45,6 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.ImmutableSet.Builder;
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -118,6 +117,11 @@ public class BYONComputeServiceAdapter implements JCloudsNativeComputeServiceAda
|
||||||
return node != null ? converter.apply(node) : null;
|
return node != null ? converter.apply(node) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(final String id) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(final String id) {
|
public void destroyNode(final String id) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
|
|
@ -94,6 +94,12 @@ public class CloudServersComputeServiceAdapter implements ComputeServiceAdapter<
|
||||||
public Server getNode(String id) {
|
public Server getNode(String id) {
|
||||||
int serverId = Integer.parseInt(id);
|
int serverId = Integer.parseInt(id);
|
||||||
return client.getServer(serverId);
|
return client.getServer(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(String id) {
|
||||||
|
int imageId = Integer.parseInt(id);
|
||||||
|
return client.getImage(imageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -210,7 +210,12 @@ public class CloudSigmaComputeServiceAdapter implements
|
||||||
public ServerInfo getNode(String id) {
|
public ServerInfo getNode(String id) {
|
||||||
return client.getServerInfo(id);
|
return client.getServerInfo(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DriveInfo getImage(String id) {
|
||||||
|
return client.getDriveInfo(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(String id) {
|
public void destroyNode(String id) {
|
||||||
ServerInfo server = getNode(id);
|
ServerInfo server = getNode(id);
|
||||||
|
|
|
@ -22,6 +22,9 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.collect.Iterables.filter;
|
import static com.google.common.collect.Iterables.filter;
|
||||||
|
import static com.google.common.collect.Iterables.get;
|
||||||
|
import static org.jclouds.cloudstack.options.DeployVirtualMachineOptions.Builder.displayName;
|
||||||
|
import static org.jclouds.cloudstack.options.ListTemplatesOptions.Builder.id;
|
||||||
import static org.jclouds.cloudstack.predicates.TemplatePredicates.isReady;
|
import static org.jclouds.cloudstack.predicates.TemplatePredicates.isReady;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -133,7 +136,7 @@ public class CloudStackComputeServiceAdapter implements
|
||||||
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
|
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
|
||||||
|
|
||||||
checkState(optionsConverters.containsKey(zone.getNetworkType()), "no options converter configured for network type %s",zone.getNetworkType());
|
checkState(optionsConverters.containsKey(zone.getNetworkType()), "no options converter configured for network type %s",zone.getNetworkType());
|
||||||
DeployVirtualMachineOptions options = DeployVirtualMachineOptions.Builder.displayName(name).name(name);
|
DeployVirtualMachineOptions options = displayName(name).name(name);
|
||||||
OptionsConverter optionsConverter = optionsConverters.get(zone.getNetworkType());
|
OptionsConverter optionsConverter = optionsConverters.get(zone.getNetworkType());
|
||||||
options = optionsConverter.apply(templateOptions, networks, zoneId, options);
|
options = optionsConverter.apply(templateOptions, networks, zoneId, options);
|
||||||
|
|
||||||
|
@ -198,6 +201,11 @@ public class CloudStackComputeServiceAdapter implements
|
||||||
return filter(client.getTemplateClient().listTemplates(), isReady());
|
return filter(client.getTemplateClient().listTemplates(), isReady());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Template getImage(String id) {
|
||||||
|
return get(client.getTemplateClient().listTemplates(id(id)), 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<VirtualMachine> listNodes() {
|
public Iterable<VirtualMachine> listNodes() {
|
||||||
return client.getVirtualMachineClient().listVirtualMachines();
|
return client.getVirtualMachineClient().listVirtualMachines();
|
||||||
|
|
|
@ -118,6 +118,11 @@ public class DeltacloudComputeServiceAdapter implements
|
||||||
return client.getInstance(URI.create(checkNotNull(id, "id")));
|
return client.getInstance(URI.create(checkNotNull(id, "id")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.jclouds.deltacloud.domain.Image getImage(String id) {
|
||||||
|
return client.getImage(URI.create(checkNotNull(id, "id")));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(String id) {
|
public void destroyNode(String id) {
|
||||||
Instance instance = getNode(id);
|
Instance instance = getNode(id);
|
||||||
|
|
|
@ -17,16 +17,18 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.ec2.compute;
|
package org.jclouds.ec2.compute;
|
||||||
|
|
||||||
import static com.google.common.collect.Iterables.concat;
|
import static com.google.common.collect.Iterables.concat;
|
||||||
import static com.google.common.collect.Iterables.filter;
|
import static com.google.common.collect.Iterables.filter;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER;
|
import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||||
import static org.jclouds.util.Preconditions2.checkNotEmpty;
|
import static org.jclouds.util.Preconditions2.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.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
@ -53,6 +55,7 @@ import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
|
@ -77,8 +80,8 @@ import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableMultimap.Builder;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,26 +96,28 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected EC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
protected EC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
|
GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||||
ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy,
|
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy startNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
SuspendNodeStrategy stopNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
Provider<TemplateOptions> templateOptionsProvider,
|
||||||
@Named("NODE_TERMINATED") Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
@Named("NODE_SUSPENDED") Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
@Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
|
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
||||||
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
|
||||||
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client,
|
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
||||||
ConcurrentMap<RegionAndName, KeyPair> credentialsMap, @Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client,
|
||||||
Optional<ImageExtension> imageExtension, GroupNamingConvention.Factory namingConvention) {
|
ConcurrentMap<RegionAndName, KeyPair> credentialsMap,
|
||||||
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
@Named("SECURITY") LoadingCache<RegionAndName, String> securityGroupMap,
|
||||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy, stopNodeStrategy,
|
Optional<ImageExtension> imageExtension, GroupNamingConvention.Factory namingConvention) {
|
||||||
templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, nodeSuspended,
|
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy,
|
||||||
initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, persistNodeCredentials, timeouts,
|
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
|
||||||
executor, imageExtension);
|
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
|
||||||
|
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
|
||||||
|
persistNodeCredentials, timeouts, executor, imageExtension);
|
||||||
this.ec2Client = ec2Client;
|
this.ec2Client = ec2Client;
|
||||||
this.credentialsMap = credentialsMap;
|
this.credentialsMap = credentialsMap;
|
||||||
this.securityGroupMap = securityGroupMap;
|
this.securityGroupMap = securityGroupMap;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.jclouds.compute.config.BindComputeStrategiesByClass;
|
||||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
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;
|
||||||
|
@ -29,6 +30,7 @@ import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||||
import org.jclouds.ec2.compute.strategy.EC2CreateNodesInGroupThenAddToSet;
|
import org.jclouds.ec2.compute.strategy.EC2CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.ec2.compute.strategy.EC2DestroyNodeStrategy;
|
import org.jclouds.ec2.compute.strategy.EC2DestroyNodeStrategy;
|
||||||
|
import org.jclouds.ec2.compute.strategy.EC2GetImageStrategy;
|
||||||
import org.jclouds.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
|
import org.jclouds.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
|
||||||
import org.jclouds.ec2.compute.strategy.EC2ListNodesStrategy;
|
import org.jclouds.ec2.compute.strategy.EC2ListNodesStrategy;
|
||||||
import org.jclouds.ec2.compute.strategy.EC2RebootNodeStrategy;
|
import org.jclouds.ec2.compute.strategy.EC2RebootNodeStrategy;
|
||||||
|
@ -69,6 +71,11 @@ public class EC2BindComputeStrategiesByClass extends BindComputeStrategiesByClas
|
||||||
return EC2GetNodeMetadataStrategy.class;
|
return EC2GetNodeMetadataStrategy.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends GetImageStrategy> defineGetImageStrategy() {
|
||||||
|
return EC2GetImageStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||||
return EC2ListNodesStrategy.class;
|
return EC2ListNodesStrategy.class;
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.jclouds.ec2.compute.extensions.EC2ImageExtension;
|
||||||
import org.jclouds.ec2.compute.functions.AddElasticIpsToNodemetadata;
|
import org.jclouds.ec2.compute.functions.AddElasticIpsToNodemetadata;
|
||||||
import org.jclouds.ec2.compute.functions.CreateUniqueKeyPair;
|
import org.jclouds.ec2.compute.functions.CreateUniqueKeyPair;
|
||||||
import org.jclouds.ec2.compute.functions.CredentialsForInstance;
|
import org.jclouds.ec2.compute.functions.CredentialsForInstance;
|
||||||
|
import org.jclouds.ec2.compute.functions.EC2ImageParser;
|
||||||
import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
|
import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
|
||||||
import org.jclouds.ec2.compute.functions.WindowsLoginCredentialsFromEncryptedData;
|
import org.jclouds.ec2.compute.functions.WindowsLoginCredentialsFromEncryptedData;
|
||||||
import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
|
import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
|
||||||
|
@ -127,6 +128,8 @@ public class EC2ComputeServiceDependenciesModule extends AbstractModule {
|
||||||
bind(new TypeLiteral<CacheLoader<RegionAndName, String>>() {
|
bind(new TypeLiteral<CacheLoader<RegionAndName, String>>() {
|
||||||
}).annotatedWith(Names.named("ELASTICIP")).to(LoadPublicIpForInstanceOrNull.class);
|
}).annotatedWith(Names.named("ELASTICIP")).to(LoadPublicIpForInstanceOrNull.class);
|
||||||
bind(WindowsLoginCredentialsFromEncryptedData.class);
|
bind(WindowsLoginCredentialsFromEncryptedData.class);
|
||||||
|
bind(new TypeLiteral<Function<org.jclouds.ec2.domain.Image, Image>>() {
|
||||||
|
}).to(EC2ImageParser.class);
|
||||||
bind(new TypeLiteral<ImageExtension>() {
|
bind(new TypeLiteral<ImageExtension>() {
|
||||||
}).to(EC2ImageExtension.class);
|
}).to(EC2ImageExtension.class);
|
||||||
bind(new TypeLiteral<PredicateWithResult<String, Image>>() {
|
bind(new TypeLiteral<PredicateWithResult<String, Image>>() {
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.ec2.compute.strategy;
|
package org.jclouds.ec2.compute.strategy;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.collect.Iterables.all;
|
import static com.google.common.collect.Iterables.all;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
import static org.jclouds.ec2.compute.util.EC2ComputeUtils.getZoneFromLocationOrNull;
|
import static org.jclouds.ec2.compute.util.EC2ComputeUtils.getZoneFromLocationOrNull;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -57,9 +57,9 @@ import com.google.common.base.Joiner;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSet.Builder;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates futures that correlate to
|
* creates futures that correlate to
|
||||||
|
@ -102,7 +102,7 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen
|
||||||
EC2Client client,
|
EC2Client client,
|
||||||
@Named("ELASTICIP")
|
@Named("ELASTICIP")
|
||||||
LoadingCache<RegionAndName, String> elasticIpCache,
|
LoadingCache<RegionAndName, String> elasticIpCache,
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider,
|
Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
|
CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
|
||||||
InstancePresent instancePresent, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
|
InstancePresent instancePresent, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.ec2.compute.strategy;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.aws.util.AWSUtils;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
|
import org.jclouds.ec2.EC2Client;
|
||||||
|
import org.jclouds.ec2.domain.Image;
|
||||||
|
import org.jclouds.ec2.options.DescribeImagesOptions;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class EC2GetImageStrategy implements GetImageStrategy {
|
||||||
|
|
||||||
|
private final EC2Client client;
|
||||||
|
private final Function<Image, org.jclouds.compute.domain.Image> imageToImage;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected EC2GetImageStrategy(EC2Client client, Function<Image, org.jclouds.compute.domain.Image> imageToImage) {
|
||||||
|
this.client = checkNotNull(client, "client");
|
||||||
|
this.imageToImage = checkNotNull(imageToImage, "imageToImage");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.jclouds.compute.domain.Image getImage(String id) {
|
||||||
|
checkNotNull(id, "id");
|
||||||
|
String[] parts = AWSUtils.parseHandle(id);
|
||||||
|
String region = parts[0];
|
||||||
|
String instanceId = parts[1];
|
||||||
|
try {
|
||||||
|
Image image = getImageInRegion(region, instanceId);
|
||||||
|
return imageToImage.apply(image);
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Image getImageInRegion(String region, String id) {
|
||||||
|
return getOnlyElement(client.getAMIServices().describeImagesInRegion(region,
|
||||||
|
DescribeImagesOptions.Builder.imageIds(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -202,6 +202,11 @@ public class ElasticStackComputeServiceAdapter implements
|
||||||
@Override
|
@Override
|
||||||
public ServerInfo getNode(String id) {
|
public ServerInfo getNode(String id) {
|
||||||
return client.getServerInfo(id);
|
return client.getServerInfo(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DriveInfo getImage(String id) {
|
||||||
|
return client.getDriveInfo(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -91,6 +91,12 @@ public class NovaComputeServiceAdapter implements ComputeServiceAdapter<Server,
|
||||||
int serverId = Integer.parseInt(id);
|
int serverId = Integer.parseInt(id);
|
||||||
return client.getServer(serverId);
|
return client.getServer(serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(String id) {
|
||||||
|
int imageId = Integer.parseInt(id);
|
||||||
|
return client.getImage(imageId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(String id) {
|
public void destroyNode(String id) {
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.v1_1.compute;
|
package org.jclouds.openstack.nova.v1_1.compute;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -46,6 +48,7 @@ import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
|
@ -88,28 +91,29 @@ public class NovaComputeService extends BaseComputeService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected NovaComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
protected NovaComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
|
GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||||
ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy,
|
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy startNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
SuspendNodeStrategy stopNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
Provider<TemplateOptions> templateOptionsProvider,
|
||||||
@Named("NODE_TERMINATED") Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
@Named("NODE_SUSPENDED") Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
@Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
|
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
||||||
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
|
||||||
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, NovaClient novaClient,
|
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
||||||
LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupMap,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, NovaClient novaClient,
|
||||||
LoadingCache<ZoneAndName, KeyPair> keyPairCache,
|
LoadingCache<ZoneAndName, SecurityGroupInZone> securityGroupMap,
|
||||||
Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByZoneId,
|
LoadingCache<ZoneAndName, KeyPair> keyPairCache,
|
||||||
GroupNamingConvention.Factory namingConvention, Optional<ImageExtension> imageExtension) {
|
Function<Set<? extends NodeMetadata>, Multimap<String, String>> orphanedGroupsByZoneId,
|
||||||
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
GroupNamingConvention.Factory namingConvention, Optional<ImageExtension> imageExtension) {
|
||||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy,
|
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy,
|
||||||
stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
|
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
|
||||||
nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, persistNodeCredentials,
|
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
|
||||||
timeouts, executor, imageExtension);
|
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
|
||||||
|
persistNodeCredentials, timeouts, executor, imageExtension);
|
||||||
this.novaClient = checkNotNull(novaClient, "novaClient");
|
this.novaClient = checkNotNull(novaClient, "novaClient");
|
||||||
this.securityGroupMap = checkNotNull(securityGroupMap, "securityGroupMap");
|
this.securityGroupMap = checkNotNull(securityGroupMap, "securityGroupMap");
|
||||||
this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");
|
this.keyPairCache = checkNotNull(keyPairCache, "keyPairCache");
|
||||||
|
|
|
@ -198,6 +198,13 @@ public class NovaComputeServiceAdapter implements
|
||||||
return server == null ? null : new ServerInZone(server, zoneAndId.getZone());
|
return server == null ? null : new ServerInZone(server, zoneAndId.getZone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImageInZone getImage(String id) {
|
||||||
|
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||||
|
Image image = novaClient.getImageClientForZone(zoneAndId.getZone()).getImage(zoneAndId.getId());
|
||||||
|
return image == null ? null : new ImageInZone(image, zoneAndId.getZone());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(String id) {
|
public void destroyNode(String id) {
|
||||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||||
|
|
|
@ -182,7 +182,7 @@ public class NovaComputeServiceContextModule extends
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("SECURITY")
|
@Named(TIMEOUT_SECURITYGROUP_PRESENT)
|
||||||
protected Predicate<AtomicReference<ZoneAndName>> securityGroupEventualConsistencyDelay(
|
protected Predicate<AtomicReference<ZoneAndName>> securityGroupEventualConsistencyDelay(
|
||||||
FindSecurityGroupWithNameAndReturnTrue in,
|
FindSecurityGroupWithNameAndReturnTrue in,
|
||||||
@Named(TIMEOUT_SECURITYGROUP_PRESENT) long msDelay) {
|
@Named(TIMEOUT_SECURITYGROUP_PRESENT) long msDelay) {
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -64,7 +64,7 @@ public class AllocateAndAddFloatingIpToNode implements
|
||||||
private final LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache;
|
private final LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AllocateAndAddFloatingIpToNode(@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
public AllocateAndAddFloatingIpToNode(@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
NovaClient novaClient, @Named("FLOATINGIP") LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache) {
|
NovaClient novaClient, @Named("FLOATINGIP") LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache) {
|
||||||
this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning");
|
this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning");
|
||||||
this.novaClient = checkNotNull(novaClient, "novaClient");
|
this.novaClient = checkNotNull(novaClient, "novaClient");
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.v1_1.compute.loaders;
|
package org.jclouds.openstack.nova.v1_1.compute.loaders;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.openstack.nova.v1_1.config.NovaProperties.TIMEOUT_SECURITYGROUP_PRESENT;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class FindSecurityGroupOrCreate extends CacheLoader<ZoneAndName, Security
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FindSecurityGroupOrCreate(
|
public FindSecurityGroupOrCreate(
|
||||||
@Named("SECURITY") Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone,
|
@Named(TIMEOUT_SECURITYGROUP_PRESENT) Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone,
|
||||||
Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator) {
|
Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator) {
|
||||||
this.returnSecurityGroupExistsInZone = checkNotNull(returnSecurityGroupExistsInZone,
|
this.returnSecurityGroupExistsInZone = checkNotNull(returnSecurityGroupExistsInZone,
|
||||||
"returnSecurityGroupExistsInZone");
|
"returnSecurityGroupExistsInZone");
|
||||||
|
|
|
@ -162,7 +162,13 @@ public class VCloudComputeServiceAdapter implements ComputeServiceAdapter<VApp,
|
||||||
URI id = URI.create(in);
|
URI id = URI.create(in);
|
||||||
return client.getVAppClient().getVApp(id);
|
return client.getVAppClient().getVApp(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VAppTemplate getImage(String in) {
|
||||||
|
URI id = URI.create(in);
|
||||||
|
return client.getVAppTemplateClient().getVAppTemplate(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(String id) {
|
public void destroyNode(String id) {
|
||||||
URI vappId = URI.create(checkNotNull(id, "node.id"));
|
URI vappId = URI.create(checkNotNull(id, "node.id"));
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.trmk.vcloud_0_8.compute;
|
package org.jclouds.trmk.vcloud_0_8.compute;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -43,6 +46,7 @@ import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
|
@ -68,25 +72,26 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected TerremarkVCloudComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
protected TerremarkVCloudComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
|
GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||||
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
|
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
SuspendNodeStrategy suspendNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
Provider<TemplateOptions> templateOptionsProvider,
|
||||||
@Named("NODE_TERMINATED") Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
@Named("NODE_SUSPENDED") Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
@Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
|
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
||||||
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
|
||||||
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys,
|
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
||||||
Optional<ImageExtension> imageExtension) {
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys,
|
||||||
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
Optional<ImageExtension> imageExtension) {
|
||||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
|
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy,
|
||||||
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
|
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
|
||||||
nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, persistNodeCredentials,
|
resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
|
||||||
timeouts, executor, imageExtension);
|
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
|
||||||
|
persistNodeCredentials, timeouts, executor, imageExtension);
|
||||||
this.cleanupOrphanKeys = cleanupOrphanKeys;
|
this.cleanupOrphanKeys = cleanupOrphanKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.jclouds.compute.config.BindComputeStrategiesByClass;
|
||||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
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;
|
||||||
|
@ -30,6 +31,7 @@ import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.StartVAppWithGroupEncodedIntoName;
|
import org.jclouds.trmk.vcloud_0_8.compute.strategy.StartVAppWithGroupEncodedIntoName;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy;
|
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudDestroyNodeStrategy;
|
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudDestroyNodeStrategy;
|
||||||
|
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudGetImageStrategy;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudGetNodeMetadataStrategy;
|
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudGetNodeMetadataStrategy;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudLifeCycleStrategy;
|
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudLifeCycleStrategy;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudListNodesStrategy;
|
import org.jclouds.trmk.vcloud_0_8.compute.strategy.TerremarkVCloudListNodesStrategy;
|
||||||
|
@ -49,6 +51,11 @@ public class TerremarkBindComputeStrategiesByClass extends BindComputeStrategies
|
||||||
return TerremarkVCloudGetNodeMetadataStrategy.class;
|
return TerremarkVCloudGetNodeMetadataStrategy.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends GetImageStrategy> defineGetImageStrategy() {
|
||||||
|
return TerremarkVCloudGetImageStrategy.class;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
||||||
return TerremarkVCloudListNodesStrategy.class;
|
return TerremarkVCloudListNodesStrategy.class;
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeService;
|
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeService;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
|
import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
|
||||||
|
import org.jclouds.trmk.vcloud_0_8.compute.functions.ImageForVCloudExpressVAppTemplate;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.ImagesInVCloudExpressOrg;
|
import org.jclouds.trmk.vcloud_0_8.compute.functions.ImagesInVCloudExpressOrg;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.NodeMetadataToOrgAndName;
|
import org.jclouds.trmk.vcloud_0_8.compute.functions.NodeMetadataToOrgAndName;
|
||||||
import org.jclouds.trmk.vcloud_0_8.compute.functions.ParseOsFromVAppTemplateName;
|
import org.jclouds.trmk.vcloud_0_8.compute.functions.ParseOsFromVAppTemplateName;
|
||||||
|
@ -42,6 +43,7 @@ import org.jclouds.trmk.vcloud_0_8.compute.strategy.ParseVAppTemplateDescription
|
||||||
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
import org.jclouds.trmk.vcloud_0_8.domain.Org;
|
||||||
import org.jclouds.trmk.vcloud_0_8.domain.Status;
|
import org.jclouds.trmk.vcloud_0_8.domain.Status;
|
||||||
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
import org.jclouds.trmk.vcloud_0_8.domain.VApp;
|
||||||
|
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -103,7 +105,10 @@ public class TerremarkVCloudComputeServiceContextModule extends BaseComputeServi
|
||||||
bind(SecureRandom.class).toInstance(new SecureRandom());
|
bind(SecureRandom.class).toInstance(new SecureRandom());
|
||||||
install(new TerremarkBindComputeStrategiesByClass());
|
install(new TerremarkBindComputeStrategiesByClass());
|
||||||
install(new TerremarkBindComputeSuppliersByClass());
|
install(new TerremarkBindComputeSuppliersByClass());
|
||||||
bindVAppConverter();
|
bind(new TypeLiteral<Function<VApp, NodeMetadata>>() {
|
||||||
|
}).to(VAppToNodeMetadata.class);
|
||||||
|
bind(new TypeLiteral<Function<VAppTemplate, Image>>() {
|
||||||
|
}).to(ImageForVCloudExpressVAppTemplate.class);
|
||||||
bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() {
|
bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() {
|
||||||
}).to(new TypeLiteral<ImagesInVCloudExpressOrg>() {
|
}).to(new TypeLiteral<ImagesInVCloudExpressOrg>() {
|
||||||
});
|
});
|
||||||
|
@ -111,11 +116,6 @@ public class TerremarkVCloudComputeServiceContextModule extends BaseComputeServi
|
||||||
}).to(ParseOsFromVAppTemplateName.class);
|
}).to(ParseOsFromVAppTemplateName.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void bindVAppConverter() {
|
|
||||||
bind(new TypeLiteral<Function<VApp, NodeMetadata>>() {
|
|
||||||
}).to(VAppToNodeMetadata.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Supplier<String> provideSuffix(final SecureRandom random) {
|
Supplier<String> provideSuffix(final SecureRandom random) {
|
||||||
|
|
|
@ -16,39 +16,44 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rimuhosting.miro.compute.strategy;
|
package org.jclouds.trmk.vcloud_0_8.compute.strategy;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient;
|
||||||
import org.jclouds.rimuhosting.miro.domain.Server;
|
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class RimuHostingGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
|
public class TerremarkVCloudGetImageStrategy implements GetImageStrategy {
|
||||||
|
|
||||||
private final RimuHostingClient client;
|
protected final TerremarkVCloudClient client;
|
||||||
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
protected final Function<VAppTemplate, Image> vAppToImage;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected RimuHostingGetNodeMetadataStrategy(RimuHostingClient client,
|
protected TerremarkVCloudGetImageStrategy(TerremarkVCloudClient client, Function<VAppTemplate, Image> vAppToImage) {
|
||||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
this.client = checkNotNull(client, "client");
|
||||||
this.client = client;
|
this.vAppToImage = vAppToImage;
|
||||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata getNode(String id) {
|
public Image getImage(String in) {
|
||||||
long serverId = Long.parseLong(id);
|
URI id = URI.create(in);
|
||||||
Server server = client.getServer(serverId);
|
VAppTemplate from = client.getVAppTemplate(id);
|
||||||
return server == null ? null : serverToNodeMetadata.apply(server);
|
if (from == null)
|
||||||
|
return null;
|
||||||
|
return vAppToImage.apply(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -74,7 +74,9 @@ public interface ComputeService {
|
||||||
* differently. However, it is a good indicator of relative speed within a cloud. memory is
|
* differently. However, it is a good indicator of relative speed within a cloud. memory is
|
||||||
* measured in megabytes and disks in gigabytes.
|
* measured in megabytes and disks in gigabytes.
|
||||||
*
|
*
|
||||||
* @return a map of hardware profiles by ID, conceding that in some clouds the "id" is not used.
|
* <h3>note</h3>
|
||||||
|
*
|
||||||
|
* This is a cached collection
|
||||||
*/
|
*/
|
||||||
Set<? extends Hardware> listHardwareProfiles();
|
Set<? extends Hardware> listHardwareProfiles();
|
||||||
|
|
||||||
|
@ -82,10 +84,22 @@ public interface ComputeService {
|
||||||
* Images define the operating system and metadata related to a node. In some clouds, Images are
|
* Images define the operating system and metadata related to a node. In some clouds, Images are
|
||||||
* bound to a specific region, and their identifiers are different across these regions. For this
|
* bound to a specific region, and their identifiers are different across these regions. For this
|
||||||
* reason, you should consider matching image requirements like operating system family with
|
* reason, you should consider matching image requirements like operating system family with
|
||||||
* TemplateBuilder as opposed to choosing an image explicitly. The getImages() command returns a
|
* TemplateBuilder as opposed to choosing an image explicitly.
|
||||||
* map of images by id.
|
*
|
||||||
|
* <h3>note</h3>
|
||||||
|
*
|
||||||
|
* This is a cached collection
|
||||||
*/
|
*/
|
||||||
Set<? extends Image> listImages();
|
Set<? extends Image> listImages();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find an image by its id.
|
||||||
|
*
|
||||||
|
* <h3>note</h3>
|
||||||
|
*
|
||||||
|
* This is an uncached call to the backend service
|
||||||
|
*/
|
||||||
|
Image getImage(String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* all nodes available to the current user by id. If possible, the returned set will include
|
* all nodes available to the current user by id. If possible, the returned set will include
|
||||||
|
@ -98,6 +112,10 @@ public interface ComputeService {
|
||||||
* which is typically region or zone. A region is a general area, like eu-west, where a zone is
|
* which is typically region or zone. A region is a general area, like eu-west, where a zone is
|
||||||
* similar to a datacenter. If a location has a parent, that implies it is within that location.
|
* similar to a datacenter. If a location has a parent, that implies it is within that location.
|
||||||
* For example a location can be a rack, whose parent is likely to be a zone.
|
* For example a location can be a rack, whose parent is likely to be a zone.
|
||||||
|
*
|
||||||
|
* <h3>note</h3>
|
||||||
|
*
|
||||||
|
* This is a cached collection
|
||||||
*/
|
*/
|
||||||
Set<? extends Location> listAssignableLocations();
|
Set<? extends Location> listAssignableLocations();
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,19 @@ package org.jclouds.compute;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.domain.LoginCredentials;
|
import org.jclouds.domain.LoginCredentials;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A means of specifying the interface between the {@link ComputeService
|
* A means of specifying the interface between the {@link ComputeService ComputeServices} and a
|
||||||
* ComputeServices} and a concrete compute cloud implementation, jclouds or
|
* concrete compute cloud implementation, jclouds or otherwise.
|
||||||
* otherwise.
|
*
|
||||||
|
* <h3>Important</h3>
|
||||||
|
*
|
||||||
|
* While implementations may cache results of calls to this interface, it is important to not cache
|
||||||
|
* within this. Otherwise, status updates will not be visible immediately.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
|
@ -35,33 +40,29 @@ import org.jclouds.javax.annotation.Nullable;
|
||||||
public interface ComputeServiceAdapter<N, H, I, L> {
|
public interface ComputeServiceAdapter<N, H, I, L> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ComputeService#createNodesInGroup(String, int, Template)} generates
|
* {@link ComputeService#createNodesInGroup(String, int, Template)} generates the parameters
|
||||||
* the parameters passed into this method such that each node in the set has
|
* passed into this method such that each node in the set has a unique name.
|
||||||
* a unique name.
|
|
||||||
*
|
*
|
||||||
* <h4>note</h4> It is intentional to return the library native node object,
|
* <h4>note</h4> It is intentional to return the library native node object, as generic type
|
||||||
* as generic type {@code N}. If you are not using library-native objects
|
* {@code N}. If you are not using library-native objects (such as libvirt {@code Domain}) use
|
||||||
* (such as libvirt {@code Domain}) use
|
|
||||||
* {@link JCloudsNativeComputeServiceAdapter} instead.
|
* {@link JCloudsNativeComputeServiceAdapter} instead.
|
||||||
*
|
*
|
||||||
* <h4>note</h4> Your responsibility is to create a node with the underlying
|
* <h4>note</h4> Your responsibility is to create a node with the underlying library and return
|
||||||
* library and return after storing its credentials in the supplied map
|
* after storing its credentials in the supplied map corresponding to
|
||||||
* corresponding to {@link ComputeServiceContext#getCredentialStore
|
* {@link ComputeServiceContext#getCredentialStore credentialStore}
|
||||||
* credentialStore}
|
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param group
|
||||||
* used to aggregate nodes with identical configuration
|
* used to aggregate nodes with identical configuration
|
||||||
* @param name
|
* @param name
|
||||||
* unique supplied name for the node, which has the tag encoded
|
* unique supplied name for the node, which has the group encoded into it.
|
||||||
* into it.
|
|
||||||
* @param template
|
* @param template
|
||||||
* includes {@code imageId}, {@code locationId}, and
|
* includes {@code imageId}, {@code locationId}, and {@code hardwareId} used to resume
|
||||||
* {@code hardwareId} used to resume the instance.
|
* the instance.
|
||||||
* @return library-native representation of a node.
|
* @return library-native representation of a node. TODO: return typed exception on
|
||||||
* TODO: return typed exception on createNodeFailure
|
* createNodeFailure
|
||||||
* @see ComputeService#createNodesInGroup(String, int, Template)
|
* @see ComputeService#createNodesInGroup(String, int, Template)
|
||||||
*/
|
*/
|
||||||
NodeAndInitialCredentials<N> createNodeWithGroupEncodedIntoName(String tag, String name, Template template);
|
NodeAndInitialCredentials<N> createNodeWithGroupEncodedIntoName(String group, String name, Template template);
|
||||||
|
|
||||||
public static class NodeAndInitialCredentials<N> {
|
public static class NodeAndInitialCredentials<N> {
|
||||||
private final N node;
|
private final N node;
|
||||||
|
@ -92,8 +93,8 @@ public interface ComputeServiceAdapter<N, H, I, L> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return credentials given by the api for the node, or null if this
|
* @return credentials given by the api for the node, or null if this information is not
|
||||||
* information is not available
|
* available
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public LoginCredentials getCredentials() {
|
public LoginCredentials getCredentials() {
|
||||||
|
@ -102,12 +103,11 @@ public interface ComputeServiceAdapter<N, H, I, L> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hardware profiles describe available cpu, memory, and disk configurations
|
* Hardware profiles describe available cpu, memory, and disk configurations that can be used to
|
||||||
* that can be used to run a node.
|
* run a node.
|
||||||
* <p/>
|
* <p/>
|
||||||
* To implement this method, return the library native hardware profiles
|
* To implement this method, return the library native hardware profiles available to the user.
|
||||||
* available to the user. These will be used to launch nodes as a part of the
|
* These will be used to launch nodes as a part of the template.
|
||||||
* template.
|
|
||||||
*
|
*
|
||||||
* @return a non-null iterable of available hardware profiles.
|
* @return a non-null iterable of available hardware profiles.
|
||||||
* @see ComputeService#listHardwareProfiles()
|
* @see ComputeService#listHardwareProfiles()
|
||||||
|
@ -115,22 +115,31 @@ public interface ComputeServiceAdapter<N, H, I, L> {
|
||||||
Iterable<H> listHardwareProfiles();
|
Iterable<H> listHardwareProfiles();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Images are the available configured operating systems that someone can run
|
* Images are the available configured operating systems that someone can run a node with.
|
||||||
* a node with. *
|
|
||||||
* <p/>
|
* <p/>
|
||||||
* To implement this method, return the library native images available to
|
* To implement this method, return the library native images available to the user. These will
|
||||||
* the user. These will be used to launch nodes as a part of the template.
|
* be used to launch nodes as a part of the template.
|
||||||
*
|
*
|
||||||
* @return a non-null iterable of available images.
|
* @return a non-null iterable of available images.
|
||||||
* @see ComputeService#listImages()
|
* @see ComputeService#listImages()
|
||||||
*/
|
*/
|
||||||
Iterable<I> listImages();
|
Iterable<I> listImages();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a specific image by id
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* {@link Image#getId}, which is not necessarily {@link Image#getProviderId}
|
||||||
|
* @return image or null if not exists.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
I getImage(String id);
|
||||||
|
|
||||||
Iterable<L> listLocations();
|
Iterable<L> listLocations();
|
||||||
|
|
||||||
N getNode(String id);
|
N getNode(String id);
|
||||||
|
|
||||||
//TODO consider making reboot/resume/suspend return the node they affected
|
// TODO consider making reboot/resume/suspend return the node they affected
|
||||||
void destroyNode(String id);
|
void destroyNode(String id);
|
||||||
|
|
||||||
void rebootNode(String id);
|
void rebootNode(String id);
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.compute.config;
|
||||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
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;
|
||||||
|
@ -42,6 +43,7 @@ public abstract class BindComputeStrategiesByClass extends AbstractModule {
|
||||||
bindAddNodeWithTagStrategy(defineAddNodeWithTagStrategy());
|
bindAddNodeWithTagStrategy(defineAddNodeWithTagStrategy());
|
||||||
bindListNodesStrategy(defineListNodesStrategy());
|
bindListNodesStrategy(defineListNodesStrategy());
|
||||||
bindGetNodeMetadataStrategy(defineGetNodeMetadataStrategy());
|
bindGetNodeMetadataStrategy(defineGetNodeMetadataStrategy());
|
||||||
|
bindGetImageStrategy(defineGetImageStrategy());
|
||||||
bindRebootNodeStrategy(defineRebootNodeStrategy());
|
bindRebootNodeStrategy(defineRebootNodeStrategy());
|
||||||
bindStartNodeStrategy(defineStartNodeStrategy());
|
bindStartNodeStrategy(defineStartNodeStrategy());
|
||||||
bindStopNodeStrategy(defineStopNodeStrategy());
|
bindStopNodeStrategy(defineStopNodeStrategy());
|
||||||
|
@ -78,7 +80,11 @@ public abstract class BindComputeStrategiesByClass extends AbstractModule {
|
||||||
protected void bindGetNodeMetadataStrategy(Class<? extends GetNodeMetadataStrategy> clazz) {
|
protected void bindGetNodeMetadataStrategy(Class<? extends GetNodeMetadataStrategy> clazz) {
|
||||||
bind(GetNodeMetadataStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
bind(GetNodeMetadataStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void bindGetImageStrategy(Class<? extends GetImageStrategy> clazz) {
|
||||||
|
bind(GetImageStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
||||||
|
}
|
||||||
|
|
||||||
protected void bindListNodesStrategy(Class<? extends ListNodesStrategy> clazz) {
|
protected void bindListNodesStrategy(Class<? extends ListNodesStrategy> clazz) {
|
||||||
bind(ListNodesStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
bind(ListNodesStrategy.class).to(clazz).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
|
@ -102,5 +108,7 @@ public abstract class BindComputeStrategiesByClass extends AbstractModule {
|
||||||
|
|
||||||
protected abstract Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy();
|
protected abstract Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy();
|
||||||
|
|
||||||
|
protected abstract Class<? extends GetImageStrategy> defineGetImageStrategy();
|
||||||
|
|
||||||
protected abstract Class<? extends ListNodesStrategy> defineListNodesStrategy();
|
protected abstract Class<? extends ListNodesStrategy> defineListNodesStrategy();
|
||||||
}
|
}
|
|
@ -35,6 +35,7 @@ import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.ImageBuilder;
|
import org.jclouds.compute.domain.ImageBuilder;
|
||||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
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.PopulateDefaultLoginCredentialsForImageStrategy;
|
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||||
|
@ -161,6 +162,12 @@ public class ComputeServiceAdapterContextModule<N, H, I, L> extends BaseComputeS
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
protected GetImageStrategy defineGetImageStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected ListNodesStrategy defineListNodesStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
protected ListNodesStrategy defineListNodesStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.compute.config;
|
package org.jclouds.compute.config;
|
||||||
|
|
||||||
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.compute.domain.TemplateBuilderSpec;
|
import org.jclouds.compute.domain.TemplateBuilderSpec;
|
||||||
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -29,31 +30,51 @@ public interface ComputeServiceProperties {
|
||||||
public static final String RESOURCENAME_PREFIX = "jclouds.compute.resourcename-prefix";
|
public static final String RESOURCENAME_PREFIX = "jclouds.compute.resourcename-prefix";
|
||||||
public static final String RESOURCENAME_DELIMITER = "jclouds.compute.resourcename-delimiter";
|
public static final String RESOURCENAME_DELIMITER = "jclouds.compute.resourcename-delimiter";
|
||||||
|
|
||||||
public static final String TIMEOUT_NODE_TERMINATED = "jclouds.compute.timeout.node-terminated";
|
|
||||||
public static final String TIMEOUT_NODE_RUNNING = "jclouds.compute.timeout.node-running";
|
public static final String TIMEOUT_NODE_RUNNING = "jclouds.compute.timeout.node-running";
|
||||||
public static final String TIMEOUT_NODE_SUSPENDED = "jclouds.compute.timeout.node-suspended";
|
public static final String TIMEOUT_NODE_SUSPENDED = "jclouds.compute.timeout.node-suspended";
|
||||||
|
public static final String TIMEOUT_NODE_TERMINATED = "jclouds.compute.timeout.node-terminated";
|
||||||
|
|
||||||
public static final String TIMEOUT_SCRIPT_COMPLETE = "jclouds.compute.timeout.script-complete";
|
public static final String TIMEOUT_SCRIPT_COMPLETE = "jclouds.compute.timeout.script-complete";
|
||||||
public static final String TIMEOUT_PORT_OPEN = "jclouds.compute.timeout.port-open";
|
public static final String TIMEOUT_PORT_OPEN = "jclouds.compute.timeout.port-open";
|
||||||
|
|
||||||
public static final String INIT_STATUS_INITIAL_PERIOD = "jclouds.compute.init-status.initial-period";
|
public static final String INIT_STATUS_INITIAL_PERIOD = "jclouds.compute.init-status.initial-period";
|
||||||
public static final String INIT_STATUS_MAX_PERIOD = "jclouds.compute.init-status.max-period";
|
public static final String INIT_STATUS_MAX_PERIOD = "jclouds.compute.init-status.max-period";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* time in milliseconds to wait for an image to finish creating.
|
||||||
|
*
|
||||||
|
* Override {@link Timeouts#imageAvailable default} by setting this property using
|
||||||
|
* {@link ContextBuilder#overrides}
|
||||||
|
*/
|
||||||
|
public static final String TIMEOUT_IMAGE_AVAILABLE = "jclouds.compute.timeout.image-available";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* overrides the default specified in the subclass of {@link BaseComputeServiceContextModule#provideTemplate}
|
* time in milliseconds to wait for an image to delete.
|
||||||
|
*
|
||||||
|
* Override {@link Timeouts#imageDeleted default} by setting this property using
|
||||||
|
* {@link ContextBuilder#overrides}
|
||||||
|
*/
|
||||||
|
public static final String TIMEOUT_IMAGE_DELETED = "jclouds.compute.timeout.image-deleted";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* overrides the default specified in the subclass of
|
||||||
|
* {@link BaseComputeServiceContextModule#provideTemplate}
|
||||||
|
*
|
||||||
* @see TemplateBuilderSpec
|
* @see TemplateBuilderSpec
|
||||||
*/
|
*/
|
||||||
public static final String TEMPLATE = "jclouds.template";
|
public static final String TEMPLATE = "jclouds.template";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* overrides the image specified in the subclass of {@link BaseComputeServiceContextModule#provideTemplate}
|
* overrides the image specified in the subclass of
|
||||||
|
* {@link BaseComputeServiceContextModule#provideTemplate}
|
||||||
*/
|
*/
|
||||||
public static final String IMAGE_ID = "jclouds.image-id";
|
public static final String IMAGE_ID = "jclouds.image-id";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* username and, if colon delimited, password of the default user on the image that is or can become root
|
* username and, if colon delimited, password of the default user on the image that is or can
|
||||||
|
* become root
|
||||||
* <p/>
|
* <p/>
|
||||||
* ex. {@code ubuntu}
|
* ex. {@code ubuntu} ex. {@code toor:password}
|
||||||
* ex. {@code toor:password}
|
|
||||||
*/
|
*/
|
||||||
public static final String IMAGE_LOGIN_USER = "jclouds.image.login-user";
|
public static final String IMAGE_LOGIN_USER = "jclouds.image.login-user";
|
||||||
|
|
||||||
|
@ -63,8 +84,8 @@ public interface ComputeServiceProperties {
|
||||||
public static final String IMAGE_AUTHENTICATE_SUDO = "jclouds.image.authenticate-sudo";
|
public static final String IMAGE_AUTHENTICATE_SUDO = "jclouds.image.authenticate-sudo";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* comma-separated nodes that we shouldn't attempt to list as they are dead
|
* comma-separated nodes that we shouldn't attempt to list as they are dead in the provider for
|
||||||
* in the provider for some reason.
|
* some reason.
|
||||||
*/
|
*/
|
||||||
public static final String BLACKLIST_NODES = "jclouds.compute.blacklist-nodes";
|
public static final String BLACKLIST_NODES = "jclouds.compute.blacklist-nodes";
|
||||||
|
|
||||||
|
|
|
@ -17,19 +17,27 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.compute.config;
|
package org.jclouds.compute.config;
|
||||||
|
|
||||||
import static com.google.common.base.Predicates.not;
|
import static com.google.common.base.Predicates.not;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_IMAGE_AVAILABLE;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_IMAGE_DELETED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.predicates.AtomicImageAvailable;
|
||||||
|
import org.jclouds.compute.predicates.AtomicImageDeleted;
|
||||||
import org.jclouds.compute.predicates.AtomicNodeRunning;
|
import org.jclouds.compute.predicates.AtomicNodeRunning;
|
||||||
import org.jclouds.compute.predicates.AtomicNodeSuspended;
|
import org.jclouds.compute.predicates.AtomicNodeSuspended;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
|
||||||
import org.jclouds.compute.predicates.AtomicNodeTerminated;
|
import org.jclouds.compute.predicates.AtomicNodeTerminated;
|
||||||
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
|
@ -47,37 +55,53 @@ public class ComputeServiceTimeoutsModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("NODE_RUNNING")
|
@Named(TIMEOUT_NODE_RUNNING)
|
||||||
protected Predicate<AtomicReference<NodeMetadata>> nodeRunning(AtomicNodeRunning stateRunning, Timeouts timeouts) {
|
protected Predicate<AtomicReference<NodeMetadata>> nodeRunning(AtomicNodeRunning statusRunning, Timeouts timeouts) {
|
||||||
return timeouts.nodeRunning == 0 ? stateRunning : new RetryablePredicate<AtomicReference<NodeMetadata>>(stateRunning,
|
return timeouts.nodeRunning == 0 ? statusRunning : new RetryablePredicate<AtomicReference<NodeMetadata>>(statusRunning,
|
||||||
timeouts.nodeRunning);
|
timeouts.nodeRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("NODE_TERMINATED")
|
@Named(TIMEOUT_NODE_TERMINATED)
|
||||||
protected Predicate<AtomicReference<NodeMetadata>> serverTerminated(AtomicNodeTerminated stateTerminated, Timeouts timeouts) {
|
protected Predicate<AtomicReference<NodeMetadata>> serverTerminated(AtomicNodeTerminated statusTerminated, Timeouts timeouts) {
|
||||||
return timeouts.nodeTerminated == 0 ? stateTerminated : new RetryablePredicate<AtomicReference<NodeMetadata>>(stateTerminated,
|
return timeouts.nodeTerminated == 0 ? statusTerminated : new RetryablePredicate<AtomicReference<NodeMetadata>>(statusTerminated,
|
||||||
timeouts.nodeTerminated);
|
timeouts.nodeTerminated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("NODE_SUSPENDED")
|
@Named(TIMEOUT_NODE_SUSPENDED)
|
||||||
protected Predicate<AtomicReference<NodeMetadata>> serverSuspended(AtomicNodeSuspended stateSuspended, Timeouts timeouts) {
|
protected Predicate<AtomicReference<NodeMetadata>> serverSuspended(AtomicNodeSuspended statusSuspended, Timeouts timeouts) {
|
||||||
return timeouts.nodeSuspended == 0 ? stateSuspended : new RetryablePredicate<AtomicReference<NodeMetadata>>(stateSuspended,
|
return timeouts.nodeSuspended == 0 ? statusSuspended : new RetryablePredicate<AtomicReference<NodeMetadata>>(statusSuspended,
|
||||||
timeouts.nodeSuspended);
|
timeouts.nodeSuspended);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("SCRIPT_COMPLETE")
|
@Named(TIMEOUT_SCRIPT_COMPLETE)
|
||||||
protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning, Timeouts timeouts) {
|
protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero statusRunning, Timeouts timeouts) {
|
||||||
return timeouts.scriptComplete == 0 ? not(stateRunning) : new RetryablePredicate<CommandUsingClient>(
|
return timeouts.scriptComplete == 0 ? not(statusRunning) : new RetryablePredicate<CommandUsingClient>(
|
||||||
not(stateRunning), timeouts.scriptComplete);
|
not(statusRunning), timeouts.scriptComplete);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
@Named(TIMEOUT_IMAGE_AVAILABLE)
|
||||||
|
protected Predicate<AtomicReference<Image>> imageAvailable(AtomicImageAvailable statusAvailable, Timeouts timeouts) {
|
||||||
|
return timeouts.imageAvailable == 0 ? statusAvailable : new RetryablePredicate<AtomicReference<Image>>(statusAvailable,
|
||||||
|
timeouts.imageAvailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
@Named(TIMEOUT_IMAGE_DELETED)
|
||||||
|
protected Predicate<AtomicReference<Image>> serverDeleted(AtomicImageDeleted statusDeleted, Timeouts timeouts) {
|
||||||
|
return timeouts.imageDeleted == 0 ? statusDeleted : new RetryablePredicate<AtomicReference<Image>>(statusDeleted,
|
||||||
|
timeouts.imageDeleted);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.compute.internal;
|
package org.jclouds.compute.internal;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Predicates.and;
|
import static com.google.common.base.Predicates.and;
|
||||||
import static com.google.common.base.Predicates.not;
|
import static com.google.common.base.Predicates.not;
|
||||||
|
@ -27,6 +26,9 @@ import static com.google.common.collect.Maps.newLinkedHashMap;
|
||||||
import static com.google.common.collect.Sets.filter;
|
import static com.google.common.collect.Sets.filter;
|
||||||
import static com.google.common.collect.Sets.newLinkedHashSet;
|
import static com.google.common.collect.Sets.newLinkedHashSet;
|
||||||
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
import static com.google.common.util.concurrent.Futures.immediateFuture;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||||
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
||||||
import static org.jclouds.compute.predicates.NodePredicates.all;
|
import static org.jclouds.compute.predicates.NodePredicates.all;
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||||
|
@ -72,6 +74,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
|
@ -119,6 +122,7 @@ public class BaseComputeService implements ComputeService {
|
||||||
private final Supplier<Set<? extends Image>> images;
|
private final Supplier<Set<? extends Image>> images;
|
||||||
private final Supplier<Set<? extends Hardware>> hardwareProfiles;
|
private final Supplier<Set<? extends Hardware>> hardwareProfiles;
|
||||||
private final Supplier<Set<? extends Location>> locations;
|
private final Supplier<Set<? extends Location>> locations;
|
||||||
|
private final GetImageStrategy getImageStrategy;
|
||||||
private final ListNodesStrategy listNodesStrategy;
|
private final ListNodesStrategy listNodesStrategy;
|
||||||
private final GetNodeMetadataStrategy getNodeMetadataStrategy;
|
private final GetNodeMetadataStrategy getNodeMetadataStrategy;
|
||||||
private final CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy;
|
private final CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy;
|
||||||
|
@ -141,26 +145,29 @@ public class BaseComputeService implements ComputeService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected BaseComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
protected BaseComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
@Memoized Supplier<Set<? extends Image>> images,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
|
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy,
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
SuspendNodeStrategy suspendNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
@Named("NODE_TERMINATED") Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
Provider<TemplateOptions> templateOptionsProvider,
|
||||||
@Named("NODE_SUSPENDED") Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
|
@Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
||||||
RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials,
|
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
||||||
Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
|
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
|
||||||
Optional<ImageExtension> imageExtension) {
|
RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials,
|
||||||
|
Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
|
||||||
|
Optional<ImageExtension> imageExtension) {
|
||||||
this.context = checkNotNull(context, "context");
|
this.context = checkNotNull(context, "context");
|
||||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
this.hardwareProfiles = checkNotNull(hardwareProfiles, "hardwareProfiles");
|
this.hardwareProfiles = checkNotNull(hardwareProfiles, "hardwareProfiles");
|
||||||
this.locations = checkNotNull(locations, "locations");
|
this.locations = checkNotNull(locations, "locations");
|
||||||
this.listNodesStrategy = checkNotNull(listNodesStrategy, "listNodesStrategy");
|
|
||||||
this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy");
|
this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy");
|
||||||
|
this.listNodesStrategy = checkNotNull(listNodesStrategy, "listNodesStrategy");
|
||||||
|
this.getImageStrategy = checkNotNull(getImageStrategy, "getImageStrategy");
|
||||||
this.runNodesAndAddToSetStrategy = checkNotNull(runNodesAndAddToSetStrategy, "runNodesAndAddToSetStrategy");
|
this.runNodesAndAddToSetStrategy = checkNotNull(runNodesAndAddToSetStrategy, "runNodesAndAddToSetStrategy");
|
||||||
this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy");
|
this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy");
|
||||||
this.resumeNodeStrategy = checkNotNull(resumeNodeStrategy, "resumeNodeStrategy");
|
this.resumeNodeStrategy = checkNotNull(resumeNodeStrategy, "resumeNodeStrategy");
|
||||||
|
@ -390,6 +397,15 @@ public class BaseComputeService implements ComputeService {
|
||||||
return getNodeMetadataStrategy.getNode(id);
|
return getNodeMetadataStrategy.getNode(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Image getImage(String id) {
|
||||||
|
checkNotNull(id, "id");
|
||||||
|
return getImageStrategy.getImage(id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,8 @@ import static org.jclouds.compute.config.ComputeServiceProperties.IMAGE_LOGIN_US
|
||||||
import static org.jclouds.compute.config.ComputeServiceProperties.INIT_STATUS_INITIAL_PERIOD;
|
import static org.jclouds.compute.config.ComputeServiceProperties.INIT_STATUS_INITIAL_PERIOD;
|
||||||
import static org.jclouds.compute.config.ComputeServiceProperties.INIT_STATUS_MAX_PERIOD;
|
import static org.jclouds.compute.config.ComputeServiceProperties.INIT_STATUS_MAX_PERIOD;
|
||||||
import static org.jclouds.compute.config.ComputeServiceProperties.OS_VERSION_MAP_JSON;
|
import static org.jclouds.compute.config.ComputeServiceProperties.OS_VERSION_MAP_JSON;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_IMAGE_AVAILABLE;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_IMAGE_DELETED;
|
||||||
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||||
|
@ -32,6 +34,7 @@ import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_PORT_O
|
||||||
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
@ -113,7 +116,7 @@ public interface ComputeServiceConstants {
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class NamingConvention {
|
public static class NamingConvention {
|
||||||
|
|
||||||
@Inject(optional = true)
|
@Inject(optional = true)
|
||||||
public final Supplier<String> randomSuffix = new Supplier<String>() {
|
public final Supplier<String> randomSuffix = new Supplier<String>() {
|
||||||
final SecureRandom random = new SecureRandom();
|
final SecureRandom random = new SecureRandom();
|
||||||
|
@ -124,7 +127,7 @@ public interface ComputeServiceConstants {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class InitStatusProperties {
|
public static class InitStatusProperties {
|
||||||
@Inject(optional = true)
|
@Inject(optional = true)
|
||||||
|
@ -166,6 +169,21 @@ public interface ComputeServiceConstants {
|
||||||
@Inject(optional = true)
|
@Inject(optional = true)
|
||||||
@Named(TIMEOUT_PORT_OPEN)
|
@Named(TIMEOUT_PORT_OPEN)
|
||||||
public long portOpen = 600 * 1000;
|
public long portOpen = 600 * 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current value of {@link ComputeServiceProperties#TIMEOUT_IMAGE_DELETED} defaults to 30
|
||||||
|
* seconds.
|
||||||
|
*/
|
||||||
|
@Inject(optional = true)
|
||||||
|
@Named(TIMEOUT_IMAGE_DELETED)
|
||||||
|
public long imageDeleted = TimeUnit.SECONDS.toMillis(30);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current value of {@link ComputeServiceProperties#TIMEOUT_IMAGE_AVAILABLE} defaults to 45
|
||||||
|
* minutes.
|
||||||
|
*/
|
||||||
|
@Inject(optional = true)
|
||||||
|
@Named(TIMEOUT_IMAGE_AVAILABLE)
|
||||||
|
public long imageAvailable = TimeUnit.MINUTES.toMillis(45);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.compute.strategy;
|
package org.jclouds.compute.strategy;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.base.Throwables.getRootCause;
|
import static com.google.common.base.Throwables.getRootCause;
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
import static org.jclouds.compute.util.ComputeServiceUtils.formatStatus;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -88,7 +88,7 @@ public class CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap implements Cal
|
||||||
|
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
public CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap(
|
public CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap(
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
OpenSocketFinder openSocketFinder, Timeouts timeouts,
|
OpenSocketFinder openSocketFinder, Timeouts timeouts,
|
||||||
Function<TemplateOptions, Statement> templateOptionsToStatement,
|
Function<TemplateOptions, Statement> templateOptionsToStatement,
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, @Assisted TemplateOptions options,
|
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, @Assisted TemplateOptions options,
|
||||||
|
@ -110,7 +110,7 @@ public class CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap implements Cal
|
||||||
|
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
public CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap(
|
public CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap(
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning, GetNodeMetadataStrategy getNode,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning, GetNodeMetadataStrategy getNode,
|
||||||
OpenSocketFinder openSocketFinder, Timeouts timeouts,
|
OpenSocketFinder openSocketFinder, Timeouts timeouts,
|
||||||
Function<TemplateOptions, Statement> templateOptionsToStatement,
|
Function<TemplateOptions, Statement> templateOptionsToStatement,
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, @Assisted TemplateOptions options,
|
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, @Assisted TemplateOptions options,
|
||||||
|
|
|
@ -16,22 +16,17 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rimuhosting.miro.compute.config;
|
package org.jclouds.compute.strategy;
|
||||||
|
|
||||||
import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* returns all details associated to the image below.
|
||||||
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit")
|
public interface GetImageStrategy {
|
||||||
public class RimuHostingComputeServiceContextModuleTest {
|
|
||||||
|
|
||||||
public void testAllStatusCovered() {
|
Image getImage(String id);
|
||||||
|
|
||||||
for (RunningState state : RunningState.values()) {
|
}
|
||||||
assert RimuHostingComputeServiceDependenciesModule.runningStateToNodeStatus.containsKey(state) : state;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -32,6 +32,7 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
|
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
|
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;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
|
@ -40,6 +41,7 @@ import org.jclouds.compute.predicates.NodePredicates;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
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.PrioritizeCredentialsFromTemplate;
|
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
|
||||||
|
@ -61,8 +63,9 @@ import com.google.common.collect.Iterables;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeWithGroupEncodedIntoName,
|
public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeWithGroupEncodedIntoName,
|
||||||
DestroyNodeStrategy, GetNodeMetadataStrategy, ListNodesStrategy, RebootNodeStrategy, ResumeNodeStrategy,
|
DestroyNodeStrategy, GetNodeMetadataStrategy, GetImageStrategy, ListNodesStrategy, RebootNodeStrategy,
|
||||||
SuspendNodeStrategy {
|
ResumeNodeStrategy, SuspendNodeStrategy {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
@ -71,17 +74,20 @@ public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeW
|
||||||
private final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
|
private final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
|
||||||
private final ComputeServiceAdapter<N, H, I, L> client;
|
private final ComputeServiceAdapter<N, H, I, L> client;
|
||||||
private final Function<N, NodeMetadata> nodeMetadataAdapter;
|
private final Function<N, NodeMetadata> nodeMetadataAdapter;
|
||||||
|
private final Function<I, Image> imageAdapter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AdaptingComputeServiceStrategies(Map<String, Credentials> credentialStore,
|
public AdaptingComputeServiceStrategies(Map<String, Credentials> credentialStore,
|
||||||
PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate,
|
PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate,
|
||||||
ComputeServiceAdapter<N, H, I, L> client, Function<N, NodeMetadata> nodeMetadataAdapter) {
|
ComputeServiceAdapter<N, H, I, L> client, Function<N, NodeMetadata> nodeMetadataAdapter,
|
||||||
|
Function<I, Image> imageAdapter) {
|
||||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||||
this.prioritizeCredentialsFromTemplate = checkNotNull(prioritizeCredentialsFromTemplate,
|
this.prioritizeCredentialsFromTemplate = checkNotNull(prioritizeCredentialsFromTemplate,
|
||||||
"prioritizeCredentialsFromTemplate");
|
"prioritizeCredentialsFromTemplate");
|
||||||
this.client = checkNotNull(client, "client");
|
this.client = checkNotNull(client, "client");
|
||||||
this.nodeMetadataAdapter = Functions.compose(addLoginCredentials, checkNotNull(nodeMetadataAdapter,
|
this.nodeMetadataAdapter = Functions.compose(addLoginCredentials, checkNotNull(nodeMetadataAdapter,
|
||||||
"nodeMetadataAdapter"));
|
"nodeMetadataAdapter"));
|
||||||
|
this.imageAdapter = checkNotNull(imageAdapter, "imageAdapter");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Function<NodeMetadata, NodeMetadata> addLoginCredentials = new Function<NodeMetadata, NodeMetadata>() {
|
private final Function<NodeMetadata, NodeMetadata> addLoginCredentials = new Function<NodeMetadata, NodeMetadata>() {
|
||||||
|
@ -108,7 +114,15 @@ public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeW
|
||||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||||
return Iterables.filter(Iterables.transform(client.listNodes(), nodeMetadataAdapter), filter);
|
return Iterables.filter(Iterables.transform(client.listNodes(), nodeMetadataAdapter), filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(String id) {
|
||||||
|
I image = client.getImage(checkNotNull(id, "id"));
|
||||||
|
if (image == null)
|
||||||
|
return null;
|
||||||
|
return imageAdapter.apply(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata getNode(String id) {
|
public NodeMetadata getNode(String id) {
|
||||||
N node = client.getNode(checkNotNull(id, "id"));
|
N node = client.getNode(checkNotNull(id, "id"));
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.jclouds.compute.domain.OperatingSystem;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.compute.domain.NodeMetadata.Status;
|
import org.jclouds.compute.domain.NodeMetadata.Status;
|
||||||
|
import org.jclouds.compute.predicates.ImagePredicates;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LoginCredentials;
|
import org.jclouds.domain.LoginCredentials;
|
||||||
import org.jclouds.location.suppliers.all.JustProvider;
|
import org.jclouds.location.suppliers.all.JustProvider;
|
||||||
|
@ -51,6 +52,7 @@ import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.ImmutableList.Builder;
|
import com.google.common.collect.ImmutableList.Builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,7 +158,12 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
|
||||||
}
|
}
|
||||||
return images.build();
|
return images.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(String id) {
|
||||||
|
return Iterables.find(listImages(), ImagePredicates.idEquals(id), null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<NodeMetadata> listNodes() {
|
public Iterable<NodeMetadata> listNodes() {
|
||||||
return nodes.values();
|
return nodes.values();
|
||||||
|
@ -230,4 +237,5 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
|
||||||
setStateOnNode(Status.PENDING, node);
|
setStateOnNode(Status.PENDING, node);
|
||||||
setStateOnNodeAfterDelay(Status.SUSPENDED, node, 50);
|
setStateOnNodeAfterDelay(Status.SUSPENDED, node, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.collect.Iterables.concat;
|
import static com.google.common.collect.Iterables.concat;
|
||||||
import static com.google.common.collect.Iterables.size;
|
import static com.google.common.collect.Iterables.size;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
@ -33,7 +34,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
public class ConcurrentOpenSocketFinder implements OpenSocketFinder {
|
public class ConcurrentOpenSocketFinder implements OpenSocketFinder {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -46,7 +46,7 @@ public class ConcurrentOpenSocketFinder implements OpenSocketFinder {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ConcurrentOpenSocketFinder(SocketOpen socketTester,
|
public ConcurrentOpenSocketFinder(SocketOpen socketTester,
|
||||||
@Named("NODE_RUNNING") final Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
@Named(TIMEOUT_NODE_RUNNING) final Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads) {
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userThreads) {
|
||||||
this.socketTester = socketTester;
|
this.socketTester = socketTester;
|
||||||
this.nodeRunning = nodeRunning;
|
this.nodeRunning = nodeRunning;
|
||||||
|
|
|
@ -207,6 +207,11 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
||||||
client.runScriptOnNodesMatching(runningInGroup("zebras-are-awesome"), InstallJDK.fromOpenJDK());
|
client.runScriptOnNodesMatching(runningInGroup("zebras-are-awesome"), InstallJDK.fromOpenJDK());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testImageById() {
|
||||||
|
Template defaultTemplate = view.getComputeService().templateBuilder().build();
|
||||||
|
assertEquals(view.getComputeService().getImage(defaultTemplate.getImage().getId()), defaultTemplate.getImage());
|
||||||
|
}
|
||||||
|
|
||||||
// since surefire and eclipse don't otherwise guarantee the order, we are
|
// since surefire and eclipse don't otherwise guarantee the order, we are
|
||||||
// starting this one alphabetically before create2nodes..
|
// starting this one alphabetically before create2nodes..
|
||||||
@Test(enabled = true, dependsOnMethods = { "testCompareSizes" })
|
@Test(enabled = true, dependsOnMethods = { "testCompareSizes" })
|
||||||
|
|
|
@ -194,7 +194,20 @@ public class GleSYSComputeServiceAdapter implements ComputeServiceAdapter<Server
|
||||||
public Set<OSTemplate> listImages() {
|
public Set<OSTemplate> listImages() {
|
||||||
return client.getServerClient().listTemplates();
|
return client.getServerClient().listTemplates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cheat until we have a getTemplate command
|
||||||
|
@Override
|
||||||
|
public OSTemplate getImage(final String id) {
|
||||||
|
return Iterables.find(listImages(), new Predicate<OSTemplate>(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(OSTemplate input) {
|
||||||
|
return input.getName().equals(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<ServerDetails> listNodes() {
|
public Iterable<ServerDetails> listNodes() {
|
||||||
return Iterables2.concreteCopy(transformParallel(client.getServerClient().listServers(), new Function<Server, Future<? extends ServerDetails>>() {
|
return Iterables2.concreteCopy(transformParallel(client.getServerClient().listServers(), new Function<Server, Future<? extends ServerDetails>>() {
|
||||||
|
|
|
@ -47,8 +47,8 @@ import org.jclouds.savvis.vpdc.reference.VCloudMediaType;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSet.Builder;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
;
|
;
|
||||||
|
@ -124,6 +124,19 @@ public class VPDCComputeServiceAdapter implements ComputeServiceAdapter<VM, VMSp
|
||||||
return client.listPredefinedOperatingSystems();
|
return client.listPredefinedOperatingSystems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cheat until we have a getImage command
|
||||||
|
@Override
|
||||||
|
public CIMOperatingSystem getImage(final String id) {
|
||||||
|
return Iterables.find(listImages(), new Predicate<CIMOperatingSystem>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(CIMOperatingSystem input) {
|
||||||
|
return (input.getOsType().getCode() + "").equals(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<VM> listNodes() {
|
public Iterable<VM> listNodes() {
|
||||||
Builder<VM> builder = ImmutableSet.builder();
|
Builder<VM> builder = ImmutableSet.builder();
|
||||||
|
|
|
@ -186,6 +186,14 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
throw Throwables.propagate(e);
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(String vmName) {
|
||||||
|
IMachine image = getNode(vmName);
|
||||||
|
if (image == null)
|
||||||
|
return null;
|
||||||
|
return imachineToImage.apply(image);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void destroyNode(String vmName) {
|
public synchronized void destroyNode(String vmName) {
|
||||||
|
|
|
@ -22,6 +22,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES;
|
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -57,6 +60,7 @@ import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
|
@ -98,14 +102,14 @@ public class AWSEC2ComputeService extends EC2ComputeService {
|
||||||
protected AWSEC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
protected AWSEC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy,
|
GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||||
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy startNodeStrategy,
|
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy startNodeStrategy,
|
||||||
SuspendNodeStrategy stopNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
SuspendNodeStrategy stopNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
Provider<TemplateOptions> templateOptionsProvider,
|
Provider<TemplateOptions> templateOptionsProvider,
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
@Named("NODE_TERMINATED") Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
@Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
||||||
@Named("NODE_SUSPENDED") Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
|
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
|
||||||
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
|
||||||
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
||||||
|
@ -116,7 +120,7 @@ public class AWSEC2ComputeService extends EC2ComputeService {
|
||||||
@Named("DELETED") Predicate<PlacementGroup> placementGroupDeleted,
|
@Named("DELETED") Predicate<PlacementGroup> placementGroupDeleted,
|
||||||
@Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames, AWSEC2AsyncClient aclient,
|
@Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames, AWSEC2AsyncClient aclient,
|
||||||
Optional<ImageExtension> imageExtension, GroupNamingConvention.Factory namingConvention) {
|
Optional<ImageExtension> imageExtension, GroupNamingConvention.Factory namingConvention) {
|
||||||
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy, getNodeMetadataStrategy,
|
||||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy,
|
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy,
|
||||||
stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
|
stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
|
||||||
nodeSuspended, initScriptRunnerFactory, runScriptOnNodeFactory, initAdminAccess, persistNodeCredentials,
|
nodeSuspended, initScriptRunnerFactory, runScriptOnNodeFactory, initAdminAccess, persistNodeCredentials,
|
||||||
|
|
|
@ -51,6 +51,7 @@ import org.jclouds.ec2.compute.domain.RegionAndName;
|
||||||
import org.jclouds.ec2.compute.extensions.EC2ImageExtension;
|
import org.jclouds.ec2.compute.extensions.EC2ImageExtension;
|
||||||
import org.jclouds.ec2.compute.functions.CreateUniqueKeyPair;
|
import org.jclouds.ec2.compute.functions.CreateUniqueKeyPair;
|
||||||
import org.jclouds.ec2.compute.functions.CredentialsForInstance;
|
import org.jclouds.ec2.compute.functions.CredentialsForInstance;
|
||||||
|
import org.jclouds.ec2.compute.functions.EC2ImageParser;
|
||||||
import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
|
import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
|
||||||
import org.jclouds.ec2.compute.loaders.CreateSecurityGroupIfNeeded;
|
import org.jclouds.ec2.compute.loaders.CreateSecurityGroupIfNeeded;
|
||||||
import org.jclouds.ec2.compute.loaders.LoadPublicIpForInstanceOrNull;
|
import org.jclouds.ec2.compute.loaders.LoadPublicIpForInstanceOrNull;
|
||||||
|
@ -98,6 +99,8 @@ public class AWSEC2ComputeServiceDependenciesModule extends EC2ComputeServiceDep
|
||||||
bind(new TypeLiteral<CacheLoader<RegionAndName, Image>>() {
|
bind(new TypeLiteral<CacheLoader<RegionAndName, Image>>() {
|
||||||
}).to(RegionAndIdToImage.class);
|
}).to(RegionAndIdToImage.class);
|
||||||
install(new FactoryModuleBuilder().build(CallForImages.Factory.class));
|
install(new FactoryModuleBuilder().build(CallForImages.Factory.class));
|
||||||
|
bind(new TypeLiteral<Function<org.jclouds.ec2.domain.Image, Image>>() {
|
||||||
|
}).to(EC2ImageParser.class);
|
||||||
bind(new TypeLiteral<ImageExtension>() {
|
bind(new TypeLiteral<ImageExtension>() {
|
||||||
}).to(EC2ImageExtension.class);
|
}).to(EC2ImageExtension.class);
|
||||||
bind(new TypeLiteral<PredicateWithResult<String, Image>>() {
|
bind(new TypeLiteral<PredicateWithResult<String, Image>>() {
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.ec2.compute.strategy;
|
package org.jclouds.aws.ec2.compute.strategy;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES;
|
import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsValuesOfEmptyString;
|
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsValuesOfEmptyString;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -81,7 +81,7 @@ public class AWSEC2CreateNodesInGroupThenAddToSet extends EC2CreateNodesInGroupT
|
||||||
protected AWSEC2CreateNodesInGroupThenAddToSet(
|
protected AWSEC2CreateNodesInGroupThenAddToSet(
|
||||||
AWSEC2Client client,
|
AWSEC2Client client,
|
||||||
@Named("ELASTICIP") LoadingCache<RegionAndName, String> elasticIpCache,
|
@Named("ELASTICIP") LoadingCache<RegionAndName, String> elasticIpCache,
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
AWSEC2AsyncClient aclient,
|
AWSEC2AsyncClient aclient,
|
||||||
@Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames,
|
@Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider,
|
Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.gogrid.compute;
|
package org.jclouds.gogrid.compute;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
|
||||||
|
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -43,6 +46,7 @@ import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
import org.jclouds.compute.strategy.GetImageStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
|
@ -65,23 +69,26 @@ import com.google.common.base.Supplier;
|
||||||
public class GoGridComputeService extends BaseComputeService {
|
public class GoGridComputeService extends BaseComputeService {
|
||||||
@Inject
|
@Inject
|
||||||
protected GoGridComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
protected GoGridComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
||||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
@Memoized Supplier<Set<? extends Image>> images,
|
||||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
|
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
|
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
|
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy,
|
||||||
@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
SuspendNodeStrategy suspendNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
@Named("NODE_TERMINATED") Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
Provider<TemplateOptions> templateOptionsProvider,
|
||||||
@Named("NODE_SUSPENDED") Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
|
@Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
|
||||||
RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
|
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Optional<ImageExtension> imageExtension) {
|
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
|
||||||
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getNodeMetadataStrategy,
|
RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials,
|
||||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
|
Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
|
||||||
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
|
Optional<ImageExtension> imageExtension) {
|
||||||
nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, persistNodeCredentials, timeouts,
|
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getImageStrategy,
|
||||||
executor, imageExtension);
|
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
|
||||||
|
resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
|
||||||
|
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
|
||||||
|
persistNodeCredentials, timeouts, executor, imageExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.gogrid.compute.strategy;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -143,13 +142,16 @@ public class GoGridComputeServiceAdapter implements ComputeServiceAdapter<Server
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Server getNode(String id) {
|
public Server getNode(String id) {
|
||||||
try {
|
return Iterables.getOnlyElement(client.getServerServices().getServersById(Long.valueOf(checkNotNull(id, "id"))),
|
||||||
return Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(checkNotNull(id, "id"))));
|
null);
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerImage getImage(String id) {
|
||||||
|
return Iterables.getOnlyElement(client.getImageServices().getImagesById(Long.valueOf(checkNotNull(id, "id"))),
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(String id) {
|
public void destroyNode(String id) {
|
||||||
client.getServerServices().deleteById(new Long(id));
|
client.getServerServices().deleteById(new Long(id));
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.jclouds.rimuhosting.miro.compute.config;
|
|
||||||
|
|
||||||
import org.jclouds.compute.config.BindComputeStrategiesByClass;
|
|
||||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
|
||||||
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.ResumeNodeStrategy;
|
|
||||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingCreateNodeWithGroupEncodedIntoName;
|
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingDestroyNodeStrategy;
|
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingGetNodeMetadataStrategy;
|
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingLifeCycleStrategy;
|
|
||||||
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingListNodesStrategy;
|
|
||||||
|
|
||||||
public class RimuHostingBindComputeStrategiesByClass extends BindComputeStrategiesByClass {
|
|
||||||
@Override
|
|
||||||
protected Class<? extends CreateNodeWithGroupEncodedIntoName> defineAddNodeWithTagStrategy() {
|
|
||||||
return RimuHostingCreateNodeWithGroupEncodedIntoName.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends DestroyNodeStrategy> defineDestroyNodeStrategy() {
|
|
||||||
return RimuHostingDestroyNodeStrategy.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends GetNodeMetadataStrategy> defineGetNodeMetadataStrategy() {
|
|
||||||
return RimuHostingGetNodeMetadataStrategy.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends ListNodesStrategy> defineListNodesStrategy() {
|
|
||||||
return RimuHostingListNodesStrategy.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends RebootNodeStrategy> defineRebootNodeStrategy() {
|
|
||||||
return RimuHostingLifeCycleStrategy.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends ResumeNodeStrategy> defineStartNodeStrategy() {
|
|
||||||
return RimuHostingLifeCycleStrategy.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends SuspendNodeStrategy> defineStopNodeStrategy() {
|
|
||||||
return RimuHostingLifeCycleStrategy.class;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.jclouds.rimuhosting.miro.compute.config;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.jclouds.compute.config.BindComputeSuppliersByClass;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
|
||||||
import org.jclouds.compute.domain.Image;
|
|
||||||
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingHardwareSupplier;
|
|
||||||
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingImageSupplier;
|
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
|
|
||||||
public class RimuHostingBindComputeSuppliersByClass extends BindComputeSuppliersByClass {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends Supplier<Set<? extends Hardware>>> defineHardwareSupplier() {
|
|
||||||
return RimuHostingHardwareSupplier.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
|
|
||||||
return RimuHostingImageSupplier.class;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,22 +18,90 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rimuhosting.miro.compute.config;
|
package org.jclouds.rimuhosting.miro.compute.config;
|
||||||
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
|
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.NodeMetadata.Status;
|
||||||
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.functions.IdentityFunction;
|
||||||
|
import org.jclouds.rimuhosting.miro.compute.functions.RimuHostingImageToImage;
|
||||||
|
import org.jclouds.rimuhosting.miro.compute.functions.ServerToNodeMetadata;
|
||||||
|
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingComputeServiceAdapter;
|
||||||
|
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.Provides;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link RimuHostingComputeServiceContext}; requires
|
* Configures the {@link RimuHostingComputeServiceContext}; requires {@link BaseComputeService}
|
||||||
* {@link RimuHostingComputeService} bound.
|
* bound.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class RimuHostingComputeServiceContextModule extends BaseComputeServiceContextModule {
|
public class RimuHostingComputeServiceContextModule extends
|
||||||
|
ComputeServiceAdapterContextModule<Server, Hardware, org.jclouds.rimuhosting.miro.domain.Image, Location> {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new RimuHostingComputeServiceDependenciesModule());
|
|
||||||
install(new RimuHostingBindComputeStrategiesByClass());
|
|
||||||
install(new RimuHostingBindComputeSuppliersByClass());
|
|
||||||
super.configure();
|
super.configure();
|
||||||
|
bind(
|
||||||
|
new TypeLiteral<ComputeServiceAdapter<Server, Hardware, org.jclouds.rimuhosting.miro.domain.Image, Location>>() {
|
||||||
|
}).to(RimuHostingComputeServiceAdapter.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
||||||
|
}).to(ServerToNodeMetadata.class);
|
||||||
|
bind(new TypeLiteral<Function<Server, Iterable<String>>>() {
|
||||||
|
}).to(ServerToPublicAddresses.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<org.jclouds.rimuhosting.miro.domain.Image, Image>>() {
|
||||||
|
}).to(RimuHostingImageToImage.class);
|
||||||
|
|
||||||
|
bind(new TypeLiteral<Function<Hardware, Hardware>>() {
|
||||||
|
}).to((Class) IdentityFunction.class);
|
||||||
|
|
||||||
|
// we aren't converting location from a provider-specific type
|
||||||
|
bind(new TypeLiteral<Function<Location, Location>>() {
|
||||||
|
}).to((Class) IdentityFunction.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final Map<RunningState, Status> runningStateToNodeStatus = ImmutableMap.<RunningState, Status> builder().put(
|
||||||
|
RunningState.RUNNING, Status.RUNNING)//
|
||||||
|
.put(RunningState.NOTRUNNING, Status.SUSPENDED)//
|
||||||
|
.put(RunningState.POWERCYCLING, Status.PENDING)//
|
||||||
|
.put(RunningState.RESTARTING, Status.PENDING)//
|
||||||
|
.put(RunningState.UNRECOGNIZED, Status.UNRECOGNIZED)//
|
||||||
|
.build();
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Map<RunningState, Status> provideServerToNodeStatus() {
|
||||||
|
return runningStateToNodeStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.jclouds.rimuhosting.miro.compute.config;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata.Status;
|
|
||||||
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.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<Function<Server, Iterable<String>>>() {
|
|
||||||
}).to(ServerToPublicAddresses.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final Map<RunningState, Status> runningStateToNodeStatus = ImmutableMap.<RunningState, Status> builder()
|
|
||||||
.put(RunningState.RUNNING, Status.RUNNING)//
|
|
||||||
.put(RunningState.NOTRUNNING, Status.SUSPENDED)//
|
|
||||||
.put(RunningState.POWERCYCLING, Status.PENDING)//
|
|
||||||
.put(RunningState.RESTARTING, Status.PENDING)//
|
|
||||||
.put(RunningState.UNRECOGNIZED, Status.UNRECOGNIZED)//
|
|
||||||
.build();
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
@Provides
|
|
||||||
Map<RunningState, Status> provideServerToNodeStatus() {
|
|
||||||
return runningStateToNodeStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,14 +16,12 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rimuhosting.miro.compute.suppliers;
|
package org.jclouds.rimuhosting.miro.compute.functions;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
@ -34,46 +32,31 @@ import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.domain.Image.Status;
|
import org.jclouds.compute.domain.Image.Status;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class RimuHostingImageSupplier implements Supplier<Set<? extends Image>> {
|
public class RimuHostingImageToImage implements Function<org.jclouds.rimuhosting.miro.domain.Image, Image> {
|
||||||
public static final Pattern RIMU_PATTERN = Pattern.compile("([a-zA-Z]+) ?([0-9.]+) .*");
|
|
||||||
private final RimuHostingClient sync;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
RimuHostingImageSupplier(RimuHostingClient sync) {
|
|
||||||
this.sync = sync;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
private Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Override
|
public Image apply(org.jclouds.rimuhosting.miro.domain.Image from) {
|
||||||
public Set<? extends Image> get() {
|
ImageBuilder builder = new ImageBuilder();
|
||||||
final Set<Image> images = Sets.newHashSet();
|
builder.ids(from.getId() + "");
|
||||||
logger.debug(">> providing images");
|
builder.name(from.getDescription());
|
||||||
for (org.jclouds.rimuhosting.miro.domain.Image from : sync.getImageList()) {
|
builder.description(from.getDescription());
|
||||||
ImageBuilder builder = new ImageBuilder();
|
builder.operatingSystem(parseOs(from));
|
||||||
builder.ids(from.getId() + "");
|
builder.status(Status.AVAILABLE);
|
||||||
builder.name(from.getDescription());
|
return builder.build();
|
||||||
builder.description(from.getDescription());
|
|
||||||
builder.operatingSystem(parseOs(from));
|
|
||||||
builder.status(Status.AVAILABLE);
|
|
||||||
images.add(builder.build());
|
|
||||||
}
|
|
||||||
logger.debug("<< images(%d)", images.size());
|
|
||||||
return images;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Pattern RIMU_PATTERN = Pattern.compile("([a-zA-Z]+) ?([0-9.]+) .*");
|
||||||
|
|
||||||
protected OperatingSystem parseOs(final org.jclouds.rimuhosting.miro.domain.Image from) {
|
protected OperatingSystem parseOs(final org.jclouds.rimuhosting.miro.domain.Image from) {
|
||||||
OsFamily osFamily = null;
|
OsFamily osFamily = null;
|
||||||
String osName = from.getId();
|
String osName = from.getId();
|
|
@ -0,0 +1,172 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.rimuhosting.miro.compute.strategy;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.collect.Memoized;
|
||||||
|
import org.jclouds.compute.ComputeService;
|
||||||
|
import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.HardwareBuilder;
|
||||||
|
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.reference.ComputeServiceConstants;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.domain.LoginCredentials;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
||||||
|
import org.jclouds.rimuhosting.miro.domain.Image;
|
||||||
|
import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
|
||||||
|
import org.jclouds.rimuhosting.miro.domain.PricingPlan;
|
||||||
|
import org.jclouds.rimuhosting.miro.domain.Server;
|
||||||
|
import org.jclouds.util.Iterables2;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* defines the connection between the {@link RimuHostingClient} implementation and the jclouds
|
||||||
|
* {@link ComputeService}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class RimuHostingComputeServiceAdapter implements ComputeServiceAdapter<Server, Hardware, Image, Location> {
|
||||||
|
@Resource
|
||||||
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
|
private Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
private final RimuHostingClient client;
|
||||||
|
private final Supplier<Set<? extends Location>> locations;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected RimuHostingComputeServiceAdapter(RimuHostingClient client,
|
||||||
|
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||||
|
this.client = checkNotNull(client, "client");
|
||||||
|
this.locations = checkNotNull(locations, "locations");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeAndInitialCredentials<Server> createNodeWithGroupEncodedIntoName(String group, String name,
|
||||||
|
Template template) {
|
||||||
|
NewServerResponse server = client.createServer(name,
|
||||||
|
checkNotNull(template.getImage().getProviderId(), "imageId"), checkNotNull(template.getHardware()
|
||||||
|
.getProviderId(), "hardwareId"));
|
||||||
|
|
||||||
|
return new NodeAndInitialCredentials<Server>(server.getServer(), server.getServer().getId() + "",
|
||||||
|
LoginCredentials.builder().password(server.getNewInstanceRequest().getCreateOptions().getPassword())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Hardware> listHardwareProfiles() {
|
||||||
|
final Set<Hardware> sizes = Sets.newHashSet();
|
||||||
|
for (final PricingPlan from : client.getPricingPlanList()) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
final Location location = Iterables.find(locations.get(), new Predicate<Location>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Location input) {
|
||||||
|
return input.getId().equals(from.getDataCenter().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
sizes.add(new HardwareBuilder().ids(from.getId()).location(location).processors(
|
||||||
|
ImmutableList.of(new Processor(1, 1.0))).ram(from.getRam()).volumes(
|
||||||
|
ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSize(), true, true))).build());
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
logger.warn("datacenter not present in " + from.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Image> listImages() {
|
||||||
|
return Iterables2.concreteCopy(client.getImageList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Server> listNodes() {
|
||||||
|
return Iterables2.concreteCopy(client.getServerList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Location> listLocations() {
|
||||||
|
// Not using the adapter to determine locations
|
||||||
|
return ImmutableSet.<Location> of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Server getNode(String id) {
|
||||||
|
long serverId = Long.parseLong(id);
|
||||||
|
return client.getServer(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// cheat until we have a getImage command
|
||||||
|
@Override
|
||||||
|
public Image getImage(final String id) {
|
||||||
|
return Iterables.find(listImages(), new Predicate<Image>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Image input) {
|
||||||
|
return input.getId().equals(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyNode(String id) {
|
||||||
|
Long serverId = Long.parseLong(id);
|
||||||
|
client.destroyServer(serverId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rebootNode(String id) {
|
||||||
|
Long serverId = Long.parseLong(id);
|
||||||
|
// if false server wasn't around in the first place
|
||||||
|
client.restartServer(serverId).getState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resumeNode(String id) {
|
||||||
|
throw new UnsupportedOperationException("suspend not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void suspendNode(String id) {
|
||||||
|
throw new UnsupportedOperationException("suspend not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,66 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.jclouds.rimuhosting.miro.compute.strategy;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.Template;
|
|
||||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
|
||||||
import org.jclouds.domain.Credentials;
|
|
||||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
|
||||||
import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
|
|
||||||
import org.jclouds.rimuhosting.miro.domain.Server;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class RimuHostingCreateNodeWithGroupEncodedIntoName implements CreateNodeWithGroupEncodedIntoName {
|
|
||||||
protected final RimuHostingClient client;
|
|
||||||
protected final Map<String, Credentials> credentialStore;
|
|
||||||
protected final Function<Server, NodeMetadata> serverToNodeMetadata;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected RimuHostingCreateNodeWithGroupEncodedIntoName(RimuHostingClient client, Map<String, Credentials> credentialStore,
|
|
||||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
|
||||||
this.client = client;
|
|
||||||
this.credentialStore = credentialStore;
|
|
||||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
|
|
||||||
NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(),
|
|
||||||
"imageId"), checkNotNull(template.getHardware().getProviderId(), "hardwareId"));
|
|
||||||
Server from = client.getServer(serverResponse.getServer().getId());
|
|
||||||
credentialStore.put("node#" + from.getId(), new Credentials("root", serverResponse.getNewInstanceRequest()
|
|
||||||
.getCreateOptions().getPassword()));
|
|
||||||
return serverToNodeMetadata.apply(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.jclouds.rimuhosting.miro.compute.strategy;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
|
||||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class RimuHostingDestroyNodeStrategy implements DestroyNodeStrategy {
|
|
||||||
private final RimuHostingClient client;
|
|
||||||
private final GetNodeMetadataStrategy getNode;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected RimuHostingDestroyNodeStrategy(RimuHostingClient client, GetNodeMetadataStrategy getNode) {
|
|
||||||
this.client = client;
|
|
||||||
this.getNode = getNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeMetadata destroyNode(String id) {
|
|
||||||
Long serverId = Long.parseLong(id);
|
|
||||||
client.destroyServer(serverId);
|
|
||||||
return getNode.getNode(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.jclouds.rimuhosting.miro.compute.strategy;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
|
||||||
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
|
||||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
|
||||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class RimuHostingLifeCycleStrategy implements RebootNodeStrategy, SuspendNodeStrategy, ResumeNodeStrategy {
|
|
||||||
private final RimuHostingClient client;
|
|
||||||
private final GetNodeMetadataStrategy getNode;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected RimuHostingLifeCycleStrategy(RimuHostingClient client, GetNodeMetadataStrategy getNode) {
|
|
||||||
this.client = client;
|
|
||||||
this.getNode = getNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeMetadata rebootNode(String id) {
|
|
||||||
Long serverId = Long.parseLong(id);
|
|
||||||
// if false server wasn't around in the first place
|
|
||||||
client.restartServer(serverId).getState();
|
|
||||||
return getNode.getNode(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeMetadata suspendNode(String id) {
|
|
||||||
throw new UnsupportedOperationException("suspend not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeMetadata resumeNode(String id) {
|
|
||||||
throw new UnsupportedOperationException("resume not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.jclouds.rimuhosting.miro.compute.strategy;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.predicates.NodePredicates;
|
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
|
||||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
|
||||||
import org.jclouds.rimuhosting.miro.domain.Server;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class RimuHostingListNodesStrategy implements ListNodesStrategy {
|
|
||||||
private final RimuHostingClient client;
|
|
||||||
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected RimuHostingListNodesStrategy(RimuHostingClient client,
|
|
||||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
|
||||||
this.client = client;
|
|
||||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<? extends ComputeMetadata> listNodes() {
|
|
||||||
return listDetailsOnNodesMatching(NodePredicates.all());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
|
||||||
return Iterables.filter(Iterables.transform(client.getServerList(), serverToNodeMetadata), filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,91 +0,0 @@
|
||||||
/**
|
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. jclouds licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.jclouds.rimuhosting.miro.compute.suppliers;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.collect.Memoized;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
|
||||||
import org.jclouds.compute.domain.HardwareBuilder;
|
|
||||||
import org.jclouds.compute.domain.Processor;
|
|
||||||
import org.jclouds.compute.domain.Volume;
|
|
||||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.logging.Logger;
|
|
||||||
import org.jclouds.rimuhosting.miro.RimuHostingClient;
|
|
||||||
import org.jclouds.rimuhosting.miro.domain.PricingPlan;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class RimuHostingHardwareSupplier implements Supplier<Set<? extends Hardware>> {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
|
||||||
protected Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
private final RimuHostingClient sync;
|
|
||||||
private final Supplier<Set<? extends Location>> locations;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
RimuHostingHardwareSupplier(RimuHostingClient sync, @Memoized Supplier<Set<? extends Location>> locations) {
|
|
||||||
this.sync = sync;
|
|
||||||
this.locations = locations;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<? extends Hardware> get() {
|
|
||||||
final Set<Hardware> sizes = Sets.newHashSet();
|
|
||||||
logger.debug(">> providing sizes");
|
|
||||||
for (final PricingPlan from : sync.getPricingPlanList()) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
final Location location = Iterables.find(locations.get(), new Predicate<Location>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(Location input) {
|
|
||||||
return input.getId().equals(from.getDataCenter().getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
sizes.add(new HardwareBuilder().ids(from.getId()).location(location).processors(
|
|
||||||
ImmutableList.of(new Processor(1, 1.0))).ram(from.getRam()).volumes(
|
|
||||||
ImmutableList.<Volume> of(new VolumeImpl((float) from.getDiskSize(), true, true))).build());
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
logger.warn("datacenter not present in " + from.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logger.debug("<< sizes(%d)", sizes.size());
|
|
||||||
return sizes;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -64,7 +64,6 @@ public class SlicehostComputeServiceAdapter implements ComputeServiceAdapter<Sli
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Flavor> listHardwareProfiles() {
|
public Iterable<Flavor> listHardwareProfiles() {
|
||||||
return client.listFlavors();
|
return client.listFlavors();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,7 +87,13 @@ public class SlicehostComputeServiceAdapter implements ComputeServiceAdapter<Sli
|
||||||
int serverId = Integer.parseInt(id);
|
int serverId = Integer.parseInt(id);
|
||||||
return client.getSlice(serverId);
|
return client.getSlice(serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(String id) {
|
||||||
|
int imageId = Integer.parseInt(id);
|
||||||
|
return client.getImage(imageId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(String id) {
|
public void destroyNode(String id) {
|
||||||
int serverId = Integer.parseInt(id);
|
int serverId = Integer.parseInt(id);
|
||||||
|
|
|
@ -50,6 +50,7 @@ import org.jclouds.domain.LoginCredentials;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
import org.jclouds.softlayer.SoftLayerClient;
|
import org.jclouds.softlayer.SoftLayerClient;
|
||||||
|
import org.jclouds.softlayer.compute.functions.ProductItemToImage;
|
||||||
import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions;
|
import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions;
|
||||||
import org.jclouds.softlayer.domain.Datacenter;
|
import org.jclouds.softlayer.domain.Datacenter;
|
||||||
import org.jclouds.softlayer.domain.Password;
|
import org.jclouds.softlayer.domain.Password;
|
||||||
|
@ -64,8 +65,8 @@ import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSet.Builder;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.ImmutableSet.Builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* defines the connection between the {@link SoftLayerClient} implementation and
|
* defines the connection between the {@link SoftLayerClient} implementation and
|
||||||
|
@ -182,7 +183,20 @@ public class SoftLayerComputeServiceAdapter implements
|
||||||
public Iterable<ProductItem> listImages() {
|
public Iterable<ProductItem> listImages() {
|
||||||
return filter(productPackageSupplier.get().getItems(), categoryCode("os"));
|
return filter(productPackageSupplier.get().getItems(), categoryCode("os"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cheat until we have a getProductItem command
|
||||||
|
@Override
|
||||||
|
public ProductItem getImage(final String id) {
|
||||||
|
return Iterables.find(listImages(), new Predicate<ProductItem>(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(ProductItem input) {
|
||||||
|
return ProductItemToImage.imageId().apply(input).equals(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<VirtualGuest> listNodes() {
|
public Iterable<VirtualGuest> listNodes() {
|
||||||
return Iterables.filter(client.getVirtualGuestClient().listVirtualGuests(), new Predicate<VirtualGuest>() {
|
return Iterables.filter(client.getVirtualGuestClient().listVirtualGuests(), new Predicate<VirtualGuest>() {
|
||||||
|
|
|
@ -69,6 +69,12 @@ public class ServerManagerComputeServiceAdapter implements ComputeServiceAdapter
|
||||||
return client.listImages();
|
return client.listImages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(String id) {
|
||||||
|
int imageId = Integer.parseInt(id);
|
||||||
|
return client.getImage(imageId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Server> listNodes() {
|
public Iterable<Server> listNodes() {
|
||||||
return client.listServers();
|
return client.listServers();
|
||||||
|
|
Loading…
Reference in New Issue