/// <summary> /// Stops an application. /// </summary> public void Stop() { //first check if the application is all finished IManagerStorage store = ManagerStorageFactory.ManagerStorage(); ApplicationStorageView app = store.GetApplication(_Id); if (app.State != ApplicationState.Stopped) { ThreadStorageView[] threads = store.GetThreads(_Id); foreach (ThreadStorageView thread in threads) { if (thread.State != ThreadState.Dead && thread.State != ThreadState.Finished) { GManager.AbortThread(new ThreadIdentifier(_Id, thread.ThreadId), thread.ExecutorId); // clean up the thread status thread.State = ThreadState.Dead; store.UpdateThread(thread); } } //update the application app.State = ApplicationState.Stopped; app.TimeCompleted = DateTime.Now; store.UpdateApplication(app); logger.Debug("Stopped the current application." + _Id); } else { logger.Debug(string.Format("Application {0} already stopped.", _Id)); } }
/// <summary> /// Remove all executors from storage. /// /// </summary> /// <remarks> /// Q: What to do with applications that have running threads on any of the executors? /// A: This is a storage level function so we cannot stop the applications on the executors from here. /// </remarks> /// <param name="storage">Target storage where this maintanance will be performed.</param> public void RemoveAllExecutors(IManagerStorage storage) { ExecutorStorageView[] executors = storage.GetExecutors(); foreach (ExecutorStorageView executor in executors) { storage.DeleteExecutor(executor); } }
/// <summary> /// Remove all applications from storage. /// </summary> /// <param name="storage">Target storage where this maintanance will be performed.</param> public void RemoveAllApplications(IManagerStorage storage) { ApplicationStorageView[] applications = storage.GetApplications(); foreach (ApplicationStorageView application in applications) { storage.DeleteApplication(application); } }
/// <summary> /// Create the default objects to complete initializing the manager storage. /// </summary> /// <param name="managerStorage"></param> protected void CreateDefaultObjects(IManagerStorage managerStorage) { // create default groups ArrayList defaultGroups = new ArrayList(); GroupStorageView newGroup; newGroup = new GroupStorageView(c_AdminsGroupId, "Administrators"); newGroup.Description = "Administrators Group"; newGroup.IsSystem = true; defaultGroups.Add(newGroup); newGroup = new GroupStorageView(c_ExecutorsGroupId, "Executors"); newGroup.Description = "Executors Group"; newGroup.IsSystem = true; defaultGroups.Add(newGroup); newGroup = new GroupStorageView(c_UsersGroupId, "Users"); newGroup.Description = "Users Group"; newGroup.IsSystem = true; defaultGroups.Add(newGroup); managerStorage.AddGroups((GroupStorageView[])defaultGroups.ToArray(typeof(GroupStorageView))); // set default permissions //permissions for admins group managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ExecuteThread); managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ManageOwnApp); managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ManageAllApps); managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ManageUsers); //permissions for executors group managerStorage.AddGroupPermission(c_ExecutorsGroupId, Permission.ExecuteThread); //permissions for users group managerStorage.AddGroupPermission(c_UsersGroupId, Permission.ManageOwnApp); // create default users ArrayList defaultUsers = new ArrayList(); UserStorageView newUser; newUser = new UserStorageView("admin", "admin", c_AdminsGroupId); newUser.IsSystem = true; defaultUsers.Add(newUser); newUser = new UserStorageView("executor", "executor", c_ExecutorsGroupId); newUser.IsSystem = true; defaultUsers.Add(newUser); newUser = new UserStorageView("user", "user", c_UsersGroupId); newUser.IsSystem = true; defaultUsers.Add(newUser); managerStorage.AddUsers((UserStorageView[])defaultUsers.ToArray(typeof(UserStorageView))); }
/// <summary> /// Create the default objects to complete initializing the manager storage. /// </summary> /// <param name="managerStorage"></param> protected void CreateDefaultObjects(IManagerStorage managerStorage) { // create default groups ArrayList defaultGroups = new ArrayList(); GroupStorageView newGroup; newGroup = new GroupStorageView(c_AdminsGroupId, "Administrators"); newGroup.Description = "Administrators Group"; newGroup.IsSystem = true; defaultGroups.Add(newGroup); newGroup = new GroupStorageView(c_ExecutorsGroupId, "Executors"); newGroup.Description = "Executors Group"; newGroup.IsSystem = true; defaultGroups.Add(newGroup); newGroup = new GroupStorageView(c_UsersGroupId, "Users"); newGroup.Description = "Users Group"; newGroup.IsSystem = true; defaultGroups.Add(newGroup); managerStorage.AddGroups((GroupStorageView[])defaultGroups.ToArray(typeof(GroupStorageView))); // set default permissions //permissions for admins group managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ExecuteThread); managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ManageOwnApp); managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ManageAllApps); managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ManageUsers); //permissions for executors group managerStorage.AddGroupPermission(c_ExecutorsGroupId, Permission.ExecuteThread); //permissions for users group managerStorage.AddGroupPermission(c_UsersGroupId, Permission.ManageOwnApp); // create default users ArrayList defaultUsers = new ArrayList(); UserStorageView newUser; newUser = new UserStorageView("admin", "admin", c_AdminsGroupId); newUser.IsSystem = true; defaultUsers.Add(newUser); newUser = new UserStorageView("executor", "executor", c_ExecutorsGroupId); newUser.IsSystem = true; defaultUsers.Add(newUser); newUser = new UserStorageView("user", "user", c_UsersGroupId); newUser.IsSystem = true; defaultUsers.Add(newUser); managerStorage.AddUsers((UserStorageView[])defaultUsers.ToArray(typeof(UserStorageView))); }
/// <summary> /// Remove all applications that were submitted before the given cut-off date. /// </summary> /// <param name="storage">Target storage where this maintanance will be performed.</param> /// <param name="timeCreatedCutOff"></param> public void RemoveApplications(IManagerStorage storage, DateTime timeCreatedCutOff) { ApplicationStorageView[] applications = storage.GetApplications(); foreach (ApplicationStorageView application in applications) { if (application.TimeCreated < timeCreatedCutOff) { storage.DeleteApplication(application); } } }
/// <summary> /// Remove all executors that have not been pinged since the given time. /// </summary> /// <param name="storage">Target storage where this maintanance will be performed.</param> /// <param name="pingTimeCutOff"></param> public void RemoveExecutors(IManagerStorage storage, DateTime pingTimeCutOff) { ExecutorStorageView[] executors = storage.GetExecutors(); foreach (ExecutorStorageView executor in executors) { if (executor.PingTime < pingTimeCutOff) { storage.DeleteExecutor(executor); } } }
/// <summary> /// Remove applications that have the given application state /// This will also remove the threads associated with these applications /// </summary> /// <param name="storage">Target storage where this maintanance will be performed.</param> /// <param name="applicationStates"></param> public void RemoveApplications(IManagerStorage storage, params ApplicationState[] applicationStates) { if (applicationStates == null || applicationStates.Length == 0) { return; } ApplicationStorageView[] applications = storage.GetApplications(); foreach (ApplicationStorageView application in applications) { int stateIndex; stateIndex = Array.IndexOf <ApplicationState>(applicationStates, application.State); if (stateIndex >= 0) { storage.DeleteApplication(application); } } }
/// <summary> /// Perform various maintenance actions as defined in the maintenance parameters. /// </summary> /// <param name="storage"></param> /// <param name="maintenanceParameters"></param> public void PerformMaintenance(IManagerStorage storage, StorageMaintenanceParameters maintenanceParameters) { RemoveApplications(storage, maintenanceParameters.ApplicationStatesToRemove); if (maintenanceParameters.RemoveAllApplications) { RemoveAllApplications(storage); } if (maintenanceParameters.RemoveAllExecutors) { RemoveAllExecutors(storage); } if (maintenanceParameters.ApplicationTimeCreatedCutOffSet) { RemoveApplications(storage, maintenanceParameters.ApplicationTimeCreatedCutOff); } if (maintenanceParameters.ExecutorPingTimeCutOffSet) { RemoveExecutors(storage, maintenanceParameters.ExecutorPingTimeCutOff); } if (maintenanceParameters.ApplicationTimeCompletedCutOffSet) { DateTime timeCompletedCutOff = DateTime.Now.Subtract(maintenanceParameters.ApplicationTimeCompletedCutOff); ApplicationStorageView[] applications = storage.GetApplications(); foreach (ApplicationStorageView application in applications) { if (application.TimeCompletedSet && application.TimeCompleted < timeCompletedCutOff) { storage.DeleteApplication(application); } } } }
/// <summary> /// Perform various maintenance actions as defined in the maintenance parameters. /// </summary> /// <param name="storage"></param> /// <param name="maintenanceParameters"></param> public void PerformMaintenance(IManagerStorage storage, StorageMaintenanceParameters maintenanceParameters) { RemoveApplications(storage, maintenanceParameters.ApplicationStatesToRemove); if (maintenanceParameters.RemoveAllApplications) { RemoveAllApplications(storage); } if (maintenanceParameters.RemoveAllExecutors) { RemoveAllExecutors(storage); } if (maintenanceParameters.ApplicationTimeCreatedCutOffSet) { RemoveApplications(storage, maintenanceParameters.ApplicationTimeCreatedCutOff); } if (maintenanceParameters.ExecutorPingTimeCutOffSet) { RemoveExecutors(storage, maintenanceParameters.ExecutorPingTimeCutOff); } if (maintenanceParameters.ApplicationTimeCompletedCutOffSet) { DateTime timeCompletedCutOff = DateTime.Now.Subtract(maintenanceParameters.ApplicationTimeCompletedCutOff); ApplicationStorageView[] applications = storage.GetApplications(); foreach (ApplicationStorageView application in applications) { if (application.TimeCompletedSet && application.TimeCompleted < timeCompletedCutOff) { storage.DeleteApplication(application); } } } }
/// <summary> /// Verify if the database is properly set up. /// /// </summary> /// <param name="id">application id</param> /// <returns>true if the application is set up in the database</returns> public bool VerifyApp(string id) { IManagerStorage store = ManagerStorageFactory.ManagerStorage(); bool appSetup = true; //create directory can be repeated, and wont throw an error even if the dir already exists. this[id].CreateDataDirectory(); ApplicationStorageView application = store.GetApplication(id); if (application == null) { appSetup = false; } else { //just make sure the status is set to ready, or else it may remain Stopped //in case of re-started multi-use apps. application.State = ApplicationState.Ready; store.UpdateApplication(application); } return(appSetup); }
/// <summary> /// Default constructor required by scheduler factory. /// </summary> public DefaultScheduler() { store = ManagerStorageFactory.ManagerStorage(); }
/// <summary> /// Create the right manager storage object based on the storage type in the configuration file. /// </summary> /// <param name="config"></param> /// <param name="overwriteDefaultDatabase">Specify if the default catalog is set to the database name in the config file.</param> /// <returns></returns> public static IManagerStorage CreateManagerStorage(Configuration config, bool overwriteDefaultDatabase) { Configuration configuration = config; if (configuration==null) { configuration = Configuration.GetConfiguration(); } string sqlConnStr; switch(configuration.DbType) { case ManagerStorageEnum.SqlServer: if (overwriteDefaultDatabase) { // build sql server configuration string sqlConnStr = string.Format( "user id={1};password={2};initial catalog={3};data source={0};Connect Timeout=5; Max Pool Size=5; Min Pool Size=5", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbName ); } else { sqlConnStr = string.Format( "user id={1};password={2};data source={0};Connect Timeout=5; Max Pool Size=5; Min Pool Size=5", configuration.DbServer, configuration.DbUsername, configuration.DbPassword ); } m_managerStorage = new SqlServerManagerDatabaseStorage(sqlConnStr); break; case ManagerStorageEnum.MySql: if (overwriteDefaultDatabase) { // build sql server configuration string sqlConnStr = string.Format( "user id={1};password={2};database={3};data source={0};Connect Timeout=5; Max Pool Size=5; Min Pool Size=5", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbName ); } else { sqlConnStr = string.Format( "user id={1};password={2};data source={0};Connect Timeout=5; Max Pool Size=5; Min Pool Size=5", configuration.DbServer, configuration.DbUsername, configuration.DbPassword ); } m_managerStorage = new MySqlManagerDatabaseStorage(sqlConnStr); break; case ManagerStorageEnum.InMemory: /// in memory storage is volatile so we always return the same object if (m_managerStorage == null) { lock (m_inMemoryManagerStorageLock) { // make sure that when we got the lock we are still uninitialized if (m_managerStorage == null) { InMemoryManagerStorage inMemoryStorage = new InMemoryManagerStorage(); // volatile storage, we must initialize the data here inMemoryStorage.InitializeStorageData(); m_managerStorage = inMemoryStorage; } } } break; default: throw new ConfigurationException(String.Format("Unknown storage type: {0}", configuration.DbType)); } return m_managerStorage; }
private void btInstall_Click(object sender, EventArgs e) { //instead of the old method, just use the ManagerStorageSetup members now. Alchemi.Manager.Configuration config = null; try { // serialize configuration Log("[ Creating Configuration File ] ... "); config = new Alchemi.Manager.Configuration(InstallLocation); config.DbServer = txServer.Text; config.DbUsername = txUsername.Text; config.DbPassword = txAdminPwd.Text; config.DbName = "master"; //we need this to initially create the alchemi database. config.Slz(); Log("[ Done ]."); //for now just use RunSQL method. ManagerStorageFactory.CreateManagerStorage(config); IManagerStorage store = ManagerStorageFactory.ManagerStorage(); // (re)create database Log("[ Setting up storage ] ... "); string scriptPath = Path.Combine(scriptLocation, "Alchemi_database.sql"); while (!File.Exists(scriptPath)) { MessageBox.Show("Alchemi SQL files not found in folder: " + scriptLocation + ". Please select the folder where the sql scripts are located!", "Locate Script Files", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DialogResult result = dirBox.ShowDialog(this); if (result == DialogResult.Cancel) { break; } scriptLocation = dirBox.SelectedPath; scriptPath = Path.Combine(scriptLocation, "Alchemi_database.sql"); } if (!File.Exists(scriptPath)) { return; //cannot continue. } // create structure Log("[ Creating Database Structure ] ... "); //load it from sql files for now. later make use of resources. using (FileStream fs = File.OpenRead(scriptPath)) { StreamReader sr = new StreamReader(fs); String sql = sr.ReadToEnd(); sr.Close(); fs.Close(); store.RunSql(sql); } Log("[ Done ]."); Log("[ Creating tables ] ... "); scriptPath = Path.Combine(scriptLocation, "Alchemi_structure.sql"); //load it from sql files for now. later make use of resources. using (FileStream fs = File.OpenRead(scriptPath)) { StreamReader sr = new StreamReader(fs); String sql = sr.ReadToEnd(); sr.Close(); fs.Close(); store.RunSql(sql); } Log("[ Done ]."); Log("[ Inserting initialization data ] ... "); scriptPath = Path.Combine(scriptLocation, "Alchemi_data.sql"); //load it from sql files for now. later make use of resources. using (FileStream fs = File.OpenRead(scriptPath)) { StreamReader sr = new StreamReader(fs); String sql = sr.ReadToEnd(); sr.Close(); fs.Close(); store.RunSql(sql); } Log("[ Done ]."); // serialize configuration Log("[ Updating Configuration File ] ... "); config.DbServer = txServer.Text; config.DbUsername = txUsername.Text; config.DbPassword = txAdminPwd.Text; config.DbName = "Alchemi"; config.Slz(); Log("[ Done ]."); Log("Wrote configuration file to " + InstallLocation); Log("[ Installation Complete! ]"); btInstall.Enabled = false; btFinish.Enabled = true; } catch (Exception ex) { Log("[ Error ]"); Log(ex.Message); return; } }
/// <summary> /// Create the right manager storage object based on the storage type in the configuration file. /// </summary> /// <param name="config"></param> /// <param name="overwriteDefaultDatabase">Specify if the default catalog is set to the database name in the config file.</param> /// <returns></returns> public static IManagerStorage CreateManagerStorage(Configuration config, bool overwriteDefaultDatabase) { Configuration configuration = config; if (configuration == null) { configuration = Configuration.GetConfiguration(); } string sqlConnStr; switch (configuration.DbType) { case ManagerStorageEnum.SqlServer: if (overwriteDefaultDatabase) { // build sql server configuration string sqlConnStr = string.Format( "user id={1};password={2};initial catalog={3};data source={0};Connect Timeout=5; Max Pool Size=5; Min Pool Size=5", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbName ); } else { sqlConnStr = string.Format( "user id={1};password={2};data source={0};Connect Timeout=5; Max Pool Size=5; Min Pool Size=5", configuration.DbServer, configuration.DbUsername, configuration.DbPassword ); } m_managerStorage = new SqlServerManagerDatabaseStorage(sqlConnStr); break; case ManagerStorageEnum.MySql: if (overwriteDefaultDatabase) { // build sql server configuration string sqlConnStr = string.Format( "user id={1};password={2};database={3};data source={0};Connect Timeout=5; Max Pool Size=5; Min Pool Size=5", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbName ); } else { sqlConnStr = string.Format( "user id={1};password={2};data source={0};Connect Timeout=5; Max Pool Size=5; Min Pool Size=5", configuration.DbServer, configuration.DbUsername, configuration.DbPassword ); } m_managerStorage = new MySqlManagerDatabaseStorage(sqlConnStr); break; case ManagerStorageEnum.InMemory: /// in memory storage is volatile so we always return the same object if (m_managerStorage == null) { lock (m_inMemoryManagerStorageLock) { // make sure that when we got the lock we are still uninitialized if (m_managerStorage == null) { InMemoryManagerStorage inMemoryStorage = new InMemoryManagerStorage(); // volatile storage, we must initialize the data here inMemoryStorage.InitializeStorageData(); m_managerStorage = inMemoryStorage; } } } break; default: throw new ConfigurationException(String.Format("Unknown storage type: {0}", configuration.DbType)); } return(m_managerStorage); }
/// <summary> /// Remove all applications that were submitted before the given cut-off date. /// </summary> /// <param name="storage">Target storage where this maintanance will be performed.</param> /// <param name="timeCreatedCutOff"></param> public void RemoveApplications(IManagerStorage storage, DateTime timeCreatedCutOff) { ApplicationStorageView[] applications = storage.GetApplications(); foreach (ApplicationStorageView application in applications) { if (application.TimeCreated < timeCreatedCutOff) { storage.DeleteApplication(application); } } }
/// <summary> /// Remove all executors that have not been pinged since the given time. /// </summary> /// <param name="storage">Target storage where this maintanance will be performed.</param> /// <param name="pingTimeCutOff"></param> public void RemoveExecutors(IManagerStorage storage, DateTime pingTimeCutOff) { ExecutorStorageView[] executors = storage.GetExecutors(); foreach (ExecutorStorageView executor in executors) { if (executor.PingTime < pingTimeCutOff) { storage.DeleteExecutor(executor); } } }
/// <summary> /// Set the manager storage. /// Used to control the current storage from the caller. /// </summary> /// <param name="managerStorage"></param> public static void SetManagerStorage(IManagerStorage managerStorage) { _managerStorage = managerStorage; }
/// <summary> /// Remove all executors that have not been pinged in the given time span /// </summary> /// <param name="storage"></param> /// <param name="cutOff"></param> public void RemoveExecutors(IManagerStorage storage, TimeSpan cutOff) { DateTime pingTimeCutOff = DateTime.Now.Subtract(cutOff); RemoveExecutors(storage, pingTimeCutOff); }
/// <summary> /// Remove all executors from storage. /// /// </summary> /// <remarks> /// Q: What to do with applications that have running threads on any of the executors? /// A: This is a storage level function so we cannot stop the applications on the executors from here. /// </remarks> /// <param name="storage">Target storage where this maintanance will be performed.</param> public void RemoveAllExecutors(IManagerStorage storage) { ExecutorStorageView[] executors = storage.GetExecutors(); foreach (ExecutorStorageView executor in executors) { storage.DeleteExecutor(executor); } }
/// <summary> /// Default constructor required by scheduler factory. /// </summary> public DefaultScheduler() { store = ManagerStorageFactory.ManagerStorage(); }
/// <summary> /// Remove applications that have the given application state /// This will also remove the threads associated with these applications /// </summary> /// <param name="storage">Target storage where this maintanance will be performed.</param> /// <param name="applicationStates"></param> public void RemoveApplications(IManagerStorage storage, params ApplicationState[] applicationStates) { if (applicationStates == null || applicationStates.Length == 0) { return; } ApplicationStorageView[] applications = storage.GetApplications(); foreach (ApplicationStorageView application in applications) { int stateIndex; stateIndex = Array.IndexOf<ApplicationState>(applicationStates, application.State); if (stateIndex >= 0) { storage.DeleteApplication(application); } } }
/// <summary> /// Set the manager storage. /// Used to control the current storage from the caller. /// </summary> /// <param name="managerStorage"></param> public static void SetManagerStorage(IManagerStorage managerStorage) { m_managerStorage = managerStorage; }
/// <summary> /// Remove all applications what were submitted before the given time span /// </summary> /// <param name="storage"></param> /// <param name="cutOff"></param> public void RemoveApplications(IManagerStorage storage, TimeSpan cutOff) { DateTime timeCreatedCutOff = DateTime.Now.Subtract(cutOff); RemoveApplications(storage, timeCreatedCutOff); }
/// <summary> /// Create the right manager storage object based on the storage type in the configuration file. /// </summary> /// <param name="config"></param> /// <param name="overwriteDefaultDatabase">Specify if the default catalog is set to the database name in the config file.</param> /// <returns></returns> public static IManagerStorage CreateManagerStorage(Configuration config, bool overwriteDefaultDatabase) { Configuration configuration = config; if (configuration==null) { configuration = Configuration.GetConfiguration(); } string sqlConnStr; switch(configuration.DbType) { case ManagerStorageEnum.SqlServer: if (overwriteDefaultDatabase) { // build sql server configuration string sqlConnStr = string.Format( "user id={1};password={2};initial catalog={3};data source={0};Connect Timeout={4}; Max Pool Size={5}; Min Pool Size={6}", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbName, configuration.DbConnectTimeout, configuration.DbMaxPoolSize, configuration.DbMinPoolSize ); } else { sqlConnStr = string.Format( "user id={1};password={2};data source={0};Connect Timeout={3}; Max Pool Size={4}; Min Pool Size={5}", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbConnectTimeout, configuration.DbMaxPoolSize, configuration.DbMinPoolSize ); } _managerStorage = new SqlServerManagerDatabaseStorage(sqlConnStr); break; case ManagerStorageEnum.MySql: if (overwriteDefaultDatabase) { // build sql server configuration string sqlConnStr = string.Format( "user id={1};password={2};database={3};data source={0};Connect Timeout={4}; Max Pool Size={5}; Min Pool Size={6}", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbName, configuration.DbConnectTimeout, configuration.DbMaxPoolSize, configuration.DbMinPoolSize ); } else { sqlConnStr = string.Format( "user id={1};password={2};data source={0};Connect Timeout={3}; Max Pool Size={4}; Min Pool Size={5}", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbConnectTimeout, configuration.DbMaxPoolSize, configuration.DbMinPoolSize ); } _managerStorage = new MySqlManagerDatabaseStorage(sqlConnStr); break; case ManagerStorageEnum.Postgresql: if (overwriteDefaultDatabase) { // build configuration string sqlConnStr = string.Format( "user id={1};password={2};database={3};port=5432;server={0};Connect Timeout={4}; Max Pool Size={5}; Min Pool Size={6}", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbName, configuration.DbConnectTimeout, configuration.DbMaxPoolSize, configuration.DbMinPoolSize ); } else { sqlConnStr = string.Format( "user id={1};password={2};database=postgres;server={0};port=5432;Connect Timeout={3}; Max Pool Size={4}; Min Pool Size={5}", configuration.DbServer, configuration.DbUsername, configuration.DbPassword, configuration.DbConnectTimeout, configuration.DbMaxPoolSize, configuration.DbMinPoolSize ); } _managerStorage = new PostgresqlManagerDatabaseStorage(sqlConnStr); break; case ManagerStorageEnum.db4o: if (_managerStorage == null) { lock (_inMemoryManagerStorageLock) { // make sure that when we got the lock we are still uninitialized if (_managerStorage == null) { db4oManagerStorage db4oStorage = new db4oManagerStorage(configuration.DbFilePath); // volatile storage, we must initialize the data here //db4oStorage.InitializeStorageData(); _managerStorage = db4oStorage; } } } break; case ManagerStorageEnum.InMemory: /// in memory storage is volatile so we always return the same object if (_managerStorage == null) { lock (_inMemoryManagerStorageLock) { // make sure that when we got the lock we are still uninitialized if (_managerStorage == null) { InMemoryManagerStorage inMemoryStorage = new InMemoryManagerStorage(); // volatile storage, we must initialize the data here inMemoryStorage.InitializeStorageData(); _managerStorage = inMemoryStorage; } } } break; default: throw new System.Configuration.ConfigurationErrorsException( string.Format("Unknown storage type: {0}", configuration.DbType)); } return _managerStorage; }
/// <summary> /// Remove all executors that have not been pinged in the given time span /// </summary> /// <param name="storage"></param> /// <param name="cutOff"></param> public void RemoveExecutors(IManagerStorage storage, TimeSpan cutOff) { DateTime pingTimeCutOff = DateTime.Now.Subtract(cutOff); RemoveExecutors(storage, pingTimeCutOff); }
/// <summary> /// Remove all applications what were submitted before the given time span /// </summary> /// <param name="storage"></param> /// <param name="cutOff"></param> public void RemoveApplications(IManagerStorage storage, TimeSpan cutOff) { DateTime timeCreatedCutOff = DateTime.Now.Subtract(cutOff); RemoveApplications(storage, timeCreatedCutOff); }
/// <summary> /// Remove all applications from storage. /// </summary> /// <param name="storage">Target storage where this maintanance will be performed.</param> public void RemoveAllApplications(IManagerStorage storage) { ApplicationStorageView[] applications = storage.GetApplications(); foreach (ApplicationStorageView application in applications) { storage.DeleteApplication(application); } }
/// <summary> /// Thread doing the actual installation /// </summary> private void WorkerThread() { ShowProgress("Installer thread starting...", 0); ShowProgress(String.Format("Database type: {0}", _parent.managerConfiguration.DbType), 0); try { /// Create a storage object with the initial catalogue left to the default one. /// This is usually master for SQL Server or nothing for mySQL IManagerStorage storage = ManagerStorageFactory.CreateManagerStorage(_parent.managerConfiguration, false); // this storage object is also a storage setup object so it is safe to cast IManagerStorageSetup setup = (IManagerStorageSetup)storage; ShowProgress("Creating the database.", 1); if (_parent.managerConfiguration.DbType == ManagerStorageEnum.db4o) { setup.CreateStorage(_parent.managerConfiguration.DbFilePath); } else { setup.CreateStorage(_parent.managerConfiguration.DbName); } ShowProgress("Database created.", 20); } catch (Exception ex1) { ShowProgress("Unable to create the database. Error message:" + ex1.Message, 100); #if DEBUG ShowProgress("Debug information:", 100); ShowProgress(ex1.ToString(), 100); #endif return; } try { IManagerStorage storage = ManagerStorageFactory.CreateManagerStorage(_parent.managerConfiguration); // this storage object is also a storage setup object so it is safe to cast IManagerStorageSetup setup = (IManagerStorageSetup)storage; ShowProgress("Creating the database structure.", 40); // create storage structures setup.SetUpStorage(); ShowProgress("Database structure created.", 60); ShowProgress("Creating default users, groups and permissions.", 80); // insert the default values setup.InitializeStorageData(); ShowProgress("All default objects created.", 90); } catch (Exception ex2) { ShowProgress("Unable to initialize the database data. Error message:" + ex2.Message, 100); #if DEBUG ShowProgress("Debug information:", 100); ShowProgress(ex2.ToString(), 100); #endif return; } ShowProgress("Done!", 100); }