diff --git a/hango-api-plane-server/pom.xml b/hango-api-plane-server/pom.xml index 78e0b106..3ece7e83 100644 --- a/hango-api-plane-server/pom.xml +++ b/hango-api-plane-server/pom.xml @@ -20,31 +20,26 @@ org.springframework.boot spring-boot-starter-web - 1.5.8.RELEASE org.springframework.boot spring-boot-starter-aop - 1.5.8.RELEASE org.springframework.boot spring-boot-starter-freemarker - 1.5.8.RELEASE org.springframework.boot spring-boot-starter-jdbc - 1.5.8.RELEASE org.springframework.boot spring-boot-starter-test - 1.5.8.RELEASE @@ -64,7 +59,12 @@ org.apache.commons commons-lang3 - 3.6 + + + + org.hibernate + hibernate-validator + 5.3.6.Final @@ -84,7 +84,6 @@ org.apache.commons commons-dbcp2 - 2.1.1 commons-logging @@ -142,7 +141,6 @@ com.jayway.jsonpath json-path - 2.4.0 @@ -161,7 +159,7 @@ net.devh grpc-server-spring-boot-starter - 1.4.0.RELEASE + 2.13.1.RELEASE diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/ApiPlaneApplication.java b/hango-api-plane-server/src/main/java/org/hango/cloud/ApiPlaneApplication.java index ab36ebe6..0117fa36 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/ApiPlaneApplication.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/ApiPlaneApplication.java @@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.PropertySource; import org.springframework.scheduling.annotation.EnableAsync; diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/ApiPlaneAutoBaseConfiguration.java b/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/ApiPlaneAutoBaseConfiguration.java index a4406275..9611ed13 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/ApiPlaneAutoBaseConfiguration.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/ApiPlaneAutoBaseConfiguration.java @@ -26,9 +26,12 @@ import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.InterceptingClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.util.ResourceUtils; import org.springframework.web.client.RestTemplate; import javax.annotation.PostConstruct; +import java.io.IOException; +import java.time.Duration; import java.util.List; @@ -46,7 +49,7 @@ RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) { return restTemplateBuilder .interceptors(interceptors) - .requestFactory(new InterceptingClientHttpRequestFactory( + .requestFactory(() -> new InterceptingClientHttpRequestFactory( new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()), interceptors)) .build(); } @@ -57,9 +60,9 @@ RestTemplate shortTimeoutRestTemplate(RestTemplateBuilder restTemplateBuilder) { List interceptors = ImmutableList.of(new RestTemplateLogInterceptor()); return restTemplateBuilder - .setConnectTimeout(1000) + .setConnectTimeout(Duration.ofSeconds(1)) .interceptors(interceptors) - .requestFactory(new InterceptingClientHttpRequestFactory( + .requestFactory(() -> new InterceptingClientHttpRequestFactory( new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()), interceptors)) .build(); } @@ -88,7 +91,8 @@ ObjectMapper jsonObjectMapper() { } @PostConstruct - void configureFreemarkerConfig() { + void configureFreemarkerConfig() throws IOException { + freemarkerConfig.setDirectoryForTemplateLoading(ResourceUtils.getFile("classpath:template")); freemarkerConfig.setNumberFormat("#"); freemarkerConfig.setSharedVariable("indent", new IndentationDirective()); freemarkerConfig.setSharedVariable("ignore", new IgnoreDirective()); diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/env/NonK8sConfiguration.java b/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/env/NonK8sConfiguration.java index 2537fe1a..c023ba37 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/env/NonK8sConfiguration.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/env/NonK8sConfiguration.java @@ -1,5 +1,6 @@ package org.hango.cloud.configuration.env; +import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder; import org.hango.cloud.configuration.ext.K8sMultiClusterProperties; import org.hango.cloud.core.GlobalConfig; import org.hango.cloud.core.editor.EditorContext; @@ -36,7 +37,6 @@ import org.hango.cloud.service.GatewayService; import org.hango.cloud.service.impl.GatewayServiceImpl; import io.grpc.Server; -import io.grpc.netty.NettyServerBuilder; import istio.mcp.nsf.SnapshotOuterClass; import istio.mcp.v1alpha1.Mcp; import istio.mcp.v1alpha1.ResourceOuterClass; diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/ext/YamlPropertyLoaderFactory.java b/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/ext/YamlPropertyLoaderFactory.java index 1848c4b5..09f1b10f 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/ext/YamlPropertyLoaderFactory.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/ext/YamlPropertyLoaderFactory.java @@ -1,14 +1,20 @@ package org.hango.cloud.configuration.ext; -import org.springframework.boot.env.YamlPropertySourceLoader; +import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; +import org.springframework.core.env.PropertiesPropertySource; +import org.springframework.core.env.PropertySource; import org.springframework.core.io.support.DefaultPropertySourceFactory; import org.springframework.core.io.support.EncodedResource; import java.io.IOException; +import java.util.Properties; public class YamlPropertyLoaderFactory extends DefaultPropertySourceFactory { @Override - public org.springframework.core.env.PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { - return new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource(), null); + public PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { + YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); + factory.setResources(resource.getResource()); + Properties properties = factory.getObject(); + return new PropertiesPropertySource(resource.getResource().getFilename(), properties); } -} +} \ No newline at end of file diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/mode/GatewayAutoConfiguration.java b/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/mode/GatewayAutoConfiguration.java index 9db2db21..2e281541 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/mode/GatewayAutoConfiguration.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/configuration/mode/GatewayAutoConfiguration.java @@ -1,7 +1,7 @@ package org.hango.cloud.configuration.mode; +import net.devh.boot.grpc.server.serverfactory.GrpcServerLifecycle; import org.hango.cloud.configuration.ApiPlaneAutoBaseConfiguration; -import net.devh.springboot.autoconfigure.grpc.server.GrpcServerLifecycle; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/core/istio/PilotHttpClient.java b/hango-api-plane-server/src/main/java/org/hango/cloud/core/istio/PilotHttpClient.java index 9b23e455..653a2d19 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/core/istio/PilotHttpClient.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/core/istio/PilotHttpClient.java @@ -10,15 +10,13 @@ import com.google.common.collect.ImmutableMap; import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServicePort; -import net.minidev.json.JSONObject; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; import org.hango.cloud.core.k8s.K8sResourceEnum; import org.hango.cloud.core.k8s.KubernetesClient; import org.hango.cloud.meta.Endpoint; -import org.hango.cloud.meta.dto.PortalServiceDTO; import org.hango.cloud.util.Const; import org.hango.cloud.util.exception.ApiPlaneException; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; import org.hango.cloud.util.exception.ExceptionConst; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +29,10 @@ import org.springframework.web.client.RestTemplate; import javax.annotation.PostConstruct; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -51,7 +52,7 @@ public class PilotHttpClient { @Value(value = "${istioName:istiod}") private String ISTIO_NAME; - @Value(value = "${meshRegistryName:galley}") + @Value(value = "${meshRegistryName:slime}") private String MESH_REGISTRY_NAME; private static final String GET_ENDPOINTZ_PATH = "/debug/endpointz?brief=true&servicePort=true"; @@ -87,6 +88,9 @@ public class PilotHttpClient { public static final Integer ERROR_PORT = -1; + private static final String ISTIOD_DEBUG_PORT_NAME = "http-legacy-discovery"; + private static final String MESH_REGISTRY_DEBUG_PORT_NAME = "aux-port"; + @PostConstruct void cacheInit() { endpointsCache = CacheBuilder.newBuilder() @@ -104,12 +108,12 @@ public Object load(String key) throws Exception { private String getIstioUrl() { if (!StringUtils.isEmpty(istioHttpUrl)) return istioHttpUrl; - return getSvcUrl(ISTIO_NAME); + return getSvcUrl(ISTIO_NAME, ISTIOD_DEBUG_PORT_NAME); } private String getMeshRegistryUrl() { if (!StringUtils.isEmpty(meshRegistryHttpUrl)) return meshRegistryHttpUrl; - return getSvcUrl(MESH_REGISTRY_NAME); + return getSvcUrl(MESH_REGISTRY_NAME, MESH_REGISTRY_DEBUG_PORT_NAME); } public List getDubboEndpoints(String igv){ @@ -266,7 +270,7 @@ public ResponseEntity getForEntity(String str, Class clz) { return entity; } - public String getSvcUrl(String svcName) { + public String getSvcUrl(String svcName, String portName) { List pilotServices = client.getObjectList(K8sResourceEnum.Service.name(), NAMESPACE, ImmutableMap.of("app", svcName)); if (CollectionUtils.isEmpty(pilotServices)) throw new ApiPlaneException(ExceptionConst.PILOT_SERVICE_NON_EXIST); Service service = pilotServices.get(0); @@ -274,7 +278,7 @@ public String getSvcUrl(String svcName) { List ports = service.getSpec().getPorts(); //get port by name equal http-legacy-discovery for (ServicePort port : ports) { - if ("http-legacy-discovery".equalsIgnoreCase(port.getName())) { + if (StringUtils.equalsIgnoreCase(portName, port.getName())){ return String.format("http://%s:%s", ip, port.getPort()); } } diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/mcp/ratelimit/RlsClusterClient.java b/hango-api-plane-server/src/main/java/org/hango/cloud/mcp/ratelimit/RlsClusterClient.java index 0e1fa0ec..32983691 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/mcp/ratelimit/RlsClusterClient.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/mcp/ratelimit/RlsClusterClient.java @@ -33,7 +33,7 @@ public RlsClusterClient(McpOptions mcpOptions, ResourceDao resourceDao, McpMarsh for (String address : mcpOptions.getRegisteredRlsCluster()) { String[] hostPort = StringUtils.split(address, ":"); if (hostPort.length == 2) { - ManagedChannel channel = ManagedChannelBuilder.forAddress(hostPort[0], Integer.parseInt(hostPort[1])).usePlaintext(true).build(); + ManagedChannel channel = ManagedChannelBuilder.forAddress(hostPort[0], Integer.parseInt(hostPort[1])).usePlaintext().build(); stubs.add(RatelimitConfigServiceGrpc.newStub(channel)); } } diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/service/impl/GatewayServiceImpl.java b/hango-api-plane-server/src/main/java/org/hango/cloud/service/impl/GatewayServiceImpl.java index e06e00c3..0fa573b4 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/service/impl/GatewayServiceImpl.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/service/impl/GatewayServiceImpl.java @@ -299,6 +299,7 @@ private boolean matchType(String type, String name, String registryId) { if (type.equalsIgnoreCase(Const.SERVICE_TYPE_K8S) && name.endsWith(".svc.cluster.local")) return true; if (type.equalsIgnoreCase(Const.SERVICE_TYPE_DUBBO) && name.endsWith(".dubbo")) return true; if (type.equalsIgnoreCase(Const.SERVICE_TYPE_EUREKA) && name.endsWith(".eureka")) return true; + if (type.equalsIgnoreCase(Const.SERVICE_TYPE_NACOS) && name.endsWith(".nacos")) return true; return false; } @@ -307,6 +308,7 @@ public void updateIstioGateway(PortalIstioGatewayDTO portalGateway) { configManager.updateConfig(Trans.portalGW2GW(portalGateway)); } + @Override public PortalIstioGatewayDTO getIstioGateway(String clusterName) { IstioGateway istioGateway = new IstioGateway(); diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/util/Const.java b/hango-api-plane-server/src/main/java/org/hango/cloud/util/Const.java index 2207c727..2d69d033 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/util/Const.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/util/Const.java @@ -26,7 +26,9 @@ public interface Const { String SERVICE_TYPE_K8S = "Kubernetes"; String SERVICE_TYPE_DUBBO = "Zookeeper"; String SERVICE_TYPE_EUREKA = "Eureka"; - List VAILD_REGISTRY = Arrays.asList(SERVICE_TYPE_CONSUL, SERVICE_TYPE_K8S, SERVICE_TYPE_DUBBO, SERVICE_TYPE_EUREKA); + + String SERVICE_TYPE_NACOS = "Nacos"; + List VAILD_REGISTRY = Arrays.asList(SERVICE_TYPE_CONSUL, SERVICE_TYPE_K8S, SERVICE_TYPE_DUBBO, SERVICE_TYPE_EUREKA,SERVICE_TYPE_NACOS); String PROTOCOL_DUBBO = "dubbo"; String DUBBO_APPLICATION = "application"; diff --git a/hango-api-plane-server/src/main/java/org/hango/cloud/util/freemarker/SupplyDirective.java b/hango-api-plane-server/src/main/java/org/hango/cloud/util/freemarker/SupplyDirective.java index 8d560e8d..e71afe3c 100644 --- a/hango-api-plane-server/src/main/java/org/hango/cloud/util/freemarker/SupplyDirective.java +++ b/hango-api-plane-server/src/main/java/org/hango/cloud/util/freemarker/SupplyDirective.java @@ -68,7 +68,7 @@ public void execute(Environment environment, Map parameters, TemplateModel[] loo gen.createOrUpdateValue("$[?]", "name", Keyword.API.replacement, Criteria.where("name").exists(false)); String yaml = gen.yamlString(); - yaml = yaml.replaceAll("(?m)^(-?\\s*)nsf-template-.*?:(?:\\s*)(<.*>)", "$1$2"); + yaml = yaml.replaceAll("(?m)^(-?\\s*)nsf-template-.*?:(?:\\s*)\"(<.*>)\"", "$1$2"); environment.getOut().write(yaml); writer.close(); diff --git a/hango-api-plane-server/src/test/java/org/hango/cloud/core/BaseConfiguration.java b/hango-api-plane-server/src/test/java/org/hango/cloud/core/BaseConfiguration.java index f2ade67a..96c67484 100644 --- a/hango-api-plane-server/src/test/java/org/hango/cloud/core/BaseConfiguration.java +++ b/hango-api-plane-server/src/test/java/org/hango/cloud/core/BaseConfiguration.java @@ -1,6 +1,6 @@ package org.hango.cloud.core; -import net.devh.springboot.autoconfigure.grpc.server.GrpcServerLifecycle; +import net.devh.boot.grpc.server.serverfactory.GrpcServerLifecycle; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/pom.xml b/pom.xml index a09840cd..761e9ca2 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,13 @@ ${project.basedir}/../target/jacoco.exec java + + + org.springframework.boot + spring-boot-starter-parent + 2.5.14 + + hango-proto hango-api-plane-server