Skip to content

Commit

Permalink
Fix PMD
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Nov 16, 2018
1 parent 625f3a9 commit 46c1419
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 247 deletions.
33 changes: 0 additions & 33 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,4 @@
<scope>test</scope>
</dependency>
</dependencies>

<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/repository</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/repository</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
32 changes: 0 additions & 32 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,36 +131,4 @@
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/repository</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/repository</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
33 changes: 0 additions & 33 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,4 @@
</dependency>

</dependencies>

<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/repository</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/repository</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://mvnrepo.alibaba-inc.com/mvn/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
2 changes: 1 addition & 1 deletion distribution/conf/nacos-logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
<appender-ref ref="async-naming-server"/>
</logger>
<logger name="com.alibaba.nacos.naming.raft" additivity="false">
<level value="DEBUG"/>
<level value="INFO"/>
<appender-ref ref="async-naming-raft"/>
</logger>
<logger name="com.alibaba.nacos.naming.event" additivity="false">
Expand Down
115 changes: 53 additions & 62 deletions naming/src/main/java/com/alibaba/nacos/naming/core/DomainsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,83 +290,74 @@ public void easyAddOrReplaceDom(Domain newDom) throws Exception {

public void easyAddIP4Dom(String domName, List<IpAddress> ips, long timestamp, long term) throws Exception {

try {

VirtualClusterDomain dom = (VirtualClusterDomain) chooseDomMap().get(domName);
if (dom == null) {
throw new IllegalArgumentException("dom doesn't exist: " + domName);
}
VirtualClusterDomain dom = (VirtualClusterDomain) chooseDomMap().get(domName);
if (dom == null) {
throw new IllegalArgumentException("dom doesn't exist: " + domName);
}

// set default port and site info if missing
for (IpAddress ip : ips) {
if (ip.getPort() == 0) {
ip.setPort(dom.getClusterMap().get(ip.getClusterName()).getDefIPPort());
}
// set default port and site info if missing
for (IpAddress ip : ips) {
if (ip.getPort() == 0) {
ip.setPort(dom.getClusterMap().get(ip.getClusterName()).getDefIPPort());
}
}

Datum datum1 = RaftCore.getDatum(UtilsAndCommons.getIPListStoreKey(dom));
String oldJson = StringUtils.EMPTY;

if (datum1 != null) {
oldJson = datum1.value;
}
Datum datum1 = RaftCore.getDatum(UtilsAndCommons.getIPListStoreKey(dom));
String oldJson = StringUtils.EMPTY;

List<IpAddress> ipAddresses;
List<IpAddress> currentIPs = dom.allIPs();
Map<String, IpAddress> map = new ConcurrentHashMap(currentIPs.size());
if (datum1 != null) {
oldJson = datum1.value;
}

for (IpAddress ipAddress : currentIPs) {
map.put(ipAddress.toIPAddr(), ipAddress);
}
List<IpAddress> ipAddresses;
List<IpAddress> currentIPs = dom.allIPs();
Map<String, IpAddress> map = new ConcurrentHashMap(currentIPs.size());

ipAddresses = setValid(oldJson, map);
for (IpAddress ipAddress : currentIPs) {
map.put(ipAddress.toIPAddr(), ipAddress);
}

Map<String, IpAddress> ipAddressMap = new HashMap<String, IpAddress>(ipAddresses.size());
ipAddresses = setValid(oldJson, map);

for (IpAddress ipAddress : ipAddresses) {
ipAddressMap.put(ipAddress.getDatumKey(), ipAddress);
}
Map<String, IpAddress> ipAddressMap = new HashMap<String, IpAddress>(ipAddresses.size());

for (IpAddress ipAddress : ips) {
if (!dom.getClusterMap().containsKey(ipAddress.getClusterName())) {
dom.getClusterMap().put(ipAddress.getClusterName(), new Cluster(ipAddress.getClusterName()));
Loggers.SRV_LOG.warn("cluster: " + ipAddress.getClusterName() + " not found, ip: " + ipAddress.toJSON()
+ ", will create new cluster with default configuration.");
}
for (IpAddress ipAddress : ipAddresses) {
ipAddressMap.put(ipAddress.getDatumKey(), ipAddress);
}

ipAddressMap.put(ipAddress.getDatumKey(), ipAddress);
for (IpAddress ipAddress : ips) {
if (!dom.getClusterMap().containsKey(ipAddress.getClusterName())) {
dom.getClusterMap().put(ipAddress.getClusterName(), new Cluster(ipAddress.getClusterName()));
Loggers.SRV_LOG.warn("cluster: " + ipAddress.getClusterName() + " not found, ip: " + ipAddress.toJSON()
+ ", will create new cluster with default configuration.");
}

if (ipAddressMap.size() <= 0) {
throw new IllegalArgumentException("ip list can not be empty, dom: " + dom.getName() + ", ip list: "
+ JSON.toJSONString(ipAddressMap.values()));
}
ipAddressMap.put(ipAddress.getDatumKey(), ipAddress);
}

// if (timestamp == -1) {
// RaftCore.doSignalPublish(UtilsAndCommons.getIPListStoreKey(dom),
// JSON.toJSONString(ipAddressMap.values()));
// } else {
String key = UtilsAndCommons.getIPListStoreKey(dom);
String value = JSON.toJSONString(ipAddressMap.values());

Datum datum = new Datum();
datum.key = key;
datum.value = value;
datum.timestamp.set(timestamp);

RaftPeer peer = new RaftPeer();
peer.ip = RaftCore.getLeader().ip;
peer.term.set(term);
peer.voteFor = RaftCore.getLeader().voteFor;
peer.heartbeatDueMs = RaftCore.getLeader().heartbeatDueMs;
peer.leaderDueMs = RaftCore.getLeader().leaderDueMs;
peer.state = RaftCore.getLeader().state;

RaftCore.onPublish(datum, peer);
// }
} finally {
// lock.unlock();
if (ipAddressMap.size() <= 0) {
throw new IllegalArgumentException("ip list can not be empty, dom: " + dom.getName() + ", ip list: "
+ JSON.toJSONString(ipAddressMap.values()));
}

String key = UtilsAndCommons.getIPListStoreKey(dom);
String value = JSON.toJSONString(ipAddressMap.values());

Datum datum = new Datum();
datum.key = key;
datum.value = value;
datum.timestamp.set(timestamp);

RaftPeer peer = new RaftPeer();
peer.ip = RaftCore.getLeader().ip;
peer.term.set(term);
peer.voteFor = RaftCore.getLeader().voteFor;
peer.heartbeatDueMs = RaftCore.getLeader().heartbeatDueMs;
peer.leaderDueMs = RaftCore.getLeader().leaderDueMs;
peer.state = RaftCore.getLeader().state;

RaftCore.onPublish(datum, peer);
}

private List<IpAddress> setValid(String oldJson, Map<String, IpAddress> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void process() {
return;
}

Loggers.EVT_LOG.info("[CLIENT-BEAT] processing beat: " + rsInfo.toString());
Loggers.EVT_LOG.debug("[CLIENT-BEAT] processing beat: " + rsInfo.toString());

String ip = rsInfo.getIp();
String clusterName = rsInfo.getCluster();
Expand All @@ -74,7 +74,7 @@ public void process() {
for (IpAddress ipAddress: ipAddresses) {
if (ipAddress.getIp().equals(ip) && ipAddress.getPort() == port) {
processed = true;
Loggers.EVT_LOG.info("[CLIENT-BEAT] refresh beat: " + rsInfo.toString());
Loggers.EVT_LOG.debug("[CLIENT-BEAT] refresh beat: " + rsInfo.toString());
ipAddress.setLastBeat(System.currentTimeMillis());
if (!ipAddress.isMarked()) {
if (!ipAddress.isValid()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ public static void onPublish(Datum datum, RaftPeer source) throws Exception {

notifier.addTask(datum, Notifier.ApplyAction.CHANGE);

Loggers.RAFT.info("data added/updated, key=" + datum.key + ", term: " +
local.term + ", data1:" + RaftCore.datums.get(datum.key) + ", data2:" + datum.value);
Loggers.RAFT.info("data added/updated, key=" + datum.key + ", term: " + local.term);
}

public static void onDelete(JSONObject params) throws Exception {
Expand Down
17 changes: 0 additions & 17 deletions naming/src/main/java/com/alibaba/nacos/naming/web/ApiCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,18 +558,7 @@ public String regService(HttpServletRequest request) throws Exception {

Lock lock = domainsManager.addLock(dom);
Condition condition = domainsManager.addCondtion(dom);

// UtilsAndCommons.RAFT_PUBLISH_EXECUTOR.execute(new Runnable() {
// @Override
// public void run() {
// try {
regDom(request);
// } catch (Exception e) {
// Loggers.SRV_LOG.error("REG-SERIVCE", "register service failed, service:" + dom, e);
// }
// }
// });

try {
lock.lock();
condition.await(5000, TimeUnit.MILLISECONDS);
Expand Down Expand Up @@ -1001,12 +990,6 @@ public void run() {
+ RunningConfig.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/api/onAddIP4Dom";

try {
//
// if (server.equals(NetUtils.localIP())) {
// onAddIP4Dom(MockHttpRequest.buildRequest2(proxyParams));
// return;
// }

HttpClient.asyncHttpPost(url, null, proxyParams, new AsyncCompletionHandler() {
@Override
public Integer onCompleted(Response response) throws Exception {
Expand Down
Loading

0 comments on commit 46c1419

Please sign in to comment.