diff --git a/common/src/main/java/com/alibaba/nacos/common/util/VersionUtils.java b/common/src/main/java/com/alibaba/nacos/common/util/VersionUtils.java new file mode 100644 index 00000000000..5609aa63c29 --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/util/VersionUtils.java @@ -0,0 +1,31 @@ +package com.alibaba.nacos.common.util; + +import java.io.InputStream; +import java.util.Properties; + +/** + * @author xingxuechao + * on:2019/2/27 12:32 PM + */ +public class VersionUtils { + + public static String VERSION; + /**获取当前version*/ + public static final String VERSION_DEFAULT = "${pom.version}"; + + + static{ + try{ + InputStream in = VersionUtils.class.getClassLoader() + .getResourceAsStream("nacos-version.txt"); + Properties props = new Properties(); + props.load(in); + String val = props.getProperty("version"); + if (val != null && !VERSION_DEFAULT.equals(val)) { + VERSION = val; + } + } catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/console/src/main/java/com/alibaba/nacos/console/controller/ServerStateController.java b/console/src/main/java/com/alibaba/nacos/console/controller/ServerStateController.java new file mode 100644 index 00000000000..f1fb43ead80 --- /dev/null +++ b/console/src/main/java/com/alibaba/nacos/console/controller/ServerStateController.java @@ -0,0 +1,60 @@ +/* + * 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.console.controller; + + +import com.alibaba.nacos.common.util.VersionUtils; +import com.alibaba.nacos.core.utils.SystemUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import java.util.HashMap; +import java.util.Map; + +/** + * @author xingxuechao + * on:2019/2/27 11:17 AM + */ +@RestController +@RequestMapping("/v1/console/server") +public class ServerStateController { + + private static final Logger logger = LoggerFactory.getLogger(ServerStateController.class); + + + public static String VERSION ; + + + @ResponseBody + @RequestMapping(value = "state", method = RequestMethod.GET) + public ResponseEntity serverState() { + Map serverState = new HashMap(3); + serverState.put("standalone_mode",SystemUtils.STANDALONE_MODE ? + SystemUtils.STANDALONE_MODE_ALONE : SystemUtils.STANDALONE_MODE_CLUSTER); + + serverState.put("function_mode", SystemUtils.FUNCTION_MODE); + serverState.put("version", VersionUtils.VERSION); + + return ResponseEntity.ok().body(serverState); + } + + + +} diff --git a/console/src/main/resources/application.properties b/console/src/main/resources/application.properties index b28b04f6431..64c42676e27 100644 --- a/console/src/main/resources/application.properties +++ b/console/src/main/resources/application.properties @@ -1,3 +1,40 @@ +# spring +server.contextPath=/nacos +server.servlet.contextPath=/nacos +server.port=8848 +nacos.cmdb.dumpTaskInterval=3600 +nacos.cmdb.eventTaskInterval=10 +nacos.cmdb.labelTaskInterval=300 +nacos.cmdb.loadDataAtStart=false + +# metrics for prometheus +#management.endpoints.web.exposure.include=* + +# metrics for elastic search +management.metrics.export.elastic.enabled=false +#management.metrics.export.elastic.host=http://localhost:9200 + +# metrics for influx +management.metrics.export.influx.enabled=false +#management.metrics.export.influx.db=springboot +#management.metrics.export.influx.uri=http://localhost:8086 +#management.metrics.export.influx.auto-create-db=true +#management.metrics.export.influx.consistency=one +#management.metrics.export.influx.compressed=true + +server.tomcat.accesslog.enabled=true +server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D +# default current work dir +server.tomcat.basedir= + +## spring security config +### turn off security +#spring.security.enabled=false +#management.security=false +#security.basic.enabled=false +#nacos.security.ignore.urls=/** + +nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/** diff --git a/console/src/main/resources/nacos-version.txt b/console/src/main/resources/nacos-version.txt new file mode 100755 index 00000000000..ae1ef5aa0bb --- /dev/null +++ b/console/src/main/resources/nacos-version.txt @@ -0,0 +1 @@ +version=${pom.version} diff --git a/core/src/main/java/com/alibaba/nacos/core/listener/StartingSpringApplicationRunListener.java b/core/src/main/java/com/alibaba/nacos/core/listener/StartingSpringApplicationRunListener.java index 86881d8dfb4..4c927a7ddad 100644 --- a/core/src/main/java/com/alibaba/nacos/core/listener/StartingSpringApplicationRunListener.java +++ b/core/src/main/java/com/alibaba/nacos/core/listener/StartingSpringApplicationRunListener.java @@ -15,6 +15,7 @@ */ package com.alibaba.nacos.core.listener; +import com.alibaba.nacos.core.utils.SystemUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; @@ -31,6 +32,7 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; +import static com.alibaba.nacos.core.utils.SystemUtils.FUNCTION_MODE; import static com.alibaba.nacos.core.utils.SystemUtils.LOCAL_IP; import static com.alibaba.nacos.core.utils.SystemUtils.NACOS_HOME; import static com.alibaba.nacos.core.utils.SystemUtils.STANDALONE_MODE; @@ -46,7 +48,9 @@ public class StartingSpringApplicationRunListener implements SpringApplicationRu private static final Logger LOGGER = LoggerFactory.getLogger(StartingSpringApplicationRunListener.class); - private static final String MODE_PROPERTY_KEY = "nacos.mode"; + private static final String MODE_PROPERTY_KEY_STAND_MODE = "nacos.mode"; + + private static final String MODE_PROPERTY_KEY_FUNCTION_MODE = "nacos.function.mode"; private static final String LOCAL_IP_PROPERTY_KEY = "nacos.local.ip"; @@ -66,11 +70,19 @@ public void starting() { @Override public void environmentPrepared(ConfigurableEnvironment environment) { if (STANDALONE_MODE) { - System.setProperty(MODE_PROPERTY_KEY, "stand alone"); + System.setProperty(MODE_PROPERTY_KEY_STAND_MODE, "stand alone"); } else { - System.setProperty(MODE_PROPERTY_KEY, "cluster"); + System.setProperty(MODE_PROPERTY_KEY_STAND_MODE, "cluster"); + } + if (FUNCTION_MODE == null) { + System.setProperty(MODE_PROPERTY_KEY_FUNCTION_MODE, "All"); + } else if(SystemUtils.FUNCTION_MODE_CONFIG.equals(FUNCTION_MODE)){ + System.setProperty(MODE_PROPERTY_KEY_FUNCTION_MODE, SystemUtils.FUNCTION_MODE_CONFIG); + } else if(SystemUtils.FUNCTION_MODE_NAMING.equals(FUNCTION_MODE)) { + System.setProperty(MODE_PROPERTY_KEY_FUNCTION_MODE, SystemUtils.FUNCTION_MODE_NAMING); } + System.setProperty(LOCAL_IP_PROPERTY_KEY, LOCAL_IP); } @@ -96,7 +108,7 @@ public void started(ConfigurableApplicationContext context) { logFilePath(); - LOGGER.info("Nacos started successfully in {} mode.", System.getProperty(MODE_PROPERTY_KEY)); + LOGGER.info("Nacos started successfully in {} mode.", System.getProperty(MODE_PROPERTY_KEY_STAND_MODE)); } @Override diff --git a/core/src/main/java/com/alibaba/nacos/core/utils/Constants.java b/core/src/main/java/com/alibaba/nacos/core/utils/Constants.java index 3cb6f63bc47..588ae88b0e2 100644 --- a/core/src/main/java/com/alibaba/nacos/core/utils/Constants.java +++ b/core/src/main/java/com/alibaba/nacos/core/utils/Constants.java @@ -33,6 +33,11 @@ public interface Constants { */ String STANDALONE_MODE_PROPERTY_NAME = "nacos.standalone"; + /** + * The System property name of Function mode + */ + String FUNCTION_MODE_PROPERTY_NAME = "nacos.functionMode"; + /** * The System property name of prefer hostname over ip */ diff --git a/core/src/main/java/com/alibaba/nacos/core/utils/SystemUtils.java b/core/src/main/java/com/alibaba/nacos/core/utils/SystemUtils.java index bb2bba6a693..4350ebba94b 100644 --- a/core/src/main/java/com/alibaba/nacos/core/utils/SystemUtils.java +++ b/core/src/main/java/com/alibaba/nacos/core/utils/SystemUtils.java @@ -27,13 +27,11 @@ import java.io.IOException; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static com.alibaba.nacos.core.utils.Constants.PREFER_HOSTNAME_OVER_IP_PROPERTY_NAME; +import static com.alibaba.nacos.core.utils.Constants.FUNCTION_MODE_PROPERTY_NAME; import static com.alibaba.nacos.core.utils.Constants.STANDALONE_MODE_PROPERTY_NAME; import static org.apache.commons.lang3.CharEncoding.UTF_8; @@ -49,6 +47,19 @@ public class SystemUtils { */ public static boolean STANDALONE_MODE = Boolean.getBoolean(STANDALONE_MODE_PROPERTY_NAME); + public static final String STANDALONE_MODE_ALONE = "standalone"; + public static final String STANDALONE_MODE_CLUSTER = "cluster"; + + /** + * server + */ + public static String FUNCTION_MODE = System.getProperty(FUNCTION_MODE_PROPERTY_NAME); + + public static final String FUNCTION_MODE_CONFIG = "config"; + public static final String FUNCTION_MODE_NAMING = "naming"; + + + private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean)ManagementFactory .getOperatingSystemMXBean(); diff --git a/core/src/main/resources/banner.txt b/core/src/main/resources/banner.txt index 204416e50f9..a4821120f1e 100644 --- a/core/src/main/resources/banner.txt +++ b/core/src/main/resources/banner.txt @@ -2,7 +2,7 @@ ,--. ,--.'| ,--,: : | Nacos ${application.version} -,`--.'`| ' : ,---. Running in ${nacos.mode} mode +,`--.'`| ' : ,---. Running in ${nacos.mode} mode, ${nacos.function.mode} function modules | : : | | ' ,'\ .--.--. Port: ${server.port} : | \ | : ,--.--. ,---. / / | / / ' Pid: ${pid} | : ' '; | / \ / \. ; ,. :| : /`./ Console: http://${nacos.local.ip}:${server.port}/nacos/index.html diff --git a/distribution/bin/startup.sh b/distribution/bin/startup.sh index 14fb807c7d5..c86dd66d660 100644 --- a/distribution/bin/startup.sh +++ b/distribution/bin/startup.sh @@ -52,12 +52,14 @@ if [ -z "$JAVA_HOME" ]; then fi export MODE="cluster" -while getopts ":m:" opt +export FUNCTION_MODE="all" +while getopts ":m:f:" opt do case $opt in m) - MODE=$OPTARG - ;; + MODE=$OPTARG;; + f) + FUNCTION_MODE=$OPTARG;; ?) echo "Unknown parameter" exit 1;; @@ -83,6 +85,13 @@ else fi +if [[ "${FUNCTION_MODE}" == "config" ]]; then + JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=config" +elif [[ "${FUNCTION_MODE}" == "naming" ]]; then + JAVA_OPT="${JAVA_OPT} -Dnacos.functionMode=naming" +fi + + JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p') if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] ; then JAVA_OPT="${JAVA_OPT} -cp .:${BASE_DIR}/plugins/cmdb/*.jar" diff --git a/distribution/conf/application.properties b/distribution/conf/application.properties index e0624f8dea1..64c42676e27 100644 --- a/distribution/conf/application.properties +++ b/distribution/conf/application.properties @@ -37,4 +37,4 @@ server.tomcat.basedir= #security.basic.enabled=false #nacos.security.ignore.urls=/** -nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/** +nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**