Search in sources :

Example 1 with StandAloneJobContainerCommunicator

use of com.alibaba.datax.core.statistics.container.communicator.job.StandAloneJobContainerCommunicator in project DataX by alibaba.

the class JobContainer method start.

/**
     * jobContainer主要负责的工作全部在start()里面,包括init、prepare、split、scheduler、
     * post以及destroy和statistics
     */
@Override
public void start() {
    LOG.info("DataX jobContainer starts job.");
    boolean hasException = false;
    boolean isDryRun = false;
    try {
        this.startTimeStamp = System.currentTimeMillis();
        isDryRun = configuration.getBool(CoreConstant.DATAX_JOB_SETTING_DRYRUN, false);
        if (isDryRun) {
            LOG.info("jobContainer starts to do preCheck ...");
            this.preCheck();
        } else {
            userConf = configuration.clone();
            LOG.debug("jobContainer starts to do preHandle ...");
            this.preHandle();
            LOG.debug("jobContainer starts to do init ...");
            this.init();
            LOG.info("jobContainer starts to do prepare ...");
            this.prepare();
            LOG.info("jobContainer starts to do split ...");
            this.totalStage = this.split();
            LOG.info("jobContainer starts to do schedule ...");
            this.schedule();
            LOG.debug("jobContainer starts to do post ...");
            this.post();
            LOG.debug("jobContainer starts to do postHandle ...");
            this.postHandle();
            LOG.info("DataX jobId [{}] completed successfully.", this.jobId);
            this.invokeHooks();
        }
    } catch (Throwable e) {
        LOG.error("Exception when job run", e);
        hasException = true;
        if (e instanceof OutOfMemoryError) {
            this.destroy();
            System.gc();
        }
        if (super.getContainerCommunicator() == null) {
            // 由于 containerCollector 是在 scheduler() 中初始化的,所以当在 scheduler() 之前出现异常时,需要在此处对 containerCollector 进行初始化
            AbstractContainerCommunicator tempContainerCollector;
            // standalone
            tempContainerCollector = new StandAloneJobContainerCommunicator(configuration);
            super.setContainerCommunicator(tempContainerCollector);
        }
        Communication communication = super.getContainerCommunicator().collect();
        // 汇报前的状态,不需要手动进行设置
        // communication.setState(State.FAILED);
        communication.setThrowable(e);
        communication.setTimestamp(this.endTimeStamp);
        Communication tempComm = new Communication();
        tempComm.setTimestamp(this.startTransferTimeStamp);
        Communication reportCommunication = CommunicationTool.getReportCommunication(communication, tempComm, this.totalStage);
        super.getContainerCommunicator().report(reportCommunication);
        throw DataXException.asDataXException(FrameworkErrorCode.RUNTIME_ERROR, e);
    } finally {
        if (!isDryRun) {
            this.destroy();
            this.endTimeStamp = System.currentTimeMillis();
            if (!hasException) {
                //最后打印cpu的平均消耗,GC的统计
                VMInfo vmInfo = VMInfo.getVmInfo();
                if (vmInfo != null) {
                    vmInfo.getDelta(false);
                    LOG.info(vmInfo.totalString());
                }
                LOG.info(PerfTrace.getInstance().summarizeNoException());
                this.logStatistics();
            }
        }
    }
}
Also used : StandAloneJobContainerCommunicator(com.alibaba.datax.core.statistics.container.communicator.job.StandAloneJobContainerCommunicator) VMInfo(com.alibaba.datax.common.statistics.VMInfo) AbstractContainerCommunicator(com.alibaba.datax.core.statistics.container.communicator.AbstractContainerCommunicator) Communication(com.alibaba.datax.core.statistics.communication.Communication)

Example 2 with StandAloneJobContainerCommunicator

use of com.alibaba.datax.core.statistics.container.communicator.job.StandAloneJobContainerCommunicator in project DataX by alibaba.

the class StandAloneSchedulerTest method testSchedule.

@Test
public void testSchedule() throws NoSuchFieldException, IllegalAccessException {
    int taskNumber = 10;
    List<Configuration> jobList = new ArrayList<Configuration>();
    List<Configuration> internal = new ArrayList<Configuration>();
    int randomSize = 20;
    int length = RandomUtils.nextInt(0, randomSize) + 1;
    for (int i = 0; i < length; i++) {
        internal.add(Configuration.newDefault());
    }
    LocalTGCommunicationManager.clear();
    for (int i = 0; i < taskNumber; i++) {
        Configuration configuration = Configuration.newDefault();
        configuration.set(CoreConstant.DATAX_CORE_CONTAINER_JOB_REPORTINTERVAL, 11);
        configuration.set(CoreConstant.DATAX_CORE_CONTAINER_JOB_ID, 0);
        configuration.set(CoreConstant.DATAX_JOB_CONTENT, internal);
        configuration.set(CoreConstant.DATAX_CORE_CONTAINER_JOB_MODE, ExecuteMode.STANDALONE.getValue());
        configuration.set(CoreConstant.DATAX_CORE_CONTAINER_TASKGROUP_ID, i);
        jobList.add(configuration);
        LocalTGCommunicationManager.registerTaskGroupCommunication(i, new Communication());
    }
    StandAloneJobContainerCommunicator standAloneJobContainerCommunicator = PowerMockito.mock(StandAloneJobContainerCommunicator.class);
    ProcessInnerScheduler scheduler = PowerMockito.spy(new StandAloneScheduler(standAloneJobContainerCommunicator));
    PowerMockito.doNothing().when(scheduler).startAllTaskGroup(anyListOf(Configuration.class));
    Communication communication = new Communication();
    communication.setState(State.SUCCEEDED);
    PowerMockito.when(standAloneJobContainerCommunicator.collect()).thenReturn(communication);
    PowerMockito.doNothing().when(standAloneJobContainerCommunicator).report(communication);
    scheduler.schedule(jobList);
}
Also used : StandAloneJobContainerCommunicator(com.alibaba.datax.core.statistics.container.communicator.job.StandAloneJobContainerCommunicator) Configuration(com.alibaba.datax.common.util.Configuration) StandAloneScheduler(com.alibaba.datax.core.job.scheduler.processinner.StandAloneScheduler) ProcessInnerScheduler(com.alibaba.datax.core.job.scheduler.processinner.ProcessInnerScheduler) ArrayList(java.util.ArrayList) Communication(com.alibaba.datax.core.statistics.communication.Communication) Test(org.junit.Test)

Example 3 with StandAloneJobContainerCommunicator

use of com.alibaba.datax.core.statistics.container.communicator.job.StandAloneJobContainerCommunicator in project DataX by alibaba.

the class JobContainer method initStandaloneScheduler.

private AbstractScheduler initStandaloneScheduler(Configuration configuration) {
    AbstractContainerCommunicator containerCommunicator = new StandAloneJobContainerCommunicator(configuration);
    super.setContainerCommunicator(containerCommunicator);
    return new StandAloneScheduler(containerCommunicator);
}
Also used : StandAloneJobContainerCommunicator(com.alibaba.datax.core.statistics.container.communicator.job.StandAloneJobContainerCommunicator) StandAloneScheduler(com.alibaba.datax.core.job.scheduler.processinner.StandAloneScheduler) AbstractContainerCommunicator(com.alibaba.datax.core.statistics.container.communicator.AbstractContainerCommunicator)

Aggregations

StandAloneJobContainerCommunicator (com.alibaba.datax.core.statistics.container.communicator.job.StandAloneJobContainerCommunicator)3 StandAloneScheduler (com.alibaba.datax.core.job.scheduler.processinner.StandAloneScheduler)2 Communication (com.alibaba.datax.core.statistics.communication.Communication)2 AbstractContainerCommunicator (com.alibaba.datax.core.statistics.container.communicator.AbstractContainerCommunicator)2 VMInfo (com.alibaba.datax.common.statistics.VMInfo)1 Configuration (com.alibaba.datax.common.util.Configuration)1 ProcessInnerScheduler (com.alibaba.datax.core.job.scheduler.processinner.ProcessInnerScheduler)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1