Search in sources :

Example 1 with IncorrectUsage

use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.

the class ImportCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    String mode;
    Optional<Path> additionalConfigFile;
    String database;
    try {
        mode = allArguments.parse("mode", args);
        database = allArguments.parse("database", args);
        additionalConfigFile = allArguments.parseOptionalPath("additional-config", args);
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    try {
        Config config = loadNeo4jConfig(homeDir, configDir, database, loadAdditionalConfig(additionalConfigFile));
        Validators.CONTAINS_NO_EXISTING_DATABASE.validate(config.get(DatabaseManagementSystemSettings.database_path));
        Importer importer = importerFactory.getImporterForMode(mode, Args.parse(args), config, outsideWorld);
        importer.doImport();
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) Config(org.neo4j.kernel.configuration.Config) IOException(java.io.IOException)

Example 2 with IncorrectUsage

use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.

the class DatabaseImporterTest method requiresFromArgument.

@Test
public void requiresFromArgument() throws Exception {
    String[] arguments = { "--mode=database", "--database=bar" };
    try {
        new DatabaseImporter(Args.parse(arguments), Config.defaults(), new NullOutsideWorld());
        fail("Should have thrown an exception.");
    } catch (IncorrectUsage e) {
        assertThat(e.getMessage(), containsString("from"));
    }
}
Also used : NullOutsideWorld(org.neo4j.commandline.admin.NullOutsideWorld) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with IncorrectUsage

use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.

the class ImportCommandTest method failIfInvalidModeSpecified.

@Test
public void failIfInvalidModeSpecified() throws Exception {
    try (NullOutsideWorld outsideWorld = new NullOutsideWorld()) {
        ImportCommand importCommand = new ImportCommand(testDir.directory("home").toPath(), testDir.directory("conf").toPath(), outsideWorld);
        String[] arguments = { "--mode=foo", "--database=bar", "--from=baz" };
        try {
            importCommand.execute(arguments);
            fail("Should have thrown an exception.");
        } catch (IncorrectUsage e) {
            assertThat(e.getMessage(), containsString("foo"));
        }
    }
}
Also used : NullOutsideWorld(org.neo4j.commandline.admin.NullOutsideWorld) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 4 with IncorrectUsage

use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.

the class CheckConsistencyCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    final String database;
    final boolean verbose;
    final Optional<Path> additionalConfigFile;
    final Path reportDir;
    final Optional<Path> backupPath;
    final boolean checkGraph;
    final boolean checkIndexes;
    final boolean checkLabelScanStore;
    final boolean checkPropertyOwners;
    try {
        database = arguments.parse("database", args);
        backupPath = arguments.parseOptionalPath("backup", args);
        verbose = arguments.parseBoolean("verbose", args);
        additionalConfigFile = arguments.parseOptionalPath("additional-config", args);
        reportDir = arguments.parseOptionalPath("report-dir", args).orElseThrow(() -> new IllegalArgumentException("report-dir must be a valid path"));
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    if (backupPath.isPresent()) {
        if (arguments.has("database", args)) {
            throw new IncorrectUsage("Only one of '--database' and '--backup' can be specified.");
        }
        if (!backupPath.get().toFile().isDirectory()) {
            throw new CommandFailed(format("Specified backup should be a directory: %s", backupPath.get()));
        }
    }
    Config config = loadNeo4jConfig(homeDir, configDir, database, loadAdditionalConfig(additionalConfigFile));
    try {
        // We can remove the loading from config file in 4.0
        if (arguments.has(CHECK_GRAPH, args)) {
            checkGraph = arguments.parseBoolean(CHECK_GRAPH, args);
        } else {
            checkGraph = ConsistencyCheckSettings.consistency_check_graph.from(config);
        }
        if (arguments.has(CHECK_INDEXES, args)) {
            checkIndexes = arguments.parseBoolean(CHECK_INDEXES, args);
        } else {
            checkIndexes = ConsistencyCheckSettings.consistency_check_indexes.from(config);
        }
        if (arguments.has(CHECK_LABEL_SCAN_STORE, args)) {
            checkLabelScanStore = arguments.parseBoolean(CHECK_LABEL_SCAN_STORE, args);
        } else {
            checkLabelScanStore = ConsistencyCheckSettings.consistency_check_label_scan_store.from(config);
        }
        if (arguments.has(CHECK_PROPERTY_OWNERS, args)) {
            checkPropertyOwners = arguments.parseBoolean(CHECK_PROPERTY_OWNERS, args);
        } else {
            checkPropertyOwners = ConsistencyCheckSettings.consistency_check_property_owners.from(config);
        }
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        File storeDir = backupPath.map(Path::toFile).orElse(config.get(database_path));
        checkDbState(storeDir, config);
        ConsistencyCheckService.Result consistencyCheckResult = consistencyCheckService.runFullConsistencyCheck(storeDir, config, ProgressMonitorFactory.textual(System.err), FormattedLogProvider.toOutputStream(System.out), fileSystem, verbose, reportDir.toFile(), new CheckConsistencyConfig(checkGraph, checkIndexes, checkLabelScanStore, checkPropertyOwners));
        if (!consistencyCheckResult.isSuccessful()) {
            throw new CommandFailed(format("Inconsistencies found. See '%s' for details.", consistencyCheckResult.reportFile()));
        }
    } catch (ConsistencyCheckIncompleteException | IOException e) {
        throw new CommandFailed("Consistency checking failed." + e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) OptionalCanonicalPath(org.neo4j.commandline.arguments.common.OptionalCanonicalPath) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) Config(org.neo4j.kernel.configuration.Config) ConsistencyCheckIncompleteException(org.neo4j.consistency.checking.full.ConsistencyCheckIncompleteException) IOException(java.io.IOException) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) CommandFailed(org.neo4j.commandline.admin.CommandFailed) File(java.io.File)

Example 5 with IncorrectUsage

use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.

the class RestoreDatabaseCli method execute.

@Override
public void execute(String[] incomingArguments) throws IncorrectUsage, CommandFailed {
    String databaseName;
    String fromPath;
    boolean forceOverwrite;
    try {
        databaseName = arguments.parse("database", incomingArguments);
        fromPath = arguments.parse("from", incomingArguments);
        forceOverwrite = arguments.parseBoolean("force", incomingArguments);
    } catch (IllegalArgumentException e) {
        throw new IncorrectUsage(e.getMessage());
    }
    Config config = loadNeo4jConfig(homeDir, configDir, databaseName);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        RestoreDatabaseCommand restoreDatabaseCommand = new RestoreDatabaseCommand(fileSystem, new File(fromPath), config, databaseName, forceOverwrite);
        restoreDatabaseCommand.execute();
    } catch (IOException e) {
        throw new CommandFailed("Failed to restore database", e);
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) Config(org.neo4j.kernel.configuration.Config) CommandFailed(org.neo4j.commandline.admin.CommandFailed) IOException(java.io.IOException) File(java.io.File)

Aggregations

IncorrectUsage (org.neo4j.commandline.admin.IncorrectUsage)10 IOException (java.io.IOException)6 File (java.io.File)5 Path (java.nio.file.Path)5 CommandFailed (org.neo4j.commandline.admin.CommandFailed)5 Config (org.neo4j.kernel.configuration.Config)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Test (org.junit.Test)4 NullOutsideWorld (org.neo4j.commandline.admin.NullOutsideWorld)4 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)3 MandatoryCanonicalPath (org.neo4j.commandline.arguments.common.MandatoryCanonicalPath)2 OptionalCanonicalPath (org.neo4j.commandline.arguments.common.OptionalCanonicalPath)2 CheckConsistencyConfig (org.neo4j.consistency.checking.full.CheckConsistencyConfig)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 Consumer (java.util.function.Consumer)1 ClusterStateDirectory (org.neo4j.causalclustering.core.state.ClusterStateDirectory)1 ClusterStateException (org.neo4j.causalclustering.core.state.ClusterStateException)1 AdminCommand (org.neo4j.commandline.admin.AdminCommand)1 OutsideWorld (org.neo4j.commandline.admin.OutsideWorld)1 Arguments (org.neo4j.commandline.arguments.Arguments)1