m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-15 04:44:54 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2020-01-15 04:44:54 +0100
commit0cb7ded87955286f950d2802fc6a0d1c9c26726a (patch)
tree6875ba1b10c804d728925c9cb282b404cd3c20f6
parent710a97612ac050ad79a20f39c5ea9a53eb7263ab (diff)
Add setting contacts in a fetcher flag
-rw-r--r--build.gradle9
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java8
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java11
3 files changed, 20 insertions, 8 deletions
diff --git a/build.gradle b/build.gradle
index c6ebcae..51a49c5 100644
--- a/build.gradle
+++ b/build.gradle
@@ -51,6 +51,14 @@ ext.querySignerHostname = {
}
/*
+Example: -DfallbackContacts=\{\"/uw/violet07\":[192,168,0,11]}
+escape at the beginning and before "
+ */
+ext.fallbackContacts = {
+ return System.getProperty("fallbackContacts") ?: "{\"" + zonePath() + "\":[127,0,0,1]}"
+}
+
+/*
Possible options:
RoundRobinExp
RoundRobinUniform
@@ -138,6 +146,7 @@ task runFetcher(type: JavaExec) {
main = 'pl.edu.mimuw.cloudatlas.fetcher.Fetcher'
args(hostname() , 1099)
systemProperty 'zone_path', zonePath()
+ systemProperty 'fallback_contacts', fallbackContacts()
}
task runInterpreter(type: JavaExec) {
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
index 5f34fe9..f147b2a 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
@@ -133,9 +133,9 @@ public class ClientController {
return "contactsForm";
}
- private Set<ValueContact> parseContactsString(DataStringInput contactsInput) throws Exception {
+ public static Set<ValueContact> parseContactsString(String contactsInput) throws Exception {
Gson gson = new Gson();
- Map<String, ArrayList> contactStrings = gson.fromJson(contactsInput.getString(), Map.class);
+ Map<String, ArrayList> contactStrings = gson.fromJson(contactsInput, Map.class);
Set<ValueContact> contactObjects = new HashSet<ValueContact>();
ArrayList<Double> cAddr;
byte[] inetArray = new byte[4];
@@ -160,7 +160,7 @@ public class ClientController {
Set<ValueContact> contactObjects;
try {
- contactObjects = parseContactsString(contactsObject);
+ contactObjects = parseContactsString(contactsObject.getString());
this.agentApi.setFallbackContacts(contactObjects);
} catch (Exception e) {
success = false;
@@ -263,7 +263,7 @@ public class ClientController {
case "Contact":
DataStringInput contactsString = new DataStringInput();
contactsString.setString(attributeObject.getValueString());
- attributeValue = parseContactsString(contactsString).iterator().next();
+ attributeValue = parseContactsString(contactsString.getString()).iterator().next();
break;
case "List":
List parsedListValue = gson.fromJson(attributeObject.getValueString(), List.class);
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java b/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java
index 12d795a..2b8d033 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java
@@ -7,11 +7,10 @@ import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.io.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
import com.google.gson.Gson;
+import pl.edu.mimuw.cloudatlas.client.ClientController;
import pl.edu.mimuw.cloudatlas.model.*;
public class Fetcher {
@@ -98,13 +97,17 @@ public class Fetcher {
String jsonAttribs;
System.out.println(System.getProperty("user.dir"));
-
+ String fallbackContactsString = System.getProperty("fallback_contacts");
+ System.out.println(fallbackContactsString);
try {
initializeApiStub();
initializePythonProcess();
bufferRead = new BufferedReader( new InputStreamReader(pythonProcess.getInputStream()));
+ Set<String> fallbackContacts = new HashSet<String>();
+ api.setFallbackContacts(ClientController.parseContactsString(fallbackContactsString));
+
while((jsonAttribs = bufferRead.readLine()) != null) {
System.out.println(jsonAttribs);
System.out.flush();