Beispiel #1
0
        /// <summary>
        /// Start service on node and connect to local GingerGrid
        /// </summary>
        /// <param name="gingerServiceObject">Service object with [GingerService] annotation</param>
        /// <param name="name">Name which will apear in GingerGrid</param>
        public void StartNode(string name, object gingerServiceObject)
        {
            GingerNode gingerNode = new GingerNode(gingerServiceObject);

            gingerNode.StartGingerNode(name, SocketHelper.GetLocalHostIP(), 15004);   // !!!!!!!!!!!!!!!! Get free port, but prefer 15001 if free
            CheckAddGingerNode(gingerNode);
        }
Beispiel #2
0
        public static void ClassInitialize(TestContext TestContext)
        {
            // We start a Ginger grid
            int HubPort = SocketHelper.GetOpenPort();

            GG = new GingerGrid(HubPort);
            GG.Start();

            // Add 2 Ginger Nodes with Dummy Driver
            DummyDriver DummyDriver1 = new DummyDriver();

            Task.Factory.StartNew(() => {
                GingerNodeStarter gingerNodeStarter = new GingerNodeStarter();
                gingerNodeStarter.StartNode("N1", new DummyDriver(), SocketHelper.GetLocalHostIP(), HubPort);
                gingerNodeStarter.StartNode("N2", new DummyDriver(), SocketHelper.GetLocalHostIP(), HubPort);
                gingerNodeStarter.Listen();
            });

            Stopwatch stopwatch = Stopwatch.StartNew();

            while (GG.NodeList.Count < 2 && stopwatch.ElapsedMilliseconds < 5000)  // max 5 seconds
            {
                Thread.Sleep(50);
            }
        }
Beispiel #3
0
        public static void ClassInitialize(TestContext TestContext)
        {
            // We start a Ginger grid
            int HubPort = SocketHelper.GetOpenPort();

            GG = new GingerGrid(HubPort);
            GG.Start();

            // Add 2 Ginger Nodes with Dummy Driver

            // TODO: check how to externalize  // make it NodeInfo and drivers capabilities
            DummyDriver        DummyDriver1 = new DummyDriver();
            DriverCapabilities DC           = new DriverCapabilities();

            DC.OS       = "Windows"; //TODO: use const
            DC.Platform = "Web";     //TODO: use const
            GingerNode GN = new GingerNode(DC, DummyDriver1);

            GN.StartGingerNode("N1", HubIP: SocketHelper.GetLocalHostIP(), HubPort: HubPort);


            DummyDriver        DummyDriver2 = new DummyDriver();
            DriverCapabilities DC2          = new DriverCapabilities();

            DC2.OS       = "Mac";
            DC2.Platform = "Java";
            GingerNode GingerNode2 = new GingerNode(DC2, DummyDriver2);

            GingerNode2.StartGingerNode("N2", HubIP: SocketHelper.GetLocalHostIP(), HubPort: HubPort);
        }
Beispiel #4
0
            public void Connect()
            {
                mGingerSocketClient2 = new GingerSocketClient2();
                mGingerSocketClient2.MessageHandler = MessageHandler;

                IPAddress ipAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);

                mGingerSocketClient2.Connect(SocketHelper.GetLocalHostIP(), mMyGingerServer.ServerPort);
            }
Beispiel #5
0
        private string CreateNodeConfigFile(string name, string serviceId)
        {
            ServiceCounter++;
            string NewName  = name + " " + ServiceCounter; // We add counter since this is auto start service and many can start so to identify
            string txt      = NewName + " | " + serviceId + " | " + SocketHelper.GetLocalHostIP() + " | " + WorkSpace.Instance.LocalGingerGrid.Port + Environment.NewLine;
            string fileName = Path.GetTempFileName();

            File.WriteAllText(fileName, txt);
            return(fileName);
        }
Beispiel #6
0
        void AddRemoteGrid()
        {
            // TODO: createWizard
            RemoteServiceGrid remoteServiceGrid = new RemoteServiceGrid()
            {
                Name = "Remote Grid 1", Host = SocketHelper.GetLocalHostIP(), HostPort = 15555, Active = true
            };

            WorkSpace.Instance.SolutionRepository.AddRepositoryItem(remoteServiceGrid);
        }
Beispiel #7
0
        Agent prep()
        {
            mGingerGrid = WorkSpace.Instance.LocalGingerGrid;

            // Start one DummyDriver - in process, so we can test whats going on everywhere
            mDummyDriver = new DummyDriver();
            GingerNode gingerNode = new GingerNode(mDummyDriver);

            gingerNode.StartGingerNode("N1", HubIP: SocketHelper.GetLocalHostIP(), HubPort: mGingerGrid.Port);

            // Wait for the Grid to be up and the node connected
            // max 30 seconds
            Stopwatch st = Stopwatch.StartNew();

            while (!gingerNode.Connected && st.ElapsedMilliseconds < 30000)
            {
                Thread.Sleep(100);
            }
            if (!gingerNode.Connected)
            {
                throw new Exception(">>>>>>>>>>>>>>>> GingerNode didn't connect to grid <<<<<<<<<<<<<<<<<<<<< " + mPluginId + "." + mServiceId);
            }

            st.Restart();

            while (mGingerGrid.NodeList.Count == 0 && st.ElapsedMilliseconds < 30000)
            {
                Thread.Sleep(100);
            }

            if (mGingerGrid.NodeList.Count == 0)
            {
                throw new Exception(">>>>>>>>>>>>>>>> NodeList count =0, no node connected <<<<<<<<<<<<<<<<<<<<< " + mPluginId + "." + mServiceId);
            }

            WorkSpace.Instance.PlugInsManager.PluginServiceIsSeesionDictionary.Add(mPluginId + "." + mServiceId, true);


            //TODO: handle no GG node found

            Agent agent = new Agent();

            agent.Name      = "agent 1";
            agent.AgentType = Agent.eAgentType.Service;
            agent.PluginId  = mPluginId;
            agent.ServiceId = mServiceId;

            mGingerRunner = new GingerRunner();
            mGingerRunner.ApplicationAgents.Add(new ApplicationAgent()
            {
                AppName = cWebApp, Agent = agent
            });

            return(agent);
        }
Beispiel #8
0
        public static string CreateNodeConfigFile(string name)
        {
            string txt = "Name=" + name + Environment.NewLine;

            txt += "GingerGridHost=" + SocketHelper.GetLocalHostIP() + Environment.NewLine;
            txt += "GingerGridPort=" + WorkSpace.Instance.LocalGingerGrid.Port + Environment.NewLine;
            string fileName = Path.GetTempFileName();

            File.WriteAllText(fileName, txt);
            return(fileName);
        }
Beispiel #9
0
        public static void ClassInit(TestContext context)
        {
            mGingerSocketClient = new GingerSocketClient();

            mGingerSocketServer          = new GingerSocketServer();
            mGingerSocketServer.Message += mGingerSocketServer_Message;

            int ServerPort = SocketHelper.GetOpenPort();

            mGingerSocketServer.StratServer(ServerPort);
            mGingerSocketClient.Connect(SocketHelper.GetLocalHostIP(), ServerPort);
        }
Beispiel #10
0
        public void StartGingerNode(string Name, string HubIP, int HubPort)
        {
            Console.WriteLine("Starting Ginger Node");
            Console.WriteLine("ServiceID: " + mServiceID);

            string Domain      = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
            string IP          = SocketHelper.GetLocalHostIP();
            string MachineName = System.Environment.MachineName;
            string OSVersion   = System.Environment.OSVersion.ToString();

            //TODO: first register at the hub
            mHubClient = new GingerSocketClient2();
            mHubClient.MessageHandler = HubClientMessageHandler;

            Console.WriteLine("Connecting to Ginger Grid Hub: " + HubIP + ":" + HubPort);
            mHubClient.Connect(HubIP, HubPort);
            if (!mHubClient.IsConnected)
            {
                return;
            }
            Console.WriteLine("Connected!");
            Console.WriteLine("Registering Ginger node");
            //Register the service in GG
            NewPayLoad PLRegister = new NewPayLoad(SocketMessages.Register);

            PLRegister.AddValue(Name);
            PLRegister.AddValue(mServiceID);
            PLRegister.AddValue(OSVersion);
            PLRegister.AddValue(MachineName);
            PLRegister.AddValue(IP);
            PLRegister.ClosePackage();
            NewPayLoad RC = mHubClient.SendRequestPayLoad(PLRegister);

            if (RC.Name == "SessionID")
            {
                mSessionID = RC.GetGuid();
                Console.WriteLine("Ginger Node started SessionID - " + mSessionID);
                if (GingerNodeMessage != null)
                {
                    GingerNodeMessage.Invoke(this, eGingerNodeEventType.Started);
                }
            }
            else
            {
                throw new Exception("Unable to find Ginger Grid at: " + HubIP + ":" + HubPort);
            }
        }
Beispiel #11
0
        public static void ClassInitialize(TestContext TestContext)
        {
            // We start a Ginger grid on open port
            int GingerHubPort = SocketHelper.GetOpenPort();

            GG = new GingerGrid(GingerHubPort);
            GG.Start();

            // Add 2 Ginger Nodes with Dummy Driver
            DummyDriver DummyDriver1 = new DummyDriver();
            GingerNode  GN           = new GingerNode(DummyDriver1);

            GN.StartGingerNode("N1", HubIP: SocketHelper.GetLocalHostIP(), HubPort: GingerHubPort);

            DummyDriver DummyDriver2 = new DummyDriver();
            GingerNode  GingerNode2  = new GingerNode(DummyDriver2);

            GingerNode2.StartGingerNode("N2", HubIP: SocketHelper.GetLocalHostIP(), HubPort: GingerHubPort);
        }
        public static void ClassInit(TestContext context)
        {
            Reporter.WorkSpaceReporter = new UnitTestWorkspaceReporter();

            int port = SocketHelper.GetOpenPort();

            // gingerGrid = WorkSpace.Instance.LocalGingerGrid; // new GingerGrid(port);
            gingerGrid = new GingerGrid(port);
            gingerGrid.Start();

            // WorkSpace.Instance.LocalGingerGrid = gingerGrid;

            webPlatform = new WebPlatformServiceFake();
            gingerNode  = new GingerNode(webPlatform);
            gingerNode.StartGingerNode("WebPlatformServiceFake 1", SocketHelper.GetLocalHostIP(), port);

            // Wait for node to be connected.

            gingerNodeProxy            = new GingerNodeProxy(gingerGrid.NodeList[0]);
            gingerNodeProxy.GingerGrid = gingerGrid;

            // GingerRunner gingerRunner = new GingerRunner();
            agent = new Agent();
            agent.GingerNodeProxy = gingerNodeProxy;
            agent.Platform        = GingerCoreNET.SolutionRepositoryLib.RepositoryObjectsLib.PlatformsLib.ePlatformType.Service;
            // agent.PluginId = "aa";
            agent.ServiceId           = "WebPlatformServiceFake";
            agent.AgentType           = Agent.eAgentType.Service;
            agent.DriverConfiguration = new Amdocs.Ginger.Common.ObservableList <DriverConfigParam>();

            //agent.st
            // agent.StartDriver();
            gingerNodeProxy.StartDriver(agent.DriverConfiguration);



            mGR = new GingerRunner();
            mGR.CurrentSolution = new Ginger.SolutionGeneral.Solution();
            mBF            = new BusinessFlow();
            mBF.Activities = new ObservableList <Activity>();
            mBF.Name       = "BF Test Java Driver";
            Platform p = new Platform();

            p.PlatformType = ePlatformType.Web;
            mBF.TargetApplications.Add(new TargetApplication()
            {
                AppName = "TestApp"
            });
            Activity activity = new Activity();

            activity.TargetApplication = "JavaTestApp";
            mBF.Activities.Add(activity);
            mBF.CurrentActivity     = activity;
            mGR.CurrentBusinessFlow = mBF;


            ApplicationAgent AA = new ApplicationAgent();

            AA.AppName = "JavaTestApp";
            AA.Agent   = agent;

            mGR.ApplicationAgents.Add(AA);
            mGR.SetCurrentActivityAgent();
        }
        static void Main(string[] args)
        {
            Console.Title = "MSAccess Database plugin";
            Console.WriteLine("Starting MSAccess Database Plugin");

            using (GingerNodeStarter gingerNodeStarter = new GingerNodeStarter())
            {
                if (args.Length > 0)
                {
                    gingerNodeStarter.StartFromConfigFile(args[0]);  // file name
                }
                else
                {
                    gingerNodeStarter.StartNode("MSAccess Service 1", new MSAccessDBCon(), SocketHelper.GetLocalHostIP(), 15001);
                }
                gingerNodeStarter.Listen();
            }
        }
Beispiel #14
0
        public void StartGingerNode(string Name, string HubIP, int HubPort)
        {
            Console.WriteLine("Starting Ginger Node");
            Console.WriteLine("ServiceID: " + mServiceID);

            string Domain      = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
            string IP          = SocketHelper.GetLocalHostIP();
            string MachineName = System.Environment.MachineName;
            string OSVersion   = System.Environment.OSVersion.ToString();

            //TODO: first register at the hub
            mHubClient = new GingerSocketClient2();
            mHubClient.MessageHandler = HubClientMessageHandler;

            // We have retry mechanism
            bool IsConnected = false;
            int  count       = 0;

            while (!IsConnected)
            {
                try
                {
                    Console.WriteLine("Connecting to Ginger Grid Hub: " + HubIP + ":" + HubPort);
                    mHubClient.Connect(HubIP, HubPort);
                    IsConnected = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Connection failed: " + ex.Message);
                    Console.WriteLine("Will retry in 5 seconds");
                    Thread.Sleep(5000);
                    count++;
                    if (count > 50) //TODO: Change it to stop watch wait for 60 seconds, or based on config
                    {
                        Console.WriteLine("All connection attempts failed, exiting");
                        return;
                    }
                }
            }

            //Register the service in GG
            NewPayLoad PLRegister = new NewPayLoad(SocketMessages.Register);

            PLRegister.AddValue(Name);
            PLRegister.AddValue(mServiceID);
            PLRegister.AddValue(OSVersion);   // TODO: translate to normal name?
            PLRegister.AddValue(MachineName); // TODO: if local host write local host
            PLRegister.AddValue(IP);

            PLRegister.ClosePackage();
            NewPayLoad RC = mHubClient.SendRequestPayLoad(PLRegister);

            //TODO: we can disconnect from hub, make Register/Unregister a function

            if (RC.Name == "SessionID")
            {
                mSessionID = RC.GetGuid();
                Console.WriteLine("Ginger Node started SessionID - " + mSessionID);
                if (GingerNodeMessage != null)
                {
                    GingerNodeMessage.Invoke(this, eGingerNodeEventType.Started);
                }
            }
            else
            {
                throw new Exception("Unable to find Ginger Grid at: " + HubIP + ":" + HubPort);
            }
        }
Beispiel #15
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);
        }
Beispiel #16
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);
        }