|
|
@@ -1,7 +1,5 @@
|
|
|
package cn.reghao.autodop.dmaster.app.service.config.impl;
|
|
|
|
|
|
-import cn.reghao.autodop.common.machine.disk.Disk;
|
|
|
-import cn.reghao.autodop.common.machine.disk.DiskInfo;
|
|
|
import cn.reghao.autodop.common.util.ByteConverter;
|
|
|
import cn.reghao.autodop.common.util.ByteType;
|
|
|
import cn.reghao.autodop.common.util.FileOps;
|
|
|
@@ -10,7 +8,8 @@ import cn.reghao.autodop.dmaster.app.db.query.config.BuildDirQuery;
|
|
|
import cn.reghao.autodop.dmaster.app.model.po.config.build.BuildDir;
|
|
|
import cn.reghao.autodop.dmaster.app.model.po.config.build.LocalBuildDir;
|
|
|
import cn.reghao.autodop.dmaster.app.service.config.BuildDirService;
|
|
|
-import cn.reghao.jdkutil.MachineId;
|
|
|
+import cn.reghao.jdkutil.machine.Disk;
|
|
|
+import cn.reghao.jdkutil.machine.MachineId;
|
|
|
import cn.reghao.jdkutil.result.Result;
|
|
|
import cn.reghao.jdkutil.result.ResultStatus;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -29,13 +28,11 @@ import java.util.Objects;
|
|
|
public class BuildDirServiceImpl implements BuildDirService {
|
|
|
private final BuildDirQuery buildDirQuery;
|
|
|
private final BuildDirCrud buildDirCrud;
|
|
|
- private final Disk disk;
|
|
|
private final ByteConverter converter;
|
|
|
|
|
|
- public BuildDirServiceImpl(BuildDirQuery buildDirQuery, BuildDirCrud buildDirCrud, Disk disk) {
|
|
|
+ public BuildDirServiceImpl(BuildDirQuery buildDirQuery, BuildDirCrud buildDirCrud) {
|
|
|
this.buildDirQuery = buildDirQuery;
|
|
|
this.buildDirCrud = buildDirCrud;
|
|
|
- this.disk = disk;
|
|
|
this.converter = new ByteConverter();
|
|
|
}
|
|
|
|
|
|
@@ -58,15 +55,15 @@ public class BuildDirServiceImpl implements BuildDirService {
|
|
|
}
|
|
|
|
|
|
private BuildDir createLocalBuildDir(String localBuildDir) throws Exception {
|
|
|
- DiskInfo diskInfo = disk.diskInfo(localBuildDir);
|
|
|
+ Disk.DiskDetail diskDetail = Disk.diskDetail(localBuildDir);
|
|
|
BuildDir buildDir = new BuildDir();
|
|
|
buildDir.setMachineId(MachineId.id());
|
|
|
buildDir.setMachineIpv4(MachineId.ipv4());
|
|
|
buildDir.setDirPath(localBuildDir);
|
|
|
- buildDir.setMountedOn(diskInfo.getMountedOn());
|
|
|
- buildDir.setTotal(converter.convert(ByteType.Bytes, diskInfo.getSize()));
|
|
|
- buildDir.setUsed(converter.convertStr(ByteType.Bytes, ByteType.MiB, diskInfo.getUsed()));
|
|
|
- buildDir.setAvail(converter.convertStr(ByteType.Bytes, ByteType.MiB, diskInfo.getAvail()));
|
|
|
+ buildDir.setMountedOn(diskDetail.getMountedOn());
|
|
|
+ buildDir.setTotal(converter.convert(ByteType.Bytes, diskDetail.getSize()));
|
|
|
+ buildDir.setUsed(converter.convertStr(ByteType.Bytes, ByteType.MiB, diskDetail.getUsed()));
|
|
|
+ buildDir.setAvail(converter.convertStr(ByteType.Bytes, ByteType.MiB, diskDetail.getAvail()));
|
|
|
buildDir.setIsDelete(false);
|
|
|
|
|
|
createLocalBuildDir(buildDir);
|
|
|
@@ -101,10 +98,10 @@ public class BuildDirServiceImpl implements BuildDirService {
|
|
|
public void refresh(BuildDir buildDir) {
|
|
|
setLocalBuildDir(buildDir);
|
|
|
String dirPath = buildDir.getDirPath();
|
|
|
- DiskInfo diskInfo = disk.diskInfo(dirPath);
|
|
|
- if (diskInfo != null) {
|
|
|
- buildDir.setUsed(converter.convertStr(ByteType.Bytes, ByteType.MiB, diskInfo.getUsed()));
|
|
|
- buildDir.setAvail(converter.convertStr(ByteType.Bytes, ByteType.MiB, diskInfo.getAvail()));
|
|
|
+ Disk.DiskDetail diskDetail = Disk.diskDetail(dirPath);
|
|
|
+ if (diskDetail != null) {
|
|
|
+ buildDir.setUsed(converter.convertStr(ByteType.Bytes, ByteType.MiB, diskDetail.getUsed()));
|
|
|
+ buildDir.setAvail(converter.convertStr(ByteType.Bytes, ByteType.MiB, diskDetail.getAvail()));
|
|
|
} else {
|
|
|
log.error("本地目录 {} 不合法,autodop-dmaster 结束运行", dirPath);
|
|
|
System.exit(1);
|
|
|
@@ -121,7 +118,7 @@ public class BuildDirServiceImpl implements BuildDirService {
|
|
|
String oldDirPath = oldBuildDir.getDirPath();
|
|
|
String oldMountedOn = oldBuildDir.getMountedOn();
|
|
|
String newDirPath = buildDir.getDirPath();
|
|
|
- String newMountedOn = disk.diskInfo(newDirPath).getMountedOn();
|
|
|
+ String newMountedOn = Disk.diskDetail(newDirPath).getMountedOn();
|
|
|
|
|
|
if (newDirPath.equals(oldDirPath)) {
|
|
|
return Result.result(ResultStatus.FAIL, "目录没有改变");
|