use of com.hubspot.mesos.SingularityDockerInfo in project Singularity by HubSpot.
the class SingularityValidator method checkDocker.
private void checkDocker(SingularityDeploy deploy) {
if (deploy.getResources().isPresent() && deploy.getContainerInfo().get().getDocker().isPresent()) {
final SingularityDockerInfo dockerInfo = deploy.getContainerInfo().get().getDocker().get();
final int numPorts = deploy.getResources().get().getNumPorts();
checkBadRequest(dockerInfo.getImage() != null, "docker image may not be null");
for (SingularityDockerPortMapping portMapping : dockerInfo.getPortMappings()) {
if (portMapping.getContainerPortType() == SingularityPortMappingType.FROM_OFFER) {
checkBadRequest(portMapping.getContainerPort() >= 0 && portMapping.getContainerPort() < numPorts, "Index of port resource for containerPort must be between 0 and %d (inclusive)", numPorts - 1);
}
if (portMapping.getHostPortType() == SingularityPortMappingType.FROM_OFFER) {
checkBadRequest(portMapping.getHostPort() >= 0 && portMapping.getHostPort() < numPorts, "Index of port resource for hostPort must be between 0 and %d (inclusive)", numPorts - 1);
}
}
}
}
use of com.hubspot.mesos.SingularityDockerInfo in project Singularity by HubSpot.
the class SingularitySchedulerTest method dockerDeployWithPorts.
private SingularityDeployBuilder dockerDeployWithPorts() {
final SingularityDockerPortMapping literalMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 80, Optional.of(SingularityPortMappingType.LITERAL), 8080, Optional.<String>absent());
final SingularityDockerPortMapping offerMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 81, Optional.of(SingularityPortMappingType.FROM_OFFER), 0, Optional.of("udp"));
final SingularityContainerInfo containerInfo = new SingularityContainerInfo(SingularityContainerType.DOCKER, Optional.<List<SingularityVolume>>absent(), Optional.of(new SingularityDockerInfo("docker-image", true, SingularityDockerNetworkType.BRIDGE, Optional.of(Arrays.asList(literalMapping, offerMapping)), Optional.of(false), Optional.of(ImmutableMap.of("env", "var=value")), Optional.absent())));
final SingularityDeployBuilder deployBuilder = new SingularityDeployBuilder(requestId, "test-docker-ports-deploy");
deployBuilder.setContainerInfo(Optional.of(containerInfo));
return deployBuilder;
}
use of com.hubspot.mesos.SingularityDockerInfo in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testDockerTask.
@Test
public void testDockerTask() {
taskResources = new Resources(1, 1, 1, 0);
final Protos.Resource portsResource = Protos.Resource.newBuilder().setName("ports").setType(Protos.Value.Type.RANGES).setRanges(Protos.Value.Ranges.newBuilder().addRange(Protos.Value.Range.newBuilder().setBegin(31000).setEnd(31000).build()).build()).build();
final SingularityDockerPortMapping literalMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 80, Optional.of(SingularityPortMappingType.LITERAL), 8080, Optional.<String>absent());
final SingularityDockerPortMapping offerMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 81, Optional.of(SingularityPortMappingType.FROM_OFFER), 0, Optional.of("udp"));
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityContainerInfo containerInfo = new SingularityContainerInfo(SingularityContainerType.DOCKER, Optional.of(Arrays.asList(new SingularityVolume("/container", Optional.of("/host"), SingularityDockerVolumeMode.RW), new SingularityVolume("/container/${TASK_REQUEST_ID}/${TASK_DEPLOY_ID}", Optional.of("/host/${TASK_ID}"), SingularityDockerVolumeMode.RO))), Optional.of(new SingularityDockerInfo("docker-image", true, SingularityDockerNetworkType.BRIDGE, Optional.of(Arrays.asList(literalMapping, offerMapping)), Optional.of(false), Optional.<Map<String, String>>of(ImmutableMap.of("env", "var=value")), Optional.absent())));
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setContainerInfo(Optional.of(containerInfo)).setCommand(Optional.of("/bin/echo")).setArguments(Optional.of(Collections.singletonList("wat"))).build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final SingularityMesosTaskHolder task = builder.buildTask(offerHolder, Collections.singletonList(portsResource), taskRequest, taskResources, executorResources);
assertEquals("/bin/echo", task.getMesosTask().getCommand().getValue());
assertEquals(1, task.getMesosTask().getCommand().getArgumentsCount());
assertEquals("wat", task.getMesosTask().getCommand().getArguments(0));
assertFalse(task.getMesosTask().getCommand().getShell());
assertEquals(Type.DOCKER, task.getMesosTask().getContainer().getType());
assertEquals("docker-image", task.getMesosTask().getContainer().getDocker().getImage());
assertTrue(task.getMesosTask().getContainer().getDocker().getPrivileged());
assertEquals("/container", task.getMesosTask().getContainer().getVolumes(0).getContainerPath());
assertEquals("/host", task.getMesosTask().getContainer().getVolumes(0).getHostPath());
assertEquals(Mode.RW, task.getMesosTask().getContainer().getVolumes(0).getMode());
Parameter envParameter = Parameter.newBuilder().setKey("env").setValue("var=value").build();
assertTrue(task.getMesosTask().getContainer().getDocker().getParametersList().contains(envParameter));
assertEquals(String.format("/container/%s/%s", task.getTask().getTaskRequest().getDeploy().getRequestId(), task.getTask().getTaskRequest().getDeploy().getId()), task.getMesosTask().getContainer().getVolumes(1).getContainerPath());
assertEquals(String.format("/host/%s", task.getMesosTask().getTaskId().getValue()), task.getMesosTask().getContainer().getVolumes(1).getHostPath());
assertEquals(Mode.RO, task.getMesosTask().getContainer().getVolumes(1).getMode());
assertEquals(80, task.getMesosTask().getContainer().getDocker().getPortMappings(0).getContainerPort());
assertEquals(8080, task.getMesosTask().getContainer().getDocker().getPortMappings(0).getHostPort());
assertEquals("tcp", task.getMesosTask().getContainer().getDocker().getPortMappings(0).getProtocol());
assertTrue(MesosUtils.getAllPorts(task.getMesosTask().getResourcesList()).contains(8080L));
assertEquals(81, task.getMesosTask().getContainer().getDocker().getPortMappings(1).getContainerPort());
assertEquals(31000, task.getMesosTask().getContainer().getDocker().getPortMappings(1).getHostPort());
assertEquals("udp", task.getMesosTask().getContainer().getDocker().getPortMappings(1).getProtocol());
assertEquals(Protos.ContainerInfo.DockerInfo.Network.BRIDGE, task.getMesosTask().getContainer().getDocker().getNetwork());
}
use of com.hubspot.mesos.SingularityDockerInfo in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testDockerMinimalNetworking.
@Test
public void testDockerMinimalNetworking() {
taskResources = new Resources(1, 1, 0, 0);
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityContainerInfo containerInfo = new SingularityContainerInfo(SingularityContainerType.DOCKER, Optional.absent(), Optional.of(new SingularityDockerInfo("docker-image", true, SingularityDockerNetworkType.NONE, Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())));
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.emptyList(), taskRequest, taskResources, executorResources);
assertEquals(Type.DOCKER, task.getMesosTask().getContainer().getType());
assertEquals(Protos.ContainerInfo.DockerInfo.Network.NONE, task.getMesosTask().getContainer().getDocker().getNetwork());
}
use of com.hubspot.mesos.SingularityDockerInfo in project Singularity by HubSpot.
the class SingularityMesosTaskBuilderTest method testAutomaticPortMapping.
@Test
public void testAutomaticPortMapping() {
NetworkConfiguration netConf = new NetworkConfiguration();
netConf.setDefaultPortMapping(true);
configuration.setNetworkConfiguration(netConf);
taskResources = new Resources(1, 1, 2);
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityContainerInfo containerInfo = new SingularityContainerInfo(SingularityContainerType.DOCKER, Optional.absent(), Optional.of(new SingularityDockerInfo("docker-image", false, SingularityDockerNetworkType.BRIDGE, Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())));
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.DOCKER, task.getMesosTask().getContainer().getType());
assertEquals(Protos.ContainerInfo.DockerInfo.Network.BRIDGE, task.getMesosTask().getContainer().getDocker().getNetwork());
List<PortMapping> portMappings = task.getMesosTask().getContainer().getDocker().getPortMappingsList();
assertEquals(2, portMappings.size());
assertEquals(31010, portMappings.get(0).getHostPort());
assertEquals(31010, portMappings.get(0).getContainerPort());
assertEquals(31011, portMappings.get(1).getHostPort());
assertEquals(31011, portMappings.get(1).getContainerPort());
}
Aggregations