Exemple #1
0
        public override string ToString()
        {
            string contextStatus     = string.Empty;
            string taskStatusMessage = string.Empty;

            foreach (ContextStatusProto contextStatusProto in context_status)
            {
                contextStatus += string.Format(CultureInfo.InvariantCulture, "evaluator {0} has context {1} in state {2} with recovery flag {3}",
                                               evaluator_status.evaluator_id,
                                               contextStatusProto.context_id,
                                               contextStatusProto.context_state,
                                               contextStatusProto.recovery);
            }
            if (task_status != null && task_status.task_message != null && task_status.task_message.Count > 0)
            {
                foreach (TaskStatusProto.TaskMessageProto taskMessageProto in task_status.task_message)
                {
                    taskStatusMessage += ByteUtilities.ByteArrarysToString(taskMessageProto.message);
                }
            }
            return(string.Format(CultureInfo.InvariantCulture, "EvaluatorHeartbeatProto: task_id=[{0}], task_status=[{1}], task_message=[{2}], evaluator_status=[{3}], context_status=[{4}], timestamp=[{5}], recoveryFlag =[{6}]",
                                 task_status == null ? string.Empty : task_status.task_id,
                                 task_status == null ? string.Empty : task_status.state.ToString(),
                                 taskStatusMessage,
                                 evaluator_status.state.ToString(),
                                 contextStatus,
                                 timestamp,
                                 recovery));
        }
Exemple #2
0
 /// <summary>
 /// Get the exception from error
 /// </summary>
 /// <param name="error"></param>
 /// <returns>excetpiont from error</returns>
 private static Exception GetException(RuntimeErrorProto error)
 {
     byte[] data = error.exception;
     if (data != null)
     {
         return(new InvalidOperationException(ByteUtilities.ByteArrarysToString(error.exception)));
     }
     return(null);
 }
Exemple #3
0
        public void OnNext(ITaskMessage taskMessage)
        {
            string msgReceived = ByteUtilities.ByteArrarysToString(taskMessage.Message);

            LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "CLR TaskMessagingTaskMessageHandler received following message from Task: {0}, Message: {1}.", taskMessage.TaskId, msgReceived));

            if (!msgReceived.StartsWith(MessageTask.MessageSend, true, CultureInfo.CurrentCulture))
            {
                Exceptions.Throw(new Exception("Unexpected message: " + msgReceived), "Unexpected task message received: " + msgReceived, LOGGER);
            }
        }
Exemple #4
0
            public void Handle(IDriverMessage value)
            {
                string message = string.Empty;

                LOGGER.Log(Level.Verbose, "Receieved a message from driver, handling it with HelloDriverMessageHandler");
                if (value.Message.IsPresent())
                {
                    message = ByteUtilities.ByteArrarysToString(value.Message.Value);
                }
                _parentTask.HandleDriverMessage(message);
            }
Exemple #5
0
        public ProcessedResults Decode(byte[] data)
        {
            string[] parts = ByteUtilities.ByteArrarysToString(data).Split('+');
            if (parts.Count() != 2)
            {
                throw new ArgumentException("cannot deserialize from" + ByteUtilities.ByteArrarysToString(data));
            }
            float loss = float.Parse(parts[0], CultureInfo.InvariantCulture);
            List <PartialMean> means = parts[1].Split('@').Select(PartialMean.FromString).ToList();

            return(new ProcessedResults(means, loss));
        }
Exemple #6
0
        public void TestHttpRequestSerializationBytesRoundTrip()
        {
            AvroHttpRequest r = CreatAvorHttpRequest();

            var b  = AvroHttpSerializer.ToBytes(r);
            var r1 = AvroHttpSerializer.FromBytes(b);

            var ri  = ByteUtilities.ByteArrarysToString(r.InputStream);
            var ri1 = ByteUtilities.ByteArrarysToString(r1.InputStream);

            Assert.AreEqual(ri, ri1);
            Assert.AreEqual(r.QueryString, r1.QueryString);
        }
Exemple #7
0
        public void TestHttpRequestSerializationJasonRoundTrip()
        {
            AvroHttpRequest r = CreatAvorHttpRequest();

            string str = AvroHttpSerializer.ToJson(r);

            byte[] bytes = ByteUtilities.StringToByteArrays(str);
            var    r1    = AvroHttpSerializer.FromBytesWithJoson(bytes);

            var ri  = ByteUtilities.ByteArrarysToString(r.InputStream);
            var ri1 = ByteUtilities.ByteArrarysToString(r1.InputStream);

            Assert.AreEqual(ri, ri1);
            Assert.AreEqual(r.QueryString, r1.QueryString);
        }
        public void OnNext(IFailedTask failedTask)
        {
            string errorMessage = string.Format(
                CultureInfo.InvariantCulture,
                "Task [{0}] has failed caused by [{1}], with message [{2}] and description [{3}]. The raw data for failure is [{4}].",
                failedTask.Id,
                failedTask.Reason.IsPresent() ? failedTask.Reason.Value : string.Empty,
                failedTask.Message,
                failedTask.Description.IsPresent() ? failedTask.Description.Value : string.Empty,
                failedTask.Data.IsPresent() ? ByteUtilities.ByteArrarysToString(failedTask.Data.Value) : string.Empty);

            Console.WriteLine(errorMessage);

            if (failedTask.GetActiveContext().IsPresent())
            {
                Console.WriteLine("Disposing the active context the failed task ran in.");

                // we must do something here: either close the context or resubmit a task to the active context
                failedTask.GetActiveContext().Value.Dispose();
            }
        }
Exemple #9
0
        /// <summary>
        /// Handle a context status update
        /// </summary>
        /// <param name="contextStatusProto"></param>
        /// <param name="notifyClientOnNewActiveContext"></param>
        private void Handle(ContextStatusProto contextStatusProto, bool notifyClientOnNewActiveContext)
        {
            string            contextId = contextStatusProto.context_id;
            Optional <string> parentId  = contextStatusProto.parent_id != null ?
                                          Optional <string> .Of(contextStatusProto.parent_id) : Optional <string> .Empty();

            if (ContextStatusProto.State.READY == contextStatusProto.context_state)
            {
                if (!_activeContextIds.Contains(contextId))
                {
                    EvaluatorContext evaluatorContext = new EvaluatorContext(this, contextId, parentId);
                    AddEvaluatorContext(evaluatorContext);
                    if (notifyClientOnNewActiveContext)
                    {
                        LOGGER.Log(Level.Info, "TODO: REPLACE THIS " + evaluatorContext.ToString());
                        //TODO
                        //dispatcher.onNext(ActiveContext.class, context);
                    }
                }
                foreach (ContextStatusProto.ContextMessageProto contextMessageProto in contextStatusProto.context_message)
                {
                    byte[] message  = contextMessageProto.message;
                    string sourceId = contextMessageProto.source_id;
                    LOGGER.Log(Level.Info, "TODO: REPLACE THIS " + sourceId + message);
                    //        this.dispatcher.onNext(ContextMessage.class,
                    //new ContextMessageImpl(theMessage, contextID, sourceID));
                }
            }
            else
            {
                if (!_activeContextIds.Contains(contextId))
                {
                    if (ContextStatusProto.State.FAIL == contextStatusProto.context_state)
                    {
                        AddEvaluatorContext(new EvaluatorContext(this, contextId, parentId));
                    }
                    else
                    {
                        var e = new InvalidOperationException("unknown context signaling state " + contextStatusProto.context_state);
                        Exceptions.Throw(e, LOGGER);
                    }
                }
            }

            EvaluatorContext context       = GetEvaluatorContext(contextId);
            EvaluatorContext parentContext = context.ParentId.IsPresent() ?
                                             GetEvaluatorContext(context.ParentId.Value) : null;

            RemoveEvaluatorContext(context);

            if (ContextStatusProto.State.FAIL == contextStatusProto.context_state)
            {
                // TODO
                Exception reason = new InvalidOperationException(ByteUtilities.ByteArrarysToString(contextStatusProto.error));
                Optional <IActiveContext> optionalParentContext = (null == parentContext) ?
                                                                  Optional <IActiveContext> .Empty() : Optional <IActiveContext> .Of(parentContext);

                LOGGER.Log(Level.Info, "TODO: REPLACE THIS " + reason.ToString() + optionalParentContext);
                // TODO
                //this.dispatcher.onNext(FailedContext.class,
                //context.getFailedContext(optionalParentContext, reason));
            }
            else if (ContextStatusProto.State.DONE == contextStatusProto.context_state)
            {
                if (null != parentContext)
                {
                    // TODO
                    //this.dispatcher.onNext(ClosedContext.class, context.getClosedContext(parentContext));
                }
                else
                {
                    LOGGER.Log(Level.Info, "Root context closed. Evaluator closed will trigger final shutdown.");
                }
            }
            else
            {
                var e = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unknown context state {0} for context {1}", contextStatusProto.context_state, contextId));
                Exceptions.Throw(e, LOGGER);
            }
        }
 /// <summary>
 /// helper function mostly used for logging
 /// </summary>
 /// <returns>seralized string</returns>
 public override string ToString()
 {
     return(ByteUtilities.ByteArrarysToString(new ProcessedResultsCodec().Encode(this)));
 }
 public void OnNext(IContextMessage value)
 {
     LOGGER.Log(Level.Info, "Received ContextMessage: " + ByteUtilities.ByteArrarysToString(value.Message));
 }
Exemple #12
0
        public void Handle(IRemoteMessage <EvaluatorHeartbeatProto> evaluatorHearBeatProtoMessage)
        {
            lock (_evaluatorDescriptor)
            {
                EvaluatorHeartbeatProto heartbeatProto = evaluatorHearBeatProtoMessage.Message;
                if (heartbeatProto.evaluator_status != null)
                {
                    EvaluatorStatusProto status = heartbeatProto.evaluator_status;
                    if (status.error != null)
                    {
                        Handle(new EvaluatorException(Id, ByteUtilities.ByteArrarysToString(status.error)));
                        return;
                    }
                    else if (_state == STATE.SUBMITTED)
                    {
                        string evaluatorRId = evaluatorHearBeatProtoMessage.Identifier.ToString();
                        LOGGER.Log(Level.Info, "TODO: REPLACE THIS " + evaluatorRId);
                        // TODO
                        // _evaluatorControlHandler = _remoteManager.getHandler(evaluatorRID, EvaluatorRuntimeProtocol.EvaluatorControlProto.class);
                        _state = STATE.RUNNING;
                        LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "Evaluator {0} is running", _evaluatorId));
                    }
                }

                LOGGER.Log(Level.Info, "Evaluator heartbeat: " + heartbeatProto);

                EvaluatorStatusProto evaluatorStatusProto = heartbeatProto.evaluator_status;
                foreach (ContextStatusProto contextStatusProto in heartbeatProto.context_status)
                {
                    Handle(contextStatusProto, heartbeatProto.task_status != null);
                }

                if (heartbeatProto.task_status != null)
                {
                    Handle(heartbeatProto.task_status);
                }

                if (evaluatorStatusProto.state == State.FAILED)
                {
                    _state = STATE.FAILED;
                    EvaluatorException e = evaluatorStatusProto.error != null ?
                                           new EvaluatorException(_evaluatorId, ByteUtilities.ByteArrarysToString(evaluatorStatusProto.error)) :
                                           new EvaluatorException(_evaluatorId, "unknown cause");
                    LOGGER.Log(Level.Warning, "Failed evaluator: " + Id + e.Message);
                    Handle(e);
                }
                else if (evaluatorStatusProto.state == State.DONE)
                {
                    LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "Evaluator {0} done", Id));
                    _state = STATE.DONE;

                    // TODO
                    // dispatcher.onNext(CompletedEvaluator.class, new CompletedEvaluator() {
                    //@Override
                    //public String getId() {
                    //  return EvaluatorManager.this.evaluatorId;
                    Dispose();
                }
            }
            LOGGER.Log(Level.Info, "DONE with evaluator heartbeat");
        }
Exemple #13
0
 /// <summary>
 /// helper function mostly used for logging
 /// </summary>
 /// <returns>the serialized string</returns>
 public override string ToString()
 {
     return(ByteUtilities.ByteArrarysToString(new CentroidsCodec().Encode(this)));
 }
Exemple #14
0
 private void Check()
 {
     if (_result.IsPresent() && _lastException.IsPresent())
     {
         LOGGER.Log(Level.Warning, "Both task result and exception are present, the expcetion will take over. Thrown away result:" + ByteUtilities.ByteArrarysToString(_result.Value));
         State   = TaskState.Failed;
         _result = Optional <byte[]> .Empty();
     }
 }
Exemple #15
0
        public void OnNext(IRemoteMessage <REEFMessage> value)
        {
            REEFMessage       remoteEvent = value.Message;
            IRemoteIdentifier id          = value.Identifier;

            LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "receive a ReefMessage from {0} Driver at {1}.", remoteEvent, id));

            if (remoteEvent.evaluatorControl != null)
            {
                if (remoteEvent.evaluatorControl.context_control != null)
                {
                    string context_message = null;
                    string task_message    = null;

                    if (remoteEvent.evaluatorControl.context_control.context_message != null)
                    {
                        context_message = remoteEvent.evaluatorControl.context_control.context_message.ToString();
                    }
                    if (remoteEvent.evaluatorControl.context_control.task_message != null)
                    {
                        task_message = ByteUtilities.ByteArrarysToString(remoteEvent.evaluatorControl.context_control.task_message);
                    }

                    if (!(string.IsNullOrEmpty(context_message) && string.IsNullOrEmpty(task_message)))
                    {
                        LOGGER.Log(Level.Info,
                                   string.Format(CultureInfo.InvariantCulture, "Control protobuf with context message [{0}] and task message [{1}]", context_message, task_message));
                    }
                    else if (remoteEvent.evaluatorControl.context_control.remove_context != null)
                    {
                        LOGGER.Log(Level.Info,
                                   string.Format(CultureInfo.InvariantCulture, "Control protobuf to remove context {0}", remoteEvent.evaluatorControl.context_control.remove_context.context_id));
                    }
                    else if (remoteEvent.evaluatorControl.context_control.add_context != null)
                    {
                        LOGGER.Log(Level.Info,
                                   string.Format(CultureInfo.InvariantCulture, "Control protobuf to add a context on top of {0}", remoteEvent.evaluatorControl.context_control.add_context.parent_context_id));
                    }
                    else if (remoteEvent.evaluatorControl.context_control.start_task != null)
                    {
                        LOGGER.Log(Level.Info,
                                   string.Format(CultureInfo.InvariantCulture, "Control protobuf to start an task in {0}", remoteEvent.evaluatorControl.context_control.start_task.context_id));
                    }
                    else if (remoteEvent.evaluatorControl.context_control.stop_task != null)
                    {
                        LOGGER.Log(Level.Info, "Control protobuf to stop task");
                    }
                    else if (remoteEvent.evaluatorControl.context_control.suspend_task != null)
                    {
                        LOGGER.Log(Level.Info, "Control protobuf to suspend task");
                    }
                }
            }
            if (_count == 0)
            {
                _begin     = DateTime.Now;
                _origBegin = _begin;
            }
            var count = Interlocked.Increment(ref _count);

            int printBatchSize = 100000;

            if (count % printBatchSize == 0)
            {
                DateTime end             = DateTime.Now;
                var      diff            = (end - _begin).TotalMilliseconds;
                double   seconds         = diff / 1000.0;
                long     eventsPerSecond = (long)(printBatchSize / seconds);
                _begin = DateTime.Now;
            }

            var observer = _observer;

            if (observer != null)
            {
                observer.OnNext(value);
            }
        }
Exemple #16
0
 public static T FromBytes(byte[] bytes)
 {
     return(FromString(ByteUtilities.ByteArrarysToString(bytes)));
 }
Exemple #17
0
 public void OnHttpRequest(ReefHttpRequest requet, ReefHttpResponse response)
 {
     LOGGER.Log(Level.Info, string.Format(CultureInfo.CurrentCulture, "HelloHttpHandler OnHttpRequest: URL: {0}, QueryString: {1}, inputStream: {2}.", requet.Url, requet.Querystring, ByteUtilities.ByteArrarysToString(requet.InputStream)));
     response.Status       = HttpStatusCode.OK;
     response.OutputStream =
         ByteUtilities.StringToByteArrays("Byte array returned from HelloHttpHandler in CLR!!!");
 }
Exemple #18
0
 public override string ToString()
 {
     return("DriverMessage [value=" + ByteUtilities.ByteArrarysToString(_value.Value) + "]");
 }
 public void OnNext(byte[] value)
 {
     LOGGER.Log(Level.Info, "Received message: " + ByteUtilities.ByteArrarysToString(value));
 }
Exemple #20
0
 public void OnNext(byte[] value)
 {
     Exceptions.Throw(new InvalidOperationException("No handler bound for client Close With Message event:" + ByteUtilities.ByteArrarysToString(value)),
                      Logger.GetLogger(typeof(DefaultClientCloseWithMessageHandler)));
 }
        /// <summary>
        /// Conver bytes which contains Json string into AvroHttpRequest object
        /// </summary>
        /// <param name="serializedBytes">The serialized bytes.</param>
        /// <returns>AvroHttpRequest.</returns>
        public static AvroHttpRequest FromBytesWithJoson(byte[] serializedBytes)
        {
            string s = ByteUtilities.ByteArrarysToString(serializedBytes);

            return(FromJson(s));
        }