Search in sources :

Example 1 with ServerMemberManager

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

the class LookupFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    when(servletContext.getContextPath()).thenReturn("");
    EnvUtil.setEnvironment(new StandardEnvironment());
    memberManager = new ServerMemberManager(servletContext);
}
Also used : ServerMemberManager(com.alibaba.nacos.core.cluster.ServerMemberManager) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Before(org.junit.Before)

Example 2 with ServerMemberManager

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

the class JRaftUtils method joinCluster.

public static void joinCluster(CliService cliService, Collection<String> members, Configuration conf, String group, PeerId self) {
    ServerMemberManager memberManager = ApplicationUtils.getBean(ServerMemberManager.class);
    if (!memberManager.isFirstIp()) {
        return;
    }
    Set<PeerId> peerIds = new HashSet<>();
    for (String s : members) {
        peerIds.add(PeerId.parsePeer(s));
    }
    peerIds.remove(self);
    for (; ; ) {
        if (peerIds.isEmpty()) {
            return;
        }
        conf = RouteTable.getInstance().getConfiguration(group);
        Iterator<PeerId> iterator = peerIds.iterator();
        while (iterator.hasNext()) {
            final PeerId peerId = iterator.next();
            if (conf.contains(peerId)) {
                iterator.remove();
                continue;
            }
            Status status = cliService.addPeer(group, conf, peerId);
            if (status.isOk()) {
                iterator.remove();
            }
        }
        ThreadUtils.sleep(1000L);
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) ServerMemberManager(com.alibaba.nacos.core.cluster.ServerMemberManager) PeerId(com.alipay.sofa.jraft.entity.PeerId) HashSet(java.util.HashSet)

Example 3 with ServerMemberManager

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

the class ClusterVersionJudgementTest method beforeMethod.

@Before
public void beforeMethod() throws Exception {
    manager = new ServerMemberManager(new MockServletContext());
    newVersionMeta = new HashMap<>(4);
    newVersionMeta.put(MemberMetaDataConstants.VERSION, newVersion);
    oldVersionMeta = new HashMap<>(4);
    oldVersionMeta.put(MemberMetaDataConstants.VERSION, oldVersion);
    ipList = new String[ipCount];
    ipList[0] = ip1;
    ipList[1] = ip2;
    ipList[2] = ip3;
    members = new LinkedList<>();
    members.add(Member.builder().ip(ipList[0]).port(defalutPort).state(NodeState.UP).build());
    members.add(Member.builder().ip(ipList[1]).port(defalutPort).state(NodeState.UP).build());
    members.add(Member.builder().ip(ipList[2]).port(defalutPort).state(NodeState.UP).build());
    manager.memberJoin(members);
}
Also used : ServerMemberManager(com.alibaba.nacos.core.cluster.ServerMemberManager) MockServletContext(org.springframework.mock.web.MockServletContext) Before(org.junit.Before)

Example 4 with ServerMemberManager

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

the class MemberLookup_ITCase method before.

@Before
public void before() throws Exception {
    System.setProperty("nacos.home", path);
    EnvUtil.setEnvironment(new StandardEnvironment());
    EnvUtil.setIsStandalone(false);
    System.out.println(EnvUtil.getStandaloneMode());
    System.out.println(Arrays.toString(LookupFactory.LookupType.values()));
    DiskUtils.forceMkdir(path);
    DiskUtils.forceMkdir(Paths.get(path, "conf").toString());
    File file = Paths.get(path, "conf", name).toFile();
    DiskUtils.touch(file);
    String ip = InetUtils.getSelfIP();
    DiskUtils.writeFile(file, (ip + ":8848," + ip + ":8847," + ip + ":8849").getBytes(StandardCharsets.UTF_8), false);
    try {
        memberManager = new ServerMemberManager(new MockServletContext());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ServerMemberManager(com.alibaba.nacos.core.cluster.ServerMemberManager) File(java.io.File) MockServletContext(org.springframework.mock.web.MockServletContext) NacosException(com.alibaba.nacos.api.exception.NacosException) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Before(org.junit.Before)

Aggregations

ServerMemberManager (com.alibaba.nacos.core.cluster.ServerMemberManager)4 Before (org.junit.Before)3 StandardEnvironment (org.springframework.core.env.StandardEnvironment)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 Status (com.alipay.sofa.jraft.Status)1 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 File (java.io.File)1 HashSet (java.util.HashSet)1