use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class DashboardServiceImpl method asyncForceRefreshStatistics.
private void asyncForceRefreshStatistics(final String namespace) {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
RegistryCenterConfiguration conf = registryCenterService.findConfigByNamespace(namespace);
if (conf != null) {
statisticsRefreshService.refresh(conf.getZkClusterKey(), false);
}
} catch (Throwable t) {
log.error("async refresh statistics error", t);
}
}
};
updateStatisticsThreadPool.submit(runnable);
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImplTest method testDeleteZkClusterFail.
@Test
public void testDeleteZkClusterFail() throws Exception {
// delete fail
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());
}
// delete fail
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());
}
// delete fail
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());
}
// delete success
when(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster("noDomainsInMemory")).thenReturn(null);
registryCenterService.deleteZkCluster("noDomainsInMemory");
verify(zkClusterInfoService, times(1)).deleteZkCluster("noDomainsInMemory");
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class NamespaceServiceImpl method deleteNamespace.
@Override
public void deleteNamespace(String namespace) throws SaturnJobConsoleException {
boolean online = isExecutorsOnline(namespace);
if (online) {
log.info("namespace {} has online executor, can not delete it", namespace);
throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "namespace has online executor, can not delete it");
} else {
RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
deleteInfosInDB(namespace);
deleteNamespaceInZk(registryCenterConfiguration, namespace);
}
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshRegistryCenter.
private void refreshRegistryCenter() {
List<String> allOnlineNamespacesTemp = new ArrayList<>();
// 获取新的zkClusters
Map<String, ZkCluster> newClusterMap = getZkClusterInfo();
// 对比旧的。不包含的,关闭操作;包含的,检查属性是否相同,如果相同,则直接赋值,否则,关闭旧的
closeInvalidZkClient(newClusterMap);
// 完善curatorFramework。如果没有,则新建
connectToZkClusterIfPossible(newClusterMap);
// 完善ZkCluster中的注册中心信息,关闭迁移了的域,新建迁移过来的域
for (Map.Entry<String, ZkCluster> zkClusterEntry : newClusterMap.entrySet()) {
ZkCluster zkCluster = zkClusterEntry.getValue();
String key = zkClusterEntry.getKey();
List<NamespaceZkClusterMapping> nsZkClusterMappingList = namespaceZkClusterMapping4SqlService.getAllMappingsOfCluster(key);
// zkCluster对应的namespace列表
List<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
closeMoveOutNamespace(key, nsZkClusterMappingList, regCenterConfList);
initOrUpdateNamespace(allOnlineNamespacesTemp, zkCluster, nsZkClusterMappingList, regCenterConfList);
}
// 直接赋值新的
zkClusterMap = (LinkedHashMap<String, ZkCluster>) newClusterMap;
log.info("new zkClusterMap is : {}", zkClusterMap);
allOnlineNamespaces = allOnlineNamespacesTemp;
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method exportNamespaceInfo2Excel.
/**
* Export namespac
*/
File exportNamespaceInfo2Excel(List<RegistryCenterConfiguration> namespaceInfoList) throws SaturnJobConsoleException {
try {
File tmpFile = SaturnConsoleUtils.createTmpFile();
WritableWorkbook writableWorkbook = Workbook.createWorkbook(tmpFile);
WritableSheet sheet1 = writableWorkbook.createSheet("ns", 0);
sheet1.addCell(new Label(0, 0, "域名"));
sheet1.addCell(new Label(1, 0, "描述"));
sheet1.addCell(new Label(2, 0, "重要等级"));
sheet1.addCell(new Label(3, 0, "Executor版本"));
sheet1.addCell(new Label(4, 0, "ZK集群"));
for (int i = 0; i < namespaceInfoList.size(); i++) {
RegistryCenterConfiguration namespaceInfo = namespaceInfoList.get(i);
sheet1.addCell(new Label(0, i + 1, namespaceInfo.getNamespace()));
sheet1.addCell(new Label(1, i + 1, namespaceInfo.getName()));
sheet1.addCell(new Label(2, i + 1, namespaceInfo.getDegree()));
sheet1.addCell(new Label(3, i + 1, namespaceInfo.getVersion()));
sheet1.addCell(new Label(4, i + 1, namespaceInfo.getZkAlias()));
}
writableWorkbook.write();
writableWorkbook.close();
return tmpFile;
} catch (Exception e) {
throw new SaturnJobConsoleException(e);
}
}
Aggregations