@Override public String apply(RunId input) { return input.getId(); } };
@Override public String apply(RunId input) { return input.getId(); } };
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || !(other instanceof RunId)) { return false; } return id.equals(((RunId) other).getId()); }
@Override public void process(WatchedEvent event) { if (event.getState() == Event.KeeperState.Expired) { LOG.warn("ZK Session expired for service {} with runId {}.", getServiceName(), runId.getId()); expired = true; } else if (event.getState() == Event.KeeperState.SyncConnected && expired) { LOG.info("Reconnected after expiration for service {} with runId {}", getServiceName(), runId.getId()); expired = false; logIfFailed(createLiveNode()); } } });
/** * @return time from the UUID if it is a time-based UUID, -1 otherwise. */ public static long getTime(RunId runId, TimeUnit timeUnit) { return getTime(runId.getId(), timeUnit); }
@Override public JsonElement serialize(RunId src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.getId()); } }
/** * Returns the zookeeper node path for the ephemeral instance node for this runId. */ protected final String getInstancePath() { return String.format("%s/%s", Constants.INSTANCES_PATH_PREFIX, getRunId().getId()); }
@Override public JsonElement serialize(RunId src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.getId()); } }
/** * Creates a {@link ProgramRunId} of this program id with the given {@link RunId}. */ public ProgramRunId run(RunId runId) { return run(runId.getId()); }
/** * @return time from the UUID if it is a time-based UUID, -1 otherwise. */ public static long getTime(RunId runId, TimeUnit timeUnit) { return getTime(runId.getId(), timeUnit); }
/** * Creates a {@link ProgramRunId} of this program id with the given {@link RunId}. */ public ProgramRunId run(RunId runId) { return run(runId.getId()); }
@Override public void error(Throwable cause) { Closeables.closeQuietly(closeable); nodeStates.put(nodeId, new WorkflowNodeState(nodeId, NodeStatus.FAILED, controller.getRunId().getId(), cause)); completion.setException(cause); } }, Threads.SAME_THREAD_EXECUTOR);
@Override public void error(Throwable cause) { Closeables.closeQuietly(closeable); nodeStates.put(nodeId, new WorkflowNodeState(nodeId, NodeStatus.FAILED, controller.getRunId().getId(), cause)); completion.setException(cause); } }, Threads.SAME_THREAD_EXECUTOR);
@Override public void killed() { Closeables.closeQuietly(closeable); nodeStates.put(nodeId, new WorkflowNodeState(nodeId, NodeStatus.KILLED, controller.getRunId().getId(), null)); completion.set(null); }
/** * Creates program arguments. It includes all configurations from the specification, excluding hConf and cConf. */ private Arguments createProgramArguments(TwillContext context, Map<String, String> configs) { Map<String, String> args = ImmutableMap.<String, String>builder() .put(ProgramOptionConstants.INSTANCE_ID, Integer.toString(context.getInstanceId())) .put(ProgramOptionConstants.INSTANCES, Integer.toString(context.getInstanceCount())) .put(ProgramOptionConstants.RUN_ID, context.getApplicationRunId().getId()) .putAll(Maps.filterKeys(configs, Predicates.not(Predicates.in(ImmutableSet.of("hConf", "cConf"))))) .build(); return new BasicArguments(args); }
/** * Returns a set of extra system arguments that will be available through the {@link ProgramOptions#getArguments()} * for the program execution. */ protected Map<String, String> getExtraSystemArguments() { Map<String, String> args = new HashMap<>(); args.put(ProgramOptionConstants.INSTANCE_ID, context == null ? "0" : Integer.toString(context.getInstanceId())); args.put(ProgramOptionConstants.INSTANCES, context == null ? "1" : Integer.toString(context.getInstanceCount())); args.put(ProgramOptionConstants.TWILL_RUN_ID, context.getApplicationRunId().getId()); args.put(ProgramOptionConstants.HOST, context.getHost().getCanonicalHostName()); return args; }
@Override public void completed() { Closeables.closeQuietly(closeable); Set<Operation> fieldLineageOperations = new HashSet<>(); if (controller instanceof WorkflowDataProvider) { fieldLineageOperations.addAll(((WorkflowDataProvider) controller).getFieldLineageOperations()); } nodeStates.put(nodeId, new WorkflowNodeState(nodeId, NodeStatus.COMPLETED, fieldLineageOperations, controller.getRunId().getId(), null)); completion.set(null); }
@Override public void completed() { Closeables.closeQuietly(closeable); Set<Operation> fieldLineageOperations = new HashSet<>(); if (controller instanceof WorkflowDataProvider) { fieldLineageOperations.addAll(((WorkflowDataProvider) controller).getFieldLineageOperations()); } nodeStates.put(nodeId, new WorkflowNodeState(nodeId, NodeStatus.COMPLETED, fieldLineageOperations, controller.getRunId().getId(), null)); completion.set(null); }
private RunId getRunId(String runnableName, int instanceId) { RunId baseId; Collection<TwillContainerController> controllers = containers.row(runnableName).values(); if (controllers.isEmpty()) { baseId = RunIds.generate(); } else { String id = controllers.iterator().next().getRunId().getId(); baseId = RunIds.fromString(id.substring(0, id.lastIndexOf('-'))); } return RunIds.fromString(baseId.getId() + '-' + instanceId); }
@Override public void containerLaunched(String runnableName, int instanceId, String containerId) { super.containerLaunched(runnableName, instanceId, containerId); if (runningPublished.compareAndSet(false, true)) { // The program is marked as running when the first container for the program is launched programStateWriterWithHeartBeat.running(twillRunId.getId()); } }