[teiid-commits] teiid SVN: r3597 - in branches/as7: admin/src/main/java/org/teiid/adminapi and 6 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Nov 1 11:20:12 EDT 2011


Author: rareddy
Date: 2011-11-01 11:20:11 -0400 (Tue, 01 Nov 2011)
New Revision: 3597

Modified:
   branches/as7/admin/src/main/java/org/teiid/adminapi/AdminFactory.java
   branches/as7/admin/src/main/java/org/teiid/adminapi/impl/PropertyDefinitionMetadata.java
   branches/as7/build/kits/jboss-as7/modules/org/jboss/teiid/main/module.xml
   branches/as7/jboss-integration/pom.xml
   branches/as7/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java
   branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
   branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java
   branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
   branches/as7/pom.xml
   branches/as7/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java
Log:
TEIID-1720: Added the exposing of ra.xml properties to the Admin API

Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/AdminFactory.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/AdminFactory.java	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/AdminFactory.java	2011-11-01 15:20:11 UTC (rev 3597)
@@ -838,51 +838,51 @@
 		@Override		
 		public Collection<PropertyDefinition> getTemplatePropertyDefinitions(String templateName) throws AdminException {
 
-			boolean connectionFactory = false;
-			Set<String> resourceAdapters = getAvailableResourceAdapterNames();
-        	if (resourceAdapters.contains(templateName)) {
-        		connectionFactory = true;
-        	}
-			
-			DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
 			ModelNode request = null;
+			ModelNode result = null;
 			try {
-				if (connectionFactory) {
-		            builder.addNode("subsystem", "resource-adapters"); //$NON-NLS-1$ //$NON-NLS-2$
-		            builder.addNode("resource-adapter", templateName); //$NON-NLS-1$
-		            builder.addNode("connection-definitions", "any"); //$NON-NLS-1$
-				}
-				else {
-		            builder.addNode("subsystem", "datasources"); //$NON-NLS-1$ //$NON-NLS-2$
-		            builder.addNode("data-source", "any"); //$NON-NLS-1$	        		
-				}
+				Set<String> resourceAdapters = getAvailableResourceAdapterNames();
+	        	if (resourceAdapters.contains(templateName)) {
+	        		DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
+		            builder.addNode("subsystem", "teiid"); //$NON-NLS-1$ //$NON-NLS-2$
+		            builder.setOperationName("read-rar-description"); //$NON-NLS-1$
+		            builder.addProperty("rar-name", templateName);
+		            request = builder.buildRequest();					
+			        try {
+			            ModelNode outcome = this.connection.execute(request);
+			            if (!Util.isSuccess(outcome)) {
+			                throw new AdminProcessingException(Util.getFailureDescription(outcome));
+			            }
+			            result = outcome.get("result");
+			        } catch (IOException e) {
+			        	throw new AdminProcessingException(e);
+			        }			            
+	        	}
+	        	else {
+	        		result = new ModelNode();
+	        		result.add(buildProperty("connection-url", "connection URL", ModelType.STRING, "connection url", true));
+	        		result.add(buildProperty("user-name", "User Name", ModelType.STRING, "user name", false));
+	        		result.add(buildProperty("password", "Password", ModelType.STRING, "password", false));
+	        		result.add(buildProperty("check-valid-connection-sql", "Connection Validate SQL", ModelType.STRING, "SQL to be used to validate the connection", false));
+	        	}
 	        	
-	            builder.setOperationName("read-resource-description"); //$NON-NLS-1$
-	            request = builder.buildRequest();
 	        } catch (OperationFormatException e) {
 	            throw new IllegalStateException("Failed to build operation", e); //$NON-NLS-1$
 	        }
-        
-			ModelNode result = null;
-	        try {
-	            ModelNode outcome = this.connection.execute(request);
-	            if (!Util.isSuccess(outcome)) {
-	                throw new AdminProcessingException(Util.getFailureDescription(outcome));
-	            }
-	            result = outcome.get("result");
-	        } catch (IOException e) {
-	        	throw new AdminProcessingException(e);
-	        }	
-	        
-	        ArrayList<PropertyDefinition> propDefinitions = new ArrayList<PropertyDefinition>();
-	        List<ModelNode> propsNodes = null;
-        	if (templateName.equals("data-source") || templateName.equals("xa-data-source")) {
-        		propsNodes = result.get("attributes").asList();
-        	}
-        	else {
-        		propsNodes = result.get("connection-definitions", "attributes").asList();
-        	}	 
-        	
+	        return buildPropertyDefinitions(result.asList());
+		}
+		
+		private ModelNode buildProperty(String name, String displayName, ModelType modelType, String description, boolean required) {
+			ModelNode node = new ModelNode();
+			node.get(name, "type").set(modelType);
+	        node.get(name, "description").set(description);
+	        node.get(name, "required").set(required);
+	        node.get(name, "display").set(displayName);
+	        return node;
+		}
+
+		private ArrayList<PropertyDefinition> buildPropertyDefinitions(List<ModelNode> propsNodes) {
+			ArrayList<PropertyDefinition> propDefinitions = new ArrayList<PropertyDefinition>();
         	for (ModelNode node:propsNodes) {
         		PropertyDefinitionMetadata def = new PropertyDefinitionMetadata();
         		Set<String> keys = node.keys();
@@ -891,26 +891,44 @@
         		def.setName(name);
         		node = node.get(name);
 
+        		if (node.hasDefined("display")) {
+        			def.setDisplayName(node.get("display").asString());
+        		}
+        		
         		if (node.hasDefined("description")) {
         			def.setDescription(node.get("description").asString());
         		}
         		
+        		if (node.hasDefined("allowed")) {
+        			List<ModelNode> allowed = node.get("allowed").asList();
+        			ArrayList<String> list = new ArrayList<String>();
+        			for(ModelNode m:allowed) {
+        				list.add(m.asString());
+        			}
+        			def.setAllowedValues(list);
+        		}        		
+        		
         		if (node.hasDefined("required")) {
         			def.setRequired(node.get("required").asBoolean());
         		}
         		
-        		if (node.hasDefined("access-type")) {
-        			String access = node.get("access-type").asString();
-        			if ("read-only".equals(access)) {
-        				def.setModifiable(false);
-        			}
-        			else if ("read-write".equals(access)) {
-        				def.setModifiable(true);
-        			}
+        		if (node.hasDefined("read-only")) {
+        			String access = node.get("read-only").asString();
+        			def.setModifiable(Boolean.parseBoolean(access));
         		}
         		
+        		if (node.hasDefined("advanced")) {
+        			String access = node.get("advanced").asString();
+        			def.setAdvanced(Boolean.parseBoolean(access));
+        		}        		
+        		
+        		if (node.hasDefined("masked")) {
+        			String access = node.get("masked").asString();
+        			def.setAdvanced(Boolean.parseBoolean(access));
+        		} 
+        		
         		if (node.hasDefined("restart-required")) {
-        			def.setRequiresRestart(RestartType.CLUSTER);
+        			def.setRequiresRestart(RestartType.NONE);
         		}
 
         		String type = node.get("type").asString();
@@ -955,7 +973,7 @@
         		}
         		propDefinitions.add(def);
         	}
-        	return propDefinitions;
+			return propDefinitions;
 		}
 
 		@Override

Modified: branches/as7/admin/src/main/java/org/teiid/adminapi/impl/PropertyDefinitionMetadata.java
===================================================================
--- branches/as7/admin/src/main/java/org/teiid/adminapi/impl/PropertyDefinitionMetadata.java	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/admin/src/main/java/org/teiid/adminapi/impl/PropertyDefinitionMetadata.java	2011-11-01 15:20:11 UTC (rev 3597)
@@ -50,6 +50,7 @@
     public String toString() {
         StringBuffer result = new StringBuffer();
         result.append("Display Name:").append(getDisplayName()); //$NON-NLS-1$
+        result.append(" Name:").append(getName()); //$NON-NLS-1$
         result.append(" Description:").append(getDescription()); //$NON-NLS-1$
         result.append(" Property Type Classname:").append(getPropertyTypeClassName()); //$NON-NLS-1$
         result.append(" Default Value:").append(getDefaultValue()); //$NON-NLS-1$

Modified: branches/as7/build/kits/jboss-as7/modules/org/jboss/teiid/main/module.xml
===================================================================
--- branches/as7/build/kits/jboss-as7/modules/org/jboss/teiid/main/module.xml	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/build/kits/jboss-as7/modules/org/jboss/teiid/main/module.xml	2011-11-01 15:20:11 UTC (rev 3597)
@@ -41,6 +41,10 @@
         <module name="javax.transaction.api"/>
         <module name="javax.activation.api"/>
         <module name="org.jboss.as.clustering.jgroups"/>
+        <!-- These dependencies here for ra.xml description -->
+        <module name="org.jboss.as.connector"/>
+        <module name="org.jboss.ironjacamar.api"/>
+        <module name="org.jboss.ironjacamar.impl"/>
     </dependencies>
 
 </module>
\ No newline at end of file

Modified: branches/as7/jboss-integration/pom.xml
===================================================================
--- branches/as7/jboss-integration/pom.xml	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/jboss-integration/pom.xml	2011-11-01 15:20:11 UTC (rev 3597)
@@ -99,6 +99,12 @@
     
     <dependency>
         <groupId>org.jboss.as</groupId>
+        <artifactId>jboss-as-connector</artifactId>
+        <scope>provided</scope>
+    </dependency>    
+    
+    <dependency>
+        <groupId>org.jboss.as</groupId>
         <artifactId>jboss-as-subsystem-test</artifactId>
         <scope>test</scope>
     </dependency>    

Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java	2011-11-01 15:20:11 UTC (rev 3597)
@@ -34,6 +34,7 @@
 	public static final String MODEL_NAME = "model-name"; //$NON-NLS-1$
 	public static final String SOURCE_NAME = "source-name"; //$NON-NLS-1$
 	public static final String DS_NAME = "ds-name"; //$NON-NLS-1$
+	public static final String RAR_NAME = "rar-name"; //$NON-NLS-1$
 	
 	public static final String SOURCE_VDBNAME = "source-vdb-name";//$NON-NLS-1$
 	public static final String SOURCE_VDBVERSION = "source-vdb-version";//$NON-NLS-1$

Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java	2011-11-01 15:20:11 UTC (rev 3597)
@@ -140,6 +140,7 @@
 		new TerminateTransaction().register(teiidSubsystem);
 		new ExecuteQuery().register(teiidSubsystem);
 		new MarkDataSourceAvailable().register(teiidSubsystem);
+		new ReadRARDescription().register(teiidSubsystem);
 	}
 
 	@Override

Modified: branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java
===================================================================
--- branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java	2011-11-01 15:20:11 UTC (rev 3597)
@@ -21,7 +21,10 @@
  */
 package org.teiid.jboss;
 
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOWED;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEFAULT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ONLY;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REPLY_PROPERTIES;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUEST_PROPERTIES;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUIRED;
@@ -45,11 +48,17 @@
 
 import javax.xml.stream.XMLStreamException;
 
+import org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor;
 import org.jboss.as.controller.OperationContext;
 import org.jboss.as.controller.OperationFailedException;
 import org.jboss.as.controller.PathAddress;
+import org.jboss.as.server.deployment.DeploymentUnit;
 import org.jboss.dmr.ModelNode;
 import org.jboss.dmr.ModelType;
+import org.jboss.jca.common.api.metadata.ra.ConfigProperty;
+import org.jboss.jca.common.api.metadata.ra.ConnectionDefinition;
+import org.jboss.jca.common.api.metadata.ra.ResourceAdapter;
+import org.jboss.jca.common.api.metadata.ra.ResourceAdapter1516;
 import org.jboss.msc.service.ServiceController;
 import org.jboss.msc.service.ServiceName;
 import org.teiid.adminapi.Admin;
@@ -63,6 +72,7 @@
 import org.teiid.client.security.SessionToken;
 import org.teiid.client.util.ResultsFuture;
 import org.teiid.core.TeiidComponentException;
+import org.teiid.deployers.ExtendedPropertyMetadata;
 import org.teiid.deployers.VDBRepository;
 import org.teiid.deployers.VDBStatusChecker;
 import org.teiid.dqp.internal.datamgr.TranslatorRepository;
@@ -1206,4 +1216,94 @@
 		operationNode.get(REQUEST_PROPERTIES, OperationsConstants.DS_NAME, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.DS_NAME));
 		
 	}		
+}
+
+class ReadRARDescription extends TeiidOperationHandler {
+	
+	protected ReadRARDescription() {
+		super("read-rar-description"); //$NON-NLS-1$
+	}
+	@Override
+	protected void executeOperation(OperationContext context, DQPCore engine, ModelNode operation) throws OperationFailedException {
+		ModelNode result = context.getResult();
+		
+		if (!operation.hasDefined(OperationsConstants.RAR_NAME)) {
+			throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.RAR_NAME+MISSING)));
+		}
+		String rarName = operation.get(OperationsConstants.RAR_NAME).asString();
+				
+		ServiceName svcName = ServiceName.JBOSS.append("deployment", "unit").append(rarName); //$NON-NLS-1$ //$NON-NLS-2$
+		ServiceController<?> sc = context.getServiceRegistry(false).getService(svcName);
+		DeploymentUnit du = DeploymentUnit.class.cast(sc.getValue());
+		ConnectorXmlDescriptor cd = du.getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY);
+		ResourceAdapter ra = cd.getConnector().getResourceadapter();
+		if (ra instanceof ResourceAdapter1516) {
+			ResourceAdapter1516 ra1516 = (ResourceAdapter1516)ra;
+			List<ConnectionDefinition> connDefinitions = ra1516.getOutboundResourceadapter().getConnectionDefinitions();
+			for (ConnectionDefinition p:connDefinitions) {
+				List<? extends ConfigProperty> props = p.getConfigProperties();
+				for (ConfigProperty prop:props) {
+					result.add(buildNode(prop));
+				}
+			}
+		}
+	}
+	private ModelNode buildNode(ConfigProperty prop) {
+		ModelNode node = new ModelNode();
+		String name = prop.getConfigPropertyName().getValue();
+		String type = prop.getConfigPropertyType().getValue();
+		
+		String defaltValue = null;
+		if (prop.getConfigPropertyValue() != null) {
+			defaltValue = prop.getConfigPropertyValue().getValue();
+		}
+		
+		String description = null;
+		if (prop.getDescriptions() != null) {
+			description = prop.getDescriptions().get(0).getValue();
+		}
+		
+		ExtendedPropertyMetadata extended = new ExtendedPropertyMetadata(name, type, description, defaltValue);
+		
+		if ("java.lang.String".equals(type)) { //$NON-NLS-1$
+			node.get(name, TYPE).set(ModelType.STRING);
+		}
+		else if ("java.lang.Integer".equals(type)) { //$NON-NLS-1$
+			node.get(name, TYPE).set(ModelType.INT);
+		}
+		else if ("java.lang.Long".equals(type)) { //$NON-NLS-1$
+			node.get(name, TYPE).set(ModelType.LONG);
+		}
+		else if ("java.lang.Boolean".equals(type)) { //$NON-NLS-1$
+			node.get(name, TYPE).set(ModelType.BOOLEAN);
+		}		
+		
+		node.get(name, REQUIRED).set(extended.required());
+		
+		if (extended.description() != null) {
+			node.get(name, DESCRIPTION).set(extended.description());
+		}
+		node.get(name, "display").set(extended.display()); //$NON-NLS-1$
+        node.get(name, READ_ONLY).set(extended.readOnly());
+        node.get(name, "advanced").set(extended.advanced()); //$NON-NLS-1$
+        
+        if (extended.allowed() != null) {
+        	for (String s:extended.allowed()) {
+        		node.get(name, ALLOWED).add(s);
+        	}
+        }
+        
+        node.get(name, "masked").set(extended.masked()); //$NON-NLS-1$
+        
+        if (extended.defaultValue() != null) {
+        	node.get(name, DEFAULT).set(extended.defaultValue());
+        }
+		return node;
+	}
+	
+	protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+		operationNode.get(REQUEST_PROPERTIES, OperationsConstants.RAR_NAME, TYPE).set(ModelType.STRING);
+		operationNode.get(REQUEST_PROPERTIES, OperationsConstants.RAR_NAME, REQUIRED).set(true);
+		operationNode.get(REQUEST_PROPERTIES, OperationsConstants.RAR_NAME, DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.RAR_NAME));		
+	}		
 }
\ No newline at end of file

Modified: branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties	2011-11-01 15:20:11 UTC (rev 3597)
@@ -195,10 +195,9 @@
 ds-name.missing=Parameter "ds-name" is required
 model-name.missing=Parameter "model-name" is required
 connection-type.missing = Parameter "connection-type" is required. Must be one of [NONE, BY_VERSION, ANY]
+rar-name.missing=Parameter "rar-name" is is required.
 
 
-
-
 # Operation descriptions (alpha layout)
 add-anyauthenticated-role.describe=Mark any authenticated to the datarole
 add-anyauthenticated-role.vdb-name.describe=VDB Name
@@ -302,4 +301,7 @@
 terminate-transaction.describe=Terminate the XA transaction
 terminate-transaction.xid.describe=xid identifier of the XA transaction
 
-workerpool-statistics.describe=Get thread statistics worker pool
\ No newline at end of file
+workerpool-statistics.describe=Get thread statistics worker pool
+
+read-rar-description.describe=Describe the properties of the Resource Adapter
+read-rar-description.rar-name.describe=resource adapter name
\ No newline at end of file

Modified: branches/as7/pom.xml
===================================================================
--- branches/as7/pom.xml	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/pom.xml	2011-11-01 15:20:11 UTC (rev 3597)
@@ -460,9 +460,14 @@
               <groupId>org.jboss.as</groupId>
               <artifactId>jboss-as-clustering-jgroups</artifactId>
               <version>${jbossas-version}</version>
-            </dependency>    
+            </dependency> 
             <dependency>
                 <groupId>org.jboss.as</groupId>
+                <artifactId>jboss-as-connector</artifactId>
+                <version>${jbossas-version}</version>
+            </dependency>                
+            <dependency>
+                <groupId>org.jboss.as</groupId>
                 <artifactId>jboss-as-subsystem-test</artifactId>
                 <version>${jbossas-version}</version>
             </dependency>                                

Modified: branches/as7/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java
===================================================================
--- branches/as7/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java	2011-10-31 20:16:17 UTC (rev 3596)
+++ branches/as7/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java	2011-11-01 15:20:11 UTC (rev 3597)
@@ -150,7 +150,7 @@
 		return masked;
 	}
 	public boolean readOnly() {
-		return editable;
+		return !editable;
 	}
 	public boolean required() {
 		return required;



More information about the teiid-commits mailing list