Modules | |
Enumerations | |
Events related with the processes | |
Classes | |
class | DeepsyPlatformManager |
Manager for access the platform functionalities and events raised More... | |
class | Platform |
Platform object | |
class | Process |
Object to manage process | |
Detailed Description
To work with Deepsy platformmanager service it is necessary to use DeepsyPlatformManager located in GMV.ITS.HAL.DEEPSY.Platform.Facade for getting the initial PlatformManager object.
To obtain a list of Process objects:
Examples
-
Get list of processes
Getting all the processes list.using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Platform{class GetListOfProcesses{static void Main(string[] args){try{string deepsyServerIp = args.Length == 0 ? "192.168.1.140" : args[0];using (IDeepsyPlatformManager platformManager = new DeepsyPlatformManager(deepsyServerIp)){IPlatform platform = platformManager.GetPlatforms().First();IEnumerable<IProcess> processes = platform.GetProcesses();Console.WriteLine($"There are {processes.Count()} processes");processes.ToList().ForEach(p => PrintProcessInfo(p));}}catch (HalException deepsyEx){Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");}catch (Exception ex){Console.WriteLine($"Error: [{ex.Message}]");}}public static void PrintProcessInfo(IProcess p){try{Console.WriteLine($"{p.Name} :");Console.WriteLine($"\t- {p.Info.Status.ToString().ToUpper()}");Console.WriteLine($"\t- seconds running: { p.Info.SecondsRunning}");Console.WriteLine($"\t- retries: { p.Info.NumberOfRetries}");Console.WriteLine($"\t- mtbf: { p.Info.Mtbf}");Console.WriteLine($"\t- exec: { p.Options.ProcessExec}");Console.WriteLine($"\t- args: { String.Join(" ", p.Options.Args)}");Console.WriteLine($"\t- critical: { p.Options.Critical.ToString().ToLower()}");Console.WriteLine($"\t- relaunch: { p.Options.Relaunch.ToString().ToLower()}");Console.WriteLine($"\t- path: { p.Options.ProcessPath}");Console.WriteLine($"\t- delay: { p.Options.DelayOnLaunch}");Console.WriteLine($"\t- preScript path: { p.Options.PreScriptPath}");Console.WriteLine($"\t- postScript path: { p.Options.PostScriptPath}");}catch (Exception e){Console.WriteLine("ERROR: " + e.Message);}}}}
-
Manage a process
Doing different tasks with a process.using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Platform{class ManageAprocess{static void Main(string[] args){try{string deepsyServerIp = args.Length == 0 ? "192.168.1.140" : args[0];using (IDeepsyPlatformManager platformManager = new DeepsyPlatformManager(deepsyServerIp)){IPlatform platform = platformManager.GetPlatforms().First();Console.WriteLine("Adding \"ping\" process with a preScript and post script");IProcessOptionsDto options = new ProcessOptionsDto(){ProcessExec = "ping",ProcessPath = "/bin/",Relaunch = true,Critical = false,DelayOnLaunch = 0,Args = new List<string>() { "127.0.0.1" },PreScriptPath = "/mntDAT/myPreScriptPath.sh",PostScriptPath = "/mntDAT/myPostScript.sh"};IProcess myProcess = platform.AddProcess("processTest", options);Console.WriteLine("Starting \"ping\" process ");myProcess.Start();Console.WriteLine("Stopping \"ping\" process ");myProcess.Stop();Console.WriteLine("Deleting \"ping\" process ");platform.DelProcess(myProcess);}}catch (HalException deepsyEx){Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");}catch (Exception ex){Console.WriteLine($"Error: [{ex.Message}]");}}}}
-
Subscribe to events
There are 4 types of events in the platform system:- ProcessListEvent : This event happens when a process is added to or removed from the system. To receive this kind of events, it is necessary to subscribe to a Platform object
-
ProcessEvent : This event happens when a process state changes. To receive this kind of events, it is necessary to subscribe to the Process object
This example subscribes to every event.
using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Platform{class PlatformEvents{static void Main(string[] args){try{string deepsyServerIp = args.Length == 0 ? "192.168.1.140" : args[0];using (IDeepsyPlatformManager platformManager = new DeepsyPlatformManager(deepsyServerIp)){IPlatform platform = platformManager.GetPlatforms().First();Console.WriteLine("Adding \"ping\" process with a preScript and post script");platform.ProcessListEventRaised += PlatformManager_ProcessList;List<IProcess> processes = platform.GetProcesses().ToList();processes.ForEach(p => p.ProcessEventRaised += P_ProcessEventRaised);IProcessOptionsDto options = new ProcessOptionsDto(){ProcessExec = "ping",ProcessPath = "/bin/",Relaunch = true,Critical = false,DelayOnLaunch = 0,Args = new List<string>() { "127.0.0.1" },PreScriptPath = "/mntDAT/myPreScriptPath.sh",PostScriptPath = "/mntDAT/myPostScript.sh"};IProcess myProcess = platform.AddProcess("processTest", options);myProcess.ProcessEventRaised += P_ProcessEventRaised;System.Threading.Thread.Sleep(1000);Console.WriteLine("Starting \"processTest\" process ");myProcess.Start();System.Threading.Thread.Sleep(1000);Console.WriteLine("Stopping \"processTest\" process ");myProcess.Stop();System.Threading.Thread.Sleep(1000);Console.WriteLine("Deleting \"processTest\" process ");platform.DelProcess(myProcess);System.Threading.Thread.Sleep(1000);Console.WriteLine("Press ESC for exit");while (Console.ReadKey().Key != ConsoleKey.Escape){}}}catch (HalException deepsyEx){Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");}catch (Exception ex){Console.WriteLine($"Error: [{ex.Message}]");}}private static void P_ProcessEventRaised(object sender, HAL.DEEPSY.Platform.Interface.Event.ProcessEvent e){Console.WriteLine($"Process status event: Process {e.process.Name} {e.status}");}private static void PlatformManager_ProcessList(object sender, HAL.DEEPSY.Platform.Interface.Event.ProcessListEvent e){Console.WriteLine($"Platform List event: Process {e.process.Name} {e.action}");}}}
-
Kick a process
An example on how to kick a process. Deadline (seconds) is the time that the process which I am kicking waits for another kick, if this time is surpassed, process will be relaunched.using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Platform{class KickAprocess{static void Main(string[] args){try{string deepsyServerIp = args.Length == 0 ? "192.168.1.140" : args[0];using (IDeepsyPlatformManager platformManager = new DeepsyPlatformManager(deepsyServerIp)){IPlatform platform = platformManager.GetPlatforms().First();Console.WriteLine("Adding \"processTest\" process with a preScript and post script");IProcessOptionsDto options = new ProcessOptionsDto(){ProcessExec = "ping",ProcessPath = "/bin/",Relaunch = true,Critical = false,DelayOnLaunch = 0,Args = new List<string>() { "127.0.0.1" },PreScriptPath = "/mntDAT/myPreScriptPath.sh",PostScriptPath = "/mntDAT/myPostScript.sh"};IProcess myProcess = platform.AddProcess("processTest", options);Console.WriteLine("Starting \"processTest\" process ");myProcess.Start();for (int i = 0; i < 6; i++){Console.WriteLine("Sending kick to process");myProcess.KickWatchdog(5);System.Threading.Thread.Sleep(3000);}Console.WriteLine("NOT sending kick to process");System.Threading.Thread.Sleep(6000);Console.WriteLine($"Process has been restarted. Status {myProcess.Info.Status}. Seconds running: {myProcess.Info.SecondsRunning}");Console.WriteLine("Disabling kick. Process will run even without kick signal");myProcess.KickWatchdog(0);System.Threading.Thread.Sleep(10000);IProcessInfoDto info = myProcess.GetInfo();Console.WriteLine($"Process is still running. Status {info.Status}. Seconds running: {info.SecondsRunning}");Console.WriteLine("Deleting \"processTest\" process ");platform.DelProcess(myProcess);Console.WriteLine("SUCCESS!");}}catch (HalException deepsyEx){Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");}catch (Exception ex){Console.WriteLine($"Error: [{ex.Message}]");}}}}