Reviewers: [email protected]

Description:
Currently JsonContainerConfig adds SERVER_HOST and SERVER_PORT
environment variables only to default container.
This change makes it add these variables to all containers configs.

Please review this at http://codereview.appspot.com/2000043/

Affected files:
 JsonContainerConfig.java


Index: JsonContainerConfig.java
===================================================================
--- JsonContainerConfig.java    (revision 987690)
+++ JsonContainerConfig.java    (working copy)
@@ -72,6 +72,8 @@
  public static final String PARENT_KEY = "parent";
  // TODO: Rename this to simply "container", gadgets.container is
unnecessary.
  public static final String CONTAINER_KEY = "gadgets.container";
+  public static final String SERVER_PORT = "SERVER_PORT";
+  public static final String SERVER_HOST = "SERVER_HOST";

  private final Map<String, Map<String, Object>> config;
  private final Expressions expressions;
@@ -95,8 +97,7 @@
    this.expressions = expressions;
    JSONObject configJson = loadContainers(containers);
    try {
-
 configJson.getJSONObject(ContainerConfig.DEFAULT_CONTAINER).put("SERVER_PORT",
port);
-
 configJson.getJSONObject(ContainerConfig.DEFAULT_CONTAINER).put("SERVER_HOST",
host);
+      addServerHosePortToAllContainers(configJson, host, port);
    } catch (JSONException e) {
      // ignore
    }
@@ -105,6 +106,22 @@
  }

  /**
+   * Adds SERVER_HOST and SERVER_PORT context variables to all containers
in
+   * the json config.
+   * @param configJson The json config object.
+   * @param host The value to set for {...@code SERVER_HOST} variable.
+   * @param port The value to set for {...@code SERVER_PORT} variable.
+   * @throws JSONException In case of errors.
+   */
+  private void addServerHosePortToAllContainers(JSONObject configJson,
String host, String port)
+      throws JSONException {
+    for (String container : JSONObject.getNames(configJson)) {
+      configJson.getJSONObject(container).put(SERVER_PORT, port);
+      configJson.getJSONObject(container).put(SERVER_HOST, host);
+    }
+  }
+
+  /**
   * Creates a new configuration from a JSON Object, for use in testing.
   */
  public JsonContainerConfig(JSONObject json, Expressions expressions) {


Thanks
Gagan

Reply via email to