Search in sources :

Example 11 with Config

use of com.torodb.standalone.config.model.Config in project torodb by torodb.

the class CliConfigUtils method uncatchedReadConfig.

private static Config uncatchedReadConfig(final CliConfig cliConfig) throws Exception {
    ObjectMapper objectMapper = ConfigUtils.mapper();
    Config defaultConfig = new Config();
    if (cliConfig.getBackend() != null) {
        defaultConfig.getBackend().setBackendImplementation(CliConfig.getBackendClass(cliConfig.getBackend()).newInstance());
    }
    ObjectNode configNode = (ObjectNode) objectMapper.valueToTree(defaultConfig);
    if (cliConfig.hasConfFile() || cliConfig.hasXmlConfFile()) {
        ObjectMapper mapper = null;
        InputStream inputStream = null;
        if (cliConfig.hasConfFile()) {
            mapper = ConfigUtils.yamlMapper();
            inputStream = cliConfig.getConfInputStream();
        } else if (cliConfig.hasXmlConfFile()) {
            mapper = ConfigUtils.xmlMapper();
            inputStream = cliConfig.getXmlConfInputStream();
        }
        if (inputStream != null) {
            Config config = mapper.readValue(inputStream, Config.class);
            configNode = mapper.valueToTree(config);
        }
    }
    if (cliConfig.getParams() != null) {
        YAMLMapper yamlMapper = ConfigUtils.yamlMapper();
        for (String paramPathValue : cliConfig.getParams()) {
            int paramPathValueSeparatorIndex = paramPathValue.indexOf('=');
            String pathAndProp = paramPathValue.substring(0, paramPathValueSeparatorIndex);
            if (pathAndProp.startsWith("/")) {
                pathAndProp = pathAndProp.substring(1);
            }
            pathAndProp = "/" + pathAndProp;
            String value = paramPathValue.substring(paramPathValueSeparatorIndex + 1);
            configNode = ConfigUtils.mergeParam(yamlMapper, configNode, pathAndProp, value);
        }
    }
    Config config = objectMapper.treeToValue(configNode, Config.class);
    validateBean(config);
    return config;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) Config(com.torodb.standalone.config.model.Config) InputStream(java.io.InputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with Config

use of com.torodb.standalone.config.model.Config in project torodb by torodb.

the class ConfigTest method testParseWithYAMLAndReplaceBackendWithParam.

@Test
public void testParseWithYAMLAndReplaceBackendWithParam() throws Exception {
    CliConfig cliConfig = new CliConfig() {

        @Override
        public boolean hasConfFile() {
            return true;
        }

        @Override
        public InputStream getConfInputStream() {
            return ConfigTest.class.getResourceAsStream("/test-parse-with-yaml.yml");
        }

        @Override
        public List<String> getParams() {
            String[] params = new String[] { "/backend=null", "/backend/derby/host=localhost", "/backend/derby/port=5432", "/backend/derby/user=root" };
            return Arrays.asList(params);
        }
    };
    Config config = CliConfigUtils.readConfig(cliConfig);
    Assert.assertTrue("/backend not defined", config.getBackend() != null);
    Assert.assertEquals("/backend/derby not defined", Derby.class, config.getBackend().getBackendImplementation().getClass());
    Assert.assertTrue("/backend/derby not identified as AbstractDerby", config.getBackend().is(Derby.class));
    Assert.assertTrue("/backend/derby not identified as AbstractDerby Like", config.getBackend().isLike(Derby.class));
    Assert.assertEquals("/backend/derby/host has different value than that specified", "localhost", config.getBackend().as(Derby.class).getHost());
    Assert.assertEquals("/backend/derby/port has different value than that specified", Integer.valueOf(5432), config.getBackend().as(Derby.class).getPort());
    Assert.assertEquals("/backend/derby/user has different value than that specified", "root", config.getBackend().as(Derby.class).getUser());
    Assert.assertEquals("/backend/derby/password specified but should have not been read from parameters", null, config.getBackend().as(Derby.class).getPassword());
}
Also used : Derby(com.torodb.standalone.config.model.backend.derby.Derby) Config(com.torodb.standalone.config.model.Config) CliConfig(com.torodb.standalone.CliConfig) CliConfig(com.torodb.standalone.CliConfig) Test(org.junit.Test)

Example 13 with Config

use of com.torodb.standalone.config.model.Config in project torodb by torodb.

the class ToroDbBootstrapServiceTest method setUp.

@Before
public void setUp() {
    config = new Config();
    config.getProtocol().getMongo().setReplication(null);
    config.getBackend().setBackendImplementation(new Derby());
    config.getBackend().as(Derby.class).setPassword("torodb");
    config.getGeneric().setLogLevel(LogLevel.TRACE);
    ConfigUtils.validateBean(config);
}
Also used : Derby(com.torodb.standalone.config.model.backend.derby.Derby) Config(com.torodb.standalone.config.model.Config) Before(org.junit.Before)

Example 14 with Config

use of com.torodb.standalone.config.model.Config in project torodb by torodb.

the class ConfigTest method testParseWithYAML.

@Test
public void testParseWithYAML() throws Exception {
    CliConfig cliConfig = new CliConfig() {

        @Override
        public boolean hasConfFile() {
            return true;
        }

        @Override
        public InputStream getConfInputStream() {
            return ConfigTest.class.getResourceAsStream("/test-parse-with-yaml.yml");
        }
    };
    Config config = CliConfigUtils.readConfig(cliConfig);
    Assert.assertTrue("/generic not defined", config.getGeneric() != null);
    Assert.assertTrue("/generic/logPackages not defined", config.getGeneric().getLogPackages() != null);
    Assert.assertTrue("/generic/logPackages/com.torodb not defined", config.getGeneric().getLogPackages().get("com.torodb") != null);
    Assert.assertEquals("/generic/logLevel has different value than that specified", LogLevel.NONE, config.getGeneric().getLogLevel());
    Assert.assertEquals("/generic/logPackages has not 1 entry", 1, config.getGeneric().getLogPackages().size());
    Assert.assertEquals("/generic/logPackages/com.torodb has different value than that specified", LogLevel.DEBUG, config.getGeneric().getLogPackages().get("com.torodb"));
    Assert.assertTrue("/protocol not defined", config.getProtocol() != null);
    Assert.assertTrue("/protocol/mongo not defined", config.getProtocol().getMongo() != null);
    Assert.assertTrue("/protocol/mongo/net not defined", config.getProtocol().getMongo().getNet() != null);
    Assert.assertTrue("/protocol/mongo/replication not defined", config.getProtocol().getMongo().getReplication() != null);
    Assert.assertEquals("/protocol/mongo/net/port has different value than that specified", Integer.valueOf(27019), config.getProtocol().getMongo().getNet().getPort());
    Assert.assertEquals("/protocol/mongo/replication has not 1 element", 1, config.getProtocol().getMongo().getReplication().size());
    Assert.assertEquals("/protocol/mongo/replication/0/replSetName has different value than that specified", "rs1", config.getProtocol().getMongo().getReplication().get(0).getReplSetName());
    Assert.assertEquals("/protocol/mongo/replication/0/role has different value than that specified", Role.HIDDEN_SLAVE, config.getProtocol().getMongo().getReplication().get(0).getRole());
    Assert.assertEquals("/protocol/mongo/replication/0/syncSource has different value than that specified", "localhost:27017", config.getProtocol().getMongo().getReplication().get(0).getSyncSource());
    Assert.assertTrue("/backend not defined", config.getBackend() != null);
    Assert.assertEquals("/backend/postgres not defined", Postgres.class, config.getBackend().getBackendImplementation().getClass());
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres", config.getBackend().is(Postgres.class));
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres Like", config.getBackend().isLike(Postgres.class));
    Assert.assertEquals("/backend/postgres/host has different value than that specified", "localhost", config.getBackend().as(Postgres.class).getHost());
    Assert.assertEquals("/backend/postgres/port has different value than that specified", Integer.valueOf(5432), config.getBackend().as(Postgres.class).getPort());
    Assert.assertEquals("/backend/postgres/user has different value than that specified", "root", config.getBackend().as(Postgres.class).getUser());
    Assert.assertEquals("/backend/postgres/password specified but should have not been read from parameters", null, config.getBackend().as(Postgres.class).getPassword());
}
Also used : Config(com.torodb.standalone.config.model.Config) CliConfig(com.torodb.standalone.CliConfig) CliConfig(com.torodb.standalone.CliConfig) Postgres(com.torodb.standalone.config.model.backend.postgres.Postgres) Test(org.junit.Test)

Example 15 with Config

use of com.torodb.standalone.config.model.Config in project torodb by torodb.

the class ConfigTest method testParseWithNullParam.

@Test
public void testParseWithNullParam() throws Exception {
    CliConfig cliConfig = new CliConfig() {

        @Override
        public List<String> getParams() {
            String[] params = new String[] { "/generic/logFile=null" };
            return Arrays.asList(params);
        }
    };
    Config config = CliConfigUtils.readConfig(cliConfig);
    Assert.assertEquals("Parameter has different value than that specified", null, config.getGeneric().getLogFile());
}
Also used : Config(com.torodb.standalone.config.model.Config) CliConfig(com.torodb.standalone.CliConfig) CliConfig(com.torodb.standalone.CliConfig) Test(org.junit.Test)

Aggregations

Config (com.torodb.standalone.config.model.Config)16 CliConfig (com.torodb.standalone.CliConfig)12 Test (org.junit.Test)12 Postgres (com.torodb.standalone.config.model.backend.postgres.Postgres)5 Derby (com.torodb.standalone.config.model.backend.derby.Derby)3 InputStream (java.io.InputStream)2 JCommander (com.beust.jcommander.JCommander)1 Console (com.beust.jcommander.internal.Console)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 Charsets (com.google.common.base.Charsets)1 Throwables (com.google.common.base.Throwables)1 HostAndPort (com.google.common.net.HostAndPort)1 Service (com.google.common.util.concurrent.Service)1 CreationException (com.google.inject.CreationException)1 ConcurrentModule (com.torodb.concurrent.guice.ConcurrentModule)1 SystemException (com.torodb.core.exceptions.SystemException)1 CoreModule (com.torodb.core.guice.CoreModule)1 MetricsModule (com.torodb.core.metrics.guice.MetricsModule)1