use of com.torodb.standalone.config.model.Config in project torodb by torodb.
the class ConfigTest method testParseWithXML.
@Test
public void testParseWithXML() throws Exception {
CliConfig cliConfig = new CliConfig() {
@Override
public boolean hasXmlConfFile() {
return true;
}
@Override
public InputStream getXmlConfInputStream() {
return ConfigTest.class.getResourceAsStream("/test-parse-with-xml.xml");
}
};
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 has different value than that specified", null, config.getBackend().as(Postgres.class).getPassword());
}
use of com.torodb.standalone.config.model.Config in project torodb by torodb.
the class BootstrapModule method configure.
@Override
protected void configure() {
binder().requireExplicitBindings();
install(new PackagingModule(clock));
install(new CoreModule());
install(new ExecutorServicesModule());
install(new ConcurrentModule());
install(new MetainfModule());
install(new MetricsModule(config.getGeneric()));
install(new BackendMultiImplementationModule(config.getProtocol().getMongo(), config.getGeneric(), config.getBackend().getBackendImplementation(), new BackendPostgresImplementationModule(), new BackendDerbyImplementationModule()));
bind(Config.class).toInstance(config);
bind(MongodServerConfig.class).toInstance(new MongodServerConfig(HostAndPort.fromParts("localhost", 27017)));
bind(BuildProperties.class).to(DefaultBuildProperties.class).asEagerSingleton();
}
use of com.torodb.standalone.config.model.Config in project torodb by torodb.
the class Main method main.
public static void main(String[] args) throws Exception {
Console console = JCommander.getConsole();
ResourceBundle cliBundle = PropertyResourceBundle.getBundle("CliMessages");
final CliConfig cliConfig = new CliConfig();
JCommander jCommander = new JCommander(cliConfig, cliBundle, args);
jCommander.setColumnSize(Integer.MAX_VALUE);
if (cliConfig.isHelp()) {
jCommander.usage();
System.exit(0);
}
if (cliConfig.isHelpParam()) {
console.println(cliBundle.getString("help-param-header"));
ResourceBundle configBundle = PropertyResourceBundle.getBundle("ConfigMessages");
ConfigUtils.printParamDescriptionFromConfigSchema(Config.class, configBundle, console, 0);
System.exit(0);
}
final Config config = CliConfigUtils.readConfig(cliConfig);
if (cliConfig.isPrintConfig()) {
ConfigUtils.printYamlConfig(config, console);
System.exit(0);
}
if (cliConfig.isPrintXmlConfig()) {
ConfigUtils.printXmlConfig(config, console);
System.exit(0);
}
configureLogger(cliConfig, config);
config.getBackend().getBackendImplementation().accept(new BackendImplementationVisitor() {
@Override
public void visit(AbstractDerby value) {
parseToropassFile(value);
}
@Override
public void visit(AbstractPostgres value) {
parseToropassFile(value);
}
public void parseToropassFile(BackendPasswordConfig value) {
try {
ConfigUtils.parseToropassFile(value);
} catch (Exception ex) {
throw new SystemException(ex);
}
}
});
if (config.getProtocol().getMongo().getReplication() != null) {
for (AbstractReplication replication : config.getProtocol().getMongo().getReplication()) {
if (replication.getAuth().getUser() != null) {
HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource()).withDefaultPort(27017);
ConfigUtils.parseMongopassFile(new MongoPasswordConfig() {
@Override
public void setPassword(String password) {
replication.getAuth().setPassword(password);
}
@Override
public String getUser() {
return replication.getAuth().getUser();
}
@Override
public Integer getPort() {
return syncSource.getPort();
}
@Override
public String getPassword() {
return replication.getAuth().getPassword();
}
@Override
public String getMongopassFile() {
return config.getProtocol().getMongo().getMongopassFile();
}
@Override
public String getHost() {
return syncSource.getHostText();
}
@Override
public String getDatabase() {
return replication.getAuth().getSource();
}
});
}
}
}
if (config.getBackend().isLike(AbstractPostgres.class)) {
AbstractPostgres postgres = config.getBackend().as(AbstractPostgres.class);
if (cliConfig.isAskForPassword()) {
console.print("Database user " + postgres.getUser() + " password:");
postgres.setPassword(readPwd());
}
} else if (config.getBackend().isLike(AbstractDerby.class)) {
AbstractDerby derby = config.getBackend().as(AbstractDerby.class);
if (cliConfig.isAskForPassword()) {
console.print("Database user " + derby.getUser() + " password:");
derby.setPassword(readPwd());
}
}
try {
Clock clock = Clock.systemDefaultZone();
Service server;
if (config.getProtocol().getMongo().getReplication() == null || config.getProtocol().getMongo().getReplication().isEmpty()) {
Service toroDbServer = ToroDbBootstrap.createStandaloneService(config, clock);
toroDbServer.startAsync();
toroDbServer.awaitRunning();
server = toroDbServer;
} else {
throw new UnsupportedOperationException("Replication not supported yet!");
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
server.stopAsync();
server.awaitTerminated();
}));
} catch (CreationException ex) {
ex.getErrorMessages().stream().forEach(m -> {
if (m.getCause() != null) {
LOGGER.error(m.getCause().getMessage());
} else {
LOGGER.error(m.getMessage());
}
});
System.exit(1);
} catch (Throwable ex) {
LOGGER.error("Fatal error on initialization", ex);
Throwable rootCause = Throwables.getRootCause(ex);
String causeMessage = rootCause.getMessage();
JCommander.getConsole().println("Fatal error while ToroDB was starting: " + causeMessage);
System.exit(1);
}
}
use of com.torodb.standalone.config.model.Config in project torodb by torodb.
the class ConfigTest method testReplicationFiltering.
@Test
public void testReplicationFiltering() 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[] { "/protocol/mongo/replication/0/include={torodb: [postgres, derby]}", "/protocol/mongo/replication/0/exclude={mongodb: {mmapv1, wiredtiger}}" };
return Arrays.asList(params);
}
};
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("/protocol/mongo/replication/0/include not defined", config.getProtocol().getMongo().getReplication().get(0).getInclude() != null);
Assert.assertTrue("/protocol/mongo/replication/0/include/torodb not defined", config.getProtocol().getMongo().getReplication().get(0).getInclude().get("torodb") != null);
Assert.assertEquals("/protocol/mongo/replication/0/include/torodb has different value than that specified", ImmutableMap.of("postgres", ImmutableList.of(), "derby", ImmutableList.of()), config.getProtocol().getMongo().getReplication().get(0).getInclude().get("torodb"));
Assert.assertTrue("/protocol/mongo/replication/0/exclude not defined", config.getProtocol().getMongo().getReplication().get(0).getExclude() != null);
Assert.assertTrue("/protocol/mongo/replication/0/exclude/mongodb not defined", config.getProtocol().getMongo().getReplication().get(0).getExclude().get("mongodb") != null);
Assert.assertEquals("/protocol/mongo/replication/0/exclude/mongodb has different value than that specified", ImmutableMap.of("mmapv1", ImmutableList.of(), "wiredtiger", ImmutableList.of()), config.getProtocol().getMongo().getReplication().get(0).getExclude().get("mongodb"));
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());
}
use of com.torodb.standalone.config.model.Config in project torodb by torodb.
the class ConfigTest method testPrintConf.
@Test
public void testPrintConf() throws Exception {
ByteArrayConsole byteArrayConsole = new ByteArrayConsole();
ConfigUtils.printYamlConfig(new Config(), byteArrayConsole);
ConfigUtils.readConfigFromYaml(Config.class, new String(byteArrayConsole.getByteArrayOutputStream().toByteArray()));
}
Aggregations