use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class CheckConsistencyCommand method execute.
@Override
public void execute() {
options.warnOnUsageOfDeprecatedOptions(spec, ctx);
if (target.backup != null) {
target.backup = target.backup.toAbsolutePath();
if (!Files.isDirectory(target.backup)) {
throw new CommandFailedException("Report directory path doesn't exist or not a directory: " + target.backup);
}
}
Config config = loadNeo4jConfig(ctx.homeDir(), ctx.confDir(), additionalConfig);
var memoryTracker = EmptyMemoryTracker.INSTANCE;
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
DatabaseLayout databaseLayout = Optional.ofNullable(target.backup).map(DatabaseLayout::ofFlat).orElseGet(() -> Neo4jLayout.of(config).databaseLayout(target.database.name()));
checkDatabaseExistence(databaseLayout);
try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
checkDbState(databaseLayout, config, memoryTracker);
// Only output progress indicator if a console receives the output
ProgressMonitorFactory progressMonitorFactory = ProgressMonitorFactory.NONE;
if (System.console() != null) {
progressMonitorFactory = ProgressMonitorFactory.textual(System.out);
}
ConsistencyCheckService.Result consistencyCheckResult;
try (Log4jLogProvider logProvider = Util.configuredLogProvider(config, System.out)) {
consistencyCheckResult = consistencyCheckService.runFullConsistencyCheck(databaseLayout, config, progressMonitorFactory, logProvider, fileSystem, verbose, options.getReportDir().normalize(), new ConsistencyFlags(options.isCheckGraph(), options.isCheckIndexes(), options.isCheckIndexStructure()));
}
if (!consistencyCheckResult.isSuccessful()) {
throw new CommandFailedException(format("Inconsistencies found. See '%s' for details.", consistencyCheckResult.reportFile()));
}
} catch (FileLockException e) {
throw new CommandFailedException("The database is in use. Stop database '" + databaseLayout.getDatabaseName() + "' and try again.", e);
} catch (CannotWriteException e) {
throw new CommandFailedException("You do not have permission to check database consistency.", e);
}
} catch (ConsistencyCheckIncompleteException | IOException e) {
throw new CommandFailedException("Consistency checking failed." + e.getMessage(), e);
}
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class MemoryRecommendationsCommand method getConfig.
private Config getConfig(Path configFile) {
if (!ctx.fs().fileExists(configFile)) {
throw new CommandFailedException("Unable to find config file, tried: " + configFile.toAbsolutePath());
}
Config config = Config.newBuilder().fromFile(configFile).set(GraphDatabaseSettings.neo4j_home, ctx.homeDir().toAbsolutePath()).commandExpansion(allowCommandExpansion).build();
ConfigUtils.disableAllConnectors(config);
return config;
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class StoreInfoCommand method printInfo.
private static String printInfo(FileSystemAbstraction fs, DatabaseLayout databaseLayout, PageCache pageCache, StorageEngineFactory storageEngineFactory, Config config, boolean structured, boolean failSilently) {
var memoryTracker = EmptyMemoryTracker.INSTANCE;
try (var ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
var storeVersionCheck = storageEngineFactory.versionCheck(fs, databaseLayout, Config.defaults(), pageCache, NullLogService.getInstance(), PageCacheTracer.NULL);
var storeVersion = storeVersionCheck.storeVersion(CursorContext.NULL).orElseThrow(() -> new CommandFailedException(format("Could not find version metadata in store '%s'", databaseLayout.databaseDirectory())));
var versionInformation = storageEngineFactory.versionInformation(storeVersion);
var recoveryRequired = checkRecoveryState(fs, databaseLayout, config, memoryTracker);
var txIdStore = storageEngineFactory.readOnlyTransactionIdStore(fs, databaseLayout, pageCache, CursorContext.NULL);
// Latest committed tx id found in metadata store. May be behind if recovery is required.
var lastTxId = txIdStore.getLastCommittedTransactionId();
var successorString = versionInformation.successor().map(StoreVersion::introductionNeo4jVersion).orElse(null);
var storeInfo = StoreInfo.notInUseResult(databaseLayout.getDatabaseName(), storeVersion, versionInformation.introductionNeo4jVersion(), successorString, lastTxId, recoveryRequired);
return storeInfo.print(structured);
} catch (FileLockException e) {
if (!failSilently) {
throw new CommandFailedException(format("Failed to execute command as the database '%s' is in use. " + "Please stop it and try again.", databaseLayout.getDatabaseName()), e);
}
return StoreInfo.inUseResult(databaseLayout.getDatabaseName()).print(structured);
} catch (CommandFailedException e) {
throw e;
} catch (Exception e) {
throw new CommandFailedException(format("Failed to execute command: '%s'.", e.getMessage()), e);
}
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class StoreInfoCommand method execute.
@Override
public void execute() {
var storageEngineFactory = StorageEngineFactory.defaultStorageEngine();
var config = CommandHelpers.buildConfig(ctx, allowCommandExpansion);
var neo4jLayout = Neo4jLayout.of(config);
try (var fs = ctx.fs();
var jobScheduler = createInitialisedScheduler();
var pageCache = StandalonePageCacheFactory.createPageCache(fs, jobScheduler, PageCacheTracer.NULL)) {
validatePath(fs, all, path, neo4jLayout);
if (all) {
var collector = structured ? Collectors.joining(",", "[", "]") : Collectors.joining(System.lineSeparator() + System.lineSeparator());
var result = Arrays.stream(fs.listFiles(path)).sorted(comparing(Path::getFileName)).map(dbPath -> neo4jLayout.databaseLayout(dbPath.getFileName().toString())).filter(dbLayout -> Validators.isExistingDatabase(fs, dbLayout)).map(dbLayout -> printInfo(fs, dbLayout, pageCache, storageEngineFactory, config, structured, true)).collect(collector);
ctx.out().println(result);
} else {
var databaseLayout = neo4jLayout.databaseLayout(path.getFileName().toString());
ctx.out().println(printInfo(fs, databaseLayout, pageCache, storageEngineFactory, config, structured, false));
}
} catch (CommandFailedException e) {
throw e;
} catch (Exception e) {
throw new CommandFailedException(format("Failed to execute command: '%s'.", e.getMessage()), e);
}
}
Aggregations