Author: rmorgan Date: 2007-03-21 20:17:56 -0800 (Wed, 21 Mar 2007) New Revision: 3810 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3810 Added: trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemLiveDataPlugin.java trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata.java trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata_get.java trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata_list.java trunk/src/org/hyperic/hq/bizapp/server/session/LiveDataBossEJBImpl.java trunk/src/org/hyperic/hq/livedata/ trunk/src/org/hyperic/hq/livedata/agent/ trunk/src/org/hyperic/hq/livedata/agent/LiveDataCommandsAPI.java trunk/src/org/hyperic/hq/livedata/agent/client/ trunk/src/org/hyperic/hq/livedata/agent/client/LiveDataClient.java trunk/src/org/hyperic/hq/livedata/agent/commands/ trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_args.java trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_result.java trunk/src/org/hyperic/hq/livedata/agent/server/ trunk/src/org/hyperic/hq/livedata/agent/server/LiveDataCommandsServer.java trunk/src/org/hyperic/hq/livedata/server/ trunk/src/org/hyperic/hq/livedata/server/session/ trunk/src/org/hyperic/hq/livedata/server/session/LiveDataManagerEJBImpl.java trunk/src/org/hyperic/hq/livedata/shared/ trunk/src/org/hyperic/hq/livedata/shared/LiveDataException.java trunk/src/org/hyperic/hq/livedata/shared/LiveDataTranslator.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 Modified: trunk/build.xml trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemPlugin.java trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell.java trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellBossManager.java trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellEntityFetcher.java trunk/src/org/hyperic/hq/product/ProductPlugin.java trunk/src/org/hyperic/hq/product/ProductPluginManager.java Log: Begin new livedata plugin framework for collecting arbitrary data. Currently only the system plugin is supported. Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-03-22 02:11:21 UTC (rev 3809) +++ trunk/build.xml 2007-03-22 04:17:56 UTC (rev 3810) @@ -742,6 +742,8 @@ <include name="org/hyperic/hq/common/shared/ProductProperties.class"/> <!-- workaround for StackOverflow w/ WLS 9.x --> <include name="weblogic/net/file/Handler.class"/> + <!-- Livedata shared classes --> + <include name="org/hyperic/hq/livedata/shared/**"/> </jar> <!-- Pack version info --> @@ -799,6 +801,8 @@ <include name="dnsjava-2.0.3.jar"/> <!-- for JMX based plugins --> <include name="mx4j/*.jar"/> + <!-- for live data translation --> + <include name="json.jar"/> </fileset> </copy> @@ -1020,6 +1024,14 @@ </manifest> </jar> + <jar basedir="${build.dir}/classes" + jarfile="${agent.dir}/lib/LiveDataServer.jar"> + <include name="org/hyperic/hq/livedata/**"/> + <manifest> + <attribute name="Main-Class" value="org.hyperic.hq.livedata.agent.server.LiveDataCommandsServer" /> + </manifest> + </jar> + <jar basedir="${build.dir}/classes" jarfile="${agent.dir}/lib/AgentClient.jar"> <exclude name="org/hyperic/hq/agent/server/**"/> <include name="org/hyperic/hq/agent/**"/> Added: trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemLiveDataPlugin.java =================================================================== --- trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemLiveDataPlugin.java (rev 0) +++ trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemLiveDataPlugin.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,83 @@ +/* + * 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.plugin.system; + +import org.hyperic.hq.product.LiveDataPlugin; +import org.hyperic.hq.product.PluginException; +import org.hyperic.hq.livedata.shared.LiveDataTranslator; +import org.hyperic.sigar.Sigar; +import org.hyperic.sigar.SigarException; +import org.json.JSONArray; + +public class SystemLiveDataPlugin extends LiveDataPlugin { + + private static final String CMD_CPUINFO = "cpuinfo"; + private static final String CMD_CPU = "cpu"; + private static final String CMD_CPUPERC = "cpuperc"; + private static final String CMD_FILESYSTEM = "filesystem"; + + private static final String _COMMANDS[] = { + CMD_CPUINFO, + CMD_CPU, + CMD_CPUPERC, + CMD_FILESYSTEM + }; + + public Object getData(String command) throws PluginException { + Sigar sigar = new Sigar(); + + try { + if (command.equals(CMD_CPUINFO)) { + return sigar.getCpuInfoList(); + } else if (command.equals(CMD_CPU)) { + return sigar.getCpuList(); + } else if (command.equals(CMD_CPUPERC)) { + return sigar.getCpuPercList(); + } else if (command.equals(CMD_FILESYSTEM)) { + return sigar.getFileSystemList(); + } else { + throw new PluginException("Unknown command '" + command + "'"); + } + } catch (SigarException e) { + throw new PluginException("Error getting system data", e); + } + } + + public String[] getCommands() { + return _COMMANDS; + } + + public static void main(String[] args) throws Exception { + SystemLiveDataPlugin p = new SystemLiveDataPlugin(); + + for (int i = 0; i < _COMMANDS.length; i++) { + System.out.println("Running command " + _COMMANDS[i]); + Object o = p.getData(_COMMANDS[i]); + JSONArray js = LiveDataTranslator.encode(o); + System.out.println(js.toString(2)); + } + } +} Modified: trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemPlugin.java =================================================================== --- trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemPlugin.java 2007-03-22 02:11:21 UTC (rev 3809) +++ trunk/plugins/system/src/org/hyperic/hq/plugin/system/SystemPlugin.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -198,6 +198,9 @@ return new LogFileTailPlugin(); } } + else if (type.equals(ProductPlugin.TYPE_LIVE_DATA)) { + return new SystemLiveDataPlugin(); + } return null; } Modified: trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell.java 2007-03-22 02:11:21 UTC (rev 3809) +++ trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -139,6 +139,7 @@ registerCommandHandler("trigger", new ClientShell_trigger(this)); registerCommandHandler("vacuum", new ClientShell_vacuum(this)); registerCommandHandler("version", new ClientShell_version(this)); + registerCommandHandler("livedata", new ClientShell_livedata(this)); this.setHandlerHidden(".", true); this.setHandlerHidden("exit", true); Modified: trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellBossManager.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellBossManager.java 2007-03-22 02:11:21 UTC (rev 3809) +++ trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellBossManager.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -42,6 +42,8 @@ import org.hyperic.hq.bizapp.shared.ProductBossUtil; import org.hyperic.hq.bizapp.shared.AIBoss; import org.hyperic.hq.bizapp.shared.AIBossUtil; +import org.hyperic.hq.bizapp.shared.LiveDataBoss; +import org.hyperic.hq.bizapp.shared.LiveDataBossUtil; import java.util.Hashtable; import javax.naming.NamingException; @@ -55,6 +57,7 @@ private ConfigBoss configBoss; private EventsBoss eventsBoss; private AIBoss aiBoss; + private LiveDataBoss liveDataBoss; protected ClientShellAuthenticator auth; @@ -75,6 +78,7 @@ this.measurementBoss = null; this.eventsBoss = null; this.aiBoss = null; + this.liveDataBoss = null; } public AppdefBoss getAppdefBoss() @@ -217,4 +221,21 @@ return this.aiBoss; } + public LiveDataBoss getLiveDataBoss() + throws NamingException, ClientShellAuthenticationException + { + if (this.liveDataBoss == null) { + try { + Hashtable env = this.auth.getNamingEnv(); + + this.liveDataBoss = LiveDataBossUtil.getHome(env).create(); + } catch (ClientShellAuthenticationException e) { + throw e; + } catch (Exception e) { + throw new NamingException("Could not get LiveDataBoss: " + e); + } + } + + return this.liveDataBoss; + } } Modified: trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellEntityFetcher.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellEntityFetcher.java 2007-03-22 02:11:21 UTC (rev 3809) +++ trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShellEntityFetcher.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -39,6 +39,7 @@ import javax.naming.NamingException; import org.hyperic.hq.agent.AgentConnectionException; +import org.hyperic.hq.agent.AgentRemoteException; import org.hyperic.hq.appdef.shared.AIIpValue; import org.hyperic.hq.appdef.shared.AIPlatformValue; import org.hyperic.hq.appdef.shared.AIServerValue; @@ -91,6 +92,7 @@ import org.hyperic.hq.bizapp.shared.EventsBoss; import org.hyperic.hq.bizapp.shared.MeasurementBoss; import org.hyperic.hq.bizapp.shared.ProductBoss; +import org.hyperic.hq.bizapp.shared.LiveDataBoss; import org.hyperic.hq.bizapp.shared.action.EmailActionConfig; import org.hyperic.hq.bizapp.shared.resourceImport.BatchImportData; import org.hyperic.hq.bizapp.shared.resourceImport.BatchImportException; @@ -115,6 +117,7 @@ import org.hyperic.hq.product.PluginException; import org.hyperic.hq.product.PluginNotFoundException; import org.hyperic.hq.scheduler.ScheduleValue; +import org.hyperic.hq.livedata.shared.LiveDataException; import org.hyperic.util.ConfigPropertyException; import org.hyperic.util.StringUtil; import org.hyperic.util.config.ConfigResponse; @@ -1099,7 +1102,7 @@ boss = this.bossManager.getMeasurementBoss(); boss.invokeDataCompact(auth.getAuthToken()); } - + public boolean ensureNamesAreIds(ConfigResponse response) throws SessionNotFoundException, SessionTimeoutException, ClientShellAuthenticationException, RemoteException, @@ -1155,6 +1158,29 @@ return (0 == numInvalid); } - + + public String getLiveData(AppdefEntityID id, String command) + throws NamingException, ClientShellAuthenticationException, + PermissionException, AgentConnectionException, RemoteException, + AgentRemoteException, AgentNotFoundException, LiveDataException, + AppdefEntityNotFoundException + { + LiveDataBoss boss; + + boss = this.bossManager.getLiveDataBoss(); + + return boss.getLiveData(auth.getAuthToken(), id, command); + } + + public String[] getLiveDataCommands(AppdefEntityID id) + throws RemoteException, NamingException, + ClientShellAuthenticationException, PluginNotFoundException + { + LiveDataBoss boss; + + boss = this.bossManager.getLiveDataBoss(); + + return boss.getLiveDataCommands(auth.getAuthToken(), id); + } } Added: trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata.java (rev 0) +++ trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,57 @@ +/* + * 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.bizapp.client.shell; + +import org.hyperic.util.shell.MultiwordShellCommand; +import org.hyperic.util.shell.ShellBase; +import org.hyperic.util.shell.ShellCommandInitException; +import org.hyperic.util.shell.ShellCommandHandler; + +public class ClientShell_livedata extends MultiwordShellCommand { + + private ClientShell shell; + + public ClientShell_livedata(ClientShell shell){ + this.shell = shell; + } + + public void init(String commandName, ShellBase shell) + throws ShellCommandInitException { + ShellCommandHandler handler; + + super.init(commandName, shell); + + handler = new ClientShell_livedata_get(this.shell); + registerSubHandler("get", handler); + + handler = new ClientShell_livedata_list(this.shell); + registerSubHandler("list", handler); + } + + public String getUsageShort(){ + return "Control resources in HQ"; + } +} Added: trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata_get.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata_get.java (rev 0) +++ trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata_get.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,83 @@ +/* + * 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.bizapp.client.shell; + +import org.hyperic.util.shell.ShellCommandUsageException; +import org.hyperic.util.shell.ShellCommandExecException; +import org.hyperic.util.shell.ShellCommandBase; +import org.hyperic.hq.appdef.shared.AppdefEntityID; +import org.json.JSONArray; + +public class ClientShell_livedata_get extends ShellCommandBase { + + private static final int[] PARAM_VALID_RESOURCE = { + ClientShell_resource.PARAM_PLATFORM, + ClientShell_resource.PARAM_SERVER, + ClientShell_resource.PARAM_SERVICE, + }; + + private ClientShellEntityFetcher _entityFetcher; + + public ClientShell_livedata_get(ClientShell shell) { + _entityFetcher = new ClientShellEntityFetcher(shell.getBossManager(), + shell.getAuthenticator()); + } + + public void processCommand(String [] args) + throws ShellCommandUsageException, ShellCommandExecException { + + if (args.length != 3) { + throw new ShellCommandUsageException(getSyntaxEx()); + } + + try { + int type = ClientShell_resource.paramToEntityType(args[0]); + AppdefEntityID id = _entityFetcher.getID(type, args[1]); + + String s = _entityFetcher.getLiveData(id, args[2]); + JSONArray json = new JSONArray(s); + this.getShell().getOutStream().println("Printing output from " + + args[2] + " command:"); + this.getShell().getOutStream().println(json.toString(2)); + + } catch (Exception e) { + throw new ShellCommandExecException(e); + } + } + + public String getSyntaxEx(){ + return "Use 'help " + this.getCommandName() + "' for details"; + } + + public String getUsageShort(){ + return "Get live data from a resource"; + } + + public String getUsageHelp (String[] args) { + return "<" + ClientShell_resource.generateArgList(PARAM_VALID_RESOURCE) + + "> < name | id > <command>"; + } +} Added: trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata_list.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata_list.java (rev 0) +++ trunk/src/org/hyperic/hq/bizapp/client/shell/ClientShell_livedata_list.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,85 @@ +/* + * 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.bizapp.client.shell; + +import org.hyperic.util.shell.ShellCommandBase; +import org.hyperic.util.shell.ShellCommandUsageException; +import org.hyperic.util.shell.ShellCommandExecException; +import org.hyperic.hq.appdef.shared.AppdefEntityID; + +import java.io.PrintStream; + +public class ClientShell_livedata_list extends ShellCommandBase { + private static final int[] PARAM_VALID_RESOURCE = { + ClientShell_resource.PARAM_PLATFORM, + ClientShell_resource.PARAM_SERVER, + ClientShell_resource.PARAM_SERVICE, + }; + + private ClientShellEntityFetcher _entityFetcher; + + public ClientShell_livedata_list(ClientShell shell) { + _entityFetcher = new ClientShellEntityFetcher(shell.getBossManager(), + shell.getAuthenticator()); + } + + public void processCommand(String [] args) + throws ShellCommandUsageException, ShellCommandExecException { + + if (args.length != 2) { + throw new ShellCommandUsageException(getSyntaxEx()); + } + + try { + int type = ClientShell_resource.paramToEntityType(args[0]); + AppdefEntityID id = _entityFetcher.getID(type, args[1]); + + String[] cmds = _entityFetcher.getLiveDataCommands(id); + + PrintStream ps = this.getShell().getOutStream(); + ps.println("Commands for " + id + ":"); + for (int i = 0; i < cmds.length; i++) { + ps.println(" " + cmds[i]); + } + + } catch (Exception e) { + throw new ShellCommandExecException(e); + } + } + + public String getSyntaxEx(){ + return "Use 'help " + this.getCommandName() + "' for details"; + } + + public String getUsageShort(){ + return "Get the live data commands for a resource"; + } + + public String getUsageHelp (String[] args) { + return "<" + ClientShell_resource.generateArgList(PARAM_VALID_RESOURCE) + + "> < name | id >"; + } +} Added: trunk/src/org/hyperic/hq/bizapp/server/session/LiveDataBossEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/server/session/LiveDataBossEJBImpl.java (rev 0) +++ trunk/src/org/hyperic/hq/bizapp/server/session/LiveDataBossEJBImpl.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,98 @@ +/* + * 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.bizapp.server.session; + +import org.hyperic.hq.appdef.shared.AppdefEntityID; +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.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 javax.ejb.SessionBean; +import javax.ejb.CreateException; +import javax.ejb.EJBException; +import javax.ejb.SessionContext; +import java.rmi.RemoteException; + +/** + * External API into the live data system. + * + * @ejb:bean name="LiveDataBoss" + * jndi-name="ejb/bizapp/LiveDataBoss" + * local-jndi-name="LocalLiveDataBoss" + * view-type="both" + * type="Stateless" + * @ejb:transaction type="Required" + */ + +public class LiveDataBossEJBImpl implements SessionBean { + + /** @ejb:create-method */ + public void ejbCreate() throws CreateException {} + public void ejbActivate() throws EJBException, RemoteException {} + public void ejbPassivate() throws EJBException, RemoteException {} + public void ejbRemove() throws EJBException, RemoteException {} + public void setSessionContext(SessionContext ctx) {} + + /** + * Get live data for a given resource + * + * The data returned is the string representation of a JSONArray. This + * is mainly because JSONArray is not Serializable. To reconstruct the + * JSONArray object use: + * + * new JSONArray(string); + * + * @ejb:interface-method + */ + public String getLiveData(int sessionId, AppdefEntityID id, + String command) + throws PermissionException, AgentConnectionException, + AgentRemoteException, AgentNotFoundException, + AppdefEntityNotFoundException, LiveDataException + { + LiveDataManagerLocal manager = LiveDataManagerEJBImpl.getOne(); + return manager.getData(id, command); + } + + /** + * Get the commands for a given resource. + * + * @ejb:interface-method + */ + public String[] getLiveDataCommands(int sessionId, AppdefEntityID id) + throws PluginNotFoundException + { + LiveDataManagerLocal manager = LiveDataManagerEJBImpl.getOne(); + + return manager.getCommands(id); + } +} Added: trunk/src/org/hyperic/hq/livedata/agent/LiveDataCommandsAPI.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/agent/LiveDataCommandsAPI.java (rev 0) +++ trunk/src/org/hyperic/hq/livedata/agent/LiveDataCommandsAPI.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,45 @@ +/* + * 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.livedata.agent; + +import org.hyperic.hq.agent.AgentAPIInfo; + +public class LiveDataCommandsAPI extends AgentAPIInfo { + private static final byte MAJOR_VER = 0x00; + private static final byte MINOR_VER = 0x00; + private static final byte BUGFIX_VER = 0x01; + + public static final String command_getData = + "hyperic.livedata.getData"; + + public static final String[] commandSet = { + command_getData + }; + + public LiveDataCommandsAPI() { + super(MAJOR_VER, MINOR_VER, BUGFIX_VER); + } +} Added: trunk/src/org/hyperic/hq/livedata/agent/client/LiveDataClient.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/agent/client/LiveDataClient.java (rev 0) +++ trunk/src/org/hyperic/hq/livedata/agent/client/LiveDataClient.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,64 @@ +/* + * 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.livedata.agent.client; + +import org.hyperic.hq.livedata.agent.LiveDataCommandsAPI; +import org.hyperic.hq.livedata.agent.commands.LiveData_args; +import org.hyperic.hq.livedata.agent.commands.LiveData_result; +import org.hyperic.hq.livedata.shared.LiveDataException; +import org.hyperic.hq.agent.client.AgentConnection; +import org.hyperic.hq.agent.AgentConnectionException; +import org.hyperic.hq.agent.AgentRemoteException; +import org.hyperic.hq.agent.AgentRemoteValue; + +import java.util.Properties; + +public class LiveDataClient { + + private LiveDataCommandsAPI _api; + private AgentConnection _agentConnection; + + public LiveDataClient(AgentConnection agentConnection) { + _agentConnection = agentConnection; + _api = new LiveDataCommandsAPI(); + } + + public String getData(String type, String command, Properties props) + throws AgentConnectionException, AgentRemoteException, + LiveDataException + { + LiveData_args args = new LiveData_args(); + + args.setConfig(type, command); + + AgentRemoteValue res = + _agentConnection.sendCommand(LiveDataCommandsAPI.command_getData, + _api.getVersion(), args); + LiveData_result val = new LiveData_result(res); + + return val.getResult(); + } +} Added: trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_args.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_args.java (rev 0) +++ trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_args.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,58 @@ +/* + * 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.livedata.agent.commands; + +import org.hyperic.hq.agent.AgentRemoteValue; + +public class LiveData_args extends AgentRemoteValue { + + private static final String PARAM_PLUGIN = "plugin"; + private static final String PARAM_COMMAND = "command"; + + public LiveData_args() { + super(); + } + + public LiveData_args(AgentRemoteValue val) { + String type = val.getValue(PARAM_PLUGIN); + String command = val.getValue(PARAM_COMMAND); + + setConfig(type, command); + } + + public void setConfig(String type, String command) { + super.setValue(PARAM_PLUGIN, type); + super.setValue(PARAM_COMMAND, command); + } + + public String getPlugin() { + return getValue(PARAM_PLUGIN); + } + + public String getCommand() { + return getValue(PARAM_COMMAND); + } +} Added: trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_result.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_result.java (rev 0) +++ trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_result.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,59 @@ +/* + * 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.livedata.agent.commands; + +import org.hyperic.hq.agent.AgentRemoteValue; +import org.hyperic.hq.agent.AgentAssertionException; +import org.hyperic.hq.agent.AgentRemoteException; + +public class LiveData_result extends AgentRemoteValue { + + private static final String PARAM_RESULT = "result"; + + public void setValue(String key, String val) { + throw new AgentAssertionException("This should never be called"); + } + + public LiveData_result() { + super(); + } + + public LiveData_result(AgentRemoteValue val) + throws AgentRemoteException { + + String result = val.getValue(PARAM_RESULT); + + setResult(result); + } + + public void setResult(String result) { + super.setValue(PARAM_RESULT, result); + } + + public String getResult() { + return super.getValue(PARAM_RESULT); + } +} Added: trunk/src/org/hyperic/hq/livedata/agent/server/LiveDataCommandsServer.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/agent/server/LiveDataCommandsServer.java (rev 0) +++ trunk/src/org/hyperic/hq/livedata/agent/server/LiveDataCommandsServer.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,102 @@ +/* + * 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.livedata.agent.server; + +import org.hyperic.hq.agent.server.AgentServerHandler; +import org.hyperic.hq.agent.server.AgentDaemon; +import org.hyperic.hq.agent.server.AgentStartException; +import org.hyperic.hq.agent.AgentAPIInfo; +import org.hyperic.hq.agent.AgentRemoteValue; +import org.hyperic.hq.agent.AgentRemoteException; +import org.hyperic.hq.livedata.agent.LiveDataCommandsAPI; +import org.hyperic.hq.livedata.agent.commands.LiveData_args; +import org.hyperic.hq.livedata.agent.commands.LiveData_result; +import org.hyperic.hq.product.LiveDataPluginManager; +import org.hyperic.hq.product.ProductPlugin; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONArray; + +import java.io.InputStream; +import java.io.OutputStream; + +public class LiveDataCommandsServer implements AgentServerHandler { + + private Log _log = LogFactory.getLog(LiveDataCommandsServer.class); + private LiveDataPluginManager _manager; + + private LiveDataCommandsAPI _commands = new LiveDataCommandsAPI(); + + public String[] getCommandSet() { + return LiveDataCommandsAPI.commandSet; + } + + public AgentAPIInfo getAPIInfo() { + return _commands; + } + + public AgentRemoteValue dispatchCommand(String cmd, AgentRemoteValue args, + InputStream inStream, + OutputStream outStream) + throws AgentRemoteException + { + if (cmd.equals(LiveDataCommandsAPI.command_getData)) { + LiveData_args res = new LiveData_args(args); + return cmdGetData(res); + } else { + throw new AgentRemoteException("Unexpected command: " + cmd); + } + } + + public void startup(AgentDaemon agent) throws AgentStartException { + + try { + _manager = (LiveDataPluginManager)agent. + getPluginManager(ProductPlugin.TYPE_LIVE_DATA); + } catch (Exception e) { + throw new AgentStartException("Unable to load live data manager", + e); + } + } + + public void shutdown() { + } + + public LiveData_result cmdGetData(LiveData_args args) + throws AgentRemoteException + { + _log.info("Asked to invoke cmdGetData for " + args.getPlugin()); + + try { + JSONArray o = _manager.getData(args.getPlugin(), args.getCommand()); + LiveData_result res = new LiveData_result(); + res.setResult(o.toString()); + return res; + } catch (Exception e) { + throw new AgentRemoteException("Unable to invoke command", e); + } + } +} Added: trunk/src/org/hyperic/hq/livedata/server/session/LiveDataManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/server/session/LiveDataManagerEJBImpl.java (rev 0) +++ trunk/src/org/hyperic/hq/livedata/server/session/LiveDataManagerEJBImpl.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,133 @@ +/* + * 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.livedata.server.session; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hyperic.hq.product.LiveDataPluginManager; +import org.hyperic.hq.product.ProductPlugin; +import org.hyperic.hq.product.PluginNotFoundException; +import org.hyperic.hq.product.server.session.ProductManagerEJBImpl; +import org.hyperic.hq.livedata.agent.client.LiveDataClient; +import org.hyperic.hq.appdef.shared.AgentConnectionUtil; +import org.hyperic.hq.appdef.shared.AppdefEntityID; +import org.hyperic.hq.appdef.shared.AgentNotFoundException; +import org.hyperic.hq.appdef.shared.AppdefEntityNotFoundException; +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.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 javax.ejb.SessionContext; +import javax.ejb.SessionBean; +import java.util.Properties; + +/** + * @ejb:bean name="LiveDataManager" + * jndi-name="ejb/livedata/LiveDataManager" + * local-jndi-name="LocalLiveDataManager" + * view-type="local" + * type="Stateless" + */ +public class LiveDataManagerEJBImpl implements SessionBean { + + private static Log _log = LogFactory.getLog(LiveDataManagerEJBImpl.class); + + private LiveDataPluginManager _manager; + + /** @ejb:create-method */ + public void ejbCreate() { + + // Get reference to the plugin manager + try { + _manager = (LiveDataPluginManager) ProductManagerEJBImpl. + getOne().getPluginManager(ProductPlugin.TYPE_LIVE_DATA); + } catch (Exception e) { + _log.error("Unable to get plugin manager", e); + } + } + + public static LiveDataManagerLocal getOne() { + try { + return LiveDataManagerUtil.getLocalHome().create(); + } catch (Exception e) { + throw new SystemException(e); + } + } + + public void ejbPostCreate() {} + public void ejbActivate() {} + public void ejbPassivate() {} + public void ejbRemove() {} + public void setSessionContext(SessionContext ctx) {} + + private String getPlugin(AppdefEntityID id) + throws AppdefEntityNotFoundException + { + ConfigManagerLocal cManager = ConfigManagerEJBImpl.getOne(); + // XXX: Seems this method should not be in the config manager. + return cManager.getPluginName(id); + } + + /** + * Get live data for a given resource. + * + * @ejb:interface-method + */ + public String getData(AppdefEntityID id, String command) + throws PermissionException, AgentNotFoundException, + AgentConnectionException, AgentRemoteException, + AppdefEntityNotFoundException, LiveDataException + { + LiveDataClient client = + new LiveDataClient(AgentConnectionUtil.getClient(id)); + Properties props = new Properties(); + + String plugin = getPlugin(id); + return client.getData(plugin, command, props); + } + + /** + * Get the available commands for a given resources. + * + * @ejb:interface-method + */ + public String[] getCommands(AppdefEntityID id) + throws PluginNotFoundException + { + try { + String plugin = getPlugin(id); + return _manager.getCommands(plugin); + } catch (AppdefEntityNotFoundException e) { + throw new PluginNotFoundException("No plugin found for " + id, e); + } + } +} Added: trunk/src/org/hyperic/hq/livedata/shared/LiveDataException.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/shared/LiveDataException.java (rev 0) +++ trunk/src/org/hyperic/hq/livedata/shared/LiveDataException.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,22 @@ +package org.hyperic.hq.livedata.shared; + +import org.hyperic.util.NestedException; + +public class LiveDataException extends NestedException { + + public LiveDataException() { + super(); + } + + public LiveDataException(String s) { + super(s); + } + + public LiveDataException(Throwable t) { + super(t); + } + + public LiveDataException(String s, Throwable t) { + super(s, t); + } +} Added: trunk/src/org/hyperic/hq/livedata/shared/LiveDataTranslator.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/shared/LiveDataTranslator.java (rev 0) +++ trunk/src/org/hyperic/hq/livedata/shared/LiveDataTranslator.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,72 @@ +/* + * 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.livedata.shared; + +import org.json.JSONObject; +import org.json.JSONArray; +import org.apache.commons.beanutils.PropertyUtils; + +import java.lang.reflect.Array; +import java.util.Map; +import java.util.Iterator; + +public class LiveDataTranslator { + + public static JSONArray encode(Object o) throws Exception { + + JSONArray jarr = new JSONArray(); + + if (o.getClass().isArray()) { + int len = Array.getLength(o); + for (int i = 0; i < len; i++) { + Object element = Array.get(o, i); + JSONObject jobj = translate(element); + jarr.put(jobj); + } + } else { + JSONObject jobj = translate(o); + jarr.put(jobj); + } + + return jarr; + } + + // XXX: handle embedded arrays + private static JSONObject translate(Object o) + throws Exception + { + JSONObject json = new JSONObject(); + + Map props = PropertyUtils.describe(o); + for (Iterator i = props.keySet().iterator(); i.hasNext(); ) { + String method = (String)i.next(); + Object val = PropertyUtils.getProperty(o, method); + json.put(method, val); + } + + return json; + } +} Added: trunk/src/org/hyperic/hq/product/LiveDataPlugin.java =================================================================== --- trunk/src/org/hyperic/hq/product/LiveDataPlugin.java (rev 0) +++ trunk/src/org/hyperic/hq/product/LiveDataPlugin.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,33 @@ +/* + * 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.product; + +public abstract class LiveDataPlugin extends GenericPlugin { + + public abstract Object getData(String command) throws PluginException; + + public abstract String[] getCommands(); +} Added: trunk/src/org/hyperic/hq/product/LiveDataPluginManager.java =================================================================== --- trunk/src/org/hyperic/hq/product/LiveDataPluginManager.java (rev 0) +++ trunk/src/org/hyperic/hq/product/LiveDataPluginManager.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,79 @@ +/* + * 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.product; + +import org.hyperic.hq.livedata.shared.LiveDataTranslator; +import org.json.JSONArray; + +import java.util.Properties; + +public class LiveDataPluginManager extends PluginManager { + + public LiveDataPluginManager(Properties props) { + super(props); + } + + public String getName() { + return ProductPlugin.TYPE_LIVE_DATA; + } + + private LiveDataPlugin getLiveDataPlugin(String plugin) + throws PluginException + { + ProductPluginManager mgr = (ProductPluginManager)getParent(); + ProductPlugin pp = mgr.getProductPlugin(plugin); + + //XXX: fix me, this only works for platforms. + LiveDataPlugin p = + (LiveDataPlugin)pp.getPlugin(ProductPlugin.TYPE_LIVE_DATA, + pp.getTypeInfo()); + if (p == null) { + throw new PluginException("Live data plugin for " + + pp.getTypeInfo() + " not found."); + } + return p; + } + + public JSONArray getData(String plugin, String command) + throws PluginException + { + LiveDataPlugin p = getLiveDataPlugin(plugin); + Object o = p.getData(command); + + try { + return LiveDataTranslator.encode(o); + } catch (Exception e) { + throw new PluginException(e); + } + } + + public String[] getCommands(String plugin) + throws PluginException + { + LiveDataPlugin p = getLiveDataPlugin(plugin); + return p.getCommands(); + } +} Modified: trunk/src/org/hyperic/hq/product/ProductPlugin.java =================================================================== --- trunk/src/org/hyperic/hq/product/ProductPlugin.java 2007-03-22 02:11:21 UTC (rev 3809) +++ trunk/src/org/hyperic/hq/product/ProductPlugin.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -41,6 +41,7 @@ public static final String TYPE_RESPONSE_TIME = "responsetime"; public static final String TYPE_LOG_TRACK = "log_track"; public static final String TYPE_CONFIG_TRACK = "config_track"; + public static final String TYPE_LIVE_DATA = "livedata"; //server import attribute propagated by ConfigManager public static final String PROP_INSTALLPATH = "installpath"; Modified: trunk/src/org/hyperic/hq/product/ProductPluginManager.java =================================================================== --- trunk/src/org/hyperic/hq/product/ProductPluginManager.java 2007-03-22 02:11:21 UTC (rev 3809) +++ trunk/src/org/hyperic/hq/product/ProductPluginManager.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -102,6 +102,7 @@ private RtPluginManager rpm; private LogTrackPluginManager ltpm; private ConfigTrackPluginManager ctpm; + private LiveDataPluginManager ldpm; public ProductPluginManager() { this(System.getProperties()); @@ -348,7 +349,8 @@ this.rpm = new RtPluginManager(props); this.ltpm = new LogTrackPluginManager(props); this.ctpm = new ConfigTrackPluginManager(props); - + this.ldpm = new LiveDataPluginManager(props); + PluginManager[] mgrs = { this.mpm, this.cpm, @@ -356,6 +358,7 @@ this.rpm, this.ltpm, this.ctpm, + this.ldpm, this //note to self }; @@ -418,6 +421,10 @@ return this.ctpm; } + public LiveDataPluginManager getLiveDataPluginManager() { + return this.ldpm; + } + public MeasurementPlugin getMeasurementPlugin(String name) { try { return (MeasurementPlugin)this.mpm.getPlugin(name); Added: trunk/src/org/hyperic/hq/product/jmx/MxLiveDataPlugin.java =================================================================== --- trunk/src/org/hyperic/hq/product/jmx/MxLiveDataPlugin.java (rev 0) +++ trunk/src/org/hyperic/hq/product/jmx/MxLiveDataPlugin.java 2007-03-22 04:17:56 UTC (rev 3810) @@ -0,0 +1,45 @@ +/* + * 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.product.jmx; + +import org.hyperic.hq.product.LiveDataPlugin; +import org.hyperic.hq.product.PluginException; + +public class MxLiveDataPlugin extends LiveDataPlugin { + + public Object getData(String command) + throws PluginException + { + return new Object(); + } + + public String[] getCommands() { + return new String[0]; + } + + public static void main(String[] args) throws Exception { + } +} |