use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DiagnosticsReportCommand method getConfig.
private Config getConfig(Path configFile) {
if (!ctx.fs().fileExists(configFile)) {
throw new CommandFailedException("Unable to find config file, tried: " + configFile.toAbsolutePath());
}
Config cfg = Config.newBuilder().fromFileNoThrow(configFile).set(GraphDatabaseSettings.neo4j_home, ctx.homeDir()).commandExpansion(allowCommandExpansion).build();
ConfigUtils.disableAllConnectors(cfg);
return cfg;
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DiagnosticsReportCommand method execute.
@Override
public void execute() {
Config config = getConfig(configFile());
jmxDumper = new JMXDumper(config, ctx.fs(), ctx.out(), ctx.err(), verbose);
DiagnosticsReporter reporter = createAndRegisterSources(config);
if (list) {
listClassifiers(reporter.getAvailableClassifiers());
return;
}
validateClassifiers(reporter);
DiagnosticsReporterProgress progress = buildProgress();
// Start dumping
try {
if (reportDir == null) {
reportDir = Path.of(System.getProperty("java.io.tmpdir")).resolve("reports").toAbsolutePath();
}
Path reportFile = reportDir.resolve(getDefaultFilename());
ctx.out().println("Writing report to " + reportFile.toAbsolutePath());
reporter.dump(classifiers, reportFile, progress, force);
} catch (IOException e) {
throw new CommandFailedException("Creating archive failed", e);
}
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class CheckConsistencyCommandIT method failsWhenInconsistenciesAreFound.
@Test
void failsWhenInconsistenciesAreFound() throws Exception {
ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
when(consistencyCheckService.runFullConsistencyCheck(any(DatabaseLayout.class), any(Config.class), any(ProgressMonitorFactory.class), any(LogProvider.class), any(FileSystemAbstraction.class), eq(true), any(), any(ConsistencyFlags.class))).thenReturn(ConsistencyCheckService.Result.failure(Path.of("/the/report/path"), new ConsistencySummaryStatistics()));
CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> {
CommandLine.populateCommand(checkConsistencyCommand, "--database=mydb", "--verbose");
checkConsistencyCommand.execute();
});
assertThat(commandFailed.getMessage()).contains(Path.of("/the/report/path").toString());
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class CheckConsistencyCommandIT method consistencyCheckerRespectDatabaseLock.
@Test
void consistencyCheckerRespectDatabaseLock() throws CannotWriteException, IOException {
ConsistencyCheckService consistencyCheckService = mock(ConsistencyCheckService.class);
CheckConsistencyCommand checkConsistencyCommand = new CheckConsistencyCommand(new ExecutionContext(homeDir, confPath), consistencyCheckService);
DatabaseLayout databaseLayout = neo4jLayout.databaseLayout("mydb");
testDirectory.getFileSystem().mkdirs(databaseLayout.databaseDirectory());
try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
CommandLine.populateCommand(checkConsistencyCommand, "--database=mydb", "--verbose");
CommandFailedException exception = assertThrows(CommandFailedException.class, checkConsistencyCommand::execute);
assertThat(exception.getCause()).isInstanceOf(FileLockException.class);
assertThat(exception.getMessage()).isEqualTo("The database is in use. Stop database 'mydb' and try again.");
}
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class SetInitialPasswordCommand method execute.
@Override
public void execute() throws IOException {
Config config = loadNeo4jConfig();
FileSystemAbstraction fileSystem = ctx.fs();
if (realUsersExist(config)) {
Path authFile = CommunitySecurityModule.getUserRepositoryFile(config);
throw new CommandFailedException(realUsersExistErrorMsg(fileSystem, authFile));
} else {
Path file = CommunitySecurityModule.getInitialUserRepositoryFile(config);
if (fileSystem.fileExists(file)) {
fileSystem.deleteFile(file);
}
FileUserRepository userRepository = new FileUserRepository(fileSystem, file, NullLogProvider.getInstance());
try {
userRepository.start();
userRepository.create(new User.Builder(INITIAL_USER_NAME, createCredentialForPassword(UTF8.encode(password))).withRequiredPasswordChange(changeRequired).build());
userRepository.shutdown();
} catch (Exception e) {
throw new RuntimeException(e);
}
ctx.out().println("Changed password for user '" + INITIAL_USER_NAME + "'.");
}
}
Aggregations