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;
77 if (clearDisabledDueToError) {
84 savedChoice = newChoice;
86 propertyChangeSupport.firePropertyChange(
"savedChoice", oldChoice, newChoice);
116 if (savedChoice == null) {
118 savedChoice =
fromKey(selectedPlatformString);
148 propertyChangeSupport.firePropertyChange(
"disabledDueToFailure", oldValue, disabledDueToFailure);
174 propertyChangeSupport.addPropertyChangeListener(listener);
183 propertyChangeSupport.removePropertyChangeListener(listener);
188 if (dbChoice.getSettingKey().equalsIgnoreCase(keyName)) {
207 }
catch (CentralRepoException ex) {
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);
254 }
catch (CentralRepoException 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) {
379 throw new CentralRepoException(
"Unable to successfully create sqlite database");
395 selectedDbChoice = choice;
404 throw new CentralRepoException(
"Unable to successfully create postgres database. Test failed with: " + curStatus);
437 throw new CentralRepoException(
"Unknown database type: " + selectedDbChoice);
454 throw new CentralRepoException(
"Unknown database type: " + selectedDbChoice);
466 if (selectedDbSettings == null) {
467 throw new CentralRepoException(
"Unable to derive connectivity manager from settings: " + selectedDbChoice);
470 boolean result =
false;
471 boolean dbCreated =
true;
482 }
catch (CentralRepoException ex) {
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);
495 throw new CentralRepoException(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);
542 configurationChanged =
true;
544 logger.log(Level.SEVERE, Bundle.CentralRepoDbManager_connectionErrorMsg_text(), ex);
584 selectedDbChoice = newSelected;
595 String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
throws CentralRepoException, NumberFormatException {
598 dbSettingsPostgres.
setHost(tbDbHostname);
599 dbSettingsPostgres.
setPort(Integer.parseInt(tbDbPort));
600 dbSettingsPostgres.
setDbName(CENTRAL_REPO_DB_NAME);
604 File databasePath =
new File(tfDatabasePath);
608 throw new IllegalStateException(
"Central Repo has an unknown selected platform: " + selectedDbChoice);
623 if (manager != null) {
626 }
catch (CentralRepoException e) {
627 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()
String getModuleSettingsKey()
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 CentralRepoSettings getInstance()
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()