Search in sources :

Example 1 with PythonInterpreterRequest

use of org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest in project apex-malhar by apache.

the class PythonRequestResponseUtil method buildRequestObjectForRunCommands.

/**
 * Builds the request object for run commands API request. See
 * {@link ApexPythonEngine#runCommands(WorkerExecutionMode, long, long, PythonInterpreterRequest)} for details
 * @param commands
 * @param timeOut timeout for the request to complete
 * @param timeUnit Time units
 * @return A request object that can be passed to the Python Engine API for run commands
 */
public static PythonInterpreterRequest<Void> buildRequestObjectForRunCommands(List<String> commands, long timeOut, TimeUnit timeUnit) {
    GenericCommandsRequestPayload genericCommandsRequestPayload = new GenericCommandsRequestPayload();
    genericCommandsRequestPayload.setGenericCommands(commands);
    PythonInterpreterRequest<Void> request = new PythonInterpreterRequest<>(Void.class);
    request.setTimeUnit(timeUnit);
    request.setTimeout(timeOut);
    request.setGenericCommandsRequestPayload(genericCommandsRequestPayload);
    return request;
}
Also used : GenericCommandsRequestPayload(org.apache.apex.malhar.python.base.requestresponse.GenericCommandsRequestPayload) PythonInterpreterRequest(org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest)

Example 2 with PythonInterpreterRequest

use of org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest in project apex-malhar by apache.

the class PythonRequestResponseUtil method buildRequestForEvalCommand.

/**
 * Builds the request object for the Eval command request. See
 * {@link ApexPythonEngine#eval(WorkerExecutionMode, long, long, PythonInterpreterRequest)} for details
 * @param evalCommand The eval expression
 * @param evalParams Variables that need to be substituted
 * @param varNameToExtract The name of variable to extract if any after the expression is evaluated. Can be null
 * @param deleteVarAfterExtract The name of the variable to delete if any. null allowed
 * @param timeOut Timeout for the API to complete processing
 * @param timeUnit Units of time for the time out variable
 * @param clazz The Class that represents the return type
 * @param <T> Template construct for Java type inference
 * @return The request object that can be used for the Eval command
 */
public static <T> PythonInterpreterRequest<T> buildRequestForEvalCommand(String evalCommand, Map<String, Object> evalParams, String varNameToExtract, boolean deleteVarAfterExtract, long timeOut, TimeUnit timeUnit, Class<T> clazz) {
    PythonInterpreterRequest<T> request = new PythonInterpreterRequest<>(clazz);
    EvalCommandRequestPayload evalCommandRequestPayload = new EvalCommandRequestPayload();
    evalCommandRequestPayload.setEvalCommand(evalCommand);
    evalCommandRequestPayload.setVariableNameToExtractInEvalCall(varNameToExtract);
    evalCommandRequestPayload.setParamsForEvalCommand(evalParams);
    evalCommandRequestPayload.setDeleteVariableAfterEvalCall(deleteVarAfterExtract);
    request.setTimeUnit(timeUnit);
    request.setTimeout(timeOut);
    request.setEvalCommandRequestPayload(evalCommandRequestPayload);
    return request;
}
Also used : EvalCommandRequestPayload(org.apache.apex.malhar.python.base.requestresponse.EvalCommandRequestPayload) PythonInterpreterRequest(org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest)

Example 3 with PythonInterpreterRequest

use of org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest in project apex-malhar by apache.

the class BaseJEPTest method buildRequestObjectForLongEvalCommand.

protected PythonInterpreterRequest<Long> buildRequestObjectForLongEvalCommand(String command, String returnVar, Map<String, Object> paramsForEval, long timeOut, TimeUnit timeUnit, boolean deleteVariable) {
    PythonInterpreterRequest<Long> request = new PythonInterpreterRequest<>(Long.class);
    request.setTimeout(timeOut);
    request.setTimeUnit(timeUnit);
    EvalCommandRequestPayload evalCommandRequestPayload = new EvalCommandRequestPayload();
    request.setEvalCommandRequestPayload(evalCommandRequestPayload);
    evalCommandRequestPayload.setParamsForEvalCommand(paramsForEval);
    evalCommandRequestPayload.setDeleteVariableAfterEvalCall(deleteVariable);
    evalCommandRequestPayload.setVariableNameToExtractInEvalCall(returnVar);
    evalCommandRequestPayload.setEvalCommand(command);
    request.setExpectedReturnType(Long.class);
    return request;
}
Also used : EvalCommandRequestPayload(org.apache.apex.malhar.python.base.requestresponse.EvalCommandRequestPayload) PythonInterpreterRequest(org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest)

Example 4 with PythonInterpreterRequest

use of org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest in project apex-malhar by apache.

the class BaseJEPTest method buildRequestObjectForVoidGenericCommand.

protected PythonInterpreterRequest<Void> buildRequestObjectForVoidGenericCommand(List<String> commands, long timeOut, TimeUnit timeUnit) {
    PythonInterpreterRequest<Void> genericCommandRequest = new PythonInterpreterRequest<>(Void.class);
    genericCommandRequest.setTimeout(timeOut);
    genericCommandRequest.setTimeUnit(timeUnit);
    GenericCommandsRequestPayload genericCommandsRequestPayload = new GenericCommandsRequestPayload();
    genericCommandsRequestPayload.setGenericCommands(commands);
    genericCommandRequest.setExpectedReturnType(Void.class);
    genericCommandRequest.setGenericCommandsRequestPayload(genericCommandsRequestPayload);
    return genericCommandRequest;
}
Also used : GenericCommandsRequestPayload(org.apache.apex.malhar.python.base.requestresponse.GenericCommandsRequestPayload) PythonInterpreterRequest(org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest)

Example 5 with PythonInterpreterRequest

use of org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest in project apex-malhar by apache.

the class PythonRequestResponseUtil method buildRequestForScriptCallCommand.

/**
 * Builds a request object that can be used for executing the script call commands.
 * @param scriptPath Full path to the file name containing the script
 * @param timeOut The time that can be used to complete the execution of the script
 * @param timeUnit Unit of time for time out parameter
 * @param clazz The class that can be used to represent the return type
 * @param <T> Java template for type inference
 * @return The Request object that can be used for a script call invocation
 */
public static <T> PythonInterpreterRequest<T> buildRequestForScriptCallCommand(String scriptPath, long timeOut, TimeUnit timeUnit, Class<T> clazz) {
    PythonInterpreterRequest<T> request = new PythonInterpreterRequest<>(clazz);
    ScriptExecutionRequestPayload scriptExecutionRequestPayload = new ScriptExecutionRequestPayload();
    scriptExecutionRequestPayload.setScriptName(scriptPath);
    request.setTimeUnit(timeUnit);
    request.setTimeout(timeOut);
    request.setScriptExecutionRequestPayload(scriptExecutionRequestPayload);
    return request;
}
Also used : ScriptExecutionRequestPayload(org.apache.apex.malhar.python.base.requestresponse.ScriptExecutionRequestPayload) PythonInterpreterRequest(org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest)

Aggregations

PythonInterpreterRequest (org.apache.apex.malhar.python.base.requestresponse.PythonInterpreterRequest)6 EvalCommandRequestPayload (org.apache.apex.malhar.python.base.requestresponse.EvalCommandRequestPayload)2 GenericCommandsRequestPayload (org.apache.apex.malhar.python.base.requestresponse.GenericCommandsRequestPayload)2 MethodCallRequestPayload (org.apache.apex.malhar.python.base.requestresponse.MethodCallRequestPayload)1 ScriptExecutionRequestPayload (org.apache.apex.malhar.python.base.requestresponse.ScriptExecutionRequestPayload)1