/// <summary> /// Receives and routes heartbeats from Evaluators. /// </summary> /// <param name="evaluatorHearBeatProto"></param> private void Handle(IRemoteMessage <EvaluatorHeartbeatProto> evaluatorHearBeatProto) { EvaluatorHeartbeatProto heartbeat = evaluatorHearBeatProto.Message; EvaluatorStatusProto status = heartbeat.evaluator_status; string evaluatorId = status.evaluator_id; LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "Heartbeat from Evaluator {0} with state {1} timestamp {2}", evaluatorId, status.state, heartbeat.timestamp)); _sanityChecker.check(evaluatorId, heartbeat.timestamp); lock (_evaluators) { if (_evaluators.ContainsKey(evaluatorId)) { EvaluatorManager evaluatorManager = _evaluators[evaluatorId]; evaluatorManager.Handle(evaluatorHearBeatProto); } else { string msg = "Contact from unkonwn evaluator with id: " + evaluatorId; if (heartbeat.evaluator_status != null) { msg += " with state" + status.state; } LOGGER.Log(Level.Error, msg); Exceptions.Throw(new InvalidOperationException(msg), LOGGER); } } }
/// <summary> /// This handles runtime error occurs on the evaluator /// </summary> /// <param name="runtimeErrorProto"></param> public void Handle(RuntimeErrorProto runtimeErrorProto) { FailedRuntime error = new FailedRuntime(runtimeErrorProto); LOGGER.Log(Level.Warning, "Runtime error:" + error); EvaluatorException evaluatorException = error.Cause != null ? new EvaluatorException(error.Id, error.Cause.Value) : new EvaluatorException(error.Id, "Runtime error"); EvaluatorManager evaluatorManager = null; lock (_evaluators) { if (_evaluators.ContainsKey(error.Id)) { evaluatorManager = _evaluators[error.Id]; } else { LOGGER.Log(Level.Warning, "Unknown evaluator runtime error: " + error.Cause); } } if (null != evaluatorManager) { evaluatorManager.Handle(evaluatorException); } }
/// <summary> /// This resource status message comes from the ResourceManager layer; telling me what it thinks /// about the state of the resource executing an Evaluator; This method simply passes the message /// off to the referenced EvaluatorManager /// </summary> /// <param name="resourceStatusProto"></param> private void Handle(ResourceStatusProto resourceStatusProto) { lock (_evaluators) { if (_evaluators.ContainsKey(resourceStatusProto.identifier)) { EvaluatorManager evaluatorManager = _evaluators[resourceStatusProto.identifier]; evaluatorManager.Handle(resourceStatusProto); } else { var e = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unknown resource status from evaluator {0} with state {1}", resourceStatusProto.identifier, resourceStatusProto.state)); Exceptions.Throw(e, LOGGER); } } }
public void Release(EvaluatorManager evaluatorManager) { lock (this) { string evaluatorManagerId = evaluatorManager.Id; if (_evaluators.ContainsKey(evaluatorManagerId)) { _evaluators.Remove(evaluatorManagerId); } else { var e = new InvalidOperationException("Trying to remove an unknown evaluator manager with id " + evaluatorManagerId); Exceptions.Throw(e, LOGGER); } } }
/// <summary> /// This method handles resource allocations by creating a new EvaluatorManager instance. /// </summary> /// <param name="resourceAllocationProto"></param> private void Handle(ResourceAllocationProto resourceAllocationProto) { lock (_evaluators) { try { INodeDescriptor nodeDescriptor = _resourceCatalog.GetNode(resourceAllocationProto.node_id); if (nodeDescriptor == null) { Exceptions.Throw(new InvalidOperationException("Unknown resurce: " + resourceAllocationProto.node_id), LOGGER); } EvaluatorDescriptorImpl evaluatorDescriptor = new EvaluatorDescriptorImpl(nodeDescriptor, EvaluatorType.UNDECIDED, resourceAllocationProto.resource_memory, resourceAllocationProto.virtual_cores); LOGGER.Log(Level.Info, "Resource allocation: new evaluator id: " + resourceAllocationProto.identifier); EvaluatorManager evaluatorManager = GetNewEvaluatorManagerInstance(resourceAllocationProto.identifier, evaluatorDescriptor); _evaluators.Add(resourceAllocationProto.identifier, evaluatorManager); } catch (Exception e) { Exceptions.Caught(e, Level.Error, LOGGER); Exceptions.Throw(new InvalidOperationException("Error handling resourceAllocationProto."), LOGGER); } } }
public EvaluatorContext(EvaluatorManager evaluatorManager, string id, Optional <string> parentId) { _identifier = id; _parentId = parentId; _evaluatorManager = evaluatorManager; }