KeeperContainerServiceImpl extends AbstractConsoleService<KeepercontainerTblDao> implements KeeperContainerService { @Override public List<KeepercontainerTbl> findBestKeeperContainersByDcCluster(String dcName, String clusterName) { long clusterOrgId; if (clusterName != null) { ClusterTbl clusterTbl = clusterService.find(clusterName); clusterOrgId = clusterTbl == null ? XPipeConsoleConstant.DEFAULT_ORG_ID : clusterTbl.getClusterOrgId(); } else { clusterOrgId = XPipeConsoleConstant.DEFAULT_ORG_ID; } logger.info("cluster org id: {}", clusterOrgId); return queryHandler.handleQuery(new DalQuery<List<KeepercontainerTbl>>() { @Override public List<KeepercontainerTbl> doQuery() throws DalException { List<KeepercontainerTbl> kcs = dao.findKeeperContainerByCluster(dcName, clusterOrgId, KeepercontainerTblEntity.READSET_KEEPER_COUNT_BY_CLUSTER); if (kcs == null || kcs.isEmpty()) { logger.info("cluster {} with org id {} is going to find keepercontainers in normal pool", clusterName, clusterOrgId); kcs = dao.findKeeperContainerByCluster(dcName, XPipeConsoleConstant.DEFAULT_ORG_ID, KeepercontainerTblEntity.READSET_KEEPER_COUNT_BY_CLUSTER); } logger.info("find keeper containers: {}", kcs); return kcs; } }); }  @Override KeepercontainerTbl find(final long id); @Override List<KeepercontainerTbl> findAllByDcName(final String dcName); @Override List<KeepercontainerTbl> findAllActiveByDcName(String dcName); @Override List<KeepercontainerTbl> findKeeperCount(String dcName); @Override List<KeepercontainerTbl> findBestKeeperContainersByDcCluster(String dcName, String clusterName); @Override void addKeeperContainer(final KeeperContainerCreateInfo createInfo); @Override List<KeeperContainerCreateInfo> getDcAllKeeperContainers(String dc); @Override void updateKeeperContainer(KeeperContainerCreateInfo createInfo); @Override List<KeeperContainerInfoModel> findAllInfos();  }
@Test public void testFindKeeperCountByClusterWithBUSpecified() { String clusterName = "cluster2"; long orgId = 2L; List<KeepercontainerTbl> keeperCount = keeperContainerService.findBestKeeperContainersByDcCluster(dcNames[0], clusterName); keeperCount.forEach(kc -> logger.info("{}", kc)); Assert.assertTrue(keeperCount.stream().allMatch(kc->kc.getKeepercontainerOrgId() == orgId)); }
@Test public void testFindKeeperCountByClusterWithBUSpecifiedAndContainsKeepers() { String clusterName = "cluster5"; long orgId = 5L; List<KeepercontainerTbl> keeperCount = keeperContainerService.findBestKeeperContainersByDcCluster(dcNames[0], clusterName); keeperCount.forEach(kc -> logger.info("{}", kc)); Assert.assertTrue(keeperCount.stream().allMatch(kc->kc.getKeepercontainerOrgId() == orgId)); }
@Test public void testFindKeeperCountByClusterWithNoneBUSpecified() { String clusterName = "cluster1"; long orgId = XPipeConsoleConstant.DEFAULT_ORG_ID; List<KeepercontainerTbl> keeperCount = keeperContainerService.findBestKeeperContainersByDcCluster(dcNames[0], clusterName); keeperCount.forEach(kc -> logger.info("{}", kc)); Assert.assertTrue(keeperCount.stream().allMatch(kc->kc.getKeepercontainerOrgId() == orgId)); }
@Test public void testFindKeeperCountByClusterWithNoKCForBU() { String clusterName = "cluster3"; long orgId = XPipeConsoleConstant.DEFAULT_ORG_ID; List<KeepercontainerTbl> keeperCount = keeperContainerService.findBestKeeperContainersByDcCluster(dcNames[0], clusterName); keeperCount.forEach(kc -> logger.info("{}", kc)); Assert.assertTrue(keeperCount.stream().allMatch(kc->kc.getKeepercontainerOrgId() == orgId)); }
@Test @DirtiesContext public void testFindKeeperCountByClusterWithAllKeeperDeleted() { String clusterName = "cluster4"; ClusterTbl clusterTbl = clusterDao.findClusterAndOrgByName(clusterName); List<KeepercontainerTbl> keeperCount = keeperContainerService.findBestKeeperContainersByDcCluster(dcNames[0], clusterName); keeperCount.forEach(kc -> logger.info("{}", kc)); Assert.assertTrue(keeperCount.stream().allMatch(kc->kc.getKeepercontainerOrgId() == clusterTbl.getClusterOrgId())); }