Author: rmorgan Date: 2007-03-22 10:38:31 -0800 (Thu, 22 Mar 2007) New Revision: 3817 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3817 Modified: trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemLiveDataPlugin.java trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellEntityFetcher.java trunk/src/org/hyperic/hq/bizapp/server/session/LiveDataBossEJBImpl.java trunk/src/org/hyperic/hq/livedata/agent/client/LiveDataClient.java trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_args.java trunk/src/org/hyperic/hq/livedata/agent/server/LiveDataCommandsServer.java trunk/src/org/hyperic/hq/livedata/server/session/LiveDataManagerEJBImpl.java trunk/src/org/hyperic/hq/product/LiveDataPlugin.java trunk/src/org/hyperic/hq/product/LiveDataPluginManager.java trunk/src/org/hyperic/hq/product/jmx/MxLiveDataPlugin.java Log: Pass measurement ConfigResponse into LiveData plugins. Modified: trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemLiveDataPlugin.java =================================================================== --- trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemLiveDataPlugin.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemLiveDataPlugin.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -30,6 +30,7 @@ import org.hyperic.hq.livedata.shared.LiveDataTranslator; import org.hyperic.sigar.Sigar; import org.hyperic.sigar.SigarException; +import org.hyperic.util.config.ConfigResponse; import org.json.JSONArray; public class SystemLiveDataPlugin extends LiveDataPlugin { @@ -46,7 +47,9 @@ CMD_FILESYSTEM }; - public Object getData(String command) throws PluginException { + public Object getData(String command, ConfigResponse config) + throws PluginException + { Sigar sigar = new Sigar(); try { @@ -72,10 +75,10 @@ public static void main(String[] args) throws Exception { SystemLiveDataPlugin p = new SystemLiveDataPlugin(); - + ConfigResponse emtpy = new ConfigResponse(); for (int i = 0; i < _COMMANDS.length; i++) { System.out.println("Running command " + _COMMANDS[i]); - Object o = p.getData(_COMMANDS[i]); + Object o = p.getData(_COMMANDS[i], emtpy); JSONArray js = LiveDataTranslator.encode(o); System.out.println(js.toString(2)); } Modified: trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellEntityFetcher.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellEntityFetcher.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellEntityFetcher.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -1163,7 +1163,8 @@ throws NamingException, ClientShellAuthenticationException, PermissionException, AgentConnectionException, RemoteException, AgentRemoteException, AgentNotFoundException, LiveDataException, - AppdefEntityNotFoundException + AppdefEntityNotFoundException, SessionTimeoutException, + SessionNotFoundException { LiveDataBoss boss; @@ -1174,7 +1175,8 @@ public String[] getLiveDataCommands(AppdefEntityID id) throws RemoteException, NamingException, - ClientShellAuthenticationException, PluginException + ClientShellAuthenticationException, PluginException, + SessionTimeoutException, SessionNotFoundException { LiveDataBoss boss; Modified: trunk/src/org/hyperic/hq/bizapp/server/session/LiveDataBossEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/server/session/LiveDataBossEJBImpl.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/src/org/hyperic/hq/bizapp/server/session/LiveDataBossEJBImpl.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -29,13 +29,16 @@ import org.hyperic.hq.appdef.shared.AgentNotFoundException; import org.hyperic.hq.appdef.shared.AppdefEntityNotFoundException; import org.hyperic.hq.authz.shared.PermissionException; +import org.hyperic.hq.authz.shared.AuthzSubjectValue; import org.hyperic.hq.agent.AgentConnectionException; import org.hyperic.hq.agent.AgentRemoteException; import org.hyperic.hq.livedata.shared.LiveDataException; import org.hyperic.hq.livedata.shared.LiveDataManagerLocal; import org.hyperic.hq.livedata.server.session.LiveDataManagerEJBImpl; -import org.hyperic.hq.product.PluginNotFoundException; import org.hyperic.hq.product.PluginException; +import org.hyperic.hq.auth.shared.SessionManager; +import org.hyperic.hq.auth.shared.SessionTimeoutException; +import org.hyperic.hq.auth.shared.SessionNotFoundException; import javax.ejb.SessionBean; import javax.ejb.CreateException; @@ -56,6 +59,8 @@ public class LiveDataBossEJBImpl implements SessionBean { + protected SessionManager _manager = SessionManager.getInstance(); + /** @ejb:create-method */ public void ejbCreate() throws CreateException {} public void ejbActivate() throws EJBException, RemoteException {} @@ -77,11 +82,13 @@ public String getLiveData(int sessionId, AppdefEntityID id, String command) throws PermissionException, AgentConnectionException, - AgentRemoteException, AgentNotFoundException, - AppdefEntityNotFoundException, LiveDataException + AgentRemoteException, AgentNotFoundException, + AppdefEntityNotFoundException, LiveDataException, + SessionTimeoutException, SessionNotFoundException { + AuthzSubjectValue subject = _manager.getSubject(sessionId); LiveDataManagerLocal manager = LiveDataManagerEJBImpl.getOne(); - return manager.getData(id, command); + return manager.getData(subject, id, command); } /** @@ -90,10 +97,11 @@ * @ejb:interface-method */ public String[] getLiveDataCommands(int sessionId, AppdefEntityID id) - throws PluginException + throws PluginException, + SessionTimeoutException, SessionNotFoundException { + AuthzSubjectValue subject = _manager.getSubject(sessionId); LiveDataManagerLocal manager = LiveDataManagerEJBImpl.getOne(); - - return manager.getCommands(id); + return manager.getCommands(subject, id); } } Modified: trunk/src/org/hyperic/hq/livedata/agent/client/LiveDataClient.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/agent/client/LiveDataClient.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/src/org/hyperic/hq/livedata/agent/client/LiveDataClient.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -33,9 +33,8 @@ import org.hyperic.hq.agent.AgentConnectionException; import org.hyperic.hq.agent.AgentRemoteException; import org.hyperic.hq.agent.AgentRemoteValue; +import org.hyperic.util.config.ConfigResponse; -import java.util.Properties; - public class LiveDataClient { private LiveDataCommandsAPI _api; @@ -46,13 +45,13 @@ _api = new LiveDataCommandsAPI(); } - public String getData(String type, String command, Properties props) + public String getData(String type, String command, ConfigResponse config) throws AgentConnectionException, AgentRemoteException, LiveDataException { LiveData_args args = new LiveData_args(); - args.setConfig(type, command); + args.setConfig(type, command, config); AgentRemoteValue res = _agentConnection.sendCommand(LiveDataCommandsAPI.command_getData, Modified: trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_args.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_args.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_args.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -26,26 +26,57 @@ package org.hyperic.hq.livedata.agent.commands; import org.hyperic.hq.agent.AgentRemoteValue; +import org.hyperic.hq.agent.AgentRemoteException; +import org.hyperic.util.config.ConfigResponse; +import org.hyperic.util.config.EncodingException; +import org.hyperic.util.encoding.Base64; public class LiveData_args extends AgentRemoteValue { private static final String PARAM_PLUGIN = "plugin"; private static final String PARAM_COMMAND = "command"; + private static final String PARAM_CONFIG = "config"; public LiveData_args() { super(); } - public LiveData_args(AgentRemoteValue val) { + public LiveData_args(AgentRemoteValue val) + throws AgentRemoteException + { String type = val.getValue(PARAM_PLUGIN); String command = val.getValue(PARAM_COMMAND); + String configStr = val.getValue(PARAM_CONFIG); - setConfig(type, command); + ConfigResponse config; + try { + config = ConfigResponse.decode(Base64.decode(configStr)); + } catch (EncodingException e) { + throw new AgentRemoteException("Unable to decode plugin " + + "configuration: " + + e.getMessage()); + } + + setConfig(type, command, config); } - public void setConfig(String type, String command) { + public void setConfig(String type, String command, ConfigResponse config) + throws AgentRemoteException + { + String configStr; + + try { + configStr = Base64.encode(config.encode()); + + } catch (EncodingException e) { + throw new AgentRemoteException("Unable to encode plugin " + + "configuration: " + + e.getMessage()); + } + super.setValue(PARAM_PLUGIN, type); super.setValue(PARAM_COMMAND, command); + super.setValue(PARAM_CONFIG, configStr); } public String getPlugin() { @@ -55,4 +86,21 @@ public String getCommand() { return getValue(PARAM_COMMAND); } + + public ConfigResponse getConfig() + throws AgentRemoteException + { + String configStr = getValue(PARAM_CONFIG); + ConfigResponse config; + + try { + config = ConfigResponse.decode(Base64.decode(configStr)); + } catch (EncodingException e) { + throw new AgentRemoteException("Unable to decode plugin " + + "configuration: " + + e.getMessage()); + } + + return config; + } } Modified: trunk/src/org/hyperic/hq/livedata/agent/server/LiveDataCommandsServer.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/agent/server/LiveDataCommandsServer.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/src/org/hyperic/hq/livedata/agent/server/LiveDataCommandsServer.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -91,7 +91,8 @@ _log.info("Asked to invoke cmdGetData for " + args.getPlugin()); try { - JSONArray o = _manager.getData(args.getPlugin(), args.getCommand()); + JSONArray o = _manager.getData(args.getPlugin(), args.getCommand(), + args.getConfig()); LiveData_result res = new LiveData_result(); res.setResult(o.toString()); return res; Modified: trunk/src/org/hyperic/hq/livedata/server/session/LiveDataManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/server/session/LiveDataManagerEJBImpl.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/src/org/hyperic/hq/livedata/server/session/LiveDataManagerEJBImpl.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -40,16 +40,17 @@ import org.hyperic.hq.appdef.shared.ConfigManagerLocal; import org.hyperic.hq.appdef.server.session.ConfigManagerEJBImpl; import org.hyperic.hq.authz.shared.PermissionException; +import org.hyperic.hq.authz.shared.AuthzSubjectValue; import org.hyperic.hq.agent.AgentConnectionException; import org.hyperic.hq.agent.AgentRemoteException; import org.hyperic.hq.common.SystemException; import org.hyperic.hq.livedata.shared.LiveDataManagerLocal; import org.hyperic.hq.livedata.shared.LiveDataManagerUtil; import org.hyperic.hq.livedata.shared.LiveDataException; +import org.hyperic.util.config.ConfigResponse; import javax.ejb.SessionContext; import javax.ejb.SessionBean; -import java.util.Properties; /** * @ejb:bean name="LiveDataManager" @@ -90,7 +91,7 @@ public void ejbRemove() {} public void setSessionContext(SessionContext ctx) {} - private String getPlugin(AppdefEntityID id) + private String getPluginName(AppdefEntityID id) throws AppdefEntityNotFoundException { ConfigManagerLocal cManager = ConfigManagerEJBImpl.getOne(); @@ -99,21 +100,41 @@ } /** + * Live data subsystem uses measurement configs. + */ + private ConfigResponse getMeasurementConfig(AuthzSubjectValue subject, + AppdefEntityID id) + throws LiveDataException + { + ConfigManagerLocal cManager = ConfigManagerEJBImpl.getOne(); + + try { + return cManager.getMergedConfigResponse(subject, + ProductPlugin.TYPE_MEASUREMENT, + id, true); + } catch (Exception e) { + throw new LiveDataException(e); + } + } + + /** * Get live data for a given resource. * * @ejb:interface-method */ - public String getData(AppdefEntityID id, String command) + public String getData(AuthzSubjectValue subject, + AppdefEntityID id, String command) throws PermissionException, AgentNotFoundException, AgentConnectionException, AgentRemoteException, AppdefEntityNotFoundException, LiveDataException { LiveDataClient client = new LiveDataClient(AgentConnectionUtil.getClient(id)); - Properties props = new Properties(); + String plugin = getPluginName(id); - String plugin = getPlugin(id); - return client.getData(plugin, command, props); + ConfigResponse config = getMeasurementConfig(subject, id); + + return client.getData(plugin, command, config); } /** @@ -121,11 +142,11 @@ * * @ejb:interface-method */ - public String[] getCommands(AppdefEntityID id) + public String[] getCommands(AuthzSubjectValue subject, AppdefEntityID id) throws PluginException { try { - String plugin = getPlugin(id); + String plugin = getPluginName(id); return _manager.getCommands(plugin); } catch (AppdefEntityNotFoundException e) { throw new PluginNotFoundException("No plugin found for " + id, e); Modified: trunk/src/org/hyperic/hq/product/LiveDataPlugin.java =================================================================== --- trunk/src/org/hyperic/hq/product/LiveDataPlugin.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/src/org/hyperic/hq/product/LiveDataPlugin.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -25,9 +25,12 @@ package org.hyperic.hq.product; +import org.hyperic.util.config.ConfigResponse; + public abstract class LiveDataPlugin extends GenericPlugin { - public abstract Object getData(String command) throws PluginException; + public abstract Object getData(String command, ConfigResponse config) + throws PluginException; public abstract String[] getCommands(); } Modified: trunk/src/org/hyperic/hq/product/LiveDataPluginManager.java =================================================================== --- trunk/src/org/hyperic/hq/product/LiveDataPluginManager.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/src/org/hyperic/hq/product/LiveDataPluginManager.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -26,6 +26,7 @@ package org.hyperic.hq.product; import org.hyperic.hq.livedata.shared.LiveDataTranslator; +import org.hyperic.util.config.ConfigResponse; import org.json.JSONArray; import java.util.Properties; @@ -57,11 +58,12 @@ return p; } - public JSONArray getData(String plugin, String command) + public JSONArray getData(String plugin, String command, + ConfigResponse config) throws PluginException { LiveDataPlugin p = getLiveDataPlugin(plugin); - Object o = p.getData(command); + Object o = p.getData(command, config); try { return LiveDataTranslator.encode(o); Modified: trunk/src/org/hyperic/hq/product/jmx/MxLiveDataPlugin.java =================================================================== --- trunk/src/org/hyperic/hq/product/jmx/MxLiveDataPlugin.java 2007-03-22 16:35:47 UTC (rev 3816) +++ trunk/src/org/hyperic/hq/product/jmx/MxLiveDataPlugin.java 2007-03-22 18:38:31 UTC (rev 3817) @@ -27,10 +27,11 @@ import org.hyperic.hq.product.LiveDataPlugin; import org.hyperic.hq.product.PluginException; +import org.hyperic.util.config.ConfigResponse; public class MxLiveDataPlugin extends LiveDataPlugin { - public Object getData(String command) + public Object getData(String command, ConfigResponse config) throws PluginException { return new Object(); |