Search in sources :

Example 26 with CommandFailedException

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;
}
Also used : Config(org.neo4j.configuration.Config) CommandFailedException(org.neo4j.cli.CommandFailedException)

Example 27 with CommandFailedException

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);
    }
}
Also used : Path(java.nio.file.Path) JMXDumper(org.neo4j.dbms.diagnostics.jmx.JMXDumper) Config(org.neo4j.configuration.Config) DiagnosticsReporterProgress(org.neo4j.kernel.diagnostics.DiagnosticsReporterProgress) DiagnosticsReporter(org.neo4j.kernel.diagnostics.DiagnosticsReporter) IOException(java.io.IOException) CommandFailedException(org.neo4j.cli.CommandFailedException)

Example 28 with CommandFailedException

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());
}
Also used : LogProvider(org.neo4j.logging.LogProvider) ExecutionContext(org.neo4j.cli.ExecutionContext) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ProgressMonitorFactory(org.neo4j.internal.helpers.progress.ProgressMonitorFactory) ConsistencyFlags(org.neo4j.consistency.checking.full.ConsistencyFlags) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) CommandFailedException(org.neo4j.cli.CommandFailedException) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.jupiter.api.Test)

Example 29 with CommandFailedException

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.");
    }
}
Also used : ExecutionContext(org.neo4j.cli.ExecutionContext) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CheckConsistencyCommand(org.neo4j.consistency.CheckConsistencyCommand) CommandFailedException(org.neo4j.cli.CommandFailedException) Test(org.junit.jupiter.api.Test)

Example 30 with CommandFailedException

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 + "'.");
    }
}
Also used : Path(java.nio.file.Path) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) User(org.neo4j.kernel.impl.security.User) Config(org.neo4j.configuration.Config) CommandFailedException(org.neo4j.cli.CommandFailedException) IOException(java.io.IOException) CommandFailedException(org.neo4j.cli.CommandFailedException)

Aggregations

CommandFailedException (org.neo4j.cli.CommandFailedException)34 Test (org.junit.jupiter.api.Test)20 IOException (java.io.IOException)10 Path (java.nio.file.Path)10 Config (org.neo4j.configuration.Config)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)9 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)6 Closeable (java.io.Closeable)5 ExecutionContext (org.neo4j.cli.ExecutionContext)5 FileLockException (org.neo4j.kernel.internal.locker.FileLockException)5 NoSuchFileException (java.nio.file.NoSuchFileException)3 CheckConsistencyCommand (org.neo4j.consistency.CheckConsistencyCommand)3 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 ConsistencyFlags (org.neo4j.consistency.checking.full.ConsistencyFlags)2 ProgressMonitorFactory (org.neo4j.internal.helpers.progress.ProgressMonitorFactory)2 DatabaseLocker (org.neo4j.kernel.internal.locker.DatabaseLocker)2 Locker (org.neo4j.kernel.internal.locker.Locker)2