in uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java [2263:2589]
private void handleServletJsonFormatDaemonsAaData(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response, boolean allDaemonsFlag)
throws IOException, ServletException
{
String methodName = "handleServletJsonFormatDaemonsAaData";
duccLogger.trace(methodName, jobid, messages.fetch("enter"));
JsonObject jsonResponse = new JsonObject();
JsonArray data = new JsonArray();
JsonArray row;
DuccDaemonsData duccDaemonsData = DuccDaemonsData.getInstance();
DuccMachinesData duccMachinesData = DuccMachinesData.getInstance();
BrokerHelper brokerHelper = BrokerHelper.getInstance();
String wsHostIP = getWebServerHostIP();
String wsHostName = getWebServerHostName();
boolean brokerAlive = brokerHelper.isAlive();
daemons:
for(DaemonName daemonName : DuccDaemonRuntimeProperties.daemonNames) {
row = new JsonArray();
String status = "";
String bootTime = "";
String hostIP = "";
String hostName = "";
String pid = "";
String pubSizeLast = "";
String pubSizeMax = "";
String heartbeatLast = "";
String heartbeatMax = "";
String heartbeatMaxTOD = "";
String jmxUrl = null;
Properties properties = DuccDaemonRuntimeProperties.getInstance().get(daemonName);
switch(daemonName) {
case Database:
if(databaseHelper.isDisabled()) {
continue daemons;
}
default:
break;
}
switch(daemonName) {
case Broker:
if(brokerAlive) {
status = DuccHandlerUtils.up();
}
else {
status = DuccHandlerUtils.down();
}
bootTime = getTimeStamp(DuccCookies.getDateStyle(request),brokerHelper.getStartTime());
hostName = useWS(wsHostName, brokerHelper.getHost());
hostIP = useWS(wsHostName, hostName, wsHostIP);
pid = ""+brokerHelper.getPID();
pubSizeLast = "-";
pubSizeMax = "-";
heartbeatLast = "";
heartbeatMax = "";
heartbeatMaxTOD = "";
jmxUrl = brokerHelper.getJmxUrl();
break;
case Database:
if(databaseHelper.isAlive()) {
status = DuccHandlerUtils.up();
}
else {
status = DuccHandlerUtils.down();
}
if(DuccPropertiesHelper.isDatabaseAutomanaged()) {
bootTime = getTimeStamp(DuccCookies.getDateStyle(request),databaseHelper.getStartTime());
hostName = useWS(wsHostName, databaseHelper.getHostListString());
hostIP = useWS(wsHostName, hostName, wsHostIP);
pid = ""+databaseHelper.getPID();
}
else {
bootTime = "-";
hostName = useWS(wsHostName, databaseHelper.getHostListString());
String[] hostList = hostName.split("\\s+");
String[] ipList = InetHelper.getIP(hostList);
StringBuffer sbuf = new StringBuffer();
if(ipList != null) {
for(String ip : ipList) {
sbuf.append(ip);
sbuf.append(" ");
}
}
hostIP = sbuf.toString();
pid = "-";
}
//
hostName = tableize(hostName);
hostIP = tableize(hostIP);
//
pubSizeLast = "-";
pubSizeMax = "-";
heartbeatLast = "";
heartbeatMax = "";
heartbeatMaxTOD = "";
jmxUrl = databaseHelper.getJmxUrl();
break;
case Webserver:
status = DuccHandlerUtils.up();
bootTime = getTimeStamp(DuccCookies.getDateStyle(request),getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyBootTime,""));
hostIP = getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyNodeIpAddress,"");
hostName = getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyNodeName,"");
pid = getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyPid,"");
pubSizeLast = "*";
pubSizeMax = "*";
heartbeatLast = "";
heartbeatMax = "";
heartbeatMaxTOD = "";
jmxUrl = getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyJmxUrl,"");
break;
default:
status = DuccHandlerUtils.unknown();
if(daemonName.equals(DaemonName.Orchestrator)) {
if(ComponentHelper.isLocked(IDuccEnv.DUCC_STATE_DIR,"orchestrator")) {
String filename = ComponentHelper.getLockFileName(IDuccEnv.DUCC_STATE_DIR,"orchestrator");
String hover = "title=\""+ComponentHelper.getLockFileNameWithPath(IDuccEnv.DUCC_STATE_DIR,"orchestrator")+"\"";
String fileNameWithHover = "<span "+hover+" >"+filename+"</span>";
status += ", "+DuccHandlerUtils.warn("warning: ")+fileNameWithHover+" found.";
}
}
bootTime = getTimeStamp(DuccCookies.getDateStyle(request),getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyBootTime,""));
hostIP = getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyNodeIpAddress,"");
hostName = getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyNodeName,"");
pid = getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyPid,"");
pubSizeLast = ""+duccDaemonsData.getEventSize(daemonName);
pubSizeMax = ""+duccDaemonsData.getEventSizeMax(daemonName);
heartbeatLast = DuccDaemonsData.getInstance().getHeartbeat(daemonName);
long timeout = DuccWebProperties.get_ducc_ws_monitored_daemon_down_millis_expiry()/1000;
if(timeout > 0) {
try {
long overtime = timeout - Long.parseLong(heartbeatLast);
if(overtime < 0) {
if(brokerAlive) {
status = DuccHandlerUtils.down();
}
if(daemonName.equals(DaemonName.Orchestrator)) {
if(ComponentHelper.isLocked(IDuccEnv.DUCC_STATE_DIR,"orchestrator")) {
String filename = ComponentHelper.getLockFileName(IDuccEnv.DUCC_STATE_DIR,"orchestrator");
String hover = "title=\""+ComponentHelper.getLockFileNameWithPath(IDuccEnv.DUCC_STATE_DIR,"orchestrator")+"\"";
String fileNameWithHover = "<span "+hover+" >"+filename+"</span>";
status += ", "+DuccHandlerUtils.warn("warning: ")+fileNameWithHover+" found.";
}
}
}
else {
if(brokerAlive) {
status = DuccHandlerUtils.up();
}
if(daemonName.equals(DaemonName.Orchestrator)) {
if(dh.is_ducc_head_virtual_master()) {
boolean reqMet = DuccData.getInstance().getLive().isJobDriverMinimalAllocateRequirementMet();
if(!reqMet) {
status = DuccHandlerUtils.up_provisional(", pending JD allocation");
}
}
}
}
}
catch(Throwable t) {
}
}
heartbeatMax = DuccDaemonsData.getInstance().getMaxHeartbeat(daemonName);
heartbeatMaxTOD = TimeStamp.simpleFormat(DuccDaemonsData.getInstance().getMaxHeartbeatTOD(daemonName));
try {
heartbeatMaxTOD = getTimeStamp(DuccCookies.getDateStyle(request),heartbeatMaxTOD);
}
catch(Exception e) {
}
jmxUrl = getPropertiesValue(properties,DuccDaemonRuntimeProperties.keyJmxUrl,"");
break;
}
// Status
row.add(new JsonPrimitive(status));
// Daemon Name
row.add(new JsonPrimitive(daemonName.name()));
// Boot Time
row.add(new JsonPrimitive(bootTime));
// Host IP
row.add(new JsonPrimitive(hostIP));
// Host Name
row.add(new JsonPrimitive(hostName));
// PID
row.add(new JsonPrimitive(pid));
// Publication Size (last)
row.add(new JsonPrimitive(""+pubSizeLast));
// Publication Size (max)
row.add(new JsonPrimitive(""+pubSizeMax));
// Heartbeat (last)
row.add(new JsonPrimitive(""+heartbeatLast));
// Heartbeat (max)
row.add(new JsonPrimitive(""+heartbeatMax));
// Heartbeat (max) TOD
row.add(new JsonPrimitive(""+heartbeatMaxTOD));
// JConsole URL
String jmxUrlLink = "";
if(jmxUrl != null) {
jmxUrlLink = buildjConsoleLink(jmxUrl);
}
row.add(new JsonPrimitive(jmxUrlLink));
//
data.add(row);
}
// <Agents>
boolean showAgents = allDaemonsFlag;
if(!showAgents) {
String cookie = DuccCookies.getCookie(request,DuccCookies.cookieAgents);
duccLogger.trace(methodName, jobid, "== show: "+cookie);
if(cookie.equals(DuccCookies.valueAgentsShow)) {
showAgents = true;
}
}
if(showAgents) {
if(dh.is_ducc_head_backup()) {
row = new JsonArray();
noAgents(row, "no data - not master");
data.add(row);
}
else {
Map<MachineInfo,NodeId> machines = duccMachinesData.getMachines();
Iterator<MachineInfo> iterator = machines.keySet().iterator();
while(iterator.hasNext()) {
row = new JsonArray();
MachineInfo machineInfo = iterator.next();
String machineName = machineInfo.getShortName();
if(machineName.startsWith("=")) {
continue;
}
// Status
StringBuffer status = new StringBuffer();
if(brokerAlive) {
String machineStatus = machineInfo.getStatus();
if(machineStatus.equals("down")) {
//status.append("<span class=\"health_red\""+">");
status.append(DuccHandlerUtils.down());
//status.append("</span>");
}
else if(machineStatus.equals("up")) {
//status.append("<span class=\"health_green\""+">");
status.append(DuccHandlerUtils.up());
//status.append("</span>");
}
else {
status.append(DuccHandlerUtils.unknown());
}
}
else {
status.append(DuccHandlerUtils.unknown());
}
row.add(new JsonPrimitive(status.toString()));
// Daemon Name
String daemonName = "Agent";
row.add(new JsonPrimitive(daemonName));
// Boot Time
String bootTime = null;
long bootTimeLong = machineInfo.getBootTime();
if(bootTimeLong > 0) {
bootTime = getTimeStamp(DuccCookies.getDateStyle(request),bootTimeLong);
}
row.add(new JsonPrimitive(bootTime));
// Host IP
String hostIP = machineInfo.getIp();
row.add(new JsonPrimitive(hostIP));
// Host Name
String hostName = machineInfo.getName();
row.add(new JsonPrimitive(hostName));
// PID
String pid = null;
long pidLong = machineInfo.getPid();
if(pidLong > 0) {
pid = ""+pidLong;
}
row.add(new JsonPrimitive(pid));
// Publication Size (last)
String publicationSizeLast = machineInfo.getPublicationSizeLast();
row.add(new JsonPrimitive(publicationSizeLast));
// Publication Size (max)
String publicationSizeMax = machineInfo.getPublicationSizeMax();
row.add(new JsonPrimitive(publicationSizeMax));
// Heartbeat (last)
String heartbeatLast = machineInfo.getHeartbeatLast();
row.add(new JsonPrimitive(heartbeatLast));
// Heartbeat (max)
long heartbeatMax = machineInfo.getHeartbeatMax();
if(heartbeatMax > 0) {
row.add(new JsonPrimitive(heartbeatMax));
}
else {
row.add(new JsonPrimitive(""));
}
// Heartbeat (max) TOD
String fmtHeartbeatMaxTOD = "";
long heartbeatMaxTOD = machineInfo.getHeartbeatMaxTOD();
if(heartbeatMaxTOD > 0) {
fmtHeartbeatMaxTOD = TimeStamp.simpleFormat(""+heartbeatMaxTOD);
try {
fmtHeartbeatMaxTOD = getTimeStamp(DuccCookies.getDateStyle(request),fmtHeartbeatMaxTOD);
}
catch(Exception e) {
}
}
row.add(new JsonPrimitive(fmtHeartbeatMaxTOD));
// JConsole URL
String jmxUrl = machineInfo.getJconsole();
String jmxUrlLink = "";
if(jmxUrl != null) {
jmxUrlLink = buildjConsoleLink(jmxUrl);
}
row.add(new JsonPrimitive(jmxUrlLink));
//
data.add(row);
}
}
}
// </Agents>
jsonResponse.add("aaData", data);
String json = jsonResponse.toString();
duccLogger.debug(methodName, jobid, json);
response.getWriter().println(json);
response.setContentType("application/json");
duccLogger.trace(methodName, jobid, messages.fetch("exit"));
}