Search in sources :

Example 1 with EbsVolume

use of com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume in project titus-control-plane by Netflix.

the class JobAssertionsTest method testEbsAndIpZoneMatchValidation.

@Test
public void testEbsAndIpZoneMatchValidation() {
    int size = 4;
    List<String> availabilityZones = JobEbsVolumeGenerator.availabilityZones().getValues(size);
    List<EbsVolume> ebsVolumes = JobEbsVolumeGenerator.jobEbsVolumes(size).toList();
    List<SignedIpAddressAllocation> ipAddressAllocations = JobIpAllocationGenerator.jobIpAllocations(size).toList();
    for (int i = 0; i < size; i++) {
        String az = availabilityZones.get(i);
        EbsVolume updatedEbsVolume = ebsVolumes.get(i).toBuilder().withVolumeAvailabilityZone(az).build();
        ebsVolumes.set(i, updatedEbsVolume);
        SignedIpAddressAllocation updatedIpAllocation = ipAddressAllocations.get(i).toBuilder().withIpAddressAllocation(ipAddressAllocations.get(i).getIpAddressAllocation().toBuilder().withIpAddressLocation(ipAddressAllocations.get(i).getIpAddressAllocation().getIpAddressLocation().toBuilder().withAvailabilityZone(az).build()).build()).build();
        ipAddressAllocations.set(i, updatedIpAllocation);
    }
    Map<String, String> violations = jobAssertions.matchingEbsAndIpZones(ebsVolumes, ipAddressAllocations);
    assertThat(violations).hasSize(0);
}
Also used : EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) Test(org.junit.Test)

Example 2 with EbsVolume

use of com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume 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 EbsVolume

use of com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume in project titus-control-plane by Netflix.

the class JobAssertionsTest method testEbsAndIpZoneDoNotMatchValidation.

@Test
public void testEbsAndIpZoneDoNotMatchValidation() {
    int size = 4;
    List<String> availabilityZones = JobEbsVolumeGenerator.availabilityZones().getValues(size);
    List<EbsVolume> ebsVolumes = JobEbsVolumeGenerator.jobEbsVolumes(size).toList();
    List<SignedIpAddressAllocation> ipAddressAllocations = JobIpAllocationGenerator.jobIpAllocations(size).toList();
    for (int i = 0; i < size; i++) {
        String az = availabilityZones.get(i);
        EbsVolume updatedEbsVolume = ebsVolumes.get(i).toBuilder().withVolumeAvailabilityZone(az).build();
        ebsVolumes.set(i, updatedEbsVolume);
    }
    Map<String, String> violations = jobAssertions.matchingEbsAndIpZones(ebsVolumes, ipAddressAllocations);
    assertThat(violations).hasSize(1);
}
Also used : EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) Test(org.junit.Test)

Example 4 with EbsVolume

use of com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume in project titus-control-plane by Netflix.

the class JobEbsVolumeSanitizerTest method testMetadataAdded.

/**
 * Tests that EBS volume metadata returned by the validator service gets set properly
 * on the sanitized job.
 */
@Test
public void testMetadataAdded() {
    ComputeValidator.EbsVolumeValidationRequest request_a = ComputeValidator.EbsVolumeValidationRequest.newBuilder().setEbsVolumeId(EBS_VOLUME_A.getVolumeId()).build();
    String azA = "us-east-1a";
    int sizeA = 5;
    EbsVolume sanitizedEbsVolumeA = EBS_VOLUME_A.toBuilder().withVolumeAvailabilityZone(azA).withVolumeCapacityGB(sizeA).build();
    ComputeValidator.EbsVolumeValidationResponse response_a = ComputeValidator.EbsVolumeValidationResponse.newBuilder().setSuccess(ComputeValidator.EbsVolumeValidationResponse.Success.newBuilder().setEbsVolumeAvailabilityZone(azA).setEbsVolumeCapacityGB(sizeA).build()).build();
    ComputeValidator.EbsVolumeValidationRequest request_b = ComputeValidator.EbsVolumeValidationRequest.newBuilder().setEbsVolumeId(EBS_VOLUME_B.getVolumeId()).build();
    String azB = "us-east-1b";
    int sizeB = 10;
    EbsVolume sanitizedEbsVolumeB = EBS_VOLUME_B.toBuilder().withVolumeAvailabilityZone(azB).withVolumeCapacityGB(sizeB).build();
    ComputeValidator.EbsVolumeValidationResponse response_b = ComputeValidator.EbsVolumeValidationResponse.newBuilder().setSuccess(ComputeValidator.EbsVolumeValidationResponse.Success.newBuilder().setEbsVolumeAvailabilityZone(azB).setEbsVolumeCapacityGB(sizeB).build()).build();
    when(validationClient.validateEbsVolume(request_a)).thenReturn(Mono.just(response_a));
    when(validationClient.validateEbsVolume(request_b)).thenReturn(Mono.just(response_b));
    StepVerifier.create(sanitizer.sanitize(JOB_WITH_DEFAULT_MULTIPLE_EBS_VOLUMES)).expectNextMatches(operator -> jobContainsVolumes(operator.apply(JOB_WITH_DEFAULT_MULTIPLE_EBS_VOLUMES), // Provide volumes in expected order (which should match original order)
    Arrays.asList(sanitizedEbsVolumeB, sanitizedEbsVolumeA))).verifyComplete();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JobDescriptorGenerator(com.netflix.titus.testkit.model.job.JobDescriptorGenerator) Arrays(java.util.Arrays) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) StepVerifier(reactor.test.StepVerifier) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Set(java.util.Set) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) HashSet(java.util.HashSet) StatusRuntimeException(io.grpc.StatusRuntimeException) List(java.util.List) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) ComputeValidator(com.netflix.compute.validator.protogen.ComputeValidator) ReactorValidationServiceClient(com.netflix.titus.ext.jobvalidator.s3.ReactorValidationServiceClient) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) Status(io.grpc.Status) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) ComputeValidator(com.netflix.compute.validator.protogen.ComputeValidator) Test(org.junit.Test)

Example 5 with EbsVolume

use of com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume in project titus-control-plane by Netflix.

the class KubePodUtil method createEbsPodAnnotations.

public static Map<String, String> createEbsPodAnnotations(Job<?> job, Task task) {
    Map<String, String> annotations = new HashMap<>();
    List<EbsVolume> ebsVolumes = job.getJobDescriptor().getContainer().getContainerResources().getEbsVolumes();
    if (ebsVolumes.isEmpty()) {
        return Collections.emptyMap();
    }
    EbsVolume ebsVolume = job.getJobDescriptor().getContainer().getContainerResources().getEbsVolumes().get(0);
    String ebsVolumeId = task.getTaskContext().get(TaskAttributes.TASK_ATTRIBUTES_EBS_VOLUME_ID);
    if (ebsVolumeId == null) {
        logger.error("Expected to find assigned EBS volume ID to task {} from volumes {}", task.getId(), ebsVolumes);
        return Collections.emptyMap();
    }
    annotations.put(KubeConstants.EBS_VOLUME_ID, ebsVolumeId);
    annotations.put(KubeConstants.EBS_MOUNT_PERMISSIONS, ebsVolume.getMountPermissions().toString());
    annotations.put(KubeConstants.EBS_MOUNT_PATH, ebsVolume.getMountPath());
    annotations.put(KubeConstants.EBS_FS_TYPE, ebsVolume.getFsType());
    return annotations;
}
Also used : EbsVolume(com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume) HashMap(java.util.HashMap)

Aggregations

EbsVolume (com.netflix.titus.api.jobmanager.model.job.ebs.EbsVolume)7 Test (org.junit.Test)5 SignedIpAddressAllocation (com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation)3 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)2 V1Affinity (io.kubernetes.client.openapi.models.V1Affinity)2 HashMap (java.util.HashMap)2 ComputeValidator (com.netflix.compute.validator.protogen.ComputeValidator)1 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)1 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)1 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)1 Task (com.netflix.titus.api.jobmanager.model.job.Task)1 IpAddressAllocation (com.netflix.titus.api.jobmanager.model.job.vpc.IpAddressAllocation)1 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)1 ValidationError (com.netflix.titus.common.model.sanitizer.ValidationError)1 TitusRuntimes (com.netflix.titus.common.runtime.TitusRuntimes)1 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)1 ReactorValidationServiceClient (com.netflix.titus.ext.jobvalidator.s3.ReactorValidationServiceClient)1 JobDescriptorGenerator (com.netflix.titus.testkit.model.job.JobDescriptorGenerator)1 Status (io.grpc.Status)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1