Skip to content

Commit

Permalink
Merge pull request #1186 from lilai23/develop
Browse files Browse the repository at this point in the history
【fix】修复配置监听问题
  • Loading branch information
luanwenfei-venus authored Apr 10, 2023
2 parents 81765fd + 5e2db36 commit 949256b
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed 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 com.huaweicloud.sermant.declarer;

import com.huaweicloud.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer;
import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer;
import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher;
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher;
import com.huaweicloud.sermant.interceptor.SpringApplicationInterceptor;

/**
* 增强run方法
*
* @author lilai
* @since 2023-04-10
*/
public class SpringApplicationDeclarer extends AbstractPluginDeclarer {
private static final String ENHANCE_CLASS = "org.springframework.boot.SpringApplication";

private static final String INTERCEPT_CLASS = SpringApplicationInterceptor.class.getCanonicalName();

private static final String METHOD_NAME = "run";

@Override
public ClassMatcher getClassMatcher() {
return ClassMatcher.nameEquals(ENHANCE_CLASS);
}

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{
InterceptDeclarer.build(MethodMatcher.nameEquals(METHOD_NAME).and(MethodMatcher.isMemberMethod()),
INTERCEPT_CLASS)
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed 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 com.huaweicloud.sermant.interceptor;

import com.huaweicloud.sermant.core.plugin.agent.entity.ExecuteContext;
import com.huaweicloud.sermant.core.plugin.agent.interceptor.AbstractInterceptor;
import com.huaweicloud.sermant.core.service.ServiceManager;
import com.huaweicloud.sermant.service.RemovalConfigService;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* 增强run方法
*
* @author lilai
* @since 2023-04-10
*/
public class SpringApplicationInterceptor extends AbstractInterceptor {
private static final AtomicBoolean INIT = new AtomicBoolean();

private final RemovalConfigService removalConfigService;

/**
* 构造方法
*/
public SpringApplicationInterceptor() {
removalConfigService = ServiceManager.getService(RemovalConfigService.class);
}

@Override
public ExecuteContext before(ExecuteContext context) {
return context;
}

@Override
public ExecuteContext after(ExecuteContext context) {
Object logStartupInfo = context.getMemberFieldValue("logStartupInfo");
if ((logStartupInfo instanceof Boolean) && (Boolean) logStartupInfo && INIT.compareAndSet(false, true)) {
removalConfigService.init();
}
return context;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed 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 com.huaweicloud.sermant.service;

import com.huaweicloud.sermant.core.plugin.service.PluginService;

/**
* 类描述
*
* @author lilai
* @since 2023-04-10
*/
public interface RemovalConfigService extends PluginService {
/**
* 初始化配置监听
*/
void init();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ com.huaweicloud.sermant.declarer.SpringCloudServerListDeclarer
com.huaweicloud.sermant.declarer.SpringBootCacheManagerDeclarer
com.huaweicloud.sermant.declarer.SpringCloudReactiveDiscoveryDeclarer
com.huaweicloud.sermant.declarer.SpringCloudDiscoveryDeclarer
com.huaweicloud.sermant.declarer.SpringCloudClientDeclarer
com.huaweicloud.sermant.declarer.SpringCloudClientDeclarer
com.huaweicloud.sermant.declarer.SpringApplicationDeclarer

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed 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 com.huaweicloud.sermant.service;

import com.huaweicloud.sermant.config.RemovalDynamicConfigListener;
import com.huaweicloud.sermant.core.plugin.subscribe.ConfigSubscriber;
import com.huaweicloud.sermant.core.plugin.subscribe.CseGroupConfigSubscriber;

/**
* 配置监听服务
*
* @author zhp
* @since 2023-04-04
*/
public class RemovalConfigServiceImpl implements RemovalConfigService {
@Override
public void init() {
ConfigSubscriber subscriber = new CseGroupConfigSubscriber("default", new RemovalDynamicConfigListener(),
"service-removal");
subscriber.subscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

com.huaweicloud.sermant.service.RemovalEventServiceImpl
com.huaweicloud.sermant.service.RequestDataCountTask
com.huaweicloud.sermant.service.RemovalConfigService
com.huaweicloud.sermant.service.RemovalConfigServiceImpl

0 comments on commit 949256b

Please sign in to comment.