Skip to content

Commit

Permalink
Merge pull request #648 from risdenk/pr-483
Browse files Browse the repository at this point in the history
[geode] Checkstyle updates for Apache Geode (incubating)
  • Loading branch information
busbey committed Mar 21, 2016
2 parents f23aa0e + fa281eb commit 280a2d1
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 45 deletions.
24 changes: 24 additions & 0 deletions geode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,29 @@ LICENSE file.
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<configuration>
<consoleOutput>true</consoleOutput>
<configLocation>../checkstyle.xml</configLocation>
<failOnViolation>true</failOnViolation>
<failsOnError>true</failsOnError>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
72 changes: 27 additions & 45 deletions geode/src/main/java/com/yahoo/ycsb/db/GeodeClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright (c) 2013 - 2016 YCSB Contributors. All rights reserved.
*
* <p>
* Licensed 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
Expand All @@ -17,67 +17,52 @@

package com.yahoo.ycsb.db;

import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.GemFireCache;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionExistsException;
import com.gemstone.gemfire.cache.RegionFactory;
import com.gemstone.gemfire.cache.RegionShortcut;
import com.gemstone.gemfire.cache.*;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.cache.client.ClientRegionFactory;
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
import com.gemstone.gemfire.internal.admin.remote.DistributionLocatorId;
import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import com.yahoo.ycsb.*;

import java.util.*;

/**
* Apache Geode (incubating) client for the YCSB benchmark.<br />
* Apache Geode (incubating) client for the YCSB benchmark.<br />
* <p>By default acts as a Geode client and tries to connect
* to Geode cache server running on localhost with default
* cache server port. Hostname and port of a Geode cacheServer
* can be provided using <code>geode.serverport=port</code> and <code>
* geode.serverhost=host</code> properties on YCSB command line.
* A locator may also be used for discovering a cacheServer
* by using the property <code>geode.locator=host[port]</code></p>
*
*
* <p>To run this client in a peer-to-peer topology with other Geode
* nodes, use the property <code>geode.topology=p2p</code>. Running
* in p2p mode will enable embedded caching in this client.</p>
*
*
* <p>YCSB by default does its operations against "usertable". When running
* as a client this is a <code>ClientRegionShortcut.PROXY</code> region,
* when running in p2p mode it is a <code>RegionShortcut.PARTITION</code>
* region. A cache.xml defining "usertable" region can be placed in the
* working directory to override these region definitions.</p>
*
*
*/
public class GeodeClient extends DB {

/** property name of the port where Geode server is listening for connections */
/** property name of the port where Geode server is listening for connections. */
private static final String SERVERPORT_PROPERTY_NAME = "geode.serverport";

/** property name of the host where Geode server is running */
/** property name of the host where Geode server is running. */
private static final String SERVERHOST_PROPERTY_NAME = "geode.serverhost";

/** default value of {@link #SERVERHOST_PROPERTY_NAME} */
/** default value of {@link #SERVERHOST_PROPERTY_NAME}. */
private static final String SERVERHOST_PROPERTY_DEFAULT = "localhost";

/** property name to specify a Geode locator. This property can be used in both
* client server and p2p topology */
private static final String LOCATOR_PROPERTY_NAME = "geode.locator";

/** property name to specify Geode topology */
/** property name to specify Geode topology. */
private static final String TOPOLOGY_PROPERTY_NAME = "geode.topology";

/** value of {@value #TOPOLOGY_PROPERTY_NAME} when peer to peer topology should be used.
Expand All @@ -86,12 +71,9 @@ public class GeodeClient extends DB {

private GemFireCache cache;

/**
* true if ycsb client runs as a client to a
* Geode cache server
*/
/** true if ycsb client runs as a client to a Geode cache server. */
private boolean isClient;

@Override
public void init() throws DBException {
Properties props = getProperties();
Expand All @@ -108,7 +90,7 @@ public void init() throws DBException {
}
serverHost = props.getProperty(SERVERHOST_PROPERTY_NAME, SERVERHOST_PROPERTY_DEFAULT);
locatorStr = props.getProperty(LOCATOR_PROPERTY_NAME);

String topology = props.getProperty(TOPOLOGY_PROPERTY_NAME);
if (topology != null && topology.equals(TOPOLOGY_P2P_VALUE)) {
CacheFactory cf = new CacheFactory();
Expand All @@ -133,10 +115,10 @@ public void init() throws DBException {
}
cache = ccf.create();
}

@Override
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
HashMap<String, ByteIterator> result) {
Region<String, Map<String, byte[]>> r = getRegion(table);
Map<String, byte[]> val = r.get(key);
if (val != null) {
Expand All @@ -156,7 +138,7 @@ public Status read(String table, String key, Set<String> fields,

@Override
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
// Geode does not support scan
return Status.ERROR;
}
Expand All @@ -179,23 +161,24 @@ public Status delete(String table, String key) {
return Status.OK;
}

private Map<String, byte[]> convertToBytearrayMap(Map<String,ByteIterator> values) {
private Map<String, byte[]> convertToBytearrayMap(Map<String, ByteIterator> values) {
Map<String, byte[]> retVal = new HashMap<String, byte[]>();
for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
retVal.put(entry.getKey(), entry.getValue().toArray());
}
return retVal;
}

private Region<String, Map<String, byte[]>> getRegion(String table) {
Region<String, Map<String, byte[]>> r = cache.getRegion(table);
if (r == null) {
try {
if (isClient) {
ClientRegionFactory<String, Map<String, byte[]>> crf = ((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY);
ClientRegionFactory<String, Map<String, byte[]>> crf =
((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY);
r = crf.create(table);
} else {
RegionFactory<String, Map<String, byte[]>> rf = ((Cache)cache).createRegionFactory(RegionShortcut.PARTITION);
RegionFactory<String, Map<String, byte[]>> rf = ((Cache) cache).createRegionFactory(RegionShortcut.PARTITION);
r = rf.create(table);
}
} catch (RegionExistsException e) {
Expand All @@ -205,5 +188,4 @@ private Region<String, Map<String, byte[]>> getRegion(String table) {
}
return r;
}

}
}
21 changes: 21 additions & 0 deletions geode/src/main/java/com/yahoo/ycsb/db/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2014-2016, Yahoo!, Inc. All rights reserved.
*
* Licensed 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. See accompanying
* LICENSE file.
*/

/**
* YCSB binding for <a href="https://geode.incubator.apache.org/">Apache Geode (incubating)</a>.
*/
package com.yahoo.ycsb.db;

0 comments on commit 280a2d1

Please sign in to comment.