コード例 #1
0
        public void SlaveAdd()
        {
            MOG_CommandManager manager = MOG_ControllerSystem.GetCommandManager();

            if (manager != null)
            {
                MOG_Network network = manager.GetNetwork();
                if (network != null)
                {
                    // Add a slave
                    MOG_ControllerSystem.LaunchSlave(network.GetID());
                }
            }
        }
コード例 #2
0
        bool RequestNewSlave(MOG_Command pCommand)
        {
            MOG_Command pClient            = null;
            bool        bAutoLaunchedSlave = false;
            bool        bThisSpecificSlaveBeingRequested = false;

            // Check if we should wait a bit longer before we request a slave?
            if (DateTime.Now < mNextSlaveRequstTime)
            {
                // Ignore this request
                return(false);
            }

            // Check for a 'SlaveMachine' section in the System's config file?
            MOG_Ini pConfigFile = MOG_ControllerSystem.GetSystem().GetConfigFile();

            string[] validSlaveMachines = null;
            if (pConfigFile.SectionExist("SlaveMachines"))
            {
                validSlaveMachines = pConfigFile.GetSectionKeys("SlaveMachines");
            }

            // Check if we obtained a list of validSlaveMachines?
            if (validSlaveMachines != null &&
                validSlaveMachines.Length > 0)
            {
                // Scan all the slaves specifically listed in our config file first
                // Walk list of specified SlaveMachines?
                foreach (string machineName in validSlaveMachines)
                {
                    // Get the SlaveMachine info
                    string machinePriority = pConfigFile.GetString("SlaveMachines", machineName);

                    bThisSpecificSlaveBeingRequested = false;

                    // Check if we have already requested this slave?
                    if (IsAlreadyRequestedSlave(machineName))
                    {
                        // We can skip this machine because we have already issued a request for a slave
                        continue;
                    }

                    // Check if we had a specific list of validSlaves specified?
                    if (pCommand.GetValidSlaves().Length != 0)
                    {
                        // Check if this machineName isn't listed in the command's validSlaves?
                        if (IsSlaveListed(machineName, pCommand.GetValidSlaves()))
                        {
                            bThisSpecificSlaveBeingRequested = true;
                        }
                        else
                        {
                            // We can skip this machine because it isn't listed as a validSlave
                            continue;
                        }
                    }

                    // Check if there is already a slave running on this machine?
                    if (mServerCommandManager.LocateRegisteredSlaveByComputerName(machineName) != null)
                    {
                        continue;
                    }

                    // Make sure there is a client running on this machine?
                    pClient = mServerCommandManager.LocateClientByComputerName(machineName);
                    if (pClient != null)
                    {
                        // Check if this Slave should be considered an AutoLaunchedSlave?
                        if (String.Compare(machinePriority, "Always", true) != 0 &&
                            String.Compare(machinePriority, "Yes", true) != 0 &&
                            String.Compare(machinePriority, "True", true) != 0)
                        {
                            // Indicate this slave should be terminated when it is no longer needed
                            bAutoLaunchedSlave = true;
                        }
                        break;
                    }
                }
            }

            // Check if we are still missing a client to launch a slave on?
            if (pClient == null)
            {
                // Scan all the registered clients looking for one that we can send this request to?
                ArrayList registeredClients = this.mServerCommandManager.GetRegisteredClients();
                for (int c = 0; c < registeredClients.Count; c++)
                {
                    MOG_Command pRegisteredClient = (MOG_Command)registeredClients[c];
                    string      machineName       = pRegisteredClient.GetComputerName();

                    bThisSpecificSlaveBeingRequested = false;

                    // Check if we have already requested this slave?
                    if (IsAlreadyRequestedSlave(machineName))
                    {
                        // We can skip this machine because we have already issued a request for a slave
                        continue;
                    }

                    // Check if there is already a slave running on this machine?
                    if (mServerCommandManager.LocateRegisteredSlaveByComputerName(machineName) != null)
                    {
                        continue;
                    }

                    // Check if we had a specific list of validSlaves specified?
                    if (pCommand.GetValidSlaves().Length != 0)
                    {
                        // Check if this machineName isn't listed in the specified validSlaves?
                        if (IsSlaveListed(machineName, pCommand.GetValidSlaves()))
                        {
                            bThisSpecificSlaveBeingRequested = true;
                        }
                        else
                        {
                            // We can skip this machine because it isn't listed as a validSlave
                            continue;
                        }
                    }
                    else
                    {
                        // Check if there was a list of validSlaveMachines specified?
                        if (validSlaveMachines != null)
                        {
                            // Check if this computer was listed?
                            if (pConfigFile.KeyExist("SlaveMachines", machineName))
                            {
                                // Make sure this isn't listed as an exclusion?
                                string machinePriority = pConfigFile.GetString("SlaveMachines", machineName);
                                if (String.Compare(machinePriority, "Never", true) != 0 ||
                                    String.Compare(machinePriority, "No", true) != 0 ||
                                    String.Compare(machinePriority, "Exempt", true) != 0 ||
                                    String.Compare(machinePriority, "Ignore", true) != 0 ||
                                    String.Compare(machinePriority, "Skip", true) != 0)
                                {
                                    continue;
                                }
                            }
                        }
                    }

                    // Looks like we can use this client
                    pClient = pRegisteredClient;
                    // Indicate this slave should be terminated when it is no longer needed
                    bAutoLaunchedSlave = true;
                    break;
                }
            }

            // Check if this is just a generic slave request?
            if (!bThisSpecificSlaveBeingRequested)
            {
                // Check if we have a maximum number of slaves to auto launch? and
                // Check if we are over our maximum number of slaves?
                if (mManagedSlavesMax != 0 &&
                    mManagedSlavesMax < mAutoLaunchedSlaveNames.Count)
                {
                    // No need to launch this slave because we have exceeded our max
                    return(false);
                }
            }

            // Check if we found a client that we can request a new slave from?
            if (pClient != null)
            {
                // Instruct this client to launch a slave
                MOG_ControllerSystem.LaunchSlave(pClient.GetNetworkID());
                // Track when this last request was made
                mNextSlaveRequstTime = DateTime.Now.AddSeconds(5);

                // Add this slave to our list of requested slave names
                AddRequestedSlave(pClient.GetComputerName());
                // Check if we should add this slave as an AutoLaunchedSlave?
                if (bAutoLaunchedSlave)
                {
                    AddAutoLaunchedSlaveName(pClient.GetComputerName());
                }

                // Indicate we launched a new slave
                return(true);
            }

            // Check if it is time to report a missing slave error?
            if (DateTime.Now > mNextNoSlaveReportTime)
            {
                // Check if there was a specific validslaves listed?
                if (pCommand.GetValidSlaves().Length > 0)
                {
                    bool bWarnUser = true;

                    // Split up the specified ValidSlaves
                    String   delimStr   = ",;";
                    Char[]   delimiter  = delimStr.ToCharArray();
                    String[] SlaveNames = pCommand.GetValidSlaves().Trim().Split(delimiter);
                    // Check the registered slaves to see if a valid slave is running
                    for (int n = 0; n < SlaveNames.Length; n++)
                    {
                        // Check if we found our matching slave name?
                        if (mServerCommandManager.LocateRegisteredSlaveByComputerName(SlaveNames[n]) != null)
                        {
                            // We found a match...this command will eventually get processed
                            bWarnUser = false;
                            break;
                        }
                    }

                    // Check if we decided to warn the user?
                    if (bWarnUser)
                    {
                        // Setup the Broadcast message indicating that there are no valid slaves running
                        string message = String.Concat("MOG Server is trying to process a command containing a 'ValidSlaves' property and has been unable to launch the needed Slave.\n",
                                                       "VALIDSLAVES=", pCommand.GetValidSlaves(), "\n\n",
                                                       "Please check this machine to ensure it is connected to the MOG Server.");
                        MOG_ControllerSystem.NetworkBroadcast(pCommand.GetUserName(), message);
                        // Record the time when this report was sent
                        mNextNoSlaveReportTime = DateTime.Now.AddMinutes(5);
                    }
                }
            }

            // Indicate that we failed to find a qualified slave
            return(false);
        }
コード例 #3
0
 private void LaunchSlave(int id)
 {
     MOG_ControllerSystem.LaunchSlave(id);
 }