Search in sources :

Example 16 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder 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());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) Test(org.junit.Test)

Example 17 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.

the class SingularityOfferPerformanceTestRunner method testSchedulerPerformance.

@Test(timeout = 600000L)
@Ignore
public void testSchedulerPerformance() {
    long start = System.currentTimeMillis();
    int numRequests = 4500;
    int numOffers = 2500;
    Random r = new Random();
    Iterator<Double> cpuIterator = r.doubles(1, 5).iterator();
    Iterator<Double> memoryIterator = r.doubles(15, 20000).iterator();
    Iterator<Double> diskIterator = r.doubles(30, 50000).iterator();
    for (int i = 0; i < numRequests; i++) {
        SingularityRequestBuilder bldr = new SingularityRequestBuilder("request-" + i, RequestType.SERVICE);
        bldr.setInstances(Optional.of(5));
        bldr.setSlavePlacement(Optional.of(SlavePlacement.GREEDY));
        SingularityRequest request = bldr.build();
        saveRequest(request);
        deployRequest(request, cpuIterator.next(), memoryIterator.next());
    }
    List<Offer> offers = new ArrayList<>(numOffers);
    for (int i = 0; i < numOffers; i++) {
        offers.add(createOffer(cpuIterator.next(), memoryIterator.next(), diskIterator.next(), "slave-" + i, "host-" + i));
    }
    System.out.println("Starting after " + JavaUtils.duration(start));
    start = System.currentTimeMillis();
    sms.resourceOffers(offers);
    final long duration = System.currentTimeMillis() - start;
    int activeTasks = taskManager.getActiveTaskIds().size();
    System.out.println(String.format("Launched %s tasks on %s offers in %s", activeTasks, numOffers, JavaUtils.durationFromMillis(duration)));
    start = System.currentTimeMillis();
    ExecutorService statusUpadtes = Executors.newFixedThreadPool(100);
    CompletableFuture<Void>[] updateFutures = new CompletableFuture[taskManager.getActiveTaskIds().size() * 5];
    AtomicInteger i = new AtomicInteger(0);
    for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
        updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
            statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_STAGING);
            return null;
        }, statusUpadtes);
        updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
            statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_STARTING);
            return null;
        }, statusUpadtes);
        updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
            statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
            return null;
        }, statusUpadtes);
        updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
            statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_FAILED);
            return null;
        }, statusUpadtes);
        updateFutures[i.getAndIncrement()] = CompletableFuture.supplyAsync(() -> {
            statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_FAILED);
            return null;
        }, statusUpadtes);
    }
    CompletableFuture.allOf(updateFutures).join();
    System.out.println(String.format("Ran %s status updates in %s", activeTasks * 5, JavaUtils.durationFromMillis(System.currentTimeMillis() - start)));
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) Random(java.util.Random) Offer(org.apache.mesos.v1.Protos.Offer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.

the class SingularitySchedulerTestBase method initRequestWithType.

protected void initRequestWithType(RequestType requestType, boolean isLoadBalanced) {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, requestType);
    bldr.setLoadBalanced(Optional.of(isLoadBalanced));
    if (requestType == RequestType.SCHEDULED) {
        bldr.setQuartzSchedule(Optional.of(schedule));
    }
    request = bldr.build();
    saveRequest(request);
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder)

Example 19 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.

the class SingularitySchedulerTestBase method buildRequest.

protected SingularityRequest buildRequest(String requestId) {
    SingularityRequest request = new SingularityRequestBuilder(requestId, RequestType.WORKER).build();
    saveRequest(request);
    return request;
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest)

Example 20 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder in project Singularity by HubSpot.

the class ValidatorTest method itForbidsRunNowOfScheduledWhenAlreadyRunning.

@Test(expected = WebApplicationException.class)
public void itForbidsRunNowOfScheduledWhenAlreadyRunning() {
    String deployID = "deploy";
    Optional<String> userEmail = Optional.absent();
    SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.SCHEDULED).setInstances(Optional.of(1)).build();
    Optional<SingularityRunNowRequest> runNowRequest = Optional.absent();
    List<SingularityTaskId> activeTasks = Collections.singletonList(activeTask());
    List<SingularityPendingTaskId> pendingTasks = Collections.emptyList();
    validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, activeTasks, pendingTasks);
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Aggregations

SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)52 Test (org.junit.Test)48 SingularityRequest (com.hubspot.singularity.SingularityRequest)37 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)22 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)17 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)12 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)10 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)9 Resources (com.hubspot.mesos.Resources)8 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)8 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)8 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)7 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)5 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)4 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 SingularityDockerInfo (com.hubspot.mesos.SingularityDockerInfo)3 SingularityDockerPortMapping (com.hubspot.mesos.SingularityDockerPortMapping)3 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)3 SingularityTask (com.hubspot.singularity.SingularityTask)3 ArrayList (java.util.ArrayList)3