modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java | 27
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java | 282 ++++++----
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/CreateResourceDelegate.java | 87 +++
3 files changed, 275 insertions(+), 121 deletions(-)
New commits:
commit bac2feb88aac349080eb91148f9f7afc7336aa28
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Mon Apr 2 16:50:03 2012 -0500
Added create resource delegate. This delegate is similar to the configuration write delegate but will be used create resource requests. The property parsing is almost identical to the configuration write delegate.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
index cea3ee6..db2f266 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
@@ -313,34 +313,13 @@ public class BaseComponent<T extends ResourceComponent<?>> implements AS7Compone
@Override
public CreateResourceReport createResource(CreateResourceReport report) {
-
if (report.getPackageDetails() != null) { // Content deployment
return deployContent(report);
} else {
- report.setStatus(CreateResourceStatus.INVALID_CONFIGURATION);
- Address createAddress = new Address(address);
- createAddress.add(report.getPluginConfiguration().getSimpleValue("path", ""),
- report.getUserSpecifiedResourceName());
- Operation op = new Operation("add", createAddress);
- for (Property prop : report.getResourceConfiguration().getProperties()) {
- if (prop instanceof PropertySimple) {
- PropertySimple ps = (PropertySimple) prop;
- String value = ps.getStringValue();
- op.addAdditionalProperty(prop.getName(), value);
- }
- // TODO more types
- }
- Result result = getASConnection().execute(op);
- if (result.isSuccess()) {
- report.setStatus(CreateResourceStatus.SUCCESS);
- report.setResourceKey(address.getPath());
- report.setResourceName(report.getUserSpecifiedResourceName());
- } else {
- report.setStatus(CreateResourceStatus.FAILURE);
- report.setErrorMessage(result.getFailureDescription());
- }
+ ConfigurationDefinition configDef = context.getResourceType().getResourceConfigurationDefinition();
+ CreateResourceDelegate delegate = new CreateResourceDelegate(configDef, connection, address);
+ return delegate.createResource(report);
}
- return report;
}
/**
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
index ccdd865..4487776 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
@@ -161,6 +161,30 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
return cop;
}
+
+ /**
+ * @return the address
+ */
+ protected Address getAddress() {
+ return this._address;
+ }
+
+
+ /**
+ * @return the connection
+ */
+ protected ASConnection getConnection() {
+ return connection;
+ }
+
+
+ /**
+ * @return the configurationDefinition
+ */
+ protected ConfigurationDefinition getConfigurationDefinition() {
+ return configurationDefinition;
+ }
+
private void updateProperty(Configuration conf, CompositeOperation cop, PropertyDefinition propDef,
Address baseAddress) {
@@ -241,7 +265,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
private void updateHandlePropertyMapSpecial(CompositeOperation cop, PropertyMap prop, PropertyDefinitionMap propDef,
Address address, List<String> existingPropNames) {
- Map<String, Object> results = prepareSimpleMap(prop, propDef);
+ Map<String, Object> results = prepareSimplePropertyMap(prop, propDef);
if (prop.get(namePropLocator)==null) {
throw new IllegalArgumentException("There is no element in the map with the name " + namePropLocator);
}
@@ -337,7 +361,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
private void createWriteAttributePropertyMap(CompositeOperation cop, PropertyMap property,
PropertyDefinitionMap propertyDefinition, Address address) {
- SimpleEntry<String, Map<String, Object>> entry = this.prepareMap(property, propertyDefinition);
+ SimpleEntry<String, Map<String, Object>> entry = this.preparePropertyMap(property, propertyDefinition);
Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
cop.addStep(writeAttribute);
}
@@ -350,7 +374,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
* @param propertyDefinition property definition
* @return parsed simple property
*/
- private SimpleEntry<String, Object> preparePropertySimple(PropertySimple property,
+ protected SimpleEntry<String, Object> preparePropertySimple(PropertySimple property,
PropertyDefinitionSimple propertyDefinition) {
SimpleEntry<String, Object> entry = null;
@@ -383,7 +407,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
* @param propertyDefinition property definition
* @return parsed list
*/
- private SimpleEntry<String, List<Object>> preparePropertyList(PropertyList property,
+ protected SimpleEntry<String, List<Object>> preparePropertyList(PropertyList property,
PropertyDefinitionList propertyDefinition) {
PropertyDefinition memberDef = propertyDefinition.getMemberDefinition();
@@ -399,9 +423,9 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
if (memberDef instanceof PropertyDefinitionMap) {
Map<String, Object> mapResult = null;
if (memberDef.getName().endsWith(":collapsed")) {
- mapResult = prepareCollapsedMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
+ mapResult = prepareCollapsedPropertyMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
} else {
- mapResult = prepareSimpleMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
+ mapResult = prepareSimplePropertyMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
}
values.add(mapResult);
}
@@ -420,16 +444,16 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
* @param propertyDefinition property definition
* @return parsed map
*/
- private SimpleEntry<String, Map<String, Object>> prepareMap(PropertyMap property,
+ protected SimpleEntry<String, Map<String, Object>> preparePropertyMap(PropertyMap property,
PropertyDefinitionMap propertyDefinition) {
Map<String, Object> results;
String propName = stripNumberIdentifier(property.getName());
if (propName.endsWith(":collapsed")) {
propName = propName.substring(0, propName.indexOf(':'));
- results = prepareCollapsedMap(property, propertyDefinition);
+ results = prepareCollapsedPropertyMap(property, propertyDefinition);
} else {
- results = prepareSimpleMap(property, propertyDefinition);
+ results = prepareSimplePropertyMap(property, propertyDefinition);
}
return new SimpleEntry<String, Map<String, Object>>(propName, results);
@@ -443,7 +467,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
* @param propertyDefinition property definition
* @return parsed map
*/
- private Map<String, Object> prepareCollapsedMap(PropertyMap property, PropertyDefinitionMap propertyDefinition) {
+ protected Map<String, Object> prepareCollapsedPropertyMap(PropertyMap property, PropertyDefinitionMap propertyDefinition) {
String key = null;
String value = null;
@@ -480,7 +504,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
* @param propertyDefinition property definition
* @return parsed map
*/
- private Map<String, Object> prepareSimpleMap(PropertyMap property, PropertyDefinitionMap propertyDefinition) {
+ protected Map<String, Object> prepareSimplePropertyMap(PropertyMap property, PropertyDefinitionMap propertyDefinition) {
Map<String,PropertyDefinition> memberDefinitions = propertyDefinition.getMap();
Map<String,Object> results = new HashMap<String,Object>();
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/CreateResourceDelegate.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/CreateResourceDelegate.java
new file mode 100644
index 0000000..2875150
--- /dev/null
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/CreateResourceDelegate.java
@@ -0,0 +1,87 @@
+/*
+ * 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.modules.plugins.jbossas7;
+
+import java.util.AbstractMap.SimpleEntry;
+
+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.configuration.definition.ConfigurationDefinition;
+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.resource.CreateResourceStatus;
+import org.rhq.core.pluginapi.inventory.CreateChildResourceFacet;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
+import org.rhq.modules.plugins.jbossas7.json.Address;
+import org.rhq.modules.plugins.jbossas7.json.Operation;
+import org.rhq.modules.plugins.jbossas7.json.Result;
+
+public class CreateResourceDelegate extends ConfigurationWriteDelegate implements CreateChildResourceFacet {
+
+ public CreateResourceDelegate(ConfigurationDefinition configDef, ASConnection connection, Address address) {
+ super(configDef, connection, address);
+ }
+
+ @Override
+ public CreateResourceReport createResource(CreateResourceReport report) {
+ report.setStatus(CreateResourceStatus.INVALID_CONFIGURATION);
+ Address createAddress = new Address(this.getAddress());
+ createAddress.add(report.getPluginConfiguration().getSimpleValue("path", ""),
+ report.getUserSpecifiedResourceName());
+
+ Operation op = new Operation("add", createAddress);
+ for (Property prop : report.getResourceConfiguration().getProperties()) {
+ SimpleEntry<String, ?> entry = null;
+
+ if (prop instanceof PropertySimple) {
+ PropertySimple propertySimple = (PropertySimple) prop;
+ PropertyDefinitionSimple propertyDefinition = this.getConfigurationDefinition()
+ .getPropertyDefinitionSimple(propertySimple.getName());
+ entry = preparePropertySimple(propertySimple, propertyDefinition);
+ } else if (prop instanceof PropertyList) {
+ PropertyList propertyList = (PropertyList) prop;
+ PropertyDefinitionList propertyDefinition = this.getConfigurationDefinition()
+ .getPropertyDefinitionList(propertyList.getName());
+ entry = preparePropertyList(propertyList, propertyDefinition);
+ } else if (prop instanceof PropertyMap) {
+ PropertyMap propertyMap = (PropertyMap) prop;
+ PropertyDefinitionMap propertyDefinition = this.getConfigurationDefinition().getPropertyDefinitionMap(
+ propertyMap.getName());
+ entry = preparePropertyMap(propertyMap, propertyDefinition);
+ }
+
+ op.addAdditionalProperty(entry.getKey(), entry.getValue());
+ }
+
+ Result result = this.getConnection().execute(op);
+ if (result.isSuccess()) {
+ report.setStatus(CreateResourceStatus.SUCCESS);
+ report.setResourceKey(this.getAddress().getPath());
+ report.setResourceName(report.getUserSpecifiedResourceName());
+ } else {
+ report.setStatus(CreateResourceStatus.FAILURE);
+ report.setErrorMessage(result.getFailureDescription());
+ }
+
+ return report;
+ }
+}
commit 1b558aa0aef400abf170e8386c0bb898b45f0276
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Mon Apr 2 16:07:55 2012 -0500
Move method documenatation in javadoc.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
index 64dee6e..ccdd865 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
@@ -541,9 +541,15 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
return ret;
}
+ /**
+ * Strip :number from the property name.
+ * The post-fixed number was added in the descriptor as unique identifier but it is not
+ * needed (and will result in an error) when writing the property back to AS configuration.
+ *
+ * @param name property name
+ * @return
+ */
private String stripNumberIdentifier(String name) {
- //strip :number from the property name, it's not needed
- //it was added in the descriptor as unique identifier
if (name.contains(":")) {
try {
Integer.parseInt(name.substring(name.lastIndexOf(':') + 1));
commit 4c29e11b7adc6b9e0f178a16c8da6f005a8751f1
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Mon Apr 2 16:04:06 2012 -0500
Refactor private methods (group all the parsing and write attribute operation creation methods).
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
index ca9d0bf..64dee6e 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
@@ -80,9 +80,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
* @throws Exception If anything goes wrong.
*/
public Configuration loadResourceConfiguration() throws Exception {
-
throw new IllegalAccessException("Please use ConfigurationLoadDelegate");
-
}
@@ -94,7 +92,6 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
public void updateResourceConfiguration(ConfigurationUpdateReport report) {
Configuration conf = report.getConfiguration();
-
CompositeOperation cop = updateGenerateOperationFromProperties(conf, _address);
Result result = connection.execute(cop);
@@ -241,58 +238,6 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
}
}
- private void createWriteAttributePropertyMap(CompositeOperation cop, PropertyMap prop,
- PropertyDefinitionMap propDef, Address address) {
-
- SimpleEntry<String, Map<String, Object>> entry = this.prepareMap(prop, propDef);
- Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
- cop.addStep(writeAttribute);
- }
-
- private SimpleEntry<String, Map<String, Object>> prepareMap(PropertyMap prop, PropertyDefinitionMap propDef) {
- Map<String,Object> results;
-
- String propName = stripNumberIdentifier(prop.getName());
- if (propName.endsWith(":collapsed")) {
- propName = propName.substring(0, propName.indexOf(':'));
- results = preparedCollapsedMap(prop, propDef);
- }
- else {
- results = prepareSimpleMap(prop, propDef);
- }
-
- return new SimpleEntry<String, Map<String, Object>>(propName, results);
- }
-
- private Map<String, Object> preparedCollapsedMap(PropertyMap propertyMap, PropertyDefinitionMap propertyDefinitionMap) {
- String first=null;
- String second=null;
-
- for (Map.Entry<String,PropertyDefinition> entry : propertyDefinitionMap.getMap().entrySet()) {
- PropertyDefinition def = entry.getValue();
- if (!def.getName().contains(":"))
- throw new IllegalArgumentException("Member names in a :collapsed map must end in :0 and :1");
-
- Property prop = propertyMap.get(def.getName());
- if (prop==null) {
- throw new IllegalArgumentException("Property " + def.getName() + " was null - must not happen");
- }
-
- PropertySimple ps = (PropertySimple) prop;
- if (def.getName().endsWith(":0"))
- first = ps.getStringValue();
- else if (def.getName().endsWith(":1"))
- second = ps.getStringValue(); // TODO other types?
- else
- throw new IllegalArgumentException("Member names in a :collapsed map must end in :0 and :1");
- }
-
-
- Map<String,Object> resultMap = new HashMap<String,Object>();
- resultMap.put(first, second);
-
- return resultMap;
- }
private void updateHandlePropertyMapSpecial(CompositeOperation cop, PropertyMap prop, PropertyDefinitionMap propDef,
Address address, List<String> existingPropNames) {
@@ -362,35 +307,99 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
operation.addAdditionalProperty(key1, value);
}
}
- cop.addStep(operation);
+
+ cop.addStep(operation);
}
}
- private void createWriteAttributePropertyList(CompositeOperation cop, PropertyList prop,
- PropertyDefinitionList propDef, Address address) {
+ private void createWriteAttributePropertySimple(CompositeOperation cop, PropertySimple property,
+ PropertyDefinitionSimple propertyDefinition, Address address) {
- SimpleEntry<String, List<Object>> entry = preparePropertyList(prop, propDef);
+ // If the property value is null and the property is optional, skip too
+ if (property.getStringValue() == null && !propertyDefinition.isRequired())
+ return;
+
+ SimpleEntry<String, Object> entry = this.preparePropertySimple(property, propertyDefinition);
Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
cop.addStep(writeAttribute);
}
- private SimpleEntry<String, List<Object>> preparePropertyList(PropertyList prop, PropertyDefinitionList propDef) {
+ private void createWriteAttributePropertyList(CompositeOperation cop, PropertyList property,
+ PropertyDefinitionList propertyDefinition, Address address) {
+
+ SimpleEntry<String, List<Object>> entry = preparePropertyList(property, propertyDefinition);
+ Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
+ cop.addStep(writeAttribute);
+ }
+
+
+ private void createWriteAttributePropertyMap(CompositeOperation cop, PropertyMap property,
+ PropertyDefinitionMap propertyDefinition, Address address) {
+
+ SimpleEntry<String, Map<String, Object>> entry = this.prepareMap(property, propertyDefinition);
+ Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
+ cop.addStep(writeAttribute);
+ }
+
+
+ /**
+ * Simple property parsing.
+ *
+ * @param property raw simple property
+ * @param propertyDefinition property definition
+ * @return parsed simple property
+ */
+ private SimpleEntry<String, Object> preparePropertySimple(PropertySimple property,
+ PropertyDefinitionSimple propertyDefinition) {
+
+ SimpleEntry<String, Object> entry = null;
- PropertyDefinition memberDef = propDef.getMemberDefinition();
- List<Property> embeddedProps = prop.getList();
+ String name = stripNumberIdentifier(property.getName());
+ if (name.endsWith(":expr")) {
+
+ String realName = name.substring(0, name.indexOf(":"));
+ try {
+ Integer num = Integer.parseInt(property.getStringValue());
+ entry = new SimpleEntry<String, Object>(realName, property.getStringValue());
+ } catch (NumberFormatException nfe) {
+ // Not a number, and expressions are allowed, so send an expression
+ Map<String, String> expr = new HashMap<String, String>(1);
+ expr.put("EXPRESSION_VALUE", property.getStringValue());
+ entry = new SimpleEntry<String, Object>(realName, expr);
+ }
+ } else {
+ entry = new SimpleEntry<String, Object>(name, property.getStringValue());
+ }
+
+ return entry;
+ }
+
+
+ /**
+ * List property parsing.
+ *
+ * @param property raw list property
+ * @param propertyDefinition property definition
+ * @return parsed list
+ */
+ private SimpleEntry<String, List<Object>> preparePropertyList(PropertyList property,
+ PropertyDefinitionList propertyDefinition) {
+
+ PropertyDefinition memberDef = propertyDefinition.getMemberDefinition();
+ List<Property> embeddedProps = property.getList();
List<Object> values = new ArrayList<Object>();
for (Property inner : embeddedProps) {
if (memberDef instanceof PropertyDefinitionSimple) {
PropertySimple ps = (PropertySimple) inner;
- if (ps.getStringValue()!=null)
+ if (ps.getStringValue() != null)
values.add(ps.getStringValue()); // TODO handling of optional vs required
}
if (memberDef instanceof PropertyDefinitionMap) {
Map<String, Object> mapResult = null;
if (memberDef.getName().endsWith(":collapsed")) {
- mapResult = preparedCollapsedMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
+ mapResult = prepareCollapsedMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
} else {
mapResult = prepareSimpleMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
}
@@ -398,51 +407,81 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
}
}
- String name = stripNumberIdentifier(prop.getName());
+ String name = stripNumberIdentifier(property.getName());
return new SimpleEntry<String, List<Object>>(name, values);
}
- private void createWriteAttributePropertySimple(CompositeOperation cop, PropertySimple propertySimple,
- PropertyDefinitionSimple propDef, Address address) {
+ /**
+ * Map property parsing.
+ *
+ * @param property raw map property
+ * @param propertyDefinition property definition
+ * @return parsed map
+ */
+ private SimpleEntry<String, Map<String, Object>> prepareMap(PropertyMap property,
+ PropertyDefinitionMap propertyDefinition) {
+ Map<String, Object> results;
- // If the property value is null and the property is optional, skip too
- if (propertySimple.getStringValue() == null && !propDef.isRequired())
- return;
+ String propName = stripNumberIdentifier(property.getName());
+ if (propName.endsWith(":collapsed")) {
+ propName = propName.substring(0, propName.indexOf(':'));
+ results = prepareCollapsedMap(property, propertyDefinition);
+ } else {
+ results = prepareSimpleMap(property, propertyDefinition);
+ }
- SimpleEntry<String, Object> entry = this.preparePropertySimple(propertySimple, propDef);
- Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
- cop.addStep(writeAttribute);
+ return new SimpleEntry<String, Map<String, Object>>(propName, results);
}
- private SimpleEntry<String, Object> preparePropertySimple(PropertySimple propertySimple,
- PropertyDefinitionSimple propDef) {
- SimpleEntry<String, Object> entry = null;
+ /**
+ * Collapsed map property parsing.
+ *
+ * @param property raw map property
+ * @param propertyDefinition property definition
+ * @return parsed map
+ */
+ private Map<String, Object> prepareCollapsedMap(PropertyMap property, PropertyDefinitionMap propertyDefinition) {
+ String key = null;
+ String value = null;
- String name = stripNumberIdentifier(propertySimple.getName());
- if (name.endsWith(":expr")) {
+ for (Map.Entry<String, PropertyDefinition> entry : propertyDefinition.getMap().entrySet()) {
+ PropertyDefinition def = entry.getValue();
+ if (!def.getName().contains(":"))
+ throw new IllegalArgumentException("Member names in a :collapsed map must end in :0 and :1");
- String realName = name.substring(0, name.indexOf(":"));
- try {
- Integer num = Integer.parseInt(propertySimple.getStringValue());
- entry = new SimpleEntry<String, Object>(realName, propertySimple.getStringValue());
- } catch (NumberFormatException nfe) {
- // Not a number, and expressions are allowed, so send an expression
- Map<String, String> expr = new HashMap<String, String>(1);
- expr.put("EXPRESSION_VALUE", propertySimple.getStringValue());
- entry = new SimpleEntry<String, Object>(realName, expr);
+ Property prop = property.get(def.getName());
+ if (prop == null) {
+ throw new IllegalArgumentException("Property " + def.getName() + " was null - must not happen");
}
- } else {
- entry = new SimpleEntry<String, Object>(name, propertySimple.getStringValue());
+
+ PropertySimple ps = (PropertySimple) prop;
+ if (def.getName().endsWith(":0"))
+ key = ps.getStringValue();
+ else if (def.getName().endsWith(":1"))
+ value = ps.getStringValue(); // TODO other types?
+ else
+ throw new IllegalArgumentException("Member names in a :collapsed map must end in :0 and :1");
}
- return entry;
+ Map<String, Object> resultMap = new HashMap<String, Object>();
+ resultMap.put(key, value);
+
+ return resultMap;
}
- private Map<String, Object> prepareSimpleMap(PropertyMap map, PropertyDefinitionMap mapDef) {
- Map<String,PropertyDefinition> memberDefinitions = mapDef.getMap();
+
+ /**
+ * Simple map property parsing.
+ *
+ * @param property raw map property
+ * @param propertyDefinition property definition
+ * @return parsed map
+ */
+ private Map<String, Object> prepareSimpleMap(PropertyMap property, PropertyDefinitionMap propertyDefinition) {
+ Map<String,PropertyDefinition> memberDefinitions = propertyDefinition.getMap();
Map<String,Object> results = new HashMap<String,Object>();
for (String name : memberDefinitions.keySet()) {
@@ -453,7 +492,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
if (memberDefinition instanceof PropertyDefinitionSimple) {
PropertyDefinitionSimple pds = (PropertyDefinitionSimple) memberDefinition;
- PropertySimple ps = (PropertySimple) map.get(name);
+ PropertySimple ps = (PropertySimple) property.get(name);
if ((ps==null || ps.getStringValue()==null ) && !pds.isRequired())
continue;
if (ps!=null)
commit a66b61bf3766620e6e541f620451290a551ca860
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Mon Apr 2 15:42:00 2012 -0500
Decouple property parsing from the composite operation creation for basic property types.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
index 0d39fd1..ca9d0bf 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
@@ -18,6 +18,7 @@
*/
package org.rhq.modules.plugins.jbossas7;
+import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -109,13 +110,12 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
}
protected CompositeOperation updateGenerateOperationFromProperties(Configuration conf, Address address) {
-
CompositeOperation cop = new CompositeOperation();
for (PropertyDefinition propDef : configurationDefinition.getNonGroupedProperties()) {
-
updateProperty(conf, cop, propDef, address);
}
+
for (PropertyGroupDefinition pgd: configurationDefinition.getGroupDefinitions()) {
String groupName = pgd.getName();
namePropLocator = null;
@@ -141,6 +141,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
log.error("Group name " + groupName + " contains no property name locator ");
return cop;
}
+
List<PropertyDefinition> definitions = configurationDefinition.getPropertiesInGroup(groupName);
for (PropertyDefinition def : definitions) {
updateProperty(conf,cop,def, address);
@@ -157,8 +158,6 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
for (PropertyDefinition def : definitions) {
updateProperty(conf,cop,def, address1);
}
-
-
} // TODO handle attribute: case
}
@@ -223,13 +222,15 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
Property prop = conf.get(propDefName);
if (prop instanceof PropertySimple && propDef instanceof PropertyDefinitionSimple) {
- updateHandlePropertySimple(cop, (PropertySimple) prop, (PropertyDefinitionSimple) propDef, baseAddress);
+ createWriteAttributePropertySimple(cop, (PropertySimple) prop, (PropertyDefinitionSimple) propDef,
+ baseAddress);
}
else if (prop instanceof PropertyList && propDef instanceof PropertyDefinitionList) {
- updateHandlePropertyList(cop, (PropertyList) prop, (PropertyDefinitionList) propDef, baseAddress);
+ createWriteAttributePropertyList(cop, (PropertyList) prop, (PropertyDefinitionList) propDef,
+ baseAddress);
}
else if (prop instanceof PropertyMap && propDef instanceof PropertyDefinitionMap) {
- updateHandlePropertyMap(cop,(PropertyMap)prop,(PropertyDefinitionMap)propDef, baseAddress);
+ createWriteAttributePropertyMap(cop, (PropertyMap) prop, (PropertyDefinitionMap) propDef, baseAddress);
}
else {
String s = "Property and definition are not matching:\n";
@@ -240,27 +241,33 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
}
}
- private void updateHandlePropertyMap(CompositeOperation cop, PropertyMap prop, PropertyDefinitionMap propDef, Address address) {
- Operation writeAttribute;
+ private void createWriteAttributePropertyMap(CompositeOperation cop, PropertyMap prop,
+ PropertyDefinitionMap propDef, Address address) {
+
+ SimpleEntry<String, Map<String, Object>> entry = this.prepareMap(prop, propDef);
+ Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
+ cop.addStep(writeAttribute);
+ }
+
+ private SimpleEntry<String, Map<String, Object>> prepareMap(PropertyMap prop, PropertyDefinitionMap propDef) {
Map<String,Object> results;
String propName = stripNumberIdentifier(prop.getName());
if (propName.endsWith(":collapsed")) {
- String realName = propName.substring(0, propName.indexOf(':'));
- results = handleCollapsedMap(prop, propDef);
- writeAttribute = new WriteAttribute(address, realName,results);
+ propName = propName.substring(0, propName.indexOf(':'));
+ results = preparedCollapsedMap(prop, propDef);
}
else {
- results = updateHandleMap(prop,propDef, address);
- writeAttribute = new WriteAttribute(address, propName,results);
+ results = prepareSimpleMap(prop, propDef);
}
- cop.addStep(writeAttribute);
- }
- private Map<String, Object> handleCollapsedMap(PropertyMap propertyMap, PropertyDefinitionMap propertyDefinitionMap) {
+ return new SimpleEntry<String, Map<String, Object>>(propName, results);
+ }
+ private Map<String, Object> preparedCollapsedMap(PropertyMap propertyMap, PropertyDefinitionMap propertyDefinitionMap) {
String first=null;
String second=null;
+
for (Map.Entry<String,PropertyDefinition> entry : propertyDefinitionMap.getMap().entrySet()) {
PropertyDefinition def = entry.getValue();
if (!def.getName().contains(":"))
@@ -289,7 +296,7 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
private void updateHandlePropertyMapSpecial(CompositeOperation cop, PropertyMap prop, PropertyDefinitionMap propDef,
Address address, List<String> existingPropNames) {
- Map<String,Object> results = updateHandleMap(prop,propDef, address);
+ Map<String, Object> results = prepareSimpleMap(prop, propDef);
if (prop.get(namePropLocator)==null) {
throw new IllegalArgumentException("There is no element in the map with the name " + namePropLocator);
}
@@ -360,12 +367,17 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
}
- private void updateHandlePropertyList(CompositeOperation cop, PropertyList prop, PropertyDefinitionList propDef,
- Address address) {
- PropertyDefinition memberDef = propDef.getMemberDefinition();
+ private void createWriteAttributePropertyList(CompositeOperation cop, PropertyList prop,
+ PropertyDefinitionList propDef, Address address) {
+
+ SimpleEntry<String, List<Object>> entry = preparePropertyList(prop, propDef);
+ Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
+ cop.addStep(writeAttribute);
+ }
- // We need to collect the list members, create an array and attach this to the cop
+ private SimpleEntry<String, List<Object>> preparePropertyList(PropertyList prop, PropertyDefinitionList propDef) {
+ PropertyDefinition memberDef = propDef.getMemberDefinition();
List<Property> embeddedProps = prop.getList();
List<Object> values = new ArrayList<Object>();
for (Property inner : embeddedProps) {
@@ -378,51 +390,58 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
if (memberDef instanceof PropertyDefinitionMap) {
Map<String, Object> mapResult = null;
if (memberDef.getName().endsWith(":collapsed")) {
- mapResult = handleCollapsedMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
+ mapResult = preparedCollapsedMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
} else {
- mapResult = updateHandleMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef, address);
+ mapResult = prepareSimpleMap((PropertyMap) inner, (PropertyDefinitionMap) memberDef);
}
values.add(mapResult);
}
}
String name = stripNumberIdentifier(prop.getName());
- Operation writeAttribute = new WriteAttribute(address,name,values);
- cop.addStep(writeAttribute);
+
+ return new SimpleEntry<String, List<Object>>(name, values);
}
- private void updateHandlePropertySimple(CompositeOperation cop, PropertySimple propertySimple,
- PropertyDefinitionSimple propDef, Address address) {
+ private void createWriteAttributePropertySimple(CompositeOperation cop, PropertySimple propertySimple,
+ PropertyDefinitionSimple propDef, Address address) {
// If the property value is null and the property is optional, skip too
- if (propertySimple.getStringValue()==null && !propDef.isRequired())
+ if (propertySimple.getStringValue() == null && !propDef.isRequired())
return;
- Operation writeAttribute = new WriteAttribute(address);
+ SimpleEntry<String, Object> entry = this.preparePropertySimple(propertySimple, propDef);
+ Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
+ cop.addStep(writeAttribute);
+ }
+
+ private SimpleEntry<String, Object> preparePropertySimple(PropertySimple propertySimple,
+ PropertyDefinitionSimple propDef) {
+
+ SimpleEntry<String, Object> entry = null;
+
String name = stripNumberIdentifier(propertySimple.getName());
if (name.endsWith(":expr")) {
- String realName = name.substring(0,name.indexOf(":"));
+ String realName = name.substring(0, name.indexOf(":"));
try {
Integer num = Integer.parseInt(propertySimple.getStringValue());
- writeAttribute.addAdditionalProperty("name",realName);
- writeAttribute.addAdditionalProperty("value",propertySimple.getStringValue());
+ entry = new SimpleEntry<String, Object>(realName, propertySimple.getStringValue());
} catch (NumberFormatException nfe) {
// Not a number, and expressions are allowed, so send an expression
- Map<String,String> expr = new HashMap<String, String>(1);
- expr.put("EXPRESSION_VALUE",propertySimple.getStringValue());
- writeAttribute.addAdditionalProperty("name", realName);
- writeAttribute.addAdditionalProperty("value",expr);
+ Map<String, String> expr = new HashMap<String, String>(1);
+ expr.put("EXPRESSION_VALUE", propertySimple.getStringValue());
+ entry = new SimpleEntry<String, Object>(realName, expr);
}
} else {
- writeAttribute.addAdditionalProperty("name",name);
- writeAttribute.addAdditionalProperty("value",propertySimple.getStringValue());
+ entry = new SimpleEntry<String, Object>(name, propertySimple.getStringValue());
}
- cop.addStep(writeAttribute);
+
+ return entry;
}
- private Map<String, Object> updateHandleMap(PropertyMap map, PropertyDefinitionMap mapDef, Address address) {
+ private Map<String, Object> prepareSimpleMap(PropertyMap map, PropertyDefinitionMap mapDef) {
Map<String,PropertyDefinition> memberDefinitions = mapDef.getMap();
Map<String,Object> results = new HashMap<String,Object>();