From 95e6c1441edadc8bec5e5e0b2682ff67f8b82f54 Mon Sep 17 00:00:00 2001 From: HzjNeverStop <441627022@qq.com> Date: Tue, 12 Apr 2022 16:33:45 +0800 Subject: [PATCH] fix isle bean endpoints (#946) --- .../beans/IsleBeansEndpointAutoConfiguration.java | 7 ++----- .../autoconfigure/test/EmptyConfiguration.java | 7 ------- .../test/IsleBeanEndpointAutoConfiguration.java | 3 +-- .../sofa/boot/actuator/beans/IsleBeansEndpoint.java | 11 ++++++----- .../components/SofaBootComponentsEndPoint.java | 10 +++++----- .../boot/actuator/beans/IsleBeanEndpointTest.java | 4 +++- .../components/SofaBootComponentsEndpointTest.java | 6 +++--- sofa-boot-project/sofa-boot-parent/pom.xml | 2 +- 8 files changed, 21 insertions(+), 29 deletions(-) diff --git a/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/main/java/com/alipay/sofa/boot/actuator/autoconfigure/beans/IsleBeansEndpointAutoConfiguration.java b/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/main/java/com/alipay/sofa/boot/actuator/autoconfigure/beans/IsleBeansEndpointAutoConfiguration.java index bf049fae5..b24c375be 100644 --- a/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/main/java/com/alipay/sofa/boot/actuator/autoconfigure/beans/IsleBeansEndpointAutoConfiguration.java +++ b/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/main/java/com/alipay/sofa/boot/actuator/autoconfigure/beans/IsleBeansEndpointAutoConfiguration.java @@ -24,7 +24,6 @@ import org.springframework.boot.actuate.beans.BeansEndpoint; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -46,10 +45,8 @@ public class IsleBeansEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnBean(ApplicationRuntimeModel.class) - public BeansEndpoint beansEndpoint(ConfigurableApplicationContext applicationContext, - ApplicationRuntimeModel applicationRuntimeModel) { - return new IsleBeansEndpoint(applicationContext, applicationRuntimeModel); + public BeansEndpoint beansEndpoint(ConfigurableApplicationContext applicationContext) { + return new IsleBeansEndpoint(applicationContext); } } diff --git a/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/actuator/autoconfigure/test/EmptyConfiguration.java b/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/actuator/autoconfigure/test/EmptyConfiguration.java index 0f7cb335a..bbb87b34e 100644 --- a/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/actuator/autoconfigure/test/EmptyConfiguration.java +++ b/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/actuator/autoconfigure/test/EmptyConfiguration.java @@ -16,9 +16,7 @@ */ package com.alipay.sofa.actuator.autoconfigure.test; -import com.alipay.sofa.isle.ApplicationRuntimeModel; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** @@ -28,9 +26,4 @@ @EnableAutoConfiguration @Configuration(proxyBeanMethods = false) public class EmptyConfiguration { - - @Bean - public ApplicationRuntimeModel applicationRuntimeModel() { - return new ApplicationRuntimeModel(); - } } diff --git a/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/actuator/autoconfigure/test/IsleBeanEndpointAutoConfiguration.java b/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/actuator/autoconfigure/test/IsleBeanEndpointAutoConfiguration.java index bc5f245c0..26c40da2c 100644 --- a/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/actuator/autoconfigure/test/IsleBeanEndpointAutoConfiguration.java +++ b/sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/actuator/autoconfigure/test/IsleBeanEndpointAutoConfiguration.java @@ -49,7 +49,6 @@ public void test() throws JsonProcessingException { JsonNode rootNode = objectMapper.readTree(response.getBody()); JsonNode contextNode = rootNode.get("contexts"); Assert.assertNotNull(contextNode); - Assert.assertEquals(2, contextNode.size()); - Assert.assertNotNull(contextNode.get("bootstrap")); + Assert.assertEquals(1, contextNode.size()); } } diff --git a/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/beans/IsleBeansEndpoint.java b/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/beans/IsleBeansEndpoint.java index 5cc5766b2..70d046191 100644 --- a/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/beans/IsleBeansEndpoint.java +++ b/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/beans/IsleBeansEndpoint.java @@ -16,6 +16,7 @@ */ package com.alipay.sofa.boot.actuator.beans; +import com.alipay.sofa.boot.constant.SofaBootConstants; import com.alipay.sofa.isle.ApplicationRuntimeModel; import com.alipay.sofa.isle.deployment.DeploymentDescriptor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -36,26 +37,26 @@ */ public class IsleBeansEndpoint extends BeansEndpoint { - private final ApplicationRuntimeModel applicationRuntimeModel; + private final ConfigurableApplicationContext context; /** * Creates a new {@code BeansEndpoint} that will describe the beans in the given * {@code context} and all of its ancestors. * * @param context the application context - * @param applicationRuntimeModel the isle runtime model * @see ConfigurableApplicationContext#getParent() */ - public IsleBeansEndpoint(ConfigurableApplicationContext context, - ApplicationRuntimeModel applicationRuntimeModel) { + public IsleBeansEndpoint(ConfigurableApplicationContext context) { super(context); - this.applicationRuntimeModel = applicationRuntimeModel; + this.context = context; } @ReadOperation @Override public ApplicationBeans beans() { ApplicationBeans applicationBeans = super.beans(); + ApplicationRuntimeModel applicationRuntimeModel = context.getBean( + SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class); Map moduleApplicationContexts = getModuleApplicationContexts(applicationRuntimeModel); applicationBeans.getContexts().putAll(moduleApplicationContexts); return applicationBeans; diff --git a/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/components/SofaBootComponentsEndPoint.java b/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/components/SofaBootComponentsEndPoint.java index df632346d..c652180eb 100644 --- a/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/components/SofaBootComponentsEndPoint.java +++ b/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/components/SofaBootComponentsEndPoint.java @@ -50,7 +50,7 @@ public SofaBootComponentsEndPoint(SofaRuntimeContext sofaRuntimeContext) { @ReadOperation public ApplicationComponents components() { ComponentManager componentManager = sofaRuntimeContext.getComponentManager(); - Map> componentsInfoMap = new HashMap<>(); + Map> componentsInfoMap = new HashMap<>(); Collection componentTypes = componentManager.getComponentTypes(); componentTypes.forEach(componentType -> { Collection componentInfos = componentManager.getComponentInfosByType(componentType); @@ -58,20 +58,20 @@ public ApplicationComponents components() { .map(componentInfo -> new ComponentDisplayInfo(componentInfo.getName().getName(), componentInfo.getApplicationContext().getId())) .collect(Collectors.toList()); - componentsInfoMap.put(componentType, componentDisplayInfos); + componentsInfoMap.put(componentType.getName(), componentDisplayInfos); }); return new ApplicationComponents(componentsInfoMap); } public static final class ApplicationComponents { - private final Map> componentsInfoMap; + private final Map> componentsInfoMap; - private ApplicationComponents(Map> componentsInfoMap) { + private ApplicationComponents(Map> componentsInfoMap) { this.componentsInfoMap = componentsInfoMap; } - public Map> getComponentsInfoMap() { + public Map> getComponentsInfoMap() { return this.componentsInfoMap; } } diff --git a/sofa-boot-project/sofa-boot-actuator/src/test/java/com/alipay/sofa/boot/actuator/beans/IsleBeanEndpointTest.java b/sofa-boot-project/sofa-boot-actuator/src/test/java/com/alipay/sofa/boot/actuator/beans/IsleBeanEndpointTest.java index 35ea6284f..bd5ce10fa 100644 --- a/sofa-boot-project/sofa-boot-actuator/src/test/java/com/alipay/sofa/boot/actuator/beans/IsleBeanEndpointTest.java +++ b/sofa-boot-project/sofa-boot-actuator/src/test/java/com/alipay/sofa/boot/actuator/beans/IsleBeanEndpointTest.java @@ -16,6 +16,7 @@ */ package com.alipay.sofa.boot.actuator.beans; +import com.alipay.sofa.boot.constant.SofaBootConstants; import com.alipay.sofa.isle.ApplicationRuntimeModel; import com.alipay.sofa.isle.deployment.DeploymentDescriptor; import org.junit.Assert; @@ -47,7 +48,8 @@ public void testBeans() { ApplicationRuntimeModel model = new ApplicationRuntimeModel(); model.addInstalled(new MockDeploymentDescriptor("A")); model.addInstalled(new MockDeploymentDescriptor("B")); - IsleBeansEndpoint isleBeansEndpoint = new IsleBeansEndpoint(context, model); + context.getBeanFactory().registerSingleton(SofaBootConstants.APPLICATION, model); + IsleBeansEndpoint isleBeansEndpoint = new IsleBeansEndpoint(context); BeansEndpoint.ApplicationBeans applicationBeans = isleBeansEndpoint.beans(); Assert.assertNotNull(applicationBeans); Map beansMap = applicationBeans.getContexts(); diff --git a/sofa-boot-project/sofa-boot-actuator/src/test/java/com/alipay/sofa/boot/actuator/components/SofaBootComponentsEndpointTest.java b/sofa-boot-project/sofa-boot-actuator/src/test/java/com/alipay/sofa/boot/actuator/components/SofaBootComponentsEndpointTest.java index 55eb2aa1e..82328305b 100644 --- a/sofa-boot-project/sofa-boot-actuator/src/test/java/com/alipay/sofa/boot/actuator/components/SofaBootComponentsEndpointTest.java +++ b/sofa-boot-project/sofa-boot-actuator/src/test/java/com/alipay/sofa/boot/actuator/components/SofaBootComponentsEndpointTest.java @@ -92,13 +92,13 @@ public void testComponents() { SofaBootComponentsEndPoint.ApplicationComponents applicationComponents = sofaBootComponentsEndPoint .components(); Assert.assertNotNull(applicationComponents); - Map> componentTypeCollectionMap = applicationComponents + Map> componentTypeCollectionMap = applicationComponents .getComponentsInfoMap(); Assert.assertNotNull(componentTypeCollectionMap); Assert.assertEquals(2, componentTypeCollectionMap.size()); Collection serviceComponentCollection = componentTypeCollectionMap - .get(ServiceComponent.SERVICE_COMPONENT_TYPE); + .get(ServiceComponent.SERVICE_COMPONENT_TYPE.getName()); Assert.assertEquals(1, serviceComponents.size()); Assert.assertTrue(serviceComponentCollection instanceof List); Assert.assertEquals("testSofaService", @@ -109,7 +109,7 @@ public void testComponents() { .get(0).getApplicationId()); Collection extComponentCollection = componentTypeCollectionMap - .get(ExtensionComponent.EXTENSION_COMPONENT_TYPE); + .get(ExtensionComponent.EXTENSION_COMPONENT_TYPE.getName()); Assert.assertEquals(1, extComponentCollection.size()); Assert.assertTrue(extComponentCollection instanceof List); Assert.assertEquals("testSofaExt", diff --git a/sofa-boot-project/sofa-boot-parent/pom.xml b/sofa-boot-project/sofa-boot-parent/pom.xml index e4a83d07b..0050bb64e 100644 --- a/sofa-boot-project/sofa-boot-parent/pom.xml +++ b/sofa-boot-project/sofa-boot-parent/pom.xml @@ -30,7 +30,7 @@ 2.22.2 - 2.1.0.RELEASE + 3.0.5 3.1.0 9.0.54 9.4.26.v20200117