Search in sources :

Example 46 with Member

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());
}
Also used : Collection(java.util.Collection) Member(com.alibaba.nacos.core.cluster.Member) Test(org.junit.Test)

Example 47 with Member

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());
}
Also used : Member(com.alibaba.nacos.core.cluster.Member) Test(org.junit.Test)

Example 48 with Member

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());
}
Also used : HashMap(java.util.HashMap) MockEnvironment(org.springframework.mock.env.MockEnvironment) ServerLoaderInfoResponse(com.alibaba.nacos.api.remote.response.ServerLoaderInfoResponse) ServerRemoteAbility(com.alibaba.nacos.api.remote.ability.ServerRemoteAbility) ServerAbilities(com.alibaba.nacos.api.ability.ServerAbilities) Member(com.alibaba.nacos.core.cluster.Member) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 49 with Member

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();
        }
    }
}
Also used : Member(com.alibaba.nacos.core.cluster.Member) MemberUtil(com.alibaba.nacos.core.cluster.MemberUtil) HashMap(java.util.HashMap) Map(java.util.Map) RpcClient(com.alibaba.nacos.common.remote.client.RpcClient)

Example 50 with Member

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;
}
Also used : DistroTransportAgent(com.alibaba.nacos.core.distributed.distro.component.DistroTransportAgent) DistroDataProcessor(com.alibaba.nacos.core.distributed.distro.component.DistroDataProcessor) Member(com.alibaba.nacos.core.cluster.Member) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Aggregations

Member (com.alibaba.nacos.core.cluster.Member)53 Test (org.junit.Test)17 NacosException (com.alibaba.nacos.api.exception.NacosException)11 HashMap (java.util.HashMap)11 Response (com.alibaba.nacos.api.remote.response.Response)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 DistroDataRequest (com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest)6 Map (java.util.Map)5 ServerLoaderInfoResponse (com.alibaba.nacos.api.remote.response.ServerLoaderInfoResponse)4 NacosAsyncRestTemplate (com.alibaba.nacos.common.http.client.NacosAsyncRestTemplate)4 DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Before (org.junit.Before)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 ServerAbilities (com.alibaba.nacos.api.ability.ServerAbilities)3 RequestCallBack (com.alibaba.nacos.api.remote.RequestCallBack)3 ServerRemoteAbility (com.alibaba.nacos.api.remote.ability.ServerRemoteAbility)3 RestResult (com.alibaba.nacos.common.model.RestResult)3 GenericType (com.alibaba.nacos.core.utils.GenericType)3