Search in sources :

Example 1 with ScriptCallOptions

use of com.walmartlabs.concord.runtime.v2.model.ScriptCallOptions 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)

Example 2 with ScriptCallOptions

use of com.walmartlabs.concord.runtime.v2.model.ScriptCallOptions in project concord by walmartlabs.

the class ScriptCallStepSerializer method serializeOptions.

private static void serializeOptions(ScriptCallOptions options, JsonGenerator gen) throws IOException {
    if (options == null) {
        return;
    }
    if (options.body() != null) {
        gen.writeObjectField("body", options.body());
    }
    writeNotEmptyObjectField("in", options.input(), gen);
    writeNotEmptyObjectField("in", options.inputExpression(), gen);
    writeNotEmptyObjectField("out", options.out(), gen);
    writeNotEmptyObjectField("out", options.outExpr(), gen);
    if (options.withItems() != null) {
        WithItems items = Objects.requireNonNull(options.withItems());
        writeWithItems(items, gen);
    }
    writeLoop(options.loop(), gen);
    if (options.retry() != null) {
        gen.writeObjectField("retry", options.retry());
    }
    writeNotEmptyObjectField("error", options.errorSteps(), gen);
    writeNotEmptyObjectField("meta", options.meta(), gen);
}
Also used : WithItems(com.walmartlabs.concord.runtime.v2.model.WithItems)

Aggregations

ScriptCall (com.walmartlabs.concord.runtime.v2.model.ScriptCall)1 ScriptCallOptions (com.walmartlabs.concord.runtime.v2.model.ScriptCallOptions)1 WithItems (com.walmartlabs.concord.runtime.v2.model.WithItems)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