mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[fix] fix upload bug
This commit is contained in:
parent
7537cc1f5d
commit
cda0c64435
@ -22,6 +22,7 @@
|
|||||||
<zip4j.version>2.5.2</zip4j.version>
|
<zip4j.version>2.5.2</zip4j.version>
|
||||||
<jgit.version>5.7.0.202003110725-r</jgit.version>
|
<jgit.version>5.7.0.202003110725-r</jgit.version>
|
||||||
<mvn.invoker.version>3.0.1</mvn.invoker.version>
|
<mvn.invoker.version>3.0.1</mvn.invoker.version>
|
||||||
|
<commons.net.version>3.6</commons.net.version>
|
||||||
|
|
||||||
<!-- 部署时跳过该module -->
|
<!-- 部署时跳过该module -->
|
||||||
<maven.deploy.skip>true</maven.deploy.skip>
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
@ -107,6 +108,13 @@
|
|||||||
<version>${jgit.version}</version>
|
<version>${jgit.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 时间工具类,NTP时间同步 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-net</groupId>
|
||||||
|
<artifactId>commons-net</artifactId>
|
||||||
|
<version>${commons.net.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Maven Invoker(编译 maven 项目) -->
|
<!-- Maven Invoker(编译 maven 项目) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.shared</groupId>
|
<groupId>org.apache.maven.shared</groupId>
|
||||||
|
@ -8,6 +8,7 @@ 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;
|
||||||
@ -38,6 +39,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();
|
||||||
|
|
||||||
// 解析配置文件
|
// 解析配置文件
|
||||||
PropertyUtils.init();
|
PropertyUtils.init();
|
||||||
Properties properties = PropertyUtils.getProperties();
|
Properties properties = PropertyUtils.getProperties();
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.github.kfcfans.oms.server.common.utils;
|
||||||
|
|
||||||
|
import com.github.kfcfans.oms.common.RemoteConstant;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.net.ntp.NTPUDPClient;
|
||||||
|
import org.apache.commons.net.ntp.NtpV3Packet;
|
||||||
|
import org.apache.commons.net.ntp.TimeInfo;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间工具
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2020/5/19
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class TimeUtils {
|
||||||
|
|
||||||
|
// NTP 授时服务器(阿里云 -> 交大 -> 水果)
|
||||||
|
private static final List<String> NTP_SERVER_LIST = Lists.newArrayList("ntp.aliyun.com", "ntp.sjtu.edu.cn", "time1.apple.com");
|
||||||
|
// 最大误差 5S
|
||||||
|
private static final long MAX_OFFSET = 5000;
|
||||||
|
|
||||||
|
public static void check() throws TimeCheckException {
|
||||||
|
|
||||||
|
NTPUDPClient timeClient = new NTPUDPClient();
|
||||||
|
timeClient.setDefaultTimeout((int) RemoteConstant.DEFAULT_TIMEOUT_MS);
|
||||||
|
|
||||||
|
for (String address : NTP_SERVER_LIST) {
|
||||||
|
try {
|
||||||
|
TimeInfo t = timeClient.getTime(InetAddress.getByName(address));
|
||||||
|
NtpV3Packet ntpV3Packet = t.getMessage();
|
||||||
|
log.info("[TimeUtils] use ntp server: {}, request result: {}", address, ntpV3Packet);
|
||||||
|
// RFC-1305标准:https://tools.ietf.org/html/rfc1305
|
||||||
|
// 忽略传输误差吧...也就几十毫秒的事(阿里云给力啊!)
|
||||||
|
long local = System.currentTimeMillis();
|
||||||
|
long ntp = ntpV3Packet.getTransmitTimeStamp().getTime();
|
||||||
|
long offset = local - ntp;
|
||||||
|
if (Math.abs(offset) > MAX_OFFSET) {
|
||||||
|
String msg = String.format("inaccurate server time(local:%d, ntp:%d), please use ntp update to calibration time", local, ntp);
|
||||||
|
throw new TimeCheckException(msg);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}catch (Exception ignore) {
|
||||||
|
log.warn("[TimeUtils] ntp server: {} may down!", address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new TimeCheckException("no available ntp server, maybe alibaba, sjtu and apple are both collapse");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class TimeCheckException extends RuntimeException {
|
||||||
|
public TimeCheckException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
public TimeCheckException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -151,7 +151,9 @@ public class ContainerService {
|
|||||||
// 将文件拷贝到正确的路径
|
// 将文件拷贝到正确的路径
|
||||||
String finalFileStr = OmsFileUtils.genContainerJarPath() + fileName;
|
String finalFileStr = OmsFileUtils.genContainerJarPath() + fileName;
|
||||||
File finalFile = new File(finalFileStr);
|
File finalFile = new File(finalFileStr);
|
||||||
FileUtils.forceDelete(finalFile);
|
if (finalFile.exists()) {
|
||||||
|
FileUtils.forceDelete(finalFile);
|
||||||
|
}
|
||||||
FileUtils.moveFile(tmpFile, finalFile);
|
FileUtils.moveFile(tmpFile, finalFile);
|
||||||
|
|
||||||
return md5;
|
return md5;
|
||||||
|
@ -4,7 +4,6 @@ package com.github.kfcfans.oms.worker.common.utils;
|
|||||||
import com.esotericsoftware.kryo.Kryo;
|
import com.esotericsoftware.kryo.Kryo;
|
||||||
import com.esotericsoftware.kryo.io.Input;
|
import com.esotericsoftware.kryo.io.Input;
|
||||||
import com.esotericsoftware.kryo.io.Output;
|
import com.esotericsoftware.kryo.io.Output;
|
||||||
import com.esotericsoftware.kryo.util.Pool;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 序列化器
|
* 序列化器
|
||||||
|
Loading…
x
Reference in New Issue
Block a user