Skip to content

Commit

Permalink
Merge pull request #95 from rareddy/TEIID-2035
Browse files Browse the repository at this point in the history
TEIID-2035: ability add remove resource-adapter and connection factories...
  • Loading branch information
rareddy committed Aug 14, 2013
2 parents 2de854b + c336015 commit edc28f6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
63 changes: 60 additions & 3 deletions admin/src/main/java/org/teiid/adminapi/AdminFactory.java
Expand Up @@ -22,7 +22,9 @@

package org.teiid.adminapi;

import static org.jboss.as.controller.client.helpers.ClientConstants.*;
import static org.jboss.as.controller.client.helpers.ClientConstants.DEPLOYMENT_REMOVE_OPERATION;
import static org.jboss.as.controller.client.helpers.ClientConstants.DEPLOYMENT_UNDEPLOY_OPERATION;
import static org.jboss.as.controller.client.helpers.ClientConstants.RESULT;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -246,9 +248,18 @@ private void createConnectionFactory(String deploymentName, String rarName, Prop

if (!getInstalledResourceAdaptorNames().contains(rarName)) {
///subsystem=resource-adapters/resource-adapter=fileDS:add
addResourceAdapter(rarName);
addArchiveResourceAdapter(rarName);
}

//AS-4776 HACK - BEGIN
else {
// add duplicate resource adapter AS-4776 Workaround
String moduleName = getResourceAdapterModuleName(rarName);
addModuleResourceAdapter(deploymentName, moduleName);
rarName = deploymentName;
}
//AS-4776 HACK - END

BuildPropertyDefinitions bpd = new BuildPropertyDefinitions();
buildResourceAdpaterProperties(rarName, bpd);
ArrayList<PropertyDefinition> jcaSpecific = bpd.getPropertyDefinitions();
Expand Down Expand Up @@ -330,12 +341,43 @@ private void addProfileNode(DefaultOperationRequestBuilder builder) throws Admin
}

// /subsystem=resource-adapters/resource-adapter=teiid-connector-ws.rar:add(archive=teiid-connector-ws.rar, transaction-support=NoTransaction)
private void addResourceAdapter(String rarName) throws AdminException {
private void addArchiveResourceAdapter(String rarName) throws AdminException {
cliCall("add", new String[] { "subsystem", "resource-adapters",
"resource-adapter", rarName },
new String[] { "archive", rarName, "transaction-support","NoTransaction" },
new ResultCallback());
}

private void addModuleResourceAdapter(String rarName, String moduleName) throws AdminException {
cliCall("add", new String[] { "subsystem", "resource-adapters",
"resource-adapter", rarName },
new String[] { "module", moduleName, "transaction-support","NoTransaction" },
new ResultCallback());
}

private String getResourceAdapterModuleName(String rarName)
throws AdminException {
final List<String> props = new ArrayList<String>();
cliCall("read-resource",
new String[] { "subsystem", "resource-adapters", "resource-adapter", rarName},
null, new ResultCallback() {
@Override
void onSuccess(ModelNode outcome, ModelNode result) throws AdminException {
List<ModelNode> properties = outcome.get("result").asList();

for (ModelNode prop:properties) {
if (!prop.getType().equals(ModelType.PROPERTY)) {
continue;
}
org.jboss.dmr.Property p = prop.asProperty();
if (p.getName().equals("module")) {
props.add(p.getValue().asString());
}
}
}
});
return props.get(0);
}

class AbstractMetadatMapper implements MetadataMapper<String>{
@Override
Expand Down Expand Up @@ -636,6 +678,14 @@ public void deleteDataSource(String deployedName) throws AdminException {
"resource-adapters", "resource-adapter", rarName,
"connection-definitions", deployedName }, null,
new ResultCallback());

//AS-4776 HACK - BEGIN
if (getInstalledResourceAdaptorNames().contains(deployedName)) {
cliCall("remove", new String[] { "subsystem",
"resource-adapters", "resource-adapter", deployedName}, null,
new ResultCallback());
}
//AS-4776 HACK - END
}
}

Expand Down Expand Up @@ -956,6 +1006,13 @@ private Set<String> getInstalledResourceAdaptorNames() throws AdminException {
private Set<String> getResourceAdapterNames() throws AdminException {
Set<String> templates = getDeployedResourceAdaptorNames();
templates.addAll(getInstalledResourceAdaptorNames());

//AS-4776 HACK - BEGIN
Map<String, String> connFactoryMap = getConnectionFactoryNames();
for (String key:connFactoryMap.keySet()) {
templates.remove(key);
}
//AS-4776 HACK - END
return templates;
}

Expand Down
Expand Up @@ -22,7 +22,13 @@

package org.teiid.arquillian;

import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
Expand Down Expand Up @@ -437,7 +443,7 @@ public void testDataRoleMapping() throws Exception{
assertFalse(dp.isAnyAuthenticated());
}

// @Test - remove it when TEIID-2035 fixed
@Test
public void testCreateConnectionFactory() throws Exception{
String deployedName = "wsOne";

Expand Down

0 comments on commit edc28f6

Please sign in to comment.