Skip to content

Commit 531dcab

Browse files
authored
Merge pull request #350 from tcellucci/adminResourcesServerPort
add guice binding for adminResourcesServerPort
2 parents 537f9f0 + e12ae29 commit 531dcab

File tree

4 files changed

+236
-210
lines changed

4 files changed

+236
-210
lines changed

karyon2-admin-web/src/main/java/netflix/adminresources/resources/EnvironmentResource.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,35 @@ public class EnvironmentResource {
4040

4141
public static class EnvResponse {
4242
private Map<String, String> env;
43+
4344
public EnvResponse(Map<String, String> env) {
4445
this.env = env;
4546
}
47+
4648
public Map<String, String> getEnv() {
4749
return env;
4850
}
4951
}
5052

5153
@GET
5254
public Response getEnvironmentVars() {
53-
// make a writable copy of the immutable System.getenv() map
54-
Map<String,String> envVarsMap = new HashMap<String,String>(System.getenv());
55-
55+
// make a writable copy of the immutable System.getenv() map
56+
Map<String, String> envVarsMap = new HashMap<String, String>(System.getenv());
57+
5658
// mask the specified properties if they're in the envVarsMap
5759
Set<String> maskedProperties = MaskedResourceHelper.getMaskedPropertiesSet();
58-
Iterator<String> maskedResourcesIter = maskedProperties.iterator();
59-
while (maskedResourcesIter.hasNext()) {
60-
String maskedResource = maskedResourcesIter.next();
61-
if (envVarsMap.containsKey(maskedResource)) {
62-
envVarsMap.put(maskedResource, MaskedResourceHelper.MASKED_PROPERTY_VALUE);
63-
}
60+
Iterator<String> maskedResourcesIter = maskedProperties.iterator();
61+
while (maskedResourcesIter.hasNext()) {
62+
String maskedResource = maskedResourcesIter.next();
63+
if (envVarsMap.containsKey(maskedResource)) {
64+
envVarsMap.put(maskedResource, MaskedResourceHelper.MASKED_PROPERTY_VALUE);
65+
}
6466
}
6567

6668
GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls();
67-
Gson gson = gsonBuilder.create();
69+
Gson gson = gsonBuilder.create();
6870
String envJson = gson.toJson(new EnvResponse(envVarsMap));
69-
71+
7072
return Response.ok(envJson).build();
7173
}
7274
}

karyon2-admin-web/src/main/java/netflix/adminresources/resources/jmx/DynaTreeNode.java

+82-86
Original file line numberDiff line numberDiff line change
@@ -8,97 +8,93 @@
88
import java.util.TreeMap;
99

1010
/**
11-
* Represents a single node in a tree and simplifies adding children and serializing the final
12-
* tree into JSON.
11+
* Represents a single node in a tree and simplifies adding children and
12+
* serializing the final tree into JSON.
13+
*
1314
* @author elandau
1415
*/
1516
public class DynaTreeNode {
16-
private String title;
17-
private String key;
18-
private String mode;
19-
private Map<String, DynaTreeNode> children;
20-
private boolean noLink = true;
21-
22-
public DynaTreeNode() {
23-
24-
}
25-
26-
public DynaTreeNode setTitle(String title) {
27-
this.title = title;
28-
return this;
29-
}
30-
31-
public String getTitle() {
32-
return this.title;
33-
}
34-
35-
public DynaTreeNode setNoLink(boolean noLink) {
36-
this.noLink = noLink;
37-
return this;
38-
}
39-
40-
public boolean getNoLink() {
41-
return this.noLink;
42-
}
43-
44-
public DynaTreeNode setKey(String key) {
45-
this.key = key;
46-
return this;
47-
}
48-
49-
public String getKey() {
50-
return this.key;
51-
}
52-
53-
public DynaTreeNode setMode(String mode) {
54-
this.mode = mode;
55-
return this;
56-
}
57-
58-
public String getMode() {
59-
return this.mode;
60-
}
61-
62-
public Map<String, DynaTreeNode> getChildren() {
63-
if (children == null) {
64-
children = new TreeMap<String, DynaTreeNode>();
65-
}
66-
return children;
67-
}
68-
69-
public DynaTreeNode getChild(String title) {
70-
return getChildren().get(title);
71-
}
72-
73-
public void putChild(DynaTreeNode child) {
74-
getChildren().put(child.title, child);
75-
}
76-
77-
@SuppressWarnings("unchecked")
17+
private String title;
18+
private String key;
19+
private String mode;
20+
private Map<String, DynaTreeNode> children;
21+
private boolean noLink = true;
22+
23+
public DynaTreeNode() {
24+
25+
}
26+
27+
public DynaTreeNode setTitle(String title) {
28+
this.title = title;
29+
return this;
30+
}
31+
32+
public String getTitle() {
33+
return this.title;
34+
}
35+
36+
public DynaTreeNode setNoLink(boolean noLink) {
37+
this.noLink = noLink;
38+
return this;
39+
}
40+
41+
public boolean getNoLink() {
42+
return this.noLink;
43+
}
44+
45+
public DynaTreeNode setKey(String key) {
46+
this.key = key;
47+
return this;
48+
}
49+
50+
public String getKey() {
51+
return this.key;
52+
}
53+
54+
public DynaTreeNode setMode(String mode) {
55+
this.mode = mode;
56+
return this;
57+
}
58+
59+
public String getMode() {
60+
return this.mode;
61+
}
62+
63+
public Map<String, DynaTreeNode> getChildren() {
64+
if (children == null) {
65+
children = new TreeMap<String, DynaTreeNode>();
66+
}
67+
return children;
68+
}
69+
70+
public DynaTreeNode getChild(String title) {
71+
return getChildren().get(title);
72+
}
73+
74+
public void putChild(DynaTreeNode child) {
75+
getChildren().put(child.title, child);
76+
}
77+
78+
@SuppressWarnings("unchecked")
7879
public JSONObject toJSONObject() throws JSONException {
79-
return new JSONObject()
80-
.put("title", title)
81-
.put("key", key)
82-
.put("noLink", noLink)
83-
.put("mode", mode)
84-
.put("expand", true)
85-
.put("children", getChildrenJSONArray());
86-
}
87-
88-
@SuppressWarnings("unchecked")
80+
return new JSONObject().put("title", title).put("key", key).put("noLink", noLink).put("mode", mode)
81+
.put("expand", true).put("children", getChildrenJSONArray());
82+
}
83+
84+
@SuppressWarnings("unchecked")
8985
public JSONArray getChildrenJSONArray() {
90-
JSONArray ar = null;
91-
if (children != null) {
92-
ar = new JSONArray();
93-
for (DynaTreeNode a : children.values()) {
94-
try {
95-
ar.put(a.toJSONObject());
86+
JSONArray ar = null;
87+
if (children != null) {
88+
ar = new JSONArray();
89+
for (DynaTreeNode a : children.values()) {
90+
try {
91+
ar.put(a.toJSONObject());
9692
} catch (JSONException e) {
97-
// TODO Auto-generated catch block
98-
e.printStackTrace();
93+
// TODO Auto-generated catch block
94+
e.printStackTrace();
9995
}
100-
}
101-
}
102-
return ar;
103-
}
96+
}
97+
}
98+
return ar;
99+
}
104100
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
package netflix.adminresources;
22

3+
import javax.inject.Named;
4+
35
import com.google.inject.AbstractModule;
6+
import com.google.inject.Provides;
47

58
public class KaryonAdminModule extends AbstractModule {
69

10+
public static final String ADMIN_RESOURCES_SERVER_PORT = "adminResourcesServerPort";
11+
712
@Override
813
protected void configure() {
914
bind(AdminResourcesContainer.class).asEagerSingleton();
1015
}
16+
17+
@Provides
18+
@Named(ADMIN_RESOURCES_SERVER_PORT)
19+
public int adminListenPort(AdminResourcesContainer adminResourcesContainer) {
20+
return adminResourcesContainer.getServerPort();
21+
}
1122
}

0 commit comments

Comments
 (0)