Skip to content

Commit

Permalink
#502 Fix bean inject error
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Jan 17, 2019
1 parent 7fa9c3a commit 806e703
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 113 deletions.
16 changes: 16 additions & 0 deletions console/src/main/resources/META-INF/nacos-default.properties
Expand Up @@ -46,3 +46,19 @@ db.password=4b9622f3f70c7677835ac5a6719e7caf
#security.basic.enabled=false
#nacos.security.ignore.urls=/**
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health,/v1/cs/**,/v1/ns/**,/v1/cmdb/**

management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200

# metrics for influx
management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
#management.metrics.export.influx.uri=http://localhost:8086
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true

server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
Expand Up @@ -16,11 +16,9 @@
package com.alibaba.nacos.naming.consistency;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.naming.consistency.ephemeral.ApConsistencyService;
import com.alibaba.nacos.naming.consistency.persistent.CpConsistencyService;
import com.alibaba.nacos.naming.consistency.ephemeral.EphemeralConsistencyService;
import com.alibaba.nacos.naming.consistency.persistent.PersistentConsistencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
Expand All @@ -33,39 +31,39 @@
public class DelegateConsistencyServiceImpl implements ConsistencyService {

@Autowired
private CpConsistencyService cpConsistencyService;
private PersistentConsistencyService persistentConsistencyService;

@Autowired
private ApConsistencyService apConsistencyService;
private EphemeralConsistencyService ephemeralConsistencyService;

@Override
public void put(Object key, Object value) throws NacosException {

persistentConsistencyService.put(key, value);
}

@Override
public void remove(Object key) throws NacosException {

persistentConsistencyService.remove(key);
}

@Override
public Object get(Object key) throws NacosException {
return null;
return persistentConsistencyService.get(key);
}

@Override
public void listen(Object key, DataListener listener) throws NacosException {

persistentConsistencyService.listen(key, listener);
}

@Override
public void unlisten(Object key, DataListener listener) throws NacosException {

persistentConsistencyService.unlisten(key, listener);
}

@Override
public boolean isResponsible(Object key) {
return false;
return true;
}

@Override
Expand Down
Expand Up @@ -21,5 +21,5 @@
* @author <a href="mailto:zpf.073@gmail.com">nkorange</a>
* @since 1.0.0
*/
public interface ApConsistencyService extends ConsistencyService {
public interface EphemeralConsistencyService extends ConsistencyService {
}

This file was deleted.

@@ -0,0 +1,63 @@
/*
* Copyright 1999-2018 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.naming.consistency.ephemeral.partialrenew;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.naming.consistency.DataListener;
import com.alibaba.nacos.naming.consistency.ephemeral.EphemeralConsistencyService;
import org.springframework.stereotype.Component;

/**
* @author <a href="mailto:zpf.073@gmail.com">nkorange</a>
*/
@Component
public class RenewConsistencyServiceImpl implements EphemeralConsistencyService {

@Override
public void put(Object key, Object value) throws NacosException {

}

@Override
public void remove(Object key) throws NacosException {

}

@Override
public Object get(Object key) throws NacosException {
return null;
}

@Override
public void listen(Object key, DataListener listener) throws NacosException {

}

@Override
public void unlisten(Object key, DataListener listener) throws NacosException {

}

@Override
public boolean isResponsible(Object key) {
return false;
}

@Override
public String getResponsibleServer(Object key) {
return null;
}
}
Expand Up @@ -29,5 +29,5 @@
* @author <a href="mailto:zpf.073@gmail.com">nkorange</a>
* @since 1.0.0
*/
public interface CpConsistencyService extends ConsistencyService {
public interface PersistentConsistencyService extends ConsistencyService {
}
Expand Up @@ -2,7 +2,7 @@

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.naming.consistency.DataListener;
import com.alibaba.nacos.naming.consistency.persistent.CpConsistencyService;
import com.alibaba.nacos.naming.consistency.persistent.PersistentConsistencyService;
import com.alibaba.nacos.naming.misc.Loggers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -14,7 +14,7 @@
* @since 1.0.0
*/
@Component
public class RaftConsistencyServiceImpl implements CpConsistencyService {
public class RaftConsistencyServiceImpl implements PersistentConsistencyService {

@Autowired
private RaftCore raftCore;
Expand Down
Expand Up @@ -639,19 +639,19 @@ public RaftPeer receivedBeat(JSONObject beat) throws Exception {
String key = entry.getString("key");
final String datumKey;

if (key.startsWith(UtilsAndCommons.RAFT_DOM_PRE)) {
int index = key.indexOf(UtilsAndCommons.RAFT_DOM_PRE);
datumKey = UtilsAndCommons.DOMAINS_DATA_ID_PRE + key.substring(index + UtilsAndCommons.RAFT_DOM_PRE.length());
} else if (key.startsWith(UtilsAndCommons.RAFT_IPLIST_PRE)) {
int index = key.indexOf(UtilsAndCommons.RAFT_IPLIST_PRE);
datumKey = UtilsAndCommons.IPADDRESS_DATA_ID_PRE + key.substring(index + UtilsAndCommons.RAFT_IPLIST_PRE.length());
} else if (key.startsWith(UtilsAndCommons.RAFT_TAG_DOM_PRE)) {
int index = key.indexOf(UtilsAndCommons.RAFT_TAG_DOM_PRE);
datumKey = UtilsAndCommons.TAG_DOMAINS_DATA_ID + key.substring(index + UtilsAndCommons.RAFT_TAG_DOM_PRE.length());
} else {
int index = key.indexOf(UtilsAndCommons.RAFT_TAG_IPLIST_PRE);
datumKey = UtilsAndCommons.NODE_TAG_IP_PRE + key.substring(index + UtilsAndCommons.RAFT_TAG_IPLIST_PRE.length());
}
if (key.startsWith(UtilsAndCommons.RAFT_DOM_PRE)) {
int index = key.indexOf(UtilsAndCommons.RAFT_DOM_PRE);
datumKey = UtilsAndCommons.DOMAINS_DATA_ID_PRE + key.substring(index + UtilsAndCommons.RAFT_DOM_PRE.length());
} else if (key.startsWith(UtilsAndCommons.RAFT_IPLIST_PRE)) {
int index = key.indexOf(UtilsAndCommons.RAFT_IPLIST_PRE);
datumKey = UtilsAndCommons.IPADDRESS_DATA_ID_PRE + key.substring(index + UtilsAndCommons.RAFT_IPLIST_PRE.length());
} else if (key.startsWith(UtilsAndCommons.RAFT_TAG_DOM_PRE)) {
int index = key.indexOf(UtilsAndCommons.RAFT_TAG_DOM_PRE);
datumKey = UtilsAndCommons.TAG_DOMAINS_DATA_ID + key.substring(index + UtilsAndCommons.RAFT_TAG_DOM_PRE.length());
} else {
int index = key.indexOf(UtilsAndCommons.RAFT_TAG_IPLIST_PRE);
datumKey = UtilsAndCommons.NODE_TAG_IP_PRE + key.substring(index + UtilsAndCommons.RAFT_TAG_IPLIST_PRE.length());
}

long timestamp = entry.getLong("timestamp");

Expand Down Expand Up @@ -703,21 +703,21 @@ public Integer onCompleted(Response response) throws Exception {
continue;
}

if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE) ||
UtilsAndCommons.INSTANCE_LIST_PERSISTED) {
RaftStore.write(datum);
}
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE) ||
UtilsAndCommons.INSTANCE_LIST_PERSISTED) {
RaftStore.write(datum);
}

datums.put(datum.key, datum);
local.resetLeaderDue();

if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
if (local.term.get() + 100 > remote.term.get()) {
getLeader().term.set(remote.term.get());
local.term.set(getLeader().term.get());
} else {
local.term.addAndGet(100);
}
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
if (local.term.get() + 100 > remote.term.get()) {
getLeader().term.set(remote.term.get());
local.term.set(getLeader().term.get());
} else {
local.term.addAndGet(100);
}

raftStore.updateTerm(local.term.get());
}
Expand Down Expand Up @@ -949,7 +949,8 @@ public void run() {

int count = 0;

if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
if (datum.key.startsWith(UtilsAndCommons.DOMAINS_DATA_ID_PRE) &&
listeners.containsKey(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {

for (DataListener listener : listeners.get(UtilsAndCommons.DOMAINS_DATA_ID_PRE)) {
try {
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.*;
Expand Down Expand Up @@ -89,7 +90,8 @@ public Thread newThread(Runnable r) {
}
});

public ServiceManager() throws NacosException {
@PostConstruct
public void init() {
// wait until distro-mapper ready because domain distribution check depends on it
// TODO may be not necessary:
while (distroMapper.getLiveSites().size() == 0) {
Expand All @@ -103,7 +105,12 @@ public ServiceManager() throws NacosException {

UtilsAndCommons.DOMAIN_UPDATE_EXECUTOR.submit(new UpdatedDomainProcessor());

consistencyService.listen(UtilsAndCommons.DOMAINS_DATA_ID_PRE, this);
try {
Loggers.SRV_LOG.info("listen for {}", UtilsAndCommons.DOMAINS_DATA_ID_PRE);
consistencyService.listen(UtilsAndCommons.DOMAINS_DATA_ID_PRE, this);
} catch (NacosException e) {
Loggers.SRV_LOG.error("listen for {} failed!", UtilsAndCommons.DOMAINS_DATA_ID_PRE);
}
}

public Map<String, VirtualClusterDomain> chooseDomMap(String namespaceId) {
Expand Down Expand Up @@ -366,7 +373,7 @@ public void addOrReplaceService(VirtualClusterDomain newDom) throws Exception {
*/
public void registerInstance(String namespaceId, String serviceName, IpAddress instance) throws Exception {

VirtualClusterDomain service = (VirtualClusterDomain) getService(namespaceId, serviceName);
VirtualClusterDomain service = getService(namespaceId, serviceName);

boolean serviceUpdated = false;
if (service == null) {
Expand Down
Expand Up @@ -83,7 +83,9 @@ public class VirtualClusterDomain implements Domain, DataListener {
private Map<String, String> metadata = new ConcurrentHashMap<>();

@JSONField(serialize = false)
private PushService pushService;
public PushService getPushService() {
return SpringContext.getAppContext().getBean(PushService.class);
}

public long getIpDeleteTimeout() {
return ipDeleteTimeout;
Expand Down Expand Up @@ -155,10 +157,6 @@ public void setSelector(Selector selector) {
this.selector = selector;
}

public VirtualClusterDomain() {
pushService = SpringContext.getAppContext().getBean(PushService.class);
}

@Override
public boolean interests(String key) {
return StringUtils.equals(key, UtilsAndCommons.IPADDRESS_DATA_ID_PRE + namespaceId + UtilsAndCommons.SERVICE_GROUP_CONNECTOR + name);
Expand Down Expand Up @@ -249,7 +247,7 @@ public void updateIPs(List<IpAddress> ips) {
clusterMap.get(entry.getKey()).updateIPs(entryIPs);
}
setLastModifiedMillis(System.currentTimeMillis());
pushService.domChanged(namespaceId, name);
getPushService().domChanged(namespaceId, name);
StringBuilder stringBuilder = new StringBuilder();

for (IpAddress ipAddress : allIPs()) {
Expand Down Expand Up @@ -536,7 +534,7 @@ public synchronized void recalculateChecksum() {

for (IpAddress ip : ips) {
String string = ip.getIp() + ":" + ip.getPort() + "_" + ip.getWeight() + "_"
+ ip.isValid() + "_" + ip.getClusterName();
+ ip.isValid() + "_" + ip.getClusterName();
ipsString.append(string);
ipsString.append(",");
}
Expand Down

0 comments on commit 806e703

Please sign in to comment.