[ Server ] [ Harbor ] - sync status - 7
This commit is contained in:
@@ -210,11 +210,14 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
|
||||
hOp.SourceHarborClient = createClient
|
||||
}
|
||||
|
||||
needToSynchronizedProject := funcArgs[2]
|
||||
log.InfoF("[Harbor Sync Project ] - start to sync harbor project => %s", needToSynchronizedProject)
|
||||
|
||||
log.DebugF("[Harbor Sync Project ] - start to check projects all exists!")
|
||||
ctx := context.Background()
|
||||
|
||||
// check both source and target harbor project exists
|
||||
needToCreateProjectNameList := []string{"cmii", "rancher"}
|
||||
needToCreateProjectNameList := []string{"rancher", "cmii"}
|
||||
|
||||
for _, projectName := range needToCreateProjectNameList {
|
||||
syncNotExistHarborProjectError := []string{
|
||||
@@ -298,7 +301,7 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
|
||||
Filters: []*model.ReplicationFilter{
|
||||
{
|
||||
Type: "name",
|
||||
Value: "rancher/**", // 根据需要同步的仓库进行调整
|
||||
Value: needToSynchronizedProject + "/**",
|
||||
},
|
||||
},
|
||||
ID: 0,
|
||||
@@ -314,12 +317,12 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
|
||||
}
|
||||
|
||||
// 在源 Harbor 中创建复制策略
|
||||
log.Info("[Harbor Sync Project ] - Start To Sync Project !")
|
||||
log.InfoF("[Harbor Sync Project ] - Start To Sync Project => %s !", needToSynchronizedProject)
|
||||
|
||||
err = targetClient.NewReplicationPolicy(ctx, octopusReplicationPolicy.DestRegistry, octopusReplicationPolicy.SrcRegistry, octopusReplicationPolicy.Deletion, octopusReplicationPolicy.Override, octopusReplicationPolicy.Enabled, octopusReplicationPolicy.Filters, octopusReplicationPolicy.Trigger, octopusReplicationPolicy.DestNamespace, octopusReplicationPolicy.Name, octopusReplicationPolicy.Name)
|
||||
|
||||
if err != nil {
|
||||
syncErrorMessage := fmt.Sprintf("[Harbor Sync Project ] - Sync Project Failed ! Error is => %s\n", err.Error())
|
||||
syncErrorMessage := fmt.Sprintf("[Harbor Sync Project ] - Sync Project [ %s ] Failed ! Error is => %s\n", needToSynchronizedProject, err.Error())
|
||||
log.Error(syncErrorMessage)
|
||||
return false, []string{
|
||||
syncErrorMessage,
|
||||
@@ -345,7 +348,7 @@ func (hOp *HarborOperator) SyncProjectExec(funcArgs []string) (bool, []string) {
|
||||
}
|
||||
|
||||
return true, []string{
|
||||
"[ Harbor Sync Project ] - sync started !",
|
||||
fmt.Sprintf("[ Harbor Sync Project ] - sync project [ %s ] started !", needToSynchronizedProject),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,10 +388,12 @@ func (hOp *HarborOperator) SyncStatusExec(funcArgs []string) (bool, []string) {
|
||||
// find the newest one only have one here
|
||||
for _, execution := range replicationExecutions {
|
||||
if !strings.HasPrefix(execution.Status, "Succeed") {
|
||||
log.InfoF("[sync status]- status are => %v", execution)
|
||||
bytes, _ := json.Marshal(execution)
|
||||
log.InfoF("[sync status]- status are => %v", string(bytes))
|
||||
// report status
|
||||
return false, []string{
|
||||
fmt.Sprintf("[sync status] - not complete ! progress is => %s %", strconv.FormatInt(execution.Succeed/execution.Total, 10)),
|
||||
fmt.Sprintf("[sync status] - not complete ! progress is => %s %",
|
||||
strconv.FormatFloat(float64(execution.Succeed)/float64(execution.Total), 'f', 1, 64)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public enum HarborFunctionEnum {
|
||||
|
||||
SYNC_PROJECT_BETWEEN_HARBOR(
|
||||
"SYNC_PROJECT_BETWEEN_HARBOR",
|
||||
"在源Harbor和目标Harbor之间同步Project, args 为目标Harbor的HostName,不带端口; 源Harbor的HostName,不带端口"
|
||||
"在源Harbor和目标Harbor之间同步Project, args 为目标Harbor的HostName,不带端口; 源Harbor的HostName,不带端口; 需要同步的仓库project(rancher cmii)名称"
|
||||
),
|
||||
|
||||
SYNC_STATUS_HARBOR(
|
||||
|
||||
@@ -7,6 +7,7 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@@ -26,7 +27,14 @@ public class ProjectDeployContext {
|
||||
|
||||
boolean agentBaseProcedureAccomplished;
|
||||
|
||||
boolean harborSynchronized;
|
||||
|
||||
public static final ArrayList<String> PROJECT_NEED_TO_BY_SYNCHRONIZED = new ArrayList<>(
|
||||
List.of(
|
||||
"rancher",
|
||||
"cmii"
|
||||
)
|
||||
);
|
||||
boolean rancherHarborSynchronized;
|
||||
boolean cmiiHarborSynchronized;
|
||||
String currentSynchronizingProject;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.wdd.func.auto.beans.ProjectDeployContext.PROJECT_NEED_TO_BY_SYNCHRONIZED;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class HarborFuncScheduler {
|
||||
@@ -40,20 +42,6 @@ public class HarborFuncScheduler {
|
||||
|
||||
private void afterRunProcedure(ProjectDeployContext projectDeployContext) {
|
||||
|
||||
int maxSyncStatusCheckCount = 1000;
|
||||
int timePinch = 2;
|
||||
|
||||
int waitCount = 0;
|
||||
|
||||
while (waitCount < maxSyncStatusCheckCount && !checkHarborSyncStatus(projectDeployContext)) {
|
||||
waitCount++;
|
||||
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(timePinch);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("wait for sync status error !");
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否安装完成, 对安装环境进行判定
|
||||
log.debug("afterRunProcedure complete!");
|
||||
@@ -77,12 +65,46 @@ public class HarborFuncScheduler {
|
||||
log.error("list harbor project failed !");
|
||||
}
|
||||
|
||||
int maxSyncStatusCheckCount = 1000;
|
||||
int timePinch = 2;
|
||||
|
||||
for (String project : PROJECT_NEED_TO_BY_SYNCHRONIZED) {
|
||||
|
||||
// 1 - sync harbor
|
||||
log.info(
|
||||
"start to sync project of [ {} ]",
|
||||
project
|
||||
);
|
||||
projectDeployContext.setCurrentSynchronizingProject(project);
|
||||
if (!SyncBetweenHarbor(projectDeployContext)) {
|
||||
log.error("sync harbor project failed !");
|
||||
log.error(
|
||||
"sync harbor project [ {} ] failed !",
|
||||
project
|
||||
);
|
||||
}
|
||||
|
||||
// 1 - load image from tar.gz
|
||||
int waitCount = 0;
|
||||
while (waitCount < maxSyncStatusCheckCount && !checkHarborSyncStatus(projectDeployContext)) {
|
||||
waitCount++;
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(timePinch);
|
||||
} catch (InterruptedException e) {
|
||||
log.error(
|
||||
"wait for project of [ {} ] sync status error !",
|
||||
project
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (waitCount == maxSyncStatusCheckCount) {
|
||||
continue;
|
||||
}
|
||||
|
||||
log.info(
|
||||
"project of [ {} ] has sync success !",
|
||||
project
|
||||
);
|
||||
}
|
||||
|
||||
log.info("Harbor Image Synchronized Succeed !");
|
||||
}
|
||||
@@ -158,9 +180,14 @@ public class HarborFuncScheduler {
|
||||
syncHarborArgList.add(HarborFunctionEnum.SYNC_PROJECT_BETWEEN_HARBOR.getOpName());
|
||||
syncHarborArgList.add(masterNode.getServerIpInV4());
|
||||
|
||||
// second arg sourceHarborHost
|
||||
String sourceHarborHost = getIPv4Address();
|
||||
syncHarborArgList.add(sourceHarborHost);
|
||||
|
||||
// third arg sync project name
|
||||
syncHarborArgList.add(projectDeployContext.getCurrentSynchronizingProject());
|
||||
|
||||
|
||||
log.info(
|
||||
"{} start ! args are => {}",
|
||||
HarborFunctionEnum.SYNC_PROJECT_BETWEEN_HARBOR.getOpName(),
|
||||
|
||||
Reference in New Issue
Block a user