Exemplo n.º 1
0
        protected static void setConfigFileAtRuntime(string[] args)
        {
            string componentToStart;

            Console.WriteLine("Please specify a component that you want to start:");
            Console.WriteLine("1. Server");
            Console.WriteLine("2. Task manager");
            Console.WriteLine("3. Client");
            Console.WriteLine("4. Computational node");
            Console.Write("> ");

            componentToStart = Console.ReadLine();
            componentToStart = componentToStart.Replace(" ", string.Empty);
            componentToStart = componentToStart.Replace(".", string.Empty);

            UInt16 port = 666;
            string hostName = Dns.GetHostName();
            IPAddress ip = Shared.Connection.ConnectionHelpers.getIPAddressOfTheLocalMachine();

            int result = 0;
            if (Int32.TryParse(componentToStart, out result)) {
                switch (result) {
                    case 1:
                        componentToStart = "SERVER";
                        break;
                    case 2:
                        componentToStart = "TASKMANAGER";
                        break;
                    case 3:
                        componentToStart = "CLIENT";
                        break;
                    case 4:
                        componentToStart = "COMPUTATIONALNODE";
                        break;
                }
            }

            switch (componentToStart.ToUpper()) {

                case "TASKMANAGER":
                    TaskManager newTaskManagerInstance = new TaskManager();
                    newTaskManagerInstance.startInstance(port, ip);
                    break;

                case "SERVER":
                    Server newServerInstance = new Server();
                    newServerInstance.startInstance(port, ip);
                    break;

                case "CLIENT":
                    ComputationalCluster.Nodes.Client newClientInstance = new ComputationalCluster.Nodes.Client();
                    newClientInstance.startInstance(port, ip);
                    break;

                case "COMPUTATIONALNODE":
                    ComputationalNode newComputationalNodeInstance = new ComputationalNode();
                    newComputationalNodeInstance.startInstance(port, ip);
                    break;
            }
        }
Exemplo n.º 2
0
        private StatusThreadsThread[] CurrentStatusThreads()
        {
            List <StatusThreadsThread> threads = new List <StatusThreadsThread>();

            foreach (NodeWorker worker in this.Workers)
            {
                threads.Add(ComputationalNode.StatusThreadsThreadFromNodeWorker(worker));
            }

            return(threads.ToArray());
        }
Exemplo n.º 3
0
        protected override string ReceivedRegister(Register register, IPAddress senderAddr)
        {
            string type = register.Type;
            Node   newNode;
            ulong  ID = RegisteredNodes.NextNodeID;

            switch (Utilities.NodeTypeForName(type))
            {
            case NodeType.TaskManager:
                newNode = new TaskManager();
                if (senderAddr != null)
                {
                    newNode.IP = senderAddr;
                }
                newNode.NodeType = Nodes.NodeType.TaskManager;
                newNode.ID       = register.Id;
                this.RegisteredComponents.RegisterTaskManager(newNode);
                break;

            case NodeType.ComputationalNode:
                newNode    = new ComputationalNode();
                newNode.ID = register.Id;
                if (senderAddr != null)
                {
                    newNode.IP = senderAddr;
                }
                newNode.NodeType = Nodes.NodeType.ComputationalNode;
                this.RegisteredComponents.RegisterComputationalNode(newNode);
                break;

            case NodeType.Server:
                newNode    = new Server();
                newNode.ID = ID;
                BackupServerQueue bsq = new BackupServerQueue {
                    backupServerId = ID,
                    messages       = new Queue <string>()
                };
                if (senderAddr != null)
                {
                    newNode.IP = senderAddr;
                }
                newNode.NodeType = Nodes.NodeType.Server;
                this.backupServerQueues.Add(bsq);
                this.RegisteredComponents.RegisterBackupServer(newNode);
                this.backupServerQueues.Add(bsq);
                break;

            case NodeType.Client:     //not needed!
                break;

            default:
                break;
            }

            //Register message is sent by TM, CN and Backup CS to the CS after they are activated.
            RegisterResponse response = new RegisterResponse();

            response.Id      = ID;
            response.Timeout = this.Timeout;
            List <RegisterResponseBackupCommunicationServersBackupCommunicationServer> backupServers = new List <RegisterResponseBackupCommunicationServersBackupCommunicationServer>();

            foreach (Node comp in this.RegisteredComponents.BackupServers)
            {
                RegisterResponseBackupCommunicationServersBackupCommunicationServer backup = new RegisterResponseBackupCommunicationServersBackupCommunicationServer();
                if (comp.IP == null)
                {
                    break;
                }
                backup.address = comp.IP.ToString();
                if (comp.Port > 0)
                {
                    backup.port          = comp.Port;
                    backup.portSpecified = true;
                }
                backupServers.Add(backup);
            }

            response.BackupCommunicationServers = backupServers.ToArray();
            if (!this.BackupMode)
            {
                Console.WriteLine("Sending RegisterResponse");
            }
            return(response.SerializeToXML());
        }
Exemplo n.º 4
0
        protected override string ReceivedRegister(Register register, IPAddress senderAddr)
        {
            string type = register.Type;
            Node newNode;
            ulong ID = RegisteredNodes.NextNodeID;
            switch (Utilities.NodeTypeForName(type)) {
                case NodeType.TaskManager:
                    newNode = new TaskManager();
                    if(senderAddr != null)
                        newNode.IP = senderAddr;
                    newNode.NodeType = Nodes.NodeType.TaskManager;
                    newNode.ID = register.Id;
                    this.RegisteredComponents.RegisterTaskManager(newNode);
                    break;
                case NodeType.ComputationalNode:
                    newNode = new ComputationalNode();
                    newNode.ID = register.Id;
                    if (senderAddr != null)
                        newNode.IP = senderAddr;
                    newNode.NodeType = Nodes.NodeType.ComputationalNode;
                    this.RegisteredComponents.RegisterComputationalNode(newNode);
                    break;
                case NodeType.Server:
                    newNode = new Server();
                    newNode.ID = ID;
                    BackupServerQueue bsq = new BackupServerQueue {
                        backupServerId = ID,
                        messages = new Queue<string>()
                    };
                    if (senderAddr != null)
                        newNode.IP = senderAddr;
                    newNode.NodeType = Nodes.NodeType.Server;
                    this.backupServerQueues.Add(bsq);
                    this.RegisteredComponents.RegisterBackupServer(newNode);
                    this.backupServerQueues.Add(bsq);
                    break;
                case NodeType.Client: //not needed!
                    break;
                default:
                    break;
            }

            //Register message is sent by TM, CN and Backup CS to the CS after they are activated.
            RegisterResponse response = new RegisterResponse();
            response.Id = ID;
            response.Timeout = this.Timeout;
            List<RegisterResponseBackupCommunicationServersBackupCommunicationServer> backupServers = new List<RegisterResponseBackupCommunicationServersBackupCommunicationServer>();
            foreach (Node comp in this.RegisteredComponents.BackupServers) {
                RegisterResponseBackupCommunicationServersBackupCommunicationServer backup = new RegisterResponseBackupCommunicationServersBackupCommunicationServer();
                if (comp.IP == null)
                    break ;
                backup.address = comp.IP.ToString();
                if (comp.Port > 0) {
                    backup.port = comp.Port;
                    backup.portSpecified = true;
                }
                backupServers.Add(backup);
            }

            response.BackupCommunicationServers = backupServers.ToArray();
            if(!this.BackupMode)
            Console.WriteLine("Sending RegisterResponse");
            return response.SerializeToXML();
        }