我正在尝试练习 oozie 工作流程。我的做法是从 ftp 获取文件并将其上传到 cloudera - HDFS。
以下是我的java代码:
public class UploadHDFS extends Configured implements Tool {
private static final Logger LOGGER = LoggerFactory.getLogger(UploadHDFS.class);
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new UploadHDFS(), args);
System.exit(res);
}
@Override
public int run(String[] strings) throws Exception {
FTPClient client = new FTPClient();
InputStream ins = null;
try {
Configuration conf = getConf();
System.out.println("------------%%+++++++++++++++++++---------------");
for (Map.Entry<String, String> entry : conf) {
System.out.printf("%s=%s\n", entry.getKey(), entry.getValue());
}
System.out.println("------------%%++++++++++++-----------");
String host = conf.get("ftp.host.address").toString();
String port = conf.get("ftp.port").toString();
....
....
return 0;
}
}
另外,我已经配置了 workflow.xml。见下文:
<workflow-app name="XXXXXX_test" xmlns="uri:oozie:workflow:0.4">
<start to="ftp_download_file"/>
<action name="ftp_download_file">
<java>
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<prepare>
<delete path="${nameNode}/user/admin/XXXXXX_test/B"/>
</prepare>
<configuration>
<property>
<name>ftp.host.address</name>
<value>192.168.1.158</value>
</property>
<property>
<name>ftp.port</name>
<value>21</value>
</property>
</configuration>
<main-class>UploadHDFS</main-class>
<file>workflow.xml#workflow.xml</file>
</java>
<ok to="merger_file"/>
<error to="kill"/>
</action>
</workflow-app>
但是,我不确定为什么无法从 workflow.xml 中获取属性。该系统为行弹出 NullPointerException:
String host = conf.get("ftp.host.address").toString(); 字符串端口 = conf.get("ftp.port").toString();
你能给我一些想法吗?
谢谢!!