You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gora.apache.org by dj...@apache.org on 2017/07/27 18:45:27 UTC
[01/32] gora git commit: Add initial gora-aerospike module
Repository: gora
Updated Branches:
refs/heads/master d5e5560ba -> 7a56d2484
Add initial gora-aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/e796c8c5
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/e796c8c5
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/e796c8c5
Branch: refs/heads/master
Commit: e796c8c511463cefdb6da785baf9373d19795995
Parents: 1b20b10
Author: nishadi <nd...@gmail.com>
Authored: Thu Jun 8 21:03:29 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jun 8 21:03:29 2017 +0530
----------------------------------------------------------------------
gora-aerospike/pom.xml | 141 +++++++++++++++++++
.../org/apache/gora/aerospike/package-info.java | 20 +++
.../gora/aerospike/store/AerospikeStore.java | 110 +++++++++++++++
.../gora/aerospike/store/package-info.java | 20 +++
pom.xml | 7 +
5 files changed, 298 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/e796c8c5/gora-aerospike/pom.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/pom.xml b/gora-aerospike/pom.xml
new file mode 100644
index 0000000..1a557f4
--- /dev/null
+++ b/gora-aerospike/pom.xml
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.gora</groupId>
+ <artifactId>gora</artifactId>
+ <version>0.8-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+ <artifactId>gora-aerospike</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache Gora :: Aerospike</name>
+ <url>http://gora.apache.org</url>
+ <description>The Apache Gora open source framework provides an in-memory data model and
+ persistence for big data. Gora supports persisting to column stores, key value stores,
+ document stores and RDBMSs, and analyzing the data with extensive Apache Hadoop MapReduce
+ support.</description>
+ <inceptionYear>2010</inceptionYear>
+ <organization>
+ <name>The Apache Software Foundation</name>
+ <url>http://www.apache.org/</url>
+ </organization>
+ <issueManagement>
+ <system>JIRA</system>
+ <url>https://issues.apache.org/jira/browse/GORA</url>
+ </issueManagement>
+ <ciManagement>
+ <system>Jenkins</system>
+ <url>https://builds.apache.org/job/Gora-trunk/</url>
+ </ciManagement>
+
+ <properties>
+ <aerospike.version>3.3.2</aerospike.version>
+ <osgi.import>*</osgi.import>
+ <osgi.export>org.apache.gora.aerospike*;version="${project.version}";-noimport:=true</osgi.export>
+ </properties>
+
+ <build>
+ <directory>target</directory>
+ <outputDirectory>target/classes</outputDirectory>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <testOutputDirectory>target/test-classes</testOutputDirectory>
+ <testSourceDirectory>src/test/java</testSourceDirectory>
+ <sourceDirectory>src/main/java</sourceDirectory>
+ <testResources>
+ <testResource>
+ <directory>${project.basedir}/src/test/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </testResource>
+ </testResources>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>${build-helper-maven-plugin.version}</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/examples/java</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!-- Gora Internal Dependencies -->
+ <dependency>
+ <groupId>org.apache.gora</groupId>
+ <artifactId>gora-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.gora</groupId>
+ <artifactId>gora-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <!--Aerospike Dependency -->
+ <dependency>
+ <groupId>com.aerospike</groupId>
+ <artifactId>aerospike-client</artifactId>
+ <version>${aerospike.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.avro</groupId>
+ <artifactId>avro</artifactId>
+ </dependency>
+
+ <!-- Hadoop Dependencies -->
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-client</artifactId>
+ </dependency>
+
+ <!-- Logging Dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+
+ <!-- Testing Dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/gora/blob/e796c8c5/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
new file mode 100644
index 0000000..0dbf8dd
--- /dev/null
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
@@ -0,0 +1,20 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * This package contains Aerospike datastore related all classes.
+ */
+package org.apache.gora.aerospike;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/gora/blob/e796c8c5/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
new file mode 100644
index 0000000..8c31773
--- /dev/null
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gora.aerospike.store;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+import com.aerospike.client.*;
+import org.apache.gora.persistency.impl.PersistentBase;
+import org.apache.gora.query.PartitionQuery;
+import org.apache.gora.query.Query;
+import org.apache.gora.query.Result;
+import org.apache.gora.store.DataStoreFactory;
+import org.apache.gora.store.impl.DataStoreBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+/**
+ * Implementation of a Aerospike data store to be used by gora.
+ *
+ * @param <K>
+ * class to be used for the key
+ * @param <T>
+ * class to be persisted within the store
+ */
+public class AerospikeStore<K,T extends PersistentBase> extends DataStoreBase<K,T> {
+
+ public static final Logger LOG = LoggerFactory.getLogger(AerospikeStore.class);
+
+ private AerospikeClient aerospikeClient;
+
+ @Override
+ public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) {
+ super.initialize(keyClass, persistentClass, properties);
+ }
+
+ @Override
+ public String getSchemaName() {
+ return null;
+ }
+
+ @Override
+ public void createSchema() {
+ }
+
+ @Override
+ public void deleteSchema() {
+ }
+
+ @Override
+ public boolean schemaExists() {
+ return true;
+ }
+
+ @Override
+ public T get(K key, String[] fields) {
+ return null;
+ }
+
+ @Override
+ public void put(K key, T val) {
+ }
+
+ @Override
+ public boolean delete(K key) {
+ return true;
+ }
+
+ @Override
+ public long deleteByQuery(Query<K,T> query) {
+ return 0;
+ }
+
+ @Override
+ public Result<K,T> execute(Query<K,T> query) {
+ return null;
+ }
+
+ @Override
+ public Query<K,T> newQuery() {
+ return null;
+ }
+
+ @Override
+ public List<PartitionQuery<K,T>> getPartitions(Query<K,T> query) throws IOException {
+ return null;
+ }
+
+ public void flush() {
+ }
+
+ @Override
+ public void close() {
+ aerospikeClient.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/e796c8c5/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
new file mode 100644
index 0000000..e92fa51
--- /dev/null
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
@@ -0,0 +1,20 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * This package contains all the Aerospike store related classes.
+ */
+package org.apache.gora.aerospike.store;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/gora/blob/e796c8c5/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f3f3058..618cda1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -733,6 +733,7 @@
<module>gora-solr-5</module>
<module>gora-tutorial</module>
<module>sources-dist</module>
+ <module>gora-aerospike</module>
</modules>
<properties>
@@ -764,6 +765,7 @@
<restlet.version>2.3.1</restlet.version>
<spark.version>1.4.1</spark.version>
+ <aerospike.version>3.3.2</aerospike.version>
<!-- Misc Dependencies -->
<guava.version>13.0</guava.version>
<commons-lang.version>2.6</commons-lang.version>
@@ -935,6 +937,11 @@
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
+ <dependency>
+ <groupId>org.apache.gora</groupId>
+ <artifactId>gora-aerospike</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- End of Internal Depednecies -->
<dependency>
[04/32] gora git commit: Add put functionality for aerospike module
Posted by dj...@apache.org.
Add put functionality for aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/8571ad90
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/8571ad90
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/8571ad90
Branch: refs/heads/master
Commit: 8571ad90db93507118897e7fb51500ac4821c47c
Parents: 5608731
Author: nishadi <nd...@gmail.com>
Authored: Sun Jun 18 14:10:27 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Sun Jun 18 14:12:57 2017 +0530
----------------------------------------------------------------------
.../store/AerospikeMappingBuilder.java | 92 +++++++++++---------
.../gora/aerospike/store/AerospikeStore.java | 43 +++++++++
2 files changed, 92 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/8571ad90/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
index 4e2b997..8744709 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
@@ -69,59 +69,65 @@ public class AerospikeMappingBuilder {
for (Element policyElement : policyElements) {
String policy = policyElement.getAttributeValue("name");
-
- if (policy.equals("write")) {
-
- WritePolicy writePolicy = new WritePolicy();
- if (policyElement.getAttributeValue("gen") != null)
- writePolicy.generationPolicy = getGenerationPolicyMapping(policyElement.getAttributeValue
- ("gen").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("exists") != null)
- writePolicy.recordExistsAction = getRecordExistsAction(policyElement.getAttributeValue
- ("exists").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("key") != null)
- writePolicy.sendKey = getKeyUsagePolicy(policyElement.getAttributeValue("key").toUpperCase
- (Locale.getDefault()));
- if (policyElement.getAttributeValue("retry") != null)
- writePolicy.retryOnTimeout = getRetryOnTimeoutPolicy(policyElement.getAttributeValue
- ("retry").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("timeout") != null)
- writePolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
- aerospikeMapping.setWritePolicy(writePolicy);
- } else if (policy.equals("read")) {
-
- Policy readPolicy = new Policy();
- if (policyElement.getAttributeValue("key") != null)
- readPolicy.sendKey = getKeyUsagePolicy(policyElement.getAttributeValue("key").toUpperCase(Locale
- .getDefault()));
- if (policyElement.getAttributeValue("timeout") != null)
- readPolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
- aerospikeMapping.setReadPolicy(readPolicy);
+ if (policy != null) {
+ if (policy.equals("write")) {
+ WritePolicy writePolicy = new WritePolicy();
+ if (policyElement.getAttributeValue("gen") != null)
+ writePolicy.generationPolicy = getGenerationPolicyMapping(policyElement.getAttributeValue
+ ("gen").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("exists") != null)
+ writePolicy.recordExistsAction = getRecordExistsAction(policyElement.getAttributeValue
+ ("exists").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("key") != null)
+ writePolicy.sendKey = getKeyUsagePolicy(policyElement.getAttributeValue("key").toUpperCase
+ (Locale.getDefault()));
+ if (policyElement.getAttributeValue("retry") != null)
+ writePolicy.retryOnTimeout = getRetryOnTimeoutPolicy(policyElement.getAttributeValue
+ ("retry").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("timeout") != null)
+ writePolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ aerospikeMapping.setWritePolicy(writePolicy);
+ } else if (policy.equals("read")) {
+ Policy readPolicy = new Policy();
+ if (policyElement.getAttributeValue("key") != null)
+ readPolicy.sendKey = getKeyUsagePolicy(policyElement.getAttributeValue("key").toUpperCase(Locale
+ .getDefault()));
+ if (policyElement.getAttributeValue("timeout") != null)
+ readPolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ aerospikeMapping.setReadPolicy(readPolicy);
+ }
}
}
// Mapping the defined classes
- List<Element> classElements = root.getChildren("policy");
+ List<Element> classElements = root.getChildren("class");
boolean persistentAndKeyClassMatches = false;
for (Element classElement : classElements) {
- if (classElement.getAttributeValue("keyClass").equals(keyClass.getCanonicalName())
- && classElement.getAttributeValue("name").equals(persistentClass.getCanonicalName())) {
- persistentAndKeyClassMatches = true;
-
- String nameSpace = classElement.getAttributeValue("namespace");
- if (nameSpace == null || nameSpace.isEmpty()) {
- throw new ConfigurationException("Gora-aerospike-mapping does not include the relevant namespace for the " +
- "class");
- }
- aerospikeMapping.setNamespace(nameSpace);
- String set = classElement.getAttributeValue("set");
- if (set != null && !set.isEmpty()) {
- //ToDo : check for schema set name
- aerospikeMapping.setSet(set);
+ String mappingKeyClass = classElement.getAttributeValue("keyClass");
+ String mappingClassName = classElement.getAttributeValue("name");
+
+ if (mappingKeyClass != null && mappingClassName != null) {
+ if (mappingKeyClass.equals(keyClass.getCanonicalName())
+ && mappingClassName.equals(persistentClass.getCanonicalName())) {
+
+ persistentAndKeyClassMatches = true;
+
+ String nameSpace = classElement.getAttributeValue("namespace");
+ if (nameSpace == null || nameSpace.isEmpty()) {
+ throw new ConfigurationException("Gora-aerospike-mapping does not include the relevant namespace for " +
+ "the class");
+ }
+ aerospikeMapping.setNamespace(nameSpace);
+
+ String set = classElement.getAttributeValue("set");
+ if (set != null && !set.isEmpty()) {
+ aerospikeMapping.setSet(set);
+ }
}
}
+
}
if (!persistentAndKeyClassMatches)
throw new ConfigurationException("Gora-aerospike-mapping does not include the name and keyClass in the " +
http://git-wip-us.apache.org/repos/asf/gora/blob/8571ad90/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 6ed1a76..c8610e1 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -22,6 +22,8 @@ import java.util.Properties;
import com.aerospike.client.*;
import com.aerospike.client.policy.ClientPolicy;
+import org.apache.avro.Schema;
+import org.apache.avro.Schema.Field;
import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.PartitionQuery;
import org.apache.gora.query.Query;
@@ -92,6 +94,18 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
@Override
public void put(K key, T value) {
+ Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(), aerospikeParameters
+ .getAerospikeMapping().getSet(), Value.get(key));
+
+ List<Field> fields = value.getSchema().getFields();
+
+ for (int i = 0; i < fields.size(); i++) {
+
+ // In retrieving the bin name, it is checked whether the server is single bin valued
+ String binName = aerospikeParameters.getBinName(fields.get(i).name());
+ Bin bin = getBin(binName, value.get(i), fields.get(i));
+ aerospikeClient.put(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey, bin);
+ }
}
@Override
@@ -126,4 +140,33 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
public void close() {
aerospikeClient.close();
}
+
+ /**
+ * Aerospike does not support Utf8 format returned from Avro.
+ * This method provides those utf8 valued bin values as strings
+ * for aerospike Value to obtain the corresponding bin value,
+ * and returns the Bin
+ *
+ * @param binName name of the bin
+ * @param value value of the bin
+ * @param field field corresponding to bin
+ * @return
+ */
+ private Bin getBin(String binName, Object value, Field field){
+
+ boolean isStringType = false;
+ if (field.schema().getType().equals(Schema.Type.STRING))
+ isStringType = true;
+ if (field.schema().getType().equals(Schema.Type.UNION)){
+ for (Schema schema :field.schema().getTypes()) {
+ if (schema.getName().equals("string"))
+ isStringType = true;
+ }
+ }
+
+ if (isStringType)
+ return new Bin(binName, Value.get(value.toString()));
+ else
+ return new Bin(binName, Value.get(value));
+ }
}
[06/32] gora git commit: Update mapping reading to support mappings
of field names to bin values in aerospike module
Posted by dj...@apache.org.
Update mapping reading to support mappings of field names to bin values in aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/b0c19774
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/b0c19774
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/b0c19774
Branch: refs/heads/master
Commit: b0c197744e40816bd5a1780684e9f31081949790
Parents: 3900a41
Author: nishadi <nd...@gmail.com>
Authored: Mon Jun 19 17:35:44 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Mon Jun 19 17:35:44 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/store/AerospikeMapping.java | 13 ++
.../store/AerospikeMappingBuilder.java | 165 ++++++++++---------
.../gora/aerospike/store/AerospikeStore.java | 76 ++++-----
3 files changed, 132 insertions(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/b0c19774/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
index 5df8a92..ae8284d 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
@@ -19,15 +19,20 @@ package org.apache.gora.aerospike.store;
import com.aerospike.client.policy.Policy;
import com.aerospike.client.policy.WritePolicy;
+import java.util.HashMap;
+import java.util.Map;
+
public class AerospikeMapping {
private String namespace;
private String set;
private WritePolicy writePolicy;
private Policy readPolicy;
+ private Map<String, String> binMapping;
public AerospikeMapping() {
writePolicy = new WritePolicy();
readPolicy = new Policy();
+ binMapping = new HashMap<>();
}
public String getNamespace() {
@@ -61,4 +66,12 @@ public class AerospikeMapping {
public void setReadPolicy(Policy readPolicy) {
this.readPolicy = readPolicy;
}
+
+ public Map<String, String> getBinMapping() {
+ return binMapping;
+ }
+
+ public void setBinMapping(Map<String, String> binMapping) {
+ this.binMapping = binMapping;
+ }
}
http://git-wip-us.apache.org/repos/asf/gora/blob/b0c19774/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
index 8744709..7b422f1 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
@@ -25,12 +25,14 @@ import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import org.jdom.JDOMException;
import javax.naming.ConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
+import java.util.HashMap;
public class AerospikeMappingBuilder {
@@ -38,107 +40,108 @@ public class AerospikeMappingBuilder {
private AerospikeMapping aerospikeMapping;
- public AerospikeMappingBuilder(String mappingFile, Class<?> keyClass, Class<?> persistentClass) throws IOException {
+ public AerospikeMappingBuilder() throws IOException {
this.aerospikeMapping = new AerospikeMapping();
- this.readMappingFile(mappingFile, keyClass, persistentClass);
}
public AerospikeMapping getAerospikeMapping() {
return this.aerospikeMapping;
}
- private void readMappingFile(String fileName, Class<?> keyClass, Class<?> persistentClass) throws IOException {
- try {
- SAXBuilder saxBuilder = new SAXBuilder();
- InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName);
- if (inputStream == null) {
- LOG.warn("Mapping file '" + fileName + "' could not be found!");
- throw new IOException("Mapping file '" + fileName + "' could not be found!");
- }
- Document document = saxBuilder.build(inputStream);
- if (document == null) {
- LOG.warn("Mapping file '" + fileName + "' could not be found!");
- throw new IOException("Mapping file '" + fileName + "' could not be found!");
- }
+ public void readMappingFile(String mappingFile, Class<?> keyClass, Class<?> persistentClass)
+ throws IOException, JDOMException, ConfigurationException {
- Element root = document.getRootElement();
-
- // Mapping the defined policies
- List<Element> policyElements = root.getChildren("policy");
-
- for (Element policyElement : policyElements) {
-
- String policy = policyElement.getAttributeValue("name");
- if (policy != null) {
- if (policy.equals("write")) {
- WritePolicy writePolicy = new WritePolicy();
- if (policyElement.getAttributeValue("gen") != null)
- writePolicy.generationPolicy = getGenerationPolicyMapping(policyElement.getAttributeValue
- ("gen").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("exists") != null)
- writePolicy.recordExistsAction = getRecordExistsAction(policyElement.getAttributeValue
- ("exists").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("key") != null)
- writePolicy.sendKey = getKeyUsagePolicy(policyElement.getAttributeValue("key").toUpperCase
- (Locale.getDefault()));
- if (policyElement.getAttributeValue("retry") != null)
- writePolicy.retryOnTimeout = getRetryOnTimeoutPolicy(policyElement.getAttributeValue
- ("retry").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("timeout") != null)
- writePolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
- aerospikeMapping.setWritePolicy(writePolicy);
- } else if (policy.equals("read")) {
- Policy readPolicy = new Policy();
- if (policyElement.getAttributeValue("key") != null)
- readPolicy.sendKey = getKeyUsagePolicy(policyElement.getAttributeValue("key").toUpperCase(Locale
- .getDefault()));
- if (policyElement.getAttributeValue("timeout") != null)
- readPolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
- aerospikeMapping.setReadPolicy(readPolicy);
- }
+ SAXBuilder saxBuilder = new SAXBuilder();
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream(mappingFile);
+ if (inputStream == null) {
+ LOG.warn("Mapping file '" + mappingFile + "' could not be found!");
+ throw new IOException("Mapping file '" + mappingFile + "' could not be found!");
+ }
+ Document document = saxBuilder.build(inputStream);
+ if (document == null) {
+ LOG.warn("Mapping file '" + mappingFile + "' could not be found!");
+ throw new IOException("Mapping file '" + mappingFile + "' could not be found!");
+ }
+
+ Element root = document.getRootElement();
+
+ List<Element> policyElements = root.getChildren("policy");
+
+ for (Element policyElement : policyElements) {
+
+ String policy = policyElement.getAttributeValue("name");
+ if (policy != null) {
+ if (policy.equals("write")) {
+ WritePolicy writePolicy = new WritePolicy();
+ if (policyElement.getAttributeValue("gen") != null)
+ writePolicy.generationPolicy = getGenerationPolicyMapping(
+ policyElement.getAttributeValue("gen").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("exists") != null)
+ writePolicy.recordExistsAction = getRecordExistsAction(
+ policyElement.getAttributeValue("exists").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("key") != null)
+ writePolicy.sendKey = getKeyUsagePolicy(
+ policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("retry") != null)
+ writePolicy.retryOnTimeout = getRetryOnTimeoutPolicy(
+ policyElement.getAttributeValue("retry").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("timeout") != null)
+ writePolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ aerospikeMapping.setWritePolicy(writePolicy);
+ } else if (policy.equals("read")) {
+ Policy readPolicy = new Policy();
+ if (policyElement.getAttributeValue("key") != null)
+ readPolicy.sendKey = getKeyUsagePolicy(
+ policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("timeout") != null)
+ readPolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ aerospikeMapping.setReadPolicy(readPolicy);
}
}
+ }
+
+ List<Element> classElements = root.getChildren("class");
- // Mapping the defined classes
- List<Element> classElements = root.getChildren("class");
+ boolean persistentClassAndKeyClassMatches = false;
+ for (Element classElement : classElements) {
- boolean persistentAndKeyClassMatches = false;
- for (Element classElement : classElements) {
+ String mappingKeyClass = classElement.getAttributeValue("keyClass");
+ String mappingClassName = classElement.getAttributeValue("name");
- String mappingKeyClass = classElement.getAttributeValue("keyClass");
- String mappingClassName = classElement.getAttributeValue("name");
+ if (mappingKeyClass != null && mappingClassName != null) {
+ if (mappingKeyClass.equals(keyClass.getCanonicalName()) && mappingClassName
+ .equals(persistentClass.getCanonicalName())) {
- if (mappingKeyClass != null && mappingClassName != null) {
- if (mappingKeyClass.equals(keyClass.getCanonicalName())
- && mappingClassName.equals(persistentClass.getCanonicalName())) {
+ persistentClassAndKeyClassMatches = true;
- persistentAndKeyClassMatches = true;
+ List<Element> fields = classElement.getChildren("field");
+ Map<String, String> binMapping = new HashMap<>();
+ for (Element field : fields) {
+ String fieldName = field.getAttributeValue("name");
+ String binName = field.getAttributeValue("bin");
+ if (fieldName != null && binName != null)
+ binMapping.put(fieldName, binName);
+ }
+ aerospikeMapping.setBinMapping(binMapping);
- String nameSpace = classElement.getAttributeValue("namespace");
- if (nameSpace == null || nameSpace.isEmpty()) {
- throw new ConfigurationException("Gora-aerospike-mapping does not include the relevant namespace for " +
- "the class");
- }
- aerospikeMapping.setNamespace(nameSpace);
+ String nameSpace = classElement.getAttributeValue("namespace");
+ if (nameSpace == null || nameSpace.isEmpty()) {
+ throw new ConfigurationException(
+ "Gora-aerospike-mapping does not include the relevant namespace for "
+ + "the class");
+ }
+ aerospikeMapping.setNamespace(nameSpace);
- String set = classElement.getAttributeValue("set");
- if (set != null && !set.isEmpty()) {
- aerospikeMapping.setSet(set);
- }
+ String set = classElement.getAttributeValue("set");
+ if (set != null && !set.isEmpty()) {
+ aerospikeMapping.setSet(set);
}
}
-
}
- if (!persistentAndKeyClassMatches)
- throw new ConfigurationException("Gora-aerospike-mapping does not include the name and keyClass in the " +
- "databean");
- } catch (IOException e) {
- LOG.error(e.getMessage(), e);
- throw new IOException(e);
- } catch (Exception e) {
- LOG.error(e.getMessage(), e);
- throw new IOException(e);
}
+ if (!persistentClassAndKeyClassMatches)
+ throw new ConfigurationException(
+ "Gora-aerospike-mapping does not include the name and keyClass in the databean");
}
private GenerationPolicy getGenerationPolicyMapping(String genPolicy) {
http://git-wip-us.apache.org/repos/asf/gora/blob/b0c19774/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index c8610e1..c452857 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -42,60 +42,59 @@ import org.slf4j.LoggerFactory;
public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K, T> {
public static final Logger LOG = LoggerFactory.getLogger(AerospikeStore.class);
+
private static final String PARSE_MAPPING_FILE_KEY = "gora.aerospike.mapping.file";
- private static final String DEFAULT_MAPPING_FILE = "gora-aerospike-mapping.xml";
+ private static final String DEFAULT_MAPPING_FILE = "gora-aerospike-mapping.xml";
private AerospikeClient aerospikeClient;
+
private AerospikeParameters aerospikeParameters;
- @Override
- public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) {
+ @Override public void initialize(Class<K> keyClass, Class<T> persistentClass,
+ Properties properties) {
super.initialize(keyClass, persistentClass, properties);
try {
- AerospikeMappingBuilder aerospikeMappingBuilder = new AerospikeMappingBuilder(getConf().get
- (PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE), keyClass,
- persistentClass);
- aerospikeParameters = new AerospikeParameters(aerospikeMappingBuilder.getAerospikeMapping(), properties);
+ AerospikeMappingBuilder aerospikeMappingBuilder = new AerospikeMappingBuilder();
+ aerospikeMappingBuilder
+ .readMappingFile(getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE),
+ keyClass, persistentClass);
+ aerospikeParameters = new AerospikeParameters(aerospikeMappingBuilder.getAerospikeMapping(),
+ properties);
ClientPolicy policy = new ClientPolicy();
policy.writePolicyDefault = aerospikeParameters.getAerospikeMapping().getWritePolicy();
policy.readPolicyDefault = aerospikeParameters.getAerospikeMapping().getReadPolicy();
- aerospikeClient = new AerospikeClient(aerospikeParameters.getHost(), aerospikeParameters.getPort());
+ aerospikeClient = new AerospikeClient(aerospikeParameters.getHost(),
+ aerospikeParameters.getPort());
aerospikeParameters.setServerSpecificParameters(aerospikeClient);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
- @Override
- public String getSchemaName() {
+ @Override public String getSchemaName() {
return null;
}
- @Override
- public void createSchema() {
+ @Override public void createSchema() {
}
- @Override
- public void deleteSchema() {
+ @Override public void deleteSchema() {
}
- @Override
- public boolean schemaExists() {
+ @Override public boolean schemaExists() {
return true;
}
- @Override
- public T get(K key, String[] fields) {
+ @Override public T get(K key, String[] fields) {
return null;
}
- @Override
- public void put(K key, T value) {
+ @Override public void put(K key, T value) {
- Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(), aerospikeParameters
- .getAerospikeMapping().getSet(), Value.get(key));
+ Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
+ aerospikeParameters.getAerospikeMapping().getSet(), Value.get(key));
List<Field> fields = value.getSchema().getFields();
@@ -104,40 +103,35 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
// In retrieving the bin name, it is checked whether the server is single bin valued
String binName = aerospikeParameters.getBinName(fields.get(i).name());
Bin bin = getBin(binName, value.get(i), fields.get(i));
- aerospikeClient.put(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey, bin);
+ aerospikeClient
+ .put(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey, bin);
}
}
- @Override
- public boolean delete(K key) {
+ @Override public boolean delete(K key) {
return true;
}
- @Override
- public long deleteByQuery(Query<K, T> query) {
+ @Override public long deleteByQuery(Query<K, T> query) {
return 0;
}
- @Override
- public Result<K, T> execute(Query<K, T> query) {
+ @Override public Result<K, T> execute(Query<K, T> query) {
return null;
}
- @Override
- public Query<K, T> newQuery() {
+ @Override public Query<K, T> newQuery() {
return null;
}
- @Override
- public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
+ @Override public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
return null;
}
public void flush() {
}
- @Override
- public void close() {
+ @Override public void close() {
aerospikeClient.close();
}
@@ -148,17 +142,17 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
* and returns the Bin
*
* @param binName name of the bin
- * @param value value of the bin
- * @param field field corresponding to bin
+ * @param value value of the bin
+ * @param field field corresponding to bin
* @return
*/
- private Bin getBin(String binName, Object value, Field field){
-
+ private Bin getBin(String binName, Object value, Field field) {
+
boolean isStringType = false;
if (field.schema().getType().equals(Schema.Type.STRING))
isStringType = true;
- if (field.schema().getType().equals(Schema.Type.UNION)){
- for (Schema schema :field.schema().getTypes()) {
+ if (field.schema().getType().equals(Schema.Type.UNION)) {
+ for (Schema schema : field.schema().getTypes()) {
if (schema.getName().equals("string"))
isStringType = true;
}
[30/32] gora git commit: Add dependency management for test-containers
Posted by dj...@apache.org.
Add dependency management for test-containers
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/38037ca9
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/38037ca9
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/38037ca9
Branch: refs/heads/master
Commit: 38037ca9530c84c8b7d88284d19b47bbc3f0ab58
Parents: 9c38409
Author: nishadi <nd...@gmail.com>
Authored: Thu Jul 27 14:07:07 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jul 27 22:33:54 2017 +0530
----------------------------------------------------------------------
gora-aerospike/pom.xml | 1 -
gora-couchdb/pom.xml | 1 -
pom.xml | 7 +++++++
3 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/38037ca9/gora-aerospike/pom.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/pom.xml b/gora-aerospike/pom.xml
index a70c3e4..c8cab41 100644
--- a/gora-aerospike/pom.xml
+++ b/gora-aerospike/pom.xml
@@ -165,7 +165,6 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
- <version>1.1.0</version>
<scope>test</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/gora/blob/38037ca9/gora-couchdb/pom.xml
----------------------------------------------------------------------
diff --git a/gora-couchdb/pom.xml b/gora-couchdb/pom.xml
index f23c097..163ed4a 100644
--- a/gora-couchdb/pom.xml
+++ b/gora-couchdb/pom.xml
@@ -217,7 +217,6 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
- <version>1.1.0</version>
<scope>test</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/gora/blob/38037ca9/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2d05a71..09af363 100644
--- a/pom.xml
+++ b/pom.xml
@@ -780,6 +780,7 @@
<!-- Testing Dependencies -->
<junit.version>4.10</junit.version>
+ <test.container.version>1.4.2</test.container.version>
<!-- Maven Plugin Dependencies -->
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
@@ -1538,6 +1539,12 @@
<version>4.4</version>
</dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <version>${test.container.version}</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>
[12/32] gora git commit: Update put and get functionality with
support for different AVRO data types
Posted by dj...@apache.org.
Update put and get functionality with support for different AVRO data types
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/27b015e5
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/27b015e5
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/27b015e5
Branch: refs/heads/master
Commit: 27b015e5dfdb67f8530e7c110d36aa55d0e42cb1
Parents: 7c3390d
Author: nishadi <nd...@gmail.com>
Authored: Mon Jun 26 18:35:02 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Mon Jun 26 18:35:02 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/store/AerospikeStore.java | 310 +++++++++++++++----
1 file changed, 246 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/27b015e5/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 9ff3c60..5a880d6 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -17,18 +17,31 @@
package org.apache.gora.aerospike.store;
import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
import java.util.Properties;
-import com.aerospike.client.*;
+import com.aerospike.client.Key;
+import com.aerospike.client.Value;
+import com.aerospike.client.Bin;
+import com.aerospike.client.Record;
+import com.aerospike.client.AerospikeClient;
import com.aerospike.client.policy.ClientPolicy;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
+import org.apache.avro.util.Utf8;
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.persistency.impl.DirtyListWrapper;
+import org.apache.gora.persistency.impl.DirtyMapWrapper;
import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.PartitionQuery;
import org.apache.gora.query.Query;
import org.apache.gora.query.Result;
import org.apache.gora.store.impl.DataStoreBase;
+import org.apache.gora.util.AvroUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,19 +93,41 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
LOG.info("Aerospike Gora datastore initialized successfully.");
}
+ /**
+ * Aerospike, being a schemaless database does not support explicit schema creation through the
+ * provided java client. When the records are added to the database, the schema is created on
+ * the fly. Thus, schema related functionality is unavailable in gora-aerospike module.
+ *
+ * @return null
+ */
@Override
public String getSchemaName() {
return null;
}
+ /**
+ * Aerospike, being a schemaless database does not support explicit schema creation through the
+ * provided java client. When the records are added to the database, the schema is created on
+ * the fly. Thus, schema creation functionality is unavailable in gora-aerospike module.
+ */
@Override
public void createSchema() {
}
+ /**
+ * Aerospike, being a schemaless database does not support explicit schema creation through the
+ * provided java client. When the records are added to the database, the schema is created on
+ * the fly. Thus, schema deletion functionality is unavailable in gora-aerospike module.
+ */
@Override
public void deleteSchema() {
}
+ /**
+ * Aerospike, being a schemaless database does not support explicit schema creation through the
+ * provided java client. When the records are added to the database, the schema is created on
+ * the fly. Thus, schema exists functionality is unavailable in gora-aerospike module.
+ */
@Override
public boolean schemaExists() {
return true;
@@ -107,9 +142,17 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
*/
@Override
public T get(K key, String[] fields) {
+
+ Value keyValue;
+ if (keyClass.getSimpleName().equalsIgnoreCase("string")) {
+ keyValue = Value.get(key.toString());
+ } else {
+ keyValue = Value.get(key);
+ }
+
fields = getFieldsToQuery(fields);
Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
- aerospikeParameters.getAerospikeMapping().getSet(), Value.get(key));
+ aerospikeParameters.getAerospikeMapping().getSet(), keyValue);
Record record = aerospikeClient
.get(aerospikeParameters.getAerospikeMapping().getReadPolicy(), recordKey, fields);
if (record == null) {
@@ -129,23 +172,35 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
@Override
public void put(K key, T persistent) {
+ Value keyValue;
+ if (keyClass.getSimpleName().equalsIgnoreCase("string")) {
+ keyValue = Value.get(key.toString());
+ } else {
+ keyValue = Value.get(key);
+ }
+
Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
- aerospikeParameters.getAerospikeMapping().getSet(), Value.get(key));
+ aerospikeParameters.getAerospikeMapping().getSet(), keyValue);
List<Field> fields = persistent.getSchema().getFields();
for (int i = 0; i < fields.size(); i++) {
- String mappingBinName = aerospikeParameters.getAerospikeMapping().getBinMapping()
- .get(fields.get(i).name());
- if (mappingBinName == null) {
- LOG.error("Aerospike mapping for field {}#{} not found. Wrong gora-aerospike-mapping.xml?",
- persistent.getClass().getName(), fields.get(i).name());
- throw new RuntimeException(
- "Aerospike mapping for field [" + persistent.getClass().getName() + "#" + fields
- .get(i).name() + "] not found. Wrong gora-aerospike-mapping.xml?");
+ Object persistentValue = persistent.get(i);
+ if (persistentValue != null) {
+ String mappingBinName = aerospikeParameters.getAerospikeMapping().getBinMapping()
+ .get(fields.get(i).name());
+ if (mappingBinName == null) {
+ LOG.error(
+ "Aerospike mapping for field {}#{} not found. Wrong gora-aerospike-mapping.xml?",
+ persistent.getClass().getName(), fields.get(i).name());
+ throw new RuntimeException(
+ "Aerospike mapping for field [" + persistent.getClass().getName() + "#" + fields
+ .get(i).name() + "] not found. Wrong gora-aerospike-mapping.xml?");
+ }
+ Bin bin = new Bin(mappingBinName,
+ getSerializableValue(persistentValue, fields.get(i).schema()));
+ aerospikeClient
+ .put(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey, bin);
}
- Bin bin = getBin(mappingBinName, persistent.get(i), fields.get(i));
- aerospikeClient
- .put(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey, bin);
}
}
@@ -188,31 +243,50 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
}
/**
- * Aerospike does not support Utf8 format returned from Avro. This method provides those utf8
- * valued bin (column) values as strings for aerospike Value to obtain the corresponding bin
- * value, and returns the Bin (column in RDBMS)
+ * Method to get the value serializable in database from the Avro persistent object
*
- * @param binName name of the bin
- * @param value value of the bin
- * @param field field corresponding to bin
- * @return Bin
+ * @param object persistent object
+ * @param schema schema of the persistent object
+ * @return serializable value
*/
- private Bin getBin(String binName, Object value, Field field) {
-
- boolean isStringType = false;
- if (field.schema().getType().equals(Schema.Type.STRING))
- isStringType = true;
- if (field.schema().getType().equals(Schema.Type.UNION)) {
- for (Schema schema : field.schema().getTypes()) {
- if (schema.getName().equals("string"))
- isStringType = true;
- }
+ private Value getSerializableValue(Object object, Schema schema) {
+
+ Value value = null;
+ switch (schema.getType()) {
+ case UNION:
+ if (object != null) {
+ int schemaPos = getUnionSchema(object, schema);
+ Schema unionSchema = schema.getTypes().get(schemaPos);
+ value = getSerializableValue(object, unionSchema);
+ }
+ break;
+ case STRING:
+ value = Value.get(object.toString());
+ break;
+ case BYTES:
+ value = Value.get(((ByteBuffer) object).array());
+ break;
+ case MAP:
+ Map<Object, Object> newMap = new HashMap<>();
+ Map<?, ?> fieldMap = (Map<?, ?>) object;
+ for (Object key : fieldMap.keySet()) {
+ newMap.put(key.toString(),
+ getSerializableValue(fieldMap.get(key), schema.getValueType()));
+ }
+ value = Value.get(newMap);
+ break;
+ case ARRAY:
+ List<Object> objectList = new ArrayList<>();
+ for (Object obj : (List<Object>) object) {
+ objectList.add(getSerializableValue(obj, schema.getElementType()));
+ }
+ value = Value.get(objectList);
+ break;
+ default:
+ value = Value.get(object);
+ break;
}
-
- if (isStringType)
- return new Bin(binName, Value.get(value.toString()));
- else
- return new Bin(binName, Value.get(value));
+ return value;
}
/**
@@ -235,46 +309,154 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
/**
* Method to set a field in the persistent object
*
- * @param field field name
+ * @param fieldName field name
* @param record record retrieved from database
* @param persistent persistent object for the field to be set
*/
- private void setPersistentField(String field, Record record, T persistent) {
+ private void setPersistentField(String fieldName, Record record, T persistent) {
- String binName = aerospikeParameters.getAerospikeMapping().getBinName(field);
+ String binName = aerospikeParameters.getAerospikeMapping().getBinName(fieldName);
if (binName == null) {
LOG.error("Aerospike mapping for field {} not found. Wrong gora-aerospike-mapping.xml",
- field);
- throw new RuntimeException("Aerospike mapping for field [" + field + "] not found. "
+ fieldName);
+ throw new RuntimeException("Aerospike mapping for field [" + fieldName + "] not found. "
+ "Wrong gora-aerospike-mapping.xml?");
}
- Schema.Type fieldDataType = fieldMap.get(field).schema().getType();
- String binDataType = record.bins.get(field).getClass().getSimpleName();
+ if (record.bins.get(fieldName) == null) {
+ return;
+ }
+ String binDataType = record.bins.get(fieldName).getClass().getSimpleName();
Object binValue = record.bins.get(binName);
- if (fieldDataType.toString().equalsIgnoreCase(binDataType)) {
- persistent.put(field, record.bins.get(binName));
- } else {
- switch (fieldDataType) {
- case UNION:
- Schema unionSchema = fieldMap.get(field).schema();
- if (unionSchema.getTypes().size() == 2) {
- Schema.Type type0 = unionSchema.getTypes().get(0).getType();
- Schema.Type type1 = unionSchema.getTypes().get(1).getType();
-
- if ((type0.equals(Schema.Type.NULL)) || (type1.equals(Schema.Type.NULL))) {
- persistent.put(field, binValue);
- }
- }
+ persistent.put(fieldName,
+ getDeserializedObject(binValue, binDataType, fieldMap.get(fieldName).schema()));
+ }
+
+ /**
+ * Method to get Avro mapped persistent object from the record retrieved from the database
+ *
+ * @param binValue value retrieved from database
+ * @param binDataType data type of the database value
+ * @param schema corresponding schema in the persistent class
+ * @return persistent object
+ */
+ private Object getDeserializedObject(Object binValue, String binDataType, Schema schema) {
+
+ Object result;
+ switch (schema.getType()) {
+
+ case MAP:
+ Map<String, Object> rawMap = (Map<String, Object>) binValue;
+ Map<Utf8, Object> deserializableMap = new HashMap<>();
+ if (rawMap == null) {
+ result = new DirtyMapWrapper(deserializableMap);
break;
- case INT:
- if (binDataType.equalsIgnoreCase("long")) {
- persistent.put(field, Math.toIntExact((Long) binValue));
+ }
+ for (Map.Entry<?, ?> e : rawMap.entrySet()) {
+ Schema innerSchema = schema.getValueType();
+ Object obj = getDeserializedObject(e.getValue(), e.getValue().getClass().getSimpleName(),
+ innerSchema);
+ if (e.getKey().getClass().getSimpleName().equalsIgnoreCase("Utf8")) {
+ deserializableMap.put((Utf8) e.getKey(), obj);
+ } else {
+ deserializableMap.put(new Utf8((String) e.getKey()), obj);
}
- break;
- default:
- break;
- }
+ }
+ result = new DirtyMapWrapper<>(deserializableMap);
+ break;
+
+ case ARRAY:
+ List<Object> rawList = (List<Object>) binValue;
+ List<Object> deserializableList = new ArrayList<>();
+ if (rawList == null) {
+ return new DirtyListWrapper(deserializableList);
+ }
+ for (Object item : rawList) {
+ Object obj = getDeserializedObject(item, item.getClass().getSimpleName(),
+ schema.getElementType());
+ deserializableList.add(obj);
+ }
+ result = new DirtyListWrapper<>(deserializableList);
+ break;
+
+ case RECORD:
+ result = (PersistentBase) binValue;
+ break;
+
+ case UNION:
+ int index = getUnionSchema(binValue, schema);
+ Schema resolvedSchema = schema.getTypes().get(index);
+ result = getDeserializedObject(binValue, binDataType, resolvedSchema);
+ break;
+
+ case ENUM:
+ result = AvroUtils.getEnumValue(schema, (String) binValue);
+ break;
+
+ case BYTES:
+ result = ByteBuffer.wrap((byte[]) binValue);
+ break;
+
+ case STRING:
+ if (binValue instanceof org.apache.avro.util.Utf8)
+ result = binValue;
+ else
+ result = new Utf8((String) binValue);
+ break;
+
+ case INT:
+ if (binDataType.equalsIgnoreCase("long")) {
+ result = Math.toIntExact((Long) binValue);
+ } else {
+ result = binValue;
+ }
+ break;
+
+ default:
+ result = binValue;
}
+ return result;
+ }
+
+ /**
+ * Method to retrieve the corresponding schema type index of a particular object having UNION
+ * schema. As UNION type can have one or more types and at a given instance, it holds an object
+ * of only one type of the defined types, this method is used to figure out the corresponding
+ * instance's
+ * schema type index.
+ *
+ * @param instanceValue value that the object holds
+ * @param unionSchema union schema containing all of the data types
+ * @return the unionSchemaPosition corresponding schema position
+ */
+ private int getUnionSchema(Object instanceValue, Schema unionSchema) {
+ int unionSchemaPos = 0;
+ for (Schema currentSchema : unionSchema.getTypes()) {
+ Schema.Type schemaType = currentSchema.getType();
+ if (instanceValue instanceof CharSequence && schemaType.equals(Schema.Type.STRING))
+ return unionSchemaPos;
+ else if (instanceValue instanceof ByteBuffer && schemaType.equals(Schema.Type.BYTES))
+ return unionSchemaPos;
+ else if (instanceValue instanceof byte[] && schemaType.equals(Schema.Type.BYTES))
+ return unionSchemaPos;
+ else if (instanceValue instanceof Integer && schemaType.equals(Schema.Type.INT))
+ return unionSchemaPos;
+ else if (instanceValue instanceof Long && schemaType.equals(Schema.Type.LONG))
+ return unionSchemaPos;
+ else if (instanceValue instanceof Double && schemaType.equals(Schema.Type.DOUBLE))
+ return unionSchemaPos;
+ else if (instanceValue instanceof Float && schemaType.equals(Schema.Type.FLOAT))
+ return unionSchemaPos;
+ else if (instanceValue instanceof Boolean && schemaType.equals(Schema.Type.BOOLEAN))
+ return unionSchemaPos;
+ else if (instanceValue instanceof Map && schemaType.equals(Schema.Type.MAP))
+ return unionSchemaPos;
+ else if (instanceValue instanceof List && schemaType.equals(Schema.Type.ARRAY))
+ return unionSchemaPos;
+ else if (instanceValue instanceof Persistent && schemaType.equals(Schema.Type.RECORD))
+ return unionSchemaPos;
+ unionSchemaPos++;
+ }
+ return 0;
}
}
[21/32] gora git commit: Add delete by query functionality to
aerospike module
Posted by dj...@apache.org.
Add delete by query functionality to aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/c485f5be
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/c485f5be
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/c485f5be
Branch: refs/heads/master
Commit: c485f5bed92b784a4dd915c6fe5d7b95a9990618
Parents: 2d667ed
Author: nishadi <nd...@gmail.com>
Authored: Wed Jul 19 23:35:55 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Wed Jul 19 23:35:55 2017 +0530
----------------------------------------------------------------------
.../aerospike/query/AerospikeQueryResult.java | 1 +
.../gora/aerospike/store/AerospikeStore.java | 20 ++++++++++++++++++-
.../aerospike/store/TestAerospikeStore.java | 21 ++++++++++++++++----
3 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/c485f5be/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
index 8858f34..3ddca3c 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
@@ -73,6 +73,7 @@ public class AerospikeQueryResult<K, T extends Persistent> extends ResultBase<K,
if (offset < 0 || offset > (resultRecords.size() - 1)) {
return false;
}
+ key = (K) resultRecords.get((int) this.offset).getKey().userKey;
persistent = (T) getDataStore()
.createPersistentInstance(resultRecords.get((int) this.offset).getRecord(), fields);
return true;
http://git-wip-us.apache.org/repos/asf/gora/blob/c485f5be/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 7fe7573..dfa8ed9 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -211,9 +211,27 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
.delete(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @param query matching records to this query will be deleted
+ * @return the number of deleted records
+ */
@Override
public long deleteByQuery(Query<K, T> query) {
- return 0;
+ Result<K, T> result = query.execute();
+ int deleteCount = 0;
+ try {
+ while(result.next()) {
+ if(aerospikeClient.delete(null,getAerospikeKey(result.getKey()))){
+ deleteCount++;
+ }
+ }
+ return deleteCount;
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ return -1;
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/gora/blob/c485f5be/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index 317fb12..d88ea1a 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -19,12 +19,17 @@
package org.apache.gora.aerospike.store;
import org.apache.gora.aerospike.GoraAerospikeTestDriver;
+import org.apache.gora.examples.WebPageDataCreator;
+import org.apache.gora.examples.generated.WebPage;
+import org.apache.gora.query.Query;
import org.apache.gora.store.DataStoreTestBase;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
+import static org.apache.gora.examples.WebPageDataCreator.URLS;
+
/**
* Test case for AerospikeStore.
*/
@@ -85,11 +90,14 @@ public class TestAerospikeStore extends DataStoreTestBase {
}
@Test
- @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testQuery() throws Exception {
- //done
- //ToDo: clear the data before executing
+ // Clearing the test data in the database
+ Query<String, WebPage> query;
+ WebPageDataCreator.createWebPageData(webPageStore);
+ query = webPageStore.newQuery();
+ webPageStore.deleteByQuery(query);
+
super.testQuery();
}
@@ -115,9 +123,14 @@ public class TestAerospikeStore extends DataStoreTestBase {
}
@Test
- @Ignore("Functionality is to be implemented in the next iteration as this incurs query execution")
@Override
public void testDelete() throws Exception {
+ // Clearing the test data in the database
+ Query<String, WebPage> query;
+ WebPageDataCreator.createWebPageData(webPageStore);
+ query = webPageStore.newQuery();
+ webPageStore.deleteByQuery(query);
+
super.testDelete();
}
[11/32] gora git commit: Add initial test base for aerorospike module
Posted by dj...@apache.org.
Add initial test base for aerorospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/7c3390d0
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/7c3390d0
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/7c3390d0
Branch: refs/heads/master
Commit: 7c3390d0a7cf72afe3ffb3e3748f993e85cce48b
Parents: d68be8d
Author: nishadi <nd...@gmail.com>
Authored: Fri Jun 23 19:37:05 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Fri Jun 23 19:37:05 2017 +0530
----------------------------------------------------------------------
gora-aerospike/pom.xml | 9 +-
.../src/test/conf/gora-aerospike-mapping.xml | 49 +++
gora-aerospike/src/test/conf/gora.properties | 17 +
.../gora/aerospike/GoraAerospikeTestDriver.java | 74 +++++
.../org/apache/gora/aerospike/package-info.java | 17 +
.../aerospike/store/TestAerospikeStore.java | 330 +++++++++++++++++++
.../gora/aerospike/store/package-info.java | 21 ++
pom.xml | 6 +
8 files changed, 522 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/7c3390d0/gora-aerospike/pom.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/pom.xml b/gora-aerospike/pom.xml
index b15693e..828f45d 100644
--- a/gora-aerospike/pom.xml
+++ b/gora-aerospike/pom.xml
@@ -63,7 +63,7 @@
<sourceDirectory>src/main/java</sourceDirectory>
<testResources>
<testResource>
- <directory>${project.basedir}/src/test/resources</directory>
+ <directory>${project.basedir}/src/test/conf</directory>
<includes>
<include>**/*</include>
</includes>
@@ -141,6 +141,13 @@
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <version>1.1.0</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/gora/blob/7c3390d0/gora-aerospike/src/test/conf/gora-aerospike-mapping.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/conf/gora-aerospike-mapping.xml b/gora-aerospike/src/test/conf/gora-aerospike-mapping.xml
new file mode 100644
index 0000000..f3f6eee
--- /dev/null
+++ b/gora-aerospike/src/test/conf/gora-aerospike-mapping.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<gora-otd>
+
+ <class name="org.apache.gora.examples.generated.Employee" keyClass="java.lang.String"
+ set="Employee" namespace = "test">
+ <field name="name" bin="name"/>
+ <field name="dateOfBirth" bin="dateOfBirth"/>
+ <field name="ssn" bin="ssn"/>
+ <field name="salary" bin="salary"/>
+ <field name="boss" bin="boss"/>
+ <field name="webpage" bin="webpage"/>
+ </class>
+
+ <class name="org.apache.gora.examples.generated.WebPage" keyClass="java.lang.String"
+ table="WebPage" namespace = "test">
+ <field name="url" bin="url"/>
+ <field name="content" bin="content"/>
+ <field name="parsedContent" bin="parsedContent"/>
+ <field name="outlinks" bin="outlinks"/>
+ <field name="headers" bin="headers"/>
+ <field name="metadata" bin="metadata"/>
+ <field name="byteData" bin="byteData"/>
+ <field name="stringData" bin="stringData"/>
+ </class>
+
+
+ <class name="org.apache.gora.examples.generated.TokenDatum" keyClass="java.lang.String" namespace = "test">
+ <field name="count" bin="count"/>
+ </class>
+
+</gora-otd>
http://git-wip-us.apache.org/repos/asf/gora/blob/7c3390d0/gora-aerospike/src/test/conf/gora.properties
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/conf/gora.properties b/gora-aerospike/src/test/conf/gora.properties
new file mode 100644
index 0000000..c0230ec
--- /dev/null
+++ b/gora-aerospike/src/test/conf/gora.properties
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+gora.datastore.default=org.apache.gora.aerospike.store.AerospikeStore
+gora.datastore.mapping.file=gora-aerospike-mapping.xml
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/gora/blob/7c3390d0/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
new file mode 100644
index 0000000..1281d9b
--- /dev/null
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.aerospike;
+
+import org.apache.gora.GoraTestDriver;
+import org.apache.gora.aerospike.store.AerospikeStore;
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.store.DataStore;
+import org.apache.gora.store.DataStoreFactory;
+import org.apache.gora.util.GoraException;
+import org.testcontainers.containers.GenericContainer;
+
+import java.util.Properties;
+
+/**
+ * Helper class for third part tests using gora-aerospike backend.
+ * @see GoraTestDriver
+ */
+public class GoraAerospikeTestDriver extends GoraTestDriver {
+
+ private GenericContainer aerospikeContainer;
+ private Properties properties = DataStoreFactory.createProps();
+
+ public GoraAerospikeTestDriver(GenericContainer aerospikeContainer) {
+ super(AerospikeStore.class);
+ this.aerospikeContainer = aerospikeContainer;
+ }
+
+ @Override
+ public void setUpClass() throws Exception {
+ properties.setProperty("server.ip", "localhost");
+ properties.setProperty("server.port", aerospikeContainer.getMappedPort(3000).toString());
+ }
+
+ @Override
+ public void tearDownClass() throws Exception {
+ }
+
+ /**
+ * Instantiate a new {@link DataStore}. Uses 'null' schema.
+ *
+ * @param keyClass The key class.
+ * @param persistentClass The value class.
+ * @return A new store instance.
+ * @throws GoraException
+ */
+ @Override
+ public <K, T extends Persistent> DataStore<K, T> createDataStore(Class<K> keyClass, Class<T> persistentClass)
+ throws GoraException {
+
+ final DataStore<K, T> dataStore = DataStoreFactory
+ .createDataStore((Class<? extends DataStore<K, T>>) dataStoreClass, keyClass, persistentClass, conf,
+ properties);
+ dataStores.add(dataStore);
+ log.info("Datastore for {} was added.", persistentClass);
+ return dataStore;
+ }
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/7c3390d0/gora-aerospike/src/test/java/org/apache/gora/aerospike/package-info.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/package-info.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/package-info.java
new file mode 100644
index 0000000..9eb6fbf
--- /dev/null
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/package-info.java
@@ -0,0 +1,17 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gora.aerospike;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/gora/blob/7c3390d0/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
new file mode 100644
index 0000000..e1af3cd
--- /dev/null
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -0,0 +1,330 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.aerospike.store;
+
+import org.apache.gora.aerospike.GoraAerospikeTestDriver;
+import org.apache.gora.examples.generated.Employee;
+import org.apache.gora.examples.generated.WebPage;
+import org.apache.gora.store.DataStoreFactory;
+import org.apache.gora.store.DataStoreTestBase;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.testcontainers.containers.GenericContainer;
+
+import java.io.IOException;
+
+/**
+ * Test case for AerospikeStore.
+ */
+public class TestAerospikeStore extends DataStoreTestBase {
+
+ private static final String DOCKER_CONTAINER_NAME = "aerospike:3.14.0";
+
+ @ClassRule
+ public static GenericContainer aerospikeContainer = new GenericContainer(DOCKER_CONTAINER_NAME);
+
+ static {
+ setTestDriver(new GoraAerospikeTestDriver(aerospikeContainer));
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testNewInstance() throws Exception {
+ // super.testNewInstance();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testCreateSchema() throws Exception {
+ // super.testCreateSchema();
+ }
+
+ @Override
+ public void assertSchemaExists(String schemaName) throws Exception {
+ super.assertSchemaExists(schemaName);
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testAutoCreateSchema() throws Exception {
+ super.testAutoCreateSchema();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void assertAutoCreateSchema() throws Exception {
+ super.assertAutoCreateSchema();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testTruncateSchema() throws Exception {
+ super.testTruncateSchema();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testDeleteSchema() throws Exception {
+ super.testDeleteSchema();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testSchemaExists() throws Exception {
+ super.testSchemaExists();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testPut() throws Exception {
+ super.testPut();
+ }
+
+ @Override
+ public void assertPut(Employee employee) throws IOException {
+ super.assertPut(employee);
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testPutNested() throws Exception {
+ super.testPutNested();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testPutArray() throws Exception {
+ super.testPutArray();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void assertPutArray() throws IOException {
+ super.assertPutArray();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testPutBytes() throws Exception {
+ super.testPutBytes();
+ }
+
+ @Override
+ public void assertPutBytes(byte[] contentBytes) throws IOException {
+ super.assertPutBytes(contentBytes);
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testPutMap() throws Exception {
+ super.testPutMap();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void assertPutMap() throws IOException {
+ super.assertPutMap();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testPutMixedMaps() throws Exception {
+ super.testPutMixedMaps();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testUpdate() throws Exception {
+ super.testUpdate();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testEmptyUpdate() throws Exception {
+ super.testEmptyUpdate();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGet() throws Exception {
+ super.testGet();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGetRecursive() throws Exception {
+ super.testGetRecursive();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGetDoubleRecursive() throws Exception {
+ super.testGetDoubleRecursive();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGetNested() throws Exception {
+ super.testGetNested();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGet3UnionField() throws Exception {
+ super.testGet3UnionField();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGetWithFields() throws Exception {
+ super.testGetWithFields();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGetWebPage() throws Exception {
+ super.testGetWebPage();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGetWebPageDefaultFields() throws Exception {
+ super.testGetWebPageDefaultFields();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGetNonExisting() throws Exception {
+ super.testGetNonExisting();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testQuery() throws Exception {
+ super.testQuery();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testQueryStartKey() throws Exception {
+ super.testQueryStartKey();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testQueryEndKey() throws Exception {
+ super.testQueryEndKey();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testQueryKeyRange() throws Exception {
+ super.testQueryKeyRange();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testQueryWebPageSingleKey() throws Exception {
+ super.testQueryWebPageSingleKey();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testQueryWebPageSingleKeyDefaultFields() throws Exception {
+ super.testQueryWebPageSingleKeyDefaultFields();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testQueryWebPageQueryEmptyResults() throws Exception {
+ super.testQueryWebPageQueryEmptyResults();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testDelete() throws Exception {
+ super.testDelete();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testDeleteByQuery() throws Exception {
+ super.testDeleteByQuery();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testDeleteByQueryFields() throws Exception {
+ super.testDeleteByQueryFields();
+ }
+
+ @Test
+ @Ignore("To be implemented")
+ @Override
+ public void testGetPartitions() throws Exception {
+ super.testGetPartitions();
+ }
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/7c3390d0/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/package-info.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/package-info.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/package-info.java
new file mode 100644
index 0000000..69670f8
--- /dev/null
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * This package contains all the unit tests for basic CRUD operations
+ * functionality of the Aerospike dataStore.
+ */
+package org.apache.gora.aerospike.store;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/gora/blob/7c3390d0/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b81d7e6..2d05a71 100644
--- a/pom.xml
+++ b/pom.xml
@@ -939,6 +939,12 @@
<artifactId>gora-aerospike</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.gora</groupId>
+ <artifactId>gora-aerospike</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
<!-- End of Internal Depednecies -->
<dependency>
[20/32] gora git commit: Add initial query model for gora-aerospike
Posted by dj...@apache.org.
Add initial query model for gora-aerospike
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/2d667edb
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/2d667edb
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/2d667edb
Branch: refs/heads/master
Commit: 2d667edb08ac241e857c9922d05f13a00c91fdc3
Parents: ecd3c59
Author: nishadi <nd...@gmail.com>
Authored: Wed Jul 19 20:44:57 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Wed Jul 19 20:44:57 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/query/AerospikeQuery.java | 33 +++++++
.../aerospike/query/AerospikeQueryResult.java | 80 ++++++++++++++++
.../aerospike/query/AerospikeResultRecord.java | 51 ++++++++++
.../gora/aerospike/store/AerospikeStore.java | 99 +++++++++++++++++++-
.../src/test/conf/gora-aerospike-mapping.xml | 2 +-
.../aerospike/store/TestAerospikeStore.java | 23 +----
6 files changed, 262 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/2d667edb/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQuery.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQuery.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQuery.java
new file mode 100644
index 0000000..d87fe6a
--- /dev/null
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQuery.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gora.aerospike.query;
+
+import org.apache.gora.persistency.impl.PersistentBase;
+import org.apache.gora.query.Query;
+import org.apache.gora.query.impl.QueryBase;
+import org.apache.gora.store.DataStore;
+
+/**
+ * Aerospike specific implementation of the {@link Query} interface.
+ */
+public class AerospikeQuery<K, T extends PersistentBase> extends QueryBase<K, T> {
+ public AerospikeQuery(DataStore<K, T> dataStore) {
+ super(dataStore);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/2d667edb/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
new file mode 100644
index 0000000..8858f34
--- /dev/null
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gora.aerospike.query;
+
+import com.aerospike.client.Record;
+import com.aerospike.client.query.RecordSet;
+import org.apache.gora.aerospike.store.AerospikeStore;
+import org.apache.gora.persistency.Persistent;
+import org.apache.gora.query.Query;
+import org.apache.gora.query.impl.ResultBase;
+import org.apache.gora.store.DataStore;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Aerospike specific implementation of the {@link org.apache.gora.query.Result}
+ * interface.
+ */
+public class AerospikeQueryResult<K, T extends Persistent> extends ResultBase<K, T> {
+
+ private List<AerospikeResultRecord> resultRecords;
+
+ private String[] fields;
+
+ public AerospikeQueryResult(DataStore<K, T> dataStore, Query<K, T> query,
+ List<AerospikeResultRecord> recordsList, String[] fields) {
+ super(dataStore, query);
+ this.resultRecords = recordsList;
+ this.fields = fields;
+ }
+
+ @Override
+ public float getProgress() throws IOException, InterruptedException {
+ //ToDo: to be implemented
+ return 0;
+ }
+
+ /**
+ * Method to get the Aerospike specific data store
+ *
+ * @return the Aerospike data store instance
+ */
+ @Override
+ public AerospikeStore getDataStore() {
+ return (AerospikeStore) super.getDataStore();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return true if more elements exist
+ * @throws IOException if we reach non-existent result
+ */
+ @Override
+ protected boolean nextInner() throws IOException {
+ if (offset < 0 || offset > (resultRecords.size() - 1)) {
+ return false;
+ }
+ persistent = (T) getDataStore()
+ .createPersistentInstance(resultRecords.get((int) this.offset).getRecord(), fields);
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/2d667edb/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeResultRecord.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeResultRecord.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeResultRecord.java
new file mode 100644
index 0000000..07d4309
--- /dev/null
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeResultRecord.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gora.aerospike.query;
+
+import com.aerospike.client.Key;
+import com.aerospike.client.Record;
+
+/**
+ * Class to hold Aerospike result records
+ */
+public class AerospikeResultRecord {
+
+ private Key key;
+ private Record record;
+
+ public AerospikeResultRecord(Key key, Record record) {
+ this.key = key;
+ this.record = record;
+ }
+
+ public Key getKey() {
+ return key;
+ }
+
+ public void setKey(Key key) {
+ this.key = key;
+ }
+
+ public Record getRecord() {
+ return record;
+ }
+
+ public void setRecord(Record record) {
+ this.record = record;
+ }
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/2d667edb/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 01fdd93..7fe7573 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -30,9 +30,14 @@ import com.aerospike.client.Bin;
import com.aerospike.client.Record;
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.policy.ClientPolicy;
+import com.aerospike.client.query.RecordSet;
+import com.aerospike.client.query.Statement;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
import org.apache.avro.util.Utf8;
+import org.apache.gora.aerospike.query.AerospikeQuery;
+import org.apache.gora.aerospike.query.AerospikeQueryResult;
+import org.apache.gora.aerospike.query.AerospikeResultRecord;
import org.apache.gora.persistency.Persistent;
import org.apache.gora.persistency.impl.DirtyListWrapper;
import org.apache.gora.persistency.impl.DirtyMapWrapper;
@@ -86,7 +91,11 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
policy.writePolicyDefault = aerospikeParameters.getAerospikeMapping().getWritePolicy();
policy.readPolicyDefault = aerospikeParameters.getAerospikeMapping().getReadPolicy();
- aerospikeClient = new AerospikeClient(aerospikeParameters.getHost(),
+ // 'SendKey' property is enabled by default as the key is needed in query execution
+ policy.readPolicyDefault.sendKey = true;
+ policy.writePolicyDefault.sendKey = true;
+
+ aerospikeClient = new AerospikeClient(policy, aerospikeParameters.getHost(),
aerospikeParameters.getPort());
aerospikeParameters.setServerSpecificParameters(aerospikeClient);
aerospikeParameters.validateServerBinConfiguration(persistentClass.getFields());
@@ -207,14 +216,83 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
return 0;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @param query the query to execute.
+ * @return the query result
+ */
@Override
public Result<K, T> execute(Query<K, T> query) {
- return null;
+
+ List<AerospikeResultRecord> resultRecords = new ArrayList<>();
+ String namespace = aerospikeParameters.getAerospikeMapping().getNamespace();
+ String set = aerospikeParameters.getAerospikeMapping().getSet();
+
+ // Query execution without any keys
+ if (query.getStartKey() == null && query.getEndKey() == null){
+
+ try (RecordSet recordSet = aerospikeClient.query(null, getStatement(namespace, set))) {
+ while (recordSet.next()) {
+ AerospikeResultRecord aerospikeRecord = new AerospikeResultRecord(recordSet.getKey(),
+ recordSet.getRecord());
+ resultRecords.add(aerospikeRecord);
+ }
+ }
+ }
+
+ // Query execution for single key
+ else if (query.getKey()!= null) {
+ Key key = getAerospikeKey(query.getKey());
+ Record record = aerospikeClient.get(null, key);
+ if(record != null){
+ resultRecords.add(new AerospikeResultRecord(key, record));
+ }
+ }
+
+ // Query execution for key ranges
+ // ToDo: Implement for other scenarios
+ else if (query.getStartKey() != null && query.getEndKey() != null) {
+// Key startKey = null, endKey = null;
+// if (query.getStartKey() != null) {
+// startKey = getAerospikeKey(query.getStartKey());
+// }
+// if (query.getEndKey() != null) {
+// endKey = getAerospikeKey(query.getEndKey());
+// }
+
+// boolean isSpecifiedRange = false;
+// try (RecordSet recordSet = aerospikeClient.query(null, getStatement(namespace, set))) {
+// while (recordSet.next()) {
+// Key key = recordSet.getKey();
+// Record record = recordSet.getRecord();
+//
+// if(key.userKey == getAerospikeKey(query.getStartKey()).userKey){
+// isSpecifiedRange = true;
+// }
+// if(key.userKey == getAerospikeKey(query.getEndKey()).userKey){
+// isSpecifiedRange = false;
+// }
+//
+// if(isSpecifiedRange){
+// AerospikeResultRecord aerospikeRecord = new AerospikeResultRecord(key,record);
+// resultRecords.add(aerospikeRecord);
+// }
+//
+// }
+ }
+
+ return new AerospikeQueryResult<>(this, query, resultRecords, getFieldsToQuery(null));
}
+ /**
+ * {@inheritDoc}
+ *
+ * @return the new query corresponding to aerospike
+ */
@Override
public Query<K, T> newQuery() {
- return null;
+ return new AerospikeQuery<>(this);
}
@Override
@@ -227,6 +305,19 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
}
/**
+ * Method to create a statement
+ *
+ * @param namespace the namespace
+ * @param set the set
+ * @return the statement
+ */
+ private Statement getStatement(String namespace, String set){
+ Statement stmt = new Statement();
+ stmt.setNamespace(namespace);
+ stmt.setSetName(set);
+ return stmt;
+ }
+ /**
* Method to close aerospike client connections to database server nodes
*/
@Override
@@ -309,7 +400,7 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
* @param fields fields
* @return persistent object created
*/
- private T createPersistentInstance(Record record, String[] fields) {
+ public T createPersistentInstance(Record record, String[] fields) {
T persistent = newPersistent();
for (String field : fields) {
http://git-wip-us.apache.org/repos/asf/gora/blob/2d667edb/gora-aerospike/src/test/conf/gora-aerospike-mapping.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/conf/gora-aerospike-mapping.xml b/gora-aerospike/src/test/conf/gora-aerospike-mapping.xml
index f3f6eee..d57edb0 100644
--- a/gora-aerospike/src/test/conf/gora-aerospike-mapping.xml
+++ b/gora-aerospike/src/test/conf/gora-aerospike-mapping.xml
@@ -30,7 +30,7 @@
</class>
<class name="org.apache.gora.examples.generated.WebPage" keyClass="java.lang.String"
- table="WebPage" namespace = "test">
+ set="WebPage" namespace = "test">
<field name="url" bin="url"/>
<field name="content" bin="content"/>
<field name="parsedContent" bin="parsedContent"/>
http://git-wip-us.apache.org/repos/asf/gora/blob/2d667edb/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index 9e93fb0..317fb12 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -88,6 +88,8 @@ public class TestAerospikeStore extends DataStoreTestBase {
@Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testQuery() throws Exception {
+ //done
+ //ToDo: clear the data before executing
super.testQuery();
}
@@ -113,27 +115,6 @@ public class TestAerospikeStore extends DataStoreTestBase {
}
@Test
- @Ignore("Functionality is to be implemented in the next iteration")
- @Override
- public void testQueryWebPageSingleKey() throws Exception {
- super.testQueryWebPageSingleKey();
- }
-
- @Test
- @Ignore("Functionality is to be implemented in the next iteration")
- @Override
- public void testQueryWebPageSingleKeyDefaultFields() throws Exception {
- super.testQueryWebPageSingleKeyDefaultFields();
- }
-
- @Test
- @Ignore("Functionality is to be implemented in the next iteration")
- @Override
- public void testQueryWebPageQueryEmptyResults() throws Exception {
- super.testQueryWebPageQueryEmptyResults();
- }
-
- @Test
@Ignore("Functionality is to be implemented in the next iteration as this incurs query execution")
@Override
public void testDelete() throws Exception {
[10/32] gora git commit: Refactor code with comments,
logging and exception handling
Posted by dj...@apache.org.
Refactor code with comments, logging and exception handling
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/d68be8df
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/d68be8df
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/d68be8df
Branch: refs/heads/master
Commit: d68be8dfb013d7f8d1e56c94d554166d6440de35
Parents: 00d392f
Author: nishadi <nd...@gmail.com>
Authored: Thu Jun 22 19:53:52 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jun 22 19:53:52 2017 +0530
----------------------------------------------------------------------
gora-aerospike/pom.xml | 1 -
.../gora/aerospike/store/AerospikeMapping.java | 6 +-
.../store/AerospikeMappingBuilder.java | 224 +++++++++++--------
.../aerospike/store/AerospikeParameters.java | 111 ++++++---
.../gora/aerospike/store/AerospikeStore.java | 84 ++++---
5 files changed, 271 insertions(+), 155 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/d68be8df/gora-aerospike/pom.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/pom.xml b/gora-aerospike/pom.xml
index ddf17a1..b15693e 100644
--- a/gora-aerospike/pom.xml
+++ b/gora-aerospike/pom.xml
@@ -50,7 +50,6 @@
</ciManagement>
<properties>
- <aerospike.version>3.3.2</aerospike.version>
<osgi.import>*</osgi.import>
<osgi.export>org.apache.gora.aerospike*;version="${project.version}";-noimport:=true</osgi.export>
</properties>
http://git-wip-us.apache.org/repos/asf/gora/blob/d68be8df/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
index 1a17241..cb000a0 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
@@ -24,9 +24,13 @@ import java.util.Map;
public class AerospikeMapping {
private String namespace;
+
private String set;
+
private WritePolicy writePolicy;
+
private Policy readPolicy;
+
private Map<String, String> binMapping;
public AerospikeMapping() {
@@ -75,7 +79,7 @@ public class AerospikeMapping {
this.binMapping = binMapping;
}
- public String getBinName(String fieldName){
+ public String getBinName(String fieldName) {
return binMapping.get(fieldName);
}
}
http://git-wip-us.apache.org/repos/asf/gora/blob/d68be8df/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
index 7b422f1..ca51c5d 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -26,6 +26,7 @@ import org.jdom.input.SAXBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jdom.JDOMException;
+
import javax.naming.ConfigurationException;
import java.io.IOException;
import java.io.InputStream;
@@ -36,11 +37,11 @@ import java.util.HashMap;
public class AerospikeMappingBuilder {
- public static final Logger LOG = LoggerFactory.getLogger(AerospikeMappingBuilder.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AerospikeMappingBuilder.class);
private AerospikeMapping aerospikeMapping;
- public AerospikeMappingBuilder() throws IOException {
+ public AerospikeMappingBuilder() {
this.aerospikeMapping = new AerospikeMapping();
}
@@ -48,102 +49,125 @@ public class AerospikeMappingBuilder {
return this.aerospikeMapping;
}
- public void readMappingFile(String mappingFile, Class<?> keyClass, Class<?> persistentClass)
- throws IOException, JDOMException, ConfigurationException {
+ /**
+ * Reads the gora aerospike mapping file
+ *
+ * @param mappingFile mapping file path
+ * @param keyClass key class
+ * @param persistentClass persistent class
+ */
+ public void readMappingFile(String mappingFile, Class<?> keyClass, Class<?> persistentClass) {
- SAXBuilder saxBuilder = new SAXBuilder();
- InputStream inputStream = getClass().getClassLoader().getResourceAsStream(mappingFile);
- if (inputStream == null) {
- LOG.warn("Mapping file '" + mappingFile + "' could not be found!");
- throw new IOException("Mapping file '" + mappingFile + "' could not be found!");
- }
- Document document = saxBuilder.build(inputStream);
- if (document == null) {
- LOG.warn("Mapping file '" + mappingFile + "' could not be found!");
- throw new IOException("Mapping file '" + mappingFile + "' could not be found!");
- }
-
- Element root = document.getRootElement();
-
- List<Element> policyElements = root.getChildren("policy");
-
- for (Element policyElement : policyElements) {
-
- String policy = policyElement.getAttributeValue("name");
- if (policy != null) {
- if (policy.equals("write")) {
- WritePolicy writePolicy = new WritePolicy();
- if (policyElement.getAttributeValue("gen") != null)
- writePolicy.generationPolicy = getGenerationPolicyMapping(
- policyElement.getAttributeValue("gen").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("exists") != null)
- writePolicy.recordExistsAction = getRecordExistsAction(
- policyElement.getAttributeValue("exists").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("key") != null)
- writePolicy.sendKey = getKeyUsagePolicy(
- policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("retry") != null)
- writePolicy.retryOnTimeout = getRetryOnTimeoutPolicy(
- policyElement.getAttributeValue("retry").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("timeout") != null)
- writePolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
- aerospikeMapping.setWritePolicy(writePolicy);
- } else if (policy.equals("read")) {
- Policy readPolicy = new Policy();
- if (policyElement.getAttributeValue("key") != null)
- readPolicy.sendKey = getKeyUsagePolicy(
- policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("timeout") != null)
- readPolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
- aerospikeMapping.setReadPolicy(readPolicy);
- }
+ try {
+ SAXBuilder saxBuilder = new SAXBuilder();
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream(mappingFile);
+ if (inputStream == null) {
+ LOG.error("Mapping file '{}' could not be found!", mappingFile);
+ throw new IOException("Mapping file '" + mappingFile + "' could not be found!");
+ }
+ Document document = saxBuilder.build(inputStream);
+ if (document == null) {
+ LOG.error("Mapping file '{}' could not be found!", mappingFile);
+ throw new IOException("Mapping file '" + mappingFile + "' could not be found!");
}
- }
-
- List<Element> classElements = root.getChildren("class");
-
- boolean persistentClassAndKeyClassMatches = false;
- for (Element classElement : classElements) {
-
- String mappingKeyClass = classElement.getAttributeValue("keyClass");
- String mappingClassName = classElement.getAttributeValue("name");
-
- if (mappingKeyClass != null && mappingClassName != null) {
- if (mappingKeyClass.equals(keyClass.getCanonicalName()) && mappingClassName
- .equals(persistentClass.getCanonicalName())) {
-
- persistentClassAndKeyClassMatches = true;
-
- List<Element> fields = classElement.getChildren("field");
- Map<String, String> binMapping = new HashMap<>();
- for (Element field : fields) {
- String fieldName = field.getAttributeValue("name");
- String binName = field.getAttributeValue("bin");
- if (fieldName != null && binName != null)
- binMapping.put(fieldName, binName);
- }
- aerospikeMapping.setBinMapping(binMapping);
- String nameSpace = classElement.getAttributeValue("namespace");
- if (nameSpace == null || nameSpace.isEmpty()) {
- throw new ConfigurationException(
- "Gora-aerospike-mapping does not include the relevant namespace for "
- + "the class");
+ Element root = document.getRootElement();
+
+ List<Element> policyElements = root.getChildren("policy");
+
+ for (Element policyElement : policyElements) {
+
+ String policy = policyElement.getAttributeValue("name");
+ if (policy != null) {
+ if (policy.equals("write")) {
+ WritePolicy writePolicy = new WritePolicy();
+ if (policyElement.getAttributeValue("gen") != null)
+ writePolicy.generationPolicy = getGenerationPolicyMapping(
+ policyElement.getAttributeValue("gen").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("exists") != null)
+ writePolicy.recordExistsAction = getRecordExistsAction(
+ policyElement.getAttributeValue("exists").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("key") != null)
+ writePolicy.sendKey = getKeyUsagePolicy(
+ policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("retry") != null)
+ writePolicy.retryOnTimeout = getRetryOnTimeoutPolicy(
+ policyElement.getAttributeValue("retry").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("timeout") != null)
+ writePolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ aerospikeMapping.setWritePolicy(writePolicy);
+ } else if (policy.equals("read")) {
+ Policy readPolicy = new Policy();
+ if (policyElement.getAttributeValue("key") != null)
+ readPolicy.sendKey = getKeyUsagePolicy(
+ policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("timeout") != null)
+ readPolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ aerospikeMapping.setReadPolicy(readPolicy);
}
- aerospikeMapping.setNamespace(nameSpace);
+ }
+ }
- String set = classElement.getAttributeValue("set");
- if (set != null && !set.isEmpty()) {
- aerospikeMapping.setSet(set);
+ List<Element> classElements = root.getChildren("class");
+
+ boolean persistentClassAndKeyClassMatches = false;
+ for (Element classElement : classElements) {
+
+ String mappingKeyClass = classElement.getAttributeValue("keyClass");
+ String mappingClassName = classElement.getAttributeValue("name");
+
+ if (mappingKeyClass != null && mappingClassName != null) {
+ if (mappingKeyClass.equals(keyClass.getCanonicalName()) && mappingClassName
+ .equals(persistentClass.getCanonicalName())) {
+
+ persistentClassAndKeyClassMatches = true;
+
+ List<Element> fields = classElement.getChildren("field");
+ Map<String, String> binMapping = new HashMap<>();
+ for (Element field : fields) {
+ String fieldName = field.getAttributeValue("name");
+ String binName = field.getAttributeValue("bin");
+ if (fieldName != null && binName != null)
+ binMapping.put(fieldName, binName);
+ }
+ aerospikeMapping.setBinMapping(binMapping);
+
+ String nameSpace = classElement.getAttributeValue("namespace");
+ if (nameSpace == null || nameSpace.isEmpty()) {
+ LOG.error("Gora-aerospike-mapping does not include the relevant namespace for the "
+ + "{} class", mappingClassName);
+ throw new ConfigurationException(
+ "Gora-aerospike-mapping does not include the relevant namespace for the "
+ + mappingClassName + "class");
+ }
+ aerospikeMapping.setNamespace(nameSpace);
+
+ String set = classElement.getAttributeValue("set");
+ if (set != null && !set.isEmpty()) {
+ aerospikeMapping.setSet(set);
+ }
}
}
}
+ if (!persistentClassAndKeyClassMatches) {
+ LOG.error("Gora-aerospike-mapping does not include the name and keyClass specified in the "
+ + "databean");
+ throw new ConfigurationException(
+ "Gora-aerospike-mapping does not include the name and keyClass specified in the "
+ + "databean");
+ }
+ } catch (IOException | JDOMException | ConfigurationException e) {
+ throw new RuntimeException(e);
}
- if (!persistentClassAndKeyClassMatches)
- throw new ConfigurationException(
- "Gora-aerospike-mapping does not include the name and keyClass in the databean");
+ LOG.info("Gora Aerospike mapping file is read successfully.");
}
+ /**
+ * Returns the corresponding generation policy from the user specified generation policy name
+ *
+ * @param genPolicy generation policy name
+ * @return corresponding generation policy
+ */
private GenerationPolicy getGenerationPolicyMapping(String genPolicy) {
if (genPolicy == null)
@@ -168,6 +192,12 @@ public class AerospikeMappingBuilder {
return generationPolicy;
}
+ /**
+ * Returns the corresponding record exist action from the user specified exists policy name
+ *
+ * @param existsPolicy exists policy name
+ * @return corresponding record exist action
+ */
private RecordExistsAction getRecordExistsAction(String existsPolicy) {
if (existsPolicy == null)
return RecordExistsAction.UPDATE;
@@ -197,6 +227,12 @@ public class AerospikeMappingBuilder {
return recordExistsAction;
}
+ /**
+ * Returns the corresponding key usage policy from the user specified key policy name
+ *
+ * @param keyPolicy key policy name
+ * @return corresponding key usage policy
+ */
private boolean getKeyUsagePolicy(String keyPolicy) {
if (keyPolicy == null)
@@ -218,6 +254,12 @@ public class AerospikeMappingBuilder {
return sendKey;
}
+ /**
+ * Returns the corresponding retry on timeout policy from the user specified retry policy name
+ *
+ * @param retry retry policy name
+ * @return corresponding retry on timeout policy
+ */
private boolean getRetryOnTimeoutPolicy(String retry) {
if (retry == null)
@@ -239,6 +281,12 @@ public class AerospikeMappingBuilder {
return retryOnTimeout;
}
+ /**
+ * Returns the timeout value from the user specified timeout value
+ *
+ * @param timeout user specified timeout value
+ * @return timeout value
+ */
private int getTimeoutValue(String timeout) {
if (timeout == null)
http://git-wip-us.apache.org/repos/asf/gora/blob/d68be8df/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
index 539e67d..141808d 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
@@ -1,42 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.gora.aerospike.store;
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.Info;
import com.aerospike.client.cluster.Node;
-import com.aerospike.client.policy.Policy;
-import com.aerospike.client.policy.WritePolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.lang.reflect.Field;
import java.util.Properties;
public class AerospikeParameters {
private String host;
+
private int port;
+
private String user;
+
private String password;
+
private AerospikeMapping aerospikeMapping;
- private boolean singleBin;
+
+ private boolean isSingleBinEnabled;
// Property names
private static final String AS_SERVER_IP = "server.ip";
+
private static final String AS_SERVER_port = "server.port";
// Default property values
private static final String DEFAULT_SERVER_IP = "localhost";
+
private static final String DEFAULT_SERVER_PORT = "3000";
- public static final Logger LOG = LoggerFactory.getLogger(AerospikeParameters.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AerospikeParameters.class);
- public AerospikeParameters(AerospikeMapping aerospikeMapping, Properties properties) throws NumberFormatException {
+ /**
+ * Constructor to create AerospikeParameters object with the given mapping and properties
+ *
+ * @param aerospikeMapping aerospike mapping initialized from the mapping file
+ * @param properties property details
+ */
+ public AerospikeParameters(AerospikeMapping aerospikeMapping, Properties properties) {
this.aerospikeMapping = aerospikeMapping;
this.host = properties.getProperty(AS_SERVER_IP, DEFAULT_SERVER_IP);
- try {
- this.port = Integer.parseInt(properties.getProperty(AS_SERVER_port, DEFAULT_SERVER_PORT));
- } catch (NumberFormatException e) {
- LOG.error(e.getMessage(), e);
- throw e;
- }
+ this.port = Integer.parseInt(properties.getProperty(AS_SERVER_port, DEFAULT_SERVER_PORT));
}
public String getHost() {
@@ -79,29 +102,48 @@ public class AerospikeParameters {
this.aerospikeMapping = aerospikeMapping;
}
- public boolean isSingleBin() {
- return singleBin;
+ public boolean isSingleBinEnabled() {
+ return isSingleBinEnabled;
}
- public void setSingleBin(boolean singleBin) {
- this.singleBin = singleBin;
+ public void setSingleBinEnabled(boolean singleBinEnabled) {
+ this.isSingleBinEnabled = singleBinEnabled;
}
+ /**
+ * Retrieves and sets the server specific parameters
+ * Validates the existence of user provided namespace and validates for single binned
+ * namespaces
+ *
+ * @param client aerospike client used to connect with the server
+ */
+ public void setServerSpecificParameters(AerospikeClient client) {
- // Some database calls need to know how the server is configured.
- public void setServerSpecificParameters(AerospikeClient client) throws Exception {
- Node node = client.getNodes()[0];
- String namespaceFilter = "namespace/" + aerospikeMapping.getNamespace();
- String namespaceTokens = Info.request(null, node, namespaceFilter);
+ String namespaceTokens = null;
+ for (Node node : client.getNodes()) {
+ String namespaceFilter = "namespace/" + aerospikeMapping.getNamespace();
+ namespaceTokens = Info.request(null, node, namespaceFilter);
+ if (namespaceTokens != null) {
+ isSingleBinEnabled = parseBoolean(namespaceTokens, "single-bin");
+ break;
+ }
+ }
if (namespaceTokens == null) {
- throw new Exception("Failed to get namespace info");
+ LOG.error("Failed to get namespace info from Aerospike");
+ throw new RuntimeException("Failed to get namespace info from Aerospike");
}
-
- singleBin = parseBoolean(namespaceTokens, "single-bin");
}
- private static boolean parseBoolean(String namespaceTokens, String name) {
+ /**
+ * Parse the namespace tokens and retrieve the corresponding boolean value for the
+ * provided parameter name
+ *
+ * @param namespaceTokens namespace tokens
+ * @param name name of the parameter
+ * @return boolean value in the namespace corresponding to the provided parameter
+ */
+ private boolean parseBoolean(String namespaceTokens, String name) {
String search = name + '=';
int begin = namespaceTokens.indexOf(search);
@@ -115,13 +157,26 @@ public class AerospikeParameters {
if (end < 0) {
end = namespaceTokens.length();
}
-
String value = namespaceTokens.substring(begin, end);
return Boolean.parseBoolean(value);
}
- // ToDo : check
- public String getBinName(String name) {
- return singleBin ? "" : name;
+ /**
+ * Method is used to validate server bin configuration. In Aerospike, it is possible to enable
+ * single bin (column) for the namespace which will disallow multiple bins (columns) for a
+ * record. Thus if the namespace is single bin enabled and the data bean contains more than one
+ * field, that namespace cannot be used to mutiple bin operations.
+ *
+ * @param fields fields of the persistent class
+ */
+ public void validateServerBinConfiguration(Field[] fields) {
+ if (isSingleBinEnabled) {
+ if (fields.length != 1) {
+ LOG.error(
+ "Aerospike server is single bin enabled and cannot allow multiple bin operations");
+ throw new RuntimeException("Aerospike server is single bin enabled and cannot allow "
+ + "multiple bin operations");
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/gora/blob/d68be8df/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 653cbf8..9ff3c60 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -40,7 +40,7 @@ import org.slf4j.LoggerFactory;
*/
public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K, T> {
- public static final Logger logger = LoggerFactory.getLogger(AerospikeStore.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AerospikeStore.class);
private static final String PARSE_MAPPING_FILE_KEY = "gora.aerospike.mapping.file";
@@ -60,39 +60,41 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
* @param properties properties
*/
@Override
- public void initialize(Class<K> keyClass, Class<T> persistentClass,
- Properties properties) {
+ public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) {
super.initialize(keyClass, persistentClass, properties);
- try {
- AerospikeMappingBuilder aerospikeMappingBuilder = new AerospikeMappingBuilder();
- aerospikeMappingBuilder
- .readMappingFile(getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE),
- keyClass, persistentClass);
- aerospikeParameters = new AerospikeParameters(aerospikeMappingBuilder.getAerospikeMapping(),
- properties);
- ClientPolicy policy = new ClientPolicy();
- policy.writePolicyDefault = aerospikeParameters.getAerospikeMapping().getWritePolicy();
- policy.readPolicyDefault = aerospikeParameters.getAerospikeMapping().getReadPolicy();
- aerospikeClient = new AerospikeClient(aerospikeParameters.getHost(),
- aerospikeParameters.getPort());
- aerospikeParameters.setServerSpecificParameters(aerospikeClient);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ AerospikeMappingBuilder aerospikeMappingBuilder = new AerospikeMappingBuilder();
+ aerospikeMappingBuilder
+ .readMappingFile(getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE), keyClass,
+ persistentClass);
+ aerospikeParameters = new AerospikeParameters(aerospikeMappingBuilder.getAerospikeMapping(),
+ properties);
+ ClientPolicy policy = new ClientPolicy();
+ policy.writePolicyDefault = aerospikeParameters.getAerospikeMapping().getWritePolicy();
+ policy.readPolicyDefault = aerospikeParameters.getAerospikeMapping().getReadPolicy();
+
+ aerospikeClient = new AerospikeClient(aerospikeParameters.getHost(),
+ aerospikeParameters.getPort());
+ aerospikeParameters.setServerSpecificParameters(aerospikeClient);
+ aerospikeParameters.validateServerBinConfiguration(persistentClass.getFields());
+ LOG.info("Aerospike Gora datastore initialized successfully.");
}
- @Override public String getSchemaName() {
+ @Override
+ public String getSchemaName() {
return null;
}
- @Override public void createSchema() {
+ @Override
+ public void createSchema() {
}
- @Override public void deleteSchema() {
+ @Override
+ public void deleteSchema() {
}
- @Override public boolean schemaExists() {
+ @Override
+ public boolean schemaExists() {
return true;
}
@@ -121,8 +123,8 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
* In writing the records, the policy defined in the mapping file is used to decide on the
* behaviour of transaction handling.
*
- * @param key key of the object
- * @param persistent object to be persisted
+ * @param key key of the object
+ * @param persistent object to be persisted
*/
@Override
public void put(K key, T persistent) {
@@ -135,6 +137,8 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
String mappingBinName = aerospikeParameters.getAerospikeMapping().getBinMapping()
.get(fields.get(i).name());
if (mappingBinName == null) {
+ LOG.error("Aerospike mapping for field {}#{} not found. Wrong gora-aerospike-mapping.xml?",
+ persistent.getClass().getName(), fields.get(i).name());
throw new RuntimeException(
"Aerospike mapping for field [" + persistent.getClass().getName() + "#" + fields
.get(i).name() + "] not found. Wrong gora-aerospike-mapping.xml?");
@@ -145,23 +149,28 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
}
}
- @Override public boolean delete(K key) {
+ @Override
+ public boolean delete(K key) {
return true;
}
- @Override public long deleteByQuery(Query<K, T> query) {
+ @Override
+ public long deleteByQuery(Query<K, T> query) {
return 0;
}
- @Override public Result<K, T> execute(Query<K, T> query) {
+ @Override
+ public Result<K, T> execute(Query<K, T> query) {
return null;
}
- @Override public Query<K, T> newQuery() {
+ @Override
+ public Query<K, T> newQuery() {
return null;
}
- @Override public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
+ @Override
+ public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
return null;
}
@@ -175,14 +184,13 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
@Override
public void close() {
aerospikeClient.close();
+ LOG.info("Aerospike Gora datastore destroyed successfully.");
}
/**
- * Aerospike does not support Utf8 format returned from Avro.
- * This method provides those utf8 valued bin values as strings
- * for aerospike Value to obtain the corresponding bin value,
- * and returns the Bin
- * Bin is the concept in Aerospike equivalent to a column in RDBMS
+ * Aerospike does not support Utf8 format returned from Avro. This method provides those utf8
+ * valued bin (column) values as strings for aerospike Value to obtain the corresponding bin
+ * value, and returns the Bin (column in RDBMS)
*
* @param binName name of the bin
* @param value value of the bin
@@ -227,14 +235,16 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
/**
* Method to set a field in the persistent object
*
- * @param field field name
- * @param record record retrieved from database
+ * @param field field name
+ * @param record record retrieved from database
* @param persistent persistent object for the field to be set
*/
private void setPersistentField(String field, Record record, T persistent) {
String binName = aerospikeParameters.getAerospikeMapping().getBinName(field);
if (binName == null) {
+ LOG.error("Aerospike mapping for field {} not found. Wrong gora-aerospike-mapping.xml",
+ field);
throw new RuntimeException("Aerospike mapping for field [" + field + "] not found. "
+ "Wrong gora-aerospike-mapping.xml?");
}
[13/32] gora git commit: Fix base test cases for put and get
functionality
Posted by dj...@apache.org.
Fix base test cases for put and get functionality
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/c72f418e
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/c72f418e
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/c72f418e
Branch: refs/heads/master
Commit: c72f418ec98b259673c695ed60fa7290708a1d55
Parents: 27b015e
Author: nishadi <nd...@gmail.com>
Authored: Mon Jun 26 18:35:54 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Mon Jun 26 18:35:54 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/GoraAerospikeTestDriver.java | 4 +
.../aerospike/store/TestAerospikeStore.java | 199 ++-----------------
2 files changed, 20 insertions(+), 183 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/c72f418e/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
index 1281d9b..10ef7a1 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -44,6 +44,10 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
@Override
public void setUpClass() throws Exception {
+
+ // Wait for the aerospike server to be started in the container
+ Thread.sleep(5000);
+
properties.setProperty("server.ip", "localhost");
properties.setProperty("server.port", aerospikeContainer.getMappedPort(3000).toString());
}
http://git-wip-us.apache.org/repos/asf/gora/blob/c72f418e/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index e1af3cd..8b63414 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -19,23 +19,18 @@
package org.apache.gora.aerospike.store;
import org.apache.gora.aerospike.GoraAerospikeTestDriver;
-import org.apache.gora.examples.generated.Employee;
-import org.apache.gora.examples.generated.WebPage;
-import org.apache.gora.store.DataStoreFactory;
import org.apache.gora.store.DataStoreTestBase;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
-import java.io.IOException;
-
/**
* Test case for AerospikeStore.
*/
public class TestAerospikeStore extends DataStoreTestBase {
- private static final String DOCKER_CONTAINER_NAME = "aerospike:3.14.0";
+ private static final String DOCKER_CONTAINER_NAME = "aerospike/aerospike-server:latest";
@ClassRule
public static GenericContainer aerospikeContainer = new GenericContainer(DOCKER_CONTAINER_NAME);
@@ -55,246 +50,84 @@ public class TestAerospikeStore extends DataStoreTestBase {
}
@Test
- @Ignore("To be implemented")
- @Override
- public void testNewInstance() throws Exception {
- // super.testNewInstance();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testCreateSchema() throws Exception {
- // super.testCreateSchema();
- }
-
- @Override
- public void assertSchemaExists(String schemaName) throws Exception {
- super.assertSchemaExists(schemaName);
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testAutoCreateSchema() throws Exception {
- super.testAutoCreateSchema();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void assertAutoCreateSchema() throws Exception {
- super.assertAutoCreateSchema();
- }
-
- @Test
- @Ignore("To be implemented")
+ @Ignore("Explicit schema creation related functionality is not supported in Aerospike")
@Override
public void testTruncateSchema() throws Exception {
super.testTruncateSchema();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Explicit schema creation related functionality is not supported in Aerospike")
@Override
public void testDeleteSchema() throws Exception {
super.testDeleteSchema();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Explicit schema creation related functionality is not supported in Aerospike")
@Override
public void testSchemaExists() throws Exception {
super.testSchemaExists();
}
@Test
- @Ignore("To be implemented")
- @Override
- public void testPut() throws Exception {
- super.testPut();
- }
-
- @Override
- public void assertPut(Employee employee) throws IOException {
- super.assertPut(employee);
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testPutNested() throws Exception {
- super.testPutNested();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testPutArray() throws Exception {
- super.testPutArray();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void assertPutArray() throws IOException {
- super.assertPutArray();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testPutBytes() throws Exception {
- super.testPutBytes();
- }
-
- @Override
- public void assertPutBytes(byte[] contentBytes) throws IOException {
- super.assertPutBytes(contentBytes);
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testPutMap() throws Exception {
- super.testPutMap();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void assertPutMap() throws IOException {
- super.assertPutMap();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testPutMixedMaps() throws Exception {
- super.testPutMixedMaps();
- }
-
- @Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testUpdate() throws Exception {
super.testUpdate();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testEmptyUpdate() throws Exception {
super.testEmptyUpdate();
}
@Test
- @Ignore("To be implemented")
- @Override
- public void testGet() throws Exception {
- super.testGet();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testGetRecursive() throws Exception {
- super.testGetRecursive();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testGetDoubleRecursive() throws Exception {
- super.testGetDoubleRecursive();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testGetNested() throws Exception {
- super.testGetNested();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testGet3UnionField() throws Exception {
- super.testGet3UnionField();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testGetWithFields() throws Exception {
- super.testGetWithFields();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testGetWebPage() throws Exception {
- super.testGetWebPage();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testGetWebPageDefaultFields() throws Exception {
- super.testGetWebPageDefaultFields();
- }
-
- @Test
- @Ignore("To be implemented")
- @Override
- public void testGetNonExisting() throws Exception {
- super.testGetNonExisting();
- }
-
- @Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testQuery() throws Exception {
super.testQuery();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testQueryStartKey() throws Exception {
super.testQueryStartKey();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testQueryEndKey() throws Exception {
super.testQueryEndKey();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testQueryKeyRange() throws Exception {
super.testQueryKeyRange();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testQueryWebPageSingleKey() throws Exception {
super.testQueryWebPageSingleKey();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testQueryWebPageSingleKeyDefaultFields() throws Exception {
super.testQueryWebPageSingleKeyDefaultFields();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testQueryWebPageQueryEmptyResults() throws Exception {
super.testQueryWebPageQueryEmptyResults();
@@ -308,21 +141,21 @@ public class TestAerospikeStore extends DataStoreTestBase {
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testDeleteByQuery() throws Exception {
super.testDeleteByQuery();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testDeleteByQueryFields() throws Exception {
super.testDeleteByQueryFields();
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testGetPartitions() throws Exception {
super.testGetPartitions();
[22/32] gora git commit: Add persistent base dirty check
Posted by dj...@apache.org.
Add persistent base dirty check
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/390a4358
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/390a4358
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/390a4358
Branch: refs/heads/master
Commit: 390a4358394c91b08ac7903d69689a62cc8c0fc8
Parents: c485f5b
Author: nishadi <nd...@gmail.com>
Authored: Sat Jul 22 08:13:40 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Sat Jul 22 08:13:40 2017 +0530
----------------------------------------------------------------------
.../apache/gora/aerospike/store/AerospikeStore.java | 11 ++++++++++-
.../gora/aerospike/store/TestAerospikeStore.java | 14 --------------
2 files changed, 10 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/390a4358/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index dfa8ed9..56f2bdb 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -177,7 +177,14 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
Key recordKey = getAerospikeKey(key);
List<Field> fields = persistent.getSchema().getFields();
+
+ if (aerospikeClient.exists(null, recordKey)) {
+ this.delete(key);
+ }
for (int i = 0; i < fields.size(); i++) {
+ if (!persistent.isDirty(i)) {
+ continue;
+ }
Object persistentValue = persistent.get(i);
if (persistentValue != null) {
String mappingBinName = aerospikeParameters.getAerospikeMapping().getBinMapping()
@@ -269,7 +276,7 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
}
// Query execution for key ranges
- // ToDo: Implement for other scenarios
+ // ToDo: Implement Query execution for key ranges
else if (query.getStartKey() != null && query.getEndKey() != null) {
// Key startKey = null, endKey = null;
// if (query.getStartKey() != null) {
@@ -335,6 +342,7 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
stmt.setSetName(set);
return stmt;
}
+
/**
* Method to close aerospike client connections to database server nodes
*/
@@ -424,6 +432,7 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
for (String field : fields) {
setPersistentField(field, record, persistent);
}
+ persistent.setDirty();
return persistent;
}
http://git-wip-us.apache.org/repos/asf/gora/blob/390a4358/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index d88ea1a..9e38e4d 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -76,20 +76,6 @@ public class TestAerospikeStore extends DataStoreTestBase {
}
@Test
- @Ignore("Functionality is to be implemented in the next iteration")
- @Override
- public void testUpdate() throws Exception {
- super.testUpdate();
- }
-
- @Test
- @Ignore("Functionality is to be implemented in the next iteration")
- @Override
- public void testEmptyUpdate() throws Exception {
- super.testEmptyUpdate();
- }
-
- @Test
@Override
public void testQuery() throws Exception {
// Clearing the test data in the database
[18/32] gora git commit: Add log4j properties for tests
Posted by dj...@apache.org.
Add log4j properties for tests
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/65201d14
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/65201d14
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/65201d14
Branch: refs/heads/master
Commit: 65201d14389de67719d14edc5ede1496b21d17e2
Parents: 3b44781
Author: nishadi <nd...@gmail.com>
Authored: Thu Jun 29 07:02:25 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jun 29 07:02:25 2017 +0530
----------------------------------------------------------------------
gora-aerospike/src/test/conf/log4j.properties | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/65201d14/gora-aerospike/src/test/conf/log4j.properties
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/conf/log4j.properties b/gora-aerospike/src/test/conf/log4j.properties
new file mode 100644
index 0000000..25272aa
--- /dev/null
+++ b/gora-aerospike/src/test/conf/log4j.properties
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+log4j.rootLogger=INFO, Console
+
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+
+log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %x %-5p [%c{3}] [%t] %m%n
+
[15/32] gora git commit: Revert gora-tutorial module default datastore
Posted by dj...@apache.org.
Revert gora-tutorial module default datastore
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/4163a062
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/4163a062
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/4163a062
Branch: refs/heads/master
Commit: 4163a062f4f2986874a4e80a3e38ecf426559b0c
Parents: b61eeaf
Author: nishadi <nd...@gmail.com>
Authored: Tue Jun 27 06:00:56 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Tue Jun 27 06:00:56 2017 +0530
----------------------------------------------------------------------
gora-tutorial/conf/gora.properties | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/4163a062/gora-tutorial/conf/gora.properties
----------------------------------------------------------------------
diff --git a/gora-tutorial/conf/gora.properties b/gora-tutorial/conf/gora.properties
index 296d191..439755e 100644
--- a/gora-tutorial/conf/gora.properties
+++ b/gora-tutorial/conf/gora.properties
@@ -16,11 +16,11 @@
##gora.datastore.default is the default detastore implementation to use
##if it is not passed to the DataStoreFactory#createDataStore() method.
-gora.datastore.default=org.apache.gora.aerospike.store.AerospikeStore
-#gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
+gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
#gora.datastore.default=org.apache.gora.couchdb.store.CouchDBStore
#gora.datastore.default=org.apache.gora.cassandra.store.CassandraStore
#gora.datastore.default=org.apache.gora.solr.store.SolrStore
+#gora.datastore.default=org.apache.gora.aerospike.store.AerospikeStore
#gora.datastore.default=org.apache.gora.avro.store.AvroStore
#gora.avrostore.input.path=hdfs://localhost:9000/gora.avrostore.test.input
[23/32] gora git commit: Update the test cases
Posted by dj...@apache.org.
Update the test cases
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/dbe962a2
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/dbe962a2
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/dbe962a2
Branch: refs/heads/master
Commit: dbe962a24475a2d288e1e1ff681c21ccd05b5cbc
Parents: 390a435
Author: nishadi <nd...@gmail.com>
Authored: Mon Jul 24 22:43:30 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Mon Jul 24 22:43:30 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/store/AerospikeStore.java | 38 +++++++---------
.../aerospike/store/TestAerospikeStore.java | 47 +++++++++++++++-----
2 files changed, 54 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/dbe962a2/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 56f2bdb..5b3a1b9 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -255,7 +255,7 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
String set = aerospikeParameters.getAerospikeMapping().getSet();
// Query execution without any keys
- if (query.getStartKey() == null && query.getEndKey() == null){
+ if (query.getStartKey() == null && query.getEndKey() == null) {
try (RecordSet recordSet = aerospikeClient.query(null, getStatement(namespace, set))) {
while (recordSet.next()) {
@@ -277,36 +277,29 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
// Query execution for key ranges
// ToDo: Implement Query execution for key ranges
- else if (query.getStartKey() != null && query.getEndKey() != null) {
-// Key startKey = null, endKey = null;
-// if (query.getStartKey() != null) {
-// startKey = getAerospikeKey(query.getStartKey());
-// }
-// if (query.getEndKey() != null) {
-// endKey = getAerospikeKey(query.getEndKey());
-// }
-
-// boolean isSpecifiedRange = false;
+// else if (query.getStartKey() != null && query.getEndKey() != null) {
+//
+// // the key range filtering at the gora-module, which is not a better solution
+// String lowerBound = query.getStartKey().toString();
+// String upperBound = query.getEndKey().toString();
+//
// try (RecordSet recordSet = aerospikeClient.query(null, getStatement(namespace, set))) {
// while (recordSet.next()) {
// Key key = recordSet.getKey();
// Record record = recordSet.getRecord();
//
-// if(key.userKey == getAerospikeKey(query.getStartKey()).userKey){
-// isSpecifiedRange = true;
-// }
-// if(key.userKey == getAerospikeKey(query.getEndKey()).userKey){
-// isSpecifiedRange = false;
-// }
+// String input = key.userKey.toString();
+// boolean isSpecifiedRange = input.compareToIgnoreCase(lowerBound) >= 0 && input
+// .compareToIgnoreCase(upperBound) <= 0;
//
-// if(isSpecifiedRange){
-// AerospikeResultRecord aerospikeRecord = new AerospikeResultRecord(key,record);
+// if (isSpecifiedRange) {
+// AerospikeResultRecord aerospikeRecord = new AerospikeResultRecord(key, record);
// resultRecords.add(aerospikeRecord);
// }
//
// }
- }
-
+// }
+// }
return new AerospikeQueryResult<>(this, query, resultRecords, getFieldsToQuery(null));
}
@@ -320,6 +313,9 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
return new AerospikeQuery<>(this);
}
+ /**
+ * The functionality is not supported as query key ranges are not supported
+ */
@Override
public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
return null;
http://git-wip-us.apache.org/repos/asf/gora/blob/dbe962a2/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index 9e38e4d..9e66327 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -23,11 +23,14 @@ import org.apache.gora.examples.WebPageDataCreator;
import org.apache.gora.examples.generated.WebPage;
import org.apache.gora.query.Query;
import org.apache.gora.store.DataStoreTestBase;
+import org.apache.gora.store.DataStoreTestUtil;
+import org.apache.gora.util.AvroUtils;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
+import static org.apache.gora.examples.WebPageDataCreator.SORTED_URLS;
import static org.apache.gora.examples.WebPageDataCreator.URLS;
/**
@@ -88,21 +91,21 @@ public class TestAerospikeStore extends DataStoreTestBase {
}
@Test
- @Ignore("Functionality is to be implemented in the next iteration")
+ @Ignore("Query key ranges based on primary key is not supported via the java client")
@Override
public void testQueryStartKey() throws Exception {
super.testQueryStartKey();
}
@Test
- @Ignore("Functionality is to be implemented in the next iteration")
+ @Ignore("Query key ranges based on primary key is not supported via the java client")
@Override
public void testQueryEndKey() throws Exception {
super.testQueryEndKey();
}
@Test
- @Ignore("Functionality is to be implemented in the next iteration")
+ @Ignore("Query key ranges based on primary key is not supported via the java client")
@Override
public void testQueryKeyRange() throws Exception {
super.testQueryKeyRange();
@@ -121,23 +124,47 @@ public class TestAerospikeStore extends DataStoreTestBase {
}
@Test
- @Ignore("Functionality is to be implemented in the next iteration")
@Override
public void testDeleteByQuery() throws Exception {
- super.testDeleteByQuery();
+
+ // Can not use the super method as they query key ranges are not supported
+ Query<String, WebPage> query;
+ //test 1 - delete all
+ WebPageDataCreator.createWebPageData(webPageStore);
+
+ query = webPageStore.newQuery();
+
+ DataStoreTestUtil.assertNumResults(webPageStore.newQuery(), URLS.length);
+ webPageStore.deleteByQuery(query);
+ webPageStore.flush();
+ DataStoreTestUtil.assertEmptyResults(webPageStore.newQuery());
+
+
+ //test 2 - delete all
+ WebPageDataCreator.createWebPageData(webPageStore);
+
+ query = webPageStore.newQuery();
+ query.setFields(AvroUtils.getSchemaFieldNames(WebPage.SCHEMA$));
+
+ DataStoreTestUtil.assertNumResults(webPageStore.newQuery(), URLS.length);
+ webPageStore.deleteByQuery(query);
+ webPageStore.flush();
+ DataStoreTestUtil.assertEmptyResults(webPageStore.newQuery());
+
+ webPageStore.truncateSchema();
}
@Test
@Ignore("Functionality is to be implemented in the next iteration")
@Override
- public void testDeleteByQueryFields() throws Exception {
- super.testDeleteByQueryFields();
+ public void testGetPartitions() throws Exception {
+ super.testGetPartitions();
}
@Test
- @Ignore("Functionality is to be implemented in the next iteration")
+ @Ignore("Not supported as query key ranges are not supported")
@Override
- public void testGetPartitions() throws Exception {
- super.testGetPartitions();
+ public void testDeleteByQueryFields() throws Exception {
+ super.testDeleteByQueryFields();
}
}
[27/32] gora git commit: Add a profile to run test cases
Posted by dj...@apache.org.
Add a profile to run test cases
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/360c6046
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/360c6046
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/360c6046
Branch: refs/heads/master
Commit: 360c6046623fc425c2125b2f9410290dbe5d69c6
Parents: 7414720
Author: nishadi <nd...@gmail.com>
Authored: Wed Jul 26 22:40:00 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Wed Jul 26 22:40:00 2017 +0530
----------------------------------------------------------------------
gora-aerospike/pom.xml | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/360c6046/gora-aerospike/pom.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/pom.xml b/gora-aerospike/pom.xml
index 8dab5b1..a70c3e4 100644
--- a/gora-aerospike/pom.xml
+++ b/gora-aerospike/pom.xml
@@ -54,6 +54,24 @@
<osgi.export>org.apache.gora.aerospike*;version="${project.version}";-noimport:=true</osgi.export>
</properties>
+ <profiles>
+ <profile>
+ <id>aerospike-with-test</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.2</version>
+ <configuration>
+ <skipTests>false</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
<build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
[24/32] gora git commit: Update query result key mapping in aerospike
module
Posted by dj...@apache.org.
Update query result key mapping in aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/6ee55e92
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/6ee55e92
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/6ee55e92
Branch: refs/heads/master
Commit: 6ee55e92440c2eb8a25bffce9fe0b18e1d49b67c
Parents: dbe962a
Author: nishadi <nd...@gmail.com>
Authored: Tue Jul 25 23:49:21 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Tue Jul 25 23:49:21 2017 +0530
----------------------------------------------------------------------
.../java/org/apache/gora/aerospike/query/AerospikeQueryResult.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/6ee55e92/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
index 3ddca3c..e135dc3 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
@@ -73,7 +73,7 @@ public class AerospikeQueryResult<K, T extends Persistent> extends ResultBase<K,
if (offset < 0 || offset > (resultRecords.size() - 1)) {
return false;
}
- key = (K) resultRecords.get((int) this.offset).getKey().userKey;
+ key = (K) resultRecords.get((int) this.offset).getKey().userKey.getObject();
persistent = (T) getDataStore()
.createPersistentInstance(resultRecords.get((int) this.offset).getRecord(), fields);
return true;
[29/32] gora git commit: Update the query results to get the progress
for aerospike module
Posted by dj...@apache.org.
Update the query results to get the progress for aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/c0aa76eb
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/c0aa76eb
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/c0aa76eb
Branch: refs/heads/master
Commit: c0aa76eb16031973f3e897ea535a0b38bfb7f11f
Parents: 360c604
Author: nishadi <nd...@gmail.com>
Authored: Thu Jul 27 10:18:13 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jul 27 10:18:13 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/query/AerospikeQueryResult.java | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/c0aa76eb/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
index e135dc3..c843082 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
@@ -17,8 +17,6 @@
*/
package org.apache.gora.aerospike.query;
-import com.aerospike.client.Record;
-import com.aerospike.client.query.RecordSet;
import org.apache.gora.aerospike.store.AerospikeStore;
import org.apache.gora.persistency.Persistent;
import org.apache.gora.query.Query;
@@ -26,7 +24,6 @@ import org.apache.gora.query.impl.ResultBase;
import org.apache.gora.store.DataStore;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -46,10 +43,20 @@ public class AerospikeQueryResult<K, T extends Persistent> extends ResultBase<K,
this.fields = fields;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @return a float value representing progress of the job
+ * @throws IOException if there is an error obtaining progress
+ * @throws InterruptedException if progress stalls or is interrupted
+ */
@Override
public float getProgress() throws IOException, InterruptedException {
- //ToDo: to be implemented
- return 0;
+ if (resultRecords != null && resultRecords.size() > 0) {
+ return (float) offset / (float) resultRecords.size();
+ } else {
+ return 0;
+ }
}
/**
[03/32] gora git commit: Merge remote-tracking branch
'upstream/master' into issue-502
Posted by dj...@apache.org.
Merge remote-tracking branch 'upstream/master' into issue-502
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/56087311
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/56087311
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/56087311
Branch: refs/heads/master
Commit: 5608731163dc05b7f8d66ea4071d0a1af04911f2
Parents: 1ad1cc9 d5e5560
Author: nishadi <nd...@gmail.com>
Authored: Sat Jun 17 22:26:45 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Sat Jun 17 22:26:45 2017 +0530
----------------------------------------------------------------------
.../gora/accumulo/store/AccumuloStoreTest.java | 13 +-
.../cassandra/store/TestCassandraStore.java | 12 -
.../apache/gora/memory/store/MemStoreTest.java | 16 +-
.../gora/memory/store/MemStoreTestDriver.java | 44 +
.../apache/gora/store/DataStoreTestBase.java | 13 -
.../gora/couchdb/store/TestCouchDBStore.java | 12 -
.../org/apache/gora/hbase/store/HBaseStore.java | 7 +-
.../test/conf/gora-hbase-mapping-mismatch.xml | 47 +
.../apache/gora/hbase/store/TestHBaseStore.java | 33 +-
.../infinispan/store/InfinispanStoreTest.java | 12 -
.../jcache/store/JCacheGoraDataStoreTest.java | 10 -
.../gora/mongodb/store/TestMongoStore.java | 14 -
gora-solr-5/pom.xml | 275 ----
.../java/org/apache/gora/solr/package-info.java | 20 -
.../org/apache/gora/solr/query/SolrQuery.java | 80 -
.../org/apache/gora/solr/query/SolrResult.java | 121 --
.../apache/gora/solr/query/package-info.java | 21 -
.../org/apache/gora/solr/store/SolrMapping.java | 58 -
.../org/apache/gora/solr/store/SolrStore.java | 841 -----------
.../apache/gora/solr/store/package-info.java | 20 -
gora-solr-5/src/test/conf/gora-solr-mapping.xml | 40 -
gora-solr-5/src/test/conf/gora.properties | 21 -
gora-solr-5/src/test/conf/log4j.properties | 35 -
.../solr/Employee/conf/lang/stopwords_en.txt | 54 -
.../test/conf/solr/Employee/conf/protwords.txt | 21 -
.../src/test/conf/solr/Employee/conf/schema.xml | 45 -
.../test/conf/solr/Employee/conf/solrconfig.xml | 107 --
.../test/conf/solr/Employee/conf/stopwords.txt | 14 -
.../test/conf/solr/Employee/conf/synonyms.txt | 29 -
.../solr/WebPage/conf/lang/stopwords_en.txt | 54 -
.../test/conf/solr/WebPage/conf/protwords.txt | 21 -
.../src/test/conf/solr/WebPage/conf/schema.xml | 46 -
.../test/conf/solr/WebPage/conf/solrconfig.xml | 107 --
.../test/conf/solr/WebPage/conf/stopwords.txt | 14 -
.../test/conf/solr/WebPage/conf/synonyms.txt | 29 -
.../test/conf/solr/collection1/conf/schema.xml | 32 -
.../conf/solr/collection1/conf/solrconfig.xml | 113 --
.../test/conf/solr/collection1/core.properties | 1 -
gora-solr-5/src/test/conf/solr/solr.xml | 69 -
gora-solr-5/src/test/conf/solr/zoo.cfg | 17 -
.../apache/gora/solr/GoraSolrTestDriver.java | 94 --
.../java/org/apache/gora/solr/package-info.java | 21 -
.../apache/gora/solr/store/TestSolrStore.java | 120 --
.../apache/gora/solr/store/package-info.java | 21 -
gora-solr/pom.xml | 90 +-
.../java/org/apache/gora/solr/package-info.java | 20 +
.../org/apache/gora/solr/query/SolrQuery.java | 22 +-
.../org/apache/gora/solr/query/SolrResult.java | 22 +-
.../apache/gora/solr/query/package-info.java | 21 +
.../org/apache/gora/solr/store/SolrMapping.java | 3 +
.../org/apache/gora/solr/store/SolrStore.java | 117 +-
.../apache/gora/solr/store/package-info.java | 20 +
.../Employee/conf/elevate.xml | 42 +
.../Employee/conf/lang/stopwords_en.txt | 54 +
.../Employee/conf/managed-schema | 33 +
.../Employee/conf/protwords.txt | 21 +
.../Employee/conf/solrconfig.xml | 1411 ++++++++++++++++++
.../Employee/conf/synonyms.txt | 29 +
.../WebPage/conf/elevate.xml | 42 +
.../WebPage/conf/lang/stopwords_en.txt | 54 +
.../WebPage/conf/managed-schema | 34 +
.../WebPage/conf/protwords.txt | 21 +
.../WebPage/conf/solrconfig.xml | 1411 ++++++++++++++++++
.../WebPage/conf/synonyms.txt | 29 +
.../collection1/conf/elevate.xml | 42 +
.../collection1/conf/managed-schema | 26 +
.../collection1/conf/solrconfig.xml | 1403 +++++++++++++++++
.../collection1/core.properties | 18 +
.../src/test/conf/solr-managed-schema/solr.xml | 53 +
.../src/test/conf/solr-managed-schema/zoo.cfg | 35 +
.../test/conf/solr/Employee/conf/solrconfig.xml | 2 +-
.../test/conf/solr/Employee/conf/stopwords.txt | 14 -
.../src/test/conf/solr/Employee/core.properties | 1 -
.../test/conf/solr/WebPage/conf/solrconfig.xml | 2 +-
.../test/conf/solr/WebPage/conf/stopwords.txt | 14 -
.../src/test/conf/solr/WebPage/core.properties | 1 -
.../conf/solr/collection1/conf/solrconfig.xml | 2 +-
.../test/conf/solr/collection1/core.properties | 17 +
gora-solr/src/test/conf/solr/solr.xml | 30 +-
gora-solr/src/test/conf/solr/zoo.cfg | 17 +
.../solr/GoraSolrManagedSchemaTestDriver.java | 89 ++
.../apache/gora/solr/GoraSolrTestDriver.java | 20 +-
.../java/org/apache/gora/solr/package-info.java | 21 +
.../solr/store/TestSolrManagedSchemaStore.java | 31 +
.../apache/gora/solr/store/TestSolrStore.java | 87 +-
.../apache/gora/solr/store/package-info.java | 21 +
gora-tutorial/pom.xml | 2 +-
pom.xml | 68 +-
88 files changed, 5484 insertions(+), 2822 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/56087311/pom.xml
----------------------------------------------------------------------
diff --cc pom.xml
index 618cda1,2c2e20a..b81d7e6
--- a/pom.xml
+++ b/pom.xml
@@@ -729,11 -729,9 +729,10 @@@
<!--module>gora-sql</module -->
<module>gora-maven-plugin</module>
<module>gora-mongodb</module>
- <!--module>gora-solr</module-->
- <module>gora-solr-5</module>
+ <module>gora-solr</module>
<module>gora-tutorial</module>
<module>sources-dist</module>
+ <module>gora-aerospike</module>
</modules>
<properties>
[09/32] gora git commit: Add get functionality for aerospike module
Posted by dj...@apache.org.
Add get functionality for aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/00d392f2
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/00d392f2
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/00d392f2
Branch: refs/heads/master
Commit: 00d392f2c71e4c6b3e1c8a2fefff0b30afd7c05a
Parents: eae36f4
Author: nishadi <nd...@gmail.com>
Authored: Thu Jun 22 10:43:16 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jun 22 10:43:16 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/store/AerospikeMapping.java | 6 +-
.../gora/aerospike/store/AerospikeStore.java | 119 +++++++++++++++++--
2 files changed, 115 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/00d392f2/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
index ae8284d..1a17241 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -74,4 +74,8 @@ public class AerospikeMapping {
public void setBinMapping(Map<String, String> binMapping) {
this.binMapping = binMapping;
}
+
+ public String getBinName(String fieldName){
+ return binMapping.get(fieldName);
+ }
}
http://git-wip-us.apache.org/repos/asf/gora/blob/00d392f2/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index df2f38d..653cbf8 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -28,7 +28,6 @@ import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.PartitionQuery;
import org.apache.gora.query.Query;
import org.apache.gora.query.Result;
-import org.apache.gora.store.DataStoreFactory;
import org.apache.gora.store.impl.DataStoreBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +40,7 @@ import org.slf4j.LoggerFactory;
*/
public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K, T> {
- public static final Logger LOG = LoggerFactory.getLogger(AerospikeStore.class);
+ public static final Logger logger = LoggerFactory.getLogger(AerospikeStore.class);
private static final String PARSE_MAPPING_FILE_KEY = "gora.aerospike.mapping.file";
@@ -51,7 +50,17 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
private AerospikeParameters aerospikeParameters;
- @Override public void initialize(Class<K> keyClass, Class<T> persistentClass,
+ /**
+ * {@inheritDoc}
+ * In initializing the aerospike datastore, read the mapping file, sets the basic
+ * aerospike specific parameters and creates the client with the user defined policies
+ *
+ * @param keyClass key class
+ * @param persistentClass persistent class
+ * @param properties properties
+ */
+ @Override
+ public void initialize(Class<K> keyClass, Class<T> persistentClass,
Properties properties) {
super.initialize(keyClass, persistentClass, properties);
@@ -87,11 +96,36 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
return true;
}
- @Override public T get(K key, String[] fields) {
- return null;
+ /**
+ * {@inheritDoc}
+ *
+ * @param key the key of the object
+ * @param fields the fields required in the object. Pass null, to retrieve all fields
+ * @return the Object corresponding to the key or null if it cannot be found
+ */
+ @Override
+ public T get(K key, String[] fields) {
+ fields = getFieldsToQuery(fields);
+ Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
+ aerospikeParameters.getAerospikeMapping().getSet(), Value.get(key));
+ Record record = aerospikeClient
+ .get(aerospikeParameters.getAerospikeMapping().getReadPolicy(), recordKey, fields);
+ if (record == null) {
+ return null;
+ }
+ return createPersistentInstance(record, fields);
}
- @Override public void put(K key, T persistent) {
+ /**
+ * Method to insert the persistent objects with the given key to the aerospike database server.
+ * In writing the records, the policy defined in the mapping file is used to decide on the
+ * behaviour of transaction handling.
+ *
+ * @param key key of the object
+ * @param persistent object to be persisted
+ */
+ @Override
+ public void put(K key, T persistent) {
Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
aerospikeParameters.getAerospikeMapping().getSet(), Value.get(key));
@@ -131,10 +165,15 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
return null;
}
+ @Override
public void flush() {
}
- @Override public void close() {
+ /**
+ * Method to close aerospike client connections to database server nodes
+ */
+ @Override
+ public void close() {
aerospikeClient.close();
}
@@ -143,11 +182,12 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
* This method provides those utf8 valued bin values as strings
* for aerospike Value to obtain the corresponding bin value,
* and returns the Bin
+ * Bin is the concept in Aerospike equivalent to a column in RDBMS
*
* @param binName name of the bin
* @param value value of the bin
* @param field field corresponding to bin
- * @return
+ * @return Bin
*/
private Bin getBin(String binName, Object value, Field field) {
@@ -166,4 +206,65 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
else
return new Bin(binName, Value.get(value));
}
+
+ /**
+ * Method to create a persistent object given the retrieved record
+ * from Aerospike database
+ *
+ * @param record record retrieved from database
+ * @param fields fields
+ * @return persistent object created
+ */
+ private T createPersistentInstance(Record record, String[] fields) {
+
+ T persistent = newPersistent();
+ for (String field : fields) {
+ setPersistentField(field, record, persistent);
+ }
+ return persistent;
+ }
+
+ /**
+ * Method to set a field in the persistent object
+ *
+ * @param field field name
+ * @param record record retrieved from database
+ * @param persistent persistent object for the field to be set
+ */
+ private void setPersistentField(String field, Record record, T persistent) {
+
+ String binName = aerospikeParameters.getAerospikeMapping().getBinName(field);
+ if (binName == null) {
+ throw new RuntimeException("Aerospike mapping for field [" + field + "] not found. "
+ + "Wrong gora-aerospike-mapping.xml?");
+ }
+ Schema.Type fieldDataType = fieldMap.get(field).schema().getType();
+ String binDataType = record.bins.get(field).getClass().getSimpleName();
+ Object binValue = record.bins.get(binName);
+
+ if (fieldDataType.toString().equalsIgnoreCase(binDataType)) {
+ persistent.put(field, record.bins.get(binName));
+ } else {
+ switch (fieldDataType) {
+ case UNION:
+ Schema unionSchema = fieldMap.get(field).schema();
+ if (unionSchema.getTypes().size() == 2) {
+ Schema.Type type0 = unionSchema.getTypes().get(0).getType();
+ Schema.Type type1 = unionSchema.getTypes().get(1).getType();
+
+ if ((type0.equals(Schema.Type.NULL)) || (type1.equals(Schema.Type.NULL))) {
+ persistent.put(field, binValue);
+ }
+ }
+ break;
+ case INT:
+ if (binDataType.equalsIgnoreCase("long")) {
+ persistent.put(field, Math.toIntExact((Long) binValue));
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
}
[28/32] gora git commit: Fix formatting issues and update java doc
comments
Posted by dj...@apache.org.
Fix formatting issues and update java doc comments
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/9c384099
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/9c384099
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/9c384099
Branch: refs/heads/master
Commit: 9c384099633c80249316af35922c99a70cbbc5be
Parents: c0aa76e
Author: nishadi <nd...@gmail.com>
Authored: Thu Jul 27 06:22:58 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jul 27 06:22:58 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/query/AerospikeQuery.java | 1 -
.../aerospike/query/AerospikeResultRecord.java | 3 +-
.../gora/aerospike/store/AerospikeMapping.java | 3 +
.../store/AerospikeMappingBuilder.java | 3 +
.../aerospike/store/AerospikeParameters.java | 3 +
.../gora/aerospike/store/AerospikeStore.java | 60 ++++++++++----------
.../gora/aerospike/GoraAerospikeTestDriver.java | 15 +++--
.../aerospike/store/TestAerospikeStore.java | 1 -
8 files changed, 50 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/9c384099/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQuery.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQuery.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQuery.java
index d87fe6a..2f97f5f 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQuery.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQuery.java
@@ -29,5 +29,4 @@ public class AerospikeQuery<K, T extends PersistentBase> extends QueryBase<K, T>
public AerospikeQuery(DataStore<K, T> dataStore) {
super(dataStore);
}
-
}
http://git-wip-us.apache.org/repos/asf/gora/blob/9c384099/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeResultRecord.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeResultRecord.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeResultRecord.java
index 07d4309..069e568 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeResultRecord.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeResultRecord.java
@@ -21,11 +21,12 @@ import com.aerospike.client.Key;
import com.aerospike.client.Record;
/**
- * Class to hold Aerospike result records
+ * Class to represent Aerospike result records
*/
public class AerospikeResultRecord {
private Key key;
+
private Record record;
public AerospikeResultRecord(Key key, Record record) {
http://git-wip-us.apache.org/repos/asf/gora/blob/9c384099/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
index cb000a0..7de7a2d 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
@@ -22,6 +22,9 @@ import com.aerospike.client.policy.WritePolicy;
import java.util.HashMap;
import java.util.Map;
+/**
+ * Class to represent the Aerospike Mapping
+ */
public class AerospikeMapping {
private String namespace;
http://git-wip-us.apache.org/repos/asf/gora/blob/9c384099/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
index f24c08f..6d4f901 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
@@ -35,6 +35,9 @@ import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
+/**
+ * Class to represent the Aerospike mapping builder
+ */
public class AerospikeMappingBuilder {
private static final Logger LOG = LoggerFactory.getLogger(AerospikeMappingBuilder.class);
http://git-wip-us.apache.org/repos/asf/gora/blob/9c384099/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
index 61ea17a..4fe61cd 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
@@ -25,6 +25,9 @@ import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.util.Properties;
+/**
+ * Class to represent the Aerospike specific parameters
+ */
public class AerospikeParameters {
private String host;
http://git-wip-us.apache.org/repos/asf/gora/blob/9c384099/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 5b3a1b9..8bd8d9f 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -229,8 +229,8 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
Result<K, T> result = query.execute();
int deleteCount = 0;
try {
- while(result.next()) {
- if(aerospikeClient.delete(null,getAerospikeKey(result.getKey()))){
+ while (result.next()) {
+ if (aerospikeClient.delete(null, getAerospikeKey(result.getKey()))) {
deleteCount++;
}
}
@@ -267,39 +267,39 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
}
// Query execution for single key
- else if (query.getKey()!= null) {
+ else if (query.getKey() != null) {
Key key = getAerospikeKey(query.getKey());
Record record = aerospikeClient.get(null, key);
- if(record != null){
+ if (record != null) {
resultRecords.add(new AerospikeResultRecord(key, record));
}
}
// Query execution for key ranges
// ToDo: Implement Query execution for key ranges
-// else if (query.getStartKey() != null && query.getEndKey() != null) {
-//
-// // the key range filtering at the gora-module, which is not a better solution
-// String lowerBound = query.getStartKey().toString();
-// String upperBound = query.getEndKey().toString();
-//
-// try (RecordSet recordSet = aerospikeClient.query(null, getStatement(namespace, set))) {
-// while (recordSet.next()) {
-// Key key = recordSet.getKey();
-// Record record = recordSet.getRecord();
-//
-// String input = key.userKey.toString();
-// boolean isSpecifiedRange = input.compareToIgnoreCase(lowerBound) >= 0 && input
-// .compareToIgnoreCase(upperBound) <= 0;
-//
-// if (isSpecifiedRange) {
-// AerospikeResultRecord aerospikeRecord = new AerospikeResultRecord(key, record);
-// resultRecords.add(aerospikeRecord);
-// }
-//
-// }
-// }
-// }
+ // else if (query.getStartKey() != null && query.getEndKey() != null) {
+ //
+ // // the key range filtering at the gora side, which is not a better solution
+ // String lowerBound = query.getStartKey().toString();
+ // String upperBound = query.getEndKey().toString();
+ //
+ // try (RecordSet recordSet = aerospikeClient.query(null, getStatement(namespace, set))) {
+ // while (recordSet.next()) {
+ // Key key = recordSet.getKey();
+ // Record record = recordSet.getRecord();
+ //
+ // String input = key.userKey.toString();
+ // boolean isSpecifiedRange = input.compareToIgnoreCase(lowerBound) >= 0 && input
+ // .compareToIgnoreCase(upperBound) <= 0;
+ //
+ // if (isSpecifiedRange) {
+ // AerospikeResultRecord aerospikeRecord = new AerospikeResultRecord(key, record);
+ // resultRecords.add(aerospikeRecord);
+ // }
+ //
+ // }
+ // }
+ // }
return new AerospikeQueryResult<>(this, query, resultRecords, getFieldsToQuery(null));
}
@@ -326,13 +326,13 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
}
/**
- * Method to create a statement
+ * Method to create a Aerospike specific statement
*
* @param namespace the namespace
* @param set the set
* @return the statement
*/
- private Statement getStatement(String namespace, String set){
+ private Statement getStatement(String namespace, String set) {
Statement stmt = new Statement();
stmt.setNamespace(namespace);
stmt.setSetName(set);
@@ -354,7 +354,7 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
* @param key persistent key
* @return aerospike key for the record
*/
- public Key getAerospikeKey(K key) {
+ private Key getAerospikeKey(K key) {
Value keyValue;
if (keyClass.getSimpleName().equalsIgnoreCase("string")) {
keyValue = Value.get(key.toString());
http://git-wip-us.apache.org/repos/asf/gora/blob/9c384099/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
index 302f605..74b32b1 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -30,11 +30,13 @@ import java.util.Properties;
/**
* Helper class for third part tests using gora-aerospike backend.
+ *
* @see GoraTestDriver
*/
public class GoraAerospikeTestDriver extends GoraTestDriver {
private final GenericContainer aerospikeContainer;
+
private final Properties properties = DataStoreFactory.createProps();
public GoraAerospikeTestDriver(GenericContainer aerospikeContainer) {
@@ -49,7 +51,8 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
Thread.sleep(5000);
properties.setProperty("gora.aerospikestore.server.ip", "localhost");
- properties.setProperty("gora.aerospikestore.server.port", aerospikeContainer.getMappedPort(3000).toString());
+ properties.setProperty("gora.aerospikestore.server.port",
+ aerospikeContainer.getMappedPort(3000).toString());
}
@Override
@@ -59,18 +62,18 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
/**
* Instantiate a new {@link DataStore}. Uses 'null' schema.
*
- * @param keyClass The key class.
+ * @param keyClass The key class.
* @param persistentClass The value class.
* @return A new store instance.
* @throws GoraException If an error occur in creating the data store
*/
@Override
- public <K, T extends Persistent> DataStore<K, T> createDataStore(Class<K> keyClass, Class<T> persistentClass)
- throws GoraException {
+ public <K, T extends Persistent> DataStore<K, T> createDataStore(Class<K> keyClass,
+ Class<T> persistentClass) throws GoraException {
final DataStore<K, T> dataStore = DataStoreFactory
- .createDataStore((Class<? extends DataStore<K, T>>) dataStoreClass, keyClass, persistentClass, conf,
- properties);
+ .createDataStore((Class<? extends DataStore<K, T>>) dataStoreClass, keyClass,
+ persistentClass, conf, properties);
dataStores.add(dataStore);
log.info("Datastore for {} was added.", persistentClass);
return dataStore;
http://git-wip-us.apache.org/repos/asf/gora/blob/9c384099/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index 9e66327..11ed458 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -139,7 +139,6 @@ public class TestAerospikeStore extends DataStoreTestBase {
webPageStore.flush();
DataStoreTestUtil.assertEmptyResults(webPageStore.newQuery());
-
//test 2 - delete all
WebPageDataCreator.createWebPageData(webPageStore);
[05/32] gora git commit: Add support for aerospike in tutorial
Posted by dj...@apache.org.
Add support for aerospike in tutorial
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/3900a41d
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/3900a41d
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/3900a41d
Branch: refs/heads/master
Commit: 3900a41d9a517025618f346b57bd0c5a1fbe89bd
Parents: 8571ad9
Author: nishadi <nd...@gmail.com>
Authored: Sun Jun 18 14:14:34 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Sun Jun 18 14:14:34 2017 +0530
----------------------------------------------------------------------
gora-tutorial/conf/gora-aerospike-mapping.xml | 30 ++++++++++++++++++++++
gora-tutorial/conf/gora.properties | 3 ++-
gora-tutorial/pom.xml | 4 +++
3 files changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/3900a41d/gora-tutorial/conf/gora-aerospike-mapping.xml
----------------------------------------------------------------------
diff --git a/gora-tutorial/conf/gora-aerospike-mapping.xml b/gora-tutorial/conf/gora-aerospike-mapping.xml
new file mode 100644
index 0000000..676f52c
--- /dev/null
+++ b/gora-tutorial/conf/gora-aerospike-mapping.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!--
+ Gora Mapping file for Aerospike Backend
+-->
+<gora-otd>
+
+ <policy name="write" gen="IGNORE" exists="CREATE" key="DIGEST" retry="ONCE" timeout="1000"/>
+ <policy name="read" key="DIGEST" timeout="1000"/>
+
+ <class name="org.apache.gora.tutorial.log.generated.Pageview" keyClass="java.lang.Long" set="AccessLog" namespace = "test" />
+ <class name="org.apache.gora.tutorial.log.generated.MetricDatum" keyClass="java.lang.String" set="Metrics" namespace = "test"/>
+
+</gora-otd>
http://git-wip-us.apache.org/repos/asf/gora/blob/3900a41d/gora-tutorial/conf/gora.properties
----------------------------------------------------------------------
diff --git a/gora-tutorial/conf/gora.properties b/gora-tutorial/conf/gora.properties
index 80de06d..296d191 100644
--- a/gora-tutorial/conf/gora.properties
+++ b/gora-tutorial/conf/gora.properties
@@ -16,7 +16,8 @@
##gora.datastore.default is the default detastore implementation to use
##if it is not passed to the DataStoreFactory#createDataStore() method.
-gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
+gora.datastore.default=org.apache.gora.aerospike.store.AerospikeStore
+#gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
#gora.datastore.default=org.apache.gora.couchdb.store.CouchDBStore
#gora.datastore.default=org.apache.gora.cassandra.store.CassandraStore
#gora.datastore.default=org.apache.gora.solr.store.SolrStore
http://git-wip-us.apache.org/repos/asf/gora/blob/3900a41d/gora-tutorial/pom.xml
----------------------------------------------------------------------
diff --git a/gora-tutorial/pom.xml b/gora-tutorial/pom.xml
index 26011a9..99ba41d 100644
--- a/gora-tutorial/pom.xml
+++ b/gora-tutorial/pom.xml
@@ -123,6 +123,10 @@
<artifactId>gora-solr</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.gora</groupId>
+ <artifactId>gora-aerospike</artifactId>
+ </dependency>
<!-- Hadoop Dependencies -->
<dependency>
<groupId>org.apache.hadoop</groupId>
[07/32] gora git commit: Update aerospike mapping file to support
field to bin value mapping
Posted by dj...@apache.org.
Update aerospike mapping file to support field to bin value mapping
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/13f252e5
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/13f252e5
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/13f252e5
Branch: refs/heads/master
Commit: 13f252e525e103155502953ebdad1006909747ba
Parents: b0c1977
Author: nishadi <nd...@gmail.com>
Authored: Mon Jun 19 17:37:02 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Mon Jun 19 17:37:02 2017 +0530
----------------------------------------------------------------------
gora-tutorial/conf/gora-aerospike-mapping.xml | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/13f252e5/gora-tutorial/conf/gora-aerospike-mapping.xml
----------------------------------------------------------------------
diff --git a/gora-tutorial/conf/gora-aerospike-mapping.xml b/gora-tutorial/conf/gora-aerospike-mapping.xml
index 676f52c..aca18ca 100644
--- a/gora-tutorial/conf/gora-aerospike-mapping.xml
+++ b/gora-tutorial/conf/gora-aerospike-mapping.xml
@@ -24,7 +24,21 @@
<policy name="write" gen="IGNORE" exists="CREATE" key="DIGEST" retry="ONCE" timeout="1000"/>
<policy name="read" key="DIGEST" timeout="1000"/>
- <class name="org.apache.gora.tutorial.log.generated.Pageview" keyClass="java.lang.Long" set="AccessLog" namespace = "test" />
- <class name="org.apache.gora.tutorial.log.generated.MetricDatum" keyClass="java.lang.String" set="Metrics" namespace = "test"/>
+ <class name="org.apache.gora.tutorial.log.generated.Pageview" keyClass="java.lang.Long" set="AccessLog" namespace = "test">
+ <field name="url" bin="url"/>
+ <field name="timestamp" bin="timestamp"/>
+ <field name="ip" bin="ip" />
+ <field name="httpMethod" bin="httpMethod"/>
+ <field name="httpStatusCode" bin="httpStatusCode"/>
+ <field name="responseSize" bin="responseSize"/>
+ <field name="referrer" bin="referrer"/>
+ <field name="userAgent" bin="userAgent"/>
+ </class>
+
+ <class name="org.apache.gora.tutorial.log.generated.MetricDatum" keyClass="java.lang.String" set="Metrics" namespace = "test">
+ <field name="metricDimension" bin="metricDimension"/>
+ <field name="timestamp" bin="ts"/>
+ <field name="metric" bin="metric"/>
+ </class>
</gora-otd>
[26/32] gora git commit: Configure maven to skip the tests by default
Posted by dj...@apache.org.
Configure maven to skip the tests by default
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/74147203
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/74147203
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/74147203
Branch: refs/heads/master
Commit: 74147203997d0ff078b5847a0749b3e0f30d2137
Parents: 08fb5dd
Author: nishadi <nd...@gmail.com>
Authored: Wed Jul 26 22:18:43 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Wed Jul 26 22:18:43 2017 +0530
----------------------------------------------------------------------
gora-aerospike/pom.xml | 8 ++++++++
1 file changed, 8 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/74147203/gora-aerospike/pom.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/pom.xml b/gora-aerospike/pom.xml
index b08611f..8dab5b1 100644
--- a/gora-aerospike/pom.xml
+++ b/gora-aerospike/pom.xml
@@ -71,6 +71,14 @@
</testResources>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.2</version>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
[32/32] gora git commit: Fix container stopping error
Posted by dj...@apache.org.
Fix container stopping error
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/7a56d248
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/7a56d248
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/7a56d248
Branch: refs/heads/master
Commit: 7a56d2484badfbceff130dab0c128f1a581827c0
Parents: 7a5d767
Author: nishadi <nd...@gmail.com>
Authored: Thu Jul 27 23:50:52 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jul 27 23:50:52 2017 +0530
----------------------------------------------------------------------
.../java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/7a56d248/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
index 88ae360..6fc120c 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -46,6 +46,7 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
@Override
public void setUpClass() throws Exception {
+ log.info("Setting up Aerospike test driver");
properties.setProperty("gora.aerospikestore.server.ip", "localhost");
properties.setProperty("gora.aerospikestore.server.port",
aerospikeContainer.getMappedPort(3000).toString());
@@ -53,7 +54,7 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
@Override
public void tearDownClass() throws Exception {
- aerospikeContainer.stop();
+ log.info("Tearing down Aerospike test driver");
}
/**
[02/32] gora git commit: Add mapping reading and initialization for
aerospike module
Posted by dj...@apache.org.
Add mapping reading and initialization for aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/1ad1cc9c
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/1ad1cc9c
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/1ad1cc9c
Branch: refs/heads/master
Commit: 1ad1cc9c96d0e2a12612a9efa76503218a935316
Parents: e796c8c
Author: nishadi <nd...@gmail.com>
Authored: Sat Jun 17 22:26:05 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Sat Jun 17 22:26:05 2017 +0530
----------------------------------------------------------------------
gora-aerospike/pom.xml | 6 +
.../gora/aerospike/store/AerospikeMapping.java | 64 +++++
.../store/AerospikeMappingBuilder.java | 246 +++++++++++++++++++
.../aerospike/store/AerospikeParameters.java | 127 ++++++++++
.../gora/aerospike/store/AerospikeStore.java | 49 ++--
5 files changed, 477 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/1ad1cc9c/gora-aerospike/pom.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/pom.xml b/gora-aerospike/pom.xml
index 1a557f4..ddf17a1 100644
--- a/gora-aerospike/pom.xml
+++ b/gora-aerospike/pom.xml
@@ -124,6 +124,12 @@
<artifactId>hadoop-client</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>jdom</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
<!-- Logging Dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
http://git-wip-us.apache.org/repos/asf/gora/blob/1ad1cc9c/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
new file mode 100644
index 0000000..5df8a92
--- /dev/null
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMapping.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gora.aerospike.store;
+
+import com.aerospike.client.policy.Policy;
+import com.aerospike.client.policy.WritePolicy;
+
+public class AerospikeMapping {
+ private String namespace;
+ private String set;
+ private WritePolicy writePolicy;
+ private Policy readPolicy;
+
+ public AerospikeMapping() {
+ writePolicy = new WritePolicy();
+ readPolicy = new Policy();
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public String getSet() {
+ return set;
+ }
+
+ public void setSet(String set) {
+ this.set = set;
+ }
+
+ public WritePolicy getWritePolicy() {
+ return writePolicy;
+ }
+
+ public void setWritePolicy(WritePolicy writePolicy) {
+ this.writePolicy = writePolicy;
+ }
+
+ public Policy getReadPolicy() {
+ return readPolicy;
+ }
+
+ public void setReadPolicy(Policy readPolicy) {
+ this.readPolicy = readPolicy;
+ }
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/1ad1cc9c/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
new file mode 100644
index 0000000..4e2b997
--- /dev/null
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
@@ -0,0 +1,246 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gora.aerospike.store;
+
+import com.aerospike.client.policy.GenerationPolicy;
+import com.aerospike.client.policy.Policy;
+import com.aerospike.client.policy.RecordExistsAction;
+import com.aerospike.client.policy.WritePolicy;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.ConfigurationException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Locale;
+
+public class AerospikeMappingBuilder {
+
+ public static final Logger LOG = LoggerFactory.getLogger(AerospikeMappingBuilder.class);
+
+ private AerospikeMapping aerospikeMapping;
+
+ public AerospikeMappingBuilder(String mappingFile, Class<?> keyClass, Class<?> persistentClass) throws IOException {
+ this.aerospikeMapping = new AerospikeMapping();
+ this.readMappingFile(mappingFile, keyClass, persistentClass);
+ }
+
+ public AerospikeMapping getAerospikeMapping() {
+ return this.aerospikeMapping;
+ }
+
+ private void readMappingFile(String fileName, Class<?> keyClass, Class<?> persistentClass) throws IOException {
+ try {
+ SAXBuilder saxBuilder = new SAXBuilder();
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName);
+ if (inputStream == null) {
+ LOG.warn("Mapping file '" + fileName + "' could not be found!");
+ throw new IOException("Mapping file '" + fileName + "' could not be found!");
+ }
+ Document document = saxBuilder.build(inputStream);
+ if (document == null) {
+ LOG.warn("Mapping file '" + fileName + "' could not be found!");
+ throw new IOException("Mapping file '" + fileName + "' could not be found!");
+ }
+
+ Element root = document.getRootElement();
+
+ // Mapping the defined policies
+ List<Element> policyElements = root.getChildren("policy");
+
+ for (Element policyElement : policyElements) {
+
+ String policy = policyElement.getAttributeValue("name");
+
+ if (policy.equals("write")) {
+
+ WritePolicy writePolicy = new WritePolicy();
+ if (policyElement.getAttributeValue("gen") != null)
+ writePolicy.generationPolicy = getGenerationPolicyMapping(policyElement.getAttributeValue
+ ("gen").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("exists") != null)
+ writePolicy.recordExistsAction = getRecordExistsAction(policyElement.getAttributeValue
+ ("exists").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("key") != null)
+ writePolicy.sendKey = getKeyUsagePolicy(policyElement.getAttributeValue("key").toUpperCase
+ (Locale.getDefault()));
+ if (policyElement.getAttributeValue("retry") != null)
+ writePolicy.retryOnTimeout = getRetryOnTimeoutPolicy(policyElement.getAttributeValue
+ ("retry").toUpperCase(Locale.getDefault()));
+ if (policyElement.getAttributeValue("timeout") != null)
+ writePolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ aerospikeMapping.setWritePolicy(writePolicy);
+ } else if (policy.equals("read")) {
+
+ Policy readPolicy = new Policy();
+ if (policyElement.getAttributeValue("key") != null)
+ readPolicy.sendKey = getKeyUsagePolicy(policyElement.getAttributeValue("key").toUpperCase(Locale
+ .getDefault()));
+ if (policyElement.getAttributeValue("timeout") != null)
+ readPolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ aerospikeMapping.setReadPolicy(readPolicy);
+ }
+ }
+
+ // Mapping the defined classes
+ List<Element> classElements = root.getChildren("policy");
+
+ boolean persistentAndKeyClassMatches = false;
+ for (Element classElement : classElements) {
+ if (classElement.getAttributeValue("keyClass").equals(keyClass.getCanonicalName())
+ && classElement.getAttributeValue("name").equals(persistentClass.getCanonicalName())) {
+ persistentAndKeyClassMatches = true;
+
+ String nameSpace = classElement.getAttributeValue("namespace");
+ if (nameSpace == null || nameSpace.isEmpty()) {
+ throw new ConfigurationException("Gora-aerospike-mapping does not include the relevant namespace for the " +
+ "class");
+ }
+ aerospikeMapping.setNamespace(nameSpace);
+
+ String set = classElement.getAttributeValue("set");
+ if (set != null && !set.isEmpty()) {
+ //ToDo : check for schema set name
+ aerospikeMapping.setSet(set);
+ }
+ }
+ }
+ if (!persistentAndKeyClassMatches)
+ throw new ConfigurationException("Gora-aerospike-mapping does not include the name and keyClass in the " +
+ "databean");
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+ throw new IOException(e);
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ throw new IOException(e);
+ }
+ }
+
+ private GenerationPolicy getGenerationPolicyMapping(String genPolicy) {
+
+ if (genPolicy == null)
+ return GenerationPolicy.NONE;
+
+ GenerationPolicy generationPolicy;
+ switch (genPolicy) {
+ case "IGNORE":
+ generationPolicy = GenerationPolicy.NONE;
+ break;
+ case "EQ":
+ generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
+ break;
+ case "GT":
+ generationPolicy = GenerationPolicy.EXPECT_GEN_GT;
+ break;
+ default: {
+ LOG.warn("Invalid generation policy provided, using the default generation policy");
+ generationPolicy = GenerationPolicy.NONE;
+ }
+ }
+ return generationPolicy;
+ }
+
+ private RecordExistsAction getRecordExistsAction(String existsPolicy) {
+ if (existsPolicy == null)
+ return RecordExistsAction.UPDATE;
+
+ RecordExistsAction recordExistsAction;
+ switch (existsPolicy) {
+ case "UPDATE":
+ recordExistsAction = RecordExistsAction.UPDATE;
+ break;
+ case "UPDATE_ONLY":
+ recordExistsAction = RecordExistsAction.UPDATE_ONLY;
+ break;
+ case "REPLACE":
+ recordExistsAction = RecordExistsAction.REPLACE;
+ break;
+ case "REPLACE_ONLY":
+ recordExistsAction = RecordExistsAction.REPLACE_ONLY;
+ break;
+ case "CREATE_ONLY":
+ recordExistsAction = RecordExistsAction.CREATE_ONLY;
+ break;
+ default: {
+ LOG.warn("Invalid record exists action provided, using the default record exists action");
+ recordExistsAction = RecordExistsAction.UPDATE;
+ }
+ }
+ return recordExistsAction;
+ }
+
+ private boolean getKeyUsagePolicy(String keyPolicy) {
+
+ if (keyPolicy == null)
+ return false;
+
+ boolean sendKey;
+ switch (keyPolicy) {
+ case "DIGEST":
+ sendKey = false;
+ break;
+ case "SEND":
+ sendKey = true;
+ break;
+ default: {
+ LOG.warn("Invalid key action policy provided, using the default key action policy");
+ sendKey = false;
+ }
+ }
+ return sendKey;
+ }
+
+ private boolean getRetryOnTimeoutPolicy(String retry) {
+
+ if (retry == null)
+ return false;
+
+ boolean retryOnTimeout;
+ switch (retry) {
+ case "NONE":
+ retryOnTimeout = false;
+ break;
+ case "ONCE":
+ retryOnTimeout = true;
+ break;
+ default: {
+ LOG.warn("Invalid key retry policy provided, using the default retry policy");
+ retryOnTimeout = false;
+ }
+ }
+ return retryOnTimeout;
+ }
+
+ private int getTimeoutValue(String timeout) {
+
+ if (timeout == null)
+ return 0;
+ int timeoutInt = 0;
+ try {
+ timeoutInt = Integer.valueOf(timeout);
+ } catch (NumberFormatException e) {
+ LOG.warn("Invalid timeout value provided, using the default timeout value");
+ }
+ return timeoutInt;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/1ad1cc9c/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
new file mode 100644
index 0000000..539e67d
--- /dev/null
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
@@ -0,0 +1,127 @@
+package org.apache.gora.aerospike.store;
+
+import com.aerospike.client.AerospikeClient;
+import com.aerospike.client.Info;
+import com.aerospike.client.cluster.Node;
+import com.aerospike.client.policy.Policy;
+import com.aerospike.client.policy.WritePolicy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Properties;
+
+public class AerospikeParameters {
+ private String host;
+ private int port;
+ private String user;
+ private String password;
+ private AerospikeMapping aerospikeMapping;
+ private boolean singleBin;
+
+ // Property names
+ private static final String AS_SERVER_IP = "server.ip";
+ private static final String AS_SERVER_port = "server.port";
+
+ // Default property values
+ private static final String DEFAULT_SERVER_IP = "localhost";
+ private static final String DEFAULT_SERVER_PORT = "3000";
+
+ public static final Logger LOG = LoggerFactory.getLogger(AerospikeParameters.class);
+
+ public AerospikeParameters(AerospikeMapping aerospikeMapping, Properties properties) throws NumberFormatException {
+ this.aerospikeMapping = aerospikeMapping;
+ this.host = properties.getProperty(AS_SERVER_IP, DEFAULT_SERVER_IP);
+ try {
+ this.port = Integer.parseInt(properties.getProperty(AS_SERVER_port, DEFAULT_SERVER_PORT));
+ } catch (NumberFormatException e) {
+ LOG.error(e.getMessage(), e);
+ throw e;
+ }
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public AerospikeMapping getAerospikeMapping() {
+ return aerospikeMapping;
+ }
+
+ public void setAerospikeMapping(AerospikeMapping aerospikeMapping) {
+ this.aerospikeMapping = aerospikeMapping;
+ }
+
+ public boolean isSingleBin() {
+ return singleBin;
+ }
+
+ public void setSingleBin(boolean singleBin) {
+ this.singleBin = singleBin;
+ }
+
+
+ // Some database calls need to know how the server is configured.
+ public void setServerSpecificParameters(AerospikeClient client) throws Exception {
+ Node node = client.getNodes()[0];
+ String namespaceFilter = "namespace/" + aerospikeMapping.getNamespace();
+ String namespaceTokens = Info.request(null, node, namespaceFilter);
+
+ if (namespaceTokens == null) {
+ throw new Exception("Failed to get namespace info");
+ }
+
+ singleBin = parseBoolean(namespaceTokens, "single-bin");
+ }
+
+ private static boolean parseBoolean(String namespaceTokens, String name) {
+ String search = name + '=';
+ int begin = namespaceTokens.indexOf(search);
+
+ if (begin < 0) {
+ return false;
+ }
+
+ begin += search.length();
+ int end = namespaceTokens.indexOf(';', begin);
+
+ if (end < 0) {
+ end = namespaceTokens.length();
+ }
+
+ String value = namespaceTokens.substring(begin, end);
+ return Boolean.parseBoolean(value);
+ }
+
+ // ToDo : check
+ public String getBinName(String name) {
+ return singleBin ? "" : name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/gora/blob/1ad1cc9c/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 8c31773..6ed1a76 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.Properties;
import com.aerospike.client.*;
+import com.aerospike.client.policy.ClientPolicy;
import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.PartitionQuery;
import org.apache.gora.query.Query;
@@ -29,23 +30,40 @@ import org.apache.gora.store.DataStoreFactory;
import org.apache.gora.store.impl.DataStoreBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
/**
* Implementation of a Aerospike data store to be used by gora.
*
- * @param <K>
- * class to be used for the key
- * @param <T>
- * class to be persisted within the store
+ * @param <K> class to be used for the key
+ * @param <T> class to be persisted within the store
*/
-public class AerospikeStore<K,T extends PersistentBase> extends DataStoreBase<K,T> {
+public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K, T> {
public static final Logger LOG = LoggerFactory.getLogger(AerospikeStore.class);
+ private static final String PARSE_MAPPING_FILE_KEY = "gora.aerospike.mapping.file";
+ private static final String DEFAULT_MAPPING_FILE = "gora-aerospike-mapping.xml";
+
private AerospikeClient aerospikeClient;
+ private AerospikeParameters aerospikeParameters;
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) {
- super.initialize(keyClass, persistentClass, properties);
+ super.initialize(keyClass, persistentClass, properties);
+
+ try {
+ AerospikeMappingBuilder aerospikeMappingBuilder = new AerospikeMappingBuilder(getConf().get
+ (PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE), keyClass,
+ persistentClass);
+ aerospikeParameters = new AerospikeParameters(aerospikeMappingBuilder.getAerospikeMapping(), properties);
+ ClientPolicy policy = new ClientPolicy();
+ policy.writePolicyDefault = aerospikeParameters.getAerospikeMapping().getWritePolicy();
+ policy.readPolicyDefault = aerospikeParameters.getAerospikeMapping().getReadPolicy();
+ aerospikeClient = new AerospikeClient(aerospikeParameters.getHost(), aerospikeParameters.getPort());
+ aerospikeParameters.setServerSpecificParameters(aerospikeClient);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
@Override
@@ -68,11 +86,12 @@ public class AerospikeStore<K,T extends PersistentBase> extends DataStoreBase<K,
@Override
public T get(K key, String[] fields) {
- return null;
+ return null;
}
@Override
- public void put(K key, T val) {
+ public void put(K key, T value) {
+
}
@Override
@@ -81,22 +100,22 @@ public class AerospikeStore<K,T extends PersistentBase> extends DataStoreBase<K,
}
@Override
- public long deleteByQuery(Query<K,T> query) {
+ public long deleteByQuery(Query<K, T> query) {
return 0;
}
@Override
- public Result<K,T> execute(Query<K,T> query) {
+ public Result<K, T> execute(Query<K, T> query) {
return null;
}
@Override
- public Query<K,T> newQuery() {
+ public Query<K, T> newQuery() {
return null;
}
@Override
- public List<PartitionQuery<K,T>> getPartitions(Query<K,T> query) throws IOException {
+ public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
return null;
}
[16/32] gora git commit: Remove redundant dependency additions from
aerospike module pom
Posted by dj...@apache.org.
Remove redundant dependency additions from aerospike module pom
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/d3a44b26
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/d3a44b26
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/d3a44b26
Branch: refs/heads/master
Commit: d3a44b261461ca260022638f75b83b24bf980641
Parents: 4163a06
Author: nishadi <nd...@gmail.com>
Authored: Tue Jun 27 06:19:57 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Tue Jun 27 06:19:57 2017 +0530
----------------------------------------------------------------------
gora-aerospike/pom.xml | 5 -----
1 file changed, 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/d3a44b26/gora-aerospike/pom.xml
----------------------------------------------------------------------
diff --git a/gora-aerospike/pom.xml b/gora-aerospike/pom.xml
index 828f45d..b08611f 100644
--- a/gora-aerospike/pom.xml
+++ b/gora-aerospike/pom.xml
@@ -137,11 +137,6 @@
<!-- Testing Dependencies -->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.1.0</version>
[17/32] gora git commit: Refactor code
Posted by dj...@apache.org.
Refactor code
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/3b44781f
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/3b44781f
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/3b44781f
Branch: refs/heads/master
Commit: 3b44781f9514988a31e2748416b1cb7015e2767a
Parents: d3a44b2
Author: nishadi <nd...@gmail.com>
Authored: Thu Jun 29 07:01:58 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jun 29 07:01:58 2017 +0530
----------------------------------------------------------------------
.../org/apache/gora/aerospike/package-info.java | 2 +-
.../store/AerospikeMappingBuilder.java | 82 +++++++++++---------
.../aerospike/store/AerospikeParameters.java | 17 ++--
.../gora/aerospike/store/AerospikeStore.java | 40 ++++++----
.../gora/aerospike/store/package-info.java | 2 +-
.../gora/aerospike/GoraAerospikeTestDriver.java | 4 +-
6 files changed, 82 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
index 0dbf8dd..7c1eae4 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
index ca51c5d..f24c08f 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
@@ -39,7 +39,7 @@ public class AerospikeMappingBuilder {
private static final Logger LOG = LoggerFactory.getLogger(AerospikeMappingBuilder.class);
- private AerospikeMapping aerospikeMapping;
+ private final AerospikeMapping aerospikeMapping;
public AerospikeMappingBuilder() {
this.aerospikeMapping = new AerospikeMapping();
@@ -81,28 +81,35 @@ public class AerospikeMappingBuilder {
if (policy != null) {
if (policy.equals("write")) {
WritePolicy writePolicy = new WritePolicy();
- if (policyElement.getAttributeValue("gen") != null)
+ if (policyElement.getAttributeValue("gen") != null) {
writePolicy.generationPolicy = getGenerationPolicyMapping(
policyElement.getAttributeValue("gen").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("exists") != null)
+ }
+ if (policyElement.getAttributeValue("exists") != null) {
writePolicy.recordExistsAction = getRecordExistsAction(
policyElement.getAttributeValue("exists").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("key") != null)
+ }
+ if (policyElement.getAttributeValue("key") != null) {
writePolicy.sendKey = getKeyUsagePolicy(
policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("retry") != null)
+ }
+ if (policyElement.getAttributeValue("retry") != null) {
writePolicy.retryOnTimeout = getRetryOnTimeoutPolicy(
policyElement.getAttributeValue("retry").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("timeout") != null)
+ }
+ if (policyElement.getAttributeValue("timeout") != null) {
writePolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ }
aerospikeMapping.setWritePolicy(writePolicy);
} else if (policy.equals("read")) {
Policy readPolicy = new Policy();
- if (policyElement.getAttributeValue("key") != null)
+ if (policyElement.getAttributeValue("key") != null) {
readPolicy.sendKey = getKeyUsagePolicy(
policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
- if (policyElement.getAttributeValue("timeout") != null)
+ }
+ if (policyElement.getAttributeValue("timeout") != null) {
readPolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+ }
aerospikeMapping.setReadPolicy(readPolicy);
}
}
@@ -116,36 +123,36 @@ public class AerospikeMappingBuilder {
String mappingKeyClass = classElement.getAttributeValue("keyClass");
String mappingClassName = classElement.getAttributeValue("name");
- if (mappingKeyClass != null && mappingClassName != null) {
- if (mappingKeyClass.equals(keyClass.getCanonicalName()) && mappingClassName
- .equals(persistentClass.getCanonicalName())) {
+ if (mappingKeyClass != null && mappingClassName != null && mappingKeyClass
+ .equals(keyClass.getCanonicalName()) && mappingClassName
+ .equals(persistentClass.getCanonicalName())) {
- persistentClassAndKeyClassMatches = true;
+ persistentClassAndKeyClassMatches = true;
- List<Element> fields = classElement.getChildren("field");
- Map<String, String> binMapping = new HashMap<>();
- for (Element field : fields) {
- String fieldName = field.getAttributeValue("name");
- String binName = field.getAttributeValue("bin");
- if (fieldName != null && binName != null)
- binMapping.put(fieldName, binName);
+ List<Element> fields = classElement.getChildren("field");
+ Map<String, String> binMapping = new HashMap<>();
+ for (Element field : fields) {
+ String fieldName = field.getAttributeValue("name");
+ String binName = field.getAttributeValue("bin");
+ if (fieldName != null && binName != null) {
+ binMapping.put(fieldName, binName);
}
- aerospikeMapping.setBinMapping(binMapping);
-
- String nameSpace = classElement.getAttributeValue("namespace");
- if (nameSpace == null || nameSpace.isEmpty()) {
- LOG.error("Gora-aerospike-mapping does not include the relevant namespace for the "
- + "{} class", mappingClassName);
- throw new ConfigurationException(
- "Gora-aerospike-mapping does not include the relevant namespace for the "
- + mappingClassName + "class");
- }
- aerospikeMapping.setNamespace(nameSpace);
+ }
+ aerospikeMapping.setBinMapping(binMapping);
+
+ String nameSpace = classElement.getAttributeValue("namespace");
+ if (nameSpace == null || nameSpace.isEmpty()) {
+ LOG.error("Gora-aerospike-mapping does not include the relevant namespace for the "
+ + "{} class", mappingClassName);
+ throw new ConfigurationException(
+ "Gora-aerospike-mapping does not include the relevant namespace for the "
+ + mappingClassName + "class");
+ }
+ aerospikeMapping.setNamespace(nameSpace);
- String set = classElement.getAttributeValue("set");
- if (set != null && !set.isEmpty()) {
- aerospikeMapping.setSet(set);
- }
+ String set = classElement.getAttributeValue("set");
+ if (set != null && !set.isEmpty()) {
+ aerospikeMapping.setSet(set);
}
}
}
@@ -262,8 +269,9 @@ public class AerospikeMappingBuilder {
*/
private boolean getRetryOnTimeoutPolicy(String retry) {
- if (retry == null)
+ if (retry == null) {
return false;
+ }
boolean retryOnTimeout;
switch (retry) {
@@ -289,8 +297,9 @@ public class AerospikeMappingBuilder {
*/
private int getTimeoutValue(String timeout) {
- if (timeout == null)
+ if (timeout == null) {
return 0;
+ }
int timeoutInt = 0;
try {
timeoutInt = Integer.valueOf(timeout);
@@ -299,5 +308,4 @@ public class AerospikeMappingBuilder {
}
return timeoutInt;
}
-
}
http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
index 141808d..5cb91e2 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
@@ -41,7 +41,7 @@ public class AerospikeParameters {
// Property names
private static final String AS_SERVER_IP = "server.ip";
- private static final String AS_SERVER_port = "server.port";
+ private static final String AS_SERVER_PORT = "server.port";
// Default property values
private static final String DEFAULT_SERVER_IP = "localhost";
@@ -59,7 +59,7 @@ public class AerospikeParameters {
public AerospikeParameters(AerospikeMapping aerospikeMapping, Properties properties) {
this.aerospikeMapping = aerospikeMapping;
this.host = properties.getProperty(AS_SERVER_IP, DEFAULT_SERVER_IP);
- this.port = Integer.parseInt(properties.getProperty(AS_SERVER_port, DEFAULT_SERVER_PORT));
+ this.port = Integer.parseInt(properties.getProperty(AS_SERVER_PORT, DEFAULT_SERVER_PORT));
}
public String getHost() {
@@ -170,13 +170,10 @@ public class AerospikeParameters {
* @param fields fields of the persistent class
*/
public void validateServerBinConfiguration(Field[] fields) {
- if (isSingleBinEnabled) {
- if (fields.length != 1) {
- LOG.error(
- "Aerospike server is single bin enabled and cannot allow multiple bin operations");
- throw new RuntimeException("Aerospike server is single bin enabled and cannot allow "
- + "multiple bin operations");
- }
+ if (isSingleBinEnabled && fields.length != 1) {
+ LOG.error("Aerospike server is single bin enabled and cannot allow multiple bin operations");
+ throw new RuntimeException("Aerospike server is single bin enabled and cannot allow "
+ + "multiple bin operations");
}
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 66de783..01fdd93 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -280,9 +280,10 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
case MAP:
Map<Object, Object> newMap = new HashMap<>();
Map<?, ?> fieldMap = (Map<?, ?>) object;
- for (Object key : fieldMap.keySet()) {
- newMap.put(key.toString(),
- getSerializableValue(fieldMap.get(key), schema.getValueType()));
+
+ for (Map.Entry<?, ?> entry : fieldMap.entrySet()) {
+ newMap.put(entry.getKey().toString(),
+ getSerializableValue(fieldMap.get(entry.getKey()), schema.getValueType()));
}
value = Value.get(newMap);
break;
@@ -444,28 +445,39 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
int unionSchemaPos = 0;
for (Schema currentSchema : unionSchema.getTypes()) {
Schema.Type schemaType = currentSchema.getType();
- if (instanceValue instanceof CharSequence && schemaType.equals(Schema.Type.STRING))
+ if (instanceValue instanceof CharSequence && schemaType.equals(Schema.Type.STRING)) {
return unionSchemaPos;
- else if (instanceValue instanceof ByteBuffer && schemaType.equals(Schema.Type.BYTES))
+ }
+ if (instanceValue instanceof ByteBuffer && schemaType.equals(Schema.Type.BYTES)) {
return unionSchemaPos;
- else if (instanceValue instanceof byte[] && schemaType.equals(Schema.Type.BYTES))
+ }
+ if (instanceValue instanceof byte[] && schemaType.equals(Schema.Type.BYTES)) {
return unionSchemaPos;
- else if (instanceValue instanceof Integer && schemaType.equals(Schema.Type.INT))
+ }
+ if (instanceValue instanceof Integer && schemaType.equals(Schema.Type.INT)) {
return unionSchemaPos;
- else if (instanceValue instanceof Long && schemaType.equals(Schema.Type.LONG))
+ }
+ if (instanceValue instanceof Long && schemaType.equals(Schema.Type.LONG)) {
return unionSchemaPos;
- else if (instanceValue instanceof Double && schemaType.equals(Schema.Type.DOUBLE))
+ }
+ if (instanceValue instanceof Double && schemaType.equals(Schema.Type.DOUBLE)) {
return unionSchemaPos;
- else if (instanceValue instanceof Float && schemaType.equals(Schema.Type.FLOAT))
+ }
+ if (instanceValue instanceof Float && schemaType.equals(Schema.Type.FLOAT)) {
return unionSchemaPos;
- else if (instanceValue instanceof Boolean && schemaType.equals(Schema.Type.BOOLEAN))
+ }
+ if (instanceValue instanceof Boolean && schemaType.equals(Schema.Type.BOOLEAN)) {
return unionSchemaPos;
- else if (instanceValue instanceof Map && schemaType.equals(Schema.Type.MAP))
+ }
+ if (instanceValue instanceof Map && schemaType.equals(Schema.Type.MAP)) {
return unionSchemaPos;
- else if (instanceValue instanceof List && schemaType.equals(Schema.Type.ARRAY))
+ }
+ if (instanceValue instanceof List && schemaType.equals(Schema.Type.ARRAY)) {
return unionSchemaPos;
- else if (instanceValue instanceof Persistent && schemaType.equals(Schema.Type.RECORD))
+ }
+ if (instanceValue instanceof Persistent && schemaType.equals(Schema.Type.RECORD)) {
return unionSchemaPos;
+ }
unionSchemaPos++;
}
return 0;
http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
index e92fa51..30f72b3 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
index 10ef7a1..6c025e4 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -34,8 +34,8 @@ import java.util.Properties;
*/
public class GoraAerospikeTestDriver extends GoraTestDriver {
- private GenericContainer aerospikeContainer;
- private Properties properties = DataStoreFactory.createProps();
+ private final GenericContainer aerospikeContainer;
+ private final Properties properties = DataStoreFactory.createProps();
public GoraAerospikeTestDriver(GenericContainer aerospikeContainer) {
super(AerospikeStore.class);
[19/32] gora git commit: Refactor code
Posted by dj...@apache.org.
Refactor code
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/ecd3c598
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/ecd3c598
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/ecd3c598
Branch: refs/heads/master
Commit: ecd3c598b98212cbd47cd415819b62614496839e
Parents: 65201d1
Author: nishadi <nd...@gmail.com>
Authored: Thu Jun 29 09:44:37 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jun 29 09:44:37 2017 +0530
----------------------------------------------------------------------
.../org/apache/gora/aerospike/store/AerospikeParameters.java | 4 ++--
.../java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/ecd3c598/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
index 5cb91e2..61ea17a 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
@@ -39,9 +39,9 @@ public class AerospikeParameters {
private boolean isSingleBinEnabled;
// Property names
- private static final String AS_SERVER_IP = "server.ip";
+ private static final String AS_SERVER_IP = "gora.aerospikestore.server.ip";
- private static final String AS_SERVER_PORT = "server.port";
+ private static final String AS_SERVER_PORT = "gora.aerospikestore.server.port";
// Default property values
private static final String DEFAULT_SERVER_IP = "localhost";
http://git-wip-us.apache.org/repos/asf/gora/blob/ecd3c598/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
index 6c025e4..5a086d8 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -62,7 +62,7 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
* @param keyClass The key class.
* @param persistentClass The value class.
* @return A new store instance.
- * @throws GoraException
+ * @throws GoraException If an error occur in creating the data store
*/
@Override
public <K, T extends Persistent> DataStore<K, T> createDataStore(Class<K> keyClass, Class<T> persistentClass)
[31/32] gora git commit: Add log based waiting strategy for the
aerospike tests
Posted by dj...@apache.org.
Add log based waiting strategy for the aerospike tests
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/7a5d7677
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/7a5d7677
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/7a5d7677
Branch: refs/heads/master
Commit: 7a5d7677e6ae10318907876c58727d68bdd72bac
Parents: 38037ca
Author: nishadi <nd...@gmail.com>
Authored: Thu Jul 27 22:53:13 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Thu Jul 27 22:53:13 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/GoraAerospikeTestDriver.java | 5 +-
.../store/AerospikeStartupLogWaitStrategy.java | 53 ++++++++++++++++++++
.../aerospike/store/TestAerospikeStore.java | 7 ++-
3 files changed, 59 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/7a5d7677/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
index 74b32b1..88ae360 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -46,10 +46,6 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
@Override
public void setUpClass() throws Exception {
-
- // Wait for the aerospike server to be started in the container
- Thread.sleep(5000);
-
properties.setProperty("gora.aerospikestore.server.ip", "localhost");
properties.setProperty("gora.aerospikestore.server.port",
aerospikeContainer.getMappedPort(3000).toString());
@@ -57,6 +53,7 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
@Override
public void tearDownClass() throws Exception {
+ aerospikeContainer.stop();
}
/**
http://git-wip-us.apache.org/repos/asf/gora/blob/7a5d7677/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/AerospikeStartupLogWaitStrategy.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/AerospikeStartupLogWaitStrategy.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/AerospikeStartupLogWaitStrategy.java
new file mode 100644
index 0000000..8b9cf5e
--- /dev/null
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/AerospikeStartupLogWaitStrategy.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.aerospike.store;
+
+import org.testcontainers.containers.ContainerLaunchException;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.OutputFrame;
+import org.testcontainers.containers.output.WaitingConsumer;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.Predicate;
+
+public class AerospikeStartupLogWaitStrategy extends GenericContainer.AbstractWaitStrategy {
+
+ private static final String regEx = ".*heartbeat-received: self 0 foreign 0.*";
+
+ private int times = 2;
+
+ protected void waitUntilReady() {
+ WaitingConsumer waitingConsumer = new WaitingConsumer();
+ this.container.followOutput(waitingConsumer);
+ Predicate waitPredicate = (outputFrame) -> {
+ String trimmedFrameText = ((OutputFrame) outputFrame).getUtf8String().replaceFirst("\n$", "");
+ return trimmedFrameText.matches(regEx);
+ };
+
+ try {
+ waitingConsumer.waitUntil(waitPredicate, this.startupTimeout.getSeconds(), TimeUnit.SECONDS,
+ this.times);
+ } catch (TimeoutException var4) {
+ throw new ContainerLaunchException(
+ "Timed out waiting for log output matching Aerospike server startup Log \'" + regEx
+ + "\'");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/gora/blob/7a5d7677/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index 11ed458..c1b4e2d 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -30,7 +30,8 @@ import org.junit.Ignore;
import org.junit.Test;
import org.testcontainers.containers.GenericContainer;
-import static org.apache.gora.examples.WebPageDataCreator.SORTED_URLS;
+import java.time.Duration;
+
import static org.apache.gora.examples.WebPageDataCreator.URLS;
/**
@@ -41,7 +42,9 @@ public class TestAerospikeStore extends DataStoreTestBase {
private static final String DOCKER_CONTAINER_NAME = "aerospike/aerospike-server:latest";
@ClassRule
- public static GenericContainer aerospikeContainer = new GenericContainer(DOCKER_CONTAINER_NAME);
+ public static GenericContainer aerospikeContainer = new GenericContainer(DOCKER_CONTAINER_NAME)
+ .withExposedPorts(3000).waitingFor(new AerospikeStartupLogWaitStrategy())
+ .withStartupTimeout(Duration.ofSeconds(240));
static {
setTestDriver(new GoraAerospikeTestDriver(aerospikeContainer));
[14/32] gora git commit: Add delete functionality for aerospike module
Posted by dj...@apache.org.
Add delete functionality for aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/b61eeaf0
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/b61eeaf0
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/b61eeaf0
Branch: refs/heads/master
Commit: b61eeaf0529f070ba19db904821b517a9e5528dc
Parents: c72f418
Author: nishadi <nd...@gmail.com>
Authored: Mon Jun 26 19:07:07 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Mon Jun 26 19:07:07 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/store/AerospikeStore.java | 49 ++++++++++++--------
.../aerospike/store/TestAerospikeStore.java | 2 +-
2 files changed, 31 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/b61eeaf0/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 5a880d6..66de783 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -143,16 +143,9 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
@Override
public T get(K key, String[] fields) {
- Value keyValue;
- if (keyClass.getSimpleName().equalsIgnoreCase("string")) {
- keyValue = Value.get(key.toString());
- } else {
- keyValue = Value.get(key);
- }
-
+ Key recordKey = getAerospikeKey(key);
fields = getFieldsToQuery(fields);
- Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
- aerospikeParameters.getAerospikeMapping().getSet(), keyValue);
+
Record record = aerospikeClient
.get(aerospikeParameters.getAerospikeMapping().getReadPolicy(), recordKey, fields);
if (record == null) {
@@ -172,15 +165,7 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
@Override
public void put(K key, T persistent) {
- Value keyValue;
- if (keyClass.getSimpleName().equalsIgnoreCase("string")) {
- keyValue = Value.get(key.toString());
- } else {
- keyValue = Value.get(key);
- }
-
- Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
- aerospikeParameters.getAerospikeMapping().getSet(), keyValue);
+ Key recordKey = getAerospikeKey(key);
List<Field> fields = persistent.getSchema().getFields();
for (int i = 0; i < fields.size(); i++) {
@@ -204,9 +189,17 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
}
}
+ /**
+ * {@inheritDoc}
+ *
+ * @param key the key of the object
+ * @return whether the object was successfully deleted
+ */
@Override
public boolean delete(K key) {
- return true;
+ Key recordKey = getAerospikeKey(key);
+ return aerospikeClient
+ .delete(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey);
}
@Override
@@ -243,6 +236,24 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
}
/**
+ * Method to get the aerospike key from the provided K
+ *
+ * @param key persistent key
+ * @return aerospike key for the record
+ */
+ public Key getAerospikeKey(K key) {
+ Value keyValue;
+ if (keyClass.getSimpleName().equalsIgnoreCase("string")) {
+ keyValue = Value.get(key.toString());
+ } else {
+ keyValue = Value.get(key);
+ }
+
+ return new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
+ aerospikeParameters.getAerospikeMapping().getSet(), keyValue);
+ }
+
+ /**
* Method to get the value serializable in database from the Avro persistent object
*
* @param object persistent object
http://git-wip-us.apache.org/repos/asf/gora/blob/b61eeaf0/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index 8b63414..9e93fb0 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -134,7 +134,7 @@ public class TestAerospikeStore extends DataStoreTestBase {
}
@Test
- @Ignore("To be implemented")
+ @Ignore("Functionality is to be implemented in the next iteration as this incurs query execution")
@Override
public void testDelete() throws Exception {
super.testDelete();
[08/32] gora git commit: Update put method to support field mapping
in aerospike module
Posted by dj...@apache.org.
Update put method to support field mapping in aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/eae36f47
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/eae36f47
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/eae36f47
Branch: refs/heads/master
Commit: eae36f4752f0e22465df552b1c8da1cb5db347fb
Parents: 13f252e
Author: nishadi <nd...@gmail.com>
Authored: Mon Jun 19 21:55:15 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Tue Jun 20 17:33:36 2017 +0530
----------------------------------------------------------------------
.../gora/aerospike/store/AerospikeStore.java | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/eae36f47/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index c452857..df2f38d 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -91,18 +91,21 @@ public class AerospikeStore<K, T extends PersistentBase> extends DataStoreBase<K
return null;
}
- @Override public void put(K key, T value) {
+ @Override public void put(K key, T persistent) {
Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
aerospikeParameters.getAerospikeMapping().getSet(), Value.get(key));
- List<Field> fields = value.getSchema().getFields();
-
+ List<Field> fields = persistent.getSchema().getFields();
for (int i = 0; i < fields.size(); i++) {
-
- // In retrieving the bin name, it is checked whether the server is single bin valued
- String binName = aerospikeParameters.getBinName(fields.get(i).name());
- Bin bin = getBin(binName, value.get(i), fields.get(i));
+ String mappingBinName = aerospikeParameters.getAerospikeMapping().getBinMapping()
+ .get(fields.get(i).name());
+ if (mappingBinName == null) {
+ throw new RuntimeException(
+ "Aerospike mapping for field [" + persistent.getClass().getName() + "#" + fields
+ .get(i).name() + "] not found. Wrong gora-aerospike-mapping.xml?");
+ }
+ Bin bin = getBin(mappingBinName, persistent.get(i), fields.get(i));
aerospikeClient
.put(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey, bin);
}
[25/32] gora git commit: Update test driver properties for aerospike
module
Posted by dj...@apache.org.
Update test driver properties for aerospike module
Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/08fb5dd3
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/08fb5dd3
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/08fb5dd3
Branch: refs/heads/master
Commit: 08fb5dd3465bf636093b056b059c8ce2deda42df
Parents: 6ee55e9
Author: nishadi <nd...@gmail.com>
Authored: Wed Jul 26 21:15:01 2017 +0530
Committer: nishadi <nd...@gmail.com>
Committed: Wed Jul 26 21:15:01 2017 +0530
----------------------------------------------------------------------
.../java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/gora/blob/08fb5dd3/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
index 5a086d8..302f605 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -48,8 +48,8 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
// Wait for the aerospike server to be started in the container
Thread.sleep(5000);
- properties.setProperty("server.ip", "localhost");
- properties.setProperty("server.port", aerospikeContainer.getMappedPort(3000).toString());
+ properties.setProperty("gora.aerospikestore.server.ip", "localhost");
+ properties.setProperty("gora.aerospikestore.server.port", aerospikeContainer.getMappedPort(3000).toString());
}
@Override