modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java | 5 modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java | 13 + modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/CreateResourceDelegate.java | 2 modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/NetworkInterfaceComponent.java | 93 ++++++++++ modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml | 64 ++++++ modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java | 27 ++ modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml | 20 +- 7 files changed, 209 insertions(+), 15 deletions(-)
New commits: commit ae8691518ef66d602b74046efa0f1395b2ce7162 Author: Heiko W. Rupp hwr@redhat.com Date: Fri May 25 11:43:51 2012 +0200
BZ 824878 Support crud on network interfaces
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 ace2a35..30fe82b 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 @@ -359,6 +359,11 @@ public class BaseComponent<T extends ResourceComponent<?>> implements AS7Compone } }
+ // Allow to modify the configuration coming in from the RHQ server see also BZ 825120 + if (report.getResourceType().getName().equals("Network Interface")) { + Configuration configuration = report.getResourceConfiguration(); + NetworkInterfaceComponent.preProcessCreateChildConfiguration(configuration); + }
CreateResourceDelegate delegate = new CreateResourceDelegate(configDef, connection, address); return delegate.createResource(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 cf4749d..a2e6cc1 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 @@ -426,6 +426,9 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet { if (property.getStringValue() == null && !propertyDefinition.isRequired()) return;
+ if (property.getName().endsWith(":ignore")) // Caller takes care + return; + if (propertyDefinition.isReadOnly() && !createChildRequested) return;
@@ -488,7 +491,8 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet { entry = new SimpleEntry<String, Object>(realName, null); } } else { - entry = new SimpleEntry<String, Object>(name, property.getStringValue()); + Object o = getObjectWithType(propertyDefinition,property.getStringValue()); + entry = new SimpleEntry<String, Object>(name, o); }
return entry; @@ -632,6 +636,12 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet { }
String val = (String) entry.getValue(); + Object ret = getObjectWithType(pds, val); + + return ret; + } + + private Object getObjectWithType(PropertyDefinitionSimple pds, String val) { PropertySimpleType type = pds.getType(); Object ret; switch (type) { @@ -656,7 +666,6 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet { default: ret= val; } - return ret; }
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 index a7201a2..4f14ea6 100644 --- 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 @@ -72,7 +72,7 @@ public class CreateResourceDelegate extends ConfigurationWriteDelegate implement PropertyDefinitionSimple propertyDefinition = this.configurationDefinition .getPropertyDefinitionSimple(propertySimple.getName());
- if (!propertyDefinition.isRequired() && propertySimple.getStringValue() == null) { + if (propertyDefinition==null || (!propertyDefinition.isRequired() && propertySimple.getStringValue() == null)) { isEntryEligible = false; } else { entry = preparePropertySimple(propertySimple, propertyDefinition); diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/NetworkInterfaceComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/NetworkInterfaceComponent.java new file mode 100644 index 0000000..5440605 --- /dev/null +++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/NetworkInterfaceComponent.java @@ -0,0 +1,93 @@ +/* + * 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. + */ + +package org.rhq.modules.plugins.jbossas7; + +import org.rhq.core.domain.configuration.Configuration; +import org.rhq.core.domain.configuration.PropertySimple; +import org.rhq.core.pluginapi.configuration.ConfigurationFacet; +import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport; + +/** + * Component classes for network interfaces + * @author Heiko W. Rupp + */ +public class NetworkInterfaceComponent extends BaseComponent<NetworkInterfaceComponent> implements + ConfigurationFacet { + + private static final String[] wildCards = {"any-address","any-ipv4-address","any-ipv6-address"}; + private static final String WILDCARD_IGNORE = "wildcard:ignore"; + + @Override + public Configuration loadResourceConfiguration() throws Exception { + Configuration configuration = super.loadResourceConfiguration(); + + + +/* TODO revisit later BZ 825169 + // We now need to get the any*address properties separately + for (String wildcard : wildCards) { + Boolean val = readAttribute(getAddress(),wildcard,Boolean.class); + if (val) { + PropertySimple wildCardProp = new PropertySimple(WILDCARD_IGNORE,wildcard); + configuration.put(wildCardProp); + break; + } + } +*/ + + return configuration; + } + + @Override + public void updateResourceConfiguration(ConfigurationUpdateReport report) { + + Configuration configuration = report.getConfiguration(); + super.updateResourceConfiguration(report); + } + + public static void preProcessCreateChildConfiguration(Configuration configuration) { + + // Server is too stupid to accept all three any*address props for :add + // [standalone@localhost:9999 interface=test] :add(any-address=true,any-ipv4-address=false,any-ipv6-address=false) + // { + // "outcome" => "failed", + // "failure-description" => "JBAS014690: any-address is invalid", + // "rolled-back" => true + //} + // So we need to filter the false ones + + for (String wildCard: wildCards) { + PropertySimple ps = configuration.getSimple(wildCard); + if (ps!=null && ps.getStringValue().equals("false")) + configuration.remove(wildCard); + } + + +/* TODO revisit later BZ 825169 + PropertySimple wildCardProp = configuration.getSimple(WILDCARD_IGNORE);//, "any-address"); + String tmp = wildCardProp.getStringValue(); + for (String wildCard : wildCards) { + boolean val = wildCard.equals(tmp); + PropertySimple prop = new PropertySimple(wildCard,val); + configuration.put(prop); + } +*/ + } +} 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 9589865..c4371af 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 @@ -6159,8 +6159,10 @@
<service name="Network Interface" discovery="SubsystemDiscovery" - class="BaseComponent" - description="A named network interface, along with required criteria for determining the IP address to associate with that interface"> + class="NetworkInterfaceComponent" + description="A named network interface, along with required criteria for determining the IP address to associate with that interface" + createDeletePolicy="both" + >
<runs-inside> <parent-resource-type name="JBossAS7 Host Controller" plugin="&pluginName;"/> @@ -6171,6 +6173,64 @@ <plugin-configuration> <c:simple-property name="path" readOnly="true" default="interface"/> </plugin-configuration> + + <resource-configuration> + + <c:simple-property name="inet-address" required="false" type="string" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether or not the address matches the given value. Value is either a IP address in IPv6 or IPv4 dotted decimal notation, or a hostname that can be resolved to an IP address. An 'undefined' value means this attribute is not relevant to the IP address selection."/> + + <c:group name="address" displayName="Wildcard selection (exactly one property must be set to true)"> + <c:simple-property name="any-address" required="true" type="boolean" readOnly="false" default="true" defaultValue="false" + description="Attribute indicating that sockets using this interface should be bound to a wildcard address. The IPv6 wildcard address (::) will be used unless the java.net.preferIpV4Stack system property is set to true, in which case the IPv4 wildcard address (0.0.0.0) will be used. If a socket is bound to an IPv6 anylocal address on a dual-stack machine, it can accept both IPv6 and IPv4 traffic; if it is bound to an IPv4 (IPv4-mapped) anylocal address, it can only accept IPv4 traffic."/> + <c:simple-property name="any-ipv4-address" required="true" type="boolean" readOnly="false" default="false" defaultValue="false" + description="Attribute indicating that sockets using this interface should be bound to the IPv4 wildcard address (0.0.0.0)."/> + <c:simple-property name="any-ipv6-address" required="true" type="boolean" readOnly="false" default="false" defaultValue="false" + description="Attribute indicating that sockets using this interface should be bound to the IPv6 wildcard address (::)."/> + </c:group> +<!-- TODO revisit later BZ 825169 + <c:simple-property name="wildcard:ignore" displayName="Address family selection" defaultValue="any-address" default="any-address" + description="Attribute indicating that sockets using this interface should be bound to a wildcard address. If set to 'Any', the IPv6 wildcard address (::) will be used unless the java.net.preferIpV4Stack system property is set to true, in which case the IPv4 wildcard address (0.0.0.0) will be used. If a socket is bound to an IPv6 anylocal address on a dual-stack machine, it can accept both IPv6 and IPv4 traffic; if it is bound to an IPv4 (IPv4-mapped) anylocal address, it can only accept IPv4 traffic."> + <c:property-options> + <c:option value="any-address" name="Any"/> + <c:option value="any-ipv4-address" name="Any IPv4"/> + <c:option value="any-ipv6-address" name="Any IPv6"/> + </c:property-options> + </c:simple-property> +--> + + <c:group name="advanced" displayName="Advanced settings" hiddenByDefault="true"> + <c:simple-property name="link-local-address" required="false" type="boolean" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether or not the address is link-local. An 'undefined' or 'false' value means this attribute is not relevant to the IP address selection."/> + <c:simple-property name="loopback" required="false" type="boolean" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether or not it is a loopback address. An 'undefined' or 'false' value means this attribute is not relevant to the IP address selection."/> + <c:simple-property name="loopback-address" required="false" type="string" readOnly="false" + description="Attribute indicating that the IP address for this interface should be the given value, if a loopback interface exists on the machine. A 'loopback address' may not actually be configured on the machine's loopback interface. Differs from inet-address in that the given value will be used even if no NIC can be found that has the IP specified address associated with it. An 'undefined' or 'false' value means this attribute is not relevant to the IP address selection."/> + + <c:simple-property name="multicast" required="false" type="boolean" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether or not its network interface supports multicast. An 'undefined' or 'false' value means this attribute is not relevant to the IP address selection."/> + + + <c:simple-property name="nic" required="false" type="string" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether its network interface has the given name. The name of a network interface (e.g. eth0, eth1, lo). An 'undefined' value means this attribute is not relevant to the IP address selection."/> + + <c:simple-property name="nic-match" required="false" type="string" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether its network interface has a name that matches the given regular expression. Value is a regular expression against which the names of the network interfaces available on the machine can be matched to find an acceptable interface. An 'undefined' value means this attribute is not relevant to the IP address selection."/> + + <c:simple-property name="point-to-point" required="false" type="boolean" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether or not its network interface is a point-to-point interface. An 'undefined' or 'false' value means this attribute is not relevant to the IP address selection"/> + <c:simple-property name="public-address" required="false" type="boolean" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether or not it is a publicly routable address. An 'undefined' or 'false' value means this attribute is not relevant to the IP address selection"/> + <c:simple-property name="site-local-address" required="false" type="boolean" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether or it is a site-local address. An 'undefined' or 'false' value means this attribute is not relevant to the IP address selection"/> + <c:simple-property name="subnet-match" required="false" type="string" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether or it the address fits in the given subnet definition. Value is a network IP address and the number of bits in the address' network prefix, written in 'slash notation'; e.g. '192.168.0.0/16'. An 'undefined' value means this attribute is not relevant to the IP address selection."/> + + <c:simple-property name="up" required="false" type="boolean" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether its network interface is currently up. An 'undefined' or 'false' value means this attribute is not relevant to the IP address selection"/> + <c:simple-property name="virtual" required="false" type="boolean" readOnly="false" + description="Attribute indicating that part of the selection criteria for choosing an IP address for this interface should be whether its network interface is a virtual interface. An 'undefined' or 'false' value means this attribute is not relevant to the IP address selection"/> + </c:group> + </resource-configuration> </service>
diff --git a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java index ae35eae..ba2f13c 100644 --- a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java +++ b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java @@ -368,7 +368,8 @@ public class ConfigurationUpdatingTest extends AbstractConfigurationHandlingTest assert step1.getAdditionalProperties().get("name").equals("test-prop"); assert step1.getAdditionalProperties().get("value").equals("Heiko"); assert step2.getAdditionalProperties().get("name").equals("check-interval"); - assert step2.getAdditionalProperties().get("value").equals("23"); + assert step2.getAdditionalProperties().get("value").equals(23); + assert step3.getAdditionalProperties().get("value").equals(true);
}
@@ -583,7 +584,7 @@ public class ConfigurationUpdatingTest extends AbstractConfigurationHandlingTest
additionalProperties = cop.step(2).getAdditionalProperties(); assert additionalProperties.get("name").equals("bar"); - assert additionalProperties.get("value").equals("456"); + assert additionalProperties.get("value").equals(456);
}
@@ -796,12 +797,12 @@ public class ConfigurationUpdatingTest extends AbstractConfigurationHandlingTest
}
- /** Tests that c:group entries are updated correctly in addition to special c:group syntax handling. + /** Tests that c:group entries are updated correctly in addition to special c:group syntax handling. * Ex. <c:group name="proxy" displayName="Proxy Options"> * <c:simple-property name="proxy-list" required="false" type="string" readOnly="false" defaultValue="" description="List of proxies, Format (hostname:port) separated with comas."/> * <c:simple-property name="proxy-url" required="false" type="string" readOnly="false" defaultValue="/" description="Base URL for MCMP requests."/> * </c:group> - * + * * @throws Exception */ public void testUpdateGroupConfiguration() throws Exception { @@ -843,4 +844,22 @@ public class ConfigurationUpdatingTest extends AbstractConfigurationHandlingTest + "' was not updated correctly. Expected '" + properties.get(name) + "' but was '" + value + "'."; } } + + public void testIgnoreProperty() throws Exception { + ConfigurationDefinition definition = loadDescriptor("testIgnore"); + + Configuration configuration = new Configuration(); + + configuration.put(new PropertySimple("normal","0xdeadbeef")); + configuration.put(new PropertySimple("test:ignore","Hello world!")); // should not create a step + + FakeConnection connection = new FakeConnection(); + + ConfigurationWriteDelegate delegate = new ConfigurationWriteDelegate(definition, connection, null); + CompositeOperation cop = delegate.updateGenerateOperationFromProperties(configuration, new Address()); + + assert cop != null; + assert cop.numberOfSteps() == 1 : "One step was expected, but got " + cop.numberOfSteps(); + + } } diff --git a/modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml b/modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml index 8959b24..4350230 100644 --- a/modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml +++ b/modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml @@ -166,6 +166,14 @@ </resource-configuration> </server>
+ <server class="foo" discovery="foo" name="testIgnore"> + + <resource-configuration> + <c:simple-property name="normal" readOnly="false"/> + <c:simple-property name="test:ignore" readOnly="false" required="false"/> + </resource-configuration> + </server> + <server class="foo" discovery="foo" name="listOfSimple1">
<resource-configuration> @@ -281,12 +289,12 @@ </c:group> </resource-configuration> </server> - + <!-- Simple c:group entries from descriptor with no special handling. --> <service name="simpleGroupNoSpecial" class="BaseComponent" discovery="SubsystemDiscovery" - description="simple grouped properties. No special handling" + description="simple grouped properties. No special handling" singleton="true"> <resource-configuration> <c:group name="proxy" displayName="Proxy Options"> @@ -302,21 +310,21 @@ <!--<c:option-source target="resource" expression="type=Connector plugin=&pluginName;"/>--> </c:simple-property> </c:group> - </resource-configuration> - </service> + </resource-configuration> + </service>
<!-- Same as previous but for update. --> <service name="simpleGroupNoSpecialUpdate" class="BaseComponent" discovery="SubsystemDiscovery" - description="simple grouped properties. No special handling" + description="simple grouped properties. No special handling" singleton="true"> <resource-configuration> <c:group name="proxy" displayName="Proxy Options"> <c:simple-property name="proxy-list" required="false" type="string" readOnly="false" defaultValue="" description="List of proxies, Format (hostname:port) separated with comas."/> <c:simple-property name="proxy-url" required="false" type="string" readOnly="false" defaultValue="/" description="Base URL for MCMP requests."/> </c:group> - </resource-configuration> + </resource-configuration> </service>
</plugin> \ No newline at end of file
rhq-commits@lists.fedorahosted.org