// [Timeout(60000)]
        public void SendActionToRemoteGrid()
        {
            // Arrange
            ActPlugIn actPlugin = new ActPlugIn()
            {
                ServiceId = "DummyService", ActionId = "A1"
            };

            //Act
            GingerNodeProxy.RemoteGridIP   = RemoteGridIP;   // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            GingerNodeProxy.RemoteGridPort = RemoteGridPort; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            GingerNodeInfo gingerNodeInfo = new GingerNodeInfo()
            {
            };
            GingerNodeProxy gingerNodeProxy = new GingerNodeProxy(gingerNodeInfo, true);

            NewPayLoad actionPayLoad = ExecuteOnPlugin.CreateActionPayload(actPlugin);
            NewPayLoad actionResult  = gingerNodeProxy.RunAction(actionPayLoad);

            ExecuteOnPlugin.ParseActionResult(actionResult, actPlugin);

            //Assert
            Assert.AreEqual(RemoteGingerGrid.NodeList.Count, 2);
            Assert.AreEqual("A1 Result", actPlugin.ExInfo);
        }
示例#2
0
        internal static void FindNodeAndRunAction(ActPlugIn act)
        {
            // If we have remote grid(s) then we go for remote run
            ObservableList <RemoteServiceGrid> remoteServiceGrids = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <RemoteServiceGrid>();

            if (remoteServiceGrids.Count > 0)
            {
                ExecuteActionOnRemotePlugin(act);
            }
            else
            {
                GingerNodeInfo GNI = null;
                try
                {
                    GNI = GetGingerNodeInfoForPluginAction((ActPlugIn)act);
                    if (GNI != null)
                    {
                        ExecuteActionOnPlugin((ActPlugIn)act, GNI);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    string errorMessage = "";
                    if (GNI == null)
                    {
                        errorMessage += "Cannot find GingerNodeInfo in service grid for: " + ((ActPlugIn)act).PluginId + ", Service " + ((ActPlugIn)act).ServiceId + Environment.NewLine;
                    }
                    errorMessage += "Error while executing Plugin Service action " + Environment.NewLine;
                    errorMessage += ex.Message;
                    act.Error     = errorMessage;
                }
            }
        }
示例#3
0
        private static GingerNodeInfo GetGingerNode(string ServiceId)
        {
            // TODO: create round robin algorithm or something smarter

            // Menahwile we can the first ready node with least amount of actions so balance across same service
            GingerGrid gingerGrid = WorkSpace.Instance.LocalGingerGrid;

            Console.WriteLine("Number of Nodes found in GingerGrid:" + gingerGrid.NodeList.Count);

            foreach (GingerNodeInfo gingerNodeInfo in gingerGrid.NodeList)
            {
                Console.WriteLine("Name:" + gingerNodeInfo.Name);
                Console.WriteLine("ServiceId:" + gingerNodeInfo.ServiceId);
                Console.WriteLine("Status:" + gingerNodeInfo.Status);
                Console.WriteLine("Host:" + gingerNodeInfo.Host);
                Console.WriteLine("IP:" + gingerNodeInfo.IP);
            }

            Console.WriteLine("Searching for ServiceID=" + ServiceId);

            GingerNodeInfo GNI = (from x in gingerGrid.NodeList
                                  where x.ServiceId == ServiceId &&
                                  x.Status == GingerNodeInfo.eStatus.Ready
                                  orderby x.ActionCount
                                  select x).FirstOrDefault();

            if (GNI is null)
            {
                Console.WriteLine("GNI is null");
            }

            return(GNI);
        }
示例#4
0
        public void Close()
        {
            try
            {
                if (AgentType == eAgentType.Service)
                {
                    if (mGingerNodeInfo != null)
                    {
                        // this is plugin driver
                        GingerNodeProxy GNP = new GingerNodeProxy(mGingerNodeInfo);
                        GNP.GingerGrid = WorkSpace.Instance.LocalGingerGrid;
                        GNP.CloseDriver();
                        if (mProcess != null)
                        {
                            // mProcess.Kill();
                            //mProcess.Close();
                            //GingerCore.General.DoEvents();
                            mProcess.CloseMainWindow();
                        }
                        mGingerNodeInfo = null;
                        // GNP.Shutdown();
                        return;
                    }
                }
                if (Driver == null)
                {
                    return;
                }

                Driver.IsDriverRunning = false;
                if (Driver.Dispatcher != null)
                {
                    Driver.Dispatcher.Invoke(() =>
                    {
                        Driver.CloseDriver();
                        Thread.Sleep(1000);
                    });
                }
                else
                {
                    Driver.CloseDriver();
                }

                if (MSTATask != null)
                {
                    // Using Cancelleation token soucrce to cancel
                    CancelTask         = new BackgroundWorker();
                    CancelTask.DoWork += new DoWorkEventHandler(CancelTMSTATask);
                    CancelTask.RunWorkerAsync();
                }

                Driver = null;
            }
            finally
            {
                OnPropertyChanged(Fields.Status);
                OnPropertyChanged(Fields.IsWindowExplorerSupportReady);
            }
        }
示例#5
0
        public void Execute(string PluginId, string ServiceId, NewPayLoad payLoad)
        {
            GingerGrid gingerGrid = WorkSpace.Instance.LocalGingerGrid;

            // string PID = GA.InputParams["PluginID"].GetValueAsString();
            PluginPackage p = (from x in mPluginPackages where x.PluginID == PluginId select x).SingleOrDefault();

            if (p == null)
            {
                throw new Exception("Plugin id not found: " + PluginId);
                // GA.AddError("Execute", "Plugin id not found: " + PID);
                // return;
            }

            //TODO: use nameof after ActPlugin move to common
            // string serviceID = GA.InputParams["PluginActionID"].GetValueAsString();


            GingerNodeInfo GNI = (from x in gingerGrid.NodeList where x.Name == p.PluginID select x).FirstOrDefault();

            //run script only if service is not up
            if (GNI == null)
            {
                string script = CommandProcessor.CreateLoadPluginScript(p.Folder);

                // hard coded!!!!!!!!!!  - use ServiceId
                script += CommandProcessor.CreateStartServiceScript("PACTService", p.PluginID, SocketHelper.GetLocalHostIP(), gingerGrid.Port);
                // script += CommandProcessor.CreateStartServiceScript("ExcelService", p.PluginID, SocketHelper.GetLocalHostIP(), gingerGrid.Port);


                Task t = new Task(() =>
                {
                    // GingerConsoleHelper.Execute(script);  // keep it for regular service dll load
                    string StarterDLL = Path.Combine(p.Folder, "GingerPACTPluginConsole.dll");
                    StartService(StarterDLL);
                });
                t.Start();
            }

            int counter = 0;

            while (GNI == null && counter < 30)
            {
                Thread.Sleep(1000);
                GNI = (from x in gingerGrid.NodeList where x.Name == "PACT" select x).FirstOrDefault();
                counter++;
            }
            if (GNI == null)
            {
                // GA.AddError("Execute", "Cannot execute action beacuse Service was not found or was not abale to start: " + p.PluginID);
            }

            GingerNodeProxy GNA = new GingerNodeProxy(GNI);

            GNA.Reserve();
            GNA.GingerGrid = gingerGrid;

            //GNA.RunAction(GA);
        }
示例#6
0
        internal static GingerNodeInfo GetGingerNodeInfoForPluginAction(ActPlugIn actPlugin)
        {
            GingerNodeInfo GNI = GetGingerNodeInfo(actPlugin.PluginId, actPlugin.ServiceId);

            if (GNI == null)
            {
                actPlugin.Error = "GNI not found, Timeout waiting for service to be available in GingerGrid";
            }

            return(GNI);
        }
示例#7
0
        public void Execute(GingerAction GA)
        {
            GingerGrid gingerGrid = WorkSpace.Instance.LocalGingerGrid;

            string        PID = GA.InputParams["PluginID"].GetValueAsString();
            PluginPackage p   = (from x in mPluginPackages where x.PluginID == PID select x).SingleOrDefault();

            if (p == null)
            {
                GA.AddError("Execute", "Plugin id not found: " + PID);
                return;
            }

            //TODO: use nameof after ActPlugin move to common
            string serviceID = GA.InputParams["PluginActionID"].GetValueAsString();

            GingerNodeInfo GNI = (from x in gingerGrid.NodeList where x.Name == p.PluginID select x).FirstOrDefault();

            //run script only if service is not up
            if (GNI == null)
            {
                string script = CommandProcessor.CreateLoadPluginScript(p.Folder);

                // hard coded!!!!!!!!!!
                script += CommandProcessor.CreateStartServiceScript("ExcelService", p.PluginID, SocketHelper.GetLocalHostIP(), gingerGrid.Port);

                Task t = new Task(() =>
                {
                    GingerConsoleHelper.Execute(script);
                });
                t.Start();
            }

            int counter = 0;

            while (GNI == null && counter < 30)
            {
                Thread.Sleep(1000);
                GNI = (from x in gingerGrid.NodeList where x.Name == p.PluginID select x).FirstOrDefault();
                counter++;
            }


            GingerNodeProxy GNA = new GingerNodeProxy(GNI);

            GNA.Reserve();
            GNA.GingerGrid = gingerGrid;

            GNA.RunAction(GA);
        }
示例#8
0
        public static void ExecuteActionOnRemotePlugin(ActPlugIn actPlugin)
        {
            NewPayLoad p = CreateActionPayload(actPlugin);


            string            serviceID         = actPlugin.ServiceId;
            RemoteServiceGrid remoteServiceGrid = FindRemoteGrid(actPlugin.ServiceId);



            // Temp !!!!!!!!!!!!!!!!! change to get GingerNodePorxy for Remote grid
            GingerNodeInfo  gingerNodeInfo  = new GingerNodeInfo();
            GingerNodeProxy gingerNodeProxy = new GingerNodeProxy(gingerNodeInfo, true);
            NewPayLoad      RC = gingerNodeProxy.RunAction(p);
        }
示例#9
0
        // Use for Actions which run without agent and are of the generic type ActPlugin -
        public static void ExecuteActionOnPlugin(ActPlugIn actPlugin, GingerNodeInfo gingerNodeInfo)
        {
            try
            {
                // first verify we have service ready or start service

                Stopwatch       st = Stopwatch.StartNew();
                GingerNodeProxy gingerNodeProxy = WorkSpace.Instance.LocalGingerGrid.GetNodeProxy(gingerNodeInfo);  // FIXME for remote grid

                //!!!!!!!!!!!!! TODO: check if null set err

                NewPayLoad p  = CreateActionPayload(actPlugin);
                NewPayLoad RC = gingerNodeProxy.RunAction(p);

                // release the node as soon as the result came in
                bool IsSessionService = WorkSpace.Instance.PlugInsManager.IsSessionService(actPlugin.PluginId, gingerNodeInfo.ServiceId);
                if (!IsSessionService)
                {
                    // standalone plugin action release the node
                    gingerNodeInfo.Status = GingerNodeInfo.eStatus.Ready;
                }
                ParseActionResult(RC, actPlugin);

                gingerNodeInfo.IncreaseActionCount();

                st.Stop();
                long millis = st.ElapsedMilliseconds;
                actPlugin.ExInfo += "Elapsed: " + millis + "ms";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                string errorMessage = "";
                if (gingerNodeInfo == null)
                {
                    errorMessage += "Cannot find GingerNodeInfo in service grid for: " + ((ActPlugIn)actPlugin).PluginId + ", Service " + ((ActPlugIn)actPlugin).ServiceId + Environment.NewLine;
                }
                errorMessage   += "Error while executing Plugin Service action " + Environment.NewLine;
                errorMessage   += ex.Message;
                actPlugin.Error = errorMessage;
            }
        }
        public void SendActionToRemoteGridOnProcess()
        {
            // TODO: start the service batch + plugin to connect, for now we use manual bat file for testing

            // Arrange
            ActPlugIn actPlugin = new ActPlugIn()
            {
                ServiceId = "DummyService", ActionId = "Sum"
            };

            actPlugin.GetOrCreateInputParam("a").Value     = "4";
            actPlugin.GetOrCreateInputParam("a").ParamType = typeof(int);
            actPlugin.GetOrCreateInputParam("b").Value     = "3";
            actPlugin.GetOrCreateInputParam("b").ParamType = typeof(int);

            //Act
            GingerNodeProxy.RemoteGridIP   = RemoteGridIP; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            GingerNodeProxy.RemoteGridPort = 15555;        // RemoteGridPort; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

            GingerNodeInfo gingerNodeInfo = new GingerNodeInfo()
            {
            };
            GingerNodeProxy gingerNodeProxy = new GingerNodeProxy(gingerNodeInfo, true);

            NewPayLoad actionPayLoad = ExecuteOnPlugin.CreateActionPayload(actPlugin);

            for (int i = 0; i < 1000; i++)
            {
                NewPayLoad actionResult = gingerNodeProxy.RunAction(actionPayLoad);
                ExecuteOnPlugin.ParseActionResult(actionResult, actPlugin);
            }

            //Assert
            Assert.AreEqual(RemoteGingerGrid.NodeList.Count, 2);
            // Assert.AreEqual("A1 Result", actPlugin.ExInfo);
        }
示例#11
0
        public void Close()
        {
            try
            {
                if (Agent.AgentType == Agent.eAgentType.Service)
                {
                    if (gingerNodeInfo != null)
                    {
                        // this is plugin driver on local machine

                        GingerNodeProxy.GingerGrid = WorkSpace.Instance.LocalGingerGrid;
                        GingerNodeProxy.CloseDriver();


                        gingerNodeInfo.Status = GingerNodeInfo.eStatus.Ready;


                        if (mProcess != null) // it means a new plugin process was started for this agent - so we close it
                        {
                            // Remove the node from the grid
                            WorkSpace.Instance.LocalGingerGrid.NodeList.Remove(gingerNodeInfo);

                            // Close the plugin process
                            mProcess.CloseMainWindow();
                        }

                        GingerNodeProxy = null;
                        gingerNodeInfo  = null;

                        return;
                    }
                    else
                    {
                        if (GingerNodeProxy != null)
                        {
                            // Running on Remote Grid
                            GingerNodeProxy.CloseDriver();
                            GingerNodeProxy.Disconnect();
                            GingerNodeProxy = null;
                        }
                    }
                }
                if (Driver == null)
                {
                    return;
                }

                Driver.IsDriverRunning = false;
                if (Driver is IDriverWindow && ((IDriverWindow)Driver).ShowWindow)
                {
                    DriversWindowUtils.OnDriverWindowEvent(DriverWindowEventArgs.eEventType.CloseDriverWindow, Driver, this);
                    Driver.CloseDriver();
                }
                else if (Driver.Dispatcher != null)
                {
                    Driver.Dispatcher.Invoke(() =>
                    {
                        Driver.CloseDriver();
                        Thread.Sleep(1000);
                    });
                }
                else
                {
                    Driver.CloseDriver();
                }
                if (MSTATask != null)
                {
                    // Using cancellation token source to cancel
                    CancelTask         = new BackgroundWorker();
                    CancelTask.DoWork += new DoWorkEventHandler(Agent.CancelTMSTATask);
                    CancelTask.RunWorkerAsync();
                }

                Driver = null;
            }
            finally
            {
                Agent.OnPropertyChanged(nameof(AgentOperations.Status));
                Agent.OnPropertyChanged(nameof(AgentOperations.IsWindowExplorerSupportReady));
            }
        }
示例#12
0
文件: Agent.cs 项目: csuffyy/Ginger
        public void Close()
        {
            try
            {
                if (AgentType == eAgentType.Service)
                {
                    if (gingerNodeInfo != null)
                    {
                        // this is plugin driver

                        GingerNodeProxy.GingerGrid = WorkSpace.Instance.LocalGingerGrid;
                        GingerNodeProxy.CloseDriver();


                        gingerNodeInfo.Status = GingerNodeInfo.eStatus.Ready;


                        if (mProcess != null) // it means a new plugin process was started for this agent - so we close it
                        {
                            // Remove the node from the grid
                            WorkSpace.Instance.LocalGingerGrid.NodeList.Remove(gingerNodeInfo);

                            // Close the plugin process
                            mProcess.CloseMainWindow();
                        }

                        GingerNodeProxy = null;
                        gingerNodeInfo  = null;

                        return;
                    }
                }
                if (Driver == null)
                {
                    return;
                }

                Driver.IsDriverRunning = false;
                if (Driver.Dispatcher != null)
                {
                    Driver.Dispatcher.Invoke(() =>
                    {
                        Driver.CloseDriver();
                        Thread.Sleep(1000);
                    });
                }
                else
                {
                    Driver.CloseDriver();
                }

                if (MSTATask != null)
                {
                    // Using cancellation token source to cancel
                    CancelTask         = new BackgroundWorker();
                    CancelTask.DoWork += new DoWorkEventHandler(CancelTMSTATask);
                    CancelTask.RunWorkerAsync();
                }

                Driver = null;
            }
            finally
            {
                OnPropertyChanged(Fields.Status);
                OnPropertyChanged(Fields.IsWindowExplorerSupportReady);
            }
        }
示例#13
0
        public void ParallelRunTest()
        {
            //Arrange
            ActPlugIn a1 = new ActPlugIn()
            {
                ActionId = "A1"
            };
            ActPlugIn a2 = new ActPlugIn()
            {
                ActionId = "A1"
            };
            ActPlugIn a3 = new ActPlugIn()
            {
                ActionId = "A1"
            };
            ActPlugIn a4 = new ActPlugIn()
            {
                ActionId = "A1"
            };
            ActPlugIn a5 = new ActPlugIn()
            {
                ActionId = "A1"
            };

            ActPlugIn b1 = new ActPlugIn()
            {
                ActionId = "A1"
            };
            ActPlugIn b2 = new ActPlugIn()
            {
                ActionId = "A1"
            };
            ActPlugIn b3 = new ActPlugIn()
            {
                ActionId = "A1"
            };
            ActPlugIn b4 = new ActPlugIn()
            {
                ActionId = "A1"
            };
            ActPlugIn b5 = new ActPlugIn()
            {
                ActionId = "A1"
            };


            // Act

            // We run on 2 drivers in parralel
            Task t1 = Task.Factory.StartNew(() =>
            {
                GingerNodeInfo GNI1  = GG.NodeList[0];
                GingerNodeProxy GNP1 = new GingerNodeProxy(GNI1);
                GNP1.GingerGrid      = GG;

                GNP1.Reserve();
                GNP1.StartDriver();

                RunAction(a1, GNP1);
                RunAction(a2, GNP1);
                RunAction(a3, GNP1);
                RunAction(a4, GNP1);
                RunAction(a5, GNP1);


                GNP1.CloseDriver();
            });

            Task t2 = Task.Factory.StartNew(() =>
            {
                GingerNodeInfo GNI2  = GG.NodeList[1];
                GingerNodeProxy GNP2 = new GingerNodeProxy(GNI2);
                GNP2.GingerGrid      = GG;

                GNP2.Reserve();
                GNP2.StartDriver();

                RunAction(b1, GNP2);
                RunAction(b2, GNP2);
                RunAction(b3, GNP2);
                RunAction(b4, GNP2);
                RunAction(b5, GNP2);

                GNP2.CloseDriver();
            });

            t1.Wait();
            t2.Wait();


            // Assert
            Assert.AreEqual(a1.Error, null);
            Assert.AreEqual(a1.ExInfo, "A1 Result");

            Assert.AreEqual(a2.Error, null);
            Assert.AreEqual(a2.ExInfo, "A1 Result");

            Assert.AreEqual(a3.Error, null);
            Assert.AreEqual(a3.ExInfo, "A1 Result");

            Assert.AreEqual(a4.Error, null);
            Assert.AreEqual(a4.ExInfo, "A1 Result");

            Assert.AreEqual(a5.Error, null);
            Assert.AreEqual(a5.ExInfo, "A1 Result");

            Assert.AreEqual(b1.Error, null);
            Assert.AreEqual(b1.ExInfo, "A1 Result");

            Assert.AreEqual(b2.Error, null);
            Assert.AreEqual(b2.ExInfo, "A1 Result");

            Assert.AreEqual(b3.Error, null);
            Assert.AreEqual(b3.ExInfo, "A1 Result");

            Assert.AreEqual(b4.Error, null);
            Assert.AreEqual(b4.ExInfo, "A1 Result");

            Assert.AreEqual(b5.Error, null);
            Assert.AreEqual(b5.ExInfo, "A1 Result");
        }