-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support start up with console only mode: step3 - console read cluster…
….conf to set remote server members. (#13080)
- Loading branch information
1 parent
8de4e36
commit 2894eba
Showing
10 changed files
with
163 additions
and
34 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
console/src/main/java/com/alibaba/nacos/console/cluster/RemoteServerMemberManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 1999-2025 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.console.cluster; | ||
|
||
import com.alibaba.nacos.api.exception.NacosException; | ||
import com.alibaba.nacos.console.handler.impl.remote.EnabledRemoteHandler; | ||
import com.alibaba.nacos.core.cluster.Member; | ||
import com.alibaba.nacos.core.cluster.MemberLookup; | ||
import com.alibaba.nacos.core.cluster.NacosMemberManager; | ||
import com.alibaba.nacos.core.cluster.lookup.LookupFactory; | ||
import com.alibaba.nacos.core.utils.Loggers; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.concurrent.ConcurrentSkipListMap; | ||
|
||
/** | ||
* Nacos remote server members manager. Only working on console mode to keep and update the remote server members. | ||
* | ||
* @author xiweng.yy | ||
*/ | ||
@Service | ||
@EnabledRemoteHandler | ||
public class RemoteServerMemberManager implements NacosMemberManager { | ||
|
||
/** | ||
* Nacos remote servers cluster node list. | ||
*/ | ||
private volatile ConcurrentSkipListMap<String, Member> serverList; | ||
|
||
/** | ||
* Addressing pattern instances. | ||
*/ | ||
private MemberLookup lookup; | ||
|
||
public RemoteServerMemberManager() { | ||
this.serverList = new ConcurrentSkipListMap<>(); | ||
} | ||
|
||
@PostConstruct | ||
public void init() throws NacosException { | ||
initAndStartLookup(); | ||
} | ||
|
||
private void initAndStartLookup() throws NacosException { | ||
this.lookup = LookupFactory.createLookUp(); | ||
this.lookup.injectMemberManager(this); | ||
this.lookup.start(); | ||
} | ||
|
||
@Override | ||
public synchronized boolean memberChange(Collection<Member> members) { | ||
ConcurrentSkipListMap<String, Member> newServerList = new ConcurrentSkipListMap<>(); | ||
for (Member each : members) { | ||
newServerList.put(each.getAddress(), each); | ||
} | ||
Loggers.CLUSTER.info("[serverlist] nacos remote server members changed to : {}", newServerList); | ||
this.serverList = newServerList; | ||
return true; | ||
} | ||
|
||
@Override | ||
public Collection<Member> allMembers() { | ||
return new HashSet<>(serverList.values()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
core/src/main/java/com/alibaba/nacos/core/cluster/NacosMemberManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 1999-2025 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.core.cluster; | ||
|
||
import com.alibaba.nacos.core.cluster.lookup.AbstractMemberLookup; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Nacos member managers. | ||
* | ||
* @author xiweng.yy | ||
*/ | ||
public interface NacosMemberManager { | ||
|
||
/** | ||
* Nacos members changed, called in {@link AbstractMemberLookup#afterLookup(Collection)}. | ||
* | ||
* @param members new members | ||
* @return {@code true} if changed, {@code false} otherwise | ||
*/ | ||
boolean memberChange(Collection<Member> members); | ||
|
||
/** | ||
* Get all members. | ||
* | ||
* @return {@link Collection} all member | ||
*/ | ||
Collection<Member> allMembers(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters