Пример #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;
            }
        }
Пример #2
0
        protected void ReceivedNoOperation(NoOperation noOperation)
        {
            List<Node> backupServers = new List<Node>();
            foreach (NoOperationBackupCommunicationServers backups in noOperation.Items) {
                if (backups.BackupCommunicationServer == null)
                    return;
                foreach (NoOperationBackupCommunicationServersBackupCommunicationServer backup in backups.BackupCommunicationServer) {
                    Node server = new Server();
                    server.IP = System.Net.IPAddress.Parse(backup.address);
                    server.NodeType = Nodes.NodeType.Server;
                    if(backup.portSpecified)
                        server.Port = backup.port;
                    backupServers.Add(server);
                }
            }

            this.RegisteredComponents.UpdateBackupServers(backupServers);
        }
Пример #3
0
        //this method is only called from AsyncClient which sent something to the server
        //and the string xml is the response.
        //node of type server can execute this method only if it is in BackupMode (so it acts as a normal node -
        //i.e. sends Status etc.)
        public void ReceivedResponse(string xml)
        {
            Console.WriteLine("Node - received response:\n" + xml + "\n");
            Object obj = xml.DeserializeXML();

            if (obj is RegisterResponse) {
                RegisterResponse registerResponse = (RegisterResponse)obj;

                RegisterResponseBackupCommunicationServersBackupCommunicationServer[] backupServers = registerResponse.BackupCommunicationServers;
                foreach (RegisterResponseBackupCommunicationServersBackupCommunicationServer comp in backupServers) {
                    Node backup = new Server();
                    backup.IP = IPAddress.Parse(comp.address);
                    if(backup.IP != null) {
                        backup.Timeout = registerResponse.Timeout;
                        backup.ID = registerResponse.Id;
                        if (comp.portSpecified)
                            backup.Port = comp.port;
                        this.RegisteredComponents.RegisterBackupServer(backup);
                    }
                }

                this.ID = registerResponse.Id;
                this.Timeout = registerResponse.Timeout;
                this.StartTimeoutTimer();

            } else if (obj is DivideProblem) {  //Message to task Manager
                this.ReceivedDivideProblem((DivideProblem)obj);

            } else if (obj is Register) {
                this.ReceivedRegister((Register)obj, null);

            } else if (obj is SolutionRequest) {
                this.ReceivedSolutionRequest((SolutionRequest)obj);

            } else if (obj is SolvePartialProblems) {
                this.ReceivedSolvePartialProblems((SolvePartialProblems)obj);

            } else if (obj is SolveRequest) {
                this.ReceivedSolveRequest((SolveRequest)obj);

            } else if (obj is Status) {
                this.ReceivedStatus((Status)obj);

            } else if (obj is NoOperation) {
                this.ReceivedNoOperation((NoOperation)obj);

            } else if(obj is SolveRequestResponse) {
                this.ReceivedSolveRequestResponse((SolveRequestResponse)obj);

            } else if(obj is Solutions) {
                this.ReceivedSolutions((Solutions)obj);
            }
        }
Пример #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();
        }