public void UpdateApplication(ApplicationStorageView updatedApplication) { ApplicationStorageView application = null; IObjectContainer container = GetStorage(); try { IList <ApplicationStorageView> apps = container.Query <ApplicationStorageView>(delegate(ApplicationStorageView app) { return(app.ApplicationId == updatedApplication.ApplicationId); }); if (apps.Count > 0) { application = apps[0]; container.Delete(application); container.Set(updatedApplication); } } finally { container.Close(); } }
/// <summary> /// Initializes this thread. /// </summary> /// <param name="primary">specifies if this thread is a primary thread. A thread is primary if it is created and scheduled by the same manager</param> public void Init(bool primary) { if (primary) { ThreadStorageView threadStorage = new ThreadStorageView(_AppId, _Id, ThreadState.Ready); ManagerStorageFactory.ManagerStorage().AddThread(threadStorage); } else { ApplicationStorageView applicationStorage = ManagerStorageFactory.ManagerStorage().GetApplication(_AppId); if (applicationStorage == null) { applicationStorage = new ApplicationStorageView( _AppId, ApplicationState.AwaitingManifest, DateTime.Now, false, "" /* TODO: What's the username here?*/); ManagerStorageFactory.ManagerStorage().AddApplication(applicationStorage); } ThreadStorageView threadStorage = new ThreadStorageView(_AppId, _Id, ThreadState.Ready); ManagerStorageFactory.ManagerStorage().AddThread(threadStorage); } }
public void SetData(ApplicationStorageView application) { this._app = application; this.lbName.Text = _app.ApplicationName; txId.Text = _app.ApplicationId; txUsername.Text = _app.Username; if (_app.TimeCreatedSet) { txCreated.Text = _app.TimeCreated.ToString(); } if (_app.TimeCompletedSet) { txCompleted.Text = _app.TimeCompleted.ToString(); } txState.Text = _app.StateString; chkPrimary.Checked = _app.Primary; txNumThreads.Text = _app.TotalThreads.ToString(); btnStop.Enabled = (_app.State != ApplicationState.Stopped); }
public void DeleteApplication(ApplicationStorageView applicationToDelete) { if (m_applications == null || applicationToDelete == null) { return; } ArrayList remainingApplications = new ArrayList(); ArrayList remainingThreads = new ArrayList(); if (m_threads != null) { foreach (ThreadStorageView thread in m_threads) { if (thread.ApplicationId != applicationToDelete.ApplicationId) { remainingThreads.Add(thread); } } } foreach (ApplicationStorageView application in m_applications) { if (application.ApplicationId != applicationToDelete.ApplicationId) { remainingApplications.Add(application); } } m_threads = remainingThreads; m_applications = remainingApplications; }
/// <summary> /// Add all kinds of objects to the storage so the maintenance functions have something to play with. /// </summary> private void PrepareComplexStorageForMaintenanceTests() { DateTime pingTime = DateTime.Now; _managerStorage.AddExecutor(new ExecutorStorageView(true, true, pingTime.AddDays(-1), "hostname", 1, "username", 1, 2, 3, 4)); _managerStorage.AddExecutor(new ExecutorStorageView(false, true, pingTime.AddDays(2), "hostname", 1, "username", 1, 2, 3, 4)); _managerStorage.AddExecutor(new ExecutorStorageView(true, false, pingTime.AddDays(1), "hostname", 1, "username", 1, 2, 3, 4)); _managerStorage.AddExecutor(new ExecutorStorageView(false, false, pingTime.AddDays(-2), "hostname", 1, "username", 1, 2, 3, 4)); DateTime timeCreated = DateTime.Now; ApplicationStorageView application1; ApplicationStorageView application2; ApplicationStorageView application3; ApplicationStorageView application4; ApplicationStorageView application5; application1 = new ApplicationStorageView(ApplicationState.AwaitingManifest, timeCreated.AddDays(-5), false, "username1"); application2 = new ApplicationStorageView(ApplicationState.Stopped, timeCreated.AddDays(-4), false, "username1"); application3 = new ApplicationStorageView(ApplicationState.Ready, timeCreated.AddDays(1), false, "username1"); application4 = new ApplicationStorageView(ApplicationState.AwaitingManifest, timeCreated.AddDays(-3), false, "username1"); application5 = new ApplicationStorageView(ApplicationState.Stopped, timeCreated.AddDays(2), false, "username1"); // leave time completed not set for application1 to test that scenario as well application2.TimeCompleted = DateTime.Now.AddDays(-4); application3.TimeCompleted = DateTime.Now.AddDays(2); application4.TimeCompleted = DateTime.Now.AddDays(-3); application5.TimeCompleted = DateTime.Now.AddDays(3); _managerStorage.AddApplication(application1); _managerStorage.AddApplication(application2); _managerStorage.AddApplication(application3); _managerStorage.AddApplication(application4); _managerStorage.AddApplication(application5); }
/// <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)); } }
public void TimeCreatedSetTestSettingIt() { ApplicationStorageView application = new ApplicationStorageView("username1"); Assert.IsFalse(application.TimeCreatedSet); application = new ApplicationStorageView(ApplicationState.AwaitingManifest, DateTime.Now, false, "username1"); Assert.IsTrue(application.TimeCreatedSet); }
public void TimeCompletedSetTestSettingIt() { ApplicationStorageView application = new ApplicationStorageView("username1"); Assert.IsFalse(application.TimeCompletedSet); application.TimeCompleted = DateTime.Now; Assert.IsTrue(application.TimeCompletedSet); }
public void IsApplicationCreatorTestFalseCreator() { ApplicationStorageView application = new ApplicationStorageView("username1"); string applicationId = _managerStorage.AddApplication(application); SecurityCredentials sc = new SecurityCredentials("username2", HashUtil.GetHash("password1", HashType.MD5)); bool result = IsApplicationCreator(sc, applicationId); Assert.IsFalse(result); }
/// <summary> /// Creates a new application /// </summary> /// <param name="username">the user associated with the application</param> /// <returns>Id of the newly created application</returns> public string CreateNew(string username) { //Krishna: changed to use the constructor with created-time ApplicationStorageView application = new ApplicationStorageView(ApplicationState.Ready, DateTime.Now, true, username); //new ApplicationStorageView(username); string appId = ManagerStorageFactory.ManagerStorage().AddApplication(application); this[appId].CreateDataDirectory(); return(appId); }
public void IsApplicationCreatorTestInvalidApplication() { ApplicationStorageView application = new ApplicationStorageView("username1"); String applicationId = m_managerStorage.AddApplication(application); String invalidApplicationId = Guid.NewGuid().ToString(); SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashUtil.HashType.MD5)); bool result = IsApplicationCreator(sc, invalidApplicationId); Assert.IsFalse(result); }
public string AddApplication(ApplicationStorageView application) { if (application == null) { return(null); } string applicationId = Guid.NewGuid().ToString(); application.ApplicationId = applicationId; _applications.Add(application); return(applicationId); }
public void UnfinishedThreadsTestNotSet() { ApplicationStorageView application = new ApplicationStorageView("username1"); try { int result = application.UnfinishedThreads; } catch { // exception expected return; } Assert.Fail("An exception was expected"); }
public void TotalThreadsTestNotSet() { ApplicationStorageView application = new ApplicationStorageView("username1"); try { Int32 result = application.TotalThreads; } catch { // exception expected return; } Assert.Fail("An exception was expected"); }
/// <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) { bool appSetup = true; //create directory can be repeated, and wont throw an error even if the dir already exists. this[id].CreateDataDirectory(); ApplicationStorageView application = ManagerStorageFactory.ManagerStorage().GetApplication(id); if (application == null) { appSetup = false; } return(appSetup); }
public ApplicationStorageView GetApplication(string applicationId) { IEnumerator enumerator = _applications.GetEnumerator(); while (enumerator.MoveNext()) { ApplicationStorageView application = (ApplicationStorageView)enumerator.Current; if (application.ApplicationId == applicationId) { return(application); } } // data not found return(null); }
public ApplicationStorageView[] GetApplications(string userName, bool populateThreadCount) { ApplicationStorageView[] allApplications; IObjectContainer container = GetStorage(); try { IList <ApplicationStorageView> applicationsList = container.Query <ApplicationStorageView>(delegate(ApplicationStorageView applicationFinder) { return(string.IsNullOrEmpty(userName) || String.Compare(applicationFinder.Username, userName, false) == 0); }); foreach (ApplicationStorageView application in applicationsList) { if (populateThreadCount) { int totalThreads; int unfinishedThreads; GetApplicationThreadCount(application.ApplicationId, out totalThreads, out unfinishedThreads); application.TotalThreads = totalThreads; application.UnfinishedThreads = unfinishedThreads; } } if (applicationsList.Count > 0) { allApplications = new ApplicationStorageView[applicationsList.Count]; applicationsList.CopyTo(allApplications, 0); } else { allApplications = new ApplicationStorageView[0]; } } finally { container.Close(); } return(allApplications); }
public String AddApplication(ApplicationStorageView application) { if (application == null) { return(null); } if (m_applications == null) { m_applications = new ArrayList(); } String applicationId = Guid.NewGuid().ToString(); application.ApplicationId = applicationId; m_applications.Add(application); return(applicationId); }
public void UpdateApplication(ApplicationStorageView updatedApplication) { if (m_applications == null || updatedApplication == null) { return; } ArrayList newApplicationList = new ArrayList(); foreach (ApplicationStorageView application in m_applications) { if (application.ApplicationId == updatedApplication.ApplicationId) { newApplicationList.Add(updatedApplication); } else { newApplicationList.Add(application); } } m_applications = newApplicationList; }
public string AddApplication(ApplicationStorageView application) { if (application == null) { return(null); } string applicationId = Guid.NewGuid().ToString(); application.ApplicationId = applicationId; IObjectContainer container = GetStorage(); try { container.Set(application); } finally { container.Close(); } return(applicationId); }
/// <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); }
public void DeleteApplication(ApplicationStorageView applicationToDelete) { if (applicationToDelete == null) { return; } IObjectContainer container = GetStorage(); try { IList <ThreadStorageView> threads = container.Query <ThreadStorageView>(delegate(ThreadStorageView threadFinder) { return(threadFinder.ApplicationId == applicationToDelete.ApplicationId); }); foreach (ThreadStorageView thread in threads) { container.Delete(thread); } IList <ApplicationStorageView> apps = container.Query <ApplicationStorageView>(delegate(ApplicationStorageView appFinder) { return(appFinder.ApplicationId == applicationToDelete.ApplicationId); }); foreach (ApplicationStorageView app in apps) { container.Delete(app); } } finally { container.Close(); } }
public ApplicationStorageView GetApplication(string applicationId) { ApplicationStorageView application = null; IObjectContainer container = GetStorage(); try { IList <ApplicationStorageView> apps = container.Query <ApplicationStorageView>(delegate(ApplicationStorageView app) { return(app.ApplicationId == applicationId); }); if (apps.Count > 0) { application = apps[0]; } } finally { container.Close(); } return(application); }
/// THIS FUNCTIONALITY IS NOT FULLY IMPLEMENTED AND IT MIGHT BE DISCARDED ALTOGETHER /// /// Loading from an XML file is the perfect tool for complex storage setups which would be useful for more in-depth unit testing /// Saving to an XML file could be used to dump the current storage state for troubleshooting, for example to receive faulty storages from the field. /// <summary> /// Save the current storage state into an XML file. /// It is important that the file format is easily editable by humans so test cases can easily be maintained. /// For this reason we do not use the build-in persistence modules. /// </summary> /// <param name="filename"></param> public void SaveToHumanReadableXmlFile(String filename) { const String storageDocumentTemplate = "<storage><users/><groups/><group_permissions/><executors/><applications/><threads/></storage>"; XmlDocument storageDocument = new XmlDocument(); storageDocument.LoadXml(storageDocumentTemplate); XmlNode usersNode = storageDocument.SelectSingleNode("/storage/users"); XmlNode groupsNode = storageDocument.SelectSingleNode("/storage/groups"); //XmlNode groupPermissionsNode = storageDocument.SelectSingleNode("/storage/group_permissions"); XmlNode executorsNode = storageDocument.SelectSingleNode("/storage/executors"); XmlNode applicationsNode = storageDocument.SelectSingleNode("/storage/applications"); XmlNode threadsNode = storageDocument.SelectSingleNode("/storage/threads"); if (m_users != null) { IEnumerator usersEnumerator = m_users.GetEnumerator(); while (usersEnumerator.MoveNext()) { UserStorageView user = usersEnumerator.Current as UserStorageView; XmlElement userElement = storageDocument.CreateElement("user"); userElement.SetAttribute("username", user.Username); userElement.SetAttribute("password", user.Password); userElement.SetAttribute("groupid", user.GroupId.ToString()); usersNode.AppendChild(userElement); } } if (m_groups != null) { IEnumerator groupsEnumerator = m_groups.GetEnumerator(); while (groupsEnumerator.MoveNext()) { GroupStorageView group = groupsEnumerator.Current as GroupStorageView; XmlElement groupElement = storageDocument.CreateElement("group"); groupElement.SetAttribute("groupname", group.GroupName); groupElement.SetAttribute("groupid", group.GroupId.ToString()); groupsNode.AppendChild(groupElement); } } // private Hashtable m_groupPermissions; // if (m_groupPermissions != null) // { // IEnumerator groupPermissionsEnumerator = m_groupPermissions.GetEnumerator(); // // while(groupPermissionsEnumerator.MoveNext()) // { // GroupPermissionStorageView group = groupPermissionsEnumerator.Current as GroupStorageView; // // XmlElement groupElement = storageDocument.CreateElement("group"); // // groupElement.SetAttribute("groupname", group.GroupName); // groupElement.SetAttribute("groupid", group.GroupId.ToString()); // // groupsNode.AppendChild(groupElement); // } // } if (m_executors != null) { IEnumerator executorsEnumerator = m_executors.GetEnumerator(); while (executorsEnumerator.MoveNext()) { ExecutorStorageView executor = executorsEnumerator.Current as ExecutorStorageView; XmlElement executorElement = storageDocument.CreateElement("executor"); executorElement.SetAttribute("executorid", executor.ExecutorId); executorElement.SetAttribute("dedicated", executor.Dedicated.ToString()); executorElement.SetAttribute("connected", executor.Connected.ToString()); executorElement.SetAttribute("pingtime", executor.PingTime.ToString()); executorElement.SetAttribute("hostname", executor.HostName); executorElement.SetAttribute("port", executor.Port.ToString()); executorElement.SetAttribute("username", executor.Username); executorElement.SetAttribute("maxcpu", executor.MaxCpu.ToString()); executorElement.SetAttribute("cpuusage", executor.CpuUsage.ToString()); executorElement.SetAttribute("availablecpu", executor.AvailableCpu.ToString()); executorElement.SetAttribute("totalcpuusage", executor.TotalCpuUsage.ToString()); executorElement.SetAttribute("maxmemory", executor.MaxMemory.ToString()); executorElement.SetAttribute("maxdisk", executor.MaxDisk.ToString()); executorElement.SetAttribute("numberofcpu", executor.NumberOfCpu.ToString()); executorElement.SetAttribute("os", executor.Os); executorElement.SetAttribute("architecture", executor.Architecture); executorsNode.AppendChild(executorElement); } } if (m_applications != null) { IEnumerator applicationsEnumerator = m_applications.GetEnumerator(); while (applicationsEnumerator.MoveNext()) { ApplicationStorageView application = applicationsEnumerator.Current as ApplicationStorageView; XmlElement applicationElement = storageDocument.CreateElement("application"); applicationElement.SetAttribute("applicationid", application.ApplicationId); applicationElement.SetAttribute("state", application.State.ToString()); applicationElement.SetAttribute("timecreated", application.TimeCreated.ToString()); applicationElement.SetAttribute("primary", application.Primary.ToString()); applicationElement.SetAttribute("username", application.Username.ToString()); applicationElement.SetAttribute("totalthreads", application.TotalThreads.ToString()); applicationElement.SetAttribute("unfinishedthreads", application.UnfinishedThreads.ToString()); applicationsNode.AppendChild(applicationElement); } } if (m_threads != null) { IEnumerator threadsEnumerator = m_threads.GetEnumerator(); while (threadsEnumerator.MoveNext()) { ThreadStorageView thread = threadsEnumerator.Current as ThreadStorageView; XmlElement threadElement = storageDocument.CreateElement("thread"); threadElement.SetAttribute("internalthreadid", thread.InternalThreadId.ToString()); threadElement.SetAttribute("applicationid", thread.ApplicationId); threadElement.SetAttribute("executorid", thread.ExecutorId); threadElement.SetAttribute("threadid", thread.ThreadId.ToString()); threadElement.SetAttribute("state", thread.State.ToString()); threadElement.SetAttribute("timestarted", thread.TimeStarted.ToString()); threadElement.SetAttribute("timefinished", thread.TimeFinished.ToString()); threadElement.SetAttribute("priority", thread.Priority.ToString()); threadElement.SetAttribute("failed", thread.Failed.ToString()); threadsNode.AppendChild(threadElement); } } storageDocument.Save(filename); }