use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class NacosClusterControllerTest method testListNodes.
@Test
public void testListNodes() {
Member member1 = new Member();
member1.setIp("1.1.1.1");
List<Member> members = Arrays.asList(member1);
Mockito.when(serverMemberManager.allMembers()).thenReturn(members);
RestResult<Collection<Member>> result = nacosClusterController.listNodes("1.1.1.1");
Assert.assertEquals(1, result.getData().size());
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class NacosClusterControllerTest method testGetHealth.
@Test
public void testGetHealth() {
Member self = new Member();
self.setState(NodeState.UP);
Mockito.when(serverMemberManager.getSelf()).thenReturn(self);
RestResult<String> result = nacosClusterController.getHealth();
Assert.assertEquals(NodeState.UP.name(), result.getData());
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class ServerLoaderControllerTest method testLoaderMetrics.
@Test
public void testLoaderMetrics() throws NacosException {
EnvUtil.setEnvironment(new MockEnvironment());
Member member = new Member();
member.setIp("1.1.1.1");
member.setPort(8848);
ServerAbilities serverAbilities = new ServerAbilities();
ServerRemoteAbility serverRemoteAbility = new ServerRemoteAbility();
serverRemoteAbility.setSupportRemoteConnection(true);
serverAbilities.setRemoteAbility(serverRemoteAbility);
member.setAbilities(serverAbilities);
Mockito.when(serverMemberManager.allMembersWithoutSelf()).thenReturn(Collections.singletonList(member));
Map<String, String> metrics = new HashMap<>();
metrics.put("conCount", "1");
ServerLoaderInfoResponse serverLoaderInfoResponse = new ServerLoaderInfoResponse();
serverLoaderInfoResponse.setLoaderMetrics(metrics);
Mockito.when(serverLoaderInfoRequestHandler.handle(Mockito.any(), Mockito.any())).thenReturn(serverLoaderInfoResponse);
Mockito.when(serverMemberManager.getSelf()).thenReturn(member);
ResponseEntity<Map<String, Object>> result = serverLoaderController.loaderMetrics();
Assert.assertEquals(9, result.getBody().size());
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class ClusterRpcClientProxy method refresh.
/**
* init cluster rpc clients.
*
* @param members cluster server list member list.
*/
private void refresh(List<Member> members) throws NacosException {
// ensure to create client of new members
for (Member member : members) {
if (MemberUtil.isSupportedLongCon(member)) {
createRpcClientAndStart(member, ConnectionType.GRPC);
}
}
// shutdown and remove old members.
Set<Map.Entry<String, RpcClient>> allClientEntrys = RpcClientFactory.getAllClientEntries();
Iterator<Map.Entry<String, RpcClient>> iterator = allClientEntrys.iterator();
List<String> newMemberKeys = members.stream().filter(MemberUtil::isSupportedLongCon).map(this::memberClientKey).collect(Collectors.toList());
while (iterator.hasNext()) {
Map.Entry<String, RpcClient> next1 = iterator.next();
if (next1.getKey().startsWith("Cluster-") && !newMemberKeys.contains(next1.getKey())) {
Loggers.CLUSTER.info("member leave,destroy client of member - > : {}", next1.getKey());
RpcClientFactory.getClient(next1.getKey()).shutdown();
iterator.remove();
}
}
}
use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.
the class DistroLoadDataTask method loadAllDataSnapshotFromRemote.
private boolean loadAllDataSnapshotFromRemote(String resourceType) {
DistroTransportAgent transportAgent = distroComponentHolder.findTransportAgent(resourceType);
DistroDataProcessor dataProcessor = distroComponentHolder.findDataProcessor(resourceType);
if (null == transportAgent || null == dataProcessor) {
Loggers.DISTRO.warn("[DISTRO-INIT] Can't find component for type {}, transportAgent: {}, dataProcessor: {}", resourceType, transportAgent, dataProcessor);
return false;
}
for (Member each : memberManager.allMembersWithoutSelf()) {
try {
Loggers.DISTRO.info("[DISTRO-INIT] load snapshot {} from {}", resourceType, each.getAddress());
DistroData distroData = transportAgent.getDatumSnapshot(each.getAddress());
boolean result = dataProcessor.processSnapshot(distroData);
Loggers.DISTRO.info("[DISTRO-INIT] load snapshot {} from {} result: {}", resourceType, each.getAddress(), result);
if (result) {
distroComponentHolder.findDataStorage(resourceType).finishInitial();
return true;
}
} catch (Exception e) {
Loggers.DISTRO.error("[DISTRO-INIT] load snapshot {} from {} failed.", resourceType, each.getAddress(), e);
}
}
return false;
}
Aggregations