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