jsoninfo: add cli arguments to the config object
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 2 Jan 2017 15:37:31 +0000 (16:37 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 4 Jan 2017 08:47:11 +0000 (09:47 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/info.java/org.olsr.v1.info.api/doc/examples/all.json
lib/info.java/org.olsr.v1.info.api/doc/examples/config.json
lib/info.java/org.olsr.v1.info.api/doc/examples/startup.json
lib/info.java/org.olsr.v1.info.api/src/org/olsr/v1/info/api/dto/JsonInfoConfigEntry.java
lib/info.java/org.olsr.v1.info.api/test/org/olsr/v1/info/api/dto/TestJsonInfoAll.java
lib/info.java/org.olsr.v1.info.api/test/org/olsr/v1/info/api/dto/TestJsonInfoConfig.java
lib/info.java/org.olsr.v1.info.api/test/org/olsr/v1/info/api/dto/TestJsonInfoConfigEntry.java
lib/info.java/org.olsr.v1.info.api/test/org/olsr/v1/info/api/dto/TestJsonInfoStartup.java
lib/jsoninfo/src/olsrd_jsoninfo.c

index dee90ec..b83cbe5 100644 (file)
   ],
   "config": {
     "configurationChecksum": "2e2c14b6e3562ddfd73111847d7a9d8277993ff7",
+    "cli": [
+      "/usr/bin/olsrd",
+      "-f",
+      "/etc/olsrd/olsrd.conf"
+    ],
     "configurationFile": "/etc/olsrd/olsrd.conf",
     "olsrPort": 698,
     "debugLevel": 0,
index e3c469b..d13042d 100644 (file)
@@ -6,6 +6,11 @@
   "uuid": "d13d7ee3-fcca-4f81-9bf5-bb5848b5d96d",
   "config": {
     "configurationChecksum": "2e2c14b6e3562ddfd73111847d7a9d8277993ff7",
+    "cli": [
+      "/usr/bin/olsrd",
+      "-f",
+      "/etc/olsrd/olsrd.conf"
+    ],
     "configurationFile": "/etc/olsrd/olsrd.conf",
     "olsrPort": 698,
     "debugLevel": 0,
index ffaff8a..560dc5b 100644 (file)
   ],
   "config": {
     "configurationChecksum": "2e2c14b6e3562ddfd73111847d7a9d8277993ff7",
+    "cli": [
+      "/usr/bin/olsrd",
+      "-f",
+      "/etc/olsrd/olsrd.conf"
+    ],
     "configurationFile": "/etc/olsrd/olsrd.conf",
     "olsrPort": 698,
     "debugLevel": 0,
index 8209c5c..36eda35 100644 (file)
@@ -1,6 +1,8 @@
 package org.olsr.v1.info.api.dto;
 
 import java.net.InetAddress;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -15,6 +17,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 @ProviderType
 public class JsonInfoConfigEntry {
   private String                          configurationChecksum    = "";
+  private final List<String>              cli                      = new LinkedList<>();
   private String                          configurationFile        = "";
   private int                             olsrPort                 = 0;
   private int                             debugLevel               = 0;
@@ -86,6 +89,24 @@ public class JsonInfoConfigEntry {
     }
   }
 
+  /**
+   * @return the CLI
+   */
+  public List<String> getCli() {
+    return this.cli;
+  }
+
+  /**
+   * @param cli the CLI to set
+   */
+  @JsonProperty("cli")
+  public void setCli(final List<String> cli) {
+    this.cli.clear();
+    if (cli != null) {
+      this.cli.addAll(cli);
+    }
+  }
+
   /**
    * @return the configuration file
    */
@@ -914,6 +935,7 @@ public class JsonInfoConfigEntry {
     final int prime = 31;
     int result = 1;
     result = (prime * result) + this.configurationChecksum.hashCode();
+    result = (prime * result) + this.cli.hashCode();
     result = (prime * result) + this.configurationFile.hashCode();
     result = (prime * result) + this.olsrPort;
     result = (prime * result) + this.debugLevel;
@@ -991,6 +1013,9 @@ public class JsonInfoConfigEntry {
     if (!this.configurationChecksum.equals(other.configurationChecksum)) {
       return false;
     }
+    if (!this.cli.equals(other.cli)) {
+      return false;
+    }
     if (!this.configurationFile.equals(other.configurationFile)) {
       return false;
     }
@@ -1152,6 +1177,8 @@ public class JsonInfoConfigEntry {
     final StringBuilder builder = new StringBuilder();
     builder.append("JsonInfoConfigEntry [configurationChecksum=");
     builder.append(this.configurationChecksum);
+    builder.append(", cli=");
+    builder.append(this.cli);
     builder.append(", configurationFile=");
     builder.append(this.configurationFile);
     builder.append(", olsrPort=");
index 7877cb3..893f19a 100644 (file)
@@ -455,7 +455,7 @@ public class TestJsonInfoAll {
   public void testHashCode() {
     this.impl.setNeighbors(null);
     int r = this.impl.hashCode();
-    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(604725356)));
+    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-557529111)));
 
     /* set */
     final Set<JsonInfoNeighborsEntry> neighbors = new TreeSet<>();
@@ -527,7 +527,7 @@ public class TestJsonInfoAll {
     this.impl.setConfig(config);
 
     r = this.impl.hashCode();
-    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(901705550)));
+    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-260548917)));
   }
 
   @Test(timeout = 8000)
index f9382f1..978794a 100644 (file)
@@ -80,7 +80,7 @@ public class TestJsonInfoConfig {
   @Test(timeout = 8000)
   public void testHashCode() {
     int r = this.impl.hashCode();
-    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1204371979)));
+    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1928340850)));
 
     /* set */
     final JsonInfoConfigEntry config = new JsonInfoConfigEntry();
@@ -88,7 +88,7 @@ public class TestJsonInfoConfig {
     this.impl.setConfig(config);
 
     r = this.impl.hashCode();
-    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-491755257)));
+    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1654009724)));
   }
 
   @Test(timeout = 8000)
index 806e36d..18fc9d0 100644 (file)
@@ -6,6 +6,8 @@ import static org.junit.Assert.assertThat;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -30,6 +32,8 @@ public class TestJsonInfoConfigEntry {
   public void testGettersAndSetters() throws UnknownHostException {
     /* initial */
     assertThat(this.impl.getConfigurationChecksum(), equalTo(""));
+    assertThat(this.impl.getCli(), notNullValue());
+    assertThat(Integer.valueOf(this.impl.getCli().size()), equalTo(Integer.valueOf(0)));
     assertThat(this.impl.getConfigurationFile(), equalTo(""));
     assertThat(Integer.valueOf(this.impl.getOlsrPort()), equalTo(Integer.valueOf(0)));
     assertThat(Integer.valueOf(this.impl.getDebugLevel()), equalTo(Integer.valueOf(0)));
@@ -85,6 +89,10 @@ public class TestJsonInfoConfigEntry {
     assertThat(Long.valueOf(this.impl.getStartTime()), equalTo(Long.valueOf(0)));
 
     /* set */
+    final List<String> cli = new LinkedList<>();
+    cli.add("-f");
+    cli.add("/etc/olsrd/olsrd.conf");
+
     final JsonInfoConfigRtTable rtTable = new JsonInfoConfigRtTable();
     rtTable.setDefault(11);
 
@@ -119,6 +127,7 @@ public class TestJsonInfoConfigEntry {
     interfaceDefaults.setMode("mode");
 
     this.impl.setConfigurationChecksum("configurationChecksum");
+    this.impl.setCli(cli);
     this.impl.setConfigurationFile("configurationFile");
     this.impl.setOlsrPort(1);
     this.impl.setDebugLevel(2);
@@ -173,6 +182,8 @@ public class TestJsonInfoConfigEntry {
 
     /* get */
     assertThat(this.impl.getConfigurationChecksum(), equalTo("configurationChecksum"));
+    assertThat(this.impl.getCli(), equalTo(cli));
+    assertThat(Integer.valueOf(this.impl.getCli().size()), equalTo(Integer.valueOf(2)));
     assertThat(this.impl.getConfigurationFile(), equalTo("configurationFile"));
     assertThat(Integer.valueOf(this.impl.getOlsrPort()), equalTo(Integer.valueOf(1)));
     assertThat(Integer.valueOf(this.impl.getDebugLevel()), equalTo(Integer.valueOf(2)));
@@ -227,9 +238,12 @@ public class TestJsonInfoConfigEntry {
     assertThat(this.impl.getOs(), equalTo("Linux"));
     assertThat(Long.valueOf(this.impl.getStartTime()), equalTo(Long.valueOf(21)));
 
+    this.impl.setCli(null);
     this.impl.setHna(null);
     this.impl.setIpcConnectAllowed(null);
 
+    assertThat(this.impl.getCli(), notNullValue());
+    assertThat(Integer.valueOf(this.impl.getCli().size()), equalTo(Integer.valueOf(0)));
     assertThat(this.impl.getHna(), notNullValue());
     assertThat(Integer.valueOf(this.impl.getHna().size()), equalTo(Integer.valueOf(0)));
     assertThat(this.impl.getIpcConnectAllowed(), notNullValue());
@@ -283,6 +297,37 @@ public class TestJsonInfoConfigEntry {
     this.impl.setConfigurationChecksum(stringOrg);
     other.setConfigurationChecksum(stringOrg);
 
+    /* cli */
+
+    final List<String> cli = new LinkedList<>();
+    cli.add("-f");
+    cli.add("/etc/olsrd/olsrd.conf");
+
+    final List<String> cliOrg = this.impl.getCli();
+
+    this.impl.setCli(null);
+    other.setCli(null);
+    r = this.impl.equals(other);
+    assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
+
+    this.impl.setCli(null);
+    other.setCli(cli);
+    r = this.impl.equals(other);
+    assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
+
+    this.impl.setCli(cli);
+    other.setCli(null);
+    r = this.impl.equals(other);
+    assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
+
+    this.impl.setCli(cli);
+    other.setCli(cli);
+    r = this.impl.equals(other);
+    assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
+
+    this.impl.setCli(cliOrg);
+    other.setCli(cliOrg);
+
     /* configurationFile */
 
     stringOrg = this.impl.getConfigurationFile();
@@ -1566,9 +1611,13 @@ public class TestJsonInfoConfigEntry {
   @Test(timeout = 8000)
   public void testHashCode() throws UnknownHostException {
     int r = this.impl.hashCode();
-    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1347784982)));
+    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(185530515)));
 
     /* set */
+    final List<String> cli = new LinkedList<>();
+    cli.add("-f");
+    cli.add("/etc/olsrd/olsrd.conf");
+
     final JsonInfoConfigRtTable rtTable = new JsonInfoConfigRtTable();
     rtTable.setDefault(11);
 
@@ -1603,6 +1652,7 @@ public class TestJsonInfoConfigEntry {
     interfaceDefaults.setMode("mode");
 
     this.impl.setConfigurationChecksum("configurationChecksum");
+    this.impl.setCli(cli);
     this.impl.setConfigurationFile("configurationFile");
     this.impl.setOlsrPort(1);
     this.impl.setDebugLevel(2);
@@ -1656,7 +1706,7 @@ public class TestJsonInfoConfigEntry {
     this.impl.setStartTime(21);
 
     r = this.impl.hashCode();
-    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1049017438)));
+    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1824937455)));
   }
 
   @Test(timeout = 8000)
index 0f35caf..bc0cb22 100644 (file)
@@ -156,7 +156,7 @@ public class TestJsonInfoStartup {
   @Test(timeout = 8000)
   public void testHashCode() {
     int r = this.impl.hashCode();
-    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(954758003)));
+    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-207496464)));
 
     /* set */
     final JsonInfoVersionEntry version = new JsonInfoVersionEntry();
@@ -174,14 +174,14 @@ public class TestJsonInfoStartup {
     this.impl.setConfig(config);
 
     r = this.impl.hashCode();
-    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(907295539)));
+    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-254958928)));
 
     /* set */
     this.impl.setVersion(null);
     this.impl.setPlugins(null);
     this.impl.setConfig(null);
 
-    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(907295539)));
+    assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-254958928)));
   }
 
   @Test(timeout = 8000)
index bccde62..acc7293 100644 (file)
@@ -1133,6 +1133,19 @@ void ipc_print_config(struct autobuf *abuf) {
   (void) olsrd_config_checksum_get(NULL, &str);
   abuf_json_string(&json_session, abuf, "configurationChecksum", str);
 
+  {
+    size_t i = 0;
+    int argc = 0;
+    char **argv = NULL;
+    get_argc_argv(&argc, &argv);
+
+    abuf_json_mark_object(&json_session, true, true, abuf, "cli");
+    for (i = 0; i < (size_t) argc; i++) {
+      abuf_json_string(&json_session, abuf, NULL, argv[i]);
+    }
+    abuf_json_mark_object(&json_session, false, true, abuf, NULL);
+  }
+
   abuf_json_string(&json_session, abuf, "configurationFile", olsr_cnf->configuration_file);
   abuf_json_int(&json_session, abuf, "olsrPort", olsr_cnf->olsrport);
   abuf_json_int(&json_session, abuf, "debugLevel", olsr_cnf->debug_level);