use of co.cask.cdap.api.annotation.TransactionControl in project cdap by caskdata.
the class SparkRuntimeService method destroy.
/**
* Calls the destroy or onFinish method of {@link ProgramLifecycle}.
*/
private void destroy(final ProgramState state) {
context.setState(state);
TransactionControl txControl = spark instanceof ProgramLifecycle ? Transactions.getTransactionControl(TransactionControl.IMPLICIT, Spark.class, spark, "destroy") : TransactionControl.IMPLICIT;
runtimeContext.destroyProgram(programLifecycle, txControl, false);
}
use of co.cask.cdap.api.annotation.TransactionControl in project cdap by caskdata.
the class MapReduceRuntimeService method beforeSubmit.
/**
* For MapReduce programs created after 3.5, calls the initialize method of the {@link ProgramLifecycle}.
* This method also sets up the Input/Output within the same transaction.
*/
private void beforeSubmit(final Job job) throws Exception {
context.setState(new ProgramState(ProgramStatus.INITIALIZING, null));
// AbstractMapReduce implements final initialize(context) and requires subclass to
// implement initialize(), whereas programs that directly implement MapReduce have
// the option to override initialize(context) (if they implement ProgramLifeCycle)
TransactionControl txControl = mapReduce instanceof AbstractMapReduce ? Transactions.getTransactionControl(TransactionControl.IMPLICIT, AbstractMapReduce.class, mapReduce, "initialize") : mapReduce instanceof ProgramLifecycle ? Transactions.getTransactionControl(TransactionControl.IMPLICIT, MapReduce.class, mapReduce, "initialize", MapReduceContext.class) : TransactionControl.IMPLICIT;
context.initializeProgram(programLifecycle, txControl, false);
// once the initialize method is executed, set the status of the MapReduce to RUNNING
context.setState(new ProgramState(ProgramStatus.RUNNING, null));
ClassLoader oldClassLoader = ClassLoaders.setContextClassLoader(context.getProgramInvocationClassLoader());
try {
// set input/outputs info, and get one of the configured mapper's TypeToken
TypeToken<?> mapperTypeToken = setInputsIfNeeded(job);
setOutputsIfNeeded(job);
setOutputClassesIfNeeded(job, mapperTypeToken);
setMapOutputClassesIfNeeded(job, mapperTypeToken);
} finally {
ClassLoaders.setContextClassLoader(oldClassLoader);
}
}
use of co.cask.cdap.api.annotation.TransactionControl in project cdap by caskdata.
the class FlowletRuntimeService method destroyFlowlet.
private void destroyFlowlet() {
LOG.debug("Destroying flowlet: {}", flowletContext);
TransactionControl txControl = Transactions.getTransactionControl(TransactionControl.IMPLICIT, Flowlet.class, flowlet, "destroy");
flowletContext.destroyProgram(flowlet, txControl, false);
LOG.debug("Flowlet destroyed: {}", flowletContext);
}
use of co.cask.cdap.api.annotation.TransactionControl in project cdap by caskdata.
the class CustomActionExecutor method execute.
void execute() throws Exception {
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(TransactionControl.IMPLICIT, AbstractCustomAction.class, customAction, "initialize") : Transactions.getTransactionControl(TransactionControl.IMPLICIT, 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, Throwables.getRootCause(t).getMessage()));
Throwables.propagateIfPossible(t, Exception.class);
throw Throwables.propagate(t);
} finally {
TransactionControl txControl = Transactions.getTransactionControl(TransactionControl.IMPLICIT, CustomAction.class, customAction, "destroy");
customActionContext.destroyProgram(customAction, txControl, false);
}
}
use of co.cask.cdap.api.annotation.TransactionControl in project cdap by caskdata.
the class AbstractHttpHandlerDelegator method wrapContentConsumer.
/**
* Returns a new instance of {@link BodyConsumer} that wraps around the given {@link HttpContentConsumer}
* and {@link DelayedHttpServiceResponder}.
*
* IMPORTANT: This method will also capture the context associated with the current thread, hence after
* this method is called, no other methods on this class should be called from the current thread.
*
* This method is called from handler class generated by {@link HttpHandlerGenerator}.
*/
@SuppressWarnings("unused")
protected final BodyConsumer wrapContentConsumer(HttpContentConsumer consumer, DelayedHttpServiceResponder responder, TransactionControl defaultTxControl) {
Preconditions.checkState(!responder.hasBufferedResponse(), "HttpContentConsumer may not be used after a response has already been sent.");
// Close the provided responder since a new one will be created for the BodyConsumerAdapter to use.
responder.close();
ServiceTaskExecutor taskExecutor = context.getServiceTaskExecutor();
Cancellable contextReleaser = context.capture();
return new BodyConsumerAdapter(new DelayedHttpServiceResponder(responder, (contentProducer, txServiceContext) -> new BodyProducerAdapter(contentProducer, txServiceContext, contextReleaser, defaultTxControl)), consumer, taskExecutor, contextReleaser, defaultTxControl);
}
Aggregations