Module watts_plugin_runner

this module takes care of running a plugin and controlling and validating its results.

Behaviours: gen_server.

Description

this module takes care of running a plugin and controlling and validating its results. It is implemented as a gen_server so that each run of a plugin has a corresponding process in the VM.

Data Types

config()

config() = #{action => parameter | request | revoke, service_id => binary(), queue => atom(), user_info => watts_userinfo:userinfo() | undefined, cred_state => binary() | undefined, params => map()}

output()

output() = #{channel_id => any(), process_id => any(), cmd => string() | undefined, std_out => [binary()], std_err => [binary()], exit_status => any()}

result()

result() = {ok, Result::map(), Output::output()} | {error, Reason::atom() | tuple(), Output::output()} | {error, Reason::atom() | tuple()}

state()

state() = #state{action = any(), client = any(), service_info = undefined | watts_service:info(), user_info = any(), params = any(), queue = any(), job_id = any(), cred_state = any(), connection = any(), con_type = any(), cmd_line = any(), cmd_stdin = undefined | binary(), cmd_output = undefined | output(), error = any()}

Function Index

add_user_info_if_present/4*add the information about the user to the parameter.
close_connection/2*close the connection.
code_change/3only returns the current state.
connect_to_service/1*connect to the plugin, either locally or via ssh.
create_cmd_and_stdin/3*create the command to execute and the stdin input.
create_command_and_update_state/5*create the command line command and update the state with it.
create_result/1*create the result from the command output.
get_connection_info/1*return the connection info from the service info.
get_plugin/1*get the plugin.
handle_call/3hande the only call, the action request.
handle_cast/2each step in the process of executing the plugin is done here.
handle_exec_message/3*handle the messages from the exec module, when done send the result.
handle_info/2handle the responses from either ssh or the executed plugin.
handle_ssh_message/3*handle the incomming ssh messages and when done trigger sending result.
init/1init the gen_server process, this just returns an empty state.
kill/1*kill this process and the execution.
maybe_local_stdin_send/2*
maybe_ssh_stdin_send/3*
output/1*create a valid basic output.
parameter_update/3*return the config and request parameter, if not performing parameter.
prepare_action/1*prepare the execution by creating the command line and connecting.
request_action/2Request the action configured in the config passed.
run_plugin/1*prepare and run a plugin.
run_plugin/5*run the plugin with its parameter.
send_reply/2*send the reply if not yet done.
send_result/1*send the result to the requesting process and stop this one.
start/0start the gen_server process (not linked).
start_link/0start the gen_server process in a linked manner.
stop/1stop the gen_server.
terminate/2check if crashed and send a reply then, if not do nothing.
timeout_result/0*generate a timout result.
trigger_sending/0*trigger sending the result.
update_exit_and_send/2*update the exit status of the command and trigger sending the result.
update_exit_status/2*update the exit status in the cmd output.
update_std_out_err/3*update the std out or error list of inputs.

Function Details

add_user_info_if_present/4 *

add_user_info_if_present(ScriptParam::map(), UserInfo::watts_userinfo:info() | undefined, ServiceId::binary(), AddAccessToken::boolean()) -> map()

add the information about the user to the parameter

close_connection/2 *

close_connection(Connection::any(), X2::ssh | local) -> ok

close the connection

code_change/3

code_change(OldVsn::any(), State::state(), Extra::any()) -> {ok, state()}

only returns the current state.

connect_to_service/1 *

connect_to_service(Info::watts_service:connection()) -> {ok, any()}

connect to the plugin, either locally or via ssh.

create_cmd_and_stdin/3 *

create_cmd_and_stdin(Cmd::binary(), EncJson::binary(), X3::boolean()) -> {string(), undefined | binary()}

create the command to execute and the stdin input

create_command_and_update_state/5 *

create_command_and_update_state(Cmd::binary(), UserInfo::watts_userinfo:info(), ServiceInfo::watts_service:info(), X4::{ok, any()}, State::state()) -> {ok, state()}

create the command line command and update the state with it.

create_result/1 *

create_result(Output::output()) -> result()

create the result from the command output.

get_connection_info/1 *

get_connection_info(X1::watts_service:info()) -> {ok, watts_service:connection()}

return the connection info from the service info

get_plugin/1 *

get_plugin(X1::watts_service:info()) -> {ok, binary()}

get the plugin

handle_call/3

handle_call(Request::{request_action, config()} | any(), From::any(), State::state()) -> {noreply, state(), pos_integer()} | {reply, ignored, state()}

hande the only call, the action request. This will start the process to iterate throught all the needed steps.

handle_cast/2

handle_cast(Msg::any(), State::state()) -> {noreply, state()} | {stop, normal, state()}

each step in the process of executing the plugin is done here. The actions performed are:

handle_exec_message/3 *

handle_exec_message(X1::atom(), Data::binary(), State::state()) -> {ok, state()}

handle the messages from the exec module, when done send the result.

handle_info/2

handle_info(Info::any(), State::state()) -> {noreply, state()} | {stop, normal, state()}

handle the responses from either ssh or the executed plugin.

See also: handle_exec_message/3, handle_ssh_message/3.

handle_ssh_message/3 *

handle_ssh_message(X1::tuple(), ChannelId::any(), State::state()) -> {ok, state()}

handle the incomming ssh messages and when done trigger sending result.

init/1

init(X1::noparams) -> {ok, state()}

init the gen_server process, this just returns an empty state.

kill/1 *

kill(State) -> any()

kill this process and the execution. this is called after a timeout.

maybe_local_stdin_send/2 *

maybe_local_stdin_send(Id::any(), Stdin::undefined | binary()) -> ok

maybe_ssh_stdin_send/3 *

maybe_ssh_stdin_send(Connection::any(), ChannelId::any(), Stdin::undefined | binary()) -> ok

output/1 *

output(Output::map()) -> output()

create a valid basic output

parameter_update/3 *

parameter_update(X1::atom(), ServiceInfo::watts_service:info(), State::state()) -> map()

return the config and request parameter, if not performing parameter.

prepare_action/1 *

prepare_action(State::state()) -> {ok, state()}

prepare the execution by creating the command line and connecting.

request_action/2

request_action(ConfigIn::config(), Pid::pid()) -> result()

Request the action configured in the config passed. The action can be one of the suppoerted actions:

run_plugin/1 *

run_plugin(State::state()) -> {ok, state()}

prepare and run a plugin

run_plugin/5 *

run_plugin(Cmd::string(), Stdin::binary() | undefined, X3::ssh | local, Connection::any(), State::state()) -> {ok, state()}

run the plugin with its parameter. The results will be sent async to this process and are handled by the handle_info/2 function.

send_reply/2 *

send_reply(Reply::result(), State::state()) -> {ok, state()}

send the reply if not yet done.

send_result/1 *

send_result(State::state()) -> {stop, normal, state()}

send the result to the requesting process and stop this one.

start/0

start() -> {ok, pid()}

start the gen_server process (not linked).

start_link/0

start_link() -> {ok, pid()}

start the gen_server process in a linked manner.

stop/1

stop(Pid::pid()) -> ok

stop the gen_server.

terminate/2

terminate(Reason::any(), State::state()) -> ok

check if crashed and send a reply then, if not do nothing.

timeout_result/0 *

timeout_result() -> result()

generate a timout result

trigger_sending/0 *

trigger_sending() -> ok

trigger sending the result.

update_exit_and_send/2 *

update_exit_and_send(ExitStatus::any(), State::state()) -> {ok, state()}

update the exit status of the command and trigger sending the result

update_exit_status/2 *

update_exit_status(ExitStatus::any(), State::state()) -> {ok, state()}

update the exit status in the cmd output

update_std_out_err/3 *

update_std_out_err(Out::binary(), Err::binary(), State::state()) -> {ok, state()}

update the std out or error list of inputs.


Generated by EDoc