@Test(expected = Exception.class) public void testNacosDeleteToNacosWithException() throws Exception { Assert.assertFalse(nacosSyncToNacosService.delete(null)); }
@Override public boolean delete(TaskDO taskDO) { try { NamingService sourceNamingService = nacosServerHolder.get(taskDO.getSourceClusterId(), taskDO.getGroupName()); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), taskDO.getGroupName()); sourceNamingService.unsubscribe(taskDO.getServiceName(), nacosListenerMap.get(taskDO.getTaskId())); List<Instance> instances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : instances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from nacos to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; }
NacosSyncToNacosServiceImpl implements SyncService { @Override public boolean delete(TaskDO taskDO) { try { NamingService sourceNamingService = nacosServerHolder.get(taskDO.getSourceClusterId(), taskDO.getGroupName()); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), taskDO.getGroupName()); sourceNamingService.unsubscribe(taskDO.getServiceName(), nacosListenerMap.get(taskDO.getTaskId())); List<Instance> instances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : instances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from nacos to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; } }
NacosSyncToNacosServiceImpl implements SyncService { @Override public boolean delete(TaskDO taskDO) { try { NamingService sourceNamingService = nacosServerHolder.get(taskDO.getSourceClusterId(), taskDO.getGroupName()); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), taskDO.getGroupName()); sourceNamingService.unsubscribe(taskDO.getServiceName(), nacosListenerMap.get(taskDO.getTaskId())); List<Instance> instances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : instances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from nacos to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; }  }
NacosSyncToNacosServiceImpl implements SyncService { @Override public boolean delete(TaskDO taskDO) { try { NamingService sourceNamingService = nacosServerHolder.get(taskDO.getSourceClusterId(), taskDO.getGroupName()); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), taskDO.getGroupName()); sourceNamingService.unsubscribe(taskDO.getServiceName(), nacosListenerMap.get(taskDO.getTaskId())); List<Instance> instances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : instances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from nacos to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; }  @Override boolean delete(TaskDO taskDO); @Override boolean sync(TaskDO taskDO); Instance buildSyncInstance(Instance instance, TaskDO taskDO); }
NacosSyncToNacosServiceImpl implements SyncService { @Override public boolean delete(TaskDO taskDO) { try { NamingService sourceNamingService = nacosServerHolder.get(taskDO.getSourceClusterId(), taskDO.getGroupName()); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), taskDO.getGroupName()); sourceNamingService.unsubscribe(taskDO.getServiceName(), nacosListenerMap.get(taskDO.getTaskId())); List<Instance> instances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : instances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from nacos to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; }  @Override boolean delete(TaskDO taskDO); @Override boolean sync(TaskDO taskDO); Instance buildSyncInstance(Instance instance, TaskDO taskDO);  }