From b944d31ef744a220f176bf7143e727223ad6b3b1 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 25 Feb 2014 12:01:55 -0500 Subject: Direct deployment for TPS. The deployment tool has been modified to deploy TPS directly from the share folder. This way the TPS UI can be upgraded automatically with RPM upgrade without having to write upgrade scripts. For this to work, the TPS web application files cannot contain any slot parameters. So, the cfgPath parameter has been removed from web.xml, and the CMSStartServlet has been modified such that if the parameter is missing it would generate a default path matching the original value in web.xml. Also, the velocity.properties has been modified to use a fixed value for the file.resource.loader.path parameter pointing to the share folder. In the future other subsystems may be modified to use the same deployment mechanism. Ticket #748, #752, #499 --- .../netscape/cms/servlet/base/CMSStartServlet.java | 31 +++++++++--- .../deployment/scriptlets/slot_substitution.py | 14 ++++-- .../deployment/scriptlets/webapp_deployment.py | 55 +++++++++++++++------- .../shared/conf/Catalina/localhost/tps.xml | 2 +- .../shared/webapps/tps/WEB-INF/velocity.properties | 2 +- base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml | 4 -- specs/pki-core.spec | 10 ++++ 7 files changed, 83 insertions(+), 35 deletions(-) diff --git a/base/server/cms/src/com/netscape/cms/servlet/base/CMSStartServlet.java b/base/server/cms/src/com/netscape/cms/servlet/base/CMSStartServlet.java index 60230dbab..ab29e2603 100644 --- a/base/server/cms/src/com/netscape/cms/servlet/base/CMSStartServlet.java +++ b/base/server/cms/src/com/netscape/cms/servlet/base/CMSStartServlet.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; import java.io.PrintWriter; -import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -46,9 +45,27 @@ public class CMSStartServlet extends HttpServlet { private static final long serialVersionUID = 515623839479425172L; public final static String PROP_CMS_CFG = "cfgPath"; - public void init(ServletConfig config) throws ServletException { - super.init(config); - String path = config.getInitParameter(PROP_CMS_CFG); + public void init() throws ServletException { + + // get web application context: / + String context = getServletContext().getContextPath(); + + // get subsystem name by removing the / prefix from the context + String subsystem = context.startsWith("/") ? context.substring(1) : context; + + // get config path from web.xml + String path = getServletConfig().getInitParameter(PROP_CMS_CFG); + + // if path not specified, use default path + if (path == null) { + // catalina.base points to instance dir + // it's defined as CATALINA_BASE in /conf/tomcat.conf + String instanceDir = System.getProperty("catalina.base"); + + // path: /conf//CS.cfg + path = instanceDir + File.separator + "conf" + File.separator + + subsystem + File.separator + "CS.cfg"; + } File f = new File(path); String old_path = ""; @@ -88,6 +105,7 @@ public class CMSStartServlet extends HttpServlet { } } } catch (Exception e) { + e.printStackTrace(); } } } @@ -95,12 +113,11 @@ public class CMSStartServlet extends HttpServlet { try { CMS.start(path); } catch (EBaseException e) { + e.printStackTrace(); } // Register realm for this subsystem - String context = getServletContext().getContextPath(); - if (context.startsWith("/")) context = context.substring(1); - ProxyRealm.registerRealm(context, new PKIRealm()); + ProxyRealm.registerRealm(subsystem, new PKIRealm()); } public void doGet(HttpServletRequest req, HttpServletResponse res) diff --git a/base/server/python/pki/server/deployment/scriptlets/slot_substitution.py b/base/server/python/pki/server/deployment/scriptlets/slot_substitution.py index a6c21e166..cc54cc49c 100644 --- a/base/server/python/pki/server/deployment/scriptlets/slot_substitution.py +++ b/base/server/python/pki/server/deployment/scriptlets/slot_substitution.py @@ -67,10 +67,16 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet): deployer.master_dict['pki_source_tomcat_conf'], deployer.master_dict['pki_target_tomcat_conf'], overwrite_flag=True) - deployer.file.apply_slot_substitution( - deployer.master_dict['pki_target_velocity_properties']) - deployer.file.apply_slot_substitution( - deployer.master_dict['pki_target_subsystem_web_xml']) + + # Configure web.xml and velocity.properties for each subsystem. + # For TPS this is not necessary since the files are no longer + # copied to the target location in the instance directory. + if deployer.master_dict['pki_subsystem'] != "TPS": + deployer.file.apply_slot_substitution( + deployer.master_dict['pki_target_velocity_properties']) + deployer.file.apply_slot_substitution( + deployer.master_dict['pki_target_subsystem_web_xml']) + # Strip "" section from subsystem "web.xml" # This is ONLY necessary because XML comments cannot be "nested"! # deployer.file.copy(deployer.master_dict['pki_target_subsystem_web_xml'], diff --git a/base/server/python/pki/server/deployment/scriptlets/webapp_deployment.py b/base/server/python/pki/server/deployment/scriptlets/webapp_deployment.py index 975028d73..0f529a9a2 100644 --- a/base/server/python/pki/server/deployment/scriptlets/webapp_deployment.py +++ b/base/server/python/pki/server/deployment/scriptlets/webapp_deployment.py @@ -44,10 +44,40 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet): config.pki_log.info(log.WEBAPP_DEPLOYMENT_SPAWN_1, __name__, extra=config.PKI_INDENTATION_LEVEL_1) + # For TPS, deploy web application directly from /usr/share/pki. + if deployer.master_dict['pki_subsystem'] == "TPS": + deployer.file.copy( + os.path.join( + config.PKI_DEPLOYMENT_SOURCE_ROOT, + "tps", + "conf", + "Catalina", + "localhost", + "tps.xml"), + os.path.join( + deployer.master_dict['pki_instance_configuration_path'], + "Catalina", + "localhost", + "tps.xml")) + return self.rv + + # For other subsystems, deploy web application into Tomcat instance. + deployer.directory.create(deployer.master_dict['pki_tomcat_webapps_subsystem_path']) + + # Copy /usr/share/pki//webapps/ + # to /webapps/ + deployer.directory.copy( + os.path.join( + config.PKI_DEPLOYMENT_SOURCE_ROOT, + deployer.master_dict['pki_subsystem'].lower(), + "webapps", + deployer.master_dict['pki_subsystem'].lower()), + deployer.master_dict['pki_tomcat_webapps_subsystem_path'], + overwrite_flag=True) + # Copy /usr/share/pki/server/webapps/pki/admin # to /webapps//admin # TODO: common templates should be deployed in common webapp - deployer.directory.create(deployer.master_dict['pki_tomcat_webapps_subsystem_path']) deployer.directory.copy( os.path.join( config.PKI_DEPLOYMENT_SOURCE_ROOT, @@ -60,17 +90,6 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet): "admin"), overwrite_flag=True) - # Copy /usr/share/pki//webapps/ - # to /webapps/ - deployer.directory.copy( - os.path.join( - config.PKI_DEPLOYMENT_SOURCE_ROOT, - deployer.master_dict['pki_subsystem'].lower(), - "webapps", - deployer.master_dict['pki_subsystem'].lower()), - deployer.master_dict['pki_tomcat_webapps_subsystem_path'], - overwrite_flag=True) - deployer.directory.create( deployer.master_dict['pki_tomcat_webapps_subsystem_webinf_classes_path']) deployer.directory.create( @@ -100,13 +119,12 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet): elif deployer.master_dict['pki_subsystem'] == "TKS": deployer.symlink.create(deployer.master_dict['pki_tks_jar'], deployer.master_dict['pki_tks_jar_link']) - elif deployer.master_dict['pki_subsystem'] == "TPS": - deployer.symlink.create(deployer.master_dict['pki_tps_jar'], - deployer.master_dict['pki_tps_jar_link']) + # set ownerships, permissions, and acls deployer.directory.set_mode(deployer.master_dict['pki_tomcat_webapps_subsystem_path']) - # Copy /usr/share/pki//conf/Catalina/localhost/.xml + # Copy web application context file + # from /usr/share/pki//conf/Catalina/localhost/.xml # to /conf/Catalina/localhost/.xml deployer.file.copy( os.path.join( @@ -137,7 +155,8 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet): "localhost", deployer.master_dict['pki_subsystem'].lower() + ".xml")) - # Delete /webapps/ - deployer.directory.delete(deployer.master_dict['pki_tomcat_webapps_subsystem_path']) + # For subsystems other than TPS, delete /webapps/. + if deployer.master_dict['pki_subsystem'] != "TPS": + deployer.directory.delete(deployer.master_dict['pki_tomcat_webapps_subsystem_path']) return self.rv diff --git a/base/tps-tomcat/shared/conf/Catalina/localhost/tps.xml b/base/tps-tomcat/shared/conf/Catalina/localhost/tps.xml index e838503a6..d80c1296d 100644 --- a/base/tps-tomcat/shared/conf/Catalina/localhost/tps.xml +++ b/base/tps-tomcat/shared/conf/Catalina/localhost/tps.xml @@ -22,7 +22,7 @@ See the License for the specific language governing permissions and limitations under the License. --> - + diff --git a/base/tps-tomcat/shared/webapps/tps/WEB-INF/velocity.properties b/base/tps-tomcat/shared/webapps/tps/WEB-INF/velocity.properties index 5cd0454cc..c1c6e4ea9 100644 --- a/base/tps-tomcat/shared/webapps/tps/WEB-INF/velocity.properties +++ b/base/tps-tomcat/shared/webapps/tps/WEB-INF/velocity.properties @@ -5,7 +5,7 @@ # resource.loader = file file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader -file.resource.loader.path = [PKI_INSTANCE_PATH]/[PKI_WEBAPPS_NAME]/[PKI_SUBSYSTEM_TYPE] +file.resource.loader.path = /usr/share/pki/server/webapps/pki file.resource.loader.cache = true file.resource.loader.modificationCheckInterval = 2 input.encoding=UTF-8 diff --git a/base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml b/base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml index 0fe3df4dc..11964a00b 100644 --- a/base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml +++ b/base/tps-tomcat/shared/webapps/tps/WEB-INF/web.xml @@ -42,10 +42,6 @@ AuthzMgr BasicAclAuthz - - cfgPath - [PKI_INSTANCE_PATH]/conf/[PKI_SUBSYSTEM_TYPE]/CS.cfg - ID tpsstart diff --git a/specs/pki-core.spec b/specs/pki-core.spec index bdfea138a..6e10ac0e3 100644 --- a/specs/pki-core.spec +++ b/specs/pki-core.spec @@ -523,6 +523,16 @@ cd build cd build %{__make} install DESTDIR=%{buildroot} INSTALL="install -p" +# Create symlinks for TPS web application +%{__mkdir_p} %{buildroot}%{_datadir}/pki/tps/webapps/tps/WEB-INF/lib +ln -s %{_javadir}/pki/pki-nsutil.jar %{buildroot}%{_datadir}/pki/tps/webapps/tps/WEB-INF/lib +ln -s %{_javadir}/pki/pki-cmsutil.jar %{buildroot}%{_datadir}/pki/tps/webapps/tps/WEB-INF/lib +ln -s %{_javadir}/pki/pki-certsrv.jar %{buildroot}%{_datadir}/pki/tps/webapps/tps/WEB-INF/lib +ln -s %{_javadir}/pki/pki-cms.jar %{buildroot}%{_datadir}/pki/tps/webapps/tps/WEB-INF/lib +ln -s %{_javadir}/pki/pki-cmscore.jar %{buildroot}%{_datadir}/pki/tps/webapps/tps/WEB-INF/lib +ln -s %{_javadir}/pki/pki-cmsbundle.jar %{buildroot}%{_datadir}/pki/tps/webapps/tps/WEB-INF/lib +ln -s %{_javadir}/pki/pki-tps.jar %{buildroot}%{_datadir}/pki/tps/webapps/tps/WEB-INF/lib + %if %{with server} # Scanning the python code with pylint. A return value of 0 represents there are no -- cgit