modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
| 5
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java
| 6
modules/core/domain/src/main/java/org/rhq/core/domain/util/OSGiVersion.java
| 153 ++++++
modules/core/domain/src/main/java/org/rhq/core/domain/util/OSGiVersionComparator.java
| 62 --
modules/enterprise/binding/src/main/java/org/rhq/bindings/SandboxedScriptEngine.java
| 1
modules/enterprise/binding/src/main/java/org/rhq/bindings/ScriptEngineFactory.java
| 15
modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientFactory.java
| 227 +++++-----
modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
| 18
modules/enterprise/binding/src/main/java/org/rhq/bindings/engine/JsEngineInitializer.java
| 6
modules/enterprise/binding/src/main/java/org/rhq/bindings/util/ResourceTypeFingerprint.java
| 182 ++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/CliNotificationSenderForm.java
| 46 +-
modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
| 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/auth/SubjectManagerBean.java
| 7
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
| 7
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerLocal.java
| 11
modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliComponent.java
| 159 ++++---
modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliSender.java
| 28 -
modules/enterprise/server/plugins/alert-cli/src/main/resources/META-INF/rhq-serverplugin.xml
| 18
18 files changed, 737 insertions(+), 216 deletions(-)
New commits:
commit 28f92d3dfcd8ac86c89e241b52a1dee6084f9a3f
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Feb 25 17:52:56 2011 +0100
Caching custom interfaces for resource proxies obtained from ProxyFactory.
This is especially important in the server environment so that we don't waste the
permgen if we don't have to.
By relying on the resource type structure to determine equality of resource types,
plugin updates are seemlessly supported.
diff --git
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientFactory.java
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientFactory.java
index 480a5dd..6f15e81 100644
---
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientFactory.java
+++
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientFactory.java
@@ -4,10 +4,10 @@ import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
import javax.jws.WebParam;
@@ -27,6 +27,7 @@ import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
import org.rhq.bindings.util.ConfigurationClassBuilder;
+import org.rhq.bindings.util.ResourceTypeFingerprint;
import org.rhq.core.domain.resource.ResourceCreationDataType;
/**
@@ -36,8 +37,16 @@ import org.rhq.core.domain.resource.ResourceCreationDataType;
*/
public class ResourceClientFactory {
+ private static class CacheRecord {
+ public ResourceTypeFingerprint fingerprint;
+ public Class<?> iface;
+ }
+
private static final Log LOG = LogFactory.getLog(ResourceClientFactory.class);
+ //keys are resource type ids
+ private static HashMap<Integer, CacheRecord> CUSTOM_CLASS_CACHE = new
HashMap<Integer, CacheRecord>();
+
private RhqFacade rhqFacade;
private PrintWriter outputWriter;
@@ -46,8 +55,6 @@ public class ResourceClientFactory {
this.outputWriter = outputWriter;
}
- private static AtomicInteger classIndex = new AtomicInteger();
-
public RhqFacade getRemoteClient() {
return rhqFacade;
}
@@ -60,73 +67,22 @@ public class ResourceClientFactory {
ResourceClientProxy proxy = new ResourceClientProxy(this, resourceId);
Class<?> customInterface = null;
- try {
- // define the dynamic class
- ClassPool pool = ClassPool.getDefault();
- CtClass customClass = pool.makeInterface(ResourceClientProxy.class.getName()
+ "__Custom__"
- + classIndex.getAndIncrement());
-
- for (String key : proxy.allProperties.keySet()) {
- Object prop = proxy.allProperties.get(key);
-
- if (prop instanceof ResourceClientProxy.Measurement) {
- ResourceClientProxy.Measurement m = (ResourceClientProxy.Measurement)
prop;
- String name = ResourceClientProxy.getterName(key);
-
- try {
- ResourceClientProxy.class.getMethod(name);
- } catch (NoSuchMethodException nsme) {
- CtMethod method =
CtNewMethod.abstractMethod(pool.get(ResourceClientProxy.Measurement.class.getName()),
- ResourceClientProxy.getterName(key), new CtClass[0], new
CtClass[0], customClass);
- customClass.addMethod(method);
- }
- } else if (prop instanceof ResourceClientProxy.Operation) {
- ResourceClientProxy.Operation o = (ResourceClientProxy.Operation)
prop;
-
- LinkedHashMap<String, CtClass> types =
ConfigurationClassBuilder.translateParameters(o
- .getDefinition().getParametersConfigurationDefinition());
-
- CtClass[] params = new CtClass[types.size()];
- int x = 0;
- for (String param : types.keySet()) {
- params[x++] = types.get(param);
- }
-
- CtMethod method =
CtNewMethod.abstractMethod(ConfigurationClassBuilder.translateConfiguration(o
- .getDefinition().getResultsConfigurationDefinition()),
ResourceClientProxy.simpleName(key), params,
- new javassist.CtClass[0], customClass);
-
- // Setup @WebParam annotations so the signatures have the config prop
names
- Annotation[][] newAnnotations = new Annotation[params.length][1];
- int i = 0;
- for (String paramName : types.keySet()) {
- newAnnotations[i] = new Annotation[1];
-
- newAnnotations[i][0] = new Annotation(WebParam.class.getName(),
method.getMethodInfo()
- .getConstPool());
- newAnnotations[i][0].addMemberValue("name", new
StringMemberValue(paramName, method
- .getMethodInfo().getConstPool()));
- i++;
- }
-
- ParameterAnnotationsAttribute newAnnotationsAttribute = new
ParameterAnnotationsAttribute(
- method.getMethodInfo().getConstPool(),
ParameterAnnotationsAttribute.visibleTag);
- newAnnotationsAttribute.setAnnotations(newAnnotations);
- method.getMethodInfo().addAttribute(newAnnotationsAttribute);
-
- customClass.addMethod(method);
- }
+ synchronized (CUSTOM_CLASS_CACHE) {
+ Integer resourceTypeId = proxy.getResourceType().getId();
+ CacheRecord record = CUSTOM_CLASS_CACHE.get(resourceTypeId);
+
+ //if we don't have a cached custom interface for this resource type
+ //or if the resource type has changed, generate the custom iface for it.
+ if (record == null || !record.fingerprint.equals(proxy.fingerprint)) {
+ record = new CacheRecord();
+ record.fingerprint = proxy.fingerprint;
+ record.iface = defineCustomInterface(proxy);
+ CUSTOM_CLASS_CACHE.put(resourceTypeId, record);
}
-
- customInterface = customClass.toClass();
- } catch (NotFoundException e) {
- LOG.error("Could not create custom interface for resource with id "
+ resourceId, e);
- } catch (CannotCompileException e) {
- LOG.error("Could not create custom interface for resource with id "
+ resourceId, e);
- } catch (Exception e) {
- LOG.error("Could not create custom interface for resource with id "
+ resourceId, e);
+
+ customInterface = record.iface;
}
-
+
if (customInterface != null) {
List<Class<?>> interfaces = new
ArrayList<Class<?>>();
@@ -185,4 +141,73 @@ public class ResourceClientFactory {
protected MethodHandler instantiateMethodHandler(ResourceClientProxy proxy,
List<Class<?>> interfaces, RhqFacade remoteClient) {
return new ResourceClientProxy.ClientProxyMethodHandler(proxy, remoteClient);
}
+
+ private Class<?> defineCustomInterface(ResourceClientProxy proxy) {
+ try {
+ // define the dynamic class
+ ClassPool pool = ClassPool.getDefault();
+ CtClass customClass = pool.makeInterface(ResourceClientProxy.class.getName()
+ proxy.fingerprint);
+
+ for (String key : proxy.allProperties.keySet()) {
+ Object prop = proxy.allProperties.get(key);
+
+ if (prop instanceof ResourceClientProxy.Measurement) {
+ String name = ResourceClientProxy.getterName(key);
+
+ try {
+ ResourceClientProxy.class.getMethod(name);
+ } catch (NoSuchMethodException nsme) {
+ CtMethod method =
CtNewMethod.abstractMethod(pool.get(ResourceClientProxy.Measurement.class.getName()),
+ ResourceClientProxy.getterName(key), new CtClass[0], new
CtClass[0], customClass);
+ customClass.addMethod(method);
+ }
+ } else if (prop instanceof ResourceClientProxy.Operation) {
+ ResourceClientProxy.Operation o = (ResourceClientProxy.Operation)
prop;
+
+ LinkedHashMap<String, CtClass> types =
ConfigurationClassBuilder.translateParameters(o
+ .getDefinition().getParametersConfigurationDefinition());
+
+ CtClass[] params = new CtClass[types.size()];
+ int x = 0;
+ for (String param : types.keySet()) {
+ params[x++] = types.get(param);
+ }
+
+ CtMethod method =
CtNewMethod.abstractMethod(ConfigurationClassBuilder.translateConfiguration(o
+ .getDefinition().getResultsConfigurationDefinition()),
ResourceClientProxy.simpleName(key), params,
+ new javassist.CtClass[0], customClass);
+
+ // Setup @WebParam annotations so the signatures have the config prop
names
+ Annotation[][] newAnnotations = new Annotation[params.length][1];
+ int i = 0;
+ for (String paramName : types.keySet()) {
+ newAnnotations[i] = new Annotation[1];
+
+ newAnnotations[i][0] = new Annotation(WebParam.class.getName(),
method.getMethodInfo()
+ .getConstPool());
+ newAnnotations[i][0].addMemberValue("name", new
StringMemberValue(paramName, method
+ .getMethodInfo().getConstPool()));
+ i++;
+ }
+
+ ParameterAnnotationsAttribute newAnnotationsAttribute = new
ParameterAnnotationsAttribute(
+ method.getMethodInfo().getConstPool(),
ParameterAnnotationsAttribute.visibleTag);
+ newAnnotationsAttribute.setAnnotations(newAnnotations);
+ method.getMethodInfo().addAttribute(newAnnotationsAttribute);
+
+ customClass.addMethod(method);
+ }
+ }
+
+ return customClass.toClass();
+ } catch (NotFoundException e) {
+ LOG.error("Could not create custom interface for resource with id "
+ proxy.getId(), e);
+ } catch (CannotCompileException e) {
+ LOG.error("Could not create custom interface for resource with id "
+ proxy.getId(), e);
+ } catch (Exception e) {
+ LOG.error("Could not create custom interface for resource with id "
+ proxy.getId(), e);
+ }
+
+ return null;
+ }
}
diff --git
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
index 5b49e18..b850605 100644
---
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
+++
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientProxy.java
@@ -29,10 +29,14 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import javassist.util.proxy.MethodHandler;
import org.rhq.bindings.util.ConfigurationClassBuilder;
import org.rhq.bindings.util.LazyLoadScenario;
+import org.rhq.bindings.util.ResourceTypeFingerprint;
import org.rhq.bindings.util.ScriptUtil;
import org.rhq.bindings.util.ShortOutput;
import org.rhq.core.domain.configuration.Configuration;
@@ -74,6 +78,8 @@ import
org.rhq.enterprise.server.resource.ResourceTypeNotFoundException;
*/
public class ResourceClientProxy {
+ private static final Log LOG = LogFactory.getLog(ResourceClientProxy.class);
+
private ResourceClientFactory proxyFactory;
private RhqFacade remoteClient;
private int resourceId;
@@ -81,6 +87,8 @@ public class ResourceClientProxy {
Map<String, Object> allProperties = new HashMap<String, Object>();
+ ResourceTypeFingerprint fingerprint;
+
// Metadata
private List<MeasurementDefinition> measurementDefinitions;
private Map<String, Measurement> measurementMap = new HashMap<String,
Measurement>();
@@ -197,6 +205,14 @@ public class ResourceClientProxy {
initOperations();
initConfigDefs();
initContent();
+
+ List<PackageType> packageTypes = new ArrayList<PackageType>();
+ for(ContentType ct : contentTypes.values()) {
+ packageTypes.add(ct.getPackageType());
+ }
+
+ fingerprint = new ResourceTypeFingerprint(resource.getResourceType(),
measurementDefinitions,
+ operationDefinitions, packageTypes, pluginConfigurationDefinition,
resourceConfigurationDefinition);
}
private void initConfigDefs() {
@@ -267,7 +283,7 @@ public class ResourceClientProxy {
contentTypes.put(packageType.getName(), new ContentType(packageType));
}
} catch (ResourceTypeNotFoundException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings
| File Templates.
+ LOG.error("Could not find resource type while creating content mappings
of the resource proxy for resource with id " + resourceId, e);
}
}
diff --git
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/util/ResourceTypeFingerprint.java
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/util/ResourceTypeFingerprint.java
new file mode 100644
index 0000000..fa20b86
--- /dev/null
+++
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/util/ResourceTypeFingerprint.java
@@ -0,0 +1,182 @@
+/*
+ * 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.util;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.core.domain.content.PackageType;
+import org.rhq.core.domain.measurement.MeasurementDefinition;
+import org.rhq.core.domain.operation.OperationDefinition;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.util.MessageDigestGenerator;
+
+/**
+ * This type is used as an identification of a resource type not based
+ * on its id but rather on its structure.
+ *
+ * @author Lukas Krejci
+ */
+public class ResourceTypeFingerprint {
+
+ private String digest;
+
+ public ResourceTypeFingerprint(ResourceType rt,
Collection<MeasurementDefinition> measurements,
+ Collection<OperationDefinition> operations, Collection<PackageType>
packageTypes,
+ ConfigurationDefinition pluginConfigurationDefinition, ConfigurationDefinition
resourceConfigurationDefinition) {
+
+ digest = computeDigest(rt, measurements, operations, packageTypes,
pluginConfigurationDefinition,
+ resourceConfigurationDefinition);
+ }
+
+ @Override
+ public int hashCode() {
+ return digest.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+
+ if (!(other instanceof ResourceTypeFingerprint)) {
+ return false;
+ }
+
+ ResourceTypeFingerprint o = (ResourceTypeFingerprint) other;
+
+ return digest.equals(o.digest);
+ }
+
+ @Override
+ public String toString() {
+ return digest;
+ }
+
+ private static String computeDigest(ResourceType rt,
Collection<MeasurementDefinition> measurements,
+ Collection<OperationDefinition> operations, Collection<PackageType>
packageTypes,
+ ConfigurationDefinition pluginConfigurationDefinition, ConfigurationDefinition
resourceConfigurationDefinition) {
+
+ StringBuilder representation = new StringBuilder();
+
+ addResourceTypeRepresentation(rt, representation);
+ addMeasurementDefinitionsRepresentations(measurements, representation);
+ addOperationDefinitionsRepresentations(operations, representation);
+ addPackageTypesRepresentations(packageTypes, representation);
+ addRepresentation(pluginConfigurationDefinition, representation);
+ addRepresentation(resourceConfigurationDefinition, representation);
+
+ return new
MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(representation.toString());
+ }
+
+ private static void addResourceTypeRepresentation(ResourceType rt, StringBuilder bld)
{
+ bld.append(rt.getName()).append(rt.getPlugin());
+ }
+
+ private static void
addMeasurementDefinitionsRepresentations(Collection<MeasurementDefinition> defs,
+ StringBuilder bld) {
+ if (defs == null) {
+ bld.append("null");
+ } else {
+ for (MeasurementDefinition d : defs) {
+ addRepresentation(d, bld);
+ }
+ }
+ }
+
+ private static void
addOperationDefinitionsRepresentations(Collection<OperationDefinition> defs,
StringBuilder bld) {
+ if (defs == null) {
+ bld.append("null");
+ } else {
+ for (OperationDefinition d : defs) {
+ addRepresentation(d, bld);
+ }
+ }
+ }
+
+ private static void addPackageTypesRepresentations(Collection<PackageType>
defs, StringBuilder bld) {
+ if (defs == null) {
+ bld.append("null");
+ } else {
+ for (PackageType d : defs) {
+ addRepresentation(d, bld);
+ }
+ }
+ }
+
+ private static void addRepresentation(MeasurementDefinition md, StringBuilder bld) {
+ bld.append(md.getName());
+ }
+
+ private static void addRepresentation(OperationDefinition od, StringBuilder bld) {
+ bld.append(od.getName());
+ addRepresentation(od.getResultsConfigurationDefinition(), bld);
+ addRepresentation(od.getParametersConfigurationDefinition(), bld);
+ }
+
+ private static void addRepresentation(PackageType pt, StringBuilder bld) {
+ bld.append(pt.getName());
+ }
+
+ private static void addRepresentation(ConfigurationDefinition cd, StringBuilder bld)
{
+ if (cd == null) {
+ bld.append("null");
+ } else {
+ addRepresentation(cd.getPropertyDefinitions(), bld);
+ }
+ }
+
+ private static void addRepresentation(Map<String, PropertyDefinition> defs,
StringBuilder bld) {
+ for (Map.Entry<String, PropertyDefinition> entry : defs.entrySet()) {
+ PropertyDefinition def = entry.getValue();
+ addRepresentation(def, bld);
+ }
+ }
+
+ private static void addRepresentation(PropertyDefinition def, StringBuilder bld) {
+ if (def instanceof PropertyDefinitionSimple) {
+ addRepresentation((PropertyDefinitionSimple) def, bld);
+ } else if (def instanceof PropertyDefinitionMap) {
+ addRepresentation((PropertyDefinitionMap) def, bld);
+ } else if (def instanceof PropertyDefinitionList) {
+ addRepresentation((PropertyDefinitionList) def, bld);
+ }
+ }
+
+ private static void addRepresentation(PropertyDefinitionSimple p, StringBuilder bld)
{
+ bld.append(p.getName()).append(p.getType().name());
+ }
+
+ private static void addRepresentation(PropertyDefinitionMap pm, StringBuilder bld) {
+ bld.append(pm.getName());
+ addRepresentation(pm.getPropertyDefinitions(), bld);
+ }
+
+ private static void addRepresentation(PropertyDefinitionList pl, StringBuilder bld)
{
+ bld.append(pl.getName());
+ addRepresentation(pl.getMemberDefinition(), bld);
+ }
+}
commit d64951a6f0b4478e85156cb08bd1e9ca772b97f1
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Feb 25 15:31:10 2011 +0100
remove e.printStacktrace(), import classes instead of using full names.
diff --git
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientFactory.java
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientFactory.java
index 2112073..480a5dd 100644
---
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientFactory.java
+++
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/client/ResourceClientFactory.java
@@ -1,14 +1,30 @@
package org.rhq.bindings.client;
import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.jws.WebParam;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javassist.CannotCompileException;
import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
import javassist.CtNewMethod;
+import javassist.NotFoundException;
import javassist.bytecode.ParameterAnnotationsAttribute;
+import javassist.bytecode.annotation.Annotation;
+import javassist.bytecode.annotation.StringMemberValue;
import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyFactory;
import org.rhq.bindings.util.ConfigurationClassBuilder;
import org.rhq.core.domain.resource.ResourceCreationDataType;
@@ -20,17 +36,19 @@ import org.rhq.core.domain.resource.ResourceCreationDataType;
*/
public class ResourceClientFactory {
- private org.rhq.bindings.client.RhqFacade rhqFacade;
+ private static final Log LOG = LogFactory.getLog(ResourceClientFactory.class);
+
+ private RhqFacade rhqFacade;
private PrintWriter outputWriter;
- public ResourceClientFactory(org.rhq.bindings.client.RhqFacade remoteClient,
PrintWriter outputWriter) {
+ public ResourceClientFactory(RhqFacade remoteClient, PrintWriter outputWriter) {
this.rhqFacade = remoteClient;
this.outputWriter = outputWriter;
}
- private static java.util.concurrent.atomic.AtomicInteger classIndex = new
java.util.concurrent.atomic.AtomicInteger();
+ private static AtomicInteger classIndex = new AtomicInteger();
- public org.rhq.bindings.client.RhqFacade getRemoteClient() {
+ public RhqFacade getRemoteClient() {
return rhqFacade;
}
@@ -38,60 +56,60 @@ public class ResourceClientFactory {
return outputWriter;
}
- public org.rhq.bindings.client.ResourceClientProxy getResource(int resourceId) {
+ public ResourceClientProxy getResource(int resourceId) {
- org.rhq.bindings.client.ResourceClientProxy proxy = new
org.rhq.bindings.client.ResourceClientProxy(this, resourceId);
- java.lang.Class<?> customInterface = null;
+ ResourceClientProxy proxy = new ResourceClientProxy(this, resourceId);
+ Class<?> customInterface = null;
try {
// define the dynamic class
- javassist.ClassPool pool = ClassPool.getDefault();
- javassist.CtClass customClass =
pool.makeInterface(org.rhq.bindings.client.ResourceClientProxy.class.getName() +
"__Custom__"
+ ClassPool pool = ClassPool.getDefault();
+ CtClass customClass = pool.makeInterface(ResourceClientProxy.class.getName()
+ "__Custom__"
+ classIndex.getAndIncrement());
- for (java.lang.String key : proxy.allProperties.keySet()) {
- java.lang.Object prop = proxy.allProperties.get(key);
+ for (String key : proxy.allProperties.keySet()) {
+ Object prop = proxy.allProperties.get(key);
- if (prop instanceof
org.rhq.bindings.client.ResourceClientProxy.Measurement) {
- org.rhq.bindings.client.ResourceClientProxy.Measurement m =
(org.rhq.bindings.client.ResourceClientProxy.Measurement) prop;
- java.lang.String name =
org.rhq.bindings.client.ResourceClientProxy.getterName(key);
+ if (prop instanceof ResourceClientProxy.Measurement) {
+ ResourceClientProxy.Measurement m = (ResourceClientProxy.Measurement)
prop;
+ String name = ResourceClientProxy.getterName(key);
try {
-
org.rhq.bindings.client.ResourceClientProxy.class.getMethod(name);
- } catch (java.lang.NoSuchMethodException nsme) {
- javassist.CtMethod method =
CtNewMethod.abstractMethod(pool.get(org.rhq.bindings.client.ResourceClientProxy.Measurement.class.getName()),
-
org.rhq.bindings.client.ResourceClientProxy.getterName(key), new javassist.CtClass[0], new
javassist.CtClass[0], customClass);
+ ResourceClientProxy.class.getMethod(name);
+ } catch (NoSuchMethodException nsme) {
+ CtMethod method =
CtNewMethod.abstractMethod(pool.get(ResourceClientProxy.Measurement.class.getName()),
+ ResourceClientProxy.getterName(key), new CtClass[0], new
CtClass[0], customClass);
customClass.addMethod(method);
}
- } else if (prop instanceof
org.rhq.bindings.client.ResourceClientProxy.Operation) {
- org.rhq.bindings.client.ResourceClientProxy.Operation o =
(org.rhq.bindings.client.ResourceClientProxy.Operation) prop;
+ } else if (prop instanceof ResourceClientProxy.Operation) {
+ ResourceClientProxy.Operation o = (ResourceClientProxy.Operation)
prop;
- java.util.LinkedHashMap<java.lang.String, javassist.CtClass>
types = ConfigurationClassBuilder.translateParameters(o
+ LinkedHashMap<String, CtClass> types =
ConfigurationClassBuilder.translateParameters(o
.getDefinition().getParametersConfigurationDefinition());
- javassist.CtClass[] params = new javassist.CtClass[types.size()];
+ CtClass[] params = new CtClass[types.size()];
int x = 0;
- for (java.lang.String param : types.keySet()) {
+ for (String param : types.keySet()) {
params[x++] = types.get(param);
}
- javassist.CtMethod method =
CtNewMethod.abstractMethod(ConfigurationClassBuilder.translateConfiguration(o
- .getDefinition().getResultsConfigurationDefinition()),
org.rhq.bindings.client.ResourceClientProxy.simpleName(key), params,
+ CtMethod method =
CtNewMethod.abstractMethod(ConfigurationClassBuilder.translateConfiguration(o
+ .getDefinition().getResultsConfigurationDefinition()),
ResourceClientProxy.simpleName(key), params,
new javassist.CtClass[0], customClass);
// Setup @WebParam annotations so the signatures have the config prop
names
- javassist.bytecode.annotation.Annotation[][] newAnnotations = new
javassist.bytecode.annotation.Annotation[params.length][1];
+ Annotation[][] newAnnotations = new Annotation[params.length][1];
int i = 0;
- for (java.lang.String paramName : types.keySet()) {
- newAnnotations[i] = new
javassist.bytecode.annotation.Annotation[1];
+ for (String paramName : types.keySet()) {
+ newAnnotations[i] = new Annotation[1];
- newAnnotations[i][0] = new
javassist.bytecode.annotation.Annotation(javax.jws.WebParam.class.getName(),
method.getMethodInfo()
+ newAnnotations[i][0] = new Annotation(WebParam.class.getName(),
method.getMethodInfo()
.getConstPool());
- newAnnotations[i][0].addMemberValue("name", new
javassist.bytecode.annotation.StringMemberValue(paramName, method
+ newAnnotations[i][0].addMemberValue("name", new
StringMemberValue(paramName, method
.getMethodInfo().getConstPool()));
i++;
}
- javassist.bytecode.ParameterAnnotationsAttribute
newAnnotationsAttribute = new javassist.bytecode.ParameterAnnotationsAttribute(
+ ParameterAnnotationsAttribute newAnnotationsAttribute = new
ParameterAnnotationsAttribute(
method.getMethodInfo().getConstPool(),
ParameterAnnotationsAttribute.visibleTag);
newAnnotationsAttribute.setAnnotations(newAnnotations);
method.getMethodInfo().addAttribute(newAnnotationsAttribute);
@@ -101,17 +119,17 @@ public class ResourceClientFactory {
}
customInterface = customClass.toClass();
- } catch (javassist.NotFoundException e) {
- e.printStackTrace();
- } catch (javassist.CannotCompileException e) {
- e.printStackTrace();
- } catch (java.lang.Exception e) {
- e.printStackTrace();
+ } catch (NotFoundException e) {
+ LOG.error("Could not create custom interface for resource with id "
+ resourceId, e);
+ } catch (CannotCompileException e) {
+ LOG.error("Could not create custom interface for resource with id "
+ resourceId, e);
+ } catch (Exception e) {
+ LOG.error("Could not create custom interface for resource with id "
+ resourceId, e);
}
if (customInterface != null) {
- java.util.List<java.lang.Class<?>> interfaces = new
java.util.ArrayList<java.lang.Class<?>>();
+ List<Class<?>> interfaces = new
ArrayList<Class<?>>();
interfaces.add(customInterface);
if (proxy.resourceConfigurationDefinition != null) {
interfaces.add(getResourceConfigurableInterface());
@@ -126,21 +144,21 @@ public class ResourceClientFactory {
interfaces.addAll(getAdditionalInterfaces(proxy));
- javassist.util.proxy.ProxyFactory proxyFactory = new
javassist.util.proxy.ProxyFactory();
- proxyFactory.setInterfaces(interfaces.toArray(new
java.lang.Class[interfaces.size()]));
-
proxyFactory.setSuperclass(org.rhq.bindings.client.ResourceClientProxy.class);
- org.rhq.bindings.client.ResourceClientProxy proxied = null;
+ ProxyFactory proxyFactory = new ProxyFactory();
+ proxyFactory.setInterfaces(interfaces.toArray(new
Class[interfaces.size()]));
+ proxyFactory.setSuperclass(ResourceClientProxy.class);
+ ResourceClientProxy proxied = null;
try {
- proxied = (org.rhq.bindings.client.ResourceClientProxy)
proxyFactory.create(new java.lang.Class[]{}, new java.lang.Object[]{},
+ proxied = (ResourceClientProxy) proxyFactory.create(new Class[]{}, new
Object[]{},
instantiateMethodHandler(proxy, interfaces, rhqFacade));
- } catch (java.lang.InstantiationException e) {
- e.printStackTrace(); //To change body of catch statement use File |
Settings | File Templates.
- } catch (java.lang.IllegalAccessException e) {
- e.printStackTrace(); //To change body of catch statement use File |
Settings | File Templates.
- } catch (java.lang.NoSuchMethodException e) {
- e.printStackTrace(); //To change body of catch statement use File |
Settings | File Templates.
- } catch (java.lang.reflect.InvocationTargetException e) {
- e.printStackTrace(); //To change body of catch statement use File |
Settings | File Templates.
+ } catch (InstantiationException e) {
+ LOG.error("Could not instantiate a ResourceClientProxy, this is a
bug.", e);
+ } catch (IllegalAccessException e) {
+ LOG.error("Could not instantiate a ResourceClientProxy, this is a
bug.", e);
+ } catch (NoSuchMethodException e) {
+ LOG.error("Could not instantiate a ResourceClientProxy, this is a
bug.", e);
+ } catch (InvocationTargetException e) {
+ LOG.error("Could not instantiate a ResourceClientProxy, this is a
bug.", e);
}
return proxied;
}
@@ -149,22 +167,22 @@ public class ResourceClientFactory {
}
protected Class<?> getResourceConfigurableInterface() {
- return org.rhq.bindings.client.ResourceClientProxy.ResourceConfigurable.class;
+ return ResourceClientProxy.ResourceConfigurable.class;
}
protected Class<?> getPluginConfigurableInterface() {
- return org.rhq.bindings.client.ResourceClientProxy.PluginConfigurable.class;
+ return ResourceClientProxy.PluginConfigurable.class;
}
protected Class<?> getContentBackedInterface() {
- return org.rhq.bindings.client.ResourceClientProxy.ContentBackedResource.class;
+ return ResourceClientProxy.ContentBackedResource.class;
}
protected Set<Class<?>> getAdditionalInterfaces(ResourceClientProxy
proxy) {
return Collections.emptySet();
}
- protected MethodHandler instantiateMethodHandler(ResourceClientProxy proxy,
List<Class<?>> interfaces, org.rhq.bindings.client.RhqFacade remoteClient) {
- return new
org.rhq.bindings.client.ResourceClientProxy.ClientProxyMethodHandler(proxy,
remoteClient);
+ protected MethodHandler instantiateMethodHandler(ResourceClientProxy proxy,
List<Class<?>> interfaces, RhqFacade remoteClient) {
+ return new ResourceClientProxy.ClientProxyMethodHandler(proxy, remoteClient);
}
}
commit 80edc2625c2e8348f52647cfb6910ea6cd4a3315
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Feb 25 13:36:46 2011 +0100
Suggesting the package version in the upload form of the CLI notification editor.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/util/OSGiVersion.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/util/OSGiVersion.java
new file mode 100644
index 0000000..0c9d664
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/util/OSGiVersion.java
@@ -0,0 +1,153 @@
+/*
+ * 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.core.domain.util;
+
+/**
+ * A simple representation of an OSGi formatted version string.
+ *
+ * All fields except the "major" part of the version can be undefined.
+ *
+ * @author Lukas Krejci
+ */
+public class OSGiVersion {
+ private int major;
+ private Integer minor;
+ private Integer micro;
+ private String qualifier;
+
+ public OSGiVersion() {
+
+ }
+
+ public OSGiVersion(String version) {
+ String[] parts = version.split("\\.");
+
+ try {
+ switch (parts.length) {
+ case 4: {
+ qualifier = parts[3];
+ }
+
+ case 3: {
+ micro = Integer.parseInt(parts[2]);
+ }
+
+ case 2: {
+ minor = Integer.parseInt(parts[1]);
+ }
+
+ case 1: {
+ major = Integer.parseInt(parts[0]);
+ break;
+ }
+
+ default: {
+ throw new IllegalArgumentException("Malformed version string ["
+ version + "]");
+ }
+ }
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Malformed version string [" +
version + "]");
+ }
+ }
+
+ /**
+ * @return the major
+ */
+ public int getMajor() {
+ return major;
+ }
+
+ /**
+ * @param major the major to set
+ */
+ public void setMajor(int major) {
+ this.major = major;
+ }
+
+ /**
+ * @return the minor
+ */
+ public Integer getMinorIfDefined() {
+ return minor;
+ }
+
+ public int getMinor() {
+ return minor == null ? 0 : minor;
+ }
+
+ /**
+ * @param minor the minor to set
+ */
+ public void setMinor(Integer minor) {
+ this.minor = minor;
+ }
+
+ /**
+ * @return the micro
+ */
+ public int getMicro() {
+ return micro == null ? 0 : micro;
+ }
+
+ public Integer getMicroIfDefined() {
+ return micro;
+ }
+
+ /**
+ * @param micro the micro to set
+ */
+ public void setMicro(Integer micro) {
+ this.micro = micro;
+ }
+
+ /**
+ * @return the qualifier
+ */
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ /**
+ * @param qualifier the qualifier to set
+ */
+ public void setQualifier(String qualifier) {
+ this.qualifier = qualifier;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder bld = new StringBuilder();
+ bld.append(major);
+
+ if (minor != null) {
+ bld.append(".").append(minor);
+ }
+
+ if (micro != null) {
+ bld.append(".").append(micro);
+ }
+
+ if (qualifier != null) {
+ bld.append(".").append(qualifier);
+ }
+
+ return bld.toString();
+ }
+}
\ No newline at end of file
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/util/OSGiVersionComparator.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/util/OSGiVersionComparator.java
index 1f3936d..70cdc74 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/util/OSGiVersionComparator.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/util/OSGiVersionComparator.java
@@ -37,58 +37,32 @@ public class OSGiVersionComparator implements Comparator<String>
{
}
public int compare(String string1, String string2) {
- Version ver1 = new Version(string1);
- Version ver2 = new Version(string2);
+ OSGiVersion ver1 = new OSGiVersion(string1);
+ OSGiVersion ver2 = new OSGiVersion(string2);
- int result = ver1.major - ver2.major;
+ int result = ver1.getMajor() - ver2.getMajor();
if (result == 0) {
- result = ver1.minor - ver2.minor;
+ result = ver1.getMinor() - ver2.getMinor();
if (result == 0) {
- result = ver1.micro - ver2.micro;
+ result = ver1.getMicro() - ver2.getMicro();
if (result == 0) {
- result = ver1.qualifier.compareTo(ver2.qualifier);
+ if (ver1.getQualifier() != null) {
+ if (ver2.getQualifier() == null) {
+ result = 1;
+ } else {
+ ver1.getQualifier().compareTo(ver2.getQualifier());
+ }
+ } else {
+ if (ver2.getQualifier() == null) {
+ result = 0;
+ } else {
+ result = -1;
+ }
+ }
}
}
}
return result;
}
-
- private class Version {
- int major;
- int minor;
- int micro;
- String qualifier = "";
-
- Version(String version) {
- String[] parts = version.split("\\.");
-
- try {
- switch (parts.length) {
- case 4: {
- qualifier = parts[3];
- }
-
- case 3: {
- micro = Integer.parseInt(parts[2]);
- }
-
- case 2: {
- minor = Integer.parseInt(parts[1]);
- }
-
- case 1: {
- major = Integer.parseInt(parts[0]);
- break;
- }
-
- default: {
- throw new IllegalArgumentException("Malformed version string
[" + version + "]");
- }
- }
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("Malformed version string ["
+ version + "]");
- }
- }
- }
}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/CliNotificationSenderForm.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/CliNotificationSenderForm.java
index 69a2a65..e8d1c1c 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/CliNotificationSenderForm.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/CliNotificationSenderForm.java
@@ -28,6 +28,10 @@ import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.events.FormSubmitFailedEvent;
import com.smartgwt.client.widgets.form.events.FormSubmitFailedHandler;
+import com.smartgwt.client.widgets.form.events.ItemChangeEvent;
+import com.smartgwt.client.widgets.form.events.ItemChangeHandler;
+import com.smartgwt.client.widgets.form.events.ItemChangedEvent;
+import com.smartgwt.client.widgets.form.events.ItemChangedHandler;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.FormItemIcon;
@@ -35,6 +39,7 @@ import com.smartgwt.client.widgets.form.fields.PasswordItem;
import com.smartgwt.client.widgets.form.fields.SectionItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.fields.UploadItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
@@ -49,6 +54,7 @@ import
org.rhq.core.domain.content.composite.PackageAndLatestVersionComposite;
import org.rhq.core.domain.criteria.PackageCriteria;
import org.rhq.core.domain.criteria.RepoCriteria;
import org.rhq.core.domain.criteria.SubjectCriteria;
+import org.rhq.core.domain.util.OSGiVersion;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.ImageManager;
@@ -570,6 +576,40 @@ public class CliNotificationSenderForm extends
AbstractNotificationSenderForm {
};
uploadForm.addFormHandler(uploadSuccessHandler);
+ uploadForm.addItemChangeHandler(new ItemChangeHandler() {
+ public void onItemChange(ItemChangeEvent event) {
+ if (event.getItem() instanceof UploadItem) {
+ String fileName = event.getNewValue().toString();
+
+ if (config.allPackages != null) {
+ for(PackageAndLatestVersionComposite plv : config.allPackages) {
+ if (plv.getGeneralPackage().getName().equals(fileName)) {
+ try {
+ OSGiVersion v = new
OSGiVersion(plv.getLatestPackageVersion().getVersion());
+ if (v.getMicroIfDefined() != null) {
+ v.setMicro(v.getMicro() + 1);
+ } else if (v.getMinorIfDefined() != null) {
+ v.setMinor(v.getMinor() + 1);
+ } else {
+ v.setMajor(v.getMajor() + 1);
+ }
+
+
uploadForm.getField("editableVersion").setValue(v.toString());
+ return;
+ } catch (IllegalArgumentException e) {
+ //ok, can't suggest anything
+ return;
+ }
+ }
+ }
+
+ //no existing package exists with the same name as the file being
uploaded
+
uploadForm.getField("editableVersion").setValue("1.0");
+ }
+ }
+ }
+ });
+
return uploadForm;
}
commit efe26a4bc40b213c69507be5ad6679ab77c9893d
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Feb 25 13:35:55 2011 +0100
small changes in the script engine factory, more useful configuration preview and
error messages in the CliSender.
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 7472953..345017f 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
@@ -80,15 +80,24 @@ public class ScriptEngineFactory {
ScriptEngine engine =
initializer.instantiate(packageFinder.findPackages("org.rhq.core.domain"));
- injectStandardBindings(engine, bindings);
+ injectStandardBindings(engine, bindings, true);
return engine;
}
- public static void injectStandardBindings(ScriptEngine engine, StandardBindings
bindings) {
+ /**
+ * Injects the values provided in the bindings into the {@link
ScriptContext#ENGINE_SCOPE engine scope}
+ * of the provided script engine.
+ *
+ * @param engine the engine
+ * @param bindings the bindings
+ * @param deleteExistingBindings true if the existing bindings should be replaced by
the provided ones, false
+ * if the provided bindings should be added to the existing ones (possibly
overwriting bindings with the same name).
+ */
+ public static void injectStandardBindings(ScriptEngine engine, StandardBindings
bindings, boolean deleteExistingBindings) {
bindings.preInject(engine);
- Bindings engineBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
+ Bindings engineBindings = deleteExistingBindings ? engine.createBindings() :
engine.getBindings(ScriptContext.ENGINE_SCOPE);
for(Map.Entry<String, Object> entry : bindings.entrySet()) {
engineBindings.put(entry.getKey(), entry.getValue());
diff --git
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/engine/JsEngineInitializer.java
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/engine/JsEngineInitializer.java
index eba36f3..3aa4616 100644
---
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/engine/JsEngineInitializer.java
+++
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/engine/JsEngineInitializer.java
@@ -20,7 +20,6 @@
package org.rhq.bindings.engine;
import java.lang.reflect.Method;
-import java.util.List;
import java.util.Set;
import javax.script.ScriptEngine;
@@ -34,13 +33,14 @@ import javax.script.ScriptException;
*/
public class JsEngineInitializer implements ScriptEngineInitializer {
+ private ScriptEngineManager engineManager = new ScriptEngineManager();
+
public boolean implementsLanguage(String language) {
return language != null && ("JavaScript".equals(language) ||
"ECMAScript".equals(language));
}
public ScriptEngine instantiate(Set<String> packages) throws ScriptException {
- ScriptEngineManager sem = new ScriptEngineManager();
- ScriptEngine eng = sem.getEngineByName("JavaScript");
+ ScriptEngine eng = engineManager.getEngineByName("JavaScript");
for(String pkg : packages) {
eng.eval("importPackage(" + pkg + ")");
diff --git
a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
index dfc2b4c..8da9d9f 100644
---
a/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
+++
b/modules/enterprise/remoting/cli/src/main/java/org/rhq/enterprise/client/commands/ScriptCommand.java
@@ -181,7 +181,7 @@ public class ScriptCommand implements ClientCommand {
bindings.put("configurationEditor", new ConfigurationEditor(client));
bindings.put("rhq", new Controller(client));
- ScriptEngineFactory.injectStandardBindings(jsEngine, bindings);
+ ScriptEngineFactory.injectStandardBindings(jsEngine, bindings, true);
ScriptEngineFactory.bindIndirectionMethods(jsEngine,
"configurationEditor", bindings.get("configurationEditor"));
ScriptEngineFactory.bindIndirectionMethods(jsEngine, "rhq",
bindings.get("rhq"));
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
index a9ee867..3916c8a 100644
---
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
@@ -25,19 +25,14 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.ArrayDeque;
import java.util.Collections;
-import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicInteger;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
@@ -54,7 +49,6 @@ 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.core.domain.content.PackageType;
import org.rhq.core.domain.content.PackageVersion;
import org.rhq.core.domain.content.Repo;
import org.rhq.core.domain.criteria.RepoCriteria;
@@ -64,7 +58,6 @@ import org.rhq.enterprise.server.auth.SessionManager;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.content.ContentSourceManagerLocal;
import org.rhq.enterprise.server.content.RepoManagerLocal;
-import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
import org.rhq.enterprise.server.plugin.pc.alert.AlertSender;
import org.rhq.enterprise.server.plugin.pc.alert.AlertSenderValidationResults;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -256,6 +249,10 @@ public class CliSender extends AlertSender<CliComponent> {
RepoManagerLocal rm = LookupUtil.getRepoManagerLocal();
final PackageVersion versionToUse =
rm.getLatestPackageVersion(LookupUtil.getSubjectManager().getOverlord(), packageId,
repoId, null);
+ if (versionToUse == null) {
+ throw new IllegalArgumentException("The package with id " +
packageId + " either doesn't exist at all or doesn't have any version.
Can't execute a CLI script without a script to run.");
+ }
+
PipedInputStream ret = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(ret);
@@ -308,11 +305,16 @@ public class CliSender extends AlertSender<CliComponent> {
Subject overlord = LookupUtil.getSubjectManager().getOverlord();
RepoManagerLocal rm = LookupUtil.getRepoManagerLocal();
PackageVersion versionToUse = rm.getLatestPackageVersion(overlord,
config.packageId, config.repoId);
-
- ret = ret.replace("$packageName", versionToUse.getDisplayName());
- ret = ret.replace("$packageVersion",
versionToUse.getDisplayVersion() == null ? versionToUse.getVersion()
- : versionToUse.getDisplayVersion());
-
+
+ if (versionToUse != null) {
+ ret = ret.replace("$packageName",
versionToUse.getDisplayName());
+ ret = ret.replace("$packageVersion",
versionToUse.getDisplayVersion() == null ? versionToUse.getVersion()
+ : versionToUse.getDisplayVersion());
+ } else {
+ ret = ret.replace("$packageName", "unknown script with
package id " + config.packageId);
+ ret = ret.replace("$packageVersion", "no version");
+ }
+
RepoCriteria criteria = new RepoCriteria();
criteria.addFilterId(config.repoId);
@@ -382,7 +384,7 @@ public class CliSender extends AlertSender<CliComponent> {
engine = ScriptEngineFactory.getScriptEngine("JavaScript",
new PackageFinder(Collections.<File> emptyList()), bindings);
} else {
- ScriptEngineFactory.injectStandardBindings(engine, bindings);
+ ScriptEngineFactory.injectStandardBindings(engine, bindings, true);
}
++ENGINES_IN_USE;
commit 9a16c738c5429d182ec5732013911574e8f3eeea
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Feb 25 13:34:31 2011 +0100
remove unused import
diff --git
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/SandboxedScriptEngine.java
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/SandboxedScriptEngine.java
index faf3e15..ed3de18 100644
---
a/modules/enterprise/binding/src/main/java/org/rhq/bindings/SandboxedScriptEngine.java
+++
b/modules/enterprise/binding/src/main/java/org/rhq/bindings/SandboxedScriptEngine.java
@@ -26,7 +26,6 @@ import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Permissions;
-import java.security.Principal;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
commit 45ceab2c82a6d2718295abeab0413f9ac8bc6064
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Feb 25 13:34:11 2011 +0100
Make the CLI alert plugin controls for managing invalid alert definitions actually
work and return more useful data.
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java
index e38a452..e8b6895 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/AlertDefinitionCriteria.java
@@ -69,8 +69,10 @@ public class AlertDefinitionCriteria extends Criteria {
filterOverrides.put("alertTemplateResourceTypeId",
"resourceType.id = ?");
filterOverrides.put("alertTemplateResourceTypeName",
"resourceType.name like ?");
filterOverrides.put("resourceIds", "resource.id IN ( ? )");
- filterOverrides.put("resourceGroupIds", "resourceGroup.id IN ( ?
)");
- filterOverrides.put("notificationSenderNames",
"alertNotifications.senderName IN ( ? )");
+ filterOverrides.put("resourceGroupIds", "resourceGroup.id IN ( ?
)");
+ filterOverrides.put("notificationSenderNames", "id IN (" +
+ "SELECT notif.alertDefinition.id FROM
AlertNotification notif " +
+ "WHERE notif.senderName IN ( ? ))");
filterOverrides.put("filterIds", "id IN ( ? )");
}
diff --git
a/modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliComponent.java
b/modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliComponent.java
index 93c5fee..2835ab9 100644
---
a/modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliComponent.java
+++
b/modules/enterprise/server/plugins/alert-cli/src/main/java/org/rhq/enterprise/server/plugins/alertCli/CliComponent.java
@@ -22,8 +22,10 @@ package org.rhq.enterprise.server.plugins.alertCli;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.rhq.core.domain.alert.AlertDefinition;
import org.rhq.core.domain.alert.notification.AlertNotification;
@@ -35,15 +37,20 @@ import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.content.PackageCategory;
import org.rhq.core.domain.content.PackageType;
+import org.rhq.core.domain.content.PackageVersion;
import org.rhq.core.domain.criteria.AlertDefinitionCriteria;
+import org.rhq.core.domain.criteria.Criteria.Restriction;
+import org.rhq.core.domain.criteria.PackageVersionCriteria;
import org.rhq.core.domain.resource.composite.DisambiguationReport;
import org.rhq.core.domain.util.DisambiguationReportRenderer;
import org.rhq.core.domain.util.PageControl;
+import org.rhq.core.domain.util.PageList;
import org.rhq.core.util.IntExtractor;
import org.rhq.enterprise.server.alert.AlertDefinitionManagerLocal;
import org.rhq.enterprise.server.alert.AlertNotificationManagerLocal;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.content.ContentManagerLocal;
+import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.plugin.pc.ControlFacet;
import org.rhq.enterprise.server.plugin.pc.ControlResults;
import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
@@ -51,6 +58,7 @@ import org.rhq.enterprise.server.plugin.pc.ServerPluginContext;
import org.rhq.enterprise.server.resource.ResourceManagerLocal;
import
org.rhq.enterprise.server.resource.disambiguation.DefaultDisambiguationUpdateStrategies;
import org.rhq.enterprise.server.util.LookupUtil;
+import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.alert.AlertPluginDescriptorType;
/**
* The plugin component for controlling the CLI alerts.
@@ -73,7 +81,8 @@ public class CliComponent implements ServerPluginComponent, ControlFacet
{
private static final String PROP_ALERT_DEFINITION_NAME =
"alertDefinitionName";
private static final String PROP_RESOURCE_PATH = "resourcePath";
private static final String PROP_RESOURCE_ID = "resourceId";
- private static final String PROP_MISCONFIGURED_ALERT_DEFS =
"misconfiguredAlertDefs";
+ private static final String PROP_MISSING_USERS = "missingUsers";
+ private static final String PROP_MISSING_SCRIPTS = "missingScripts";
private static final String PROP_ALERT_DEFINITION = "alertDefinition";
private static final String PROP_ALERT_DEFINITION_ID =
"alertDefinitionId";
private static final String PROP_USER_NAME = "userName";
@@ -87,7 +96,7 @@ public class CliComponent implements ServerPluginComponent, ControlFacet
{
private SubjectManagerLocal subjectManager;
public void initialize(ServerPluginContext context) throws Exception {
- pluginName = context.getPluginEnvironment().getPluginDescriptor().getName();
+ pluginName =
((AlertPluginDescriptorType)context.getPluginEnvironment().getPluginDescriptor()).getShortName();
subjectManager = LookupUtil.getSubjectManager();
ContentManagerLocal cm = LookupUtil.getContentManager();
@@ -147,34 +156,33 @@ public class CliComponent implements ServerPluginComponent,
ControlFacet {
}
private void checkAlertsValidity(ControlResults results, Configuration parameters) {
- List<AlertNotification> invalidNotifs =
getAllCliNotificationsWithInvalidUser();
+ List<AlertNotification> allCliNotifications =
getAllCliNotifications(null);
+
+ Configuration resConfig = results.getComplexResults();
- for(AlertNotification cliNotification : invalidNotifs) {
- AlertDefinition def = cliNotification.getAlertDefinition();
-
- Configuration resConfig = results.getComplexResults();
-
- PropertyList misconfigured =
resConfig.getList(PROP_MISCONFIGURED_ALERT_DEFS);
- if (misconfigured == null) {
- misconfigured = new PropertyList(PROP_MISCONFIGURED_ALERT_DEFS);
- resConfig.put(misconfigured);
- }
-
- PropertyMap alertDefinitionMap = new PropertyMap(PROP_ALERT_DEFINITION);
-
- alertDefinitionMap.put(new PropertySimple(PROP_ALERT_DEFINITION_ID,
def.getId()));
- alertDefinitionMap.put(new PropertySimple(PROP_ALERT_DEFINITION_NAME,
def.getName()));
- alertDefinitionMap.put(new PropertySimple(PROP_RESOURCE_ID,
def.getResource().getId()));
-
- misconfigured.add(alertDefinitionMap);
- }
+ PropertyList missingUsersList = new PropertyList(PROP_MISSING_USERS);
+ resConfig.put(missingUsersList);
+
+ List<AlertNotification> invalidNotifs =
getCliNotificationsWithInvalidUser(allCliNotifications);
+ convertNotificationsToInvalidAlertDefResults(missingUsersList, invalidNotifs);
+
+ PropertyList missingScriptsList = new PropertyList(PROP_MISSING_SCRIPTS);
+ resConfig.put(missingScriptsList);
+
+ invalidNotifs = getCliNotificationsWithInvalidPackage(allCliNotifications);
+ convertNotificationsToInvalidAlertDefResults(missingScriptsList, invalidNotifs);
//ok, now we have to obtain the resource paths. doing it out of the above loop
reduces the number
//of server roundtrips
- ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
- PropertyList misconfigured =
results.getComplexResults().getList(PROP_MISCONFIGURED_ALERT_DEFS);
- if (misconfigured != null) {
- List<DisambiguationReport<Property>> disambiguated =
resourceManager.disambiguate(misconfigured.getList(),
+
+ List<Property> allMissing = new ArrayList<Property>();
+ allMissing.addAll(missingUsersList.getList());
+ allMissing.addAll(missingScriptsList.getList());
+
+ if (allMissing.size() > 0) {
+ ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
+
+ List<DisambiguationReport<Property>> disambiguated =
resourceManager.disambiguate(allMissing,
new IntExtractor<Property>() {
public int extract(Property object) {
PropertyMap map = (PropertyMap) object;
@@ -200,7 +208,7 @@ public class CliComponent implements ServerPluginComponent,
ControlFacet {
PropertySimple userNameProp = parameters.getSimple(PROP_USER_NAME);
PropertySimple alertDefIdsProp = parameters.getSimple(PROP_ALERT_DEF_IDS);
- if (userNameProp == null) {
+ if (userNameProp == null || userNameProp.getStringValue() == null ||
userNameProp.getStringValue().trim().length() == 0) {
throw new IllegalArgumentException("User name not specified.");
}
@@ -214,16 +222,15 @@ public class CliComponent implements ServerPluginComponent,
ControlFacet {
//now get the list of the alert notifications to update
List<AlertNotification> notifsToReAssign = null;
- if (alertDefIdsProp == null || alertDefIdsProp.getStringValue().trim().length()
== 0) {
- notifsToReAssign = getAllCliNotificationsWithInvalidUser();
+ if (alertDefIdsProp == null || alertDefIdsProp.getStringValue() == null ||
alertDefIdsProp.getStringValue().trim().length() == 0) {
+ notifsToReAssign =
getCliNotificationsWithInvalidUser(getAllCliNotifications(null));
} else {
List<Integer> alertDefIds =
asIdList(alertDefIdsProp.getStringValue().split("\\s*,\\s*"));
List<AlertDefinition> defs =
getAlertDefinitionsWithCliNotifications(alertDefIds);
notifsToReAssign = new ArrayList<AlertNotification>();
for(AlertDefinition def : defs) {
- AlertNotification cliNotif =
getCliNotification(def.getAlertNotifications());
- if (cliNotif != null) {
+ for(AlertNotification cliNotif :
getCliNotifications(def.getAlertNotifications())) {
notifsToReAssign.add(cliNotif);
}
}
@@ -236,17 +243,18 @@ public class CliComponent implements ServerPluginComponent,
ControlFacet {
notificationManager.massReconfigure(notifIds, updates);
}
- private AlertNotification getCliNotification(List<AlertNotification>
notifications) {
+ private List<AlertNotification>
getCliNotifications(List<AlertNotification> notifications) {
+ ArrayList<AlertNotification> ret = new
ArrayList<AlertNotification>();
for(AlertNotification n : notifications) {
if (pluginName.equals(n.getSenderName())) {
- return n;
+ ret.add(n);
}
}
- return null;
+ return ret;
}
- private List<AlertDefinition>
getAlertDefinitionsWithCliNotifications(Collection<Integer> ids) {
+ private List<AlertDefinition>
getAlertDefinitionsWithCliNotifications(Collection<Integer> alertDefIds) {
SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
AlertDefinitionManagerLocal manager = LookupUtil.getAlertDefinitionManager();
@@ -256,29 +264,33 @@ public class CliComponent implements ServerPluginComponent,
ControlFacet {
criteria.addFilterNotificationNames(pluginName);
criteria.setPageControl(PageControl.getUnlimitedInstance());
criteria.fetchAlertNotifications(true);
- if (ids != null) {
- criteria.addFilterIds(ids.toArray(new Integer[ids.size()]));
+ if (alertDefIds != null) {
+ criteria.addFilterIds(alertDefIds.toArray(new Integer[alertDefIds.size()]));
}
return manager.findAlertDefinitionsByCriteria(overlord, criteria);
}
- private List<AlertNotification> getAllCliNotificationsWithInvalidUser() {
+ private List<AlertNotification>
getAllCliNotifications(Collection<Integer> alertDefIds) {
List<AlertNotification> ret = new ArrayList<AlertNotification>();
- SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
-
- List<AlertDefinition> defs =
getAlertDefinitionsWithCliNotifications(null);
+ List<AlertDefinition> defs =
getAlertDefinitionsWithCliNotifications(alertDefIds);
for(AlertDefinition def : defs) {
List<AlertNotification> notifications = def.getAlertNotifications();
- AlertNotification cliNotification = getCliNotification(notifications);
-
- if (cliNotification == null) {
- //we always should find this but a little bit of paranoia never hurt
anyone
- continue;
- }
+ ret.addAll(getCliNotifications(notifications));
+ }
+
+ return ret;
+ }
+
+ private List<AlertNotification>
getCliNotificationsWithInvalidUser(List<AlertNotification> allNotifications) {
+ List<AlertNotification> ret = new ArrayList<AlertNotification>();
+
+ SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
+
+ for(AlertNotification cliNotification : allNotifications) {
Subject checkSubject = null;
@@ -297,6 +309,59 @@ public class CliComponent implements ServerPluginComponent,
ControlFacet {
return ret;
}
+ private List<AlertNotification>
getCliNotificationsWithInvalidPackage(List<AlertNotification> allNotifications) {
+ List<AlertNotification> ret = new ArrayList<AlertNotification>();
+
+ ContentManagerLocal contentManager = LookupUtil.getContentManager();
+ SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
+
+ Subject overlord = subjectManager.getOverlord();
+
+ PackageVersionCriteria crit = new PackageVersionCriteria();
+ crit.setRestriction(Restriction.COUNT_ONLY);
+
+ for(AlertNotification cliNotification : allNotifications) {
+
+ int count = 0;
+
+ String packageId =
cliNotification.getConfiguration().getSimpleValue(CliSender.PROP_PACKAGE_ID, null);
+ if (packageId != null) {
+ crit.addFilterPackageId(Integer.valueOf(packageId));
+
+ PageList<PackageVersion> res =
contentManager.findPackageVersionsByCriteria(overlord, crit);
+ count = res.getTotalSize();
+ }
+
+ if (count == 0) {
+ ret.add(cliNotification);
+ }
+ }
+
+ return ret;
+ }
+
+ private void convertNotificationsToInvalidAlertDefResults(PropertyList results,
List<AlertNotification> invalidNotifications) {
+ Set<AlertDefinition> processedDefs = new HashSet<AlertDefinition>();
+
+ for(AlertNotification cliNotification : invalidNotifications) {
+ AlertDefinition def = cliNotification.getAlertDefinition();
+
+ if (!processedDefs.add(def)) {
+ //skip this definition - it has more than one incorrect notifs and we
already
+ //included it in the output.
+ continue;
+ }
+
+ PropertyMap alertDefinitionMap = new PropertyMap(PROP_ALERT_DEFINITION);
+
+ alertDefinitionMap.put(new PropertySimple(PROP_ALERT_DEFINITION_ID,
def.getId()));
+ alertDefinitionMap.put(new PropertySimple(PROP_ALERT_DEFINITION_NAME,
def.getName()));
+ alertDefinitionMap.put(new PropertySimple(PROP_RESOURCE_ID,
def.getResource().getId()));
+
+ results.add(alertDefinitionMap);
+ }
+ }
+
private List<Integer> asIdList(String... ids) {
List<Integer> ret = new ArrayList<Integer>();
for(String id : ids) {
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
index 4f60e6f..c4dcdea 100644
---
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
@@ -15,14 +15,18 @@
</serverplugin:help>
<serverplugin:plugin-component class="CliComponent">
- <serverplugin:control name="checkAlertsValidity">
+ <serverplugin:control name="checkAlertsValidity"
description="Alert scripts run authenticated as a user specified in their
definitions. If a user is deleted, the alert definition will contain invalid reference to
that user and needs to be update manually. Also the script can be deleted from a repo, or
the repo itself can be deleted, at which point there is not script to run. This operation
returns a list of such misconfigured alert definitions.">
<serverplugin:results>
- <c:list-property name="misconfiguredAlertDefs"
displayName="Misconfigured Alert Definitions">
- <c:description>
- Alert scripts run authenticated as a user specified in their
definitions. If a user is deleted,
- the alert definition will contain invalid reference to that user
and needs to be update manually.
- This operation returns a list of such misconfigured alert
definitions.
- </c:description>
+ <c:list-property name="missingUsers"
displayName="Alerts with notifications referencing non-existent user.">
+ <c:map-property name="alertDefinition">
+ <c:simple-property name="alertDefinitionId" />
+ <c:simple-property name="alertDefinitionName" />
+ <c:simple-property name="resourceId" />
+ <c:simple-property name="resourcePath" />
+ </c:map-property>
+ </c:list-property>
+
+ <c:list-property name="missingScripts"
displayName="Alerts with notifications referencing non-existent scripts.">
<c:map-property name="alertDefinition">
<c:simple-property name="alertDefinitionId" />
<c:simple-property name="alertDefinitionName" />
commit 86c740a3822f79167facb90b64d85d5667cb52db
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Fri Feb 25 13:32:34 2011 +0100
Deleting a user will cause all the repos s/he owned to have no owner and thus become
readonly to anyone except repository managers. Deleting a user will therefore not cause
disappearance of any packages s/he previously created and that might be used throughout
the inventory as backing content for resources or as CLI scripts.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
index c1014e2..ecf97ce 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/content/Repo.java
@@ -126,7 +126,9 @@ import org.rhq.core.domain.resource.Resource;
@NamedQuery(name = Repo.QUERY_CHECK_REPO_OWNED_BY_SUBJECT_ID, query = "SELECT
COUNT(r) FROM Repo r" //
+ " WHERE r.id = :repoId"
- + " AND r.owner.id = :subjectId")
+ + " AND r.owner.id = :subjectId"),
+ @NamedQuery(name = Repo.QUERY_UPDATE_REMOVE_OWNER_FROM_REPOS_OWNED_BY_SUBJECT, query
= "" +
+ "UPDATE Repo r SET r.owner = null WHERE r.owner.id = :ownerId")
})
@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_REPO_ID_SEQ")
@Table(name = "RHQ_REPO")
@@ -152,6 +154,7 @@ public class Repo implements Serializable {
public static final String QUERY_FIND_CANDIDATES_WITH_ONLY_CONTENT_SOURCE =
"Repo.findCandidatesWithOnlyContentSource";
public static final String QUERY_CHECK_REPO_VISIBLE_BY_SUBJECT_ID =
"Repo.findVisibleReposBySubjectId";
public static final String QUERY_CHECK_REPO_OWNED_BY_SUBJECT_ID =
"Repo.isRepoOwnedBySubjectId";
+ public static final String QUERY_UPDATE_REMOVE_OWNER_FROM_REPOS_OWNED_BY_SUBJECT =
"Repo.removeOwnerFromReposOwnerBySubject";
private static final long serialVersionUID = 1L;
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/auth/SubjectManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/auth/SubjectManagerBean.java
index b3a25c9..3c5cc9e 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/auth/SubjectManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/auth/SubjectManagerBean.java
@@ -61,6 +61,7 @@ import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
import org.rhq.enterprise.server.authz.PermissionException;
import org.rhq.enterprise.server.authz.RequiredPermission;
import org.rhq.enterprise.server.authz.RoleManagerLocal;
+import org.rhq.enterprise.server.content.RepoManagerLocal;
import org.rhq.enterprise.server.core.CustomJaasDeploymentServiceMBean;
import org.rhq.enterprise.server.exception.LoginException;
import org.rhq.enterprise.server.resource.group.LdapGroupManagerLocal;
@@ -103,6 +104,10 @@ public class SubjectManagerBean implements SubjectManagerLocal,
SubjectManagerRe
@IgnoreDependency
private RoleManagerLocal roleManager;
+ @EJB
+ @IgnoreDependency
+ private RepoManagerLocal repoManager;
+
private SessionManager sessionManager = SessionManager.getInstance();
/**
@@ -754,6 +759,8 @@ public class SubjectManagerBean implements SubjectManagerLocal,
SubjectManagerRe
}
alertNotificationManager.cleanseAlertNotificationBySubject(doomedSubject.getId());
+ repoManager.removeOwnershipOfSubject(doomedSubject.getId());
+
entityManager.remove(doomedSubject);
return;
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
index 9dbf92b..6eadde8 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerBean.java
@@ -694,6 +694,13 @@ public class RepoManagerBean implements RepoManagerLocal,
RepoManagerRemote {
}
}
+ public void removeOwnershipOfSubject(int subjectId) {
+ Query q =
entityManager.createNamedQuery(Repo.QUERY_UPDATE_REMOVE_OWNER_FROM_REPOS_OWNED_BY_SUBJECT);
+ q.setParameter("ownerId", subjectId);
+
+ q.executeUpdate();
+ }
+
@RequiredPermission(Permission.MANAGE_REPOSITORIES)
public RepoGroup createRepoGroup(Subject subject, RepoGroup repoGroup) throws
RepoException {
validateRepoGroup(repoGroup);
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerLocal.java
index 99ab618..bc22d81 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/content/RepoManagerLocal.java
@@ -210,6 +210,17 @@ public interface RepoManagerLocal {
*/
void importCandidateRepo(Subject subject, List<Integer> repoIds) throws
RepoException;
+ /**
+ * When a user gets deleted, all of his/her repos remain intact but become
+ * unassigned to any user. This way no links to packages are broken upon user
deletion
+ * and repository manager can then decide what to do with the leftover repos.
+ * <p>
+ * This method therefore sets the owner of all repos owned by provided subject to
null.
+ *
+ * @param subjectId
+ */
+ void removeOwnershipOfSubject(int subjectId);
+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
// The following are shared with the Remote Interface
commit 49d947b89a34847fa71b16124600ff0ddd511a64
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Feb 22 23:46:40 2011 +0100
fail the validation if another user is entered with incorrect credentials.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/CliNotificationSenderForm.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/CliNotificationSenderForm.java
index 61b3f3d..69a2a65 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/CliNotificationSenderForm.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/CliNotificationSenderForm.java
@@ -593,7 +593,11 @@ public class CliNotificationSenderForm extends
AbstractNotificationSenderForm {
config.selectedSubject = result;
verifyUserButton.setIcons(result == null ? authFailureIcon :
authSuccessIcon);
markForRedraw();
- action.onSuccess(null);
+ if (result == null) {
+ action.onFailure(null);
+ } else {
+ action.onSuccess(null);
+ }
}
});
}