Search in sources :

Example 21 with ValidationError

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

the class AggregatingValidatorTest method validateHardPassTimeout.

@Test
public void validateHardPassTimeout() {
    AdmissionValidator pass = new PassJobValidator();
    AdmissionValidator never = new NeverJobValidator(ValidationError.Type.HARD);
    AdmissionValidator validator = new AggregatingValidator(configuration, registry, Arrays.asList(pass, never));
    Mono<Set<ValidationError>> mono = validator.validate(MOCK_JOB);
    StepVerifier.create(mono).expectNextMatches(errors -> errors.size() == 1).verifyComplete();
    Set<ValidationError> errors = mono.block();
    validateTimeoutErrors(errors);
    validateErrorType(errors, ValidationError.Type.HARD);
}
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)

Example 22 with ValidationError

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

the class SanitizingJobServiceGateway method updateJobCapacity.

@Override
public Completable updateJobCapacity(JobCapacityUpdate jobCapacityUpdate, CallMetadata callMetadata) {
    Capacity newCapacity = GrpcJobManagementModelConverters.toCoreCapacity(jobCapacityUpdate.getCapacity());
    Set<ValidationError> violations = entitySanitizer.validate(newCapacity);
    if (!violations.isEmpty()) {
        return Completable.error(TitusServiceException.invalidArgument(violations));
    }
    return delegate.updateJobCapacity(jobCapacityUpdate, callMetadata);
}
Also used : Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError)

Example 23 with ValidationError

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

the class SanitizingJobServiceGateway method updateJobCapacityWithOptionalAttributes.

@Override
public Completable updateJobCapacityWithOptionalAttributes(JobCapacityUpdateWithOptionalAttributes jobCapacityUpdateWithOptionalAttributes, CallMetadata callMetadata) {
    final JobCapacityWithOptionalAttributes jobCapacityWithOptionalAttributes = jobCapacityUpdateWithOptionalAttributes.getJobCapacityWithOptionalAttributes();
    CapacityAttributes capacityAttributes = GrpcJobManagementModelConverters.toCoreCapacityAttributes(jobCapacityWithOptionalAttributes);
    Set<ValidationError> violations = entitySanitizer.validate(capacityAttributes);
    if (!violations.isEmpty()) {
        return Completable.error(TitusServiceException.invalidArgument(violations));
    }
    return delegate.updateJobCapacityWithOptionalAttributes(jobCapacityUpdateWithOptionalAttributes, callMetadata);
}
Also used : JobCapacityWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityWithOptionalAttributes) CapacityAttributes(com.netflix.titus.api.jobmanager.model.job.CapacityAttributes) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError)

Example 24 with ValidationError

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

the class ArchaiusEffectiveJobDisruptionBudgetResolver method parse.

private DisruptionBudget parse(String newValue) throws Exception {
    DisruptionBudget budget = ObjectMappers.storeMapper().readValue(newValue, DisruptionBudget.class);
    Preconditions.checkArgument(!(budget.getDisruptionBudgetPolicy() instanceof SelfManagedDisruptionBudgetPolicy), "Self managed migration policy not allowed as a fallback");
    DisruptionBudget sanitized = sanitizer.sanitize(budget).orElse(budget);
    Set<ValidationError> violations = sanitizer.validate(sanitized);
    Preconditions.checkState(violations.isEmpty(), "Invalid self managed fallback disruption budget: value=%s, violations=%s", sanitized, violations);
    return sanitized;
}
Also used : SelfManagedDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.SelfManagedDisruptionBudgetPolicy) DisruptionBudget(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError)

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