From 75dfd107bbc485e8973a48f2348a2a481ef16e9d Mon Sep 17 00:00:00 2001 From: Gagharv Date: Mon, 20 Jul 2020 19:40:30 +0800 Subject: [PATCH 1/9] [#3353]Adjust the value logic of clientBeatInterval (#3377) --- .../com/alibaba/nacos/api/naming/pojo/Instance.java | 13 +++++++++++++ .../naming/controllers/InstanceController.java | 7 +++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/com/alibaba/nacos/api/naming/pojo/Instance.java b/api/src/main/java/com/alibaba/nacos/api/naming/pojo/Instance.java index 9f96cfb95..14f674224 100644 --- a/api/src/main/java/com/alibaba/nacos/api/naming/pojo/Instance.java +++ b/api/src/main/java/com/alibaba/nacos/api/naming/pojo/Instance.java @@ -231,6 +231,19 @@ public class Instance { Constants.DEFAULT_INSTANCE_ID_GENERATOR); } + /** + * Returns {@code true} if this metadata contains the specified key. + * + * @param key metadata key + * @return {@code true} if this metadata contains the specified key + */ + public boolean containsMetadata(final String key) { + if (getMetadata() == null || getMetadata().isEmpty()) { + return false; + } + return getMetadata().containsKey(key); + } + private long getMetaDataByKeyWithDefault(final String key, final long defaultValue) { if (getMetadata() == null || getMetadata().isEmpty()) { return defaultValue; diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java index 0d3aecfb7..403ff6ec9 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java @@ -20,6 +20,7 @@ import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.api.naming.NamingResponseCode; +import com.alibaba.nacos.api.naming.PreservedMetadataKeys; import com.alibaba.nacos.api.naming.utils.NamingUtils; import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.core.auth.ActionTypes; @@ -322,7 +323,7 @@ public class InstanceController { public ObjectNode beat(HttpServletRequest request) throws Exception { ObjectNode result = JacksonUtils.createEmptyJsonNode(); - result.put("clientBeatInterval", switchDomain.getClientBeatInterval()); + result.put(SwitchEntry.CLIENT_BEAT_INTERVAL, switchDomain.getClientBeatInterval()); String beat = WebUtils.optional(request, "beat", StringUtils.EMPTY); RsInfo clientBeat = null; @@ -385,7 +386,9 @@ public class InstanceController { service.processClientBeat(clientBeat); result.put(CommonParams.CODE, NamingResponseCode.OK); - result.put("clientBeatInterval", instance.getInstanceHeartBeatInterval()); + if (instance.containsMetadata(PreservedMetadataKeys.HEART_BEAT_INTERVAL)) { + result.put(SwitchEntry.CLIENT_BEAT_INTERVAL, instance.getInstanceHeartBeatInterval()); + } result.put(SwitchEntry.LIGHT_BEAT_ENABLED, switchDomain.isLightBeatEnabled()); return result; } From 5eb7d6a38dc8124951018183a012e9df9d240fda Mon Sep 17 00:00:00 2001 From: GangHuo <993610942@qq.com> Date: Mon, 20 Jul 2020 19:41:53 +0800 Subject: [PATCH 2/9] [ISSUE #3370] Issue with executing shell script /bin/sh^M on Unix/Linux (#3371) * Replace RuntimeException caused by HealthCheckerFactory with Nacos serialization exception * 1. Format startup.sh and shutdown.sh. Use Unix/Linux standard newline LF 2. Solve the OS = Windows error when packaging Maven (does not affect packaging) --- distribution/release-nacos.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribution/release-nacos.xml b/distribution/release-nacos.xml index 06298093a..1c7b2a10d 100644 --- a/distribution/release-nacos.xml +++ b/distribution/release-nacos.xml @@ -55,7 +55,7 @@ ../console/target/nacos-server.jar - /target/ + target/ From 2eaed4bcdc4375be7a812e09aa5356e03a4fe3ed Mon Sep 17 00:00:00 2001 From: yangy Date: Tue, 21 Jul 2020 14:50:19 +0800 Subject: [PATCH 3/9] Use PrepareStatement to replace string concatenation (#3393) --- .../embedded/EmbeddedStoragePersistServiceImpl.java | 4 ++-- .../repository/extrnal/ExternalStoragePersistServiceImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java index e510740bd..cf9e19124 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java @@ -1078,8 +1078,8 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService { @Override public int configInfoCount(String tenant) { - String sql = " SELECT COUNT(ID) FROM config_info where tenant_id like '" + tenant + "'"; - Integer result = databaseOperate.queryOne(sql, Integer.class); + String sql = " SELECT COUNT(ID) FROM config_info where tenant_id like ?"; + Integer result = databaseOperate.queryOne(sql, new Object[] {tenant}, Integer.class); if (result == null) { throw new IllegalArgumentException("configInfoCount error"); } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java index 6ced726e7..46bf257ac 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalStoragePersistServiceImpl.java @@ -1130,8 +1130,8 @@ public class ExternalStoragePersistServiceImpl implements PersistService { @Override public int configInfoCount(String tenant) { - String sql = " SELECT COUNT(ID) FROM config_info where tenant_id like '" + tenant + "'"; - Integer result = jt.queryForObject(sql, Integer.class); + String sql = " SELECT COUNT(ID) FROM config_info where tenant_id like ?"; + Integer result = jt.queryForObject(sql, new Object[] {tenant}, Integer.class); if (result == null) { throw new IllegalArgumentException("configInfoCount error"); } From 75a06834f5583a442416bad46ae71f73ae5072c7 Mon Sep 17 00:00:00 2001 From: "mai.jh" Date: Tue, 21 Jul 2020 14:53:03 +0800 Subject: [PATCH 4/9] unified implementation of http client package division (#3400) --- .../nacos/client/config/impl/ConfigHttpClientManager.java | 2 +- .../alibaba/nacos/common/http/AbstractHttpClientFactory.java | 4 ++-- .../nacos/common/http/client/AbstractNacosRestTemplate.java | 4 ++++ .../common/http/client/HttpClientRequestInterceptor.java | 2 ++ .../common/http/client/InterceptingHttpClientRequest.java | 2 ++ .../nacos/common/http/client/NacosAsyncRestTemplate.java | 3 +++ .../alibaba/nacos/common/http/client/NacosRestTemplate.java | 3 +++ .../http/client/{ => handler}/AbstractResponseHandler.java | 3 ++- .../common/http/client/{ => handler}/BeanResponseHandler.java | 3 ++- .../common/http/client/{ => handler}/ResponseHandler.java | 3 ++- .../http/client/{ => handler}/RestResultResponseHandler.java | 3 ++- .../http/client/{ => handler}/StringResponseHandler.java | 3 ++- .../http/client/{ => request}/AsyncHttpClientRequest.java | 3 ++- .../client/{ => request}/DefaultAsyncHttpClientRequest.java | 4 +++- .../http/client/{ => request}/DefaultHttpClientRequest.java | 4 +++- .../common/http/client/{ => request}/HttpClientRequest.java | 3 ++- .../http/client/{ => request}/JdkHttpClientRequest.java | 4 +++- .../http/client/{ => response}/DefaultClientHttpResponse.java | 2 +- .../common/http/client/{ => response}/HttpClientResponse.java | 2 +- .../http/client/{ => response}/JdkHttpClientResponse.java | 2 +- .../test/common/NacosRestTemplate_Interceptors_ITCase.java | 2 +- 21 files changed, 44 insertions(+), 17 deletions(-) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => handler}/AbstractResponseHandler.java (94%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => handler}/BeanResponseHandler.java (91%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => handler}/ResponseHandler.java (91%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => handler}/RestResultResponseHandler.java (93%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => handler}/StringResponseHandler.java (91%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => request}/AsyncHttpClientRequest.java (92%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => request}/DefaultAsyncHttpClientRequest.java (93%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => request}/DefaultHttpClientRequest.java (94%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => request}/HttpClientRequest.java (90%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => request}/JdkHttpClientRequest.java (94%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => response}/DefaultClientHttpResponse.java (97%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => response}/HttpClientResponse.java (97%) rename common/src/main/java/com/alibaba/nacos/common/http/client/{ => response}/JdkHttpClientResponse.java (97%) diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigHttpClientManager.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigHttpClientManager.java index d28ef4b2b..158c336da 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigHttpClientManager.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigHttpClientManager.java @@ -25,8 +25,8 @@ import com.alibaba.nacos.common.http.HttpClientBeanHolder; import com.alibaba.nacos.common.http.HttpClientConfig; import com.alibaba.nacos.common.http.HttpClientFactory; import com.alibaba.nacos.common.http.client.HttpClientRequestInterceptor; -import com.alibaba.nacos.common.http.client.HttpClientResponse; import com.alibaba.nacos.common.http.client.NacosRestTemplate; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.lifecycle.Closeable; import com.alibaba.nacos.common.model.RequestHttpEntity; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/AbstractHttpClientFactory.java b/common/src/main/java/com/alibaba/nacos/common/http/AbstractHttpClientFactory.java index e09a29b21..317265d31 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/AbstractHttpClientFactory.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/AbstractHttpClientFactory.java @@ -16,10 +16,10 @@ package com.alibaba.nacos.common.http; -import com.alibaba.nacos.common.http.client.DefaultAsyncHttpClientRequest; -import com.alibaba.nacos.common.http.client.JdkHttpClientRequest; import com.alibaba.nacos.common.http.client.NacosAsyncRestTemplate; import com.alibaba.nacos.common.http.client.NacosRestTemplate; +import com.alibaba.nacos.common.http.client.request.DefaultAsyncHttpClientRequest; +import com.alibaba.nacos.common.http.client.request.JdkHttpClientRequest; import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.nio.client.HttpAsyncClients; import org.slf4j.Logger; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/AbstractNacosRestTemplate.java b/common/src/main/java/com/alibaba/nacos/common/http/client/AbstractNacosRestTemplate.java index 7edd64e6e..006e596c7 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/AbstractNacosRestTemplate.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/AbstractNacosRestTemplate.java @@ -17,6 +17,10 @@ package com.alibaba.nacos.common.http.client; import com.alibaba.nacos.common.constant.ResponseHandlerType; +import com.alibaba.nacos.common.http.client.handler.BeanResponseHandler; +import com.alibaba.nacos.common.http.client.handler.ResponseHandler; +import com.alibaba.nacos.common.http.client.handler.RestResultResponseHandler; +import com.alibaba.nacos.common.http.client.handler.StringResponseHandler; import com.alibaba.nacos.common.utils.JacksonUtils; import com.fasterxml.jackson.databind.JavaType; import org.slf4j.Logger; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientRequestInterceptor.java b/common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientRequestInterceptor.java index 442221bff..8e984fb1d 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientRequestInterceptor.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientRequestInterceptor.java @@ -16,6 +16,8 @@ package com.alibaba.nacos.common.http.client; +import com.alibaba.nacos.common.http.client.request.HttpClientRequest; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.model.RequestHttpEntity; import java.net.URI; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/InterceptingHttpClientRequest.java b/common/src/main/java/com/alibaba/nacos/common/http/client/InterceptingHttpClientRequest.java index e612cc2e6..03b9713fe 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/InterceptingHttpClientRequest.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/InterceptingHttpClientRequest.java @@ -16,6 +16,8 @@ package com.alibaba.nacos.common.http.client; +import com.alibaba.nacos.common.http.client.request.HttpClientRequest; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.model.RequestHttpEntity; import java.io.IOException; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/NacosAsyncRestTemplate.java b/common/src/main/java/com/alibaba/nacos/common/http/client/NacosAsyncRestTemplate.java index f894c3a6d..31ee7999f 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/NacosAsyncRestTemplate.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/NacosAsyncRestTemplate.java @@ -18,6 +18,9 @@ package com.alibaba.nacos.common.http.client; import com.alibaba.nacos.common.http.Callback; import com.alibaba.nacos.common.http.HttpUtils; +import com.alibaba.nacos.common.http.client.handler.ResponseHandler; +import com.alibaba.nacos.common.http.client.request.AsyncHttpClientRequest; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.http.param.MediaType; import com.alibaba.nacos.common.http.param.Query; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/NacosRestTemplate.java b/common/src/main/java/com/alibaba/nacos/common/http/client/NacosRestTemplate.java index 38d9ce2d8..dd89929db 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/NacosRestTemplate.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/NacosRestTemplate.java @@ -19,6 +19,9 @@ package com.alibaba.nacos.common.http.client; import com.alibaba.nacos.common.http.HttpClientConfig; import com.alibaba.nacos.common.http.HttpRestResult; import com.alibaba.nacos.common.http.HttpUtils; +import com.alibaba.nacos.common.http.client.handler.ResponseHandler; +import com.alibaba.nacos.common.http.client.request.HttpClientRequest; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.http.param.MediaType; import com.alibaba.nacos.common.http.param.Query; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/AbstractResponseHandler.java b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/AbstractResponseHandler.java similarity index 94% rename from common/src/main/java/com/alibaba/nacos/common/http/client/AbstractResponseHandler.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/handler/AbstractResponseHandler.java index 698ddb915..049188371 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/AbstractResponseHandler.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/AbstractResponseHandler.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.handler; import com.alibaba.nacos.common.http.HttpRestResult; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.utils.IoUtils; import org.apache.http.HttpStatus; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/BeanResponseHandler.java b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/BeanResponseHandler.java similarity index 91% rename from common/src/main/java/com/alibaba/nacos/common/http/client/BeanResponseHandler.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/handler/BeanResponseHandler.java index 4a667e57d..70c531534 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/BeanResponseHandler.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/BeanResponseHandler.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.handler; import com.alibaba.nacos.common.http.HttpRestResult; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.utils.JacksonUtils; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/ResponseHandler.java b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/ResponseHandler.java similarity index 91% rename from common/src/main/java/com/alibaba/nacos/common/http/client/ResponseHandler.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/handler/ResponseHandler.java index 8508d1d8c..75feefe85 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/ResponseHandler.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/ResponseHandler.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.handler; import com.alibaba.nacos.common.http.HttpRestResult; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import java.lang.reflect.Type; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/RestResultResponseHandler.java b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/RestResultResponseHandler.java similarity index 93% rename from common/src/main/java/com/alibaba/nacos/common/http/client/RestResultResponseHandler.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/handler/RestResultResponseHandler.java index bb9da540b..ec83b6aec 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/RestResultResponseHandler.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/RestResultResponseHandler.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.handler; import com.alibaba.nacos.common.http.HttpRestResult; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.model.RestResult; import com.alibaba.nacos.common.utils.JacksonUtils; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/StringResponseHandler.java b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/StringResponseHandler.java similarity index 91% rename from common/src/main/java/com/alibaba/nacos/common/http/client/StringResponseHandler.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/handler/StringResponseHandler.java index ba1020d5a..43ca2cb44 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/StringResponseHandler.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/handler/StringResponseHandler.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.handler; import com.alibaba.nacos.common.http.HttpRestResult; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.utils.IoUtils; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/AsyncHttpClientRequest.java b/common/src/main/java/com/alibaba/nacos/common/http/client/request/AsyncHttpClientRequest.java similarity index 92% rename from common/src/main/java/com/alibaba/nacos/common/http/client/AsyncHttpClientRequest.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/request/AsyncHttpClientRequest.java index 3d2b4d93b..4c8e4f1b7 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/AsyncHttpClientRequest.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/request/AsyncHttpClientRequest.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.request; import com.alibaba.nacos.common.http.Callback; +import com.alibaba.nacos.common.http.client.handler.ResponseHandler; import com.alibaba.nacos.common.model.RequestHttpEntity; import java.io.Closeable; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/DefaultAsyncHttpClientRequest.java b/common/src/main/java/com/alibaba/nacos/common/http/client/request/DefaultAsyncHttpClientRequest.java similarity index 93% rename from common/src/main/java/com/alibaba/nacos/common/http/client/DefaultAsyncHttpClientRequest.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/request/DefaultAsyncHttpClientRequest.java index 7b5d2f5ed..58544c481 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/DefaultAsyncHttpClientRequest.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/request/DefaultAsyncHttpClientRequest.java @@ -14,10 +14,12 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.request; import com.alibaba.nacos.common.http.Callback; import com.alibaba.nacos.common.http.HttpRestResult; +import com.alibaba.nacos.common.http.client.handler.ResponseHandler; +import com.alibaba.nacos.common.http.client.response.DefaultClientHttpResponse; import com.alibaba.nacos.common.model.RequestHttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpRequestBase; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/DefaultHttpClientRequest.java b/common/src/main/java/com/alibaba/nacos/common/http/client/request/DefaultHttpClientRequest.java similarity index 94% rename from common/src/main/java/com/alibaba/nacos/common/http/client/DefaultHttpClientRequest.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/request/DefaultHttpClientRequest.java index 459211bb0..b36fc4780 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/DefaultHttpClientRequest.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/request/DefaultHttpClientRequest.java @@ -14,11 +14,13 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.request; import com.alibaba.nacos.common.constant.HttpHeaderConsts; import com.alibaba.nacos.common.http.BaseHttpMethod; import com.alibaba.nacos.common.http.HttpClientConfig; +import com.alibaba.nacos.common.http.client.response.DefaultClientHttpResponse; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.http.param.MediaType; import com.alibaba.nacos.common.model.RequestHttpEntity; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientRequest.java b/common/src/main/java/com/alibaba/nacos/common/http/client/request/HttpClientRequest.java similarity index 90% rename from common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientRequest.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/request/HttpClientRequest.java index 92466edb6..fac947d3e 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientRequest.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/request/HttpClientRequest.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.request; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.model.RequestHttpEntity; import java.io.Closeable; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/JdkHttpClientRequest.java b/common/src/main/java/com/alibaba/nacos/common/http/client/request/JdkHttpClientRequest.java similarity index 94% rename from common/src/main/java/com/alibaba/nacos/common/http/client/JdkHttpClientRequest.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/request/JdkHttpClientRequest.java index 538dd061a..e18bc1183 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/JdkHttpClientRequest.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/request/JdkHttpClientRequest.java @@ -14,11 +14,13 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.request; import com.alibaba.nacos.common.constant.HttpHeaderConsts; import com.alibaba.nacos.common.http.HttpClientConfig; import com.alibaba.nacos.common.http.HttpUtils; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; +import com.alibaba.nacos.common.http.client.response.JdkHttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.http.param.MediaType; import com.alibaba.nacos.common.model.RequestHttpEntity; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/DefaultClientHttpResponse.java b/common/src/main/java/com/alibaba/nacos/common/http/client/response/DefaultClientHttpResponse.java similarity index 97% rename from common/src/main/java/com/alibaba/nacos/common/http/client/DefaultClientHttpResponse.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/response/DefaultClientHttpResponse.java index e785cd44d..ff7da32f7 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/DefaultClientHttpResponse.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/response/DefaultClientHttpResponse.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.response; import com.alibaba.nacos.common.http.param.Header; import org.apache.http.HttpResponse; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientResponse.java b/common/src/main/java/com/alibaba/nacos/common/http/client/response/HttpClientResponse.java similarity index 97% rename from common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientResponse.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/response/HttpClientResponse.java index e11a26f28..35c4c5cd7 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/HttpClientResponse.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/response/HttpClientResponse.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.response; import com.alibaba.nacos.common.http.param.Header; diff --git a/common/src/main/java/com/alibaba/nacos/common/http/client/JdkHttpClientResponse.java b/common/src/main/java/com/alibaba/nacos/common/http/client/response/JdkHttpClientResponse.java similarity index 97% rename from common/src/main/java/com/alibaba/nacos/common/http/client/JdkHttpClientResponse.java rename to common/src/main/java/com/alibaba/nacos/common/http/client/response/JdkHttpClientResponse.java index 6332650d1..f4ad0794d 100644 --- a/common/src/main/java/com/alibaba/nacos/common/http/client/JdkHttpClientResponse.java +++ b/common/src/main/java/com/alibaba/nacos/common/http/client/response/JdkHttpClientResponse.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.nacos.common.http.client; +package com.alibaba.nacos.common.http.client.response; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.utils.IoUtils; diff --git a/test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_Interceptors_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_Interceptors_ITCase.java index de36a71df..b7cb1073b 100644 --- a/test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_Interceptors_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/common/NacosRestTemplate_Interceptors_ITCase.java @@ -21,8 +21,8 @@ import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.common.http.HttpClientBeanHolder; import com.alibaba.nacos.common.http.HttpRestResult; import com.alibaba.nacos.common.http.client.HttpClientRequestInterceptor; -import com.alibaba.nacos.common.http.client.HttpClientResponse; import com.alibaba.nacos.common.http.client.NacosRestTemplate; +import com.alibaba.nacos.common.http.client.response.HttpClientResponse; import com.alibaba.nacos.common.http.param.Header; import com.alibaba.nacos.common.http.param.Query; import com.alibaba.nacos.common.model.RequestHttpEntity; From 479ef3ff65b871f512af505db3726cc12142bcad Mon Sep 17 00:00:00 2001 From: Hu Zongtang Date: Wed, 22 Jul 2020 17:48:57 +0800 Subject: [PATCH 5/9] [ISSUE#3409]fix Nacos can't start by the startup.cmd script in windows enviroment. (#3416) --- distribution/bin/startup.cmd | 71 ++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/distribution/bin/startup.cmd b/distribution/bin/startup.cmd index 2df9905f0..ff4dfc7e0 100755 --- a/distribution/bin/startup.cmd +++ b/distribution/bin/startup.cmd @@ -24,7 +24,7 @@ set BASE_DIR="%BASE_DIR:~0,-5%" set DEFAULT_SEARCH_LOCATIONS="classpath:/,classpath:/config/,file:./,file:./config/" set CUSTOM_SEARCH_LOCATIONS=%DEFAULT_SEARCH_LOCATIONS%,file:%BASE_DIR%/conf/ -set MODE="standalone" +set MODE="cluster" set FUNCTION_MODE="all" set SERVER=nacos-server set MODE_INDEX=-1 @@ -36,46 +36,61 @@ set EMBEDDED_STORAGE="" set i=0 for %%a in (%*) do ( - if "%%a" == "-m" ( set /a MODE_INDEX=!i!+1 ) - if "%%a" == "-f" ( set /a FUNCTION_MODE_INDEX=!i!+1 ) - if "%%a" == "-s" ( set /a SERVER_INDEX=!i!+1 ) - if "%%a" == "-p" ( set /a EMBEDDED_STORAGE_INDEX=!i!+1 ) - set /a i+=1 + if "%%a" == "-m" ( set /a MODE_INDEX=!i!+1 ) + if "%%a" == "-f" ( set /a FUNCTION_MODE_INDEX=!i!+1 ) + if "%%a" == "-s" ( set /a SERVER_INDEX=!i!+1 ) + if "%%a" == "-p" ( set /a EMBEDDED_STORAGE_INDEX=!i!+1 ) + set /a i+=1 ) set i=0 for %%a in (%*) do ( - if %MODE_INDEX% == !i! ( set MODE="%%a" ) - if %FUNCTION_MODE_INDEX% == !i! ( set FUNCTION_MODE="%%a" ) - if %SERVER_INDEX% == !i! (set SERVER="%%a") - if %EMBEDDED_STORAGE_INDEX% == !i! (set EMBEDDED_STORAGE="%%a") - set /a i+=1 + if %MODE_INDEX% == !i! ( set MODE="%%a" ) + if %FUNCTION_MODE_INDEX% == !i! ( set FUNCTION_MODE="%%a" ) + if %SERVER_INDEX% == !i! (set SERVER="%%a") + if %EMBEDDED_STORAGE_INDEX% == !i! (set EMBEDDED_STORAGE="%%a") + set /a i+=1 ) +rem if nacos startup mode is standalone if %MODE% == "standalone" ( - set "JAVA_OPT=%JAVA_OPT% -Xms512m -Xmx512m -Xmn256m" - set "JAVA_OPT=%JAVA_OPT% -Dnacos.standalone=true" -) else ( - if %EMBEDDED_STORAGE% == "embedded" ( - set "JAVA_OPT=%JAVA_OPT% -DembeddedStorage=true" - ) - set "JAVA_OPT=%JAVA_OPT% -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m" - set "JAVA_OPT=%JAVA_OPT% -XX:-OmitStackTraceInFastThrow XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%BASE_DIR%\logs\java_heapdump.hprof" - set "JAVA_OPT=%JAVA_OPT% -XX:-UseLargePages" + echo "nacos is starting with standalone" + set "NACOS_OPTS=-Dnacos.standalone=true" + set "NACOS_JVM_OPTS=-Xms512m -Xmx512m -Xmn256m" ) +rem if nacos startup mode is cluster +if %MODE% == "cluster" ( + echo "nacos is starting with cluster" + if %EMBEDDED_STORAGE% == "embedded" ( + set "NACOS_OPTS=-DembeddedStorage=true" + ) + + set "NACOS_JVM_OPTS=-server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%BASE_DIR%\logs\java_heapdump.hprof -XX:-UseLargePages" +) + +rem set nacos's functionMode if %FUNCTION_MODE% == "config" ( - set "JAVA_OPT=%JAVA_OPT% -Dnacos.functionMode=config" + set "NACOS_OPTS=%NACOS_OPTS% -Dnacos.functionMode=config" ) + if %FUNCTION_MODE% == "naming" ( - set "JAVA_OPT=%JAVA_OPT% -Dnacos.functionMode=naming" + set "NACOS_OPTS=%NACOS_OPTS% -Dnacos.functionMode=naming" ) -set "JAVA_OPT=%JAVA_OPT% -Dloader.path=%BASE_DIR%/plugins/health,%BASE_DIR%/plugins/cmdb" +rem set nacos options +set "NACOS_OPTS=%NACOS_OPTS% -Dloader.path=%BASE_DIR%/plugins/health,%BASE_DIR%/plugins/cmdb" +set "NACOS_OPTS=%NACOS_OPTS% -Dnacos.home=%BASE_DIR%" +set "NACOS_OPTS=%NACOS_OPTS% -jar %BASE_DIR%\target\%SERVER%.jar" -set "JAVA_OPT=%JAVA_OPT% -Dnacos.home=%BASE_DIR%" -set "JAVA_OPT=%JAVA_OPT% -jar %BASE_DIR%\target\%SERVER%.jar" -set "JAVA_OPT=%JAVA_OPT% --spring.config.location=%CUSTOM_SEARCH_LOCATIONS%" -set "JAVA_OPT=%JAVA_OPT% --logging.config=%BASE_DIR%/conf/nacos-logback.xml" +rem set nacos spring config location +set "NACOS_CONFIG_OPTS=--spring.config.location=%CUSTOM_SEARCH_LOCATIONS%" -call "%JAVA%" %JAVA_OPT% nacos.nacos %* +rem set nacos log4j file location +set "NACOS_LOG4J_OPTS=--logging.config=%BASE_DIR%/conf/nacos-logback.xml" + + +set COMMAND="%JAVA%" %NACOS_JVM_OPTS% %NACOS_OPTS% %NACOS_CONFIG_OPTS% %NACOS_LOG4J_OPTS% nacos.nacos %* + +rem start nacos command +%COMMAND% \ No newline at end of file From c3818ff064a13e2a413425adbec33aa6ef3689e7 Mon Sep 17 00:00:00 2001 From: ljhrot <296093710@qq.com> Date: Sat, 25 Jul 2020 23:07:13 +0800 Subject: [PATCH 6/9] Fix bad SQL grammar (#3445) --- .../repository/embedded/EmbeddedStoragePersistServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java index cf9e19124..7e5298de1 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedStoragePersistServiceImpl.java @@ -2194,7 +2194,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService { @Override public boolean isExistTable(String tableName) { - String sql = String.format("select 1 from %s limit 1", tableName); + String sql = String.format("SELECT 1 FROM %s FETCH FIRST ROW ONLY", tableName); try { databaseOperate.queryOne(sql, Integer.class); return true; From d19b441540423245e945c0b9b14846f4676cdbab Mon Sep 17 00:00:00 2001 From: senekis Date: Mon, 27 Jul 2020 09:44:53 +0800 Subject: [PATCH 7/9] Fix #3428, Fix token valid go login bug (#3449) --- console/src/main/resources/static/console-fe/src/globalLib.js | 2 +- .../src/main/resources/static/console-fe/src/utils/request.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/console/src/main/resources/static/console-fe/src/globalLib.js b/console/src/main/resources/static/console-fe/src/globalLib.js index 6aefbff0d..902d1c187 100644 --- a/console/src/main/resources/static/console-fe/src/globalLib.js +++ b/console/src/main/resources/static/console-fe/src/globalLib.js @@ -528,7 +528,7 @@ const request = (function(_global) { } if ( [401, 403].includes(status) && - ['unknown user!', 'token invalid', 'token expired!'].includes(responseJSON.message) + ['unknown user!', 'token invalid!', 'token expired!'].includes(responseJSON.message) ) { goLogin(); } diff --git a/console/src/main/resources/static/console-fe/src/utils/request.js b/console/src/main/resources/static/console-fe/src/utils/request.js index b1687fb9f..64ee6ba9e 100644 --- a/console/src/main/resources/static/console-fe/src/utils/request.js +++ b/console/src/main/resources/static/console-fe/src/utils/request.js @@ -85,7 +85,7 @@ const request = () => { if ( [401, 403].includes(status) && - ['unknown user!', 'token invalid', 'token expired!'].includes(message) + ['unknown user!', 'token invalid!', 'token expired!'].includes(message) ) { goLogin(); } From 377f77871141f6b2688791c9752dd12bd2075cc2 Mon Sep 17 00:00:00 2001 From: yanjunnf Date: Mon, 27 Jul 2020 10:13:56 +0800 Subject: [PATCH 8/9] [#3388]Reset nacos roles, permissions during reloading role info from database (#3442) * Reset nacos roles, permissions during reloading role info from database * Add volatile to guarantee visibility in threads --- .../security/nacos/roles/NacosRoleServiceImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/console/src/main/java/com/alibaba/nacos/console/security/nacos/roles/NacosRoleServiceImpl.java b/console/src/main/java/com/alibaba/nacos/console/security/nacos/roles/NacosRoleServiceImpl.java index 2d9b66aab..0f4a268ca 100644 --- a/console/src/main/java/com/alibaba/nacos/console/security/nacos/roles/NacosRoleServiceImpl.java +++ b/console/src/main/java/com/alibaba/nacos/console/security/nacos/roles/NacosRoleServiceImpl.java @@ -64,11 +64,11 @@ public class NacosRoleServiceImpl { @Autowired private PermissionPersistService permissionPersistService; - private final Set roleSet = new ConcurrentHashSet<>(); + private volatile Set roleSet = new ConcurrentHashSet<>(); - private final Map> roleInfoMap = new ConcurrentHashMap<>(); + private volatile Map> roleInfoMap = new ConcurrentHashMap<>(); - private final Map> permissionInfoMap = new ConcurrentHashMap<>(); + private volatile Map> permissionInfoMap = new ConcurrentHashMap<>(); @Scheduled(initialDelay = 5000, fixedDelay = 15000) private void reload() { @@ -95,9 +95,9 @@ public class NacosRoleServiceImpl { tmpPermissionInfoMap.put(role, permissionInfoPage.getPageItems()); } - roleSet.addAll(tmpRoleSet); - roleInfoMap.putAll(tmpRoleInfoMap); - permissionInfoMap.putAll(tmpPermissionInfoMap); + roleSet = tmpRoleSet; + roleInfoMap = tmpRoleInfoMap; + permissionInfoMap = tmpPermissionInfoMap; } catch (Exception e) { Loggers.AUTH.warn("[LOAD-ROLES] load failed", e); } From bc3d13f6cb43fe362d37d753903818a3cef6e7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BF=8A=20SionYang?= <263976490@qq.com> Date: Mon, 27 Jul 2020 10:14:18 +0800 Subject: [PATCH 9/9] Update issue templates (#3427) * Update issue templates * Delete duplicate bug report --- .github/ISSUE_TEMPLATE/bug-report.md | 41 ++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 28 +++++++++++++ .github/ISSUE_TEMPLATE/old-issue-template.md | 37 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/old-issue-template.md diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 000000000..da04fd312 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,41 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + + + +**Describe the bug** +A clear and concise description of what the bug is. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Acutally behavior** +A clear and concise description of what you actually to happen. + +**How to Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Desktop (please complete the following information):** + - OS: [e.g. Centos] + - Version [e.g. nacos-server 1.3.1, nacos-client 1.3.1] + - Module [e.g. naming/config] + - SDK [e.g. original, spring-cloud-alibaba-nacos, dubbo] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..1ac8f2bae --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,28 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + + + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/old-issue-template.md b/.github/ISSUE_TEMPLATE/old-issue-template.md new file mode 100644 index 000000000..a3a71cf7e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/old-issue-template.md @@ -0,0 +1,37 @@ +--- +name: Old issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- + + + +## Issue Description + +Type: *bug report* or *feature request* + +### Describe what happened (or what feature you want) + + +### Describe what you expected to happen + + +### How to reproduce it (as minimally and precisely as possible) + +1. +2. +3. + +### Tell us your environment + + +### Anything else we need to know?