Merge pull request #124 from alibaba/0.2.2

0.2.2
This commit is contained in:
小马哥 2018-10-15 17:10:57 +08:00 committed by GitHub
commit e05bc7a682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
141 changed files with 3750 additions and 4479 deletions

View File

@ -16,7 +16,8 @@
<parent> <parent>
<groupId>com.alibaba.nacos</groupId> <groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId> <artifactId>nacos-all</artifactId>
<version>0.2.1</version> <version>0.2.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -32,10 +33,25 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
</dependency> </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> </dependencies>
</project> </project>

View File

@ -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 );
}
}

View File

@ -16,7 +16,8 @@
<parent> <parent>
<groupId>com.alibaba.nacos</groupId> <groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId> <artifactId>nacos-all</artifactId>
<version>0.2.1</version> <version>0.2.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -32,67 +33,46 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<scope>provided</scope> <optional>true</optional>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
<version>2.8.2</version> <version>2.8.2</version>
<scope>provided</scope> <optional>true</optional>
</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>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId> <artifactId>log4j-slf4j-impl</artifactId>
<scope>provided</scope> <optional>true</optional>
</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>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>nacos-common</artifactId> <artifactId>nacos-common</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>nacos-api</artifactId> <artifactId>nacos-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId> <artifactId>logback-core</artifactId>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
@ -114,11 +94,19 @@
<artifactId>jcip-annotations</artifactId> <artifactId>jcip-annotations</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.spotbugs</groupId> <groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId> <artifactId>spotbugs-annotations</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -15,16 +15,15 @@
*/ */
package com.alibaba.nacos.client.logger; 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.log4j2.Log4j2LoggerFactory;
import com.alibaba.nacos.client.logger.nop.NopLoggerFactory; import com.alibaba.nacos.client.logger.nop.NopLoggerFactory;
import com.alibaba.nacos.client.logger.slf4j.Slf4jLoggerFactory; import com.alibaba.nacos.client.logger.slf4j.Slf4jLoggerFactory;
import com.alibaba.nacos.client.logger.support.ILoggerFactory; import com.alibaba.nacos.client.logger.support.ILoggerFactory;
import com.alibaba.nacos.client.logger.support.LogLog; import com.alibaba.nacos.client.logger.support.LogLog;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* <pre> * <pre>
* 阿里中间件LoggerFactory获取具体日志实现 * 阿里中间件LoggerFactory获取具体日志实现
@ -56,20 +55,15 @@ public class LoggerFactory {
setLoggerFactory(new Slf4jLoggerFactory()); setLoggerFactory(new Slf4jLoggerFactory());
LogLog.info("Init JM logger with Slf4jLoggerFactory success, " + LoggerFactory.class.getClassLoader()); LogLog.info("Init JM logger with Slf4jLoggerFactory success, " + LoggerFactory.class.getClassLoader());
} catch (Throwable e1) { } catch (Throwable e1) {
try {
setLoggerFactory(new Log4jLoggerFactory());
LogLog.info("Init JM logger with Log4jLoggerFactory, " + LoggerFactory.class.getClassLoader());
} catch (Throwable e2) {
try { try {
setLoggerFactory(new Log4j2LoggerFactory()); setLoggerFactory(new Log4j2LoggerFactory());
LogLog.info("Init JM logger with Log4j2LoggerFactory, " + LoggerFactory.class.getClassLoader()); LogLog.info("Init JM logger with Log4j2LoggerFactory, " + LoggerFactory.class.getClassLoader());
} catch (Throwable e3) { } catch (Throwable e2) {
setLoggerFactory(new NopLoggerFactory()); setLoggerFactory(new NopLoggerFactory());
LogLog.warn("Init JM logger with NopLoggerFactory, pay attention. " LogLog.warn("Init JM logger with NopLoggerFactory, pay attention. "
+ LoggerFactory.class.getClassLoader(), e2); + LoggerFactory.class.getClassLoader(), e2);
} }
} }
}
loggerCache = new ConcurrentHashMap<String, Logger>(); loggerCache = new ConcurrentHashMap<String, Logger>();
} }

View File

@ -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);
}
}

View File

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

View File

@ -15,8 +15,6 @@
*/ */
package com.alibaba.nacos.client.logger.option; 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.Level;
import com.alibaba.nacos.client.logger.support.LogLog; import com.alibaba.nacos.client.logger.support.LogLog;

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -15,24 +15,25 @@
*/ */
package com.alibaba.nacos.client.logger.slf4j; 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.Logger;
import com.alibaba.nacos.client.logger.option.ActivateOption; import com.alibaba.nacos.client.logger.option.ActivateOption;
import com.alibaba.nacos.client.logger.support.LoggerHelper; import com.alibaba.nacos.client.logger.support.LoggerHelper;
import com.alibaba.nacos.client.logger.support.LoggerSupport; import com.alibaba.nacos.client.logger.support.LoggerSupport;
import com.alibaba.nacos.client.logger.util.MessageUtil; import com.alibaba.nacos.client.logger.util.MessageUtil;
import java.lang.reflect.Constructor;
/** /**
* slf4j logger * slf4j logger
* @author Nacos
* *
* @author Nacos
*/ */
public class Slf4jLogger extends LoggerSupport implements Logger { public class Slf4jLogger extends LoggerSupport implements Logger {
private static boolean CanUseEncoder = false; private static boolean CanUseEncoder = false;
private static final String LOGBACK_CLASSNAME = "ch.qos.logback.classic.Logger"; 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"; private static final String SLF4JLOG4J_CLASSNAME = "org.apache.logging.slf4j.Log4jLogger";
static { static {
try { try {
// logback从0.9.19开始采用encoder@see http://logback.qos.ch/manual/encoders.html // 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; private org.slf4j.Logger delegate;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public public Slf4jLogger(org.slf4j.Logger delegate) {
Slf4jLogger(org.slf4j.Logger delegate){
super(delegate); super(delegate);
if (delegate == null) { if (delegate == null) {
throw new IllegalArgumentException("delegate Logger is null"); throw new IllegalArgumentException("delegate Logger is null");
@ -61,8 +61,6 @@ public class Slf4jLogger extends LoggerSupport implements Logger {
} else { } else {
activateOptionClass = "com.alibaba.nacos.client.logger.option.Logback918ActivateOption"; 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())) { } else if (SLF4JLOG4J_CLASSNAME.equals(delegate.getClass().getName())) {
activateOptionClass = "com.alibaba.nacos.client.logger.option.Slf4jLog4j2AdapterActivateOption"; activateOptionClass = "com.alibaba.nacos.client.logger.option.Slf4jLog4j2AdapterActivateOption";
} }

View File

@ -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;
}
}

View File

@ -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);
}
}
}
}

View File

@ -229,9 +229,6 @@ public class ConcurrentDiskUtil {
} }
} }
public static void main(String[] args) {
}
static final public Logger log = LogUtils.LOG; static final public Logger log = LogUtils.LOG;
static final int RETRY_COUNT = 10; static final int RETRY_COUNT = 10;
static final int SLEEP_BASETIME = 10; static final int SLEEP_BASETIME = 10;

View File

@ -175,12 +175,6 @@ public class HttpClient {
return sb.toString(); 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 { public static class HttpResult {
final public int code; final public int code;
final public String content; final public String content;

View File

@ -18,7 +18,8 @@
<parent> <parent>
<groupId>com.alibaba.nacos</groupId> <groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId> <artifactId>nacos-all</artifactId>
<version>0.2.1</version> <version>0.2.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -33,19 +34,28 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -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"));
}
}

View File

@ -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";
}

View File

@ -15,11 +15,9 @@
*/ */
package com.alibaba.nacos.common.util; package com.alibaba.nacos.common.util;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.io.IOUtils;
import java.io.*; import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
/** /**
@ -29,120 +27,6 @@ import java.util.zip.GZIPInputStream;
*/ */
public class IoUtils { 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 { public static byte[] tryDecompress(InputStream raw) throws Exception {
try { try {
@ -151,8 +35,7 @@ public class IoUtils {
ByteArrayOutputStream out ByteArrayOutputStream out
= new ByteArrayOutputStream(); = new ByteArrayOutputStream();
IOUtils.copy(gis, out);
IoUtils.copy(gis, out);
return out.toByteArray(); return out.toByteArray();
} catch (Exception e) { } catch (Exception e) {
@ -162,12 +45,5 @@ public class IoUtils {
return null; return null;
} }
public static void main(String[] args) throws IOException {
// String path = "/Users/zhupengfei/test_write.txt";
// writeStringToFile(new File(path), "hello2222", "utf-8");
}
} }

View File

@ -16,18 +16,28 @@
package com.alibaba.nacos.common.util; package com.alibaba.nacos.common.util;
import com.sun.management.OperatingSystemMXBean;
import org.apache.commons.lang3.StringUtils;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.sun.management.OperatingSystemMXBean;
/** /**
* @author nacos * @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(); private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
@ -45,10 +55,6 @@ public class SystemUtil {
return env; return env;
} }
public static void main(String[] args) throws SQLException {
System.out.println(Boolean.parseBoolean("Tfue"));
}
public static float getLoad() { public static float getLoad() {
return (float) operatingSystemMXBean.getSystemLoadAverage(); return (float) operatingSystemMXBean.getSystemLoadAverage();
} }

View File

@ -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);
}
}

View File

@ -17,7 +17,8 @@
<parent> <parent>
<groupId>com.alibaba.nacos</groupId> <groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId> <artifactId>nacos-all</artifactId>
<version>0.2.1</version> <version>0.2.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -33,39 +34,27 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>nacos-core</artifactId> <artifactId>nacos-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
</dependency> </dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId> <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
@ -98,10 +87,6 @@
</dependency> </dependency>
<!-- Provided --> <!-- Provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.jackson</groupId> <groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-lgpl</artifactId> <artifactId>jackson-mapper-lgpl</artifactId>
@ -115,7 +100,33 @@
<groupId>com.github.spotbugs</groupId> <groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId> <artifactId>spotbugs-annotations</artifactId>
</dependency> </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> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -143,13 +154,9 @@
</plugins> </plugins>
<resources> <resources>
<resource> <resource>
<filtering>true</filtering>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<excludes> <excludes>
<exclude>application.properties</exclude> <exclude>application.properties</exclude>
<exclude>banner.txt</exclude>
<exclude>schema.sql</exclude>
<exclude>nacos-db.sql</exclude>
</excludes> </excludes>
</resource> </resource>
</resources> </resources>

View File

@ -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";
}
}
}

View File

@ -15,26 +15,20 @@
*/ */
package com.alibaba.nacos.config.server; package com.alibaba.nacos.config.server;
import java.net.UnknownHostException;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; 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 * Config main
* *
* @author Nacos * @author Nacos
*
*/ */
@SpringBootApplication(scanBasePackages = "com.alibaba.nacos.config.server") @SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@ServletComponentScan
public class Config { public class Config {
public static void main(String[] args) throws UnknownHostException { public static void main(String[] args) throws UnknownHostException {
SpringApplication.run(Config.class, args); SpringApplication.run(Config.class, args);
} }
} }

View File

@ -15,19 +15,6 @@
*/ */
package com.alibaba.nacos.config.server.aspect; 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.Constants;
import com.alibaba.nacos.config.server.constant.CounterMode; import com.alibaba.nacos.config.server.constant.CounterMode;
import com.alibaba.nacos.config.server.model.ConfigInfo; 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.PersistService;
import com.alibaba.nacos.config.server.service.capacity.CapacityService; import com.alibaba.nacos.config.server.service.capacity.CapacityService;
import com.alibaba.nacos.config.server.utils.PropertyUtil; 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;
/** /**
* 容量管理切面批量写入更新暂不处理 * 容量管理切面批量写入更新暂不处理

View File

@ -15,18 +15,17 @@
*/ */
package com.alibaba.nacos.config.server.aspect; 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.service.ConfigService;
import com.alibaba.nacos.config.server.utils.GroupKey2; import com.alibaba.nacos.config.server.utils.GroupKey2;
import com.alibaba.nacos.config.server.utils.LogUtil; import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.config.server.utils.MD5; import com.alibaba.nacos.config.server.utils.MD5;
import com.alibaba.nacos.config.server.utils.RequestUtil; 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 * * Created with IntelliJ IDEA. User: dingjoey Date: 13-12-12 Time: 21:12

View File

@ -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 {
// }
// }
//}

View File

@ -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;
// }
//
//}

View File

@ -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;
// }
//
//}

View File

@ -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 {
}

View File

@ -17,8 +17,8 @@ package com.alibaba.nacos.config.server.constant;
/** /**
* Server Constants * Server Constants
* @author Nacos
* *
* @author Nacos
*/ */
public class Constants { public class Constants {
@ -101,23 +101,43 @@ public class Constants {
*/ */
public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5; 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"; public static final String ENCODE = "UTF-8";

View File

@ -15,9 +15,11 @@
*/ */
package com.alibaba.nacos.config.server.controller; package com.alibaba.nacos.config.server.controller;
import javax.servlet.http.HttpServletResponse; import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.RestResult;
import org.apache.commons.lang.StringUtils; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.nacos.config.server.constant.Constants; import javax.servlet.http.HttpServletResponse;
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;
/** /**
* capcity manage * capcity manage

View File

@ -15,13 +15,12 @@
*/ */
package com.alibaba.nacos.config.server.controller; package com.alibaba.nacos.config.server.controller;
import java.io.IOException; import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.SampleResult;
import javax.servlet.ServletException; import com.alibaba.nacos.config.server.service.LongPollingService;
import javax.servlet.http.HttpServletRequest; import com.alibaba.nacos.config.server.service.dump.DumpService;
import javax.servlet.http.HttpServletResponse; import com.alibaba.nacos.config.server.service.notify.NotifyService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; 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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.nacos.config.server.constant.Constants; import javax.servlet.ServletException;
import com.alibaba.nacos.config.server.model.SampleResult; import javax.servlet.http.HttpServletRequest;
import com.alibaba.nacos.config.server.service.LongPullingService; import javax.servlet.http.HttpServletResponse;
import com.alibaba.nacos.config.server.service.dump.DumpService; import java.io.IOException;
import com.alibaba.nacos.config.server.service.notify.NotifyService;
/** /**
@ -51,7 +49,7 @@ public class CommunicationController {
private DumpService dumpService; private DumpService dumpService;
@Autowired @Autowired
protected LongPullingService longPullingService; protected LongPollingService longPollingService;
private String trueStr = "true"; private String trueStr = "true";
@ -92,7 +90,7 @@ public class CommunicationController {
ModelMap modelMap) ModelMap modelMap)
throws IOException, ServletException, Exception { throws IOException, ServletException, Exception {
group = StringUtils.isBlank(group) ? Constants.DEFAULT_GROUP : group; group = StringUtils.isBlank(group) ? Constants.DEFAULT_GROUP : group;
SampleResult sampleResult = longPullingService.getCollectSubscribleInfo(dataId, group, tenant); SampleResult sampleResult = longPollingService.getCollectSubscribleInfo(dataId, group, tenant);
return sampleResult; return sampleResult;
} }
@ -106,7 +104,7 @@ public class CommunicationController {
@RequestParam("ip") String ip, @RequestParam("ip") String ip,
ModelMap modelMap) ModelMap modelMap)
throws IOException, ServletException, Exception { throws IOException, ServletException, Exception {
SampleResult sampleResult = longPullingService.getCollectSubscribleInfoByIp(ip); SampleResult sampleResult = longPollingService.getCollectSubscribleInfoByIp(ip);
return sampleResult; return sampleResult;
} }
} }

View File

@ -15,6 +15,7 @@
*/ */
package com.alibaba.nacos.config.server.controller; package com.alibaba.nacos.config.server.controller;
import java.io.IOException; import java.io.IOException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.sql.Timestamp; import java.sql.Timestamp;
@ -34,26 +35,35 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.nacos.config.server.constant.Constants; import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.exception.NacosException; import com.alibaba.nacos.config.server.exception.NacosException;
import com.alibaba.nacos.config.server.model.ConfigAdvanceInfo; import com.alibaba.nacos.config.server.model.*;
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.service.AggrWhitelist; import com.alibaba.nacos.config.server.service.AggrWhitelist;
import com.alibaba.nacos.config.server.service.ConfigDataChangeEvent; import com.alibaba.nacos.config.server.service.ConfigDataChangeEvent;
import com.alibaba.nacos.config.server.service.ConfigSubService; import com.alibaba.nacos.config.server.service.ConfigSubService;
import com.alibaba.nacos.config.server.service.PersistService; import com.alibaba.nacos.config.server.service.PersistService;
import com.alibaba.nacos.config.server.service.merge.MergeDatumService; import com.alibaba.nacos.config.server.service.merge.MergeDatumService;
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService; import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
import com.alibaba.nacos.config.server.utils.MD5Util; import com.alibaba.nacos.config.server.utils.*;
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.event.EventDispatcher; 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;
/** /**
* 软负载客户端发布数据专用控制器 * 软负载客户端发布数据专用控制器

View File

@ -15,8 +15,22 @@
*/ */
package com.alibaba.nacos.config.server.controller; 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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -27,29 +41,8 @@ import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.ServletException; import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
import javax.servlet.http.HttpServletRequest; import static com.alibaba.nacos.config.server.utils.LogUtil.pullLog;
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;
/** /**
* ConfigServlet inner for aop * ConfigServlet inner for aop
@ -60,7 +53,7 @@ import com.alibaba.nacos.config.server.utils.TimeUtils;
public class ConfigServletInner { public class ConfigServletInner {
@Autowired @Autowired
private LongPullingService longPullingService; private LongPollingService longPollingService;
@Autowired @Autowired
private PersistService persistService; 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 { public String doPollingConfig(HttpServletRequest request, HttpServletResponse response, Map<String, String> clientMd5Map, int probeRequestSize) throws IOException, ServletException {
// 长轮询 // 长轮询
if (LongPullingService.isSupportLongPulling(request)) { if (LongPollingService.isSupportLongPulling(request)) {
longPullingService.addLongPullingClient(request, response, clientMd5Map, probeRequestSize); longPollingService.addLongPullingClient(request, response, clientMd5Map, probeRequestSize);
return HttpServletResponse.SC_OK + ""; return HttpServletResponse.SC_OK + "";
} }
@ -141,7 +134,7 @@ public class ConfigServletInner {
if (isBeta) { if (isBeta) {
md5 = cacheItem.getMd54Beta(); md5 = cacheItem.getMd54Beta();
lastModified = cacheItem.getLastModifiedTs4Beta(); lastModified = cacheItem.getLastModifiedTs4Beta();
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
configInfoBase = persistService.findConfigInfo4Beta(dataId, group,tenant); configInfoBase = persistService.findConfigInfo4Beta(dataId, group,tenant);
} else { } else {
file = DiskUtil.targetBetaFile(dataId, group, tenant); file = DiskUtil.targetBetaFile(dataId, group, tenant);
@ -158,7 +151,7 @@ public class ConfigServletInner {
lastModified = cacheItem.tagLastModifiedTs.get(autoTag); lastModified = cacheItem.tagLastModifiedTs.get(autoTag);
} }
} }
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
configInfoBase = persistService.findConfigInfo4Tag(dataId, group, tenant, autoTag); configInfoBase = persistService.findConfigInfo4Tag(dataId, group, tenant, autoTag);
} else { } else {
file = DiskUtil.targetTagFile(dataId, group, tenant, autoTag); file = DiskUtil.targetTagFile(dataId, group, tenant, autoTag);
@ -169,7 +162,7 @@ public class ConfigServletInner {
} else { } else {
md5 = cacheItem.getMd5(); md5 = cacheItem.getMd5();
lastModified = cacheItem.getLastModifiedTs(); lastModified = cacheItem.getLastModifiedTs();
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
configInfoBase = persistService.findConfigInfo(dataId, group, tenant); configInfoBase = persistService.findConfigInfo(dataId, group, tenant);
} else { } else {
file = DiskUtil.targetFile(dataId, group, tenant); 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); configInfoBase = persistService.findConfigInfo4Tag(dataId, group, tenant, tag);
} else { } else {
file = DiskUtil.targetTagFile(dataId, group, tenant, tag); file = DiskUtil.targetTagFile(dataId, group, tenant, tag);
@ -230,7 +223,7 @@ public class ConfigServletInner {
response.setHeader("Pragma", "no-cache"); response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0); response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache,no-store"); response.setHeader("Cache-Control", "no-cache,no-store");
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
response.setDateHeader("Last-Modified", lastModified); response.setDateHeader("Last-Modified", lastModified);
} else { } else {
fis = new FileInputStream(file); fis = new FileInputStream(file);
@ -238,7 +231,7 @@ public class ConfigServletInner {
} }
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
out = response.getWriter(); out = response.getWriter();
out.print(configInfoBase.getContent()); out.print(configInfoBase.getContent());
out.flush(); out.flush();

View File

@ -15,17 +15,18 @@
*/ */
package com.alibaba.nacos.config.server.controller; 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.constant.Constants;
import com.alibaba.nacos.config.server.service.DataSourceService; import com.alibaba.nacos.config.server.service.DataSourceService;
import com.alibaba.nacos.config.server.service.DynamicDataSource; import com.alibaba.nacos.config.server.service.DynamicDataSource;
import com.alibaba.nacos.config.server.service.ServerListService; import com.alibaba.nacos.config.server.service.ServerListService;
import com.alibaba.nacos.config.server.utils.SystemConfig; 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 * health service

View File

@ -15,10 +15,11 @@
*/ */
package com.alibaba.nacos.config.server.controller; package com.alibaba.nacos.config.server.controller;
import javax.servlet.http.HttpServletRequest; import com.alibaba.nacos.config.server.constant.Constants;
import javax.servlet.http.HttpServletResponse; import com.alibaba.nacos.config.server.model.ConfigHistoryInfo;
import com.alibaba.nacos.config.server.model.Page;
import org.apache.commons.lang.StringUtils; import com.alibaba.nacos.config.server.service.PersistService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; 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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.nacos.config.server.constant.Constants; import javax.servlet.http.HttpServletRequest;
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo; import javax.servlet.http.HttpServletResponse;
import com.alibaba.nacos.config.server.model.Page;
import com.alibaba.nacos.config.server.service.PersistService;
/** /**
* 管理控制器 * 管理控制器

View File

@ -15,15 +15,12 @@
*/ */
package com.alibaba.nacos.config.server.controller; package com.alibaba.nacos.config.server.controller;
import java.io.IOException; import com.alibaba.nacos.config.server.constant.Constants;
import java.util.HashMap; import com.alibaba.nacos.config.server.model.GroupkeyListenserStatus;
import java.util.Map; import com.alibaba.nacos.config.server.model.SampleResult;
import com.alibaba.nacos.config.server.service.ConfigSubService;
import javax.servlet.ServletException; import com.alibaba.nacos.config.server.utils.GroupKey2;
import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; 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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.nacos.config.server.constant.Constants; import javax.servlet.ServletException;
import com.alibaba.nacos.config.server.model.GroupkeyListenserStatus; import javax.servlet.http.HttpServletRequest;
import com.alibaba.nacos.config.server.model.SampleResult; import javax.servlet.http.HttpServletResponse;
import com.alibaba.nacos.config.server.service.ConfigSubService; import java.io.IOException;
import com.alibaba.nacos.config.server.utils.GroupKey2; import java.util.HashMap;
import java.util.Map;
/** /**
* Config longpulling * Config longpulling

View File

@ -15,9 +15,9 @@
*/ */
package com.alibaba.nacos.config.server.controller; package com.alibaba.nacos.config.server.controller;
import javax.servlet.http.HttpServletRequest; import com.alibaba.nacos.config.server.constant.Constants;
import javax.servlet.http.HttpServletResponse; import com.alibaba.nacos.config.server.service.PersistService;
import com.alibaba.nacos.config.server.service.dump.DumpService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.nacos.config.server.constant.Constants; import javax.servlet.http.HttpServletRequest;
import com.alibaba.nacos.config.server.service.PersistService; import javax.servlet.http.HttpServletResponse;
import com.alibaba.nacos.config.server.service.dump.DumpService;
/** /**
* 管理控制器 * 管理控制器

View File

@ -15,13 +15,12 @@
*/ */
package com.alibaba.nacos.config.server.exception; 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.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/** /**
* global exception handler * global exception handler
* *

View File

@ -15,19 +15,14 @@
*/ */
package com.alibaba.nacos.config.server.filter; 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 java.io.IOException;
import javax.servlet.Filter; import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
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;
/** /**
* encode filter * encode filter
@ -36,8 +31,8 @@ import com.alibaba.nacos.config.server.constant.Constants;
* *
*/ */
@Order(1) @Order(1)
@javax.servlet.annotation.WebFilter(filterName = "webFilter", urlPatterns = "/*") @WebFilter(filterName = "webFilter", urlPatterns = "/*")
public class WebFilter implements Filter { public class NacosWebFilter implements Filter {
static private String webRootPath; static private String webRootPath;

View File

@ -15,6 +15,11 @@
*/ */
package com.alibaba.nacos.config.server.manager; 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.lang.management.ManagementFactory;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
@ -23,11 +28,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock; 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;
/** /**

View File

@ -15,12 +15,12 @@
*/ */
package com.alibaba.nacos.config.server.model; 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.constant.Constants;
import com.alibaba.nacos.config.server.utils.SimpleReadWriteLock; import com.alibaba.nacos.config.server.utils.SimpleReadWriteLock;
import com.alibaba.nacos.config.server.utils.SingletonRepository.DataIdGroupIdCache; import com.alibaba.nacos.config.server.utils.SingletonRepository.DataIdGroupIdCache;
import java.util.List;
import java.util.Map;
/** /**
* cache item * cache item
* @author Nacos * @author Nacos

View File

@ -15,11 +15,11 @@
*/ */
package com.alibaba.nacos.config.server.model; package com.alibaba.nacos.config.server.model;
import com.alibaba.nacos.config.server.utils.MD5;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Serializable; import java.io.Serializable;
import com.alibaba.nacos.config.server.utils.MD5;
/** /**
* 不能增加字段为了兼容老前台接口老接口增加一个字段会出现不兼容问题设置的model * 不能增加字段为了兼容老前台接口老接口增加一个字段会出现不兼容问题设置的model
* *

View File

@ -15,15 +15,17 @@
*/ */
package com.alibaba.nacos.config.server.monitor; 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.ClientTrackService;
import com.alibaba.nacos.config.server.service.ConfigService; import com.alibaba.nacos.config.server.service.ConfigService;
import com.alibaba.nacos.config.server.service.TimerTaskService; import com.alibaba.nacos.config.server.service.TimerTaskService;
import com.alibaba.nacos.config.server.service.notify.AsyncNotifyService; 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 * Memory monitor

View File

@ -22,7 +22,6 @@ import java.util.concurrent.atomic.AtomicLong;
* Response Monitory * Response Monitory
* *
* @author Nacos * @author Nacos
*
*/ */
public class ResponseMonitor { public class ResponseMonitor {
static AtomicLong[] getConfigCountDetail = new AtomicLong[8]; static AtomicLong[] getConfigCountDetail = new AtomicLong[8];
@ -78,20 +77,4 @@ public class ResponseMonitor {
s.append("3000以上ms:" + df.format(getConfigCountDetail[7].getAndSet(0) * 100 / getConfigCount.getAndSet(0))).append("%\r\n"); s.append("3000以上ms:" + df.format(getConfigCountDetail[7].getAndSet(0) * 100 / getConfigCount.getAndSet(0))).append("%\r\n");
return s.toString(); 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());
}
} }

View File

@ -15,8 +15,10 @@
*/ */
package com.alibaba.nacos.config.server.service; package com.alibaba.nacos.config.server.service;
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog; import com.alibaba.nacos.config.server.utils.RegexParser;
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.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,11 +26,8 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils; import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
import org.apache.commons.lang.StringUtils; import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
import org.springframework.stereotype.Service;
import com.alibaba.nacos.config.server.utils.RegexParser;
/** /**

View File

@ -15,23 +15,9 @@
*/ */
package com.alibaba.nacos.config.server.service; 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.dbcp.BasicDataSource;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
@ -41,12 +27,24 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate; 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 * Base data source
* @author Nacos
* *
* @author Nacos
*/ */
@Service("basicDataSourceService") @Service("basicDataSourceService")
public class BasicDataSourceServiceImpl implements DataSourceService { public class BasicDataSourceServiceImpl implements DataSourceService {
@ -79,8 +77,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
@PostConstruct @PostConstruct
public void init() { public void init() {
queryTimeout = NumberUtils queryTimeout = NumberUtils.toInt(System.getProperty("QUERYTIMEOUT"), 3);
.toInt(System.getProperty("QUERYTIMEOUT"), 3);
jt = new JdbcTemplate(); jt = new JdbcTemplate();
/** /**
* 设置最大记录数防止内存膨胀 * 设置最大记录数防止内存膨胀
@ -108,7 +105,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
* 事务的超时时间需要与普通操作区分开 * 事务的超时时间需要与普通操作区分开
*/ */
tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT); tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT);
if (!PropertyUtil.isStandaloneMode()) { if (!STANDALONE_MODE) {
try { try {
reload(); reload();
} catch (IOException e) { } catch (IOException e) {

View File

@ -15,17 +15,16 @@
*/ */
package com.alibaba.nacos.config.server.service; 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.lang.StringUtils; import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
import org.springframework.stereotype.Service;
import com.alibaba.nacos.config.server.model.ACLInfo;
import com.alibaba.nacos.config.server.utils.JSONUtils;
/** /**
* Client ip whitelist * Client ip whitelist
* @author Nacos * @author Nacos

View File

@ -15,13 +15,13 @@
*/ */
package com.alibaba.nacos.config.server.service; package com.alibaba.nacos.config.server.service;
import com.alibaba.nacos.config.server.model.SubscriberStatus;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import com.alibaba.nacos.config.server.model.SubscriberStatus;
/** /**
* 跟踪客户端md5的服务 一段时间没有比较md5后就删除IP对应的记录 * 跟踪客户端md5的服务 一段时间没有比较md5后就删除IP对应的记录

View File

@ -15,9 +15,8 @@
*/ */
package com.alibaba.nacos.config.server.service; package com.alibaba.nacos.config.server.service;
import org.apache.commons.lang.StringUtils;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event; import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
import org.apache.commons.lang3.StringUtils;
/** /**

View File

@ -15,34 +15,26 @@
*/ */
package com.alibaba.nacos.config.server.service; 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.constant.Constants;
import com.alibaba.nacos.config.server.model.CacheItem; 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.GroupKey;
import com.alibaba.nacos.config.server.utils.GroupKey2; import com.alibaba.nacos.config.server.utils.GroupKey2;
import com.alibaba.nacos.config.server.utils.MD5; import com.alibaba.nacos.config.server.utils.MD5;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher; 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.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 * config service
* @author Nacos * @author Nacos
@ -82,7 +74,7 @@ public class ConfigService {
"[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, " "[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}", + "lastModifiedNew={}",
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs); groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
} else if (!PropertyUtil.isStandaloneMode()) { } else if (!STANDALONE_MODE) {
DiskUtil.saveToDisk(dataId, group, tenant, content); DiskUtil.saveToDisk(dataId, group, tenant, content);
} }
updateMd5(groupKey, md5, lastModifiedTs); updateMd5(groupKey, md5, lastModifiedTs);
@ -126,7 +118,7 @@ public class ConfigService {
"[dump-beta-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, " "[dump-beta-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}", + "lastModifiedNew={}",
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs); groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
} else if (!PropertyUtil.isStandaloneMode()) { } else if (!STANDALONE_MODE) {
DiskUtil.saveBetaToDisk(dataId, group, tenant, content); DiskUtil.saveBetaToDisk(dataId, group, tenant, content);
} }
String[] betaIpsArr = betaIps.split(","); String[] betaIpsArr = betaIps.split(",");
@ -164,7 +156,7 @@ public class ConfigService {
"[dump-tag-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, " "[dump-tag-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}", + "lastModifiedNew={}",
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs); groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
} else if (!PropertyUtil.isStandaloneMode()) { } else if (!STANDALONE_MODE) {
DiskUtil.saveTagToDisk(dataId, group, tenant, tag, content); DiskUtil.saveTagToDisk(dataId, group, tenant, tag, content);
} }
@ -196,7 +188,7 @@ public class ConfigService {
try { try {
final String md5 = MD5.getInstance().getMD5String(content); final String md5 = MD5.getInstance().getMD5String(content);
if (!PropertyUtil.isStandaloneMode()) { if (!STANDALONE_MODE) {
String loacalMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant); String loacalMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant);
if(md5.equals(loacalMd5)) { if(md5.equals(loacalMd5)) {
dumpLog.warn( dumpLog.warn(
@ -222,7 +214,7 @@ public class ConfigService {
{ {
String aggreds = null; String aggreds = null;
try { try {
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
ConfigInfoBase config = persistService.findConfigInfoBase(AggrWhitelist.AGGRIDS_METADATA, "DEFAULT_GROUP"); ConfigInfoBase config = persistService.findConfigInfoBase(AggrWhitelist.AGGRIDS_METADATA, "DEFAULT_GROUP");
if (config != null) { if (config != null) {
aggreds = config.getContent(); aggreds = config.getContent();
@ -240,7 +232,7 @@ public class ConfigService {
String clientIpWhitelist = null; String clientIpWhitelist = null;
try { try {
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
ConfigInfoBase config = persistService.findConfigInfoBase(ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, "DEFAULT_GROUP"); ConfigInfoBase config = persistService.findConfigInfoBase(ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, "DEFAULT_GROUP");
if (config != null) { if (config != null) {
clientIpWhitelist = config.getContent(); clientIpWhitelist = config.getContent();
@ -259,7 +251,7 @@ public class ConfigService {
String switchContent= null; String switchContent= null;
try { try {
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
ConfigInfoBase config = persistService.findConfigInfoBase(SwitchService.SWITCH_META_DATAID, "DEFAULT_GROUP"); ConfigInfoBase config = persistService.findConfigInfoBase(SwitchService.SWITCH_META_DATAID, "DEFAULT_GROUP");
if (config != null) { if (config != null) {
switchContent = config.getContent(); switchContent = config.getContent();
@ -326,7 +318,7 @@ public class ConfigService {
} }
try { try {
if (!PropertyUtil.isStandaloneMode()) { if (!STANDALONE_MODE) {
DiskUtil.removeConfigInfo(dataId, group, tenant); DiskUtil.removeConfigInfo(dataId, group, tenant);
} }
CACHE.remove(groupKey); CACHE.remove(groupKey);
@ -359,7 +351,7 @@ public class ConfigService {
} }
try { try {
if (!PropertyUtil.isStandaloneMode()) { if (!STANDALONE_MODE) {
DiskUtil.removeConfigInfo4Beta(dataId, group, tenant); DiskUtil.removeConfigInfo4Beta(dataId, group, tenant);
} }
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey, true, CACHE.get(groupKey).getIps4Beta())); EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey, true, CACHE.get(groupKey).getIps4Beta()));
@ -394,7 +386,7 @@ public class ConfigService {
} }
try { try {
if (!PropertyUtil.isStandaloneMode()) { if (!STANDALONE_MODE) {
DiskUtil.removeConfigInfo4Tag(dataId, group, tenant, tag); DiskUtil.removeConfigInfo4Tag(dataId, group, tenant, tag);
} }

View File

@ -15,30 +15,6 @@
*/ */
package com.alibaba.nacos.config.server.service; 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.constant.Constants;
import com.alibaba.nacos.config.server.model.SampleResult; import com.alibaba.nacos.config.server.model.SampleResult;
import com.alibaba.nacos.config.server.service.notify.NotifyService; 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.LogUtil;
import com.alibaba.nacos.config.server.utils.RunningConfigUtils; import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
import com.alibaba.nacos.config.server.utils.ThreadUtil; 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 * config sub service
* @author Nacos * @author Nacos

View File

@ -15,21 +15,20 @@
*/ */
package com.alibaba.nacos.config.server.service; 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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; 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;
/** /**
* 磁盘操作工具类 * 磁盘操作工具类

View File

@ -15,11 +15,12 @@
*/ */
package com.alibaba.nacos.config.server.service; package com.alibaba.nacos.config.server.service;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
/** /**
* datasource adapter * datasource adapter
* @author Nacos * @author Nacos
@ -40,7 +41,7 @@ public class DynamicDataSource implements ApplicationContextAware {
public DataSourceService getDataSource() { public DataSourceService getDataSource() {
DataSourceService dataSourceService = null; DataSourceService dataSourceService = null;
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
dataSourceService = (DataSourceService)applicationContext.getBean("localDataSourceService"); dataSourceService = (DataSourceService)applicationContext.getBean("localDataSourceService");
} else { } else {
dataSourceService = (DataSourceService)applicationContext.getBean("basicDataSourceService"); dataSourceService = (DataSourceService)applicationContext.getBean("basicDataSourceService");

View File

@ -15,10 +15,10 @@
*/ */
package com.alibaba.nacos.config.server.service; package com.alibaba.nacos.config.server.service;
import java.util.List;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event; import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
import java.util.List;
/** /**
* 本地数据发生变更的事件 * 本地数据发生变更的事件
* @author Nacos * @author Nacos

View File

@ -15,6 +15,19 @@
*/ */
package com.alibaba.nacos.config.server.service; 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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
@ -25,28 +38,18 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct; import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
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;
/** /**
* local data source * local data source
* *
* @author Nacos * @author Nacos
*
*/ */
@Service("localDataSourceService") @Service("localDataSourceService")
public class LocalDataSourceServiceImpl implements DataSourceService { 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 JDBC_DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver";
private static final String DERBY_BASE_DIR = "data" + File.separator + "derby-data"; private static final String DERBY_BASE_DIR = "data" + File.separator + "derby-data";
private static String appHome = System.getProperty("user.home") + File.separator + "nacos"; private static String appHome = System.getProperty("user.home") + File.separator + "nacos";
@ -86,7 +89,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
tm.setDataSource(ds); tm.setDataSource(ds);
tjt.setTimeout(5000); tjt.setTimeout(5000);
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
reload(); reload();
} }
} }
@ -98,8 +101,11 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
throw new RuntimeException("datasource is null"); throw new RuntimeException("datasource is null");
} }
try { try {
execute(ds.getConnection(), "schema.sql"); execute(ds.getConnection(), "META-INF/schema.sql");
} catch (Exception e) { } catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e);
}
throw new RuntimeException("load schema.sql error." + e); throw new RuntimeException("load schema.sql error." + e);
} }
} }
@ -131,6 +137,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
/** /**
* 读取SQL文件 * 读取SQL文件
*
* @param sqlFile sql * @param sqlFile sql
* @return sqls * @return sqls
* @throws Exception Exception * @throws Exception Exception
@ -144,7 +151,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
URL url = classLoader.getResource(sqlFile); URL url = classLoader.getResource(sqlFile);
sqlFileIn = url.openStream(); sqlFileIn = url.openStream();
} else { } 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); sqlFileIn = new FileInputStream(file);
} }
@ -174,6 +181,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
/** /**
* 执行SQL语句 * 执行SQL语句
*
* @param conn connect * @param conn connect
* @param sqlFile sql * @param sqlFile sql
* @throws Exception Exception * @throws Exception Exception

View File

@ -15,35 +15,6 @@
*/ */
package com.alibaba.nacos.config.server.service; 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.model.SampleResult;
import com.alibaba.nacos.config.server.utils.GroupKey; import com.alibaba.nacos.config.server.utils.GroupKey;
import com.alibaba.nacos.config.server.utils.LogUtil; 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.RequestUtil;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.AbstractEventListener; import com.alibaba.nacos.config.server.utils.event.EventDispatcher.AbstractEventListener;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event; 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 * @author Nacos
*/ */
@Service @Service
public class LongPullingService extends AbstractEventListener { public class LongPollingService extends AbstractEventListener {
private static final int FIXED_POLLING_INTERVAL_MS = 10000; 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) { public void addLongPullingClient(HttpServletRequest req, HttpServletResponse rsp, Map<String, String> clientMd5Map, int probeRequestSize) {
String str = req.getHeader(LongPullingService.LONG_PULLING_HEADER); String str = req.getHeader(LongPollingService.LONG_PULLING_HEADER);
String noHangUpFlag = req.getHeader(LongPullingService.LONG_PULLING_NO_HANG_UP_HEADER); String noHangUpFlag = req.getHeader(LongPollingService.LONG_PULLING_NO_HANG_UP_HEADER);
String appName = req.getHeader(RequestUtil.CLIENT_APPNAME_HEADER); String appName = req.getHeader(RequestUtil.CLIENT_APPNAME_HEADER);
String tag = req.getHeader("Vipserver-Tag"); String tag = req.getHeader("Vipserver-Tag");
int delayTime=SwitchService.getSwitchInteger(SwitchService.FIXED_DELAY_TIME, 500); int delayTime=SwitchService.getSwitchInteger(SwitchService.FIXED_DELAY_TIME, 500);
@ -285,7 +267,7 @@ public class LongPullingService extends AbstractEventListener {
} }
@SuppressWarnings("PMD.ThreadPoolCreationRule") @SuppressWarnings("PMD.ThreadPoolCreationRule")
public LongPullingService() { public LongPollingService() {
allSubs = new ConcurrentLinkedQueue<ClientLongPulling>(); allSubs = new ConcurrentLinkedQueue<ClientLongPulling>();
scheduler = Executors.newScheduledThreadPool(1, new ThreadFactory() { scheduler = Executors.newScheduledThreadPool(1, new ThreadFactory() {

View File

@ -15,25 +15,14 @@
*/ */
package com.alibaba.nacos.config.server.service; package com.alibaba.nacos.config.server.service;
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog; import com.alibaba.nacos.config.server.model.*;
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog; import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.config.server.utils.MD5;
import java.io.IOException; import com.alibaba.nacos.config.server.utils.PaginationHelper;
import java.sql.Connection; import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
import java.sql.PreparedStatement; import com.google.common.collect.Lists;
import java.sql.ResultSet; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.sql.SQLException; import org.apache.commons.lang3.StringUtils;
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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
@ -54,25 +43,17 @@ import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import com.alibaba.nacos.config.server.model.ConfigAdvanceInfo; import javax.annotation.PostConstruct;
import com.alibaba.nacos.config.server.model.ConfigAllInfo; import java.io.IOException;
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo; import java.sql.*;
import com.alibaba.nacos.config.server.model.ConfigInfo; import java.util.ArrayList;
import com.alibaba.nacos.config.server.model.ConfigInfo4Beta; import java.util.Collections;
import com.alibaba.nacos.config.server.model.ConfigInfo4Tag; import java.util.List;
import com.alibaba.nacos.config.server.model.ConfigInfoAggr; import java.util.Map;
import com.alibaba.nacos.config.server.model.ConfigInfoBase; import java.util.Map.Entry;
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 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> * 数据库服务提供ConfigInfo在数据库的存取<br>

View File

@ -15,39 +15,6 @@
*/ */
package com.alibaba.nacos.config.server.service; 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.constant.Constants;
import com.alibaba.nacos.config.server.service.notify.NotifyService; import com.alibaba.nacos.config.server.service.notify.NotifyService;
import com.alibaba.nacos.config.server.service.notify.NotifyService.HttpResult; 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.RunningConfigUtils;
import com.alibaba.nacos.config.server.utils.SystemConfig; import com.alibaba.nacos.config.server.utils.SystemConfig;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher; 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 * Serverlist service
@ -71,10 +65,8 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
@Autowired @Autowired
private ServletContext servletContext; private ServletContext servletContext;
@Value("${server.port}")
private int port; private int port;
@PostConstruct @PostConstruct
public void init() { public void init() {
serverPort = System.getProperty("nacos.server.port", "8848"); 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); defaultLog.error("nacos-XXXX", "[serverlist] failed to get serverlist from disk!", e);
} }
if (isUseAddressServer() && !PropertyUtil.isStandaloneMode()) { if (isUseAddressServer() && !STANDALONE_MODE) {
try { try {
HttpResult result = NotifyService.invokeURL(addressServerUrl, null, null); HttpResult result = NotifyService.invokeURL(addressServerUrl, null, null);

View File

@ -15,19 +15,18 @@
*/ */
package com.alibaba.nacos.config.server.service; 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 com.alibaba.nacos.config.server.utils.LogUtil;
import org.apache.commons.io.IOUtils;
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
/** /**
* Switch * Switch
* @author Nacos * @author Nacos

View File

@ -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.GroupCapacity;
import com.alibaba.nacos.config.server.model.capacity.TenantCapacity; import com.alibaba.nacos.config.server.model.capacity.TenantCapacity;
import com.alibaba.nacos.config.server.service.PersistService; 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.LogUtil;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.config.server.utils.TimeUtils; import com.alibaba.nacos.config.server.utils.TimeUtils;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -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.Capacity;
import com.alibaba.nacos.config.server.model.capacity.GroupCapacity; 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.DataSourceService;
import com.alibaba.nacos.config.server.service.DynamicDataSource; 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.alibaba.nacos.config.server.utils.TimeUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.CannotGetJdbcConnectionException;
import org.springframework.jdbc.core.JdbcTemplate; 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.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog; import javax.annotation.PostConstruct;
import java.sql.*; import java.sql.*;
import java.util.List; 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 * Group Capacity Service
@ -284,7 +279,7 @@ public class GroupCapacityPersistService {
public List<GroupCapacity> getCapacityList4CorrectUsage(long lastId, int pageSize) { public List<GroupCapacity> getCapacityList4CorrectUsage(long lastId, int pageSize) {
String sql = "select id, group_id from group_capacity where id>? limit ?"; 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"; sql = "select id, group_id from group_capacity where id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
} }
try { try {

View File

@ -16,16 +16,11 @@
package com.alibaba.nacos.config.server.service.capacity; package com.alibaba.nacos.config.server.service.capacity;
import com.alibaba.nacos.config.server.model.capacity.TenantCapacity; 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.DataSourceService;
import com.alibaba.nacos.config.server.service.DynamicDataSource; 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.alibaba.nacos.config.server.utils.TimeUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.CannotGetJdbcConnectionException;
import org.springframework.jdbc.core.JdbcTemplate; 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.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog; import javax.annotation.PostConstruct;
import java.sql.*; import java.sql.*;
import java.util.List; 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 * Tenant Capacity Service
@ -234,7 +229,7 @@ public class TenantCapacityPersistService {
public List<TenantCapacity> getCapacityList4CorrectUsage(long lastId, int pageSize) { public List<TenantCapacity> getCapacityList4CorrectUsage(long lastId, int pageSize) {
String sql = "select id, tenant_id from tenant_capacity where id>? limit ?"; 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"; sql = "select id, tenant_id from tenant_capacity where id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
} }

View File

@ -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.ConfigInfoAggr;
import com.alibaba.nacos.config.server.model.ConfigInfoChanged; import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
import com.alibaba.nacos.config.server.model.Page; import com.alibaba.nacos.config.server.model.Page;
import com.alibaba.nacos.config.server.service.ConfigService; import com.alibaba.nacos.config.server.service.*;
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.PersistService.ConfigInfoWrapper; import com.alibaba.nacos.config.server.service.PersistService.ConfigInfoWrapper;
import com.alibaba.nacos.config.server.service.merge.MergeTaskProcessor; import com.alibaba.nacos.config.server.service.merge.MergeTaskProcessor;
import com.alibaba.nacos.config.server.utils.*; import com.alibaba.nacos.config.server.utils.*;
import org.apache.commons.io.IOUtils; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; 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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Properties;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; 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 * Dump data service
@ -161,7 +153,7 @@ public class DumpService {
throw new RuntimeException( throw new RuntimeException(
"Nacos Server did not start because dumpservice bean construction failure :\n" + e.getMessage()); "Nacos Server did not start because dumpservice bean construction failure :\n" + e.getMessage());
} }
if (!PropertyUtil.isStandaloneMode()) { if (!STANDALONE_MODE) {
Runnable heartbeat = new Runnable() { Runnable heartbeat = new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -15,22 +15,13 @@
*/ */
package com.alibaba.nacos.config.server.service.dump; 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.AbstractTask;
import com.alibaba.nacos.config.server.manager.TaskProcessor; import com.alibaba.nacos.config.server.manager.TaskProcessor;
import com.alibaba.nacos.config.server.model.ConfigInfo; import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.ConfigInfo4Beta; import com.alibaba.nacos.config.server.model.ConfigInfo4Beta;
import com.alibaba.nacos.config.server.model.ConfigInfo4Tag; import com.alibaba.nacos.config.server.model.ConfigInfo4Tag;
import com.alibaba.nacos.config.server.model.Page; import com.alibaba.nacos.config.server.model.Page;
import com.alibaba.nacos.config.server.service.AggrWhitelist; import com.alibaba.nacos.config.server.service.*;
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.PersistService.ConfigInfoBetaWrapper; 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.ConfigInfoTagWrapper;
import com.alibaba.nacos.config.server.service.PersistService.ConfigInfoWrapper; 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.MD5;
import com.alibaba.nacos.config.server.utils.StringUtils; 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 * Dump data task
* @author Nacos * @author Nacos

View File

@ -15,16 +15,6 @@
*/ */
package com.alibaba.nacos.config.server.service.merge; 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.manager.TaskManager;
import com.alibaba.nacos.config.server.model.ConfigInfo; import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.ConfigInfoAggr; 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.ContentUtils;
import com.alibaba.nacos.config.server.utils.SystemConfig; import com.alibaba.nacos.config.server.utils.SystemConfig;
import com.alibaba.nacos.config.server.utils.TimeUtils; 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;
/** /**

View File

@ -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.SystemConfig;
import com.alibaba.nacos.config.server.utils.TimeUtils; import com.alibaba.nacos.config.server.utils.TimeUtils;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher; import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/** /**

View File

@ -15,19 +15,13 @@
*/ */
package com.alibaba.nacos.config.server.service.notify; package com.alibaba.nacos.config.server.service.notify;
import java.io.UnsupportedEncodingException; import com.alibaba.nacos.config.server.constant.Constants;
import java.net.URLEncoder; import com.alibaba.nacos.config.server.service.ConfigDataChangeEvent;
import java.text.MessageFormat; import com.alibaba.nacos.config.server.service.ServerListService;
import java.util.ArrayList; import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
import java.util.LinkedList; import com.alibaba.nacos.config.server.utils.*;
import java.util.List; import com.alibaba.nacos.config.server.utils.event.EventDispatcher.AbstractEventListener;
import java.util.Queue; import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
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 org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.alibaba.nacos.config.server.constant.Constants; import java.io.UnsupportedEncodingException;
import com.alibaba.nacos.config.server.service.ConfigDataChangeEvent; import java.net.URLEncoder;
import com.alibaba.nacos.config.server.service.ServerListService; import java.text.MessageFormat;
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService; import java.util.ArrayList;
import com.alibaba.nacos.config.server.utils.LogUtil; import java.util.LinkedList;
import com.alibaba.nacos.config.server.utils.PropertyUtil; import java.util.List;
import com.alibaba.nacos.config.server.utils.RunningConfigUtils; import java.util.Queue;
import com.alibaba.nacos.config.server.utils.StringUtils; import java.util.concurrent.*;
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;
/** /**
* Async notify service * Async notify service

View File

@ -15,21 +15,19 @@
*/ */
package com.alibaba.nacos.config.server.service.notify; 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.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; 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 * 通知其他节点取最新数据的服务 监听数据变更事件通知所有的server

View File

@ -15,23 +15,16 @@
*/ */
package com.alibaba.nacos.config.server.service.notify; 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.manager.AbstractTask;
import com.alibaba.nacos.config.server.service.ServerListService; import com.alibaba.nacos.config.server.service.ServerListService;
import com.alibaba.nacos.config.server.utils.GroupKey2; import com.alibaba.nacos.config.server.utils.GroupKey2;
import com.alibaba.nacos.config.server.utils.LogUtil; 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 * Notify Single server

View File

@ -15,14 +15,6 @@
*/ */
package com.alibaba.nacos.config.server.service.notify; 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.constant.Constants;
import com.alibaba.nacos.config.server.manager.AbstractTask; import com.alibaba.nacos.config.server.manager.AbstractTask;
import com.alibaba.nacos.config.server.manager.TaskProcessor; 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.service.trace.ConfigTraceService;
import com.alibaba.nacos.config.server.utils.RunningConfigUtils; import com.alibaba.nacos.config.server.utils.RunningConfigUtils;
import com.alibaba.nacos.config.server.utils.SystemConfig; 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;
/** /**

View File

@ -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.LogUtil;
import com.alibaba.nacos.config.server.utils.MD5; import com.alibaba.nacos.config.server.utils.MD5;
import com.alibaba.nacos.config.server.utils.SystemConfig; import com.alibaba.nacos.config.server.utils.SystemConfig;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* Config trace * Config trace

View File

@ -15,10 +15,10 @@
*/ */
package com.alibaba.nacos.config.server.utils; 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 com.alibaba.nacos.config.server.constant.Constants;
import static com.alibaba.nacos.config.server.constant.Constants.WORD_SEPARATOR;
/** /**
* Content utils * Content utils
* @author Nacos * @author Nacos

View File

@ -15,13 +15,13 @@
*/ */
package com.alibaba.nacos.config.server.utils; 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.DeserializationConfig.Feature;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.JavaType; import org.codehaus.jackson.type.JavaType;
import org.codehaus.jackson.type.TypeReference; import org.codehaus.jackson.type.TypeReference;
import java.io.IOException;
/** /**
* json util * json util
* @author Nacos * @author Nacos

View File

@ -17,9 +17,6 @@ package com.alibaba.nacos.config.server.utils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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 * log util
@ -28,30 +25,6 @@ import ch.qos.logback.core.joran.spi.JoranException;
*/ */
public class LogUtil { 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");
}
}
}
/** /**
* 默认的日志 * 默认的日志
*/ */

View File

@ -15,14 +15,14 @@
*/ */
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import com.alibaba.nacos.config.server.constant.Constants;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import com.alibaba.nacos.config.server.constant.Constants;
/** /**
* md5 * md5
* @author Nacos * @author Nacos

View File

@ -15,28 +15,21 @@
*/ */
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import static com.alibaba.nacos.config.server.constant.Constants.LINE_SEPARATOR; import com.alibaba.nacos.config.server.constant.Constants;
import static com.alibaba.nacos.config.server.constant.Constants.WORD_SEPARATOR; import com.alibaba.nacos.config.server.service.ConfigService;
import org.apache.commons.lang3.StringUtils;
import java.io.CharArrayWriter; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import javax.servlet.http.HttpServletResponse;
import java.io.InputStream; import java.io.*;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import static com.alibaba.nacos.config.server.constant.Constants.LINE_SEPARATOR;
import javax.servlet.http.HttpServletResponse; import static com.alibaba.nacos.config.server.constant.Constants.WORD_SEPARATOR;
import org.apache.commons.lang.StringUtils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.service.ConfigService;
/** /**
* 轮询逻辑封装类 * 轮询逻辑封装类

View File

@ -15,12 +15,13 @@
*/ */
package com.alibaba.nacos.config.server.utils; 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.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper; 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; final int startRow = (pageNo - 1) * pageSize;
String selectSQL = ""; String selectSQL = "";
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
selectSQL = sqlFetchRows + " OFFSET "+startRow+" ROWS FETCH NEXT "+pageSize+" ROWS ONLY"; selectSQL = sqlFetchRows + " OFFSET "+startRow+" ROWS FETCH NEXT "+pageSize+" ROWS ONLY";
} else if (lastMaxId != null) { } else if (lastMaxId != null) {
selectSQL = sqlFetchRows + " and id > " + lastMaxId + " order by id asc" + " limit " + 0 + "," + pageSize; selectSQL = sqlFetchRows + " and id > " + lastMaxId + " order by id asc" + " limit " + 0 + "," + pageSize;
@ -132,7 +133,7 @@ public class PaginationHelper<E> {
} }
String selectSQL = sqlFetchRows; String selectSQL = sqlFetchRows;
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
} }
@ -172,7 +173,7 @@ public class PaginationHelper<E> {
} }
String selectSQL = sqlFetchRows; String selectSQL = sqlFetchRows;
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); 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>(); final Page<E> page = new Page<E>();
String selectSQL = sqlFetchRows; String selectSQL = sqlFetchRows;
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); 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[]) { public void updateLimit(final JdbcTemplate jt, final String sql, final Object args[]) {
String sqlUpdate = sql; String sqlUpdate = sql;
if (PropertyUtil.isStandaloneMode()) { if (STANDALONE_MODE) {
sqlUpdate = sqlUpdate.replaceAll("limit \\?", "OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY"); sqlUpdate = sqlUpdate.replaceAll("limit \\?", "OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");
} }

View File

@ -15,11 +15,10 @@
*/ */
package com.alibaba.nacos.config.server.utils; 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 com.alibaba.nacos.config.server.exception.NacosException;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
/** /**
* 参数合法性检查工具类 * 参数合法性检查工具类

View File

@ -15,18 +15,19 @@
*/ */
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import javax.annotation.PostConstruct;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
/** /**
* properties utils * properties utils
* *
* @author Nacos * @author Nacos
*
*/ */
@Component @Component
public class PropertyUtil { public class PropertyUtil {
@ -80,15 +81,9 @@ public class PropertyUtil {
*/ */
private static int correctUsageDelay = 10 * 60; private static int correctUsageDelay = 10 * 60;
private static boolean standaloneMode = false;
@Autowired @Autowired
private Environment env; private Environment env;
static {
setStandaloneMode(Boolean.parseBoolean(System.getProperty("nacos.standalone", "false")));
}
@PostConstruct @PostConstruct
public void init() { public void init() {
try { try {
@ -206,11 +201,7 @@ public class PropertyUtil {
} }
public static boolean isStandaloneMode() { public static boolean isStandaloneMode() {
return standaloneMode; return STANDALONE_MODE;
}
public static void setStandaloneMode(boolean standaloneMode) {
PropertyUtil.standaloneMode = standaloneMode;
} }
public static void setNotifyConnectTimeout(int notifyConnectTimeout) { public static void setNotifyConnectTimeout(int notifyConnectTimeout) {

View File

@ -15,9 +15,7 @@
*/ */
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import org.apache.commons.lang.CharUtils; import org.apache.commons.lang3.CharUtils;
import org.apache.commons.lang.NullArgumentException;
/** /**
@ -40,7 +38,7 @@ public class RegexParser {
*/ */
static public String regexFormat(String regex) { static public String regexFormat(String regex) {
if (regex == null) { 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(); StringBuffer result = new StringBuffer();
result.append("^"); result.append("^");
@ -75,8 +73,4 @@ public class RegexParser {
return (regex.contains("?") || regex.contains("*")); return (regex.contains("?") || regex.contains("*"));
} }
public static void main(String[] args) {
String str = "com.taobao.uic.*";
System.out.println(str + " -> " + regexFormat(str));
}
} }

View File

@ -15,16 +15,12 @@
*/ */
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import java.io.File; import com.alibaba.nacos.config.server.constant.Constants;
import java.io.IOException;
import java.io.InputStream; import java.io.*;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL; import java.net.URL;
import java.util.Properties; import java.util.Properties;
import com.alibaba.nacos.config.server.constant.Constants;
/** /**
* resource util * resource util

View File

@ -15,10 +15,10 @@
*/ */
package com.alibaba.nacos.config.server.utils; 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 javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import static com.alibaba.nacos.config.server.utils.LogUtil.defaultLog;
/** /**
* write response * write response

View File

@ -15,13 +15,13 @@
*/ */
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.context.WebServerInitializedEvent; import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.ServletContext;
/** /**
* Running config * Running config
* @author dungu.zpf * @author dungu.zpf

View File

@ -15,14 +15,14 @@
*/ */
package com.alibaba.nacos.config.server.utils; 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.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.util.Enumeration; import java.util.Enumeration;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* System config * System config
* @author Nacos * @author Nacos

View File

@ -15,15 +15,17 @@
*/ */
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import org.apache.commons.lang3.time.FastDateFormat;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import org.apache.commons.lang.time.FastDateFormat;
/** /**
* Time util * Time util
* @author Nacos
* *
* @author Nacos
*/ */
public class TimeUtils { public class TimeUtils {
@ -31,9 +33,6 @@ public class TimeUtils {
Date date = new Date(); Date date = new Date();
return new Timestamp(date.getTime()); return new Timestamp(date.getTime());
} }
public static void main(String[] args) {
System.out.println(getCurrentTime().toString());
}
static public String getCurrentTimeStr() { static public String getCurrentTimeStr() {
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();

View File

@ -15,11 +15,11 @@
*/ */
package com.alibaba.nacos.config.server.utils; package com.alibaba.nacos.config.server.utils;
import com.alibaba.nacos.config.server.constant.Constants;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.alibaba.nacos.config.server.constant.Constants;
/** /**
* 分析url的工具类 * 分析url的工具类

View File

@ -15,12 +15,12 @@
*/ */
package com.alibaba.nacos.config.server.utils.event; package com.alibaba.nacos.config.server.utils.event;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* Event dispatcher * Event dispatcher

View File

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml> <included>
<configuration scan="true" scanPeriod="10 seconds">
<appender name="dumpFile" <appender name="dumpFile"
class="ch.qos.logback.core.rolling.RollingFileAppender"> class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${user.home}/nacos/logs/config-dump.log</file> <file>${user.home}/nacos/logs/config-dump.log</file>
@ -279,5 +277,6 @@
<level value="INFO"/> <level value="INFO"/>
<appender-ref ref="rootFile"/> <appender-ref ref="rootFile"/>
</root> </root>
</configuration>
</included>

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);
// }
//
//}

View File

@ -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);
}
}

View File

@ -18,7 +18,8 @@
<parent> <parent>
<groupId>com.alibaba.nacos</groupId> <groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId> <artifactId>nacos-all</artifactId>
<version>0.2.1</version> <version>0.2.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>nacos-console</artifactId> <artifactId>nacos-console</artifactId>
<!--<packaging>war</packaging>--> <!--<packaging>war</packaging>-->
@ -34,33 +35,17 @@
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>nacos-config</artifactId> <artifactId>nacos-config</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.59</version>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>nacos-naming</artifactId> <artifactId>nacos-naming</artifactId>
</dependency> </dependency>
<!-- log -->
<!-- log4j通过slf4j来代理 -->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.apache.tomcat.embed</groupId>
<artifactId>log4j-over-slf4j</artifactId> <artifactId>tomcat-embed-jasper</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>
</dependency> </dependency>
<!-- log -->
</dependencies> </dependencies>
<build> <build>
<finalName>nacos-server</finalName> <finalName>nacos-server</finalName>

View File

@ -1,8 +1,5 @@
# spring # Console Default Properties
management.security.enabled=false
server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.port=8848
spring.mvc.view.prefix=/jsp/ spring.mvc.view.prefix=/jsp/
# 响应页面默认后缀 # 响应页面默认后缀
spring.mvc.view.suffix=.jsp spring.mvc.view.suffix=.jsp

View File

@ -1,15 +0,0 @@
,--.
,--.'|
,--,: : |
,`--.'`| ' : ,---.
| : : | | ' ,'\ .--.--.
: | \ | : ,--.--. ,---. / / | / / '
| : ' '; | / \ / \. ; ,. :| : /`./
' ' ;. ;.--. .-. | / / '' | |: :| : ;_
| | | \ | \__\/: . .. ' / ' | .; : \ \ `.
' : | ; .' ," .--.; |' ; :__| : | `----. \
| | '`--' / / ,. |' | '.'|\ \ / / /`--' /
' : | ; : .' \ : : `----' '--'. /
; |.' | , .-./\ \ / `--'---'
'---' `--`---' `----'

Some files were not shown because too many files have changed in this diff Show More