Search in sources :

Example 1 with AbstractCustomAction

use of io.cdap.cdap.api.customaction.AbstractCustomAction in project cdap by caskdata.

the class CustomActionExecutor method execute.

void execute() throws Exception {
    TransactionControl defaultTxControl = customActionContext.getDefaultTxControl();
    try {
        customActionContext.setState(new ProgramState(ProgramStatus.INITIALIZING, null));
        // AbstractCustomAction implements final initialize(context) and requires subclass to
        // implement initialize(), whereas programs that directly implement CustomAction can
        // override initialize(context)
        TransactionControl txControl = customAction instanceof AbstractCustomAction ? Transactions.getTransactionControl(defaultTxControl, AbstractCustomAction.class, customAction, "initialize") : Transactions.getTransactionControl(defaultTxControl, CustomAction.class, customAction, "initialize", CustomActionContext.class);
        customActionContext.initializeProgram(customAction, txControl, false);
        customActionContext.setState(new ProgramState(ProgramStatus.RUNNING, null));
        customActionContext.execute(customAction::run);
        customActionContext.setState(new ProgramState(ProgramStatus.COMPLETED, null));
    } catch (Throwable t) {
        customActionContext.setState(new ProgramState(ProgramStatus.FAILED, Exceptions.condenseThrowableMessage(t)));
        Throwables.propagateIfPossible(t, Exception.class);
        throw Throwables.propagate(t);
    } finally {
        TransactionControl txControl = Transactions.getTransactionControl(defaultTxControl, CustomAction.class, customAction, "destroy");
        customActionContext.destroyProgram(customAction, txControl, false);
    }
}
Also used : AbstractCustomAction(io.cdap.cdap.api.customaction.AbstractCustomAction) CustomAction(io.cdap.cdap.api.customaction.CustomAction) TransactionControl(io.cdap.cdap.api.annotation.TransactionControl) AbstractCustomAction(io.cdap.cdap.api.customaction.AbstractCustomAction) CustomActionContext(io.cdap.cdap.api.customaction.CustomActionContext) BasicCustomActionContext(io.cdap.cdap.internal.app.runtime.customaction.BasicCustomActionContext) ProgramState(io.cdap.cdap.api.ProgramState)

Aggregations

ProgramState (io.cdap.cdap.api.ProgramState)1 TransactionControl (io.cdap.cdap.api.annotation.TransactionControl)1 AbstractCustomAction (io.cdap.cdap.api.customaction.AbstractCustomAction)1 CustomAction (io.cdap.cdap.api.customaction.CustomAction)1 CustomActionContext (io.cdap.cdap.api.customaction.CustomActionContext)1 BasicCustomActionContext (io.cdap.cdap.internal.app.runtime.customaction.BasicCustomActionContext)1