Esempio n. 1
0
 /// <summary>
 /// Adds a new worker registration to the pool.
 /// </summary>
 /// <param name="workerRegistration">Registration details of new worker.</param>
 public void AddToPool(WorkerRegistration workerRegistration)
 {
     lock (registrationPool)
     {
         registrationPool.Add(workerRegistration);
     }
     runtimeConfiguration.GetLoggerInstance().Msg("Manager", "Worker Registration Pool", $"Worker with name '{workerRegistration.Name}' was added to the pool.");
 }
Esempio n. 2
0
        /// <summary>
        /// Registers a new worker by assigning a GUID and sets all health check values to their initial values.
        /// Does not attempt a network connection initialization or handshake (this is handled by WorkerRegistrationManager).
        /// </summary>
        /// <returns>Registration info for the next worker to connect.</returns>
        public WorkerRegistration RegisterNewWorker()
        {
            int                port           = basePort + registrationPool.Count;
            DateTime           firstHeartBeat = DateTime.Now;
            string             name           = "worker-" + (registrationPool.Count + 1);
            WorkerRegistration registration   = new WorkerRegistration(name, null, port, firstHeartBeat);

            AddToPool(registration);
            return(registration);
        }
Esempio n. 3
0
 /// <summary>
 /// Processes a message and dispatches any needed sub-tasks.
 /// </summary>
 /// <param name="workerRegistration">Registration for worker that sent the message.</param>
 /// <param name="rawCommand">Command string sent by worker.</param>
 public void ProcessMessage(WorkerRegistration workerRegistration, string rawCommand)
 {
     if (Regex.IsMatch(rawCommand, @"^HEARTBEAT$"))
     {
         updateHeartbeat(workerRegistration);
     }
     if (Regex.IsMatch(rawCommand, @"^VAR "))
     {
         dataStoreManager.ProcessCommand(rawCommand, workerRegistration);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Handles the registration of new workers and performs a hand-off to a private communication port
        /// </summary>
        /// <param name="newClient">Active connection from worker requesting registration.</param>
        private void startWorkerRegistrationProcess(TCPClient newClient)
        {
            WorkerRegistration registration = getNewWorkerRegistrationInformation(newClient.ReceiveObject <string>());

            try
            {
                newClient.SendObject <string>($"{registration.Port.ToString()}|{registration.Name}");
            }
            catch (ArgumentException e)
            {
                sharedLogger.Error("Manger", "Worker Registration Manager", $"Worker registration with new worker '{registration.Name}' failed.");
                sharedLogger.ErrorStackTrace("Manager", "Worker Registration Manager", new Exception("An error occurred while registering a new worker.", e));
                return;
            }
            catch (IOException e)
            {
                sharedLogger.Error("Manger", "Worker Registration Manager", $"Worker registration with new worker '{registration.Name}' failed.");
                sharedLogger.ErrorStackTrace("Manager", "Worker Registration Manager", new Exception($"A network error occurred while sending registration information for worker '{registration.Name}'.", e));
                return;
            }
            sharedLogger.Debug("Manager", "Worker Registration Service", $"Transferring {registration.Name} to new connection...");
            TCPServer newConnection;

            try
            {
                newConnection             = new TCPServer(managerBindIP, registration.Port);
                registration.ClientServer = newConnection.WaitForNextConnection();
            }
            catch (ArgumentException e)
            {
                sharedLogger.Error("Manger", "Worker Registration Manager", $"Worker registration with new worker '{registration.Name}' failed.");
                sharedLogger.ErrorStackTrace("Manager", "Worker Registration Manager", new Exception("An error occurred while registering a new worker.", e));
                return;
            }
            catch (IOException e)
            {
                sharedLogger.Error("Manger", "Worker Registration Manager", $"Worker registration with new worker '{registration.Name}' failed.");
                sharedLogger.ErrorStackTrace("Manager", "Worker Registration Manager", new Exception($"A network error occurred while transferring worker '{registration.Name}' to new communication port.", e));
                return;
            }
            sharedLogger.Debug("Manager", "Worker Registration Service", $"Connection successful on new channel.");
        }
Esempio n. 5
0
 private void updateHeartbeat(WorkerRegistration workerRegistration)
 {
     //sharedLogger.Debug($"Heartbeat update for {workerRegistration.Name}.");
     workerRegistration.LastHeartBeat = DateTime.Now;
 }