const int WATCH_OUT = 10*1000; // maximum time to update in milliseconds #endregion Fields #region Methods static ExecutionService.TaskDescription[] GenerateTasks(System.Random rnd) { var resourcesService = new ResourceBaseService.ResourceBaseServiceClient(); string[] names = resourcesService.GetResourceNames().Where(name => name == "b14").ToArray(); List<string> allowedNames = new List<string>(); foreach (string name in names) { var res = resourcesService.GetResourceByName(name); if (res.Nodes.Any(n => n.Packages.Any(p => p.Name.ToLowerInvariant() == PACK_NAME.ToLowerInvariant()))) allowedNames.Add(name); } int nameIndex = rnd.Next(allowedNames.Count); string resourceName = allowedNames[nameIndex]; var executionService = new ExecutionService.ExecutionBrokerServiceClient(); ulong generatedTaskId = executionService.GetNewTaskId(); var tasks = new ExecutionService.TaskDescription[] { new ExecutionService.TaskDescription() { WfId = "Watchina", TaskId = generatedTaskId, UserId = "sm", LaunchMode = ExecutionService.TaskLaunchMode.Auto, ExecParams = new Dictionary<string,string>() { {"Resource", resourceName}, }, Package = "cnm", Params = new Dictionary<string,string>() { {"in_format", "short"}, }, InputFiles = new ExecutionService.TaskFileDescription[] { new ExecutionService.TaskFileDescription { StorageId = "cnm_60k_p32", FileName = "cnm.in", SlotName = "inDataFile" }, } }, new ExecutionService.TaskDescription() { WfId = "Watchina", TaskId = generatedTaskId, UserId = "sm", LaunchMode = ExecutionService.TaskLaunchMode.Auto, ExecParams = new Dictionary<string,string>() { {"Resource", resourceName}, }, Package = "testp", Method = "arithm", Params = new Dictionary<string,string>() { {"operation", "plus"}, }, InputFiles = new ExecutionService.TaskFileDescription[] { new ExecutionService.TaskFileDescription { StorageId = "number1", FileName = "my0.in", SlotName = "inf0" }, new ExecutionService.TaskFileDescription { StorageId = "number25", FileName = "my1.in", SlotName = "inf1" }, }, OutputFiles = new ExecutionService.TaskFileDescription[] { new ExecutionService.TaskFileDescription { StorageId = null, FileName = "out.txt", SlotName = "out_file" } } } }; var packTasks = tasks.Where(t => t.Package.ToLowerInvariant() == PACK_NAME.ToLowerInvariant()).ToArray(); return packTasks; }
static void Heartbeat(ServiceToBeat serviceType) { Thread.Sleep(TimeSpan.FromSeconds(10)); var rnd = new System.Random(); while (true) { try { // todo : heartbeat for each service in config if (serviceType == ServiceToBeat.Executor) { var executor = new ExecutionBrokerService.ExecutionBrokerServiceClient(); try { //Console.Write("{0} - ", DateTime.Now.ToString(TIME_FORMAT)); Indicators.IsBeating = true; executor.Update(); Indicators.IsBeating = false; //Console.WriteLine(DateTime.Now.ToString(TIME_FORMAT)); executor.Close(); } catch { Indicators.IsBeating = false; executor.Abort(); throw; } } else if (serviceType == ServiceToBeat.ResourceBase) { var resourceBase = new ResourceBaseService.ResourceBaseServiceClient(); try { resourceBase.GetResourceNames(); // only need to call to refresh resources, no need in result resourceBase.Close(); } catch { resourceBase.Abort(); throw; } } } catch (Exception e) { //Indicators.IsBeating = false; LogToConsole(e); Thread.Sleep(5000); } finally { //Indicators.IsBeating = false; Thread.Sleep(rnd.Next(TICK, TACK)); } } }