Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 4fe7718

Browse files
committed
WHIRR-722: Improve user and system level logging capability
1 parent 4c45b6f commit 4fe7718

File tree

6 files changed

+90
-22
lines changed

6 files changed

+90
-22
lines changed

CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Release 0.9.0 (Unreleased Changes)
66

77
IMPROVEMENTS
88

9+
WHIRR-722. Improve user and system level logging capability. (graham)
10+
911
WHIRR-721. Improve robustness of volume device detection. (graham)
1012

1113
BUG FIXES

conf/log4j-cli.xml

+2-12
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
-->
2424
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
2525
debug="false">
26-
27-
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
28-
<param name="Threshold" value="INFO" />
29-
<layout class="org.apache.log4j.PatternLayout">
30-
<param name="ConversionPattern" value="%m%n"/>
31-
</layout>
32-
</appender>
3326

3427
<appender name="ROLLINGFILE" class="org.apache.log4j.DailyRollingFileAppender">
3528
<param name="File" value="whirr.log" />
@@ -41,10 +34,8 @@
4134
</layout>
4235
</appender>
4336

44-
<logger name="org.apache.whirr" additivity="false">
45-
<level value="DEBUG" />
46-
<appender-ref ref="CONSOLE" />
47-
<appender-ref ref="ROLLINGFILE" />
37+
<logger name="org.apache.whirr">
38+
<level value="INFO" />
4839
</logger>
4940

5041
<logger name="jclouds.compute">
@@ -60,7 +51,6 @@
6051
</logger>
6152

6253
<root>
63-
<priority value="INFO" />
6454
<appender-ref ref="ROLLINGFILE" />
6555
</root>
6656

core/src/main/java/org/apache/whirr/ClusterSpec.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ public enum Property {
196196

197197
KERBEROS_REALM(String.class, false, "Kerberos realm to use in security configuration"),
198198

199-
AWS_EC2_PLACEMENT_GROUP(String.class, false, "If given, use this existing EC2 placement group. (aws-ec2 specific option)");
199+
AWS_EC2_PLACEMENT_GROUP(String.class, false, "If given, use this existing EC2 placement group. (aws-ec2 specific option)"),
200+
201+
QUIET(Boolean.class, false, "Adjust user level, console logging verbosity.");
200202

201203
private Class<?> type;
202204
private boolean multipleArguments;
@@ -329,6 +331,8 @@ public static ClusterSpec withNoDefaults(Configuration conf)
329331

330332
private Map<String,Node> byonNodes;
331333

334+
private boolean isQuiet;
335+
332336
public ClusterSpec() throws ConfigurationException {
333337
this(new PropertiesConfiguration());
334338
}
@@ -404,6 +408,8 @@ public ClusterSpec(Configuration userConfig, boolean loadDefaults, Map<String,No
404408

405409
setByonNodes(byonNodes);
406410

411+
setQuiet(config.getBoolean(Property.QUIET.getConfigName(), Boolean.FALSE));
412+
407413
Map<String, List<String>> fr = new HashMap<String, List<String>>();
408414
String firewallPrefix = Property.FIREWALL_RULES.getConfigName();
409415
Pattern firewallRuleKeyPattern = Pattern.compile("^".concat(Pattern.quote(firewallPrefix).concat("(?:\\.(.+))?$")));
@@ -609,6 +615,10 @@ public String getBlobStoreProvider() {
609615
}
610616
return blobStoreProvider;
611617
}
618+
619+
public boolean isQuiet() {
620+
return isQuiet;
621+
}
612622

613623
/**
614624
* Probably jclouds should provide a similar mechanism
@@ -981,6 +991,10 @@ public void setByonNodes(Map<String,Node> byonNodes) {
981991
this.byonNodes = byonNodes;
982992
}
983993

994+
public void setQuiet(boolean isQuiet) {
995+
this.isQuiet = isQuiet;
996+
}
997+
984998
public void setVersion(String version) {
985999
this.version = version;
9861000
}
@@ -1106,7 +1120,7 @@ public int hashCode() {
11061120
getByonNodes()
11071121
);
11081122
}
1109-
1123+
11101124
public String toString() {
11111125
return Objects.toStringHelper(this).omitNullValues()
11121126
.add("instanceTemplates", getInstanceTemplates())

core/src/main/java/org/apache/whirr/command/AbstractClusterCommand.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,19 @@ public AbstractClusterCommand(String name, String description, ClusterController
8080
.describedAs("config.properties")
8181
.ofType(String.class);
8282

83-
parser.accepts("quiet", "Be less verbose");
84-
8583
this.factory = factory;
8684
this.stateStoreFactory = stateStoreFactory;
8785

8886
optionSpecs = Maps.newHashMap();
8987
for (Property property : EnumSet.allOf(Property.class)) {
90-
ArgumentAcceptingOptionSpec<?> spec = parser
91-
.accepts(property.getSimpleName(), property.getDescription())
92-
.withRequiredArg()
93-
.ofType(property.getType());
88+
ArgumentAcceptingOptionSpec<?> spec = null;
89+
if (property.getType().equals(Boolean.class)) {
90+
spec = parser.accepts(property.getSimpleName(), property.getDescription()).withOptionalArg()
91+
.ofType(property.getType());
92+
} else {
93+
spec = parser.accepts(property.getSimpleName(), property.getDescription()).withRequiredArg()
94+
.ofType(property.getType());
95+
}
9496
if (property.hasMultipleArguments()) {
9597
spec.withValuesSeparatedBy(',');
9698
}
@@ -112,6 +114,9 @@ protected ClusterSpec getClusterSpec(OptionSet optionSet) throws ConfigurationEx
112114
} else {
113115
value = optionSet.valueOf(option);
114116
}
117+
if (value == null && property.getType().equals(Boolean.class) && optionSet.has(property.getSimpleName())) {
118+
value = Boolean.TRUE.toString();
119+
}
115120
if (value != null) {
116121
optionsConfig.setProperty(property.getConfigName(), value);
117122
}
@@ -165,7 +170,7 @@ protected ClusterStateStore createClusterStateStore(ClusterSpec spec) {
165170

166171
protected void printProviderInfo(PrintStream out, PrintStream err,
167172
ClusterSpec clusterSpec, OptionSet optionSet) {
168-
if (!optionSet.has("quiet")) {
173+
if (!clusterSpec.isQuiet()) {
169174
out.println(String.format("Running on provider %s using identity %s", clusterSpec.getProvider(), clusterSpec.getIdentity()));
170175
}
171176
}

core/src/test/java/org/apache/whirr/command/AbstractClusterCommandTest.java

+48-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,61 @@ public int run(InputStream in, PrintStream out, PrintStream err,
4848
};
4949

5050
Map<String, File> keys = KeyPair.generateTemporaryFiles();
51-
OptionSet optionSet = clusterCommand.parser.parse(
51+
OptionSet optionSet = clusterCommand.parser.parse("--quiet",
5252
"--service-name", "overridden-test-service",
5353
"--config", "whirr-override-test.properties",
5454
"--private-key-file", keys.get("private").getAbsolutePath()
5555
);
5656
ClusterSpec clusterSpec = clusterCommand.getClusterSpec(optionSet);
57+
assertThat(optionSet.has("quiet"), is(true));
58+
assertThat(clusterSpec.isQuiet(), is(true));
5759
assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
5860
assertThat(clusterSpec.getClusterName(), is("test-cluster"));
61+
62+
optionSet = clusterCommand.parser.parse("--quiet", "true",
63+
"--service-name", "overridden-test-service",
64+
"--config", "whirr-override-test.properties",
65+
"--private-key-file", keys.get("private").getAbsolutePath()
66+
);
67+
clusterSpec = clusterCommand.getClusterSpec(optionSet);
68+
assertThat(optionSet.has("quiet"), is(true));
69+
assertThat(clusterSpec.isQuiet(), is(true));
70+
assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
71+
assertThat(clusterSpec.getClusterName(), is("test-cluster"));
72+
73+
optionSet = clusterCommand.parser.parse("--quiet", "false",
74+
"--service-name", "overridden-test-service",
75+
"--config", "whirr-override-test.properties",
76+
"--private-key-file", keys.get("private").getAbsolutePath()
77+
);
78+
clusterSpec = clusterCommand.getClusterSpec(optionSet);
79+
assertThat(optionSet.has("quiet"), is(true));
80+
assertThat(clusterSpec.isQuiet(), is(false));
81+
assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
82+
assertThat(clusterSpec.getClusterName(), is("test-cluster"));
83+
84+
optionSet = clusterCommand.parser.parse("--quiet", "some-value",
85+
"--service-name", "overridden-test-service",
86+
"--config", "whirr-override-test.properties",
87+
"--private-key-file", keys.get("private").getAbsolutePath()
88+
);
89+
clusterSpec = clusterCommand.getClusterSpec(optionSet);
90+
assertThat(optionSet.has("quiet"), is(true));
91+
assertThat(clusterSpec.isQuiet(), is(false));
92+
assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
93+
assertThat(clusterSpec.getClusterName(), is("test-cluster"));
94+
95+
optionSet = clusterCommand.parser.parse(
96+
"--service-name", "overridden-test-service",
97+
"--config", "whirr-override-test.properties",
98+
"--private-key-file", keys.get("private").getAbsolutePath()
99+
);
100+
clusterSpec = clusterCommand.getClusterSpec(optionSet);
101+
assertThat(optionSet.has("quiet"), is(false));
102+
assertThat(clusterSpec.isQuiet(), is(false));
103+
assertThat(clusterSpec.getServiceName(), is("overridden-test-service"));
104+
assertThat(clusterSpec.getClusterName(), is("test-cluster"));
105+
59106
}
60107

61108
/**

src/site/xdoc/configuration-guide.xml

+10
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd
8888
<td>Whether or not to automatically terminate all nodes when cluster
8989
launch fails for some reason.</td>
9090
</tr>
91+
<tr valign="top">
92+
<td>
93+
<tt>whirr.quiet</tt>
94+
</td>
95+
<td>
96+
<tt>--quiet</tt>
97+
</td>
98+
<td>false</td>
99+
<td>Adjust user level, console logging verbosity. System level logs controlled via <tt>conf/log4j-cli.xml</tt>.</td>
100+
</tr>
91101
</table>
92102
<subsection name="Instance Templates Options"></subsection>
93103
<table border="0">

0 commit comments

Comments
 (0)