Skip to content

Commit

Permalink
Merge pull request #350 from tcellucci/adminResourcesServerPort
Browse files Browse the repository at this point in the history
add guice binding for adminResourcesServerPort
  • Loading branch information
tcellucci authored Nov 22, 2016
2 parents 537f9f0 + e12ae29 commit 531dcab
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,35 @@ public class EnvironmentResource {

public static class EnvResponse {
private Map<String, String> env;

public EnvResponse(Map<String, String> env) {
this.env = env;
}

public Map<String, String> getEnv() {
return env;
}
}

@GET
public Response getEnvironmentVars() {
// make a writable copy of the immutable System.getenv() map
Map<String,String> envVarsMap = new HashMap<String,String>(System.getenv());
// make a writable copy of the immutable System.getenv() map
Map<String, String> envVarsMap = new HashMap<String, String>(System.getenv());

// mask the specified properties if they're in the envVarsMap
Set<String> maskedProperties = MaskedResourceHelper.getMaskedPropertiesSet();
Iterator<String> maskedResourcesIter = maskedProperties.iterator();
while (maskedResourcesIter.hasNext()) {
String maskedResource = maskedResourcesIter.next();
if (envVarsMap.containsKey(maskedResource)) {
envVarsMap.put(maskedResource, MaskedResourceHelper.MASKED_PROPERTY_VALUE);
}
Iterator<String> maskedResourcesIter = maskedProperties.iterator();
while (maskedResourcesIter.hasNext()) {
String maskedResource = maskedResourcesIter.next();
if (envVarsMap.containsKey(maskedResource)) {
envVarsMap.put(maskedResource, MaskedResourceHelper.MASKED_PROPERTY_VALUE);
}
}

GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
Gson gson = gsonBuilder.create();
Gson gson = gsonBuilder.create();
String envJson = gson.toJson(new EnvResponse(envVarsMap));

return Response.ok(envJson).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,97 +8,93 @@
import java.util.TreeMap;

/**
* Represents a single node in a tree and simplifies adding children and serializing the final
* tree into JSON.
* Represents a single node in a tree and simplifies adding children and
* serializing the final tree into JSON.
*
* @author elandau
*/
public class DynaTreeNode {
private String title;
private String key;
private String mode;
private Map<String, DynaTreeNode> children;
private boolean noLink = true;
public DynaTreeNode() {
}
public DynaTreeNode setTitle(String title) {
this.title = title;
return this;
}
public String getTitle() {
return this.title;
}
public DynaTreeNode setNoLink(boolean noLink) {
this.noLink = noLink;
return this;
}
public boolean getNoLink() {
return this.noLink;
}
public DynaTreeNode setKey(String key) {
this.key = key;
return this;
}
public String getKey() {
return this.key;
}
public DynaTreeNode setMode(String mode) {
this.mode = mode;
return this;
}

public String getMode() {
return this.mode;
}
public Map<String, DynaTreeNode> getChildren() {
if (children == null) {
children = new TreeMap<String, DynaTreeNode>();
}
return children;
}
public DynaTreeNode getChild(String title) {
return getChildren().get(title);
}
public void putChild(DynaTreeNode child) {
getChildren().put(child.title, child);
}
@SuppressWarnings("unchecked")
private String title;
private String key;
private String mode;
private Map<String, DynaTreeNode> children;
private boolean noLink = true;

public DynaTreeNode() {

}

public DynaTreeNode setTitle(String title) {
this.title = title;
return this;
}

public String getTitle() {
return this.title;
}

public DynaTreeNode setNoLink(boolean noLink) {
this.noLink = noLink;
return this;
}

public boolean getNoLink() {
return this.noLink;
}

public DynaTreeNode setKey(String key) {
this.key = key;
return this;
}

public String getKey() {
return this.key;
}

public DynaTreeNode setMode(String mode) {
this.mode = mode;
return this;
}

public String getMode() {
return this.mode;
}

public Map<String, DynaTreeNode> getChildren() {
if (children == null) {
children = new TreeMap<String, DynaTreeNode>();
}
return children;
}

public DynaTreeNode getChild(String title) {
return getChildren().get(title);
}

public void putChild(DynaTreeNode child) {
getChildren().put(child.title, child);
}

@SuppressWarnings("unchecked")
public JSONObject toJSONObject() throws JSONException {
return new JSONObject()
.put("title", title)
.put("key", key)
.put("noLink", noLink)
.put("mode", mode)
.put("expand", true)
.put("children", getChildrenJSONArray());
}

@SuppressWarnings("unchecked")
return new JSONObject().put("title", title).put("key", key).put("noLink", noLink).put("mode", mode)
.put("expand", true).put("children", getChildrenJSONArray());
}

@SuppressWarnings("unchecked")
public JSONArray getChildrenJSONArray() {
JSONArray ar = null;
if (children != null) {
ar = new JSONArray();
for (DynaTreeNode a : children.values()) {
try {
ar.put(a.toJSONObject());
JSONArray ar = null;
if (children != null) {
ar = new JSONArray();
for (DynaTreeNode a : children.values()) {
try {
ar.put(a.toJSONObject());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return ar;
}
}
}
return ar;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package netflix.adminresources;

import javax.inject.Named;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;

public class KaryonAdminModule extends AbstractModule {

public static final String ADMIN_RESOURCES_SERVER_PORT = "adminResourcesServerPort";

@Override
protected void configure() {
bind(AdminResourcesContainer.class).asEagerSingleton();
}

@Provides
@Named(ADMIN_RESOURCES_SERVER_PORT)
public int adminListenPort(AdminResourcesContainer adminResourcesContainer) {
return adminResourcesContainer.getServerPort();
}
}
Loading

0 comments on commit 531dcab

Please sign in to comment.