From 5dff657eefdf964311b2cd69a0f634808326ffc2 Mon Sep 17 00:00:00 2001 From: tjq Date: Mon, 18 May 2020 09:52:25 +0800 Subject: [PATCH] [dev] update version to 1.2.0, start to test container --- oh-my-scheduler-client/pom.xml | 4 +-- oh-my-scheduler-common/pom.xml | 2 +- .../ServerDestroyContainerRequest.java | 19 +++++++++++++ oh-my-scheduler-server/pom.xml | 4 +-- .../common/constans/ContainerStatus.java | 3 ++- .../oms/server/service/ContainerService.java | 27 +++++++++++++++++++ .../web/controller/ContainerController.java | 14 +++++----- .../server/web/response/ContainerInfoVO.java | 9 ++++--- oh-my-scheduler-worker-samples/pom.xml | 2 +- oh-my-scheduler-worker/pom.xml | 4 +-- .../github/kfcfans/oms/worker/OhMyWorker.java | 2 ++ 11 files changed, 69 insertions(+), 21 deletions(-) create mode 100644 oh-my-scheduler-common/src/main/java/com/github/kfcfans/oms/common/request/ServerDestroyContainerRequest.java diff --git a/oh-my-scheduler-client/pom.xml b/oh-my-scheduler-client/pom.xml index 2f508f92..63ed06f5 100644 --- a/oh-my-scheduler-client/pom.xml +++ b/oh-my-scheduler-client/pom.xml @@ -10,11 +10,11 @@ 4.0.0 oh-my-scheduler-client - 1.1.1 + 1.2.0 jar - 1.1.1 + 1.2.0 5.6.1 diff --git a/oh-my-scheduler-common/pom.xml b/oh-my-scheduler-common/pom.xml index 3ceae542..2aceec3d 100644 --- a/oh-my-scheduler-common/pom.xml +++ b/oh-my-scheduler-common/pom.xml @@ -10,7 +10,7 @@ 4.0.0 oh-my-scheduler-common - 1.1.1 + 1.2.0 jar diff --git a/oh-my-scheduler-common/src/main/java/com/github/kfcfans/oms/common/request/ServerDestroyContainerRequest.java b/oh-my-scheduler-common/src/main/java/com/github/kfcfans/oms/common/request/ServerDestroyContainerRequest.java new file mode 100644 index 00000000..d6076a99 --- /dev/null +++ b/oh-my-scheduler-common/src/main/java/com/github/kfcfans/oms/common/request/ServerDestroyContainerRequest.java @@ -0,0 +1,19 @@ +package com.github.kfcfans.oms.common.request; + +import com.github.kfcfans.oms.common.OmsSerializable; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 服务器销毁容器请求 + * + * @author tjq + * @since 2020/5/18 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ServerDestroyContainerRequest implements OmsSerializable { + private String containerName; +} diff --git a/oh-my-scheduler-server/pom.xml b/oh-my-scheduler-server/pom.xml index b910b873..ad79c368 100644 --- a/oh-my-scheduler-server/pom.xml +++ b/oh-my-scheduler-server/pom.xml @@ -10,13 +10,13 @@ 4.0.0 oh-my-scheduler-server - 1.1.1 + 1.2.0 jar 2.9.2 2.2.6.RELEASE - 1.1.1 + 1.2.0 8.0.19 1.4.200 2.5.2 diff --git a/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/common/constans/ContainerStatus.java b/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/common/constans/ContainerStatus.java index cb28d166..61c90434 100644 --- a/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/common/constans/ContainerStatus.java +++ b/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/common/constans/ContainerStatus.java @@ -15,7 +15,8 @@ import lombok.Getter; public enum ContainerStatus { ENABLE(1), - DISABLE(2); + DISABLE(2), + DELETED(99); private int v; diff --git a/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/service/ContainerService.java b/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/service/ContainerService.java index 8001c086..25a20abc 100644 --- a/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/service/ContainerService.java +++ b/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/service/ContainerService.java @@ -2,13 +2,16 @@ package com.github.kfcfans.oms.server.service; import akka.actor.ActorSelection; import com.github.kfcfans.oms.common.model.GitRepoInfo; +import com.github.kfcfans.oms.common.model.SystemMetrics; import com.github.kfcfans.oms.common.request.ServerDeployContainerRequest; +import com.github.kfcfans.oms.common.request.ServerDestroyContainerRequest; import com.github.kfcfans.oms.common.utils.CommonUtils; import com.github.kfcfans.oms.common.utils.JsonUtils; import com.github.kfcfans.oms.common.utils.NetUtils; import com.github.kfcfans.oms.server.akka.OhMyServer; import com.github.kfcfans.oms.server.akka.actors.ServerActor; import com.github.kfcfans.oms.server.common.constans.ContainerSourceType; +import com.github.kfcfans.oms.server.common.constans.ContainerStatus; import com.github.kfcfans.oms.server.common.utils.OmsFileUtils; import com.github.kfcfans.oms.server.persistence.core.model.ContainerInfoDO; import com.github.kfcfans.oms.server.persistence.core.repository.ContainerInfoRepository; @@ -103,6 +106,30 @@ public class ContainerService { containerInfoRepository.saveAndFlush(container); } + /** + * 删除容器(通知 Worker 销毁容器 & 删除数据库) + * @param appId 应用ID,用于保护性判断 + * @param containerId 容器ID + */ + public void delete(Long appId, Long containerId) { + + ContainerInfoDO container = containerInfoRepository.findById(containerId).orElseThrow(() -> new IllegalArgumentException("can't find container by id: " + containerId)); + + if (!Objects.equals(appId, container.getAppId())) { + throw new RuntimeException("Permission Denied!"); + } + + ServerDestroyContainerRequest destroyRequest = new ServerDestroyContainerRequest(container.getContainerName()); + WorkerManagerService.getActiveWorkerInfo(container.getAppId()).keySet().forEach(akkaAddress -> { + ActorSelection workerActor = OhMyServer.getWorkerActor(akkaAddress); + workerActor.tell(destroyRequest, null); + }); + + log.info("[ContainerService] delete container: {}.", container); + // 硬删除算了...留着好像也没什么用 + containerInfoRepository.deleteById(containerId); + } + /** * 上传用于部署的容器的 Jar 文件 * @param file 接受的文件 diff --git a/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/web/controller/ContainerController.java b/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/web/controller/ContainerController.java index c72be4eb..dc5816b6 100644 --- a/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/web/controller/ContainerController.java +++ b/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/web/controller/ContainerController.java @@ -66,6 +66,12 @@ public class ContainerController { return ResultDTO.success(null); } + @GetMapping("/delete") + public ResultDTO deleteContainer(Long appId, Long containerId) { + containerService.delete(appId, containerId); + return ResultDTO.success(null); + } + @GetMapping("/list") public ResultDTO> listContainers(Long appId) { List res = containerInfoRepository.findByAppId(appId).stream().map(ContainerController::convert).collect(Collectors.toList()); @@ -79,14 +85,6 @@ public class ContainerController { return ResultDTO.success(mock); } - @GetMapping("/delete") - public ResultDTO deleteContainer(Long appId, Long containerId) { - // TODO: 先停止各个Worker的容器实例 - containerInfoRepository.deleteById(containerId); - return ResultDTO.success(null); - } - - private static ContainerInfoVO convert(ContainerInfoDO containerInfoDO) { ContainerInfoVO vo = new ContainerInfoVO(); BeanUtils.copyProperties(containerInfoDO, vo); diff --git a/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/web/response/ContainerInfoVO.java b/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/web/response/ContainerInfoVO.java index 85afbb98..3438c4d3 100644 --- a/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/web/response/ContainerInfoVO.java +++ b/oh-my-scheduler-server/src/main/java/com/github/kfcfans/oms/server/web/response/ContainerInfoVO.java @@ -14,8 +14,6 @@ import java.util.Date; public class ContainerInfoVO { private Long id; - // 所属的应用ID - private Long appId; private String containerName; @@ -24,12 +22,15 @@ public class ContainerInfoVO { // 由 sourceType 决定,JarFile -> String,存储文件名称;Git -> JSON,包括 URL,branch,username,password private String sourceInfo; - // jar的MD5,唯一,作为 GridFS 的文件名 - private String md5; + // 版本 (Jar包使用md5,Git使用commitId,前者32位,后者40位,不会产生碰撞) + private String version; // 状态,枚举值为 ContainerStatus private Integer status; + // 上一次部署时间 + private Date lastDeployTime; + private Date gmtCreate; private Date gmtModified; } diff --git a/oh-my-scheduler-worker-samples/pom.xml b/oh-my-scheduler-worker-samples/pom.xml index 71d8503f..6df6c75d 100644 --- a/oh-my-scheduler-worker-samples/pom.xml +++ b/oh-my-scheduler-worker-samples/pom.xml @@ -14,7 +14,7 @@ 2.2.6.RELEASE - 1.1.1 + 1.2.0 1.2.68 diff --git a/oh-my-scheduler-worker/pom.xml b/oh-my-scheduler-worker/pom.xml index 14a2729d..02e022e9 100644 --- a/oh-my-scheduler-worker/pom.xml +++ b/oh-my-scheduler-worker/pom.xml @@ -10,12 +10,12 @@ 4.0.0 oh-my-scheduler-worker - 1.1.1 + 1.2.0 jar 5.2.4.RELEASE - 1.1.1 + 1.2.0 1.4.200 3.4.2 5.6.1 diff --git a/oh-my-scheduler-worker/src/main/java/com/github/kfcfans/oms/worker/OhMyWorker.java b/oh-my-scheduler-worker/src/main/java/com/github/kfcfans/oms/worker/OhMyWorker.java index 9c9af7bc..ec5765ce 100644 --- a/oh-my-scheduler-worker/src/main/java/com/github/kfcfans/oms/worker/OhMyWorker.java +++ b/oh-my-scheduler-worker/src/main/java/com/github/kfcfans/oms/worker/OhMyWorker.java @@ -8,6 +8,7 @@ import com.github.kfcfans.oms.common.utils.CommonUtils; import com.github.kfcfans.oms.common.utils.JsonUtils; import com.github.kfcfans.oms.worker.actors.ProcessorTrackerActor; import com.github.kfcfans.oms.worker.actors.TaskTrackerActor; +import com.github.kfcfans.oms.worker.actors.WorkerActor; import com.github.kfcfans.oms.worker.background.OmsLogHandler; import com.github.kfcfans.oms.worker.background.ServerDiscoveryService; import com.github.kfcfans.oms.worker.background.WorkerHealthReporter; @@ -97,6 +98,7 @@ public class OhMyWorker implements ApplicationContextAware, InitializingBean, Di actorSystem = ActorSystem.create(RemoteConstant.WORKER_ACTOR_SYSTEM_NAME, akkaFinalConfig); actorSystem.actorOf(Props.create(TaskTrackerActor.class), RemoteConstant.Task_TRACKER_ACTOR_NAME); actorSystem.actorOf(Props.create(ProcessorTrackerActor.class), RemoteConstant.PROCESSOR_TRACKER_ACTOR_NAME); + actorSystem.actorOf(Props.create(WorkerActor.class), RemoteConstant.WORKER_ACTOR_NAME); log.info("[OhMyWorker] akka-remote listening address: {}", workerAddress); log.info("[OhMyWorker] akka ActorSystem({}) initialized successfully.", actorSystem);