use of com.spotify.helios.common.descriptors.DeploymentGroup 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");
log.info("preparing to initiate rolling-update on deployment-group: name={}, jobId={}", deploymentGroup.getName(), jobId);
final DeploymentGroup updated = deploymentGroup.toBuilder().setJobId(jobId).setRolloutOptions(options).setRollingUpdateReason(MANUAL).build();
if (getJob(jobId) == null) {
throw new JobDoesNotExistException(jobId);
}
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);
}
}
use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.
the class DeploymentGroupCreateCommandTest method testCreateDeploymentGroup.
@Test
public void testCreateDeploymentGroup() throws Exception {
mockCreateResponse(CreateDeploymentGroupResponse.Status.CREATED);
assertEquals(0, command.run(options, client, out, false, null));
final ArgumentCaptor<DeploymentGroup> captor = ArgumentCaptor.forClass(DeploymentGroup.class);
verify(client).createDeploymentGroup(captor.capture());
assertEquals(GROUP_NAME, captor.getValue().getName());
assertEquals(HOST_SELECTORS, captor.getValue().getHostSelectors());
final String output = baos.toString();
assertThat(output, containsString("\"name\":\"foo-group\""));
assertThat(output, containsString("\"hostSelectors\":[" + "{\"label\":\"foo\",\"operand\":\"bar\",\"operator\":\"EQUALS\"}," + "{\"label\":\"baz\",\"operand\":\"qux\",\"operator\":\"EQUALS\"}" + "]"));
assertThat(output, containsString("CREATED"));
}
use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.
the class DeploymentGroupInspectCommandTest method setUp.
@Before
public void setUp() {
// use a real, dummy Subparser impl to avoid having to mock out every single call
final ArgumentParser parser = ArgumentParsers.newArgumentParser("test");
final Subparser subparser = parser.addSubparsers().addParser("inspect");
command = new DeploymentGroupInspectCommand(subparser);
when(client.deploymentGroup(NAME)).thenReturn(Futures.immediateFuture(DEPLOYMENT_GROUP));
final ListenableFuture<DeploymentGroup> nullFuture = Futures.immediateFuture(null);
when(client.deploymentGroup(NON_EXISTENT_NAME)).thenReturn(nullFuture);
}
use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.
the class ZooKeeperMasterModel method getInitRollingUpdateOps.
private RollingUpdateOp getInitRollingUpdateOps(final DeploymentGroup deploymentGroup, final List<String> updateHosts, final List<String> undeployHosts, final ZooKeeperClient zooKeeperClient) throws KeeperException {
final List<RolloutTask> rolloutTasks = new ArrayList<>();
// give precedence to the updateHosts list so we don't end up in a state where we updated a host
// and then removed the job from it (because of buggy logic in the calling method)
final List<String> updateHostsCopy = new ArrayList<>(updateHosts);
final List<String> undeployHostsCopy = new ArrayList<>(undeployHosts);
undeployHostsCopy.removeAll(updateHostsCopy);
// we only care about hosts that are UP
final List<String> upHostsToUndeploy = undeployHostsCopy.stream().filter(host -> checkHostUp(zooKeeperClient, host)).collect(Collectors.toList());
final List<String> upHostsToDeploy = updateHostsCopy.stream().filter(host -> checkHostUp(zooKeeperClient, host)).collect(Collectors.toList());
rolloutTasks.addAll(RollingUndeployPlanner.of(deploymentGroup).plan(upHostsToUndeploy));
rolloutTasks.addAll(RollingUpdatePlanner.of(deploymentGroup).plan(upHostsToDeploy));
log.info("generated rolloutTasks for deployment-group name={} " + "updateHosts={} undeployHosts={}: {}", deploymentGroup.getName(), updateHosts, undeployHosts, rolloutTasks);
final DeploymentGroupTasks tasks = DeploymentGroupTasks.newBuilder().setRolloutTasks(rolloutTasks).setTaskIndex(0).setDeploymentGroup(deploymentGroup).build();
return new RollingUpdateOpFactory(tasks, DEPLOYMENT_GROUP_EVENT_FACTORY).start(deploymentGroup, zooKeeperClient);
}
use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.
the class ZooKeeperMasterModel method getDeploymentGroupHosts.
@Override
public List<String> getDeploymentGroupHosts(final String name) throws DeploymentGroupDoesNotExistException {
log.debug("getting deployment group hosts: {}", name);
final ZooKeeperClient client = provider.get("getDeploymentGroupHosts");
final DeploymentGroup deploymentGroup = getDeploymentGroup(client, name);
if (deploymentGroup == null) {
throw new DeploymentGroupDoesNotExistException(name);
}
return getHosts(client, Paths.statusDeploymentGroupHosts(name));
}
Aggregations