4556 allow upgrade failure message to indicate that CR is incompatable

This commit is contained in:
William Schaefer 2018-12-21 15:37:53 -05:00
parent 52c4aad251
commit b0a80f0260
7 changed files with 84 additions and 29 deletions

View File

@ -3171,7 +3171,7 @@ abstract class AbstractSqlEamDb implements EamDb {
* @throws EamDbException
*/
@Override
public void upgradeSchema() throws EamDbException, SQLException {
public void upgradeSchema() throws EamDbException, SQLException, IncompatibleCentralRepoException {
ResultSet resultSet = null;
Statement statement = null;
@ -3225,7 +3225,7 @@ abstract class AbstractSqlEamDb implements EamDb {
//we can not use the CaseDbSchemaVersionNumber.isCompatible method
//because it is specific to case db schema versions only supporting major versions greater than 1
if (SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() < dbSchemaVersion.getMajor()) {
throw new EamDbException("The selected Central Repository is not compatable with the current version of the application, please upgrade the application if you wish to use this Central Repository");
throw new IncompatibleCentralRepoException("The selected Central Repository is not compatable with the current version of the application, please upgrade the application if you wish to use this Central Repository");
}
if (dbSchemaVersion.equals(SOFTWARE_CR_DB_SCHEMA_VERSION)) {
logger.log(Level.INFO, "Central Repository is up to date");

View File

@ -710,7 +710,7 @@ public interface EamDb {
*
* @throws EamDbException
*/
public void upgradeSchema() throws EamDbException, SQLException;
public void upgradeSchema() throws EamDbException, SQLException, IncompatibleCentralRepoException;
/**
* Gets an exclusive lock (if applicable). Will return the lock if

View File

@ -25,6 +25,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.logging.Level;
import org.openide.util.NbBundle.Messages;
import org.sleuthkit.autopsy.coordinationservice.CoordinationService;
import org.sleuthkit.autopsy.coordinationservice.CoordinationService.CoordinationServiceException;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -172,9 +173,10 @@ public class EamDbUtil {
*
* @return true if the upgrade succeeds, false otherwise.
*/
public static boolean upgradeDatabase() {
@Messages({"EamDbUtil.centralRepoUpgradeFailed.message=Failed to upgrade central repository. It has been disabled."})
public static void upgradeDatabase() throws EamDbException {
if (!EamDb.isEnabled()) {
return true;
return;
}
CoordinationService.Lock lock = null;
@ -188,7 +190,7 @@ public class EamDbUtil {
db.upgradeSchema();
} catch (EamDbException | SQLException ex) {
} catch (EamDbException | SQLException | IncompatibleCentralRepoException ex) {
LOGGER.log(Level.SEVERE, "Error updating central repository", ex);
// Disable the central repo and clear the current settings.
@ -196,15 +198,18 @@ public class EamDbUtil {
if (null != EamDb.getInstance()) {
EamDb.getInstance().shutdownConnections();
}
} catch (EamDbException ex2) {
} catch (EamDbException ignored) {
LOGGER.log(Level.SEVERE, "Error shutting down central repo connection pool", ex);
}
setUseCentralRepo(false);
EamDbPlatformEnum.setSelectedPlatform(EamDbPlatformEnum.DISABLED.name());
EamDbPlatformEnum.saveSelectedPlatform();
return false;
String messageForDialog = Bundle.EamDbUtil_centralRepoUpgradeFailed_message();
if (ex instanceof IncompatibleCentralRepoException) {
messageForDialog = ex.getMessage() + "\n\n" + messageForDialog;
}
throw new EamDbException(messageForDialog);
} finally {
if (lock != null) {
try {
@ -214,7 +219,6 @@ public class EamDbUtil {
}
}
}
return true;
}
/**

View File

@ -0,0 +1,53 @@
/*
*
* Autopsy Forensic Browser
*
* Copyright 2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.autopsy.centralrepository.datamodel;
/**
* Exception to denote that the Central Repo is not compatable with the current version of the software.
*/
public class IncompatibleCentralRepoException extends Exception {
private static final long serialVersionUID = 1L;
/**
* Construct an exception with the given message.
* @param message error message
*/
public IncompatibleCentralRepoException(String message){
super(message);
}
/**
* Construct an exception with the given message and inner exception.
* @param message error message
* @param cause inner exception
*/
public IncompatibleCentralRepoException(String message, Throwable cause){
super(message, cause);
}
/**
* Construct an exception with the given inner exception.
* @param cause inner exception
*/
public IncompatibleCentralRepoException(Throwable cause){
super(cause);
}
}

View File

@ -1118,7 +1118,7 @@ final class SqliteEamDb extends AbstractSqlEamDb {
* @throws EamDbException
*/
@Override
public void upgradeSchema() throws EamDbException, SQLException {
public void upgradeSchema() throws EamDbException, SQLException, IncompatibleCentralRepoException {
try {
acquireExclusiveLock();
super.upgradeSchema();

View File

@ -23,6 +23,7 @@ import org.openide.modules.ModuleInstall;
import org.openide.util.NbBundle;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -50,21 +51,20 @@ public class Installer extends ModuleInstall {
super();
}
@NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository upgrade failed",
"Installer.centralRepoUpgradeFailed.message=Failed to upgrade central repository. It has been disabled."
})
@NbBundle.Messages({"Installer.centralRepoUpgradeFailed.title=Central repository upgrade failed"})
@Override
public void restored() {
Case.addPropertyChangeListener(pcl);
ieListener.installListeners();
// Perform the database upgrade and inform the user if it fails
if (!EamDbUtil.upgradeDatabase()) {
try {
EamDbUtil.upgradeDatabase();
} catch (EamDbException ex) {
if (RuntimeProperties.runningWithGUI()) {
WindowManager.getDefault().invokeWhenUIReady(() -> {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(),
"Installer.centralRepoUpgradeFailed.message"),
ex.getMessage(),
NbBundle.getMessage(this.getClass(),
"Installer.centralRepoUpgradeFailed.title"),
JOptionPane.ERROR_MESSAGE);

View File

@ -30,6 +30,7 @@ import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
import org.sleuthkit.autopsy.corecomponents.OptionsPanel;
import org.sleuthkit.autopsy.events.AutopsyEvent;
import org.sleuthkit.autopsy.ingest.IngestManager;
@ -75,9 +76,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
ingestStateUpdated(Case.isCaseOpen());
}
@Messages({"GlobalSettingsPanel.updateFailed.title=Update failed",
"GlobalSettingsPanel.updateFailed.message=Failed to update database. Central repository has been disabled."
})
@Messages({"GlobalSettingsPanel.updateFailed.title=Central repository upgrade failed"})
private void updateDatabase() {
if (EamDbPlatformEnum.getSelectedPlatform().equals(DISABLED)) {
@ -86,16 +85,15 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
boolean result = EamDbUtil.upgradeDatabase();
EamDbUtil.upgradeDatabase();
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
if (!result) {
JOptionPane.showMessageDialog(this,
NbBundle.getMessage(this.getClass(),
"GlobalSettingsPanel.updateFailed.message"),
NbBundle.getMessage(this.getClass(),
"GlobalSettingsPanel.updateFailed.title"),
JOptionPane.WARNING_MESSAGE);
}
} catch (EamDbException ex) {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
JOptionPane.showMessageDialog(this,
ex.getMessage(),
NbBundle.getMessage(this.getClass(),
"GlobalSettingsPanel.updateFailed.title"),
JOptionPane.WARNING_MESSAGE);
} finally {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}