public static void main(String[] args) {
String configJson = "";
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("morphlines:[\n" +
" {\n" +
" id : dxytest\n" +
" importCommands : [\"org.kitesdk.**\", \"com.app.topklb.extra.etl.morphline.commands.**\"]\n" +
" commands : [ \n" +
" { readJson {} }\n" +
"\t{ forEach { \n" +
"\tarrays : \"objects\"\n" +
"\t} \n" +
"\t} \n" +
"\t{\n" +
" convertTime {\n" +
"\tfield : modified\n" +
"\tinputFormat : \"yyyy-MM-dd\"\n" +
"\tinputTimezone : Asia/Shanghai\n" +
"\tinputLocale : zh_CN\n" +
"\toutputFormat : \"yyyy-MM-dd HH:mm:ss\"\n" +
"\toutputTimezone : Asia/Shanghai\n" +
"\toutputLocale: zh_CN\n" +
" }\n" +
"}\n" +
"{ extractJsonPaths\n" +
" {\n" +
"\t paths: {\n" +
"\t\tINTELLIGENCE.CONFIDENCE : \"/objects[]/confidence\"\n" +
"\t\tDOMAIN : \"/objects[]/observables[]/value\"\n" +
"\t\tINTELLIGENCE.LAST_SEEN : \"/objects[]/modified\"\n" +
"\t\tINTELLIGENCE.MOD_TIME : \"/objects[]/modified\"\n" +
"\t\tINTELLIGENCE.FIRST_SEEN : \"/objects[]/modified\"\n" +
"\t\t}\n" +
" }\n" +
"}\n" +
"{json2domain {}}\n" +
"\t\n" +
"\t]\n" +
" }\n" +
"]");
configJson = stringBuilder.toString();
System.out.println("config--->" + configJson);
MorphlineContext morphlineContext = new MorphlineContext.Builder().build();
Config config = ConfigFactory.parseString(configJson);
Compiler compiler = new Compiler();
//这里morphlineId实际从jobmap中获取测试可以写死
Config morphlineConfig = compiler.find("dxytest", config, null);
Command morphing = compiler.compile(morphlineConfig, morphlineContext, null);
Notifications.notifyBeginTransaction(morphing);
Record record = new Record();
try {
InputStream in = new BufferedInputStream(new FileInputStream(new File("D:\\topsec\\work\\mytest1\\src\\main\\resources\\config\\morpline.json")));
record.put(Fields.ATTACHMENT_BODY, in);
Notifications.notifyStartSession(morphing);
morphing.process(record);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
Notifications.notifyShutdown(morphing);
System.out.println("----game over------>");
}