Search in sources :

Example 46 with HeliosClient

use of com.spotify.helios.client.HeliosClient in project helios by spotify.

the class DeploymentGroupTest method testRemovingAgentTagUndeploysJob.

@Test
public void testRemovingAgentTagUndeploysJob() throws Exception {
    final HeliosClient client = defaultClient();
    final String oldHost = testHost();
    final String deregisterHost = testHost() + "2";
    final String unchangedHost = testHost() + "3";
    final String newHost = testHost() + "4";
    final String anotherNewHost = testHost() + "5";
    @SuppressWarnings("VariableDeclarationUsageDistance") AgentMain oldAgent = startDefaultAgent(oldHost, "--labels", "foo=bar");
    awaitUpWithLabels(oldHost, "foo", "bar");
    final AgentMain deregisterAgent = startDefaultAgent(deregisterHost, "--labels", "foo=bar");
    awaitUpWithLabels(deregisterHost, "foo", "bar");
    startDefaultAgent(unchangedHost, "--labels", "foo=bar");
    awaitUpWithLabels(unchangedHost, "foo", "bar");
    cli("create-deployment-group", "--json", TEST_GROUP, "foo=bar");
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    cli("rolling-update", "--async", testJobNameAndVersion, TEST_GROUP);
    awaitTaskState(jobId, oldHost, TaskStatus.State.RUNNING);
    awaitTaskState(jobId, deregisterHost, TaskStatus.State.RUNNING);
    awaitTaskState(jobId, unchangedHost, TaskStatus.State.RUNNING);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
    // Rollout should be complete and on its second iteration at this point.
    // Start another agent and wait for it to have the job deployed to it.
    startDefaultAgent(newHost, "--labels", "foo=bar");
    awaitUpWithLabels(newHost, "foo", "bar");
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(jobId, newHost, TaskStatus.State.RUNNING);
    // Restart the old agent with labels that still match the deployment group
    // The job should not be undeployed.
    stopAgent(oldAgent);
    oldAgent = startDefaultAgent(oldHost, "--labels", "foo=bar", "another=label");
    awaitUpWithLabels(oldHost, "foo", "bar", "another", "label");
    awaitTaskState(jobId, oldHost, TaskStatus.State.RUNNING);
    // Restart the old agent with labels that do not match the deployment group.
    stopAgent(oldAgent);
    oldAgent = startDefaultAgent(oldHost, "--labels", "foo=notbar");
    awaitUpWithLabels(oldHost, "foo", "notbar");
    // ...which should trigger a rolling update
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    // Start yet another agent in order to trigger another rolling update.
    startDefaultAgent(anotherNewHost, "--labels", "foo=bar");
    // Wait for the rolling update(s) to finish.
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
    // ...which should remove the job.
    awaitUndeployed(oldHost, jobId);
    // Restart the old agent with labels that match the deployment group (again)
    // The job should be deployed.
    stopAgent(oldAgent);
    startDefaultAgent(oldHost, "--labels", "foo=bar");
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
    awaitTaskState(jobId, oldHost, TaskStatus.State.RUNNING);
    // Deregister an agent
    stopAgent(deregisterAgent);
    final HostDeregisterResponse deregisterResponse = client.deregisterHost(deregisterHost).get();
    assertEquals(HostDeregisterResponse.Status.OK, deregisterResponse.getStatus());
    // Make sure we 'undeploy' from the now non-existent agent.
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.ROLLING_OUT);
    awaitDeploymentGroupStatus(client, TEST_GROUP, DeploymentGroupStatus.State.DONE);
}
Also used : HostDeregisterResponse(com.spotify.helios.common.protocol.HostDeregisterResponse) AgentMain(com.spotify.helios.agent.AgentMain) Matchers.containsString(org.hamcrest.Matchers.containsString) HeliosClient(com.spotify.helios.client.HeliosClient) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 47 with HeliosClient

use of com.spotify.helios.client.HeliosClient in project helios by spotify.

the class DeploymentGroupTest method testRollingUpdatePerformance.

@Ignore
@Test
public void testRollingUpdatePerformance() throws Exception {
    final List<String> hosts = ImmutableList.of("dc1-" + testHost() + "-a1.dc1.example.com", "dc1-" + testHost() + "-a2.dc1.example.com", "dc2-" + testHost() + "-a1.dc2.example.com", "dc2-" + testHost() + "-a3.dc2.example.com", "dc3-" + testHost() + "-a4.dc3.example.com");
    // start agents
    for (final String host : hosts) {
        startDefaultAgent(host, "--labels", TEST_LABEL);
    }
    // Wait for agents to come up
    final HeliosClient client = defaultClient();
    for (final String host : hosts) {
        awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
    }
    for (int i = 0; i < 50; ++i) {
        cli("create-deployment-group", "--json", TEST_GROUP + "-" + i, "tol=ahdsksajd");
        cli("rolling-update", "--async", testJobNameAndVersion, TEST_GROUP + "-" + i);
    }
    // create a deployment group and job
    cli("create-deployment-group", "--json", TEST_GROUP, TEST_LABEL);
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
    // TODO: fix this!
    // Wait for the host-updater
    Thread.sleep(2000);
    // trigger a rolling update
    cli("rolling-update", "--async", testJobNameAndVersion, TEST_GROUP);
    final long t0 = System.currentTimeMillis();
    // ensure the job is running on all agents and the deployment group reaches DONE
    for (final String host : hosts) {
        awaitTaskState(jobId, host, TaskStatus.State.RUNNING);
    }
    final Deployment deployment = defaultClient().hostStatus(hosts.get(0)).get().getJobs().get(jobId);
    assertEquals(TEST_GROUP, deployment.getDeploymentGroupName());
    awaitDeploymentGroupStatus(defaultClient(), TEST_GROUP, DeploymentGroupStatus.State.DONE);
    System.out.printf("1 active / 0 inactive: Time to roll out: %.2f s\n", (System.currentTimeMillis() - t0) / 1000.0);
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) Matchers.containsString(org.hamcrest.Matchers.containsString) HeliosClient(com.spotify.helios.client.HeliosClient) JobId(com.spotify.helios.common.descriptors.JobId) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 48 with HeliosClient

use of com.spotify.helios.client.HeliosClient in project helios by spotify.

the class DeploymentTest method test.

@Test
public void test() throws Exception {
    final Map<String, PortMapping> ports = ImmutableMap.of("foos", PortMapping.of(17, externalPort));
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost());
    // Create a job
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setPorts(ports).setCreatingUser(TEST_USER).build();
    final JobId jobId = job.getId();
    final CreateJobResponse created = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, created.getStatus());
    final CreateJobResponse duplicateJob = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.JOB_ALREADY_EXISTS, duplicateJob.getStatus());
    // Try querying for the job
    final Map<JobId, Job> noMatchJobs = client.jobs(testJobName + "not_matching").get();
    assertTrue(noMatchJobs.isEmpty());
    final Map<JobId, Job> matchJobs1 = client.jobs(testJobName).get();
    assertJobsEqual(ImmutableMap.of(jobId, job), matchJobs1);
    final Map<JobId, Job> matchJobs2 = client.jobs(testJobName + ":" + testJobVersion).get();
    assertJobsEqual(ImmutableMap.of(jobId, job), matchJobs2);
    final Map<JobId, Job> matchJobs3 = client.jobs(job.getId().toString()).get();
    assertJobsEqual(ImmutableMap.of(jobId, job), matchJobs3);
    // Wait for agent to come up
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Deploy the job on the agent
    final Deployment deployment = Deployment.of(jobId, START, TEST_USER);
    final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
    final JobDeployResponse deployed2 = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.JOB_ALREADY_DEPLOYED, deployed2.getStatus());
    final JobDeployResponse deployed3 = client.deploy(Deployment.of(BOGUS_JOB, START), testHost()).get();
    assertEquals(JobDeployResponse.Status.JOB_NOT_FOUND, deployed3.getStatus());
    final JobDeployResponse deployed4 = client.deploy(deployment, BOGUS_HOST).get();
    assertEquals(JobDeployResponse.Status.HOST_NOT_FOUND, deployed4.getStatus());
    // undeploy and redeploy to make sure things still work in the face of the tombstone
    final JobUndeployResponse undeployResp = client.undeploy(jobId, testHost()).get();
    assertEquals(JobUndeployResponse.Status.OK, undeployResp.getStatus());
    final JobDeployResponse redeployed = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, redeployed.getStatus());
    // Check that the job is in the desired state
    final Deployment fetchedDeployment = client.deployment(testHost(), jobId).get();
    assertEquals(deployment, fetchedDeployment);
    // Wait for the job to run
    TaskStatus taskStatus;
    taskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    assertJobEquals(job, taskStatus.getJob());
    assertEquals(JobDeleteResponse.Status.STILL_IN_USE, client.deleteJob(jobId).get().getStatus());
    // Wait for a while and make sure that the container is still running
    Thread.sleep(5000);
    final HostStatus hostStatus = client.hostStatus(testHost()).get();
    taskStatus = hostStatus.getStatuses().get(jobId);
    assertEquals(jobId.toString(), RUNNING, taskStatus.getState());
    // Undeploy the job
    final JobUndeployResponse undeployed = client.undeploy(jobId, testHost()).get();
    assertEquals(JobUndeployResponse.Status.OK, undeployed.getStatus());
    // Make sure that it is no longer in the desired state
    final Deployment undeployedJob = client.deployment(testHost(), jobId).get();
    assertTrue(undeployedJob == null);
    // Wait for the task to disappear
    awaitTaskGone(client, testHost(), jobId, LONG_WAIT_SECONDS, SECONDS);
    // Verify that the job can be deleted
    assertEquals(JobDeleteResponse.Status.OK, client.deleteJob(jobId).get().getStatus());
    // Verify that a nonexistent job returns JOB_NOT_FOUND
    assertEquals(JobDeleteResponse.Status.JOB_NOT_FOUND, client.deleteJob(jobId).get().getStatus());
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) Integer.toHexString(java.lang.Integer.toHexString) HeliosClient(com.spotify.helios.client.HeliosClient) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) JobUndeployResponse(com.spotify.helios.common.protocol.JobUndeployResponse) HostStatus(com.spotify.helios.common.descriptors.HostStatus) PortMapping(com.spotify.helios.common.descriptors.PortMapping) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 49 with HeliosClient

use of com.spotify.helios.client.HeliosClient in project helios by spotify.

the class DeploymentTest method testJobWithDigest.

@Test
public void testJobWithDigest() throws Exception {
    startDefaultMaster();
    final HeliosClient client = defaultClient();
    startDefaultAgent(testHost());
    // Create a job
    final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX_WITH_DIGEST).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
    final JobId jobId = job.getId();
    final CreateJobResponse created = client.createJob(job).get();
    assertEquals(CreateJobResponse.Status.OK, created.getStatus());
    // Try querying for the job
    final Map<JobId, Job> matchJobs = client.jobs(testJobName).get();
    assertJobsEqual(ImmutableMap.of(jobId, job), matchJobs);
    assertEquals(BUSYBOX_WITH_DIGEST, matchJobs.get(jobId).getImage());
    // Wait for agent to come up
    awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
    awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    // Deploy the job on the agent
    final Deployment deployment = Deployment.of(jobId, START, TEST_USER);
    final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
    assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
    // Wait for the job to run
    TaskStatus taskStatus;
    taskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
    assertJobEquals(job, taskStatus.getJob());
}
Also used : CreateJobResponse(com.spotify.helios.common.protocol.CreateJobResponse) Deployment(com.spotify.helios.common.descriptors.Deployment) HeliosClient(com.spotify.helios.client.HeliosClient) Job(com.spotify.helios.common.descriptors.Job) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 50 with HeliosClient

use of com.spotify.helios.client.HeliosClient in project helios by spotify.

the class MasterRespondsWithNoZkTest method test.

@Test
public void test() throws Exception {
    startDefaultMasterDontWaitForZk(new MockCuratorClientFactory(), "--zk-connection-timeout", "1");
    final HeliosClient client = defaultClient();
    try {
        final String result = client.listMasters().get().get(0);
        fail("Exception should have been thrown, as ZK doesnt exist - got " + result);
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof HeliosException);
    }
}
Also used : HeliosException(com.spotify.helios.common.HeliosException) Matchers.anyString(org.mockito.Matchers.anyString) HeliosClient(com.spotify.helios.client.HeliosClient) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

HeliosClient (com.spotify.helios.client.HeliosClient)57 Test (org.junit.Test)53 JobId (com.spotify.helios.common.descriptors.JobId)35 Job (com.spotify.helios.common.descriptors.Job)25 Deployment (com.spotify.helios.common.descriptors.Deployment)19 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)14 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)13 Matchers.containsString (org.hamcrest.Matchers.containsString)11 DockerClient (com.spotify.docker.client.DockerClient)10 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)10 HostStatus (com.spotify.helios.common.descriptors.HostStatus)9 AgentMain (com.spotify.helios.agent.AgentMain)8 JobStatus (com.spotify.helios.common.descriptors.JobStatus)6 PortMapping (com.spotify.helios.common.descriptors.PortMapping)5 Map (java.util.Map)5 ExecHealthCheck (com.spotify.helios.common.descriptors.ExecHealthCheck)4 HealthCheck (com.spotify.helios.common.descriptors.HealthCheck)4 HttpHealthCheck (com.spotify.helios.common.descriptors.HttpHealthCheck)4 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)4 TcpHealthCheck (com.spotify.helios.common.descriptors.TcpHealthCheck)4