private void ValidateProcessor(ClaraApplicationEntity claraAe)
        {
            Guard.Against.Null(claraAe, nameof(claraAe));

            if (!_configurationValidator.IsClaraAeTitleValid(_dicomAdapterConfiguration.Value.Dicom.Scp.AeTitles, "dicom>scp>ae-title", claraAe, true))
            {
                throw new Exception("Invalid Clara (local) AE Title specs provided or AE Title already exits");
            }

            var type      = typeof(JobProcessorBase).GetType <JobProcessorBase>(claraAe.Processor);
            var attribute = (ProcessorValidationAttribute)Attribute.GetCustomAttributes(type, typeof(ProcessorValidationAttribute)).FirstOrDefault();

            if (attribute == null)
            {
                throw new ConfigurationException($"Processor type {claraAe.Processor} does not have a `ProcessorValidationAttribute` defined.");
            }

            var validator = attribute.ValidatorType.CreateInstance <IJobProcessorValidator>(_serviceProvider);

            validator.Validate(claraAe.AeTitle, claraAe.ProcessorSettings);
        }
Пример #2
0
        private void HandleClaraAeTitleEvents(WatchEventType eventType, ClaraApplicationEntityCustomResource item)
        {
            lock (SyncRoot)
            {
                switch (eventType)
                {
                case WatchEventType.Added:
                    if (!_configurationValidator.IsClaraAeTitleValid(_configuration.Value.Dicom.Scp.AeTitles, "dicom>scp>ae-title", item.Spec, true))
                    {
                        _logger.Log(LogLevel.Error, $"The configured Clara AE Title is invalid: {item.Spec.Name} with AE Title {item.Spec.AeTitle}.");
                        return;
                    }

                    _configuration.Value.Dicom.Scp.AeTitles.Add(item.Spec);
                    _logger.Log(LogLevel.Information, $"Clara AE Title added: {item.Spec.AeTitle} with processor: {string.Join(",", item.Spec.Processor)}");
                    break;

                case WatchEventType.Deleted:
                    var deleted = _configuration.Value.Dicom.Scp.AeTitles.FirstOrDefault(p => p.Name.Equals(item.Spec.Name, StringComparison.OrdinalIgnoreCase));
                    if (deleted != null)
                    {
                        _configuration.Value.Dicom.Scp.AeTitles.Remove(deleted);
                    }

                    _logger.Log(LogLevel.Information, $"Clara AE Title deleted: {item.Spec.Name}");
                    break;

                default:
                    _logger.Log(LogLevel.Warning, $"Unsupported watch event type {eventType} detected for {item.Metadata.Name}");
                    break;
                }

                if (ClaraAeTitlesChanged != null)
                {
                    ClaraAeTitlesChanged(item.Spec, new AeTitleUpdatedEventArgs(eventType));
                }
            }
        }
Пример #3
0
        private object CreateCrdFromType(T item)
        {
            if (item is ClaraApplicationEntity claraAe)
            {
                if (!_configurationValidator.IsClaraAeTitleValid(_dicomAdapterConfiguration.Value.Dicom.Scp.AeTitles, "dicom>scp>ae-title", claraAe, true))
                {
                    throw new Exception("Invalid Clara (local) AE Title specs provided or AE Title already exits");
                }

                claraAe.SetDefaultValues();

                return(new ClaraApplicationEntityCustomResource
                {
                    Kind = _customResourceDefinition.Kind,
                    ApiVersion = _customResourceDefinition.ApiVersion,
                    Metadata = new k8s.Models.V1ObjectMeta
                    {
                        Name = claraAe.Name.ToLowerInvariant()
                    },
                    Spec = claraAe,
                    Status = AeTitleStatus.Default
                });
            }
            else if (item is SourceApplicationEntity sourceAe)
            {
                if (!_dicomAdapterConfiguration.Value.ReadAeTitlesFromCrd)
                {
                    throw new CrdNotEnabledException("dicom>scp>read-sources-from-crd is disabled");
                }

                if (!_configurationValidator.IsSourceValid(sourceAe))
                {
                    throw new Exception("Invalid source AE Title specs provided");
                }

                return(new SourceApplicationEntityCustomResource
                {
                    Kind = _customResourceDefinition.Kind,
                    ApiVersion = _customResourceDefinition.ApiVersion,
                    Metadata = new k8s.Models.V1ObjectMeta
                    {
                        Name = sourceAe.AeTitle.ToLowerInvariant()
                    },
                    Spec = sourceAe,
                    Status = AeTitleStatus.Default
                });
            }
            else if (item is DestinationApplicationEntity destAe)
            {
                if (!_dicomAdapterConfiguration.Value.ReadAeTitlesFromCrd)
                {
                    throw new CrdNotEnabledException("dicom>scu>read-destinations-from-crd is disabled");
                }

                if (!_configurationValidator.IsDestinationValid(destAe))
                {
                    throw new Exception("Invalid destination specs provided");
                }

                return(new DestinationApplicationEntityCustomResource
                {
                    Kind = _customResourceDefinition.Kind,
                    ApiVersion = _customResourceDefinition.ApiVersion,
                    Metadata = new k8s.Models.V1ObjectMeta
                    {
                        Name = destAe.Name.ToLowerInvariant()
                    },
                    Spec = destAe,
                    Status = AeTitleStatus.Default
                });
            }
            throw new ApplicationException($"Unsupported data type: {item.GetType()}");
        }