Search in sources :

Example 1 with Environment

use of org.apache.mesos.v1.Protos.Environment 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

SingularityDeploy (com.hubspot.singularity.SingularityDeploy)1 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)1 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)1 SingularityPendingTaskBuilder (com.hubspot.singularity.SingularityPendingTaskBuilder)1 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)1 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)1 HashMap (java.util.HashMap)1 TaskInfo (org.apache.mesos.v1.Protos.TaskInfo)1 Test (org.junit.Test)1