|
@@ -0,0 +1,70 @@
|
|
|
|
+package com.its.rota.server.controller;
|
|
|
|
+
|
|
|
|
+import com.its.rota.server.dto.CenterDto;
|
|
|
|
+import com.its.rota.server.dto.NET;
|
|
|
|
+import com.its.rota.server.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 ItsRotaServerController {
|
|
|
|
+
|
|
|
|
+ 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 Server Running Information" + sep);
|
|
|
|
+ sb.append(heading + sep);
|
|
|
|
+ sb.append(String.format("%s, %s:%d, Traffic Time: %s",
|
|
|
|
+ center.getCenterId(), center.getIpAddress(), center.getCommPort(), ApplicationRepository.checkTrafficTime) + 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 Send Time", "Count", "Center Name") + sep);
|
|
|
|
+ sb.append(heading + sep);
|
|
|
|
+ int total = 0;
|
|
|
|
+ int onLine = 0;
|
|
|
|
+ List<String> keySet = new ArrayList<>(this.repo.getCenterMap().keySet());
|
|
|
|
+ Collections.sort(keySet);
|
|
|
|
+ for (String key : keySet) {
|
|
|
|
+ CenterDto region = this.repo.getCenterMap().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().getLastSendTime(), region.getTraffic().getTotalSends(),
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|