use of com.alibaba.datax.transformer.Transformer 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);
}
}
use of com.alibaba.datax.transformer.Transformer in project DataX by alibaba.
the class GroovyTransformer method initGroovyTransformer.
private void initGroovyTransformer(String code, List<String> extraPackage) {
GroovyClassLoader loader = new GroovyClassLoader(GroovyTransformer.class.getClassLoader());
String groovyRule = getGroovyRule(code, extraPackage);
Class groovyClass;
try {
groovyClass = loader.parseClass(groovyRule);
} catch (CompilationFailedException cfe) {
throw DataXException.asDataXException(TransformerErrorCode.TRANSFORMER_GROOVY_INIT_EXCEPTION, cfe);
}
try {
Object t = groovyClass.newInstance();
if (!(t instanceof Transformer)) {
throw DataXException.asDataXException(TransformerErrorCode.TRANSFORMER_GROOVY_INIT_EXCEPTION, "datax bug! contact askdatax");
}
this.groovyTransformer = (Transformer) t;
} catch (Throwable ex) {
throw DataXException.asDataXException(TransformerErrorCode.TRANSFORMER_GROOVY_INIT_EXCEPTION, ex);
}
}
Aggregations