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()); } }