[fix] fix instanceLog's bug

This commit is contained in:
tjq 2020-05-19 22:44:55 +08:00
parent 1cb3314186
commit c5c7f7fd71
9 changed files with 45 additions and 12 deletions

View File

@ -8,7 +8,6 @@ import com.github.kfcfans.oms.common.utils.NetUtils;
import com.github.kfcfans.oms.server.akka.actors.FriendActor; import com.github.kfcfans.oms.server.akka.actors.FriendActor;
import com.github.kfcfans.oms.server.akka.actors.ServerActor; import com.github.kfcfans.oms.server.akka.actors.ServerActor;
import com.github.kfcfans.oms.server.common.utils.PropertyUtils; import com.github.kfcfans.oms.server.common.utils.PropertyUtils;
import com.github.kfcfans.oms.server.common.utils.TimeUtils;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.typesafe.config.Config; import com.typesafe.config.Config;
@ -39,7 +38,8 @@ public class OhMyServer {
Stopwatch stopwatch = Stopwatch.createStarted(); Stopwatch stopwatch = Stopwatch.createStarted();
log.info("[OhMyServer] OhMyServer's akka system start to bootstrap..."); log.info("[OhMyServer] OhMyServer's akka system start to bootstrap...");
TimeUtils.check(); // 忽略了一个问题机器是没办法访问外网的除非架设自己的NTP服务器
// TimeUtils.check();
// 解析配置文件 // 解析配置文件
PropertyUtils.init(); PropertyUtils.init();

View File

@ -13,7 +13,7 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public enum ContainerSourceType { public enum ContainerSourceType {
JarFile(1, "Jar文件"), FatJar(1, "Jar文件"),
Git(2, "Git代码库"); Git(2, "Git代码库");
private final int v; private final int v;

View File

@ -55,6 +55,8 @@ public class TimeUtils {
} }
} }
public static final class TimeCheckException extends RuntimeException { public static final class TimeCheckException extends RuntimeException {
public TimeCheckException(String message) { public TimeCheckException(String message) {
super(message); super(message);

View File

@ -90,7 +90,7 @@ public class ContainerService {
container.setStatus(request.getStatus().getV()); container.setStatus(request.getStatus().getV());
// 文件上传形式的 sourceInfo 为该文件的 md5 Git形式的 md5 在部署阶段生成 // 文件上传形式的 sourceInfo 为该文件的 md5 Git形式的 md5 在部署阶段生成
if (request.getSourceType() == ContainerSourceType.JarFile) { if (request.getSourceType() == ContainerSourceType.FatJar) {
container.setVersion(request.getSourceInfo()); container.setVersion(request.getSourceInfo());
}else { }else {
container.setVersion("init"); container.setVersion("init");

View File

@ -3,6 +3,8 @@ package com.github.kfcfans.oms.server.web.controller;
import com.github.kfcfans.oms.common.model.DeployedContainerInfo; import com.github.kfcfans.oms.common.model.DeployedContainerInfo;
import com.github.kfcfans.oms.common.response.ResultDTO; import com.github.kfcfans.oms.common.response.ResultDTO;
import com.github.kfcfans.oms.server.akka.OhMyServer; import com.github.kfcfans.oms.server.akka.OhMyServer;
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.ContainerTemplateGenerator; import com.github.kfcfans.oms.server.common.utils.ContainerTemplateGenerator;
import com.github.kfcfans.oms.server.common.utils.OmsFileUtils; import com.github.kfcfans.oms.server.common.utils.OmsFileUtils;
import com.github.kfcfans.oms.server.persistence.core.model.AppInfoDO; import com.github.kfcfans.oms.server.persistence.core.model.AppInfoDO;
@ -15,6 +17,7 @@ import com.github.kfcfans.oms.server.web.request.GenerateContainerTemplateReques
import com.github.kfcfans.oms.server.web.request.SaveContainerInfoRequest; import com.github.kfcfans.oms.server.web.request.SaveContainerInfoRequest;
import com.github.kfcfans.oms.server.web.response.ContainerInfoVO; import com.github.kfcfans.oms.server.web.response.ContainerInfoVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -109,6 +112,15 @@ public class ContainerController {
private static ContainerInfoVO convert(ContainerInfoDO containerInfoDO) { private static ContainerInfoVO convert(ContainerInfoDO containerInfoDO) {
ContainerInfoVO vo = new ContainerInfoVO(); ContainerInfoVO vo = new ContainerInfoVO();
BeanUtils.copyProperties(containerInfoDO, vo); BeanUtils.copyProperties(containerInfoDO, vo);
if (containerInfoDO.getLastDeployTime() == null) {
vo.setLastDeployTime("N/A");
}else {
vo.setLastDeployTime(DateFormatUtils.format(containerInfoDO.getLastDeployTime(), "yyyy-MM-dd HH:mm:ss"));
}
ContainerStatus status = ContainerStatus.of(containerInfoDO.getStatus());
vo.setStatus(status.name());
ContainerSourceType sourceType = ContainerSourceType.of(containerInfoDO.getSourceType());
vo.setSourceType(sourceType.name());
return vo; return vo;
} }
} }

View File

@ -78,7 +78,7 @@ public class InstanceController {
// 转发HTTP请求如果使用Akka则需要传输两次而转发HTTP请求只需要传输一次""数据包 // 转发HTTP请求如果使用Akka则需要传输两次而转发HTTP请求只需要传输一次""数据包
if (!OhMyServer.getActorSystemAddress().equals(targetServer)) { if (!OhMyServer.getActorSystemAddress().equals(targetServer)) {
String ip = targetServer.split(":")[0]; String ip = targetServer.split(":")[0];
String url = "http://" + ip + ":" + port + "/instance/log?instanceId=" + instanceId; String url = String.format("http://%s:%s/instance/log?instanceId=%d&index=%d", ip, port, instanceId, index);
try { try {
response.sendRedirect(url); response.sendRedirect(url);
return ResultDTO.success(StringPage.simple("redirecting...")); return ResultDTO.success(StringPage.simple("redirecting..."));

View File

@ -18,7 +18,7 @@ public class ContainerInfoVO {
private String containerName; private String containerName;
// 容器类型枚举值为 ContainerSourceType // 容器类型枚举值为 ContainerSourceType
private Integer sourceType; private String sourceType;
// sourceType 决定JarFile -> String存储文件名称Git -> JSON包括 URLbranchusernamepassword // sourceType 决定JarFile -> String存储文件名称Git -> JSON包括 URLbranchusernamepassword
private String sourceInfo; private String sourceInfo;
@ -26,10 +26,10 @@ public class ContainerInfoVO {
private String version; private String version;
// 状态枚举值为 ContainerStatus // 状态枚举值为 ContainerStatus
private Integer status; private String status;
// 上一次部署时间 // 上一次部署时间
private Date lastDeployTime; private String lastDeployTime;
private Date gmtCreate; private Date gmtCreate;
private Date gmtModified; private Date gmtModified;

View File

@ -1,5 +1,5 @@
# 基础镜像 # 基础镜像由于OhMyScheduler-Server的运行需要Maven和Git环境就自己打包了一个镜像
FROM openjdk:8 FROM tjqq/jdk-maven-git:8
# 维护者 # 维护者
MAINTAINER tengjiqi@gmail.com MAINTAINER tengjiqi@gmail.com
# 设置环境变量 # 设置环境变量
@ -8,8 +8,8 @@ ENV APP_NAME=oh-my-scheduler-server
ENV PARAMS="" ENV PARAMS=""
# 将应用 jar 包拷入 docker # 将应用 jar 包拷入 docker
COPY oms-server.jar /oms-server.jar COPY oms-server.jar /oms-server.jar
# 暴露端口HTTP + AKKA # 暴露端口HTTP + AKKA-Server + AKKA-Client
EXPOSE 7700 10086 EXPOSE 7700 10086 27777
# 创建 docker 文件目录(盲猜这是用户目录) # 创建 docker 文件目录(盲猜这是用户目录)
RUN mkdir -p /root/oms-server RUN mkdir -p /root/oms-server
# 挂载数据卷,将文件直接输出到宿主机(注意,此处挂载的是匿名卷,即在宿主机位置随机) # 挂载数据卷,将文件直接输出到宿主机(注意,此处挂载的是匿名卷,即在宿主机位置随机)

View File

@ -0,0 +1,19 @@
#!/bin/bash
# -p允许后面跟一个字符串作为提示 -r保证读入的是原始内容不会发生任何转义
read -r -p "请输入Dockedr镜像版本:" version
echo "即将构建的Docker镜像oms-server:$version"
read -r -p "任意键继续:"
# 一键部署脚本,请勿挪动脚本
cd `dirname $0`/../.. || exit
echo "================== 构建 jar =================="
mvn clean package -DskipTests -Pdev -U -e
echo "================== 拷贝 jar =================="
/bin/cp -rf oh-my-scheduler-server/target/*.jar others/oms-server.jar
ls -l others/oms-server.jar
echo "================== 构建应用镜像 =================="
docker build -t tjqq/oms-server:$version others/. || exit
echo "================== (关闭老应用)括号代表非必须,只是顺便运行下新版本进行测试 =================="
docker stop oms-server
echo "================== (删除老容器) =================="
docker container rm oms-server