Question

I am trying to practise an oozie workflow. My practice is to get a file from ftp and upload it to cloudera - HDFS.

The following is my java code:

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;  
    }
}

Also, I have config the workflow.xml. See below:

<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>

However, I am not sure why I cannot get the properties from the workflow.xml. That system pops up NullPointerException for the rows:

String host = conf.get("ftp.host.address").toString(); String port = conf.get("ftp.port").toString();

Could you please give me some ideas?

Thanks!!

Was it helpful?

Solution

Oozie configuration location passed by system variable "oozie.action.conf.xml", please use such code as Java Action example:

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 
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top