use of com.spotify.helios.common.descriptors.RolloutOptions in project helios by spotify.
the class ZooKeeperMasterModel method isRolloutTimedOut.
private boolean isRolloutTimedOut(final ZooKeeperClient client, final DeploymentGroup deploymentGroup) {
final String groupName = deploymentGroup.getName();
final RolloutOptions defaultOptions = RolloutOptions.getDefault();
final long groupTimeoutSetting = deploymentGroup.getRolloutOptions() == null ? defaultOptions.getTimeout() : deploymentGroup.getRolloutOptions().withFallback(defaultOptions).getTimeout();
final long secondsSinceDeploy;
try {
final String statusPath = Paths.statusDeploymentGroupTasks(groupName);
secondsSinceDeploy = MILLISECONDS.toSeconds(System.currentTimeMillis() - client.getNode(statusPath).getStat().getMtime());
} catch (KeeperException e) {
// statusPath doesn't exist or some other ZK issue. probably this deployment group
// was removed.
log.warn("error determining deployment group modification time: name={}", groupName, e);
return false;
}
if (secondsSinceDeploy > groupTimeoutSetting) {
log.info("rolling-update on deployment-group name={} has timed out after " + "{} seconds (rolloutOptions.timeout={})", groupName, secondsSinceDeploy, groupTimeoutSetting);
return true;
}
return false;
}
use of com.spotify.helios.common.descriptors.RolloutOptions in project helios by spotify.
the class ZooKeeperMasterModel method rollingUpdate.
@Override
public void rollingUpdate(final DeploymentGroup deploymentGroup, final JobId jobId, final RolloutOptions options) throws DeploymentGroupDoesNotExistException, JobDoesNotExistException {
checkNotNull(deploymentGroup, "deploymentGroup");
final Job job = getJob(jobId);
if (job == null) {
throw new JobDoesNotExistException(jobId);
}
final RolloutOptions rolloutOptionsWithFallback = rolloutOptionsWithFallback(options, job);
log.info("preparing to initiate rolling-update on deployment-group: " + "name={}, jobId={}, options={}", deploymentGroup.getName(), jobId, rolloutOptionsWithFallback);
final DeploymentGroup updated = deploymentGroup.toBuilder().setJobId(jobId).setRolloutOptions(rolloutOptionsWithFallback).setRollingUpdateReason(MANUAL).build();
final List<ZooKeeperOperation> operations = Lists.newArrayList();
final ZooKeeperClient client = provider.get("rollingUpdate");
operations.add(set(Paths.configDeploymentGroup(updated.getName()), updated));
try {
final RollingUpdateOp op = getInitRollingUpdateOps(updated, client);
operations.addAll(op.operations());
log.info("starting zookeeper transaction for rolling-update on " + "deployment-group name={} jobId={}. List of operations: {}", deploymentGroup.getName(), jobId, operations);
client.transaction(operations);
emitEvents(deploymentGroupEventTopic, op.events());
log.info("initiated rolling-update on deployment-group: name={}, jobId={}", deploymentGroup.getName(), jobId);
} catch (final NoNodeException e) {
throw new DeploymentGroupDoesNotExistException(deploymentGroup.getName());
} catch (final KeeperException e) {
throw new HeliosRuntimeException("rolling-update on deployment-group " + deploymentGroup.getName() + " failed. " + e.getMessage(), e);
}
}
use of com.spotify.helios.common.descriptors.RolloutOptions in project helios by spotify.
the class RollingUpdateCommandTest method testRollingUpdateMigrate.
@Test
public void testRollingUpdateMigrate() throws Exception {
when(client.rollingUpdate(anyString(), any(JobId.class), any(RolloutOptions.class))).thenReturn(immediateFuture(new RollingUpdateResponse(RollingUpdateResponse.Status.OK)));
when(client.deploymentGroupStatus(GROUP_NAME)).then(new ResponseAnswer(statusResponse(DeploymentGroupStatusResponse.Status.ACTIVE, null, makeHostStatus("host1", JOB_ID, TaskStatus.State.RUNNING))));
when(options.getBoolean("migrate")).thenReturn(true);
final int ret = command.runWithJobId(options, client, out, true, JOB_ID, null);
final String output = baos.toString();
// Verify that rollingUpdate() was called with migrate=true
verify(client).rollingUpdate(GROUP_NAME, JOB_ID, new RolloutOptions(TIMEOUT, PARALLELISM, true, false, TOKEN));
assertEquals(0, ret);
assertJsonOutputEquals(output, ImmutableMap.<String, Object>builder().put("status", "DONE").put("duration", 0.00).put("parallelism", PARALLELISM).put("timeout", TIMEOUT).put("overlap", false).put("token", TOKEN).build());
}
use of com.spotify.helios.common.descriptors.RolloutOptions in project helios by spotify.
the class RollingUpdateCommandTest method testRollingUpdateMigrateJson.
@Test
public void testRollingUpdateMigrateJson() throws Exception {
when(client.rollingUpdate(anyString(), any(JobId.class), any(RolloutOptions.class))).thenReturn(immediateFuture(new RollingUpdateResponse(RollingUpdateResponse.Status.OK)));
when(client.deploymentGroupStatus(GROUP_NAME)).then(new ResponseAnswer(statusResponse(DeploymentGroupStatusResponse.Status.ACTIVE, null, makeHostStatus("host1", JOB_ID, TaskStatus.State.RUNNING))));
when(options.getBoolean("migrate")).thenReturn(true);
final int ret = command.runWithJob(options, client, out, true, JOB, null);
final String output = baos.toString();
// Verify that rollingUpdate() was called with migrate=true
final RolloutOptions rolloutOptions = RolloutOptions.newBuilder().setTimeout(TIMEOUT).setParallelism(PARALLELISM).setMigrate(true).setOverlap(false).setToken(TOKEN).setIgnoreFailures(false).build();
verify(client).rollingUpdate(GROUP_NAME, JOB_ID, rolloutOptions);
assertEquals(0, ret);
assertJsonOutputEquals(output, ImmutableMap.<String, Object>builder().put("status", "DONE").put("duration", 0.00).put("parallelism", PARALLELISM).put("timeout", TIMEOUT).put("overlap", false).put("token", TOKEN).put("ignoreFailures", false).put("migrate", true).build());
}
use of com.spotify.helios.common.descriptors.RolloutOptions in project helios by spotify.
the class ZooKeeperMasterModelTest method testRolloutOptionsWithFallback.
@Test
public void testRolloutOptionsWithFallback() throws Exception {
final RolloutOptions options = RolloutOptions.newBuilder().setTimeout(123L).setParallelism(2).build();
final Job job = Job.newBuilder().setName("foo").setRolloutOptions(RolloutOptions.newBuilder().setParallelism(2).setOverlap(true).setToken("bar").build()).build();
final RolloutOptions rolloutOptions = rolloutOptionsWithFallback(options, job);
assertThat(rolloutOptions, equalTo(RolloutOptions.newBuilder().setParallelism(2).setTimeout(123L).setOverlap(true).setToken("bar").setMigrate(false).setIgnoreFailures(false).build()));
}
Aggregations