[ https://issues.apache.org/jira/browse/GORA-502?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16064155#comment-16064155 ]
ASF GitHub Bot commented on GORA-502: ------------------------------------- Github user kamaci commented on a diff in the pull request: https://github.com/apache/gora/pull/111#discussion_r124165992 --- Diff: gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java --- @@ -0,0 +1,182 @@ +/* + * 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 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 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"; + + private static final Logger LOG = LoggerFactory.getLogger(AerospikeParameters.class); + + /** + * 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); + this.port = Integer.parseInt(properties.getProperty(AS_SERVER_port, DEFAULT_SERVER_PORT)); + } + + 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 isSingleBinEnabled() { + return isSingleBinEnabled; + } + + 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) { + + 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) { + LOG.error("Failed to get namespace info from Aerospike"); + throw new RuntimeException("Failed to get namespace info from Aerospike"); + } + } + + /** + * 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); + + 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); + } + + /** + * 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) { --- End diff -- This and below lines of if statements can be merged. > Implement Aerospike Datastore > ----------------------------- > > Key: GORA-502 > URL: https://issues.apache.org/jira/browse/GORA-502 > Project: Apache Gora > Issue Type: New Feature > Components: gora-aerospike, storage > Affects Versions: 0.6.1 > Reporter: Cihad Guzel > Assignee: Nishadi Kirielle > Labels: gsoc2017 > Fix For: 0.8 > > > Aerospike is a NoSQL database solution for real-time operational > applications, delivering predictable performance at scale, superior uptime, > and high availability at the lowest TCO compared to first-generation NoSQL > and relational databases. It could be nice to support Aerospike as a > datastore at Gora. Aerospike uses Apache v2 license for Java client and uses > aGPL license for Aerospike Server Community Edition. > (http://www.aerospike.com/products/) -- This message was sent by Atlassian JIRA (v6.4.14#64029)