use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.
the class OnlineBackupCommand method execute.
@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
final HostnamePort address;
final Path folder;
final String name;
final boolean fallbackToFull;
final boolean doConsistencyCheck;
final Optional<Path> additionalConfig;
final Path reportDir;
final long timeout;
final boolean checkGraph;
final boolean checkIndexes;
final boolean checkLabelScanStore;
final boolean checkPropertyOwners;
try {
address = toHostnamePort(new HostnamePort("localhost", 6362)).apply(arguments.parse("from", args));
folder = arguments.parseMandatoryPath("backup-dir", args);
name = arguments.parse("name", args);
fallbackToFull = arguments.parseBoolean("fallback-to-full", args);
doConsistencyCheck = arguments.parseBoolean("check-consistency", args);
timeout = parseTimeout(args);
additionalConfig = arguments.parseOptionalPath("additional-config", args);
reportDir = arguments.parseOptionalPath("cc-report-dir", args).orElseThrow(() -> new IllegalArgumentException("cc-report-dir must be a path"));
} catch (IllegalArgumentException e) {
throw new IncorrectUsage(e.getMessage());
}
// Make sure destination exists
if (!outsideWorld.fileSystem().isDirectory(folder.toFile())) {
throw new CommandFailed(String.format("Directory '%s' does not exist.", folder));
}
if (!outsideWorld.fileSystem().isDirectory(reportDir.toFile())) {
throw new CommandFailed(String.format("Directory '%s' does not exist.", reportDir));
}
File destination = folder.resolve(name).toFile();
Config config = loadConfig(additionalConfig);
boolean done = false;
try {
// We can remove the loading from config file in 4.0
if (arguments.has("cc-graph", args)) {
checkGraph = arguments.parseBoolean("cc-graph", args);
} else {
checkGraph = ConsistencyCheckSettings.consistency_check_graph.from(config);
}
if (arguments.has("cc-indexes", args)) {
checkIndexes = arguments.parseBoolean("cc-indexes", args);
} else {
checkIndexes = ConsistencyCheckSettings.consistency_check_indexes.from(config);
}
if (arguments.has("cc-label-scan-store", args)) {
checkLabelScanStore = arguments.parseBoolean("cc-label-scan-store", args);
} else {
checkLabelScanStore = ConsistencyCheckSettings.consistency_check_label_scan_store.from(config);
}
if (arguments.has("cc-property-owners", args)) {
checkPropertyOwners = arguments.parseBoolean("cc-property-owners", args);
} else {
checkPropertyOwners = ConsistencyCheckSettings.consistency_check_property_owners.from(config);
}
} catch (IllegalArgumentException e) {
throw new IncorrectUsage(e.getMessage());
}
File[] listFiles = outsideWorld.fileSystem().listFiles(destination);
if (listFiles != null && listFiles.length > 0) {
outsideWorld.stdOutLine("Destination is not empty, doing incremental backup...");
try {
backupService.doIncrementalBackup(address.getHost(), address.getPort(), destination, timeout, config);
done = true;
} catch (Exception e) {
if (fallbackToFull) {
outsideWorld.stdErrLine("Incremental backup failed: " + e.getMessage());
String renamed = renameExistingBackup(folder, name);
outsideWorld.stdErrLine(String.format("Old backup renamed to '%s'.", renamed));
} else {
throw new CommandFailed("Backup failed: " + e.getMessage(), e);
}
}
}
if (!done) {
outsideWorld.stdOutLine("Doing full backup...");
try {
backupService.doFullBackup(address.getHost(), address.getPort(), destination, ConsistencyCheck.NONE, config, timeout, false);
} catch (Exception e) {
throw new CommandFailed("Backup failed: " + e.getMessage(), e);
}
}
if (doConsistencyCheck) {
try {
outsideWorld.stdOutLine("Doing consistency check...");
ConsistencyCheckService.Result ccResult = consistencyCheckService.runFullConsistencyCheck(destination, config, ProgressMonitorFactory.textual(outsideWorld.errorStream()), FormattedLogProvider.toOutputStream(outsideWorld.outStream()), outsideWorld.fileSystem(), false, reportDir.toFile(), new CheckConsistencyConfig(checkGraph, checkIndexes, checkLabelScanStore, checkPropertyOwners));
if (!ccResult.isSuccessful()) {
throw new CommandFailed(String.format("Inconsistencies found. See '%s' for details.", ccResult.reportFile()), STATUS_CC_INCONSISTENT);
}
} catch (Throwable e) {
if (e instanceof CommandFailed) {
throw (CommandFailed) e;
}
throw new CommandFailed("Failed to do consistency check on backup: " + e.getMessage(), e, STATUS_CC_ERROR);
}
}
outsideWorld.stdOutLine("Backup complete.");
}
use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.
the class UnbindFromClusterCommand method execute.
@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
try {
Config config = loadNeo4jConfig(homeDir, configDir, arguments.parse("database", args));
File dataDirectory = config.get(DatabaseManagementSystemSettings.data_directory);
Path pathToSpecificDatabase = config.get(DatabaseManagementSystemSettings.database_path).toPath();
Validators.CONTAINS_EXISTING_DATABASE.validate(pathToSpecificDatabase.toFile());
confirmTargetDirectoryIsWritable(pathToSpecificDatabase);
ClusterStateDirectory clusterStateDirectory = new ClusterStateDirectory(dataDirectory);
clusterStateDirectory.initialize(outsideWorld.fileSystem());
deleteClusterStateIn(clusterStateDirectory.get().toPath());
} catch (StoreLockException e) {
throw new CommandFailed("Database is currently locked. Please shutdown Neo4j.", e);
} catch (IllegalArgumentException e) {
throw new IncorrectUsage(e.getMessage());
} catch (UnbindFailureException | CannotWriteException | IOException | ClusterStateException e) {
throw new CommandFailed(e.getMessage(), e);
}
}
use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.
the class VersionCommand method execute.
@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
final Path storeDir = arguments.parseMandatoryPath("store", args);
Validators.CONTAINS_EXISTING_DATABASE.validate(storeDir.toFile());
try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
final String storeVersion = new StoreVersionCheck(pageCache).getVersion(storeDir.resolve(MetaDataStore.DEFAULT_NAME).toFile()).orElseThrow(() -> new CommandFailed(String.format("Could not find version metadata in store '%s'", storeDir)));
final String fmt = "%-25s%s";
out.accept(String.format(fmt, "Store format version:", storeVersion));
RecordFormats format = RecordFormatSelector.selectForVersion(storeVersion);
out.accept(String.format(fmt, "Introduced in version:", format.introductionVersion()));
findSuccessor(format).map(next -> String.format(fmt, "Superseded in version:", next.introductionVersion())).ifPresent(out);
out.accept(String.format(fmt, "Current version:", Version.getNeo4jVersion()));
} catch (IOException e) {
throw new CommandFailed(e.getMessage(), e);
}
}
use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.
the class DatabaseImporterTest method failIfSourceIsNotAStore.
@Test
public void failIfSourceIsNotAStore() throws Exception {
File from = testDir.directory("empty");
String[] arguments = { "--mode=database", "--database=bar", "--from=" + from.getAbsolutePath() };
try {
new DatabaseImporter(Args.parse(arguments), Config.defaults(), new NullOutsideWorld());
fail("Should have thrown an exception.");
} catch (IncorrectUsage e) {
assertThat(e.getMessage(), containsString("does not contain a database"));
}
}
use of org.neo4j.commandline.admin.IncorrectUsage in project neo4j by neo4j.
the class ImportCommandTest method requiresDatabaseArgument.
@Test
public void requiresDatabaseArgument() throws Exception {
try (NullOutsideWorld outsideWorld = new NullOutsideWorld()) {
ImportCommand importCommand = new ImportCommand(testDir.directory("home").toPath(), testDir.directory("conf").toPath(), outsideWorld);
String[] arguments = { "--mode=database", "--from=bar" };
try {
importCommand.execute(arguments);
fail("Should have thrown an exception.");
} catch (IncorrectUsage e) {
assertThat(e.getMessage(), containsString("database"));
}
}
}
Aggregations