private static JsonObject analyzeBatch(BatchScript script) { assert script != null; JsonArray jobflows = new JsonArray(); for (FlowScript flowScript : script.getAllFlows()) { JsonObject jobflow = analyzeJobflow(flowScript); jobflows.add(jobflow); } JsonObject batch = new JsonObject(); batch.addProperty("id", script.getId()); batch.add("jobflows", jobflows); return batch; }
static Configuration parseConfiguration(String[] args) throws ParseException { assert args != null; LOG.debug("Analyzing YAESS Explain arguments: {}", Arrays.toString(args)); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); String script = cmd.getOptionValue(OPT_SCRIPT.getOpt()); LOG.debug("Script: {}", script); Configuration result = new Configuration(); LOG.debug("Loading script: {}", script); try { Properties properties = CommandLineUtil.loadProperties(new File(script)); result.script = BatchScript.load(properties); } catch (Exception e) { throw new IllegalArgumentException(MessageFormat.format( "Invalid script \"{0}\".", script), e); } LOG.debug("Analyzed YAESS Explain arguments"); return result; }
/** * Loads a {@link BatchScript}. * @param properties source properties * @return the loaded script * @throws IllegalArgumentException if script is invalid, or some parameters were {@code null} */ public static BatchScript load(Properties properties) { if (properties == null) { throw new IllegalArgumentException("properties must not be null"); //$NON-NLS-1$ } String version = properties.getProperty(KEY_VERSION); if (VERSION.equals(version) == false) { throw new IllegalArgumentException(MessageFormat.format( "Unsupported script version: {0}", version)); } String batchId = properties.getProperty(KEY_ID); String verificationCode = properties.getProperty(KEY_VERIFICATION_CODE); Set<String> flowIds = FlowScript.extractFlowIds(properties); List<FlowScript> flowScripts = new ArrayList<>(); for (String flowId : flowIds) { FlowScript flowScript = FlowScript.load(properties, flowId); flowScripts.add(flowScript); } return new BatchScript(batchId, verificationCode, flowScripts); } }
private static void consumeRuntimeContext( ExecutionTask result, Map<String, String> copyDefinitions, BatchScript script) { assert result != null; assert copyDefinitions != null; assert script != null; RuntimeContext rc = RuntimeContext.get().batchId(script.getId()).buildId(script.getBuildId()); Ternary dryRunResult = consumeBoolean(copyDefinitions, KEY_VERIFY_DRYRUN); if (dryRunResult == Ternary.TRUE) { rc = rc.mode(ExecutionMode.SIMULATION); } else if (dryRunResult == Ternary.FALSE) { rc = rc.mode(ExecutionMode.PRODUCTION); } Ternary verify = consumeBoolean(copyDefinitions, KEY_VERIFY_APPLICATION); if (verify == Ternary.FALSE) { rc = rc.buildId(null); } result.runtimeContext = rc; result.getEnv().putAll(rc.unapply()); }
BatchScheduler(String batchId, BatchScript batchScript, ExecutionLock lock, ExecutorService executor) { assert batchId != null; assert batchScript != null; assert lock != null; assert executor != null; this.batchId = batchId; this.flows = new LinkedList<>(batchScript.getAllFlows()); this.lock = lock; this.executor = executor; this.running = new HashMap<>(); this.blocking = new HashSet<>(); for (FlowScript flow : flows) { blocking.add(flow.getId()); } this.doneQueue = new LinkedBlockingQueue<>(); }
private static void consumeSkipFlows( ExecutionTask task, Map<String, String> copyDefinitions, BatchScript script) { assert task != null; assert copyDefinitions != null; assert script != null; String flows = copyDefinitions.remove(KEY_SKIP_FLOWS); if (flows == null || flows.trim().isEmpty()) { return; } LOG.debug("Definition: {}={}", KEY_SKIP_FLOWS, flows); for (String flowIdCandidate : flows.split(",")) { String flowId = flowIdCandidate.trim(); if (flowId.isEmpty() == false) { FlowScript flow = script.findFlow(flowId); if (flow == null) { throw new IllegalArgumentException(MessageFormat.format( "Unknown flowId in definition {0} : {1}", KEY_SKIP_FLOWS, flowId)); } task.skipFlows.add(flowId); } } }
throw new IllegalArgumentException("executionId must not be null"); //$NON-NLS-1$ FlowScript flow = script.findFlow(flowId); if (flow == null) { throw new IllegalArgumentException(MessageFormat.format(
BatchScript batch = BatchScript.load(script);
/** * Executes a target phase. * @param context the current context * @throws InterruptedException if interrupted during this execution * @throws IOException if failed to execute target phase * @throws IllegalArgumentException if some parameters were {@code null} * @since 0.2.5 */ public void executePhase(ExecutionContext context) throws InterruptedException, IOException { if (context == null) { throw new IllegalArgumentException("context must not be null"); //$NON-NLS-1$ } FlowScript flow = script.findFlow(context.getFlowId()); if (flow == null) { throw new IllegalArgumentException(MessageFormat.format( "Flow is undefined: batchId={0}, flowId={1}, executionId={2}", context.getBatchId(), context.getFlowId(), context.getExecutionId())); } Set<ExecutionScript> executions = flow.getScripts().get(context.getPhase()); try (ExecutionLock lock = acquireExecutionLock(context.getBatchId())) { lock.beginFlow(context.getFlowId(), context.getExecutionId()); executePhase(context, executions, flow.getEnabledScriptKinds()); lock.endFlow(context.getFlowId(), context.getExecutionId()); } }