How to get ApplicationID from inside Apache Apex application?

Tags: apache-apex
Question!

Is it possible to retrieve the Apex application ID: e.g.application_1463594017097_0024 within the Apex program? For example from the DAG object or some other object?



Answers

Use the conf object passed to StreamingApplication

String appid = dag.getValue(DAGContext.APPLICATION_ID);

In an operator, use

String appid = Context.OperatorContext.getValue(Context.DAGContext. APPLICATION_ID);

Note: It can't be run within populateDAG function. APPLICATION_ID is assigned to an application once it is launched. In populateDag() phase, the logical plan is being created but the actual YARN application is not created. There isn't an APPLICATION_ID created yet which is why it is null.



This video can help you solving your question :)
By: admin