/// <summary> /// Constructor used from Network.Dispatcher /// </summary> public Job(List <ExperimentalUnit> experimentalUnits, HerdAgentInfo herdAgent) { Name = "Job #" + jobId; jobId++; ExperimentalUnits = experimentalUnits; HerdAgent = herdAgent; }
/// <summary> /// Returns the first experimental unit that fits the agent /// </summary> /// <param name="pendingExperiments">The pending experimental units</param> /// <param name="numFreeCores">The number agent's free cores</param> /// <param name="bAgentUsed">Is the agent already being used for another experimental unit?</param> /// <param name="agent">The herd agent</param> /// <returns></returns> static ExperimentalUnit FirstFittingExperiment(List <ExperimentalUnit> pendingExperiments, int numFreeCores, bool bAgentUsed, HerdAgentInfo agent) { foreach (ExperimentalUnit experiment in pendingExperiments) { experiment.SelectedVersion = agent.BestMatch(experiment); if (experiment.SelectedVersion != null) { //If NumCPUCores = "all", then the experiment only fits the agent in case it hasn't been given any other experimental unit if ((experiment.RunTimeReqs.NumCPUCores == 0 && !bAgentUsed) //If NumCPUCores != "all", then experiment only fits the agent if the number of cpu cores used is less than those available || (experiment.RunTimeReqs.NumCPUCores > 0 && experiment.RunTimeReqs.NumCPUCores <= numFreeCores)) { return(experiment); } } } return(null); }
void DiscoveryCallback(IAsyncResult ar) { UdpClient udpClient = (UdpClient)((ShepherdUdpState)(ar.AsyncState)).Client; IPEndPoint ip = (IPEndPoint)((ShepherdUdpState)(ar.AsyncState)).Ip; XMLStream inputXMLStream = new XMLStream(); XElement xmlDescription; string herdAgentXMLDescription; try { Byte[] receiveBytes = udpClient.EndReceive(ar, ref ip); { herdAgentXMLDescription = Encoding.ASCII.GetString(receiveBytes); if (herdAgentXMLDescription.IndexOf('<') == 0) { xmlDescription = XElement.Parse(herdAgentXMLDescription); HerdAgentInfo herdAgentInfo = new HerdAgentInfo(); herdAgentInfo.Parse(xmlDescription); //we copy the ip address into the properties herdAgentInfo.ipAddress = ip; //we update the ack time DateTime now = DateTime.Now; herdAgentInfo.lastACK = now; bool agentAddedToList = false; lock (m_listLock) { if (!m_herdAgentList.ContainsKey(herdAgentInfo.ProcessorId)) { m_herdAgentList[herdAgentInfo.IpAddressString] = herdAgentInfo; //We have to use the ip address until ProcessorId is a GUID on all deployed agents agentAddedToList = true; } } if (agentAddedToList) { //check how much time ago the agent list was updated double lastUpdateElapsedTime = (now - m_lastHerdAgentListUpdate).TotalSeconds; //notify, if we have to, that the agent list has probably changed if (lastUpdateElapsedTime > m_herdAgentListUpdateTime) { m_lastHerdAgentListUpdate = now; } m_notifyAgentListChanged?.Invoke(herdAgentInfo); } } } udpClient.BeginReceive(new AsyncCallback(DiscoveryCallback), ar.AsyncState); } catch (TaskCanceledException ex) { LogMessage("Task canceled exception in Shepherd"); LogMessage(ex.ToString()); } catch (Exception ex) { LogMessage("Exception in discovery callback function"); LogMessage(ex.StackTrace); } }
static ExperimentalUnit FirstFittingExperiment(List <ExperimentalUnit> pendingExperiments, int numFreeCores, bool bAgentUsed, HerdAgentInfo agent) { foreach (ExperimentalUnit experiment in pendingExperiments) { AppVersion bestMatchingVersion = agent.BestMatch(experiment.AppVersions); if (bestMatchingVersion != null) { //run-time requirements are calculated when a version is selected experiment.SelectedVersion = agent.BestMatch(experiment.AppVersions); if (experiment.SelectedVersion == null) { return(null); } experiment.GetRuntimeRequirements(experiment.SelectedVersion, experiment.AppVersions); if (experiment.RunTimeReqs == null) { return(null); } //Check that the version chosen for the agent supports the architecture requested by the run-time if ((experiment.RunTimeReqs.Architecture == Herd.Network.PropValues.None || experiment.RunTimeReqs.Architecture == experiment.SelectedVersion.Requirements.Architecture) && //If NumCPUCores = "all", then the experiment only fits the agent in case it hasn't been given any other experimental unit ((experiment.RunTimeReqs.NumCPUCores == 0 && !bAgentUsed) //If NumCPUCores != "all", then experiment only fits the agent if the number of cpu cores used is less than those available || (experiment.RunTimeReqs.NumCPUCores > 0 && experiment.RunTimeReqs.NumCPUCores <= numFreeCores))) { return(experiment); } } } return(null); }