use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class NamingSubscriberServiceAggregationImpl method getSubscribersFromRemotes.
private void getSubscribersFromRemotes(String namespaceId, String serviceName, Collection<Subscriber> result) {
for (Member server : memberManager.allMembersWithoutSelf()) {
Map<String, String> paramValues = new HashMap<>(128);
paramValues.put(CommonParams.SERVICE_NAME, serviceName);
paramValues.put(CommonParams.NAMESPACE_ID, namespaceId);
paramValues.put("aggregation", String.valueOf(Boolean.FALSE));
// TODO replace with gRPC
RestResult<String> response = HttpClient.httpGet(HTTP_PREFIX + server.getAddress() + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + SUBSCRIBER_ON_SYNC_URL, new ArrayList<>(), paramValues);
if (response.ok()) {
Subscribers subscribers = JacksonUtils.toObj(response.getData(), Subscribers.class);
result.addAll(subscribers.getSubscribers());
}
}
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class ServerMemberManager_ITCase method testMemberHealthCheck.
@Test
public void testMemberHealthCheck() throws Exception {
AtomicReference<Collection<Member>> healthMembers = new AtomicReference<>();
CountDownLatch first = new CountDownLatch(1);
CountDownLatch second = new CountDownLatch(1);
NotifyCenter.registerSubscriber(new Subscriber<MembersChangeEvent>() {
@Override
public void onEvent(MembersChangeEvent event) {
System.out.println(event);
healthMembers.set(MemberUtil.selectTargetMembers(event.getMembers(), member -> !NodeState.DOWN.equals(member.getState())));
if (first.getCount() == 1) {
first.countDown();
return;
}
if (second.getCount() == 1) {
second.countDown();
}
}
@Override
public Class<? extends Event> subscribeType() {
return MembersChangeEvent.class;
}
});
String firstIp = "127.0.0.1:8847";
String secondIp = "127.0.0.1:8848";
String thirdIp = "127.0.0.1:8849";
Map<String, Member> map = new HashMap<>(4);
map.put(firstIp, Member.builder().ip("127.0.0.1").port(8847).state(NodeState.UP).build());
map.put(secondIp, Member.builder().ip("127.0.0.1").port(8848).state(NodeState.UP).build());
map.put(thirdIp, Member.builder().ip("127.0.0.1").port(8849).state(NodeState.UP).build());
Set<Member> firstMemberList = new HashSet<>(map.values());
memberManager.memberJoin(map.values());
first.await();
Set<Member> copy = new HashSet<>(firstMemberList);
copy.removeAll(healthMembers.get());
Assert.assertEquals(2, copy.size());
Member member = map.get(firstIp);
member.setState(NodeState.DOWN);
Assert.assertTrue(memberManager.update(member));
second.await();
copy = new HashSet<>(firstMemberList);
copy.removeAll(healthMembers.get());
Assert.assertEquals(3, copy.size());
Assert.assertTrue(copy.contains(map.get(firstIp)));
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class NacosClusterV2ControllerTest method testUpdate.
@Test
public void testUpdate() {
Mockito.when(serverMemberManager.update(Mockito.any())).thenReturn(true);
Member member = new Member();
member.setIp("1.1.1.1");
member.setPort(8848);
member.setAddress("test");
RestResult<Void> result = nacosClusterV2Controller.updateNodes(Collections.singletonList(member));
Assert.assertTrue(result.ok());
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class NacosClusterV2ControllerTest method testListNodes.
@Test
public void testListNodes() {
Member member1 = new Member();
member1.setIp("1.1.1.1");
member1.setPort(8848);
member1.setState(NodeState.DOWN);
Member member2 = new Member();
member2.setIp("2.2.2.2");
member2.setPort(8848);
List<Member> members = Arrays.asList(member1, member2);
Mockito.when(serverMemberManager.allMembers()).thenReturn(members);
RestResult<Collection<Member>> result1 = nacosClusterV2Controller.listNodes("1.1.1.1", null);
Assert.assertTrue(result1.getData().stream().findFirst().isPresent());
Assert.assertEquals("1.1.1.1:8848", result1.getData().stream().findFirst().get().getAddress());
RestResult<Collection<Member>> result2 = nacosClusterV2Controller.listNodes(null, "up");
Assert.assertTrue(result2.getData().stream().findFirst().isPresent());
Assert.assertEquals("2.2.2.2:8848", result2.getData().stream().findFirst().get().getAddress());
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class UpgradeJudgementTest method mockMember.
private Collection<Member> mockMember(String... versions) {
Collection<Member> result = new HashSet<>();
for (int i = 0; i < versions.length; i++) {
Member member = new Member();
member.setPort(i);
if (StringUtils.isNotBlank(versions[i])) {
member.setExtendVal(MemberMetaDataConstants.VERSION, versions[i]);
}
result.add(member);
}
when(memberManager.getSelf()).thenReturn(result.iterator().next());
when(memberManager.allMembers()).thenReturn(result);
return result;
}
Aggregations