Skip to content

Commit

Permalink
Merge pull request #17 from diegopacheco/dev
Browse files Browse the repository at this point in the history
Support for Rnd k/v and new Redis Validation Tasks.
  • Loading branch information
diegopacheco committed Mar 28, 2018
2 parents defec8b + 091d587 commit 8eaa92e
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 50 deletions.
4 changes: 2 additions & 2 deletions dynomite-cluster-checker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ run {

repositories {
jcenter()
mavenLocal()
mavenCentral()
}

buildscript {
repositories {
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:+'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.diegopacheco.dynomite.cluster.checker.cluster;

import com.github.diegopacheco.dynomite.cluster.checker.parser.DynomiteNodeInfo;

import redis.clients.jedis.Jedis;

/**
* RedisNodeConnectionManager connects to a single redis node.
*
* @author diegopacheco
* @since 27/03/2018
*
*/
public class RedisNodeConnectionManager {

public static Jedis createNodeConnection(DynomiteNodeInfo node) {
Jedis jedisClient = new Jedis(node.getServer(), new Integer(node.getRedisPort()));
jedisClient.connect();
return jedisClient;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@

import org.apache.log4j.Logger;

import com.github.diegopacheco.dynomite.cluster.checker.cluster.DCCConnectionManager;
import com.github.diegopacheco.dynomite.cluster.checker.parser.DynomiteNodeInfo;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import com.netflix.dyno.jedis.DynoJedisClient;

@Singleton
public class ClientCache {
public class DynoClientCache {

private static Cache<String, DynoJedisClient> cache;
private static final Logger logger = Logger.getLogger(ClientCache.class);
private static final Logger logger = Logger.getLogger(DynoClientCache.class);

static {
cache = CacheBuilder.newBuilder().
Expand Down Expand Up @@ -49,19 +47,4 @@ public static void put(String seeds, DynoJedisClient client) {
cache.put(seeds, client);
}

public static void main(String[] args) {
String seeds = "127.0.0.1:8102:rack1:dc:100";
DynoJedisClient client = DCCConnectionManager.createSingleNodeCluster("test1",new DynomiteNodeInfo("127.0.0.1", "8102", "rack1", "dc", "100"));

ClientCache.put(seeds, client);
System.out.println(ClientCache.get(seeds));
System.out.println(ClientCache.get(seeds));
System.out.println(ClientCache.get(seeds));

String seeds2 = "127.0.0.1:8102:rack1:dc:0";
ClientCache.put(seeds2, client);
System.out.println(ClientCache.get(seeds2));
System.out.println(ClientCache.get(seeds));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.diegopacheco.dynomite.cluster.checker.cluster.cache;

import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import org.apache.log4j.Logger;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;

import redis.clients.jedis.Jedis;

@Singleton
public class RedisClientCache {

private static Cache<String, Jedis> cache;
private static final Logger logger = Logger.getLogger(RedisClientCache.class);

static {
cache = CacheBuilder.newBuilder().
maximumSize(500).
expireAfterAccess(2, TimeUnit.HOURS).
removalListener(new RemovalListener<String, Jedis>() {
@Override
public void onRemoval(RemovalNotification<String, Jedis> notification) {
logger.debug("Removing... " + notification.getKey());
try {
notification.getValue().disconnect();
} catch (Exception e) {
logger.error("Error on close evicted client. EX: " + e);
}
}
}).build();
}

public static Jedis get(String node) {
try {
return cache.getIfPresent(node);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public static void put(String node, Jedis client) {
cache.put(node, client);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ public class ExecutionContext {
private List<DynomiteNodeInfo> offlineNodes = new ArrayList<>();

private DynoJedisClient wholeClusterClient = null;

private ExecutionReport executionReport = new ExecutionReport();

private String replicationKey;
private String replicationValue;

private String failOverKey;
private String failOverValue;

public ExecutionContext() {}


public String getRawSeeds() {
return rawSeeds;
}
Expand Down Expand Up @@ -77,5 +81,34 @@ public ExecutionReport getExecutionReport() {
public void setExecutionReport(ExecutionReport executionReport) {
this.executionReport = executionReport;
}

public String getReplicationKey() {
return replicationKey;
}
public void setReplicationKey(String replicationKey) {
this.replicationKey = replicationKey;
}

public String getReplicationValue() {
return (replicationValue==null) ? "" : replicationValue;
}
public void setReplicationValue(String replicationValue) {
this.replicationValue = replicationValue;
}

public String getFailOverKey() {
return failOverKey;
}

public void setFailOverKey(String failOverKey) {
this.failOverKey = failOverKey;
}

public String getFailOverValue() {
return (failOverValue==null) ? "" : failOverValue;
}
public void setFailOverValue(String failOverValue) {
this.failOverValue = failOverValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ExecutionReport {

private String failoverStatus = "";
private Integer replicationCount = 0;
private Integer redisReplicationCount = 0;

private List<NodeCheckerResponse> nodesReport = new ArrayList<>();
private List<DynomiteNodeInfo> offlineNodes = new ArrayList<>();
Expand Down Expand Up @@ -71,6 +72,13 @@ public void setReplicationCount(Integer replicationCount) {
this.replicationCount = replicationCount;
}

public Integer getRedisReplicationCount() {
return redisReplicationCount;
}
public void setRedisReplicationCount(Integer redisReplicationCount) {
this.redisReplicationCount = redisReplicationCount;
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down Expand Up @@ -111,7 +119,8 @@ public boolean equals(Object obj) {
@Override
public String toString() {
return "ExecutionReport [timeToRun=" + timeToRun + ", failoverStatus=" + failoverStatus + ", replicationCount="
+ replicationCount + ", nodesReport=" + nodesReport + ", offlineNodes=" + offlineNodes + "]";
+ replicationCount + ", redisReplicationCount=" + redisReplicationCount + ", nodesReport=" + nodesReport
+ ", offlineNodes=" + offlineNodes + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class NodeCheckerResponse implements JsonPrinter {
private String getTime;

private boolean consistency = false;
private boolean consistencyRedis = false;

private String insertError = null;
private String getError = null;
Expand Down Expand Up @@ -108,6 +109,7 @@ public String toJson(){
"\"insertError\":\"" + insertError + "\"," +
"\"getError\":\"" + getError + "\"," +
"\"consistency\":\"" + consistency + ",\"" +
"\"consistencyRedis\":\"" + consistencyRedis + ",\"" +
"}";
}

Expand All @@ -119,6 +121,7 @@ public String toPrettyJson(){
pritIfNotNull(" \"getTime\":\"" + getTime + "\",\r\n",getTime) +
pritIfNotNull(" \"insertError\":\"" + insertError + "\", \r\n",insertError) +
pritIfNotNull(" \"getError\":\"" + getError + "\", \r\n ",getError) +
pritIfNotNull(" \"consistencyRedis\":\"" + consistencyRedis + "\",\r\n",boolToString(consistencyRedis)) +
pritIfNotNull(" \"consistency\":\"" + consistency + "\"\r\n,",boolToString(consistency)) +
pritIfNotNull(" }",boolToString(true));
}
Expand All @@ -131,6 +134,7 @@ public String toPrettyTelemetryJson(){
pritIfNotNull(" \"getTime\":\"" + new Double(getTime().replace("ms", "").trim()).intValue() + "\",\r\n",getTime) +
pritIfNotNull(" \"insertError\":\"" + resolveErrorTelemetry(insertError) + "\",\r\n",resolveErrorTelemetry(insertError)) +
pritIfNotNull(" \"getError\":\"" + resolveErrorTelemetry(getError) + "\",\r\n",resolveErrorTelemetry(getError)) +
pritIfNotNull(" \"consistencyRedis\":\"" + resolveBoolean(consistencyRedis) + "\",\r\n",boolToString(consistencyRedis)) +
pritIfNotNull(" \"consistency\":\"" + resolveBoolean(consistency) + "\"\r\n" ,boolToString(consistency)) +
pritIfNotNull(" }",boolToString(true));
}
Expand Down Expand Up @@ -159,6 +163,38 @@ private String resolveErrorTelemetry(String field){
return ("".equals(field) || null == field) ? "0" : "1";
}

public boolean isConsistencyRedis() {
return consistencyRedis;
}
public void setConsistencyRedis(boolean consistencyRedis) {
this.consistencyRedis = consistencyRedis;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((seeds == null) ? 0 : seeds.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
NodeCheckerResponse other = (NodeCheckerResponse) obj;
if (seeds == null) {
if (other.seeds != null)
return false;
} else if (!seeds.equals(other.seeds))
return false;
return true;
}

@Override
public String toString() {
return toPrettyJson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void main(String[] args) {
Boolean isTelemetryMode = isTelemtryModeSet(args) ? true : false;

DCCTaskExecutionEngine dcc = new DCCTaskExecutionEngine();
String jsonResult = dcc.run(args[0], isTelemetryMode);
String jsonResult = dcc.run(extractArg(0,args), isTelemetryMode);

logger.info(jsonResult);
}catch(Exception e){
Expand All @@ -47,5 +47,13 @@ private static boolean isTelemtryModeSet(String[] args) {
String parameter = args[1];
return (parameter.equalsIgnoreCase("false") || parameter.equalsIgnoreCase("true"));
}

private static String extractArg(int index,String[] args) {
try {
return args[index];
}catch(Exception e) {
return "";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class DynomiteNodeInfo {
private String rack;
private String dc;
private String tokens;
private String redisPort = "6379";
private DynoJedisClient nodeClient;

public DynomiteNodeInfo() {}
Expand All @@ -32,6 +33,16 @@ public DynomiteNodeInfo(String server, String port, String rack, String dc, Stri
this.tokens = tokens;
}

public DynomiteNodeInfo(String server, String port, String rack, String dc, String tokens,String redisPort) {
super();
this.server = server;
this.port = port;
this.rack = rack;
this.dc = dc;
this.tokens = tokens;
this.redisPort = redisPort;
}

public String toJsonTopology(){
return " { \"token\":\""+ this.getTokens()
+ "\",\"hostname\":\"" + this.getServer()
Expand All @@ -50,6 +61,10 @@ public Host toHOST(){
public String toSeed(){
return getServer() + ":" + getPort() + ":" + getRack() + ":" + getDc() + ":" + getTokens();
}

public String toSeedRedis(){
return getServer() + ":" + getPort() + ":" + getRack() + ":" + getDc() + ":" + getTokens() + ":" + getRedisPort();
}

public String getServer() {
return server;
Expand Down Expand Up @@ -98,6 +113,14 @@ public void setNodeClient(DynoJedisClient nodeClient) {
this.nodeClient = nodeClient;
}

public String getRedisPort() {
return redisPort;
}

public void setRedisPort(String redisPort) {
this.redisPort = redisPort;
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down Expand Up @@ -125,7 +148,7 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return server + ":" + port + ":" + rack + ":" + dc + ":" + tokens;
return server + ":" + port + ":" + rack + ":" + dc + ":" + tokens + ":" + redisPort;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static List<DynomiteNodeInfo> parse(String seeds){
node.setRack(itens[2]);
node.setDc(itens[3]);
node.setTokens(itens[4]);
try {
node.setRedisPort(itens[5]);
}catch(Exception e) {
}
result.add(node);
}

Expand Down
Loading

0 comments on commit 8eaa92e

Please sign in to comment.