5373 finish using AutopsyException for purposes of 4595

This commit is contained in:
William Schaefer 2019-08-02 14:41:59 -04:00
parent 0966948b5e
commit f7e1b845ba
4 changed files with 42 additions and 40 deletions

View File

@ -3246,10 +3246,10 @@ abstract class AbstractSqlEamDb implements EamDb {
try { try {
minorVersion = Integer.parseInt(minorVersionStr); minorVersion = Integer.parseInt(minorVersionStr);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
throw new EamDbException(Bundle.AbstractSqlEamDb_badMinorSchema_message(minorVersionStr), ex); throw new EamDbException("Bad value for schema minor version (" + minorVersionStr + ") - database is corrupt", Bundle.AbstractSqlEamDb_badMinorSchema_message(minorVersionStr), ex);
} }
} else { } else {
throw new EamDbException(Bundle.AbstractSqlEamDb_failedToReadMinorVersion_message()); throw new EamDbException("Failed to read schema minor version from db_info table", Bundle.AbstractSqlEamDb_failedToReadMinorVersion_message());
} }
int majorVersion = 0; int majorVersion = 0;
@ -3260,10 +3260,10 @@ abstract class AbstractSqlEamDb implements EamDb {
try { try {
majorVersion = Integer.parseInt(majorVersionStr); majorVersion = Integer.parseInt(majorVersionStr);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
throw new EamDbException(Bundle.AbstractSqlEamDb_badMajorSchema_message(majorVersionStr), ex); throw new EamDbException("Bad value for schema version (" + majorVersionStr + ") - database is corrupt", Bundle.AbstractSqlEamDb_badMajorSchema_message(majorVersionStr), ex);
} }
} else { } else {
throw new EamDbException(Bundle.AbstractSqlEamDb_failedToReadMajorVersion_message()); throw new EamDbException("Failed to read schema major version from db_info table", Bundle.AbstractSqlEamDb_failedToReadMajorVersion_message());
} }
/* /*
@ -3341,7 +3341,7 @@ abstract class AbstractSqlEamDb implements EamDb {
addObjectIdIndexTemplate = SqliteEamDbSettings.getAddObjectIdIndexTemplate(); addObjectIdIndexTemplate = SqliteEamDbSettings.getAddObjectIdIndexTemplate();
break; break;
default: default:
throw new EamDbException(Bundle.AbstractSqlEamDb_cannotUpgrage_message(selectedPlatform.name())); throw new EamDbException("Currently selected database platform \"" + selectedPlatform.name() + "\" can not be upgraded.", Bundle.AbstractSqlEamDb_cannotUpgrage_message(selectedPlatform.name()));
} }
final String dataSourcesTableName = "data_sources"; final String dataSourcesTableName = "data_sources";
final String dataSourceObjectIdColumnName = "datasource_obj_id"; final String dataSourceObjectIdColumnName = "datasource_obj_id";
@ -3501,7 +3501,7 @@ abstract class AbstractSqlEamDb implements EamDb {
statement.execute("DROP TABLE old_data_sources"); statement.execute("DROP TABLE old_data_sources");
break; break;
default: default:
throw new EamDbException(Bundle.AbstractSqlEamDb_cannotUpgrage_message(selectedPlatform.name())); throw new EamDbException("Currently selected database platform \"" + selectedPlatform.name() + "\" can not be upgraded.", Bundle.AbstractSqlEamDb_cannotUpgrage_message(selectedPlatform.name()));
} }
} }
updateSchemaVersion(conn); updateSchemaVersion(conn);

View File

@ -31,6 +31,7 @@ import org.sleuthkit.autopsy.coordinationservice.CoordinationService.Coordinatio
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.SOFTWARE_CR_DB_SCHEMA_VERSION; import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.SOFTWARE_CR_DB_SCHEMA_VERSION;
import org.sleuthkit.autopsy.exceptions.AutopsyException;
/** /**
* *
@ -181,32 +182,39 @@ public class EamDbUtil {
} }
EamDb db = null; EamDb db = null;
CoordinationService.Lock lock = null; CoordinationService.Lock lock = null;
String messageForDialog = "";
//get connection //get connection
try { try {
db = EamDb.getInstance();
} catch (EamDbException ex) {
LOGGER.log(Level.SEVERE, "Error updating central repository, unable to make connection", ex);
messageForDialog = Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message();
}
//get lock necessary for upgrade
if (db != null) {
try { try {
// This may return null if locking isn't supported, which is fine. It will db = EamDb.getInstance();
// throw an exception if locking is supported but we can't get the lock } catch (EamDbException ex) {
// (meaning the database is in use by another user) LOGGER.log(Level.SEVERE, "Error updating central repository, unable to make connection", ex);
lock = db.getExclusiveMultiUserDbLock(); throw new EamDbException("Error updating central repository, unable to make connection", Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
//perform upgrade }
//get lock necessary for upgrade
if (db != null) {
try {
// This may return null if locking isn't supported, which is fine. It will
// throw an exception if locking is supported but we can't get the lock
// (meaning the database is in use by another user)
lock = db.getExclusiveMultiUserDbLock();
//perform upgrade
} catch (EamDbException ex) {
LOGGER.log(Level.SEVERE, "Error updating central repository, unable to acquire exclusive lock", ex);
throw new EamDbException("Error updating central repository, unable to acquire exclusive lock", Bundle.EamDbUtil_exclusiveLockAquisitionFailure_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
}
try { try {
db.upgradeSchema(); db.upgradeSchema();
} catch (EamDbException | SQLException | IncompatibleCentralRepoException ex) { } catch (EamDbException ex) {
LOGGER.log(Level.SEVERE, "Error updating central repository", ex); LOGGER.log(Level.SEVERE, "Error updating central repository", ex);
messageForDialog = Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(); throw new EamDbException("Error updating central repository", ex.getUserMessage() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
if (ex instanceof IncompatibleCentralRepoException) { } catch (SQLException ex) {
messageForDialog = ex.getMessage() + "\n\n" + messageForDialog; LOGGER.log(Level.SEVERE, "Error updating central repository", ex);
} else if (ex instanceof EamDbException) { throw new EamDbException("Error updating central repository", Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
messageForDialog = ex.getMessage() + Bundle.EamDbUtil_centralRepoDisabled_message(); } catch (IncompatibleCentralRepoException ex) {
} LOGGER.log(Level.SEVERE, "Error updating central repository", ex);
throw new EamDbException("Error updating central repository", ex.getMessage() + "\n\n" + Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
} finally { } finally {
if (lock != null) { if (lock != null) {
try { try {
@ -216,16 +224,11 @@ public class EamDbUtil {
} }
} }
} }
} catch (EamDbException ex) { } else {
LOGGER.log(Level.SEVERE, "Error updating central repository, unable to acquire exclusive lock", ex); throw new EamDbException("Unable to connect to database", Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message());
messageForDialog = Bundle.EamDbUtil_exclusiveLockAquisitionFailure_message() + Bundle.EamDbUtil_centralRepoDisabled_message();
} }
} catch (EamDbException ex) {
} else { // Disable the central repo and clear the current settings.
messageForDialog = Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message();
}
// Disable the central repo and clear the current settings.
if (!messageForDialog.isEmpty()) {
try { try {
if (null != EamDb.getInstance()) { if (null != EamDb.getInstance()) {
EamDb.getInstance().shutdownConnections(); EamDb.getInstance().shutdownConnections();
@ -235,8 +238,7 @@ public class EamDbUtil {
} }
EamDbPlatformEnum.setSelectedPlatform(EamDbPlatformEnum.DISABLED.name()); EamDbPlatformEnum.setSelectedPlatform(EamDbPlatformEnum.DISABLED.name());
EamDbPlatformEnum.saveSelectedPlatform(); EamDbPlatformEnum.saveSelectedPlatform();
throw ex;
throw new EamDbException(messageForDialog, messageForDialog);
} }
} }

View File

@ -76,7 +76,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
ingestStateUpdated(Case.isCaseOpen()); ingestStateUpdated(Case.isCaseOpen());
} }
@Messages({"GlobalSettingsPanel.updateFailed.title=Central repository upgrade failed"}) @Messages({"GlobalSettingsPanel.updateFailed.title=Central repository disabled"})
private void updateDatabase() { private void updateDatabase() {
if (EamDbPlatformEnum.getSelectedPlatform().equals(DISABLED)) { if (EamDbPlatformEnum.getSelectedPlatform().equals(DISABLED)) {
@ -90,7 +90,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
} catch (EamDbException ex) { } catch (EamDbException ex) {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
JOptionPane.showMessageDialog(this, JOptionPane.showMessageDialog(this,
ex.getMessage(), ex.getUserMessage(),
NbBundle.getMessage(this.getClass(), NbBundle.getMessage(this.getClass(),
"GlobalSettingsPanel.updateFailed.title"), "GlobalSettingsPanel.updateFailed.title"),
JOptionPane.WARNING_MESSAGE); JOptionPane.WARNING_MESSAGE);

View File

@ -18,7 +18,7 @@
*/ */
package org.sleuthkit.autopsy.exceptions; package org.sleuthkit.autopsy.exceptions;
public class AutopsyException extends Exception { public abstract class AutopsyException extends Exception {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;