|
@@ -1,175 +0,0 @@
|
|
|
-import cn.reghao.devops.common.build.model.constant.RepoAuthType;
|
|
|
|
|
-import cn.reghao.devops.common.build.tool.repo.GitImpl;
|
|
|
|
|
-import cn.reghao.devops.common.docker.DockerImpl;
|
|
|
|
|
-import cn.reghao.devops.common.ws.WsClient;
|
|
|
|
|
-import cn.reghao.devops.manager.app.model.po.config.build.RepoAuthConfig;
|
|
|
|
|
-import cn.reghao.devops.manager.app.model.vo.ChartData;
|
|
|
|
|
-import cn.reghao.devops.model.NginxLog;
|
|
|
|
|
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
|
|
-import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
|
|
-import cn.reghao.jutil.jdk.text.TextFile;
|
|
|
|
|
-import com.github.dockerjava.api.command.InspectContainerResponse;
|
|
|
|
|
-import com.github.dockerjava.api.model.Container;
|
|
|
|
|
-import org.junit.Test;
|
|
|
|
|
-
|
|
|
|
|
-import java.text.ParseException;
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
|
|
-import java.time.ZoneId;
|
|
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
-import java.util.regex.Pattern;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * @author reghao
|
|
|
|
|
- * @date 2022-05-07 09:32:40
|
|
|
|
|
- */
|
|
|
|
|
-public class BuildTest {
|
|
|
|
|
- @Test
|
|
|
|
|
- public void gitTest() throws Exception {
|
|
|
|
|
- String repo = "https://codeup.aliyun.com/5f1f8daf6207a1a8b17f6742/FrontEnd/iquizoo.admin.git";
|
|
|
|
|
- RepoAuthConfig repoAuthConfig = new RepoAuthConfig();
|
|
|
|
|
- repoAuthConfig.setAuthType(RepoAuthType.http.getName());
|
|
|
|
|
- repoAuthConfig.setUsername("azygjs");
|
|
|
|
|
- repoAuthConfig.setPassword("6wNSPZH4");
|
|
|
|
|
-
|
|
|
|
|
- GitImpl git = new GitImpl(repoAuthConfig.getRepoAuth());
|
|
|
|
|
- List<String> list = git.remoteBranches(repo);
|
|
|
|
|
- System.out.println();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- public void dockerListTest() {
|
|
|
|
|
- Pattern pattern = Pattern.compile("^\\S*$");
|
|
|
|
|
- String str = "dfa safd";
|
|
|
|
|
- String str1 = "dfasafd";
|
|
|
|
|
- boolean matched = pattern.matcher(str).matches();
|
|
|
|
|
- System.out.println();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- public void dockerBuildTest() throws Exception {
|
|
|
|
|
- DockerImpl docker = new DockerImpl();
|
|
|
|
|
- String repoTag = "file:12345678";
|
|
|
|
|
- String compileHome = "/home/reghao/code/aha/tnb/file/file-service";
|
|
|
|
|
- docker.build(repoTag, compileHome);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- public void dockerTest() {
|
|
|
|
|
- DockerImpl docker = new DockerImpl();
|
|
|
|
|
- InspectContainerResponse containerInfo = docker.ps("dnkt-admin");
|
|
|
|
|
-
|
|
|
|
|
- List<Container> list = docker.ps(true);
|
|
|
|
|
- list.forEach(container -> {
|
|
|
|
|
- container.getId();
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- public void wsTest() throws InterruptedException {
|
|
|
|
|
- String url = "wss://devops.reghao.cn/ws/log/pull?token=12345678";
|
|
|
|
|
- url = "wss://devops.reghao.cn/ws/message?token=12345678";
|
|
|
|
|
-
|
|
|
|
|
- WsClient wsClient = new WsClient(url);
|
|
|
|
|
- wsClient.connect();
|
|
|
|
|
-
|
|
|
|
|
- Thread.sleep(3600_000);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- public void test() throws ParseException {
|
|
|
|
|
- Map<String, Integer> map = new TreeMap<>();
|
|
|
|
|
-
|
|
|
|
|
- TextFile textFile = new TextFile();
|
|
|
|
|
- String filePath = "/home/reghao/Downloads/api.iquizoo.com.access.log";
|
|
|
|
|
- List<String> list = textFile.read(filePath);
|
|
|
|
|
- for (String line : list) {
|
|
|
|
|
- String address = line.split(" - ")[0];
|
|
|
|
|
- String date = line.split("- \\[")[1].split("]")[0];
|
|
|
|
|
- LocalDateTime localDateTime = DateTimeConverter.localDateTime1(date);
|
|
|
|
|
- String dateTimeStr = DateTimeConverter.format(localDateTime);
|
|
|
|
|
-
|
|
|
|
|
- String key = dateTimeStr;
|
|
|
|
|
- Integer count = map.get(key);
|
|
|
|
|
- if (count == null) {
|
|
|
|
|
- map.put(key, 1);
|
|
|
|
|
- } else {
|
|
|
|
|
- int count1 = map.get(key) + 1;
|
|
|
|
|
- map.put(key, count1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- List<Map.Entry<String, Integer>> list1 = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
|
|
|
|
|
- //然后通过比较器来实现排序
|
|
|
|
|
- Collections.sort(list1, new Comparator<Map.Entry<String, Integer>>() {
|
|
|
|
|
- //升序排序
|
|
|
|
|
- public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
|
|
|
|
|
- return o2.getKey().compareTo(o1.getKey());
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- for(Map.Entry<String, Integer> mapping : list1) {
|
|
|
|
|
- String key = mapping.getKey();
|
|
|
|
|
- int value = mapping.getValue();
|
|
|
|
|
-
|
|
|
|
|
- ChartData chartData = new ChartData();
|
|
|
|
|
- //chartData.setTotal(value);
|
|
|
|
|
- Object obj1 = key;
|
|
|
|
|
- Object obj2 = Integer.valueOf(-1);
|
|
|
|
|
- List<Object> list2 = new ArrayList<>();
|
|
|
|
|
- list2.add(obj1);
|
|
|
|
|
- list2.add(obj2);
|
|
|
|
|
- //chartData.setTime(List.of(list2));
|
|
|
|
|
- System.out.println(mapping.getKey() + " -> " +mapping.getValue());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Test
|
|
|
|
|
- public void logTest() throws ParseException {
|
|
|
|
|
- /*File file = new File("");
|
|
|
|
|
- JsonConverter.jsonFileToObject(file, NginxLog.class);*/
|
|
|
|
|
-
|
|
|
|
|
- TextFile textFile = new TextFile();
|
|
|
|
|
- String filePath = "/home/reghao/Downloads/api.iquizoo.com.access1.log";
|
|
|
|
|
- filePath = "/home/reghao/Downloads/api.iquizoo.com.access.log-20231107";
|
|
|
|
|
- filePath = "/home/reghao/Downloads/api.iquizoo.com.access.log-20231108";
|
|
|
|
|
-
|
|
|
|
|
- List<String> list = textFile.read(filePath);
|
|
|
|
|
- List<NginxLog> nginxLogs = new ArrayList<>();
|
|
|
|
|
- for (String line : list) {
|
|
|
|
|
- if (!line.startsWith("{")) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- NginxLog nginxLog = JsonConverter.jsonToObject(line, NginxLog.class);
|
|
|
|
|
- nginxLogs.add(nginxLog);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- // e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Integer> map = new TreeMap<>();
|
|
|
|
|
- for (NginxLog nginxLog : nginxLogs) {
|
|
|
|
|
- String date = nginxLog.getTimeIso8601();
|
|
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss+08:00")
|
|
|
|
|
- .withZone(ZoneId.of("UTC"));
|
|
|
|
|
- LocalDateTime localDateTime = LocalDateTime.parse(date, formatter);
|
|
|
|
|
- String dateTimeStr = DateTimeConverter.format(localDateTime);
|
|
|
|
|
-
|
|
|
|
|
- String key = dateTimeStr;
|
|
|
|
|
- Integer count = map.get(key);
|
|
|
|
|
- if (count == null) {
|
|
|
|
|
- map.put(key, 1);
|
|
|
|
|
- } else {
|
|
|
|
|
- int count1 = map.get(key) + 1;
|
|
|
|
|
- map.put(key, count1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- System.out.println();
|
|
|
|
|
- map.forEach((key, value) -> {
|
|
|
|
|
- System.out.println(key + " -> " + value);
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|