passing environment variables to flink program

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

passing environment variables to flink program

Jian Jiang
I am doing a Flink evaluation against Spark. My program is a JNI application and requires LD_LIBRARY_PATH to be set among other needed variables. In Spark I can do that multiple ways. One way is to use --conf 'spark.executorEnv.XXX=blah'. It works great.

How do I do that in Flink?

thanks
jackie
Reply | Threaded
Open this post in threaded view
|

Re: passing environment variables to flink program

Stephan Ewen
Hi!

What kind of setup are you using, YARN or standalone?

In both modes, you should be able to pass your flags via the config entry "env.java.opts" in the flink-conf.yaml file. See here https://ci.apache.org/projects/flink/flink-docs-master/setup/config.html#other

We have never passed library paths to link external JNI libraries with that, so let usknow if that works...

Greetings,
Stephan


On Mon, Nov 2, 2015 at 10:12 AM, youarehow <[hidden email]> wrote:
I am doing a Flink evaluation against Spark. My program is a JNI application
and requires LD_LIBRARY_PATH to be set among other needed variables. In
Spark I can do that multiple ways. One way is to use --conf
'spark.executorEnv.XXX=blah'. It works great.

How do I do that in Flink?

thanks
jackie



--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/passing-environment-variables-to-flink-program-tp3337.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: passing environment variables to flink program

Jian Jiang
This has less to do with JNI but much to do how to pass custom environment variables.

We are using YARN and the data is in HDFS. I have run the JNI program in local mode within Eclipse with no problem since I can set up the environment variables easily by using run configurations. Just I don't know how to do it when running inside YARN.

The JNI program relies on LD_LIBRARY_PATH since the native side dynamically load other libraries (all copied on each node).

public final class NativeProcessor{
       
        static
        {
                System.loadLibrary("nativeprocessor");//environment variables must have been set before this!!
        }
...
}

For example, when loading libnativeprocessor.so, the so may use LD_LIBRARY_PATH or other custom environment variables to initialize, say, some static native variables.

The env.java.opts can be used by java but not native libraries - especially in the above case it is used in a classloading static block so the variables need to be ready before loading native library. In hadoop mapreduce job we can use -Dmapreduce.map.env and -Dmapreduce.reduce.env to do this. In Spark we can use --conf 'spark.executor.XXX=blah'. I just can not find an equivalent in Flink yet.

thanks
jackie



 
Reply | Threaded
Open this post in threaded view
|

Re: passing environment variables to flink program

Stephan Ewen
Ah, okay, I confused the issue.

The environment variables would need to be defined or exported in the environment that spawns TaskManager processes. I think there is nothing for that in Flink yet, but it should not be hard to add that.

Can you open an issue for that in JIRA?

Thanks,
Stephan


On Mon, Nov 2, 2015 at 1:03 PM, Jian Jiang <[hidden email]> wrote:
This has less to do with JNI but much to do how to pass custom environment
variables.

We are using YARN and the data is in HDFS. I have run the JNI program in
local mode within Eclipse with no problem since I can set up the environment
variables easily by using run configurations. Just I don't know how to do it
when running inside YARN.

The JNI program relies on LD_LIBRARY_PATH since the native side dynamically
load other libraries (all copied on each node).

public final class NativeProcessor{

        static
        {
                System.loadLibrary("nativeprocessor");//environment variables must have
been set before this!!
        }
...
}

For example, when loading libnativeprocessor.so, the so may use
LD_LIBRARY_PATH or other custom environment variables to initialize, say,
some static native variables.

The env.java.opts can be used by java but not native libraries - especially
in the above case it is used in a classloading static block so the variables
need to be ready before loading native library. In hadoop mapreduce job we
can use -Dmapreduce.map.env and -Dmapreduce.reduce.env to do this. In Spark
we can use --conf 'spark.executor.XXX=blah'. I just can not find an
equivalent in Flink yet.

thanks
jackie







--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/passing-environment-variables-to-flink-program-tp3337p3340.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

RE: [IE] Re: passing environment variables to flink program

Jian Jiang

1.    Sure. I have created FLINK-2954.

 

Thanks

jackie

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Stephan Ewen
Sent: Monday, November 02, 2015 4:35 PM
To: [hidden email]
Subject: [IE] Re: passing environment variables to flink program

 

Ah, okay, I confused the issue.

 

The environment variables would need to be defined or exported in the environment that spawns TaskManager processes. I think there is nothing for that in Flink yet, but it should not be hard to add that.

 

Can you open an issue for that in JIRA?

 

Thanks,

Stephan

 

 

On Mon, Nov 2, 2015 at 1:03 PM, Jian Jiang <[hidden email]> wrote:

This has less to do with JNI but much to do how to pass custom environment
variables.

We are using YARN and the data is in HDFS. I have run the JNI program in
local mode within Eclipse with no problem since I can set up the environment
variables easily by using run configurations. Just I don't know how to do it
when running inside YARN.

The JNI program relies on LD_LIBRARY_PATH since the native side dynamically
load other libraries (all copied on each node).

public final class NativeProcessor{

        static
        {
                System.loadLibrary("nativeprocessor");//environment variables must have
been set before this!!
        }
...
}

For example, when loading libnativeprocessor.so, the so may use
LD_LIBRARY_PATH or other custom environment variables to initialize, say,
some static native variables.

The env.java.opts can be used by java but not native libraries - especially
in the above case it is used in a classloading static block so the variables
need to be ready before loading native library. In hadoop mapreduce job we
can use -Dmapreduce.map.env and -Dmapreduce.reduce.env to do this. In Spark
we can use --conf 'spark.executor.XXX=blah'. I just can not find an
equivalent in Flink yet.

thanks
jackie







--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/passing-environment-variables-to-flink-program-tp3337p3340.html

Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

 

This message contains proprietary information from Equifax which may be confidential. If you are not an intended recipient, please refrain from any disclosure, copying, distribution or use of this information and note that such actions are prohibited. If you have received this transmission in error, please notify by e-mail [hidden email]. Equifax® is a registered trademark of Equifax Inc. All rights reserved.
Reply | Threaded
Open this post in threaded view
|

Re: [IE] Re: passing environment variables to flink program

Stephan Ewen
Thanks!

Let's see if we can get that feature added soon...

On Mon, Nov 2, 2015 at 3:02 PM, Jian Jiang <[hidden email]> wrote:

1.    Sure. I have created FLINK-2954.

 

Thanks

jackie

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Stephan Ewen
Sent: Monday, November 02, 2015 4:35 PM
To: [hidden email]
Subject: [IE] Re: passing environment variables to flink program

 

Ah, okay, I confused the issue.

 

The environment variables would need to be defined or exported in the environment that spawns TaskManager processes. I think there is nothing for that in Flink yet, but it should not be hard to add that.

 

Can you open an issue for that in JIRA?

 

Thanks,

Stephan

 

 

On Mon, Nov 2, 2015 at 1:03 PM, Jian Jiang <[hidden email]> wrote:

This has less to do with JNI but much to do how to pass custom environment
variables.

We are using YARN and the data is in HDFS. I have run the JNI program in
local mode within Eclipse with no problem since I can set up the environment
variables easily by using run configurations. Just I don't know how to do it
when running inside YARN.

The JNI program relies on LD_LIBRARY_PATH since the native side dynamically
load other libraries (all copied on each node).

public final class NativeProcessor{

        static
        {
                System.loadLibrary("nativeprocessor");//environment variables must have
been set before this!!
        }
...
}

For example, when loading libnativeprocessor.so, the so may use
LD_LIBRARY_PATH or other custom environment variables to initialize, say,
some static native variables.

The env.java.opts can be used by java but not native libraries - especially
in the above case it is used in a classloading static block so the variables
need to be ready before loading native library. In hadoop mapreduce job we
can use -Dmapreduce.map.env and -Dmapreduce.reduce.env to do this. In Spark
we can use --conf 'spark.executor.XXX=blah'. I just can not find an
equivalent in Flink yet.

thanks
jackie







--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/passing-environment-variables-to-flink-program-tp3337p3340.html

Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

 

This message contains proprietary information from Equifax which may be confidential. If you are not an intended recipient, please refrain from any disclosure, copying, distribution or use of this information and note that such actions are prohibited. If you have received this transmission in error, please notify by e-mail [hidden email]. Equifax® is a registered trademark of Equifax Inc. All rights reserved.

Reply | Threaded
Open this post in threaded view
|

Re: [IE] Re: passing environment variables to flink program

Jian Jiang
I have to continue the evaluation so I managed to patch a fix to my local build. In case someone cannot wait here is what I did:

1. In the flink-core's ConfigConstants.java add

public static final String FLINK_JVM_OPTIONS = "env.java.opts"; <-- existing
public static final String FLINK_CUSTOM_ENV_VARS = "env.custom.env.vars";

2. In the flink-conf.yaml now you can add environment variables separated by "|":

env.custom.env.vars: name1=value1|name2=value2|name3=value3 ....

3. In the flink-yarn's YarnJobManager.scala's createContainerLaunchContext() method add the following between the two existing lines:

    Utils.setupEnv(yarnConf, containerEnv) <-- existing
   
    val customEnvOpts = flinkConfiguration.getString(ConfigConstants.FLINK_CUSTOM_ENV_VARS, "")
   
if(customEnvOpts!=null)
{
val variables = customEnvOpts.split("\\|");
if(variables!=null&&variables.length>0)
{
for(variable <- variables)
{
val pair = variable.split("=");
containerEnv.put(pair(0), pair(1));
}
}
}
    containerEnv.put(FlinkYarnClientBase.ENV_CLIENT_USERNAME, yarnClientUsername) <-- existing

Now the container running my program sees the env variables.

Note this is temp work around for local personally and should be discarded once Flink 1.0 comes out.
Reply | Threaded
Open this post in threaded view
|

Re: [IE] Re: passing environment variables to flink program

rmetzger0
Just a little note, the feature requested in FLINK-2954 has been implemented and is available in 1.0-SNAPSHOT now.

Please let me know if its working as expected.

On Wed, Nov 4, 2015 at 6:35 PM, Jian Jiang <[hidden email]> wrote:
I have to continue the evaluation so I managed to patch a fix to my local
build. In case someone cannot wait here is what I did:

1. In the flink-core's ConfigConstants.java add

public static final String FLINK_JVM_OPTIONS = "env.java.opts"; <-- existing
public static final String FLINK_CUSTOM_ENV_VARS = "env.custom.env.vars";

2. In the flink-conf.yaml now you can add environment variables separated by
"|":

env.custom.env.vars: name1=value1|name2=value2|name3=value3 ....

3. In the flink-yarn's YarnJobManager.scala's createContainerLaunchContext()
method add the following between the two existing lines:

    Utils.setupEnv(yarnConf, containerEnv) <-- existing

    val customEnvOpts =
flinkConfiguration.getString(ConfigConstants.FLINK_CUSTOM_ENV_VARS, "")

if(customEnvOpts!=null)
{
val variables = customEnvOpts.split("\\|");
if(variables!=null&&variables.length>0)
{
for(variable <- variables)
{
val pair = variable.split("=");
containerEnv.put(pair(0), pair(1));
}
}
}
    containerEnv.put(FlinkYarnClientBase.ENV_CLIENT_USERNAME,
yarnClientUsername) <-- existing

Now the container running my program sees the env variables.

Note this is temp work around for local personally and should be discarded
once Flink 1.0 comes out.




--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/passing-environment-variables-to-flink-program-tp3337p3367.html
Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

RE: [IE] Re: [IE] Re: passing environment variables to flink program

Jian Jiang

Thanks Robert –

 

I will update you when get time.

 

jackie

From: rmetzger0 [via Apache Flink User Mailing List archive.] [mailto:ml-node+[hidden email]]
Sent: Saturday, December 05, 2015 9:12 AM
To: Jian Jiang
Subject: [IE] Re: [IE] Re: passing environment variables to flink program

 

Just a little note, the feature requested in FLINK-2954 has been implemented and is available in 1.0-SNAPSHOT now.

 

Please let me know if its working as expected.

 

On Wed, Nov 4, 2015 at 6:35 PM, Jian Jiang <[hidden email]> wrote:

I have to continue the evaluation so I managed to patch a fix to my local
build. In case someone cannot wait here is what I did:

1. In the flink-core's ConfigConstants.java add

public static final String FLINK_JVM_OPTIONS = "env.java.opts"; <-- existing
public static final String FLINK_CUSTOM_ENV_VARS = "env.custom.env.vars";

2. In the flink-conf.yaml now you can add environment variables separated by
"|":

env.custom.env.vars: name1=value1|name2=value2|name3=value3 ....

3. In the flink-yarn's YarnJobManager.scala's createContainerLaunchContext()
method add the following between the two existing lines:

    Utils.setupEnv(yarnConf, containerEnv) <-- existing

    val customEnvOpts =
flinkConfiguration.getString(ConfigConstants.FLINK_CUSTOM_ENV_VARS, "")

if(customEnvOpts!=null)
{
val variables = customEnvOpts.split("\\|");
if(variables!=null&&variables.length>0)
{
for(variable <- variables)
{
val pair = variable.split("=");
containerEnv.put(pair(0), pair(1));
}
}
}
    containerEnv.put(FlinkYarnClientBase.ENV_CLIENT_USERNAME,
yarnClientUsername) <-- existing

Now the container running my program sees the env variables.

Note this is temp work around for local personally and should be discarded
once Flink 1.0 comes out.




--
View this message in context: http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/passing-environment-variables-to-flink-program-tp3337p3367.html

Sent from the Apache Flink User Mailing List archive. mailing list archive at Nabble.com.

 

 


To unsubscribe from passing environment variables to flink program, click here.
NAML

This message contains proprietary information from Equifax which may be confidential. If you are not an intended recipient, please refrain from any disclosure, copying, distribution or use of this information and note that such actions are prohibited. If you have received this transmission in error, please notify by e-mail [hidden email]. Equifax® is a registered trademark of Equifax Inc. All rights reserved.