-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1186 from lilai23/develop
【fix】修复配置监听问题
- Loading branch information
Showing
7 changed files
with
178 additions
and
52 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...oval-plugin/src/main/java/com/huaweicloud/sermant/declarer/SpringApplicationDeclarer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...lugin/src/main/java/com/huaweicloud/sermant/interceptor/SpringApplicationInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...al/removal-plugin/src/main/java/com/huaweicloud/sermant/service/RemovalConfigService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
...l/removal-service/src/main/java/com/huaweicloud/sermant/service/RemovalConfigService.java
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...moval-service/src/main/java/com/huaweicloud/sermant/service/RemovalConfigServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters