Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
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
            });
        }