[ Server ] [ Harbor ] - sync projects
This commit is contained in:
@@ -78,7 +78,9 @@ public class FuncServiceImpl implements FuncService {
|
||||
true
|
||||
);
|
||||
|
||||
return JudgeSyncBaseCommandResult(syncResultLog);
|
||||
boolean harborResult = JudgeSyncBaseCommandResult(syncResultLog);
|
||||
|
||||
return harborResult;
|
||||
}
|
||||
|
||||
private boolean JudgeSyncBaseCommandResult(List<String> syncResultLog) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -60,13 +62,12 @@ public class HarborFuncScheduler {
|
||||
}
|
||||
|
||||
// 1 - sync harbor
|
||||
|
||||
if (!SyncBetweenHarbor(projectDeployContext)) {
|
||||
log.error("sync harbor project failed !");
|
||||
}
|
||||
|
||||
// 1 - load image from tar.gz
|
||||
|
||||
|
||||
|
||||
|
||||
log.info("Harbor Image Synchronized Succeed !");
|
||||
}
|
||||
|
||||
@@ -115,13 +116,13 @@ public class HarborFuncScheduler {
|
||||
listProjectArgList.add(masterNode.getServerIpInV4());
|
||||
|
||||
// send harbor create message
|
||||
boolean createProjectOK = funcService.callHarborFuncAndJudge(
|
||||
boolean listProjectOK = funcService.callHarborFuncAndJudge(
|
||||
masterNode.getTopicName(),
|
||||
HarborFunctionEnum.LIST_PROJECT,
|
||||
listProjectArgList
|
||||
);
|
||||
|
||||
if (!createProjectOK) {
|
||||
if (!listProjectOK) {
|
||||
log.error(
|
||||
"[ListHarborProject] - List Harbor Project Failed !=> {}",
|
||||
listProjectArgList
|
||||
@@ -132,6 +133,69 @@ public class HarborFuncScheduler {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean SyncBetweenHarbor(ProjectDeployContext projectDeployContext) {
|
||||
|
||||
// use master node as harbor server
|
||||
ServerInfoPO masterNode = projectDeployContext.getMasterNode();
|
||||
|
||||
ArrayList<String> syncHarborArgList = new ArrayList<>();
|
||||
syncHarborArgList.add(HarborFunctionEnum.LIST_PROJECT.getOpName());
|
||||
syncHarborArgList.add(masterNode.getServerIpInV4());
|
||||
|
||||
String sourceHarborHost = getIPv4Address();
|
||||
syncHarborArgList.add(sourceHarborHost);
|
||||
|
||||
boolean syncHarborProjectOk = funcService.callHarborFuncAndJudge(
|
||||
masterNode.getTopicName(),
|
||||
HarborFunctionEnum.SYNC_PROJECT_BETWEEN_HARBOR,
|
||||
syncHarborArgList
|
||||
);
|
||||
|
||||
if (!syncHarborProjectOk) {
|
||||
log.error(
|
||||
"[SYNC_PROJECT_BETWEEN_HARBOR] - Sync Harbor Project Failed !=> {}",
|
||||
syncHarborArgList
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private String getIPv4Address() {
|
||||
|
||||
String os = System
|
||||
.getProperty("os.name")
|
||||
.toLowerCase();
|
||||
String devHarborSourceHost = "10.250.0.100";
|
||||
if (os.contains("linux")) {
|
||||
try {
|
||||
InetAddress localhost = InetAddress.getLocalHost();
|
||||
|
||||
if (localhost.getHostAddress() != null && !localhost
|
||||
.getHostAddress()
|
||||
.isEmpty()) {
|
||||
return localhost.getHostAddress();
|
||||
} else {
|
||||
|
||||
return devHarborSourceHost;
|
||||
}
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
} else {
|
||||
log.info(
|
||||
"getIPv4Address => dev env set ipv4 addr to => {}",
|
||||
devHarborSourceHost
|
||||
);
|
||||
return devHarborSourceHost;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void beforeRunProcedure(ProjectDeployContext projectDeployContext) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user