Ejemplo n.º 1
0
        private static EvaluatorException CreateEvaluatorException(EvaluatorInfo eval)
        {
            var failureInfo = eval.Failure;
            var errorBytes  = failureInfo.Exception.Data.ToByteArray();

            if (errorBytes == null || errorBytes.Length == 0)
            {
                Logger.Log(Level.Error, "Exception without object details: {0}", failureInfo.Exception.Message);
                return(new EvaluatorException(
                           eval.EvaluatorId,
                           failureInfo.Exception.Message,
                           string.Join(";", failureInfo.Exception.StackTrace)));
            }
            // When the Exception originates from the C# side.
            Exception inner;

            try
            {
                inner = (Exception)ByteUtilities.DeserializeFromBinaryFormat(errorBytes);
            }
            catch (SerializationException se)
            {
                inner = NonSerializableEvaluatorException.UnableToDeserialize(
                    "Exception from Evaluator was not able to be deserialized, returning a NonSerializableEvaluatorException.",
                    se);
            }
            return(new EvaluatorException(eval.EvaluatorId, inner.Message, inner));
        }
Ejemplo n.º 2
0
 private BridgeFailedContext CreateFailedContextAndForget(EvaluatorInfo info, string contextId)
 {
     lock (_lock)
     {
         var evaluatorId = info.EvaluatorId;
         if (_activeContexts.TryGetValue(contextId, out BridgeActiveContext activeContext))
         {
             _activeContexts.Remove(contextId);
             var parentContext = activeContext.ParentId.IsPresent()
                 ? _activeContexts[activeContext.ParentId.Value]
                 : null;
             return(new BridgeFailedContext(contextId,
                                            evaluatorId,
                                            activeContext.EvaluatorDescriptor,
                                            Optional <IActiveContext> .OfNullable(parentContext)));
         }
         else
         {
             return(new BridgeFailedContext(contextId,
                                            evaluatorId,
                                            CreateEvaluatorDescriptor(info.DescriptorInfo),
                                            Optional <IActiveContext> .Empty()));
         }
     }
 }
Ejemplo n.º 3
0
 public override async Task <Void> DriverRestartFailedEvaluatorHandler(EvaluatorInfo request, ServerCallContext context)
 {
     try
     {
         await _driverBridge.DispatchDriverRestartFailedEvaluatorEvent(CreateFailedEvaluator(request));
     }
     catch (Exception ex)
     {
         _bridgeClock.Dispose(ex);
     }
     return(Void);
 }
Ejemplo n.º 4
0
 public override async Task <Void> FailedEvaluatorHandler(EvaluatorInfo info, ServerCallContext context)
 {
     try
     {
         Logger.Log(Level.Info, "Failed evaluator id {0}", info.EvaluatorId);
         await _driverBridge.DispatchFailedEvaluatorEvent(CreateFailedEvaluator(info));
     }
     catch (Exception ex)
     {
         _bridgeClock.Dispose(ex);
     }
     return(Void);
 }
Ejemplo n.º 5
0
 public override async Task <Void> CompletedEvaluatorHandler(EvaluatorInfo request, ServerCallContext context)
 {
     try
     {
         Logger.Log(Level.Info, "Completed evaluator id {0}", request.EvaluatorId);
         await _driverBridge.DispatchCompletedEvaluatorEvent(new BridgeCompletedEvaluator(request.EvaluatorId));
     }
     catch (Exception ex)
     {
         _bridgeClock.Dispose(ex);
     }
     return(Void);
 }
Ejemplo n.º 6
0
        // Evaluator handlers

        public override async Task <Void> AllocatedEvaluatorHandler(EvaluatorInfo request, ServerCallContext context)
        {
            try
            {
                Logger.Log(Level.Info, "Allocated evaluator id {0}", request.EvaluatorId);
                var evaluatorDescriptor = CreateEvaluatorDescriptor(request.DescriptorInfo);
                await _driverBridge.DispatchAllocatedEvaluatorEventAsync(
                    new BridgeAllocatedEvaluator(request.EvaluatorId, _driverServiceClient, evaluatorDescriptor));
            }
            catch (Exception ex)
            {
                _bridgeClock.Dispose(ex);
            }
            return(Void);
        }
Ejemplo n.º 7
0
        static EvaluatorInfo GetEvaluatorInfo(string expr, IEnumerable <string> argNames)
        {
            EvaluatorInfo evaluatorInfo;

            lock (s_evaluators)
            {
                if (!s_evaluators.TryGetValue(expr, out evaluatorInfo))
                {
                    evaluatorInfo                = new EvaluatorInfo();
                    evaluatorInfo.Parameters     = new List <ParameterExpression>();
                    evaluatorInfo.RootExpression = CreateExpr(evaluatorInfo.Parameters,
                                                              s_tokenRegex.Matches(expr).Cast <Match>().ToArray());
                    s_evaluators.Add(expr, evaluatorInfo);
                }
            }

            if (evaluatorInfo.Parameters.Select(p => p.Name).Except(argNames).Any())
            {
                throw new ArgumentException("Expression uses arguments other than the specified", "expr");
            }

            return(evaluatorInfo);
        }
Ejemplo n.º 8
0
        private BridgeFailedEvaluator CreateFailedEvaluator(EvaluatorInfo info)
        {
            try
            {
                var failedContexts = info.Failure.FailedContexts.Select(contextId =>
                                                                        CreateFailedContextAndForget(info, contextId)).Cast <IFailedContext>().ToList();
                var failedTask = string.IsNullOrEmpty(info.Failure.FailedTaskId)
                    ? Optional <IFailedTask> .Empty()
                    : Optional <IFailedTask> .Of(CreateFailedTaskAndForget(info.Failure.FailedTaskId,
                                                                           info.Failure.Exception,
                                                                           Optional <IActiveContext> .Empty()));

                return(new BridgeFailedEvaluator(
                           info.EvaluatorId,
                           CreateEvaluatorException(info),
                           failedContexts,
                           failedTask));
            }
            catch (Exception ex)
            {
                Logger.Log(Level.Error, "could not create failed evaluator", ex);
                throw;
            }
        }
Ejemplo n.º 9
0
 public DictionaryEvaluator(string name, IDictionary <string, string> propertyValues)
 {
     Info            = new EvaluatorInfo(name);
     _propertyValues = propertyValues;
 }
Ejemplo n.º 10
0
 public DictionaryEvaluator()
 {
     Info            = new EvaluatorInfo("dict");
     _propertyValues = new Dictionary <string, string>();
 }