Search in sources :

Example 1 with ResourceResolver

use of com.walmartlabs.concord.runtime.v2.runner.ResourceResolver in project concord by walmartlabs.

the class ScriptCallCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    state.peekFrame(threadId).pop();
    Context ctx = runtime.getService(Context.class);
    ExpressionEvaluator expressionEvaluator = runtime.getService(ExpressionEvaluator.class);
    ScriptEvaluator scriptEvaluator = runtime.getService(ScriptEvaluator.class);
    ResourceResolver resourceResolver = runtime.getService(ResourceResolver.class);
    ScriptCall call = getStep();
    ScriptCallOptions opts = Objects.requireNonNull(call.getOptions());
    Map<String, Object> input = VMUtils.prepareInput(expressionEvaluator, ctx, opts.input(), opts.inputExpression());
    String language = getLanguage(expressionEvaluator, scriptEvaluator, ctx, call);
    Reader content = getContent(expressionEvaluator, resourceResolver, ctx, call);
    ScriptResult scriptResult;
    try {
        scriptResult = scriptEvaluator.eval(ctx, language, content, input);
    } finally {
        try {
            content.close();
        } catch (IOException e) {
            // we don't have to do anything about it, but we're going to log the error just in case
            log.warn("Error while closing the script's reader: {}", e.getMessage() + ". This is most likely a bug.");
        }
    }
    OutputUtils.process(runtime, ctx, scriptResult.items(), opts.out(), opts.outExpr());
}
Also used : Context(com.walmartlabs.concord.runtime.v2.sdk.Context) ScriptResult(com.walmartlabs.concord.runtime.v2.runner.script.ScriptResult) ScriptEvaluator(com.walmartlabs.concord.runtime.v2.runner.script.ScriptEvaluator) ScriptCallOptions(com.walmartlabs.concord.runtime.v2.model.ScriptCallOptions) ScriptCall(com.walmartlabs.concord.runtime.v2.model.ScriptCall) ResourceResolver(com.walmartlabs.concord.runtime.v2.runner.ResourceResolver) ExpressionEvaluator(com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)

Aggregations

ScriptCall (com.walmartlabs.concord.runtime.v2.model.ScriptCall)1 ScriptCallOptions (com.walmartlabs.concord.runtime.v2.model.ScriptCallOptions)1 ResourceResolver (com.walmartlabs.concord.runtime.v2.runner.ResourceResolver)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 ScriptEvaluator (com.walmartlabs.concord.runtime.v2.runner.script.ScriptEvaluator)1 ScriptResult (com.walmartlabs.concord.runtime.v2.runner.script.ScriptResult)1 Context (com.walmartlabs.concord.runtime.v2.sdk.Context)1