Search in sources :

Example 51 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class ProtocolManager method injectMembers4CP.

private void injectMembers4CP(Config config) {
    final Member selfMember = memberManager.getSelf();
    final String self = selfMember.getIp() + ":" + Integer.parseInt(String.valueOf(selfMember.getExtendVal(MemberMetaDataConstants.RAFT_PORT)));
    Set<String> others = toCPMembersInfo(memberManager.allMembers());
    config.setMembers(self, others);
}
Also used : Member(com.alibaba.nacos.core.cluster.Member)

Example 52 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class RaftPeerSet method changePeers.

protected void changePeers(Collection<Member> members) {
    Map<String, RaftPeer> tmpPeers = new HashMap<>(members.size());
    for (Member member : members) {
        final String address = member.getAddress();
        if (peers.containsKey(address)) {
            tmpPeers.put(address, peers.get(address));
            continue;
        }
        RaftPeer raftPeer = new RaftPeer();
        raftPeer.ip = address;
        // first time meet the local server:
        if (EnvUtil.getLocalAddress().equals(address)) {
            raftPeer.term.set(localTerm.get());
        }
        tmpPeers.put(address, raftPeer);
    }
    // replace raft peer set:
    peers = tmpPeers;
    ready = true;
    Loggers.RAFT.info("raft peers changed: " + members);
}
Also used : HashMap(java.util.HashMap) Member(com.alibaba.nacos.core.cluster.Member)

Example 53 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class OperatorController method getHealthyServerList.

/**
 * This interface will be removed in a future release.
 *
 * @param healthy whether only query health server.
 * @return "ok"
 * @deprecated 1.3.0 This function will be deleted sometime after version 1.3.0
 */
@GetMapping("/servers")
public ObjectNode getHealthyServerList(@RequestParam(required = false) boolean healthy) {
    ObjectNode result = JacksonUtils.createEmptyJsonNode();
    if (healthy) {
        List<Member> healthyMember = memberManager.allMembers().stream().filter(member -> member.getState() == NodeState.UP).collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
        result.replace("servers", JacksonUtils.transferToJsonNode(healthyMember));
    } else {
        result.replace("servers", JacksonUtils.transferToJsonNode(memberManager.allMembers()));
    }
    return result;
}
Also used : IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) RequestParam(org.springframework.web.bind.annotation.RequestParam) Member(com.alibaba.nacos.core.cluster.Member) SwitchEntry(com.alibaba.nacos.naming.misc.SwitchEntry) WebUtils(com.alibaba.nacos.core.utils.WebUtils) ServerListManager(com.alibaba.nacos.naming.cluster.ServerListManager) ServerMemberManager(com.alibaba.nacos.core.cluster.ServerMemberManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ServiceManager(com.alibaba.nacos.naming.core.ServiceManager) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) ClientConstants(com.alibaba.nacos.naming.constants.ClientConstants) HttpServletRequest(javax.servlet.http.HttpServletRequest) PutMapping(org.springframework.web.bind.annotation.PutMapping) ServerStatusManager(com.alibaba.nacos.naming.cluster.ServerStatusManager) SwitchDomain(com.alibaba.nacos.naming.misc.SwitchDomain) NacosException(com.alibaba.nacos.api.exception.NacosException) GetMapping(org.springframework.web.bind.annotation.GetMapping) RaftCore(com.alibaba.nacos.naming.consistency.persistent.raft.RaftCore) JsonNode(com.fasterxml.jackson.databind.JsonNode) MetricsMonitor(com.alibaba.nacos.naming.monitor.MetricsMonitor) JacksonUtils(com.alibaba.nacos.common.utils.JacksonUtils) ClientManager(com.alibaba.nacos.naming.core.v2.client.manager.ClientManager) EnvUtil(com.alibaba.nacos.sys.env.EnvUtil) Collection(java.util.Collection) InternetAddressUtil(com.alibaba.nacos.common.utils.InternetAddressUtil) Loggers(com.alibaba.nacos.naming.misc.Loggers) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) DistroMapper(com.alibaba.nacos.naming.core.DistroMapper) SwitchManager(com.alibaba.nacos.naming.misc.SwitchManager) RestController(org.springframework.web.bind.annotation.RestController) UtilsAndCommons(com.alibaba.nacos.naming.misc.UtilsAndCommons) List(java.util.List) Constants(com.alibaba.nacos.api.common.Constants) ActionTypes(com.alibaba.nacos.plugin.auth.constant.ActionTypes) Secured(com.alibaba.nacos.auth.annotation.Secured) NodeState(com.alibaba.nacos.core.cluster.NodeState) Service(com.alibaba.nacos.naming.core.Service) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Member(com.alibaba.nacos.core.cluster.Member) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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