Search in sources :

Example 1 with ComplexTransformer

use of com.alibaba.datax.transformer.ComplexTransformer in project DataX by alibaba.

the class TransformerRegistry method loadTransformer.

public static void loadTransformer(String each) {
    String transformerPath = CoreConstant.DATAX_STORAGE_TRANSFORMER_HOME + File.separator + each;
    Configuration transformerConfiguration;
    try {
        transformerConfiguration = loadTransFormerConfig(transformerPath);
    } catch (Exception e) {
        LOG.error(String.format("skip transformer(%s),load transformer.json error, path = %s, ", each, transformerPath), e);
        return;
    }
    String className = transformerConfiguration.getString("class");
    if (StringUtils.isEmpty(className)) {
        LOG.error(String.format("skip transformer(%s),class not config, path = %s, config = %s", each, transformerPath, transformerConfiguration.beautify()));
        return;
    }
    String funName = transformerConfiguration.getString("name");
    if (!each.equals(funName)) {
        LOG.warn(String.format("transformer(%s) name not match transformer.json config name[%s], will ignore json's name, path = %s, config = %s", each, funName, transformerPath, transformerConfiguration.beautify()));
    }
    JarLoader jarLoader = new JarLoader(new String[] { transformerPath });
    try {
        Class<?> transformerClass = jarLoader.loadClass(className);
        Object transformer = transformerClass.newInstance();
        if (ComplexTransformer.class.isAssignableFrom(transformer.getClass())) {
            ((ComplexTransformer) transformer).setTransformerName(each);
            registComplexTransformer((ComplexTransformer) transformer, jarLoader, false);
        } else if (Transformer.class.isAssignableFrom(transformer.getClass())) {
            ((Transformer) transformer).setTransformerName(each);
            registTransformer((Transformer) transformer, jarLoader, false);
        } else {
            LOG.error(String.format("load Transformer class(%s) error, path = %s", className, transformerPath));
        }
    } catch (Exception e) {
        //错误funciton跳过
        LOG.error(String.format("skip transformer(%s),load Transformer class error, path = %s ", each, transformerPath), e);
    }
}
Also used : ComplexTransformer(com.alibaba.datax.transformer.ComplexTransformer) Transformer(com.alibaba.datax.transformer.Transformer) Configuration(com.alibaba.datax.common.util.Configuration) JarLoader(com.alibaba.datax.core.util.container.JarLoader) ComplexTransformer(com.alibaba.datax.transformer.ComplexTransformer) DataXException(com.alibaba.datax.common.exception.DataXException)

Aggregations

DataXException (com.alibaba.datax.common.exception.DataXException)1 Configuration (com.alibaba.datax.common.util.Configuration)1 JarLoader (com.alibaba.datax.core.util.container.JarLoader)1 ComplexTransformer (com.alibaba.datax.transformer.ComplexTransformer)1 Transformer (com.alibaba.datax.transformer.Transformer)1