Search in sources :

Example 1 with ValidationError

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

the class ScalingPolicyModelSanitizationTest method testInvalidStepScalingPolicyNoAlarmConfiguration.

@Test
public void testInvalidStepScalingPolicyNoAlarmConfiguration() {
    PolicyConfiguration policyConfiguration = PolicyConfiguration.newBuilder().withStepScalingPolicyConfiguration(mock(StepScalingPolicyConfiguration.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("alarmConfiguration must be specified for a step scaling policy");
}
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) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Example 2 with ValidationError

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

the class JobAssertions method validateMatchingEbsAndIpZones.

public static Set<ValidationError> validateMatchingEbsAndIpZones(List<EbsVolume> ebsVolumes, List<SignedIpAddressAllocation> ipSignedAddressAllocations) {
    if (ebsVolumes == null || ipSignedAddressAllocations == null) {
        return Collections.emptySet();
    }
    if (ebsVolumes.isEmpty() || ipSignedAddressAllocations.isEmpty()) {
        return Collections.emptySet();
    }
    int numElements = Math.min(ebsVolumes.size(), ipSignedAddressAllocations.size());
    for (int i = 0; i < numElements; i++) {
        EbsVolume ebsVolume = ebsVolumes.get(i);
        IpAddressAllocation ipAddressAllocation = ipSignedAddressAllocations.get(i).getIpAddressAllocation();
        if (!ebsVolume.getVolumeAvailabilityZone().equals(ipAddressAllocation.getIpAddressLocation().getAvailabilityZone())) {
            return Collections.singleton(new ValidationError("containerResources.ebsVolumes", String.format("EBS volume %s zone %s conflicts with Static IP %s zone %s and index %d", ebsVolume.getVolumeId(), ebsVolume.getVolumeAvailabilityZone(), ipAddressAllocation.getAllocationId(), ipAddressAllocation.getIpAddressLocation().getAvailabilityZone(), i)));
        }
    }
    return Collections.emptySet();
}
Also used : SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) IpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.IpAddressAllocation) EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError)

Example 3 with ValidationError

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

the class JobS3LogLocationValidator method toValidationError.

private Set<ValidationError> toValidationError(List<ValidationFailure> failures) {
    Set<ValidationError> result = new HashSet<>();
    failures.forEach(failure -> {
        result.add(new ValidationError(JobAttributes.JOB_CONTAINER_ATTRIBUTE_S3_BUCKET_NAME, String.format("Access denied: errorCode=%s, errorMessage=%s", failure.getErrorCode(), failure.getErrorMessage())));
    });
    return result;
}
Also used : ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) HashSet(java.util.HashSet)

Example 4 with ValidationError

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

the class JobModelSanitizationTest method testJobWithInvalidPlatformSidecar.

@Test
public void testJobWithInvalidPlatformSidecar() {
    PlatformSidecar badPS = PlatformSidecar.newBuilder().withName("BAD_NAME").withChannel("BAD_CHANNEL").build();
    JobDescriptor<BatchJobExt> badJobDescriptor = oneTaskBatchJobDescriptor().but(jd -> jd.toBuilder().withPlatformSidecars(Collections.singletonList(badPS)).build());
    Set<ValidationError> violations = entitySanitizer.validate(badJobDescriptor);
    assertThat(violations).hasSize(2);
}
Also used : PlatformSidecar(com.netflix.titus.api.jobmanager.model.job.PlatformSidecar) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) ValidationError(com.netflix.titus.common.model.sanitizer.ValidationError) Test(org.junit.Test)

Example 5 with ValidationError

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

the class JobModelSanitizationTest method testJobWithInvalidVolume.

@Test
public void testJobWithInvalidVolume() {
    VolumeSource vs = new SaaSVolumeSource("BAD_SAAS_NAME");
    Volume badVolume = Volume.newBuilder().withName("BAD_NAME").withVolumeSource(vs).build();
    JobDescriptor<BatchJobExt> badJobDescriptor = oneTaskBatchJobDescriptor().but(jd -> jd.toBuilder().withVolumes(Collections.singletonList(badVolume)).build());
    Set<ValidationError> violations = entitySanitizer.validate(badJobDescriptor);
    assertThat(violations).hasSize(2);
}
Also used : SaaSVolumeSource(com.netflix.titus.api.jobmanager.model.job.volume.SaaSVolumeSource) VolumeSource(com.netflix.titus.api.jobmanager.model.job.volume.VolumeSource) SaaSVolumeSource(com.netflix.titus.api.jobmanager.model.job.volume.SaaSVolumeSource) Volume(com.netflix.titus.api.jobmanager.model.job.volume.Volume) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) 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