modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HornetQComponent.java | 260 +---------
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JmsComponent.java | 81 ---
modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml | 11
3 files changed, 55 insertions(+), 297 deletions(-)
New commits:
commit 0ea5517803362a642eccf78fbf26fd5ae922e7b0
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Apr 24 22:02:42 2012 +0200
BZ 802467 - check for at least one jndi-name and the connector name being present
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HornetQComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HornetQComponent.java
index d07ebeb..6ffa409 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HornetQComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/HornetQComponent.java
@@ -1,23 +1,31 @@
-package org.rhq.modules.plugins.jbossas7;
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.
+ */
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+package org.rhq.modules.plugins.jbossas7;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.Property;
import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.resource.CreateResourceStatus;
+import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pluginapi.inventory.CreateResourceReport;
-import org.rhq.modules.plugins.jbossas7.json.Address;
-import org.rhq.modules.plugins.jbossas7.json.ComplexResult;
-import org.rhq.modules.plugins.jbossas7.json.Operation;
-import org.rhq.modules.plugins.jbossas7.json.Result;
/**
* Component class for HornetQ related stuff
@@ -28,222 +36,30 @@ public class HornetQComponent extends BaseComponent {
@Override
public CreateResourceReport createResource(CreateResourceReport report) {
- String targetTypeName = report.getResourceType().getName();
- String resourceName = report.getUserSpecifiedResourceName();
- Configuration rc = report.getResourceConfiguration();
- Address targetAddress = new Address(getPath());
-
- CreationType targetType = CreationType.getForName(targetTypeName);
- if (targetType==null)
- throw new IllegalArgumentException("Type " + targetTypeName + " not yet supported");
-
- targetAddress.add(targetType.as7name,resourceName);
- List<String> entries;
-
- Result res;
- Operation op = new Operation("read-operation-description",targetAddress);
- op.addAdditionalProperty("name","add");
- ComplexResult cres = getASConnection().executeComplex(op);
- Map<String,Map<String,Object>> definitions;
- if (cres.isSuccess()) {
- definitions = (Map<String, Map<String, Object>>) cres.getResult().get("request-properties");
- }
- else {
- definitions = Collections.emptyMap();
- }
-
- op = new Operation("add",targetAddress);
- switch (targetType) {
- case JMS_QUEUE:
- entries = getEntriesPropertyFromConfig(rc);
- op.addAdditionalProperty("entries",entries);
-
- processSimpleProperties(op,rc, definitions);
-
-/*
- String durableProp = rc.getSimpleValue("durable","false");
- op.addAdditionalProperty("durable",Boolean.valueOf(durableProp));
-
- PropertySimple selectorProp = (PropertySimple) rc.get("selector");
- if (selectorProp!=null && selectorProp.getStringValue()!=null && !selectorProp.getStringValue().isEmpty())
- op.addAdditionalProperty("selector",selectorProp.getStringValue());
-*/
-
- break;
- case JMS_TOPIC:
- entries = getEntriesPropertyFromConfig(rc);
- op.addAdditionalProperty("entries",entries);
-
- break;
-
- case CONNECTION_FACTORY:
- entries = getEntriesPropertyFromConfig(rc);
- op.addAdditionalProperty("entries",entries);
-
- processSimpleProperties(op,rc,definitions);
-
- // now handle the connector
- PropertyMap connectorMap = (PropertyMap) rc.get("connector:collapsed");
- Map<String,String> map = new HashMap<String, String>(1);
- String key = connectorMap.getSimpleValue("name:0", null);
- String value = connectorMap.getSimpleValue("backup:1", null);
- if (key==null) {
- report.setErrorMessage("No connector name given");
- report.setStatus(CreateResourceStatus.FAILURE);
- return report;
- }
- map.put(key, value);
- op.addAdditionalProperty("connector",map);
-
- break;
- }
-
-
- res = getASConnection().execute(op);
- if (res.isSuccess()) {
- report.setResourceKey(targetAddress.getPath());
- report.setResourceName(resourceName);
- report.setStatus(CreateResourceStatus.SUCCESS);
- } else {
- report.setErrorMessage(res.getFailureDescription());
+ Configuration resourceConfiguration = report.getResourceConfiguration();
+ PropertyList entries = resourceConfiguration.getList("entries");
+ if (entries == null || entries.getList().isEmpty()) {
+ report.setErrorMessage("You need to provide at least one JNDI name");
report.setStatus(CreateResourceStatus.FAILURE);
- report.setException(res.getRhqThrowable());
+ return report;
}
- return report;
- }
-
- /**
- * Add the data from the simple properties as additional properties to the passed operation
- * @param op Operation
- * @param rc configuration with the properties to use
- * @param definitions AS7 metadata
- */
- private void processSimpleProperties(Operation op, Configuration rc, Map<String, Map<String, Object>> definitions) {
- Map<String,PropertySimple> properties = rc.getSimpleProperties();
- for (PropertySimple ps : properties.values()) {
-
- Map<String,Object> def = definitions.get(ps.getName());
- String value = ps.getStringValue();
-
- if (value!=null) {
- Object o = getValueAndType(value,def);
- op.addAdditionalProperty(ps.getName(),o);
+ ResourceType resourceType = report.getResourceType();
+ if (resourceType.getName().equals("Connection-Factory")) {
+ // we need to check that a connector is given
+ PropertyMap connector = resourceConfiguration.getMap("connector:collapsed");
+ if (connector == null) {
+ throw new IllegalStateException("No connector entry found");
}
- }
- }
-
- private Object getValueAndType(String value, Map<String, Object> def) {
-
- Object ret;
- DataType dt = getTypeFromProps(def);
- switch (dt) {
- case BOOLEAN:
- ret = Boolean.valueOf(value);
- break;
- case INT:
- ret = Integer.valueOf(value);
- break;
- case LONG:
- ret = Long.valueOf(value);
- break;
- case BIG_DECIMAL:
- ret = Double.valueOf(value);
- break;
- case DOUBLE:
- ret = Double.valueOf(value);
- break;
-
- default:
- ret = value;
- }
-
- return ret;
- }
-
- private DataType getTypeFromProps(Map<String, Object> props) {
- Map<String,String> tMap = (Map<String, String>) props.get("type");
- if (tMap==null)
- return DataType.OBJECT;
-
- String type = tMap.get("TYPE_MODEL_VALUE");
- DataType ret = DataType.valueOf(type);
-
- return ret;
- }
-
- /**
- * Get the JNDI entries
- * @param rc Configuration parameters
- * @return List of string entries
- */
- private List<String> getEntriesPropertyFromConfig(Configuration rc) {
- PropertyList entriesListProp = (PropertyList) rc.get("entries");
- List<Property> psl = entriesListProp.getList();
- List<String> entries = new ArrayList<String>(psl.size());
- for (Property p :psl) {
- PropertySimple ps = (PropertySimple) p;
- entries.add(ps.getStringValue());
- }
- return entries;
- }
-
- /**
- * Supported types for resource creation
- */
- enum CreationType {
- JMS_QUEUE("JMS Queue","jms-queue"),
- JMS_TOPIC("JMS Topic","jms-topic"),
- CONNECTION_FACTORY("Connection-Factory","connection-factory")
- ;
-
- private String descriptorName;
- private String as7name;
-
- /**
- * Create a Type
- * @param descriptorName type name as it is listed in the plugin descriptor
- * @param as7name the type by which as7 knows it.
- */
- CreationType(String descriptorName, String as7name) {
-
- this.descriptorName = descriptorName;
- this.as7name = as7name;
- }
-
- public static CreationType getForName(String targetTypeName) {
- EnumSet<CreationType> set = EnumSet.allOf(CreationType.class);
- for (CreationType t : set) {
- if (t.descriptorName.equals(targetTypeName))
- return t;
+ PropertySimple name = connector.getSimple("name:0");
+ if (name == null || name.getStringValue() == null || name.getStringValue().isEmpty()) {
+ report.setErrorMessage("You need to provide a connector name");
+ report.setStatus(CreateResourceStatus.FAILURE);
+ return report;
}
- return null;
- }
- }
-
- public enum DataType {
-
- STRING(false,"string"),
- INT(true,"integer"),
- BOOLEAN(false,"boolean"),
- LONG(true,"long"),
- BIG_DECIMAL(true,"long"),
- OBJECT(false,"-object-"),
- LIST(false,"-list-"),
- DOUBLE(true,"long")
- ;
-
- private boolean numeric;
- private String rhqName;
-
- private DataType(boolean numeric, String rhqName) {
- this.numeric = numeric;
- this.rhqName = rhqName;
}
- public boolean isNumeric() {
- return numeric;
- }
+ report = super.createResource(report);
+ return report;
}
-
}
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JmsComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JmsComponent.java
index 678362f..9a8122c 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JmsComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JmsComponent.java
@@ -18,25 +18,10 @@
*/
package org.rhq.modules.plugins.jbossas7;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
-import org.rhq.core.domain.resource.CreateResourceStatus;
-import org.rhq.core.pluginapi.inventory.CreateResourceReport;
-import org.rhq.modules.plugins.jbossas7.json.Address;
-import org.rhq.modules.plugins.jbossas7.json.ComplexResult;
-import org.rhq.modules.plugins.jbossas7.json.Operation;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
/**
* Component class for the JMS subsystem
@@ -44,61 +29,17 @@ import org.rhq.modules.plugins.jbossas7.json.Operation;
*/
public class JmsComponent extends BaseComponent {
- private final Log log = LogFactory.getLog(JmsComponent.class);
-
@Override
- public CreateResourceReport createResource(CreateResourceReport report) {
-
-
- Configuration pConf = report.getPluginConfiguration();
- Configuration resConf = report.getResourceConfiguration();
- ConfigurationDefinition resConfDef = report.getResourceType().getResourceConfigurationDefinition();
-
- String type = pConf.getSimpleValue("path", "");
-
- Address theAddress = new Address(address);
- theAddress.add(type, report.getUserSpecifiedResourceName());
- Operation op = new Operation("add",theAddress);
-
- // Loop over the properties from the config and add them as properties to the op TODO make generally available ?
- for (Map.Entry<String, Property> entry: resConf.getAllProperties().entrySet()) {
- Property value = entry.getValue();
- if (value !=null) {
- String name = entry.getKey();
-
-
- if (value instanceof PropertySimple) {
- PropertyDefinitionSimple propDef = (PropertyDefinitionSimple) resConfDef.get(name);
- PropertySimple ps = (PropertySimple) value;
- op.addAdditionalProperty(name, getObjectForProperty(ps,propDef));
- } else if (value instanceof PropertyList) {
- PropertyList propertyList = (PropertyList) value;
- List<Object> list = new ArrayList<Object>();
- PropertyDefinitionList pd = resConfDef.getPropertyDefinitionList(name);
- PropertyDefinitionSimple propDef = (PropertyDefinitionSimple) pd.getMemberDefinition();
- for (Property p : propertyList.getList()) {
-
- Object o = getObjectForProperty((PropertySimple) p, propDef);
- list.add(o);
- }
- op.addAdditionalProperty(name,list);
- }
- }
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+
+ Configuration resourceConfiguration = report.getConfiguration();
+ PropertyList entries = resourceConfiguration.getList("entries");
+ if (entries == null || entries.getList().isEmpty()) {
+ report.setErrorMessage("You need to provide at least one JNDI name");
+ report.setStatus(ConfigurationUpdateStatus.FAILURE);
+ return;
}
- ComplexResult res = (ComplexResult) getASConnection().executeComplex(op);
-
- // TODO Currently this reports a failure even if it succeeds for jms
- if (res == null || !res.isSuccess()) {
- report.setStatus(CreateResourceStatus.FAILURE);
- } else {
- report.setStatus(CreateResourceStatus.SUCCESS);
- report.setResourceKey(theAddress.toString());
- report.setResourceName(report.getUserSpecifiedResourceName());
- }
-
- log.info(report);
- return report;
+ super.updateResourceConfiguration(report);
}
-
}
diff --git a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
index 186d98a..b611cc2 100644
--- a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
@@ -343,7 +343,7 @@
<c:map-property name="*:name" displayName="Name" readOnly="true">
<c:simple-property name="name" displayName="Property-Name" readOnly="true"/>
<c:simple-property name="value" displayName="Value"/>
- <c:simple-property name="boot-time" defaultValue="true" default="true" type="boolean"
+ <c:simple-property name="boot-time" defaultValue="true" default="true" type="boolean" required="false"
description="If true the system property is passed on the command-line to the started server jvm. If false, it will be pushed to the server as part of the startup sequence.">
<c:property-options>
<c:option value="true"/>
@@ -466,7 +466,7 @@
<c:map-property name="*:name" displayName="Name" readOnly="true">
<c:simple-property name="name" displayName="Property-Name" readOnly="true"/>
<c:simple-property name="value" displayName="Value"/>
- <c:simple-property name="boot-time" defaultValue="true" default="true" type="boolean"
+ <c:simple-property name="boot-time" defaultValue="true" default="true" type="boolean" required="false"
description="If true the system property is passed on the command-line to the started server jvm. If false, it will be pushed to the server as part of the startup sequence.">
<c:property-options>
<c:option value="true"/>
@@ -499,7 +499,7 @@
<c:map-property name="*:name" displayName="Name" readOnly="true">
<c:simple-property name="name" displayName="Property-Name" readOnly="true"/>
<c:simple-property name="value" displayName="Value"/>
- <c:simple-property name="boot-time" defaultValue="true" default="true" type="boolean"
+ <c:simple-property name="boot-time" defaultValue="true" default="true" type="boolean" required="false"
description="If true the system property is passed on the command-line to the started server jvm. If false, it will be pushed to the server as part of the startup sequence.">
<c:property-options>
<c:option value="true"/>
@@ -597,7 +597,8 @@
<c:map-property name="*:name" displayName="Name" readOnly="true">
<c:simple-property name="name" displayName="Property-Name" readOnly="true"/>
<c:simple-property name="value" displayName="Value"/>
- <c:simple-property name="boot-time" defaultValue="true" description="If true the system property is passed on the command-line to the started server jvm. If false, it will be pushed to the server as part of the startup sequence.">
+ <c:simple-property name="boot-time" defaultValue="true" default="true" required="false"
+ description="If true the system property is passed on the command-line to the started server jvm. If false, it will be pushed to the server as part of the startup sequence.">
<c:property-options>
<c:option value="true"/>
<c:option value="false"/>
@@ -1262,7 +1263,7 @@
<c:map-property name="connector:collapsed" required="true" readOnly="false" displayName="Connector"
description="Defines the connectors. These are stored in a map by connector name, with the backup connectors stored as the value, or an undefined value if there is no backup connector.">
<c:simple-property name="name:0" displayName="Name" description="Connector name" required="true"/>
- <c:simple-property name="backup:1" displayName="Backup" description="Backup connector name"/>
+ <c:simple-property name="backup:1" displayName="Backup" description="Backup connector name" required="false"/>
</c:map-property>
<c:simple-property name="auto-group" required="false" type="boolean" readOnly="false" description="Whether or not message grouping is automatically used"/>
<c:simple-property name="block-on-acknowledge" required="false" type="boolean" readOnly="false" description="True to set block on acknowledge."/>