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);
}
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);
}
}
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);
}
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();
}
}
Aggregations