public void DataSetNothingForCompNode()
        {
            var comps = new Dictionary <int, ActiveComponent>();

            comps.Add(1, new ActiveComponent()
            {
                ComponentType    = ComponentType.ComputationalNode,
                SolvableProblems = new[] { "abc" }
            });
            var dict  = new Dictionary <int, ProblemDataSet>();
            var bytes = new byte[1] {
                1
            };

            dict.Add(1,
                     new ProblemDataSet()
            {
                CommonData    = bytes,
                TaskManagerId = 1,
                ProblemType   = "abc",
                PartialSets   = null
            });
            var ret = DataSetOps.GetMessageForCompNode(comps, 1, dict);

            Assert.IsNull(ret);
        }
        public void DataSetNothingForTaskManager()
        {
            var comps = new Dictionary <int, ActiveComponent>();

            comps.Add(1, new ActiveComponent()
            {
                ComponentType    = ComponentType.TaskManager,
                SolvableProblems = new[] { "def" }
            });
            var dict  = new Dictionary <int, ProblemDataSet>();
            var bytes = new byte[1] {
                1
            };

            dict.Add(1,
                     new ProblemDataSet()
            {
                CommonData    = bytes,
                TaskManagerId = 0,
                ProblemType   = "abc"
            });
            var ret = DataSetOps.GetMessageForTaskManager(comps, 1, dict);

            Assert.IsNull(ret);
        }
        public void DataSetDivideForProperTaskManager()
        {
            var comps = new Dictionary <int, ActiveComponent>();

            comps.Add(1, new ActiveComponent()
            {
                ComponentType    = ComponentType.TaskManager,
                SolvableProblems = new [] { "abc" }
            });
            var dict  = new Dictionary <int, ProblemDataSet>();
            var bytes = new byte[1] {
                1
            };

            dict.Add(1,
                     new ProblemDataSet()
            {
                CommonData    = bytes,
                TaskManagerId = 0,
                ProblemType   = "abc"
            });
            var ret = DataSetOps.GetMessageForTaskManager(comps, 1, dict);

            Assert.AreEqual(typeof(DivideProblem), ret.GetType());
            var msg = ret.Cast <DivideProblem>();

            Assert.AreEqual(1, msg.Data.Length);
            Assert.AreEqual(1, msg.Data[0]);
            Assert.AreEqual(1, dict[1].TaskManagerId);
        }
 private void StatusThreadWork(int who,
                               IDictionary <int, ActiveComponent> activeComponents, IDictionary <int, ProblemDataSet> dataSets)
 {
     while (_doStatusWork)
     {
         var elapsed = activeComponents[who].StatusWatch.ElapsedMilliseconds;
         if (elapsed > Properties.Settings.Default.Timeout)
         {
             //backup timeout
             if (activeComponents[who].ComponentType == ComponentType.CommunicationServer)
             {
                 continue;
             }
             Message deregister = new Register()
             {
                 Deregister          = true,
                 DeregisterSpecified = true,
                 Id          = (ulong)who,
                 IdSpecified = true
             };
             SynchronizationQueue.Enqueue(deregister);
             Log.DebugFormat("TIMEOUT of {0}. Deregistering.", activeComponents[who].ComponentType);
             DataSetOps.HandleClientMalfunction(activeComponents, who, dataSets);
             activeComponents.Remove(who);
             return;
         }
         Thread.Sleep((int)Properties.Settings.Default.Timeout);
     }
 }
示例#5
0
 protected override void ProcessDivideProblemMessage(DivideProblem message,
                                                     IDictionary <int, ProblemDataSet> dataSets,
                                                     IDictionary <int, ActiveComponent> activeComponents)
 {
     WriteControlInformation(message);
     DataSetOps.HandleDivideProblem(message, dataSets);
 }
        public void DataSetCompNodeFailureNextCompNodeWork()
        {
            var comps = new Dictionary <int, ActiveComponent>();

            comps.Add(1, new ActiveComponent()
            {
                ComponentType    = ComponentType.ComputationalNode,
                SolvableProblems = new[] { "abc" }
            });
            comps.Add(2, new ActiveComponent()
            {
                ComponentType    = ComponentType.ComputationalNode,
                SolvableProblems = new[] { "abc" }
            });

            var dict  = new Dictionary <int, ProblemDataSet>();
            var bytes = new byte[1] {
                1
            };

            dict.Add(1,
                     new ProblemDataSet()
            {
                CommonData    = bytes,
                TaskManagerId = 1,
                ProblemType   = "abc",
                PartialSets   = new[]
                {
                    new PartialSet()
                    {
                        PartialProblem  = new SolvePartialProblemsPartialProblem(),
                        PartialSolution = null,
                        Status          = PartialSetStatus.Fresh
                    }
                }
            });
            var ret = DataSetOps.GetMessageForCompNode(comps, 1, dict);

            Assert.AreEqual(typeof(SolvePartialProblems), ret.GetType());

            DataSetOps.HandleClientMalfunction(comps, 1, dict);

            var ret2 = DataSetOps.GetMessageForCompNode(comps, 2, dict);

            Assert.AreEqual(typeof(SolvePartialProblems), ret2.GetType());
            var msg = ret2.Cast <SolvePartialProblems>();

            Assert.AreEqual(1, msg.PartialProblems.Length);
            Assert.AreEqual(1, msg.CommonData.Length);
            Assert.AreEqual(1, msg.CommonData[0]);
            Assert.AreEqual(2, dict[1].PartialSets[0].NodeId);
        }
示例#7
0
        protected override Message[] RespondSolutionRequestMessage(SolutionRequest message,
                                                                   IDictionary <int, ProblemDataSet> dataSets,
                                                                   IDictionary <int, ActiveComponent> activeComponents, List <BackupServerInfo> backups)
        {
            //sent by client node. send NoOperation + CaseExtractor.GetSolutionState
            var solutionState = DataSetOps.GetSolutionState(message, dataSets);

            if (solutionState == null)
            {
                return(new Message[] { new NoOperation()
                                       {
                                           BackupServersInfo = backups.ToArray()
                                       } });
            }

            return(new Message[] { solutionState, new NoOperation()
                                   {
                                       BackupServersInfo = backups.ToArray()
                                   } });
        }
        public void DataSetTaskManagerFailureNextTaskManagerWork()
        {
            var comps = new Dictionary <int, ActiveComponent>();

            comps.Add(1, new ActiveComponent()
            {
                ComponentType    = ComponentType.TaskManager,
                SolvableProblems = new[] { "abc" }
            });
            comps.Add(2, new ActiveComponent()
            {
                ComponentType    = ComponentType.TaskManager,
                SolvableProblems = new [] { "abc" }
            });
            var dict  = new Dictionary <int, ProblemDataSet>();
            var bytes = new byte[1] {
                1
            };

            dict.Add(1,
                     new ProblemDataSet()
            {
                CommonData    = bytes,
                TaskManagerId = 0,
                ProblemType   = "abc"
            });
            var ret = DataSetOps.GetMessageForTaskManager(comps, 1, dict);

            Assert.AreEqual(typeof(DivideProblem), ret.GetType());

            DataSetOps.HandleClientMalfunction(comps, 1, dict);

            var ret2 = DataSetOps.GetMessageForTaskManager(comps, 2, dict);

            Assert.AreEqual(typeof(DivideProblem), ret2.GetType());
            var msg2 = ret.Cast <DivideProblem>();

            Assert.AreEqual(1, msg2.Data.Length);
            Assert.AreEqual(1, msg2.Data[0]);
            Assert.AreEqual(2, dict[1].TaskManagerId);
        }
        public void DataSetSolutionsForTaskManager()
        {
            var comps = new Dictionary <int, ActiveComponent>();

            comps.Add(1, new ActiveComponent()
            {
                ComponentType    = ComponentType.TaskManager,
                SolvableProblems = new[] { "abc" }
            });
            var dict  = new Dictionary <int, ProblemDataSet>();
            var bytes = new byte[1] {
                1
            };

            dict.Add(1,
                     new ProblemDataSet()
            {
                CommonData    = bytes,
                TaskManagerId = 1,
                ProblemType   = "abc",
                PartialSets   = new []
                {
                    new PartialSet()
                    {
                        PartialProblem  = new SolvePartialProblemsPartialProblem(),
                        PartialSolution = new SolutionsSolution(),
                        Status          = PartialSetStatus.Ongoing
                    }
                }
            });
            var ret = DataSetOps.GetMessageForTaskManager(comps, 1, dict);

            Assert.AreEqual(typeof(Solutions), ret.GetType());
            var msg = ret.Cast <Solutions>();

            Assert.AreEqual(1, msg.SolutionsList.Length);
            Assert.AreEqual(1, msg.CommonData.Length);
            Assert.AreEqual(1, msg.CommonData[0]);
        }
        public void DataSetFinalSolutionState()
        {
            var dict  = new Dictionary <int, ProblemDataSet>();
            var bytes = new byte[1] {
                1
            };

            dict.Add(1,
                     new ProblemDataSet()
            {
                CommonData    = bytes,
                TaskManagerId = 1,
                ProblemType   = "abc",
                PartialSets   = new[]
                {
                    new PartialSet()
                    {
                        PartialProblem  = new SolvePartialProblemsPartialProblem(),
                        PartialSolution = new SolutionsSolution()
                        {
                            Type = SolutionsSolutionType.Final
                        },
                        Status = PartialSetStatus.Sent
                    }
                }
            });
            var ret = DataSetOps.GetSolutionState(new SolutionRequest()
            {
                Id = 1
            }, dict);

            Assert.AreEqual(typeof(Solutions), ret.GetType());
            var msg = ret.Cast <Solutions>();

            Assert.AreEqual(1, msg.SolutionsList.Length);
            Assert.AreEqual(SolutionsSolutionType.Final, msg.SolutionsList[0].Type);
        }
        public void DataSetMultipleProblemsTest()
        {
            var comps = new Dictionary <int, ActiveComponent>();

            comps.Add(1, new ActiveComponent()
            {
                ComponentType    = ComponentType.ComputationalNode,
                SolvableProblems = new[] { "abc" }
            });
            comps.Add(2, new ActiveComponent()
            {
                ComponentType    = ComponentType.ComputationalNode,
                SolvableProblems = new[] { "abc" }
            });

            var dict  = new Dictionary <int, ProblemDataSet>();
            var bytes = new byte[1] {
                1
            };

            dict.Add(1,
                     new ProblemDataSet()
            {
                CommonData    = bytes,
                TaskManagerId = 1,
                ProblemType   = "abc",
                PartialSets   = new[]
                {
                    new PartialSet()
                    {
                        PartialProblem  = new SolvePartialProblemsPartialProblem(),
                        PartialSolution = null,
                        Status          = PartialSetStatus.Fresh
                    }
                }
            });
            dict.Add(2,
                     new ProblemDataSet()
            {
                CommonData    = bytes,
                TaskManagerId = 1,
                ProblemType   = "abc",
                PartialSets   = new[]
                {
                    new PartialSet()
                    {
                        PartialProblem  = new SolvePartialProblemsPartialProblem(),
                        PartialSolution = null,
                        Status          = PartialSetStatus.Fresh
                    }
                }
            });
            var ret = DataSetOps.GetMessageForCompNode(comps, 1, dict);

            Assert.AreEqual(typeof(SolvePartialProblems), ret.GetType());
            Assert.AreEqual(1, dict[1].PartialSets[0].NodeId);

            var ret2 = DataSetOps.GetMessageForCompNode(comps, 2, dict);

            Assert.AreEqual(typeof(SolvePartialProblems), ret2.GetType());
            Assert.AreEqual(2, dict[2].PartialSets[0].NodeId);
        }
示例#12
0
        protected override Message[] RespondStatusMessage(Status message,
                                                          IDictionary <int, ProblemDataSet> dataSets,
                                                          IDictionary <int, ActiveComponent> activeComponents, List <BackupServerInfo> backups)
        {
            //if sent by TM - send NoOp + return from CaseExtractor.GetMessageForTaskManager
            //if sent by CN - send NoOp + return from CaseExtractor.GetMessageForCompNode
            var who = (int)message.Id;

            if (!activeComponents.ContainsKey(who))
            {
                return new Message[] { new Error()
                                       {
                                           ErrorMessage = "who are you?",
                                           ErrorType    = ErrorErrorType.UnknownSender
                                       } }
            }
            ;

            activeComponents[who].StatusWatch.Restart();

            Message whatToDo = null;

            Log.DebugFormat("Handling status message of {0}(id={1}). Searching for problems.",
                            activeComponents[who].ComponentType, who);
            switch (activeComponents[who].ComponentType)
            {
            case ComponentType.ComputationalNode:
                whatToDo = DataSetOps.GetMessageForCompNode(activeComponents, who, dataSets);

                break;

            case ComponentType.TaskManager:
                whatToDo = DataSetOps.GetMessageForTaskManager(activeComponents, who, dataSets);
                break;

            case ComponentType.CommunicationServer:
                var msgs = SynchronizationQueue.ToList();
                SynchronizationQueue = new ConcurrentQueue <Message>();
                msgs.Add(new NoOperation()
                {
                    BackupServersInfo = backups.ToArray()
                });
                return(msgs.ToArray());
            }

            var noop = new NoOperation()
            {
                BackupServersInfo = backups.ToArray()
            };

            if (whatToDo == null)
            {
                Log.DebugFormat("Nothing additional found for {0} (id={1})",
                                activeComponents[who].ComponentType, who);
                return(new Message[]
                {
                    noop
                });
            }
            Log.DebugFormat("Found problem ({0}) for {1} (id={2})",
                            whatToDo.MessageType, activeComponents[who].ComponentType, who);

            SynchronizationQueue.Enqueue(whatToDo);
            return(new[]
            {
                whatToDo,
                noop
            });
        }