use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.
the class ZooKeeperClusterIdTest method testAgent.
@Test
public void testAgent() throws Exception {
startDefaultMaster("--zk-cluster-id=" + zkClusterId);
startDefaultAgent(testHost(), "--zk-cluster-id=" + zkClusterId);
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Create job and deploy it
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId, testHost());
final TaskStatus runningStatus = awaitTaskState(jobId, testHost(), RUNNING);
final String containerId = runningStatus.getContainerId();
// Delete the config node which contains the cluster ID and all the job definitions
zk().curatorWithSuperAuth().delete().deletingChildrenIfNeeded().forPath("/config");
// Sleep for a second so agent has a chance to react to deletion
Thread.sleep(1000);
// Make sure the agent didn't stop the job
try (final DockerClient docker = getNewDockerClient()) {
final List<Container> containers = docker.listContainers();
final CustomTypeSafeMatcher<Container> containerIdMatcher = new CustomTypeSafeMatcher<Container>("Container with id " + containerId) {
@Override
protected boolean matchesSafely(Container container) {
return container.id().equals(containerId);
}
};
assertContainersMatch(containers, containerIdMatcher);
}
}
use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.
the class ZooKeeperMasterModel method updateDeployment.
/**
* Used to update the existing deployment of a job.
*/
@Override
public void updateDeployment(final String host, final Deployment deployment, final String token) throws HostNotFoundException, JobNotDeployedException, TokenVerificationException {
log.info("updating deployment {}: {}", deployment, host);
final ZooKeeperClient client = provider.get("updateDeployment");
final JobId jobId = deployment.getJobId();
final Job job = getJob(client, jobId);
final Deployment existingDeployment = getDeployment(host, jobId);
if (job == null) {
throw new JobNotDeployedException(host, jobId);
}
verifyToken(token, job);
assertHostExists(client, host);
assertTaskExists(client, host, deployment.getJobId());
final String path = Paths.configHostJob(host, jobId);
final Task task = new Task(job, deployment.getGoal(), existingDeployment.getDeployerUser(), existingDeployment.getDeployerMaster(), existingDeployment.getDeploymentGroupName());
try {
client.setData(path, task.toJsonBytes());
} catch (Exception e) {
throw new HeliosRuntimeException("updating deployment " + deployment + " on host " + host + " failed", e);
}
}
use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.
the class ZooKeeperMasterModel method checkForPortConflicts.
private static void checkForPortConflicts(final ZooKeeperClient client, final String host, final int port, final JobId jobId) throws JobPortAllocationConflictException {
try {
final String path = Paths.configHostPort(host, port);
if (client.stat(path) == null) {
return;
}
final byte[] b = client.getData(path);
final JobId existingJobId = parse(b, JobId.class);
throw new JobPortAllocationConflictException(jobId, existingJobId, host, port);
} catch (KeeperException | IOException ex) {
throw new HeliosRuntimeException("checking port allocations failed", ex);
}
}
use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.
the class ZooKeeperMasterModel method listHostJobs.
private List<JobId> listHostJobs(final ZooKeeperClient client, final String host) {
final List<String> jobIdStrings;
final String folder = Paths.statusHostJobs(host);
try {
jobIdStrings = client.getChildren(folder);
} catch (KeeperException.NoNodeException e) {
return null;
} catch (KeeperException e) {
throw new HeliosRuntimeException("List tasks for host failed: " + host, e);
}
final ImmutableList.Builder<JobId> jobIds = ImmutableList.builder();
for (final String jobIdString : jobIdStrings) {
jobIds.add(JobId.fromString(jobIdString));
}
return jobIds.build();
}
use of com.spotify.helios.common.descriptors.JobId in project helios by spotify.
the class ZooKeeperMasterModel method addJob.
/**
* Adds a job into the configuration.
*/
@Override
public void addJob(final Job job) throws JobExistsException {
log.info("adding job: {}", job);
final JobId id = job.getId();
final UUID operationId = UUID.randomUUID();
final String creationPath = Paths.configJobCreation(id, operationId);
final ZooKeeperClient client = provider.get("addJob");
try {
try {
client.ensurePath(Paths.historyJob(id));
client.transaction(create(Paths.configJob(id), job), create(Paths.configJobRefShort(id), id), create(Paths.configJobHosts(id)), create(creationPath), // change down the tree. Effectively, make it that version == cVersion.
set(Paths.configJobs(), UUID.randomUUID().toString().getBytes()));
} catch (final NodeExistsException e) {
if (client.exists(creationPath) != null) {
// The job was created, we're done here
return;
}
throw new JobExistsException(id.toString());
}
} catch (NoNodeException e) {
throw new HeliosRuntimeException("adding job " + job + " failed due to missing ZK path: " + e.getPath(), e);
} catch (final KeeperException e) {
throw new HeliosRuntimeException("adding job " + job + " failed", e);
}
}
Aggregations