gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djkevi...@apache.org
Subject [10/32] gora git commit: Refactor code with comments, logging and exception handling
Date Thu, 27 Jul 2017 18:45:36 GMT
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 <ndimeshi@gmail.com>
Authored: Thu Jun 22 19:53:52 2017 +0530
Committer: nishadi <ndimeshi@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?");
     }


Mime
View raw message