Пример #1
0
            public void AddPuppetMaster(PuppetMasterService service)
            {
                String key = "";

                try {
                    service.ProbeObject();
                    key = service.ServiceURL;
                } catch (Exception) {
                    return;
                }
                IList <String> brokenServices = new List <String>();

                if (!puppetMastersList.Any((KeyValuePair <String, PuppetMasterService> s) => {
                    try {
                        s.Value.ProbeObject();
                        return(s.Value.ServiceURL == service.ServiceURL);
                    } catch (Exception) {
                        brokenServices.Add(s.Key);
                    }
                    return(false);
                }))
                {
                    puppetMastersList.Add(key, service);
                }

                foreach (String k in brokenServices)
                {
                    puppetMastersList.Remove(k);
                }
            }
Пример #2
0
        private void startPuppetMasterService()
        {
            int         port = Convert.ToInt32(portnum);
            IDictionary RemoteChannelProperties = new Dictionary <string, string>();

            RemoteChannelProperties["name"] = "PuppetMasterChannel";
            RemoteChannelProperties["port"] = port.ToString();
            TcpChannel channel = new TcpChannel(RemoteChannelProperties, null, null);

            ChannelServices.RegisterChannel(channel, true);


            pms     = new PuppetMasterService();
            pms.Gui = this;
            objRef  = RemotingServices.Marshal(pms, Common.Constants.PUPPET_MASTER_SERVICE_NAME, typeof(PuppetMasterService));

            /*
             * RemotingConfiguration.RegisterWellKnownServiceType(
             *   typeof(PuppetMasterService),
             *   service,
             *   WellKnownObjectMode.Singleton);
             */

            string service_string = "tcp://" + getIPAddress() + ":" + port + "/" + Common.Constants.PUPPET_MASTER_SERVICE_NAME;

            show("Started " + service_string);
        }
Пример #3
0
 private void AddPuppetMaster(PuppetMasterService pm)
 {
     if (pm == null)
     {
         return;
     }
     manager.AddPuppetMaster(pm);
 }
Пример #4
0
        private void parseWorker(IDictionary <String, String> parameters, int lineNumber)
        {
            string id = parameters["id"];
            string puppetMasterURL = parameters["puppetmaster-url"];
            string serviceURL      = parameters["service-url"];
            string entryURL        = parameters["entry-url"];

            if (!id.Equals("") &&
                !puppetMasterURL.Equals("") &&
                !serviceURL.Equals(""))
            {
                if (RegexConstants.PATTERN_ID.IsMatch(id) &&
                    RegexConstants.PATTERN_URL.IsMatch(puppetMasterURL))
                {
                    int parsedID = 0;
                    try {
                        parsedID = Int32.Parse(id);
                    } catch (FormatException) {
                        showMessage(Constants.COMMAND_WORKER_INVALID_PARAMETERS);
                    }

                    PuppetMasterService pm =
                        (PuppetMasterService)Factory.Instance.GetService(
                            typeof(PuppetMasterService), puppetMasterURL);

                    if (pm == null)
                    {
                        showMessage("Cannot locate: " + puppetMasterURL);
                    }
                    else
                    {
                        AddPuppetMaster(pm);
                        createWorkerThread(pm, parsedID, serviceURL, entryURL);
                    }
                }
                else
                {
                    showMessage(Constants.COMMAND_WORKER_INVALID_PARAMETERS);
                    return;
                }
            }
            else
            {
                showMessage(Constants.COMMAND_WORKER_INVALID_SYNTAX);
            }
        }
Пример #5
0
        private void initConsole()
        {
            string serviceName = Constants.PUPPETMASTER_SERVICE_NAME;
            int    port        = Constants.PUPPETMASTER_PORT_START;

            puppetMaster = new PuppetMaster(serviceName);

            service = new PuppetMasterService(puppetMaster);

            initService(port, serviceName);

            Console.WriteLine("Running service at " + puppetMasterURL);
            Console.WriteLine("Accepting commands here");

            initParser();

            consoleJob();
        }
Пример #6
0
 private void createWorkerThread(PuppetMasterService pm, int parsedID, string serviceURL, string entryURL)
 {
     try {
         if (entryURL.Equals(""))
         {
             pm.CreateWorker(parsedID, serviceURL, null);
         }
         else if (RegexConstants.PATTERN_URL.IsMatch(entryURL))
         {
             pm.CreateWorker(parsedID, serviceURL, entryURL);
         }
         else
         {
             showMessage(Constants.COMMAND_WORKER_INVALID_ENTRY_URL);
         }
     } catch (SocketException) {
         showMessage("Service not found. Maybe the PuppetMaster is down.");
     }
 }
Пример #7
0
 public void setPMSObject(PuppetMasterService pms)
 {
     _pms = pms;
     _msgDispatcher.setPMSObject(_pms);
 }
Пример #8
0
        private void initPMSObject()
        {
            connectionString = "tcp://" + _puppetIP + ":" + _puppetPort + "/" + Common.Constants.PUPPET_MASTER_SERVICE_NAME;

            pms = (PuppetMasterService)Activator.GetObject(
                typeof(PuppetMasterService),
                connectionString);
        }
 public void setPMSObject(PuppetMasterService pms)
 {
     _pms = pms;
 }
Пример #10
0
        private void startPuppetMasterService()
        {
            int port = Convert.ToInt32(portnum);
            IDictionary RemoteChannelProperties = new Dictionary<string, string>();
            RemoteChannelProperties["name"] = "PuppetMasterChannel";
            RemoteChannelProperties["port"] = port.ToString();
            TcpChannel channel = new TcpChannel(RemoteChannelProperties, null, null);
            ChannelServices.RegisterChannel(channel, true);

            pms = new PuppetMasterService();
            pms.Gui = this;
            objRef = RemotingServices.Marshal(pms, Common.Constants.PUPPET_MASTER_SERVICE_NAME, typeof(PuppetMasterService));

            /*
             RemotingConfiguration.RegisterWellKnownServiceType(
                 typeof(PuppetMasterService),
                 service,
                 WellKnownObjectMode.Singleton);
             */

            string service_string = "tcp://" + getIPAddress() + ":" + port + "/" + Common.Constants.PUPPET_MASTER_SERVICE_NAME;
            show("Started " + service_string);
        }
 private void AddPuppetMaster(PuppetMasterService pm)
 {
     if (pm == null) {
         return;
     }
     manager.AddPuppetMaster(pm);
 }
            public void AddPuppetMaster(PuppetMasterService service)
            {
                String key = "";
                try {
                    service.ProbeObject();
                    key = service.ServiceURL;
                } catch (Exception) {
                    return;
                }
                IList<String> brokenServices = new List<String>();
                if (!puppetMastersList.Any((KeyValuePair<String, PuppetMasterService> s) => {
                    try {
                        s.Value.ProbeObject();
                        return s.Value.ServiceURL == service.ServiceURL;
                    } catch (Exception) {
                        brokenServices.Add(s.Key);
                    }
                    return false;
                })) {
                    puppetMastersList.Add(key, service);
                }

                foreach (String k in brokenServices) {
                    puppetMastersList.Remove(k);
                }
            }
        private void initConsole()
        {
            string serviceName = Constants.PUPPETMASTER_SERVICE_NAME;
            int port = Constants.PUPPETMASTER_PORT_START;

            puppetMaster = new PuppetMaster(serviceName);

            service = new PuppetMasterService(puppetMaster);

            initService(port, serviceName);

            Console.WriteLine("Running service at " + puppetMasterURL);
            Console.WriteLine("Accepting commands here");

            initParser();

            consoleJob();
        }
 private void createWorkerThread(PuppetMasterService pm, int parsedID, string serviceURL, string entryURL)
 {
     try {
         if (entryURL.Equals("")) {
             pm.CreateWorker(parsedID, serviceURL, null);
         } else if (RegexConstants.PATTERN_URL.IsMatch(entryURL)) {
             pm.CreateWorker(parsedID, serviceURL, entryURL);
         } else {
             showMessage(Constants.COMMAND_WORKER_INVALID_ENTRY_URL);
         }
     } catch (SocketException) {
         showMessage("Service not found. Maybe the PuppetMaster is down.");
     }
 }
Пример #15
0
        static void Main(string[] args)
        {
            //StreamReader reader = File.OpenText(args[0]);

            StreamReader reader = null;


            Console.WriteLine("Choose type of command introduction: s for script w for writing commands");
            string inputtype = Console.ReadLine();

            //if user choose script mode
            if (inputtype == "s")
            {
                try
                {
                    //open the script
                    reader = File.OpenText(AuxFunctions.GetProjPath() + "\\scripts\\PuppetMaster\\" + "script.txt");
                }
                catch (FileNotFoundException e)
                {
                    Console.WriteLine("Introduce a correct script file");
                }
            }


            Console.WriteLine("Choose the algorithm: x for XL and s for SMR");

            //get the type of algorithm
            string algorithm = Console.ReadLine();

            Console.WriteLine("Choose the mode: a for advanced, b for basic");

            string mode = Console.ReadLine();


            //initiliaze a executer of commands
            PuppetMasterService MasterofPuppets = new PuppetMasterService(algorithm, mode);

            //get the commands from cmd input
            if (reader == null)
            {
                while (true)
                {
                    Console.WriteLine("Write a command:" + "\n\r");
                    string Command = Console.ReadLine();
                    Console.WriteLine(Command);

                    //execute the command
                    MasterofPuppets.Execute(Command);
                }
            }

            //choose the typeof execution
            Console.WriteLine("Choose type of execution: s for step, nothing for complete");

            //get the type of execution
            string command = Console.ReadLine();

            //if step by step add a readline to stop the full execution
            if (command == "s")
            {
                Console.WriteLine("Step by Step execution");
                Console.ReadLine();

                string line;

                while ((line = reader.ReadLine()) != null)
                {
                    MasterofPuppets.Execute(line);

                    Console.ReadLine();
                }
            }

            //if complete just execute the lines
            else
            {
                string line;

                while ((line = reader.ReadLine()) != null)
                {
                    MasterofPuppets.Execute(line);
                }
            }

            Console.ReadLine();
        }
Пример #16
0
 public void setPMS(PuppetMasterService pms)
 {
     this.pms = pms;
 }