Search in sources :

Example 16 with DataxProcessor

use of com.qlangtech.tis.datax.impl.DataxProcessor in project tis by qlangtech.

the class DataXExecuteInterceptor method execute.

@Override
protected ExecuteResult execute(IExecChainContext execChainContext) throws Exception {
    int nThreads = 2;
    final ExecutorService executorService = new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(DataXJobSubmit.MAX_TABS_NUM_IN_PER_JOB), Executors.defaultThreadFactory());
    final Map<String, TISReactor.TaskAndMilestone> taskMap = Maps.newHashMap();
    RpcServiceReference statusRpc = getDataXExecReporter();
    DataxProcessor appSource = execChainContext.getAppSource();
    IRemoteTaskTrigger jobTrigger = null;
    RunningStatus runningStatus = null;
    List<IRemoteTaskTrigger> triggers = Lists.newArrayList();
    List<File> cfgFileNames = appSource.getDataxCfgFileNames(null);
    if (CollectionUtils.isEmpty(cfgFileNames)) {
        throw new IllegalStateException("dataX cfgFileNames can not be empty");
    }
    DataXJobSubmit.InstanceType expectDataXJobSumit = getDataXTriggerType();
    Optional<DataXJobSubmit> jobSubmit = DataXJobSubmit.getDataXJobSubmit(expectDataXJobSumit);
    // 如果分布式worker ready的话
    if (!jobSubmit.isPresent()) {
        throw new IllegalStateException("can not find expect jobSubmit by type:" + expectDataXJobSumit);
    }
    DataXJobSubmit submit = jobSubmit.get();
    final DataXJobSubmit.IDataXJobContext dataXJobContext = submit.createJobContext(execChainContext);
    Objects.requireNonNull(dataXJobContext, "dataXJobContext can not be null");
    try {
        DumpPhaseStatus dumpStatus = this.getPhaseStatus(execChainContext, FullbuildPhase.FullDump);
        for (File fileName : cfgFileNames) {
            jobTrigger = createDataXJob(dataXJobContext, submit, expectDataXJobSumit, statusRpc, appSource, fileName.getName());
            triggers.add(jobTrigger);
            taskMap.put(fileName.getName(), new TISReactor.TaskAndMilestone(DataflowTask.createDumpTask(jobTrigger)));
            // StatusRpcClient.AssembleSvcCompsite svc = statusRpc.get();
            // 将任务注册,可供页面展示
            // svc.reportDumpJobStatus(false, false, true, execChainContext.getTaskId()
            // , fileName.getName(), 0, 0);
            dumpStatus.getTable(fileName.getName()).setWaiting(true);
        }
        logger.info("trigger dataX jobs by mode:{},with:{}", this.getDataXTriggerType(), cfgFileNames.stream().map((f) -> f.getName()).collect(Collectors.joining(",")));
        // for (IRemoteJobTrigger t : triggers) {
        // t.submitJob();
        // }
        IDataxReader reader = appSource.getReader(null);
        List<ISelectedTab> selectedTabs = reader.getSelectedTabs();
        // Map<String, IDataxProcessor.TableAlias> tabAlias = appSource.getTabAlias();
        IDataxWriter writer = appSource.getWriter(null);
        if (writer instanceof IDataXBatchPost) {
            IDataXBatchPost batchPostTask = (IDataXBatchPost) writer;
            JoinPhaseStatus phaseStatus = this.getPhaseStatus(execChainContext, FullbuildPhase.JOIN);
            for (ISelectedTab entry : selectedTabs) {
                IRemoteTaskTrigger postTaskTrigger = batchPostTask.createPostTask(execChainContext, entry);
                triggers.add(postTaskTrigger);
                JoinPhaseStatus.JoinTaskStatus taskStatus = phaseStatus.getTaskStatus(postTaskTrigger.getTaskName());
                taskStatus.setWaiting(true);
                taskMap.put(postTaskTrigger.getTaskName(), new TISReactor.TaskAndMilestone(createJoinTask(postTaskTrigger, taskStatus)));
            }
        }
        // example: "->a ->b a,b->c"
        String dagSessionSpec = triggers.stream().map((trigger) -> {
            List<String> dpts = trigger.getTaskDependencies();
            return dpts.stream().collect(Collectors.joining(",")) + "->" + trigger.getTaskName();
        }).collect(Collectors.joining(" "));
        logger.info("dataX:{} of dagSessionSpec:{}", execChainContext.getIndexName(), dagSessionSpec);
        ExecuteResult[] faildResult = new ExecuteResult[] { ExecuteResult.createSuccess() };
        this.executeDAG(executorService, execChainContext, dagSessionSpec, taskMap, new ReactorListener() {

            @Override
            public void onTaskCompleted(Task t) {
            // dumpPhaseStatus.isComplete();
            // joinPhaseStatus.isComplete();
            }

            @Override
            public void onTaskFailed(Task t, Throwable err, boolean fatal) {
                logger.error(t.getDisplayName(), err);
                faildResult[0] = ExecuteResult.createFaild().setMessage("status.runningStatus.isComplete():" + err.getMessage());
                if (err instanceof InterruptedException) {
                    logger.warn("DataX Name:{},taskid:{} has been canceled", execChainContext.getIndexName(), execChainContext.getTaskId());
                    // this job has been cancel, trigger from TisServlet.doDelete()
                    for (IRemoteTaskTrigger tt : triggers) {
                        try {
                            tt.cancel();
                        } catch (Throwable ex) {
                        }
                    }
                }
            }
        });
        // ExecuteResult result = new ExecuteResult(!faild);
        for (IRemoteTaskTrigger trigger : triggers) {
            if (trigger.isAsyn()) {
                execChainContext.addAsynSubJob(new IExecChainContext.AsynSubJob(trigger.getAsynJobName()));
            }
        }
        return faildResult[0];
    } finally {
        try {
            dataXJobContext.destroy();
        } catch (Throwable e) {
            logger.error(e.getMessage(), e);
        }
    }
}
Also used : ExecuteResult(com.qlangtech.tis.exec.ExecuteResult) java.util(java.util) IDataxWriter(com.qlangtech.tis.datax.IDataxWriter) IExecChainContext(com.qlangtech.tis.exec.IExecChainContext) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) LoggerFactory(org.slf4j.LoggerFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) RpcServiceReference(com.tis.hadoop.rpc.RpcServiceReference) Lists(com.google.common.collect.Lists) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) CollectionUtils(org.apache.commons.collections.CollectionUtils) DataXJobSubmit(com.qlangtech.tis.datax.DataXJobSubmit) JoinPhaseStatus(com.qlangtech.tis.fullbuild.phasestatus.impl.JoinPhaseStatus) IDataxReader(com.qlangtech.tis.datax.IDataxReader) AdapterStatusUmbilicalProtocol(com.qlangtech.tis.realtime.yarn.rpc.impl.AdapterStatusUmbilicalProtocol) DumpPhaseStatus(com.qlangtech.tis.fullbuild.phasestatus.impl.DumpPhaseStatus) Task(org.jvnet.hudson.reactor.Task) IDataXBatchPost(com.qlangtech.tis.datax.IDataXBatchPost) TrackableExecuteInterceptor(com.qlangtech.tis.exec.impl.TrackableExecuteInterceptor) FullbuildPhase(com.qlangtech.tis.assemble.FullbuildPhase) IncrStatusUmbilicalProtocolImpl(com.qlangtech.tis.rpc.server.IncrStatusUmbilicalProtocolImpl) IRemoteTaskTrigger(com.qlangtech.tis.fullbuild.indexbuild.IRemoteTaskTrigger) Logger(org.slf4j.Logger) java.util.concurrent(java.util.concurrent) IncrStatusUmbilicalProtocol(com.qlangtech.tis.realtime.yarn.rpc.IncrStatusUmbilicalProtocol) ReactorListener(org.jvnet.hudson.reactor.ReactorListener) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) File(java.io.File) RunningStatus(com.qlangtech.tis.fullbuild.indexbuild.RunningStatus) DataflowTask(com.qlangtech.tis.fullbuild.taskflow.DataflowTask) TISReactor(com.qlangtech.tis.fullbuild.taskflow.TISReactor) ITISRpcService(com.tis.hadoop.rpc.ITISRpcService) Task(org.jvnet.hudson.reactor.Task) DataflowTask(com.qlangtech.tis.fullbuild.taskflow.DataflowTask) DataXJobSubmit(com.qlangtech.tis.datax.DataXJobSubmit) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) RpcServiceReference(com.tis.hadoop.rpc.RpcServiceReference) DumpPhaseStatus(com.qlangtech.tis.fullbuild.phasestatus.impl.DumpPhaseStatus) IDataXBatchPost(com.qlangtech.tis.datax.IDataXBatchPost) IExecChainContext(com.qlangtech.tis.exec.IExecChainContext) IDataxReader(com.qlangtech.tis.datax.IDataxReader) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) RunningStatus(com.qlangtech.tis.fullbuild.indexbuild.RunningStatus) ExecuteResult(com.qlangtech.tis.exec.ExecuteResult) IRemoteTaskTrigger(com.qlangtech.tis.fullbuild.indexbuild.IRemoteTaskTrigger) IDataxWriter(com.qlangtech.tis.datax.IDataxWriter) JoinPhaseStatus(com.qlangtech.tis.fullbuild.phasestatus.impl.JoinPhaseStatus) TISReactor(com.qlangtech.tis.fullbuild.taskflow.TISReactor) ReactorListener(org.jvnet.hudson.reactor.ReactorListener) File(java.io.File)

Example 17 with DataxProcessor

use of com.qlangtech.tis.datax.impl.DataxProcessor in project tis by qlangtech.

the class DataxExecutor method exec.

public void exec(Integer jobId, String jobName, String dataxName, String execTimeStamp) throws Exception {
    boolean success = false;
    MDC.put(IParamContext.KEY_TASK_ID, String.valueOf(jobId));
    try {
        logger.info("process DataX job, dataXName:{},jobid:{},jobName:{}", dataxName, jobId, jobName);
        DataxExecutor.synchronizeDataXPluginsFromRemoteRepository(dataxName, jobName);
        final JarLoader uberClassLoader = new TISJarLoader(TIS.get().getPluginManager());
        DataxProcessor dataxProcessor = DataxProcessor.load(null, dataxName);
        this.startWork(dataxName, jobId, jobName, execTimeStamp, dataxProcessor, uberClassLoader);
        success = true;
    } finally {
        TIS.clean();
        if (execMode == DataXJobSubmit.InstanceType.DISTRIBUTE) {
            try {
                DagTaskUtils.feedbackAsynTaskStatus(jobId, jobName, success);
            } catch (Throwable e) {
                logger.warn("notify exec result faild,jobId:" + jobId + ",jobName:" + jobName, e);
            }
        }
    }
}
Also used : DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) JarLoader(com.alibaba.datax.core.util.container.JarLoader)

Example 18 with DataxProcessor

use of com.qlangtech.tis.datax.impl.DataxProcessor in project tis by qlangtech.

the class TestStreamComponentCodeGeneratorFlink method testSingleTableCodeGenerator.

/**
 * 测试单表增量脚本生成
 *
 * @throws Exception
 */
public void testSingleTableCodeGenerator() throws Exception {
    // CoreAction.create
    // String topologyName = "employees4local";
    String collectionName = "mysql_elastic";
    IAppSource appSource = IAppSource.load(null, collectionName);
    assertTrue(appSource instanceof DataxProcessor);
    DataxProcessor dataXProcessor = (DataxProcessor) appSource;
    // Optional<ERRules> erRule = ERRules.getErRule(topologyName);
    // // 测试针对单表的的topology增量脚本生成
    long timestamp = 20191111115959l;
    // SqlTaskNodeMeta.SqlDataFlowTopology topology = SqlTaskNodeMeta.getSqlDataFlowTopology(topologyName);
    // assertNotNull(topology);
    // if (!erRule.isPresent()) {
    // ERRules.createDefaultErRule(topology);
    // }
    List<FacadeContext> facadeList = Lists.newArrayList();
    StreamComponentCodeGeneratorFlink streamCodeGenerator = new StreamComponentCodeGeneratorFlink(collectionName, timestamp, facadeList, (IBasicAppSource) appSource);
    // EasyMock.replay(streamIncrGenerateStrategy);
    streamCodeGenerator.build();
    TestStreamComponentCodeGenerator.assertGenerateContentEqual(timestamp, collectionName, "MysqlElasticListener.scala");
// EasyMock.verify(streamIncrGenerateStrategy);
}
Also used : DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) IAppSource(com.qlangtech.tis.manage.IAppSource)

Aggregations

DataxProcessor (com.qlangtech.tis.datax.impl.DataxProcessor)18 File (java.io.File)11 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)9 Lists (com.google.common.collect.Lists)3 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)3 Collectors (java.util.stream.Collectors)3 Maps (com.google.common.collect.Maps)2 IHiveConnGetter (com.qlangtech.tis.config.hive.IHiveConnGetter)2 DataXJobSubmit (com.qlangtech.tis.datax.DataXJobSubmit)2 IDataxReader (com.qlangtech.tis.datax.IDataxReader)2 DataXCfgGenerator (com.qlangtech.tis.datax.impl.DataXCfgGenerator)2 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)2 DataxWriter (com.qlangtech.tis.datax.impl.DataxWriter)2 IExecChainContext (com.qlangtech.tis.exec.IExecChainContext)2 IRemoteTaskTrigger (com.qlangtech.tis.fullbuild.indexbuild.IRemoteTaskTrigger)2 IAppSource (com.qlangtech.tis.manage.IAppSource)2 java.util (java.util)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2