Search in sources :

Example 1 with DataxWriter

use of com.qlangtech.tis.datax.impl.DataxWriter in project plugins by qlangtech.

the class TestDataxMySQLWriter method testFieldCount.

public void testFieldCount() throws Exception {
    DataxMySQLWriter mySQLWriter = new DataxMySQLWriter();
    Descriptor<DataxWriter> descriptor = mySQLWriter.getDescriptor();
    PluginFormProperties pluginFormPropertyTypes = descriptor.getPluginFormPropertyTypes();
    assertTrue(pluginFormPropertyTypes instanceof RootFormProperties);
    assertEquals(8, pluginFormPropertyTypes.getKVTuples().size());
}
Also used : DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) RootFormProperties(com.qlangtech.tis.extension.impl.RootFormProperties) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties)

Example 2 with DataxWriter

use of com.qlangtech.tis.datax.impl.DataxWriter in project plugins by qlangtech.

the class WriterTemplate method realExecuteDump.

/**
 * dataXWriter执行
 *
 * @param writerJson
 * @param dataxWriter
 * @throws IllegalAccessException
 */
public static void realExecuteDump(final String writerJson, IDataXPluginMeta dataxWriter, Function<Configuration, Configuration>... cfgSetter) throws IllegalAccessException {
    final JarLoader uberClassLoader = new JarLoader(new String[] { "." });
    DataxExecutor.initializeClassLoader(Sets.newHashSet("plugin.reader.streamreader", "plugin.writer." + dataxWriter.getDataxMeta().getName()), uberClassLoader);
    // Map<String, JarLoader> jarLoaderCenter = (Map<String, JarLoader>) jarLoaderCenterField.get(null);
    // jarLoaderCenter.clear();
    // 
    // 
    // jarLoaderCenter.put("plugin.reader.streamreader", uberClassLoader);
    // jarLoaderCenter.put("plugin.writer." + dataxWriter.getDataxMeta().getName(), uberClassLoader);
    Configuration allConf = // 
    IOUtils.loadResourceFromClasspath(// 
    MockDataxReaderContext.class, "container.json", true, (input) -> {
        Configuration cfg = Configuration.from(input);
        // "streamreader": {
        // "class": "com.alibaba.datax.plugin.reader.streamreader.StreamReader"
        // }
        cfg.set("plugin.reader.streamreader.class", "com.alibaba.datax.plugin.reader.streamreader.StreamReader");
        cfg.set("plugin.writer." + dataxWriter.getDataxMeta().getName() + ".class", dataxWriter.getDataxMeta().getImplClass());
        // 
        cfg.set(// 
        "job.content[0].writer", IOUtils.loadResourceFromClasspath(dataxWriter.getClass(), writerJson, true, (writerJsonInput) -> {
            Configuration c = Configuration.from(writerJsonInput);
            for (Function<Configuration, Configuration> setter : cfgSetter) {
                c = setter.apply(c);
            }
            return c;
        }));
        return cfg;
    });
    // 绑定column转换信息
    ColumnCast.bind(allConf);
    LoadUtil.bind(allConf);
    JobContainer container = new JobContainer(allConf);
    container.start();
}
Also used : ColumnCast(com.alibaba.datax.common.element.ColumnCast) BasicTest(com.qlangtech.tis.plugin.test.BasicTest) MockDataxReaderContext(com.qlangtech.tis.plugin.datax.MockDataxReaderContext) DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) EasyMock(org.easymock.EasyMock) JarLoader(com.alibaba.datax.core.util.container.JarLoader) Function(java.util.function.Function) LoadUtil(com.alibaba.datax.core.util.container.LoadUtil) Sets(com.google.common.collect.Sets) Configuration(com.alibaba.datax.common.util.Configuration) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) com.qlangtech.tis.datax(com.qlangtech.tis.datax) DataXReaderColType(com.qlangtech.tis.plugin.ds.DataXReaderColType) List(java.util.List) JSON(com.alibaba.fastjson.JSON) Lists(com.google.common.collect.Lists) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) Optional(java.util.Optional) JSONObject(com.alibaba.fastjson.JSONObject) Assert(org.junit.Assert) JobContainer(com.alibaba.datax.core.job.JobContainer) DataXCfgGenerator(com.qlangtech.tis.datax.impl.DataXCfgGenerator) JobContainer(com.alibaba.datax.core.job.JobContainer) Function(java.util.function.Function) JarLoader(com.alibaba.datax.core.util.container.JarLoader) Configuration(com.alibaba.datax.common.util.Configuration)

Example 3 with DataxWriter

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

the class DataxExecutor method startWork.

/**
 * 开始执行数据同步任务
 *
 * @param dataxName
 * @throws IOException
 * @throws Exception
 */
public void startWork(String dataxName, Integer jobId, String jobName, String execTimeStamp, IDataxProcessor dataxProcessor, final JarLoader uberClassLoader) throws IOException, Exception {
    try {
        Objects.requireNonNull(dataxProcessor, "dataxProcessor can not be null");
        KeyedPluginStore<DataxReader> readerStore = DataxReader.getPluginStore(null, dataxName);
        KeyedPluginStore<DataxWriter> writerStore = DataxWriter.getPluginStore(null, dataxName);
        File jobPath = new File(dataxProcessor.getDataxCfgDir(null), jobName);
        ;
        DataxReader reader = readerStore.getPlugin();
        Objects.requireNonNull(reader, "dataxName:" + dataxName + " relevant reader can not be null");
        DataxWriter writer = writerStore.getPlugin();
        Objects.requireNonNull(writer, "dataxName:" + dataxName + " relevant writer can not be null");
        this.readerMeta = reader.getDataxMeta();
        this.writerMeta = writer.getDataxMeta();
        Objects.requireNonNull(readerMeta, "readerMeta can not be null");
        Objects.requireNonNull(writerMeta, "writerMeta can not be null");
        initializeClassLoader(Sets.newHashSet(this.getPluginReaderKey(), this.getPluginWriterKey()), uberClassLoader);
        entry(new DataXJobArgs(jobPath, jobId, "standalone", execTimeStamp), jobName);
    } catch (Throwable e) {
        throw new Exception(e);
    } finally {
        cleanPerfTrace();
    }
}
Also used : DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) File(java.io.File) DataXException(com.alibaba.datax.common.exception.DataXException) IOException(java.io.IOException)

Example 4 with DataxWriter

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

the class CoreAction method doGetDataXReaderWriterDesc.

private static IndexIncrStatus doGetDataXReaderWriterDesc(String appName) throws Exception {
    IndexIncrStatus incrStatus = new IndexIncrStatus();
    DataxProcessor dataxProcessor = DataxProcessor.load(null, appName);
    DataxWriter writer = (DataxWriter) dataxProcessor.getWriter(null);
    incrStatus.setWriterDesc(createDescVals(writer.getDescriptor()));
    DataxReader reader = (DataxReader) dataxProcessor.getReader(null);
    incrStatus.setReaderDesc(createDescVals(reader.getDescriptor()));
    return incrStatus;
}
Also used : DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) DataxReader(com.qlangtech.tis.datax.impl.DataxReader)

Aggregations

DataxWriter (com.qlangtech.tis.datax.impl.DataxWriter)4 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)2 ColumnCast (com.alibaba.datax.common.element.ColumnCast)1 DataXException (com.alibaba.datax.common.exception.DataXException)1 Configuration (com.alibaba.datax.common.util.Configuration)1 JobContainer (com.alibaba.datax.core.job.JobContainer)1 JarLoader (com.alibaba.datax.core.util.container.JarLoader)1 LoadUtil (com.alibaba.datax.core.util.container.LoadUtil)1 JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 com.qlangtech.tis.datax (com.qlangtech.tis.datax)1 DataXCfgGenerator (com.qlangtech.tis.datax.impl.DataXCfgGenerator)1 DataxProcessor (com.qlangtech.tis.datax.impl.DataxProcessor)1 PluginFormProperties (com.qlangtech.tis.extension.PluginFormProperties)1 IOUtils (com.qlangtech.tis.extension.impl.IOUtils)1 RootFormProperties (com.qlangtech.tis.extension.impl.RootFormProperties)1 MockDataxReaderContext (com.qlangtech.tis.plugin.datax.MockDataxReaderContext)1 DataXReaderColType (com.qlangtech.tis.plugin.ds.DataXReaderColType)1