Search in sources :

Example 11 with ValidationError

use of com.netflix.titus.common.model.sanitizer.ValidationError in project titus-control-plane by Netflix.

the class JobReconciliationFrameworkFactory method validateJob.

private Optional<Job> validateJob(Job job) {
    // Perform strict validation for reporting purposes
    Set<ValidationError> strictViolations = strictEntitySanitizer.validate(job);
    if (!strictViolations.isEmpty()) {
        logger.error("No strictly consistent job record found: jobId={}, violations={}", job.getId(), EntitySanitizerUtil.toStringMap(strictViolations));
        errorCollector.strictlyInvalidJob(job.getId());
    }
    // Required checks
    Set<ValidationError> violations = permissiveEntitySanitizer.validate(job);
    if (!violations.isEmpty()) {
        logger.error("Bad job record found: jobId={}, violations={}", job.getId(), EntitySanitizerUtil.toStringMap(violations));
        if (jobManagerConfiguration.isFailOnDataValidation()) {
            return Optional.empty();
        }
    }
    // If version is missing (old job objects) create one based on the current job state.
    Job jobWithVersion = job;
    if (job.getVersion() == null || job.getVersion().getTimestamp() < 0) {
        Version newVersion = Version.newBuilder().withTimestamp(job.getStatus().getTimestamp()).build();
        jobWithVersion = job.toBuilder().withVersion(newVersion).build();
    }
    return Optional.of(jobWithVersion);
}
Also used : Version(com.netflix.titus.api.jobmanager.model.job.Version) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 12 with ValidationError

use of com.netflix.titus.common.model.sanitizer.ValidationError in project titus-control-plane by Netflix.

the class DefaultJobManagementServiceGrpc method validateAndConvertJobDisruptionBudgetToCoreModel.

private Optional<DisruptionBudget> validateAndConvertJobDisruptionBudgetToCoreModel(com.netflix.titus.api.jobmanager.model.job.Job<?> coreJob, JobDisruptionBudget grpcDisruptionBudget, StreamObserver<Empty> responseObserver) {
    DisruptionBudget coreDisruptionBudget;
    try {
        coreDisruptionBudget = GrpcJobManagementModelConverters.toCoreDisruptionBudget(grpcDisruptionBudget);
    } catch (Exception e) {
        safeOnError(logger, TitusServiceException.invalidArgument("Error when converting GRPC disruption budget to the internal model: " + e.getMessage()), responseObserver);
        return Optional.empty();
    }
    DisruptionBudget sanitizedCoreDisruptionBudget = entitySanitizer.sanitize(coreDisruptionBudget).orElse(coreDisruptionBudget);
    Set<ValidationError> violations = entitySanitizer.validate(sanitizedCoreDisruptionBudget);
    if (!violations.isEmpty()) {
        safeOnError(logger, TitusServiceException.invalidArgument(violations), responseObserver);
        return Optional.empty();
    }
    return Optional.of(sanitizedCoreDisruptionBudget);
}
Also used : DisruptionBudget(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget) JobDisruptionBudget(com.netflix.titus.grpc.protogen.JobDisruptionBudget) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) StatusRuntimeException(io.grpc.StatusRuntimeException) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException)

Example 13 with ValidationError

use of com.netflix.titus.common.model.sanitizer.ValidationError in project titus-control-plane by Netflix.

the class ScalingPolicyModelSanitizationTest method testInvalidScalingConfigurationWithBothPolicies.

@Test
public void testInvalidScalingConfigurationWithBothPolicies() {
    PolicyConfiguration policyConfiguration = PolicyConfiguration.newBuilder().withStepScalingPolicyConfiguration(mock(StepScalingPolicyConfiguration.class)).withAlarmConfiguration(mock(AlarmConfiguration.class)).withTargetTrackingPolicy(mock(TargetTrackingPolicy.class)).build();
    AutoScalingPolicy autoScalingPolicy = AutoScalingPolicy.newBuilder().withPolicyConfiguration(policyConfiguration).build();
    Set<ValidationError> validationErrors = newScalingPolicySanitizer().validate(autoScalingPolicy);
    assertThat(validationErrors).hasSize(1);
    assertThat(CollectionsExt.first(validationErrors).getDescription()).isEqualTo("exactly one scaling policy should be set");
}
Also used : AutoScalingPolicy(com.netflix.titus.api.appscale.model.AutoScalingPolicy) StepScalingPolicyConfiguration(com.netflix.titus.api.appscale.model.StepScalingPolicyConfiguration) PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration) AlarmConfiguration(com.netflix.titus.api.appscale.model.AlarmConfiguration) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Example 14 with ValidationError

use of com.netflix.titus.common.model.sanitizer.ValidationError in project titus-control-plane by Netflix.

the class AggregatingValidatorTest method validateSoftPass.

@Test
public void validateSoftPass() {
    AdmissionValidator pass = new PassJobValidator();
    AdmissionValidator validator = new AggregatingValidator(configuration, registry, Arrays.asList(pass));
    Mono<Set<ValidationError>> mono = validator.validate(MOCK_JOB);
    StepVerifier.create(mono).expectNextMatches(errors -> errors.size() == 0).verifyComplete();
}
Also used : Arrays(java.util.Arrays) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TitusValidatorConfiguration(com.netflix.titus.common.model.admission.TitusValidatorConfiguration) StepVerifier(reactor.test.StepVerifier) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Collectors(java.util.stream.Collectors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Duration(java.time.Duration) Registry(com.netflix.spectator.api.Registry) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Collections(java.util.Collections) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Set(java.util.Set) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Test(org.junit.Test)

Example 15 with ValidationError

use of com.netflix.titus.common.model.sanitizer.ValidationError in project titus-control-plane by Netflix.

the class AggregatingValidatorTest method validateHardPassFailTimeout.

@Test
public void validateHardPassFailTimeout() {
    AdmissionValidator pass = new PassJobValidator();
    AdmissionValidator fail = new FailJobValidator();
    AdmissionValidator never = new NeverJobValidator();
    AdmissionValidator parallelValidator = new AggregatingValidator(configuration, registry, Arrays.asList(pass, fail, never));
    Mono<Set<ValidationError>> mono = parallelValidator.validate(MOCK_JOB);
    StepVerifier.create(mono).expectNextMatches(errors -> errors.size() == 2).verifyComplete();
    Set<ValidationError> errors = mono.block();
    validateErrorType(errors, ValidationError.Type.HARD);
    Collection<ValidationError> failErrors = errors.stream().filter(error -> error.getField().equals(FailJobValidator.ERR_FIELD)).collect(Collectors.toList());
    assertThat(failErrors).hasSize(1);
    validateFailErrors(failErrors);
    Collection<ValidationError> timeoutErrors = errors.stream().filter(error -> error.getField().equals(NeverJobValidator.class.getSimpleName())).collect(Collectors.toList());
    assertThat(timeoutErrors).hasSize(1);
    validateTimeoutErrors(timeoutErrors);
}
Also used : Arrays(java.util.Arrays) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TitusValidatorConfiguration(com.netflix.titus.common.model.admission.TitusValidatorConfiguration) StepVerifier(reactor.test.StepVerifier) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Collectors(java.util.stream.Collectors) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Duration(java.time.Duration) Registry(com.netflix.spectator.api.Registry) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) Collections(java.util.Collections) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Set(java.util.Set) AdmissionValidator(com.netflix.titus.common.model.admission.AdmissionValidator) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Aggregations

ValidationError (com.netflix.titus.common.model.sanitizer.ValidationError)24 Test (org.junit.Test)14 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)10 Registry (com.netflix.spectator.api.Registry)10 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)10 AdmissionValidator (com.netflix.titus.common.model.admission.AdmissionValidator)10 TitusValidatorConfiguration (com.netflix.titus.common.model.admission.TitusValidatorConfiguration)10 Duration (java.time.Duration)10 Arrays (java.util.Arrays)10 Collection (java.util.Collection)10 Collections (java.util.Collections)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 Before (org.junit.Before)10 Mockito.mock (org.mockito.Mockito.mock)10 Mockito.when (org.mockito.Mockito.when)10 Mono (reactor.core.publisher.Mono)10 StepVerifier (reactor.test.StepVerifier)10 AutoScalingPolicy (com.netflix.titus.api.appscale.model.AutoScalingPolicy)2