From: <cl...@hy...> - 2007-09-10 04:57:50
|
Author: clee Date: 2007-09-09 21:57:43 -0700 (Sun, 09 Sep 2007) New Revision: 5863 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=5863 Modified: trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java trunk/src/org/hyperic/hq/appdef/server/session/ServerManagerEJBImpl.java trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java Log: [HHQ-552] Remove compatible groups of removed types Modified: trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java 2007-09-09 12:52:28 UTC (rev 5862) +++ trunk/src/org/hyperic/hq/appdef/server/session/PlatformManagerEJBImpl.java 2007-09-10 04:57:43 UTC (rev 5863) @@ -48,8 +48,11 @@ import org.hyperic.hq.appdef.shared.AIQueueManagerUtil; import org.hyperic.hq.appdef.shared.AppdefDuplicateFQDNException; import org.hyperic.hq.appdef.shared.AppdefDuplicateNameException; +import org.hyperic.hq.appdef.shared.AppdefEntityConstants; import org.hyperic.hq.appdef.shared.AppdefEntityID; import org.hyperic.hq.appdef.shared.AppdefEntityNotFoundException; +import org.hyperic.hq.appdef.shared.AppdefGroupManagerLocal; +import org.hyperic.hq.appdef.shared.AppdefGroupNotFoundException; import org.hyperic.hq.appdef.shared.AppdefGroupValue; import org.hyperic.hq.appdef.shared.ApplicationNotFoundException; import org.hyperic.hq.appdef.shared.IpValue; @@ -64,6 +67,8 @@ import org.hyperic.hq.appdef.shared.PlatformManagerLocal; import org.hyperic.hq.appdef.shared.PlatformManagerUtil; import org.hyperic.hq.appdef.shared.ServerManagerLocal; +import org.hyperic.hq.appdef.shared.pager.AppdefGroupPagerFilterGrpEntRes; +import org.hyperic.hq.appdef.shared.pager.AppdefPagerFilter; import org.hyperic.hq.appdef.Agent; import org.hyperic.hq.appdef.AppService; import org.hyperic.hq.appdef.ConfigResponseDB; @@ -74,6 +79,7 @@ import org.hyperic.hq.authz.shared.ResourceValue; import org.hyperic.hq.common.ApplicationException; import org.hyperic.hq.common.SystemException; +import org.hyperic.hq.common.VetoException; import org.hyperic.hq.common.shared.ProductProperties; import org.hyperic.hq.product.PlatformTypeInfo; import org.hyperic.util.pager.PageControl; @@ -1191,7 +1197,9 @@ } PlatformTypeDAO ptLHome = getPlatformTypeDAO(); Collection curPlatforms = ptLHome.findByPlugin(plugin); - + + AuthzSubjectValue overlord = null; + AppdefGroupManagerLocal grpMgr = AppdefGroupManagerEJBImpl.getOne(); for (Iterator i = curPlatforms.iterator(); i.hasNext();) { PlatformType ptlocal = (PlatformType) i.next(); String localName = ptlocal.getName(); @@ -1200,8 +1208,55 @@ // See if this exists if (pinfo == null) { - // Remove platforms which are not supposed to exist - _log.debug("Removing PlatformType: " + localName); + try { + // Remove platforms which are not supposed to exist + _log.debug("Removing PlatformType: " + localName); + // Get overlord + if (overlord == null) + overlord = getOverlord(); + + // Find resource groups of this type and remove + AppdefGroupPagerFilterGrpEntRes filter = + new AppdefGroupPagerFilterGrpEntRes ( + AppdefEntityConstants.APPDEF_TYPE_PLATFORM, + ptlocal.getId().intValue(), true); + + List groups = grpMgr + .findAllGroups(overlord, PageControl.PAGE_ALL, + new AppdefPagerFilter[] { filter }); + for (Iterator grpIt = groups.iterator(); + grpIt.hasNext(); ) { + try { + AppdefGroupValue grp = + (AppdefGroupValue) grpIt.next(); + grpMgr.deleteGroup(overlord, grp.getId()); + } catch (AppdefGroupNotFoundException e) { + /* assert false : + "Delete based on a group should not " + + "result in AppdefGroupNotFoundException";*/ + } catch (VetoException e) { + // Why can't we delete? + log.error("Cannot delete group", e); + } + } + + // Remove all services + for (Iterator pltIt = ptlocal.getPlatforms().iterator(); + pltIt.hasNext(); ) { + Platform pltLocal = (Platform) pltIt.next(); + try { + removePlatform(overlord, pltLocal); + } catch (PlatformNotFoundException e) { + assert false : + "Delete based on a platform should not " + + "result in PlatformNotFoundException"; + } + } + } catch (PermissionException e) { + assert false : + "Overlord should not run into PermissionException"; + } + ptLHome.remove(ptlocal); } else { String curName = ptlocal.getName(); Modified: trunk/src/org/hyperic/hq/appdef/server/session/ServerManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ServerManagerEJBImpl.java 2007-09-09 12:52:28 UTC (rev 5862) +++ trunk/src/org/hyperic/hq/appdef/server/session/ServerManagerEJBImpl.java 2007-09-10 04:57:43 UTC (rev 5863) @@ -44,7 +44,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hyperic.hq.appdef.shared.AppdefDuplicateNameException; +import org.hyperic.hq.appdef.shared.AppdefEntityConstants; import org.hyperic.hq.appdef.shared.AppdefEntityID; +import org.hyperic.hq.appdef.shared.AppdefGroupManagerLocal; +import org.hyperic.hq.appdef.shared.AppdefGroupNotFoundException; +import org.hyperic.hq.appdef.shared.AppdefGroupValue; import org.hyperic.hq.appdef.shared.ApplicationNotFoundException; import org.hyperic.hq.appdef.shared.PlatformNotFoundException; import org.hyperic.hq.appdef.shared.ServerLightValue; @@ -57,12 +61,15 @@ import org.hyperic.hq.appdef.shared.ServerManagerLocal; import org.hyperic.hq.appdef.shared.ServerManagerUtil; import org.hyperic.hq.appdef.shared.PlatformManagerLocal; +import org.hyperic.hq.appdef.shared.pager.AppdefGroupPagerFilterGrpEntRes; +import org.hyperic.hq.appdef.shared.pager.AppdefPagerFilter; import org.hyperic.hq.appdef.AppService; import org.hyperic.hq.authz.shared.AuthzConstants; import org.hyperic.hq.authz.shared.AuthzSubjectValue; import org.hyperic.hq.authz.shared.PermissionException; import org.hyperic.hq.authz.shared.ResourceValue; import org.hyperic.hq.common.SystemException; +import org.hyperic.hq.common.VetoException; import org.hyperic.hq.product.ServerTypeInfo; import org.hyperic.util.ArrayUtil; import org.hyperic.util.pager.PageControl; @@ -1202,7 +1209,9 @@ ServerTypeDAO stLHome = getServerTypeDAO(); Collection curServers = stLHome.findByPlugin(plugin); - + + AuthzSubjectValue overlord = null; + AppdefGroupManagerLocal grpMgr = AppdefGroupManagerEJBImpl.getOne(); for (Iterator i = curServers.iterator(); i.hasNext();) { ServerType stlocal = (ServerType) i.next(); String serverName = stlocal.getName(); @@ -1212,6 +1221,54 @@ // See if this exists if (sinfo == null) { log.debug("Removing ServerType: " + serverName); + + // Get overlord + if (overlord == null) + overlord = getOverlord(); + + // Find resource groups of this type and remove + AppdefGroupPagerFilterGrpEntRes filter = + new AppdefGroupPagerFilterGrpEntRes ( + AppdefEntityConstants.APPDEF_TYPE_SERVER, + stlocal.getId().intValue(), true); + + try { + List groups = grpMgr + .findAllGroups(overlord, PageControl.PAGE_ALL, + new AppdefPagerFilter[] { filter }); + for (Iterator grpIt = groups.iterator(); + grpIt.hasNext(); ) { + try { + AppdefGroupValue grp = + (AppdefGroupValue) grpIt.next(); + grpMgr.deleteGroup(overlord, grp.getId()); + } catch (AppdefGroupNotFoundException e) { + assert false : + "Delete based on a group should not " + + "result in AppdefGroupNotFoundException"; + } catch (VetoException e) { + // Why can't we delete? + log.error("Cannot delete group", e); + } + } + + // Remove all services + for (Iterator svrIt = stlocal.getServers().iterator(); + svrIt.hasNext(); ) { + Server svrLocal = (Server) svrIt.next(); + try { + removeServer(overlord, svrLocal); + } catch (ServerNotFoundException e) { + assert false : + "Delete based on a server should not " + + "result in ServerNotFoundException"; + } + } + } catch (PermissionException e) { + assert false : + "Overlord should not run into PermissionException"; + } + stLHome.remove(stlocal); } else { String curDesc = stlocal.getDescription(); Modified: trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java 2007-09-09 12:52:28 UTC (rev 5862) +++ trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java 2007-09-10 04:57:43 UTC (rev 5863) @@ -47,6 +47,7 @@ import org.hyperic.hq.appdef.shared.AppdefEntityConstants; import org.hyperic.hq.appdef.shared.AppdefEntityID; import org.hyperic.hq.appdef.shared.AppdefEntityNotFoundException; +import org.hyperic.hq.appdef.shared.AppdefGroupManagerLocal; import org.hyperic.hq.appdef.shared.AppdefGroupNotFoundException; import org.hyperic.hq.appdef.shared.AppdefGroupValue; import org.hyperic.hq.appdef.shared.ApplicationNotFoundException; @@ -63,6 +64,8 @@ import org.hyperic.hq.appdef.shared.ValidationException; import org.hyperic.hq.appdef.shared.ServiceManagerLocal; import org.hyperic.hq.appdef.shared.ServiceManagerUtil; +import org.hyperic.hq.appdef.shared.pager.AppdefGroupPagerFilterGrpEntRes; +import org.hyperic.hq.appdef.shared.pager.AppdefPagerFilter; import org.hyperic.hq.appdef.AppService; import org.hyperic.hq.appdef.ServiceCluster; import org.hyperic.hq.authz.shared.AuthzConstants; @@ -1409,6 +1412,7 @@ HashMap serverTypes = new HashMap(); ServiceTypeDAO stLHome = getServiceTypeDAO(); + AppdefGroupManagerLocal grpMgr = AppdefGroupManagerEJBImpl.getOne(); try { Collection curServices = stLHome.findByPlugin(plugin); ServerTypeDAO stHome = getServerTypeDAO(); @@ -1429,20 +1433,44 @@ // Get overlord if (overlord == null) overlord = getOverlord(); + + // Find resource groups of this type and remove + AppdefGroupPagerFilterGrpEntRes filter = + new AppdefGroupPagerFilterGrpEntRes ( + AppdefEntityConstants.APPDEF_TYPE_SERVICE, + stlocal.getId().intValue(), true); - // Remove all services - for (Iterator svcIt = stlocal.getServices().iterator(); - svcIt.hasNext(); ) { - Service svcLocal = (Service) svcIt.next(); - try { + try { + List groups = grpMgr + .findAllGroups(overlord, PageControl.PAGE_ALL, + new AppdefPagerFilter[] { filter }); + for (Iterator grpIt = groups.iterator(); + grpIt.hasNext(); ) { + try { + AppdefGroupValue grp = + (AppdefGroupValue) grpIt.next(); + grpMgr.deleteGroup(overlord, grp.getId()); + } catch (AppdefGroupNotFoundException e) { + assert false : + "Delete based on a group should not " + + "result in AppdefGroupNotFoundException"; + } catch (VetoException e) { + // Why can't we delete? + log.error("Cannot delete group", e); + } + } + + // Remove all services + for (Iterator svcIt = stlocal.getServices().iterator(); + svcIt.hasNext(); ) { + Service svcLocal = (Service) svcIt.next(); removeService(overlord, svcLocal); - } catch (PermissionException e) { - // This should never happen, we're the overlord - throw new SystemException(e); - } + } + } catch (PermissionException e) { + assert false : + "Overlord should not run into PermissionException"; } - - + stLHome.remove(stlocal); } else { // Just update it |