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);
}
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);
}
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");
}
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();
}
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);
}
Aggregations