Skip to content

Commit

Permalink
fix isle bean endpoints (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
HzjNeverStop authored Apr 12, 2022
1 parent 7ca5a91 commit 95e6c14
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -28,9 +26,4 @@
@EnableAutoConfiguration
@Configuration(proxyBeanMethods = false)
public class EmptyConfiguration {

@Bean
public ApplicationRuntimeModel applicationRuntimeModel() {
return new ApplicationRuntimeModel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, ContextBeans> moduleApplicationContexts = getModuleApplicationContexts(applicationRuntimeModel);
applicationBeans.getContexts().putAll(moduleApplicationContexts);
return applicationBeans;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ public SofaBootComponentsEndPoint(SofaRuntimeContext sofaRuntimeContext) {
@ReadOperation
public ApplicationComponents components() {
ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
Map<ComponentType, Collection<ComponentDisplayInfo>> componentsInfoMap = new HashMap<>();
Map<String, Collection<ComponentDisplayInfo>> componentsInfoMap = new HashMap<>();
Collection<ComponentType> componentTypes = componentManager.getComponentTypes();
componentTypes.forEach(componentType -> {
Collection<ComponentInfo> componentInfos = componentManager.getComponentInfosByType(componentType);
Collection<ComponentDisplayInfo> componentDisplayInfos = componentInfos.stream()
.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<ComponentType, Collection<ComponentDisplayInfo>> componentsInfoMap;
private final Map<String, Collection<ComponentDisplayInfo>> componentsInfoMap;

private ApplicationComponents(Map<ComponentType, Collection<ComponentDisplayInfo>> componentsInfoMap) {
private ApplicationComponents(Map<String, Collection<ComponentDisplayInfo>> componentsInfoMap) {
this.componentsInfoMap = componentsInfoMap;
}

public Map<ComponentType, Collection<ComponentDisplayInfo>> getComponentsInfoMap() {
public Map<String, Collection<ComponentDisplayInfo>> getComponentsInfoMap() {
return this.componentsInfoMap;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, BeansEndpoint.ContextBeans> beansMap = applicationBeans.getContexts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public void testComponents() {
SofaBootComponentsEndPoint.ApplicationComponents applicationComponents = sofaBootComponentsEndPoint
.components();
Assert.assertNotNull(applicationComponents);
Map<ComponentType, Collection<SofaBootComponentsEndPoint.ComponentDisplayInfo>> componentTypeCollectionMap = applicationComponents
Map<String, Collection<SofaBootComponentsEndPoint.ComponentDisplayInfo>> componentTypeCollectionMap = applicationComponents
.getComponentsInfoMap();
Assert.assertNotNull(componentTypeCollectionMap);
Assert.assertEquals(2, componentTypeCollectionMap.size());

Collection<SofaBootComponentsEndPoint.ComponentDisplayInfo> 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",
Expand All @@ -109,7 +109,7 @@ public void testComponents() {
.get(0).getApplicationId());

Collection<SofaBootComponentsEndPoint.ComponentDisplayInfo> 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",
Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<maven.surefire.plugin>2.22.2</maven.surefire.plugin>

<!-- for dependencyManagement -->
<spring.cloud.starter.openfeign.version>2.1.0.RELEASE</spring.cloud.starter.openfeign.version>
<spring.cloud.starter.openfeign.version>3.0.5</spring.cloud.starter.openfeign.version>
<javax.servlet.version>3.1.0</javax.servlet.version>
<tomcat.version>9.0.54</tomcat.version>
<jetty.version>9.4.26.v20200117</jetty.version>
Expand Down

0 comments on commit 95e6c14

Please sign in to comment.