/// <summary>
 ///  Called with a specific ContextStatusProto that must be delivered to the driver
 /// </summary>
 /// <param name="contextStatusProto"></param>
 public void OnNext(ContextStatusProto contextStatusProto)
 {
     LOGGER.Log(Level.Verbose, "Before acquiring lock: HeartbeatManager::OnNext(ContextStatusProto)");
     lock (this)
     {
         LOGGER.Log(Level.Verbose, "HeartbeatManager::OnNext(ContextStatusProto)");
         List<ContextStatusProto> contextStatusProtos = new List<ContextStatusProto>();
         contextStatusProtos.Add(contextStatusProto);
         contextStatusProtos.AddRange(ContextManager.GetContextStatusCollection());
         EvaluatorHeartbeatProto heartbeatProto = GetEvaluatorHeartbeatProto(
             EvaluatorRuntime.GetEvaluatorStatus(),
             contextStatusProtos,
             Optional<TaskStatusProto>.Empty());
         LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "Triggered a heartbeat: {0}.", heartbeatProto));
         Send(heartbeatProto);
     }
 }
示例#2
0
 /// <summary>
 /// THIS ASSUMES THAT IT IS CALLED ON A THREAD HOLDING THE LOCK ON THE HeartBeatManager
 /// </summary>
 /// <param name="e"></param>
 private void HandleContextException(ContextClientCodeException e)
 {
     LOGGER.Log(Level.Error, "ContextClientCodeException", e);
     byte[] exception = ByteUtilities.StringToByteArrays(e.ToString());
     ContextStatusProto contextStatusProto = new ContextStatusProto()
     {
         context_id = e.ContextId,
         context_state = ContextStatusProto.State.FAIL,
         error = exception
     };
     if (e.ParentId.IsPresent())
     {
         contextStatusProto.parent_id = e.ParentId.Value;
     }
     LOGGER.Log(Level.Error, "Sending Heartbeat for a failed context: {0}", contextStatusProto);
     _heartBeatManager.OnNext(contextStatusProto);
 }
示例#3
0
        /// <summary>
        /// get context's status in protocol buffer
        /// </summary>
        /// <returns>this context's status in protocol buffer form.</returns>
        public ContextStatusProto GetContextStatus()
        {
            lock (_contextLifeCycle)
            {
                ContextStatusProto contextStatusProto = new ContextStatusProto()
                {
                    context_id = Id,
                    context_state = _contextState,
                };
                if (_parentContext.IsPresent())
                {
                    contextStatusProto.parent_id = _parentContext.Value.Id;
                }

                foreach (IContextMessageSource source in _contextLifeCycle.ContextMessageSources)
                {
                    Optional<ContextMessage> contextMessageOptional = source.Message;
                    if (contextMessageOptional.IsPresent())
                    {
                        ContextStatusProto.ContextMessageProto contextMessageProto
                            = new ContextStatusProto.ContextMessageProto()
                            {
                                source_id = contextMessageOptional.Value.MessageSourceId,
                            };
                        contextMessageProto.message = ByteUtilities.CopyBytesFrom(contextMessageOptional.Value.Bytes);
                        contextStatusProto.context_message.Add(contextMessageProto);
                    }
                }
                return contextStatusProto;
            }
        }
示例#4
0
        /// <summary>
        /// get context's status in protocol buffer
        /// </summary>
        /// <returns>this context's status in protocol buffer form.</returns>
        public ContextStatusProto GetContextStatus()
        {
            lock (_contextLifeCycle)
            {
                var contextStatusProto = new ContextStatusProto
                {
                    context_id = Id,
                    context_state = _contextState,
                };
                if (_parentContext.IsPresent())
                {
                    contextStatusProto.parent_id = _parentContext.Value.Id;
                }

                foreach (var sourceMessage in _contextLifeCycle.ContextMessageSources.Where(src => src.Message.IsPresent()).Select(src => src.Message.Value))
                {
                    var contextMessageProto = new ContextStatusProto.ContextMessageProto
                    {
                        source_id = sourceMessage.MessageSourceId,
                        message = ByteUtilities.CopyBytesFrom(sourceMessage.Bytes),
                    };
                    contextStatusProto.context_message.Add(contextMessageProto);
                }

                return contextStatusProto;
            }
        }
示例#5
0
        private void HandleContextException(Exception e, string contextId, string parentContextId)
        {
            lock (_heartBeatManager)
            {
                LOGGER.Log(Level.Warning, "ContextException", e);

                byte[] exception = ByteUtilities.StringToByteArrays(e.ToString());
                var contextStatusProto = new ContextStatusProto
                {
                    context_id = contextId,
                    context_state = ContextStatusProto.State.FAIL,
                    parent_id = parentContextId,
                    error = exception
                };

                LOGGER.Log(Level.Error, "Sending Heartbeat for a failed context: {0}", contextStatusProto);
                _heartBeatManager.OnNext(contextStatusProto);
            }
        }
示例#6
0
        /// <summary>
        /// get context's status in protocol buffer
        /// </summary>
        /// <returns>this context's status in protocol buffer form.</returns>
        public ContextStatusProto GetContextStatus()
        {
            lock (_contextLifeCycle)
            {
                var contextStatusProto = new ContextStatusProto
                {
                    context_id = Id,
                    context_state = _contextState,
                };
                if (_parentContext.IsPresent())
                {
                    contextStatusProto.parent_id = _parentContext.Value.Id;
                }

                foreach (var source in _contextLifeCycle.ContextMessageSources)
                {
                    // Note: Please do not convert to LINQ expression, as source.Message
                    // may not return the same object in subsequent Get calls.
                    var sourceMessage = source.Message;
                    if (sourceMessage.IsPresent())
                    {
                        var contextMessageProto = new ContextStatusProto.ContextMessageProto
                        {
                            source_id = sourceMessage.Value.MessageSourceId,
                            message = ByteUtilities.CopyBytesFrom(sourceMessage.Value.Bytes),
                        };

                        contextStatusProto.context_message.Add(contextMessageProto);
                    }
                }

                return contextStatusProto;
            }
        }