@Test public void testDeleteZkClusterFail() throws Exception { when(zkClusterMap.get("empty")).thenReturn(null); try { registryCenterService.deleteZkCluster("empty"); fail("should not be here"); } catch (SaturnJobConsoleException e) { Assert.assertEquals("fail to delete.for ZkCluster does not exist", e.getMessage()); } ZkCluster zkCluster = new ZkCluster(); ArrayList<RegistryCenterConfiguration> regCenterConfList = new ArrayList(); zkCluster.setRegCenterConfList(regCenterConfList); regCenterConfList.add(new RegistryCenterConfiguration()); when(zkClusterMap.get("hasDomains")).thenReturn(zkCluster); try { registryCenterService.deleteZkCluster("hasDomains"); fail("should not be here"); } catch (SaturnJobConsoleException e) { Assert.assertEquals("fail to delete.for ZkCluster still has domains", e.getMessage()); } when(zkClusterMap.get("noDomainsInMemory")).thenReturn(new ZkCluster()); when(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster("noDomainsInMemory")).thenReturn(Arrays.asList("")); try { registryCenterService.deleteZkCluster("noDomainsInMemory"); fail("should not be here"); } catch (SaturnJobConsoleException e) { Assert.assertEquals("fail to delete.for ZkCluster still has domains", e.getMessage()); } when(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster("noDomainsInMemory")).thenReturn(null); registryCenterService.deleteZkCluster("noDomainsInMemory"); verify(zkClusterInfoService, times(1)).deleteZkCluster("noDomainsInMemory"); }
@Transactional(rollbackFor = Exception.class) @Override public void deleteZkCluster(String zkClusterKey) throws SaturnJobConsoleException { if (getZkCluster(zkClusterKey) == null) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster does not exist"); } if (domainCount(zkClusterKey) > 0) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } if (!CollectionUtils.isEmpty(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster(zkClusterKey))) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } zkClusterInfoService.deleteZkCluster(zkClusterKey); notifyRefreshRegCenter(); }
RegistryCenterServiceImpl implements RegistryCenterService { @Transactional(rollbackFor = Exception.class) @Override public void deleteZkCluster(String zkClusterKey) throws SaturnJobConsoleException { if (getZkCluster(zkClusterKey) == null) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster does not exist"); } if (domainCount(zkClusterKey) > 0) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } if (!CollectionUtils.isEmpty(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster(zkClusterKey))) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } zkClusterInfoService.deleteZkCluster(zkClusterKey); notifyRefreshRegCenter(); } }
RegistryCenterServiceImpl implements RegistryCenterService { @Transactional(rollbackFor = Exception.class) @Override public void deleteZkCluster(String zkClusterKey) throws SaturnJobConsoleException { if (getZkCluster(zkClusterKey) == null) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster does not exist"); } if (domainCount(zkClusterKey) > 0) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } if (!CollectionUtils.isEmpty(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster(zkClusterKey))) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } zkClusterInfoService.deleteZkCluster(zkClusterKey); notifyRefreshRegCenter(); }  }
RegistryCenterServiceImpl implements RegistryCenterService { @Transactional(rollbackFor = Exception.class) @Override public void deleteZkCluster(String zkClusterKey) throws SaturnJobConsoleException { if (getZkCluster(zkClusterKey) == null) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster does not exist"); } if (domainCount(zkClusterKey) > 0) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } if (!CollectionUtils.isEmpty(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster(zkClusterKey))) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } zkClusterInfoService.deleteZkCluster(zkClusterKey); notifyRefreshRegCenter(); }  @PostConstruct void init(); @PreDestroy void destroy(); @Override RegistryCenterClient connect(final String nameAndNameSpace); @Override RegistryCenterClient connectByNamespace(String namespace); @Override RegistryCenterConfiguration findConfig(String nameAndNamespace); @Override RegistryCenterConfiguration findConfigByNamespace(String namespace); @Override List<RegistryCenterConfiguration> findConfigsByZkCluster(ZkCluster zkCluster); @Override CuratorRepository.CuratorFrameworkOp connectOnly(String zkAddr, String namespace); @Override void notifyRefreshRegCenter(); @Override RegistryCenterClient getCuratorByNameAndNamespace(String nameAndNamespace); @Override boolean isDashboardLeader(String zkClusterKey); @Override ZkCluster getZkCluster(String zkClusterKey); @Transactional(rollbackFor = Exception.class) @Override void createZkCluster(String zkClusterKey, String alias, String connectString, String description); @Transactional(rollbackFor = Exception.class) @Override void updateZkCluster(String zkClusterKey, String connectString, String description); @Override Collection<ZkCluster> getZkClusterList(); @Override List<ZkCluster> getOnlineZkClusterList(); @Override int domainCount(String zkClusterKey); @Override boolean namespaceIsCorrect(String namespace, CuratorFramework curatorFramework); @Override List<String> getNamespaces(); @Override File exportNamespaceInfo(List<String> namespaceList); @Transactional(rollbackFor = {Exception.class}) @Override void createNamespace(NamespaceDomainInfo namespaceDomainInfo); @Override void updateNamespace(NamespaceDomainInfo namespaceDomainInfo); @Override NamespaceDomainInfo getNamespace(String namespace); @Transactional(rollbackFor = {Exception.class}) @Override void bindNamespaceAndZkCluster(String namespace, String zkClusterKey, String updatedBy); @Override CuratorRepository.CuratorFrameworkOp getCuratorFrameworkOp(String namespace); @Override synchronized void refreshRegistryCenterForNamespace(String zkClusterName, String namespace); @Transactional(rollbackFor = Exception.class) @Override void deleteZkCluster(String zkClusterKey); }
RegistryCenterServiceImpl implements RegistryCenterService { @Transactional(rollbackFor = Exception.class) @Override public void deleteZkCluster(String zkClusterKey) throws SaturnJobConsoleException { if (getZkCluster(zkClusterKey) == null) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster does not exist"); } if (domainCount(zkClusterKey) > 0) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } if (!CollectionUtils.isEmpty(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster(zkClusterKey))) { throw new SaturnJobConsoleException("fail to delete.for ZkCluster still has domains"); } zkClusterInfoService.deleteZkCluster(zkClusterKey); notifyRefreshRegCenter(); }  @PostConstruct void init(); @PreDestroy void destroy(); @Override RegistryCenterClient connect(final String nameAndNameSpace); @Override RegistryCenterClient connectByNamespace(String namespace); @Override RegistryCenterConfiguration findConfig(String nameAndNamespace); @Override RegistryCenterConfiguration findConfigByNamespace(String namespace); @Override List<RegistryCenterConfiguration> findConfigsByZkCluster(ZkCluster zkCluster); @Override CuratorRepository.CuratorFrameworkOp connectOnly(String zkAddr, String namespace); @Override void notifyRefreshRegCenter(); @Override RegistryCenterClient getCuratorByNameAndNamespace(String nameAndNamespace); @Override boolean isDashboardLeader(String zkClusterKey); @Override ZkCluster getZkCluster(String zkClusterKey); @Transactional(rollbackFor = Exception.class) @Override void createZkCluster(String zkClusterKey, String alias, String connectString, String description); @Transactional(rollbackFor = Exception.class) @Override void updateZkCluster(String zkClusterKey, String connectString, String description); @Override Collection<ZkCluster> getZkClusterList(); @Override List<ZkCluster> getOnlineZkClusterList(); @Override int domainCount(String zkClusterKey); @Override boolean namespaceIsCorrect(String namespace, CuratorFramework curatorFramework); @Override List<String> getNamespaces(); @Override File exportNamespaceInfo(List<String> namespaceList); @Transactional(rollbackFor = {Exception.class}) @Override void createNamespace(NamespaceDomainInfo namespaceDomainInfo); @Override void updateNamespace(NamespaceDomainInfo namespaceDomainInfo); @Override NamespaceDomainInfo getNamespace(String namespace); @Transactional(rollbackFor = {Exception.class}) @Override void bindNamespaceAndZkCluster(String namespace, String zkClusterKey, String updatedBy); @Override CuratorRepository.CuratorFrameworkOp getCuratorFrameworkOp(String namespace); @Override synchronized void refreshRegistryCenterForNamespace(String zkClusterName, String namespace); @Transactional(rollbackFor = Exception.class) @Override void deleteZkCluster(String zkClusterKey);  }