public AppStartFailureException(AppIdTuple appIdTuple, string reason, Exception innerEx=null) : base(string.Format( "Application '{0}' failed to start. Reason: {1}", appIdTuple, reason), innerEx) { this.appIdTuple = appIdTuple; this.reason = reason; }
public override void Execute(IList<string> args) { if (args.Count == 0) throw new MissingArgumentException("appIdTuple", "AppIdTuple expected."); var t = new AppIdTuple(args[0]); if (t.AppId == "") throw new ArgumentSyntaxErrorException("appIdTuple", args[0], "\"machineId.appId\" expected"); ctrl.KillApp(t); }
string getAppStatusCode( AppIdTuple appIdTuple, AppState st, bool isPartOfPlan ) { string stCode = "Not running"; var currPlan = ctrl.GetCurrentPlan(); bool planRunning = (currPlan != null) && currPlan.Running && isPartOfPlan; bool connected = callbacks.isConnectedDeleg(); var currTime = DateTime.UtcNow; bool isRemoteApp = appIdTuple.MachineId != this.machineId; if( isRemoteApp && !connected ) { stCode = "??? (discon.)"; return stCode; } if( planRunning && !st.PlanApplied ) { stCode = "Planned"; } if (st.Started) { if (st.Running && !st.Initialized) { stCode = "Initializing"; } if (st.Running && st.Initialized) { stCode = "Running"; } if (!st.Running) { if (st.Killed) { stCode = "Killed"; } else { stCode = string.Format("Terminated ({0})", st.ExitCode); } } } else if (st.StartFailed) { stCode = "Failed to start"; } var statusInfoAge = currTime - st.LastChange; if( isRemoteApp && statusInfoAge > TimeSpan.FromSeconds(3) ) { stCode += string.Format(" (no info for {0:0} sec)", statusInfoAge.TotalSeconds); } return stCode; }
public AppState GetAppState(AppIdTuple appIdTuple) { try { return appsState[appIdTuple]; } catch { throw new UnknownAppIdException(appIdTuple); } }
public void testKillApp_invalidAppId() { var ctrlMock = new Mock<IDirigentControl>(); var appIdTuple = new AppIdTuple("justmachine."); ctrlMock.Setup(f => f.KillApp(appIdTuple)); var cmdRepo = new CommandRepository(); cmdRepo.Register(new Commands.KillApp(ctrlMock.Object)); cmdRepo.ParseAndExecute(new List<string>() { "KillApp", "justmachine." }); //Assert.AreEqual("); }
public void testKillApp() { var ctrlMock = new Mock<IDirigentControl>(); var appIdTuple = new AppIdTuple("m1.a"); ctrlMock.Setup(f => f.KillApp(appIdTuple)).Verifiable(); var cmdRepo = new CommandRepository(); cmdRepo.Register(new Commands.KillApp(ctrlMock.Object)); cmdRepo.ParseAndExecute(new List<string>() { "KillApp", "m1.a" }); ctrlMock.Verify(); //Assert.AreEqual("); }
public void testSelectPlanAndKillApp() { var ctrlMock = new Mock<IDirigentControl>(); var appIdTuple = new AppIdTuple("m1.a"); var appDef = new AppDef() { AppIdTuple = appIdTuple }; var plan = new LaunchPlan("plan1", new List<AppDef>() { appDef } ); var planRepo = new List<ILaunchPlan>() { plan }; ctrlMock.Setup(f => f.GetPlanRepo()).Returns(planRepo); ctrlMock.Setup(f => f.SelectPlan(plan)).Verifiable(); var cmdRepo = new CommandRepository(); cmdRepo.Register( new Commands.SelectPlan(ctrlMock.Object) ); cmdRepo.ParseAndExecute(new List<string>() { ";SelectPlan", "plan1;", "KillApp", "m1.a1;" }); ctrlMock.Verify(); //Assert.AreEqual("); }
public UnknownAppIdException(AppIdTuple appIdTuple) : base("AppId '" + appIdTuple.MachineId + "." + appIdTuple.AppId + "' not found.") { this.appIdTuple = appIdTuple; }
public void RestartApp(AppIdTuple appIdTuple) { client.BroadcastMessage(new RestartAppMessage(appIdTuple)); }
private void gridApps_MouseClick(object sender, MouseEventArgs e) { var hti = gridApps.HitTest(e.X,e.Y); int currentRow = hti.RowIndex; int currentCol = hti.ColumnIndex; if (currentRow >= 0) // ignore header clicks { DataGridViewRow focused = gridApps.Rows[currentRow]; var appIdTuple = new AppIdTuple(focused.Cells[0].Value as string); var st = ctrl.GetAppState(appIdTuple); bool connected = callbacks.isConnectedDeleg(); bool isLocalApp = appIdTuple.MachineId == this.machineId; bool isAccessible = isLocalApp || connected; // can we change its state? if (e.Button == MouseButtons.Right) { // build popup menu var popup = new System.Windows.Forms.ContextMenuStrip(this.components); popup.Enabled = connected || allowLocalIfDisconnected; var launchItem = new System.Windows.Forms.ToolStripMenuItem("&Launch"); launchItem.Click += (s, a) => guardedOp(() => ctrl.LaunchApp(appIdTuple)); launchItem.Enabled = isAccessible && !st.Running; popup.Items.Add(launchItem); var killItem = new System.Windows.Forms.ToolStripMenuItem("&Kill"); killItem.Click += (s, a) => guardedOp( () => ctrl.KillApp(appIdTuple) ); killItem.Enabled = isAccessible && st.Running; popup.Items.Add(killItem); var restartItem = new System.Windows.Forms.ToolStripMenuItem("&Restart"); restartItem.Click += (s, a) => guardedOp( () => ctrl.RestartApp(appIdTuple) ); restartItem.Enabled = isAccessible && st.Running; popup.Items.Add(restartItem); popup.Show(Cursor.Position); } else if (e.Button == MouseButtons.Left) { // icon clicks if( currentCol == 2 ) { if( isAccessible && !st.Running ) { guardedOp(() => ctrl.LaunchApp(appIdTuple)); } } if( currentCol == 3 ) { if( isAccessible && st.Running ) { guardedOp(() => ctrl.KillApp(appIdTuple)); } } if( currentCol == 4 ) { if( isAccessible && st.Running ) { guardedOp(() => ctrl.RestartApp(appIdTuple)); } } } } }
public void SetRemoteAppState(AppIdTuple appIdTuple, AppState state) { appsState[appIdTuple] = state; }
private void gridApps_MouseDoubleClick(object sender, MouseEventArgs e) { // launch the app if (e.Button == MouseButtons.Left) { int currentMouseOverRow = gridApps.HitTest(e.X,e.Y).RowIndex; if (currentMouseOverRow >= 0) { DataGridViewRow focused = gridApps.Rows[currentMouseOverRow]; var appIdTuple = new AppIdTuple(focused.Cells[0].Value as string); var st = ctrl.GetAppState(appIdTuple); guardedOp(() => ctrl.LaunchApp(appIdTuple)); } } }
public void makeInitialized( AppIdTuple id ) { makeLaunched(id); appsState[id].Initialized = true; }
public void RestartApp(AppIdTuple appIdTuple) { KillApp( appIdTuple ); LaunchApp( appIdTuple ); }
// // Implementation of IDirigentControl // public AppState GetAppState(AppIdTuple appIdTuple) { return localOps.GetAppState(appIdTuple); }
public void LaunchApp(AppIdTuple appIdTuple) { client.BroadcastMessage( new LaunchAppMessage( appIdTuple ) ); }
public AppState GetAppState(AppIdTuple appIdTuple) { return(appsState[appIdTuple]); }
public bool Equals(AppIdTuple p) { // If parameter is null return false: if ((object)p == null) { return false; } // Return true if the fields match: return (MachineId == p.MachineId) && (AppId == p.AppId); }
public AppState GetAppState(AppIdTuple appIdTuple) { return appsState[appIdTuple]; }
/// <summary> /// Kills a local app. /// </summary> /// <param name="appIdTuple"></param> public void KillApp(AppIdTuple appIdTuple) { if( !(localApps.ContainsKey(appIdTuple) )) { throw new NotALocalApp(appIdTuple, machineId); } var la = localApps[appIdTuple]; var appState = appsState[la.AppDef.AppIdTuple]; if( la.launcher != null ) // already started? { if (la.launcher.Running) { appState.Killed = true; } log.DebugFormat("Killing app {0}", la.AppDef.AppIdTuple); la.launcher.Kill(); la.launcher = null; } }
/// <summary> /// Sets new status info for given app. /// To be used for remote apps whose status gets received from master. /// </summary> /// <param name="appIdTuple"></param> /// <param name="appState"></param> public void SetRemoteAppState( AppIdTuple appIdTuple, AppState appState ) { appsState[appIdTuple] = appState; }
public NotALocalApp(AppIdTuple appIdTuple, string localMachineId) : base("MachineId in '" + appIdTuple.MachineId + "." + appIdTuple.AppId + "' is not the one of this computer (" + localMachineId + ").") { this.appIdTuple = appIdTuple; }
public NotALocalApp( AppIdTuple appIdTuple, string localMachineId ) : base("MachineId in '"+appIdTuple.MachineId+"."+appIdTuple.AppId+"' is not the one of this computer ("+localMachineId+").") { this.appIdTuple = appIdTuple; }
public InvalidAppConfig(AppIdTuple app, string msg) : base(string.Format("Invalid app '{0}' config: '{1}'.", app, msg)) { this.app = app; this.msg = msg; }
public void KillApp(AppIdTuple appIdTuple) { client.BroadcastMessage(new KillAppMessage(appIdTuple)); }
public void makeLaunched( AppIdTuple id ) { appsState[id].PlanApplied = true; appsState[id].Started = true; appsState[id].Running = true; }
/// <summary> /// Launches a local app if not already running. /// </summary> /// <param name="appIdTuple"></param> public void LaunchApp(AppIdTuple appIdTuple) { if( !(localApps.ContainsKey(appIdTuple) )) { throw new NotALocalApp(appIdTuple, machineId); } var la = localApps[appIdTuple]; var appState = appsState[la.AppDef.AppIdTuple]; // don't do anything if the app is already running if( la.launcher != null && la.launcher.Running ) { return; } log.DebugFormat("Launching app {0}", la.AppDef.AppIdTuple); // launch the application appState.Started = false; appState.StartFailed = false; appState.Killed = false; la.watchers.Clear(); la.launcher = launcherFactory.createLauncher( la.AppDef ); try { la.launcher.Launch(); appState.Started = true; appState.Initialized = true; // a watcher can set it to false upon its creation if it works like an AppInitDetector //// instantiate app watchers //foreach( var watcherDef in la.AppDef.Watchers ) //{ // var w = appWatcherFactory.create( la.AppDef, appsState[appIdTuple], la.launcher.ProcessId, watcherDef); // la.watchers.Add( w ); //} // instantiate init detector (also a watcher) { // compatibility with InitialCondition="timeout 2.0" ... convert to XML definition <timeout>2.0</timeout> { if( !string.IsNullOrEmpty( la.AppDef.InitializedCondition ) ) { string name; string args; AppInitializedDetectorFactory.ParseDefinitionString( la.AppDef.InitializedCondition, out name, out args ); string xmlString = string.Format("<{0}>{1}</{0}>", name, args); var aid = appAppInitializedDetectorFactory.create( la.AppDef, appsState[appIdTuple], la.launcher.ProcessId, XElement.Parse(xmlString) ); log.DebugFormat("Adding InitDetector {0}, pid {1}", aid.GetType().Name, la.launcher.ProcessId ); la.watchers.Add( aid ); } } foreach( var xml in la.AppDef.InitDetectors ) { var aid = appAppInitializedDetectorFactory.create( la.AppDef, appsState[appIdTuple], la.launcher.ProcessId, XElement.Parse(xml)); log.DebugFormat("Adding InitDetector {0}, pid {1}", aid.GetType().Name, la.launcher.ProcessId ); la.watchers.Add( aid ); } } // instantiate window positioners foreach( var xml in la.AppDef.WindowPosXml ) { log.DebugFormat("Adding WindowsPositioner, pid {0}", la.launcher.ProcessId ); var wpo = new WindowPositioner( la.AppDef, appsState[appIdTuple], la.launcher.ProcessId, XElement.Parse(xml) ); la.watchers.Add( wpo ); } // instantiate autorestarter if( la.AppDef.RestartOnCrash ) { log.DebugFormat("Adding AutoRestarter, pid {0}", la.launcher.ProcessId ); var ar = new AutoRestarter( la.AppDef, appsState[appIdTuple], la.launcher.ProcessId, new XElement("Autorestart") ); la.watchers.Add( ar ); } } catch( Exception ex ) // app launching failed { log.ErrorFormat("Exception: App \"{0}\"start failure {1}", la.AppDef.AppIdTuple, ex); appState.StartFailed = true; throw; } }
public void SetRemoteAppState(AppIdTuple appIdTuple, AppState state) { localOps.SetRemoteAppState(appIdTuple, state); }
public AppState GetAppState(AppIdTuple appIdTuple) { return impl.GetAppState(appIdTuple); }
public void KillApp(AppIdTuple appIdTuple) { client.BroadcastMessage( new KillAppMessage( appIdTuple ) ); }
public void KillApp(AppIdTuple appIdTuple) { impl.KillApp(appIdTuple); }
public void RestartApp(AppIdTuple appIdTuple) { client.BroadcastMessage( new RestartAppMessage( appIdTuple ) ); }
public void LaunchApp(AppIdTuple appIdTuple) { impl.LaunchApp(appIdTuple); }
public UnknownAppIdException( AppIdTuple appIdTuple ) : base("AppId '"+appIdTuple.MachineId+"."+appIdTuple.AppId+"' not found.") { this.appIdTuple = appIdTuple; }
public void RestartApp(AppIdTuple appIdTuple) { impl.RestartApp(appIdTuple); }
public InvalidAppConfig( AppIdTuple app, string msg ) : base(string.Format("Invalid app '{0}' config: '{1}'.", app, msg )) { this.app = app; this.msg = msg; }
public void SetRemoteAppState(AppIdTuple appIdTuple, AppState state) { impl.SetRemoteAppState(appIdTuple, state); }