@Override public String getId() { return script.getId(); }
@Override public Set<String> getBlockerIds() { return script.getBlockerIds(); }
for (ExecutionScript script : phase.getValue()) { String scriptPrefix = getPrefix(getId(), phase.getKey(), String.format("%04d", index++)); properties.setProperty(scriptPrefix + KEY_ID, script.getId()); properties.setProperty(scriptPrefix + KEY_KIND, script.getKind().getSymbol()); properties.setProperty(scriptPrefix + KEY_BLOCKERS, join(script.getBlockerIds())); properties.setProperty(scriptPrefix + KEY_SUPPORTED_EXTENSIONS, join(script.getSupportedExtensions())); String envPrefix = scriptPrefix + KEY_ENV_PREFIX; for (Map.Entry<String, String> entry : script.getEnvironmentVariables().entrySet()) { properties.setProperty(envPrefix + entry.getKey(), entry.getValue()); switch (script.getKind()) { case COMMAND: { CommandScript s = (CommandScript) script; throw new AssertionError(script.getKind());
private String getAsakusaHomePath( ExecutionContext context, ExecutionScript script, ExecutionScriptHandler<?> handler) throws IOException, InterruptedException { assert context != null; assert script != null; assert handler != null; String inScript = script.getEnvironmentVariables().get(ENV_ASAKUSA_HOME); if (inScript != null && inScript.equals(PLACEHOLDER_HOME) == false) { LOG.debug("Asakusa location is found in script: {} -> {}", script.getId(), inScript); return inScript; } Map<String, String> environmentVariables = handler.getEnvironmentVariables(context, script); String inHandler = environmentVariables.get(ENV_ASAKUSA_HOME); if (inHandler != null) { LOG.debug("Asakusa location is found in handler: {} -> {}", script.getId(), inHandler); return inHandler; } throw new IOException(MessageFormat.format( "{0} is not defined for \"{1}\"", ENV_ASAKUSA_HOME, handler.getHandlerId())); }
private Map<String, String> buildEnvironmentVariables( ExecutionContext context, ExecutionScript script) throws InterruptedException, IOException { assert script != null; Map<String, String> env = new HashMap<>(); env.putAll(getEnvironmentVariables(context, script)); env.putAll(context.getEnvironmentVariables()); env.putAll(script.getEnvironmentVariables()); return env; }
/** * Builds {@link ExecutionContext#getExtensions() extensions} for the script. * @param context the current context * @param script the target script * @return the extended arguments */ public static Map<String, Blob> getExtensions(ExecutionContext context, ExecutionScript script) { Map<String, Blob> results = new LinkedHashMap<>(); Map<String, Blob> extensions = context.getExtensions(); Set<String> supported = script.getSupportedExtensions(); for (Map.Entry<String, Blob> entry : extensions.entrySet()) { if (supported.contains(entry.getKey())) { results.put(entry.getKey(), entry.getValue()); } } return results; }
private Map<String, String> buildEnvironmentVariables( ExecutionContext context, ExecutionScript script) throws InterruptedException, IOException { assert script != null; Map<String, String> env = new HashMap<>(); env.putAll(getEnvironmentVariables(context, script)); env.putAll(context.getEnvironmentVariables()); env.putAll(script.getEnvironmentVariables()); return env; } }
List<ScriptJob<?>> results = new ArrayList<>(); for (ExecutionScript execution : executions) { if (enables.contains(execution.getKind()) == false) { throw new IllegalStateException(MessageFormat.format( "job kind {2} is not enabled in this flow (batch={0}, flow={1})", context.getBatchId(), context.getFlowId(), execution.getKind())); switch (execution.getKind()) { case COMMAND: { CommandScript exec = (CommandScript) execution;
@Override public String getJobLabel() { return script.getId(); }
@Override String getKey(ExecutionContext context, ExecutionScript script) { if (script == null) { return null; } return MessageFormat.format( "{0}.{1}.{2}", context.getFlowId(), context.getPhase().getSymbol(), script.getId()); } },
/** * Computes the tracking ID. * @param context target context * @param script target script * @return the operation ID * @since 0.5.0 */ public static String computeTrackingId(ExecutionContext context, ExecutionScript script) { return MessageFormat.format( "YAESS/{0}/{1}/{2}/{3}/{4}", context.getBatchId(), context.getFlowId(), context.getPhase(), context.getExecutionId(), script.getId()); }
private ExecutionScriptHandler<T> resolve( ExecutionContext context, ExecutionScript script) throws IOException { assert context != null; Properties batchConf = getBatchConf(context, script); String key = findKey(context, script, batchConf); if (key != null) { ExecutionScriptHandler<T> target = delegations.get(key); if (target != null) { return target; } throw new IOException(MessageFormat.format( "Invalid dispatch target for multidispatch plugin: " + "{4} (batchId={0}, flowId={1}, phase={2}, stageId={3})", context.getBatchId(), context.getFlowId(), context.getPhase(), script == null ? LABEL_UNDEFINED : script.getId(), key)); } ExecutionScriptHandler<T> defaultTarget = delegations.get(PREFIX_DEFAULT); assert defaultTarget != null; return defaultTarget; }
@Override public void execute( ExecutionMonitor monitor, ExecutionContext context, T script) throws InterruptedException, IOException { ExecutionScriptHandler<T> target = resolve(context, script); assert target != null; YSLOG.info("I01002", target.getHandlerId(), context.getBatchId(), context.getFlowId(), context.getPhase(), context.getExecutionId(), script.getId()); target.execute(monitor, context, script); }