Search in sources :

Example 6 with CommandFailed

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

the class DumpCommandTest method shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock.

@Test
public void shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock() throws Exception {
    assumeFalse("We haven't found a way to reliably tests permissions on Windows", SystemUtils.IS_OS_WINDOWS);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        StoreLocker storeLocker = new StoreLocker(fileSystem)) {
        storeLocker.checkLock(databaseDirectory.toFile());
        try (Closeable ignored = withPermissions(databaseDirectory.resolve(StoreLocker.STORE_LOCK_FILENAME), emptySet())) {
            execute("foo.db");
            fail("expected exception");
        } catch (CommandFailed e) {
            assertThat(e.getMessage(), equalTo("you do not have permission to dump the database -- is Neo4j " + "running as a different user?"));
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) StoreLocker(org.neo4j.kernel.internal.StoreLocker) Closeable(java.io.Closeable) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 7 with CommandFailed

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

the class DumpCommandTest method shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage.

@Test
public void shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage() throws Exception {
    doThrow(new IOException("the-message")).when(dumper).dump(any(), any(), any());
    try {
        execute("foo.db");
        fail("expected exception");
    } catch (CommandFailed e) {
        assertThat(e.getMessage(), equalTo("unable to dump database: IOException: the-message"));
    }
}
Also used : CommandFailed(org.neo4j.commandline.admin.CommandFailed) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with CommandFailed

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

the class DumpCommandTest method shouldGiveAClearErrorIfTheArchiveAlreadyExists.

@Test
public void shouldGiveAClearErrorIfTheArchiveAlreadyExists() throws Exception {
    doThrow(new FileAlreadyExistsException("the-archive-path")).when(dumper).dump(any(), any(), any());
    try {
        execute("foo.db");
        fail("expected exception");
    } catch (CommandFailed e) {
        assertThat(e.getMessage(), equalTo("archive already exists: the-archive-path"));
    }
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 9 with CommandFailed

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

the class LoadCommandTest method shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage.

@Test
public void shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage() throws IOException, IncorrectUsage, IncorrectFormat {
    doThrow(new FileSystemException("the-message")).when(loader).load(any(), any());
    try {
        execute(null);
        fail("expected exception");
    } catch (CommandFailed e) {
        assertThat(e.getMessage(), equalTo("unable to load database: FileSystemException: the-message"));
    }
}
Also used : FileSystemException(java.nio.file.FileSystemException) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 10 with CommandFailed

use of org.neo4j.commandline.admin.CommandFailed 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);
    }
}
Also used : Path(java.nio.file.Path) ClusterStateDirectory(org.neo4j.causalclustering.core.state.ClusterStateDirectory) Config(org.neo4j.kernel.configuration.Config) StoreLockException(org.neo4j.kernel.StoreLockException) IOException(java.io.IOException) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) CommandFailed(org.neo4j.commandline.admin.CommandFailed) ClusterStateException(org.neo4j.causalclustering.core.state.ClusterStateException) File(java.io.File)

Aggregations

CommandFailed (org.neo4j.commandline.admin.CommandFailed)18 Test (org.junit.Test)9 Path (java.nio.file.Path)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 File (java.io.File)7 IOException (java.io.IOException)7 Config (org.neo4j.kernel.configuration.Config)7 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)6 IncorrectUsage (org.neo4j.commandline.admin.IncorrectUsage)5 CheckConsistencyConfig (org.neo4j.consistency.checking.full.CheckConsistencyConfig)3 StoreLocker (org.neo4j.kernel.internal.StoreLocker)3 Closeable (java.io.Closeable)2 OutsideWorld (org.neo4j.commandline.admin.OutsideWorld)2 MandatoryCanonicalPath (org.neo4j.commandline.arguments.common.MandatoryCanonicalPath)2 OptionalCanonicalPath (org.neo4j.commandline.arguments.common.OptionalCanonicalPath)2 StoreLockException (org.neo4j.kernel.StoreLockException)2 FileUserRepository (org.neo4j.server.security.auth.FileUserRepository)2 FileLock (java.nio.channels.FileLock)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 FileSystemException (java.nio.file.FileSystemException)1