[jboss-cvs] JBossAS SVN: r110911 - in projects/jboss-jca/trunk/rhq/src: main/java/org/jboss/jca/rhq/ra and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Mar 15 02:56:04 EDT 2011
Author: gaol
Date: 2011-03-15 02:56:04 -0400 (Tue, 15 Mar 2011)
New Revision: 110911
Modified:
projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/core/AbstractResourceComponent.java
projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/ra/McfResourceComponent.java
projects/jboss-jca/trunk/rhq/src/main/resources/META-INF/rhq-plugin.xml
projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/test/XATestCase.java
Log:
[JBJCA-518] updates conn-pool configurations of McfResourceComponent
Modified: projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/core/AbstractResourceComponent.java
===================================================================
--- projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/core/AbstractResourceComponent.java 2011-03-15 00:43:57 UTC (rev 110910)
+++ projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/core/AbstractResourceComponent.java 2011-03-15 06:56:04 UTC (rev 110911)
@@ -31,6 +31,7 @@
import org.jboss.logging.Logger;
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;
@@ -254,5 +255,122 @@
else
return null;
}
+
+ /**
+ * Updates the ConfigProperty from value of ProperyList to the jcaObj.
+ *
+ * @param jcaObj the JCA object which the value will be update to
+ * @param configPropList the PropertyList where the value comes from
+ * @param configProperties The ConfigProperty list
+ */
+ protected void updatePropertyList(Object jcaObj, PropertyList configPropList, List<ConfigProperty> configProperties)
+ {
+ for (Property prop : configPropList.getList())
+ {
+ PropertyMap propMap = (PropertyMap)prop;
+ String configName = propMap.getSimpleValue("name", null);
+ String type = propMap.getSimpleValue("type", null);
+ String valueString = propMap.getSimpleValue("value", null);
+ ConfigProperty configProp = getConfigPropertyByName(configName, configProperties);
+ if (null == configProp)
+ {
+ throw new IllegalStateException("Can not find ConfigProperty with name: " + configName);
+ }
+ if (!configProp.isDynamic())
+ {
+ logger.warn("ConfigProperty with name: " + configName + " is not updatable, ignore it.");
+ continue;
+ }
+ try
+ {
+ setPropertyValue(jcaObj, configName, type, valueString);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Can not update ConfigProperty value.", e);
+ }
+ }
+ }
+
+ private void setPropertyValue(Object jcaObj, String name, String type, String valueString) throws Exception
+ {
+ Class<?> typeCls = Class.forName(type);
+ Object value = convertObjValue(typeCls, valueString);
+ String methodNameBase = name.substring(0, 1).toUpperCase() + name.substring(1);
+ String methodName = "set" + methodNameBase;
+ Method setMtd = jcaObj.getClass().getMethod(methodName, typeCls);
+ setMtd.invoke(jcaObj, value);
+ }
+ /**
+ * convertObjValue
+ *
+ * @param typeCls Class.
+ * the Class is one of the <code>config-property-typeType</code> defined in <code>connector_1.6.xsd</code>
+ * @param valueString value string
+ * @return value in typeCls
+ */
+ private Object convertObjValue(Class<?> typeCls, String valueString)
+ {
+ if (typeCls.equals(String.class))
+ {
+ return valueString;
+ }
+ else if (typeCls.equals(Character.class))
+ {
+ return Character.valueOf(valueString.charAt(0));
+ }
+ else if (typeCls.equals(Integer.class))
+ {
+ return Integer.valueOf(valueString);
+ }
+ else if (typeCls.equals(Boolean.class))
+ {
+ return Boolean.valueOf(valueString);
+ }
+ else if (typeCls.equals(Double.class))
+ {
+ return Double.valueOf(valueString);
+ }
+ else if (typeCls.equals(Byte.class))
+ {
+ return Byte.valueOf(valueString);
+ }
+ else if (typeCls.equals(Short.class))
+ {
+ return Short.valueOf(valueString);
+ }
+ else if (typeCls.equals(Long.class))
+ {
+ return Long.valueOf(valueString);
+ }
+ else if (typeCls.equals(Float.class))
+ {
+ return Float.valueOf(valueString);
+ }
+ else
+ {
+ throw new IllegalStateException("Unknown class: " + typeCls);
+ }
+ }
+
+ /**
+ * getConfigPropertyByName
+ *
+ * @param configName ConfigProperty name
+ * @param configProperties ConfigProperty list
+ * @return ConfigProperty with name configName, otherwise null.
+ */
+ protected ConfigProperty getConfigPropertyByName(String configName, List<ConfigProperty> configProperties)
+ {
+ for (ConfigProperty configProperty : configProperties)
+ {
+ if (configName.equals(configProperty.getName()))
+ {
+ return configProperty;
+ }
+ }
+ return null;
+ }
+
}
Modified: projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/ra/McfResourceComponent.java
===================================================================
--- projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/ra/McfResourceComponent.java 2011-03-15 00:43:57 UTC (rev 110910)
+++ projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/ra/McfResourceComponent.java 2011-03-15 06:56:04 UTC (rev 110911)
@@ -38,12 +38,20 @@
import org.jboss.logging.Logger;
import org.rhq.core.domain.configuration.Configuration;
+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.pluginapi.configuration.ConfigurationUpdateReport;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
/**
* McfResourceComponent represent the ManagedConnectionFactory in JCA container.
*
+ * The <i>mcf</i> will be initialized when <code>start(ResourceContext)</code> method is called.
+ * The <i>mcf</i> will be released when <code>stop()</code> method is called.
+ *
+ * The <i>mcf</i> must be kept not-null value during the life time of this <code>McfResourceComponent</code>.
+ *
* @author <a href="mailto:lgao at redhat.com">Lin Gao</a>
* @author <a href="mailto:jeff.zhang at jboss.org">Jeff Zhang</a>
*/
@@ -51,44 +59,80 @@
{
/** log */
private static final Logger logger = Logger.getLogger(McfResourceComponent.class);
-
+
+ /** ManagedConnectionFactory associated with this McfResourceComponent */
+ private ManagedConnectionFactory mcf = null;
+
/**
- * loadResourceConfiguration
+ * start
*
- *
- * @return Configuration Configuration
+ * @param resourceContext The ResourceContext
* @throws Exception exception
*/
+ @SuppressWarnings("rawtypes")
@Override
- public Configuration loadResourceConfiguration() throws Exception
+ public void start(ResourceContext resourceContext) throws Exception
{
- Configuration config = new Configuration();
-
- ManagementRepository mr = ManagementRepositoryManager.getManagementRepository();
- Connector connector = ManagementRepositoryHelper.getConnectorByUniqueId(mr, getRarUniqueId());
-
- String jcaClsName = getJCAClassName();
- ManagedConnectionFactory mcf = null;
- for (ManagedConnectionFactory connectorMcf : connector.getManagedConnectionFactories())
+ super.start(resourceContext);
+ if (null == this.mcf)
{
- Class<?> mcfCls = connectorMcf.getManagedConnectionFactory().getClass();
- if (mcfCls.getName().equals(jcaClsName))
+ ManagementRepository mr = ManagementRepositoryManager.getManagementRepository();
+ Connector connector = ManagementRepositoryHelper.getConnectorByUniqueId(mr, getRarUniqueId());
+ String jcaClsName = getJCAClassName();
+ for (ManagedConnectionFactory connectorMcf : connector.getManagedConnectionFactories())
{
- logger.debug("Class Name is: " + jcaClsName);
- mcf = connectorMcf;
- break;
+ Class<?> mcfCls = connectorMcf.getManagedConnectionFactory().getClass();
+ if (mcfCls.getName().equals(jcaClsName))
+ {
+ logger.debug("Class Name is: " + jcaClsName);
+ this.mcf = connectorMcf;
+ break;
+ }
}
}
- if (null == mcf)
+ validateState();
+ }
+
+ /**
+ * stop
+ */
+ @Override
+ public void stop()
+ {
+ super.stop();
+ this.mcf = null;
+ }
+
+ /**
+ * Check that the mcf is not null.
+ */
+ private void validateState()
+ {
+ if (null == this.mcf)
{
- throw new IllegalStateException("Can not find the associated ManagedConnectionFactory in the Connector.");
+ throw new IllegalStateException("ManagedConnectionFactory can not be found.");
}
+ }
+
+ /**
+ * loadResourceConfiguration
+ *
+ *
+ * @return Configuration Configuration
+ * @throws Exception exception
+ */
+ @Override
+ public Configuration loadResourceConfiguration() throws Exception
+ {
+ validateState();
- javax.resource.spi.ManagedConnectionFactory jcaMcf = mcf.getManagedConnectionFactory();
+ Configuration config = new Configuration();
+
+ javax.resource.spi.ManagedConnectionFactory jcaMcf = this.mcf.getManagedConnectionFactory();
// jndi name
// mcf-class-name
- PropertySimple clsNameProp = new PropertySimple("mcf-class-name", jcaClsName);
+ PropertySimple clsNameProp = new PropertySimple("mcf-class-name", getJCAClassName());
config.put(clsNameProp);
// cf-interface-name
@@ -105,7 +149,7 @@
config.put(useRaAssoProp);
// conn_pool
- PoolConfiguration poolConfig = mcf.getPoolConfiguration();
+ PoolConfiguration poolConfig = this.mcf.getPoolConfiguration();
PropertySimple minSizeProp = new PropertySimple("min-pool-size", Integer.valueOf(poolConfig.getMinSize()));
config.put(minSizeProp);
@@ -124,7 +168,7 @@
PropertySimple backGroundValidateMintuesProp = new PropertySimple("background-validation-minutes", bvMinutes);
config.put(backGroundValidateMintuesProp);
- Integer blTimeout = Integer.valueOf((int)poolConfig.getBlockingTimeout());
+ Long blTimeout = Long.valueOf(poolConfig.getBlockingTimeout());
PropertySimple blockingTimeoutProp = new PropertySimple("blocking-timeout-millis", blTimeout);
config.put(blockingTimeoutProp);
@@ -144,10 +188,72 @@
config.put(useFasFailProp);
// config properties
- List<ConfigProperty> mcfConfProps = mcf.getConfigProperties();
+ List<ConfigProperty> mcfConfProps = this.mcf.getConfigProperties();
PropertyList configList = getConfigPropertiesList(jcaMcf, mcfConfProps);
config.put(configList);
return config;
}
+
+
+ /**
+ * updateResourceConfiguration
+ *
+ * @param updateResourceConfiguration the ConfigurationUpdateReport
+ */
+ @Override
+ public void updateResourceConfiguration(ConfigurationUpdateReport updateResourceConfiguration)
+ {
+ validateState();
+ super.updateResourceConfiguration(updateResourceConfiguration);
+ Configuration config = updateResourceConfiguration.getConfiguration();
+
+ // update conn-pool configurations
+ PoolConfiguration poolConfig = this.mcf.getPoolConfiguration();
+ Integer minPoolSize = Integer.valueOf(config.getSimpleValue("min-pool-size", "0"));
+ poolConfig.setMinSize(minPoolSize.intValue());
+
+ Integer maxPoolSize = Integer.valueOf(config.getSimpleValue("max-pool-size", "20"));
+ poolConfig.setMaxSize(maxPoolSize.intValue());
+
+ Boolean backGroundValid = Boolean.valueOf(config.getSimpleValue("background-validation", "false"));
+ poolConfig.setBackgroundValidation(backGroundValid.booleanValue());
+
+ // background-validation-millis
+
+ // background-validation-minutes
+ Integer backGroundValidMinutes = Integer.valueOf(config.getSimpleValue("background-validation-minutes", "0"));
+ poolConfig.setBackgroundValidationMinutes(backGroundValidMinutes.intValue());
+
+ // blocking-timeout-millis
+ Long blockTimeoutMillis = Long.valueOf(config.getSimpleValue("blocking-timeout-millis", "30000"));
+ poolConfig.setBlockingTimeout(blockTimeoutMillis.longValue());
+
+ // idle-timeout-minutes
+ Integer idleTimeoutMinutes = Integer.valueOf(config.getSimpleValue("idle-timeout-minutes", "30"));
+ Long idleTimeoutMillis = Long.valueOf(idleTimeoutMinutes * 60 * 1000);
+ poolConfig.setIdleTimeout(idleTimeoutMillis.longValue());
+
+ // prefill
+ Boolean preFill = Boolean.valueOf(config.getSimpleValue("prefill", "true"));
+ poolConfig.setPrefill(preFill);
+
+ // use-strict-min
+ Boolean useStrictMin = Boolean.valueOf(config.getSimpleValue("use-strict-min", "false"));
+ poolConfig.setStrictMin(useStrictMin);
+
+ // use-fast-fail
+ Boolean useFastFail = Boolean.valueOf(config.getSimpleValue("use-fast-fail", "false"));
+ poolConfig.setUseFastFail(useFastFail);
+
+ // config-properties
+ PropertyList configPropertiesList = config.getList("config-property");
+ javax.resource.spi.ManagedConnectionFactory jcaMcf = this.mcf.getManagedConnectionFactory();
+ List<ConfigProperty> configProperties = this.mcf.getConfigProperties();
+ updatePropertyList(jcaMcf, configPropertiesList, configProperties);
+
+ updateResourceConfiguration.setStatus(ConfigurationUpdateStatus.SUCCESS);
+
+ }
+
}
Modified: projects/jboss-jca/trunk/rhq/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- projects/jboss-jca/trunk/rhq/src/main/resources/META-INF/rhq-plugin.xml 2011-03-15 00:43:57 UTC (rev 110910)
+++ projects/jboss-jca/trunk/rhq/src/main/resources/META-INF/rhq-plugin.xml 2011-03-15 06:56:04 UTC (rev 110911)
@@ -97,7 +97,7 @@
<c:simple-property name="blocking-timeout-millis" displayName="Blocking Timeout in Milliseconds"
units="milliseconds" defaultValue="30000"
- type="integer" required="false">
+ type="long" required="false">
<c:description>
Indicates the maximum time in milliseconds to block while waiting for a connection before throwing
an exception. Note that this blocks only while waiting for a permit for a connection, and will never
@@ -386,7 +386,7 @@
<!-- Resource Adpater -->
<service name="Resource Adapter" discovery="org.jboss.jca.rhq.ra.RaResourceDiscoveryComponent"
- class="org.jboss.jca.rhq.ra.RaResourceComponent" supportsManualAdd="true">
+ class="org.jboss.jca.rhq.ra.RaResourceComponent">
<resource-configuration>
<c:group name="general" displayName="General">
@@ -401,7 +401,7 @@
<!-- Managed Connection Factories. Includes No Tx / Tx connection factories -->
<service name="Connection Factory" discovery="org.jboss.jca.rhq.ra.CfResourceDiscoveryComponent"
- class="org.jboss.jca.rhq.ra.CfResourceComponent" supportsManualAdd="true">
+ class="org.jboss.jca.rhq.ra.CfResourceComponent">
<resource-configuration>
<c:group name="general" displayName="General">
@@ -447,7 +447,7 @@
<c:simple-property name="use-ra-association" displayName="Use ResourceAdapterAssociation" type="boolean" readOnly="true"/>
</c:group>
- <c:group name="conn_pool" displayName="Connection Pool">
+ <c:group name="conn-pool" displayName="Connection Pool">
&datasourceAndConnectionFactoryConnectionResourceConfigProps;
&datasourceAndConnectionFactoryAdvancedResourceConfigProps;
</c:group>
Modified: projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/test/XATestCase.java
===================================================================
--- projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/test/XATestCase.java 2011-03-15 00:43:57 UTC (rev 110910)
+++ projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/test/XATestCase.java 2011-03-15 06:56:04 UTC (rev 110911)
@@ -21,6 +21,12 @@
*/
package org.jboss.jca.rhq.test;
+import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration;
+import org.jboss.jca.core.api.management.Connector;
+import org.jboss.jca.core.api.management.ManagementRepository;
+import org.jboss.jca.rhq.core.ManagementRepositoryManager;
+import org.jboss.jca.rhq.util.ManagementRepositoryHelper;
+
import java.io.File;
import java.util.Set;
@@ -29,6 +35,7 @@
import org.junit.Test;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
@@ -36,6 +43,7 @@
import org.rhq.core.pc.inventory.RuntimeDiscoveryExecutor;
import org.rhq.core.pc.plugin.FileSystemPluginFinder;
import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import static org.junit.Assert.*;
@@ -96,7 +104,7 @@
{
assertEquals(1, res.getChildResources().size());
- // text mcf
+ // test mcf loadConfiguration
Resource mcfRes = res.getChildResources().iterator().next();
ConfigurationFacet mcfConfigFacet = (ConfigurationFacet)im.getResourceComponent(mcfRes);
Configuration mcfConfig = mcfConfigFacet.loadResourceConfiguration();
@@ -115,6 +123,33 @@
assertEquals("false", mcfConfig.getSimpleValue("use-strict-min", null));
assertEquals("false", mcfConfig.getSimpleValue("use-fast-fail", null));
+ // test mcf updateConfiguration
+ mcfConfig.put(new PropertySimple("min-pool-size", 5));
+ mcfConfig.put(new PropertySimple("max-pool-size", 15));
+ mcfConfig.put(new PropertySimple("background-validation", true));
+ mcfConfig.put(new PropertySimple("background-validation-minutes", 30));
+ mcfConfig.put(new PropertySimple("blocking-timeout-millis", 10000));
+ mcfConfig.put(new PropertySimple("idle-timeout-minutes", 15));
+ mcfConfig.put(new PropertySimple("prefill", false));
+ mcfConfig.put(new PropertySimple("use-strict-min", true));
+ mcfConfig.put(new PropertySimple("use-fast-fail", true));
+
+ ConfigurationUpdateReport updateConfigReport = new ConfigurationUpdateReport(mcfConfig);
+ mcfConfigFacet.updateResourceConfiguration(updateConfigReport);
+
+ ManagementRepository manRepo = ManagementRepositoryManager.getManagementRepository();
+ Connector connector = ManagementRepositoryHelper.getConnectorByUniqueId(manRepo, "xa.rar");
+ PoolConfiguration poolConfig = connector.getManagedConnectionFactories().get(0).getPoolConfiguration();
+
+ assertEquals(5, poolConfig.getMinSize());
+ assertEquals(15, poolConfig.getMaxSize());
+ assertTrue(poolConfig.isBackgroundValidation());
+ assertEquals(30, poolConfig.getBackgroundValidationMinutes());
+ assertEquals(10000, poolConfig.getBlockingTimeout());
+ assertEquals(15 * 60 * 1000L, poolConfig.getIdleTimeout());
+ assertFalse(poolConfig.isPrefill());
+ assertTrue(poolConfig.isStrictMin());
+ assertTrue(poolConfig.isUseFastFail());
}
if (res.getName().equals("XAAdminObjectImpl"))
{
More information about the jboss-cvs-commits
mailing list