Skip to content

Commit

Permalink
Merge pull request #12667 from DioxideCN/develop-issue#12028_native
Browse files Browse the repository at this point in the history
[ISSUE#12028] Support GraalVM Native Image
  • Loading branch information
JianweiWang authored Oct 29, 2024
2 parents 4334cd1 + 7f780f4 commit c67bbf8
Show file tree
Hide file tree
Showing 280 changed files with 24,403 additions and 1,764 deletions.
4 changes: 2 additions & 2 deletions address/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public List<Instance> generateInstancesByIps(String serviceName, String rawProdu
}

private String[] generateIpAndPort(String ip) {
String[] result = InternetAddressUtil.splitIPPortStr(ip);
String[] result = InternetAddressUtil.splitIpPortStr(ip);
if (result.length != InternetAddressUtil.SPLIT_IP_PORT_RESULT_LENGTH) {
return new String[] {result[0], String.valueOf(AddressServerConstants.DEFAULT_SERVER_PORT)};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;

/**
Expand All @@ -34,8 +36,10 @@ public class AddressServerSecurityConfiguration {
@Order(99)
public SecurityFilterChain addressServerSecurityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(
requestMatcherRegistry -> requestMatcherRegistry.mvcMatchers("/nacos/v1/as/**").authenticated()).csrf()
.disable().httpBasic();
requestMatcherRegistry -> requestMatcherRegistry
.requestMatchers("/nacos/v1/as/**").authenticated())
.csrf(AbstractHttpConfigurer::disable)
.httpBasic(Customizer.withDefaults());
return http.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public ResponseEntity<String> postCluster(@RequestParam(required = false) String
String serviceName = addressServerGeneratorManager.generateNacosServiceName(productName);

Result result = registerCluster(serviceName, rawProductName, clusterName, ips);
if (InternetAddressUtil.checkOK(result.getCheckResult())) {
if (InternetAddressUtil.checkOk(result.getCheckResult())) {
responseEntity = ResponseEntity
.ok("product=" + rawProductName + ",cluster=" + rawClusterName + "; put success with size="
+ result.getSize());
Expand Down Expand Up @@ -133,8 +133,8 @@ private Result registerCluster(String serviceName, String productName, String cl
clusterOperator.updateClusterMetadata(Constants.DEFAULT_NAMESPACE_ID, serviceName, clusterName, metadata);
}
String[] ipArray = addressServerManager.splitIps(ips);
String checkResult = InternetAddressUtil.checkIPs(ipArray);
if (InternetAddressUtil.checkOK(checkResult)) {
String checkResult = InternetAddressUtil.checkIps(ipArray);
if (InternetAddressUtil.checkOk(checkResult)) {
List<Instance> instanceList = addressServerGeneratorManager
.generateInstancesByIps(serviceName, productName, clusterName, ipArray);
for (Instance instance : instanceList) {
Expand Down Expand Up @@ -181,8 +181,8 @@ public ResponseEntity<String> deleteCluster(@RequestParam(required = false) Stri
}
// delete specified ip list
String[] ipArray = addressServerManager.splitIps(ips);
String checkResult = InternetAddressUtil.checkIPs(ipArray);
if (InternetAddressUtil.checkOK(checkResult)) {
String checkResult = InternetAddressUtil.checkIps(ipArray);
if (InternetAddressUtil.checkOk(checkResult)) {
List<Instance> instanceList = addressServerGeneratorManager
.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
for (Instance each : instanceList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
</encoder>
</appender>

<logger name="com.alibaba.nacos.address.main" additivity="false">
<level value="INFO"/>
<logger name="com.alibaba.nacos.address.main" additivity="false" level="INFO">
<appender-ref ref="nacos-address"/>
</logger>
</included>
Expand Down
4 changes: 4 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<groupId>io.grpc</groupId>
<artifactId>grpc-util</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-inprocess</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.alibaba.nacos.api.grpc.auto;

import io.grpc.ClientCall;

import static io.grpc.MethodDescriptor.generateFullMethodName;
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
Expand Down Expand Up @@ -202,8 +204,8 @@ protected RequestFutureStub build(io.grpc.Channel channel,
*/
public com.google.common.util.concurrent.ListenableFuture<com.alibaba.nacos.api.grpc.auto.Payload> request(
com.alibaba.nacos.api.grpc.auto.Payload request) {
return futureUnaryCall(
getChannel().newCall(getRequestMethod(), getCallOptions()), request);
return futureUnaryCall(getChannel().newCall(getRequestMethod(),
getCallOptions()), request);
}
}

Expand Down
10 changes: 5 additions & 5 deletions api/src/main/java/com/alibaba/nacos/api/naming/pojo/Cluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class Cluster implements Serializable {
/**
* Whether or not use instance port to do health check.
*/
private boolean useIPPort4Check = true;
private boolean useIpPort4Check = true;

private Map<String, String> metadata = new HashMap<>();

Expand Down Expand Up @@ -116,12 +116,12 @@ public void setDefaultCheckPort(int defaultCheckPort) {
this.defaultCheckPort = defaultCheckPort;
}

public boolean isUseIPPort4Check() {
return useIPPort4Check;
public boolean isUseIpPort4Check() {
return useIpPort4Check;
}

public void setUseIPPort4Check(boolean useIPPort4Check) {
this.useIPPort4Check = useIPPort4Check;
public void setUseIpPort4Check(boolean useIpPort4Check) {
this.useIpPort4Check = useIpPort4Check;
}

public Map<String, String> getMetadata() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ public class ServiceInfo {

private String checksum = "";

private volatile boolean allIPs = false;
private volatile boolean allIps = false;

private volatile boolean reachProtectionThreshold = false;

public ServiceInfo() {
}

public boolean isAllIPs() {
return allIPs;
public boolean isAllIps() {
return allIps;
}

public void setAllIPs(boolean allIPs) {
this.allIPs = allIPs;
public void setAllIps(boolean allIps) {
this.allIps = allIps;
}

/**
Expand Down Expand Up @@ -180,7 +180,7 @@ public void setCacheMillis(long cacheMillis) {
* @return true if validate, otherwise false
*/
public boolean validate() {
if (isAllIPs()) {
if (isAllIps()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class NetUtils {
*
* @return local ip
*/
public static String localIP() {
public static String localIp() {
if (!StringUtils.isEmpty(localIp)) {
return localIp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ void testSetAndGet() {
assertEquals(Tcp.TYPE, actual.getHealthChecker().getType());
assertEquals(80, actual.getDefaultPort());
assertEquals(80, actual.getDefaultCheckPort());
assertTrue(actual.isUseIPPort4Check());
assertTrue(actual.isUseIpPort4Check());
assertTrue(actual.getMetadata().isEmpty());
actual.setName("cluster");
actual.setServiceName("group@@service");
actual.setHealthChecker(new Http());
actual.setDefaultPort(81);
actual.setDefaultCheckPort(82);
actual.setUseIPPort4Check(false);
actual.setUseIpPort4Check(false);
actual.setMetadata(Collections.singletonMap("a", "a"));
assertEquals("cluster", actual.getName());
assertEquals("group@@service", actual.getServiceName());
assertEquals(Http.TYPE, actual.getHealthChecker().getType());
assertEquals(81, actual.getDefaultPort());
assertEquals(82, actual.getDefaultCheckPort());
assertFalse(actual.isUseIPPort4Check());
assertFalse(actual.isUseIpPort4Check());
assertFalse(actual.getMetadata().isEmpty());
assertTrue(actual.getMetadata().containsKey("a"));
assertEquals("a", actual.getMetadata().get("a"));
Expand All @@ -78,30 +78,30 @@ void testJsonSerialize() throws JsonProcessingException {
actual.setHealthChecker(new Http());
actual.setDefaultPort(81);
actual.setDefaultCheckPort(82);
actual.setUseIPPort4Check(false);
actual.setUseIpPort4Check(false);
actual.setMetadata(Collections.singletonMap("a", "a"));
String json = mapper.writeValueAsString(actual);
assertTrue(json.contains("\"serviceName\":\"group@@service\""));
assertTrue(json.contains("\"name\":\"cluster\""));
assertTrue(json.contains("\"type\":\"HTTP\""));
assertTrue(json.contains("\"defaultPort\":81"));
assertTrue(json.contains("\"defaultCheckPort\":82"));
assertTrue(json.contains("\"useIPPort4Check\":false"));
assertTrue(json.contains("\"useIpPort4Check\":false"));
assertTrue(json.contains("\"metadata\":{\"a\":\"a\"}"));
}

@Test
void testJsonDeserialize() throws JsonProcessingException {
String json = "{\"serviceName\":\"group@@service\",\"name\":\"cluster\","
+ "\"healthChecker\":{\"type\":\"HTTP\",\"path\":\"\",\"headers\":\"\",\"expectedResponseCode\":200},"
+ "\"defaultPort\":81,\"defaultCheckPort\":82,\"useIPPort4Check\":false,\"metadata\":{\"a\":\"a\"}}";
+ "\"defaultPort\":81,\"defaultCheckPort\":82,\"useIpPort4Check\":false,\"metadata\":{\"a\":\"a\"}}";
Cluster actual = mapper.readValue(json, Cluster.class);
assertEquals("cluster", actual.getName());
assertEquals("group@@service", actual.getServiceName());
assertEquals(Http.TYPE, actual.getHealthChecker().getType());
assertEquals(81, actual.getDefaultPort());
assertEquals(82, actual.getDefaultCheckPort());
assertFalse(actual.isUseIPPort4Check());
assertFalse(actual.isUseIpPort4Check());
assertFalse(actual.getMetadata().isEmpty());
assertTrue(actual.getMetadata().containsKey("a"));
assertEquals("a", actual.getMetadata().get("a"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void testSerialize() throws JsonProcessingException {
assertTrue(actual.contains("\"lastRefTime\":0"));
assertTrue(actual.contains("\"checksum\":\"\""));
assertTrue(actual.contains("\"valid\":true"));
assertTrue(actual.contains("\"allIPs\":false"));
assertTrue(actual.contains("\"allIps\":false"));
assertFalse(actual.contains("jsonFromServer"));
assertFalse(actual.contains("key"));
assertFalse(actual.contains("keyEncoded"));
Expand All @@ -67,7 +67,7 @@ void testSerialize() throws JsonProcessingException {
@Test
void testDeserialize() throws IOException {
String example = "{\"name\":\"G@@testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[],"
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}";
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIps\":false,\"valid\":true,\"groupName\":\"\"}";
ServiceInfo actual = mapper.readValue(example, ServiceInfo.class);
assertEquals("G@@testName", actual.getName());
assertEquals(0, actual.ipCount());
Expand All @@ -79,7 +79,7 @@ void testDeserialize() throws IOException {
assertTrue(actual.expired());
assertTrue(actual.getHosts().isEmpty());
assertTrue(actual.isValid());
assertFalse(actual.isAllIPs());
assertFalse(actual.isAllIps());
}

@Test
Expand Down Expand Up @@ -121,7 +121,7 @@ void testServiceInfoConstructorWithError() {

@Test
void testValidateForAllIps() {
serviceInfo.setAllIPs(true);
serviceInfo.setAllIps(true);
assertTrue(serviceInfo.validate());
}

Expand Down
10 changes: 5 additions & 5 deletions api/src/test/java/com/alibaba/nacos/api/utils/NetUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ void tearDown() throws Exception {
@Test
void testLocalIpWithSpecifiedIp() {
System.setProperty("com.alibaba.nacos.client.local.ip", "10.2.8.8");
assertEquals("10.2.8.8", NetUtils.localIP());
assertEquals("10.2.8.8", NetUtils.localIp());
System.setProperty("com.alibaba.nacos.client.local.ip", "10.2.8.9");
assertEquals("10.2.8.8", NetUtils.localIP());
assertEquals("10.2.8.8", NetUtils.localIp());
}

@Test
void testLocalIpWithPreferHostname() throws Exception {
InetAddress inetAddress = invokeGetInetAddress();
String hostname = inetAddress.getHostName();
System.setProperty("com.alibaba.nacos.client.local.preferHostname", "true");
assertEquals(hostname, NetUtils.localIP());
assertEquals(hostname, NetUtils.localIp());
}

@Test
void testLocalIpWithoutPreferHostname() throws Exception {
InetAddress inetAddress = invokeGetInetAddress();
String ip = inetAddress.getHostAddress();
assertEquals(ip, NetUtils.localIP());
assertEquals(ip, NetUtils.localIp());
}

@Test
Expand All @@ -75,7 +75,7 @@ void testLocalIpWithException() throws Exception {
try {
System.setProperty("java.net.preferIPv6Addresses", "aaa");
InetAddress expect = InetAddress.getLocalHost();
assertEquals(expect.getHostAddress(), NetUtils.localIP());
assertEquals(expect.getHostAddress(), NetUtils.localIp());
} finally {
field.set(null, properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.alibaba.nacos.auth.util.Loggers;
import com.alibaba.nacos.common.utils.StringUtils;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.alibaba.nacos.plugin.auth.spi.server.AuthPluginManager;
import com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Map;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.alibaba.nacos.auth.parser.AbstractResourceParser;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

/**
* Abstract Http Resource Parser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.common.utils.StringUtils;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Properties;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.common.utils.StringUtils;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Properties;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.junit.jupiter.api.Test;
import org.springframework.mock.env.MockEnvironment;

import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;

class AuthConfigsTest {
Expand Down Expand Up @@ -57,10 +59,13 @@ void testUpgradeFromEvent() {
environment.setProperty("nacos.core.auth.enable.userAgentAuthWhite", String.valueOf(TEST_ENABLE_UA_WHITE));

authConfigs.onEvent(ServerConfigChangeEvent.newEvent());
assertEquals(TEST_AUTH_ENABLED, authConfigs.isAuthEnabled());
assertEquals(TEST_CACHING_ENABLED, authConfigs.isCachingEnabled());
assertEquals(Optional.of(TEST_AUTH_ENABLED).orElse(Boolean.FALSE),
Optional.of(authConfigs.isAuthEnabled()).orElse(Boolean.FALSE));
assertEquals(Optional.of(TEST_CACHING_ENABLED).orElse(Boolean.FALSE),
Optional.of(authConfigs.isCachingEnabled()).orElse(Boolean.FALSE));
assertEquals(TEST_SERVER_IDENTITY_KEY, authConfigs.getServerIdentityKey());
assertEquals(TEST_SERVER_IDENTITY_VALUE, authConfigs.getServerIdentityValue());
assertEquals(TEST_ENABLE_UA_WHITE, authConfigs.isEnableUserAgentAuthWhite());
assertEquals(Optional.of(TEST_ENABLE_UA_WHITE).orElse(Boolean.FALSE),
Optional.of(authConfigs.isEnableUserAgentAuthWhite()).orElse(Boolean.FALSE));
}
}
Loading

0 comments on commit c67bbf8

Please sign in to comment.