commit
e05bc7a682
18
api/pom.xml
18
api/pom.xml
@ -16,7 +16,8 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -32,10 +33,25 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public AppTest( String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( AppTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
@ -16,7 +16,8 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -32,67 +33,46 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.8.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -114,11 +94,19 @@
|
||||
<artifactId>jcip-annotations</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-annotations</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -15,16 +15,15 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.logger;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.alibaba.nacos.client.logger.log4j.Log4jLoggerFactory;
|
||||
import com.alibaba.nacos.client.logger.log4j2.Log4j2LoggerFactory;
|
||||
import com.alibaba.nacos.client.logger.nop.NopLoggerFactory;
|
||||
import com.alibaba.nacos.client.logger.slf4j.Slf4jLoggerFactory;
|
||||
import com.alibaba.nacos.client.logger.support.ILoggerFactory;
|
||||
import com.alibaba.nacos.client.logger.support.LogLog;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 阿里中间件LoggerFactory,获取具体日志实现
|
||||
@ -56,20 +55,15 @@ public class LoggerFactory {
|
||||
setLoggerFactory(new Slf4jLoggerFactory());
|
||||
LogLog.info("Init JM logger with Slf4jLoggerFactory success, " + LoggerFactory.class.getClassLoader());
|
||||
} catch (Throwable e1) {
|
||||
try {
|
||||
setLoggerFactory(new Log4jLoggerFactory());
|
||||
LogLog.info("Init JM logger with Log4jLoggerFactory, " + LoggerFactory.class.getClassLoader());
|
||||
} catch (Throwable e2) {
|
||||
try {
|
||||
setLoggerFactory(new Log4j2LoggerFactory());
|
||||
LogLog.info("Init JM logger with Log4j2LoggerFactory, " + LoggerFactory.class.getClassLoader());
|
||||
} catch (Throwable e3) {
|
||||
} catch (Throwable e2) {
|
||||
setLoggerFactory(new NopLoggerFactory());
|
||||
LogLog.warn("Init JM logger with NopLoggerFactory, pay attention. "
|
||||
+ LoggerFactory.class.getClassLoader(), e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loggerCache = new ConcurrentHashMap<String, Logger>();
|
||||
}
|
||||
|
@ -1,146 +0,0 @@
|
||||
/*
|
||||
* 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.client.logger.log4j;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
import com.alibaba.nacos.client.logger.Logger;
|
||||
import com.alibaba.nacos.client.logger.option.Log4jActivateOption;
|
||||
import com.alibaba.nacos.client.logger.support.LoggerHelper;
|
||||
import com.alibaba.nacos.client.logger.support.LoggerSupport;
|
||||
import com.alibaba.nacos.client.logger.util.MessageUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Log4jLogger
|
||||
* @author Nacos
|
||||
*
|
||||
*/
|
||||
public class Log4jLogger extends LoggerSupport implements Logger {
|
||||
|
||||
private org.apache.log4j.Logger delegate;
|
||||
|
||||
public Log4jLogger(org.apache.log4j.Logger delegate) {
|
||||
super(delegate);
|
||||
|
||||
if (delegate == null) {
|
||||
throw new IllegalArgumentException("delegate Logger is null");
|
||||
}
|
||||
this.delegate = delegate;
|
||||
|
||||
this.activateOption = new Log4jActivateOption(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String context, String message) {
|
||||
if (isDebugEnabled()) {
|
||||
message = LoggerHelper.getResourceBundleString(getProductName(), message);
|
||||
delegate.debug(MessageUtil.getMessage(context, message));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String context, String format, Object... args) {
|
||||
if (isDebugEnabled()) {
|
||||
format = LoggerHelper.getResourceBundleString(getProductName(), format);
|
||||
delegate.debug(MessageUtil.getMessage(context, MessageUtil.formatMessage(format, args)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String context, String message) {
|
||||
if (isInfoEnabled()) {
|
||||
message = LoggerHelper.getResourceBundleString(getProductName(), message);
|
||||
delegate.info(MessageUtil.getMessage(context, message));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String context, String format, Object... args) {
|
||||
if (isInfoEnabled()) {
|
||||
format = LoggerHelper.getResourceBundleString(getProductName(), format);
|
||||
delegate.info(MessageUtil.getMessage(context, MessageUtil.formatMessage(format, args)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message, Throwable t) {
|
||||
if (isWarnEnabled()) {
|
||||
message = LoggerHelper.getResourceBundleString(getProductName(), message);
|
||||
delegate.warn(MessageUtil.getMessage(null, message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String context, String message) {
|
||||
if (isWarnEnabled()) {
|
||||
message = LoggerHelper.getResourceBundleString(getProductName(), message);
|
||||
delegate.warn(MessageUtil.getMessage(context, message));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String context, String format, Object... args) {
|
||||
if (isWarnEnabled()) {
|
||||
format = LoggerHelper.getResourceBundleString(getProductName(), format);
|
||||
delegate.warn(MessageUtil.getMessage(context, MessageUtil.formatMessage(format, args)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String context, String errorCode, String message) {
|
||||
if (isErrorEnabled()) {
|
||||
message = LoggerHelper.getResourceBundleString(getProductName(), message);
|
||||
delegate.error(MessageUtil.getMessage(context, errorCode, message));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String context, String errorCode, String message, Throwable t) {
|
||||
if (isErrorEnabled()) {
|
||||
message = LoggerHelper.getResourceBundleString(getProductName(), message);
|
||||
delegate.error(MessageUtil.getMessage(context, errorCode, message), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String context, String errorCode, String format, Object... args) {
|
||||
if (isErrorEnabled()) {
|
||||
format = LoggerHelper.getResourceBundleString(getProductName(), format);
|
||||
delegate.error(MessageUtil.getMessage(context, errorCode, MessageUtil.formatMessage(format, args)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return delegate.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return delegate.isInfoEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnabled() {
|
||||
return delegate.isEnabledFor(Level.WARN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnabled() {
|
||||
return delegate.isEnabledFor(Level.ERROR);
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 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.client.logger.log4j;
|
||||
|
||||
import org.apache.log4j.LogManager;
|
||||
|
||||
import com.alibaba.nacos.client.logger.Logger;
|
||||
import com.alibaba.nacos.client.logger.nop.NopLogger;
|
||||
import com.alibaba.nacos.client.logger.support.ILoggerFactory;
|
||||
import com.alibaba.nacos.client.logger.support.LogLog;
|
||||
|
||||
/**
|
||||
* Log4jLogger Factory
|
||||
* @author Nacos
|
||||
*
|
||||
*/
|
||||
public class Log4jLoggerFactory implements ILoggerFactory {
|
||||
|
||||
public Log4jLoggerFactory() throws ClassNotFoundException {
|
||||
Class.forName("org.apache.log4j.Level");
|
||||
}
|
||||
|
||||
public Logger getLogger(Class<?> clazz) {
|
||||
try {
|
||||
return new Log4jLogger(LogManager.getLogger(clazz));
|
||||
} catch (Throwable t) {
|
||||
LogLog.error("Failed to get Log4jLogger", t);
|
||||
return new NopLogger();
|
||||
}
|
||||
}
|
||||
|
||||
public Logger getLogger(String name) {
|
||||
try {
|
||||
return new Log4jLogger(LogManager.getLogger(name));
|
||||
} catch (Throwable t) {
|
||||
LogLog.error("Failed to get Log4jLogger", t);
|
||||
return new NopLogger();
|
||||
}
|
||||
}
|
||||
}
|
@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.logger.option;
|
||||
|
||||
import org.apache.log4j.AsyncAppender;
|
||||
|
||||
import com.alibaba.nacos.client.logger.Level;
|
||||
import com.alibaba.nacos.client.logger.support.LogLog;
|
||||
|
||||
|
@ -1,212 +0,0 @@
|
||||
/*
|
||||
* 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.client.logger.option;
|
||||
|
||||
import org.apache.log4j.*;
|
||||
|
||||
import com.alibaba.nacos.client.logger.Logger;
|
||||
import com.alibaba.nacos.client.logger.support.LoggerHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ActivateOption的Log4j实现
|
||||
*
|
||||
* @author zhuyong 2014年3月20日 上午10:24:36
|
||||
*/
|
||||
public class Log4jActivateOption extends AbstractActiveOption {
|
||||
|
||||
protected org.apache.log4j.Logger logger;
|
||||
|
||||
public Log4jActivateOption(org.apache.log4j.Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateConsoleAppender(String target, String encoding) {
|
||||
org.apache.log4j.ConsoleAppender appender = new org.apache.log4j.ConsoleAppender();
|
||||
appender.setLayout(new PatternLayout(LoggerHelper.getPattern()));
|
||||
appender.setTarget(target);
|
||||
appender.setEncoding(encoding);
|
||||
appender.activateOptions();
|
||||
|
||||
logger.removeAllAppenders();
|
||||
logger.addAppender(appender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAppender(String productName, String file, String encoding) {
|
||||
org.apache.log4j.Appender appender = getLog4jDailyRollingFileAppender(productName, file, encoding);
|
||||
logger.removeAllAppenders();
|
||||
logger.addAppender(appender);
|
||||
|
||||
setProductName(productName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAsyncAppender(String productName, String file, String encoding) {
|
||||
activateAsyncAppender(productName, file, encoding, Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAsyncAppender(String productName, String file, String encoding, int queueSize,
|
||||
int discardingThreshold) {
|
||||
activateAppender(productName, file, encoding);
|
||||
activateAsync(queueSize, discardingThreshold);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAppenderWithTimeAndSizeRolling(String productName, String file, String encoding, String size) {
|
||||
activateAppender(productName, file, encoding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevel(com.alibaba.nacos.client.logger.Level level) {
|
||||
this.level = level;
|
||||
logger.setLevel(org.apache.log4j.Level.toLevel(level.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdditivity(boolean additivity) {
|
||||
logger.setAdditivity(additivity);
|
||||
}
|
||||
|
||||
protected org.apache.log4j.Appender getLog4jDailyRollingFileAppender(String productName, String file,
|
||||
String encoding) {
|
||||
DailyRollingFileAppender appender = new DailyRollingFileAppender();
|
||||
appender.setName(productName + "." + file.replace(File.separatorChar, '.') + ".Appender");
|
||||
appender.setLayout(new PatternLayout(LoggerHelper.getPattern(productName)));
|
||||
appender.setAppend(true);
|
||||
appender.setFile(LoggerHelper.getLogFileP(productName, file));
|
||||
appender.setEncoding(encoding);
|
||||
appender.activateOptions();
|
||||
|
||||
return appender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAppender(Logger logger) {
|
||||
if (!(logger.getDelegate() instanceof org.apache.log4j.Logger)) {
|
||||
throw new IllegalArgumentException(
|
||||
"logger must be org.apache.log4j.Logger, but it's " + logger.getDelegate().getClass());
|
||||
}
|
||||
activateAppender((org.apache.log4j.Logger) logger.getDelegate());
|
||||
|
||||
setProductName(logger.getProductName());
|
||||
}
|
||||
|
||||
protected void activateAppender(org.apache.log4j.Logger logger) {
|
||||
this.logger.removeAllAppenders();
|
||||
|
||||
Enumeration<?> enums = logger.getAllAppenders();
|
||||
while (enums != null && enums.hasMoreElements()) {
|
||||
this.logger.addAppender((Appender) enums.nextElement());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAppenderWithTimeAndSizeRolling(String productName, String file, String encoding, String size,
|
||||
String datePattern) {
|
||||
Appender appender = getLog4jRollingFileAppender(productName, file, encoding, size, datePattern, -1);
|
||||
|
||||
logger.removeAllAppenders();
|
||||
logger.addAppender(appender);
|
||||
|
||||
setProductName(productName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAppenderWithTimeAndSizeRolling(String productName, String file, String encoding, String size,
|
||||
String datePattern, int maxBackupIndex) {
|
||||
Appender appender = getLog4jRollingFileAppender(productName, file, encoding, size, datePattern, maxBackupIndex);
|
||||
logger.removeAllAppenders();
|
||||
logger.addAppender(appender);
|
||||
|
||||
setProductName(productName);
|
||||
}
|
||||
|
||||
protected org.apache.log4j.Appender getLog4jRollingFileAppender(String productName, String file, String encoding,
|
||||
String size, String datePattern,
|
||||
int maxBackupIndex) {
|
||||
RollingFileAppender appender = new RollingFileAppender();
|
||||
appender.setName(productName + "." + file.replace(File.separatorChar, '.') + ".Appender");
|
||||
appender.setLayout(new PatternLayout(LoggerHelper.getPattern(productName)));
|
||||
appender.setAppend(true);
|
||||
appender.setFile(LoggerHelper.getLogFileP(productName, file));
|
||||
appender.setEncoding(encoding);
|
||||
appender.setMaxFileSize(size);
|
||||
if (maxBackupIndex >= 0) {
|
||||
// 等于0表示直接truck
|
||||
appender.setMaxBackupIndex(maxBackupIndex);
|
||||
}
|
||||
appender.activateOptions();
|
||||
|
||||
return appender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAppenderWithSizeRolling(String productName, String file, String encoding, String size,
|
||||
int maxBackupIndex) {
|
||||
Appender appender = getLog4jRollingFileAppender(productName, file, encoding, size, null, maxBackupIndex);
|
||||
logger.removeAllAppenders();
|
||||
logger.addAppender(appender);
|
||||
|
||||
setProductName(productName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAsync(int queueSize, int discardingThreshold) {
|
||||
// discardingThreshold is unused for log4j
|
||||
List<Object[]> args = new ArrayList<Object[]>();
|
||||
|
||||
if (queueSize != Integer.MIN_VALUE) {
|
||||
args.add(new Object[] { "setBufferSize", new Class<?>[] { int.class }, queueSize });
|
||||
}
|
||||
activateAsync(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activateAsync(List<Object[]> args) {
|
||||
AsyncAppender asyncAppender = new AsyncAppender();
|
||||
|
||||
invokeMethod(asyncAppender, args);
|
||||
|
||||
asyncAppender.setName(productName + "." + logger.getName() + ".AsyncAppender");
|
||||
Enumeration<Appender> appenders = logger.getAllAppenders();
|
||||
|
||||
if (appenders == null) {
|
||||
throw new IllegalStateException("Activate async appender failed, no appender exist.");
|
||||
}
|
||||
|
||||
while (appenders.hasMoreElements()) {
|
||||
asyncAppender.addAppender(appenders.nextElement());
|
||||
}
|
||||
|
||||
appenders = logger.getAllAppenders();
|
||||
while (appenders.hasMoreElements()) {
|
||||
logger.removeAppender(appenders.nextElement());
|
||||
}
|
||||
|
||||
logger.addAppender(asyncAppender);
|
||||
|
||||
setProductName(productName);
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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.client.logger.option;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.alibaba.nacos.client.logger.Logger;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
/**
|
||||
* Slf4j-log4j12架构下的ActivateOption实现
|
||||
*
|
||||
* @author zhuyong 2014年3月20日 上午10:26:04
|
||||
*/
|
||||
public class Slf4jLog4jAdapterActivateOption extends Log4jActivateOption {
|
||||
|
||||
private static Field loggerField = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
loggerField = org.slf4j.impl.Log4jLoggerAdapter.class.getDeclaredField("logger");
|
||||
loggerField.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("logger must be instanceof org.slf4j.impl.Log4jLoggerAdapter", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Slf4jLog4jAdapterActivateOption(Object logger) {
|
||||
super(null);
|
||||
|
||||
try {
|
||||
org.apache.log4j.Logger log4jLogger = (org.apache.log4j.Logger) loggerField.get(logger);
|
||||
super.logger = log4jLogger;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("logger must be instanceof org.slf4j.impl.Log4jLoggerAdapter", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressFBWarnings("NM_WRONG_PACKAGE")
|
||||
public void activateAppender(Logger logger) {
|
||||
if (!(logger.getDelegate() instanceof org.slf4j.impl.Log4jLoggerAdapter)) {
|
||||
throw new IllegalArgumentException(
|
||||
"logger must be org.slf4j.impl.Log4jLoggerAdapter, but it's "
|
||||
+ logger.getDelegate().getClass());
|
||||
}
|
||||
|
||||
try {
|
||||
org.apache.log4j.Logger log4jLogger =
|
||||
(org.apache.log4j.Logger) loggerField.get(logger.getDelegate());
|
||||
super.activateAppender(log4jLogger);
|
||||
setProductName(logger.getProductName());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("activateAppender error, ", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,24 +15,25 @@
|
||||
*/
|
||||
package com.alibaba.nacos.client.logger.slf4j;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import com.alibaba.nacos.client.logger.Logger;
|
||||
import com.alibaba.nacos.client.logger.option.ActivateOption;
|
||||
import com.alibaba.nacos.client.logger.support.LoggerHelper;
|
||||
import com.alibaba.nacos.client.logger.support.LoggerSupport;
|
||||
import com.alibaba.nacos.client.logger.util.MessageUtil;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
* slf4j logger
|
||||
* @author Nacos
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class Slf4jLogger extends LoggerSupport implements Logger {
|
||||
|
||||
private static boolean CanUseEncoder = false;
|
||||
private static final String LOGBACK_CLASSNAME = "ch.qos.logback.classic.Logger";
|
||||
private static final String SLF4J_CLASSNAME = "org.slf4j.impl.Log4jLoggerAdapter";
|
||||
private static final String SLF4JLOG4J_CLASSNAME = "org.apache.logging.slf4j.Log4jLogger";
|
||||
|
||||
static {
|
||||
try {
|
||||
// logback从0.9.19开始采用encoder,@see http://logback.qos.ch/manual/encoders.html
|
||||
@ -46,8 +47,7 @@ public class Slf4jLogger extends LoggerSupport implements Logger {
|
||||
private org.slf4j.Logger delegate;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public
|
||||
Slf4jLogger(org.slf4j.Logger delegate){
|
||||
public Slf4jLogger(org.slf4j.Logger delegate) {
|
||||
super(delegate);
|
||||
if (delegate == null) {
|
||||
throw new IllegalArgumentException("delegate Logger is null");
|
||||
@ -61,8 +61,6 @@ public class Slf4jLogger extends LoggerSupport implements Logger {
|
||||
} else {
|
||||
activateOptionClass = "com.alibaba.nacos.client.logger.option.Logback918ActivateOption";
|
||||
}
|
||||
} else if (SLF4J_CLASSNAME.equals(delegate.getClass().getName())) {
|
||||
activateOptionClass = "com.alibaba.nacos.client.logger.option.Slf4jLog4jAdapterActivateOption";
|
||||
} else if (SLF4JLOG4J_CLASSNAME.equals(delegate.getClass().getName())) {
|
||||
activateOptionClass = "com.alibaba.nacos.client.logger.option.Slf4jLog4j2AdapterActivateOption";
|
||||
}
|
||||
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2014 Alibaba.com All right reserved. This software is the
|
||||
* confidential and proprietary information of Alibaba.com ("Confidential
|
||||
* Information"). You shall not disclose such Confidential Information and shall
|
||||
* use it only in accordance with the terms of the license agreement you entered
|
||||
* into with Alibaba.com.
|
||||
*/
|
||||
package com.alibaba.nacos.client.logger.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.log4j.spi.ThrowableRenderer;
|
||||
|
||||
/**
|
||||
* 针对 Log4j 1.2.16 及以上版本,提供对异常栈的深度控制
|
||||
*
|
||||
* @author zhuyong 2014年9月19日 上午10:31:48
|
||||
*/
|
||||
public final class DepthThrowableRenderer implements ThrowableRenderer {
|
||||
|
||||
private int depth = -1;
|
||||
|
||||
public DepthThrowableRenderer(int depth) {
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public void setDepth(int depth) {
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public String[] doRender(final Throwable throwable) {
|
||||
return render(throwable, depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render throwable using Throwable.printStackTrace.
|
||||
*
|
||||
* @param throwable throwable, may not be null.
|
||||
* @param depth stack depth
|
||||
* @return string representation.
|
||||
*/
|
||||
public static String[] render(final Throwable throwable, final int depth) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
try {
|
||||
throwable.printStackTrace(pw);
|
||||
} catch (RuntimeException ex) {
|
||||
}
|
||||
pw.flush();
|
||||
LineNumberReader reader = new LineNumberReader(new StringReader(sw.toString()));
|
||||
ArrayList<String> lines = new ArrayList<String>();
|
||||
try {
|
||||
String line = reader.readLine();
|
||||
int count = 0;
|
||||
while (line != null && (depth == -1 || count++ <= depth)) {
|
||||
lines.add(line);
|
||||
line = reader.readLine();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
if (ex instanceof InterruptedIOException) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
lines.add(ex.toString());
|
||||
}
|
||||
String[] tempRep = new String[lines.size()];
|
||||
lines.toArray(tempRep);
|
||||
return tempRep;
|
||||
}
|
||||
}
|
@ -1,201 +0,0 @@
|
||||
/*
|
||||
* 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.client.logger.support;
|
||||
|
||||
import org.apache.log4j.Appender;
|
||||
import org.apache.log4j.AsyncAppender;
|
||||
import org.apache.log4j.ConsoleAppender;
|
||||
import org.apache.log4j.FileAppender;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.spi.LoggerRepository;
|
||||
import org.apache.log4j.spi.ThrowableRenderer;
|
||||
import org.apache.log4j.spi.ThrowableRendererSupport;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhuyong on 2017/6/28.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule")
|
||||
public class Log4jHelper {
|
||||
|
||||
private static boolean Log4j = false, Log4jGT1216 = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> loggerClass = Class.forName("org.apache.log4j.Logger");
|
||||
// 这里可能会加载到应用中依赖的log4j,因此需要判断classloader
|
||||
if (loggerClass.getClassLoader().equals(Log4jHelper.class.getClassLoader())) {
|
||||
LogManager.getLoggerRepository();
|
||||
try {
|
||||
Class<?> throwableRendererClass = Class.forName("org.apache.log4j.spi.ThrowableRenderer");
|
||||
// 这里可能会加载到应用中依赖的log4j 1.2.16版本的类,因此需要额外判断
|
||||
if (loggerClass.getClassLoader().equals(throwableRendererClass.getClassLoader())
|
||||
&& throwableRendererClass.getClassLoader().equals(Log4jHelper.class.getClassLoader())) {
|
||||
Log4jGT1216 = true;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
LogLog.warn("log4j must >= 1.2.16 for change throwable depth");
|
||||
}
|
||||
Log4j = true;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
}
|
||||
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
|
||||
public static Boolean setDepth(int depth) {
|
||||
if (Log4j && Log4jGT1216) {
|
||||
try {
|
||||
LoggerRepository repo = LogManager.getLoggerRepository();
|
||||
doSetDepth(repo, depth);
|
||||
return Boolean.TRUE;
|
||||
} catch (Throwable t) {
|
||||
// ignore
|
||||
LogLog.error("failed to set depth for log4j", t);
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")
|
||||
public static Boolean changeLevel(String name, String level) {
|
||||
if (Log4j) {
|
||||
Level l = Level.toLevel(level, Level.ERROR);
|
||||
Logger logger = LogManager.getLoggerRepository().exists(name);
|
||||
if (logger != null) {
|
||||
logger.setLevel(l);
|
||||
LogLog.info("set log4j log level success, " + name + ": " + l);
|
||||
return true;
|
||||
} else {
|
||||
Logger root = LogManager.getLoggerRepository().getRootLogger();
|
||||
if (root.getName().equals(name)) {
|
||||
root.setLevel(l);
|
||||
LogLog.info("set log4j log level success, " + name + ": " + l);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
LogLog.info("set log4j log level fail, no logger name exists: " + name);
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<String, LoggerInfo> getLoggers(String name) {
|
||||
Map<String, LoggerInfo> appenders = new HashMap<String, LoggerInfo>(10);
|
||||
if (!Log4j) {
|
||||
return appenders;
|
||||
}
|
||||
|
||||
if (name != null && !"".equals(name.trim())) {
|
||||
Logger logger = LogManager.getLoggerRepository().exists(name);
|
||||
if (logger != null) {
|
||||
appenders.put(name, doGetLoggerInfo(logger));
|
||||
}
|
||||
} else {
|
||||
// 获取所有logger时,如果没有appender则忽略
|
||||
Enumeration<Logger> loggers = LogManager.getLoggerRepository().getCurrentLoggers();
|
||||
|
||||
if (loggers != null) {
|
||||
while (loggers.hasMoreElements()) {
|
||||
Logger logger = loggers.nextElement();
|
||||
LoggerInfo info = doGetLoggerInfo(logger);
|
||||
if (info.getAppenders() == null || !info.getAppenders().isEmpty()) {
|
||||
appenders.put(logger.getName(), info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger root = LogManager.getLoggerRepository().getRootLogger();
|
||||
if (root != null) {
|
||||
LoggerInfo info = doGetLoggerInfo(root);
|
||||
if (info.getAppenders() == null || !info.getAppenders().isEmpty()) {
|
||||
appenders.put(root.getName(), info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return appenders;
|
||||
}
|
||||
|
||||
private static LoggerInfo doGetLoggerInfo(Logger logger) {
|
||||
LoggerInfo info = new LoggerInfo(logger.getName(), logger.getAdditivity());
|
||||
Level level = logger.getLevel(), effectiveLevel = logger.getEffectiveLevel();
|
||||
if (level != null) {
|
||||
info.setLevel(level.toString());
|
||||
}
|
||||
if (effectiveLevel != null) {
|
||||
info.setEffectiveLevel(effectiveLevel.toString());
|
||||
}
|
||||
|
||||
List<AppenderInfo> result = doGetLoggerAppenders(logger.getAllAppenders());
|
||||
info.setAppenders(result);
|
||||
return info;
|
||||
}
|
||||
|
||||
private static List<AppenderInfo> doGetLoggerAppenders(Enumeration<Appender> appenders) {
|
||||
List<AppenderInfo> result = new ArrayList<AppenderInfo>();
|
||||
|
||||
while (appenders.hasMoreElements()) {
|
||||
AppenderInfo info = new AppenderInfo();
|
||||
Appender appender = appenders.nextElement();
|
||||
|
||||
info.setName(appender.getName());
|
||||
info.setType(appender.getClass().getName());
|
||||
|
||||
result.add(info);
|
||||
if (appender instanceof FileAppender) {
|
||||
info.setFile(((FileAppender) appender).getFile());
|
||||
} else if (appender instanceof ConsoleAppender) {
|
||||
info.withDetail("target", ((ConsoleAppender) appender).getTarget());
|
||||
} else if (appender instanceof AsyncAppender) {
|
||||
List<AppenderInfo> asyncs = doGetLoggerAppenders(((AsyncAppender) appender).getAllAppenders());
|
||||
// 标明异步appender
|
||||
List<String> nestedNames = new ArrayList<String>();
|
||||
for (AppenderInfo a : asyncs) {
|
||||
nestedNames.add(a.getName());
|
||||
result.add(a);
|
||||
}
|
||||
info.withDetail("nestedNames", nestedNames);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void doSetDepth(LoggerRepository repo, int depth) {
|
||||
if (repo instanceof ThrowableRendererSupport) {
|
||||
Object tr = ((ThrowableRendererSupport) repo).getThrowableRenderer();
|
||||
if (tr == null || !(tr instanceof DepthThrowableRenderer)) {
|
||||
Object ctr = new DepthThrowableRenderer(depth);
|
||||
// 自定义ThrowableRender,栈深度设置
|
||||
((ThrowableRendererSupport) repo).setThrowableRenderer((ThrowableRenderer) ctr);
|
||||
LogLog.info("set log4j log depth success, depth: " + depth);
|
||||
} else {
|
||||
((DepthThrowableRenderer) tr).setDepth(depth);
|
||||
LogLog.info("set log4j log depth success, depth: " + depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -229,9 +229,6 @@ public class ConcurrentDiskUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
static final public Logger log = LogUtils.LOG;
|
||||
static final int RETRY_COUNT = 10;
|
||||
static final int SLEEP_BASETIME = 10;
|
||||
|
@ -175,12 +175,6 @@ public class HttpClient {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
Map<String, String> params = new HashMap<String, String>(2);
|
||||
params.put("s", "Wms+rkGG8jlaBBbpl8FIDxxNQGA=");
|
||||
System.out.println(encodingParams(params, "utf-8"));
|
||||
}
|
||||
|
||||
public static class HttpResult {
|
||||
final public int code;
|
||||
final public String content;
|
||||
|
@ -18,7 +18,8 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -33,19 +34,28 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,85 +0,0 @@
|
||||
/*
|
||||
* 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.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* 遍历目标文件夹下的所有文件,在文件头上加上license协议
|
||||
* 注意:读取/写入文件默认用utf-8进行
|
||||
* @author en.xuze@alipay.com
|
||||
* @version $Id: AppendLicense.java, v 0.1 2018年7月4日 下午2:31:16 en.xuze@alipay.com Exp $
|
||||
*/
|
||||
public class AppendLicense {
|
||||
|
||||
private static List<File> targetFiles = new LinkedList<File>();
|
||||
private static String licenseFile = "/Users/en.xuze/git/nacos/common/license";
|
||||
private static String targetDirOrFile = "/Users/en.xuze/git/nacos";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
List<String> licenseContents = IOUtils.readLines(new FileInputStream(new File(licenseFile)), "utf-8");
|
||||
readFiles(targetDirOrFile);
|
||||
for (Iterator<File> iterator = targetFiles.iterator(); iterator.hasNext();) {
|
||||
File file = (File) iterator.next();
|
||||
List<String> srcFileContents = IOUtils.readLines(new FileInputStream(file), "utf-8");
|
||||
List<String> writeContents = new ArrayList<String>();
|
||||
writeContents.addAll(licenseContents);
|
||||
writeContents.addAll(srcFileContents);
|
||||
IOUtils.writeLines(writeContents, "\n", new FileOutputStream(file));
|
||||
System.out.println("append license to file:" + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
private static void readFiles(String filePath) {
|
||||
if (filePath == null) {
|
||||
return;
|
||||
}
|
||||
File temp = new File(filePath);
|
||||
File[] files = null;
|
||||
if (temp.isFile()) {
|
||||
if (needAppend(temp.getName())) {
|
||||
targetFiles.add(temp);
|
||||
}
|
||||
} else {
|
||||
files = temp.listFiles();
|
||||
}
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
for (File f : files) {
|
||||
if (f.isFile()) {
|
||||
if (needAppend(f.getName())) {
|
||||
targetFiles.add(f);
|
||||
}
|
||||
} else if (f.isDirectory()) {
|
||||
readFiles(f.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean needAppend(String fileName) {
|
||||
return (fileName.endsWith(".java"));
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.common.util;
|
||||
|
||||
/**
|
||||
* Nacos common constants
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.2
|
||||
*/
|
||||
public interface Constants {
|
||||
|
||||
/**
|
||||
* Spring Profile : "standalone"
|
||||
*/
|
||||
String STANDALONE_SPRING_PROFILE = "standalone";
|
||||
}
|
@ -15,11 +15,9 @@
|
||||
*/
|
||||
package com.alibaba.nacos.common.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
@ -29,120 +27,6 @@ import java.util.zip.GZIPInputStream;
|
||||
*/
|
||||
public class IoUtils {
|
||||
|
||||
static public String toString(InputStream input, String encoding) throws IOException {
|
||||
return (null == encoding) ? toString(new InputStreamReader(input, "UTF-8"))
|
||||
: toString(new InputStreamReader(input, encoding));
|
||||
}
|
||||
|
||||
static public String toString(Reader reader) throws IOException {
|
||||
CharArrayWriter sw = new CharArrayWriter();
|
||||
copy(reader, sw);
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
|
||||
static public long copy(Reader input, Writer output) throws IOException {
|
||||
char[] buffer = new char[1 << 12];
|
||||
long count = 0;
|
||||
for (int n = 0; (n = input.read(buffer)) >= 0; ) {
|
||||
output.write(buffer, 0, n);
|
||||
count += n;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static public long copy(InputStream input, OutputStream output) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
int totalBytes = 0;
|
||||
while ((bytesRead = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, bytesRead);
|
||||
|
||||
totalBytes += bytesRead;
|
||||
}
|
||||
|
||||
return totalBytes;
|
||||
}
|
||||
|
||||
static public List<String> readLines(Reader input) throws IOException {
|
||||
BufferedReader reader = toBufferedReader(input);
|
||||
List<String> list = new ArrayList<String>();
|
||||
String line = null;
|
||||
for (; ; ) {
|
||||
line = reader.readLine();
|
||||
if (null != line) {
|
||||
if (StringUtils.isNotEmpty(line)) {
|
||||
list.add(line.trim());
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static private BufferedReader toBufferedReader(Reader reader) {
|
||||
return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(
|
||||
reader);
|
||||
}
|
||||
|
||||
|
||||
public static boolean delete(File fileOrDir) throws IOException {
|
||||
if (fileOrDir == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fileOrDir.isDirectory()) {
|
||||
cleanDirectory(fileOrDir);
|
||||
}
|
||||
|
||||
return fileOrDir.delete();
|
||||
}
|
||||
|
||||
public static void cleanDirectory(File directory) throws IOException {
|
||||
if (!directory.exists()) {
|
||||
String message = directory + " does not exist";
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
|
||||
if (!directory.isDirectory()) {
|
||||
String message = directory + " is not a directory";
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
|
||||
File[] files = directory.listFiles();
|
||||
if (files == null) {
|
||||
throw new IOException("Failed to list contents of " + directory);
|
||||
}
|
||||
|
||||
IOException exception = null;
|
||||
for (File file : files) {
|
||||
try {
|
||||
delete(file);
|
||||
} catch (IOException ioe) {
|
||||
exception = ioe;
|
||||
}
|
||||
}
|
||||
|
||||
if (null != exception) {
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeStringToFile(File file, String data, String encoding)
|
||||
throws IOException {
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(file);
|
||||
os.write(data.getBytes(encoding));
|
||||
os.flush();
|
||||
} finally {
|
||||
if (null != os) {
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] tryDecompress(InputStream raw) throws Exception {
|
||||
|
||||
try {
|
||||
@ -151,8 +35,7 @@ public class IoUtils {
|
||||
ByteArrayOutputStream out
|
||||
= new ByteArrayOutputStream();
|
||||
|
||||
|
||||
IoUtils.copy(gis, out);
|
||||
IOUtils.copy(gis, out);
|
||||
|
||||
return out.toByteArray();
|
||||
} catch (Exception e) {
|
||||
@ -162,12 +45,5 @@ public class IoUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
// String path = "/Users/zhupengfei/test_write.txt";
|
||||
|
||||
// writeStringToFile(new File(path), "hello2222", "utf-8");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,18 +16,28 @@
|
||||
|
||||
package com.alibaba.nacos.common.util;
|
||||
|
||||
import com.sun.management.OperatingSystemMXBean;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.sun.management.OperatingSystemMXBean;
|
||||
|
||||
/**
|
||||
* @author nacos
|
||||
*/
|
||||
public class SystemUtil {
|
||||
public class SystemUtils {
|
||||
|
||||
/**
|
||||
* The System property name of Standalone mode
|
||||
*/
|
||||
public static final String STANDALONE_MODE_PROPERTY_NAME = "nacos.standalone";
|
||||
|
||||
/**
|
||||
* Standalone mode or not
|
||||
*/
|
||||
public static final boolean STANDALONE_MODE = Boolean.getBoolean(STANDALONE_MODE_PROPERTY_NAME);
|
||||
|
||||
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
||||
|
||||
@ -45,10 +55,6 @@ public class SystemUtil {
|
||||
return env;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws SQLException {
|
||||
System.out.println(Boolean.parseBoolean("Tfue"));
|
||||
}
|
||||
|
||||
public static float getLoad() {
|
||||
return (float) operatingSystemMXBean.getSystemLoadAverage();
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.common;
|
||||
|
||||
import com.alibaba.nacos.common.util.SystemUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* {@link SystemUtils} Test
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.2
|
||||
*/
|
||||
public class SystemUtilsTest {
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
private static boolean standaloneMode = random.nextBoolean();
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
System.setProperty("nacos.standalone", String.valueOf(standaloneMode));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandaloneModeConstants() {
|
||||
|
||||
System.out.printf("System property \"%s\" = %s \n", "nacos.standalone", standaloneMode);
|
||||
|
||||
if ("true".equalsIgnoreCase(System.getProperty("nacos.standalone"))) {
|
||||
Assert.assertTrue(SystemUtils.STANDALONE_MODE);
|
||||
} else {
|
||||
Assert.assertFalse(SystemUtils.STANDALONE_MODE);
|
||||
}
|
||||
|
||||
Assert.assertEquals(standaloneMode, SystemUtils.STANDALONE_MODE);
|
||||
|
||||
}
|
||||
}
|
@ -17,7 +17,8 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -33,39 +34,27 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>taglibs</groupId>
|
||||
<artifactId>standard</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
@ -98,10 +87,6 @@
|
||||
</dependency>
|
||||
|
||||
<!-- Provided -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-mapper-lgpl</artifactId>
|
||||
@ -115,7 +100,33 @@
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-annotations</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@ -143,13 +154,9 @@
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources</directory>
|
||||
<excludes>
|
||||
<exclude>application.properties</exclude>
|
||||
<exclude>banner.txt</exclude>
|
||||
<exclude>schema.sql</exclude>
|
||||
<exclude>nacos-db.sql</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.AppNameUtils;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.joran.JoranConfigurator;
|
||||
|
||||
/**
|
||||
* logback test
|
||||
* @author Nacos
|
||||
*
|
||||
*/
|
||||
public class LogbackInitTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LogbackInitTest.class);
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
AppNameUtils.class.getClassLoader();
|
||||
String classpath = AppNameUtils.class.getResource("/").getPath();
|
||||
System.out.println("The classpath is " + classpath);
|
||||
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
lc.reset();
|
||||
|
||||
JoranConfigurator configurator = new JoranConfigurator();
|
||||
configurator.setContext(lc);
|
||||
configurator.doConfigure(LogbackInitTest.class.getResource("logback-jiuren.xml"));
|
||||
|
||||
for (;;) {
|
||||
logger.info("hello");
|
||||
System.out.println(getLevel(logger));
|
||||
Thread.sleep(1000L);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static String getLevel(Logger logger) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
return "debug";
|
||||
} else if (logger.isInfoEnabled()) {
|
||||
return "info";
|
||||
} else if (logger.isWarnEnabled()) {
|
||||
return "warn";
|
||||
} else if (logger.isErrorEnabled()) {
|
||||
return "error";
|
||||
} else {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
}
|
@ -15,26 +15,20 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* Config main
|
||||
*
|
||||
* @author Nacos
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = "com.alibaba.nacos.config.server")
|
||||
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
|
||||
@ServletComponentScan
|
||||
@SpringBootApplication
|
||||
public class Config {
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException {
|
||||
SpringApplication.run(Config.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,19 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.aspect;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.constant.CounterMode;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||
@ -35,6 +22,17 @@ import com.alibaba.nacos.config.server.model.capacity.Capacity;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.service.capacity.CapacityService;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* 容量管理切面:批量写入、更新暂不处理
|
||||
|
@ -15,18 +15,17 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.aspect;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
import com.alibaba.nacos.config.server.service.ConfigService;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey2;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
import com.alibaba.nacos.config.server.utils.RequestUtil;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* * Created with IntelliJ IDEA. User: dingjoey Date: 13-12-12 Time: 21:12
|
||||
|
@ -0,0 +1,198 @@
|
||||
///*
|
||||
// * Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
// * contributor license agreements. See the NOTICE file distributed with
|
||||
// * this work for additional information regarding copyright ownership.
|
||||
// * The ASF licenses this file to You 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.config.server.configuration;
|
||||
//
|
||||
//import com.alibaba.nacos.config.server.service.BasicDataSourceServiceImpl;
|
||||
//import com.alibaba.nacos.config.server.service.TimerTaskService;
|
||||
//import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
//import org.apache.commons.dbcp.BasicDataSource;
|
||||
//import org.apache.commons.lang.math.NumberUtils;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.context.annotation.Profile;
|
||||
//import org.springframework.jdbc.core.JdbcTemplate;
|
||||
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
//import org.springframework.transaction.support.TransactionTemplate;
|
||||
//
|
||||
//import javax.annotation.PostConstruct;
|
||||
//import javax.sql.DataSource;
|
||||
//import java.io.IOException;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//import java.util.regex.Pattern;
|
||||
//
|
||||
//import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
//
|
||||
///**
|
||||
// * Cluster {@link DataSource} {@link Configuration}
|
||||
// *
|
||||
// * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
// * @since 0.2.2
|
||||
// */
|
||||
//@Profile("!standalone")
|
||||
//@Configuration
|
||||
//public class ClusterDataSourceConfiguration {
|
||||
//
|
||||
// private static final String JDBC_DRIVER_NAME = "com.mysql.jdbc.Driver";
|
||||
//
|
||||
// /**
|
||||
// * JDBC执行超时时间, 单位秒
|
||||
// */
|
||||
// private int queryTimeout = 3;
|
||||
//
|
||||
// private static final int TRANSACTION_QUERY_TIMEOUT = 5;
|
||||
//
|
||||
// private static final String DB_LOAD_ERROR_MSG = "[db-load-error]load jdbc.properties error";
|
||||
//
|
||||
// private List<BasicDataSource> dataSourceList = new ArrayList<BasicDataSource>();
|
||||
// private JdbcTemplate jt;
|
||||
// private DataSourceTransactionManager tm;
|
||||
// private TransactionTemplate tjt;
|
||||
//
|
||||
// private JdbcTemplate testMasterJT;
|
||||
// private JdbcTemplate testMasterWritableJT;
|
||||
//
|
||||
// volatile private List<JdbcTemplate> testJTList;
|
||||
// volatile private List<Boolean> isHealthList;
|
||||
// private volatile int masterIndex;
|
||||
// private static Pattern ipPattern = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
|
||||
//
|
||||
//
|
||||
//
|
||||
// @PostConstruct
|
||||
// public void init() {
|
||||
// queryTimeout = NumberUtils
|
||||
// .toInt(System.getProperty("QUERYTIMEOUT"), 3);
|
||||
// jt = new JdbcTemplate();
|
||||
// /**
|
||||
// * 设置最大记录数,防止内存膨胀
|
||||
// */
|
||||
// jt.setMaxRows(50000);
|
||||
// jt.setQueryTimeout(queryTimeout);
|
||||
//
|
||||
// testMasterJT = new JdbcTemplate();
|
||||
// testMasterJT.setQueryTimeout(queryTimeout);
|
||||
//
|
||||
// testMasterWritableJT = new JdbcTemplate();
|
||||
// /**
|
||||
// * 防止login接口因为主库不可用而rt太长
|
||||
// */
|
||||
// testMasterWritableJT.setQueryTimeout(1);
|
||||
// /**
|
||||
// * 数据库健康检测
|
||||
// */
|
||||
// testJTList = new ArrayList<JdbcTemplate>();
|
||||
// isHealthList = new ArrayList<Boolean>();
|
||||
//
|
||||
// tm = new DataSourceTransactionManager();
|
||||
// tjt = new TransactionTemplate(tm);
|
||||
// /**
|
||||
// * 事务的超时时间需要与普通操作区分开
|
||||
// */
|
||||
// tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT);
|
||||
// if (!STANDALONE_MODE) {
|
||||
// try {
|
||||
// reload();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// throw new RuntimeException(DB_LOAD_ERROR_MSG);
|
||||
// }
|
||||
//
|
||||
// TimerTaskService.scheduleWithFixedDelay(new BasicDataSourceServiceImpl.SelectMasterTask(), 10, 10,
|
||||
// TimeUnit.SECONDS);
|
||||
// TimerTaskService.scheduleWithFixedDelay(new BasicDataSourceServiceImpl.CheckDBHealthTask(), 10, 10,
|
||||
// TimeUnit.SECONDS);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public synchronized void reload() throws IOException {
|
||||
// List<BasicDataSource> dblist = new ArrayList<BasicDataSource>();
|
||||
// try {
|
||||
// String val = null;
|
||||
// val = env.getProperty("db.num");
|
||||
// if (null == val) {
|
||||
// throw new IllegalArgumentException("db.num is null");
|
||||
// }
|
||||
// int dbNum = Integer.parseInt(val.trim());
|
||||
//
|
||||
// for (int i = 0; i < dbNum; i++) {
|
||||
// BasicDataSource ds = new BasicDataSource();
|
||||
// ds.setDriverClassName(JDBC_DRIVER_NAME);
|
||||
//
|
||||
// val = env.getProperty("db.url." + i);
|
||||
// if (null == val) {
|
||||
// fatalLog.error("db.url." + i + " is null");
|
||||
// throw new IllegalArgumentException();
|
||||
// }
|
||||
// ds.setUrl(val.trim());
|
||||
//
|
||||
// val = env.getProperty("db.user");
|
||||
// if (null == val) {
|
||||
// fatalLog.error("db.user is null");
|
||||
// throw new IllegalArgumentException();
|
||||
// }
|
||||
// ds.setUsername(val.trim());
|
||||
//
|
||||
// val = env.getProperty("db.password");
|
||||
// if (null == val) {
|
||||
// fatalLog.error("db.password is null");
|
||||
// throw new IllegalArgumentException();
|
||||
// }
|
||||
// ds.setPassword(val.trim());
|
||||
//
|
||||
// val = env.getProperty("db.initialSize");
|
||||
// ds.setInitialSize(Integer.parseInt(defaultIfNull(val, "10")));
|
||||
//
|
||||
// val = env.getProperty("db.maxActive");
|
||||
// ds.setMaxActive(Integer.parseInt(defaultIfNull(val, "20")));
|
||||
//
|
||||
// val = env.getProperty("db.maxIdle");
|
||||
// ds.setMaxIdle(Integer.parseInt(defaultIfNull(val, "50")));
|
||||
//
|
||||
// ds.setMaxWait(3000L);
|
||||
// ds.setPoolPreparedStatements(true);
|
||||
//
|
||||
// // 每10分钟检查一遍连接池
|
||||
// ds.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES
|
||||
// .toMillis(10L));
|
||||
// ds.setTestWhileIdle(true);
|
||||
// ds.setValidationQuery("SELECT 1 FROM dual");
|
||||
//
|
||||
// dblist.add(ds);
|
||||
//
|
||||
// JdbcTemplate jdbcTemplate = new JdbcTemplate();
|
||||
// jdbcTemplate.setQueryTimeout(queryTimeout);
|
||||
// jdbcTemplate.setDataSource(ds);
|
||||
//
|
||||
// testJTList.add(jdbcTemplate);
|
||||
// isHealthList.add(Boolean.TRUE);
|
||||
// }
|
||||
//
|
||||
// if (dblist == null || dblist.size() == 0) {
|
||||
// throw new RuntimeException("no datasource available");
|
||||
// }
|
||||
//
|
||||
// dataSourceList = dblist;
|
||||
// new BasicDataSourceServiceImpl.SelectMasterTask().run();
|
||||
// new BasicDataSourceServiceImpl.CheckDBHealthTask().run();
|
||||
// } catch (RuntimeException e) {
|
||||
// fatalLog.error(DB_LOAD_ERROR_MSG, e);
|
||||
// throw new IOException(e);
|
||||
// } finally {
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -0,0 +1,63 @@
|
||||
///*
|
||||
// * Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
// * contributor license agreements. See the NOTICE file distributed with
|
||||
// * this work for additional information regarding copyright ownership.
|
||||
// * The ASF licenses this file to You 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.config.server.configuration;
|
||||
//
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.annotation.Qualifier;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.core.env.Environment;
|
||||
//import org.springframework.jdbc.core.JdbcTemplate;
|
||||
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
//import org.springframework.transaction.PlatformTransactionManager;
|
||||
//
|
||||
//import javax.sql.DataSource;
|
||||
//
|
||||
///**
|
||||
// * DataBase {@link Configuration}
|
||||
// *
|
||||
// * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
// * @since 0.2.2
|
||||
// */
|
||||
//@Configuration
|
||||
//public class DataBaseConfiguration {
|
||||
//
|
||||
// /**
|
||||
// * The bean name of {@link DataSource} for Nacos Config
|
||||
// */
|
||||
// public static final String DATA_SOURCE_BEAN_NAME = "nacosConfigDataSource";
|
||||
//
|
||||
// @Bean
|
||||
// @Autowired
|
||||
// public JdbcTemplate jdbcTemplate(@Qualifier(DATA_SOURCE_BEAN_NAME) DataSource dataSource, Environment environment) {
|
||||
// JdbcTemplate jdbcTemplate = new JdbcTemplate();
|
||||
// jdbcTemplate = new JdbcTemplate();
|
||||
// jdbcTemplate.setMaxRows(50000);
|
||||
// jdbcTemplate.setQueryTimeout(5000);
|
||||
// jdbcTemplate.setDataSource(dataSource);
|
||||
// return jdbcTemplate;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// @Autowired
|
||||
// public PlatformTransactionManager transactionManager(@Qualifier(DATA_SOURCE_BEAN_NAME) DataSource dataSource) {
|
||||
// DataSourceTransactionManager manager = new DataSourceTransactionManager();
|
||||
// manager.setDataSource(dataSource);
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
//}
|
@ -0,0 +1,75 @@
|
||||
///*
|
||||
// * Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
// * contributor license agreements. See the NOTICE file distributed with
|
||||
// * this work for additional information regarding copyright ownership.
|
||||
// * The ASF licenses this file to You 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.config.server.configuration;
|
||||
//
|
||||
//import org.apache.commons.dbcp.BasicDataSource;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.context.annotation.Profile;
|
||||
//import org.springframework.core.env.Environment;
|
||||
//
|
||||
//import javax.sql.DataSource;
|
||||
//import java.io.File;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//import static com.alibaba.nacos.config.server.configuration.DataBaseConfiguration.DATA_SOURCE_BEAN_NAME;
|
||||
//
|
||||
///**
|
||||
// * Local {@link DataSource} {@link Configuration}
|
||||
// *
|
||||
// * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
// * @since 0.2.2
|
||||
// */
|
||||
//@Profile("standalone")
|
||||
//@Configuration
|
||||
//public class LocalDataSourceConfiguration {
|
||||
//
|
||||
// private static final String JDBC_DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver";
|
||||
//
|
||||
// private static final String DERBY_BASE_DIR = "data" + File.separator + "derby-data";
|
||||
//
|
||||
// private static final String NACOS_HOME_PROPERTY_NAME = "nacos.home";
|
||||
//
|
||||
// private static final String DEFAULT_APP_NAME = System.getProperty("user.home") + File.separator + "nacos";
|
||||
//
|
||||
// private static final String APP_HOME = System.getProperty(NACOS_HOME_PROPERTY_NAME, DEFAULT_APP_NAME);
|
||||
//
|
||||
// private static final String DATA_SOURCE_URL = "jdbc:derby:" + APP_HOME + File.separator + DERBY_BASE_DIR +
|
||||
// ";create=true";
|
||||
//
|
||||
// private static final String USER_NAME = "nacos";
|
||||
//
|
||||
// private static final String PASSWORD = "nacos";
|
||||
//
|
||||
// @Bean(name = DATA_SOURCE_BEAN_NAME,destroyMethod = "close")
|
||||
// public DataSource nacosConfigDataSource(Environment environment) {
|
||||
// BasicDataSource ds = new BasicDataSource();
|
||||
// ds.setDriverClassName(JDBC_DRIVER_NAME);
|
||||
// ds.setUrl(DATA_SOURCE_URL);
|
||||
// ds.setUsername(USER_NAME);
|
||||
// ds.setPassword(PASSWORD);
|
||||
// ds.setInitialSize(environment.getProperty("db.initialSize", int.class, 20));
|
||||
// ds.setMaxActive(environment.getProperty("db.maxActive", int.class, 30));
|
||||
// ds.setMaxIdle(environment.getProperty("db.maxIdle", int.class, 50));
|
||||
// ds.setMaxWait(environment.getProperty("db.maxWait", long.class, 10000L));
|
||||
// ds.setPoolPreparedStatements(true);
|
||||
// ds.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES.toMillis(10L));
|
||||
// ds.setTestWhileIdle(true);
|
||||
// return ds;
|
||||
// }
|
||||
//
|
||||
//}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.config.server.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Nacos Config {@link Configuration} includes required Spring components.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.2
|
||||
*/
|
||||
@Configuration
|
||||
public class NacosConfigConfiguration {
|
||||
}
|
@ -17,8 +17,8 @@ package com.alibaba.nacos.config.server.constant;
|
||||
|
||||
/**
|
||||
* Server Constants
|
||||
* @author Nacos
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class Constants {
|
||||
|
||||
@ -101,23 +101,43 @@ public class Constants {
|
||||
*/
|
||||
public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;
|
||||
|
||||
public static final String BASE_PATH = "/v1/cs";
|
||||
public static final String BASE_PATH = "/nacos/v1/cs";
|
||||
|
||||
public static final String OPS_CONTROLLER_PATH = BASE_PATH + "/ops";
|
||||
public static final String DEFAULT_OPS_CONTROLLER_PATH = BASE_PATH + "/ops";
|
||||
|
||||
public static final String CAPACITY_CONTROLLER_PATH = BASE_PATH + "/capacity";
|
||||
public static final String OPS_CONTROLLER_PATH = "${nacos.config.ops.path" + ":" + DEFAULT_OPS_CONTROLLER_PATH + "}";
|
||||
|
||||
public static final String COMMUNICATION_CONTROLLER_PATH = BASE_PATH + "/communication";
|
||||
public static final String DEFAULT_CAPACITY_CONTROLLER_PATH = BASE_PATH + "/capacity";
|
||||
|
||||
public static final String CONFIG_CONTROLLER_PATH = BASE_PATH + "/configs";
|
||||
public static final String CAPACITY_CONTROLLER_PATH = "${nacos.config.capacity.path" + ":" + DEFAULT_CAPACITY_CONTROLLER_PATH + "}";
|
||||
|
||||
public static final String HEALTH_CONTROLLER_PATH = BASE_PATH + "/health";
|
||||
public static final String DEFAULT_COMMUNICATION_CONTROLLER_PATH = BASE_PATH + "/communication";
|
||||
|
||||
public static final String HISTORY_CONTROLLER_PATH = BASE_PATH + "/history";
|
||||
// public static final String COMMUNICATION_CONTROLLER_PATH = "${nacos.config.communication.path" + ":" + DEFAULT_COMMUNICATION_CONTROLLER_PATH + "}";
|
||||
|
||||
public static final String LISTENER_CONTROLLER_PATH = BASE_PATH + "/listener";
|
||||
public static final String COMMUNICATION_CONTROLLER_PATH = DEFAULT_COMMUNICATION_CONTROLLER_PATH;
|
||||
|
||||
public static final String NAMESPACE_CONTROLLER_PATH = BASE_PATH + "/namespaces";
|
||||
public static final String DEFAULT_CONFIG_CONTROLLER_PATH = BASE_PATH + "/configs";
|
||||
|
||||
public static final String CONFIG_CONTROLLER_PATH = "${nacos.config.path" + ":" + DEFAULT_CONFIG_CONTROLLER_PATH + "}";
|
||||
|
||||
public static final String DEFAULT_HEALTH_CONTROLLER_PATH = BASE_PATH + "/health";
|
||||
|
||||
// public static final String HEALTH_CONTROLLER_PATH = "${nacos.config.health.path" + ":" + DEFAULT_HEALTH_CONTROLLER_PATH + "}";
|
||||
|
||||
public static final String HEALTH_CONTROLLER_PATH = DEFAULT_HEALTH_CONTROLLER_PATH;
|
||||
|
||||
public static final String DEFAULT_HISTORY_CONTROLLER_PATH = BASE_PATH + "/history";
|
||||
|
||||
public static final String HISTORY_CONTROLLER_PATH = "${nacos.config.history.path" + ":" + DEFAULT_HISTORY_CONTROLLER_PATH + "}";
|
||||
|
||||
public static final String DEFAULT_LISTENER_CONTROLLER_PATH = BASE_PATH + "/listener";
|
||||
|
||||
public static final String LISTENER_CONTROLLER_PATH = "${nacos.config.listener.path" + ":" + DEFAULT_LISTENER_CONTROLLER_PATH + "}";
|
||||
|
||||
public static final String DEFAULT_NAMESPACE_CONTROLLER_PATH = BASE_PATH + "/namespaces";
|
||||
|
||||
public static final String NAMESPACE_CONTROLLER_PATH = "${nacos.config.namespaces.path" + ":" + DEFAULT_NAMESPACE_CONTROLLER_PATH + "}";
|
||||
|
||||
public static final String ENCODE = "UTF-8";
|
||||
|
||||
|
@ -15,9 +15,11 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.RestResult;
|
||||
import com.alibaba.nacos.config.server.model.capacity.Capacity;
|
||||
import com.alibaba.nacos.config.server.service.capacity.CapacityService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -27,10 +29,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.RestResult;
|
||||
import com.alibaba.nacos.config.server.model.capacity.Capacity;
|
||||
import com.alibaba.nacos.config.server.service.capacity.CapacityService;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* capcity manage
|
||||
|
@ -15,13 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.SampleResult;
|
||||
import com.alibaba.nacos.config.server.service.LongPollingService;
|
||||
import com.alibaba.nacos.config.server.service.dump.DumpService;
|
||||
import com.alibaba.nacos.config.server.service.notify.NotifyService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
@ -30,11 +29,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.SampleResult;
|
||||
import com.alibaba.nacos.config.server.service.LongPullingService;
|
||||
import com.alibaba.nacos.config.server.service.dump.DumpService;
|
||||
import com.alibaba.nacos.config.server.service.notify.NotifyService;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
@ -51,7 +49,7 @@ public class CommunicationController {
|
||||
private DumpService dumpService;
|
||||
|
||||
@Autowired
|
||||
protected LongPullingService longPullingService;
|
||||
protected LongPollingService longPollingService;
|
||||
|
||||
private String trueStr = "true";
|
||||
|
||||
@ -92,7 +90,7 @@ public class CommunicationController {
|
||||
ModelMap modelMap)
|
||||
throws IOException, ServletException, Exception {
|
||||
group = StringUtils.isBlank(group) ? Constants.DEFAULT_GROUP : group;
|
||||
SampleResult sampleResult = longPullingService.getCollectSubscribleInfo(dataId, group, tenant);
|
||||
SampleResult sampleResult = longPollingService.getCollectSubscribleInfo(dataId, group, tenant);
|
||||
return sampleResult;
|
||||
}
|
||||
|
||||
@ -106,7 +104,7 @@ public class CommunicationController {
|
||||
@RequestParam("ip") String ip,
|
||||
ModelMap modelMap)
|
||||
throws IOException, ServletException, Exception {
|
||||
SampleResult sampleResult = longPullingService.getCollectSubscribleInfoByIp(ip);
|
||||
SampleResult sampleResult = longPollingService.getCollectSubscribleInfoByIp(ip);
|
||||
return sampleResult;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.sql.Timestamp;
|
||||
@ -34,26 +35,35 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.exception.NacosException;
|
||||
import com.alibaba.nacos.config.server.model.ConfigAdvanceInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigAllInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo4Beta;
|
||||
import com.alibaba.nacos.config.server.model.GroupkeyListenserStatus;
|
||||
import com.alibaba.nacos.config.server.model.Page;
|
||||
import com.alibaba.nacos.config.server.model.RestResult;
|
||||
import com.alibaba.nacos.config.server.model.SampleResult;
|
||||
import com.alibaba.nacos.config.server.model.*;
|
||||
import com.alibaba.nacos.config.server.service.AggrWhitelist;
|
||||
import com.alibaba.nacos.config.server.service.ConfigDataChangeEvent;
|
||||
import com.alibaba.nacos.config.server.service.ConfigSubService;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.service.merge.MergeDatumService;
|
||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||
import com.alibaba.nacos.config.server.utils.MD5Util;
|
||||
import com.alibaba.nacos.config.server.utils.ParamUtils;
|
||||
import com.alibaba.nacos.config.server.utils.RequestUtil;
|
||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.alibaba.nacos.config.server.utils.*;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 软负载客户端发布数据专用控制器
|
||||
|
@ -15,8 +15,22 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.pullLog;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.CacheItem;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoBase;
|
||||
import com.alibaba.nacos.config.server.service.ConfigService;
|
||||
import com.alibaba.nacos.config.server.service.DiskUtil;
|
||||
import com.alibaba.nacos.config.server.service.LongPollingService;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||
import com.alibaba.nacos.config.server.utils.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@ -27,29 +41,8 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.CacheItem;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoBase;
|
||||
import com.alibaba.nacos.config.server.service.ConfigService;
|
||||
import com.alibaba.nacos.config.server.service.DiskUtil;
|
||||
import com.alibaba.nacos.config.server.service.LongPullingService;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey2;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5Util;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.Protocol;
|
||||
import com.alibaba.nacos.config.server.utils.RequestUtil;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.pullLog;
|
||||
|
||||
/**
|
||||
* ConfigServlet inner for aop
|
||||
@ -60,7 +53,7 @@ import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
public class ConfigServletInner {
|
||||
|
||||
@Autowired
|
||||
private LongPullingService longPullingService;
|
||||
private LongPollingService longPollingService;
|
||||
|
||||
@Autowired
|
||||
private PersistService persistService;
|
||||
@ -74,8 +67,8 @@ public class ConfigServletInner {
|
||||
public String doPollingConfig(HttpServletRequest request, HttpServletResponse response, Map<String, String> clientMd5Map, int probeRequestSize) throws IOException, ServletException {
|
||||
|
||||
// 长轮询
|
||||
if (LongPullingService.isSupportLongPulling(request)) {
|
||||
longPullingService.addLongPullingClient(request, response, clientMd5Map, probeRequestSize);
|
||||
if (LongPollingService.isSupportLongPulling(request)) {
|
||||
longPollingService.addLongPullingClient(request, response, clientMd5Map, probeRequestSize);
|
||||
return HttpServletResponse.SC_OK + "";
|
||||
}
|
||||
|
||||
@ -141,7 +134,7 @@ public class ConfigServletInner {
|
||||
if (isBeta) {
|
||||
md5 = cacheItem.getMd54Beta();
|
||||
lastModified = cacheItem.getLastModifiedTs4Beta();
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
configInfoBase = persistService.findConfigInfo4Beta(dataId, group,tenant);
|
||||
} else {
|
||||
file = DiskUtil.targetBetaFile(dataId, group, tenant);
|
||||
@ -158,7 +151,7 @@ public class ConfigServletInner {
|
||||
lastModified = cacheItem.tagLastModifiedTs.get(autoTag);
|
||||
}
|
||||
}
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
configInfoBase = persistService.findConfigInfo4Tag(dataId, group, tenant, autoTag);
|
||||
} else {
|
||||
file = DiskUtil.targetTagFile(dataId, group, tenant, autoTag);
|
||||
@ -169,7 +162,7 @@ public class ConfigServletInner {
|
||||
} else {
|
||||
md5 = cacheItem.getMd5();
|
||||
lastModified = cacheItem.getLastModifiedTs();
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
configInfoBase = persistService.findConfigInfo(dataId, group, tenant);
|
||||
} else {
|
||||
file = DiskUtil.targetFile(dataId, group, tenant);
|
||||
@ -201,7 +194,7 @@ public class ConfigServletInner {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
configInfoBase = persistService.findConfigInfo4Tag(dataId, group, tenant, tag);
|
||||
} else {
|
||||
file = DiskUtil.targetTagFile(dataId, group, tenant, tag);
|
||||
@ -230,7 +223,7 @@ public class ConfigServletInner {
|
||||
response.setHeader("Pragma", "no-cache");
|
||||
response.setDateHeader("Expires", 0);
|
||||
response.setHeader("Cache-Control", "no-cache,no-store");
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
response.setDateHeader("Last-Modified", lastModified);
|
||||
} else {
|
||||
fis = new FileInputStream(file);
|
||||
@ -238,7 +231,7 @@ public class ConfigServletInner {
|
||||
}
|
||||
|
||||
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
out = response.getWriter();
|
||||
out.print(configInfoBase.getContent());
|
||||
out.flush();
|
||||
|
@ -15,17 +15,18 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.service.DataSourceService;
|
||||
import com.alibaba.nacos.config.server.service.DynamicDataSource;
|
||||
import com.alibaba.nacos.config.server.service.ServerListService;
|
||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* health service
|
||||
|
@ -15,10 +15,11 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo;
|
||||
import com.alibaba.nacos.config.server.model.Page;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
@ -27,10 +28,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo;
|
||||
import com.alibaba.nacos.config.server.model.Page;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 管理控制器。
|
||||
|
@ -15,15 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.GroupkeyListenserStatus;
|
||||
import com.alibaba.nacos.config.server.model.SampleResult;
|
||||
import com.alibaba.nacos.config.server.service.ConfigSubService;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey2;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
@ -32,11 +29,12 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.GroupkeyListenserStatus;
|
||||
import com.alibaba.nacos.config.server.model.SampleResult;
|
||||
import com.alibaba.nacos.config.server.service.ConfigSubService;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey2;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Config longpulling
|
||||
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.service.dump.DumpService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -26,9 +26,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.service.dump.DumpService;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 管理控制器。
|
||||
|
@ -15,13 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* global exception handler
|
||||
*
|
||||
|
@ -15,19 +15,14 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.filter;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
|
||||
/**
|
||||
* encode filter
|
||||
@ -36,8 +31,8 @@ import com.alibaba.nacos.config.server.constant.Constants;
|
||||
*
|
||||
*/
|
||||
@Order(1)
|
||||
@javax.servlet.annotation.WebFilter(filterName = "webFilter", urlPatterns = "/*")
|
||||
public class WebFilter implements Filter {
|
||||
@WebFilter(filterName = "webFilter", urlPatterns = "/*")
|
||||
public class NacosWebFilter implements Filter {
|
||||
|
||||
static private String webRootPath;
|
||||
|
@ -15,6 +15,11 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.manager;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
@ -23,11 +28,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import javax.management.ObjectName;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.SimpleReadWriteLock;
|
||||
import com.alibaba.nacos.config.server.utils.SingletonRepository.DataIdGroupIdCache;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
/**
|
||||
* cache item
|
||||
* @author Nacos
|
||||
|
@ -15,11 +15,11 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.model;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
|
||||
/**
|
||||
* 不能增加字段,为了兼容老前台接口(老接口增加一个字段会出现不兼容问题)设置的model。
|
||||
*
|
||||
|
@ -15,15 +15,17 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.monitor;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.alibaba.nacos.config.server.service.ClientTrackService;
|
||||
import com.alibaba.nacos.config.server.service.ConfigService;
|
||||
import com.alibaba.nacos.config.server.service.TimerTaskService;
|
||||
import com.alibaba.nacos.config.server.service.notify.AsyncNotifyService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;
|
||||
|
||||
/**
|
||||
* Memory monitor
|
||||
|
@ -22,7 +22,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
* Response Monitory
|
||||
*
|
||||
* @author Nacos
|
||||
*
|
||||
*/
|
||||
public class ResponseMonitor {
|
||||
static AtomicLong[] getConfigCountDetail = new AtomicLong[8];
|
||||
@ -35,63 +34,47 @@ public class ResponseMonitor {
|
||||
private static final int MS_2000 = 2000;
|
||||
private static final int MS_3000 = 3000;
|
||||
|
||||
static{
|
||||
static {
|
||||
refresh();
|
||||
}
|
||||
|
||||
public static void refresh(){
|
||||
for(int i = 0; i< getConfigCountDetail.length;i++){
|
||||
public static void refresh() {
|
||||
for (int i = 0; i < getConfigCountDetail.length; i++) {
|
||||
getConfigCountDetail[i] = new AtomicLong();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addConfigTime(long time){
|
||||
public static void addConfigTime(long time) {
|
||||
getConfigCount.incrementAndGet();
|
||||
if(time < MS_50){
|
||||
if (time < MS_50) {
|
||||
getConfigCountDetail[0].incrementAndGet();
|
||||
} else if(time < MS_100) {
|
||||
} else if (time < MS_100) {
|
||||
getConfigCountDetail[1].incrementAndGet();
|
||||
} else if (time < MS_200){
|
||||
} else if (time < MS_200) {
|
||||
getConfigCountDetail[2].incrementAndGet();
|
||||
} else if(time < MS_500){
|
||||
} else if (time < MS_500) {
|
||||
getConfigCountDetail[3].incrementAndGet();
|
||||
} else if(time < MS_1000){
|
||||
} else if (time < MS_1000) {
|
||||
getConfigCountDetail[4].incrementAndGet();
|
||||
} else if(time < MS_2000){
|
||||
} else if (time < MS_2000) {
|
||||
getConfigCountDetail[5].incrementAndGet();
|
||||
} else if(time < MS_3000){
|
||||
} else if (time < MS_3000) {
|
||||
getConfigCountDetail[6].incrementAndGet();
|
||||
} else {
|
||||
getConfigCountDetail[7].incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getStringForPrint(){
|
||||
public static String getStringForPrint() {
|
||||
DecimalFormat df = new DecimalFormat("##.0");
|
||||
StringBuilder s = new StringBuilder("getConfig monitor:\r\n");
|
||||
s.append("0-50ms:" + df.format(getConfigCountDetail[0].getAndSet(0)*100/ getConfigCount.get())).append("%\r\n");
|
||||
s.append("100-200ms:" + df.format(getConfigCountDetail[2].getAndSet(0)*100/ getConfigCount.get())).append("%\r\n");
|
||||
s.append("200-500ms:" + df.format(getConfigCountDetail[3].getAndSet(0)*100/ getConfigCount.get())).append("%\r\n");
|
||||
s.append("500-1000ms:" + df.format(getConfigCountDetail[4].getAndSet(0)*100/ getConfigCount.get())).append("%\r\n");
|
||||
s.append("1000-2000ms:" + df.format(getConfigCountDetail[5].getAndSet(0)*100/ getConfigCount.get())).append("%\r\n");
|
||||
s.append("2000-3000ms:" + df.format(getConfigCountDetail[6].getAndSet(0)*100/ getConfigCount.get())).append("%\r\n");
|
||||
s.append("3000以上ms:" + df.format(getConfigCountDetail[7].getAndSet(0)*100/ getConfigCount.getAndSet(0))).append("%\r\n");
|
||||
s.append("0-50ms:" + df.format(getConfigCountDetail[0].getAndSet(0) * 100 / getConfigCount.get())).append("%\r\n");
|
||||
s.append("100-200ms:" + df.format(getConfigCountDetail[2].getAndSet(0) * 100 / getConfigCount.get())).append("%\r\n");
|
||||
s.append("200-500ms:" + df.format(getConfigCountDetail[3].getAndSet(0) * 100 / getConfigCount.get())).append("%\r\n");
|
||||
s.append("500-1000ms:" + df.format(getConfigCountDetail[4].getAndSet(0) * 100 / getConfigCount.get())).append("%\r\n");
|
||||
s.append("1000-2000ms:" + df.format(getConfigCountDetail[5].getAndSet(0) * 100 / getConfigCount.get())).append("%\r\n");
|
||||
s.append("2000-3000ms:" + df.format(getConfigCountDetail[6].getAndSet(0) * 100 / getConfigCount.get())).append("%\r\n");
|
||||
s.append("3000以上ms:" + df.format(getConfigCountDetail[7].getAndSet(0) * 100 / getConfigCount.getAndSet(0))).append("%\r\n");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ResponseMonitor.addConfigTime(10);
|
||||
ResponseMonitor.addConfigTime(10);
|
||||
ResponseMonitor.addConfigTime(10);
|
||||
ResponseMonitor.addConfigTime(10);
|
||||
ResponseMonitor.addConfigTime(100);
|
||||
ResponseMonitor.addConfigTime(150);
|
||||
ResponseMonitor.addConfigTime(250);
|
||||
ResponseMonitor.addConfigTime(350);
|
||||
ResponseMonitor.addConfigTime(750);
|
||||
ResponseMonitor.addConfigTime(15000);
|
||||
System.out.println(ResponseMonitor.getStringForPrint());
|
||||
System.out.println(ResponseMonitor.getStringForPrint());
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
import com.alibaba.nacos.config.server.utils.RegexParser;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
@ -24,11 +26,8 @@ import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.RegexParser;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -15,23 +15,9 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.service.PersistService.CONFIG_INFO4BETA_ROW_MAPPER;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@ -41,12 +27,24 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
import static com.alibaba.nacos.config.server.service.PersistService.CONFIG_INFO4BETA_ROW_MAPPER;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
/**
|
||||
* Base data source
|
||||
* @author Nacos
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
@Service("basicDataSourceService")
|
||||
public class BasicDataSourceServiceImpl implements DataSourceService {
|
||||
@ -79,8 +77,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
queryTimeout = NumberUtils
|
||||
.toInt(System.getProperty("QUERYTIMEOUT"), 3);
|
||||
queryTimeout = NumberUtils.toInt(System.getProperty("QUERYTIMEOUT"), 3);
|
||||
jt = new JdbcTemplate();
|
||||
/**
|
||||
* 设置最大记录数,防止内存膨胀
|
||||
@ -108,7 +105,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
||||
* 事务的超时时间需要与普通操作区分开
|
||||
*/
|
||||
tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT);
|
||||
if (!PropertyUtil.isStandaloneMode()) {
|
||||
if (!STANDALONE_MODE) {
|
||||
try {
|
||||
reload();
|
||||
} catch (IOException e) {
|
||||
@ -241,7 +238,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
||||
}
|
||||
|
||||
public String getHealth() {
|
||||
for (int i = 0 ; i < isHealthList.size(); i++) {
|
||||
for (int i = 0; i < isHealthList.size(); i++) {
|
||||
if (!isHealthList.get(i)) {
|
||||
if (i == masterIndex) {
|
||||
/**
|
||||
|
@ -15,17 +15,16 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import com.alibaba.nacos.config.server.model.ACLInfo;
|
||||
import com.alibaba.nacos.config.server.utils.JSONUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.ACLInfo;
|
||||
import com.alibaba.nacos.config.server.utils.JSONUtils;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
/**
|
||||
* Client ip whitelist
|
||||
* @author Nacos
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.SubscriberStatus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.SubscriberStatus;
|
||||
|
||||
|
||||
/**
|
||||
* 跟踪客户端md5的服务。 一段时间没有比较md5后,就删除IP对应的记录。
|
||||
|
@ -15,9 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -15,34 +15,26 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.dumpLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoBase;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.CacheItem;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoBase;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey2;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.*;
|
||||
|
||||
/**
|
||||
* config service
|
||||
* @author Nacos
|
||||
@ -82,7 +74,7 @@ public class ConfigService {
|
||||
"[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
|
||||
+ "lastModifiedNew={}",
|
||||
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
|
||||
} else if (!PropertyUtil.isStandaloneMode()) {
|
||||
} else if (!STANDALONE_MODE) {
|
||||
DiskUtil.saveToDisk(dataId, group, tenant, content);
|
||||
}
|
||||
updateMd5(groupKey, md5, lastModifiedTs);
|
||||
@ -126,7 +118,7 @@ public class ConfigService {
|
||||
"[dump-beta-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
|
||||
+ "lastModifiedNew={}",
|
||||
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
|
||||
} else if (!PropertyUtil.isStandaloneMode()) {
|
||||
} else if (!STANDALONE_MODE) {
|
||||
DiskUtil.saveBetaToDisk(dataId, group, tenant, content);
|
||||
}
|
||||
String[] betaIpsArr = betaIps.split(",");
|
||||
@ -164,7 +156,7 @@ public class ConfigService {
|
||||
"[dump-tag-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
|
||||
+ "lastModifiedNew={}",
|
||||
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
|
||||
} else if (!PropertyUtil.isStandaloneMode()) {
|
||||
} else if (!STANDALONE_MODE) {
|
||||
DiskUtil.saveTagToDisk(dataId, group, tenant, tag, content);
|
||||
}
|
||||
|
||||
@ -196,7 +188,7 @@ public class ConfigService {
|
||||
|
||||
try {
|
||||
final String md5 = MD5.getInstance().getMD5String(content);
|
||||
if (!PropertyUtil.isStandaloneMode()) {
|
||||
if (!STANDALONE_MODE) {
|
||||
String loacalMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant);
|
||||
if(md5.equals(loacalMd5)) {
|
||||
dumpLog.warn(
|
||||
@ -222,7 +214,7 @@ public class ConfigService {
|
||||
{
|
||||
String aggreds = null;
|
||||
try {
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
ConfigInfoBase config = persistService.findConfigInfoBase(AggrWhitelist.AGGRIDS_METADATA, "DEFAULT_GROUP");
|
||||
if (config != null) {
|
||||
aggreds = config.getContent();
|
||||
@ -240,7 +232,7 @@ public class ConfigService {
|
||||
|
||||
String clientIpWhitelist = null;
|
||||
try {
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
ConfigInfoBase config = persistService.findConfigInfoBase(ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, "DEFAULT_GROUP");
|
||||
if (config != null) {
|
||||
clientIpWhitelist = config.getContent();
|
||||
@ -259,7 +251,7 @@ public class ConfigService {
|
||||
|
||||
String switchContent= null;
|
||||
try {
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
ConfigInfoBase config = persistService.findConfigInfoBase(SwitchService.SWITCH_META_DATAID, "DEFAULT_GROUP");
|
||||
if (config != null) {
|
||||
switchContent = config.getContent();
|
||||
@ -326,7 +318,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!PropertyUtil.isStandaloneMode()) {
|
||||
if (!STANDALONE_MODE) {
|
||||
DiskUtil.removeConfigInfo(dataId, group, tenant);
|
||||
}
|
||||
CACHE.remove(groupKey);
|
||||
@ -359,7 +351,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!PropertyUtil.isStandaloneMode()) {
|
||||
if (!STANDALONE_MODE) {
|
||||
DiskUtil.removeConfigInfo4Beta(dataId, group, tenant);
|
||||
}
|
||||
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey, true, CACHE.get(groupKey).getIps4Beta()));
|
||||
@ -394,7 +386,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!PropertyUtil.isStandaloneMode()) {
|
||||
if (!STANDALONE_MODE) {
|
||||
DiskUtil.removeConfigInfo4Tag(dataId, group, tenant, tag);
|
||||
}
|
||||
|
||||
|
@ -15,30 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletionService;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.codehaus.jackson.type.TypeReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.model.SampleResult;
|
||||
import com.alibaba.nacos.config.server.service.notify.NotifyService;
|
||||
@ -46,6 +22,18 @@ import com.alibaba.nacos.config.server.utils.JSONUtils;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
|
||||
import com.alibaba.nacos.config.server.utils.ThreadUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.codehaus.jackson.type.TypeReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
/**
|
||||
* config sub service
|
||||
* @author Nacos
|
||||
|
@ -15,21 +15,20 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
|
||||
|
||||
/**
|
||||
* 磁盘操作工具类。
|
||||
|
@ -15,11 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
|
||||
/**
|
||||
* datasource adapter
|
||||
* @author Nacos
|
||||
@ -40,7 +41,7 @@ public class DynamicDataSource implements ApplicationContextAware {
|
||||
public DataSourceService getDataSource() {
|
||||
DataSourceService dataSourceService = null;
|
||||
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
dataSourceService = (DataSourceService)applicationContext.getBean("localDataSourceService");
|
||||
} else {
|
||||
dataSourceService = (DataSourceService)applicationContext.getBean("basicDataSourceService");
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 本地数据发生变更的事件。
|
||||
* @author Nacos
|
||||
|
@ -15,6 +15,19 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
@ -25,28 +38,18 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
|
||||
/**
|
||||
* local data source
|
||||
*
|
||||
* @author Nacos
|
||||
*
|
||||
*/
|
||||
@Service("localDataSourceService")
|
||||
public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LocalDataSourceServiceImpl.class);
|
||||
|
||||
private static final String JDBC_DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver";
|
||||
private static final String DERBY_BASE_DIR = "data" + File.separator + "derby-data";
|
||||
private static String appHome = System.getProperty("user.home") + File.separator + "nacos";
|
||||
@ -86,7 +89,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
tm.setDataSource(ds);
|
||||
tjt.setTimeout(5000);
|
||||
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
reload();
|
||||
}
|
||||
}
|
||||
@ -98,8 +101,11 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
throw new RuntimeException("datasource is null");
|
||||
}
|
||||
try {
|
||||
execute(ds.getConnection(), "schema.sql");
|
||||
execute(ds.getConnection(), "META-INF/schema.sql");
|
||||
} catch (Exception e) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
throw new RuntimeException("load schema.sql error." + e);
|
||||
}
|
||||
}
|
||||
@ -131,6 +137,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
|
||||
/**
|
||||
* 读取SQL文件
|
||||
*
|
||||
* @param sqlFile sql
|
||||
* @return sqls
|
||||
* @throws Exception Exception
|
||||
@ -144,7 +151,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
URL url = classLoader.getResource(sqlFile);
|
||||
sqlFileIn = url.openStream();
|
||||
} else {
|
||||
File file = new File(System.getProperty(NACOS_HOME_KEY) + File.separator + "conf" + File.separator + sqlFile);
|
||||
File file = new File(System.getProperty(NACOS_HOME_KEY) + "/conf/schema.sql");
|
||||
sqlFileIn = new FileInputStream(file);
|
||||
}
|
||||
|
||||
@ -174,6 +181,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
|
||||
/**
|
||||
* 执行SQL语句
|
||||
*
|
||||
* @param conn connect
|
||||
* @param sqlFile sql
|
||||
* @throws Exception Exception
|
||||
|
@ -15,35 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.pullLog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.SampleResult;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
@ -51,13 +22,24 @@ import com.alibaba.nacos.config.server.utils.MD5Util;
|
||||
import com.alibaba.nacos.config.server.utils.RequestUtil;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.AbstractEventListener;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.pullLog;
|
||||
|
||||
/**
|
||||
* 长轮询服务。负责处理
|
||||
* @author Nacos
|
||||
*/
|
||||
@Service
|
||||
public class LongPullingService extends AbstractEventListener {
|
||||
public class LongPollingService extends AbstractEventListener {
|
||||
|
||||
private static final int FIXED_POLLING_INTERVAL_MS = 10000;
|
||||
|
||||
@ -222,8 +204,8 @@ public class LongPullingService extends AbstractEventListener {
|
||||
|
||||
public void addLongPullingClient(HttpServletRequest req, HttpServletResponse rsp, Map<String, String> clientMd5Map, int probeRequestSize) {
|
||||
|
||||
String str = req.getHeader(LongPullingService.LONG_PULLING_HEADER);
|
||||
String noHangUpFlag = req.getHeader(LongPullingService.LONG_PULLING_NO_HANG_UP_HEADER);
|
||||
String str = req.getHeader(LongPollingService.LONG_PULLING_HEADER);
|
||||
String noHangUpFlag = req.getHeader(LongPollingService.LONG_PULLING_NO_HANG_UP_HEADER);
|
||||
String appName = req.getHeader(RequestUtil.CLIENT_APPNAME_HEADER);
|
||||
String tag = req.getHeader("Vipserver-Tag");
|
||||
int delayTime=SwitchService.getSwitchInteger(SwitchService.FIXED_DELAY_TIME, 500);
|
||||
@ -285,7 +267,7 @@ public class LongPullingService extends AbstractEventListener {
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||
public LongPullingService() {
|
||||
public LongPollingService() {
|
||||
allSubs = new ConcurrentLinkedQueue<ClientLongPulling>();
|
||||
|
||||
scheduler = Executors.newScheduledThreadPool(1, new ThreadFactory() {
|
@ -15,25 +15,14 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import com.alibaba.nacos.config.server.model.*;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
import com.alibaba.nacos.config.server.utils.PaginationHelper;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||
import com.google.common.collect.Lists;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
@ -54,25 +43,17 @@ import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.ConfigAdvanceInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigAllInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo4Beta;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo4Tag;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoBase;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
|
||||
import com.alibaba.nacos.config.server.model.ConfigKey;
|
||||
import com.alibaba.nacos.config.server.model.Page;
|
||||
import com.alibaba.nacos.config.server.model.SubInfo;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
import com.alibaba.nacos.config.server.utils.PaginationHelper;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||
import com.google.common.collect.Lists;
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
/**
|
||||
* 数据库服务,提供ConfigInfo在数据库的存取<br>
|
||||
|
@ -15,39 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.utils.HttpClientUtils;
|
||||
import org.apache.http.concurrent.FutureCallback;
|
||||
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClients;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.service.notify.NotifyService;
|
||||
import com.alibaba.nacos.config.server.service.notify.NotifyService.HttpResult;
|
||||
@ -56,6 +23,33 @@ import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
|
||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.utils.HttpClientUtils;
|
||||
import org.apache.http.concurrent.FutureCallback;
|
||||
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClients;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
/**
|
||||
* Serverlist service
|
||||
@ -71,10 +65,8 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
||||
@Autowired
|
||||
private ServletContext servletContext;
|
||||
|
||||
@Value("${server.port}")
|
||||
private int port;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
serverPort = System.getProperty("nacos.server.port", "8848");
|
||||
@ -249,7 +241,7 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
||||
defaultLog.error("nacos-XXXX", "[serverlist] failed to get serverlist from disk!", e);
|
||||
}
|
||||
|
||||
if (isUseAddressServer() && !PropertyUtil.isStandaloneMode()) {
|
||||
if (isUseAddressServer() && !STANDALONE_MODE) {
|
||||
try {
|
||||
HttpResult result = NotifyService.invokeURL(addressServerUrl, null, null);
|
||||
|
||||
|
@ -15,19 +15,18 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
/**
|
||||
* Switch
|
||||
* @author Nacos
|
||||
|
@ -20,13 +20,12 @@ import com.alibaba.nacos.config.server.model.capacity.Capacity;
|
||||
import com.alibaba.nacos.config.server.model.capacity.GroupCapacity;
|
||||
import com.alibaba.nacos.config.server.model.capacity.TenantCapacity;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -17,16 +17,11 @@ package com.alibaba.nacos.config.server.service.capacity;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.capacity.Capacity;
|
||||
import com.alibaba.nacos.config.server.model.capacity.GroupCapacity;
|
||||
import com.alibaba.nacos.config.server.service.BasicDataSourceServiceImpl;
|
||||
import com.alibaba.nacos.config.server.service.DataSourceService;
|
||||
import com.alibaba.nacos.config.server.service.DynamicDataSource;
|
||||
import com.alibaba.nacos.config.server.service.LocalDataSourceServiceImpl;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.CannotGetJdbcConnectionException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@ -35,12 +30,12 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.sql.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
/**
|
||||
* Group Capacity Service
|
||||
@ -284,7 +279,7 @@ public class GroupCapacityPersistService {
|
||||
public List<GroupCapacity> getCapacityList4CorrectUsage(long lastId, int pageSize) {
|
||||
String sql = "select id, group_id from group_capacity where id>? limit ?";
|
||||
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
sql = "select id, group_id from group_capacity where id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
|
||||
}
|
||||
try {
|
||||
|
@ -16,16 +16,11 @@
|
||||
package com.alibaba.nacos.config.server.service.capacity;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.capacity.TenantCapacity;
|
||||
import com.alibaba.nacos.config.server.service.BasicDataSourceServiceImpl;
|
||||
import com.alibaba.nacos.config.server.service.DataSourceService;
|
||||
import com.alibaba.nacos.config.server.service.DynamicDataSource;
|
||||
import com.alibaba.nacos.config.server.service.LocalDataSourceServiceImpl;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.CannotGetJdbcConnectionException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@ -34,12 +29,12 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.sql.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
/**
|
||||
* Tenant Capacity Service
|
||||
@ -234,7 +229,7 @@ public class TenantCapacityPersistService {
|
||||
public List<TenantCapacity> getCapacityList4CorrectUsage(long lastId, int pageSize) {
|
||||
String sql = "select id, tenant_id from tenant_capacity where id>? limit ?";
|
||||
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
sql = "select id, tenant_id from tenant_capacity where id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
|
||||
}
|
||||
|
||||
|
@ -21,41 +21,33 @@ import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
|
||||
import com.alibaba.nacos.config.server.model.Page;
|
||||
import com.alibaba.nacos.config.server.service.ConfigService;
|
||||
import com.alibaba.nacos.config.server.service.DiskUtil;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.service.ServerListService;
|
||||
import com.alibaba.nacos.config.server.service.TimerTaskService;
|
||||
import com.alibaba.nacos.config.server.service.*;
|
||||
import com.alibaba.nacos.config.server.service.PersistService.ConfigInfoWrapper;
|
||||
import com.alibaba.nacos.config.server.service.merge.MergeTaskProcessor;
|
||||
import com.alibaba.nacos.config.server.utils.*;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
|
||||
/**
|
||||
* Dump data service
|
||||
@ -161,7 +153,7 @@ public class DumpService {
|
||||
throw new RuntimeException(
|
||||
"Nacos Server did not start because dumpservice bean construction failure :\n" + e.getMessage());
|
||||
}
|
||||
if (!PropertyUtil.isStandaloneMode()) {
|
||||
if (!STANDALONE_MODE) {
|
||||
Runnable heartbeat = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -15,22 +15,13 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service.dump;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.nacos.config.server.manager.AbstractTask;
|
||||
import com.alibaba.nacos.config.server.manager.TaskProcessor;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo4Beta;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo4Tag;
|
||||
import com.alibaba.nacos.config.server.model.Page;
|
||||
import com.alibaba.nacos.config.server.service.AggrWhitelist;
|
||||
import com.alibaba.nacos.config.server.service.ClientIpWhiteList;
|
||||
import com.alibaba.nacos.config.server.service.ConfigService;
|
||||
import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.service.SwitchService;
|
||||
import com.alibaba.nacos.config.server.service.*;
|
||||
import com.alibaba.nacos.config.server.service.PersistService.ConfigInfoBetaWrapper;
|
||||
import com.alibaba.nacos.config.server.service.PersistService.ConfigInfoTagWrapper;
|
||||
import com.alibaba.nacos.config.server.service.PersistService.ConfigInfoWrapper;
|
||||
@ -40,6 +31,11 @@ import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
|
||||
/**
|
||||
* Dump data task
|
||||
* @author Nacos
|
||||
|
@ -15,16 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service.merge;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.nacos.config.server.manager.TaskManager;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfo;
|
||||
import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
|
||||
@ -34,6 +24,15 @@ import com.alibaba.nacos.config.server.service.PersistService;
|
||||
import com.alibaba.nacos.config.server.utils.ContentUtils;
|
||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -29,13 +29,12 @@ import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -15,19 +15,13 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service.notify;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.service.ConfigDataChangeEvent;
|
||||
import com.alibaba.nacos.config.server.service.ServerListService;
|
||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||
import com.alibaba.nacos.config.server.utils.*;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.AbstractEventListener;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
@ -41,17 +35,14 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.service.ConfigDataChangeEvent;
|
||||
import com.alibaba.nacos.config.server.service.ServerListService;
|
||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.AbstractEventListener;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* Async notify service
|
||||
|
@ -15,21 +15,19 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service.notify;
|
||||
|
||||
import com.alibaba.nacos.config.server.manager.TaskManager;
|
||||
import com.alibaba.nacos.config.server.service.ServerListService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.nacos.config.server.manager.TaskManager;
|
||||
import com.alibaba.nacos.config.server.service.ServerListService;
|
||||
|
||||
|
||||
/**
|
||||
* 通知其他节点取最新数据的服务。 监听数据变更事件,通知所有的server。
|
||||
|
@ -15,23 +15,16 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service.notify;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.alibaba.nacos.config.server.manager.AbstractTask;
|
||||
import com.alibaba.nacos.config.server.service.ServerListService;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey2;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* Notify Single server
|
||||
|
@ -15,14 +15,6 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service.notify;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.manager.AbstractTask;
|
||||
import com.alibaba.nacos.config.server.manager.TaskProcessor;
|
||||
@ -31,6 +23,13 @@ import com.alibaba.nacos.config.server.service.notify.NotifyService.HttpResult;
|
||||
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
|
||||
import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
|
||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -18,8 +18,7 @@ package com.alibaba.nacos.config.server.service.trace;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
import com.alibaba.nacos.config.server.utils.SystemConfig;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
/**
|
||||
* Config trace
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import static com.alibaba.nacos.config.server.constant.Constants.WORD_SEPARATOR;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
|
||||
import static com.alibaba.nacos.config.server.constant.Constants.WORD_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Content utils
|
||||
* @author Nacos
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.map.DeserializationConfig.Feature;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.type.JavaType;
|
||||
import org.codehaus.jackson.type.TypeReference;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* json util
|
||||
* @author Nacos
|
||||
|
@ -17,9 +17,6 @@ package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.joran.JoranConfigurator;
|
||||
import ch.qos.logback.core.joran.spi.JoranException;
|
||||
|
||||
/**
|
||||
* log util
|
||||
@ -28,30 +25,6 @@ import ch.qos.logback.core.joran.spi.JoranException;
|
||||
*/
|
||||
public class LogUtil {
|
||||
|
||||
static {
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
lc.reset();
|
||||
|
||||
JoranConfigurator configurator = new JoranConfigurator();
|
||||
|
||||
String nacosDir = System.getProperty("nacos.home");
|
||||
if (StringUtils.isBlank(nacosDir)) {
|
||||
configurator.setContext(lc);
|
||||
try {
|
||||
configurator.doConfigure(LogUtil.class.getResource("/nacos-config-logback.xml"));
|
||||
} catch (JoranException e) {
|
||||
System.err.println("init logger fail by nacos-config-logback.xml");
|
||||
}
|
||||
} else {
|
||||
configurator.setContext(lc);
|
||||
try {
|
||||
configurator.doConfigure(nacosDir + "/conf/nacos-logback.xml");
|
||||
} catch (JoranException e) {
|
||||
System.err.println("init logger fail by " + nacosDir + "/conf/nacos-logback.xml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认的日志
|
||||
*/
|
||||
|
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
|
||||
/**
|
||||
* md5
|
||||
* @author Nacos
|
||||
|
@ -15,28 +15,21 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import static com.alibaba.nacos.config.server.constant.Constants.LINE_SEPARATOR;
|
||||
import static com.alibaba.nacos.config.server.constant.Constants.WORD_SEPARATOR;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.service.ConfigService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.service.ConfigService;
|
||||
import static com.alibaba.nacos.config.server.constant.Constants.LINE_SEPARATOR;
|
||||
import static com.alibaba.nacos.config.server.constant.Constants.WORD_SEPARATOR;
|
||||
|
||||
/**
|
||||
* 轮询逻辑封装类
|
||||
|
@ -15,12 +15,13 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.Page;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import com.alibaba.nacos.config.server.model.Page;
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
|
||||
|
||||
/**
|
||||
@ -88,7 +89,7 @@ public class PaginationHelper<E> {
|
||||
|
||||
final int startRow = (pageNo - 1) * pageSize;
|
||||
String selectSQL = "";
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
selectSQL = sqlFetchRows + " OFFSET "+startRow+" ROWS FETCH NEXT "+pageSize+" ROWS ONLY";
|
||||
} else if (lastMaxId != null) {
|
||||
selectSQL = sqlFetchRows + " and id > " + lastMaxId + " order by id asc" + " limit " + 0 + "," + pageSize;
|
||||
@ -132,7 +133,7 @@ public class PaginationHelper<E> {
|
||||
}
|
||||
|
||||
String selectSQL = sqlFetchRows;
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
|
||||
}
|
||||
|
||||
@ -172,7 +173,7 @@ public class PaginationHelper<E> {
|
||||
}
|
||||
|
||||
String selectSQL = sqlFetchRows;
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
|
||||
}
|
||||
|
||||
@ -192,7 +193,7 @@ public class PaginationHelper<E> {
|
||||
final Page<E> page = new Page<E>();
|
||||
|
||||
String selectSQL = sqlFetchRows;
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
|
||||
}
|
||||
|
||||
@ -206,7 +207,7 @@ public class PaginationHelper<E> {
|
||||
public void updateLimit(final JdbcTemplate jt, final String sql, final Object args[]) {
|
||||
String sqlUpdate = sql;
|
||||
|
||||
if (PropertyUtil.isStandaloneMode()) {
|
||||
if (STANDALONE_MODE) {
|
||||
sqlUpdate = sqlUpdate.replaceAll("limit \\?", "OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.alibaba.nacos.config.server.exception.NacosException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 参数合法性检查工具类
|
||||
|
@ -15,18 +15,19 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
|
||||
/**
|
||||
* properties utils
|
||||
*
|
||||
* @author Nacos
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class PropertyUtil {
|
||||
@ -80,15 +81,9 @@ public class PropertyUtil {
|
||||
*/
|
||||
private static int correctUsageDelay = 10 * 60;
|
||||
|
||||
private static boolean standaloneMode = false;
|
||||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
|
||||
static {
|
||||
setStandaloneMode(Boolean.parseBoolean(System.getProperty("nacos.standalone", "false")));
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
try {
|
||||
@ -206,11 +201,7 @@ public class PropertyUtil {
|
||||
}
|
||||
|
||||
public static boolean isStandaloneMode() {
|
||||
return standaloneMode;
|
||||
}
|
||||
|
||||
public static void setStandaloneMode(boolean standaloneMode) {
|
||||
PropertyUtil.standaloneMode = standaloneMode;
|
||||
return STANDALONE_MODE;
|
||||
}
|
||||
|
||||
public static void setNotifyConnectTimeout(int notifyConnectTimeout) {
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import org.apache.commons.lang.CharUtils;
|
||||
import org.apache.commons.lang.NullArgumentException;
|
||||
|
||||
import org.apache.commons.lang3.CharUtils;
|
||||
|
||||
|
||||
/**
|
||||
@ -40,7 +38,7 @@ public class RegexParser {
|
||||
*/
|
||||
static public String regexFormat(String regex) {
|
||||
if (regex == null) {
|
||||
throw new NullArgumentException("regex string can't be null");
|
||||
throw new NullPointerException("regex string can't be null");
|
||||
}
|
||||
StringBuffer result = new StringBuffer();
|
||||
result.append("^");
|
||||
@ -75,8 +73,4 @@ public class RegexParser {
|
||||
return (regex.contains("?") || regex.contains("*"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str = "com.taobao.uic.*";
|
||||
System.out.println(str + " -> " + regexFormat(str));
|
||||
}
|
||||
}
|
||||
|
@ -15,16 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
|
||||
|
||||
/**
|
||||
* resource util
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
|
||||
|
||||
/**
|
||||
* write response
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* Running config
|
||||
* @author dungu.zpf
|
||||
|
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* System config
|
||||
* @author Nacos
|
||||
|
@ -15,15 +15,17 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
|
||||
import org.apache.commons.lang3.time.FastDateFormat;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang.time.FastDateFormat;
|
||||
/**
|
||||
* Time util
|
||||
* @author Nacos
|
||||
*
|
||||
* @author Nacos
|
||||
*/
|
||||
public class TimeUtils {
|
||||
|
||||
@ -31,9 +33,6 @@ public class TimeUtils {
|
||||
Date date = new Date();
|
||||
return new Timestamp(date.getTime());
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(getCurrentTime().toString());
|
||||
}
|
||||
|
||||
static public String getCurrentTimeStr() {
|
||||
Calendar c = Calendar.getInstance();
|
||||
|
@ -15,11 +15,11 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
|
||||
|
||||
/**
|
||||
* 分析url的工具类
|
||||
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.utils.event;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* Event dispatcher
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
|
||||
<included>
|
||||
<appender name="dumpFile"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${user.home}/nacos/logs/config-dump.log</file>
|
||||
@ -220,64 +218,65 @@
|
||||
</appender>
|
||||
|
||||
<logger name="com.alibaba.nacos.config.dumpLog" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="dumpFile" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="dumpFile"/>
|
||||
</logger>
|
||||
<logger name="com.alibaba.nacos.config.pullLog" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="pullFile" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="pullFile"/>
|
||||
</logger>
|
||||
<logger name="com.alibaba.nacos.config.pullCheckLog" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="pullCheckFile" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="pullCheckFile"/>
|
||||
</logger>
|
||||
<logger name="com.alibaba.nacos.config.fatal" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="fatalFile" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="fatalFile"/>
|
||||
</logger>
|
||||
<logger name="com.alibaba.nacos.config.monitorLog" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="memoryFile" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="memoryFile"/>
|
||||
</logger>
|
||||
|
||||
<logger name="com.alibaba.nacos.config.aclLog" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="aclLog" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="aclLog"/>
|
||||
</logger>
|
||||
|
||||
<logger name="com.alibaba.nacos.config.clientLog" additivity="false">
|
||||
<level value="info" />
|
||||
<appender-ref ref="clientLog" />
|
||||
<level value="info"/>
|
||||
<appender-ref ref="clientLog"/>
|
||||
</logger>
|
||||
|
||||
<logger name="com.alibaba.nacos.config.sdkLog" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="sdkLog" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="sdkLog"/>
|
||||
</logger>
|
||||
|
||||
<logger name="com.alibaba.nacos.config.notifyLog" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="notifyLog" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="notifyLog"/>
|
||||
</logger>
|
||||
|
||||
<logger name="com.alibaba.nacos.config.traceLog" additivity="false">
|
||||
<level value="info" />
|
||||
<appender-ref ref="traceLog" />
|
||||
<level value="info"/>
|
||||
<appender-ref ref="traceLog"/>
|
||||
</logger>
|
||||
|
||||
<logger name="com.alibaba.nacos.config.appCollectorLog" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="appCollectorLog" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="appCollectorLog"/>
|
||||
</logger>
|
||||
|
||||
<logger name="com.alibaba.nacos.config.startLog" additivity="false">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="startLog" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="startLog"/>
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="rootFile" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="rootFile"/>
|
||||
</root>
|
||||
</configuration>
|
||||
|
||||
</included>
|
||||
|
@ -1,17 +0,0 @@
|
||||
# spring
|
||||
management.security.enabled=false
|
||||
server.servlet.context-path=/nacos
|
||||
server.port=8848
|
||||
|
||||
db.num=2
|
||||
db.url.0=url1
|
||||
db.url.1=url2
|
||||
db.user=user
|
||||
db.password=pwd
|
||||
|
||||
spring.http.encoding.force=true
|
||||
spring.http.encoding.charset=UTF-8
|
||||
spring.http.encoding.enabled=true
|
||||
server.tomcat.uri-encoding=UTF-8
|
||||
spring.messages.encoding=UTF-8
|
||||
security.headers.content-type=application/json;charset=UTF-8
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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.config.mock;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
|
||||
|
||||
public class FilterConfigMock implements FilterConfig {
|
||||
|
||||
public FilterConfigMock(ServletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getFilterName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletContext getServletContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration getInitParameterNames() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
final ServletContext context;
|
||||
}
|
@ -1,356 +0,0 @@
|
||||
/*
|
||||
* 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.config.mock;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.EventListener;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterRegistration;
|
||||
import javax.servlet.FilterRegistration.Dynamic;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRegistration;
|
||||
import javax.servlet.SessionCookieConfig;
|
||||
import javax.servlet.SessionTrackingMode;
|
||||
import javax.servlet.descriptor.JspConfigDescriptor;
|
||||
|
||||
|
||||
|
||||
|
||||
public class ServletContextMock implements ServletContext {
|
||||
|
||||
@Override
|
||||
public String getContextPath() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletContext getContext(String uripath) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMimeType(String file) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set getResourcePaths(String path) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getResource(String path) throws MalformedURLException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String path) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestDispatcher getRequestDispatcher(String path) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestDispatcher getNamedDispatcher(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Servlet getServlet(String name) throws ServletException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration getServlets() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration getServletNames() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String msg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Exception exception, String msg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message, Throwable throwable) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRealPath(String path) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerInfo() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration getInitParameterNames() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration getAttributeNames() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object object) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServletContextName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dynamic addFilter(String arg0, String arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dynamic addFilter(String arg0, Filter arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dynamic addFilter(String arg0, Class<? extends Filter> arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(Class<? extends EventListener> arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(String arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends EventListener> void addListener(T arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public javax.servlet.ServletRegistration.Dynamic addServlet(String arg0, String arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public javax.servlet.ServletRegistration.Dynamic addServlet(String arg0, Servlet arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public javax.servlet.ServletRegistration.Dynamic addServlet(String arg0,
|
||||
Class<? extends Servlet> arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Filter> T createFilter(Class<T> arg0) throws ServletException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends EventListener> T createListener(Class<T> arg0) throws ServletException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Servlet> T createServlet(Class<T> arg0) throws ServletException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void declareRoles(String... arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getClassLoader() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEffectiveMajorVersion() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEffectiveMinorVersion() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterRegistration getFilterRegistration(String arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JspConfigDescriptor getJspConfigDescriptor() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletRegistration getServletRegistration(String arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends ServletRegistration> getServletRegistrations() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionCookieConfig getSessionCookieConfig() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setInitParameter(String arg0, String arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSessionTrackingModes(Set<SessionTrackingMode> arg0)
|
||||
throws IllegalStateException, IllegalArgumentException {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVirtualServerName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
///*
|
||||
// * Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
// * contributor license agreements. See the NOTICE file distributed with
|
||||
// * this work for additional information regarding copyright ownership.
|
||||
// * The ASF licenses this file to You 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.config.server.configuration;
|
||||
//
|
||||
//import org.apache.commons.dbcp.BasicDataSource;
|
||||
//import org.junit.Assert;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.annotation.Qualifier;
|
||||
//import org.springframework.jdbc.core.JdbcTemplate;
|
||||
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
//import org.springframework.test.context.ActiveProfiles;
|
||||
//import org.springframework.test.context.ContextConfiguration;
|
||||
//import org.springframework.test.context.TestPropertySource;
|
||||
//import org.springframework.test.context.junit4.SpringRunner;
|
||||
//import org.springframework.transaction.PlatformTransactionManager;
|
||||
//
|
||||
//import javax.sql.DataSource;
|
||||
//
|
||||
//import static com.alibaba.nacos.config.server.configuration.DataBaseConfiguration.DATA_SOURCE_BEAN_NAME;
|
||||
//
|
||||
///**
|
||||
// * {@link LocalDataSourceConfiguration} Test
|
||||
// *
|
||||
// * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
// * @since 0.2.2
|
||||
// */
|
||||
//@RunWith(SpringRunner.class)
|
||||
//@ContextConfiguration(classes = {
|
||||
// LocalDataSourceConfiguration.class,
|
||||
// DataBaseConfiguration.class,
|
||||
// LocalDataSourceConfigurationTest.class
|
||||
//})
|
||||
//@TestPropertySource(properties = {
|
||||
// "db.initialSize=1",
|
||||
// "db.maxActive=2",
|
||||
// "db.maxIdle=3",
|
||||
// "db.maxWait=4",
|
||||
//})
|
||||
//@ActiveProfiles("standalone")
|
||||
//public class LocalDataSourceConfigurationTest {
|
||||
//
|
||||
// @Autowired
|
||||
// @Qualifier(DATA_SOURCE_BEAN_NAME)
|
||||
// private DataSource nacosConfigDataSource;
|
||||
//
|
||||
// @Autowired
|
||||
// private JdbcTemplate jdbcTemplate;
|
||||
//
|
||||
// @Autowired
|
||||
// private PlatformTransactionManager platformTransactionManager;
|
||||
//
|
||||
// @Test
|
||||
// public void testDataSource() {
|
||||
// Assert.assertNotNull(nacosConfigDataSource);
|
||||
// Assert.assertTrue(nacosConfigDataSource instanceof BasicDataSource);
|
||||
// BasicDataSource dataSource = BasicDataSource.class.cast(nacosConfigDataSource);
|
||||
// Assert.assertEquals(1, dataSource.getInitialSize());
|
||||
// Assert.assertEquals(2, dataSource.getMaxActive());
|
||||
// Assert.assertEquals(3, dataSource.getMaxIdle());
|
||||
// Assert.assertEquals(4, dataSource.getMaxWait());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testJdbcTemplate() {
|
||||
// Assert.assertEquals(jdbcTemplate.getDataSource(), nacosConfigDataSource);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testPlatformTransactionManager() {
|
||||
// Assert.assertTrue(platformTransactionManager instanceof DataSourceTransactionManager);
|
||||
// DataSourceTransactionManager transactionManager = (DataSourceTransactionManager) platformTransactionManager;
|
||||
// Assert.assertEquals(transactionManager.getDataSource(), nacosConfigDataSource);
|
||||
// }
|
||||
//
|
||||
//}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.config.server.constant;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static com.alibaba.nacos.config.server.constant.Constants.*;
|
||||
|
||||
/**
|
||||
* {@link Constants} Test
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.2
|
||||
*/
|
||||
public class ConstantsTest {
|
||||
|
||||
@Test
|
||||
public void testControllerPathsDefaultValues() {
|
||||
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
Assert.assertEquals(DEFAULT_CAPACITY_CONTROLLER_PATH, environment.resolvePlaceholders(CAPACITY_CONTROLLER_PATH));
|
||||
Assert.assertEquals(DEFAULT_COMMUNICATION_CONTROLLER_PATH, environment.resolvePlaceholders(COMMUNICATION_CONTROLLER_PATH));
|
||||
Assert.assertEquals(DEFAULT_CONFIG_CONTROLLER_PATH, environment.resolvePlaceholders(CONFIG_CONTROLLER_PATH));
|
||||
Assert.assertEquals(DEFAULT_HEALTH_CONTROLLER_PATH, environment.resolvePlaceholders(HEALTH_CONTROLLER_PATH));
|
||||
Assert.assertEquals(DEFAULT_HISTORY_CONTROLLER_PATH, environment.resolvePlaceholders(HISTORY_CONTROLLER_PATH));
|
||||
Assert.assertEquals(DEFAULT_LISTENER_CONTROLLER_PATH, environment.resolvePlaceholders(LISTENER_CONTROLLER_PATH));
|
||||
Assert.assertEquals(DEFAULT_NAMESPACE_CONTROLLER_PATH, environment.resolvePlaceholders(NAMESPACE_CONTROLLER_PATH));
|
||||
|
||||
|
||||
Assert.assertEquals("/nacos/v1/cs/capacity", DEFAULT_CAPACITY_CONTROLLER_PATH);
|
||||
Assert.assertEquals("/nacos/v1/cs/communication", DEFAULT_COMMUNICATION_CONTROLLER_PATH);
|
||||
Assert.assertEquals("/nacos/v1/cs/configs", DEFAULT_CONFIG_CONTROLLER_PATH);
|
||||
Assert.assertEquals("/nacos/v1/cs/health", DEFAULT_HEALTH_CONTROLLER_PATH);
|
||||
Assert.assertEquals("/nacos/v1/cs/history", DEFAULT_HISTORY_CONTROLLER_PATH);
|
||||
Assert.assertEquals("/nacos/v1/cs/listener", DEFAULT_LISTENER_CONTROLLER_PATH);
|
||||
Assert.assertEquals("/nacos/v1/cs/namespaces", DEFAULT_NAMESPACE_CONTROLLER_PATH);
|
||||
}
|
||||
}
|
@ -18,7 +18,8 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-all</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>nacos-console</artifactId>
|
||||
<!--<packaging>war</packaging>-->
|
||||
@ -34,33 +35,17 @@
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-jasper</artifactId>
|
||||
<version>7.0.59</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-naming</artifactId>
|
||||
</dependency>
|
||||
<!-- log -->
|
||||
<!-- log4j通过slf4j来代理 -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
</dependency>
|
||||
<!-- apache commons logging通过slf4j来代理 -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
</dependency>
|
||||
<!-- java.util.logging 通过slf4j来代理 -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jul-to-slf4j</artifactId>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-jasper</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- log -->
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>nacos-server</finalName>
|
||||
|
@ -1,8 +1,5 @@
|
||||
# spring
|
||||
management.security.enabled=false
|
||||
server.contextPath=/nacos
|
||||
server.servlet.contextPath=/nacos
|
||||
server.port=8848
|
||||
# Console Default Properties
|
||||
|
||||
spring.mvc.view.prefix=/jsp/
|
||||
# 响应页面默认后缀
|
||||
spring.mvc.view.suffix=.jsp
|
@ -1,15 +0,0 @@
|
||||
|
||||
,--.
|
||||
,--.'|
|
||||
,--,: : |
|
||||
,`--.'`| ' : ,---.
|
||||
| : : | | ' ,'\ .--.--.
|
||||
: | \ | : ,--.--. ,---. / / | / / '
|
||||
| : ' '; | / \ / \. ; ,. :| : /`./
|
||||
' ' ;. ;.--. .-. | / / '' | |: :| : ;_
|
||||
| | | \ | \__\/: . .. ' / ' | .; : \ \ `.
|
||||
' : | ; .' ," .--.; |' ; :__| : | `----. \
|
||||
| | '`--' / / ,. |' | '.'|\ \ / / /`--' /
|
||||
' : | ; : .' \ : : `----' '--'. /
|
||||
; |.' | , .-./\ \ / `--'---'
|
||||
'---' `--`---' `----'
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user