Skip to content
Browse files

ISPN-2225 Configuration API and XML parser for the HBase CacheStore

  • Loading branch information...
1 parent 089812e commit 1f688398fde47ca96f3372f07e5c0929e551e034 @tristantarrant tristantarrant committed with galderz
View
2 cachestore/hbase/src/main/java/org/infinispan/loaders/hbase/HBaseCacheStore.java
@@ -108,7 +108,7 @@ public void start() throws CacheLoaderException {
Map<String, String> props = new HashMap<String, String>();
props.put("hbase.zookeeper.quorum", config.hbaseZookeeperQuorum);
- props.put("hbase.zookeeper.property.clientPort", config.hbaseZookeeperPropertyClientPort);
+ props.put("hbase.zookeeper.property.clientPort", Integer.toString(config.hbaseZookeeperPropertyClientPort));
hbf = new HBaseFacade(props);
} catch (Exception e) {
throw new ConfigurationException(e);
View
8 cachestore/hbase/src/main/java/org/infinispan/loaders/hbase/HBaseCacheStoreConfig.java
@@ -41,7 +41,7 @@
/**
* @configRef desc="The HBase zookeeper client port."
*/
- String hbaseZookeeperPropertyClientPort = "2181";
+ int hbaseZookeeperPropertyClientPort = 2181;
/**
* @configRef desc="The HBase table for storing the cache entries"
@@ -94,7 +94,7 @@ public HBaseCacheStoreConfig() {
setCacheLoaderClassName(HBaseCacheStore.class.getName());
}
- public String getHbaseRootDir() {
+ public String getHbaseZookeeperQuorum() {
return hbaseZookeeperQuorum;
}
@@ -102,11 +102,11 @@ public void setHbaseZookeeperQuorum(String hbaseZookeeperQuorum) {
this.hbaseZookeeperQuorum = hbaseZookeeperQuorum;
}
- public String getHbaseZookeeperPropertyClientPort() {
+ public int getHbaseZookeeperPropertyClientPort() {
return hbaseZookeeperPropertyClientPort;
}
- public void setHbaseZookeeperPropertyClientPort(String hbaseZookeeperPropertyClientPort) {
+ public void setHbaseZookeeperPropertyClientPort(int hbaseZookeeperPropertyClientPort) {
this.hbaseZookeeperPropertyClientPort = hbaseZookeeperPropertyClientPort;
}
View
80 cachestore/hbase/src/main/java/org/infinispan/loaders/hbase/configuration/Attribute.java
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.infinispan.loaders.hbase.configuration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.infinispan.loaders.hbase.HBaseCacheStore;
+
+/**
+ * Enumerates the attributes used by the {@link HBaseCacheStore} configuration
+ *
+ * @author Tristan Tarrant
+ * @since 5.2
+ */
+public enum Attribute {
+ // must be first
+ UNKNOWN(null),
+ AUTO_CREATE_TABLE("autoCreateTable"),
+ ENTRY_COLUMN_FAMILY("entryColumnFamily"),
+ ENTRY_TABLE("entryTable"),
+ ENTRY_VALUE_FIELD("entryValueField"),
+ EXPIRATION_COLUMN_FAMILY("expirationColumnFamily"),
+ EXPIRATION_TABLE("expirationTable"),
+ EXPIRATION_VALUE_FIELD("expirationValueField"),
+ HBASE_ZOOKEEPER_QUORUM_HOST("hbaseZookeeperQuorumHost"),
+ HBASE_ZOOKEEPER_CLIENT_PORT("hbaseZookeeperClientPort"),
+ KEY_MAPPER("keyMapper"),
+ SHARED_TABLE("sharedTable"),
+ ;
+
+ private final String name;
+
+ private Attribute(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName() {
+ return name;
+ }
+
+ private static final Map<String, Attribute> attributes;
+
+ static {
+ final Map<String, Attribute> map = new HashMap<String, Attribute>(64);
+ for (Attribute attribute : values()) {
+ final String name = attribute.getLocalName();
+ if (name != null) {
+ map.put(name, attribute);
+ }
+ }
+ attributes = map;
+ }
+
+ public static Attribute forName(final String localName) {
+ final Attribute attribute = attributes.get(localName);
+ return attribute == null ? UNKNOWN : attribute;
+ }
+}
View
75 cachestore/hbase/src/main/java/org/infinispan/loaders/hbase/configuration/Element.java
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., 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.infinispan.loaders.hbase.configuration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.infinispan.loaders.hbase.HBaseCacheStore;
+
+/**
+ * An enumeration of all the recognized XML element local names for the {@link HBaseCacheStore}
+ *
+ * @author Tristan Tarrant
+ * @since 5.2
+ */
+public enum Element {
+ // must be first
+ UNKNOWN(null),
+
+ HBASE_STORE("hbaseStore"),
+ ;
+
+ private final String name;
+
+ Element(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * Get the local name of this element.
+ *
+ * @return the local name
+ */
+ public String getLocalName() {
+ return name;
+ }
+
+ private static final Map<String, Element> MAP;
+
+ static {
+ final Map<String, Element> map = new HashMap<String, Element>(8);
+ for (Element element : values()) {
+ final String name = element.getLocalName();
+ if (name != null) {
+ map.put(name, element);
+ }
+ }
+ MAP = map;
+ }
+
+ public static Element forName(final String localName) {
+ final Element element = MAP.get(localName);
+ return element == null ? UNKNOWN : element;
+ }
+}
View
128 ...rc/main/java/org/infinispan/loaders/hbase/configuration/HBaseCacheStoreConfiguration.java
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.infinispan.loaders.hbase.configuration;
+
+import org.infinispan.configuration.BuiltBy;
+import org.infinispan.configuration.cache.AbstractStoreConfiguration;
+import org.infinispan.configuration.cache.AsyncStoreConfiguration;
+import org.infinispan.configuration.cache.LegacyConfigurationAdaptor;
+import org.infinispan.configuration.cache.LegacyLoaderAdapter;
+import org.infinispan.configuration.cache.SingletonStoreConfiguration;
+import org.infinispan.loaders.hbase.HBaseCacheStoreConfig;
+import org.infinispan.util.TypedProperties;
+
+@BuiltBy(HBaseCacheStoreConfigurationBuilder.class)
+public class HBaseCacheStoreConfiguration extends AbstractStoreConfiguration implements LegacyLoaderAdapter<HBaseCacheStoreConfig> {
+
+ private final boolean autoCreateTable;
+ private final String entryColumnFamily;
+ private final String entryTable;
+ private final String entryValueField;
+ private final String expirationColumnFamily;
+ private final String expirationTable;
+ private final String expirationValueField;
+ private final String hbaseZookeeperQuorumHost;
+ private final int hbaseZookeeperClientPort;
+ private final String keyMapper;
+ private final boolean sharedTable;
+
+ public HBaseCacheStoreConfiguration(boolean autoCreateTable, String entryColumnFamily, String entryTable, String entryValueField, String expirationColumnFamily,
+ String expirationTable, String expirationValueField, String hbaseZookeeperQuorumHost, int hbaseZookeeperClientPort, String keyMapper, boolean sharedTable,
+ boolean purgeOnStartup, boolean purgeSynchronously, int purgerThreads, boolean fetchPersistentState, boolean ignoreModifications, TypedProperties properties,
+ AsyncStoreConfiguration asyncStoreConfiguration, SingletonStoreConfiguration singletonStoreConfiguration) {
+ super(purgeOnStartup, purgeSynchronously, purgerThreads, fetchPersistentState, ignoreModifications, properties, asyncStoreConfiguration, singletonStoreConfiguration);
+ this.autoCreateTable = autoCreateTable;
+ this.entryColumnFamily = entryColumnFamily;
+ this.entryTable = entryTable;
+ this.entryValueField = entryValueField;
+ this.expirationColumnFamily = expirationColumnFamily;
+ this.expirationTable = expirationTable;
+ this.expirationValueField = expirationValueField;
+ this.hbaseZookeeperQuorumHost = hbaseZookeeperQuorumHost;
+ this.hbaseZookeeperClientPort = hbaseZookeeperClientPort;
+ this.keyMapper = keyMapper;
+ this.sharedTable = sharedTable;
+ }
+
+ public boolean autoCreateTable() {
+ return autoCreateTable;
+ }
+
+ public String entryColumnFamily() {
+ return entryColumnFamily;
+ }
+
+ public String entryTable() {
+ return entryTable;
+ }
+
+ public String entryValueField() {
+ return entryValueField;
+ }
+
+ public String expirationColumnFamily() {
+ return expirationColumnFamily;
+ }
+
+ public String expirationTable() {
+ return expirationTable;
+ }
+
+ public String expirationValueField() {
+ return expirationValueField;
+ }
+
+ public String hbaseZookeeperQuorumHost() {
+ return hbaseZookeeperQuorumHost;
+ }
+
+ public int hbaseZookeeperClientPort() {
+ return hbaseZookeeperClientPort;
+ }
+
+ public String keyMapper() {
+ return keyMapper;
+ }
+
+ public boolean sharedTable() {
+ return sharedTable;
+ }
+
+ @Override
+ public HBaseCacheStoreConfig adapt() {
+ HBaseCacheStoreConfig config = new HBaseCacheStoreConfig();
+
+ LegacyConfigurationAdaptor.adapt(this, config);
+
+ config.setAutoCreateTable(autoCreateTable);
+ config.setEntryColumnFamily(entryColumnFamily);
+ config.setEntryTable(entryTable);
+ config.setEntryValueField(entryValueField);
+ config.setExpirationColumnFamily(expirationColumnFamily);
+ config.setExpirationTable(expirationTable);
+ config.setExpirationValueField(expirationValueField);
+ config.setHbaseZookeeperPropertyClientPort(hbaseZookeeperClientPort);
+ config.setHbaseZookeeperQuorum(hbaseZookeeperQuorumHost);
+ config.setKeyMapper(keyMapper);
+ config.setSharedTable(sharedTable);
+
+ return config;
+ }
+
+}
View
190 .../java/org/infinispan/loaders/hbase/configuration/HBaseCacheStoreConfigurationBuilder.java
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.infinispan.loaders.hbase.configuration;
+
+import org.infinispan.configuration.cache.AbstractStoreConfigurationBuilder;
+import org.infinispan.configuration.cache.LoadersConfigurationBuilder;
+import org.infinispan.loaders.hbase.HBaseCacheStore;
+import org.infinispan.loaders.keymappers.MarshalledValueOrPrimitiveMapper;
+import org.infinispan.loaders.keymappers.TwoWayKey2StringMapper;
+import org.infinispan.util.TypedProperties;
+
+/**
+ * HBaseCacheStoreConfigurationBuilder. Configures a {@link HBaseCacheStore}
+ *
+ * @author Tristan Tarrant
+ * @since 5.2
+ */
+public class HBaseCacheStoreConfigurationBuilder extends AbstractStoreConfigurationBuilder<HBaseCacheStoreConfiguration, HBaseCacheStoreConfigurationBuilder> {
+
+ private boolean autoCreateTable = true;
+ private String entryColumnFamily = "E";
+ private String entryTable = "ISPNCacheStore";
+ private String entryValueField = "EV";
+ private String expirationColumnFamily = "X";
+ private String expirationTable = "ISPNCacheStoreExpiration";
+ private String expirationValueField = "XV";
+ private String hbaseZookeeperQuorumHost = "localhost";
+ private int hbaseZookeeperClientPort = 2181;
+ private String keyMapper = MarshalledValueOrPrimitiveMapper.class.getName();
+ private boolean sharedTable = false;
+
+ public HBaseCacheStoreConfigurationBuilder(LoadersConfigurationBuilder builder) {
+ super(builder);
+ }
+
+ @Override
+ public HBaseCacheStoreConfigurationBuilder self() {
+ return this;
+ }
+
+ /**
+ * Whether to automatically create the HBase table with the appropriate column families (true by
+ * default).
+ */
+ public HBaseCacheStoreConfigurationBuilder autoCreateTable(boolean autoCreateTable) {
+ this.autoCreateTable = autoCreateTable;
+ return this;
+ }
+
+ /**
+ * The column family for entries. Defaults to 'E'
+ */
+ public HBaseCacheStoreConfigurationBuilder entryColumnFamily(String entryColumnFamily) {
+ this.entryColumnFamily = entryColumnFamily;
+ return this;
+ }
+
+ /**
+ * The HBase table for storing the cache entries. Defaults to 'ISPNCacheStore'
+ */
+ public HBaseCacheStoreConfigurationBuilder entryTable(String entryTable) {
+ this.entryTable = entryTable;
+ return this;
+ }
+
+ /**
+ * The field name containing the entries. Defaults to 'EV'
+ */
+ public HBaseCacheStoreConfigurationBuilder entryValueField(String entryValueField) {
+ this.entryValueField = entryValueField;
+ return this;
+ }
+
+ /**
+ * The column family for expiration metadata. Defaults to 'X'
+ */
+ public HBaseCacheStoreConfigurationBuilder expirationColumnFamily(String expirationColumnFamily) {
+ this.expirationColumnFamily = expirationColumnFamily;
+ return this;
+ }
+
+ /**
+ * The HBase table for storing the cache expiration metadata. Defaults to
+ * 'ISPNCacheStoreExpiration'
+ */
+ public HBaseCacheStoreConfigurationBuilder expirationTable(String expirationTable) {
+ this.expirationTable = expirationTable;
+ return this;
+ }
+
+ /**
+ * The field name containing the expiration metadata. Defaults to 'XV'
+ */
+ public HBaseCacheStoreConfigurationBuilder expirationValueField(String expirationValueField) {
+ this.expirationValueField = expirationValueField;
+ return this;
+ }
+
+ /**
+ * The HBase zookeeper client port. Defaults to 'localhost'
+ */
+ public HBaseCacheStoreConfigurationBuilder hbaseZookeeperQuorumHost(String hbaseZookeeperQuorumHost) {
+ this.hbaseZookeeperQuorumHost = hbaseZookeeperQuorumHost;
+ return this;
+ }
+
+ /**
+ * The HBase zookeeper client port. Defaults to '2181'
+ */
+ public HBaseCacheStoreConfigurationBuilder hbaseZookeeperClientPort(int hbaseZookeeperClientPort) {
+ this.hbaseZookeeperClientPort = hbaseZookeeperClientPort;
+ return this;
+ }
+
+ /**
+ * The keymapper for converting keys to strings (uses the
+ * {@link MarshalledValueOrPrimitiveMapper} by default)
+ */
+ public HBaseCacheStoreConfigurationBuilder keyMapper(String keyMapper) {
+ this.keyMapper = keyMapper;
+ return this;
+ }
+
+ /**
+ * The keymapper for converting keys to strings (uses the
+ * {@link MarshalledValueOrPrimitiveMapper} by default)
+ */
+ public HBaseCacheStoreConfigurationBuilder keyMapper(Class<? extends TwoWayKey2StringMapper> keyMapper) {
+ this.keyMapper = keyMapper.getName();
+ return this;
+ }
+
+ /**
+ * Whether the table is shared between multiple caches. Defaults to 'false'
+ */
+ public HBaseCacheStoreConfigurationBuilder sharedTable(boolean sharedTable) {
+ this.sharedTable = sharedTable;
+ return this;
+ }
+
+ @Override
+ public HBaseCacheStoreConfiguration create() {
+ return new HBaseCacheStoreConfiguration(autoCreateTable, entryColumnFamily, entryTable, entryValueField, expirationColumnFamily, expirationTable, expirationValueField,
+ hbaseZookeeperQuorumHost, hbaseZookeeperClientPort, keyMapper, sharedTable, purgeOnStartup, purgeSynchronously, purgerThreads, fetchPersistentState,
+ ignoreModifications, TypedProperties.toTypedProperties(properties), async.create(), singletonStore.create());
+ }
+
+ @Override
+ public HBaseCacheStoreConfigurationBuilder read(HBaseCacheStoreConfiguration template) {
+ autoCreateTable = template.autoCreateTable();
+ entryColumnFamily = template.entryColumnFamily();
+ entryTable = template.entryTable();
+ entryValueField = template.entryValueField();
+ expirationColumnFamily = template.expirationColumnFamily();
+ expirationTable = template.expirationTable();
+ expirationValueField = template.expirationValueField();
+ hbaseZookeeperQuorumHost = template.hbaseZookeeperQuorumHost();
+ hbaseZookeeperClientPort = template.hbaseZookeeperClientPort();
+ keyMapper = template.keyMapper();
+ sharedTable = template.sharedTable();
+
+ // AbstractStore-specific configuration
+ fetchPersistentState = template.fetchPersistentState();
+ ignoreModifications = template.ignoreModifications();
+ properties = template.properties();
+ purgeOnStartup = template.purgeOnStartup();
+ purgeSynchronously = template.purgeSynchronously();
+ async.read(template.async());
+ singletonStore.read(template.singletonStore());
+
+ return this;
+ }
+
+}
View
138 ...java/org/infinispan/loaders/hbase/configuration/HBaseCacheStoreConfigurationParser52.java
@@ -0,0 +1,138 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.infinispan.loaders.hbase.configuration;
+
+import static org.infinispan.util.StringPropertyReplacer.replaceProperties;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.cache.LoadersConfigurationBuilder;
+import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
+import org.infinispan.configuration.parsing.ConfigurationParser;
+import org.infinispan.configuration.parsing.Namespace;
+import org.infinispan.configuration.parsing.ParseUtils;
+import org.infinispan.configuration.parsing.Parser52;
+import org.jboss.staxmapper.XMLExtendedStreamReader;
+
+/**
+ *
+ * HBaseCacheStoreConfigurationParser52.
+ *
+ * @author Tristan Tarrant
+ * @since 5.2
+ */
+public class HBaseCacheStoreConfigurationParser52 implements ConfigurationParser<ConfigurationBuilderHolder> {
+
+ private static final Namespace NAMESPACES[] = { new Namespace(Namespace.INFINISPAN_NS_BASE_URI, "hbase", Element.HBASE_STORE.getLocalName(), 5, 2),
+ new Namespace("", Element.HBASE_STORE.getLocalName(), 0, 0) };
+
+ public HBaseCacheStoreConfigurationParser52() {
+ }
+
+ @Override
+ public Namespace[] getSupportedNamespaces() {
+ return NAMESPACES;
+ }
+
+ @Override
+ public void readElement(final XMLExtendedStreamReader reader, final ConfigurationBuilderHolder holder) throws XMLStreamException {
+ ConfigurationBuilder builder = holder.getCurrentConfigurationBuilder();
+
+ Element element = Element.forName(reader.getLocalName());
+ switch (element) {
+ case HBASE_STORE: {
+ parseHBaseStore(reader, builder.loaders(), holder.getClassLoader());
+ break;
+ }
+ default: {
+ throw ParseUtils.unexpectedElement(reader);
+ }
+ }
+ }
+
+ private void parseHBaseStore(final XMLExtendedStreamReader reader, LoadersConfigurationBuilder loadersBuilder, ClassLoader classLoader) throws XMLStreamException {
+ HBaseCacheStoreConfigurationBuilder builder = new HBaseCacheStoreConfigurationBuilder(loadersBuilder);
+ parseHBaseStoreAttributes(reader, builder);
+
+ while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
+ Parser52.parseCommonStoreChildren(reader, builder);
+ }
+ loadersBuilder.addStore(builder);
+ }
+
+ private void parseHBaseStoreAttributes(XMLExtendedStreamReader reader, HBaseCacheStoreConfigurationBuilder builder) throws XMLStreamException {
+ for (int i = 0; i < reader.getAttributeCount(); i++) {
+ ParseUtils.requireNoNamespaceAttribute(reader, i);
+ String value = replaceProperties(reader.getAttributeValue(i));
+ Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
+ switch (attribute) {
+ case AUTO_CREATE_TABLE: {
+ builder.autoCreateTable(Boolean.parseBoolean(value));
+ break;
+ }
+ case ENTRY_COLUMN_FAMILY: {
+ builder.entryColumnFamily(value);
+ break;
+ }
+ case ENTRY_TABLE: {
+ builder.entryTable(value);
+ break;
+ }
+ case ENTRY_VALUE_FIELD: {
+ builder.entryValueField(value);
+ break;
+ }
+ case EXPIRATION_COLUMN_FAMILY: {
+ builder.expirationColumnFamily(value);
+ break;
+ }
+ case EXPIRATION_TABLE: {
+ builder.expirationTable(value);
+ break;
+ }
+ case EXPIRATION_VALUE_FIELD: {
+ builder.expirationValueField(value);
+ break;
+ }
+ case HBASE_ZOOKEEPER_QUORUM_HOST: {
+ builder.hbaseZookeeperQuorumHost(value);
+ break;
+ }
+ case HBASE_ZOOKEEPER_CLIENT_PORT: {
+ builder.hbaseZookeeperClientPort(Integer.parseInt(value));
+ break;
+ }
+ case KEY_MAPPER: {
+ builder.keyMapper(value);
+ break;
+ }
+ case SHARED_TABLE: {
+ builder.sharedTable(Boolean.parseBoolean(value));
+ break;
+ }
+ default: {
+ Parser52.parseCommonStoreAttributes(reader, i, builder);
+ break;
+ }
+ }
+ }
+ }
+}
View
1 ...main/resources/META-INF/services/org.infinispan.configuration.parsing.ConfigurationParser
@@ -0,0 +1 @@
+org.infinispan.loaders.hbase.configuration.HBaseCacheStoreConfigurationParser52
View
110 cachestore/hbase/src/main/resources/schema/infinispan-cachestore-hbase-config-5.2.xsd
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+
+<!--
+ ~ Copyright 2012 Red Hat, Inc. and/or its affiliates.
+ ~
+ ~ 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 library; if not, write to the Free Software
+ ~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ ~ 02110-1301 USA
+ -->
+
+<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" targetNamespace="urn:infinispan:config:hbase:5.2" xmlns:tns="urn:infinispan:config:hbase:5.2" xmlns:config="urn:infinispan:config:5.2" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:import namespace="urn:infinispan:config:5.2" schemaLocation="http://www.infinispan.org/schemas/infinispan-config-5.2.xsd" />
+
+ <xs:complexType name="hbaseStore">
+ <xs:complexContent>
+ <xs:extension base="config:store">
+ <xs:sequence>
+ </xs:sequence>
+ <xs:attribute name="autoCreateTable" type="xs:boolean" default="true">
+ <xs:annotation>
+ <xs:documentation>
+ Whether to automatically create the HBase table with the appropriate column families (true by default).
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="entryColumnFamily" type="xs:string" default="E">
+ <xs:annotation>
+ <xs:documentation>
+ The column family for entries. Defaults to 'E'
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="entryTable" type="xs:string" default="ISPNCacheStore">
+ <xs:annotation>
+ <xs:documentation>
+ The HBase table for storing the cache entries. Defaults to 'ISPNCacheStore'
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="entryValueField" type="xs:string" default="EV">
+ <xs:annotation>
+ <xs:documentation>
+ The field name containing the entries. Defaults to 'EV'
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="expirationColumnFamily" type="xs:string" default="X">
+ <xs:annotation>
+ <xs:documentation>
+ The column family for expiration metadata. Defaults to 'X'
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="expirationTable" type="xs:string" default="ISPNCacheStoreExpiration">
+ <xs:annotation>
+ <xs:documentation>
+ The HBase table for storing the cache expiration metadata. Defaults to 'ISPNCacheStoreExpiration'
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="expirationValueField" type="xs:string" default="XV">
+ <xs:annotation>
+ <xs:documentation>
+ The field name containing the expiration metadata. Defaults to 'XV'
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="hbaseZookeeperQuorumHost" type="xs:string" default="localhost">
+ <xs:annotation>
+ <xs:documentation>
+ The HBase zookeeper client port. Defaults to 'localhost'
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="hbaseZookeeperClientPort" type="xs:int" default="2181">
+ <xs:annotation>
+ <xs:documentation>
+ The HBase zookeeper client port. Defaults to '2181'
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="keyMapper" type="xs:string" default="org.infinispan.loaders.keymappers.MarshalledValueOrPrimitiveMapper">
+ <xs:annotation>
+ <xs:documentation>
+ The keymapper for converting keys to strings (uses the MarshalledValueOrPrimitiveMapper by default)
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="sharedTable" type="xs:boolean" default="false">
+ <xs:annotation>
+ <xs:documentation>
+ Whether the table is shared between multiple caches. Defaults to 'false'
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+</xs:schema>
View
4 cachestore/hbase/src/test/java/org/infinispan/loaders/hbase/HBaseCacheStoreConfigTest.java
@@ -31,10 +31,10 @@
public void setConfigurationPropertiesFileTest() throws CacheLoaderException {
HBaseCacheStoreConfig config = new HBaseCacheStoreConfig();
-
+
assert config.entryTable == "ISPNCacheStore";
assert config.hbaseZookeeperQuorum == "localhost";
- assert config.hbaseZookeeperPropertyClientPort == "2181";
+ assert config.hbaseZookeeperPropertyClientPort == 2181;
assert config.entryColumnFamily == "E";
assert config.entryValueField == "EV";
assert config.expirationTable == "ISPNCacheStoreExpiration";
View
3 cachestore/hbase/src/test/java/org/infinispan/loaders/hbase/HBaseCacheStoreTest.java
@@ -63,8 +63,7 @@ protected CacheStore createCacheStore() throws Exception {
if (USE_EMBEDDED) {
// overwrite the ZooKeeper client port with the port from the embedded server
- conf.setHbaseZookeeperPropertyClientPort(Integer
- .toString(EmbeddedServerHelper.zooKeeperPort));
+ conf.setHbaseZookeeperPropertyClientPort(EmbeddedServerHelper.zooKeeperPort);
}
cs.init(conf, getCache(), getMarshaller());
View
87 ...ore/hbase/src/test/java/org/infinispan/loaders/hbase/configuration/ConfigurationTest.java
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.infinispan.loaders.hbase.configuration;
+
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.loaders.hbase.HBaseCacheStoreConfig;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "loaders.hbase.configuration.ConfigurationTest")
+public class ConfigurationTest {
+
+ public void testHBaseCacheStoreConfigurationAdaptor() {
+ ConfigurationBuilder b = new ConfigurationBuilder();
+ b.loaders().addStore(HBaseCacheStoreConfigurationBuilder.class)
+ .autoCreateTable(false)
+ .entryColumnFamily("ECF")
+ .entryTable("ET")
+ .entryValueField("EVF")
+ .expirationColumnFamily("XCF")
+ .expirationTable("XT")
+ .expirationValueField("XVF")
+ .hbaseZookeeperClientPort(4321)
+ .hbaseZookeeperQuorumHost("myhost")
+ .sharedTable(true)
+ .fetchPersistentState(true).async().enable();
+ Configuration configuration = b.build();
+ HBaseCacheStoreConfiguration store = (HBaseCacheStoreConfiguration) configuration.loaders().cacheLoaders().get(0);
+ assert !store.autoCreateTable();
+ assert store.entryColumnFamily().equals("ECF");
+ assert store.entryTable().equals("ET");
+ assert store.entryValueField().equals("EVF");
+ assert store.expirationColumnFamily().equals("XCF");
+ assert store.expirationTable().equals("XT");
+ assert store.expirationValueField().equals("XVF");
+ assert store.hbaseZookeeperQuorumHost().equals("myhost");
+ assert store.hbaseZookeeperClientPort() == 4321;
+ assert store.sharedTable();
+ assert store.fetchPersistentState();
+ assert store.async().enabled();
+
+ b = new ConfigurationBuilder();
+ b.loaders().addStore(HBaseCacheStoreConfigurationBuilder.class).read(store);
+ Configuration configuration2 = b.build();
+ HBaseCacheStoreConfiguration store2 = (HBaseCacheStoreConfiguration) configuration2.loaders().cacheLoaders().get(0);
+ assert !store2.autoCreateTable();
+ assert store2.entryColumnFamily().equals("ECF");
+ assert store2.entryTable().equals("ET");
+ assert store2.entryValueField().equals("EVF");
+ assert store2.expirationColumnFamily().equals("XCF");
+ assert store2.expirationTable().equals("XT");
+ assert store2.expirationValueField().equals("XVF");
+ assert store2.hbaseZookeeperQuorumHost().equals("myhost");
+ assert store2.hbaseZookeeperClientPort() == 4321;
+ assert store2.sharedTable();
+ assert store2.fetchPersistentState();
+ assert store2.async().enabled();
+
+ HBaseCacheStoreConfig legacy = store.adapt();
+ assert !legacy.isAutoCreateTable();
+ assert legacy.getEntryColumnFamily().equals("ECF");
+ assert legacy.getEntryTable().equals("ET");
+ assert legacy.getEntryValueField().equals("EVF");
+ assert legacy.getExpirationColumnFamily().equals("XCF");
+ assert legacy.getExpirationTable().equals("XT");
+ assert legacy.getExpirationValueField().equals("XVF");
+ assert legacy.getHbaseZookeeperPropertyClientPort() == 4321;
+ assert legacy.isFetchPersistentState();
+ assert legacy.getAsyncStoreConfig().isEnabled();
+ }
+}
View
81 ...re/hbase/src/test/java/org/infinispan/loaders/hbase/configuration/XmlFileParsingTest.java
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009 Red Hat Inc. and/or its affiliates and other
+ * contributors as indicated by the @author tags. All rights reserved.
+ * 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.infinispan.loaders.hbase.configuration;
+
+import static org.infinispan.test.TestingUtil.INFINISPAN_START_TAG;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.infinispan.configuration.cache.LoaderConfiguration;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.test.AbstractInfinispanTest;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "loaders.hbase.configuration.XmlFileParsingTest")
+public class XmlFileParsingTest extends AbstractInfinispanTest {
+
+ private EmbeddedCacheManager cacheManager;
+
+ @AfterMethod(alwaysRun = true)
+ public void cleanup() {
+ TestingUtil.killCacheManagers(cacheManager);
+ }
+
+ public void testRemoteCacheStore() throws Exception {
+ String config = INFINISPAN_START_TAG +
+ " <default>\n" +
+ " <loaders>\n" +
+ " <hbaseStore xmlns=\"urn:infinispan:config:hbase:5.2\" fetchPersistentState=\"true\" autoCreateTable=\"false\" entryColumnFamily=\"ECF\" entryTable=\"ET\" " +
+ " entryValueField=\"EVF\" expirationColumnFamily=\"XCF\" expirationTable=\"XT\" expirationValueField=\"XVF\" hbaseZookeeperQuorumHost=\"myhost\" hbaseZookeeperClientPort=\"4321\" sharedTable=\"true\">\n" +
+ " <async enabled=\"true\" />\n" +
+ " </hbaseStore>\n" +
+ " </loaders>\n" +
+ " </default>\n" +
+ TestingUtil.INFINISPAN_END_TAG;
+
+ HBaseCacheStoreConfiguration store = (HBaseCacheStoreConfiguration) buildCacheManagerWithCacheStore(config);
+ assert !store.autoCreateTable();
+ assert store.entryColumnFamily().equals("ECF");
+ assert store.entryTable().equals("ET");
+ assert store.entryValueField().equals("EVF");
+ assert store.expirationColumnFamily().equals("XCF");
+ assert store.expirationTable().equals("XT");
+ assert store.expirationValueField().equals("XVF");
+ assert store.hbaseZookeeperQuorumHost().equals("myhost");
+ assert store.hbaseZookeeperClientPort() == 4321;
+ assert store.sharedTable();
+ assert store.fetchPersistentState();
+ assert store.async().enabled();
+ }
+
+ private LoaderConfiguration buildCacheManagerWithCacheStore(final String config) throws IOException {
+ InputStream is = new ByteArrayInputStream(config.getBytes());
+ cacheManager = TestCacheManagerFactory.fromStream(is);
+ assert cacheManager.getDefaultCacheConfiguration().loaders().cacheLoaders().size() == 1;
+ return cacheManager.getDefaultCacheConfiguration().loaders().cacheLoaders().get(0);
+ }
+}

0 comments on commit 1f68839

Please sign in to comment.
Something went wrong with that request. Please try again.