diff --git a/connectors/connector-infinispan/pom.xml b/connectors/connector-infinispan/pom.xml new file mode 100644 index 0000000000..88db031b51 --- /dev/null +++ b/connectors/connector-infinispan/pom.xml @@ -0,0 +1,113 @@ + + + + connectors + org.jboss.teiid + 8.2.0.Beta1-SNAPSHOT + + 4.0.0 + connector-infinispan + org.jboss.teiid.connectors + rar + Infinispan Connector + This connector creates the connection to the Infinispan Cache + + 5.1.2.FINAL + + + + + org.jboss.teiid + teiid-api + provided + + + org.jboss.teiid + teiid-common-core + provided + + + org.jboss.teiid.connectors + translator-object + ${project.version} + provided + + + + javax.resource + connector-api + 1.5 + provided + + + + org.infinispan + infinispan-core + ${version.infinispan} + + + org.infinispan + infinispan-client-hotrod + ${version.infinispan} + + + + org.infinispan + infinispan-server-hotrod + ${version.org.infinispan} + test + + + + org.jboss.marshalling + jboss-marshalling-river + test + + + + org.jgroups + jgroups + test + + + + junit + junit + 4.4 + test + + + + + + + maven-jar-plugin + + + build_jar + process-classes + + jar + + + + src/main/rar/META-INF/MANIFEST.MF + + + + + deploy_jar + package + + jar + + + lib + + + + + + + + diff --git a/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanConnectionImpl.java b/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanConnectionImpl.java new file mode 100644 index 0000000000..1c36b02385 --- /dev/null +++ b/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanConnectionImpl.java @@ -0,0 +1,103 @@ +/* + * JBoss, Home of Professional Open Source. + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ + +package org.teiid.resource.adapter.infinispan; + +import java.util.Map; + +import org.teiid.logging.LogConstants; +import org.teiid.logging.LogManager; +import org.teiid.resource.spi.BasicConnection; +import org.teiid.translator.TranslatorException; +import org.teiid.translator.object.ObjectConnection; + + +/** + * Represents a connection to an Infinispan cache. + */ +public class InfinispanConnectionImpl extends BasicConnection implements ObjectConnection { + + private InfinispanManagedConnectionFactory config; + + public InfinispanConnectionImpl(InfinispanManagedConnectionFactory config) { + this.config = config; + + LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Infinispan Connection has been newly created."); //$NON-NLS-1$ + } + + /** + * Close the connection, if a connection requires closing. + * (non-Javadoc) + */ + @Override + public void close() { + config = null; + } + + /** + * Will return true if the CacheContainer has been started. + * @return boolean true if CacheContainer has been started + */ + public boolean isAlive() { + boolean alive = (config == null ? false : config.getCacheManager() != null); + LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Infinispan Cache Connection is alive: " + alive); //$NON-NLS-1$ + return (alive); + } + + @Override + public Map getMap(String name) throws TranslatorException { + Map m = null; + LogManager + .logTrace(LogConstants.CTX_CONNECTOR, "=== GetMap : " + name + "==="); //$NON-NLS-1$ + + m = config.getCacheManager().getCache(); + + if (name == null) { + m = config.getCacheManager().getCache(); + } else { + m = config.getCacheManager().getCache(name); + } + + if (m == null) { + final String msg = InfinispanPlugin.Util.getString("InfinispanConnection.cacheNotDefined", (name != null ? name : "Default") ); //$NON-NLS-1$ + throw new TranslatorException(msg); + } + + return m; + } + + @Override + public Class getType(String name) throws TranslatorException { + LogManager + .logTrace(LogConstants.CTX_CONNECTOR, + "=== GetType : " + name + "==="); //$NON-NLS-1$ + + Class type = config.getCacheType(name); + if (type != null) { + return type; + } + final String msg = InfinispanPlugin.Util.getString("InfinispanConnection.typeNotFound", (name != null ? name : "Default") ); //$NON-NLS-1$ + throw new TranslatorException(msg); + } + + +} diff --git a/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanManagedConnectionFactory.java b/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanManagedConnectionFactory.java new file mode 100644 index 0000000000..80bf799a0b --- /dev/null +++ b/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanManagedConnectionFactory.java @@ -0,0 +1,379 @@ +/* + * JBoss, Home of Professional Open Source. + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ +package org.teiid.resource.adapter.infinispan; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.resource.ResourceException; +import javax.resource.spi.InvalidPropertyException; + +import org.infinispan.Cache; +import org.infinispan.api.BasicCacheContainer; +import org.infinispan.client.hotrod.RemoteCacheManager; +import org.infinispan.manager.CacheContainer; +import org.infinispan.manager.DefaultCacheManager; +import org.teiid.core.TeiidRuntimeException; +import org.teiid.core.util.PropertiesUtils; +import org.teiid.core.util.StringUtil; +import org.teiid.logging.LogConstants; +import org.teiid.logging.LogManager; +import org.teiid.resource.spi.BasicConnectionFactory; +import org.teiid.resource.spi.BasicManagedConnectionFactory; + + +public class InfinispanManagedConnectionFactory extends BasicManagedConnectionFactory { + + private static final long serialVersionUID = -9153717006234080627L; + private String remoteServerList=null; + private String configurationFileNameForLocalCache = null; + private String hotrodClientPropertiesFile = null; + private String cacheJndiName=null; + @SuppressWarnings("rawtypes") + private Map typeMap = null; + private String cacheTypes = null; + private BasicCacheContainer cacheContainer = null; + + + @Override + public BasicConnectionFactory createConnectionFactory() throws ResourceException { + if (this.cacheTypes == null) { + throw new InvalidPropertyException(InfinispanPlugin.Util.getString("InfinispanManagedConnectionFactory.cacheTypeMapNotSet")); //$NON-NLS-1$ + } + + if (remoteServerList == null && + configurationFileNameForLocalCache == null && + hotrodClientPropertiesFile == null && + cacheJndiName == null) { + throw new InvalidPropertyException(InfinispanPlugin.Util.getString("InfinispanManagedConnectionFactory.invalidServerConfiguration")); //$NON-NLS-1$ + + } + + createCacheContainer(); + + return new BasicConnectionFactory() { + + private static final long serialVersionUID = 2579916624625349535L; + + @Override + public InfinispanConnectionImpl getConnection() throws ResourceException { + return new InfinispanConnectionImpl(InfinispanManagedConnectionFactory.this); + } + }; + } + + /** + * Get the cacheName:ClassName[;cacheName:ClassName...] cache type mappings. + * + * @return cacheName:ClassName[;cacheName:ClassName...] cache type mappings + * @see #setCacheTypeMap(String) + */ + public String getCacheTypeMap() { + return cacheTypes; + } + + /** + * Set the cache type mapping cacheName:ClassName[;cacheName:ClassName...] that represent + * the root node class type for 1 or more caches available for access. + * + * @param cacheTypeMap + * the cache type mappings passed in the form of cacheName:ClassName[;cacheName:ClassName...] + * @see #getCacheTypeMap() + */ + @SuppressWarnings("rawtypes") + public void setCacheTypeMap( + String cacheTypeMap) { + if (this.cacheTypes == cacheTypeMap + || this.cacheTypes != null + && this.cacheTypes.equals(cacheTypeMap)) + return; // unchanged + this.cacheTypes = cacheTypeMap; + + List types = StringUtil.getTokens(this.cacheTypes, ","); + typeMap = new HashMap(types.size()); + for(String type : types) { + final List mapped = StringUtil.getTokens(type, ":"); + final String cacheName = mapped.get(0); + final String className = mapped.get(1); + + try { + typeMap.put(cacheName, Class.forName(className)); + } catch (ClassNotFoundException e) { + throw new TeiidRuntimeException("Class hasn't been added to the classpath: "+ e.getMessage());//$NON-NLS-1$ + } + + } + } + + + public Class getCacheType(String cacheName) { + return typeMap.get(cacheName); + } + + /** + * Returns the host:port[;host:port...] list that identifies the remote servers + * to include in this cluster; + * @return host:port[;host:port...] list + */ + public String getRemoteServerList() { + return remoteServerList; + } + + /** + * Set the list of remote servers that make up the Infinispan cluster. The servers must be Infinispan HotRod servers. The list + * must be in the appropriate format of host:port[;host:port...] that would be used when defining an Infinispan + * {@link RemoteCacheManager} instance. If the value is missing, localhost:11311 is assumed. + * + * @param remoteServerList the server list in appropriate server:port;server2:port2 format. + */ + public void setRemoteServerList( String remoteServerList ) { + if (this.remoteServerList == remoteServerList || this.remoteServerList != null + && this.remoteServerList.equals(remoteServerList)) return; // unchanged + this.remoteServerList = remoteServerList; + } + + /** + * Get the name of the configuration resource or file that should be used to + * configure a local {@link CacheContainer} using {@link DefaultCacheManager}. + * + * @return the name of the resource or file configuration that should be + * passed to the {@link CacheContainer} + * @see #setConfigurationFileNameForLocalCache(String) + */ + public String getConfigurationFileNameForLocalCache() { + return configurationFileNameForLocalCache; + } + + /** + * Set the name of the configuration that should be used to configure a + * local {@link Cache cache} using the {@link DefaultCacheManager}. + * + * @param configurationFileName + * the name of the configuration file that should be used to load + * the {@link CacheContainer} + * @see #getConfigurationFileNameForLocalCache() + */ + public void setConfigurationFileNameForLocalCache( + String configurationFileName) { + if (this.configurationFileNameForLocalCache == configurationFileName + || this.configurationFileNameForLocalCache != null + && this.configurationFileNameForLocalCache.equals(configurationFileName)) + return; // unchanged + this.configurationFileNameForLocalCache = configurationFileName; + } + + /** + * Get the name of the HotRod client properties file that should be used to + * configure a RemoteCacheManager remoteCacheManager. + * + * @return the name of the HotRod client properties file to be + * used to configure {@link RemoteCacheContainer} + * @see #setHotRodClientPropertiesFile(String) + */ + public String getHotRodClientPropertiesFile() { + return hotrodClientPropertiesFile; + } + + /** + * Set the name of the HotRod client properties file that should be used to configure a + * {@link RemoteCacheManager remoteCacheManager}. + * + * @param propertieFileName + * the name of the HotRod client properties file that should be used to configure + * the {@link RemoteCacheContainer remote} container. + * @see #getHotRodClientPropertiesFile() + */ + public void setHotRodClientPropertiesFile( + String propertieFileName) { + if (this.hotrodClientPropertiesFile == propertieFileName + || this.hotrodClientPropertiesFile != null + && this.hotrodClientPropertiesFile.equals(propertieFileName)) + return; // unchanged + this.hotrodClientPropertiesFile = propertieFileName; + } + + /** + * Get the JNDI Name of the cache. + * @return JNDI Name of cache + */ + public String getCacheJndiName() { + return cacheJndiName; + } + + /** + * Set the JNDI name to a {@link Map cache} instance that should be used as this source. + * + * @param jndiName the JNDI name of the {@link Map cache} instance that should be used + * @see #setCacheJndiName(String) + */ + public void setCacheJndiName( String jndiName ) { + this.cacheJndiName = jndiName; + } + + + + protected BasicCacheContainer getCacheManager() { + return this.cacheContainer; + } + + + protected void createCacheContainer() throws ResourceException { + this.cacheContainer=this.getLocalCacheContainer(); + if (this.cacheContainer == null) { + this.cacheContainer= createRemoteCacheContainer(); + } + } + + private RemoteCacheManager createRemoteCacheContainer() throws ResourceException { + + RemoteCacheManager container = null; + if (this.getHotRodClientPropertiesFile() != null) { + File f = new File(this.getHotRodClientPropertiesFile()); + if (! f.exists()) { + throw new InvalidPropertyException(InfinispanPlugin.Util.getString("InfinispanManagedConnectionFactory.clientPropertiesFileDoesNotExist", this.getHotRodClientPropertiesFile())); //$NON-NLS-1$ + + } + try { + Properties props = PropertiesUtils.load(f.getAbsolutePath()); + container = new RemoteCacheManager(props); + container.start(); + container.getCache(); + } catch (MalformedURLException e) { + throw new ResourceException(e); + } catch (IOException e) { + throw new ResourceException(e); + } + + LogManager + .logInfo(LogConstants.CTX_CONNECTOR, + "=== Using RemoteCacheManager (loaded by configuration) ==="); //$NON-NLS-1$ + + } else { + if (this.getRemoteServerList() != null + || !this.getRemoteServerList().isEmpty()) { //$NON-NLS-1$ + + Properties props = new Properties(); + props.put("infinispan.client.hotrod.server_list", this.getRemoteServerList()); + container = new RemoteCacheManager(props); + container.start(); + LogManager + .logInfo(LogConstants.CTX_CONNECTOR, + "=== Using RemoteCacheManager (loaded by serverlist) ==="); //$NON-NLS-1$ + } + } + + return container; + } + protected BasicCacheContainer getLocalCacheContainer() throws ResourceException { + + Object cache = null; + if (this.getConfigurationFileNameForLocalCache() != null) { + + DefaultCacheManager container; + try { + container = new DefaultCacheManager( + this.getConfigurationFileNameForLocalCache()); + } catch (IOException e) { + throw new ResourceException(e); + } + LogManager + .logInfo(LogConstants.CTX_CONNECTOR, + "=== Using DefaultCacheManager (loaded by configuration) ==="); //$NON-NLS-1$ + return container; + + } + + String jndiName = getCacheJndiName(); + if (jndiName != null && jndiName.trim().length() != 0) { + try { + Context context = null; + try { + context = new InitialContext(); + } catch (NamingException err) { + throw new ResourceException(err); + } + cache = context.lookup(jndiName); + + if (cache == null) { + throw new ResourceException("Unable to find cache using JNDI: " + jndiName); //$NON-NLS-1$ + } + + LogManager + .logInfo(LogConstants.CTX_CONNECTOR, + "=== Using CacheContainer (obtained by JNDI: " + jndiName + " ==="); //$NON-NLS-1$ + + + return (BasicCacheContainer) cache; + } catch (Exception err) { + if (err instanceof RuntimeException) throw (RuntimeException)err; + throw new ResourceException(err); + } + } + return null; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((remoteServerList == null) ? 0 : remoteServerList.hashCode()); + result = prime * result + ((configurationFileNameForLocalCache == null) ? 0 : configurationFileNameForLocalCache.hashCode()); + result = prime * result + ((hotrodClientPropertiesFile == null) ? 0 : hotrodClientPropertiesFile.hashCode()); + result = prime * result + ((cacheJndiName == null) ? 0 : cacheJndiName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + InfinispanManagedConnectionFactory other = (InfinispanManagedConnectionFactory) obj; + + if (!checkEquals(this.remoteServerList, other.remoteServerList)) { + return false; + } + if (!checkEquals(this.configurationFileNameForLocalCache, other.configurationFileNameForLocalCache)) { + return false; + } + if (!checkEquals(this.hotrodClientPropertiesFile, other.hotrodClientPropertiesFile)) { + return false; + } + if (!checkEquals(this.cacheJndiName, other.cacheJndiName)) { + return false; + } + return false; + + } + +} diff --git a/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanPlugin.java b/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanPlugin.java new file mode 100644 index 0000000000..bdb9d12bbb --- /dev/null +++ b/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanPlugin.java @@ -0,0 +1,41 @@ +/* + * JBoss, Home of Professional Open Source. + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ +package org.teiid.resource.adapter.infinispan; + +import java.util.ResourceBundle; + +import org.teiid.core.BundleUtil; + + +/** + * LDAPPlugin + */ +public class InfinispanPlugin { + + public static final String PLUGIN_ID = InfinispanPlugin.class.getPackage().getName(); + + /** + * Provides access to the plugin's log and to it's resources. + */ + public static final BundleUtil Util = new BundleUtil(PLUGIN_ID, PLUGIN_ID + ".i18n", ResourceBundle.getBundle(PLUGIN_ID + ".i18n")); //$NON-NLS-1$ //$NON-NLS-2$ + +} diff --git a/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanResourceAdapter.java b/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanResourceAdapter.java new file mode 100644 index 0000000000..8f608c50e9 --- /dev/null +++ b/connectors/connector-infinispan/src/main/java/org/teiid/resource/adapter/infinispan/InfinispanResourceAdapter.java @@ -0,0 +1,43 @@ +/* + * JBoss, Home of Professional Open Source. + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ +package org.teiid.resource.adapter.infinispan; + +import org.teiid.resource.spi.BasicResourceAdapter; + +public class InfinispanResourceAdapter extends BasicResourceAdapter { + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + return true; + } +} diff --git a/connectors/connector-infinispan/src/main/rar/META-INF/MANIFEST.MF b/connectors/connector-infinispan/src/main/rar/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..ef8c55ace4 --- /dev/null +++ b/connectors/connector-infinispan/src/main/rar/META-INF/MANIFEST.MF @@ -0,0 +1 @@ +Dependencies: org.jboss.teiid.common-core,org.jboss.teiid.api,javax.api,org.jboss.teiid.translator.object,org.jboss.teiid.translator.object.jars,org.infinispan.client.hotrod,org.infinispan.cachestore.remote diff --git a/connectors/connector-infinispan/src/main/rar/META-INF/ra.xml b/connectors/connector-infinispan/src/main/rar/META-INF/ra.xml new file mode 100644 index 0000000000..3e61f20ac3 --- /dev/null +++ b/connectors/connector-infinispan/src/main/rar/META-INF/ra.xml @@ -0,0 +1,86 @@ + + + + + Red Hat Middleware LLC + Teiid Infinispan Resource Adapter + 1.0 + + + JBoss, Home of Professional Open Source. + Copyright 2006, 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. + + true + + + org.teiid.resource.adapter.infinispan.InfinispanResourceAdapter + + + + org.teiid.resource.adapter.infinispan.InfinispanManagedConnectionFactory + + + {$display:"Cache Type Mapping",$description:"Cache Type Map(cacheName:className[;cacheName:className...])",$required="true"} + CacheTypeMap + java.lang.String + + + + {$display:"Server List",$description:"Server List (host:port[;host:port...]) to connect to"} + RemoteServerList + java.lang.String + + + + {$display:"Config File for Local Cache",$description:"Infinispan Configuration File for configuring local cache"} + ConfigurationFileNameForLocalCache + java.lang.String + + + + {$display:"HotRod Client Properties File",$description:"HotRod Client properties file for configuring connection to remote cache"} + HotRodClientPropertiesFile + java.lang.String + + + + {$display:"Cache JndiName",$description:"JNDI Name to find CacheContainer"} + CacheJndiName + java.lang.String + + + + javax.resource.cci.ConnectionFactory + org.teiid.resource.adapter.custom.spi.WrappedConnectionFactory + javax.resource.cci.Connection + org.teiid.resource.adapter.custom.spi.WrappedConnection + + + + NoTransaction + + + BasicPassword + javax.resource.spi.security.PasswordCredential + + false + + + diff --git a/connectors/connector-infinispan/src/main/resources/org/teiid/resource/adapter/infinispan/i18n.properties b/connectors/connector-infinispan/src/main/resources/org/teiid/resource/adapter/infinispan/i18n.properties new file mode 100644 index 0000000000..635e464992 --- /dev/null +++ b/connectors/connector-infinispan/src/main/resources/org/teiid/resource/adapter/infinispan/i18n.properties @@ -0,0 +1,28 @@ +# +# JBoss, Home of Professional Open Source. +# See the COPYRIGHT.txt file distributed with this work for information +# regarding copyright ownership. Some portions may be licensed +# to Red Hat, Inc. under one or more contributor license agreements. +# +# This library 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 library 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 library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 USA. +# + +InfinispanManagedConnectionFactory.cacheTypeMapNotSet=CacheTypeMap has not been set +InfinispanManagedConnectionFactory.invalidServerConfiguration=Must set configuration as to how the cache will be obtained (i.e., configuration, jndi or server list) +InfinispanManagedConnectionFactory.clientPropertiesFileDoesNotExist=HotRod client properties file {0} does not exist + +InfinispanConnection.cacheNotDefined={0} cache was not defined, see CacheTypeMap setting +InfinispanConnection.typeNotFound=Unable to determine class type in cache {0} diff --git a/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/RemoteInfinispanTestHelper.java b/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/RemoteInfinispanTestHelper.java new file mode 100644 index 0000000000..bc8e866d8c --- /dev/null +++ b/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/RemoteInfinispanTestHelper.java @@ -0,0 +1,107 @@ +/* + * JBoss, Home of Professional Open Source. + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ +package org.teiid.resource.adapter.infinispan; + +import java.io.IOException; +import java.net.InetAddress; +import java.util.Properties; + +import org.infinispan.manager.DefaultCacheManager; +import org.infinispan.server.core.Main; +import org.infinispan.server.hotrod.HotRodServer; + +/** + */ +public class RemoteInfinispanTestHelper { + protected static final String CACHE_NAME = "test"; //$NON-NLS-1$ + protected static final int PORT = 11311; + protected static final int TIMEOUT = 0; + protected static final String CONFIG_FILE = "src/test/resources/infinispan_remote_config.xml"; + + private static HotRodServer server = null; + private static int count = 0; + private static DefaultCacheManager CACHEMANAGER = null; + + public static synchronized HotRodServer createServer() throws IOException { + count++; + if (server == null) { + CACHEMANAGER = new DefaultCacheManager(CONFIG_FILE); + + CACHEMANAGER.start(); + // This doesn't work on IPv6, because the util assumes "127.0.0.1" ... + // server = HotRodTestingUtil.startHotRodServer(cacheManager, HOST, PORT); + + server = new HotRodServer(); + String hostAddress = hostAddress(); + String hostPort = Integer.toString(hostPort()); + String timeoutStr = Integer.toString(TIMEOUT); + Properties props = new Properties(); + props.setProperty(Main.PROP_KEY_HOST(), hostAddress); + props.setProperty(Main.PROP_KEY_PORT(), hostPort); + props.setProperty(Main.PROP_KEY_IDLE_TIMEOUT(), timeoutStr); + props.setProperty(Main.PROP_KEY_PROXY_HOST(), hostAddress); + props.setProperty(Main.PROP_KEY_PROXY_PORT(), hostPort); + // System.out.println("Starting HotRot Server at " + hostAddress + ":" + hostPort); + server.start(props, CACHEMANAGER); + + server.cacheManager().startCaches(CACHE_NAME); + + server.getCacheManager().getCache(CACHE_NAME).put("1", new String("value1")); //$NON-NLS-1$ //$NON-NLS-2$ + server.getCacheManager().getCache(CACHE_NAME).put("2", new String("value2")); //$NON-NLS-1$ //$NON-NLS-2$ + + } + return server; + } + + public static DefaultCacheManager getCacheManager() { + return CACHEMANAGER; + } + + public static int hostPort() { + return PORT; + } + + /** + * Return the IP address of this host, in either IPv4 or IPv6 format. + * + * @return the IP address as a string + */ + public static String hostAddress() { + try { + return InetAddress.getLocalHost().getHostAddress(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static synchronized void releaseServer() { + --count; + if (count <= 0) { + try { + // System.out.println("Stopping HotRot Server at " + hostAddress() + ":" + hostPort()); + server.stop(); + } finally { + server = null; + } + } + } +} diff --git a/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/TestInfinispanConfigFileLocalCache.java b/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/TestInfinispanConfigFileLocalCache.java new file mode 100644 index 0000000000..4f2a20c981 --- /dev/null +++ b/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/TestInfinispanConfigFileLocalCache.java @@ -0,0 +1,65 @@ +/* + * JBoss, Home of Professional Open Source. + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ +package org.teiid.resource.adapter.infinispan; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Map; + +import java.lang.Long; +import org.junit.BeforeClass; +import org.junit.Test; +import org.teiid.translator.object.ObjectConnection; + +@SuppressWarnings("nls") +public class TestInfinispanConfigFileLocalCache { + + private static InfinispanManagedConnectionFactory factory = null; + + @BeforeClass + public static void beforeEachClass() throws Exception { + + factory = new InfinispanManagedConnectionFactory(); + + factory.setConfigurationFileNameForLocalCache("./src/test/resources/infinispan_persistent_config.xml"); + factory.setCacheTypeMap(RemoteInfinispanTestHelper.CACHE_NAME + ":" + "java.lang.Long"); + + // initialize container and cache + factory.createCacheContainer(); + factory.getCacheManager().getCache(RemoteInfinispanTestHelper.CACHE_NAME).put("1", new Long(12345678)); + + } + + @Test + public void testConnection() throws Exception { + + ObjectConnection conn = factory.createConnectionFactory().getConnection(); + Map m = conn.getMap(RemoteInfinispanTestHelper.CACHE_NAME); + + assertNotNull(m); + + Class t = conn.getType(RemoteInfinispanTestHelper.CACHE_NAME); + + assertEquals(Long.class, t); + } +} diff --git a/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/TestInfinispanConfigFileRemoteCache.java b/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/TestInfinispanConfigFileRemoteCache.java new file mode 100644 index 0000000000..bd3d6d6e4d --- /dev/null +++ b/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/TestInfinispanConfigFileRemoteCache.java @@ -0,0 +1,82 @@ +/* + * JBoss, Home of Professional Open Source. + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ +package org.teiid.resource.adapter.infinispan; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.util.Map; +import java.util.Properties; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.teiid.core.util.PropertiesUtils; +import org.teiid.translator.object.ObjectConnection; + +@SuppressWarnings("nls") +public class TestInfinispanConfigFileRemoteCache { + + private static InfinispanManagedConnectionFactory factory = null; + + + @BeforeClass + public static void beforeEachClass() throws Exception { + RemoteInfinispanTestHelper.createServer(); + + System.out.println("Hostaddress " + RemoteInfinispanTestHelper.hostAddress()); + + // read in the properties template file and set the server host:port and then save for use + File f = new File("./src/test/resources/hotrod-client.properties"); + + Properties props = PropertiesUtils.load(f.getAbsolutePath()); + props.setProperty("infinispan.client.hotrod.server_list", RemoteInfinispanTestHelper.hostAddress() + ":" + RemoteInfinispanTestHelper.hostPort()); + + PropertiesUtils.print("./target/hotrod-client.properties", props); + + factory = new InfinispanManagedConnectionFactory(); + + factory.setHotRodClientPropertiesFile("./target/hotrod-client.properties"); + factory.setCacheTypeMap(RemoteInfinispanTestHelper.CACHE_NAME + ":" + "java.lang.String"); + + } + + @AfterClass + public static void closeConnection() throws Exception { + RemoteInfinispanTestHelper.releaseServer(); + } + + + @Test + public void testConnection() throws Exception { + + ObjectConnection conn = factory.createConnectionFactory().getConnection(); + Map m = conn.getMap(RemoteInfinispanTestHelper.CACHE_NAME); + + assertNotNull(m); + + Class t = conn.getType(RemoteInfinispanTestHelper.CACHE_NAME); + + assertEquals(String.class, t); + } +} diff --git a/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/TestInfinispanServerList.java b/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/TestInfinispanServerList.java new file mode 100644 index 0000000000..7760350001 --- /dev/null +++ b/connectors/connector-infinispan/src/test/java/org/teiid/resource/adapter/infinispan/TestInfinispanServerList.java @@ -0,0 +1,77 @@ +/* + * JBoss, Home of Professional Open Source. + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA. + */ + +package org.teiid.resource.adapter.infinispan; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Map; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.teiid.translator.object.ObjectConnection; + + +@SuppressWarnings("nls") +public class TestInfinispanServerList { + private InfinispanManagedConnectionFactory factory = null; + + @BeforeClass + public static void beforeEachClass() throws Exception { + RemoteInfinispanTestHelper.createServer(); + + } + + @Before public void beforeEachTest() throws Exception{ + + factory = new InfinispanManagedConnectionFactory(); + + factory.setRemoteServerList(RemoteInfinispanTestHelper.hostAddress() + ":" + RemoteInfinispanTestHelper.hostPort()); + factory.setCacheTypeMap(RemoteInfinispanTestHelper.CACHE_NAME + ":" + "java.lang.String"); + } + + @AfterClass + public static void closeConnection() throws Exception { + RemoteInfinispanTestHelper.releaseServer(); + } + + @Test + public void testRemoteConnection() throws Exception { + + ObjectConnection conn = factory.createConnectionFactory().getConnection(); + Map m = conn.getMap(RemoteInfinispanTestHelper.CACHE_NAME); + + assertNotNull(m); + + Class t = conn.getType(RemoteInfinispanTestHelper.CACHE_NAME); + + assertEquals(String.class, t); + } + + + + + +} diff --git a/connectors/connector-infinispan/src/test/resources/hotrod-client.properties b/connectors/connector-infinispan/src/test/resources/hotrod-client.properties new file mode 100644 index 0000000000..a1ed269cc6 --- /dev/null +++ b/connectors/connector-infinispan/src/test/resources/hotrod-client.properties @@ -0,0 +1,3 @@ +infinispan.client.hotrod.server_list=${server.list} +infinispan.client.hotrod.ping_on_startup=true +infinispan.client.hotrod.transport_factory=org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory \ No newline at end of file diff --git a/connectors/connector-infinispan/src/test/resources/infinispan_persistent_config.xml b/connectors/connector-infinispan/src/test/resources/infinispan_persistent_config.xml new file mode 100644 index 0000000000..cd361d4730 --- /dev/null +++ b/connectors/connector-infinispan/src/test/resources/infinispan_persistent_config.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/connectors/connector-infinispan/src/test/resources/infinispan_persistent_indexing_config.xml b/connectors/connector-infinispan/src/test/resources/infinispan_persistent_indexing_config.xml new file mode 100644 index 0000000000..03188f2c59 --- /dev/null +++ b/connectors/connector-infinispan/src/test/resources/infinispan_persistent_indexing_config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/connectors/connector-infinispan/src/test/resources/infinispan_remote_config.xml b/connectors/connector-infinispan/src/test/resources/infinispan_remote_config.xml new file mode 100644 index 0000000000..0efa67fe8c --- /dev/null +++ b/connectors/connector-infinispan/src/test/resources/infinispan_remote_config.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + +