[ Cmii ] [ Octopus ] - add Image Function Scheduler - 2

This commit is contained in:
zeaslity
2024-03-28 15:13:11 +08:00
parent 08c526c4a4
commit aa4412f042
8 changed files with 121 additions and 17 deletions

View File

@@ -22,6 +22,9 @@ public class ImageSyncContext {
// function args
ArrayList<String> imageSyncFuncArgs;
// download only
Boolean downloadAndCompressOnly;
// target
ProjectInfoPO projectInfoPO;
ServerInfoPO projectMasterNode;

View File

@@ -121,12 +121,15 @@ public class FuncServiceImpl implements FuncService {
// add in
funcArgs.add(0, imageFunctionEnum.getFuncName());
return syncCallFunction(
List<String> resultLog = syncCallFunction(
agentTopicName,
ExecutionMessageType.IMAGE,
funcArgs,
true
);
funcArgs.remove(0);
return resultLog;
}

View File

@@ -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)) {

View File

@@ -31,8 +31,12 @@ public class CoreProjectServiceImpl implements CoreProjectService {
@Override
public Page<ProjectInfoPO> 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<ProjectInfoPO>(projectInfoService.getBaseMapper())
.likeRight(
StringUtils.isNotBlank(projectQueryEntity.getProjectName()),

View File

@@ -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

View File

@@ -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

View File

@@ -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<ProjectInfoPO> result = projectService.projectQueryByEntity(null);
assertNull(result);
}
@Test
public void testProjectQueryByEntityWithNullProjectNameAndProjectNamespace() {
ProjectQueryEntity entity = new ProjectQueryEntity();
Page<ProjectInfoPO> result = projectService.projectQueryByEntity(entity);
assertNull(result);
}
@SneakyThrows
@Test
public void testProjectQueryByEntityWithNullPageNumberAndPageSize() {
ProjectQueryEntity entity = new ProjectQueryEntity();
// entity.setProjectName("");
entity.setProjectNamespace("wdd");
Page<ProjectInfoPO> 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<ProjectInfoPO> expectedPage = new Page<>(2, 20);
when(projectInfoService.getBaseMapper().selectList(any())).thenReturn(new ArrayList<>());
Page<ProjectInfoPO> result = projectService.projectQueryByEntity(entity);
assertNotNull(result);
Assertions.assertEquals(expectedPage.getCurrent(), result.getCurrent());
Assertions.assertEquals(expectedPage.getSize(), result.getSize());
}
}

View File

@@ -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<String> CmiiAppNameList = new ArrayList<>(List.of(
// "harbor.cdcyy.com.cn/cmii/cmii-uav-mission:5.3.0-cqly-032802"
));
ArrayList<String> 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();