@Test public void testGetClusterMetaCurrentPrimaryDcNotMigrating(){ long currentActiveDcId = randomInt(); long clusterId = randomInt(); long destinationDcId = currentActiveDcId + 1; DcTbl dcTbl = new DcTbl(); ClusterTbl clusterTbl = new ClusterTbl(); clusterTbl.setId(clusterId); clusterTbl.setActivedcId(currentActiveDcId); when(migrationService.findLatestUnfinishedMigrationCluster(clusterId)).thenReturn(new MigrationClusterTbl().setDestinationDcId(destinationDcId)); dcTbl.setId(destinationDcId); for(ClusterStatus clusterStatus : ClusterStatus.values()){ if(clusterStatus == ClusterStatus.Migrating){ continue; } clusterTbl.setStatus(clusterStatus.toString()); Assert.assertEquals(currentActiveDcId, clusterMetaServiceImpl.getClusterMetaCurrentPrimaryDc(dcTbl, clusterTbl)); } }
@Override public long getClusterMetaCurrentPrimaryDc(DcTbl dcInfo, ClusterTbl clusterInfo) { if (ClusterStatus.isSameClusterStatus(clusterInfo.getStatus(), ClusterStatus.Migrating)) { MigrationClusterTbl migrationCluster = migrationService.findLatestUnfinishedMigrationCluster(clusterInfo.getId()); if(migrationCluster != null && dcInfo.getId() == migrationCluster.getDestinationDcId()) { return migrationCluster.getDestinationDcId(); } } return clusterInfo.getActivedcId(); }
ClusterMetaServiceImpl extends AbstractMetaService implements ClusterMetaService { @Override public long getClusterMetaCurrentPrimaryDc(DcTbl dcInfo, ClusterTbl clusterInfo) { if (ClusterStatus.isSameClusterStatus(clusterInfo.getStatus(), ClusterStatus.Migrating)) { MigrationClusterTbl migrationCluster = migrationService.findLatestUnfinishedMigrationCluster(clusterInfo.getId()); if(migrationCluster != null && dcInfo.getId() == migrationCluster.getDestinationDcId()) { return migrationCluster.getDestinationDcId(); } } return clusterInfo.getActivedcId(); } }
ClusterMetaServiceImpl extends AbstractMetaService implements ClusterMetaService { @Override public long getClusterMetaCurrentPrimaryDc(DcTbl dcInfo, ClusterTbl clusterInfo) { if (ClusterStatus.isSameClusterStatus(clusterInfo.getStatus(), ClusterStatus.Migrating)) { MigrationClusterTbl migrationCluster = migrationService.findLatestUnfinishedMigrationCluster(clusterInfo.getId()); if(migrationCluster != null && dcInfo.getId() == migrationCluster.getDestinationDcId()) { return migrationCluster.getDestinationDcId(); } } return clusterInfo.getActivedcId(); }  }
ClusterMetaServiceImpl extends AbstractMetaService implements ClusterMetaService { @Override public long getClusterMetaCurrentPrimaryDc(DcTbl dcInfo, ClusterTbl clusterInfo) { if (ClusterStatus.isSameClusterStatus(clusterInfo.getStatus(), ClusterStatus.Migrating)) { MigrationClusterTbl migrationCluster = migrationService.findLatestUnfinishedMigrationCluster(clusterInfo.getId()); if(migrationCluster != null && dcInfo.getId() == migrationCluster.getDestinationDcId()) { return migrationCluster.getDestinationDcId(); } } return clusterInfo.getActivedcId(); }  @Override ClusterMeta loadClusterMeta(DcMeta dcMeta, ClusterTbl clusterTbl, DcMetaQueryVO dcMetaQueryVO); @Override ClusterMeta getClusterMeta(final String dcName, final String clusterName); @Override long getClusterMetaCurrentPrimaryDc(DcTbl dcInfo, ClusterTbl clusterInfo); void setMigrationService(MigrationService migrationService); }
ClusterMetaServiceImpl extends AbstractMetaService implements ClusterMetaService { @Override public long getClusterMetaCurrentPrimaryDc(DcTbl dcInfo, ClusterTbl clusterInfo) { if (ClusterStatus.isSameClusterStatus(clusterInfo.getStatus(), ClusterStatus.Migrating)) { MigrationClusterTbl migrationCluster = migrationService.findLatestUnfinishedMigrationCluster(clusterInfo.getId()); if(migrationCluster != null && dcInfo.getId() == migrationCluster.getDestinationDcId()) { return migrationCluster.getDestinationDcId(); } } return clusterInfo.getActivedcId(); }  @Override ClusterMeta loadClusterMeta(DcMeta dcMeta, ClusterTbl clusterTbl, DcMetaQueryVO dcMetaQueryVO); @Override ClusterMeta getClusterMeta(final String dcName, final String clusterName); @Override long getClusterMetaCurrentPrimaryDc(DcTbl dcInfo, ClusterTbl clusterInfo); void setMigrationService(MigrationService migrationService);  }