Skip to content

Commit

Permalink
Merge pull request spring-cloud#28 from jhonyelink/gateway_4x_KM-836_opt
Browse files Browse the repository at this point in the history
kylin 4x + kylin manager 2 + gateway 2.0.0
  • Loading branch information
jhonyelink committed Nov 25, 2020
2 parents de6384a + 914fbe9 commit eec1128
Show file tree
Hide file tree
Showing 58 changed files with 1,976 additions and 275 deletions.
2 changes: 1 addition & 1 deletion build/bin/gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function start_gateway() {

cd ${GATEWAY_HOME}/server

nohup java -Xms4g -Xmx4g -Dreactor.netty.http.server.accessLogEnabled=true -Dgateway.home=${GATEWAY_HOME} -Dfile.encoding=UTF-8 -Dlogging.path=${GATEWAY_HOME}/logs -Dspring.config.additional-location=${gateway_properties} -Dloader.path="${GATEWAY_HOME}/server/jars" -jar gateway.jar >> ${GATEWAY_HOME}/logs/gateway.log 2>&1 < /dev/null & echo $! > ${GATEWAY_HOME}/pid &
nohup java -Xms4g -Xmx4g -Dspring.profiles.active=prod -Dreactor.netty.http.server.accessLogEnabled=true -Dgateway.home=${GATEWAY_HOME} -Dfile.encoding=UTF-8 -Dlogging.path=${GATEWAY_HOME}/logs -Dspring.config.additional-location=${gateway_properties} -Dloader.path="${GATEWAY_HOME}/server/jars" -jar gateway.jar >> ${GATEWAY_HOME}/logs/gateway.log 2>&1 < /dev/null & echo $! > ${GATEWAY_HOME}/pid &

PID=`cat ${GATEWAY_HOME}/pid`
echo $(date "+%Y-%m-%d %H:%M:%S ") "new Gateway process pid is "${PID} >> ${GATEWAY_HOME}/logs/gateway.log
Expand Down
8 changes: 5 additions & 3 deletions build/conf/gateway.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# health check ping strategy configuration
#kylin.gateway.health.ping-strategy.retry-times=3
#kylin.gateway.health.ping-strategy.interval-seconds=5
# kylin.gateway.health.ping-strategy.interval-seconds=10

# datasource configuration, type optional: jdbc
#kylin.gateway.datasource.type=jdbc
Expand All @@ -42,10 +42,12 @@
#kylin.gateway.datasource.username=username
#kylin.gateway.datasource.password=password
#kylin.gateway.datasource.table-name=table_name
#kylin.gateway.datasource.cluster-id=cluster1

# datasource configuration, type optional: file
#kylin.gateway.datasource.type=file
#kylin.gateway.datasource.route-table-file-path=${gateway.home}/conf/route_table
#kylin.gateway.datasource.cluster-id=cluster2

# if only default, must config true.
#kylin.gateway.route.query-route-default=false
# route table fresh interval
#kylin.gateway.route.refresh-interval=3s
21 changes: 17 additions & 4 deletions build/conf/route_table
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
{"id":4, "backends":["10.1.2.56:7070"], "project":"p1", "resourceGroup":"common_query_1", "type":"ASYNC"}
{"id":5, "backends":["10.1.2.56:7070"], "project":"p1", "resourceGroup":"common_query_2", "type":"CUBE"}
{"id":6, "backends":["10.1.2.56:7070"], "project":"p2", "resourceGroup":"common_query_3", "order": 10 , "type":"CUBE"}
{"id":1, "backends":["10.1.2.56:7070"], "resourceGroup":"default", "type":"GLOBAL"}

{"cluster": "c1", "backends":["10.1.2.56:7070"], "project":"p1", "resourceGroup":"1", "type":"BUILD"}
{"cluster": "c1", "backends":["10.1.2.56:7070"], "project":"p1", "resourceGroup":"1", "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.56:7070"], "project":"p2", "resourceGroup":"1", "order": 10 , "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.56:7070"], "project":"p3", "resourceGroup":"1", "order": 10 , "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.152:7071"], "project":"p3", "resourceGroup":"2", "order": 10 , "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.56:7070"], "project":"p4", "resourceGroup":"1", "order": 10 , "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.153:7071"], "project":"p5", "resourceGroup":"3", "order": 10 , "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.153:7071"], "project":"p6", "resourceGroup":"3", "order": 10 , "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.153:7071"], "project":"p7", "resourceGroup":"3", "order": 10 , "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.153:7071"], "project":"p8", "resourceGroup":"3", "order": 10 , "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.153:7071"], "project":"p9", "resourceGroup":"3", "order": 10 , "type":"QUERY"}
{"cluster": "c1", "backends":["10.1.2.153:7071"], "project":"p10", "resourceGroup":"3", "order": 10 , "type":"QUERY"}


{"cluster": "c1", "backends":["10.1.2.56:7070"], "resourceGroup":"0", "type":"GLOBAL"}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.kyligence.kap.gateway.config;

import io.kyligence.kap.gateway.constant.KylinGatewayVersion;
import io.kyligence.kap.gateway.filter.KylinLoadBalancerClientFilter;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.gateway.config.LoadBalancerProperties;
import org.springframework.cloud.gateway.filter.LoadBalancerClientFilter;
import org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter;
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.DispatcherHandler;

@ConditionalOnProperty(name = "kylin.gateway.ke.version", havingValue = KylinGatewayVersion.KYLIN_4X)
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({LoadBalancerClient.class, RibbonAutoConfiguration.class,
DispatcherHandler.class})
@AutoConfigureAfter(RibbonAutoConfiguration.class)
@EnableConfigurationProperties(LoadBalancerProperties.class)
public class GatewayKylinLoadBalancerClientAutoConfiguration {

@Bean
@ConditionalOnMissingBean({LoadBalancerClientFilter.class,
ReactiveLoadBalancerClientFilter.class})
public LoadBalancerClientFilter loadBalancerClientFilter(LoadBalancerClient client,
LoadBalancerProperties properties) {
return new KylinLoadBalancerClientFilter(client, properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.kyligence.kap.gateway.config;

import com.google.common.collect.ImmutableList;
import io.kyligence.kap.gateway.entity.KylinRouteRaw;
import io.kyligence.kap.gateway.utils.TimeUtil;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

@Slf4j
@Scope(value = "singleton")
@Component
public class GlobalConfig {

@Value(value = "${kylin.gateway.route.refresh-interval:3s}")
private String refreshInterval;

@Getter
private ImmutableList<KylinRouteRaw> lastValidRawRouteTable = ImmutableList.of();

@Getter
private final AtomicLong lastValidRawRouteTableMvcc = new AtomicLong(0);

public long getRouteRefreshIntervalSeconds() {
long refreshSeconds = 3;
try {
refreshSeconds = TimeUtil.timeStringAs(refreshInterval, TimeUnit.SECONDS);
} catch (Exception e) {
log.error("Failed to init route refresh-interval, use 3 seconds !", e);
}
return refreshSeconds;
}

public void setLastValidRawRouteTable(Collection<KylinRouteRaw> rawRouteTable) {
this.lastValidRawRouteTable = ImmutableList.copyOf(rawRouteTable);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kyligence.kap.gateway.config;

import io.kyligence.kap.gateway.filter.Kylin3XReactiveLoadBalancerClientFilter;
import io.kyligence.kap.gateway.constant.KylinGatewayVersion;
import io.kyligence.kap.gateway.filter.Kylin3XLoadBalancerClientFilter;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -15,7 +16,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.DispatcherHandler;

@ConditionalOnProperty(name = "kylin.gateway.ke.version", havingValue = "3x")
@ConditionalOnProperty(name = "kylin.gateway.ke.version", havingValue = KylinGatewayVersion.KYLIN_3X)
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({LoadBalancerClient.class, RibbonAutoConfiguration.class,
DispatcherHandler.class})
Expand All @@ -28,7 +29,7 @@ public class Kylin3XGatewayLoadBalancerClientAutoConfiguration {
ReactiveLoadBalancerClientFilter.class})
public LoadBalancerClientFilter loadBalancerClientFilter(LoadBalancerClient client,
LoadBalancerProperties properties) {
return new Kylin3XReactiveLoadBalancerClientFilter(client, properties);
return new Kylin3XLoadBalancerClientFilter(client, properties);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package io.kyligence.kap.gateway.config;

import io.kyligence.kap.gateway.exception.KylinErrorAttributes;
import io.kyligence.kap.gateway.filter.KylinRedirectToGatewayFilter;
import io.kyligence.kap.gateway.predicate.KylinGlobalRoutePredicateFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.reactive.error.DefaultErrorAttributes;
import org.springframework.cloud.gateway.config.GatewayClassPathWarningAutoConfiguration;
import org.springframework.cloud.gateway.config.GatewayLoadBalancerClientAutoConfiguration;
import io.kyligence.kap.gateway.predicate.KylinRoutePredicateFactory;
Expand All @@ -30,9 +33,19 @@ public KylinRoutePredicateFactory kylinRoutePredicateFactory() {
return new KylinRoutePredicateFactory();
}

@Bean
public KylinGlobalRoutePredicateFactory kylinGlobalRoutePredicateFactory() {
return new KylinGlobalRoutePredicateFactory();
}

@Bean
public KylinRedirectToGatewayFilter kylinRedirectToGatewayFilter() {
return new KylinRedirectToGatewayFilter();
}

@Bean
public DefaultErrorAttributes errorAttributes() {
return new KylinErrorAttributes();
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package io.kyligence.kap.gateway.config;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import io.kyligence.kap.gateway.constant.KylinGatewayVersion;
import io.kyligence.kap.gateway.entity.KylinJdbcDataSource;
import io.kyligence.kap.gateway.persistent.FileDataSource;
import io.kyligence.kap.gateway.route.reader.FileRouteTableReader;
import io.kyligence.kap.gateway.route.reader.IRouteTableReader;
import io.kyligence.kap.gateway.route.reader.KylinJdbcRouteTableReader;
import io.kyligence.kap.gateway.route.reader.Kylin3XJdbcRouteTableReader;
import io.kyligence.kap.gateway.persistent.KylinJdbcTemplate;
import io.kyligence.kap.gateway.route.reader.KylinJdbcRouteTableReader;
import io.kyligence.kap.gateway.route.reader.MockRouteTableReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand All @@ -21,6 +24,9 @@
@EnableConfigurationProperties
public class KylinRouteTableConfiguration {

@Value(value = "${kylin.gateway.ke.version:4x}")
private String version;

@Bean
@ConditionalOnProperty(name = "kylin.gateway.datasource.type", havingValue = "jdbc")
@ConfigurationProperties(prefix = "kylin.gateway.datasource")
Expand All @@ -36,9 +42,15 @@ public IRouteTableReader kylinRouteStore(KylinJdbcDataSource kylinJdbcDataSource
.url(kylinJdbcDataSource.getUrl())
.username(kylinJdbcDataSource.getUsername())
.password(kylinJdbcDataSource.getPassword()).build();
return new KylinJdbcRouteTableReader(
new KylinJdbcTemplate(dataSource, kylinJdbcDataSource.getTableName()),
kylinJdbcDataSource.getTableName());

if (KylinGatewayVersion.KYLIN_3X.equals(version)) {
return new Kylin3XJdbcRouteTableReader(
new KylinJdbcTemplate(dataSource, kylinJdbcDataSource.getTableName()),
kylinJdbcDataSource.getTableName());
}

return new KylinJdbcRouteTableReader(new KylinJdbcTemplate(dataSource, kylinJdbcDataSource.getTableName()),
kylinJdbcDataSource.getTableName(), kylinJdbcDataSource.getClusterId());
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.kyligence.kap.gateway.constant;

public enum Kylin3xResourceGroupTypeEnum {

GLOBAL, // default group, global request is routing to default group
CUBE, //
ASYNC;

Kylin3xResourceGroupTypeEnum() {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.kyligence.kap.gateway.constant;

public class KylinGatewayVersion {

private KylinGatewayVersion() {

}

public static final String KYLIN_3X = "3x";

public static final String KYLIN_4X = "4x";

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package io.kyligence.kap.gateway.constant;

public enum KylinResourceGroupTypeEnum {
// All reuqest
DEFAULT,

GLOBAL, // default group, global request is routing to default group
CUBE, //
ASYNC;
// No project request
GLOBAL,

KylinResourceGroupTypeEnum() {
// All request in a project
QUERY,

}
// No request
BUILD,

VIP,

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ private KylinRouteConstant() {

public static final String KYLIN_ROUTE_PREDICATE = "Kylin";

public static final String KYLIN_GLOBAL_ROUTE_PREDICATE = "KylinGlobal";

public static final String PREDICATE_ARG_KEY_0 = "_genkey_0";

public static final String PREDICATE_ARG_KEY_1 = "_genkey_1";
Expand All @@ -17,4 +19,6 @@ private KylinRouteConstant() {
public static final String QUERY_SUFFIX = "/api/query";

public static final String DEFAULT_RESOURCE_GROUP = "default";

public static final String GLOBAL_RESOURCE_GROUP = "global";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public class KylinJdbcDataSource {

private String tableName;

private String clusterId;

}
Loading

0 comments on commit eec1128

Please sign in to comment.