Add minimla coordination service node deletion for multi-user cases

This commit is contained in:
Richard Cordovano 2018-12-31 14:57:43 -05:00
parent 378fe917d0
commit 382cd4bc1e
2 changed files with 49 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2011-2018 Basis Technology Corp. * Copyright 2011-2019 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org * Contact: carrier <at> sleuthkit <dot> org
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -57,6 +57,7 @@ import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.openide.util.Exceptions;
import org.openide.util.Lookup; import org.openide.util.Lookup;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages; import org.openide.util.NbBundle.Messages;
@ -705,8 +706,8 @@ public class Case {
"Case.progressIndicatorTitle.deletingCase=Deleting Case", "Case.progressIndicatorTitle.deletingCase=Deleting Case",
"Case.exceptionMessage.cannotDeleteCurrentCase=Cannot delete current case, it must be closed first.", "Case.exceptionMessage.cannotDeleteCurrentCase=Cannot delete current case, it must be closed first.",
"Case.progressMessage.checkingForOtherUser=Checking to see if another user has the case open...", "Case.progressMessage.checkingForOtherUser=Checking to see if another user has the case open...",
"Case.exceptionMessage.cannotGetLockToDeleteCase=Cannot delete case because it is open for another user or there is a problem with the coordination service." "Case.exceptionMessage.cannotGetLockToDeleteCase=Cannot delete case because it is open for another user or there is a problem with the coordination service.",
}) "Case.exceptionMessage.failedToDeleteCoordinationServiceNodes=Failed to delete the coordination service nodes for the case.",})
public static void deleteCase(CaseMetadata metadata) throws CaseActionException { public static void deleteCase(CaseMetadata metadata) throws CaseActionException {
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
stopWatch.start(); stopWatch.start();
@ -751,14 +752,56 @@ public class Case {
} catch (CoordinationServiceException ex) { } catch (CoordinationServiceException ex) {
stopWatch.stop(); stopWatch.stop();
logger.log(Level.INFO, String.format("Used %d s to fail to acquire case directory coordination service lock for %s (%s) in %s", stopWatch.getElapsedTimeSecs(), metadata.getCaseDisplayName(), metadata.getCaseName(), metadata.getCaseDirectory())); logger.log(Level.INFO, String.format("Used %d s to fail to acquire case directory coordination service lock for %s (%s) in %s", stopWatch.getElapsedTimeSecs(), metadata.getCaseDisplayName(), metadata.getCaseName(), metadata.getCaseDirectory()));
throw new CaseActionException(Bundle.Case_exceptionMessage_cannotGetLockToDeleteCase(), ex); throw new CaseActionException(Bundle.Case_exceptionMessage_failedToDeleteCoordinationServiceNodes(), ex);
} }
} }
try {
deleteCoordinationServiceNodes(metadata, progressIndicator);
} catch (CoordinationServiceException ex) {
throw new CaseActionException(Bundle.Case_creationException_couldNotAcquireDirLock());
}
} finally { } finally {
progressIndicator.finish(); progressIndicator.finish();
} }
} }
/**
* Deletes teh coordination nodes for a multi-user case.
*
* @param metadata The metadata for the case to delete.
* @param progressIndicator The progress indicator for the deletion
* operation.
*
* @throws CoordinationServiceException If there is a problem getting the
* coordination service.
*/
@Messages({
"Case.progressMessage.deletingCoordinationServiceNodes=Deleting coordination service nodes..."
})
static void deleteCoordinationServiceNodes(CaseMetadata metadata, ProgressIndicator progressIndicator) throws CoordinationServiceException {
progressIndicator.progress(Bundle.Case_progressMessage_deletingCoordinationServiceNodes());
CoordinationService coordinationService;
coordinationService = CoordinationService.getInstance();
String resourcesLockNodePath = metadata.getCaseDirectory() + "_resources";
try {
coordinationService.deleteNode(CategoryNode.CASES, resourcesLockNodePath);
} catch (CoordinationServiceException ex) {
/*
* Log but do not notify the user.
*/
logger.log(Level.SEVERE, String.format("Failed to delete resources lock coordination service node for %s (%s) in %s", metadata.getCaseDisplayName(), metadata.getCaseName(), metadata.getCaseDirectory()), ex);
}
String caseDirectoryLockNodePath = metadata.getCaseDirectory();
try {
coordinationService.deleteNode(CategoryNode.CASES, caseDirectoryLockNodePath);
} catch (CoordinationServiceException ex) {
/*
* Log but do not notify the user.
*/
logger.log(Level.SEVERE, String.format("Failed to delete case directory lock coordination service node for %s (%s) in %s", metadata.getCaseDisplayName(), metadata.getCaseName(), metadata.getCaseDirectory()), ex);
}
}
/** /**
* Opens a new or existing case as the current case. * Opens a new or existing case as the current case.
* *

View File

@ -366,7 +366,7 @@ public final class CoordinationService {
* @throws CoordinationServiceException If there is an error deleting the * @throws CoordinationServiceException If there is an error deleting the
* node. * node.
*/ */
void deleteNode(CategoryNode category, String nodePath) throws CoordinationServiceException { public void deleteNode(CategoryNode category, String nodePath) throws CoordinationServiceException {
String fullNodePath = getFullyQualifiedNodePath(category, nodePath); String fullNodePath = getFullyQualifiedNodePath(category, nodePath);
try { try {
curator.delete().forPath(fullNodePath); curator.delete().forPath(fullNodePath);