Beispiel #1
0
        public async Task <ActionResult <string> > Create(SourceApplicationEntity item)
        {
            try
            {
                if (!item.IsValid(_dicomAdapterRepository.AsQueryable().Select(p => p.AeTitle), out IList <string> validationErrors))
                {
                    throw new ConfigurationException(string.Join(Environment.NewLine, validationErrors));
                }

                await _dicomAdapterRepository.AddAsync(item);

                await _dicomAdapterRepository.SaveChangesAsync();

                _logger.Log(LogLevel.Information, $"DICOM source added AE Title={item.AeTitle}, Host/IP={item.HostIp}.");
                return(CreatedAtAction(nameof(GetAeTitle), new { aeTitle = item.AeTitle }, item));
            }
            catch (ConfigurationException ex)
            {
                return(Problem(title: "Validation error.", statusCode: (int)System.Net.HttpStatusCode.BadRequest, detail: ex.Message));
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, ex, "Error adding new Source Application Entity.");
                return(Problem(title: "Error adding new Source Application Entity.", statusCode: (int)System.Net.HttpStatusCode.InternalServerError, detail: ex.Message));
            }
        }
Beispiel #2
0
        private void ValidateProcessor(ClaraApplicationEntity claraAe)
        {
            Guard.Against.Null(claraAe, nameof(claraAe));

            if (!claraAe.IsValid(_dicomAdapterRepository.AsQueryable().Select(p => p.AeTitle), out IList <string> validationErrors))
            {
                throw new ConfigurationException(string.Join(Environment.NewLine, validationErrors));
            }

            ProcessorValidationAttribute attribute;

            try
            {
                var type = typeof(JobProcessorBase).GetType <JobProcessorBase>(claraAe.Processor);
                attribute = (ProcessorValidationAttribute)Attribute.GetCustomAttributes(type, typeof(ProcessorValidationAttribute)).FirstOrDefault();
            }
            catch (ConfigurationException ex)
            {
                throw new ConfigurationException($"Invalid job processor: {ex.Message}.", ex);
            }

            if (attribute is 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);
        }
        public async Task <InferenceJob> Take(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                _logger.Log(LogLevel.Debug, $"Queryig for new job...");
                var request = _inferenceJobRepository
                              .AsQueryable()
                              .Where(p => (p.State == InferenceJobState.Queued ||
                                           p.State == InferenceJobState.Created ||
                                           p.State == InferenceJobState.PayloadUploaded ||
                                           p.State == InferenceJobState.MetadataUploaded) &&
                                     p.LastUpdate < DateTime.UtcNow.AddSeconds(-_configuration.Value.Services.Platform.RetryDelaySeconds))
                              .OrderBy(p => p.LastUpdate)
                              .FirstOrDefault();

                if (!(request is null))
                {
                    using var loggerScope = _logger.BeginScope(new LogginDataDictionary <string, object> { { "JobId", request.JobId }, { "PayloadId", request.PayloadId } });
                    var originalState = request.State;
                    request.State = request.State switch
                    {
                        InferenceJobState.Queued => InferenceJobState.Creating,
                        InferenceJobState.Created => InferenceJobState.MetadataUploading,
                        InferenceJobState.MetadataUploaded => InferenceJobState.PayloadUploading,
                        InferenceJobState.PayloadUploaded => InferenceJobState.Starting
                    };
                    _logger.Log(LogLevel.Information, $"Updating inference job {request.JobId} from {originalState } to {request.State}. (Attempt #{request.TryCount + 1}).");
                    await UpdateInferenceJob(request, cancellationToken);

                    return(request);
                }
                await Task.Delay(250);
            }

            throw new OperationCanceledException("Cancellation requested.");
        }
Beispiel #4
0
        public InferenceRequest Get(string jobId, string payloadId)
        {
            if (string.IsNullOrWhiteSpace(jobId) && string.IsNullOrWhiteSpace(payloadId))
            {
                throw new ArgumentNullException($"at least one of {nameof(jobId)} or {nameof(payloadId)} must be provided.");
            }
            var query = _inferenceRequestRepository.AsQueryable();

            if (!string.IsNullOrWhiteSpace(payloadId))
            {
                query = query.Where(p => p.PayloadId.Equals(payloadId));
            }
            if (!string.IsNullOrWhiteSpace(jobId))
            {
                query = query.Where(p => p.JobId.Equals(jobId));
            }

            return(query.FirstOrDefault());
        }