use of org.apache.commons.configuration.CompositeConfiguration in project titan by thinkaurelius.
the class AbstractCassandraKeyColumnValueStoreTest method testCustomCFCompressor.
@Test
public void testCustomCFCompressor() throws StorageException {
final String cname = "DeflateCompressor";
final String ckb = "128";
final String cf = TEST_CF_NAME + "_gzip";
Configuration gzipCompressorCfg = new BaseConfiguration();
gzipCompressorCfg.setProperty(AbstractCassandraStoreManager.COMPRESSION_KEY, cname);
gzipCompressorCfg.setProperty(AbstractCassandraStoreManager.COMPRESSION_CHUNKS_SIZE_KEY, ckb);
gzipCompressorCfg = new CompositeConfiguration(Arrays.asList(gzipCompressorCfg, getBaseStorageConfiguration()));
AbstractCassandraStoreManager mgr = openStorageManager(gzipCompressorCfg);
// N.B.: clearStorage() truncates CFs but does not delete them
mgr.openDatabase(cf);
final Map<String, String> expected = ImmutableMap.<String, String>builder().put("sstable_compression", DEFAULT_COMPRESSOR_PACKAGE + "." + cname).put("chunk_length_kb", ckb).build();
assertEquals(expected, mgr.getCompressionOptions(cf));
}
use of org.apache.commons.configuration.CompositeConfiguration in project titan by thinkaurelius.
the class AbstractCassandraKeyColumnValueStoreTest method testDisableCFCompressor.
@Test
public void testDisableCFCompressor() throws StorageException {
final String cf = TEST_CF_NAME + "_nocompress";
Configuration noCompressorCfg = new BaseConfiguration();
noCompressorCfg.setProperty(AbstractCassandraStoreManager.ENABLE_COMPRESSION_KEY, "false");
noCompressorCfg = new CompositeConfiguration(Arrays.asList(noCompressorCfg, getBaseStorageConfiguration()));
AbstractCassandraStoreManager mgr = openStorageManager(noCompressorCfg);
// N.B.: clearStorage() truncates CFs but does not delete them
mgr.openDatabase(cf);
assertEquals(Collections.emptyMap(), mgr.getCompressionOptions(cf));
}
use of org.apache.commons.configuration.CompositeConfiguration in project whirr by apache.
the class BootstrapClusterActionTest method testSubroleInvoked.
@Test
@SuppressWarnings("unchecked")
public void testSubroleInvoked() 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 puppet:module::manifest+something-else");
conf.addProperty("whirr.provider", "ec2");
config.addConfiguration(conf);
ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);
Set<String> nn = new HashSet<String>();
nn.add("puppet:module::manifest");
nn.add("something-else");
TestNodeStarterFactory nodeStarterFactory = null;
ClusterActionHandlerFactory puppetHandlerFactory = mock(ClusterActionHandlerFactory.class);
ClusterActionHandler handler = mock(ClusterActionHandler.class);
when(puppetHandlerFactory.getRolePrefix()).thenReturn("puppet:");
when(puppetHandlerFactory.create("module::manifest")).thenReturn(handler);
when(handler.getRole()).thenReturn("something-else");
LoadingCache<String, ClusterActionHandler> handlerMap = new HandlerMapFactory().create(ImmutableSet.of(puppetHandlerFactory), ImmutableSet.of(handler));
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);
Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
Stack<Integer> nnStack = new Stack<Integer>();
nnStack.push(new Integer(1));
reaction.put(nn, nnStack);
nodeStarterFactory = new TestNodeStarterFactory(reaction);
BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap, nodeStarterFactory);
bootstrapper.execute(clusterSpec, null);
if (nodeStarterFactory != null) {
nodeStarterFactory.validateCompletion();
}
}
use of org.apache.commons.configuration.CompositeConfiguration in project whirr by apache.
the class BootstrapClusterActionTest method testSubroleNotSupported.
@SuppressWarnings("unchecked")
@Test(expected = IllegalArgumentException.class)
public /**
* test is the same as previous (SubroleInvoked) except it knows puppet, not puppet:, as the role;
* the colon in the role def'n is the indication it accepts subroles,
* so this should throw IllegalArgument when we refer to puppet:module...
*/
void testSubroleNotSupported() 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 puppet:module::manifest+something-else");
conf.addProperty("whirr.provider", "ec2");
config.addConfiguration(conf);
ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);
Set<String> nn = new HashSet<String>();
nn.add("puppet:module::manifest");
nn.add("something-else");
TestNodeStarterFactory nodeStarterFactory = null;
ClusterActionHandlerFactory puppetHandlerFactory = mock(ClusterActionHandlerFactory.class);
ClusterActionHandler handler = mock(ClusterActionHandler.class);
when(puppetHandlerFactory.getRolePrefix()).thenReturn("puppet");
when(handler.getRole()).thenReturn("something-else");
LoadingCache<String, ClusterActionHandler> handlerMap = new HandlerMapFactory().create(ImmutableSet.of(puppetHandlerFactory), ImmutableSet.of(handler));
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);
when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
when(serviceContext.getComputeService()).thenReturn(computeService);
when(computeService.templateBuilder()).thenReturn(templateBuilder);
when(templateBuilder.from((TemplateBuilderSpec) any())).thenReturn(templateBuilder);
when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
when(templateBuilder.build()).thenReturn(template);
Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
Stack<Integer> nnStack = new Stack<Integer>();
nnStack.push(1);
reaction.put(nn, nnStack);
nodeStarterFactory = new TestNodeStarterFactory(reaction);
BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap, nodeStarterFactory);
bootstrapper.execute(clusterSpec, null);
if (nodeStarterFactory != null) {
nodeStarterFactory.validateCompletion();
}
}
use of org.apache.commons.configuration.CompositeConfiguration in project whirr by apache.
the class AbstractClusterCommand method getClusterSpec.
/**
* Load the cluster spec by parsing the command line option set
*/
protected ClusterSpec getClusterSpec(OptionSet optionSet) throws ConfigurationException {
Configuration optionsConfig = new PropertiesConfiguration();
for (Map.Entry<Property, OptionSpec<?>> entry : optionSpecs.entrySet()) {
Property property = entry.getKey();
OptionSpec<?> option = entry.getValue();
Object value;
if (property.hasMultipleArguments()) {
value = optionSet.valuesOf(option);
} else {
value = optionSet.valueOf(option);
}
if (value == null && property.getType().equals(Boolean.class) && optionSet.has(property.getSimpleName())) {
value = Boolean.TRUE.toString();
}
if (value != null) {
optionsConfig.setProperty(property.getConfigName(), value);
}
}
CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(optionsConfig);
if (optionSet.has(configOption)) {
Configuration defaults = new PropertiesConfiguration(optionSet.valueOf(configOption));
config.addConfiguration(defaults);
}
ClusterSpec clusterSpec = new ClusterSpec(config);
for (Property required : EnumSet.of(CLUSTER_NAME, PROVIDER, IDENTITY, CREDENTIAL, INSTANCE_TEMPLATES, PRIVATE_KEY_FILE)) {
if (clusterSpec.getConfiguration().getString(required.getConfigName()) == null) {
throw new IllegalArgumentException(String.format("Option '%s' not set.", required.getSimpleName()));
}
}
return clusterSpec;
}
Aggregations