|
@@ -0,0 +1,69 @@
|
|
|
|
+package com.its.rota.client.controller;
|
|
|
|
+
|
|
|
|
+import com.its.rota.client.dto.CenterDto;
|
|
|
|
+import com.its.rota.client.dto.NET;
|
|
|
|
+import com.its.rota.client.repository.ApplicationRepository;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
+@RequestMapping("/info")
|
|
|
|
+public class ItsRotaClientController {
|
|
|
|
+
|
|
|
|
+ private final ApplicationRepository repo;
|
|
|
|
+
|
|
|
|
+ @GetMapping(value = "", produces = {"application/json; charset=utf8"})
|
|
|
|
+ public String info() {
|
|
|
|
+ String sep = System.getProperty("line.separator");
|
|
|
|
+ String heading = "---------------------------------------------------------------------------------------------------------";
|
|
|
|
+
|
|
|
|
+ CenterDto center = ApplicationRepository.center;
|
|
|
|
+
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ sb.append(heading + sep);
|
|
|
|
+ sb.append("ITS Rota Client Running Information" + sep);
|
|
|
|
+ sb.append(heading + sep);
|
|
|
|
+ sb.append(String.format("%s, %s", center.getCenterId(), center.getIpAddress()) + sep);
|
|
|
|
+ sb.append(heading + sep);
|
|
|
|
+ sb.append(String.format("%s %-15.15s %-8.8s %-20.20s %-20.20s %-20.20s %7s %s",
|
|
|
|
+ "---", "IP Address", "Network",
|
|
|
|
+ "Connect Time", "Disconnect Time",
|
|
|
|
+ "Last Recv Time", "Count", "Center Name") + sep);
|
|
|
|
+ sb.append(heading + sep);
|
|
|
|
+ int total = 0;
|
|
|
|
+ int onLine = 0;
|
|
|
|
+ List<String> keySet = new ArrayList<>(this.repo.getRegionCenterMap().keySet());
|
|
|
|
+ Collections.sort(keySet);
|
|
|
|
+ for (String key : keySet) {
|
|
|
|
+ CenterDto region = this.repo.getRegionCenterMap().get(key);
|
|
|
|
+ if (region == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ total++;
|
|
|
|
+ String commStatus = "Closed";
|
|
|
|
+ if (region.getNetState().getState() != NET.CLOSED) {
|
|
|
|
+ commStatus = "Connect";
|
|
|
|
+ onLine++;
|
|
|
|
+ }
|
|
|
|
+ sb.append(String.format("%s %-15.15s %-8.8s %-20.20s %-20.20s %-20.20s %7d %s",
|
|
|
|
+ region.getCenterId(), region.getIpAddress(), commStatus,
|
|
|
|
+ region.getNetState().getConnectTimeString(), region.getNetState().getDisconnectTimeString(),
|
|
|
|
+ region.getTraffic().getLastRecvTime(), region.getTraffic().getTotalRecv(),
|
|
|
|
+ region.getCenterInfo()) + sep);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ sb.append(heading + sep);
|
|
|
|
+ sb.append(String.format("Total : %d, OnLine(Connect): %d", total, onLine) + sep);
|
|
|
|
+ sb.append(heading + sep);
|
|
|
|
+ return sb.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|