Submitted by Graham on Tue, 2006-04-25 16:37
java to get the name of the instance for a db on the local host
(uses shell script similar to the srvcheck solution)
import java.net.InetAddress;
import oracle.ops.mgmt.database.Instance;
import oracle.ops.mgmt.database.ParallelServerConfig;
import oracle.ops.mgmt.operation.GetConfigurationOperation;
import oracle.ops.mgmt.operation.GetConfigurationResult;
public class ClusterLocalInstance {
private static final String USAGE = "checks to see name of local instance for provided db name";
public static void main(String[] args) {
if (args.length > 1) {
System.err.println("too many arguments");
System.err.println(USAGE);
System.exit(1);
} else if (args.length == 0) {
System.err.println("no argument - provide a name to lookup!");
System.err.println(USAGE);
System.exit(1);
} else if (args.length == 1
&& (args[0].equals("-h") || args[0].equals("-?"))) {
System.err.println("'"+args[0]+"' : help");
System.out.println(USAGE);
System.exit(0);
} else if (args.length == 1
&& args[0].startsWith("-")) {
System.err.println("argument '"+args[0]+"' not understood");
System.err.println(USAGE);
System.exit(1);
}
String host = "";
try
{
InetAddress localMachine = InetAddress.getLocalHost();Â
host = localMachine.getHostName();
}
catch(java.net.UnknownHostException uhe)
{
System.err.println(uhe.toString());
System.exit(1);
}
GetConfigurationOperation gco = new GetConfigurationOperation(args[0]);
GetConfigurationResult gcor = (GetConfigurationResult)gco.run();
ParallelServerConfig result = gcor.getResult();
String [] instances = result.enumerateInstances();
for (int i = 0; i < instances.length; i++) {
Instance instance = result.getInstance(instances[i]);
if (instance.getNode().equals(host)) {
System.out.println(instance.getName());
System.exit(0);
}
}
System.err.println("Couldn't find a local instance for " + args[0]);
System.exit(1);
}
}