use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class ListCluster method doExecute.
@Override
protected Object doExecute() throws Exception {
validateInput();
ListClusterCommand command = new ListClusterCommand(clusterControllerFactory);
ClusterSpec clusterSpec = getClusterSpec();
if (clusterSpec != null) {
command.run(System.in, System.out, System.err, clusterSpec);
}
return null;
}
use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class BlobCacheTest method testSelectBestLocation.
@Test
public void testSelectBestLocation() throws Exception {
ClusterSpec spec = getTestClusterSpec();
if (!spec.getProvider().equals("aws") && !spec.getProvider().equals("aws-ec2")) {
// this test can be executed only on amazon but the internal
return;
// location selection mechanism should work for any cloud provider
}
spec.setTemplate(TemplateBuilderSpec.parse("locationId=eu-west-1"));
BlobCache cache = BlobCache.getInstance(ComputeCache.INSTANCE, spec);
assertThat(cache.getLocation().getId(), is("EU"));
}
use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class BlobCacheTest method testSpecifyCacheContainerInConfig.
@Test
public void testSpecifyCacheContainerInConfig() throws Exception {
ClusterSpec spec = getTestClusterSpec();
BlobStoreContext context = BlobStoreContextBuilder.build(spec);
String container = generateRandomContainerName(context);
LOG.info("Created temporary container '{}'", container);
try {
spec.setBlobStoreCacheContainer(container);
BlobCache cache = BlobCache.getInstance(ComputeCache.INSTANCE, spec);
assertThat(cache.getContainer(), is(container));
cache.dropAndClose();
assertThat(context.getBlobStore().containerExists(container), is(true));
} finally {
LOG.info("Removing temporary container '{}'", container);
context.getBlobStore().deleteContainer(container);
}
}
use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class BootstrapTemplateTest method testDifferentPrices.
@Test
public void testDifferentPrices() throws Exception {
ClusterSpec clusterSpec = buildClusterSpecWith(ImmutableMap.of("whirr.instance-templates", "1 role1, 1 role2", "whirr.aws-ec2-spot-price", "0.1", "whirr.templates.role2.aws-ec2-spot-price", "0.3"));
assertSpotPriceIs(clusterSpec, "role1", 0.1f);
assertSpotPriceIs(clusterSpec, "role2", 0.3f);
}
use of org.apache.whirr.ClusterSpec in project whirr by apache.
the class BootstrapClusterActionTest method testDoActionRetriesSucceed.
@SuppressWarnings("unchecked")
@Test
public void testDoActionRetriesSucceed() throws Exception {
CompositeConfiguration config = new CompositeConfiguration();
if (System.getProperty("config") != null) {
config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
}
Configuration conf = new PropertiesConfiguration();
conf.addProperty("whirr.service-name", "test-service");
conf.addProperty("whirr.cluster-name", "test-cluster");
conf.addProperty("whirr.instance-templates", "1 hadoop-namenode+hadoop-jobtracker,4 hadoop-datanode+hadoop-tasktracker");
conf.addProperty("whirr.instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker");
conf.addProperty("whirr.provider", "ec2");
config.addConfiguration(conf);
ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);
Set<String> jtnn = new HashSet<String>();
jtnn.add("hadoop-jobtracker");
jtnn.add("hadoop-namenode");
Set<String> dntt = new HashSet<String>();
dntt.add("hadoop-datanode");
dntt.add("hadoop-tasktracker");
TestNodeStarterFactory nodeStarterFactory = null;
ClusterActionHandler handler = mock(ClusterActionHandler.class);
LoadingCache<String, ClusterActionHandler> handlerMap = convertMapToLoadingCache(ImmutableMap.<String, ClusterActionHandler>builder().put("hadoop-jobtracker", handler).put("hadoop-namenode", handler).put("hadoop-datanode", handler).put("hadoop-tasktracker", handler).build());
Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
ComputeService computeService = mock(ComputeService.class);
TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
Template template = mock(Template.class);
TemplateOptions templateOptions = mock(TemplateOptions.class);
when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
when(serviceContext.getComputeService()).thenReturn(computeService);
when(computeService.getContext()).thenReturn(serviceContext);
when(serviceContext.getBackendType()).thenReturn(TypeToken.class.cast(TypeToken.of(Context.class)));
when(computeService.templateBuilder()).thenReturn(templateBuilder);
when(templateBuilder.from((TemplateBuilderSpec) any())).thenReturn(templateBuilder);
when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
when(templateBuilder.build()).thenReturn(template);
when(template.getOptions()).thenReturn(templateOptions);
// here is a scenario when jt+nn fails once, then the retry is successful
// and from the dn+tt one node fails, then the retry is successful
Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
Stack<Integer> jtnnStack = new Stack<Integer>();
// then ok
jtnnStack.push(1);
// initially fail
jtnnStack.push(0);
reaction.put(jtnn, jtnnStack);
Stack<Integer> ddttStack = new Stack<Integer>();
// 3 from 4, just enough
ddttStack.push(3);
reaction.put(dntt, ddttStack);
nodeStarterFactory = new TestNodeStarterFactory(reaction);
BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap, nodeStarterFactory);
bootstrapper.execute(clusterSpec, null);
if (nodeStarterFactory != null) {
nodeStarterFactory.validateCompletion();
}
}
Aggregations