final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(ListLoggerLevels.class);
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
boolean isCluster = false;
boolean isDas = false;
boolean isInstance = false;
boolean isConfig = false;
String targetConfigName = "";
try {
HashMap<String, String> props = null;
Config config = domain.getConfigNamed(target);
if (config != null) {
targetConfigName = target;
isConfig = true;
Server targetServer = domain.getServerNamed(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME);
if (targetServer.getConfigRef().equals(target)) {
isDas = true;
}
} else {
Server targetServer = domain.getServerNamed(target);
if (targetServer != null && targetServer.isDas()) {
isDas = true;
} else {
com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
if (cluster != null) {
isCluster = true;
targetConfigName = cluster.getConfigRef();
} else if (targetServer != null) {
isInstance = true;
targetConfigName = targetServer.getConfigRef();
}
}
if (isInstance) {
Cluster clusterForInstance = targetServer.getCluster();
if (clusterForInstance != null) {
targetConfigName = clusterForInstance.getConfigRef();
}
}
}
if (isCluster || isInstance) {
props = (HashMap<String, String>) loggingConfig.getLoggingProperties(targetConfigName);
} else if (isDas) {
props = (HashMap<String, String>) loggingConfig.getLoggingProperties();
} else if (isConfig) {
// This loop is for the config which is not part of any target
props = (HashMap<String, String>) loggingConfig.getLoggingProperties(targetConfigName);
} else {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
String msg = localStrings.getLocalString("invalid.target.sys.props",
"Invalid target: {0}. Valid default target is a server named ''server'' (default) or cluster name.", target);
report.setMessage(msg);
return;
}
List<String> keys = new ArrayList<String>();
keys.addAll(props.keySet());
Collections.sort(keys);
Iterator<String> it2 = keys.iterator();
// The following Map & List are used to hold the REST data
Map<String, String> logLevelMap = new HashMap<String, String>();
List<String> loggerList = new ArrayList<String>();
while (it2.hasNext()) {
String name = it2.next();
if (name.endsWith(".level") && !name.equals(".level")) {
final ActionReport.MessagePart part = report.getTopMessagePart()
.addChild();
String n = name.substring(0, name.lastIndexOf(".level"));
part.setMessage(n + "\t" + "<" + (String) props.get(name) + ">");
logLevelMap.put(n, props.get(name)); //Needed for REST xml and JSON output
loggerList.add(n); //Needed for REST xml and JSON output
}
}
// Populate the extraProperties data structure for REST...
Properties restData = new Properties();
restData.put("logLevels", logLevelMap);
restData.put("loggers", loggerList);
report.setExtraProperties(restData);
} catch (IOException ex) {
report.setMessage(localStrings.getLocalString("get.log.level.failed",
"Could not get logging levels for {0}.", target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}