Skip to content

Commit

Permalink
[ZEPPELIN-4240] Fixed the date format error in cluster management page
Browse files Browse the repository at this point in the history
### What is this PR for?
The startup time of the zeppelin service and the interpreter process in the cluster metadata. The heartbeat time is the LocalDateTime.
The correct format is not displayed in the cluster management page.

### What type of PR is it?
[Bug Fix]

### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-4240

### How should this be tested?
* [CI Pass](https://travis-ci.org/liuxunorg/zeppelin/builds/558822999)

### Screenshots (if appropriate)

# Before fixed
![cluster-web-page-error-time](https://user-images.githubusercontent.com/3677382/61205136-d8870f00-a721-11e9-9879-174cd5b6ad0e.png)

# After fixed
![FormattedDateTime](https://user-images.githubusercontent.com/3677382/61205142-dd4bc300-a721-11e9-80f6-beb930eed834.gif)

### Questions:
* Does the licenses files need update?
* Is there breaking changes for older versions?
* Does this needs documentation?

Author: Xun Liu <[email protected]>

Closes apache#3407 from liuxunorg/ZEPPELIN-4240 and squashes the following commits:

bd07e6c [Xun Liu] modify function `formatLocalDateTime(...)`
f1fa1a6 [Xun Liu] [ZEPPELIN-4240] Formatted display service time in the cluster management page
  • Loading branch information
xunliu committed Aug 1, 2019
1 parent de4c0bc commit e391de0
Showing 1 changed file with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -130,13 +132,29 @@ public Response getClusterNodes(){
}

if (properties.containsKey(ClusterMeta.SERVER_START_TIME)) {
sortProperties.put(ClusterMeta.SERVER_START_TIME, properties.get(ClusterMeta.SERVER_START_TIME));
// format LocalDateTime
Object serverStartTime = properties.get(ClusterMeta.SERVER_START_TIME);
if (serverStartTime instanceof LocalDateTime) {
LocalDateTime localDateTime = (LocalDateTime) serverStartTime;
String dateTime = formatLocalDateTime(localDateTime);
sortProperties.put(ClusterMeta.SERVER_START_TIME, dateTime);
} else {
sortProperties.put(ClusterMeta.SERVER_START_TIME, "Wrong time type!");
}
}
if (properties.containsKey(ClusterMeta.STATUS)) {
sortProperties.put(ClusterMeta.STATUS, properties.get(ClusterMeta.STATUS));
}
if (properties.containsKey(ClusterMeta.LATEST_HEARTBEAT)) {
sortProperties.put(ClusterMeta.LATEST_HEARTBEAT, properties.get(ClusterMeta.LATEST_HEARTBEAT));
// format LocalDateTime
Object latestHeartbeat = properties.get(ClusterMeta.LATEST_HEARTBEAT);
if (latestHeartbeat instanceof LocalDateTime) {
LocalDateTime localDateTime = (LocalDateTime) latestHeartbeat;
String dateTime = formatLocalDateTime(localDateTime);
sortProperties.put(ClusterMeta.LATEST_HEARTBEAT, dateTime);
} else {
sortProperties.put(ClusterMeta.LATEST_HEARTBEAT, "Wrong time type!");
}
}
if (properties.containsKey(ClusterMeta.INTP_PROCESS_LIST)) {
sortProperties.put(ClusterMeta.INTP_PROCESS_LIST, properties.get(ClusterMeta.INTP_PROCESS_LIST));
Expand All @@ -152,8 +170,10 @@ public Response getClusterNodes(){
return new JsonResponse(Response.Status.OK, "", nodes).build();
}

private String formatIntpLink(String intpName) {
return String.format("<a href=\"/#/cluster/%s\">%s</a>", intpName, intpName);
private String formatLocalDateTime(LocalDateTime localDateTime) {
DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME;
String strDate = localDateTime.format(dtf);
return strDate;
}

/**
Expand All @@ -177,6 +197,30 @@ public Response getClusterNode(@PathParam("nodeName") String nodeName,
HashMap<String, Object> node = new HashMap<String, Object>();
node.put(ClusterMeta.NODE_NAME, intpNodeName);
node.put(PROPERTIES, intpMetaEntity.getValue());

// format LocalDateTime
HashMap<String, Object> properties = intpMetaEntity.getValue();
if (properties.containsKey(ClusterMeta.INTP_START_TIME)) {
Object intpStartTime = properties.get(ClusterMeta.INTP_START_TIME);
if (intpStartTime instanceof LocalDateTime) {
LocalDateTime localDateTime = (LocalDateTime) intpStartTime;
String dateTime = formatLocalDateTime(localDateTime);
properties.put(ClusterMeta.INTP_START_TIME, dateTime);
} else {
properties.put(ClusterMeta.INTP_START_TIME, "Wrong time type!");
}
}
if (properties.containsKey(ClusterMeta.LATEST_HEARTBEAT)) {
Object latestHeartbeat = properties.get(ClusterMeta.LATEST_HEARTBEAT);
if (latestHeartbeat instanceof LocalDateTime) {
LocalDateTime localDateTime = (LocalDateTime) latestHeartbeat;
String dateTime = formatLocalDateTime(localDateTime);
properties.put(ClusterMeta.LATEST_HEARTBEAT, dateTime);
} else {
properties.put(ClusterMeta.LATEST_HEARTBEAT, "Wrong time type!");
}
}

intpProcesses.add(node);
}
}
Expand Down

0 comments on commit e391de0

Please sign in to comment.