From e3cf8a6140c24734d2ee3ffd49cdf44f13f57590 Mon Sep 17 00:00:00 2001 From: prachi Date: Mon, 14 May 2012 15:37:45 -0700 Subject: [PATCH] CS-14856: upgrade script:schema-2214to30.sql fails while upgrading CS 2.2.14 to Bonita http://bugs.cloudstack.org/browse/CS-14856 - Problem is with the awsapi webapp being loaded first in tomcat before cloudstack webapp. There is no way this order can be controlled. - We are not supporting upgrades for awsapi feature - The solution is awsapi will check if the db exists during initialization. If not, the webapp will fail to load. Error loading the webapp can be seen in the catalina.out output. - But this should not affect CloudStack db upgrade. --- awsapi/conf/CloudStack.cfg.xml | 1 - awsapi/conf/hibernate.cfg.xml | 1 - .../lifecycle/ServiceEngineLifecycle.java | 17 +++++++++++++++-- .../bridge/persist/dao/UserCredentialsDao.java | 8 ++------ .../cloud/bridge/service/EC2MainServlet.java | 9 ++++----- .../com/cloud/bridge/service/S3RestServlet.java | 6 +++--- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/awsapi/conf/CloudStack.cfg.xml b/awsapi/conf/CloudStack.cfg.xml index cad7398a6f0..00bc7832519 100644 --- a/awsapi/conf/CloudStack.cfg.xml +++ b/awsapi/conf/CloudStack.cfg.xml @@ -10,7 +10,6 @@ 2 - update true org.hibernate.dialect.MySQLDialect diff --git a/awsapi/conf/hibernate.cfg.xml b/awsapi/conf/hibernate.cfg.xml index 3542cd23bc2..bc445bd4f1d 100644 --- a/awsapi/conf/hibernate.cfg.xml +++ b/awsapi/conf/hibernate.cfg.xml @@ -10,7 +10,6 @@ 2 - update true org.hibernate.dialect.MySQLDialect diff --git a/awsapi/src/com/cloud/bridge/lifecycle/ServiceEngineLifecycle.java b/awsapi/src/com/cloud/bridge/lifecycle/ServiceEngineLifecycle.java index 83060b6a1cf..099715c6663 100644 --- a/awsapi/src/com/cloud/bridge/lifecycle/ServiceEngineLifecycle.java +++ b/awsapi/src/com/cloud/bridge/lifecycle/ServiceEngineLifecycle.java @@ -18,6 +18,9 @@ package com.cloud.bridge.lifecycle; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.description.AxisService; import org.apache.axis2.engine.ServiceLifeCycle; +import org.apache.log4j.Logger; + +import com.cloud.bridge.persist.dao.UserCredentialsDao; import com.cloud.bridge.service.controller.s3.ServiceProvider; @@ -29,13 +32,23 @@ import com.cloud.bridge.service.controller.s3.ServiceProvider; */ public class ServiceEngineLifecycle implements ServiceLifeCycle { private static final long serialVersionUID = -249114759030608486L; + public static final Logger logger = Logger.getLogger(ServiceEngineLifecycle.class); + private static boolean initialized = false; public void startUp(ConfigurationContext config, AxisService service) { // initialize service provider during Axis engine startup - ServiceProvider.getInstance(); + try{ + UserCredentialsDao.preCheckTableExistence(); + ServiceProvider.getInstance(); + ServiceEngineLifecycle.initialized = true; + }catch(Exception e){ + logger.error("Error initializing awsapi: "+ e.getMessage()); + } } public void shutDown(ConfigurationContext config, AxisService service) { - ServiceProvider.getInstance().shutdown(); + if(ServiceEngineLifecycle.initialized){ + ServiceProvider.getInstance().shutdown(); + } } }; diff --git a/awsapi/src/com/cloud/bridge/persist/dao/UserCredentialsDao.java b/awsapi/src/com/cloud/bridge/persist/dao/UserCredentialsDao.java index 2300535a22f..13b6d741a05 100644 --- a/awsapi/src/com/cloud/bridge/persist/dao/UserCredentialsDao.java +++ b/awsapi/src/com/cloud/bridge/persist/dao/UserCredentialsDao.java @@ -139,13 +139,9 @@ public class UserCredentialsDao extends BaseDao{ conn = null; } - public static void preCheckTableExistence() { + public static void preCheckTableExistence() throws Exception{ UserCredentialsDao dao = new UserCredentialsDao(); - try { - dao.checkTableExistence(); - } catch (Exception e) { - e.printStackTrace(); - } + dao.checkTableExistence(); } private void checkTableExistence() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { diff --git a/awsapi/src/com/cloud/bridge/service/EC2MainServlet.java b/awsapi/src/com/cloud/bridge/service/EC2MainServlet.java index 6448c84c15c..a25ea037100 100644 --- a/awsapi/src/com/cloud/bridge/service/EC2MainServlet.java +++ b/awsapi/src/com/cloud/bridge/service/EC2MainServlet.java @@ -40,12 +40,11 @@ public class EC2MainServlet extends HttpServlet{ if(value != null){ isEC2APIEnabled = Boolean.valueOf(value); } - - }finally { - PersistContext.commitTransaction(true); + PersistContext.commitTransaction(true); PersistContext.closeSession(true); - } - + }catch(Exception e){ + throw new ServletException("Error initializing awsapi: " + e.getMessage()); + } } protected void doGet(HttpServletRequest req, HttpServletResponse resp) { diff --git a/awsapi/src/com/cloud/bridge/service/S3RestServlet.java b/awsapi/src/com/cloud/bridge/service/S3RestServlet.java index 27b782e407b..99365591474 100644 --- a/awsapi/src/com/cloud/bridge/service/S3RestServlet.java +++ b/awsapi/src/com/cloud/bridge/service/S3RestServlet.java @@ -115,10 +115,10 @@ public class S3RestServlet extends HttpServlet { if(value != null) { isS3APIEnabled = Boolean.valueOf(value); } - - }finally { - PersistContext.commitTransaction(true); + PersistContext.commitTransaction(true); PersistContext.closeSession(true); + }catch(Exception e){ + throw new ServletException("Error initializing awsapi: " + e.getMessage()); } }