From aa4412f042e62a382761edb0f1bdfc1ceed89659 Mon Sep 17 00:00:00 2001 From: zeaslity Date: Thu, 28 Mar 2024 15:13:11 +0800 Subject: [PATCH] [ Cmii ] [ Octopus ] - add Image Function Scheduler - 2 --- .../wdd/func/auto/beans/ImageSyncContext.java | 3 + .../func/auto/service/FuncServiceImpl.java | 5 +- .../func/auto/service/ImageFuncScheduler.java | 10 ++- .../impl/CoreProjectServiceImpl.java | 7 +- server/src/main/resources/application-dev.yml | 6 +- server/src/main/resources/application.yml | 8 +- .../coreService/TestCoreProjectService.java | 75 +++++++++++++++++++ .../server/func/TestImageSyncScheduler.java | 24 ++++-- 8 files changed, 121 insertions(+), 17 deletions(-) create mode 100644 server/src/test/java/io/wdd/server/coreService/TestCoreProjectService.java diff --git a/server/src/main/java/io/wdd/func/auto/beans/ImageSyncContext.java b/server/src/main/java/io/wdd/func/auto/beans/ImageSyncContext.java index da48c4b..7396a91 100644 --- a/server/src/main/java/io/wdd/func/auto/beans/ImageSyncContext.java +++ b/server/src/main/java/io/wdd/func/auto/beans/ImageSyncContext.java @@ -22,6 +22,9 @@ public class ImageSyncContext { // function args ArrayList imageSyncFuncArgs; + // download only + Boolean downloadAndCompressOnly; + // target ProjectInfoPO projectInfoPO; ServerInfoPO projectMasterNode; diff --git a/server/src/main/java/io/wdd/func/auto/service/FuncServiceImpl.java b/server/src/main/java/io/wdd/func/auto/service/FuncServiceImpl.java index bb9b858..697c2f2 100644 --- a/server/src/main/java/io/wdd/func/auto/service/FuncServiceImpl.java +++ b/server/src/main/java/io/wdd/func/auto/service/FuncServiceImpl.java @@ -121,12 +121,15 @@ public class FuncServiceImpl implements FuncService { // add in funcArgs.add(0, imageFunctionEnum.getFuncName()); - return syncCallFunction( + List resultLog = syncCallFunction( agentTopicName, ExecutionMessageType.IMAGE, funcArgs, true ); + + funcArgs.remove(0); + return resultLog; } diff --git a/server/src/main/java/io/wdd/func/auto/service/ImageFuncScheduler.java b/server/src/main/java/io/wdd/func/auto/service/ImageFuncScheduler.java index 298ef91..7c5d617 100644 --- a/server/src/main/java/io/wdd/func/auto/service/ImageFuncScheduler.java +++ b/server/src/main/java/io/wdd/func/auto/service/ImageFuncScheduler.java @@ -81,10 +81,12 @@ public class ImageFuncScheduler { } - if (CollectionUtils.isNotEmpty(cmiiAppNameTagList)) { + if (CollectionUtils.isNotEmpty(imageFullNameList)) { if (CollectionUtils.isEmpty(realFullNameList)) { + // realFullNameList = imageFullNameList; } else { + // cmii app tag name not null && imageFullNameList not nuill realFullNameList.addAll(imageFullNameList); } } @@ -122,6 +124,12 @@ public class ImageFuncScheduler { return; } + log.info("Image Sync Half Complete ! Gzip file name => {}", gzipFileName); + if (imageSyncContext.getDownloadAndCompressOnly()) { + log.info("Image Sync download only !"); + return; + } + // outside agent resultLog = funcService.callImageFuncService(outsideAgentTopicName, DOWNLOAD_GZIP_IMAGE_FILE, imageSyncFuncArgs); if (!JudgeSyncBaseCommandResult(resultLog)) { diff --git a/server/src/main/java/io/wdd/server/coreService/impl/CoreProjectServiceImpl.java b/server/src/main/java/io/wdd/server/coreService/impl/CoreProjectServiceImpl.java index de07d3b..8e0a040 100644 --- a/server/src/main/java/io/wdd/server/coreService/impl/CoreProjectServiceImpl.java +++ b/server/src/main/java/io/wdd/server/coreService/impl/CoreProjectServiceImpl.java @@ -31,8 +31,12 @@ public class CoreProjectServiceImpl implements CoreProjectService { @Override public Page projectQueryByEntity(ProjectQueryEntity projectQueryEntity) { - if (projectQueryEntity == null || projectQueryEntity.getProjectName() == null || projectQueryEntity.getProjectNamespace() == null) { + if (projectQueryEntity == null) { return null; + } else { + if (projectQueryEntity.getProjectName() == null && projectQueryEntity.getProjectNamespace() == null) { + return null; + } } if (projectQueryEntity.getPageNumber() == null || projectQueryEntity.getPageSize() == null) { @@ -45,6 +49,7 @@ public class CoreProjectServiceImpl implements CoreProjectService { projectQueryEntity.getPageSize() ); + // like wdd? new LambdaQueryChainWrapper(projectInfoService.getBaseMapper()) .likeRight( StringUtils.isNotBlank(projectQueryEntity.getProjectName()), diff --git a/server/src/main/resources/application-dev.yml b/server/src/main/resources/application-dev.yml index 7bd166a..c997f1f 100644 --- a/server/src/main/resources/application-dev.yml +++ b/server/src/main/resources/application-dev.yml @@ -6,7 +6,7 @@ spring: allow-circular-references: true allow-bean-definition-overriding: true rabbitmq: - host: 192.168.35.71 + host: 10.250.0.100 port: 20672 username: boge password: boge8tingH @@ -21,7 +21,7 @@ spring: max-interval: 65000 initial-interval: 65000 redis: - host: 192.168.35.71 + host: 10.250.0.100 port: 21370 database: 0 password: boge8tingH @@ -50,7 +50,7 @@ spring: time-between-eviction-runs: 50000 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.35.71:21306/octopus_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 + url: jdbc:mysql://10.250.0.100:21306/octopus_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 username: boge password: boge8tingH type: com.zaxxer.hikari.HikariDataSource diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 6230d11..8fcb553 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -2,14 +2,14 @@ server: port: 9999 # shanghai 42.192.52.227 -# local 42.192.52.227 +# local 10.250.0.100 # cqga 42.192.52.227 spring: main: allow-circular-references: true allow-bean-definition-overriding: true rabbitmq: - host: 42.192.52.227 + host: 10.250.0.100 port: 20672 username: boge password: boge8tingH @@ -24,7 +24,7 @@ spring: max-interval: 65000 initial-interval: 65000 redis: - host: 42.192.52.227 + host: 10.250.0.100 port: 21370 database: 0 password: boge8tingH @@ -47,7 +47,7 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://42.192.52.227:21306/octopus_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 + url: jdbc:mysql://10.250.0.100:21306/octopus_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 username: boge password: boge8tingH type: com.zaxxer.hikari.HikariDataSource diff --git a/server/src/test/java/io/wdd/server/coreService/TestCoreProjectService.java b/server/src/test/java/io/wdd/server/coreService/TestCoreProjectService.java new file mode 100644 index 0000000..70805ef --- /dev/null +++ b/server/src/test/java/io/wdd/server/coreService/TestCoreProjectService.java @@ -0,0 +1,75 @@ +package io.wdd.server.coreService; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.wdd.server.beans.po.ProjectInfoPO; +import io.wdd.server.beans.request.ProjectQueryEntity; +import io.wdd.server.service.ProjectInfoService; +import lombok.SneakyThrows; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@SpringBootTest +public class TestCoreProjectService { + + @Autowired + ObjectMapper objectMapper; + @Autowired + private ProjectInfoService projectInfoService; + @Autowired + private CoreProjectService projectService; + + @Test + public void testProjectQueryByEntityWithNullEntity() { + Page result = projectService.projectQueryByEntity(null); + assertNull(result); + } + + @Test + public void testProjectQueryByEntityWithNullProjectNameAndProjectNamespace() { + ProjectQueryEntity entity = new ProjectQueryEntity(); + Page result = projectService.projectQueryByEntity(entity); + assertNull(result); + } + + @SneakyThrows + @Test + public void testProjectQueryByEntityWithNullPageNumberAndPageSize() { + ProjectQueryEntity entity = new ProjectQueryEntity(); +// entity.setProjectName(""); + entity.setProjectNamespace("wdd"); + Page result = projectService.projectQueryByEntity(entity); + + String s = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(result); + System.out.println(s); + assertNotNull(result); + Assertions.assertEquals(1, result.getCurrent()); + Assertions.assertEquals(10, result.getSize()); + } + + @Test + public void testProjectQueryByEntityWithValidEntity() { + ProjectQueryEntity entity = new ProjectQueryEntity(); +// entity.setProjectName("Test Project"); + entity.setProjectNamespace("wdd"); + entity.setPageNumber(2); + entity.setPageSize(20); + + Page expectedPage = new Page<>(2, 20); + when(projectInfoService.getBaseMapper().selectList(any())).thenReturn(new ArrayList<>()); + + Page result = projectService.projectQueryByEntity(entity); + assertNotNull(result); + Assertions.assertEquals(expectedPage.getCurrent(), result.getCurrent()); + Assertions.assertEquals(expectedPage.getSize(), result.getSize()); + } +} diff --git a/server/src/test/java/io/wdd/server/func/TestImageSyncScheduler.java b/server/src/test/java/io/wdd/server/func/TestImageSyncScheduler.java index 55d3292..398f2df 100644 --- a/server/src/test/java/io/wdd/server/func/TestImageSyncScheduler.java +++ b/server/src/test/java/io/wdd/server/func/TestImageSyncScheduler.java @@ -11,7 +11,8 @@ import io.wdd.server.coreService.CoreProjectServerService; import io.wdd.server.coreService.CoreProjectService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; @@ -27,31 +28,40 @@ public class TestImageSyncScheduler { ImageFuncScheduler imageFuncScheduler; - @Resource + @Autowired CoreProjectService coreProjectService; - @Resource + @Autowired CoreProjectServerService coreProjectServerService; @Test public void runImageSync() { ArrayList CmiiAppNameList = new ArrayList<>(List.of( - +// "harbor.cdcyy.com.cn/cmii/cmii-uav-mission:5.3.0-cqly-032802" )); ArrayList ImageFullNameList = new ArrayList<>(List.of( - + "harbor.cdcyy.com.cn/cmii/cmii-uav-mission:5.3.0-cqly-032802" )); - String projectNamespace = "xmyd"; + Boolean downloadAndCompressOnly = true; + String projectNamespace = "wdd"; + + String innerWorkerAgentName = "Chengdu-amd64-65-lapwdd"; //wdd +// String innerWorkerAgentName = "Chengdu-amd64-71-3571gd"; //prod + + + // 之下不要修改 除非你知道自己在干什么! // start ImageSyncContext imageSyncContext = new ImageSyncContext(); + imageSyncContext.setDownloadAndCompressOnly(downloadAndCompressOnly); + // inner - imageSyncContext.setInnerWorkerAgentName("Chengdu-amd64-71-3571gd"); + imageSyncContext.setInnerWorkerAgentName(innerWorkerAgentName); // dev ProjectQueryEntity projectQueryEntity = ProjectQueryEntity.builder().projectNamespace(projectNamespace).build();