use of com.spotify.helios.common.descriptors.Job in project helios by spotify.
the class PredefinedPortImageDeploymentTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
startDefaultAgent(testHost());
final HeliosClient client = defaultClient();
// Create a job using an image exposing port 11211 but without mapping it
final Job job1 = Job.newBuilder().setName(testTag + "memcached").setVersion("v1").setImage(MEMCACHED).build();
final JobId jobId1 = job1.getId();
client.createJob(job1).get();
// Create a job using an image exposing port 11211 and map it to a specific external port
final Job job2 = Job.newBuilder().setName(testTag + "memcached").setVersion("v2").setImage(MEMCACHED).setPorts(ImmutableMap.of("tcp", PortMapping.of(11211, externalPort))).build();
final JobId jobId2 = job2.getId();
client.createJob(job2).get();
// Wait for agent to come up
awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Deploy the jobs on the agent
client.deploy(Deployment.of(jobId1, START), testHost()).get();
client.deploy(Deployment.of(jobId2, START), testHost()).get();
// Wait for the jobs to run
awaitJobState(client, testHost(), jobId1, RUNNING, LONG_WAIT_SECONDS, SECONDS);
awaitJobState(client, testHost(), jobId2, RUNNING, LONG_WAIT_SECONDS, SECONDS);
}
use of com.spotify.helios.common.descriptors.Job in project helios by spotify.
the class ZooKeeperMasterModelIntegrationTest method testUpdateDeploy.
@Test
public void testUpdateDeploy() throws Exception {
try {
stopJob(model, JOB);
fail("should have thrown JobNotDeployedException");
} catch (JobNotDeployedException e) {
assertTrue(true);
} catch (Exception e) {
fail("Should have thrown an JobNotDeployedException, got " + e.getClass());
}
model.addJob(JOB);
try {
stopJob(model, JOB);
fail("should have thrown exception");
} catch (HostNotFoundException e) {
assertTrue(true);
} catch (Exception e) {
fail("Should have thrown an HostNotFoundException");
}
model.registerHost(HOST, "foo");
final List<String> hosts = model.listHosts();
assertThat(hosts, hasItem(HOST));
try {
stopJob(model, JOB);
fail("should have thrown exception");
} catch (JobNotDeployedException e) {
assertTrue(true);
} catch (Exception e) {
fail("Should have thrown an JobNotDeployedException");
}
model.deployJob(HOST, Deployment.newBuilder().setGoal(Goal.START).setJobId(JOB.getId()).build());
final Map<JobId, Job> jobsOnHost = model.getJobs();
assertEquals(1, jobsOnHost.size());
final Job descriptor = jobsOnHost.get(JOB.getId());
assertEquals(JOB, descriptor);
// should succeed this time!
stopJob(model, JOB);
final Deployment jobCfg = model.getDeployment(HOST, JOB.getId());
assertEquals(Goal.STOP, jobCfg.getGoal());
}
use of com.spotify.helios.common.descriptors.Job in project helios by spotify.
the class ZooKeeperMasterModelIntegrationTest method testJobCreation.
@Test
public void testJobCreation() throws Exception {
assertThat(model.getJobs().entrySet(), empty());
model.addJob(JOB);
assertEquals(model.getJobs().get(JOB_ID), JOB);
assertEquals(model.getJob(JOB_ID), JOB);
final Job secondJob = Job.newBuilder().setCommand(ImmutableList.of(COMMAND)).setImage(IMAGE).setName(JOB_NAME).setVersion("SECOND").build();
model.addJob(secondJob);
assertEquals(model.getJob(secondJob.getId()), secondJob);
assertEquals(2, model.getJobs().size());
}
use of com.spotify.helios.common.descriptors.Job in project helios by spotify.
the class SupervisorTest method verifySupervisorHandlesUndeployingOfNotRunningContainerWithGracePeriod.
/**
* Verifies a fix for a NPE that is thrown when the Supervisor receives a goal of UNDEPLOY for a
* job with gracePeriod that has never been STARTed.
*/
@Test
public void verifySupervisorHandlesUndeployingOfNotRunningContainerWithGracePeriod() throws Exception {
final int gracePeriod = 5;
final Job job = JOB.toBuilder().setGracePeriod(gracePeriod).build();
final Supervisor sut = createSupervisor(job);
sut.setGoal(Goal.UNDEPLOY);
// when the NPE was thrown, the model was never updated
verify(model, timeout(30000)).setTaskStatus(eq(job.getId()), argThat(is(taskStatusWithState(TaskStatus.State.STOPPING))));
verify(model, timeout(30000)).setTaskStatus(eq(job.getId()), argThat(is(taskStatusWithState(TaskStatus.State.STOPPED))));
verify(sleeper, never()).sleep(gracePeriod * 1000);
}
use of com.spotify.helios.common.descriptors.Job in project helios by spotify.
the class DeploymentGroupTest method testUpdateDeploymentGroupHosts.
// A test that ensures healthy deployment groups will perform a rolling update when their hosts
// change.
@Test
public void testUpdateDeploymentGroupHosts() throws Exception {
final ZooKeeperClient client = spy(this.client);
final ZooKeeperMasterModel masterModel = spy(newMasterModel(client));
// Return a job so we can add a real deployment group.
final Job job = Job.newBuilder().setCommand(ImmutableList.of("COMMAND")).setImage("IMAGE").setName("JOB_NAME").setVersion("VERSION").build();
doReturn(job).when(masterModel).getJob(job.getId());
// Add a real deployment group.
final DeploymentGroup dg = DeploymentGroup.newBuilder().setName(GROUP_NAME).setHostSelectors(ImmutableList.of(HostSelector.parse("role=melmac"))).setJobId(job.getId()).setRolloutOptions(RolloutOptions.newBuilder().build()).setRollingUpdateReason(MANUAL).build();
masterModel.addDeploymentGroup(dg);
// Setup some hosts
final String oldHost = "host1";
final String newHost = "host2";
client.ensurePath(Paths.configHost(oldHost));
client.ensurePath(Paths.configHost(newHost));
client.ensurePath(Paths.statusHostUp(oldHost));
client.ensurePath(Paths.statusHostUp(newHost));
// Give the deployment group a host.
client.setData(Paths.statusDeploymentGroupHosts(dg.getName()), Json.asBytes(ImmutableList.of(oldHost)));
// And a status...
client.setData(Paths.statusDeploymentGroup(dg.getName()), DeploymentGroupStatus.newBuilder().setState(DONE).build().toJsonBytes());
// Switch out our host!
// TODO(negz): Use an unchanged host, make sure ordering remains the same.
masterModel.updateDeploymentGroupHosts(dg.getName(), ImmutableList.of(newHost));
verify(client, times(2)).transaction(opCaptor.capture());
final DeploymentGroup changed = dg.toBuilder().setRollingUpdateReason(HOSTS_CHANGED).build();
// Ensure we set the DG status to HOSTS_CHANGED.
// This means we triggered a rolling update.
final ZooKeeperOperation setDeploymentGroupHostChanged = set(Paths.configDeploymentGroup(dg.getName()), changed);
// Ensure ZK tasks are written to:
// - Perform a rolling undeploy for the removed (old) host
// - Perform a rolling update for the added (new) host and the unchanged host
final List<RolloutTask> tasks = ImmutableList.<RolloutTask>builder().addAll(RollingUndeployPlanner.of(changed).plan(singletonList(oldHost))).addAll(RollingUpdatePlanner.of(changed).plan(singletonList(newHost))).build();
final ZooKeeperOperation setDeploymentGroupTasks = set(Paths.statusDeploymentGroupTasks(dg.getName()), DeploymentGroupTasks.newBuilder().setRolloutTasks(tasks).setTaskIndex(0).setDeploymentGroup(changed).build());
assertThat(opCaptor.getValue(), hasItems(setDeploymentGroupHostChanged, setDeploymentGroupTasks));
}
Aggregations