use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class ClusterVersionJudgementTest method testPartMemberIsNewVersion.
@Test
public void testPartMemberIsNewVersion() {
Collection<Member> allMembers = manager.allMembers();
AtomicInteger count = new AtomicInteger();
allMembers.forEach(member -> {
if (count.get() == 0) {
member.setExtendInfo(oldVersionMeta);
} else {
count.incrementAndGet();
member.setExtendInfo(newVersionMeta);
}
});
judgement = new ClusterVersionJudgement(manager);
judgement.judge();
Assert.assertFalse(judgement.allMemberIsNewVersion());
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class NotifyTaskProcessor method process.
@Override
public boolean process(NacosTask task) {
NotifyTask notifyTask = (NotifyTask) task;
String dataId = notifyTask.getDataId();
String group = notifyTask.getGroup();
String tenant = notifyTask.getTenant();
long lastModified = notifyTask.getLastModified();
boolean isok = true;
for (Member ip : memberManager.allMembers()) {
isok = notifyToDump(dataId, group, tenant, lastModified, ip.getAddress()) && isok;
}
return isok;
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class ConfigSubService method runCollectionJob.
private List<SampleResult> runCollectionJob(String url, Map<String, String> params, CompletionService<SampleResult> completionService, List<SampleResult> resultList) {
Collection<Member> ipList = memberManager.allMembers();
List<SampleResult> collectionResult = new ArrayList<>(ipList.size());
// Submit query task.
for (Member ip : ipList) {
try {
completionService.submit(new Job(ip.getAddress(), url, params));
} catch (Exception e) {
// Send request failed.
LogUtil.DEFAULT_LOG.warn("Get client info from {} with exception: {} during submit job", ip, e.getMessage());
}
}
// Get and merge result.
SampleResult sampleResults;
for (Member member : ipList) {
try {
Future<SampleResult> f = completionService.poll(1000, TimeUnit.MILLISECONDS);
try {
if (f != null) {
sampleResults = f.get(500, TimeUnit.MILLISECONDS);
if (sampleResults != null) {
collectionResult.add(sampleResults);
}
} else {
LogUtil.DEFAULT_LOG.warn("The task in ip: {} did not completed in 1000ms ", member);
}
} catch (TimeoutException e) {
f.cancel(true);
LogUtil.DEFAULT_LOG.warn("get task result with TimeoutException: {} ", e.getMessage());
}
} catch (InterruptedException e) {
LogUtil.DEFAULT_LOG.warn("get task result with InterruptedException: {} ", e.getMessage());
} catch (ExecutionException e) {
LogUtil.DEFAULT_LOG.warn("get task result with ExecutionException: {} ", e.getMessage());
}
}
return collectionResult;
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class ClientMetricsController method metric.
/**
* get client metric.
*
* @param ip client ip .
* @return ResponseEntity
*/
@GetMapping("/cluster")
public ResponseEntity metric(@RequestParam("ip") String ip, @RequestParam(value = "dataId", required = false) String dataId, @RequestParam(value = "group", required = false) String group, @RequestParam(value = "tenant", required = false) String tenant) {
Loggers.CORE.info("Get cluster config metrics received, ip={},dataId={},group={},tenant={}", ip, dataId, group, tenant);
Map<String, Object> responseMap = new HashMap<>(3);
Collection<Member> members = serverMemberManager.allMembers();
final NacosAsyncRestTemplate nacosAsyncRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(Loggers.CLUSTER);
CountDownLatch latch = new CountDownLatch(members.size());
for (Member member : members) {
String url = HttpUtils.buildUrl(false, member.getAddress(), EnvUtil.getContextPath(), Constants.METRICS_CONTROLLER_PATH, "current");
Query query = Query.newInstance().addParam("ip", ip).addParam("dataId", dataId).addParam("group", group).addParam("tenant", tenant);
nacosAsyncRestTemplate.get(url, Header.EMPTY, query, new GenericType<Map>() {
}.getType(), new Callback<Map>() {
@Override
public void onReceive(RestResult<Map> result) {
if (result.ok()) {
responseMap.putAll(result.getData());
}
latch.countDown();
}
@Override
public void onError(Throwable throwable) {
Loggers.CORE.error("Get config metrics error from member address={}, ip={},dataId={},group={},tenant={},error={}", member.getAddress(), ip, dataId, group, tenant, throwable);
latch.countDown();
}
@Override
public void onCancel() {
latch.countDown();
}
});
}
try {
latch.await(3L, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
return ResponseEntity.ok().body(responseMap);
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class CurcuitFilter method listenerSelfInCluster.
private void listenerSelfInCluster() {
protocol.protocolMetaData().subscribe(Constants.CONFIG_MODEL_RAFT_GROUP, MetadataKey.RAFT_GROUP_MEMBER, o -> {
if (!(o instanceof ProtocolMetaData.ValueItem)) {
return;
}
final List<String> peers = (List<String>) ((ProtocolMetaData.ValueItem) o).getData();
if (CollectionUtils.isEmpty(peers)) {
isOpenService = false;
return;
}
final Member self = memberManager.getSelf();
final String raftAddress = self.getIp() + ":" + self.getExtendVal(MemberMetaDataConstants.RAFT_PORT);
// Only when you are in the cluster and the current Leader is
// elected can you provide external services
isOpenService = peers.contains(raftAddress);
});
}
Aggregations