public async Task <ApiValidationResult> ResumeJob(string tenantId, string jobId)
        {
            var jobData = await JobStore.Load(tenantId, jobId);

            if (jobData == null)
            {
                return(ApiValidationResult.Failure(ErrorKeys.InvalidJobId));
            }

            if (jobData.Status.State == JobState.InProgress)
            {
                return(ApiValidationResult.Ok());
            }

            var changeableStates = new[] { JobState.Draining, JobState.Paused };

            if (changeableStates.Any(s => s == jobData.Status.State))
            {
                var updated = await JobStore.UpdateState(tenantId, jobId, jobData.Status.State, JobState.InProgress);

                if (updated)
                {
                    await JobNotification.NotifyJobUpdated(jobId);

                    return(ApiValidationResult.Ok());
                }
            }

            return(ApiValidationResult.Failure(ErrorKeys.InvalidJobState));
        }
Esempio n. 2
0
        public IActionResult Publish([FromBody] PublishInput input)
        {
            Logger.LogDebug($"PublishMessageController - Publish method called with this input: {input}");
            if (input == null)
            {
                return(BadRequest(new ApiValidationError(nameof(input), ErrorKeys.ParameterNull)));
            }

            if (input.Payload == null)
            {
                return(BadRequest(new ApiValidationError(nameof(PublishInput.Payload), ErrorKeys.ParameterNull)));
            }

            if (string.IsNullOrWhiteSpace(input.Category))
            {
                return(BadRequest(new ApiValidationError(nameof(PublishInput.Category), ErrorKeys.ParameterNull)));
            }

            if (!input.ValidateTags())
            {
                return(BadRequest(new ApiValidationError(nameof(PublishInput.Tags), ErrorKeys.ParameterNull)));
            }

            var result = _publishMessageLogic.ProduceMessage(input);

            if (!string.IsNullOrEmpty(result.Error))
            {
                return(BadRequest(new { Message = result.Error }));
            }

            return(Ok(ApiValidationResult.Ok()));
        }
        private ApiValidationResult ValidateForPurgeJobQueue(string jobId)
        {
            if (string.IsNullOrWhiteSpace(jobId))
            {
                return(ApiValidationResult.Failure(nameof(jobId), ErrorKeys.ArgumentCanNotBeEmpty));
            }

            return(ApiValidationResult.Ok());
        }
Esempio n. 4
0
        public IActionResult InsertIncomingMessages([FromBody] object input)
        {
            if (!_hostingEnvironment.IsDevelopment())
            {
                return(NotFound());
            }

            return(Ok(ApiValidationResult.Ok()));
        }
        public async Task <ApiValidationResult> StopJob(string tenantId, string jobId)
        {
            var jobData = await JobStore.Load(tenantId, jobId);

            if (jobData == null)
            {
                return(ApiValidationResult.Failure(ErrorKeys.InvalidJobId));
            }

            if (jobData.Status.State == JobState.Stopped)
            {
                return(ApiValidationResult.Ok());
            }

            if (jobData.Configuration.IsIndefinite)
            {
                return(ApiValidationResult.Failure(ErrorKeys.InvalidJobAction));
            }

            if (jobData.Configuration.PreprocessorJobIds.SafeAny())
            {
                foreach (var preprocessorJobId in jobData.Configuration.PreprocessorJobIds)
                {
                    var preprocessorJobStatus = await JobStore.LoadStatus(tenantId, preprocessorJobId);

                    if (preprocessorJobStatus.State < JobState.Completed)
                    {
                        return(ApiValidationResult.Failure(ErrorKeys.JobActionHasPreprocessorDependency,
                                                           new[] { preprocessorJobId }));
                    }
                }
            }

            var changeableStates = new[] { JobState.InProgress, JobState.Draining, JobState.Paused };

            if (changeableStates.Any(s => s == jobData.Status.State))
            {
                var updated = await JobStore.UpdateState(tenantId, jobId, jobData.Status.State, JobState.Stopped);

                if (updated)
                {
                    await JobNotification.NotifyJobUpdated(jobId);

                    var jobStepSource = GetJobQueue(jobData);
                    if (jobStepSource != null)
                    {
                        await jobStepSource.Purge();
                    }

                    return(ApiValidationResult.Ok());
                }
            }

            return(ApiValidationResult.Failure(ErrorKeys.InvalidJobState));
        }
        public async Task <ApiValidationResult> PurgeJobQueue(string tenantId, string jobId)
        {
            var jobData = await JobStore.Load(tenantId, jobId);

            if (jobData == null)
            {
                return(ApiValidationResult.Failure(ErrorKeys.InvalidJobId));
            }

            var jobStepSource = GetJobQueue(jobData);

            if (jobStepSource == null)
            {
                return(ApiValidationResult.Failure(ErrorKeys.UnknownInternalServerError));
            }

            await jobStepSource.Purge();

            return(ApiValidationResult.Ok());
        }
Esempio n. 7
0
 public static ApiValidationResult ToValidationResult(this HttpResponseMessage response)
 {
     return(response.IsSuccessStatusCode
         ? ApiValidationResult.Ok()
         : ApiValidationResult.Failure(response.ToValidationError()));
 }