Пример #1
0
        public void Read()
        {
            if (this.validator == null)
            {
                this.validator = this.Factory.CreateInstance<IValidationActor>(typeof(ValidationActor));
            }

            this.GetAndValidateInput(this.validator);
        }
        private async Task ExecuteValidationActors(IPreValidationContext validationContext, CancellationToken cancellationToken)
        {
            // Get L/A and split the learners into separate lists
            IEnumerable <IMessage> messageShards = _learnerPerActorService.Process();

            List <Task <string> > actorTasks = new List <Task <string> >();

            foreach (IMessage messageShard in messageShards)
            {
                _logger.LogDebug($"validation Shard has {messageShard.Learners.Count} learners");

                // create actors for each Shard.
                IValidationActor actor = GetValidationActor();

                // TODO:get reference data per each shard and send it to Actors
                byte[] ilrMessageAsBytes = Encoding.UTF8.GetBytes(_jsonSerializationService.Serialize(messageShard));

                byte[] internalDataCacheAsBytes =
                    Encoding.UTF8.GetBytes(_jsonSerializationService.Serialize(_internalDataCache));
                byte[] externalDataCacheAsBytes =
                    Encoding.UTF8.GetBytes(_jsonSerializationService.Serialize(_externalDataCache));
                byte[] fileDataCacheAsBytes =
                    Encoding.UTF8.GetBytes(_jsonSerializationService.Serialize(_fileDataCache));

                ValidationActorModel validationActorModel = new ValidationActorModel
                {
                    JobId             = validationContext.JobId,
                    Message           = ilrMessageAsBytes,
                    InternalDataCache = internalDataCacheAsBytes,
                    ExternalDataCache = externalDataCacheAsBytes,
                    FileDataCache     = fileDataCacheAsBytes,
                };

                actorTasks.Add(actor.Validate(validationActorModel, cancellationToken));
            }

            _logger.LogDebug($"Starting {actorTasks.Count} validation actors");

            await Task.WhenAll(actorTasks.ToArray()).ConfigureAwait(false);

            _logger.LogDebug("All Validation Actors completed");

            cancellationToken.ThrowIfCancellationRequested();

            foreach (Task <string> actorTask in actorTasks)
            {
                IEnumerable <U> errors = _jsonSerializationService.Deserialize <IEnumerable <U> >(actorTask.Result);

                foreach (U error in errors)
                {
                    _validationErrorCache.Add(error);
                }
            }
        }
Пример #3
0
        private void GetAndValidateInput(IValidationActor validator)
        {
            var message = Console.ReadLine();

            if (String.Equals(message, ExitCommand, StringComparison.OrdinalIgnoreCase))
            {
                // shut down the entire actor system (allows the process to exit)
                Program.DontBreak = false;
            }
            else
            {
                this.validator.Validate(message);
            }
        }
        private async Task DestroyValidationActorAsync(IValidationActor validationActor, CancellationToken cancellationToken)
        {
            try
            {
                ActorId actorId = validationActor.GetActorId();

                IActorService myActorServiceProxy = ActorServiceProxy.Create(
                    new Uri($"{FabricRuntime.GetActivationContext().ApplicationName}/ValidationActorService"),
                    actorId);

                await myActorServiceProxy.DeleteActorAsync(actorId, cancellationToken);
            }
            catch (Exception ex)
            {
                _logger.LogError("Problem deleting actor", ex);
            }
        }
        private async Task ExecuteValidationActors(IPreValidationContext validationContext, CancellationToken cancellationToken)
        {
            // Get L/A and split the learners into separate lists
            IEnumerable <IMessage> learnerMessageShards = await _learnerPerActorProviderService.ProvideAsync();

            IEnumerable <IMessage> learnerDPMessageShards = await _learnerDPPerActorProviderService.ProvideAsync();

            List <IValidationActor>   learnerValidationActors   = new List <IValidationActor>();
            List <IValidationDPActor> learnerDPValidationActors = new List <IValidationDPActor>();
            List <Task <string> >     actorTasks = new List <Task <string> >();
            List <Task> actorDestroys            = new List <Task>();

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            _logger.LogDebug($"Validation will create {learnerMessageShards?.Count() ?? 0} actors");
            _logger.LogDebug($"DP Validation will create {learnerDPMessageShards?.Count() ?? 0} actors");

            string internalDataCacheAsString =
                _jsonSerializationService.Serialize(_internalDataCache);

            _logger.LogDebug($"_internalDataCache {internalDataCacheAsString.Length}");
            string fileDataCacheAsString =
                _jsonSerializationService.Serialize(_fileDataCache);

            _logger.LogDebug($"fileDataCacheAsString {fileDataCacheAsString.Length}");
            string externalDataCacheAsString =
                _jsonSerializationService.Serialize(_externalDataCache);

            _logger.LogDebug($"ExternalDataCache: {externalDataCacheAsString.Length}");
            string taskListAsString = _jsonSerializationService.Serialize(validationContext.Tasks);

            _logger.LogDebug($"taskListAsString {taskListAsString.Length}");

            if (learnerMessageShards != null)
            {
                foreach (IMessage messageShard in learnerMessageShards)
                {
                    _logger.LogDebug($"Validation Shard has {messageShard.Learners.Count} learners");

                    // create actors for each Shard.
                    IValidationActor actor = GetValidationActor();
                    learnerValidationActors.Add(actor);

                    // TODO:get reference data per each shard and send it to Actors
                    string ilrMessageAsString = _jsonSerializationService.Serialize(messageShard);

                    ValidationActorModel validationActorModel = new ValidationActorModel
                    {
                        JobId             = validationContext.JobId,
                        Message           = ilrMessageAsString,
                        InternalDataCache = internalDataCacheAsString,
                        ExternalDataCache = externalDataCacheAsString,
                        FileDataCache     = fileDataCacheAsString,
                        TaskList          = taskListAsString
                    };

                    actorTasks.Add(actor.Validate(validationActorModel, cancellationToken));
                }
            }

            if (learnerDPMessageShards != null)
            {
                foreach (IMessage messageShard in learnerDPMessageShards)
                {
                    _logger.LogDebug($"DP Validation Shard has {messageShard.LearnerDestinationAndProgressions.Count} learner DP records");

                    // create actors for each Shard.
                    IValidationDPActor actor = GetValidationDPActor();
                    learnerDPValidationActors.Add(actor);

                    // TODO:get reference data per each shard and send it to Actors
                    string ilrMessageAsString = _jsonSerializationService.Serialize(messageShard);

                    ValidationDPActorModel validationActorModel = new ValidationDPActorModel
                    {
                        JobId             = validationContext.JobId,
                        Message           = ilrMessageAsString,
                        InternalDataCache = internalDataCacheAsString,
                        ExternalDataCache = externalDataCacheAsString,
                        FileDataCache     = fileDataCacheAsString,
                        TaskList          = taskListAsString
                    };

                    actorTasks.Add(actor.Validate(validationActorModel, cancellationToken));
                }
            }

            _logger.LogDebug($"Starting {actorTasks.Count} validation actors after {stopWatch.ElapsedMilliseconds}ms prep time");
            stopWatch.Restart();

            await Task.WhenAll(actorTasks.ToArray()).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();

            _logger.LogDebug($"Collating {actorTasks.Count} validation actors after {stopWatch.ElapsedMilliseconds}ms execution time");
            stopWatch.Restart();

            foreach (Task <string> actorTask in actorTasks)
            {
                IEnumerable <U> errors = _jsonSerializationService.Deserialize <IEnumerable <U> >(actorTask.Result);

                foreach (U error in errors)
                {
                    _validationErrorCache.Add(error);
                }
            }

            _logger.LogDebug($"Destroying {actorTasks.Count} validation actors after {stopWatch.ElapsedMilliseconds}ms collation time");

            foreach (IValidationActor validationActor in learnerValidationActors)
            {
                actorDestroys.Add(DestroyValidationActorAsync(validationActor, cancellationToken));
            }

            foreach (IValidationDPActor validationDPActor in learnerDPValidationActors)
            {
                actorDestroys.Add(DestroyValidationDPActorAsync(validationDPActor, cancellationToken));
            }

            await Task.WhenAll(actorDestroys.ToArray()).ConfigureAwait(false);
        }