Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: release-v1.1 features and bugfixs #11

Merged
merged 3 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions hango-api-plane-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,26 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>

<dependency>
Expand All @@ -64,7 +59,12 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.6.Final</version>
</dependency>

<!-- https://mvnrepository.com/artifact/commons-net/commons-net -->
Expand All @@ -84,7 +84,6 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
Expand Down Expand Up @@ -142,7 +141,6 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>

<dependency>
Expand All @@ -161,7 +159,7 @@
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-server-spring-boot-starter</artifactId>
<version>1.4.0.RELEASE</version>
<version>2.13.1.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.reflections/reflections -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -46,7 +49,7 @@ RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {

return restTemplateBuilder
.interceptors(interceptors)
.requestFactory(new InterceptingClientHttpRequestFactory(
.requestFactory(() -> new InterceptingClientHttpRequestFactory(
new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()), interceptors))
.build();
}
Expand All @@ -57,9 +60,9 @@ RestTemplate shortTimeoutRestTemplate(RestTemplateBuilder restTemplateBuilder) {
List<ClientHttpRequestInterceptor> 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();
}
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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()
Expand All @@ -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<Endpoint> getDubboEndpoints(String igv){
Expand Down Expand Up @@ -266,15 +270,15 @@ public <T> ResponseEntity<T> getForEntity(String str, Class<T> clz) {
return entity;
}

public String getSvcUrl(String svcName) {
public String getSvcUrl(String svcName, String portName) {
List<Service> 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);
String ip = service.getSpec().getClusterIP();
List<ServicePort> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -307,6 +308,7 @@ public void updateIstioGateway(PortalIstioGatewayDTO portalGateway) {
configManager.updateConfig(Trans.portalGW2GW(portalGateway));
}


@Override
public PortalIstioGatewayDTO getIstioGateway(String clusterName) {
IstioGateway istioGateway = new IstioGateway();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public interface Const {
String SERVICE_TYPE_K8S = "Kubernetes";
String SERVICE_TYPE_DUBBO = "Zookeeper";
String SERVICE_TYPE_EUREKA = "Eureka";
List<String> VAILD_REGISTRY = Arrays.asList(SERVICE_TYPE_CONSUL, SERVICE_TYPE_K8S, SERVICE_TYPE_DUBBO, SERVICE_TYPE_EUREKA);

String SERVICE_TYPE_NACOS = "Nacos";
List<String> 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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.14</version>
</parent>

<modules>
<module>hango-proto</module>
<module>hango-api-plane-server</module>
Expand Down