use of com.spotify.helios.common.HeliosRuntimeException 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.HeliosRuntimeException 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.HeliosRuntimeException in project helios by spotify.
the class ZooKeeperMasterModel method removeDeploymentGroup.
/**
* Remove a deployment group.
*
* <p>If successful, all ZK nodes associated with the DG will be deleted. Specifically these
* nodes are guaranteed to be non-existent after a successful remove (not all of them might exist
* before, though):
* <ul>
* <li>/config/deployment-groups/[group-name]</li>
* <li>/status/deployment-groups/[group-name]</li>
* <li>/status/deployment-groups/[group-name]/hosts</li>
* <li>/status/deployment-groups/[group-name]/removed</li>
* <li>/status/deployment-group-tasks/[group-name]</li>
* </ul>
* If the operation fails no ZK nodes will be removed.
*
* @throws DeploymentGroupDoesNotExistException If the DG does not exist.
*/
@Override
public void removeDeploymentGroup(final String name) throws DeploymentGroupDoesNotExistException {
log.info("removing deployment-group: name={}", name);
final ZooKeeperClient client = provider.get("removeDeploymentGroup");
try {
client.ensurePath(Paths.configDeploymentGroups());
client.ensurePath(Paths.statusDeploymentGroups());
client.ensurePath(Paths.statusDeploymentGroupTasks());
final List<ZooKeeperOperation> operations = Lists.newArrayList();
final List<String> paths = ImmutableList.of(Paths.configDeploymentGroup(name), Paths.statusDeploymentGroup(name), Paths.statusDeploymentGroupHosts(name), Paths.statusDeploymentGroupRemovedHosts(name), Paths.statusDeploymentGroupTasks(name));
// DGs to become slower and spam logs with errors so we want to avoid it.
for (final String path : paths) {
if (client.exists(path) == null) {
operations.add(create(path));
}
}
for (final String path : Lists.reverse(paths)) {
operations.add(delete(path));
}
client.transaction(operations);
} catch (final NoNodeException e) {
throw new DeploymentGroupDoesNotExistException(name);
} catch (final KeeperException e) {
throw new HeliosRuntimeException("removing deployment-group " + name + " failed", e);
}
}
use of com.spotify.helios.common.HeliosRuntimeException 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);
}
}
use of com.spotify.helios.common.HeliosRuntimeException in project helios by spotify.
the class ZooKeeperMasterModel method addDeploymentGroup.
/**
* Create a deployment group.
*
* <p>If successful, the following ZK nodes will be created:
* <ul>
* <li>/config/deployment-groups/[group-name]</li>
* <li>/status/deployment-groups/[group-name]</li>
* <li>/status/deployment-groups/[group-name]/hosts</li>
* </ul>
* These nodes are guaranteed to exist until the DG is removed.
*
* <p>If the operation fails no ZK nodes will be created. If any of the nodes above already exist
* the operation will fail.
*
* @throws DeploymentGroupExistsException If a DG with the same name already exists.
*/
@Override
public void addDeploymentGroup(final DeploymentGroup deploymentGroup) throws DeploymentGroupExistsException {
log.info("adding deployment-group: {}", deploymentGroup);
final ZooKeeperClient client = provider.get("addDeploymentGroup");
try {
try {
client.ensurePath(Paths.configDeploymentGroups());
client.ensurePath(Paths.statusDeploymentGroups());
client.transaction(create(Paths.configDeploymentGroup(deploymentGroup.getName()), deploymentGroup), create(Paths.statusDeploymentGroup(deploymentGroup.getName())), create(Paths.statusDeploymentGroupHosts(deploymentGroup.getName()), Json.asBytesUnchecked(emptyList())), create(Paths.statusDeploymentGroupRemovedHosts(deploymentGroup.getName()), Json.asBytesUnchecked(emptyList())));
} catch (final NodeExistsException e) {
throw new DeploymentGroupExistsException(deploymentGroup.getName());
}
} catch (final KeeperException e) {
throw new HeliosRuntimeException("adding deployment-group " + deploymentGroup + " failed", e);
}
}
Aggregations