Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r371 - in trunk: java/ch/idok/dmsd/impl/controller java/ch/idok/dmsd/main sites/psi/scripts/admin/dmsd/dist

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r371 - in trunk: java/ch/idok/dmsd/impl/controller java/ch/idok/dmsd/main sites/psi/scripts/admin/dmsd/dist


Chronological Thread 
  • From: "AFS account Stadler Hans Christian" <stadler_h AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r371 - in trunk: java/ch/idok/dmsd/impl/controller java/ch/idok/dmsd/main sites/psi/scripts/admin/dmsd/dist
  • Date: Wed, 24 Jun 2009 16:06:12 +0200
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: stadler_h
Date: Wed Jun 24 16:06:11 2009
New Revision: 371

Log:
Added dmsd help and nthreads service command

Added:
trunk/sites/psi/scripts/admin/dmsd/dist/help-dmsd.sh (contents, props
changed)
trunk/sites/psi/scripts/admin/dmsd/dist/nthreads-dmsd.sh (contents,
props changed)
Modified:
trunk/java/ch/idok/dmsd/impl/controller/ExternalDaemonController.java
trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManager.java
trunk/java/ch/idok/dmsd/main/Daemon.java
trunk/sites/psi/scripts/admin/dmsd/dist/dmsd

Modified:
trunk/java/ch/idok/dmsd/impl/controller/ExternalDaemonController.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/controller/ExternalDaemonController.java
(original)
+++ trunk/java/ch/idok/dmsd/impl/controller/ExternalDaemonController.java
Wed Jun 24 16:06:11 2009
@@ -29,6 +29,7 @@
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
+import java.util.logging.Logger;

import ch.idok.common.errorhandling.DmsException;
import ch.idok.common.errorhandling.ErrorType;
@@ -49,12 +50,11 @@
*/
public StringBuffer argDesc() {
StringBuffer sb = new StringBuffer();
- sb
- .append("\textra commands: None, only stop, status and
loglevel are supported so far\n");
- sb
- .append("\tall-arg3: The host name where the jndi server
resides that has registered the mbean server\n");
+ sb.append("\textra commands: nthreads - get/set the number of
threads in the thread pool\n");
+ sb.append("\tall-arg3: The host name where the jndi server resides
that has registered the mbean server\n");
sb.append("\tall-arg4: The port name for the jndi server\n");
- sb.append("\tloglevel-arg5: The new log level\n");
+ sb.append("\tloglevel-arg5: The new log level, or 'get' to get the
current log level\n");
+ sb.append("\tnthreads-arg5: 'get' for reading the number of threads,
otherwise the new number of threads\n");
return sb;
}

@@ -85,8 +85,7 @@
new
ObjectName(SimpleControllerManagerMBean.MBeanName),
SimpleControllerManagerMBean.class, false);
if (simpleControl == null)
- DmsException
- .throwIt(
+ DmsException.throwIt(
ErrorType.JMX_ACCESS,
this,
"Cannot communicate with the DMS daemon",
@@ -112,7 +111,9 @@
*/
public void control(String[] args) throws DmsException {
DmsException ex = null;
+ Logger logger = null;
try {
+ logger = Setup.getConfig().getLogger("ExternalCommand");
do {
if (args.length < 5) {
ex = new DmsException(ErrorType.BAD_ARG, this,
@@ -120,29 +121,15 @@
+ args.length + " arguments");
break;
}
- Setup.getConfig()
- .getLogger("ExternalCommand")
- .severe("******** Executing command "+args[0]);
- SimpleControllerManagerMBean simpleControl = jmxConnect(
- args[3], args[4]);
+ logger.info("connecting to JMX bean...");
+ SimpleControllerManagerMBean simpleControl =
jmxConnect(args[3], args[4]);
if (args[0].equals("loglevel")) {
- if (args.length != 6) {
- ex = new DmsException(ErrorType.BAD_ARG, this,
- "Wrong number of arguments", "Detected "
- + args.length + " arguments");
- break;
- }
- String msg = simpleControl.setLogLevel(args[5]);
- if (msg == null) {
- } else if (msg.startsWith("logLevel=")) {
- System.out.println(msg);
- msg = null;
- } else {
- ex = new DmsException(ErrorType.BAD_ARG, this, msg,
- "This error message was returned from the
daemon");
- break;
- }
- return;
+ logLevel(simpleControl, args);
+ break;
+ }
+ if (args[0].equals("nthreads")) {
+ nthreads(simpleControl, args);
+ break;
}
if (args.length != 5) {
ex = new DmsException(ErrorType.BAD_ARG, this,
@@ -155,15 +142,13 @@
else if (args[0].equals("status"))
simpleControl.pingDaemon();
else {
- ex = new DmsException(
- ErrorType.BAD_ARG,
- this,
- "Only the 'stop', 'status' and 'loglevel'
commands are supported",
+ ex = new DmsException(ErrorType.BAD_ARG, this,
+ "Only the 'nthreads', 'stop', 'status' and
'loglevel' commands are supported",
args[0] + ": unsupported command");
break;
}
- return;
} while (false);
+ return;
} catch (DmsException dex) {
ex = dex;
} catch (Throwable e) {
@@ -172,4 +157,53 @@
}
throw ex;
}
+
+ /**
+ * @brief Set the new global log level.
+ * @param simpleControl The JMX bean
+ * @param args The argument strings
+ * @throws DmsException On error
+ */
+ private void logLevel (SimpleControllerManagerMBean simpleControl,
String args[]) throws DmsException {
+ {
+ if (args.length != 6) {
+ throw new DmsException(ErrorType.BAD_ARG, this, "Wrong
number of arguments",
+ "Detected " + args.length + "
arguments");
+ }
+ String msg = simpleControl.setLogLevel(args[5]);
+ if (msg == null) {
+ } else if (msg.startsWith("logLevel=")) {
+ System.out.println(msg);
+ msg = null;
+ } else {
+ throw new DmsException(ErrorType.BAD_ARG, this, msg,
+ "This error message was returned
from the daemon");
+ }
+ }
+ }
+
+ /**
+ * @brief Set/get number of threads in the thread pool
+ * @param simpleControl The JMX Bean
+ * @param args Argument strings
+ * @throws DmsException On error
+ */
+ private void nthreads (SimpleControllerManagerMBean simpleControl,
String args[]) throws DmsException {
+ {
+ if (args.length != 6) {
+ throw new DmsException(ErrorType.BAD_ARG, this, "Wrong
number of arguments",
+ "Detected " + args.length + " arguments");
+ }
+ if (args[5].equals("get")) {
+
System.out.println("nthreads="+simpleControl.getNumberOfThreads());
+ } else {
+ try {
+
simpleControl.setNumberOfThreads(Integer.parseInt(args[5]));
+ } catch (NumberFormatException ex) {
+ throw new DmsException(ErrorType.BAD_ARG, this, "Integer
argument expected", "No int: "+args[5]);
+ }
+ }
+ }
+ }
+
}

Modified: trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManager.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManager.java
(original)
+++ trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManager.java
Wed Jun 24 16:06:11 2009
@@ -144,6 +144,7 @@
* @brief Set number of threads
*/
public void setNumberOfThreads(int nThreads) {
+ controller.logger.info("Setting number of threads to "+nThreads);
controller.setNumberOfThreads(nThreads);
}


Modified: trunk/java/ch/idok/dmsd/main/Daemon.java
==============================================================================
--- trunk/java/ch/idok/dmsd/main/Daemon.java (original)
+++ trunk/java/ch/idok/dmsd/main/Daemon.java Wed Jun 24 16:06:11 2009
@@ -30,6 +30,7 @@

import ch.idok.common.errorhandling.DmsException;
import ch.idok.common.errorhandling.ErrorType;
+import ch.idok.common.errorhandling.Util;
import ch.idok.dmsd.config.Config;
import ch.idok.dmsd.config.Setup;
import ch.idok.dmsd.management.ExternalDaemonControl;
@@ -58,12 +59,11 @@
sb
.append("\t 'status' for daemon status (running/not
running)\n");
sb.append("\t 'loglevel' for changing the log level\n");
- sb.append("\t 'help' to see more commands\n");
+ sb.append("\t 'help' to see this help text\n");
sb.append("\targ1: The log level\n");
sb.append("\targ2: The configurator class\n");
if (msg != null) {
- sb
- .append(" Configurator specific arguments for the
'daemon' command:\n");
+ sb.append(" Configurator specific commands and arguments:\n");
sb.append(msg);
} else {
sb.append("\tThe config-args are configurator specific.\n");
@@ -76,22 +76,28 @@
*
* This method must not return.
*/
- static void controlCommand(Logger logger, ExternalDaemonControl proxy,
- String args[]) {
+ static void controlCommand(Logger logger, ExternalDaemonControl proxy,
String args[]) {
try {
- proxy.control(args);
- logger.severe("Operation " + args[0] + " finished successfully");
- System.exit(0);
- } catch (DmsException ex) {
- if (ex.getErrorType() == ErrorType.JMX_ACCESS) {
- logger.info("Command " + args[0] + ": " +
ex.getLogMessage());
+ StringBuilder sb = new
StringBuilder("*****************\ncontrollCommand: ");
+ for (String s : args) {
+ sb.append(s);
+ sb.append(' ');
+ }
+ logger.severe(sb.toString());
+ if (args[0].equals("help")) {
+ System.out.println(usage(proxy.argDesc()).toString());
} else {
- logger.severe(usage(proxy.argDesc()).toString());
- logger.log(Level.SEVERE, ex.getLogMessage(), ex);
+ proxy.control(args);
}
+ logger.severe("Operation " + args[0] + " finished successfully");
+ System.exit(0);
} catch (Throwable th) {
- logger.severe(proxy.argDesc().toString());
- logger.log(Level.SEVERE, th.getLocalizedMessage(), th);
+ StringBuffer sb = new StringBuffer("Command ");
+ sb.append(args[0]).append(": ").append(th.getLocalizedMessage());
+ System.err.println(sb.toString());
+ sb.append('\n');
+ Util.getStackTrace(sb, th);
+ logger.severe(sb.toString());
}
System.exit(1);
}
@@ -126,7 +132,7 @@
try {
setup.initialize(args);
config = Setup.getConfig();
- if (!args[0].equals("daemon"))
+ if (! args[0].equals("daemon"))
controlCommand(initialLogger,
config.getExternalDaemonControl(), args); // exits
config.initialize(args); // Construct pipeline

Modified: trunk/sites/psi/scripts/admin/dmsd/dist/dmsd
==============================================================================
--- trunk/sites/psi/scripts/admin/dmsd/dist/dmsd (original)
+++ trunk/sites/psi/scripts/admin/dmsd/dist/dmsd Wed Jun 24 16:06:11
2009
@@ -91,7 +91,7 @@

function f_loglevel () {
test -r ./loglevel-dmsd.sh || { echo $"Error: loglevel-dmsd.sh is not
readable"; return 1; }
- ./loglevel-dmsd.sh $1
+ ./loglevel-dmsd.sh ${@}
return ${?}
}

@@ -100,8 +100,20 @@
return 0
}

+f_nthreads () {
+ test -r ./nthreads-dmsd.sh || { echo $"Error: nthreads-dmsd.sh is not
readable"; return 1; }
+ ./nthreads-dmsd.sh "${@}"
+ return ${?}
+}
+
+f_help () {
+ test -r ./help-dmsd.sh || { echo $"Error: help-dmsd.sh is not
readable"; return 1; }
+ ./help-dmsd.sh "${@}"
+ return ${?}
+}
+
f_usage() {
- echo $"Usage: $0
{start|stop|status|restart|condrestart|version|loglevel <level>}"
+ echo $"Usage: $0
{start|stop|status|restart|condrestart|help|version|loglevel <level>|nthreads
[N]}"
exit 1
}


Added: trunk/sites/psi/scripts/admin/dmsd/dist/help-dmsd.sh
==============================================================================
--- (empty file)
+++ trunk/sites/psi/scripts/admin/dmsd/dist/help-dmsd.sh Wed Jun 24
16:06:11 2009
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+##
+## Copyright (C) 2006-2008 iDok team.
+##
+## This program is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License
+## as published by the Free Software Foundation; either version 2
+## of the License, or (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+##
+## See the GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
+##
+
+# Call the help command of the DMS daemon
+
+test -r ./dmsd.config || { echo "Error: ./dmsd.config file is not readable!"
>&2; exit 1; }
+test -r ./dmsd.jar || { echo "Error: ./dmsd.jar is not readable!" >&2; exit
1; }
+
+# Source the config file
+. ./dmsd.config
+
+${JAVA} \
+ -Dcom.sun.management.jmxremote \
+ -cp dmsd.jar:${CLASS_PATH} \
+ ch.idok.dmsd.main.Daemon \
+ help \
+ ${UTIL_LOG_LEVEL} \
+ ${CONFIGURATOR} 1>&2
+
+exit ${?}

Added: trunk/sites/psi/scripts/admin/dmsd/dist/nthreads-dmsd.sh
==============================================================================
--- (empty file)
+++ trunk/sites/psi/scripts/admin/dmsd/dist/nthreads-dmsd.sh Wed Jun 24
16:06:11 2009
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+##
+## Copyright (C) 2006-2008 iDok team.
+##
+## This program is free software; you can redistribute it and/or
+## modify it under the terms of the GNU General Public License
+## as published by the Free Software Foundation; either version 2
+## of the License, or (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+##
+## See the GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
+##
+
+# Read/set the number of threads in the thread pool of the DMS daemon
+# Argument 1: Absent->read, N->Set nthreads to N
+
+test -r ./dmsd.config || { echo "Error: ./dmsd.config file is not readable!"
>&2; exit 1; }
+test -r ./dmsd.jar || { echo "Error: ./dmsd.jar is not readable!" >&2; exit
1; }
+
+# Source the config file
+. ./dmsd.config
+
+${JAVA} \
+ -Dcom.sun.management.jmxremote \
+ -cp dmsd.jar:${CLASS_PATH} \
+ ch.idok.dmsd.main.Daemon \
+ nthreads \
+ ${UTIL_LOG_LEVEL} \
+ ${CONFIGURATOR} \
+ localhost \
+ ${JMX_PORT} \
+ "${1}" 1>&2
+
+exit ${?}
+



  • [idok-commit] idok commit r371 - in trunk: java/ch/idok/dmsd/impl/controller java/ch/idok/dmsd/main sites/psi/scripts/admin/dmsd/dist, AFS account Stadler Hans Christian, 06/24/2009

Archive powered by MHonArc 2.6.19.

Top of Page