mirror of https://github.com/apache/jclouds.git
Issue 252: created templateBuilder.any() which can be used to get the known bootable params of a template, as well helper functions
This commit is contained in:
parent
bf3e66a6b2
commit
d8e21ad8d0
|
@ -35,6 +35,7 @@ import org.jclouds.aws.ec2.EC2Client;
|
||||||
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule.GetRegionFromLocation;
|
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule.GetRegionFromLocation;
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules;
|
import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules;
|
||||||
|
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
||||||
import org.jclouds.aws.ec2.domain.KeyPair;
|
import org.jclouds.aws.ec2.domain.KeyPair;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -42,6 +43,7 @@ import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.Size;
|
import org.jclouds.compute.domain.Size;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
|
@ -70,13 +72,14 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy,
|
GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, ComputeUtils utils,
|
Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
|
Provider<TemplateOptions> templateOptionsProvider, ComputeUtils utils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client,
|
||||||
GetRegionFromLocation getRegionFromLocation,
|
GetRegionFromLocation getRegionFromLocation,
|
||||||
Map<RegionAndName, KeyPair> credentialsMap, Map<RegionAndName, String> securityGroupMap) {
|
Map<RegionAndName, KeyPair> credentialsMap, Map<RegionAndName, String> securityGroupMap) {
|
||||||
super(context, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
super(context, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
|
||||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
|
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
|
||||||
templateBuilderProvider, utils, executor);
|
templateBuilderProvider, templateOptionsProvider, utils, executor);
|
||||||
this.ec2Client = ec2Client;
|
this.ec2Client = ec2Client;
|
||||||
this.getRegionFromLocation = getRegionFromLocation;
|
this.getRegionFromLocation = getRegionFromLocation;
|
||||||
this.credentialsMap = credentialsMap;
|
this.credentialsMap = credentialsMap;
|
||||||
|
@ -107,6 +110,10 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* like {@link BaseComputeService#destroyNodesMatching} except that this will clean implicit
|
||||||
|
* keypairs and security groups.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
|
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
|
||||||
Set<? extends NodeMetadata> deadOnes = super.destroyNodesMatching(filter);
|
Set<? extends NodeMetadata> deadOnes = super.destroyNodesMatching(filter);
|
||||||
|
@ -122,4 +129,12 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
}
|
}
|
||||||
return deadOnes;
|
return deadOnes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns template options, except of type {@link EC2TemplateOptions}.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public EC2TemplateOptions templateOptions() {
|
||||||
|
return EC2TemplateOptions.class.cast(super.templateOptions());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -64,7 +64,6 @@ import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.Size;
|
import org.jclouds.compute.domain.Size;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.predicates.NodePredicates;
|
import org.jclouds.compute.predicates.NodePredicates;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
||||||
|
@ -139,7 +138,8 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
TemplateBuilder provideTemplate(TemplateBuilderImpl template) {
|
@Named("DEFAULT")
|
||||||
|
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||||
return template.architecture(Architecture.X86_32).osFamily(UBUNTU);
|
return template.architecture(Architecture.X86_32).osFamily(UBUNTU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.jclouds.compute.domain.Architecture;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
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.TemplateBuilder;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.predicates.NodePredicates;
|
import org.jclouds.compute.predicates.NodePredicates;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||||
|
@ -83,11 +83,6 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
return new JschSshClientModule();
|
return new JschSshClientModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Template buildTemplate(TemplateBuilder templateBuilder) {
|
|
||||||
return templateBuilder.imageId("ami-714ba518").build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtendedOptionsAndLogin() throws Exception {
|
public void testExtendedOptionsAndLogin() throws Exception {
|
||||||
SecurityGroupClient securityGroupClient = EC2Client.class.cast(
|
SecurityGroupClient securityGroupClient = EC2Client.class.cast(
|
||||||
|
@ -101,10 +96,10 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
String tag = this.tag + "optionsandlogin";
|
String tag = this.tag + "optionsandlogin";
|
||||||
|
|
||||||
Template template = buildTemplate(client.templateBuilder());
|
TemplateOptions options = client.templateOptions();
|
||||||
|
|
||||||
template.getOptions().as(EC2TemplateOptions.class).securityGroups(tag);
|
options.as(EC2TemplateOptions.class).securityGroups(tag);
|
||||||
template.getOptions().as(EC2TemplateOptions.class).keyPair(tag);
|
options.as(EC2TemplateOptions.class).keyPair(tag);
|
||||||
|
|
||||||
String startedId = null;
|
String startedId = null;
|
||||||
try {
|
try {
|
||||||
|
@ -116,9 +111,10 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
// create a keypair to pass in as well
|
// create a keypair to pass in as well
|
||||||
KeyPair result = keyPairClient.createKeyPairInRegion(null, tag);
|
KeyPair result = keyPairClient.createKeyPairInRegion(null, tag);
|
||||||
|
|
||||||
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, template);
|
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
|
||||||
Credentials good = nodes.iterator().next().getCredentials();
|
NodeMetadata first = Iterables.get(nodes, 0);
|
||||||
assert good.account != null;
|
assert first.getCredentials() != null : first;
|
||||||
|
assert first.getCredentials().account != null : first;
|
||||||
|
|
||||||
startedId = Iterables.getOnlyElement(nodes).getId();
|
startedId = Iterables.getOnlyElement(nodes).getId();
|
||||||
|
|
||||||
|
@ -135,8 +131,8 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
assert group.getIpPermissions().size() == 0 : group;
|
assert group.getIpPermissions().size() == 0 : group;
|
||||||
|
|
||||||
// try to run a script with the original keyPair
|
// try to run a script with the original keyPair
|
||||||
runScriptWithCreds(tag, template.getImage().getOsFamily(), new Credentials(good.account,
|
runScriptWithCreds(tag, first.getImage().getOsFamily(), new Credentials(first
|
||||||
result.getKeyMaterial()));
|
.getCredentials().account, result.getKeyMaterial()));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
client.destroyNodesMatching(NodePredicates.withTag(tag));
|
client.destroyNodesMatching(NodePredicates.withTag(tag));
|
||||||
|
@ -162,17 +158,17 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
String tag = this.tag + "optionsnokey";
|
String tag = this.tag + "optionsnokey";
|
||||||
|
|
||||||
Template template = buildTemplate(client.templateBuilder());
|
TemplateOptions options = client.templateOptions();
|
||||||
|
|
||||||
template.getOptions().as(EC2TemplateOptions.class).securityGroups(tag);
|
options.as(EC2TemplateOptions.class).securityGroups(tag);
|
||||||
template.getOptions().as(EC2TemplateOptions.class).noKeyPair();
|
options.as(EC2TemplateOptions.class).noKeyPair();
|
||||||
|
|
||||||
String startedId = null;
|
String startedId = null;
|
||||||
try {
|
try {
|
||||||
// create the security group
|
// create the security group
|
||||||
securityGroupClient.createSecurityGroupInRegion(null, tag, tag);
|
securityGroupClient.createSecurityGroupInRegion(null, tag, tag);
|
||||||
|
|
||||||
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, template);
|
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
|
||||||
Credentials creds = nodes.iterator().next().getCredentials();
|
Credentials creds = nodes.iterator().next().getCredentials();
|
||||||
assert creds == null;
|
assert creds == null;
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,13 @@
|
||||||
package org.jclouds.aws.ec2.compute;
|
package org.jclouds.aws.ec2.compute;
|
||||||
|
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
|
import static org.easymock.EasyMock.expect;
|
||||||
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
|
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.compute.domain.EC2Size;
|
import org.jclouds.aws.ec2.compute.domain.EC2Size;
|
||||||
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
|
|
||||||
import org.jclouds.compute.domain.Architecture;
|
import org.jclouds.compute.domain.Architecture;
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
@ -35,6 +39,7 @@ import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.domain.internal.ImageImpl;
|
import org.jclouds.compute.domain.internal.ImageImpl;
|
||||||
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
||||||
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
|
@ -110,16 +115,25 @@ public class EC2ComputeServiceTest {
|
||||||
"m2.xlarge", String.valueOf(template.getSize()));
|
"m2.xlarge", String.valueOf(template.getSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private TemplateBuilder newTemplateBuilder() {
|
private TemplateBuilder newTemplateBuilder() {
|
||||||
Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null);
|
Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null);
|
||||||
|
|
||||||
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
TemplateOptions defaultOptions = createMock(TemplateOptions.class);
|
||||||
|
|
||||||
|
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||||
|
|
||||||
Image image = new ImageImpl("ami-image", "image", location, null, Maps
|
Image image = new ImageImpl("ami-image", "image", location, null, Maps
|
||||||
.<String, String> newHashMap(), "description", "1.0", null, "ubuntu",
|
.<String, String> newHashMap(), "description", "1.0", null, "ubuntu",
|
||||||
Architecture.X86_64, new Credentials("root", null));
|
Architecture.X86_64, new Credentials("root", null));
|
||||||
|
replay(optionsProvider);
|
||||||
|
replay(templateBuilderProvider);
|
||||||
return new TemplateBuilderImpl(ImmutableSet.of(location), ImmutableSet.of(image),
|
return new TemplateBuilderImpl(ImmutableSet.of(location), ImmutableSet.of(image),
|
||||||
ImmutableSet.of(EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, EC2Size.M1_LARGE,
|
ImmutableSet.of(EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, EC2Size.M1_LARGE,
|
||||||
EC2Size.M1_SMALL, EC2Size.M1_XLARGE, EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE,
|
EC2Size.M1_SMALL, EC2Size.M1_XLARGE, EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE,
|
||||||
EC2Size.M2_4XLARGE), location, new EC2TemplateOptions()) {
|
EC2Size.M2_4XLARGE), location, optionsProvider, templateBuilderProvider) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
import org.jclouds.compute.options.RunScriptOptions;
|
import org.jclouds.compute.options.RunScriptOptions;
|
||||||
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.ssh.ExecResponse;
|
import org.jclouds.ssh.ExecResponse;
|
||||||
|
|
||||||
|
@ -54,6 +55,11 @@ public interface ComputeService {
|
||||||
*/
|
*/
|
||||||
TemplateBuilder templateBuilder();
|
TemplateBuilder templateBuilder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a new set of options for running nodes
|
||||||
|
*/
|
||||||
|
TemplateOptions templateOptions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list sizes command shows you the options including virtual cpu count, memory, and disks.
|
* The list sizes command shows you the options including virtual cpu count, memory, and disks.
|
||||||
* cpu count is not a portable quantity across clouds, as they are measured differently. However,
|
* cpu count is not a portable quantity across clouds, as they are measured differently. However,
|
||||||
|
@ -125,6 +131,19 @@ public interface ComputeService {
|
||||||
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template)
|
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template)
|
||||||
throws RunNodesException;
|
throws RunNodesException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like {@link ComputeService#runNodesWithTag(String,int,Template)}, except that the template is
|
||||||
|
* default, equivalent to {@code templateBuilder().any().options(templateOptions)}.
|
||||||
|
*/
|
||||||
|
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count,
|
||||||
|
TemplateOptions templateOptions) throws RunNodesException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like {@link ComputeService#runNodesWithTag(String,int,TemplateOptions)}, except that the
|
||||||
|
* options are default, as specified in {@link ComputeService#templateOptions}.
|
||||||
|
*/
|
||||||
|
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destroy the node. If it is the only node in a tag set, the dependent resources will also be
|
* destroy the node. If it is the only node in a tag set, the dependent resources will also be
|
||||||
* destroyed.
|
* destroyed.
|
||||||
|
|
|
@ -30,6 +30,12 @@ import com.google.inject.ImplementedBy;
|
||||||
*/
|
*/
|
||||||
@ImplementedBy(TemplateBuilderImpl.class)
|
@ImplementedBy(TemplateBuilderImpl.class)
|
||||||
public interface TemplateBuilder {
|
public interface TemplateBuilder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prime this builder with parameters known to work on the current compute provider.
|
||||||
|
*/
|
||||||
|
TemplateBuilder any();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure this template to require the minimum size of the parameter.
|
* Configure this template to require the minimum size of the parameter.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -52,6 +52,7 @@ import org.jclouds.compute.domain.Size;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.options.RunScriptOptions;
|
import org.jclouds.compute.options.RunScriptOptions;
|
||||||
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.predicates.NodePredicates;
|
import org.jclouds.compute.predicates.NodePredicates;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
|
@ -95,6 +96,7 @@ public class BaseComputeService implements ComputeService {
|
||||||
protected final RebootNodeStrategy rebootNodeStrategy;
|
protected final RebootNodeStrategy rebootNodeStrategy;
|
||||||
protected final DestroyNodeStrategy destroyNodeStrategy;
|
protected final DestroyNodeStrategy destroyNodeStrategy;
|
||||||
protected final Provider<TemplateBuilder> templateBuilderProvider;
|
protected final Provider<TemplateBuilder> templateBuilderProvider;
|
||||||
|
protected final Provider<TemplateOptions> templateOptionsProvider;
|
||||||
protected final ComputeUtils utils;
|
protected final ComputeUtils utils;
|
||||||
protected final ExecutorService executor;
|
protected final ExecutorService executor;
|
||||||
|
|
||||||
|
@ -105,7 +107,8 @@ public class BaseComputeService implements ComputeService {
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy,
|
GetNodeMetadataStrategy getNodeMetadataStrategy,
|
||||||
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
|
||||||
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
|
||||||
Provider<TemplateBuilder> templateBuilderProvider, ComputeUtils utils,
|
Provider<TemplateBuilder> templateBuilderProvider,
|
||||||
|
Provider<TemplateOptions> templateOptionsProvider, ComputeUtils utils,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
|
||||||
this.context = checkNotNull(context, "context");
|
this.context = checkNotNull(context, "context");
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
|
@ -120,18 +123,26 @@ public class BaseComputeService implements ComputeService {
|
||||||
this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy");
|
this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy");
|
||||||
this.templateBuilderProvider = checkNotNull(templateBuilderProvider,
|
this.templateBuilderProvider = checkNotNull(templateBuilderProvider,
|
||||||
"templateBuilderProvider");
|
"templateBuilderProvider");
|
||||||
|
this.templateOptionsProvider = checkNotNull(templateOptionsProvider,
|
||||||
|
"templateOptionsProvider");
|
||||||
this.utils = checkNotNull(utils, "utils");
|
this.utils = checkNotNull(utils, "utils");
|
||||||
this.executor = checkNotNull(executor, "executor");
|
this.executor = checkNotNull(executor, "executor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ComputeServiceContext getContext() {
|
public ComputeServiceContext getContext() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends NodeMetadata> runNodesWithTag(final String tag, int count,
|
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count, Template template)
|
||||||
final Template template) throws RunNodesException {
|
throws RunNodesException {
|
||||||
checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens");
|
checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens");
|
||||||
checkNotNull(template.getLocation(), "location");
|
checkNotNull(template.getLocation(), "location");
|
||||||
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)",
|
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)",
|
||||||
|
@ -149,6 +160,27 @@ public class BaseComputeService implements ComputeService {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count,
|
||||||
|
TemplateOptions templateOptions) throws RunNodesException {
|
||||||
|
return runNodesWithTag(tag, count, templateBuilder().any().options(templateOptions).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Set<? extends NodeMetadata> runNodesWithTag(String tag, int count)
|
||||||
|
throws RunNodesException {
|
||||||
|
return runNodesWithTag(tag, count, templateOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(Location location, String id) {
|
public void destroyNode(Location location, String id) {
|
||||||
checkNotNull(location, "location");
|
checkNotNull(location, "location");
|
||||||
|
@ -158,6 +190,9 @@ public class BaseComputeService implements ComputeService {
|
||||||
logger.debug("<< destroyed node(%s/%s) success(%s)", location.getId(), id, successful);
|
logger.debug("<< destroyed node(%s/%s) success(%s)", location.getId(), id, successful);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
|
public Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter) {
|
||||||
logger.debug(">> destroying nodes matching(%s)", filter);
|
logger.debug(">> destroying nodes matching(%s)", filter);
|
||||||
|
@ -184,6 +219,9 @@ public class BaseComputeService implements ComputeService {
|
||||||
.not(NodePredicates.TERMINATED)));
|
.not(NodePredicates.TERMINATED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends ComputeMetadata> listNodes() {
|
public Set<? extends ComputeMetadata> listNodes() {
|
||||||
logger.debug(">> listing nodes");
|
logger.debug(">> listing nodes");
|
||||||
|
@ -192,6 +230,9 @@ public class BaseComputeService implements ComputeService {
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter) {
|
public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<ComputeMetadata> filter) {
|
||||||
checkNotNull(filter, "filter");
|
checkNotNull(filter, "filter");
|
||||||
|
@ -202,26 +243,41 @@ public class BaseComputeService implements ComputeService {
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends Size> listSizes() {
|
public Set<? extends Size> listSizes() {
|
||||||
return sizes.get();
|
return sizes.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends Image> listImages() {
|
public Set<? extends Image> listImages() {
|
||||||
return images.get();
|
return images.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends Location> listAssignableLocations() {
|
public Set<? extends Location> listAssignableLocations() {
|
||||||
return locations.get();
|
return locations.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TemplateBuilder templateBuilder() {
|
public TemplateBuilder templateBuilder() {
|
||||||
return templateBuilderProvider.get();
|
return templateBuilderProvider.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata getNodeMetadata(Location location, String id) {
|
public NodeMetadata getNodeMetadata(Location location, String id) {
|
||||||
checkNotNull(location, "location");
|
checkNotNull(location, "location");
|
||||||
|
@ -229,6 +285,9 @@ public class BaseComputeService implements ComputeService {
|
||||||
return getNodeMetadataStrategy.execute(location, id);
|
return getNodeMetadataStrategy.execute(location, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void rebootNode(Location location, String id) {
|
public void rebootNode(Location location, String id) {
|
||||||
checkNotNull(location, "location");
|
checkNotNull(location, "location");
|
||||||
|
@ -238,6 +297,9 @@ public class BaseComputeService implements ComputeService {
|
||||||
logger.debug("<< rebooted node(%s/%s) success(%s)", location.getId(), id, successful);
|
logger.debug("<< rebooted node(%s/%s) success(%s)", location.getId(), id, successful);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void rebootNodesMatching(Predicate<NodeMetadata> filter) {
|
public void rebootNodesMatching(Predicate<NodeMetadata> filter) {
|
||||||
logger.debug(">> rebooting nodes matching(%s)", filter);
|
logger.debug(">> rebooting nodes matching(%s)", filter);
|
||||||
|
@ -257,10 +319,7 @@ public class BaseComputeService implements ComputeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws RunScriptOnNodesException
|
* {@inheritDoc}
|
||||||
* @see #runScriptOnNodesMatching(Predicate, byte[],
|
|
||||||
* org.jclouds.compute.options.RunScriptOptions)
|
|
||||||
* @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String)
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(
|
public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(
|
||||||
|
@ -269,20 +328,7 @@ public class BaseComputeService implements ComputeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the script on all nodes with the specific tag.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @param filter
|
|
||||||
* Predicate-based filter to define on which nodes the script is to be executed
|
|
||||||
* @param runScript
|
|
||||||
* script to run in byte format. If the script is a string, use
|
|
||||||
* {@link String#getBytes()} to retrieve the bytes
|
|
||||||
* @param options
|
|
||||||
* nullable options to how to run the script, whether to override credentials
|
|
||||||
* @return map with node identifiers and corresponding responses
|
|
||||||
* @throws RunScriptOnNodesException
|
|
||||||
* if anything goes wrong during script execution
|
|
||||||
*
|
|
||||||
* @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String)
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
|
public Map<NodeMetadata, ExecResponse> runScriptOnNodesMatching(Predicate<NodeMetadata> filter,
|
||||||
|
@ -373,4 +419,9 @@ public class BaseComputeService implements ComputeService {
|
||||||
private Iterable<? extends NodeMetadata> detailsOnAllNodes() {
|
private Iterable<? extends NodeMetadata> detailsOnAllNodes() {
|
||||||
return listNodesStrategy.listDetailsOnNodesMatching(NodePredicates.all());
|
return listNodesStrategy.listDetailsOnNodesMatching(NodePredicates.all());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TemplateOptions templateOptions() {
|
||||||
|
return templateOptionsProvider.get();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -26,6 +26,7 @@ import java.util.Set;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.Architecture;
|
import org.jclouds.compute.domain.Architecture;
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
|
@ -63,6 +64,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
private final Set<? extends Image> images;
|
private final Set<? extends Image> images;
|
||||||
private final Set<? extends Size> sizes;
|
private final Set<? extends Size> sizes;
|
||||||
private final Set<? extends Location> locations;
|
private final Set<? extends Location> locations;
|
||||||
|
private final Provider<TemplateOptions> optionsProvider;
|
||||||
|
private final Provider<TemplateBuilder> defaultTemplateProvider;
|
||||||
|
private final Location defaultLocation;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
OsFamily os;
|
OsFamily os;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@ -77,32 +82,32 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
String osDescription;
|
String osDescription;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String imageVersion;
|
String imageVersion;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String imageName;
|
String imageName;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String imageDescription;
|
String imageDescription;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
double minCores;
|
double minCores;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
int minRam;
|
int minRam;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean biggest;
|
boolean biggest;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean fastest;
|
boolean fastest;
|
||||||
|
@VisibleForTesting
|
||||||
private TemplateOptions options;
|
TemplateOptions options;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected TemplateBuilderImpl(Set<? extends Location> locations, Set<? extends Image> images,
|
protected TemplateBuilderImpl(Set<? extends Location> locations, Set<? extends Image> images,
|
||||||
Set<? extends Size> sizes, Location defaultLocation, TemplateOptions options) {
|
Set<? extends Size> sizes, Location defaultLocation,
|
||||||
|
Provider<TemplateOptions> optionsProvider,
|
||||||
|
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
this.images = images;
|
this.images = images;
|
||||||
this.sizes = sizes;
|
this.sizes = sizes;
|
||||||
this.locationId = defaultLocation.getId();
|
this.defaultLocation = defaultLocation;
|
||||||
this.options = options;
|
this.optionsProvider = optionsProvider;
|
||||||
|
this.defaultTemplateProvider = defaultTemplateProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Predicate<ComputeMetadata> locationPredicate = new Predicate<ComputeMetadata>() {
|
private final Predicate<ComputeMetadata> locationPredicate = new Predicate<ComputeMetadata>() {
|
||||||
|
@ -389,6 +394,12 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Template build() {
|
public Template build() {
|
||||||
|
if (nothingChanged())
|
||||||
|
return defaultTemplateProvider.get().build();
|
||||||
|
if (locationId == null)
|
||||||
|
locationId = defaultLocation.getId();
|
||||||
|
if (options == null)
|
||||||
|
options = optionsProvider.get();
|
||||||
logger.debug(">> searching params(%s)", this);
|
logger.debug(">> searching params(%s)", this);
|
||||||
Image image;
|
Image image;
|
||||||
try {
|
try {
|
||||||
|
@ -511,6 +522,22 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean nothingChanged() {
|
||||||
|
return os == null && arch == null && locationId == null && imageId == null && sizeId == null
|
||||||
|
&& osDescription == null && imageVersion == null && imageName == null
|
||||||
|
&& imageDescription == null && minCores == 0 && minRam == 0 && !biggest && !fastest
|
||||||
|
&& options == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TemplateBuilder any() {
|
||||||
|
return defaultTemplateProvider.get();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[arch=" + arch + ", biggest=" + biggest + ", fastest=" + fastest + ", imageName="
|
return "[arch=" + arch + ", biggest=" + biggest + ", fastest=" + fastest + ", imageName="
|
||||||
|
|
|
@ -41,7 +41,7 @@ import java.util.Arrays;
|
||||||
*/
|
*/
|
||||||
public class TemplateOptions {
|
public class TemplateOptions {
|
||||||
|
|
||||||
public static final TemplateOptions NONE = new TemplateOptions();
|
public static final TemplateOptions NONE = new ImmutableTemplateOptions(new TemplateOptions());
|
||||||
|
|
||||||
public static class ImmutableTemplateOptions extends TemplateOptions {
|
public static class ImmutableTemplateOptions extends TemplateOptions {
|
||||||
private final TemplateOptions delegate;
|
private final TemplateOptions delegate;
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class NodePredicates {
|
||||||
checkNotEmpty(tag, "Tag must be defined");
|
checkNotEmpty(tag, "Tag must be defined");
|
||||||
return new Predicate<NodeMetadata>() {
|
return new Predicate<NodeMetadata>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable NodeMetadata nodeMetadata) {
|
public boolean apply(NodeMetadata nodeMetadata) {
|
||||||
return tag.equals(nodeMetadata.getTag())
|
return tag.equals(nodeMetadata.getTag())
|
||||||
&& nodeMetadata.getState() == NodeState.RUNNING;
|
&& nodeMetadata.getState() == NodeState.RUNNING;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public class NodePredicates {
|
||||||
*/
|
*/
|
||||||
public static final Predicate<NodeMetadata> ACTIVE = new Predicate<NodeMetadata>() {
|
public static final Predicate<NodeMetadata> ACTIVE = new Predicate<NodeMetadata>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable NodeMetadata nodeMetadata) {
|
public boolean apply(NodeMetadata nodeMetadata) {
|
||||||
return nodeMetadata.getState() == NodeState.RUNNING;
|
return nodeMetadata.getState() == NodeState.RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public class NodePredicates {
|
||||||
*/
|
*/
|
||||||
public static final Predicate<NodeMetadata> TERMINATED = new Predicate<NodeMetadata>() {
|
public static final Predicate<NodeMetadata> TERMINATED = new Predicate<NodeMetadata>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable NodeMetadata nodeMetadata) {
|
public boolean apply(NodeMetadata nodeMetadata) {
|
||||||
return nodeMetadata.getState() == NodeState.TERMINATED;
|
return nodeMetadata.getState() == NodeState.TERMINATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,23 +226,22 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public void testScriptExecutionAfterBootWithBasicTemplate() throws Exception {
|
public void testScriptExecutionAfterBootWithBasicTemplate() throws Exception {
|
||||||
String tag = this.tag + "run";
|
String tag = this.tag + "run";
|
||||||
Template simpleTemplate = buildTemplate(client.templateBuilder());
|
TemplateOptions options = client.templateOptions().blockOnPort(22, 120);
|
||||||
simpleTemplate.getOptions().blockOnPort(22, 120);
|
|
||||||
try {
|
try {
|
||||||
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, simpleTemplate);
|
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
|
||||||
Credentials good = nodes.iterator().next().getCredentials();
|
Credentials good = nodes.iterator().next().getCredentials();
|
||||||
assert good.account != null;
|
assert good.account != null;
|
||||||
|
|
||||||
|
Image image = Iterables.get(nodes, 0).getImage();
|
||||||
try {
|
try {
|
||||||
Map<? extends NodeMetadata, ExecResponse> responses = runScriptWithCreds(tag,
|
Map<? extends NodeMetadata, ExecResponse> responses = runScriptWithCreds(tag, image
|
||||||
simpleTemplate.getImage().getOsFamily(),
|
.getOsFamily(), new Credentials(good.account, "romeo"));
|
||||||
new Credentials(good.account, "romeo"));
|
|
||||||
assert false : "shouldn't pass with a bad password\n" + responses;
|
assert false : "shouldn't pass with a bad password\n" + responses;
|
||||||
} catch (RunScriptOnNodesException e) {
|
} catch (RunScriptOnNodesException e) {
|
||||||
assert Throwables.getRootCause(e).getMessage().contains("Auth fail") : e;
|
assert Throwables.getRootCause(e).getMessage().contains("Auth fail") : e;
|
||||||
}
|
}
|
||||||
|
|
||||||
runScriptWithCreds(tag, simpleTemplate.getImage().getOsFamily(), good);
|
runScriptWithCreds(tag, image.getOsFamily(), good);
|
||||||
|
|
||||||
checkNodes(nodes, tag);
|
checkNodes(nodes, tag);
|
||||||
|
|
||||||
|
@ -319,9 +318,9 @@ public abstract class BaseComputeServiceLiveTest {
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
|
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
|
||||||
public void testGet() throws Exception {
|
public void testGet() throws Exception {
|
||||||
Set<? extends NodeMetadata> nodes = client.listNodesDetailsMatching(NodePredicates.all());
|
Set<? extends NodeMetadata> metadataSet = Sets.newHashSet(Iterables.filter(client
|
||||||
Set<? extends NodeMetadata> metadataSet = Sets.newHashSet(Iterables.filter(nodes, Predicates
|
.listNodesDetailsMatching(NodePredicates.all()), Predicates.and(NodePredicates
|
||||||
.and(NodePredicates.withTag(tag), Predicates.not(NodePredicates.TERMINATED))));
|
.withTag(tag), Predicates.not(NodePredicates.TERMINATED))));
|
||||||
for (NodeMetadata node : nodes) {
|
for (NodeMetadata node : nodes) {
|
||||||
metadataSet.remove(node);
|
metadataSet.remove(node);
|
||||||
NodeMetadata metadata = client.getNodeMetadata(node.getLocation(), node.getId());
|
NodeMetadata metadata = client.getNodeMetadata(node.getLocation(), node.getId());
|
||||||
|
|
|
@ -18,16 +18,23 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.compute.internal;
|
package org.jclouds.compute.internal;
|
||||||
|
|
||||||
|
import static org.easymock.EasyMock.expect;
|
||||||
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
|
import static org.easymock.classextension.EasyMock.verify;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.Architecture;
|
import org.jclouds.compute.domain.Architecture;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.domain.Size;
|
import org.jclouds.compute.domain.Size;
|
||||||
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
@ -39,11 +46,175 @@ import com.google.common.collect.ImmutableSet;
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class TemplateBuilderImplTest {
|
public class TemplateBuilderImplTest {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testNothingUsesDefaultTemplateBuilder() {
|
||||||
|
|
||||||
|
Location defaultLocation = createMock(Location.class);
|
||||||
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||||
|
|
||||||
|
expect(templateBuilderProvider.get()).andReturn(defaultTemplate);
|
||||||
|
expect(defaultTemplate.build()).andReturn(null);
|
||||||
|
|
||||||
|
replay(defaultTemplate);
|
||||||
|
replay(defaultLocation);
|
||||||
|
replay(optionsProvider);
|
||||||
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
|
TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableSet.<Location> of(),
|
||||||
|
ImmutableSet.<Image> of(), ImmutableSet.<Size> of(), defaultLocation,
|
||||||
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
|
template.build();
|
||||||
|
|
||||||
|
verify(defaultTemplate);
|
||||||
|
verify(defaultLocation);
|
||||||
|
verify(optionsProvider);
|
||||||
|
verify(templateBuilderProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testSuppliedLocationWithNoOptions() {
|
||||||
|
|
||||||
|
Location defaultLocation = createMock(Location.class);
|
||||||
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
TemplateOptions defaultOptions = createMock(TemplateOptions.class);
|
||||||
|
|
||||||
|
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||||
|
|
||||||
|
replay(defaultOptions);
|
||||||
|
replay(defaultLocation);
|
||||||
|
replay(optionsProvider);
|
||||||
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
|
TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableSet.<Location> of(),
|
||||||
|
ImmutableSet.<Image> of(), ImmutableSet.<Size> of(), defaultLocation,
|
||||||
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
|
try {
|
||||||
|
template.imageId("foo").locationId("location").build();
|
||||||
|
assert false;
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(defaultOptions);
|
||||||
|
verify(defaultLocation);
|
||||||
|
verify(optionsProvider);
|
||||||
|
verify(templateBuilderProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testSuppliedLocationAndOptions() {
|
||||||
|
|
||||||
|
Location defaultLocation = createMock(Location.class);
|
||||||
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
|
||||||
|
replay(defaultLocation);
|
||||||
|
replay(optionsProvider);
|
||||||
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
|
TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableSet.<Location> of(),
|
||||||
|
ImmutableSet.<Image> of(), ImmutableSet.<Size> of(), defaultLocation,
|
||||||
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
|
try {
|
||||||
|
template.imageId("foo").options(TemplateOptions.NONE).locationId("location").build();
|
||||||
|
assert false;
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(defaultLocation);
|
||||||
|
verify(optionsProvider);
|
||||||
|
verify(templateBuilderProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testDefaultLocationWithNoOptions() {
|
||||||
|
|
||||||
|
Location defaultLocation = createMock(Location.class);
|
||||||
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
TemplateOptions defaultOptions = createMock(TemplateOptions.class);
|
||||||
|
|
||||||
|
expect(defaultLocation.getId()).andReturn("foo");
|
||||||
|
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||||
|
|
||||||
|
replay(defaultOptions);
|
||||||
|
replay(defaultLocation);
|
||||||
|
replay(optionsProvider);
|
||||||
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
|
TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableSet.<Location> of(),
|
||||||
|
ImmutableSet.<Image> of(), ImmutableSet.<Size> of(), defaultLocation,
|
||||||
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
|
try {
|
||||||
|
template.imageId("foo").build();
|
||||||
|
assert false;
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(defaultOptions);
|
||||||
|
verify(defaultLocation);
|
||||||
|
verify(optionsProvider);
|
||||||
|
verify(templateBuilderProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testDefaultLocationWithOptions() {
|
||||||
|
|
||||||
|
Location defaultLocation = createMock(Location.class);
|
||||||
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
|
||||||
|
expect(defaultLocation.getId()).andReturn("foo");
|
||||||
|
|
||||||
|
replay(defaultLocation);
|
||||||
|
replay(optionsProvider);
|
||||||
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
|
TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableSet.<Location> of(),
|
||||||
|
ImmutableSet.<Image> of(), ImmutableSet.<Size> of(), defaultLocation,
|
||||||
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
|
try {
|
||||||
|
template.imageId("foo").options(TemplateOptions.NONE).build();
|
||||||
|
assert false;
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(defaultLocation);
|
||||||
|
verify(optionsProvider);
|
||||||
|
verify(templateBuilderProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testImageIdNullsEverythingElse() {
|
public void testImageIdNullsEverythingElse() {
|
||||||
|
Location defaultLocation = createMock(Location.class);
|
||||||
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
|
||||||
|
replay(defaultLocation);
|
||||||
|
replay(optionsProvider);
|
||||||
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableSet.<Location> of(),
|
TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableSet.<Location> of(),
|
||||||
ImmutableSet.<Image> of(), ImmutableSet.<Size> of(), new LocationImpl(
|
ImmutableSet.<Image> of(), ImmutableSet.<Size> of(), defaultLocation,
|
||||||
LocationScope.REGION, " id", "description", null), new TemplateOptions());
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
template.architecture(Architecture.X86_32);
|
template.architecture(Architecture.X86_32);
|
||||||
template.imageDescriptionMatches("imageDescriptionMatches");
|
template.imageDescriptionMatches("imageDescriptionMatches");
|
||||||
template.imageNameMatches("imageNameMatches");
|
template.imageNameMatches("imageNameMatches");
|
||||||
|
@ -68,6 +239,9 @@ public class TemplateBuilderImplTest {
|
||||||
assertEquals(template.os, null);
|
assertEquals(template.os, null);
|
||||||
assertEquals(template.imageId, "myid");
|
assertEquals(template.imageId, "myid");
|
||||||
|
|
||||||
|
verify(defaultLocation);
|
||||||
|
verify(optionsProvider);
|
||||||
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,6 @@ import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.domain.internal.ImageImpl;
|
import org.jclouds.compute.domain.internal.ImageImpl;
|
||||||
import org.jclouds.compute.domain.internal.SizeImpl;
|
import org.jclouds.compute.domain.internal.SizeImpl;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
|
||||||
import org.jclouds.compute.predicates.NodePredicates;
|
import org.jclouds.compute.predicates.NodePredicates;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
||||||
|
@ -111,7 +110,8 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
TemplateBuilder provideTemplate(TemplateBuilderImpl template) {
|
@Named("DEFAULT")
|
||||||
|
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||||
return template.osFamily(CENTOS).imageNameMatches(".*w/ None.*");
|
return template.osFamily(CENTOS).imageNameMatches(".*w/ None.*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ import org.jclouds.compute.domain.internal.NodeMetadataImpl;
|
||||||
import org.jclouds.compute.domain.internal.SizeImpl;
|
import org.jclouds.compute.domain.internal.SizeImpl;
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
import org.jclouds.compute.internal.BaseComputeService;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
|
||||||
import org.jclouds.compute.predicates.NodePredicates;
|
import org.jclouds.compute.predicates.NodePredicates;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
||||||
|
@ -118,7 +117,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
TemplateBuilder provideTemplate(TemplateBuilderImpl template) {
|
@Named("DEFAULT")
|
||||||
|
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||||
return template.osFamily(UBUNTU);
|
return template.osFamily(UBUNTU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,6 @@ import org.jclouds.compute.domain.internal.ImageImpl;
|
||||||
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
|
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
|
||||||
import org.jclouds.compute.domain.internal.SizeImpl;
|
import org.jclouds.compute.domain.internal.SizeImpl;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
|
||||||
import org.jclouds.compute.predicates.NodePredicates;
|
import org.jclouds.compute.predicates.NodePredicates;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient;
|
||||||
|
@ -119,7 +118,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
TemplateBuilder provideTemplate(TemplateBuilderImpl template) {
|
@Named("DEFAULT")
|
||||||
|
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||||
return template.sizeId("MIRO1B").osFamily(UBUNTU);
|
return template.sizeId("MIRO1B").osFamily(UBUNTU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,6 @@ import org.jclouds.compute.domain.internal.ImageImpl;
|
||||||
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
|
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
|
||||||
import org.jclouds.compute.domain.internal.SizeImpl;
|
import org.jclouds.compute.domain.internal.SizeImpl;
|
||||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||||
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
|
||||||
import org.jclouds.compute.predicates.ScriptStatusReturnsZero;
|
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;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
|
@ -127,7 +126,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
protected TemplateBuilder provideTemplate(TemplateBuilderImpl template) {
|
@Named("DEFAULT")
|
||||||
|
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||||
return template.osFamily(UBUNTU);
|
return template.osFamily(UBUNTU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.vcloud.hostingdotcom.compute.config;
|
||||||
import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
|
||||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||||
import org.jclouds.compute.strategy.impl.ReturnNullCredentials;
|
import org.jclouds.compute.strategy.impl.ReturnNullCredentials;
|
||||||
import org.jclouds.vcloud.compute.VCloudComputeClient;
|
import org.jclouds.vcloud.compute.VCloudComputeClient;
|
||||||
|
@ -49,7 +48,7 @@ public class HostingDotComVCloudComputeServiceContextModule extends
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TemplateBuilder provideTemplate(TemplateBuilderImpl template) {
|
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||||
return template.osFamily(CENTOS);
|
return template.osFamily(CENTOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ import org.jclouds.compute.domain.Size;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.domain.internal.ImageImpl;
|
import org.jclouds.compute.domain.internal.ImageImpl;
|
||||||
import org.jclouds.compute.domain.internal.SizeImpl;
|
import org.jclouds.compute.domain.internal.SizeImpl;
|
||||||
import org.jclouds.compute.internal.TemplateBuilderImpl;
|
|
||||||
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
|
||||||
import org.jclouds.concurrent.ConcurrentUtils;
|
import org.jclouds.concurrent.ConcurrentUtils;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
@ -93,7 +92,7 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TemplateBuilder provideTemplate(TemplateBuilderImpl template) {
|
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||||
return template.osFamily(OsFamily.UBUNTU);
|
return template.osFamily(OsFamily.UBUNTU);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue