Search in sources :

Example 6 with SingularityPendingTaskBuilder

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

the class SingularitySchedulerTestBase method buildPendingTask.

protected SingularityPendingTask buildPendingTask(SingularityRequest request, SingularityDeploy deploy, long launchTime, int instanceNo, Optional<String> runId) {
    SingularityPendingTaskId pendingTaskId = new SingularityPendingTaskId(request.getId(), deploy.getId(), launchTime, instanceNo, PendingType.IMMEDIATE, launchTime);
    SingularityPendingTask pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(pendingTaskId).setRunId(runId).build();
    return pendingTask;
}
Also used : SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder)

Example 7 with SingularityPendingTaskBuilder

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

the class SingularityMesosTaskBuilderTest method testEnvironmentVariableOverrides.

@Test
public void testEnvironmentVariableOverrides() {
    Map<String, String> overrideVariables = new HashMap<>();
    overrideVariables.put("MY_NEW_ENV_VAR", "test");
    overrideVariables.put("STARTED_BY_USER", "notTestUser");
    final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
    final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setCommand(Optional.of("/bin/echo hi")).build();
    final SingularityPendingTask pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(new SingularityPendingTaskId("test", "1", 0, 1, PendingType.IMMEDIATE, 0)).setUser(user).setEnvOverrides(overrideVariables).build();
    final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
    final TaskInfo task = builder.buildTask(offerHolder, null, taskRequest, taskResources, executorResources).getMesosTask();
    Map<String, String> environmentVariables = task.getCommand().getEnvironment().getVariablesList().stream().collect(Collectors.toMap(Variable::getName, Variable::getValue));
    for (String key : overrideVariables.keySet()) {
        assertEquals("Environment variable " + key + " not overridden.", environmentVariables.get(key), overrideVariables.get(key));
    }
}
Also used : TaskInfo(org.apache.mesos.v1.Protos.TaskInfo) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) HashMap(java.util.HashMap) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder) Test(org.junit.Test)

Aggregations

SingularityPendingTaskBuilder (com.hubspot.singularity.SingularityPendingTaskBuilder)7 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)7 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 ProtobufModule (com.hubspot.jackson.datatype.protobuf.ProtobufModule)1 Resources (com.hubspot.mesos.Resources)1 InvalidSingularityTaskIdException (com.hubspot.singularity.InvalidSingularityTaskIdException)1 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)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 ExecutorIdGenerator (com.hubspot.singularity.data.ExecutorIdGenerator)1 MesosProtosUtils (com.hubspot.singularity.helpers.MesosProtosUtils)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1