use of com.hubspot.singularity.SingularityRequest 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());
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class HistoryPersisterTest method testDeployCountPurging.
@Test
public void testDeployCountPurging() {
SingularityRequest requestOne = buildRequest("request1");
SingularityRequest requestTwo = buildRequest("request2");
SingularityDeploy requestOneDeployOne = initAndFinishDeploy(requestOne, "r1d1");
SingularityDeploy requestOneDeployTwo = initAndFinishDeploy(requestOne, "r1d2");
SingularityDeploy requestOneDeployThree = initAndFinishDeploy(requestOne, "r1d3");
// r1d4 is the active deploy, not eligible for purging
SingularityDeploy requestOneDeployFour = initAndFinishDeploy(requestOne, "r1d4");
SingularityDeploy requestTwoDeployOne = initAndFinishDeploy(requestTwo, "r2d1");
// r2d2 is the active deploy, not eligible for purging
SingularityDeploy requestTwoDeployTwo = initAndFinishDeploy(requestTwo, "r2d2");
configuration.setMaxStaleDeploysPerRequestInZkWhenNoDatabase(Optional.of(2));
deployHistoryPersister.runActionOnPoll();
Assert.assertTrue(!deployManager.getDeployHistory(requestOneDeployOne.getRequestId(), requestOneDeployOne.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestOneDeployTwo.getRequestId(), requestOneDeployTwo.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestOneDeployThree.getRequestId(), requestOneDeployThree.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestOneDeployFour.getRequestId(), requestOneDeployFour.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestTwoDeployOne.getRequestId(), requestTwoDeployOne.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestTwoDeployTwo.getRequestId(), requestTwoDeployTwo.getId(), true).isPresent());
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class HistoryPersisterTest method testRequestCountPurging.
@Test
public void testRequestCountPurging() {
final SingularityRequest requestOne = new SingularityRequestBuilder("request1", RequestType.WORKER).build();
final SingularityRequest requestTwo = new SingularityRequestBuilder("request2", RequestType.WORKER).build();
final SingularityRequest requestThree = new SingularityRequestBuilder("request3", RequestType.WORKER).build();
saveRequest(requestOne);
saveRequest(requestTwo);
saveRequest(requestThree);
configuration.setMaxRequestsWithHistoryInZkWhenNoDatabase(Optional.of(2));
configuration.setDeleteStaleRequestsFromZkWhenNoDatabaseAfterHours(7);
requestManager.startDeletingRequest(requestOne, Optional.absent(), user, Optional.<String>absent(), Optional.<String>absent());
requestManager.deleteHistoryParent(requestOne.getId());
requestManager.activate(requestOne, RequestHistoryType.CREATED, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(4), Optional.<String>absent(), Optional.<String>absent());
requestManager.cooldown(requestOne, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(3));
requestManager.startDeletingRequest(requestTwo, Optional.absent(), user, Optional.<String>absent(), Optional.<String>absent());
requestManager.deleteHistoryParent(requestTwo.getId());
requestManager.activate(requestTwo, RequestHistoryType.CREATED, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(4), Optional.<String>absent(), Optional.<String>absent());
requestManager.cooldown(requestTwo, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(3));
requestManager.startDeletingRequest(requestThree, Optional.absent(), user, Optional.<String>absent(), Optional.<String>absent());
requestManager.deleteHistoryParent(requestThree.getId());
requestManager.activate(requestThree, RequestHistoryType.CREATED, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(4), Optional.<String>absent(), Optional.<String>absent());
requestManager.cooldown(requestThree, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(3));
Assert.assertEquals(2, requestManager.getRequestHistory(requestOne.getId()).size());
Assert.assertEquals(2, requestManager.getRequestHistory(requestTwo.getId()).size());
Assert.assertEquals(2, requestManager.getRequestHistory(requestThree.getId()).size());
requestHistoryPersister.runActionOnPoll();
Assert.assertEquals(0, requestManager.getRequestHistory(requestOne.getId()).size());
Assert.assertEquals(2, requestManager.getRequestHistory(requestTwo.getId()).size());
Assert.assertEquals(2, requestManager.getRequestHistory(requestThree.getId()).size());
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class SingularityDeploysTest method testUsesNewRequestDataFromPendingDeploy.
@Test
public void testUsesNewRequestDataFromPendingDeploy() {
initRequest();
initFirstDeploy();
saveAndSchedule(request.toBuilder().setInstances(Optional.of(2)));
scheduler.drainPendingQueue();
Assert.assertEquals(2, taskManager.getPendingTaskIds().size());
Assert.assertEquals(2, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
SingularityRequest newRequest = request.toBuilder().setInstances(Optional.of(1)).build();
String deployId = "test_new_request_data";
SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), deployId).setCommand(Optional.of("sleep 100")).build();
deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
List<SingularityPendingTaskId> pendingTaskIdsForNewDeploy = new ArrayList<>();
for (SingularityPendingTaskId pendingTaskId : taskManager.getPendingTaskIds()) {
if (pendingTaskId.getDeployId().equals(deployId)) {
pendingTaskIdsForNewDeploy.add(pendingTaskId);
}
}
Assert.assertEquals(1, pendingTaskIdsForNewDeploy.size());
Assert.assertEquals(2, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
resourceOffers();
for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, deployId)) {
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
}
deployChecker.checkDeploys();
Assert.assertEquals(1, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class SingularityDeploysTest method testCannotUpdateRequestDuringPendingDeployWithNewData.
@Test(expected = WebApplicationException.class)
public void testCannotUpdateRequestDuringPendingDeployWithNewData() {
initRequest();
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
SingularityRequest newRequest = request.toBuilder().setInstances(Optional.of(1)).build();
String deployId = "test_new_request_data";
SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), deployId).setCommand(Optional.of("sleep 100")).build();
deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
requestResource.postRequest(newRequest, singularityUser);
}
Aggregations