我正在尝试练习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(); String port = conf.get(“ftp.port”)。toString();
你能给我一些想法吗?
谢谢!
答案 0 :(得分:3)
系统变量“oozie.action.conf.xml”传递的Oozie配置位置,请使用Java Action示例代码:
public class UploadHDFS {
public static void main(String[] args) throws Exception {
new UploadHDFS().execute();
}
public void execute() {
String configurationLocation = System.getProperty("oozie.action.conf.xml");
Path localConfigurationPath = new Path(configurationLocation);
Configuration configuration = new Configuration();
configuration.addResource(localConfigurationPath);
// .. continue here
}
}