modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java | 2 modules/enterprise/binding/src/main/java/org/rhq/bindings/ScriptEngineFactory.java | 2 modules/enterprise/binding/src/main/java/org/rhq/bindings/client/AbstractRhqFacadeProxy.java | 103 ++++ modules/enterprise/remoting/client-api/src/main/java/org/rhq/enterprise/client/RemoteClientProxy.java | 85 +-- modules/enterprise/server/client-api/pom.xml | 21 modules/enterprise/server/client-api/src/main/java/org/rhq/enterprise/client/LocalClient.java | 223 ++++++++++ modules/enterprise/server/client-api/src/main/java/org/rhq/enterprise/client/LocalClientProxy.java | 67 +++ modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java | 19 modules/enterprise/server/plugins/alert-cli/pom.xml | 9 modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliSender.java | 112 +++++ modules/enterprise/server/plugins/alert-cli/src/main/resources/META-INF/rhq-serverplugin.xml | 26 + modules/enterprise/server/plugins/pom.xml | 1 12 files changed, 592 insertions(+), 78 deletions(-)
New commits: commit 31fada88661aba7a52d79519e32b9742224ffcb0 Author: Lukas Krejci lkrejci@redhat.com Date: Sat Jan 15 00:39:26 2011 +0100
Some initial code for the alert-cli plugin.
diff --git a/modules/enterprise/server/plugins/alert-cli/pom.xml b/modules/enterprise/server/plugins/alert-cli/pom.xml index 55aa5d3..5349beb 100644 --- a/modules/enterprise/server/plugins/alert-cli/pom.xml +++ b/modules/enterprise/server/plugins/alert-cli/pom.xml @@ -16,6 +16,15 @@ <developerConnection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/enterprise/server/plugins/alert-cli/</developerConnection> </scm> + <dependencies> + <dependency> + <groupId>org.rhq</groupId> + <artifactId>rhq-server-client-api</artifactId> + <version>4.0.0-SNAPSHOT</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + </dependencies> <properties> <scm.module.path>modules/enterprise/server/plugins/alert-cli/</scm.module.path> </properties> diff --git a/modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliSender.java b/modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliSender.java new file mode 100644 index 0000000..64d1a22 --- /dev/null +++ b/modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliSender.java @@ -0,0 +1,112 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +package org.rhq.enterprise.server.plugins.alertCli; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Collections; + +import javax.script.ScriptEngine; +import javax.script.ScriptException; + +import org.apache.commons.logging.LogFactory; + +import org.apache.commons.logging.Log; + +import org.rhq.bindings.ScriptEngineFactory; +import org.rhq.bindings.StandardBindings; +import org.rhq.bindings.util.PackageFinder; +import org.rhq.core.domain.alert.Alert; +import org.rhq.core.domain.alert.notification.SenderResult; +import org.rhq.core.domain.auth.Subject; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.enterprise.client.LocalClient; +import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent; +import org.rhq.enterprise.server.plugin.pc.alert.AlertSender; +import org.rhq.enterprise.server.util.LookupUtil; + +/** + * Uses CLI to perform the alert notification. + * + * @author Lukas Krejci + */ +public class CliSender extends AlertSender<ServerPluginComponent> { + private static final Log LOG = LogFactory.getLog(CliSender.class); + + public SenderResult send(Alert alert) { + SenderResult result = new SenderResult(); + BufferedReader reader = null; + try { + ScriptEngine engine = getScriptEngine(alert); + + PropertySimple packageIdProp = alertParameters.getSimple("packageId"); + + if (packageIdProp == null) { + return SenderResult.getSimpleFailure("The configuration doesn't contain the mandatory 'packageId' property. This should not happen."); + } + + Integer packageId = packageIdProp.getIntegerValue(); + + if (packageId == null) { + return SenderResult.getSimpleFailure("No script defined."); + } + + //TODO getting the package bits is going to require changes to the content manager + //this is gonna have to be asynchronous because the package bits are possibly + //only going to be downloaded. + InputStream packageBits = null; + + reader = new BufferedReader(new InputStreamReader(packageBits)); + + Object ret = engine.eval(reader); + + //TODO what to do with the return value, if any + + return result; + } catch (Exception e) { + //TODO I don't like this + return SenderResult.getSimpleFailure(e.getMessage()); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + LOG.error("Failed to close the script reader.", e); + } + } + } + } + + private ScriptEngine getScriptEngine(Alert alert) throws ScriptException, IOException { + Subject overlord = LookupUtil.getSubjectManager().getOverlord(); + + LocalClient client = new LocalClient(overlord); + + //TODO define some meaningful printwriter + StandardBindings bindings = new StandardBindings(null, client); + bindings.put("alert", alert); + + return ScriptEngineFactory.getScriptEngine("JavaScript", new PackageFinder(Collections.<File> emptyList()), + bindings); + } +} diff --git a/modules/enterprise/server/plugins/alert-cli/src/main/resources/META-INF/rhq-serverplugin.xml b/modules/enterprise/server/plugins/alert-cli/src/main/resources/META-INF/rhq-serverplugin.xml new file mode 100644 index 0000000..ffcbb4b --- /dev/null +++ b/modules/enterprise/server/plugins/alert-cli/src/main/resources/META-INF/rhq-serverplugin.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<alert-plugin + name="alert-cli" + displayName="Alert:CLI" + xmlns="urn:xmlns:rhq-serverplugin.alert" + xmlns:c="urn:xmlns:rhq-configuration" + xmlns:serverplugin="urn:xmlns:rhq-serverplugin" + package="org.rhq.enterprise.server.plugins.alertCli" + description="Alert sender plugin that can execute a CLI script." + > + + serverplugin:help + Used to execute a CLI script. + </serverplugin:help> + + <!-- How does this sender show up in drop downs etc --> + <short-name>CLI Script</short-name> + + <!-- Class that does the actual sending --> + <plugin-class>CliSender</plugin-class> + + <alert-configuration> + <c:simple-property name="packageId" type="integer" required="true" description="The id of the package containing the script to execute."/> + </alert-configuration> +</alert-plugin> \ No newline at end of file diff --git a/modules/enterprise/server/plugins/pom.xml b/modules/enterprise/server/plugins/pom.xml index 29d09dd..86d8cfe 100644 --- a/modules/enterprise/server/plugins/pom.xml +++ b/modules/enterprise/server/plugins/pom.xml @@ -80,6 +80,7 @@ --> <module>alert-snmp</module> <module>alert-subject</module> + <module>alert-cli</module> <module>cobbler</module> <module>filetemplate-bundle</module> <module>ant-bundle</module>
commit 85a908e58fd9f691c6e730ec7a358e3b97a9ca7c Author: Lukas Krejci lkrejci@redhat.com Date: Sat Jan 15 00:37:43 2011 +0100
Defining a new implementation of the RhqFacade that uses the local SLSBs and created a new server/client-api module for it to be used for running the server-side CLI scripts.
diff --git a/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/AbstractRhqFacadeProxy.java b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/AbstractRhqFacadeProxy.java new file mode 100644 index 0000000..bacdafb --- /dev/null +++ b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/AbstractRhqFacadeProxy.java @@ -0,0 +1,103 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +package org.rhq.bindings.client; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +import org.rhq.bindings.util.InterfaceSimplifier; +import org.rhq.core.domain.auth.Subject; + +/** + * An abstract {@link InvocationHandler} to help the script users create proxies to actually call the + * correct methods on RHQ. This base implementation provides its inheritors with the facade impl and the concrete + * manager they should invoke the methods on and does the "de-simplification" of the arguments (i.e. the opposite of {@link InterfaceSimplifier#simplify(Class)}. + * + * @author Lukas Krejci + */ +public abstract class AbstractRhqFacadeProxy<T extends RhqFacade> implements InvocationHandler { + + private T facade; + private RhqManagers manager; + + protected AbstractRhqFacadeProxy(T facade, RhqManagers manager) { + this.facade = facade; + this.manager = manager; + } + + protected T getRhqFacade() { + return facade; + } + + protected RhqManagers getManager() { + return manager; + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Class<?>[] params = method.getParameterTypes(); + + try { + Class<?>[] interfaces = method.getDeclaringClass().getInterfaces(); + + Class<?> originalClass; + if (interfaces != null && interfaces.length > 0) { + originalClass = interfaces[0]; + } else { + originalClass = method.getDeclaringClass(); + } + + // See if this method really exists or if its a simplified set of parameters + originalClass.getMethod(method.getName(), method.getParameterTypes()); + + } catch (Exception e) { + // If this was not in the original interface it must've been added in the Simplifier... add back the subject argument + int numArgs = (null == args) ? 0 : args.length; + Object[] newArgs = new Object[numArgs + 1]; + if (numArgs > 0) { + System.arraycopy(args, 0, newArgs, 1, numArgs); + } + newArgs[0] = getRhqFacade().getSubject(); + args = newArgs; + + int numParams = (null == params) ? 0 : params.length; + Class<?>[] newParams = new Class[numParams + 1]; + if (numParams > 0) { + System.arraycopy(params, 0, newParams, 1, numParams); + } + newParams[0] = Subject.class; + params = newParams; + } + + return doInvoke(proxy, method, params, args); + } + + /** + * This method actually calls the method according to the RhqFacade's implementation. The <code>argTypes</code> + * and <code>args</code> are de-simplified (and thus the method can't be supplied just as a simple {@link Method} instance). + * + * @param proxy the proxy the method is executing on + * @param method the original method + * @param argTypes the de-simplified argument types + * @param args the de-simplified argumens + * @return the result of the invocation + * @throws Throwable if invocation throws an error + */ + protected abstract Object doInvoke(Object proxy, Method originalMethod, Class<?>[] argTypes, Object[] args) throws Throwable; +} diff --git a/modules/enterprise/remoting/client-api/src/main/java/org/rhq/enterprise/client/RemoteClientProxy.java b/modules/enterprise/remoting/client-api/src/main/java/org/rhq/enterprise/client/RemoteClientProxy.java index 5e897cb..2d57488 100644 --- a/modules/enterprise/remoting/client-api/src/main/java/org/rhq/enterprise/client/RemoteClientProxy.java +++ b/modules/enterprise/remoting/client-api/src/main/java/org/rhq/enterprise/client/RemoteClientProxy.java @@ -18,18 +18,14 @@ */ package org.rhq.enterprise.client;
-import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy;
-import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.jboss.remoting.invocation.NameBasedInvocation;
+import org.rhq.bindings.client.AbstractRhqFacadeProxy; import org.rhq.bindings.client.RhqManagers; import org.rhq.bindings.util.InterfaceSimplifier; -import org.rhq.core.domain.auth.Subject; import org.rhq.core.server.ExternalizableStrategy;
/** @@ -37,19 +33,16 @@ import org.rhq.core.server.ExternalizableStrategy; * to SLSB Remotes over a remoting invoker. * * @author Greg Hinkle + * @author Lukas Krejci */ -public class RemoteClientProxy implements InvocationHandler { - private RemoteClient client; - private RhqManagers manager; +public class RemoteClientProxy extends AbstractRhqFacadeProxy<RemoteClient> {
- // public RHQRemoteClientProxy(RHQRemoteClient client, Class targetClass) { public RemoteClientProxy(RemoteClient client, RhqManagers manager) { - this.client = client; - this.manager = manager; + super(client, manager); }
public Class<?> getRemoteInterface() { - return this.manager.remote(); + return this.getManager().remote(); }
@SuppressWarnings("unchecked") @@ -57,7 +50,7 @@ public class RemoteClientProxy implements InvocationHandler { try { RemoteClientProxy gpc = new RemoteClientProxy(remoteClient, manager);
- Class<?> intf = InterfaceSimplifier.simplify(gpc.manager.remote()); + Class<?> intf = InterfaceSimplifier.simplify(manager.remote());
return (T) Proxy .newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { intf }, gpc); @@ -67,62 +60,32 @@ public class RemoteClientProxy implements InvocationHandler { }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - try { - // make sure we're serializing in Remote Client mode for rich serialization - ExternalizableStrategy.setStrategy(ExternalizableStrategy.Subsystem.REFLECTIVE_SERIALIZATION); - - String methodName = manager.beanName() + ":" + method.getName(); - - Class<?>[] params = method.getParameterTypes(); - - try { - Class<?>[] interfaces = method.getDeclaringClass().getInterfaces(); - - Class<?> originalClass; - if (interfaces != null && interfaces.length > 0) { - originalClass = interfaces[0]; - } else { - originalClass = method.getDeclaringClass(); - } - - // See if this method really exists or if its a simplified set of parameters - originalClass.getMethod(method.getName(), method.getParameterTypes()); + return super.invoke(proxy, method, args); + } catch (Throwable t) { + t.printStackTrace(); + throw t; + } + }
- } catch (Exception e) { - // If this was not in the original interface it must've been added in the Simplifier... add back the subject argument - int numArgs = (null == args) ? 0 : args.length; - Object[] newArgs = new Object[numArgs + 1]; - if (numArgs > 0) { - System.arraycopy(args, 0, newArgs, 1, numArgs); - } - newArgs[0] = client.getSubject(); - args = newArgs; + protected Object doInvoke(Object proxy, Method originalMethod, java.lang.Class<?>[] argTypes, Object[] args) throws Throwable { + ExternalizableStrategy.setStrategy(ExternalizableStrategy.Subsystem.REFLECTIVE_SERIALIZATION);
- int numParams = (null == params) ? 0 : params.length; - Class<?>[] newParams = new Class[numParams + 1]; - if (numParams > 0) { - System.arraycopy(params, 0, newParams, 1, numParams); - } - newParams[0] = Subject.class; - params = newParams; - } + String methodName = getManager().beanName() + ":" + originalMethod.getName();
- String[] paramSig = createParamSignature(params); - NameBasedInvocation request = new NameBasedInvocation(methodName, args, paramSig); + String[] paramSig = createParamSignature(argTypes); + + NameBasedInvocation request = new NameBasedInvocation(methodName, args, paramSig);
- Object response = client.getRemotingClient().invoke(request); + Object response = getRhqFacade().getRemotingClient().invoke(request);
- if (response instanceof Throwable) { - throw (Throwable) response; - } - return response; - } catch (Throwable t) { - t.printStackTrace(); - throw t; + if (response instanceof Throwable) { + throw (Throwable) response; } + + return response; } - + private String[] createParamSignature(Class<?>[] types) { String[] paramSig = new String[types.length]; for (int x = 0; x < types.length; x++) { diff --git a/modules/enterprise/server/client-api/pom.xml b/modules/enterprise/server/client-api/pom.xml new file mode 100644 index 0000000..47d1f6b --- /dev/null +++ b/modules/enterprise/server/client-api/pom.xml @@ -0,0 +1,21 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>rhq-enterprise-server-parent</artifactId> + <groupId>org.rhq</groupId> + <version>4.0.0-SNAPSHOT</version> + </parent> + <groupId>org.rhq</groupId> + <artifactId>rhq-server-client-api</artifactId> + <version>4.0.0-SNAPSHOT</version> + <name>RHQ Enterprise Server Client API</name> + <description>The implementation of the client API when accessing the server locally</description> + <dependencies> + <dependency> + <groupId>org.rhq</groupId> + <artifactId>rhq-script-bindings</artifactId> + <version>4.0.0-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + </dependencies> +</project> \ No newline at end of file diff --git a/modules/enterprise/server/client-api/src/main/java/org/rhq/enterprise/client/LocalClient.java b/modules/enterprise/server/client-api/src/main/java/org/rhq/enterprise/client/LocalClient.java new file mode 100644 index 0000000..0462638 --- /dev/null +++ b/modules/enterprise/server/client-api/src/main/java/org/rhq/enterprise/client/LocalClient.java @@ -0,0 +1,223 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +package org.rhq.enterprise.client; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.rhq.bindings.client.RhqFacade; +import org.rhq.bindings.client.RhqManagers; +import org.rhq.core.domain.auth.Subject; +import org.rhq.enterprise.server.alert.AlertDefinitionManagerRemote; +import org.rhq.enterprise.server.alert.AlertManagerRemote; +import org.rhq.enterprise.server.auth.SubjectManagerRemote; +import org.rhq.enterprise.server.authz.RoleManagerRemote; +import org.rhq.enterprise.server.bundle.BundleManagerRemote; +import org.rhq.enterprise.server.configuration.ConfigurationManagerRemote; +import org.rhq.enterprise.server.content.ContentManagerRemote; +import org.rhq.enterprise.server.content.RepoManagerRemote; +import org.rhq.enterprise.server.discovery.DiscoveryBossRemote; +import org.rhq.enterprise.server.event.EventManagerRemote; +import org.rhq.enterprise.server.install.remote.RemoteInstallManagerRemote; +import org.rhq.enterprise.server.measurement.AvailabilityManagerRemote; +import org.rhq.enterprise.server.measurement.CallTimeDataManagerRemote; +import org.rhq.enterprise.server.measurement.MeasurementBaselineManagerRemote; +import org.rhq.enterprise.server.measurement.MeasurementDataManagerRemote; +import org.rhq.enterprise.server.measurement.MeasurementDefinitionManagerRemote; +import org.rhq.enterprise.server.measurement.MeasurementScheduleManagerRemote; +import org.rhq.enterprise.server.operation.OperationManagerRemote; +import org.rhq.enterprise.server.report.DataAccessManagerRemote; +import org.rhq.enterprise.server.resource.ResourceFactoryManagerRemote; +import org.rhq.enterprise.server.resource.ResourceManagerRemote; +import org.rhq.enterprise.server.resource.ResourceTypeManagerRemote; +import org.rhq.enterprise.server.resource.group.ResourceGroupManagerRemote; +import org.rhq.enterprise.server.search.SavedSearchManagerRemote; +import org.rhq.enterprise.server.support.SupportManagerRemote; +import org.rhq.enterprise.server.system.SystemManagerRemote; +import org.rhq.enterprise.server.tagging.TagManagerRemote; +import org.rhq.enterprise.server.util.LookupUtil; + +/** + * + * + * @author Lukas Krejci + */ +public class LocalClient implements RhqFacade { + + private static final Log LOG = LogFactory.getLog(LocalClient.class); + + private Subject subject; + private Map<String, Object> managers; + + public LocalClient(Subject subject) { + this.subject = subject; + } + + public Subject getSubject() { + return subject; + } + + public Subject login(String user, String password) throws Exception { + return subject; + } + + public void logout() { + } + + public boolean isLoggedIn() { + return true; + } + + public AlertManagerRemote getAlertManager() { + return getProxy(LookupUtil.getAlertManager(), AlertManagerRemote.class); + } + + public AlertDefinitionManagerRemote getAlertDefinitionManager() { + return getProxy(LookupUtil.getAlertDefinitionManager(), AlertDefinitionManagerRemote.class); + } + + public AvailabilityManagerRemote getAvailabilityManager() { + return getProxy(LookupUtil.getAvailabilityManager(), AvailabilityManagerRemote.class); + } + + public BundleManagerRemote getBundleManager() { + return getProxy(LookupUtil.getBundleManager(), BundleManagerRemote.class); + } + + public CallTimeDataManagerRemote getCallTimeDataManager() { + return getProxy(LookupUtil.getCallTimeDataManager(), CallTimeDataManagerRemote.class); + } + + public RepoManagerRemote getRepoManager() { + return getProxy(LookupUtil.getRepoManagerLocal(), RepoManagerRemote.class); + } + + public ConfigurationManagerRemote getConfigurationManager() { + return getProxy(LookupUtil.getConfigurationManager(), ConfigurationManagerRemote.class); + } + + public ContentManagerRemote getContentManager() { + return getProxy(LookupUtil.getContentManager(), ContentManagerRemote.class); + } + + public DataAccessManagerRemote getDataAccessManager() { + return getProxy(LookupUtil.getDataAccessManager(), DataAccessManagerRemote.class); + } + + public DiscoveryBossRemote getDiscoveryBoss() { + return getProxy(LookupUtil.getDiscoveryBoss(), DiscoveryBossRemote.class); + } + + public EventManagerRemote getEventManager() { + return getProxy(LookupUtil.getEventManager(), EventManagerRemote.class); + } + + public MeasurementBaselineManagerRemote getMeasurementBaselineManager() { + return getProxy(LookupUtil.getMeasurementBaselineManager(), MeasurementBaselineManagerRemote.class); + } + + public MeasurementDataManagerRemote getMeasurementDataManager() { + return getProxy(LookupUtil.getMeasurementDataManager(), MeasurementDataManagerRemote.class); + } + + public MeasurementDefinitionManagerRemote getMeasurementDefinitionManager() { + return getProxy(LookupUtil.getMeasurementDefinitionManager(), MeasurementDefinitionManagerRemote.class); + } + + public MeasurementScheduleManagerRemote getMeasurementScheduleManager() { + return getProxy(LookupUtil.getMeasurementScheduleManager(), MeasurementScheduleManagerRemote.class); + } + + public OperationManagerRemote getOperationManager() { + return getProxy(LookupUtil.getOperationManager(), OperationManagerRemote.class); + } + + public ResourceManagerRemote getResourceManager() { + return getProxy(LookupUtil.getResourceManager(), ResourceManagerRemote.class); + } + + public ResourceFactoryManagerRemote getResourceFactoryManager() { + return getProxy(LookupUtil.getResourceFactoryManager(), ResourceFactoryManagerRemote.class); + } + + public ResourceGroupManagerRemote getResourceGroupManager() { + return getProxy(LookupUtil.getResourceGroupManager(), ResourceGroupManagerRemote.class); + } + + public ResourceTypeManagerRemote getResourceTypeManager() { + return getProxy(LookupUtil.getResourceTypeManager(), ResourceTypeManagerRemote.class); + } + + public RoleManagerRemote getRoleManager() { + return getProxy(LookupUtil.getRoleManager(), RoleManagerRemote.class); + } + + public SavedSearchManagerRemote getSavedSearchManager() { + return getProxy(LookupUtil.getSavedSearchManager(), SavedSearchManagerRemote.class); + } + + public SubjectManagerRemote getSubjectManager() { + return getProxy(LookupUtil.getSubjectManager(), SubjectManagerRemote.class); + } + + public SupportManagerRemote getSupportManager() { + return getProxy(LookupUtil.getSupportManager(), SupportManagerRemote.class); + } + + public SystemManagerRemote getSystemManager() { + return getProxy(LookupUtil.getSystemManager(), SystemManagerRemote.class); + } + + public RemoteInstallManagerRemote getRemoteInstallManager() { + return getProxy(LookupUtil.getRemoteInstallManager(), RemoteInstallManagerRemote.class); + } + + public TagManagerRemote getTagManager() { + return getProxy(LookupUtil.getTagManager(), TagManagerRemote.class); + } + + public Map<String, Object> getManagers() { + if (managers == null) { + + managers = new HashMap<String, Object>(); + + for (RhqManagers manager : RhqManagers.values()) { + try { + Method m = getClass().getMethod("get" + manager.name()); + managers.put(manager.name(), m.invoke(this)); + } catch (Throwable e) { + LOG.error("Failed to load manager " + manager + " due to missing class.", e); + } + } + } + + return managers; + } + + private <T> T getProxy(Object slsb, Class<T> iface) { + RhqManagers manager = RhqManagers.forInterface(iface); + + return iface.cast(new LocalClientProxy(slsb, this, manager)); + } +} diff --git a/modules/enterprise/server/client-api/src/main/java/org/rhq/enterprise/client/LocalClientProxy.java b/modules/enterprise/server/client-api/src/main/java/org/rhq/enterprise/client/LocalClientProxy.java new file mode 100644 index 0000000..5f3ff90 --- /dev/null +++ b/modules/enterprise/server/client-api/src/main/java/org/rhq/enterprise/client/LocalClientProxy.java @@ -0,0 +1,67 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +package org.rhq.enterprise.client; + +import java.lang.reflect.Method; +import java.util.Arrays; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.rhq.bindings.client.AbstractRhqFacadeProxy; +import org.rhq.bindings.client.RhqManagers; + +/** + * This is a proxy interface that simply calls given (de-simplified) method on a provided object. + * The use-case here is to invoke a method from a remote interface on the local SLSB. + * + * @author Lukas Krejci + */ +public class LocalClientProxy extends AbstractRhqFacadeProxy<LocalClient> { + + private static final Log LOG = LogFactory.getLog(LocalClientProxy.class); + + private Object localSLSB; + + public LocalClientProxy(Object localSLSB, LocalClient client, RhqManagers manager) { + super(client, manager); + this.localSLSB = localSLSB; + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + try { + return super.invoke(proxy, method, args); + } catch (Throwable t) { + LOG.warn("Proxied invocation of method [" + method + "] on [" + getManager() + "] failed.", t); + throw t; + } + } + + protected Object doInvoke(Object proxy, Method originalMethod, java.lang.Class<?>[] argTypes, Object[] args) throws Throwable { + try { + Method realMethod = localSLSB.getClass().getMethod(originalMethod.getName(), argTypes); + + return realMethod.invoke(localSLSB, args); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException("Method [" + originalMethod + "] does not have a desimplified counterpart with arguments " + Arrays.asList(argTypes) + ".", e); + } + }; + +}
commit f099315a543671acf0098838b6ccded98b591091 Author: Lukas Krejci lkrejci@redhat.com Date: Sat Jan 15 00:33:54 2011 +0100
remove unused imports
diff --git a/modules/enterprise/binding/src/main/java/org/rhq/bindings/ScriptEngineFactory.java b/modules/enterprise/binding/src/main/java/org/rhq/bindings/ScriptEngineFactory.java index 0fdf46a..7472953 100644 --- a/modules/enterprise/binding/src/main/java/org/rhq/bindings/ScriptEngineFactory.java +++ b/modules/enterprise/binding/src/main/java/org/rhq/bindings/ScriptEngineFactory.java @@ -37,9 +37,7 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.bindings.engine.JsEngineInitializer; import org.rhq.bindings.engine.ScriptEngineInitializer; -import org.rhq.bindings.export.Exporter; import org.rhq.bindings.util.PackageFinder; -import org.rhq.core.domain.util.PageControl;
/** * This is RHQ specific imitation of ScriptEngineFactory.
commit a825962db3c7bacf83f3c7f5bf11f33dc8b2ebb1 Merge: c240a5c... 4d895c6... Author: Lukas Krejci lkrejci@redhat.com Date: Fri Jan 14 14:26:22 2011 +0100
Merge branch 'master' into cli-alert-notifs
commit 4d895c6794fc8b746e4f8c2f7593b7deaa083d76 Author: Lukas Krejci lkrejci@redhat.com Date: Fri Jan 14 14:25:40 2011 +0100
Fix the discrepancy between the return type of the query ResourceType.FIND_ALL_TEMPLATE_COUNT_COMPOSITES and the type expected in the code.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java index 947bf62..9e0ce28 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java @@ -96,8 +96,6 @@ import org.rhq.core.domain.util.Summary; @NamedQuery(name = ResourceType.FIND_CHILDREN_BY_PARENT, query = "SELECT DISTINCT rt FROM ResourceType AS rt " + "JOIN FETCH rt.parentResourceTypes AS pa " + // also fetch parents, as we need them later "WHERE rt.deleted = false and pa IN (:resourceType)"), - // template count composites need the parent types fetched; however, because of a quirk in hibernate, - // we can't use the template component constructor in the select, we'll build the composites in our code @NamedQuery(name = ResourceType.FIND_ALL_TEMPLATE_COUNT_COMPOSITES, query = "" // + "SELECT new org.rhq.core.domain.resource.composite.ResourceTypeTemplateCountComposite" // + "(" // diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java index b4086b9..e225f7e 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java @@ -391,23 +391,19 @@ public class ResourceTypeManagerBean implements ResourceTypeManagerLocal, Resour ResourceFacetsCache.getSingleton().reload(facets); }
- @SuppressWarnings("unchecked") public Map<Integer, ResourceTypeTemplateCountComposite> getTemplateCountCompositeMap() { Query templateCountQuery = entityManager.createNamedQuery(ResourceType.FIND_ALL_TEMPLATE_COUNT_COMPOSITES); - // the weirdness here is because we needed to JOIN FETCH the parent types, but hibernate bombs when you do that - // and try to use a composite constructor in the query itself. We need to build the composites here. - // Our results will be a list of arrays that we'll build into the composite below - List<?> results = templateCountQuery.getResultList(); + + @SuppressWarnings("unchecked") + List<ResourceTypeTemplateCountComposite> results = (List<ResourceTypeTemplateCountComposite>) templateCountQuery.getResultList();
// we don't need to send all the data in resource types over the wire, so we'll be scrubbing the types // to avoid the scrubbed types getting persisted back to the db, let's clear the persistence context entityManager.clear();
Map<Integer, ResourceTypeTemplateCountComposite> compositeMap = new HashMap<Integer, ResourceTypeTemplateCountComposite>(); - for (Object result : results) { - Object[] array = (Object[]) result; - - ResourceType type = (ResourceType) array[0]; + for (ResourceTypeTemplateCountComposite result : results) { + ResourceType type = result.getType();
// scrub it to avoid sending data over the wire we don't need // some of these are eagerly loaded, but my paranoia says assume everything is eagerly loaded to purge it all @@ -427,10 +423,7 @@ public class ResourceTypeManagerBean implements ResourceTypeManagerLocal, Resour type.setResources(null); type.setSubCategory(null);
- ResourceTypeTemplateCountComposite composite = new ResourceTypeTemplateCountComposite(type, - ((Number) array[1]).longValue(), ((Number) array[2]).longValue(), ((Number) array[3]).longValue(), - ((Number) array[4]).longValue()); - compositeMap.put(composite.getType().getId(), composite); + compositeMap.put(type.getId(), result); }
return compositeMap;
rhq-commits@lists.fedorahosted.org