Author: rareddy
Date: 2010-01-15 17:01:27 -0500 (Fri, 15 Jan 2010)
New Revision: 1749
Added:
branches/JCA/jboss-integration/src/test/resources/connector-loopback.rar
Modified:
branches/JCA/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
branches/JCA/jboss-integration/src/main/java/org/teiid/templates/connector/ConnectorTypeTemplateInfo.java
branches/JCA/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
Log:
TEIID-833: adding support for adding custom connector types based on RAR file added to the
system automatically
Modified:
branches/JCA/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
===================================================================
---
branches/JCA/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2010-01-15
18:29:16 UTC (rev 1748)
+++
branches/JCA/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2010-01-15
22:01:27 UTC (rev 1749)
@@ -22,6 +22,10 @@
package org.teiid.adminapi.jboss;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
@@ -30,6 +34,8 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.spi.management.deploy.DeploymentManager;
@@ -488,9 +494,9 @@
private String getRarDeployerName(String rarName) throws AdminException{
try {
- Set<String> rarDeployments =
getView().getDeploymentNamesForType("JavaEEResourceAdaptor");
+ Set<String> rarDeployments =
getView().getDeploymentNamesForType("rar");
for (String name: rarDeployments) {
- if (name.endsWith(rarName)) {
+ if (name.endsWith(rarName+"/")) {
return name;
}
}
@@ -502,12 +508,30 @@
@Override
public void addConnectorType(String connectorName, URL rarURL) throws AdminException{
+ if (!connectorName.startsWith("connector-")) {
+ throw new AdminProcessingException("Teiid connector names must start with
\"connector-\"");
+ }
+
if (!connectorName.endsWith(".rar")) {
connectorName = connectorName + ".rar";
}
+
+ String deployerName = getRarDeployerName(connectorName);
+ if (deployerName != null) {
+ throw new AdminProcessingException("A Connectory with
name:"+connectorName+" already exists!");
+ }
+
ManagedUtil.deployArchive(getDeploymentManager(), connectorName, rarURL, false);
- //TODO: also need to add a template for the properties
+ //also need to add a template for the properties
+ try {
+ String connectorNameWithoutExt = connectorName.substring(0,
connectorName.length()-4);
+ File jarFile = Admin.createConnectorTypeTemplate(connectorNameWithoutExt);
+ ManagedUtil.deployArchive(getDeploymentManager(),
connectorNameWithoutExt+"-template.jar", jarFile.toURI().toURL(), false);
+ jarFile.delete();
+ } catch (IOException e) {
+ deleteConnectorType(connectorName);
+ }
}
@Override
@@ -518,9 +542,11 @@
String deployerName = getRarDeployerName(connectorName);
if (deployerName != null) {
ManagedUtil.removeArchive(getDeploymentManager(), deployerName);
+
+ //also need to delete template for the properties
+ String connectorNameWithoutExt = connectorName.substring(0,
connectorName.length()-4);
+ ManagedUtil.removeArchive(getDeploymentManager(),
connectorNameWithoutExt+"-template.jar");
}
-
- //TODO: also need to delete template for the properties
}
@Override
@@ -721,4 +747,38 @@
public Collection<PropertyDefinition> getDataSourcePropertyDefinitions() throws
AdminException {
return getConnectorTypePropertyDefinitions(XA_DATA_SOURCE_TEMPLATE);
}
+
+ private static final String connectorTemplate =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
+ "<deployment xmlns=\"urn:jboss:bean-deployer:2.0\">\n"
+
+ "<!-- This is Teiid connector type template - DO NOT DELETE -->\n"+
+ "<bean name=\"${name}\"
class=\"org.teiid.templates.connector.ConnectorTypeTemplate\">\n" +
+ " <property name=\"info\"><inject
bean=\"${name}-templateinfo\"/></property>\n" +
+ " <property name=\"targetTemplate\"><inject
bean=\"NoTxConnectionFactoryTemplate\"/></property>\n" +
+ "</bean>\n" +
+ "<bean name=\"${name}-templateinfo\"
class=\"org.teiid.templates.connector.ConnectorTypeTemplateInfo\">\n" +
+ " <constructor
factoryMethod=\"createTemplateInfo\">\n" +
+ " <factory
bean=\"DSDeploymentTemplateInfoFactory\"/>\n" +
+ " <parameter
class=\"java.lang.Class\">org.teiid.templates.connector.ConnectorTypeTemplateInfo</parameter>\n"
+
+ " <parameter
class=\"java.lang.Class\">org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData</parameter>\n"
+
+ " <parameter
class=\"java.lang.String\">${name}</parameter>\n" +
+ " <parameter
class=\"java.lang.String\">${name}</parameter>\n"+
+ " </constructor>\n" +
+ "</bean>\n"+
+ "</deployment>";
+
+ private static File createConnectorTypeTemplate(String name) throws IOException {
+ String content = connectorTemplate.replace("${name}", name);
+
+ File jarFile = File.createTempFile(name, ".jar");
+ JarOutputStream jo = new JarOutputStream(new BufferedOutputStream(new
FileOutputStream(jarFile)));
+
+ JarEntry je = new JarEntry("META-INF/jboss-beans.xml");
+ jo.putNextEntry(je);
+
+ jo.write(content.getBytes());
+
+ jo.close();
+ return jarFile;
+ }
}
Modified:
branches/JCA/jboss-integration/src/main/java/org/teiid/templates/connector/ConnectorTypeTemplateInfo.java
===================================================================
---
branches/JCA/jboss-integration/src/main/java/org/teiid/templates/connector/ConnectorTypeTemplateInfo.java 2010-01-15
18:29:16 UTC (rev 1748)
+++
branches/JCA/jboss-integration/src/main/java/org/teiid/templates/connector/ConnectorTypeTemplateInfo.java 2010-01-15
22:01:27 UTC (rev 1749)
@@ -104,7 +104,9 @@
String description = descMetadata.getDescription();
fields.setDescription(description);
fields.setMetaType(metaType);
- fields.setField(Fields.DEFAULT_VALUE, ManagedUtil.wrap(metaType,
metadata.getValue()));
+ if (metadata.getValue() != null && metadata.getValue().trim().length() > 0)
{
+ fields.setField(Fields.DEFAULT_VALUE, ManagedUtil.wrap(metaType,
metadata.getValue()));
+ }
fields.setField(Fields.READ_ONLY, false);
ManagedPropertyImpl dsTypeMP = new ManagedPropertyImpl(fields);
addProperty(dsTypeMP);
Modified:
branches/JCA/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
===================================================================
---
branches/JCA/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java 2010-01-15
18:29:16 UTC (rev 1748)
+++
branches/JCA/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java 2010-01-15
22:01:27 UTC (rev 1749)
@@ -244,4 +244,19 @@
Collection<PropertyDefinition> defs =
admin.getDataSourcePropertyDefinitions();
System.out.println(defs);
}
+
+ @Test
+ public void testTemplate() throws Exception{
+ File f = new File(UnitTestUtil.getTestDataPath()+"/connector-loopback.rar");
+ admin.addConnectorType("connector-loopy", f.toURI().toURL());
+
+ Set<String> names = admin.getConnectorTypes();
+ assertTrue(names.contains("connector-loopy"));
+
+ }
+
+ @Test
+ public void testTemplateRemove() throws Exception{
+ admin.deleteConnectorType("connector-loopy");
+ }
}
Added: branches/JCA/jboss-integration/src/test/resources/connector-loopback.rar
===================================================================
(Binary files differ)
Property changes on:
branches/JCA/jboss-integration/src/test/resources/connector-loopback.rar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Show replies by date