mirror of https://github.com/longtai-cn/hippo4j
Development Agent mode dynamic change (#1325)
parent
1b81e00b56
commit
618b382401
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.hippo4j.agent.plugin.spring.boot.v2.boot;
|
||||
|
||||
import cn.hippo4j.agent.core.boot.BootService;
|
||||
import cn.hippo4j.agent.core.boot.DefaultImplementor;
|
||||
import cn.hippo4j.agent.core.logging.api.ILog;
|
||||
import cn.hippo4j.agent.core.logging.api.LogManager;
|
||||
|
||||
/**
|
||||
* SpringBoot v1 plugin boot service
|
||||
*/
|
||||
@DefaultImplementor
|
||||
public class SpringBootV2PluginBootService implements BootService {
|
||||
|
||||
private static final ILog LOGGER = LogManager.getLogger(SpringBootV2PluginBootService.class);
|
||||
|
||||
@Override
|
||||
public void prepare() throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void boot() throws Throwable {
|
||||
LOGGER.info("Loader SpringBootV2PluginBootService...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() throws Throwable {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
cn.hippo4j.agent.plugin.spring.boot.v2.boot.SpringBootV2PluginBootService
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.hippo4j.agent.plugin.spring.common.support;
|
||||
|
||||
import cn.hippo4j.agent.plugin.spring.common.conf.SpringBootConfig;
|
||||
import cn.hippo4j.threadpool.dynamic.api.ThreadPoolDynamicRefresh;
|
||||
import com.ctrip.framework.apollo.ConfigChangeListener;
|
||||
import com.ctrip.framework.apollo.ConfigFile;
|
||||
import com.ctrip.framework.apollo.ConfigService;
|
||||
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
|
||||
import com.ctrip.framework.apollo.model.ConfigChange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.hippo4j.agent.core.conf.Constants.SPRING_BOOT_CONFIG_PREFIX;
|
||||
|
||||
/**
|
||||
* Abstract dynamic thread poo change handler spring
|
||||
*/
|
||||
public abstract class AbstractDynamicThreadPoolChangeHandlerSpring implements ThreadPoolDynamicRefresh {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractDynamicThreadPoolChangeHandlerSpring.class);
|
||||
|
||||
public void registerListener() {
|
||||
List<String> apolloNamespaces = SpringBootConfig.Spring.Dynamic.Thread_Pool.Apollo.NAMESPACE;
|
||||
String namespace = apolloNamespaces.get(0);
|
||||
String configFileType = SpringBootConfig.Spring.Dynamic.Thread_Pool.CONFIG_FILE_TYPE;
|
||||
|
||||
com.ctrip.framework.apollo.Config config = ConfigService.getConfig(String.format("%s.%s", namespace, configFileType));
|
||||
ConfigChangeListener configChangeListener = configChangeEvent -> {
|
||||
String replacedNamespace = namespace.replaceAll("." + configFileType, "");
|
||||
ConfigFileFormat configFileFormat = ConfigFileFormat.fromString(configFileType);
|
||||
ConfigFile configFile = ConfigService.getConfigFile(replacedNamespace, configFileFormat);
|
||||
Map<String, Object> newChangeValueMap = new HashMap<>();
|
||||
configChangeEvent.changedKeys().stream().filter(each -> each.contains(SPRING_BOOT_CONFIG_PREFIX)).forEach(each -> {
|
||||
ConfigChange change = configChangeEvent.getChange(each);
|
||||
String newValue = change.getNewValue();
|
||||
newChangeValueMap.put(each, newValue);
|
||||
});
|
||||
dynamicRefresh(configFile.getContent(), newChangeValueMap);
|
||||
};
|
||||
config.addChangeListener(configChangeListener);
|
||||
LOGGER.info("[Hippo4j-Agent] Dynamic thread pool refresher, add apollo listener success. namespace: {}", namespace);
|
||||
}
|
||||
|
||||
public void dynamicRefresh(String configContent, Map<String, Object> newValueChangeMap) {
|
||||
try {
|
||||
// String configFileType = SpringBootConfig.Spring.Dynamic.Thread_Pool.CONFIG_FILE_TYPE;
|
||||
//
|
||||
// Map<Object, Object> afterConfigMap = ConfigParserHandler.getInstance().parseConfig(configContent,
|
||||
// ConfigFileTypeEnum.of(configFileType));
|
||||
// if (CollectionUtil.isNotEmpty(newValueChangeMap)) {
|
||||
// Optional.ofNullable(afterConfigMap).ifPresent(each -> each.putAll(newValueChangeMap));
|
||||
// }
|
||||
// TODO
|
||||
// BootstrapConfigProperties afterConfigProperties = bindProperties(afterConfigMap, context);
|
||||
//
|
||||
// List<ExecutorProperties> executors = afterConfigProperties.getExecutors();
|
||||
// for (ExecutorProperties afterProperties : executors) {
|
||||
// String threadPoolId =
|
||||
// afterProperties.getThreadPoolId();
|
||||
// AgentThreadPoolExecutorHolder holder = AgentThreadPoolInstanceRegistry.getInstance().getHolder(threadPoolId);
|
||||
// if (holder.isEmpty() ||
|
||||
// holder.getExecutor() == null) {
|
||||
// continue;
|
||||
// }
|
||||
// ExecutorProperties beforeProperties = convert(holder.getProperties());
|
||||
// if (!checkConsistency(threadPoolId, beforeProperties, afterProperties)) {
|
||||
// continue;
|
||||
// }
|
||||
// dynamicRefreshPool(beforeProperties, afterProperties);
|
||||
// holder.setProperties(failDefaultExecutorProperties(beforeProperties, afterProperties)); // do refresh.
|
||||
// ChangeParameterNotifyRequest changeRequest = buildChangeRequest(beforeProperties, afterProperties);
|
||||
// LOGGER.info(CHANGE_THREAD_POOL_TEXT, threadPoolId, String.format(CHANGE_DELIMITER,
|
||||
// beforeProperties.getCorePoolSize(), changeRequest.getNowCorePoolSize()), String.format(CHANGE_DELIMITER, beforeProperties.getMaximumPoolSize(), changeRequest.getNowMaximumPoolSize()),
|
||||
// String.format(CHANGE_DELIMITER, beforeProperties.getQueueCapacity(), changeRequest.getNowQueueCapacity()), String.format(CHANGE_DELIMITER, beforeProperties.getKeepAliveTime(),
|
||||
// changeRequest.getNowKeepAliveTime()), String.format(CHANGE_DELIMITER, beforeProperties.getExecuteTimeOut(), changeRequest.getNowExecuteTimeOut()), String.format(CHANGE_DELIMITER,
|
||||
// beforeProperties.getRejectedHandler(), changeRequest.getNowRejectedName()), String.format(CHANGE_DELIMITER, beforeProperties.getAllowCoreThreadTimeOut(),
|
||||
// changeRequest.getNowAllowsCoreThreadTimeOut()));
|
||||
// }
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("[Hippo4j-Agent] config mode dynamic refresh failed.", ex);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.hippo4j</groupId>
|
||||
<artifactId>hippo4j-threadpool-agent-example</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hippo4j-threadpool-agent-config-apollo-example</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ctrip.framework.apollo</groupId>
|
||||
<artifactId>apollo-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cn.hippo4j.example.agent.config.apollo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Agent config apollo example application.
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class AgentConfigApolloExampleApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AgentConfigApolloExampleApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
server.port=8092
|
||||
server.servlet.context-path=/example
|
||||
app.id=dynamic-threadpool-example
|
||||
apollo.meta=http://127.0.0.1:8080
|
||||
apollo.autoUpdateInjectedSpringProperties=true
|
||||
apollo.bootstrap.enabled=true
|
||||
apollo.bootstrap.namespaces=application
|
||||
apollo.bootstrap.eagerLoad.enabled=true
|
||||
# The following parameters are used for testing
|
||||
env=dev
|
||||
apollo.configService=http://127.0.0.1:8080
|
||||
spring.profiles.active=dev
|
||||
spring.application.name=hippo4j-config-apollo-spring-boot-starter-example
|
||||
management.metrics.export.prometheus.enabled=true
|
||||
management.server.port=29998
|
||||
management.endpoints.web.exposure.include=*
|
||||
spring.dynamic.thread-pool.enable=true
|
||||
spring.dynamic.thread-pool.banner=true
|
||||
spring.dynamic.thread-pool.check-state-interval=3
|
||||
#spring.dynamic.thread-pool.monitor.enable=true
|
||||
#spring.dynamic.thread-pool.monitor.collect-types=micrometer
|
||||
#spring.dynamic.thread-pool.monitor.thread-pool-types=dynamic,web
|
||||
#spring.dynamic.thread-pool.monitor.initial-delay=10000
|
||||
#spring.dynamic.thread-pool.monitor.collect-interval=5000
|
||||
#spring.dynamic.thread-pool.notify-platforms[0].platform=WECHAT
|
||||
#spring.dynamic.thread-pool.notify-platforms[0].token=ac0426a5-c712-474c-9bff-72b8b8f5caff
|
||||
#spring.dynamic.thread-pool.notify-platforms[1].platform=DING
|
||||
#spring.dynamic.thread-pool.notify-platforms[1].token=56417ebba6a27ca352f0de77a2ae9da66d01f39610b5ee8a6033c60ef9071c55
|
||||
#spring.dynamic.thread-pool.notify-platforms[2].platform=LARK
|
||||
#spring.dynamic.thread-pool.notify-platforms[2].token=2cbf2808-3839-4c26-a04d-fd201dd51f9e
|
||||
spring.dynamic.thread-pool.apollo.namespace=application
|
||||
spring.dynamic.thread-pool.config-file-type=properties
|
||||
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.hippo4j</groupId>
|
||||
<artifactId>hippo4j-threadpool-example</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hippo4j-threadpool-agent-example</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>config-apollo</module>
|
||||
</modules>
|
||||
</project>
|
Loading…
Reference in new issue