Search in sources :

Example 41 with JobId

use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.

the class Agent method startUp.

@Override
protected void startUp() throws Exception {
    for (final Entry<JobId, Execution> entry : executions.get().entrySet()) {
        final Execution execution = entry.getValue();
        final Job job = execution.getJob();
        if (execution.getPorts() != null) {
            createSupervisor(job, execution.getPorts());
        }
    }
    model.addListener(modelListener);
    reactor.startAsync().awaitRunning();
    reactor.signal();
}
Also used : Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId)

Example 42 with JobId

use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.

the class JobListCommandTest method setUp.

@Before
public void setUp() {
    // use a real, dummy Subparser impl to avoid having to mock out every single call
    final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
    final Subparser subparser = parser.addSubparsers().addParser("list");
    command = new JobListCommand(subparser);
    when(client.jobs()).thenReturn(Futures.immediateFuture(jobs));
    final Map<JobId, JobStatus> statuses = new HashMap<>();
    for (final JobId jobId : jobs.keySet()) {
        // pretend each job is deployed
        final JobStatus status = JobStatus.newBuilder().setDeployments(ImmutableMap.of("host", Deployment.of(jobId, Goal.START))).build();
        statuses.put(jobId, status);
    }
    when(client.jobStatuses(jobs.keySet())).thenReturn(Futures.immediateFuture(statuses));
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) HashMap(java.util.HashMap) Subparser(net.sourceforge.argparse4j.inf.Subparser) ArgumentParser(net.sourceforge.argparse4j.inf.ArgumentParser) JobId(com.spotify.helios.common.descriptors.JobId) Before(org.junit.Before)

Example 43 with JobId

use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.

the class ExpiredJobReaperTest method testExpiredJobReaper.

@Test
public void testExpiredJobReaper() throws Exception {
    when(mockClock.now()).thenReturn(new Instant(CURRENT_TS));
    when(masterModel.getJobs()).thenReturn(JOBS);
    when(masterModel.getJobStatus(any(JobId.class))).then(new Answer<JobStatus>() {

        @Override
        public JobStatus answer(final InvocationOnMock invocation) throws Throwable {
            final JobId jobId = (JobId) invocation.getArguments()[0];
            final Map<String, Deployment> deployments = ImmutableMap.of("hostA", Deployment.of(jobId, Goal.START), "hostB", Deployment.of(jobId, Goal.START));
            return JobStatus.newBuilder().setJob(JOBS.get(jobId)).setDeployments(deployments).build();
        }
    });
    ExpiredJobReaper.newBuilder().setClock(mockClock).setMasterModel(masterModel).build().runOneIteration();
    // Make sure that the expiring job was removed, but that the non-expiring job
    // and the job that expires far in the future were not.
    verify(masterModel).undeployJob(eq("hostA"), eq(EXPIRING_JOB_ID), eq(""));
    verify(masterModel).undeployJob(eq("hostB"), eq(EXPIRING_JOB_ID), eq(""));
    verify(masterModel).removeJob(eq(EXPIRING_JOB_ID), eq(""));
    verifyNoMoreInteractions(ignoreStubs(masterModel));
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Instant(org.joda.time.Instant) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 44 with JobId

use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.

the class CliDeploymentTest method testUndeployingNonexistantHostJson.

@Test
public void testUndeployingNonexistantHostJson() throws Exception {
    startDefaultMaster();
    // Wait for master to come up
    Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {

        @Override
        public String call() throws Exception {
            final String output = cli("masters");
            return output.contains(masterName()) ? output : null;
        }
    });
    // Create job
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    // Verify that undeploying a nonexistent job from a host fails
    final String output = cli("undeploy", "--json", jobId.toString(), BOGUS_HOST);
    final JobDeployResponse jobDeployResponse = Json.read(output, JobDeployResponse.class);
    assertEquals(JobDeployResponse.Status.HOST_NOT_FOUND, jobDeployResponse.getStatus());
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 45 with JobId

use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.

the class ContainerHostNameTest method testValidHostname.

@Test
public void testValidHostname() throws Exception {
    startDefaultMaster();
    startDefaultAgent(testHost());
    awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    try (final DockerClient dockerClient = getNewDockerClient()) {
        final List<String> command = asList("hostname", "-f");
        // Create job
        final JobId jobId = createJob(Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setHostname(testHost()).setCommand(command).build());
        // deploy
        deployJob(jobId, testHost());
        final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED);
        final String log;
        try (final LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout(), stderr())) {
            log = logs.readFully();
        }
        assertThat(log, containsString(testHost()));
    }
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Matchers.containsString(org.hamcrest.Matchers.containsString) LogStream(com.spotify.docker.client.LogStream) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Aggregations

JobId (com.spotify.helios.common.descriptors.JobId)115 Test (org.junit.Test)68 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)41 Job (com.spotify.helios.common.descriptors.Job)37 HeliosClient (com.spotify.helios.client.HeliosClient)35 Deployment (com.spotify.helios.common.descriptors.Deployment)29 Matchers.containsString (org.hamcrest.Matchers.containsString)25 DockerClient (com.spotify.docker.client.DockerClient)19 JobStatus (com.spotify.helios.common.descriptors.JobStatus)19 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)16 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)13 IOException (java.io.IOException)12 HostStatus (com.spotify.helios.common.descriptors.HostStatus)11 Map (java.util.Map)11 LogStream (com.spotify.docker.client.LogStream)10 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)10 KeeperException (org.apache.zookeeper.KeeperException)9 TaskStatusEvent (com.spotify.helios.common.descriptors.TaskStatusEvent)8 AgentMain (com.spotify.helios.agent.AgentMain)7 PortMapping (com.spotify.helios.common.descriptors.PortMapping)7