Search in sources :

Example 46 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.

the class TestConfigurationSubscription method testExceptionInConfigLoad.

@Test(timeout = 60000)
public void testExceptionInConfigLoad() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("prop1", "1");
    writer.save();
    DeterministicScheduler mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
    final AtomicInteger count = new AtomicInteger(1);
    conf.addConfigurationListener(new ConfigurationListener() {

        @Override
        public void configurationChanged(ConfigurationEvent event) {
            LOG.info("config changed {}", event);
            // Throw after so we actually see the update anyway.
            if (!event.isBeforeUpdate()) {
                count.getAndIncrement();
                throw new RuntimeException("config listener threw and exception");
            }
        }
    });
    int i = 0;
    int initial = 0;
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }
    initial = count.get();
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }
}
Also used : ConfigurationEvent(org.apache.commons.configuration.event.ConfigurationEvent) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeterministicScheduler(org.jmock.lib.concurrent.DeterministicScheduler) Test(org.junit.Test)

Example 47 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.

the class TestConfUtils method testLoadConfiguration.

@Test(timeout = 60000)
public void testLoadConfiguration() {
    Configuration conf1 = new CompositeConfiguration();
    conf1.setProperty("key1", "value1");
    conf1.setProperty("key2", "value2");
    conf1.setProperty("key3", "value3");
    Configuration conf2 = new CompositeConfiguration();
    conf2.setProperty("bkc.key1", "bkc.value1");
    conf2.setProperty("bkc.key4", "bkc.value4");
    assertEquals("value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals(null, conf1.getString("key4"));
    ConfUtils.loadConfiguration(conf1, conf2, "bkc.");
    assertEquals("bkc.value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals("bkc.value4", conf1.getString("key4"));
    assertEquals(null, conf1.getString("bkc.key1"));
    assertEquals(null, conf1.getString("bkc.key4"));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Test(org.junit.Test)

Example 48 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.

the class StorageServer method loadConfFile.

private static void loadConfFile(CompositeConfiguration conf, String confFile) throws IllegalArgumentException {
    try {
        Configuration loadedConf = new PropertiesConfiguration(new File(confFile).toURI().toURL());
        conf.addConfiguration(loadedConf);
    } catch (MalformedURLException e) {
        log.error("Could not open configuration file {}", confFile, e);
        throw new IllegalArgumentException("Could not open configuration file " + confFile, e);
    } catch (ConfigurationException e) {
        log.error("Malformed configuration file {}", confFile, e);
        throw new IllegalArgumentException("Malformed configuration file " + confFile, e);
    }
    log.info("Loaded configuration file {}", confFile);
}
Also used : MalformedURLException(java.net.MalformedURLException) Configuration(org.apache.commons.configuration.Configuration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) StorageServerConfiguration(org.apache.bookkeeper.stream.server.conf.StorageServerConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) BookieConfiguration(org.apache.bookkeeper.stream.server.conf.BookieConfiguration) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) DLConfiguration(org.apache.bookkeeper.stream.server.conf.DLConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) File(java.io.File)

Example 49 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.

the class StorageServer method doMain.

static int doMain(String[] args) {
    // register thread uncaught exception handler
    Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> log.error("Uncaught exception in thread {}: {}", thread.getName(), exception.getMessage()));
    // parse the commandline
    ServerArguments arguments = new ServerArguments();
    JCommander jCommander = new JCommander(arguments);
    jCommander.setProgramName("StorageServer");
    jCommander.parse(args);
    if (arguments.help) {
        jCommander.usage();
        return ExitCode.INVALID_CONF.code();
    }
    CompositeConfiguration conf = new CompositeConfiguration();
    if (null != arguments.serverConfigFile) {
        loadConfFile(conf, arguments.serverConfigFile);
    }
    int grpcPort = arguments.port;
    LifecycleComponent storageServer;
    try {
        storageServer = startStorageServer(conf, grpcPort, 1024, Optional.empty());
    } catch (ConfigurationException e) {
        log.error("Invalid storage configuration", e);
        return ExitCode.INVALID_CONF.code();
    } catch (UnknownHostException e) {
        log.error("Unknonw host name", e);
        return ExitCode.UNKNOWN_HOSTNAME.code();
    }
    CompletableFuture<Void> liveFuture = ComponentStarter.startComponent(storageServer);
    try {
        liveFuture.get();
    } catch (InterruptedException e) {
        // the server is interrupted.
        Thread.currentThread().interrupt();
        log.info("Storage server is interrupted. Exiting ...");
    } catch (ExecutionException e) {
        log.info("Storage server is exiting ...");
    }
    return ExitCode.OK.code();
}
Also used : UnknownHostException(java.net.UnknownHostException) LifecycleComponent(org.apache.bookkeeper.common.component.LifecycleComponent) ConfigurationException(org.apache.commons.configuration.ConfigurationException) JCommander(com.beust.jcommander.JCommander) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ExecutionException(java.util.concurrent.ExecutionException) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint)

Example 50 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.

the class TestDefaultStorageContainerFactory method testCreate.

@Test
public void testCreate() throws Exception {
    OrderedScheduler scheduler = mock(OrderedScheduler.class);
    OrderedScheduler snapshotScheduler = mock(OrderedScheduler.class);
    MVCCStoreFactory storeFactory = mock(MVCCStoreFactory.class);
    ListeningScheduledExecutorService snapshotExecutor = mock(ListeningScheduledExecutorService.class);
    when(snapshotScheduler.chooseThread(anyLong())).thenReturn(snapshotExecutor);
    Mockito.doReturn(mock(ListenableScheduledFuture.class)).when(snapshotExecutor).scheduleWithFixedDelay(any(Runnable.class), anyInt(), anyInt(), any(TimeUnit.class));
    DefaultStorageContainerFactory factory = new DefaultStorageContainerFactory(new StorageConfiguration(new CompositeConfiguration()), (streamId, rangeId) -> streamId, scheduler, storeFactory, URI.create("distributedlog://127.0.0.1/stream/storage"));
    StorageContainer sc = factory.createStorageContainer(1234L);
    assertTrue(sc instanceof StorageContainerImpl);
    assertEquals(1234L, sc.getId());
}
Also used : MVCCStoreFactory(org.apache.bookkeeper.stream.storage.impl.store.MVCCStoreFactory) ListeningScheduledExecutorService(com.google.common.util.concurrent.ListeningScheduledExecutorService) ListenableScheduledFuture(com.google.common.util.concurrent.ListenableScheduledFuture) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) TimeUnit(java.util.concurrent.TimeUnit) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) Test(org.junit.Test)

Aggregations

CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)89 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)46 Test (org.junit.Test)24 ClusterController (org.apache.whirr.ClusterController)22 Configuration (org.apache.commons.configuration.Configuration)21 File (java.io.File)17 Before (org.junit.Before)11 ForceField (ffx.potential.parameters.ForceField)10 ConfigurationException (org.apache.commons.configuration.ConfigurationException)9 HadoopProxy (org.apache.whirr.service.hadoop.HadoopProxy)9 BeforeClass (org.junit.BeforeClass)9 IOException (java.io.IOException)8 ClusterSpec (org.apache.whirr.ClusterSpec)8 MolecularAssembly (ffx.potential.MolecularAssembly)7 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)7 PDBFilter (ffx.potential.parsers.PDBFilter)7 MapConfiguration (org.apache.commons.configuration.MapConfiguration)6 Crystal (ffx.crystal.Crystal)5 ReflectionList (ffx.crystal.ReflectionList)5 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)5