Ejemplo n.º 1
0
        private async Task <List <ComponentModel> > PushAnalyserJobConfig(
            string storageChannelName,

            JobConfigUpdateCommand jobConfigUpdateCommand)
        {
            var analysers = new List <ComponentModel>();

            foreach (var analyser in jobConfigUpdateCommand.DataAnalysers)
            {
                var analyserComponent = await _componentRegistry
                                        .GetComponentByIdAsync(analyser);

                if (analyserComponent == null)
                {
                    _logger.TrackWarning(
                        "ComponentConfig",
                        $"Analyser {analyser} was not registered");
                }
                else
                {
                    analysers.Add(analyserComponent);
                }
            }

            var notification = new AnalyserConfigUpdateNotification()
            {
                JobId      = jobConfigUpdateCommand.JobId,
                Attributes = new Dictionary <string, string>(),
                OutputMessageBrokerChannels = new[] { storageChannelName },
            };

            var configUpdateTasks = analysers.Select(async analyserCmp =>
            {
                _logger.TrackInfo(
                    "ComponentConfig",
                    $"Config pushed to: {analyserCmp}, updateChannelName: {analyserCmp.UpdateChannelName}",
                    new
                {
                    config = notification
                });

                await _componentConfigUpdateNotifier.NotifyComponentAsync(
                    analyserCmp.UpdateChannelName,
                    notification);

                var componentConfig = new JobComponentConfig
                {
                    ComponentId = analyserCmp.ComponentId,
                    Attributes  = analyserCmp.Attributes,
                    JobId       = jobConfigUpdateCommand.JobId,
                    OutputMessageBrokerChannels = notification.OutputMessageBrokerChannels
                };

                await _componentRegistry.InsertJobComponentConfigAsync(componentConfig);
            });

            await Task.WhenAll(configUpdateTasks);

            return(analysers);
        }
Ejemplo n.º 2
0
        private async Task PushNetworkDataAcquisitionJobConfig(
            string storageChannelName,
            IEnumerable <string> selectedAnalysersChannels,
            JobConfigUpdateCommand jobConfigUpdateCommand)
        {
            var outputChannels = selectedAnalysersChannels
                                 .Concat(new[] { storageChannelName, })
                                 .ToArray();

            foreach (var dataAcquirer in jobConfigUpdateCommand.DataAcquirers)
            {
                var attributes = jobConfigUpdateCommand
                                 .Attributes.GetValue(dataAcquirer)?.ToObject <JObject>() ?? new JObject();

                try
                {
                    var topicQuery = new JProperty("TopicQuery", jobConfigUpdateCommand.TopicQuery);
                    attributes.Add(topicQuery);
                    var languageProperty = new JProperty("Language", jobConfigUpdateCommand.Language);
                    attributes.Add(languageProperty);
                }
                catch (Exception e)
                {
                    _logger.TrackError(
                        "PushNetworkJobConfig",
                        "Error while adding attributes",
                        new
                    {
                        jobId     = jobConfigUpdateCommand.JobId,
                        exception = e
                    });

                    throw;
                }

                var notification = new DataAcquisitionConfigUpdateNotification
                {
                    JobId      = jobConfigUpdateCommand.JobId,
                    Attributes = attributes,
                    OutputMessageBrokerChannels = outputChannels,
                    Command = JobCommand.Start
                };

                await NotifyComponent(
                    jobConfigUpdateCommand.JobId,
                    dataAcquirer,
                    notification);

                var componentConfig = new JobComponentConfig
                {
                    ComponentId = dataAcquirer,
                    Attributes  = attributes,
                    JobId       = jobConfigUpdateCommand.JobId,
                    OutputMessageBrokerChannels = notification.OutputMessageBrokerChannels
                };

                await _componentRegistry.InsertJobComponentConfigAsync(componentConfig);
            }
        }
Ejemplo n.º 3
0
        public async Task <JobConfigUpdateResult> StartJobAsync(
            JobConfigUpdateCommand jobConfigUpdateCommand)
        {
            var storage = _componentRegistry.GetRegisteredStorage();

            if (storage == null)
            {
                _logger.TrackError(
                    "StartJob",
                    "No storage component was registered");
                return(JobConfigUpdateResult.Failed("No storage is present. Job can't be done"));
            }


            var job = new Job
            {
                FinishedAt = null,
                JobName    = jobConfigUpdateCommand.JobName,
                JobStatus  = JobStatus.Running,
                JobId      = jobConfigUpdateCommand.JobId,
                Owner      = "admin",
                TopicQuery = jobConfigUpdateCommand.TopicQuery,
                StartedAt  = DateTime.Now,
            };

            var analysers = await PushAnalyserJobConfig(
                storage.AnalysedDataInputChannel,
                jobConfigUpdateCommand);


            var analysersInputs = analysers.Select(r => r.InputChannelName).ToArray();

            await PushNetworkDataAcquisitionJobConfig(
                storage.AcquiredDataInputChannel,
                analysersInputs,
                jobConfigUpdateCommand);

            await _jobStorage.InsertNewJobAsync(job);

            return(JobConfigUpdateResult.Successfull(
                       jobConfigUpdateCommand.JobId,
                       JobStatus.Running));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <JobResponse> > SubmitJob()
        {
            var body = await new System.IO.StreamReader(this.Request.Body).ReadToEndAsync();
            JobSubmitRequest jobSubmitRequest = JsonConvert.DeserializeObject <JobSubmitRequest>(body);

            if (jobSubmitRequest == null)
            {
                return(BadRequest("Invalid body"));
            }
            if (jobSubmitRequest?.SelectedDataAnalysers?.Any() == false)
            {
                return(BadRequest("No analysers were selected"));
            }
            if (jobSubmitRequest?.SelectedDataAcquirers?.Any() == false)
            {
                return(BadRequest("No analysers were selected"));
            }

            var jobId = Guid.NewGuid();
            var jobConfigUpdateNotification = JobConfigUpdateCommand.NewJob(
                jobId,
                jobSubmitRequest.JobName,
                jobSubmitRequest.SelectedDataAnalysers,
                jobSubmitRequest.SelectedDataAcquirers,
                jobSubmitRequest.TopicQuery,
                jobSubmitRequest.Language,
                jobSubmitRequest.Attributes
                );

            var configUpdateResult = await _subscribedComponentManager
                                     .StartJobAsync(jobConfigUpdateNotification);

            if (configUpdateResult.HasError)
            {
                return(BadRequest($"Job submit failed, error: {configUpdateResult.Error}"));
            }

            var jobSubmitResponse = new JobResponse(
                configUpdateResult.JobId,
                configUpdateResult.Status);

            return(Ok(jobSubmitResponse));
        }