From: <cl...@hy...> - 2008-09-06 04:25:02
|
Author: clee Date: 2008-09-05 21:24:59 -0700 (Fri, 05 Sep 2008) New Revision: 11017 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=11017 Removed: trunk/src/org/hyperic/hq/appdef/server/session/ClusterDeleteCallback.java Modified: trunk/src/org/hyperic/hq/appdef/server/session/ApplicationManagerEJBImpl.java Log: [HHQ-2115] Implement GroupChangeCallback rather than ClusterDeleteCallback to clean up AppServices Modified: trunk/src/org/hyperic/hq/appdef/server/session/ApplicationManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ApplicationManagerEJBImpl.java 2008-09-05 21:49:06 UTC (rev 11016) +++ trunk/src/org/hyperic/hq/appdef/server/session/ApplicationManagerEJBImpl.java 2008-09-06 04:24:59 UTC (rev 11017) @@ -58,6 +58,7 @@ import org.hyperic.hq.appdef.ServiceCluster; import org.hyperic.hq.application.HQApp; import org.hyperic.hq.authz.server.session.AuthzSubject; +import org.hyperic.hq.authz.server.session.GroupChangeCallback; import org.hyperic.hq.authz.server.session.Resource; import org.hyperic.hq.authz.server.session.ResourceGroup; import org.hyperic.hq.authz.server.session.ResourceManagerEJBImpl; @@ -74,7 +75,6 @@ import org.hyperic.util.pager.Pager; import org.hyperic.util.pager.SortAttribute; import org.hyperic.dao.DAOFactory; -import org.hyperic.hq.dao.AppServiceDAO; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -757,32 +757,35 @@ app.setResource(resource); } - private class GroupDeleteWatcher - implements ClusterDeleteCallback - { - public void preDelete(ServiceCluster c) throws VetoException { - ResourceBundle b = - ResourceBundle.getBundle("org.hyperic.hq.appdef.Resources"); - - Collection apps = getApplicationDAO().findUsingGroup(c.getGroup()); - - if (apps.size() != 0) { - throw new VetoException(b.getString("cluster.inUse")); - } - } - - public void groupMembersChanged(ResourceGroup g) { - } - } - /** * @ejb:interface-method */ public void startup() { log.info("Application manager starting up!"); - HQApp.getInstance().registerCallbackListener(ClusterDeleteCallback.class, - new GroupDeleteWatcher()); + HQApp.getInstance().registerCallbackListener(GroupChangeCallback.class, + new GroupChangeCallback() { + public void preGroupDelete(ResourceGroup g) + throws VetoException { + Collection apps = getApplicationDAO().findUsingGroup(g); + AppServiceDAO dao = getAppServiceDAO(); + for (Iterator it = apps.iterator(); it.hasNext(); ) { + Application app = (Application) it.next(); + // Find the app service and remove it + try { + AppService svc = dao.findByAppAndCluster(app, g); + app.getAppServices().remove(svc); + dao.remove(svc); + } catch (ObjectNotFoundException e) { + continue; + } + } + } + + public void postGroupCreate(ResourceGroup g) {} + + public void groupMembersChanged(ResourceGroup g) {} + }); } public static ApplicationManagerLocal getOne() { Deleted: trunk/src/org/hyperic/hq/appdef/server/session/ClusterDeleteCallback.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ClusterDeleteCallback.java 2008-09-05 21:49:06 UTC (rev 11016) +++ trunk/src/org/hyperic/hq/appdef/server/session/ClusterDeleteCallback.java 2008-09-06 04:24:59 UTC (rev 11017) @@ -1,36 +0,0 @@ -/* - * NOTE: This copyright does *not* cover user programs that use HQ - * program services by normal system calls through the application - * program interfaces provided as part of the Hyperic Plug-in Development - * Kit or the Hyperic Client Development Kit - this is merely considered - * normal use of the program, and does *not* fall under the heading of - * "derived work". - * - * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. - * This file is part of HQ. - * - * HQ is free software; you can redistribute it and/or modify - * it under the terms version 2 of the GNU General Public License as - * published by the Free Software Foundation. This program 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 General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -package org.hyperic.hq.appdef.server.session; - -import org.hyperic.hq.appdef.ServiceCluster; -import org.hyperic.hq.common.VetoException; - -public interface ClusterDeleteCallback { - /** - * Called before a group is deleted, to allow other people to disallow it. - */ - void preDelete(ServiceCluster c) throws VetoException; -} |