Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GORA-502 Implement Aerospike Data Store #111

Merged
merged 2 commits into from Jul 27, 2017
Merged

Conversation

nishadi
Copy link
Contributor

@nishadi nishadi commented Jun 20, 2017

This is a work in progress branch

Copy link
Member

@lewismc lewismc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very good @nishadi

Please consider my comments and additionally

  • Make sure that every license header is a comment only and not a documentation block e.g. use following
/*
 *
 *
 */

instead of

/**
  *
  *
  */
  • Also please begin to document EVERY public method as you make your way through the code. This will distinguish your code as of higher quality.

Thank you, this is an excellent start.

SAXBuilder saxBuilder = new SAXBuilder();
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(mappingFile);
if (inputStream == null) {
LOG.warn("Mapping file '" + mappingFile + "' could not be found!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use parameterized logging.

}
Document document = saxBuilder.build(inputStream);
if (document == null) {
LOG.warn("Mapping file '" + mappingFile + "' could not be found!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use parameterized logging.

@@ -0,0 +1,127 @@
package org.apache.gora.aerospike.store;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the header

import java.util.List;
import java.util.Properties;

import com.aerospike.client.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove wildcard imports please. Use explicit imports. Thank you.

}

/**
* Aerospike does not support Utf8 format returned from Avro.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is bin? Can you elaborate and make it clearer?

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please retain HBaseStore are default and merely add AerospikeStore to end of list.

pom.xml Outdated
<groupId>org.apache.gora</groupId>
<artifactId>gora-aerospike</artifactId>
<version>${project.version}</version>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also include the test artifact e.g.

+      <dependency>
+        <groupId>org.apache.gora</groupId>
+        <artifactId>gora-aerospike</artifactId>
+        <version>${project.version}</version>
+        <type>test-jar</type>
+      </dependency>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the test artifact

</ciManagement>

<properties>
<aerospike.version>3.3.2</aerospike.version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to include aerospike.version here if you have already included in within parent pom.xml.

<artifactId>junit</artifactId>
</dependency>

<dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this dependency to parent pom and define version separately.

*/
public class GoraAerospikeTestDriver extends GoraTestDriver {

private GenericContainer aerospikeContainer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check whether you can make this test-containers code generic, this can be reused for other datastore which doesn't have java based embedded server.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the GoraTestDriver class we can add this field( GenericContaine), and in the instances when we need to use the docker based setup environment, we can provide a separate constructor to handle the container. I will look further into generalizing this further to create the docker instance at the DataStoreTestBase level.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final variable?

@djkevincr
Copy link
Member

@nishadi very good work, heading in right direction :)

@nishadi
Copy link
Contributor Author

nishadi commented Jun 26, 2017

@lewismc @djkevincr Thank you for reviewing. Updated the code base as per the given feedback :)

if (policy != null) {
if (policy.equals("write")) {
WritePolicy writePolicy = new WritePolicy();
if (policyElement.getAttributeValue("gen") != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that my comment is not placed when I wrote it. I wrote about that:
Could you check this Apple bug: https://www.imperialviolet.org/2014/02/22/applebug.html

Please put curly braces even they are single line of if statements at your PR.


private static final Logger LOG = LoggerFactory.getLogger(AerospikeMappingBuilder.class);

private AerospikeMapping aerospikeMapping;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final variable?

public class GoraAerospikeTestDriver extends GoraTestDriver {

private GenericContainer aerospikeContainer;
private Properties properties = DataStoreFactory.createProps();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final variable?

@@ -0,0 +1,20 @@
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** -> /*

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the doc comment

@@ -0,0 +1,20 @@
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** -> /*

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the doc comment

* @param keyClass The key class.
* @param persistentClass The value class.
* @return A new store instance.
* @throws GoraException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@throws -> throws

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the exception description

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else after a return statement?


String policy = policyElement.getAttributeValue("name");
if (policy != null) {
if (policy.equals("write")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an enum for such policies?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no ENUM for policy names at this level (write policies or read policies). But when defining values for each policy, there are ENUMs which I have used in below sections while assigning the policy values.

String mappingKeyClass = classElement.getAttributeValue("keyClass");
String mappingClassName = classElement.getAttributeValue("name");

if (mappingKeyClass != null && mappingClassName != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and below lines of if statements can be merged.

// Property names
private static final String AS_SERVER_IP = "server.ip";

private static final String AS_SERVER_port = "server.port";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AS_SERVER_port -> AS_SERVER_PORT?

* @param fields fields of the persistent class
*/
public void validateServerBinConfiguration(Field[] fields) {
if (isSingleBinEnabled) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and below lines of if statements can be merged.

case MAP:
Map<Object, Object> newMap = new HashMap<>();
Map<?, ?> fieldMap = (Map<?, ?>) object;
for (Object key : fieldMap.keySet()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can iterate over the entrySet.

public void setUpClass() throws Exception {

// Wait for the aerospike server to be started in the container
Thread.sleep(5000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check this condition with a framework like Awaitility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check for a method to find out whether the server has been started in the docker container, so that we can use this framework in waiting for the status of the server

@nishadi
Copy link
Contributor Author

nishadi commented Jun 29, 2017

@kamaci thank you for reviewing. Added changes as suggested

<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do this. Instead use the @ Ignore syntax for JUnit. Please see http://junit.sourceforge.net/javadoc/org/junit/Ignore.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Lewis, This was done basically as I have used Docker to start up the Aerospike server for the test cases. If the build environment does not have Docker environment, the test cases get failed due to the absence of the server. That is the reason why the test cases are made skipped by default as it is done in the couchdb store.
https://lists.apache.org/thread.html/d9816c1e3f3a73fe07a3bc19035c532ffde2163aca5cc43e6d854158@%3Cdev.gora.apache.org%3E

I have added a profile to activate the test cases when we need to run the test cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lewismc Shall I proceed merging the PR to master? Are you done with reviewing/happy with the changes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy with this +1 from me

<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.1.0</version>
<scope>test</scope>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define the version separately in parent pom.

@djkevincr
Copy link
Member

Build passes without any issue.

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Apache Gora ....................................... SUCCESS [1.370s]
[INFO] Apache Gora :: Compiler ........................... SUCCESS [2.063s]
[INFO] Apache Gora :: Compiler-CLI ....................... SUCCESS [1.380s]
[INFO] Apache Gora :: Core ............................... SUCCESS [1:17.004s]
[INFO] Apache Gora :: Accumulo ........................... SUCCESS [1:33.638s]
[INFO] Apache Gora :: Cassandra .......................... SUCCESS [53.152s]
[INFO] Apache Gora :: GoraCI ............................. SUCCESS [3.377s]
[INFO] Apache Gora :: HBase .............................. SUCCESS [2:38.696s]
[INFO] Apache Gora :: Infinispan ......................... SUCCESS [1:19.227s]
[INFO] Apache Gora :: JCache ............................. SUCCESS [1:11.505s]
[INFO] Apache Gora :: Dynamodb ........................... SUCCESS [4.452s]
[INFO] Apache Gora :: CouchDB ............................ SUCCESS [3.742s]
[INFO] Apache Gora :: Maven Plugin ....................... SUCCESS [3.379s]
[INFO] Apache Gora :: MongoDB ............................ SUCCESS [1:29.381s]
[INFO] Apache Gora :: Solr ............................... SUCCESS [3:00.093s]
[INFO] Apache Gora :: Aerospike .......................... SUCCESS [3.017s]
[INFO] Apache Gora :: Tutorial ........................... SUCCESS [7.266s]
[INFO] Apache Gora :: Sources-Dist ....................... SUCCESS [0.501s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13:54.015s
[INFO] Finished at: Thu Jul 27 23:40:39 IST 2017
[INFO] Final Memory: 80M/710M
[INFO] ------------------------------------------------------------------------

@nishadi nishadi changed the title [WIP] GORA-502 Implement Aerospike Data Store GORA-502 Implement Aerospike Data Store Jul 27, 2017
@djkevincr
Copy link
Member

Locally tested Aerospike datastore tests with activating maven profile - mvn clean install -P aerospike-with-test

Results :

Tests run: 33, Failures: 0, Errors: 0, Skipped: 8

@asfgit asfgit merged commit 0e8b046 into apache:master Jul 27, 2017
@djkevincr
Copy link
Member

@nishadi This is really awesome work :) I am really happy to merge your work to the master. As we discussed please create tickets for any remaining work. Once again we are really thankful for your awesome contributions.
Thanks all for reviewing the PR. @lewismc @kamaci @renato2099

@lewismc
Copy link
Member

lewismc commented Jul 27, 2017

Can you guys possibly upgrade aerospike-client to most recent?
http://search.maven.org/#artifactdetails|com.aerospike|aerospike-client|4.0.6|jar

@djkevincr
Copy link
Member

+1

@nishadi
Copy link
Contributor Author

nishadi commented Jul 27, 2017

I will update the client to the latest.

https://issues.apache.org/jira/browse/GORA-515

@nishadi
Copy link
Contributor Author

nishadi commented Jul 27, 2017

I have sent the PR on the aerospike client update. Thanks a lot @djkevincr for merging to the master. Thanks a lot to the great the support given. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants