diff options
| author | Selvasundaram <selvam@gluster.com> | 2011-08-18 22:55:20 +0530 |
|---|---|---|
| committer | Selvasundaram <selvam@gluster.com> | 2011-08-18 22:55:20 +0530 |
| commit | 8d5fd6a259f8d4c8f51ff6011f0018c8dc884134 (patch) | |
| tree | 0c796371fe4559b8301d1dde2eb31a4f8c2c90f5 | |
| parent | d905c66247f3f0ada455544388a7700d088cbb7e (diff) | |
| parent | 3db6ac956fea2138d2a1b09022612b8c6ead2df9 (diff) | |
Merge branch 'master' of github.com:gluster/console
6 files changed, 137 insertions, 85 deletions
diff --git a/src/com.gluster.storage.management.console/plugin.xml b/src/com.gluster.storage.management.console/plugin.xml index 6fb95258..cf3c8eb3 100644 --- a/src/com.gluster.storage.management.console/plugin.xml +++ b/src/com.gluster.storage.management.console/plugin.xml @@ -1213,30 +1213,6 @@ </view> <view closeable="false" - id="com.gluster.storage.management.console.views.details.DetailsView" - minimized="false" - moveable="false" - ratio="0.70f" - relationship="right" - relative="com.gluster.storage.management.console.views.navigator.NavigationView" - showTitle="false" - standalone="false" - visible="false"> - </view> - <view - closeable="true" - id="org.eclipse.ui.views.ProgressView" - minimized="false" - moveable="false" - ratio="0.80f" - relationship="bottom" - relative="com.gluster.storage.management.console.views.ClusterSummaryView" - showTitle="true" - standalone="true" - visible="false"> - </view> - <view - closeable="false" id="com.gluster.storage.management.console.views.DiscoveredServersView" minimized="false" moveable="false" @@ -1253,8 +1229,8 @@ minimized="false" moveable="false" ratio="0.30f" - relationship="right" - relative="com.gluster.storage.management.console.views.navigator.NavigationView" + relationship="stack" + relative="com.gluster.storage.management.console.views.ClusterSummaryView" showTitle="true" standalone="false" visible="false"> diff --git a/src/com.gluster.storage.management.gateway/WebContent/WEB-INF/web.xml b/src/com.gluster.storage.management.gateway/WebContent/WEB-INF/web.xml index 54872639..750ef171 100644 --- a/src/com.gluster.storage.management.gateway/WebContent/WEB-INF/web.xml +++ b/src/com.gluster.storage.management.gateway/WebContent/WEB-INF/web.xml @@ -22,6 +22,9 @@ <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> + <listener> + <listener-class>com.gluster.storage.management.gateway.listeners.ShutdownListener</listener-class> + </listener> <servlet> <servlet-name>gluster-resources-1.0</servlet-name> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class> diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/listeners/ShutdownListener.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/listeners/ShutdownListener.java new file mode 100644 index 00000000..23ae36ae --- /dev/null +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/listeners/ShutdownListener.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Gluster Management Console 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 Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + *******************************************************************************/ +package com.gluster.storage.management.gateway.listeners; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import com.gluster.storage.management.gateway.utils.DBUtil; + +/** + * Shuts down the Derby database when gateway is being stopped. + */ +public class ShutdownListener implements ServletContextListener { + + /* (non-Javadoc) + * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) + */ + @Override + public void contextDestroyed(ServletContextEvent arg0) { + // Embedded derby must be shut down when the gateway stops. + DBUtil.shutdownDerby(); + } + + /* (non-Javadoc) + * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) + */ + @Override + public void contextInitialized(ServletContextEvent arg0) { + } +} diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitServerTask.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitServerTask.java index b29f271f..db95e8b6 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitServerTask.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/tasks/InitServerTask.java @@ -149,18 +149,6 @@ public class InitServerTask extends JdbcDaoSupport { // Database not created yet. Create it! initDatabase(); } - - // For development time debugging. To be removed later. - List<ClusterInfo> clusters = clusterDao.findAll(); - logger.info(clusters.size()); - - if (clusters.size() > 0) { - for (ClusterInfo cluster : clusters) { - logger.info("Cluster: [" + cluster.getId() + "][" + cluster.getName() + "]"); - } - } else { - - } } private void upgradeData(String fromVersion, String toVersion) { diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/DBUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/DBUtil.java new file mode 100644 index 00000000..e224b4cb --- /dev/null +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/DBUtil.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Gluster Management Console 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 Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + *******************************************************************************/ +package com.gluster.storage.management.gateway.utils; + +import java.sql.DriverManager; +import java.sql.SQLException; + +import org.apache.derby.jdbc.EmbeddedDriver; +import org.apache.log4j.Logger; + +import com.gluster.storage.management.core.constants.CoreConstants; + +/** + * + */ +public class DBUtil { + private static final Logger logger = Logger.getLogger(DBUtil.class); + public static void shutdownDerby() { + try { + // the shutdown=true attribute shuts down Derby + DriverManager.getConnection("jdbc:derby:;shutdown=true"); + + // To shut down a specific database only, but keep the + // engine running (for example for connecting to other + // databases), specify a database in the connection URL: + //DriverManager.getConnection("jdbc:derby:" + dbName + ";shutdown=true"); + } catch (Exception e) { + if(e instanceof SQLException) { + SQLException se = (SQLException) e; + if (((se.getErrorCode() == 50000) && ("XJ015".equals(se.getSQLState())))) { + // we got the expected exception + logger.info("Derby shut down normally"); + // Note that for single database shutdown, the expected + // SQL state is "08006", and the error code is 45000. + } else { + // if the error code or SQLState is different, we have + // an unexpected exception (shutdown failed) + logger.error("Derby did not shut down normally!" + inspectSQLException(se), se); + } + } else { + logger.error("Derby did not shut down normally! [" + e.getMessage() + "]", e); + } + } + // force garbage collection to unload the EmbeddedDriver + // so Derby can be restarted + System.gc(); + } + + /** + * Extracts details of an SQLException chain to <code>String</code>. + * Details included are SQL State, Error code, Exception message. + * + * @param e the SQLException from which to print details. + */ + private static String inspectSQLException(SQLException e) + { + // Unwraps the entire exception chain to unveil the real cause of the + // Exception. + String errMsg = ""; + while (e != null) + { + errMsg += "\n----- SQLException -----" + CoreConstants.NEWLINE + " SQL State: " + e.getSQLState() + + CoreConstants.NEWLINE + " Error Code: " + e.getErrorCode() + CoreConstants.NEWLINE + + " Message: " + e.getMessage(); + e = e.getNextException(); + } + return errMsg; + } +} diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/PasswordManager.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/PasswordManager.java index df3aeff7..a3593d0c 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/PasswordManager.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/PasswordManager.java @@ -49,7 +49,7 @@ public class PasswordManager { System.out.println("Password for user [" + username + "] reset successsfully to default value of [" + CoreConstants.DEFAULT_PASSWORD + "]." + CoreConstants.NEWLINE); - shutdownDerby(); + DBUtil.shutdownDerby(); } catch (Exception e) { System.err.println(CoreConstants.NEWLINE + CoreConstants.NEWLINE + "Password reset for user [" + username + "] failed! " + CoreConstants.NEWLINE @@ -59,52 +59,6 @@ public class PasswordManager { } } - private void shutdownDerby() { - try { - // the shutdown=true attribute shuts down Derby - DriverManager.getConnection("jdbc:derby:;shutdown=true"); - - // To shut down a specific database only, but keep the - // engine running (for example for connecting to other - // databases), specify a database in the connection URL: - //DriverManager.getConnection("jdbc:derby:" + dbName + ";shutdown=true"); - } catch (SQLException se) { - if (((se.getErrorCode() == 50000) && ("XJ015".equals(se.getSQLState())))) { - // we got the expected exception - System.out.println("Derby shut down normally"); - // Note that for single database shutdown, the expected - // SQL state is "08006", and the error code is 45000. - } else { - // if the error code or SQLState is different, we have - // an unexpected exception (shutdown failed) - System.err.println("Derby did not shut down normally"); - printSQLException(se); - } - } - } - - /** - * Prints details of an SQLException chain to <code>System.err</code>. - * Details included are SQL State, Error code, Exception message. - * - * @param e the SQLException from which to print details. - */ - private void printSQLException(SQLException e) - { - // Unwraps the entire exception chain to unveil the real cause of the - // Exception. - while (e != null) - { - System.err.println("\n----- SQLException -----"); - System.err.println(" SQL State: " + e.getSQLState()); - System.err.println(" Error Code: " + e.getErrorCode()); - System.err.println(" Message: " + e.getMessage()); - // for stack traces, refer to derby.log or uncomment this: - //e.printStackTrace(System.err); - e = e.getNextException(); - } - } - private ReflectionSaltSource createSaltSource() { ReflectionSaltSource saltSource = new ReflectionSaltSource(); saltSource.setUserPropertyToUse("username"); |
