19package org.sleuthkit.autopsy.centralrepository.datamodel;
21import java.beans.PropertyChangeListener;
22import java.beans.PropertyChangeSupport;
24import java.sql.SQLException;
25import java.util.logging.Level;
26import org.openide.util.NbBundle;
27import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings;
28import org.sleuthkit.autopsy.coordinationservice.CoordinationService;
29import org.sleuthkit.autopsy.core.UserPreferences;
30import org.sleuthkit.autopsy.coreutils.Logger;
31import org.sleuthkit.autopsy.coreutils.ModuleSettings;
77 if (clearDisabledDueToError) {
188 if (dbChoice.getSettingKey().equalsIgnoreCase(keyName)) {
208 logger.log(Level.SEVERE,
"Error updating central repository, unable to make connection", ex);
209 onUpgradeError(
"Error updating central repository, unable to make connection",
210 Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
231 return db.getExclusiveMultiUserDbLock();
234 logger.log(Level.SEVERE,
"Error updating central repository, unable to acquire exclusive lock", ex);
235 onUpgradeError(
"Error updating central repository, unable to acquire exclusive lock",
236 Bundle.EamDbUtil_exclusiveLockAquisitionFailure_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
255 logger.log(Level.SEVERE,
"Error updating central repository", ex);
257 }
catch (SQLException ex) {
258 logger.log(Level.SEVERE,
"Error updating central repository", ex);
260 Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
262 logger.log(Level.SEVERE,
"Error updating central repository", ex);
264 ex.getMessage() +
"\n\n" + Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
270 logger.log(Level.SEVERE,
"Error releasing database lock", ex);
281 @NbBundle.Messages(value = {
"EamDbUtil.centralRepoDisabled.message= The Central Repository has been disabled.",
"EamDbUtil.centralRepoUpgradeFailed.message=Failed to upgrade Central Repository.",
"EamDbUtil.centralRepoConnectionFailed.message=Unable to connect to Central Repository.",
"EamDbUtil.exclusiveLockAquisitionFailure.message=Unable to acquire exclusive lock for Central Repository."})
295 Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(),
null);
306 logger.log(Level.SEVERE,
"Error shutting down central repo connection pool", ex2);
309 if (innerException ==
null) {
404 throw new CentralRepoException(
"Unable to successfully create postgres database. Test failed with: " + curStatus);
466 if (selectedDbSettings ==
null) {
470 boolean result =
false;
471 boolean dbCreated =
true;
483 logger.log(Level.SEVERE,
"Unable to create database for central repository with settings " + selectedDbSettings, ex);
493 String schemaError =
"Unable to initialize database schema or insert contents into central repository.";
494 logger.severe(schemaError);
505 @NbBundle.Messages({
"CentralRepoDbManager.connectionErrorMsg.text=Failed to connect to central repository database."})
517 if (
null != previousDbManager) {
522 logger.log(Level.SEVERE,
"Failed to close database connections in previously selected platform.", ex);
540 logger.info(
"Saving central repo settings for db: " + selectedDbSettings);
544 logger.log(Level.SEVERE, Bundle.CentralRepoDbManager_connectionErrorMsg_text(), ex);
595 String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
throws CentralRepoException, NumberFormatException {
604 File databasePath =
new File(tfDatabasePath);
608 throw new IllegalStateException(
"Central Repo has an unknown selected platform: " +
selectedDbChoice);
623 if (manager !=
null) {
627 logger.log(Level.WARNING,
"unable to test status of db connection in central repo", e);
static CentralRepoSettings getInstance()
String getModuleSettingsKey()
static boolean isPostgresMultiuserAllowed()
void setupPostgresDb(CentralRepoDbChoice choice)
static CentralRepoDbChoice fromKey(String keyName)
static void removePropertyChangeListener(PropertyChangeListener listener)
static final Object dbChoiceLock
final SqliteCentralRepoSettings dbSettingsSqlite
boolean configurationChanged
static CoordinationService.Lock obtainCentralRepoLock(CentralRepository db)
final PostgresCentralRepoSettings dbSettingsMultiUser
PostgresCentralRepoSettings getDbSettingsPostgres()
static final PropertyChangeSupport propertyChangeSupport
void saveNewCentralRepo()
CentralRepoDbConnectivityManager getSelectedSettings()
static final String CENTRAL_REPOSITORY_SETTINGS_KEY
void setupDefaultSqliteDb()
static CentralRepoDbChoice getSavedDbChoice()
boolean wasConfigurationChanged()
PostgresCentralRepoSettings getDbSettingsMultiUser()
static final Logger logger
RdbmsCentralRepoFactory getDbFactory()
static void addPropertyChangeListener(PropertyChangeListener listener)
DatabaseTestResult getStatus()
boolean testDatabaseSettingsAreValid(String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
static void disableDueToFailure()
CentralRepoDbChoice selectedDbChoice
static final String DB_SELECTED_PLATFORM_KEY
CentralRepoDbChoice getSelectedDbChoice()
static boolean isDisabledDueToFailure()
final PostgresCentralRepoSettings dbSettingsPostgres
static void updatedDbSchema(CentralRepository db, CoordinationService.Lock lock)
DatabaseTestResult testStatus()
static void upgradeDatabase()
static final String CENTRAL_REPO_DB_NAME
void setSelctedDbChoice(CentralRepoDbChoice newSelected)
static void onUpgradeError(String message, String desc, Exception innerException)
static void setDisabledDueToFailure(boolean disabledDueToFailure)
static final String DISABLED_DUE_TO_FAILURE_KEY
static final Object disabledDueToFailureLock
DatabaseTestResult testingStatus
static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice, boolean clearDisabledDueToError)
static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice)
static volatile CentralRepoDbChoice savedChoice
static CentralRepository obtainCentralRepository()
SqliteCentralRepoSettings getDbSettingsSqlite()
static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected)
DatabaseTestResult testStatus()
boolean insertDefaultDatabaseContent()
boolean initializeDatabaseSchema()
static final String DEFAULT_DBNAME
static boolean getIsMultiUserModeEnabled()
synchronized static Logger getLogger(String name)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static synchronized String getConfigSetting(String moduleName, String settingName)
DatabaseTestResult testStatus()
boolean verifyDatabaseExists()
static CentralRepository getInstance()
void shutdownConnections()
static boolean isEnabled()
PostgresSettingsLoader MULTIUSER_SETTINGS_LOADER
PostgresSettingsLoader CUSTOM_SETTINGS_LOADER