use of com.spotify.helios.common.protocol.HostDeregisterResponse in project helios by spotify.
the class DeregisterTest method testDeregisterHostThatDoesntExist.
@Test
public void testDeregisterHostThatDoesntExist() throws Exception {
startDefaultMaster();
final String host = testHost();
final HeliosClient client = defaultClient();
final HostDeregisterResponse deregisterResponse = client.deregisterHost(host).get();
assertEquals(HostDeregisterResponse.Status.NOT_FOUND, deregisterResponse.getStatus());
}
use of com.spotify.helios.common.protocol.HostDeregisterResponse in project helios by spotify.
the class DeregisterTest method testDeregister.
@Test
public void testDeregister() throws Exception {
startDefaultMaster();
final String host = testHost();
final AgentMain agent = startDefaultAgent(host);
final HeliosClient client = defaultClient();
// Create a job
final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setPorts(ImmutableMap.of("foo", PortMapping.of(4711), "bar", PortMapping.of(4712, ports.localPort("bar")))).build();
final JobId jobId = job.getId();
final CreateJobResponse created = client.createJob(job).get();
assertEquals(CreateJobResponse.Status.OK, created.getStatus());
// Wait for agent to come up
awaitHostRegistered(client, host, LONG_WAIT_SECONDS, SECONDS);
awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
// Deploy the job on the agent
final Deployment deployment = Deployment.of(jobId, START);
final JobDeployResponse deployed = client.deploy(deployment, host).get();
assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
// Wait for the job to run
awaitJobState(client, host, jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
// Kill off agent
agent.stopAsync().awaitTerminated();
// Deregister agent
final HostDeregisterResponse deregisterResponse = client.deregisterHost(host).get();
assertEquals(HostDeregisterResponse.Status.OK, deregisterResponse.getStatus());
// Verify that it's possible to remove the job
final JobDeleteResponse deleteResponse = client.deleteJob(jobId).get();
assertEquals(JobDeleteResponse.Status.OK, deleteResponse.getStatus());
}
use of com.spotify.helios.common.protocol.HostDeregisterResponse in project helios by spotify.
the class HostDeregisterCommand method run.
@Override
int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException, IOException {
final String host = options.getString(hostArg.getDest());
final boolean yes = options.getBoolean(yesArg.getDest());
final boolean force = options.getBoolean(forceArg.getDest());
if (force) {
log.warn("If you are using '--force' to skip the interactive prompt, " + "note that we have deprecated it. Please use '--yes'.");
}
if (!yes && !force) {
out.printf("This will deregister the host %s%n", host);
final boolean confirmed = Utils.userConfirmed(out, stdin);
if (!confirmed) {
return 1;
}
}
out.printf("Deregistering host %s%n", host);
int code = 0;
final HostDeregisterResponse response = client.deregisterHost(host).get();
out.printf("%s: ", host);
if (response.getStatus() == HostDeregisterResponse.Status.OK) {
out.printf("done%n");
} else {
out.printf("failed: %s%n", response);
if (response.getStatus() == HostDeregisterResponse.Status.NOT_FOUND) {
final HostResolver resolver = HostResolver.create(client);
final List<String> resolved = resolver.getSortedMatches(host);
if (!resolved.isEmpty()) {
out.println("We didn't find your hostname, but we did find some possible matches for you:" + "\n " + Joiner.on("\n ").join(resolved) + "\n");
}
}
code = 1;
}
return code;
}
use of com.spotify.helios.common.protocol.HostDeregisterResponse in project helios by spotify.
the class DeregisterTest method testDeregisterJobDeployedWithoutStatus.
// Verify that we can deregister a host there are jobs deployed to it, for which there's no
// corresponding status information. For example, if a job was deployed to the host after is went
// down.
@Test
public void testDeregisterJobDeployedWithoutStatus() throws Exception {
startDefaultMaster();
final String host = testHost();
final HeliosClient client = defaultClient();
final DefaultZooKeeperClient zkClient = new DefaultZooKeeperClient(zk().curatorWithSuperAuth());
final String idPath = Paths.configHostId(host);
ZooKeeperRegistrarUtil.registerHost(zkClient, idPath, host, UUID.randomUUID().toString());
// Create a job
final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setPorts(ImmutableMap.of("foo", PortMapping.of(4711), "bar", PortMapping.of(4712, ports.localPort("bar")))).build();
final JobId jobId = job.getId();
final CreateJobResponse created = client.createJob(job).get();
assertEquals(CreateJobResponse.Status.OK, created.getStatus());
// Deploy the job on the agent
final Deployment deployment = Deployment.of(jobId, START);
final JobDeployResponse deployed = client.deploy(deployment, host).get();
assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
// Deregister agent
final HostDeregisterResponse deregisterResponse = client.deregisterHost(host).get();
assertEquals(HostDeregisterResponse.Status.OK, deregisterResponse.getStatus());
// Verify that it's possible to remove the job
final JobDeleteResponse deleteResponse = client.deleteJob(jobId).get();
assertEquals(JobDeleteResponse.Status.OK, deleteResponse.getStatus());
}
use of com.spotify.helios.common.protocol.HostDeregisterResponse 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);
}
Aggregations