Search in sources :

Example 1 with Delegator

use of io.cdap.cdap.common.lang.Delegator in project cdap by caskdata.

the class DistributedProgramRuntimeService method createRuntimeInfo.

@Override
protected RuntimeInfo createRuntimeInfo(final ProgramController controller, final ProgramId programId, final Runnable cleanUpTask) {
    SimpleRuntimeInfo runtimeInfo = new SimpleRuntimeInfo(controller, programId, cleanUpTask);
    // Add a listener that publishes KILLED status notification when the YARN application is killed in case that
    // the KILLED status notification is not published from the YARN application container, so we don't need to wait
    // for the run record corrector to mark the status as KILLED.
    // Also, the local staging files can be deleted when the twill program is alive.
    controller.addListener(new AbstractListener() {

        ProgramController actualController = controller;

        @Override
        public void init(ProgramController.State currentState, @Nullable Throwable cause) {
            while (actualController instanceof Delegator) {
                // noinspection unchecked
                actualController = ((Delegator<ProgramController>) actualController).getDelegate();
            }
            if (actualController instanceof AbstractTwillProgramController) {
                runtimeInfo.setTwillRunId(((AbstractTwillProgramController) actualController).getTwillRunId());
            }
            if (currentState == ProgramController.State.ALIVE) {
                alive();
            } else if (currentState == ProgramController.State.KILLED) {
                killed();
            }
        }

        @Override
        public void alive() {
            cleanUpTask.run();
        }

        @Override
        public void killed() {
            programStateWriter.killed(programId.run(controller.getRunId()));
        }
    }, Threads.SAME_THREAD_EXECUTOR);
    return runtimeInfo;
}
Also used : ProgramController(io.cdap.cdap.app.runtime.ProgramController) Delegator(io.cdap.cdap.common.lang.Delegator) AbstractListener(io.cdap.cdap.internal.app.runtime.AbstractListener) SimpleRuntimeInfo(io.cdap.cdap.internal.app.runtime.service.SimpleRuntimeInfo)

Aggregations

ProgramController (io.cdap.cdap.app.runtime.ProgramController)1 Delegator (io.cdap.cdap.common.lang.Delegator)1 AbstractListener (io.cdap.cdap.internal.app.runtime.AbstractListener)1 SimpleRuntimeInfo (io.cdap.cdap.internal.app.runtime.service.SimpleRuntimeInfo)1