Search in sources :

Example 1 with NetworkConfiguration

use of com.hubspot.singularity.config.NetworkConfiguration 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());
}
Also used : SingularityContainerInfo(com.hubspot.mesos.SingularityContainerInfo) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityMesosTaskHolder(com.hubspot.singularity.helpers.SingularityMesosTaskHolder) NetworkConfiguration(com.hubspot.singularity.config.NetworkConfiguration) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) PortMapping(org.apache.mesos.v1.Protos.ContainerInfo.DockerInfo.PortMapping) SingularityPortMapping(com.hubspot.mesos.SingularityPortMapping) SingularityDockerPortMapping(com.hubspot.mesos.SingularityDockerPortMapping) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SingularityDockerInfo(com.hubspot.mesos.SingularityDockerInfo) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Aggregations

Resources (com.hubspot.mesos.Resources)1 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)1 SingularityDockerInfo (com.hubspot.mesos.SingularityDockerInfo)1 SingularityDockerPortMapping (com.hubspot.mesos.SingularityDockerPortMapping)1 SingularityPortMapping (com.hubspot.mesos.SingularityPortMapping)1 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)1 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)1 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)1 NetworkConfiguration (com.hubspot.singularity.config.NetworkConfiguration)1 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)1 PortMapping (org.apache.mesos.v1.Protos.ContainerInfo.DockerInfo.PortMapping)1 Test (org.junit.Test)1