I tend to work with ODI quite a bit. Recently, I came across a scenario where the standalone agent on one of our boxes was turning itself off once in a while. While the issue was fixed, it did provide the impetus for this post. Today, we’ll take a look at the ODI (11g) standalone agent, and, at a simple start script to (re)start it. If we open up the physical agent from ODI Studio, we can see that it has the following components.
The host name, is the server on which the agent is installed. The agent install is tied to a port (usually, 20910). The protocol used, is “http”, in this case. The application context is set to “oraclediagent” for standalone agents. BTW, Oracle provides an example tutorial on setting up the 11g agent.
If we put those pieces together, we have the components to put together a URL. For instance, if we open up a browser and put those elements in, we get the following results, if everything is working normally:
If we now turn the agent service off, we can see:
We can use this information to our advantage when starting the ODI agent. The thing to understand, is that when resolving URLs, a return code of “200” is considered to be successful (see statuses). We can ascertain this for the ODI agent URL, on Firefox, by right clicking and selecting Inspect Element.
Knowing this, we can set up a simple script to check whether the service is available, and turn it on, if needed. I will be using Groovy code (for earlier examples on the Groovy Console, check this link) in this example. The first line sets up the agentURL, and the second line, preps a DOS command (we are using “sc” as the agent is on a Windows box) which can be used to start the agent.
1 2 3 4 |
// The ODI server URL + port number, converted to a "URL". urlInfo = "http://unlk.net:20910/oraclediagent".toURL() // Simple DOS start command command = "C:\\Windows\\SysWOW64\\sc.exe \\\\unlk.net start oracle.odi.Agent" |
Note that you need to escape the “\”. Also, the location of the “sc” executable maybe different on your machine. Lastly, the service name on my box, is “oracle.odi.agent”.
We can now set up a simple “try/catch” statement to open the http connection and check for the response code. This is done in the “try” section below.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
try { connection = urlInfo.openConnection() println "Connection code is ${connection.responseCode}. All Good" // We need 200 as the response. connection.disconnect() } catch (ConnectException ex) { // Connection exception detected Process process = command.execute() // Execute the start command def out = new StringBuffer() def err = new StringBuffer() process.consumeProcessOutput(out,err) // Log the output/error process.waitFor() println out println err } |
The “catch exception” section above checks for http connection issues. It then proceeds to run the “sc start” command. It also writes out the responses to the console. Let’s look at this code in action. In the screenshot below, the agent is up and functional.
In the screenshot below, the agent service is down, and is being restarted by the script.
You can then add a “sleep” if you wish to check if the agent is up again if you wish. The code in its entirety:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// The ODI server URL + port number, converted to a "URL". urlInfo = "http://unlk.net:20910/oraclediagent".toURL() // Simple DOS start command command = "C:\\Windows\\SysWOW64\\sc.exe \\\\unlk.net start oracle.odi.Agent" //Check the connection. try { connection = urlInfo.openConnection() println "Connection code is ${connection.responseCode}. All Good" // We need 200 as the response. connection.disconnect() } catch (ConnectException ex) { // Connection exception detected Process process = command.execute() // Execute the start command def out = new StringBuffer() def err = new StringBuffer() process.consumeProcessOutput(out,err) // Log the output/error process.waitFor() println out println err } // Commented out, use if needed. // sleep(30000) // connection = urlInfo.openConnection() // println "Connection code is ${connection.responseCode}. All Good" // connection.disconnect() |
Obviously, there are different ways to do this type of thing. You can write this sort of code with any programming platform. You can also check status of the agent directly as well. I thought it would be a different way to understand how the ODI agent works before exploring some of the posts coming soon, which address other aspects of ODI.
Hey Mr Vijay,
What ended up being the problem with the agent?
Pedro
Is there any way to test connection of any data server ? I seen one function testDataServer but not able to use that. Could you please assist here.
Hi,
When you do have an agent fail, is there a way to get an email notification? I know I can build a package to ping the agent and then send mail if it fails but I’d need to add that to a load plan. My issue is I want an email notification that sends automatically if the agent fails to run, before it even gets to the load plan.
Dane
Hi,
you can try adding a procedure to the groovy code, which sends email.
Vj
Hi,
Does anyone know what the script for a cron job that notifies me of a nightly ODI agent run fail would look like? I want to schedule a notification if the agent for our nightly run does not work but I’m not sure how to set it up.
Thanks,
Dane