forked from ctripcorp/x-pipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lishanglin
committed
Mar 19, 2024
1 parent
b3a26f9
commit 7e547d8
Showing
10 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ava/com/ctrip/xpipe/redis/console/controller/api/migrate/meta/ClusterMigrationStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.ctrip.xpipe.redis.console.controller.api.migrate.meta; | ||
|
||
import com.ctrip.xpipe.redis.console.cache.DcCache; | ||
import com.ctrip.xpipe.redis.console.migration.status.MigrationStatus; | ||
import com.ctrip.xpipe.redis.console.model.DcTbl; | ||
import com.ctrip.xpipe.redis.console.model.MigrationClusterTbl; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2024/3/18 | ||
*/ | ||
public class ClusterMigrationStatus { | ||
|
||
public Long startAt; | ||
|
||
public Long endAt; | ||
|
||
public String sourceDc; | ||
|
||
public String destDc; | ||
|
||
public String status; | ||
|
||
public static ClusterMigrationStatus from(MigrationClusterTbl migrationClusterTbl, DcCache dcCache) { | ||
ClusterMigrationStatus migrationStatus = new ClusterMigrationStatus(); | ||
migrationStatus.startAt = TimeUnit.MILLISECONDS.toSeconds(migrationClusterTbl.getStartTime().getTime()); | ||
if (null != migrationClusterTbl.getEndTime()) { | ||
migrationStatus.endAt = TimeUnit.MILLISECONDS.toSeconds(migrationClusterTbl.getEndTime().getTime()); | ||
} else { | ||
migrationStatus.endAt = null; | ||
} | ||
|
||
DcTbl srcDcTbl = dcCache.find(migrationClusterTbl.getSourceDcId()); | ||
DcTbl destDcTbl = dcCache.find(migrationClusterTbl.getDestinationDcId()); | ||
if (null != srcDcTbl) migrationStatus.sourceDc = srcDcTbl.getDcName(); | ||
if (null != destDcTbl) migrationStatus.destDc = destDcTbl.getDcName(); | ||
migrationStatus.status = MigrationStatus.valueOf(migrationClusterTbl.getStatus()).getType(); | ||
|
||
return migrationStatus; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ClusterMigrationStatus{" + | ||
"startAt=" + startAt + | ||
", endAt=" + endAt + | ||
", sourceDc='" + sourceDc + '\'' + | ||
", destDc='" + destDc + '\'' + | ||
", status='" + status + '\'' + | ||
'}'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...n/java/com/ctrip/xpipe/redis/console/controller/api/migrate/meta/MigrationHistoryReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.ctrip.xpipe.redis.console.controller.api.migrate.meta; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2024/3/18 | ||
*/ | ||
public class MigrationHistoryReq { | ||
|
||
public long from; | ||
|
||
public long to; | ||
|
||
public Set<String> clusters; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ava/com/ctrip/xpipe/redis/console/controller/api/migrate/MigrationApiIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.ctrip.xpipe.redis.console.controller.api.migrate; | ||
|
||
import com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest; | ||
import com.ctrip.xpipe.redis.console.controller.api.migrate.meta.ClusterMigrationStatus; | ||
import com.ctrip.xpipe.redis.console.controller.api.migrate.meta.MigrationHistoryReq; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2024/3/18 | ||
*/ | ||
public class MigrationApiIntegrationTest extends AbstractConsoleIntegrationTest { | ||
|
||
@Autowired | ||
private MigrationApi migrationApi; | ||
|
||
@Test | ||
public void testGetClusterMigrationHistory() { | ||
MigrationHistoryReq req = new MigrationHistoryReq(); | ||
req.from = 0; | ||
req.to = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + 600; | ||
req.clusters = Collections.singleton("cluster2"); | ||
|
||
Map<String, List<ClusterMigrationStatus>> resp = migrationApi.getClusterMigrationHistory(req); | ||
logger.info("[testGetClusterMigrationHistory] {}", resp); | ||
Assert.assertTrue(resp.containsKey("cluster2")); | ||
Assert.assertEquals(1, resp.get("cluster2").size()); | ||
Assert.assertEquals("Processing", resp.get("cluster2").get(0).status); | ||
} | ||
|
||
protected String prepareDatas() throws IOException { | ||
return prepareDatasFromFile("src/test/resources/migration-test.sql"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters