Search in sources :

Example 6 with RolloutOptions

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;
}
Also used : RolloutOptions(com.spotify.helios.common.descriptors.RolloutOptions) KeeperException(org.apache.zookeeper.KeeperException)

Example 7 with RolloutOptions

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);
    }
}
Also used : RolloutOptions(com.spotify.helios.common.descriptors.RolloutOptions) RollingUpdateOp(com.spotify.helios.rollingupdate.RollingUpdateOp) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) Job(com.spotify.helios.common.descriptors.Job) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) KeeperException(org.apache.zookeeper.KeeperException)

Example 8 with RolloutOptions

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());
}
Also used : RolloutOptions(com.spotify.helios.common.descriptors.RolloutOptions) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) Matchers.anyString(org.mockito.Matchers.anyString) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 9 with RolloutOptions

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());
}
Also used : RolloutOptions(com.spotify.helios.common.descriptors.RolloutOptions) RollingUpdateResponse(com.spotify.helios.common.protocol.RollingUpdateResponse) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 10 with RolloutOptions

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()));
}
Also used : RolloutOptions(com.spotify.helios.common.descriptors.RolloutOptions) Job(com.spotify.helios.common.descriptors.Job) Test(org.junit.Test)

Aggregations

RolloutOptions (com.spotify.helios.common.descriptors.RolloutOptions)10 JobId (com.spotify.helios.common.descriptors.JobId)5 RollingUpdateResponse (com.spotify.helios.common.protocol.RollingUpdateResponse)5 Test (org.junit.Test)4 Job (com.spotify.helios.common.descriptors.Job)3 Matchers.anyString (org.mockito.Matchers.anyString)3 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)2 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)2 DeploymentGroupStatusResponse (com.spotify.helios.common.protocol.DeploymentGroupStatusResponse)2 KeeperException (org.apache.zookeeper.KeeperException)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)1 HostSelector (com.spotify.helios.common.descriptors.HostSelector)1 PortMapping (com.spotify.helios.common.descriptors.PortMapping)1 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)1 ServicePorts (com.spotify.helios.common.descriptors.ServicePorts)1 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)1 RollingUpdateOp (com.spotify.helios.rollingupdate.RollingUpdateOp)1 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)1