Skip to content

Commit

Permalink
Merge pull request #11452 from alibaba/develop
Browse files Browse the repository at this point in the history
Upgrade to 2.3.0
  • Loading branch information
KomachiSion committed Nov 30, 2023
2 parents ca6d151 + 7b51777 commit 8ac6c84
Show file tree
Hide file tree
Showing 294 changed files with 9,615 additions and 3,759 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
- name: "Codecov"
uses: codecov/codecov-action@v3.1.0
with:
files: ./address/target/site/jacoco/jacoco.xml,./api/target/site/jacoco/jacoco.xml,./auth/target/site/jacoco/jacoco.xml,./client/target/site/jacoco/jacoco.xml,./common/target/site/jacoco/jacoco.xml,./consistency/target/site/jacoco/jacoco.xml,./console/target/site/jacoco/jacoco.xml,./core/target/site/jacoco/jacoco.xml,./naming/target/site/jacoco/jacoco.xml,./plugin-default-impl/target/site/jacoco/jacoco.xml,./plugin/auth/target/site/jacoco/jacoco.xml,./plugin/encryption/target/site/jacoco/jacoco.xml,./sys/target/site/jacoco/jacoco.xml
files: ./address/target/site/jacoco/jacoco.xml,./api/target/site/jacoco/jacoco.xml,./auth/target/site/jacoco/jacoco.xml,./client/target/site/jacoco/jacoco.xml,./common/target/site/jacoco/jacoco.xml,./consistency/target/site/jacoco/jacoco.xml,./console/target/site/jacoco/jacoco.xml,./core/target/site/jacoco/jacoco.xml,./naming/target/site/jacoco/jacoco.xml,./persistence/target/site/jacoco/jacoco.xml,./plugin-default-impl/nacos-default-auth-plugin/target/site/jacoco/jacoco.xml,./plugin/auth/target/site/jacoco/jacoco.xml,./plugin/config/target/site/jacoco/jacoco.xml,./plugin/control/target/site/jacoco/jacoco.xml,./plugin/datasource/target/site/jacoco/jacoco.xml,./plugin/encryption/target/site/jacoco/jacoco.xml,./plugin/environment/target/site/jacoco/jacoco.xml,./plugin/trace/target/site/jacoco/jacoco.xml,./prometheus/target/site/jacoco/jacoco.xml,./sys/target/site/jacoco/jacoco.xml
2 changes: 1 addition & 1 deletion .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
name: Upload distribution tar
with:
name: nacos
path: distribution/target/nacos-server-*-SNAPSHOT.tar.gz
path: distribution/target/nacos-server-*.tar.gz
- name: Save PR number
run: |
mkdir -p ./pr
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Build and save docker images
id: build-images
run: |
mv nacos-server-*-SNAPSHOT.tar.gz nacos-e2e/cicd/build
mv nacos-server-*.tar.gz nacos-e2e/cicd/build
cd nacos-e2e/cicd/build
version=${{ github.event.pull_request.number || github.ref_name }}-$(uuidgen)
mkdir versionlist
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
name: Upload distribution tar
with:
name: nacos
path: distribution/target/nacos-server-*-SNAPSHOT.tar.gz
path: distribution/target/nacos-server-*.tar.gz

docker:
if: ${{ success() }}
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
- name: Build and save docker images
id: build-images
run: |
mv nacos-server-*-SNAPSHOT.tar.gz nacos-e2e/cicd/build/
mv nacos-server-*.tar.gz nacos-e2e/cicd/build/
cd nacos-e2e/cicd/build
version=${{ github.event.pull_request.number || github.ref_name }}-$(uuidgen)
mkdir versionlist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
Expand All @@ -30,6 +30,12 @@
* @date 2022/8/31 12:27
**/
public enum AbilityKey {

/**
* Server support register or deregister persistent instance by grpc.
*/
SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC("supportPersistentInstanceByGrpc",
"support persistent instance by grpc", AbilityMode.SERVER),

/**
* For Test temporarily.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ServerAbilities extends AbstractAbilityRegistry {
*
*/
// put ability here, which you want current server supports
supportedAbilities.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC, true);
}

/**.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,14 @@ public boolean validate() {
return false;
}

List<Instance> validHosts = new ArrayList<>();
boolean existValidHosts = false;
for (Instance host : hosts) {
if (!host.isHealthy()) {
continue;
}

for (int i = 0; i < host.getWeight(); i++) {
validHosts.add(host);
if (host.isHealthy() && host.getWeight() > 0) {
existValidHosts = true;
break;
}
}
//No valid hosts, return false.
return !validHosts.isEmpty();
return existValidHosts;
}

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.api.naming.remote.request;

import com.alibaba.nacos.api.naming.pojo.Instance;

/**
* Nacos persistent instances request.
*
* @author blake.qiu
*/
public class PersistentInstanceRequest extends AbstractNamingRequest {

private String type;

private Instance instance;

public PersistentInstanceRequest() {
}

public PersistentInstanceRequest(String namespace, String serviceName, String groupName, String type, Instance instance) {
super(namespace, serviceName, groupName);
this.type = type;
this.instance = instance;
}

public String getType() {
return this.type;
}

public void setType(String type) {
this.type = type;
}

public Instance getInstance() {
return instance;
}

public void setInstance(Instance instance) {
this.instance = instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public static String getGroupedNameOptional(final String serviceName, final Stri
* @throws NacosException if check failed, throw exception
*/
public static void checkInstanceIsLegal(Instance instance) throws NacosException {
if (null == instance) {
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.INSTANCE_ERROR,
"Instance can not be null.");
}
if (instance.getInstanceHeartBeatTimeOut() < instance.getInstanceHeartBeatInterval()
|| instance.getIpDeleteTimeout() < instance.getInstanceHeartBeatInterval()) {
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.INSTANCE_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ com.alibaba.nacos.api.config.remote.request.cluster.ConfigChangeClusterSyncReque
com.alibaba.nacos.api.config.remote.response.cluster.ConfigChangeClusterSyncResponse
com.alibaba.nacos.api.naming.remote.request.BatchInstanceRequest
com.alibaba.nacos.api.naming.remote.request.InstanceRequest
com.alibaba.nacos.api.naming.remote.request.PersistentInstanceRequest
com.alibaba.nacos.api.naming.remote.request.NotifySubscriberRequest
com.alibaba.nacos.api.naming.remote.request.ServiceListRequest
com.alibaba.nacos.api.naming.remote.request.ServiceQueryRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@

package com.alibaba.nacos.api.ability.register.impl;

import com.alibaba.nacos.api.ability.constant.AbilityKey;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class ServerAbilitiesTest {

@Test
public void testGetStaticAbilities() {
// TODO add the server abilities.
assertTrue(ServerAbilities.getStaticAbilities().isEmpty());
assertFalse(ServerAbilities.getStaticAbilities().isEmpty());
}

@Test
public void testSupportPersistentInstanceByGrpcAbilities() {
assertTrue(ServerAbilities.getStaticAbilities().get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.BeforeClass;
Expand All @@ -41,6 +42,7 @@ public static void setUpBeforeClass() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
}

@Before
Expand All @@ -52,7 +54,8 @@ public void setUp() throws Exception {
public void testSerialize() throws JsonProcessingException {
serverAbilities = new ServerRemoteAbility();
String json = mapper.writeValueAsString(serverAbilities);
assertEquals("{\"supportRemoteConnection\":false,\"grpcReportEnabled\":true}", json);
assertTrue(json.contains("\"supportRemoteConnection\":false"));
assertTrue(json.contains("\"grpcReportEnabled\":true"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;

Expand Down Expand Up @@ -60,6 +61,7 @@ public static void setUp() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
}

public abstract void testSerialize() throws JsonProcessingException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testSerialize() throws JsonProcessingException {
String json = mapper.writeValueAsString(configBatchListenRequest);
assertTrue(json.contains("\"listen\":" + "true"));
assertTrue(json.contains(
"\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\",\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}]"));
"\"configListenContexts\":[{\"dataId\":\"test_data\",\"group\":\"group\",\"md5\":\"test_MD5\",\"tenant\":\"test_tenant\"}]"));
assertTrue(json.contains("\"module\":\"" + Constants.Config.CONFIG_MODULE));
assertTrue(json.contains("\"requestId\":\"" + requestId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testSerializeSuccessResponse() throws JsonProcessingException {
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
assertTrue(json.contains("\"errorCode\":0"));
assertTrue(json.contains(
"\"changedConfigs\":[{\"group\":\"group\",\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}]"));
"\"changedConfigs\":[{\"dataId\":\"test_data\",\"group\":\"group\",\"tenant\":\"test_tenant\"}]"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 1999-2021 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.api.naming.remote.request;

import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class PersistentInstanceRequestTest extends BasedNamingRequestTest {

@Test
public void testSerialize() throws JsonProcessingException {
PersistentInstanceRequest request = new PersistentInstanceRequest(NAMESPACE, SERVICE, GROUP,
NamingRemoteConstants.REGISTER_INSTANCE, new Instance());
String json = mapper.writeValueAsString(request);
checkSerializeBasedInfo(json);
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
assertTrue(json.contains("\"instance\":{"));
}

@Test
public void testDeserialize() throws JsonProcessingException {
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
+ "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true,"
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
+ "\"instanceHeartBeatInterval\":5000,\"instanceHeartBeatTimeOut\":15000,\"ipDeleteTimeout\":30000},"
+ "\"module\":\"naming\"}";
PersistentInstanceRequest actual = mapper.readValue(json, PersistentInstanceRequest.class);
checkNamingRequestBasedInfo(actual);
assertEquals(NamingRemoteConstants.DE_REGISTER_INSTANCE, actual.getType());
assertEquals(new Instance(), actual.getInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,19 @@ public void testCheckInstanceIsEphemeral() throws NacosException {
Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM);
}
}

@Test
public void testCheckInstanceIsNull() throws NacosException {
Instance instance = new Instance();
instance.setIp("127.0.0.1");
instance.setPort(9089);
NamingUtils.checkInstanceIsLegal(instance);
try {
NamingUtils.checkInstanceIsLegal(null);
} catch (NacosException e) {
Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM);
}
}

@Test
public void testIsNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.MapperFeature;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -40,6 +41,7 @@ public static void setUpBeforeClass() throws Exception {
mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
}

@Before
Expand All @@ -51,7 +53,8 @@ public void setUp() throws Exception {
public void testSerialize() throws JsonProcessingException {
serverAbilities = new ServerRemoteAbility();
String json = mapper.writeValueAsString(serverAbilities);
assertEquals("{\"supportRemoteConnection\":false,\"grpcReportEnabled\":true}", json);
assertTrue(json.contains("\"supportRemoteConnection\":false"));
assertTrue(json.contains("\"grpcReportEnabled\":true"));
}

@Test
Expand Down

0 comments on commit 8ac6c84

Please sign in to comment.