Exemplo 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);
        }
Exemplo 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);
            }
        }
Exemplo n.º 3
0
 public Task InsertJobComponentConfigAsync(JobComponentConfig jobConfig)
 {
     _jobComponentConfigs.AddOrUpdate(
         jobConfig.ComponentId,
         new List <JobComponentConfig> {
         jobConfig
     },
         (key, list) =>
     {
         list.Add(jobConfig);
         return(list);
     });
     return(Task.CompletedTask);
 }
Exemplo n.º 4
0
        public async Task InsertJobComponentConfigAsync(JobComponentConfig jobConfig)
        {
            await WaitOnStorage();

            var jsonBody    = JsonConvert.SerializeObject(jobConfig);
            var httpContent = new StringContent(jsonBody, Encoding.UTF8, "application/json");

            var jobConfigUri = new Uri(
                _insertComponentJobConfigUriTemplate
                .Replace("componentId", jobConfig.ComponentId));

            var response = await _httpClient.PostAsync(jobConfigUri, httpContent);

            if (!response.IsSuccessStatusCode)
            {
                var error = await response.Content.ReadAsStringAsync();

                throw new InvalidOperationException($"Adding job to storage failed: {error}");
            }
        }
Exemplo n.º 5
0
        private async Task InsertComponentJobConfigAsync(string componentId, Guid jobId)
        {
            IEnumerable <string> assert(JobComponentConfig a, JobComponentConfig b)
            {
                yield return(AssertProperty("ComponentId", (r) => r.ComponentId, a, b));

                yield return(AssertProperty("JobId", (r) => r.JobId, a, b));

                yield return(AssertProperty("OutputChannel(Length)", (r) => r.OutputMessageBrokerChannels.Length, a, b));

                yield return(AssertProperty("OutputChannel(Item)", (r) => r.OutputMessageBrokerChannels[0], a, b));

                yield return(AssertProperty("Attributes", (r) => r.Attributes?.Count, a, b));
            }

            var jobComponent = new JobComponentConfig
            {
                ComponentId = componentId,
                JobId       = jobId,
                OutputMessageBrokerChannels = new[] { "channels.output1" },
                Attributes = new JObject()
            };
            await _componentRegistry.InsertJobComponentConfigAsync(jobComponent);

            var components = await _componentRegistry.GetAllComponentJobConfigsAsync(componentId);


            if (components.Count != 1)
            {
                throw new JmsAssertException("invalid amount of components retrieved");
            }

            var errors = assert(jobComponent, components[0]).Where(r => !(r is null));

            AssertErrors("Component Job config", errors);
        }
Exemplo n.º 6
0
 public Task InsertJobComponentConfigAsync(JobComponentConfig jobConfig)
 {
     return(Task.CompletedTask);
 }