19 package org.sleuthkit.autopsy.centralrepository.datamodel;
21 import java.beans.PropertyChangeListener;
22 import java.beans.PropertyChangeSupport;
24 import java.sql.SQLException;
25 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
76 if (clearDisabledDueToError) {
83 savedChoice = newChoice;
85 propertyChangeSupport.firePropertyChange(
"savedChoice", oldChoice, newChoice);
115 if (savedChoice == null) {
117 savedChoice =
fromKey(selectedPlatformString);
147 propertyChangeSupport.firePropertyChange(
"disabledDueToFailure", oldValue, disabledDueToFailure);
173 propertyChangeSupport.addPropertyChangeListener(listener);
182 propertyChangeSupport.removePropertyChangeListener(listener);
187 if (dbChoice.getSettingKey().equalsIgnoreCase(keyName)) {
206 }
catch (CentralRepoException ex) {
207 logger.log(Level.SEVERE,
"Error updating central repository, unable to make connection", ex);
208 onUpgradeError(
"Error updating central repository, unable to make connection",
209 Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
230 return db.getExclusiveMultiUserDbLock();
233 logger.log(Level.SEVERE,
"Error updating central repository, unable to acquire exclusive lock", ex);
234 onUpgradeError(
"Error updating central repository, unable to acquire exclusive lock",
235 Bundle.EamDbUtil_exclusiveLockAquisitionFailure_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
253 }
catch (CentralRepoException ex) {
254 logger.log(Level.SEVERE,
"Error updating central repository", ex);
256 }
catch (SQLException ex) {
257 logger.log(Level.SEVERE,
"Error updating central repository", ex);
259 Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
261 logger.log(Level.SEVERE,
"Error updating central repository", ex);
263 ex.getMessage() +
"\n\n" + Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
269 logger.log(Level.SEVERE,
"Error releasing database lock", ex);
280 @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."})
294 Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), null);
305 logger.log(Level.SEVERE,
"Error shutting down central repo connection pool", ex2);
308 if (innerException == null) {
378 throw new CentralRepoException(
"Unable to successfully create sqlite database");
394 selectedDbChoice = choice;
403 throw new CentralRepoException(
"Unable to successfully create postgres database. Test failed with: " + curStatus);
436 throw new CentralRepoException(
"Unknown database type: " + selectedDbChoice);
453 throw new CentralRepoException(
"Unknown database type: " + selectedDbChoice);
465 if (selectedDbSettings == null) {
466 throw new CentralRepoException(
"Unable to derive connectivity manager from settings: " + selectedDbChoice);
469 boolean result =
false;
470 boolean dbCreated =
true;
481 }
catch (CentralRepoException ex) {
482 logger.log(Level.SEVERE,
"Unable to create database for central repository with settings " + selectedDbSettings, ex);
492 String schemaError =
"Unable to initialize database schema or insert contents into central repository.";
493 logger.severe(schemaError);
494 throw new CentralRepoException(schemaError);
504 @NbBundle.Messages({
"CentralRepoDbManager.connectionErrorMsg.text=Failed to connect to central repository database."})
516 if (null != previousDbManager) {
521 logger.log(Level.SEVERE,
"Failed to close database connections in previously selected platform.", ex);
539 logger.info(
"Saving central repo settings for db: " + selectedDbSettings);
541 configurationChanged =
true;
543 logger.log(Level.SEVERE, Bundle.CentralRepoDbManager_connectionErrorMsg_text(), ex);
583 selectedDbChoice = newSelected;
594 String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
throws CentralRepoException, NumberFormatException {
597 dbSettingsPostgres.
setHost(tbDbHostname);
598 dbSettingsPostgres.
setPort(Integer.parseInt(tbDbPort));
599 dbSettingsPostgres.
setDbName(CENTRAL_REPO_DB_NAME);
603 File databasePath =
new File(tfDatabasePath);
607 throw new IllegalStateException(
"Central Repo has an unknown selected platform: " + selectedDbChoice);
622 if (manager != null) {
625 }
catch (CentralRepoException e) {
626 logger.log(Level.WARNING,
"unable to test status of db connection in central repo", e);
final SqliteCentralRepoSettings dbSettingsSqlite
static synchronized String getConfigSetting(String moduleName, String settingName)
DatabaseTestResult getStatus()
DatabaseTestResult testStatus()
void setupDefaultSqliteDb()
static void removePropertyChangeListener(PropertyChangeListener listener)
static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice, boolean clearDisabledDueToError)
static final Object disabledDueToFailureLock
boolean insertDefaultDatabaseContent()
CentralRepoDbConnectivityManager getSelectedSettings()
PostgresCentralRepoSettings getDbSettingsMultiUser()
static void onUpgradeError(String message, String desc, Exception innerException)
SqliteCentralRepoSettings getDbSettingsSqlite()
static volatile CentralRepoDbChoice savedChoice
void setUserName(String userName)
DatabaseTestResult testingStatus
static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected)
static final String CENTRAL_REPOSITORY_SETTINGS_KEY
static CentralRepoDbChoice fromKey(String keyName)
static void upgradeDatabase()
static CentralRepoDbChoice getSavedDbChoice()
static boolean getIsMultiUserModeEnabled()
static boolean isPostgresMultiuserAllowed()
static final String DISABLED_DUE_TO_FAILURE_KEY
PostgresSettingsLoader MULTIUSER_SETTINGS_LOADER
static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice)
PostgresSettingsLoader CUSTOM_SETTINGS_LOADER
void saveNewCentralRepo()
static void disableDueToFailure()
static final String DB_SELECTED_PLATFORM_KEY
static boolean isDisabledDueToFailure()
static final String CENTRAL_REPO_DB_NAME
static CoordinationService.Lock obtainCentralRepoLock(CentralRepository db)
void setDbName(String dbName)
boolean testDatabaseSettingsAreValid(String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
DatabaseTestResult testStatus()
void setupDefaultSettings()
void setPassword(String password)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
void setHost(String host)
void shutdownConnections()
static CentralRepository obtainCentralRepository()
final PostgresCentralRepoSettings dbSettingsPostgres
CentralRepoDbChoice getSelectedDbChoice()
PostgresCentralRepoSettings getDbSettingsPostgres()
boolean wasConfigurationChanged()
static void addPropertyChangeListener(PropertyChangeListener listener)
void setDbDirectory(String dbDirectory)
static void updatedDbSchema(CentralRepository db, CoordinationService.Lock lock)
boolean verifyDatabaseExists()
final PostgresCentralRepoSettings dbSettingsMultiUser
DatabaseTestResult testStatus()
synchronized static Logger getLogger(String name)
void setDbName(String dbName)
CentralRepoDbChoice selectedDbChoice
static final Object dbChoiceLock
boolean initializeDatabaseSchema()
static void setDisabledDueToFailure(boolean disabledDueToFailure)
static final String DEFAULT_DBNAME
void setSelctedDbChoice(CentralRepoDbChoice newSelected)
static CentralRepository getInstance()
boolean configurationChanged
static final PropertyChangeSupport propertyChangeSupport
void setupPostgresDb(CentralRepoDbChoice choice)
RdbmsCentralRepoFactory getDbFactory()
static final Logger logger
static boolean isEnabled()