>From d8aa387981de8af5e4a8be565ec36d953eb80092 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Tue, 22 Jul 2014 00:03:47 -0400 Subject: [PATCH 7/9] Add ability to enable/disable dynamic subsystems The CA installation process requires starting with the profile subsystem disabled, then enabling it once profiles have been loaded into the database. Accordingly, to avoid hacks with hardcoded offsets, add the "enabled" CS.cfg configuration parameter along with methods to enable or disable a subsystem based on the subsystem ID. Subsystems are enabled by default. This commit also removes an assumption that the subsystem config sub-store names are sequential numbers beginning at `0'. --- base/common/src/com/netscape/certsrv/apps/CMS.java | 22 ++++++++ .../src/com/netscape/certsrv/apps/ICMSEngine.java | 9 +++ .../src/com/netscape/cmscore/apps/CMSEngine.java | 64 ++++++++++++++++------ .../netscape/cmscore/app/CMSEngineDefaultStub.java | 3 + 4 files changed, 82 insertions(+), 16 deletions(-) diff --git a/base/common/src/com/netscape/certsrv/apps/CMS.java b/base/common/src/com/netscape/certsrv/apps/CMS.java index 63c1a2c..38a6994 100644 --- a/base/common/src/com/netscape/certsrv/apps/CMS.java +++ b/base/common/src/com/netscape/certsrv/apps/CMS.java @@ -511,6 +511,28 @@ public final class CMS { } /** + * Enable the subsystem with the given ID. + * + * Does not start the subsystem. + * + * @param id Subsystem ID. + */ + public static void enableSubsystem(String id) throws EBaseException { + _engine.setSubsystemEnabled(id, true); + } + + /** + * Disable the subsystem with the given ID. + * + * Does not stop the subsystem. + * + * @param id Subsystem ID. + */ + public static void disableSubsystem(String id) throws EBaseException { + _engine.setSubsystemEnabled(id, false); + } + + /** * Retrieves the localized user message from UserMessages.properties. * * @param msgID message id defined in UserMessages.properties diff --git a/base/common/src/com/netscape/certsrv/apps/ICMSEngine.java b/base/common/src/com/netscape/certsrv/apps/ICMSEngine.java index 74fa090..5c78a7c 100644 --- a/base/common/src/com/netscape/certsrv/apps/ICMSEngine.java +++ b/base/common/src/com/netscape/certsrv/apps/ICMSEngine.java @@ -171,6 +171,15 @@ public interface ICMSEngine extends ISubsystem { public Enumeration getSubsystems(); /** + * Set whether the given subsystem is enabled. + * + * @param id The subsystem ID. + * @param enabled Whether the subsystem is enabled + */ + public void setSubsystemEnabled(String id, boolean enabled) + throws EBaseException; + + /** * Retrieves the registered subsytem with the given name. * * @param name subsystem name diff --git a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java index 68c6482..1fbfade 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java +++ b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java @@ -181,6 +181,7 @@ public class CMSEngine implements ICMSEngine { private static final String PROP_SUBSYSTEM = "subsystem"; private static final String PROP_ID = "id"; private static final String PROP_CLASS = "class"; + private static final String PROP_ENABLED = "enabled"; private static final String SERVER_XML = "server.xml"; public static final SubsystemRegistry mSSReg = SubsystemRegistry.getInstance(); @@ -866,32 +867,34 @@ public class CMSEngine implements ICMSEngine { } } + private Vector getDynSubsystemNames() throws EBaseException { + IConfigStore ssconfig = mConfig.getSubStore(PROP_SUBSYSTEM); + Enumeration ssNames = ssconfig.getSubStoreNames(); + Vector ssNamesVector = new Vector(); + while (ssNames.hasMoreElements()) + ssNamesVector.add(ssNames.nextElement()); + return ssNamesVector; + } + /** * load dynamic subsystems */ private void loadDynSubsystems() throws EBaseException { - IConfigStore ssconfig = mConfig.getSubStore(PROP_SUBSYSTEM); - - // count number of dyn loaded subsystems. - Enumeration ssnames = ssconfig.getSubStoreNames(); - int nsubsystems = 0; - - for (nsubsystems = 0; ssnames.hasMoreElements(); nsubsystems++) - ssnames.nextElement(); + Vector ssNames = getDynSubsystemNames(); if (Debug.ON) { - Debug.trace(nsubsystems + " dyn subsystems loading.."); + Debug.trace(ssNames.size() + " dyn subsystems loading.."); } - if (nsubsystems == 0) - return; // load dyn subsystems. - mDynSubsystems = new SubsystemInfo[nsubsystems]; - for (int i = 0; i < mDynSubsystems.length; i++) { - IConfigStore config = - ssconfig.getSubStore(String.valueOf(i)); + IConfigStore ssconfig = mConfig.getSubStore(PROP_SUBSYSTEM); + mDynSubsystems = new SubsystemInfo[ssNames.size()]; + int i = 0; + for (String ssName : ssNames) { + IConfigStore config = ssconfig.getSubStore(ssName); String id = config.getString(PROP_ID); String classname = config.getString(PROP_CLASS); + boolean enabled = config.getBoolean(PROP_ENABLED, true); ISubsystem ss = null; try { @@ -906,11 +909,30 @@ public class CMSEngine implements ICMSEngine { throw new EBaseException( CMS.getUserMessage("CMS_BASE_LOAD_FAILED_1", id, e.toString())); } - mDynSubsystems[i] = new SubsystemInfo(id, ss); + mDynSubsystems[i++] = new SubsystemInfo(id, ss, enabled); Debug.trace("loaded dyn subsystem " + id); } } + /** + * Set whether the given subsystem is enabled. + * + * @param id The subsystem ID. + * @param enabled Whether the subsystem is enabled + */ + public void setSubsystemEnabled(String id, boolean enabled) + throws EBaseException { + IConfigStore ssconfig = mConfig.getSubStore(PROP_SUBSYSTEM); + Vector ssNames = getDynSubsystemNames(); + for (String ssName : ssNames) { + IConfigStore config = ssconfig.getSubStore(ssName); + if (id.equalsIgnoreCase(config.getString(PROP_ID))) { + config.putBoolean(PROP_ENABLED, enabled); + break; + } + } + } + public LDAPConnection getBoundConnection(String host, int port, int version, LDAPSSLSocketFactoryExt fac, String bindDN, String bindPW) throws LDAPException { @@ -928,6 +950,10 @@ public class CMSEngine implements ICMSEngine { IConfigStore ssConfig = mConfig.getSubStore(id); CMS.debug("CMSEngine: initSubsystem id=" + id); + if (!ssinfo.mEnabled) { + CMS.debug("CMSEngine: subsystem disabled id=" + id); + return; + } if (doSetId) ss.setId(id); CMS.debug("CMSEngine: ready to init id=" + id); @@ -2000,10 +2026,16 @@ class WarningListener implements ILogEventListener { class SubsystemInfo { public final String mId; public final ISubsystem mInstance; + public final boolean mEnabled; public SubsystemInfo(String id, ISubsystem ssInstance) { + this(id, ssInstance, true); + } + + public SubsystemInfo(String id, ISubsystem ssInstance, boolean enabled) { mId = id; mInstance = ssInstance; + mEnabled = enabled; } } diff --git a/base/server/test/com/netscape/cmscore/app/CMSEngineDefaultStub.java b/base/server/test/com/netscape/cmscore/app/CMSEngineDefaultStub.java index db39964..0b7518d 100644 --- a/base/server/test/com/netscape/cmscore/app/CMSEngineDefaultStub.java +++ b/base/server/test/com/netscape/cmscore/app/CMSEngineDefaultStub.java @@ -135,6 +135,9 @@ public class CMSEngineDefaultStub implements ICMSEngine { return null; } + public void setSubsystemEnabled(String id, boolean enabled) { + }; + public ISubsystem getSubsystem(String name) { return null; } -- 1.9.3