private void SetupLocalAe(params string[] names)
        {
            var claraCrdList = new ClaraApplicationEntityCustomResourceList();

            claraCrdList.Items = new List <ClaraApplicationEntityCustomResource>();
            foreach (var name in names)
            {
                var aet = new ClaraApplicationEntityCustomResource
                {
                    Spec = new ClaraApplicationEntity
                    {
                        AeTitle           = name,
                        Name              = name,
                        ProcessorSettings = new Dictionary <string, string>()
                        {
                            { "pipeline-test", "123" }
                        }
                    },
                    Metadata = new V1ObjectMeta {
                        Name = name
                    }
                };
                claraCrdList.Items.Add(aet);
            }

            _dicomAdapterFixture.KubernetesClient
            .Setup(p => p.ListNamespacedCustomObjectWithHttpMessagesAsync(It.Is <CustomResourceDefinition>(p => p.Kind == "ClaraAeTitle")))
            .Returns(Task.FromResult(new HttpOperationResponse <object>
            {
                Body     = new object(),
                Response = new HttpResponseMessage {
                    Content = new StringContent(JsonConvert.SerializeObject(claraCrdList))
                }
            }));
        }
Exemplo n.º 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));
                }
            }
        }