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));
        }
        private ApiValidationResult ValidateForPurgeJobQueue(string jobId)
        {
            if (string.IsNullOrWhiteSpace(jobId))
            {
                return(ApiValidationResult.Failure(nameof(jobId), ErrorKeys.ArgumentCanNotBeEmpty));
            }

            return(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));
        }
Example #4
0
        /// <summary>Validates the specified API request context resolver.</summary>
        /// <param name="contextResolver">The API request context resolver.</param>
        /// <returns></returns>
        public Task <IList <ApiValidationResult> > Validate(IApiRequestContextResolver contextResolver)
        {
            var context             = contextResolver?.GetContext();
            var suggestedStatusCode = context.Configuration.ValidationErrorConfiguration.UriBindingErrorStatusCode;

            var results = new List <ApiValidationResult>();

            results.Add(ApiValidationResult.Failure("VALIDATOR-4.1", suggestedHttpStatusCode: suggestedStatusCode));
            results.Add(ApiValidationResult.Failure("VALIDATOR-4.2", suggestedHttpStatusCode: suggestedStatusCode));

            return(Task.FromResult(results as IList <ApiValidationResult>));
        }
        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());
        }
Example #6
0
 protected IHttpActionResult ValidationError(string error)
 {
     return(new ValidationErrorResult(ApiValidationResult.Failure(error), this));
 }
 protected IHttpActionResult ValidationError(string propertyPath, string errorKey)
 {
     return(new ValidationErrorResult(ApiValidationResult.Failure(propertyPath, errorKey), this));
 }
 protected IHttpActionResult ValidationError(string errorKey, IEnumerable <string> errorParams = null)
 {
     return(new ValidationErrorResult(errorParams == null
         ? ApiValidationResult.Failure(errorKey)
         : ApiValidationResult.Failure(errorKey, errorParams), this));
 }
 protected IHttpActionResult ValidationError(IEnumerable <ApiValidationError> errors)
 {
     return(new ValidationErrorResult(ApiValidationResult.Failure(errors), this));
 }
Example #10
0
 public static ApiValidationResult ToValidationResult(this HttpResponseMessage response)
 {
     return(response.IsSuccessStatusCode
         ? ApiValidationResult.Ok()
         : ApiValidationResult.Failure(response.ToValidationError()));
 }