Skip to content

Commit

Permalink
Merge pull request #4 from alibaba/develop
Browse files Browse the repository at this point in the history
update
  • Loading branch information
stackisok authored Sep 9, 2019
2 parents 8162533 + e5f6cab commit d3b586b
Show file tree
Hide file tree
Showing 32 changed files with 256 additions and 179 deletions.
4 changes: 4 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public class Constants {
public static final String NULL_STRING = "null";

public static final String NUMBER_PATTERN = "^\\d+$";

public static final String ANY_PATTERN = ".*";

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import com.google.common.base.Objects;

/**
* @author nkorange
Expand Down Expand Up @@ -138,7 +138,7 @@ public void jsonAdapterCallback(SerializeWriter writer) {

@Override
public int hashCode() {
return Objects.hash(path, headers, expectedResponseCode);
return Objects.hashCode(path, headers, expectedResponseCode);
}

@Override
Expand Down Expand Up @@ -184,7 +184,7 @@ public Tcp() {

@Override
public int hashCode() {
return Objects.hash(TYPE);
return Objects.hashCode(TYPE);
}

@Override
Expand Down Expand Up @@ -250,7 +250,7 @@ public void jsonAdapterCallback(SerializeWriter writer) {

@Override
public int hashCode() {
return Objects.hash(user, pwd, cmd);
return Objects.hashCode(user, pwd, cmd);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.alibaba.nacos.client.config.utils.IOUtils;
import com.alibaba.nacos.client.config.utils.MD5;
import com.alibaba.nacos.client.utils.ParamUtil;
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
import com.alibaba.nacos.common.util.UuidUtils;
import com.alibaba.nacos.common.util.VersionUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -201,7 +203,7 @@ static private void setHeaders(HttpURLConnection conn, List<String> headers, Str
conn.addRequestProperty(iter.next(), iter.next());
}
}
conn.addRequestProperty("Client-Version", ParamUtil.getClientVersion());
conn.addRequestProperty(HttpHeaderConsts.CLIENT_VERSION_HEADER, VersionUtils.VERSION);
conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding);

String ts = String.valueOf(System.currentTimeMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public Thread newThread(Runnable r) {

public void addBeatInfo(String serviceName, BeatInfo beatInfo) {
NAMING_LOGGER.info("[BEAT] adding beat: {} to beat map.", beatInfo);
dom2Beat.put(buildKey(serviceName, beatInfo.getIp(), beatInfo.getPort()), beatInfo);
String key = buildKey(serviceName, beatInfo.getIp(), beatInfo.getPort());
BeatInfo existBeat = null;
//fix #1733
if ((existBeat = dom2Beat.remove(key)) != null) {
existBeat.setStopped(true);
}
dom2Beat.put(key, beatInfo);
executorService.schedule(new BeatTask(beatInfo), beatInfo.getPeriod(), TimeUnit.MILLISECONDS);
MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import com.alibaba.nacos.client.utils.AppNameUtils;
import com.alibaba.nacos.client.utils.StringUtils;
import com.alibaba.nacos.client.utils.TemplateUtils;
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
import com.alibaba.nacos.common.util.HttpMethod;
import com.alibaba.nacos.common.util.UuidUtils;
import com.alibaba.nacos.common.util.VersionUtils;

import java.io.IOException;
import java.io.StringReader;
Expand Down Expand Up @@ -499,8 +501,9 @@ private void checkSignature(Map<String, String> params) {
}

public List<String> builderHeaders() {
List<String> headers = Arrays.asList("Client-Version", UtilAndComs.VERSION,
"User-Agent", UtilAndComs.VERSION,
List<String> headers = Arrays.asList(
HttpHeaderConsts.CLIENT_VERSION_HEADER, VersionUtils.VERSION,
HttpHeaderConsts.USER_AGENT_HEADER, UtilAndComs.VERSION,
"Accept-Encoding", "gzip,deflate,sdch",
"Connection", "Keep-Alive",
"RequestId", UuidUtils.generateUuid(), "Request-Module", "Naming");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.constant;

/**
* Nacos header constants
*
* @author ly
*/
public interface HttpHeaderConsts {

String CLIENT_VERSION_HEADER = "Client-Version";
String USER_AGENT_HEADER = "User-Agent";

}
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public ResponseEntity<byte[]> exportConfig(HttpServletRequest request,
defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "ids", required = false)List<Long> ids) {
ids.removeAll(Collections.singleton(null));
List<ConfigInfo> dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids);
List<ConfigAllInfo> dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids);
List<ZipUtils.ZipItem> zipItemList = new ArrayList<>();
StringBuilder metaData = null;
for(ConfigInfo ci : dataList){
Expand Down Expand Up @@ -482,7 +482,7 @@ public RestResult<Map<String, Object>> importAndPublishConfig(HttpServletRequest
return ResultBuilder.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData);
}
}
List<ConfigInfo> configInfoList = null;
List<ConfigAllInfo> configInfoList = null;
try {
ZipUtils.UnZipResult unziped = ZipUtils.unzip(file.getBytes());
ZipUtils.ZipItem metaDataZipItem = unziped.getMetaDataItem();
Expand Down Expand Up @@ -516,7 +516,7 @@ public RestResult<Map<String, Object>> importAndPublishConfig(HttpServletRequest
+ "~" + tempDataId.substring(tempDataId.lastIndexOf(".") + 1);
}
String metaDataId = group + "." + tempDataId + ".app";
ConfigInfo ci = new ConfigInfo();
ConfigAllInfo ci = new ConfigAllInfo();
ci.setTenant(namespace);
ci.setGroup(group);
ci.setDataId(dataId);
Expand Down Expand Up @@ -570,18 +570,19 @@ public RestResult<Map<String, Object>> cloneConfig(HttpServletRequest request,
}

ids.removeAll(Collections.singleton(null));
List<ConfigInfo> queryedDataList = persistService.findAllConfigInfo4Export(null,null, null, null, ids);
List<ConfigAllInfo> queryedDataList = persistService.findAllConfigInfo4Export(null,null, null, null, ids);

if(queryedDataList == null || queryedDataList.isEmpty()){
failedData.put("succCount", 0);
return ResultBuilder.buildResult(ResultCodeEnum.DATA_EMPTY, failedData);
}

List<ConfigInfo> configInfoList4Clone = new ArrayList<>(queryedDataList.size());
List<ConfigAllInfo> configInfoList4Clone = new ArrayList<>(queryedDataList.size());

for(ConfigInfo ci : queryedDataList){
ConfigInfo ci4save = new ConfigInfo();
for(ConfigAllInfo ci : queryedDataList){
ConfigAllInfo ci4save = new ConfigAllInfo();
ci4save.setTenant(namespace);
ci4save.setType(ci.getType());
ci4save.setGroup(ci.getGroup());
ci4save.setDataId(ci.getDataId());
ci4save.setContent(ci.getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class PersistService {

private DataSourceService dataSourceService;

private static final String SQL_FIND_ALL_CONFIG_INFO = "select data_id,group_id,tenant_id,app_name,content,type from config_info";
private static final String SQL_FIND_ALL_CONFIG_INFO = "select id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,src_ip,c_desc,c_use,effect,c_schema from config_info";

private static final String SQL_TENANT_INFO_COUNT_BY_TENANT_ID = "select count(1) from tenant_info where tenant_id = ?";

Expand Down Expand Up @@ -3419,7 +3419,7 @@ public Boolean completeMd5() {
* @param group
* @return Collection of ConfigInfo objects
*/
public List<ConfigInfo> findAllConfigInfo4Export(final String dataId, final String group, final String tenant,
public List<ConfigAllInfo> findAllConfigInfo4Export(final String dataId, final String group, final String tenant,
final String appName, final List<Long> ids) {
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
StringBuilder where = new StringBuilder(" where ");
Expand Down Expand Up @@ -3451,7 +3451,7 @@ public List<ConfigInfo> findAllConfigInfo4Export(final String dataId, final Stri
}
}
try {
return this.jt.query(SQL_FIND_ALL_CONFIG_INFO + where, paramList.toArray(), CONFIG_INFO_ROW_MAPPER);
return this.jt.query(SQL_FIND_ALL_CONFIG_INFO + where, paramList.toArray(), CONFIG_ALL_INFO_ROW_MAPPER);
} catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error] " + e.toString(), e);
throw e;
Expand All @@ -3466,15 +3466,15 @@ public List<ConfigInfo> findAllConfigInfo4Export(final String dataId, final Stri
* failData: import failed data (only with abort for the same configs)
* skipData: data skipped at import (only with skip for the same configs)
*/
public Map<String, Object> batchInsertOrUpdate(List<ConfigInfo> configInfoList, String srcUser, String srcIp,
public Map<String, Object> batchInsertOrUpdate(List<ConfigAllInfo> configInfoList, String srcUser, String srcIp,
Map<String, Object> configAdvanceInfo, Timestamp time, boolean notify, SameConfigPolicy policy) throws NacosException {
int succCount = 0;
int skipCount = 0;
List<Map<String, String>> failData = null;
List<Map<String, String>> skipData = null;

for (int i = 0; i < configInfoList.size(); i++) {
ConfigInfo configInfo = configInfoList.get(i);
ConfigAllInfo configInfo = configInfoList.get(i);
try {
ParamUtils.checkParam(configInfo.getDataId(), configInfo.getGroup(), "datumId", configInfo.getContent());
} catch (NacosException e) {
Expand All @@ -3484,14 +3484,16 @@ public Map<String, Object> batchInsertOrUpdate(List<ConfigInfo> configInfoList,
ConfigInfo configInfo2Save = new ConfigInfo(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant(), configInfo.getAppName(), configInfo.getContent());

// simple judgment of file type based on suffix
String type = null;
if (configInfo.getDataId().contains(SPOT)) {
String extName = configInfo.getDataId().substring(configInfo.getDataId().lastIndexOf(SPOT) + 1).toLowerCase();
try {
type = FileTypeEnum.valueOf(extName).getFileType();
} catch (Exception ex) {
type = FileTypeEnum.TEXT.getFileType();
String type = configInfo.getType();
if (StringUtils.isBlank(type)) {
// simple judgment of file type based on suffix
if (configInfo.getDataId().contains(SPOT)) {
String extName = configInfo.getDataId().substring(configInfo.getDataId().lastIndexOf(SPOT) + 1).toUpperCase();
try {
type = FileTypeEnum.valueOf(extName).getFileType();
} catch (Exception ex) {
type = FileTypeEnum.TEXT.getFileType();
}
}
}
if (configAdvanceInfo == null) {
Expand Down
11 changes: 1 addition & 10 deletions console/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
# spring

server.servlet.contextPath=/nacos
server.servlet.context-path=/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/**
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface Constants {
*/
String STANDALONE_MODE_PROPERTY_NAME = "nacos.standalone";

/**
/**
* The System property name of Function mode
*/
String FUNCTION_MODE_PROPERTY_NAME = "nacos.functionMode";
Expand All @@ -43,6 +43,11 @@ public interface Constants {
*/
String PREFER_HOSTNAME_OVER_IP_PROPERTY_NAME = "nacos.preferHostnameOverIp";

/**
* the root context path
*/
String ROOT_WEB_CONTEXT_PATH = "/";

String NACOS_SERVER_IP = "nacos.server.ip";

String USE_ONLY_SITE_INTERFACES = "nacos.inetutils.use-only-site-local-interfaces";
Expand All @@ -51,4 +56,6 @@ public interface Constants {
String IP_ADDRESS = "nacos.inetutils.ip-address";
String PREFER_HOSTNAME_OVER_IP = "nacos.inetutils.prefer-hostname-over-ip";
String SYSTEM_PREFER_HOSTNAME_OVER_IP = "nacos.preferHostnameOverIp";
String WEB_CONTEXT_PATH = "server.servlet.context-path";
String COMMA_DIVISION = ",";
}
11 changes: 10 additions & 1 deletion core/src/main/java/com/alibaba/nacos/core/utils/SystemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@ public static List<String> readClusterConf() throws IOException {
instance = instance.substring(0, instance.indexOf(comment));
instance = instance.trim();
}
instanceList.add(instance);
int multiIndex = instance.indexOf(Constants.COMMA_DIVISION);
if (multiIndex > 0) {
// support the format: ip1:port,ip2:port # multi inline
for (String ins : instance.split(Constants.COMMA_DIVISION)) {
instanceList.add(ins);
}
} else {
//support the format: 192.168.71.52:8848
instanceList.add(instance);
}
}
return instanceList;
} finally {
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/com/alibaba/nacos/core/utils/WebUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.alibaba.nacos.core.utils;

import com.alibaba.nacos.common.constant.HttpHeaderConsts;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -71,4 +72,20 @@ public static String getAcceptEncoding(HttpServletRequest req) {
encode = encode.contains(",") ? encode.substring(0, encode.indexOf(",")) : encode;
return encode.contains(";") ? encode.substring(0, encode.indexOf(";")) : encode;
}

/**
* Returns the value of the request header "user-agent" as a <code>String</code>.
*
* @param request HttpServletRequest
* @return the value of the request header "user-agent", or the value of the
* request header "client-version" if the request does not have a
* header of "user-agent"
*/
public static String getUserAgent(HttpServletRequest request) {
String userAgent = request.getHeader(HttpHeaderConsts.USER_AGENT_HEADER);
if (StringUtils.isEmpty(userAgent)) {
userAgent = StringUtils.defaultIfEmpty(request.getHeader(HttpHeaderConsts.CLIENT_VERSION_HEADER), StringUtils.EMPTY);
}
return userAgent;
}
}
4 changes: 3 additions & 1 deletion distribution/bin/shutdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
# 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.
cd `dirname $0`/../target
target_dir=`pwd`

pid=`ps ax | grep -i 'nacos.nacos' |grep java | grep -v grep | awk '{print $1}'`
pid=`ps ax | grep -i 'nacos.nacos' | grep ${target_dir} | grep java | grep -v grep | awk '{print $1}'`
if [ -z "$pid" ] ; then
echo "No nacosServer running."
exit -1;
Expand Down
Loading

0 comments on commit d3b586b

Please sign in to comment.