Search in sources :

Example 21 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class LoadUtil method loadPluginClass.

/**
     * 反射出具体plugin实例
     *
     * @param pluginType
     * @param pluginName
     * @param pluginRunType
     * @return
     */
@SuppressWarnings("unchecked")
private static synchronized Class<? extends AbstractPlugin> loadPluginClass(PluginType pluginType, String pluginName, ContainerType pluginRunType) {
    Configuration pluginConf = getPluginConf(pluginType, pluginName);
    JarLoader jarLoader = LoadUtil.getJarLoader(pluginType, pluginName);
    try {
        return (Class<? extends AbstractPlugin>) jarLoader.loadClass(pluginConf.getString("class") + "$" + pluginRunType.value());
    } catch (Exception e) {
        throw DataXException.asDataXException(FrameworkErrorCode.RUNTIME_ERROR, e);
    }
}
Also used : Configuration(com.alibaba.datax.common.util.Configuration) AbstractPlugin(com.alibaba.datax.common.plugin.AbstractPlugin) DataXException(com.alibaba.datax.common.exception.DataXException)

Example 22 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class JobAssignUtilTest method test_02.

@Test
public void test_02() {
    String jobString = "{\"job\":{\"setting\":{},\"content\":[{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}},{\"reader\":{\"type\":\"fakereader\",\"parameter\":{}},\"writer\":{\"type\":\"fakewriter\",\"parameter\":{}}}]}}";
    Configuration configuration = Configuration.from(jobString);
    int taskNumber = StringUtils.countMatches(jobString, "fakereader");
    System.out.println("taskNumber:" + taskNumber);
    for (int i = 0; i < taskNumber; i++) {
        configuration.set("job.content[" + i + "].taskId", i);
    }
    //        System.out.println(configuration.beautify());
    int channelNumber = 13;
    int channelsPerTaskGroup = 5;
    List<Configuration> result = JobAssignUtil.assignFairly(configuration, channelNumber, channelsPerTaskGroup);
    System.out.println("===================================");
    for (Configuration conf : result) {
        System.out.println(conf.beautify());
        System.out.println("----------------");
    }
//        System.out.println(configuration);
}
Also used : Configuration(com.alibaba.datax.common.util.Configuration) Test(org.junit.Test)

Example 23 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class JobAssignUtilTest method test_01.

@Test
public void test_01() {
    Configuration configuration = Configuration.from(new File(JobAssignUtil.class.getResource("/job/job.json").getFile()));
    configuration.set("job.content[0].taskId", 0);
    configuration.set("job.content[1].taskId", 1);
    System.out.println(configuration.beautify());
    int channelNumber = 3;
    int channelsPerTaskGroup = 1;
    List<Configuration> result = JobAssignUtil.assignFairly(configuration, channelNumber, channelsPerTaskGroup);
    System.out.println("===================================");
    for (Configuration conf : result) {
        System.out.println(conf.beautify());
        System.out.println("----------------");
    }
    System.out.println(configuration);
}
Also used : Configuration(com.alibaba.datax.common.util.Configuration) JobAssignUtil(com.alibaba.datax.core.container.util.JobAssignUtil) File(java.io.File) Test(org.junit.Test)

Example 24 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class JobContainerTest method testPreHandlerByReader.

@Test
public void testPreHandlerByReader() throws Exception {
    Configuration copyConfig = this.configuration.clone();
    copyConfig.set(CoreConstant.DATAX_JOB_PREHANDLER_PLUGINTYPE, "reader");
    copyConfig.set(CoreConstant.DATAX_JOB_PREHANDLER_PLUGINNAME, "fakereader");
    JobContainer jobContainer = new JobContainer(copyConfig);
    Method initMethod = jobContainer.getClass().getDeclaredMethod("preHandle");
    initMethod.setAccessible(true);
    initMethod.invoke(jobContainer, new Object[] {});
    System.out.println(copyConfig.get("job.preHandler.test"));
    Assert.assertEquals("readPreDone", copyConfig.get("job.preHandler.test"));
}
Also used : JobContainer(com.alibaba.datax.core.job.JobContainer) Configuration(com.alibaba.datax.common.util.Configuration) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 25 with Configuration

use of com.alibaba.datax.common.util.Configuration in project DataX by alibaba.

the class JobContainerTest method testMergeReaderAndWriterSlicesConfigsException.

@Test(expected = Exception.class)
public void testMergeReaderAndWriterSlicesConfigsException() throws Exception {
    JobContainer jobContainer = new JobContainer(this.configuration);
    Method initMethod = jobContainer.getClass().getDeclaredMethod("init");
    initMethod.setAccessible(true);
    initMethod.invoke(jobContainer, new Object[] {});
    initMethod.setAccessible(false);
    int readerSplitNumber = 100;
    int writerSplitNumber = readerSplitNumber + 1;
    List<Configuration> readerSplitConfigurations = new ArrayList<Configuration>();
    List<Configuration> writerSplitConfigurations = new ArrayList<Configuration>();
    for (int i = 0; i < readerSplitNumber; i++) {
        Configuration readerOneConfig = Configuration.newDefault();
        readerSplitConfigurations.add(readerOneConfig);
    }
    for (int i = 0; i < writerSplitNumber; i++) {
        Configuration readerOneConfig = Configuration.newDefault();
        writerSplitConfigurations.add(readerOneConfig);
    }
    initMethod = jobContainer.getClass().getDeclaredMethod("mergeReaderAndWriterSlicesConfigs", List.class, List.class);
    initMethod.setAccessible(true);
    initMethod.invoke(jobContainer, readerSplitConfigurations, writerSplitConfigurations);
}
Also used : JobContainer(com.alibaba.datax.core.job.JobContainer) Configuration(com.alibaba.datax.common.util.Configuration) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

Configuration (com.alibaba.datax.common.util.Configuration)82 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)19 Communication (com.alibaba.datax.core.statistics.communication.Communication)13 DataXException (com.alibaba.datax.common.exception.DataXException)9 Method (java.lang.reflect.Method)8 Record (com.alibaba.datax.common.element.Record)7 JobContainer (com.alibaba.datax.core.job.JobContainer)6 IOException (java.io.IOException)5 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)5 LongColumn (com.alibaba.datax.common.element.LongColumn)4 TaskPluginCollector (com.alibaba.datax.common.plugin.TaskPluginCollector)4 TaskGroupContainer (com.alibaba.datax.core.taskgroup.TaskGroupContainer)4 Channel (com.alibaba.datax.core.transport.channel.Channel)4 MemoryChannel (com.alibaba.datax.core.transport.channel.memory.MemoryChannel)4 DefaultRecord (com.alibaba.datax.core.transport.record.DefaultRecord)4 File (java.io.File)4 HashSet (java.util.HashSet)3 List (java.util.List)3 VMInfo (com.alibaba.datax.common.statistics.VMInfo)2