Four Stars

Access Context Environment in tjavarow

I have variables that I load into context variables from a MySql database. All works fine. However I now have different environments: development & production. I'm assigning my context variables in a tjavarow but I need to assign a path context variable different based on which environment. I'm not sure how to tell in the tjavarow component which environment is running.

 

My assignment is currently:

 

context.path = input_row.path;

 

But I need to do an if..then or similar if environment = "production" ....etc

 

Any guidance would be helpful.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Twelve Stars

Re: Access Context Environment in tjavarow

There is quite an elegant way of handling this and you are practically there. As you have done, forget the Contexts (ie the context variable environments...dev, test, prod, etc). Keep what you have but assign another parameter to your MySQL database table holding your contexts to identify the environment. Then, on each of your environment machines (assuming different machines for different environments) set an operating system environment variable. DEV for your dev environment, TEST for test, etc, etc. Then in your jobs use some code to grab that variable when the job runs and use it in your MySQL query when retrieving the context variables. 

 

I do this all the time. As an example, below is a method I use in a routine to grab a system environment variable.....

 

public static String getEnvironmentVariable(String variableName) {
		String returnVal = System.getenv(variableName);

		if (returnVal == null) {
			System.out.println(variableName
					+ " does not exist or holds no value");
		}
		return returnVal;
	}

 I've left a little bit for you to figure out, but from what you have said it looks like you are practically there.

 

Good luck!

Rilhia Solutions
1 REPLY
Twelve Stars

Re: Access Context Environment in tjavarow

There is quite an elegant way of handling this and you are practically there. As you have done, forget the Contexts (ie the context variable environments...dev, test, prod, etc). Keep what you have but assign another parameter to your MySQL database table holding your contexts to identify the environment. Then, on each of your environment machines (assuming different machines for different environments) set an operating system environment variable. DEV for your dev environment, TEST for test, etc, etc. Then in your jobs use some code to grab that variable when the job runs and use it in your MySQL query when retrieving the context variables. 

 

I do this all the time. As an example, below is a method I use in a routine to grab a system environment variable.....

 

public static String getEnvironmentVariable(String variableName) {
		String returnVal = System.getenv(variableName);

		if (returnVal == null) {
			System.out.println(variableName
					+ " does not exist or holds no value");
		}
		return returnVal;
	}

 I've left a little bit for you to figure out, but from what you have said it looks like you are practically there.

 

Good luck!

Rilhia Solutions