From: <cl...@hy...> - 2008-10-23 16:57:46
|
Author: clee Date: 2008-10-23 09:57:35 -0700 (Thu, 23 Oct 2008) New Revision: 11576 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=11576 Modified: trunk/src/org/hyperic/hq/appdef/server/session/ResourceTreeGenerator.java trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java trunk/src/org/hyperic/hq/appdef/shared/resourceTree/PlatformNode.java trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ResourceTree.java trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ServerNode.java trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ServiceNode.java trunk/src/org/hyperic/hq/bizapp/server/session/LatherDispatcher.java Log: Store POJOs in PlatformNode and ServiceNode as most of the time we're just getting the IDs of those objects, no point in doing extra work Modified: trunk/src/org/hyperic/hq/appdef/server/session/ResourceTreeGenerator.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ResourceTreeGenerator.java 2008-10-23 15:29:28 UTC (rev 11575) +++ trunk/src/org/hyperic/hq/appdef/server/session/ResourceTreeGenerator.java 2008-10-23 16:57:35 UTC (rev 11576) @@ -34,15 +34,11 @@ import org.hyperic.hq.appdef.shared.AppdefEntityID; import org.hyperic.hq.appdef.shared.AppdefEntityNotFoundException; import org.hyperic.hq.appdef.shared.AppdefEntityValue; -import org.hyperic.hq.appdef.shared.ApplicationManagerLocal; import org.hyperic.hq.appdef.shared.ApplicationNotFoundException; import org.hyperic.hq.appdef.shared.ApplicationValue; import org.hyperic.hq.appdef.shared.PlatformNotFoundException; -import org.hyperic.hq.appdef.shared.PlatformValue; -import org.hyperic.hq.appdef.shared.ServerManagerLocal; import org.hyperic.hq.appdef.shared.ServerValue; import org.hyperic.hq.appdef.shared.ServiceManagerLocal; -import org.hyperic.hq.appdef.shared.ServiceValue; import org.hyperic.hq.appdef.shared.resourceTree.ApplicationNode; import org.hyperic.hq.appdef.shared.resourceTree.PlatformNode; import org.hyperic.hq.appdef.shared.resourceTree.ResourceTree; @@ -72,10 +68,8 @@ private static final int GO_UP = 1 << 5; private static final int GO_DOWN = 1 << 6; - private ApplicationManagerLocal appMan; - private ServerManagerLocal serverMan; - private ServiceManagerLocal serviceMan; - private AuthzSubject subject; + private ServiceManagerLocal _serviceMan; + private AuthzSubject _subject; // Caches so we don't do much work twice private HashSet upPlats; // Platform IDs which we've traversed up from @@ -87,7 +81,7 @@ private HashSet dnApps; // App IDs which we've traversed down from ResourceTreeGenerator(AuthzSubject subject){ - this.subject = subject; + _subject = subject; upPlats = new HashSet(); upServers = new HashSet(); @@ -97,9 +91,7 @@ dnServices = new HashMap(); dnApps = new HashSet(); - appMan = ApplicationManagerEJBImpl.getOne(); - serverMan = ServerManagerEJBImpl.getOne(); - serviceMan = ServiceManagerEJBImpl.getOne(); + _serviceMan = ServiceManagerEJBImpl.getOne(); } /** @@ -135,7 +127,7 @@ res = new ResourceTree(); - for(int i=0; i<ids.length; i++){ + for (int i = 0; i < ids.length; i++) { Integer iID = ids[i].getId(); switch(ids[i].getType()){ @@ -152,8 +144,8 @@ addFromApp(iID, direction, res); break; default: - throw new SystemException("Unable to generate tree " + - "from " + ids[i]); + throw new SystemException("Unable to generate tree from " + + ids[i]); } } return res; @@ -163,12 +155,12 @@ throws PermissionException, AppdefEntityNotFoundException, PlatformNotFoundException { - PlatformValue val; + Platform val; try { AppdefEntityValue aeval = new AppdefEntityValue( - AppdefEntityID.newPlatformID(id), subject); - val = (PlatformValue) aeval.getResourceValue(); + AppdefEntityID.newPlatformID(id), _subject); + val = (Platform) aeval.getResourcePOJO(); } catch(PermissionException exc){ throw new PermissionException("Failed to find platform " + id + ": permission denied"); @@ -184,7 +176,7 @@ try { AppdefEntityValue aeval = new AppdefEntityValue( - AppdefEntityID.newServerID(id), subject); + AppdefEntityID.newServerID(id), _subject); val = (ServerValue) aeval.getResourceValue(); } catch(PermissionException exc){ throw new PermissionException("Failed to find server " + id + @@ -197,12 +189,12 @@ private void addFromService(Integer id, int direction, ResourceTree tree) throws PermissionException, AppdefEntityNotFoundException { - ServiceValue val; + Service val; try { AppdefEntityValue aeval = new AppdefEntityValue( - AppdefEntityID.newServiceID(id), subject); - val = (ServiceValue) aeval.getResourceValue(); + AppdefEntityID.newServiceID(id), _subject); + val = (Service) aeval.getResourcePOJO(); } catch(PermissionException exc){ throw new PermissionException("Failed to find service " + id + ": permission denied"); @@ -217,13 +209,13 @@ ApplicationValue val; AppdefEntityValue aeval = new AppdefEntityValue( - AppdefEntityID.newAppID(id), subject); + AppdefEntityID.newAppID(id), _subject); val = (ApplicationValue) aeval.getResourceValue(); traverseApp(val, direction, tree); } - private PlatformNode traversePlatform(PlatformValue platform, + private PlatformNode traversePlatform(Platform platform, int direction, ResourceTree tree) throws PermissionException @@ -244,20 +236,20 @@ upPlats.add(platform.getId()); try { - servers = serverMan.getServersByPlatform( - subject, platformID, true, null); + servers = ServerManagerEJBImpl.getOne().getServersByPlatform( + _subject, platformID, true, null); } catch(AppdefEntityNotFoundException exc){ throw new SystemException("Internal inconsistancy: " + - "could not find servers for " + - "platform '" + platform + "'"); + "could not find servers for " + + "platform '" + platform + "'"); } catch(PermissionException exc){ throw new SystemException("Failed to get servers for " + - "platform " + platformID + - ": permission denied"); + "platform " + platformID + + ": permission denied"); } - for(Iterator i=servers.iterator(); i.hasNext(); ){ - traverseServer((ServerValue)i.next(), GO_UP, tree); + for (Iterator i = servers.iterator(); i.hasNext();) { + traverseServer((ServerValue) i.next(), GO_UP, tree); } } return res; @@ -267,19 +259,17 @@ ResourceTree tree) throws PermissionException { - Integer serverID; + Integer serverID = server.getId(); ServerNode res; - - serverID = server.getId(); - if((res = (ServerNode)dnServers.get(serverID)) == null){ + if ((res = (ServerNode) dnServers.get(serverID)) == null) { PlatformNode platformNode; - PlatformValue platform; + Platform platform; AppdefEntityValue aeval = new AppdefEntityValue(server.getPlatform().getEntityId(), - subject); + _subject); try { - platform = (PlatformValue) aeval.getResourceValue(); + platform = (Platform) aeval.getResourcePOJO(); } catch(AppdefEntityNotFoundException exc){ throw new SystemException("Internal inconsistancy: " + "could not find platform " + @@ -302,15 +292,12 @@ } - if((direction & GO_UP) != 0 && - !upServers.contains(serverID)) - { + if ((direction & GO_UP) != 0 && !upServers.contains(serverID)) { List services; upServers.add(serverID); try { - services = serviceMan.getServicesByServer(subject, serverID, - PageControl.PAGE_ALL); + services = _serviceMan.getServicesByServer(_subject, serverID); } catch(AppdefEntityNotFoundException exc){ throw new SystemException("Internal inconsistancy: " + "could not find services for " + @@ -323,13 +310,13 @@ } for(Iterator i=services.iterator(); i.hasNext(); ){ - traverseService((ServiceValue)i.next(), GO_UP, tree); + traverseService((Service)i.next(), GO_UP, tree); } } return res; } - private ServiceNode traverseService(ServiceValue service, int direction, + private ServiceNode traverseService(Service service, int direction, ResourceTree tree) throws PermissionException { @@ -342,7 +329,7 @@ ServerValue server; AppdefEntityValue aeval = new AppdefEntityValue(service.getServer().getEntityId(), - subject); + _subject); try { server = (ServerValue) aeval.getResourceValue(); } catch(AppdefEntityNotFoundException exc){ @@ -365,18 +352,16 @@ } - if((direction & GO_UP) != 0 && - !upServices.contains(service.getId())) - { + if ((direction & GO_UP) != 0 && !upServices.contains(service.getId())) { List apps; upServices.add(service.getId()); try { AppdefEntityID id = AppdefEntityID.newServiceID(service.getId()); - apps = - appMan.getApplicationsByResource(subject, id, - PageControl.PAGE_ALL); + apps = ApplicationManagerEJBImpl.getOne() + .getApplicationsByResource(_subject, id, + PageControl.PAGE_ALL); } catch(ApplicationNotFoundException exc){ throw new SystemException("Internal inconsistancy: could not " + "find apps for service '" + @@ -404,24 +389,21 @@ appNode = tree.addApplication(app); - if((direction & GO_DOWN) != 0){ + if ((direction & GO_DOWN) != 0) { try { services = - serviceMan.getServicesByApplication(subject, app.getId(), - PageControl.PAGE_ALL); + _serviceMan.getServicesByApplication(_subject, app.getId()); } catch(AppdefEntityNotFoundException exc){ throw new SystemException("Internal inconsistancy: could " + - "not get services on which " + - "application " + app.getId() + - " depends on"); + "not get services on which " + + "application " + app.getId() + + " depends on"); } for(Iterator i=services.iterator(); i.hasNext(); ){ - ServiceNode servNode; + ServiceNode servNode = + traverseService((Service) i.next(), GO_DOWN, tree); - servNode = traverseService((ServiceValue) i.next(), GO_DOWN, - tree); - appNode.linkToService(servNode); } } Modified: trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java 2008-10-23 15:29:28 UTC (rev 11575) +++ trunk/src/org/hyperic/hq/appdef/server/session/ServiceManagerEJBImpl.java 2008-10-23 16:57:35 UTC (rev 11576) @@ -603,8 +603,7 @@ Integer serverId, PageControl pc) throws ServiceNotFoundException, ServerNotFoundException, PermissionException { - return getServicesByServer(subject, serverId, APPDEF_RES_TYPE_UNDEFINED, - pc); + return getServicesByServer(subject, serverId, null, pc); } /** @@ -614,6 +613,26 @@ Integer serverId, Integer svcTypeId, PageControl pc) throws ServiceNotFoundException, PermissionException { + List toBePaged = getServicesByServerImpl(subject, serverId, svcTypeId, + pc); + return valuePager.seek(toBePaged, pc); + } + + /** + * Get service POJOs by server and type. + * @ejb:interface-method + */ + public List getServicesByServer(AuthzSubject subject, Integer serverId) + throws ServiceNotFoundException, ServerNotFoundException, + PermissionException { + return getServicesByServerImpl(subject, serverId, null, + PageControl.PAGE_ALL); + } + + private List getServicesByServerImpl(AuthzSubject subject, + Integer serverId, Integer svcTypeId, + PageControl pc) + throws PermissionException, ServiceNotFoundException { if (svcTypeId == null) svcTypeId = APPDEF_RES_TYPE_UNDEFINED; @@ -621,20 +640,16 @@ switch (pc.getSortattribute()) { case SortAttribute.SERVICE_TYPE: - services = - getServiceDAO().findByServer_orderType(serverId); + services = getServiceDAO().findByServer_orderType(serverId); break; case SortAttribute.SERVICE_NAME: default: if (svcTypeId != APPDEF_RES_TYPE_UNDEFINED) { - services = - getServiceDAO().findByServerAndType_orderName( - serverId, svcTypeId); + services = getServiceDAO() + .findByServerAndType_orderName(serverId, svcTypeId); } else { - services = - getServiceDAO().findByServer_orderName( - serverId); + services = getServiceDAO().findByServer_orderName(serverId); } break; } @@ -643,8 +658,7 @@ Collections.reverse(services); } - List toBePaged = filterUnviewable(subject, services); - return valuePager.seek(toBePaged, pc); + return filterUnviewable(subject, services); } /** @@ -914,10 +928,30 @@ */ public PageList getServicesByApplication(AuthzSubject subject, Integer appId, Integer svcTypeId, - PageControl pc ) + PageControl pc) throws PermissionException, ApplicationNotFoundException, ServiceNotFoundException { + return filterAndPage(getServicesByApplication(appId, pc), subject, + svcTypeId, pc); + } + /** + * @ejb:interface-method + * @return A List of Service and ServiceCluster objects + * representing all of the services that the given subject is allowed to view. + * @throws ApplicationNotFoundException if the appId is bogus + * @throws ServiceNotFoundException if services could not be looked up + */ + public List getServicesByApplication(AuthzSubject subject, Integer appId) + throws PermissionException, ApplicationNotFoundException, + ServiceNotFoundException { + return filterUnviewable(subject, + getServicesByApplication(appId, + PageControl.PAGE_ALL)); + } + + private List getServicesByApplication(Integer appId, PageControl pc) + throws ApplicationNotFoundException { try { // we only look up the application to validate // the appId param @@ -927,23 +961,19 @@ } Collection appServiceCollection; - AppServiceDAO appServLocHome = - DAOFactory.getDAOFactory().getAppServiceDAO(); - pc = PageControl.initDefaults (pc, SortAttribute.SERVICE_NAME); + AppServiceDAO dao = new AppServiceDAO(DAOFactory.getDAOFactory()); + pc = PageControl.initDefaults(pc, SortAttribute.SERVICE_NAME); switch (pc.getSortattribute()) { - case SortAttribute.SERVICE_NAME : - appServiceCollection = appServLocHome - .findByApplication_orderSvcName(appId,pc.isAscending()); + case SortAttribute.SERVICE_NAME: + case SortAttribute.RESOURCE_NAME: + appServiceCollection = + dao.findByApplication_orderSvcName(appId, pc.isAscending()); break; - case SortAttribute.RESOURCE_NAME : - appServiceCollection = appServLocHome - .findByApplication_orderSvcName(appId,pc.isAscending()); + case SortAttribute.SERVICE_TYPE: + appServiceCollection = + dao.findByApplication_orderSvcType(appId, pc.isAscending()); break; - case SortAttribute.SERVICE_TYPE : - appServiceCollection = appServLocHome - .findByApplication_orderSvcType(appId,pc.isAscending()); - break; default: throw new IllegalArgumentException("Unsupported sort " + "attribute [" + @@ -961,8 +991,8 @@ services.add(appService.getService()); } } - return filterAndPage(services, subject, svcTypeId, pc); - } + return services; + } /** * @ejb:interface-method Modified: trunk/src/org/hyperic/hq/appdef/shared/resourceTree/PlatformNode.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/shared/resourceTree/PlatformNode.java 2008-10-23 15:29:28 UTC (rev 11575) +++ trunk/src/org/hyperic/hq/appdef/shared/resourceTree/PlatformNode.java 2008-10-23 16:57:35 UTC (rev 11576) @@ -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 @@ -25,29 +25,29 @@ package org.hyperic.hq.appdef.shared.resourceTree; -import org.hyperic.hq.appdef.shared.PlatformValue; -import org.hyperic.hq.appdef.shared.ServerValue; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.hyperic.hq.appdef.server.session.Platform; +import org.hyperic.hq.appdef.shared.ServerValue; + public class PlatformNode implements java.io.Serializable { private ResourceTree tree; - private PlatformValue platform; + private Platform platform; private ArrayList servers; private boolean showServers = false; - PlatformNode(ResourceTree tree, PlatformValue platform){ + PlatformNode(ResourceTree tree, Platform platform){ this.tree = tree; this.platform = platform; this.servers = new ArrayList(); } - public PlatformValue getPlatform(){ + public Platform getPlatform(){ return this.platform; } Modified: trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ResourceTree.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ResourceTree.java 2008-10-23 15:29:28 UTC (rev 11575) +++ trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ResourceTree.java 2008-10-23 16:57:35 UTC (rev 11576) @@ -29,8 +29,8 @@ import java.util.Iterator; import java.util.List; +import org.hyperic.hq.appdef.server.session.Platform; import org.hyperic.hq.appdef.shared.ApplicationValue; -import org.hyperic.hq.appdef.shared.PlatformValue; /** * A tree which represents portions of a hierarchy. The tree @@ -60,7 +60,7 @@ return this.apps.iterator(); } - public PlatformNode addPlatform(PlatformValue platform){ + public PlatformNode addPlatform(Platform platform){ PlatformNode node; node = new PlatformNode(this, platform); Modified: trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ServerNode.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ServerNode.java 2008-10-23 15:29:28 UTC (rev 11575) +++ trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ServerNode.java 2008-10-23 16:57:35 UTC (rev 11576) @@ -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 @@ -25,13 +25,13 @@ package org.hyperic.hq.appdef.shared.resourceTree; -import org.hyperic.hq.appdef.shared.ServerValue; -import org.hyperic.hq.appdef.shared.ServiceValue; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.hyperic.hq.appdef.server.session.Service; +import org.hyperic.hq.appdef.shared.ServerValue; + public class ServerNode implements java.io.Serializable { @@ -57,7 +57,7 @@ return this.ownerPlatform; } - public ServiceNode addService(ServiceValue service){ + public ServiceNode addService(Service service){ ServiceNode node; node = new ServiceNode(this.tree, this, service); Modified: trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ServiceNode.java =================================================================== --- trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ServiceNode.java 2008-10-23 15:29:28 UTC (rev 11575) +++ trunk/src/org/hyperic/hq/appdef/shared/resourceTree/ServiceNode.java 2008-10-23 16:57:35 UTC (rev 11576) @@ -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 @@ -25,24 +25,24 @@ package org.hyperic.hq.appdef.shared.resourceTree; -import org.hyperic.hq.appdef.shared.ServiceValue; +import org.hyperic.hq.appdef.server.session.Service; public class ServiceNode implements java.io.Serializable { private ResourceTree tree; private ServerNode ownerServer; - private ServiceValue service; + private Service service; ServiceNode(ResourceTree tree, ServerNode ownerServer, - ServiceValue service) + Service service) { this.tree = tree; this.ownerServer = ownerServer; this.service = service; } - public ServiceValue getService(){ + public Service getService(){ return this.service; } Modified: trunk/src/org/hyperic/hq/bizapp/server/session/LatherDispatcher.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/server/session/LatherDispatcher.java 2008-10-23 15:29:28 UTC (rev 11575) +++ trunk/src/org/hyperic/hq/bizapp/server/session/LatherDispatcher.java 2008-10-23 16:57:35 UTC (rev 11576) @@ -49,6 +49,7 @@ import org.hyperic.hq.agent.client.AgentCommandsClient; import org.hyperic.hq.agent.client.AgentCommandsClientFactory; import org.hyperic.hq.appdef.Agent; +import org.hyperic.hq.appdef.server.session.AppdefResource; import org.hyperic.hq.appdef.server.session.Platform; import org.hyperic.hq.appdef.server.session.ResourceRefreshZevent; import org.hyperic.hq.appdef.server.session.Server; @@ -683,6 +684,11 @@ return res; } + private void addMeasurementConfig(List ents, AppdefResource resource){ + addMeasurementConfig(ents, resource.getEntityId(), + resource.getAppdefResourceType().getName()); + } + private void addMeasurementConfig(List ents, AppdefResourceValue resource){ addMeasurementConfig(ents, resource.getEntityId(), resource.getAppdefResourceTypeValue().getName()); |