Search in sources :

Example 1 with CoreConfigParser

use of com.vaticle.typedb.core.server.parameters.CoreConfigParser in project grakn by graknlabs.

the class TypeDBServer method main.

public static void main(String[] args) {
    try {
        printASCIILogo();
        CoreConfigParser configParser = new CoreConfigParser();
        ArgsParser<ServerSubcommand> argsParser = new ArgsParser<ServerSubcommand>().subcommand(new ServerSubcommandParser.Server(configParser)).subcommand(new ServerSubcommandParser.Import()).subcommand(new ServerSubcommandParser.Export());
        Optional<ServerSubcommand> subcmd = argsParser.parse(args);
        if (subcmd.isEmpty()) {
            LOG.error(UNRECOGNISED_CLI_COMMAND.message(String.join(" ", args)));
            LOG.error(argsParser.usage());
            System.exit(1);
        } else {
            if (subcmd.get().isServer()) {
                ServerSubcommand.Server subcmdServer = subcmd.get().asServer();
                if (subcmdServer.isHelp())
                    System.out.println(argsParser.help());
                else if (subcmdServer.isVersion())
                    System.out.println("Version: " + Version.VERSION);
                else
                    runServer(subcmdServer);
            } else if (subcmd.get().isImport()) {
                importData(subcmd.get().asImport());
            } else if (subcmd.get().isExport()) {
                exportData(subcmd.get().asExport());
            } else
                throw TypeDBException.of(ILLEGAL_STATE);
        }
    } catch (Exception e) {
        if (e instanceof TypeDBException) {
            LOG.error(e.getMessage());
        } else {
            LOG.error(e.getMessage(), e);
            LOG.error(EXITED_WITH_ERROR.message());
        }
        System.exit(1);
    }
    System.exit(0);
}
Also used : TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) ServerSubcommandParser(com.vaticle.typedb.core.server.parameters.ServerSubcommandParser) CoreConfigParser(com.vaticle.typedb.core.server.parameters.CoreConfigParser) BindException(java.net.BindException) IOException(java.io.IOException) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) ServerSubcommand(com.vaticle.typedb.core.server.parameters.ServerSubcommand)

Example 2 with CoreConfigParser

use of com.vaticle.typedb.core.server.parameters.CoreConfigParser in project grakn by graknlabs.

the class CoreConfigTest method overrides_list_can_be_yaml_or_repeated.

@Test
public void overrides_list_can_be_yaml_or_repeated() {
    CoreConfig config = CoreConfigFactory.config(set(new Option("log.logger.typedb.output", "[file]")), new CoreConfigParser());
    assertEquals(set("file"), set(config.log().logger().filteredLoggers().get("typedb").outputs()));
    CoreConfig configWithRepeatedArgs = CoreConfigFactory.config(set(new Option("log.logger.typedb.output", "file"), new Option("log.logger.typedb.output", "stdout")), new CoreConfigParser());
    assertEquals(set("stdout", "file"), set(configWithRepeatedArgs.log().logger().filteredLoggers().get("typedb").outputs()));
}
Also used : CoreConfig(com.vaticle.typedb.core.server.parameters.CoreConfig) Option(com.vaticle.typedb.core.server.parameters.util.Option) CoreConfigParser(com.vaticle.typedb.core.server.parameters.CoreConfigParser) Test(org.junit.Test)

Example 3 with CoreConfigParser

use of com.vaticle.typedb.core.server.parameters.CoreConfigParser in project grakn by graknlabs.

the class CoreConfigTest method config_invalid_path_throws.

@Test
public void config_invalid_path_throws() {
    Path configMissing = Util.getTypedbDir().resolve("server/test/missing.yml");
    try {
        CoreConfigFactory.config(configMissing, new HashSet<>(), new CoreConfigParser());
        fail();
    } catch (TypeDBException e) {
        assert e.code().isPresent();
        assertEquals(CONFIG_FILE_NOT_FOUND.code(), e.code().get());
    }
}
Also used : Path(java.nio.file.Path) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) CoreConfigParser(com.vaticle.typedb.core.server.parameters.CoreConfigParser) Test(org.junit.Test)

Example 4 with CoreConfigParser

use of com.vaticle.typedb.core.server.parameters.CoreConfigParser in project grakn by graknlabs.

the class CoreConfigTest method config_file_missing_data_throws.

@Test
public void config_file_missing_data_throws() {
    Path configMissingLog = Util.getTypedbDir().resolve("server/test/config/config-missing-data.yml");
    try {
        CoreConfigFactory.config(configMissingLog, new HashSet<>(), new CoreConfigParser());
        fail();
    } catch (TypeDBException e) {
        assert e.code().isPresent();
        assertEquals(MISSING_CONFIG_OPTION.code(), e.code().get());
        assertEquals(MISSING_CONFIG_OPTION.message("storage.data"), e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) CoreConfigParser(com.vaticle.typedb.core.server.parameters.CoreConfigParser) Test(org.junit.Test)

Example 5 with CoreConfigParser

use of com.vaticle.typedb.core.server.parameters.CoreConfigParser in project grakn by graknlabs.

the class CoreConfigTest method config_file_invalid_output_reference_throws.

@Test
public void config_file_invalid_output_reference_throws() {
    Path configInvalidOutput = Util.getTypedbDir().resolve("server/test/config/config-invalid-logger-output.yml");
    try {
        CoreConfigFactory.config(configInvalidOutput, new HashSet<>(), new CoreConfigParser());
        fail();
    } catch (TypeDBException e) {
        assert e.code().isPresent();
        assertEquals(CONFIG_OUTPUT_UNRECOGNISED.code(), e.code().get());
    }
}
Also used : Path(java.nio.file.Path) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) CoreConfigParser(com.vaticle.typedb.core.server.parameters.CoreConfigParser) Test(org.junit.Test)

Aggregations

CoreConfigParser (com.vaticle.typedb.core.server.parameters.CoreConfigParser)11 Test (org.junit.Test)10 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)7 Path (java.nio.file.Path)7 CoreConfig (com.vaticle.typedb.core.server.parameters.CoreConfig)4 InetSocketAddress (java.net.InetSocketAddress)3 Option (com.vaticle.typedb.core.server.parameters.util.Option)2 ServerSubcommand (com.vaticle.typedb.core.server.parameters.ServerSubcommand)1 ServerSubcommandParser (com.vaticle.typedb.core.server.parameters.ServerSubcommandParser)1 IOException (java.io.IOException)1 BindException (java.net.BindException)1