From: <cl...@hy...> - 2008-05-05 22:02:47
|
Author: clee Date: 2008-05-05 15:02:42 -0700 (Mon, 05 May 2008) New Revision: 9343 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=9343 Modified: trunk/src/org/hyperic/hq/appdef/server/session/AppdefStartupListener.java trunk/src/org/hyperic/hq/appdef/server/session/ApplicationDAO.java trunk/src/org/hyperic/hq/appdef/server/session/ApplicationManagerEJBImpl.java trunk/src/org/hyperic/hq/appdef/server/session/PlatformDAO.java trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java trunk/src/org/hyperic/hq/appdef/server/session/ServerDAO.java trunk/src/org/hyperic/hq/appdef/server/session/ServerManagerEJBImpl.java trunk/src/org/hyperic/hq/appdef/server/session/ServiceDAO.java trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java Log: Add ResourceDeleteCallback to null out Resources when they are deleted Modified: trunk/src/org/hyperic/hq/appdef/server/session/AppdefStartupListener.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/AppdefStartupListener.java 2008-05-05 20:52:30 UTC (rev 9342) +++ trunk/src/org/hyperic/hq/appdef/server/session/AppdefStartupListener.java 2008-05-05 22:02:42 UTC (rev 9343) @@ -6,7 +6,7 @@ * normal use of the program, and does *not* fall under the heading of * "derived work". * - * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. + * Copyright (C) [2004-2008], Hyperic, Inc. * This file is part of HQ. * * HQ is free software; you can redistribute it and/or modify @@ -26,8 +26,12 @@ package org.hyperic.hq.appdef.server.session; import org.hyperic.hq.appdef.galerts.ResourceAuxLogProvider; +import org.hyperic.hq.appdef.shared.AppdefEntityConstants; import org.hyperic.hq.application.HQApp; import org.hyperic.hq.application.StartupListener; +import org.hyperic.hq.authz.server.session.Resource; +import org.hyperic.hq.authz.server.session.ResourceDeleteCallback; +import org.hyperic.hq.common.VetoException; public class AppdefStartupListener implements StartupListener @@ -48,6 +52,28 @@ app.registerCallbackCaller(ClusterDeleteCallback.class); _agentCreateCallback = (AgentCreateCallback) app.registerCallbackCaller(AgentCreateCallback.class); + app.registerCallbackListener(ResourceDeleteCallback.class, + new ResourceDeleteCallback() { + + public void preResourceDelete(Resource r) + throws VetoException { + switch (r.getResourceType().getAppdefType()) { + case AppdefEntityConstants.APPDEF_TYPE_PLATFORM: + PlatformManagerEJBImpl.getOne().handleResourceDelete(r); + break; + case AppdefEntityConstants.APPDEF_TYPE_SERVER: + ServerManagerEJBImpl.getOne().handleResourceDelete(r); + break; + case AppdefEntityConstants.APPDEF_TYPE_SERVICE: + ServiceManagerEJBImpl.getOne().handleResourceDelete(r); + break; + case AppdefEntityConstants.APPDEF_TYPE_APPLICATION: + ApplicationManagerEJBImpl.getOne() + .handleResourceDelete(r); + break; + } + } + }); } ApplicationManagerEJBImpl.getOne().startup(); } Modified: trunk/src/org/hyperic/hq/appdef/server/session/ApplicationDAO.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ApplicationDAO.java 2008-05-05 20:52:30 UTC (rev 9342) +++ trunk/src/org/hyperic/hq/appdef/server/session/ApplicationDAO.java 2008-05-05 22:02:42 UTC (rev 9343) @@ -38,6 +38,7 @@ import org.hyperic.hq.appdef.shared.ApplicationValue; import org.hyperic.hq.appdef.shared.DependencyNode; import org.hyperic.hq.appdef.shared.DependencyTree; +import org.hyperic.hq.authz.server.session.Resource; import org.hyperic.hq.authz.server.session.ResourceGroup; import org.hyperic.hq.dao.AppServiceDAO; import org.hyperic.hq.dao.AppSvcDependencyDAO; @@ -306,4 +307,10 @@ .setParameter("group", g) .list(); } + + void clearResource(Resource res) { + createQuery("update Application set resource = null where id = ?") + .setParameter(0, res.getInstanceId()) + .executeUpdate(); + } } Modified: trunk/src/org/hyperic/hq/appdef/server/session/ApplicationManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ApplicationManagerEJBImpl.java 2008-05-05 20:52:30 UTC (rev 9342) +++ trunk/src/org/hyperic/hq/appdef/server/session/ApplicationManagerEJBImpl.java 2008-05-05 22:02:42 UTC (rev 9343) @@ -266,6 +266,13 @@ } } + /** + * @ejb:interface-method + */ + public void handleResourceDelete(Resource resource) { + getApplicationDAO().clearResource(resource); + } + private AppServiceDAO getAppServiceDAO() { return new AppServiceDAO(DAOFactory.getDAOFactory()); } Modified: trunk/src/org/hyperic/hq/appdef/server/session/PlatformDAO.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/PlatformDAO.java 2008-05-05 20:52:30 UTC (rev 9342) +++ trunk/src/org/hyperic/hq/appdef/server/session/PlatformDAO.java 2008-05-05 22:02:42 UTC (rev 9343) @@ -362,4 +362,10 @@ return (Number)getSession().createQuery("select count(*) from Platform") .uniqueResult(); } + + void clearResource(Resource res) { + createQuery("update Platform set resource = null where id = ?") + .setParameter(0, res.getInstanceId()) + .executeUpdate(); + } } Modified: trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java 2008-05-05 20:52:30 UTC (rev 9342) +++ trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java 2008-05-05 22:02:42 UTC (rev 9343) @@ -335,7 +335,14 @@ if (pushed) AuditManagerEJBImpl.getOne().popContainer(false); } - } + } + + /** + * @ejb:interface-method + */ + public void handleResourceDelete(Resource resource) { + getPlatformDAO().clearResource(resource); + } /** * Create a Platform of a specified type Modified: trunk/src/org/hyperic/hq/appdef/server/session/ServerDAO.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ServerDAO.java 2008-05-05 20:52:30 UTC (rev 9342) +++ trunk/src/org/hyperic/hq/appdef/server/session/ServerDAO.java 2008-05-05 22:02:42 UTC (rev 9343) @@ -243,4 +243,10 @@ "where st.virtual=false"; return (Number)getSession().createQuery(sql).uniqueResult(); } + + void clearResource(Resource res) { + createQuery("update Server set resource = null where id = ?") + .setParameter(0, res.getInstanceId()) + .executeUpdate(); + } } Modified: trunk/src/org/hyperic/hq/appdef/server/session/ServerManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ServerManagerEJBImpl.java 2008-05-05 20:52:30 UTC (rev 9342) +++ trunk/src/org/hyperic/hq/appdef/server/session/ServerManagerEJBImpl.java 2008-05-05 22:02:42 UTC (rev 9343) @@ -336,6 +336,13 @@ } /** + * @ejb:interface-method + */ + public void handleResourceDelete(Resource resource) { + getServerDAO().clearResource(resource); + } + + /** * Find all server types * @return list of serverTypeValues * @ejb:interface-method Modified: trunk/src/org/hyperic/hq/appdef/server/session/ServiceDAO.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ServiceDAO.java 2008-05-05 20:52:30 UTC (rev 9342) +++ trunk/src/org/hyperic/hq/appdef/server/session/ServiceDAO.java 2008-05-05 22:02:42 UTC (rev 9343) @@ -346,4 +346,10 @@ return (Number)getSession().createQuery("select count(*) from Service") .uniqueResult(); } + + void clearResource(Resource res) { + createQuery("update Service set resource = null where id = ?") + .setParameter(0, res.getInstanceId()) + .executeUpdate(); + } } Modified: trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java 2008-05-05 20:52:30 UTC (rev 9342) +++ trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java 2008-05-05 22:02:42 UTC (rev 9343) @@ -1467,6 +1467,13 @@ } /** + * @ejb:interface-method + */ + public void handleResourceDelete(Resource resource) { + getServiceDAO().clearResource(resource); + } + + /** * Returns a list of 2 element arrays. The first element is the name of * the service type, the second element is the # of services of that * type in the inventory. |