[jboss-cvs] JBossAS SVN: r86691 - in branches/Branch_5_x: profileservice/src/main/org/jboss/profileservice/management and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 2 16:38:43 EDT 2009


Author: scott.stark at jboss.org
Date: 2009-04-02 16:38:43 -0400 (Thu, 02 Apr 2009)
New Revision: 86691

Added:
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java
Modified:
   branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java
   branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java
   branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
Log:
JBAS-6672, handle removed properties as unspecified properties with no admin level value.

Modified: branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java
===================================================================
--- branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java	2009-04-02 20:29:49 UTC (rev 86690)
+++ branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java	2009-04-02 20:38:43 UTC (rev 86691)
@@ -37,6 +37,7 @@
 import org.jboss.managed.api.ManagedProperty;
 import org.jboss.managed.api.factory.ManagedObjectFactory;
 import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
+import org.jboss.metatype.api.values.SimpleValue;
 import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
 import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
 import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
@@ -113,7 +114,19 @@
    protected void writeTemplate(File dsXml, DeploymentTemplateInfo values)
       throws Exception
    {
-      String cfType = ((DsDataSourceTemplateInfo)values).getConnectionFactoryType();
+      // Look for the CF type using the dsType ManagedProperty
+      ManagedProperty dsTypeMP = values.getProperties().get("dsType");
+      String cfType = null;
+      if(dsTypeMP == null)
+      {
+         // Try casting this to a DsDataSourceTemplateInfo
+         cfType = ((DsDataSourceTemplateInfo)values).getConnectionFactoryType();
+      }
+      else
+      {
+         SimpleValue dsTypeSV = (SimpleValue) dsTypeMP.getValue();
+         cfType = dsTypeSV.getValue().toString();
+      }
 
       ManagedConnectionFactoryDeploymentMetaData mcf;
       ManagedObjectFactory mof = ManagedObjectFactoryBuilder.create();

Modified: branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java
===================================================================
--- branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java	2009-04-02 20:29:49 UTC (rev 86690)
+++ branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java	2009-04-02 20:38:43 UTC (rev 86691)
@@ -32,6 +32,7 @@
 import org.jboss.managed.api.ManagedProperty;
 import org.jboss.managed.api.annotation.ManagementObjectID;
 import org.jboss.managed.plugins.BasicDeploymentTemplateInfo;
+import org.jboss.managed.plugins.DefaultFieldsImpl;
 import org.jboss.managed.plugins.ManagedPropertyImpl;
 import org.jboss.metatype.api.types.SimpleMetaType;
 import org.jboss.metatype.api.values.MetaValue;
@@ -127,6 +128,14 @@
    private void populate()
    {
       populateDefaultValues();
+      // Pass the 
+      DefaultFieldsImpl fields = new DefaultFieldsImpl("dsType");
+      fields.setDescription("The datasource type");
+      fields.setMetaType(SimpleMetaType.STRING);
+      fields.setValue(SimpleValueSupport.wrap(dsType));
+      fields.setField(Fields.READ_ONLY, Boolean.TRUE);
+      ManagedPropertyImpl dsTypeMP = new ManagedPropertyImpl(fields);
+      addProperty(dsTypeMP);
       
       // DataSource
 //      if("local-tx-datasource".equals(dsType))

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java	2009-04-02 20:29:49 UTC (rev 86690)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java	2009-04-02 20:38:43 UTC (rev 86691)
@@ -87,7 +87,9 @@
          String deploymentName = template.getDeploymentName(deploymentBaseName);
          if(deploymentName == null)
             throw new IllegalStateException("getDeploymentName returned a null value.");
-         base = template.applyTemplate(info);
+         // Wrap info to exclude all removed properties
+         FilteredDeploymentTemplateInfo filterInfo = new FilteredDeploymentTemplateInfo(info);
+         base = template.applyTemplate(filterInfo);
          if(base == null)
             throw new IllegalStateException("applyTemplate returned null virtual file.");
 

Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java	                        (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java	2009-04-02 20:38:43 UTC (rev 86691)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.profileservice.management;
+
+import java.util.Map;
+
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * A DeploymentTemplateInfo that filters out any ManagedProperties that have
+ * been removed.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class FilteredDeploymentTemplateInfo
+   implements DeploymentTemplateInfo
+{
+   private DeploymentTemplateInfo delegate;
+
+   public FilteredDeploymentTemplateInfo(DeploymentTemplateInfo delegate)
+   {
+      this.delegate = delegate;
+   }
+
+   public DeploymentTemplateInfo copy()
+   {
+      FilteredDeploymentTemplateInfo copy = new FilteredDeploymentTemplateInfo(delegate.copy());
+      return copy;
+   }
+
+   public String getDescription()
+   {
+      return delegate.getDescription();
+   }
+
+   public String getName()
+   {
+      return delegate.getName();
+   }
+
+   public Map<String, ManagedProperty> getProperties()
+   {
+      RemovedPropertyMap props = new RemovedPropertyMap(delegate.getProperties());
+      return props;
+   }
+
+   public String getRootManagedPropertyName()
+   {
+      return delegate.getRootManagedPropertyName();
+   }
+}


Property changes on: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/FilteredDeploymentTemplateInfo.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-04-02 20:29:49 UTC (rev 86690)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-04-02 20:38:43 UTC (rev 86691)
@@ -1089,9 +1089,17 @@
       // Dispatch any runtime component property values
       for(ManagedProperty prop : comp.getProperties().values())
       {
-         // Skip null values && non-CONFIGURATION values
-         if( prop.getValue() == null || prop.hasViewUse(ViewUse.CONFIGURATION) == false)
+         // Skip null values && non-CONFIGURATION values, unmodified values, and removed values
+         boolean skip = prop.getValue() == null
+            || prop.hasViewUse(ViewUse.CONFIGURATION) == false
+            || prop.isModified() == false
+            || prop.isRemoved() == true;
+         if( skip )
+         {
+            if(log.isTraceEnabled())
+               log.trace("Skipping component property: "+prop);
             continue;
+         }
 
          ManagedProperty ctxProp = serverComp.getProperties().get(prop.getName());
          // Check for a mapped name

Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java	                        (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java	2009-04-02 20:38:43 UTC (rev 86691)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.profileservice.management;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * Map<String, ManagedProperty> that filters out ManagedPropertys that have
+ * isRemoved == true.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class RemovedPropertyMap
+   implements Map<String, ManagedProperty>
+{
+   private Map<String, ManagedProperty> delegate;
+   private Set<String> keySet;
+
+   public RemovedPropertyMap(Map<String, ManagedProperty> delegate)
+   {
+      this.delegate = delegate;
+      // Filter out the removed property keys
+      keySet = new HashSet<String>();
+      for(String key : delegate.keySet())
+      {
+         ManagedProperty mp = delegate.get(key);
+         if(mp.isRemoved() == false)
+            keySet.add(key);
+      }
+   }
+
+   public void clear()
+   {
+      delegate.clear();
+      keySet.clear();
+   }
+
+   public boolean containsKey(Object key)
+   {
+      return keySet.contains(key);
+   }
+
+   public boolean containsValue(Object value)
+   {
+      ManagedProperty mp = (ManagedProperty) value;
+      return keySet.contains(mp.getName());
+   }
+
+   public Set<Entry<String, ManagedProperty>> entrySet()
+   {
+      return delegate.entrySet();
+   }
+
+   public boolean equals(Object o)
+   {
+      return delegate.equals(o);
+   }
+
+   public ManagedProperty get(Object key)
+   {
+      ManagedProperty mp = delegate.get(key);
+      if(mp.isRemoved())
+         mp = null;
+      return mp;
+   }
+
+   public int hashCode()
+   {
+      return delegate.hashCode();
+   }
+
+   public boolean isEmpty()
+   {
+      return keySet.isEmpty();
+   }
+
+   public Set<String> keySet()
+   {
+      return keySet;
+   }
+
+   public ManagedProperty put(String key, ManagedProperty value)
+   {
+      if(value.isRemoved())
+         keySet.add(key);
+      return delegate.put(key, value);
+   }
+
+   public void putAll(Map<? extends String, ? extends ManagedProperty> t)
+   {
+      delegate.putAll(t);
+   }
+
+   public ManagedProperty remove(Object key)
+   {
+      if(keySet.contains(key))
+         keySet.remove(key);
+      return delegate.remove(key);
+   }
+
+   public int size()
+   {
+      return keySet.size();
+   }
+
+   public Collection<ManagedProperty> values()
+   {
+      ArrayList<ManagedProperty> values = new ArrayList<ManagedProperty>();
+      for(ManagedProperty mp : delegate.values())
+      {
+         if(mp.isRemoved() == false)
+            values.add(mp);
+      }
+      return values;
+   }
+}


Property changes on: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/RemovedPropertyMap.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java	2009-04-02 20:38:43 UTC (rev 86691)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.profileservice.test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.spi.management.KnownComponentTypes;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+
+/**
+ * Additional tests of managing DataSources
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DataSourceUnitTestCase extends AbstractProfileServiceTest
+{
+   public DataSourceUnitTestCase(String s)
+   {
+      super(s);
+   }
+
+   /**
+    * JBAS-6672 related testing of properties having default values
+    * @throws Exception
+    */
+   public void testRemovedProperties() throws Exception
+   {
+      ManagementView mgtView = getManagementView();
+      String templateName = "LocalTxDataSourceTemplate";
+      String jndiName = "testRemovedPropertiesDS";
+      DeploymentTemplateInfo dsInfo = mgtView.getTemplate(templateName);
+      assertNotNull("template " + templateName + " found", dsInfo);
+      log.info(dsInfo.getProperties().keySet());
+      Map<String, ManagedProperty> props = dsInfo.getProperties();
+
+      // Set key property values
+      ManagedProperty jndiNameMP = props.get("jndi-name");
+      jndiNameMP.setValue(SimpleValueSupport.wrap(jndiName));
+      ManagedProperty driverClass = props.get("driver-class");
+      driverClass.setValue(SimpleValueSupport.wrap("org.hsqldb.jdbcDriver"));
+      ManagedProperty connUrl = props.get("connection-url");
+      connUrl.setValue(SimpleValueSupport.wrap("jdbc:hsqldb:."));
+      ManagedProperty userName = props.get("user-name");
+      userName.setValue(SimpleValueSupport.wrap("sa"));
+      ManagedProperty password = props.get("password");
+      password.setValue(SimpleValueSupport.wrap(""));
+
+      // Remove the 
+      ManagedProperty useJavaCtx = props.get("use-java-context");
+      SimpleValue nullBoolean = SimpleValueSupport.wrap(false);
+      ((SimpleValueSupport)nullBoolean).setValue(null);
+      useJavaCtx.setValue(nullBoolean);
+      useJavaCtx.setRemoved(true);
+      
+      mgtView.applyTemplate("testRemovedProperties", dsInfo);
+
+      // reload the view and new datasource component
+      ComponentType componentType = new ComponentType("DataSource", "LocalTx");
+      activeView = null;
+      mgtView = getManagementView();
+      ManagedComponent dsMC = getManagedComponent(mgtView, componentType, jndiName);
+      assertNotNull(dsMC);
+
+      // Validate that the use-java-context value is true
+      useJavaCtx = dsMC.getProperty("use-java-context");
+      assertNotNull(useJavaCtx);
+      assertEquals(SimpleValueSupport.wrap(Boolean.TRUE), useJavaCtx.getValue());
+      
+      // Update the use-java-context value
+      ManagedProperty minPoolSize = dsMC.getProperty("min-pool-size");
+      MetaValue oldValue = minPoolSize.getValue();
+      minPoolSize.setValue(SimpleValueSupport.wrap(1));
+      minPoolSize.setRemoved(true);
+      ManagedProperty maxPoolSize = dsMC.getProperty("max-pool-size");
+      maxPoolSize.setValue(SimpleValueSupport.wrap(999));
+      activeView.updateComponent(dsMC);
+      dsMC = getManagedComponent(mgtView, componentType, jndiName);
+      assertNotNull(dsMC);
+      minPoolSize = dsMC.getProperty("min-pool-size");
+      assertEquals(oldValue, minPoolSize.getValue());
+      maxPoolSize = dsMC.getProperty("max-pool-size");
+      assertEquals(SimpleValueSupport.wrap(999), maxPoolSize.getValue());
+      
+      // Remove the deployment
+      removeDeployment("testRemovedProperties-ds.xml");
+   }
+
+}


Property changes on: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/DataSourceUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision




More information about the jboss-cvs-commits mailing list