Skip to content
Snippets Groups Projects
Commit c2d4786b authored by Jan David Mol's avatar Jan David Mol
Browse files

SW-685: Propagate database port/user/password from jOTDBserver command line to...

SW-685: Propagate database port/user/password from jOTDBserver command line to OTDB wrapper. Draw credentials from dbcredentials in OTB server startup script.
parent 4fccdf55
No related branches found
No related tags found
No related merge requests found
...@@ -285,7 +285,9 @@ if __name__ == "__main__": ...@@ -285,7 +285,9 @@ if __name__ == "__main__":
parser = OptionParser("%prog [options]") parser = OptionParser("%prog [options]")
parser.add_option("-D", "--database", dest="database", type="string", default="", parser.add_option("-D", "--database", dest="database", type="string", default="",
help="Name of the database") help="Print credentials of a specific database")
parser.add_option("-S", "--shell", dest="shell", action="store_true", default=False,
help="Use machine-readable output for use in shell scripts")
parser.add_option("-L", "--list", dest="list", action="store_true", default=False, parser.add_option("-L", "--list", dest="list", action="store_true", default=False,
help="List known databases") help="List known databases")
parser.add_option("-F", "--files", dest="files", action="store_true", default=False, parser.add_option("-F", "--files", dest="files", action="store_true", default=False,
...@@ -313,5 +315,14 @@ if __name__ == "__main__": ...@@ -313,5 +315,14 @@ if __name__ == "__main__":
sys.exit(0) sys.exit(0)
""" Print credentials of a specific database. """ """ Print credentials of a specific database. """
print(str(dbc.get(options.database))) creds = dbc.get(options.database)
if options.shell:
print("DBUSER=%s" % (creds.user,))
print("DBPASSWORD=%s" % (creds.password,))
print("DBDATABASE=%s" % (creds.database,))
print("DBHOST=%s" % (creds.host,))
print("DBPORT=%s" % (creds.port,))
else:
print(str(creds))
...@@ -161,12 +161,11 @@ echo "Logging serverlogs to file $logfile" ...@@ -161,12 +161,11 @@ echo "Logging serverlogs to file $logfile"
serverpid=0 serverpid=0
ps -ef | grep -v grep | grep java | grep server | grep $port1 2>&1 1>/dev/null ps -ef | grep -v grep | grep java | grep server | grep $port1 2>&1 1>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
if [ "$LOFARENV" == "TEST" ]; then # use dbcredentials.py to extract OTDB credentials in shell form
dbhost=sasdbtest source /opt/lofar/lofarinit.sh
else declare `python3 -m lofar.common.dbcredentials -D OTDB -S`
dbhost=sasdb
fi $JAVA_HOME/bin/java -cp $CLASSPATH nl.astron.lofar.sas.otb.jotdb3.jOTDBserver -s `hostname` -d $DBHOST -P $DBPORT -p $port1 -o $port2 -U $DBUSER -W "$DBPASSWORD" 2>&1 1>&$logfile &
$JAVA_HOME/bin/java -cp $CLASSPATH nl.astron.lofar.sas.otb.jotdb3.jOTDBserver -s `hostname` -d $dbhost -p $port1 -o $port2 2>&1 1>&$logfile &
serverpid=$! serverpid=$!
echo Started server with PID: $serverpid echo Started server with PID: $serverpid
else else
......
...@@ -40,9 +40,11 @@ public class jOTDBaccess implements jOTDBaccessInterface ...@@ -40,9 +40,11 @@ public class jOTDBaccess implements jOTDBaccessInterface
private Logger logger = Logger.getLogger(jOTDBaccess.class); private Logger logger = Logger.getLogger(jOTDBaccess.class);
private static int seqNr = 0; private static int seqNr = 0;
private String itsDBname=""; private String itsDBname="";
private String itsDBpwd=""; private String itsDBuser="";
private String itsDBpassword="";
private String itsDB=""; private String itsDB="";
private String itsDBhost=""; private String itsDBhost="";
private String itsDBport=0;
private String itsRMIhost=""; private String itsRMIhost="";
private int itsRMIobjectPort=0; private int itsRMIobjectPort=0;
private int itsRMIport = 0; private int itsRMIport = 0;
...@@ -59,9 +61,12 @@ public class jOTDBaccess implements jOTDBaccessInterface ...@@ -59,9 +61,12 @@ public class jOTDBaccess implements jOTDBaccessInterface
public jOTDBaccess( String aDBhost, String anRMIhost,int anRMIport, int anRMIobjectPort,Registry aLocalRegistry) throws RemoteException public jOTDBaccess( String aDBhost, String aDBport, String aDBuser, String aDBpassword, String anRMIhost,int anRMIport, int anRMIobjectPort,Registry aLocalRegistry) throws RemoteException
{ {
itsDBhost=aDBhost; itsDBhost=aDBhost;
itsDBport=aDBport;
itsDBuser=aDBuser;
itsDBpassword=aDBpassword;
itsRMIhost=anRMIhost; itsRMIhost=anRMIhost;
itsRMIport=anRMIport; itsRMIport=anRMIport;
itsRMIobjectPort=anRMIobjectPort; itsRMIobjectPort=anRMIobjectPort;
...@@ -185,7 +190,7 @@ public class jOTDBaccess implements jOTDBaccessInterface ...@@ -185,7 +190,7 @@ public class jOTDBaccess implements jOTDBaccessInterface
try { try {
// Export jOTDBconnection // Export jOTDBconnection
jOTDBconnection aC = new jOTDBconnection("paulus", "boskabouter", dbName,itsDBhost,ext); jOTDBconnection aC = new jOTDBconnection(itsDBuser, itsDBpassword, dbName, itsDBhost, itsDBport, ext);
connection.put(serviceName,aC); connection.put(serviceName,aC);
//A custom port was specified, export the object using the port specified //A custom port was specified, export the object using the port specified
......
...@@ -38,11 +38,11 @@ public class jOTDBconnection implements jOTDBinterface ...@@ -38,11 +38,11 @@ public class jOTDBconnection implements jOTDBinterface
} }
// Just creates an object and registers the connection parameters. // Just creates an object and registers the connection parameters.
public jOTDBconnection (String username, String passwd, String database, String hostname, String ext) public jOTDBconnection (String username, String passwd, String database, String hostname, String port, String ext)
{ {
try { try {
itsName=ext; itsName=ext;
initOTDBconnection (username, passwd, database, hostname); initOTDBconnection (username, passwd, database, hostname, port);
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error during connection init :" + ex); System.out.println("Error during connection init :" + ex);
} }
...@@ -52,7 +52,7 @@ public class jOTDBconnection implements jOTDBinterface ...@@ -52,7 +52,7 @@ public class jOTDBconnection implements jOTDBinterface
{ {
try { try {
itsName="_test_1"; itsName="_test_1";
initOTDBconnection("paulus", "boskabouter", "otdbtest" , "dop50.astron.nl"); initOTDBconnection("paulus", "boskabouter", "otdbtest" , "dop50.astron.nl", 5432);
} catch (Exception ex) { } catch (Exception ex) {
System.out.println("Error during connection init :" + ex); System.out.println("Error during connection init :" + ex);
} }
...@@ -61,7 +61,7 @@ public class jOTDBconnection implements jOTDBinterface ...@@ -61,7 +61,7 @@ public class jOTDBconnection implements jOTDBinterface
// Create a OTDBconnection instance // Create a OTDBconnection instance
private native void initOTDBconnection (String username, String passwd, String database, String hostname) throws Exception; private native void initOTDBconnection (String username, String passwd, String database, String hostname, int port) throws Exception;
// To test if we are (still) connected. // To test if we are (still) connected.
@Override @Override
......
...@@ -118,6 +118,9 @@ public class jOTDBserver { ...@@ -118,6 +118,9 @@ public class jOTDBserver {
String dbHostName = ""; String dbHostName = "";
String dbPort = 5432;
String dbUser = "postgres";
String dbPassword = "";
String serverHostName = ""; String serverHostName = "";
int rmiPort = 0; int rmiPort = 0;
int rmiObjectPort = 0; int rmiObjectPort = 0;
...@@ -128,6 +131,9 @@ public class jOTDBserver { ...@@ -128,6 +131,9 @@ public class jOTDBserver {
GetOptDesc options[] = { GetOptDesc options[] = {
new GetOptDesc('s', "serverHostName", true), new GetOptDesc('s', "serverHostName", true),
new GetOptDesc('d', "dbHostName", true), new GetOptDesc('d', "dbHostName", true),
new GetOptDesc('P', "dbPort", true),
new GetOptDesc('U', "dbUser", true),
new GetOptDesc('W', "dbPassword", true),
new GetOptDesc('p', "rmiPort", true), new GetOptDesc('p', "rmiPort", true),
new GetOptDesc('o', "rmiObjectPort", true), new GetOptDesc('o', "rmiObjectPort", true),
new GetOptDesc('h', "help", false) new GetOptDesc('h', "help", false)
...@@ -146,6 +152,15 @@ public class jOTDBserver { ...@@ -146,6 +152,15 @@ public class jOTDBserver {
case 'd': case 'd':
dbHostName = (String)optionsFound.get(key); dbHostName = (String)optionsFound.get(key);
break; break;
case 'P':
dbPort = (String)optionsFound.get(key);
break;
case 'U':
dbUser = (String)optionsFound.get(key);
break;
case 'W':
dbPassword = (String)optionsFound.get(key);
break;
case 'p': case 'p':
rmiPort = Integer.parseInt((String)optionsFound.get(key)); rmiPort = Integer.parseInt((String)optionsFound.get(key));
break; break;
...@@ -161,7 +176,7 @@ public class jOTDBserver { ...@@ -161,7 +176,7 @@ public class jOTDBserver {
} }
} }
if (errs) { if (errs) {
System.out.println("Usage: java -jar jOTDBnewServer.jar -p rmiPort -o rmiObjectPort [-s server] [-d database server] [-h]"); System.out.println("Usage: java -jar jOTDBnewServer.jar -p rmiPort -o rmiObjectPort [-s server] [-d database server] [-P database port] [-U database user] [-W database password] [-h]");
System.out.println(""); System.out.println("");
System.out.println(" The rmi port is needed for rmi traffic and must be unique fior each server"); System.out.println(" The rmi port is needed for rmi traffic and must be unique fior each server");
System.out.println(" The rmiObjectPort is needed for firewall/tunneling java objects and must be unique for each server"); System.out.println(" The rmiObjectPort is needed for firewall/tunneling java objects and must be unique for each server");
...@@ -203,7 +218,7 @@ public class jOTDBserver { ...@@ -203,7 +218,7 @@ public class jOTDBserver {
} }
logger.info("jOTDBserver setting up RMI server objects on port "+rmiObjectPort+" ..."); logger.info("jOTDBserver setting up RMI server objects on port "+rmiObjectPort+" ...");
access = new jOTDBaccess(dbHostName, serverHostName, rmiPort, rmiObjectPort, registry); access = new jOTDBaccess(dbHostName, dbPort, dbUser, dbPassword, serverHostName, rmiPort, rmiObjectPort, registry);
jOTDBaccessInterface stub = jOTDBaccessInterface stub =
(jOTDBaccessInterface) UnicastRemoteObject.exportObject(access, rmiObjectPort); (jOTDBaccessInterface) UnicastRemoteObject.exportObject(access, rmiObjectPort);
......
...@@ -51,20 +51,22 @@ using namespace std; ...@@ -51,20 +51,22 @@ using namespace std;
* Method: initOTDBconnection * Method: initOTDBconnection
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;); * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;);
*/ */
JNIEXPORT void JNICALL Java_nl_astron_lofar_sas_otb_jotdb3_jOTDBconnection_initOTDBconnection(JNIEnv *env, jobject jOTDBconnection, jstring username, jstring passwd, jstring database, jstring hostname) { JNIEXPORT void JNICALL Java_nl_astron_lofar_sas_otb_jotdb3_jOTDBconnection_initOTDBconnection(JNIEnv *env, jobject jOTDBconnection, jstring username, jstring passwd, jstring database, jstring hostname, jstring port) {
const char* user = env->GetStringUTFChars(username, 0); const char* user = env->GetStringUTFChars(username, 0);
const char* pass = env->GetStringUTFChars(passwd, 0); const char* pass = env->GetStringUTFChars(passwd, 0);
const char* db = env->GetStringUTFChars(database, 0); const char* db = env->GetStringUTFChars(database, 0);
const char* hn = env->GetStringUTFChars(hostname, 0); const char* hn = env->GetStringUTFChars(hostname, 0);
const char* pt = env->GetStringUTFChars(port, 0);
const string u (user); const string u (user);
const string p (pass); const string p (pass);
const string d (db); const string d (db);
const string h (hn); const string h (hn);
const string prt (pt);
const char* n(0); const char* n(0);
jstring str(0); jstring str(0);
try { try {
OTDBconnection* aPtr = new OTDBconnection(u, p, d, h); OTDBconnection* aPtr = new OTDBconnection(u, p, d, h, prt);
if ( !aPtr) { if ( !aPtr) {
env->ThrowNew(env->FindClass("java/lang/Exception"),"Error creating OTDBconnection"); env->ThrowNew(env->FindClass("java/lang/Exception"),"Error creating OTDBconnection");
return; return;
......
# $Id$ # $Id$
# PyCommon is needed for OTB, which uses dbcredentials. OTB is installed in parallel to this subsystem.
lofar_package(CCU_MAC lofar_package(CCU_MAC
DEPENDS CEPCU CUDaemons CURTDBDaemons StaticMetaData MessageDaemons) DEPENDS CEPCU CUDaemons CURTDBDaemons StaticMetaData MessageDaemons PyCommon)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment