Skip to content

Commit

Permalink
Merge pull request #2341 from jsonwan/github_perf/graceful
Browse files Browse the repository at this point in the history
perf: 容器化环境支持无损更新 #2338
  • Loading branch information
jsonwan authored Aug 17, 2023
2 parents f2f9849 + 9ca7772 commit bdce3ca
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tencent.bk.job.common.consul.config;

import org.springframework.boot.availability.ApplicationAvailabilityBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class JobApplicationAvailabilityAutoConfiguration {

@Bean
public ApplicationAvailabilityBean applicationAvailability() {
return new ApplicationAvailabilityBean();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.bk.job.common.consul.config.JobApplicationAvailabilityAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.tencent.bk.job.common.k8s.availability;

import com.tencent.bk.job.common.util.ThreadUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.availability.ApplicationAvailabilityBean;
import org.springframework.boot.availability.AvailabilityChangeEvent;
import org.springframework.boot.availability.ReadinessState;

@Slf4j
public class JobApplicationAvailabilityBean extends ApplicationAvailabilityBean {
@Override
public void onApplicationEvent(AvailabilityChangeEvent<?> event) {
super.onApplicationEvent(event);
if (ReadinessState.REFUSING_TRAFFIC == event.getState()) {
// SpringCloud负载均衡缓存默认为35s,等待调用方缓存刷新后再真正关闭Spring容器
int waitSeconds = 35;
while (waitSeconds > 0) {
ThreadUtils.sleep(1000);
log.info("wait for GracefulShutdown, {}s left", waitSeconds--);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tencent.bk.job.common.k8s.config;

import com.tencent.bk.job.common.k8s.availability.JobApplicationAvailabilityBean;
import org.springframework.boot.availability.ApplicationAvailabilityBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class JobApplicationAvailabilityAutoConfiguration {

@Bean
public ApplicationAvailabilityBean applicationAvailability() {
return new JobApplicationAvailabilityBean();
}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.bk.job.common.k8s.config.K8sServiceInfoServiceAutoConfig
com.tencent.bk.job.common.k8s.config.K8sServiceInfoServiceAutoConfig,\
com.tencent.bk.job.common.k8s.config.JobApplicationAvailabilityAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
import com.tencent.bk.job.common.config.FeatureToggleConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.DependsOn;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class})
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class,
ApplicationAvailabilityAutoConfiguration.class})
@EnableCaching
@EnableFeignClients
@EnableScheduling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.tencent.bk.job.common.config.FeatureToggleConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
Expand All @@ -37,7 +38,8 @@
/**
* @since 21/7/2020 10:55
*/
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class})
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class,
ApplicationAvailabilityAutoConfiguration.class})
@EnableCaching
@EnableFeignClients
@EnableScheduling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.cloud.config.server.EnableConfigServer;

/**
* @date 2019/09/20
*/
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job")
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude =
{ApplicationAvailabilityAutoConfiguration.class})
@EnableConfigServer
public class JobConfigBootApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
import com.tencent.bk.job.crontab.config.JobQuartzProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;

/**
* @date 2019/09/20
*/
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class})
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class,
ApplicationAvailabilityAutoConfiguration.class})
@EnableFeignClients
@EnableConfigurationProperties({FeatureToggleConfig.class, JobQuartzProperties.class})
public class JobCrontabBootApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
import com.tencent.bk.job.common.config.FeatureToggleConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;


@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class})
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class,
ApplicationAvailabilityAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients
@EnableConfigurationProperties({FeatureToggleConfig.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableScheduling;

@Slf4j
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class})
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class,
ApplicationAvailabilityAutoConfiguration.class})
@EnableCaching
@EnableFeignClients
@EnableScheduling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.web.embedded.NettyWebServerFactoryCustomizer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
Expand All @@ -43,7 +44,8 @@
/**
* @date 2019/09/20
*/
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job")
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude =
{ApplicationAvailabilityAutoConfiguration.class})
@EnableDiscoveryClient
@Slf4j
@EnableConfigurationProperties({FeatureToggleConfig.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
import com.tencent.bk.job.common.config.FeatureToggleConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;

/**
* @date 2019/09/20
*/
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job")
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude =
{ApplicationAvailabilityAutoConfiguration.class})
@EnableFeignClients
@EnableConfigurationProperties({FeatureToggleConfig.class})
public class JobLogBootApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
import com.tencent.bk.job.common.config.FeatureToggleConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class})
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude = {RedisAutoConfiguration.class,
ApplicationAvailabilityAutoConfiguration.class})
@EnableConfigurationProperties({FeatureToggleConfig.class})
@EnableCaching
@EnableFeignClients
Expand Down
2 changes: 1 addition & 1 deletion support-files/kubernetes/images/backend/backend.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bkjob/jdk:0.0.2
FROM bkjob/jdk:0.0.3

LABEL maintainer="Tencent BlueKing Job"

Expand Down
4 changes: 2 additions & 2 deletions support-files/kubernetes/images/backend/jdk.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bkjob/os:0.0.1
FROM bkjob/os:0.0.2

LABEL maintainer="Tencent BlueKing Job"

Expand All @@ -10,4 +10,4 @@ RUN mkdir -p /data && \
rm -f TencentKona8.0.3.b2_jdk_linux-x86_64_8u262.tar.gz
ENV JAVA_HOME=/data/TencentKona-8.0.3-262
ENV PATH=${JAVA_HOME}/bin:$PATH
ENV CLASSPATH=.:${JAVA_HOME}/lib
ENV CLASSPATH=.:${JAVA_HOME}/lib
4 changes: 3 additions & 1 deletion support-files/kubernetes/images/backend/os.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
RUN yum install -y vim && \
yum install -y less && \
yum install -y wget && \
yum install -y lrzsz
yum install -y lrzsz && \
yum install -y net-tools.x86_64 && \
yum install -y bind-utils

0 comments on commit bdce3ca

Please sign in to comment.