GOSSIP-34 remove json that makes ASF sad

This commit is contained in:
Edward Capriolo
2017-01-03 14:12:21 -05:00
parent f1935beb6a
commit 0bdf2f6920
9 changed files with 45 additions and 38 deletions

View File

@ -22,7 +22,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URISyntaxException;
import org.json.JSONException;
public class GossipRunner {
@ -46,8 +46,6 @@ public class GossipRunner {
gossipService.start();
} catch (FileNotFoundException e) {
System.err.println("The given file is not found!");
} catch (JSONException e) {
System.err.println("The given file is not in the correct JSON format!");
} catch (IOException e) {
System.err.println("Could not read the configuration file: " + e.getMessage());
} catch (InterruptedException e) {

View File

@ -25,17 +25,18 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* This object represents the settings used when starting the gossip service.
*
* @author harmenw
*/
public class StartupSettings {
private static final Logger log = Logger.getLogger(StartupSettings.class);
@ -160,7 +161,7 @@ public class StartupSettings {
* Thrown when reading the file gives problems.
* @throws URISyntaxException
*/
public static StartupSettings fromJSONFile(File jsonFile) throws JSONException,
public static StartupSettings fromJSONFile(File jsonFile) throws
FileNotFoundException, IOException, URISyntaxException {
// Read the file to a String.
StringBuffer buffer = new StringBuffer();
@ -170,32 +171,31 @@ public class StartupSettings {
buffer.append(line.trim());
}
}
JSONObject jsonObject = new JSONArray(buffer.toString()).getJSONObject(0);
String uri = jsonObject.getString("uri");
String id = jsonObject.getString("id");
int gossipInterval = jsonObject.getInt("gossip_interval");
int cleanupInterval = jsonObject.getInt("cleanup_interval");
String cluster = jsonObject.getString("cluster");
ObjectMapper om = new ObjectMapper();
JsonNode root = om.readTree(jsonFile);
JsonNode jsonObject = root.get(0);
String uri = jsonObject.get("uri").textValue();
String id = jsonObject.get("id").textValue();
int gossipInterval = jsonObject.get("gossip_interval").intValue();
int cleanupInterval = jsonObject.get("cleanup_interval").intValue();
String cluster = jsonObject.get("cluster").textValue();
if (cluster == null){
throw new IllegalArgumentException("cluster was null. It is required");
}
URI uri2 = new URI(uri);
StartupSettings settings = new StartupSettings(id, uri2, new GossipSettings(gossipInterval,
cleanupInterval), cluster);
// Now iterate over the members from the config file and add them to the settings.
String configMembersDetails = "Config-members [";
JSONArray membersJSON = jsonObject.getJSONArray("members");
for (int i = 0; i < membersJSON.length(); i++) {
JSONObject memberJSON = membersJSON.getJSONObject(i);
URI uri3 = new URI(memberJSON.getString("uri"));
RemoteGossipMember member = new RemoteGossipMember(memberJSON.getString("cluster"),
JsonNode membersJSON = jsonObject.get("members");
Iterator<JsonNode> it = membersJSON.iterator();
while (it.hasNext()){
JsonNode child = it.next();
URI uri3 = new URI(child.get("uri").textValue());
RemoteGossipMember member = new RemoteGossipMember(child.get("cluster").asText(),
uri3, "", 0);
settings.addGossipMember(member);
configMembersDetails += member.getAddress();
if (i < (membersJSON.length() - 1))
configMembersDetails += ", ";
configMembersDetails += ", ";
}
log.info(configMembersDetails + "]");

View File

@ -39,7 +39,9 @@ import org.apache.gossip.udp.UdpActiveGossipMessage;
import org.apache.gossip.udp.UdpGossipDataMessage;
import org.apache.gossip.udp.UdpSharedGossipDataMessage;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* [The active thread: periodically send gossip request.] The class handles gossiping the membership

View File

@ -31,7 +31,6 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy;
@ -52,7 +51,9 @@ import org.apache.gossip.udp.UdpGossipDataMessage;
import org.apache.gossip.udp.UdpNotAMemberFault;
import org.apache.gossip.udp.UdpSharedGossipDataMessage;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
public class GossipCore {

View File

@ -27,7 +27,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.gossip.model.Base;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* [The passive thread: reply to incoming gossip request.] This class handles the passive cycle,

View File

@ -21,7 +21,6 @@ import org.apache.gossip.GossipMember;
import org.apache.gossip.GossipSettings;
import org.apache.gossip.event.GossipListener;
import org.apache.gossip.manager.GossipManager;
import org.apache.gossip.manager.impl.OnlyProcessReceivedPassiveGossipThread;
import java.net.URI;
import java.util.List;

View File

@ -22,9 +22,11 @@ import org.apache.gossip.udp.UdpActiveGossipOk;
import org.apache.gossip.udp.UdpGossipDataMessage;
import org.apache.gossip.udp.UdpNotAMemberFault;
import org.apache.gossip.udp.UdpSharedGossipDataMessage;
import org.codehaus.jackson.annotate.JsonSubTypes;
import org.codehaus.jackson.annotate.JsonSubTypes.Type;
import org.codehaus.jackson.annotate.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
@JsonTypeInfo(
use = JsonTypeInfo.Id.CLASS,