private int compare(final CharBuffer b1, final CharBuffer b2) { if (isNumerical(b1) && isNumerical(b2)) { return compareNumerically(b1, b2); } return compareAsStrings(b1, b2); }
public static RollingUpdatePlanner of(final DeploymentGroup deploymentGroup) { return new RollingUpdatePlanner(deploymentGroup); }
public static RollingUndeployPlanner of(final DeploymentGroup deploymentGroup) { return new RollingUndeployPlanner(deploymentGroup); }
@Override public int compare(final CharSequence s1, final CharSequence s2) { final CharBuffer b1 = wrap(s1); final CharBuffer b2 = wrap(s2); while (b1.hasRemaining() && b2.hasRemaining()) { moveWindow(b1); moveWindow(b2); final int result = compare(b1, b2); if (result != 0) { return result; } prepareForNextIteration(b1); prepareForNextIteration(b2); } return s1.length() - s2.length(); }
.collect(Collectors.toList()); rolloutTasks.addAll(RollingUndeployPlanner.of(deploymentGroup) .plan(upHostsToUndeploy)); rolloutTasks.addAll(RollingUpdatePlanner.of(deploymentGroup) .plan(upHostsToDeploy)); .build(); return new RollingUpdateOpFactory(tasks, DEPLOYMENT_GROUP_EVENT_FACTORY) .start(deploymentGroup, zooKeeperClient);
final String errMsg = isNullOrEmpty(host) ? msg : host + ": " + msg; if (isIgnoreFailures()) { log.info( "would have set state=FAILED for deploymentGroup={} but ignoreFailures is set to true " deploymentGroup.getName(), errorCode, errMsg); return nextTask(operations); final Map<String, Object> taskEv = eventFactory.rollingUpdateTaskFailed( deploymentGroup, task, errMsg, errorCode, metadata); events.add(taskEv); events.add(eventFactory.rollingUpdateFailed(deploymentGroup, taskEv)); log.info("rolling-update step on deployment-group name={} failed; message={}", deploymentGroup.getName(), errMsg); return new RollingUpdateOp(ImmutableList.copyOf(operations), ImmutableList.copyOf(events));
private void moveWindow(final CharBuffer buffer) { int start = buffer.position(); int end = buffer.position(); final boolean isNumerical = isDigit(buffer.get(start)); while (end < buffer.limit() && isNumerical == isDigit(buffer.get(end))) { ++end; if (isNumerical && (start + 1 < buffer.limit()) && isZero(buffer.get(start)) && isDigit(buffer.get(end))) { ++start; // trim leading zeros } } buffer.position(start) .limit(end); }
/** * Create a new RollingUpdateService. * * @param masterModel The {@link MasterModel} to use for retrieving data. * @param reactorFactory The factory to use for creating reactors. */ public RollingUpdateService(final MasterModel masterModel, final ReactorFactory reactorFactory) { this.masterModel = checkNotNull(masterModel, "masterModel"); checkNotNull(reactorFactory, "reactorFactory"); this.hostUpdateReactor = reactorFactory.create("hostUpdate", new UpdateDeploymentGroupHosts(), HOST_UPDATE_INTERVAL); this.rollingUpdateReactor = reactorFactory.create("rollingUpdate", new RollingUpdate(), UPDATE_INTERVAL); }
public Map<String, Object> rollingUpdateTaskFailed(final DeploymentGroup deploymentGroup, final RolloutTask task, final String error, final RollingUpdateError errorCode, final Map<String, Object> metadata) { final Map<String, Object> ev = createEvent("rollingUpdateTaskResult", deploymentGroup); ev.putAll(metadata); ev.put("success", 0); ev.put("error", error); ev.put("errorCode", errorCode); return addTaskFields(ev, task); }
private RollingUpdateOp rollingUpdateAwaitUndeployed(final ZooKeeperClient client, final RollingUpdateOpFactory opFactory, final DeploymentGroup deploymentGroup, final String host) { final TaskStatus taskStatus = getTaskStatus(client, host, deploymentGroup.getJobId()); if (taskStatus == null) { // The task status (i.e. /status/hosts/<host>/job/<job-id>) has been removed, indicating the // job has been undeployed. return opFactory.nextTask(); } if (isRolloutTimedOut(client, deploymentGroup)) { return opFactory.error("timed out while waiting for job undeployment", host, RollingUpdateError.TIMED_OUT_WAITING_FOR_JOB_TO_UNDEPLOY); } return opFactory.yield(); }
public Map<String, Object> rollingUpdateTaskSucceeded(final DeploymentGroup deploymentGroup, final RolloutTask task) { final Map<String, Object> ev = createEvent("rollingUpdateTaskResult", deploymentGroup); ev.put("success", 1); return addTaskFields(ev, task); }
private boolean isNumerical(final CharBuffer buffer) { return isDigit(buffer.charAt(0)); }
public Map<String, Object> rollingUpdateDone(final DeploymentGroup deploymentGroup) { final Map<String, Object> ev = createEvent("rollingUpdateFinished", deploymentGroup); ev.put("success", 1); return ev; }
public RollingUpdateOp error(final String msg, final String host, final RollingUpdateError errorCode) { return error(msg, host, errorCode, Collections.<String, Object>emptyMap()); }
public RollingUpdateOp nextTask() { return nextTask(Collections.<ZooKeeperOperation>emptyList()); }
/** * Don't advance to the next task -- yield and have the current task be executed again in the * next iteration. * * @return {@link RollingUpdateOp} */ public RollingUpdateOp yield() { // Do nothing return new RollingUpdateOp(ImmutableList.<ZooKeeperOperation>of(), ImmutableList.<Map<String, Object>>of()); }
@Override public List<RolloutTask> plan(final List<String> hosts) { // generate the rollout tasks final List<RolloutTask> rolloutTasks = Lists.newArrayList(); final int parallelism = deploymentGroup.getRolloutOptions() != null && deploymentGroup.getRolloutOptions().getParallelism() != null ? deploymentGroup.getRolloutOptions().getParallelism() : 1; Lists.partition(hosts, parallelism) .forEach(partition -> rolloutTasks.addAll(rolloutTasks(partition))); return ImmutableList.copyOf(rolloutTasks); }
public Map<String, Object> rollingUpdateFailed(final DeploymentGroup deploymentGroup, final Map<String, Object> failEvent) { final Map<String, Object> ev = createEvent("rollingUpdateFinished", deploymentGroup); ev.put("success", 0); ev.put("failedTask", failEvent); return ev; } }
public RollingUpdateOp error(final Exception ex, final String host, final RollingUpdateError errorCode) { final String message; if (errorCode == RollingUpdateError.PORT_CONFLICT) { message = ex.getMessage() + " (the conflicting job was deployed manually or by a different deployment group)"; } else { message = ex.getMessage(); } return error(message, host, errorCode); } }
public Map<String, Object> rollingUpdateStarted(final DeploymentGroup deploymentGroup) { final Map<String, Object> ev = createEvent("rollingUpdateStarted", deploymentGroup); ev.put("reason", deploymentGroup.getRollingUpdateReason()); return ev; }