use of com.hubspot.mesos.SingularityMesosImage in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testMesosContainer.
@Test
public void testMesosContainer() {
taskResources = new Resources(1, 1, 2);
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityContainerInfo containerInfo = new SingularityContainerInfo(SingularityContainerType.MESOS, Optional.of(Collections.singletonList(new SingularityVolume("/testing", Optional.of("/host"), SingularityDockerVolumeMode.RW, Optional.of(new SingularityVolumeSource(SingularityVolumeSourceType.DOCKER_VOLUME, Optional.of(new SingularityDockerVolume(Optional.of("rexray"), Optional.of("testvolume-%i"), Collections.singletonMap("iops", "1")))))))), Optional.absent(), Optional.of(new SingularityMesosInfo(Optional.of(new SingularityMesosImage(SingularityMesosImageType.DOCKER, Optional.absent(), Optional.of(new SingularityDockerImage("test:image")), true)))), Optional.of(Arrays.asList(new SingularityNetworkInfo(Optional.of("network-name"), Optional.of(Arrays.asList("blue", "purple")), Optional.of(Arrays.asList(new SingularityPortMapping(0, 8080, Optional.of("tcp")), new SingularityPortMapping(8888, 8081, Optional.of("udp"))))))));
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setContainerInfo(Optional.of(containerInfo)).build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final SingularityMesosTaskHolder task = builder.buildTask(offerHolder, Collections.singletonList(MesosUtils.getPortRangeResource(31010, 31011)), taskRequest, taskResources, executorResources);
assertEquals(Type.MESOS, task.getMesosTask().getContainer().getType());
final Image image = task.getMesosTask().getContainer().getMesos().getImage();
assertEquals(Protos.Image.Type.DOCKER, image.getType());
assertEquals("test:image", image.getDocker().getName());
final Volume volume = task.getMesosTask().getContainer().getVolumesList().get(0);
assertEquals("/testing", volume.getContainerPath());
assertEquals("/host", volume.getHostPath());
assertEquals(Volume.Mode.RW, volume.getMode());
assertEquals(Volume.Source.Type.DOCKER_VOLUME, volume.getSource().getType());
final DockerVolume dockerVolume = volume.getSource().getDockerVolume();
assertEquals("rexray", dockerVolume.getDriver());
assertEquals("testvolume-1", dockerVolume.getName());
assertEquals("iops", dockerVolume.getDriverOptions().getParameterList().get(0).getKey());
final NetworkInfo networkInfo = task.getMesosTask().getContainer().getNetworkInfosList().get(0);
assertEquals("network-name", networkInfo.getName());
assertEquals(Arrays.asList("blue", "purple"), networkInfo.getGroupsList());
final List<Protos.NetworkInfo.PortMapping> portMappings = networkInfo.getPortMappingsList();
assertEquals(2, portMappings.size());
assertEquals(31010, portMappings.get(0).getHostPort());
assertEquals(8080, portMappings.get(0).getContainerPort());
assertEquals("tcp", portMappings.get(0).getProtocol());
assertEquals(8888, portMappings.get(1).getHostPort());
assertEquals(8081, portMappings.get(1).getContainerPort());
assertEquals("udp", portMappings.get(1).getProtocol());
}
use of com.hubspot.mesos.SingularityMesosImage in project Singularity by HubSpot.
the class SingularityMesosTaskBuilder method prepareMesosInfo.
private void prepareMesosInfo(ContainerInfo.Builder containerBuilder, final SingularityContainerInfo containerInfo) {
if (!containerInfo.getMesos().isPresent()) {
return;
}
final MesosInfo.Builder builder = MesosInfo.newBuilder();
final SingularityMesosInfo mesos = containerInfo.getMesos().get();
if (mesos.getImage().isPresent()) {
final SingularityMesosImage image = mesos.getImage().get();
final Image.Builder imageBuilder = Image.newBuilder();
imageBuilder.setType(Image.Type.valueOf(image.getType().toString()));
if (image.getAppc().isPresent()) {
final SingularityAppcImage appc = image.getAppc().get();
final Image.Appc.Builder appcBuilder = Image.Appc.newBuilder();
appcBuilder.setName(appc.getName());
if (appc.getId().isPresent()) {
appcBuilder.setId(appc.getId().get());
}
imageBuilder.setAppc(appcBuilder.build());
}
if (image.getDocker().isPresent()) {
final SingularityDockerImage docker = image.getDocker().get();
final Image.Docker.Builder dockerBuilder = Image.Docker.newBuilder();
dockerBuilder.setName(docker.getName());
imageBuilder.setDocker(dockerBuilder.build());
}
builder.setImage(imageBuilder.build());
}
containerBuilder.setMesos(builder.build());
}
Aggregations