From 514919db72a656e8a41e93fd31ea9beeabccc527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Tue, 23 Aug 2022 10:58:48 +0800 Subject: [PATCH 01/14] add a minor changes to log the missing modules in SpringContextInstallStage --- .../isle/stage/SpringContextInstallStage.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index 3a05e0cd1..80e81541e 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -62,7 +62,7 @@ public class SpringContextInstallStage extends AbstractPipelineStage { private static final int DEFAULT_REFRESH_TASK_QUEUE_SIZE = 1000; private static final int CPU_COUNT = Runtime.getRuntime() - .availableProcessors(); ; + .availableProcessors(); private final SofaModuleProperties sofaModuleProperties; @@ -156,18 +156,31 @@ private void outputModulesMessage(ApplicationRuntimeModel application) private String getErrorMessageByApplicationModule(ApplicationRuntimeModel application) { StringBuilder sbError = new StringBuilder(512); if (application.getDeployRegistry().getPendingEntries().size() > 0) { - sbError.append("\n").append(ErrorCode.convert("01-12000")).append(".)").append("(") - .append(application.getDeployRegistry().getPendingEntries().size()) - .append(") >>>>>>>>\n"); + sbError.append("\n").append(ErrorCode.convert("01-12000")).append("(") + .append(application.getDeployRegistry().getPendingEntries().size()) + .append(") >>>>>>>>\n"); + + for (DependencyTree.Entry entry : application + .getDeployRegistry().getPendingEntries()) { + if (application.getAllDeployments().contains(entry.get())) { + sbError.append("[").append(entry.getKey()).append("]").append(" depends on ") + .append(entry.getWaitsFor()) + .append(", but the latter can not be resolved.").append("\n"); + } + } } - for (DependencyTree.Entry entry : application - .getDeployRegistry().getPendingEntries()) { - if (application.getAllDeployments().contains(entry.get())) { - sbError.append("[").append(entry.getKey()).append("]").append(" depends on ") - .append(entry.getWaitsFor()).append(", but the latter can not be resolved.") - .append("\n"); + if (application.getDeployRegistry().getMissingRequirements().size() > 0) { + sbError.append("Missing modules").append("(") + .append(application.getDeployRegistry().getMissingRequirements().size()) + .append(") >>>>>>>>\n"); + + for (DependencyTree.Entry entry : application + .getDeployRegistry().getMissingRequirements()) { + sbError.append("[").append(entry.getKey()).append("]").append("\n"); } + + sbError.append("Please add the corresponding modules.").append("\n"); } return sbError.toString(); From 81fc95402e4f318bde5eb39cf7368a99d38ce9c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Tue, 23 Aug 2022 13:58:01 +0800 Subject: [PATCH 02/14] add a minor changes to log the missing modules in SpringContextInstallStage --- .../com/alipay/sofa/isle/stage/SpringContextInstallStage.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index 80e81541e..c4368ae2e 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -179,7 +179,6 @@ private String getErrorMessageByApplicationModule(ApplicationRuntimeModel applic .getDeployRegistry().getMissingRequirements()) { sbError.append("[").append(entry.getKey()).append("]").append("\n"); } - sbError.append("Please add the corresponding modules.").append("\n"); } From 2ab9871aaed241e321f11016cee5c1fddcfde22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Tue, 23 Aug 2022 14:08:30 +0800 Subject: [PATCH 03/14] add a minor changes to log the missing modules in SpringContextInstallStage --- .../com/alipay/sofa/isle/stage/SpringContextInstallStage.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index c4368ae2e..80e81541e 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -179,6 +179,7 @@ private String getErrorMessageByApplicationModule(ApplicationRuntimeModel applic .getDeployRegistry().getMissingRequirements()) { sbError.append("[").append(entry.getKey()).append("]").append("\n"); } + sbError.append("Please add the corresponding modules.").append("\n"); } From c8e353f19e7a9d68976be6404bba5262bab65cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Tue, 23 Aug 2022 14:12:44 +0800 Subject: [PATCH 04/14] add a minor changes to log the missing modules in SpringContextInstallStage --- .../isle/stage/SpringContextInstallStage.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index 80e81541e..d81a66c95 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -157,26 +157,26 @@ private String getErrorMessageByApplicationModule(ApplicationRuntimeModel applic StringBuilder sbError = new StringBuilder(512); if (application.getDeployRegistry().getPendingEntries().size() > 0) { sbError.append("\n").append(ErrorCode.convert("01-12000")).append("(") - .append(application.getDeployRegistry().getPendingEntries().size()) - .append(") >>>>>>>>\n"); + .append(application.getDeployRegistry().getPendingEntries().size()) + .append(") >>>>>>>>\n"); for (DependencyTree.Entry entry : application - .getDeployRegistry().getPendingEntries()) { + .getDeployRegistry().getPendingEntries()) { if (application.getAllDeployments().contains(entry.get())) { sbError.append("[").append(entry.getKey()).append("]").append(" depends on ") - .append(entry.getWaitsFor()) - .append(", but the latter can not be resolved.").append("\n"); + .append(entry.getWaitsFor()) + .append(", but the latter can not be resolved.").append("\n"); } } } if (application.getDeployRegistry().getMissingRequirements().size() > 0) { sbError.append("Missing modules").append("(") - .append(application.getDeployRegistry().getMissingRequirements().size()) - .append(") >>>>>>>>\n"); + .append(application.getDeployRegistry().getMissingRequirements().size()) + .append(") >>>>>>>>\n"); for (DependencyTree.Entry entry : application - .getDeployRegistry().getMissingRequirements()) { + .getDeployRegistry().getMissingRequirements()) { sbError.append("[").append(entry.getKey()).append("]").append("\n"); } From c043f3b70f157d21ed723b55b22f341a3a9066a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Wed, 7 Sep 2022 11:54:58 +0800 Subject: [PATCH 05/14] Add a function that can remove the corresponding components when modules install failure --- .../spring/config/SofaModuleProperties.java | 31 ++++++++++++------- .../isle/stage/SpringContextInstallStage.java | 18 +++++++++-- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/spring/config/SofaModuleProperties.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/spring/config/SofaModuleProperties.java index 0e74dad34..14fce6718 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/spring/config/SofaModuleProperties.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/spring/config/SofaModuleProperties.java @@ -27,19 +27,20 @@ */ @ConfigurationProperties(prefix = PREFIX) public class SofaModuleProperties { - static final String PREFIX = "com.alipay.sofa.boot"; + static final String PREFIX = "com.alipay.sofa.boot"; private String activeProfiles; - private long beanLoadCost = 100; - private boolean allowBeanDefinitionOverriding = false; - private boolean moduleStartUpParallel = true; - private boolean publishEventToParent = false; - private boolean enableIsle = true; - private boolean allowModuleOverriding = false; - private boolean ignoreModuleInstallFailure = false; - private float parallelRefreshCoreCountFactor = 5.0f; - private long parallelRefreshTimeout = 60; - private long parallelRefreshCheckPeriod = 30; + private long beanLoadCost = 100; + private boolean allowBeanDefinitionOverriding = false; + private boolean moduleStartUpParallel = true; + private boolean publishEventToParent = false; + private boolean enableIsle = true; + private boolean allowModuleOverriding = false; + private boolean ignoreModuleInstallFailure = false; + private boolean removeComponentWhenModuleInstallFailure = true; + private float parallelRefreshCoreCountFactor = 5.0f; + private long parallelRefreshTimeout = 60; + private long parallelRefreshCheckPeriod = 30; public String getActiveProfiles() { return activeProfiles; @@ -128,4 +129,12 @@ public long getParallelRefreshCheckPeriod() { public void setParallelRefreshCheckPeriod(long parallelRefreshCheckPeriod) { this.parallelRefreshCheckPeriod = parallelRefreshCheckPeriod; } + + public boolean isRemoveComponentWhenModuleInstallFailure() { + return removeComponentWhenModuleInstallFailure; + } + + public void setRemoveComponentWhenModuleInstallFailure(boolean removeComponentWhenModuleInstallFailure) { + this.removeComponentWhenModuleInstallFailure = removeComponentWhenModuleInstallFailure; + } } diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index d81a66c95..3dd3f5ccd 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -30,6 +30,7 @@ import com.alipay.sofa.runtime.api.component.ComponentName; import com.alipay.sofa.runtime.log.SofaLogger; import com.alipay.sofa.runtime.spi.component.ComponentInfo; +import com.alipay.sofa.runtime.spi.component.ComponentManager; import com.alipay.sofa.runtime.spi.component.Implementation; import com.alipay.sofa.runtime.spi.util.ComponentNameFactory; import com.alipay.sofa.runtime.spring.SpringContextComponent; @@ -40,6 +41,7 @@ import org.springframework.util.StringUtils; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.CopyOnWriteArrayList; @@ -84,11 +86,21 @@ protected void doProcess() throws Exception { throw new DeploymentException(ErrorCode.convert("01-11000"), t); } - if (!sofaModuleProperties.isIgnoreModuleInstallFailure()) { - if (!application.getFailed().isEmpty()) { - List failedModuleNames = application.getFailed().stream().map(DeploymentDescriptor::getModuleName).collect(Collectors.toList()); + if (!application.getFailed().isEmpty()) { + List failedModuleNames = application.getFailed().stream().map(DeploymentDescriptor::getModuleName).collect(Collectors.toList()); + if(!sofaModuleProperties.isIgnoreModuleInstallFailure()) { throw new DeploymentException(ErrorCode.convert("01-11007", failedModuleNames)); } + // remove component when module install failure + if(sofaModuleProperties.isRemoveComponentWhenModuleInstallFailure()){ + ComponentManager componentManager = application.getSofaRuntimeContext().getComponentManager(); + Collection componentInfos = componentManager.getComponents(); + for(ComponentInfo componentInfo : componentInfos) { + if(failedModuleNames.contains(componentInfo.getApplicationContext().getId())){ + componentManager.unregister(componentInfo); + } + } + } } } From 49d78217edb52daed7c85a6c9e7aee0eb19cb85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Wed, 7 Sep 2022 17:53:45 +0800 Subject: [PATCH 06/14] Add test case for removing the components when module install failure --- .../spring/config/SofaModuleProperties.java | 36 ++++---- .../isle/stage/SpringContextInstallStage.java | 10 +- .../test/SpringContextInstallStageTest.java | 91 +++++++++++++++++-- .../resources/sofa-boot/log-codes.properties | 1 + 4 files changed, 111 insertions(+), 27 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/spring/config/SofaModuleProperties.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/spring/config/SofaModuleProperties.java index 14fce6718..0b748306f 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/spring/config/SofaModuleProperties.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/spring/config/SofaModuleProperties.java @@ -16,10 +16,10 @@ */ package com.alipay.sofa.isle.spring.config; -import static com.alipay.sofa.isle.spring.config.SofaModuleProperties.PREFIX; - import org.springframework.boot.context.properties.ConfigurationProperties; +import static com.alipay.sofa.isle.spring.config.SofaModuleProperties.PREFIX; + /** * Properties * @@ -27,20 +27,20 @@ */ @ConfigurationProperties(prefix = PREFIX) public class SofaModuleProperties { - static final String PREFIX = "com.alipay.sofa.boot"; + static final String PREFIX = "com.alipay.sofa.boot"; private String activeProfiles; - private long beanLoadCost = 100; - private boolean allowBeanDefinitionOverriding = false; - private boolean moduleStartUpParallel = true; - private boolean publishEventToParent = false; - private boolean enableIsle = true; - private boolean allowModuleOverriding = false; - private boolean ignoreModuleInstallFailure = false; - private boolean removeComponentWhenModuleInstallFailure = true; - private float parallelRefreshCoreCountFactor = 5.0f; - private long parallelRefreshTimeout = 60; - private long parallelRefreshCheckPeriod = 30; + private long beanLoadCost = 100; + private boolean allowBeanDefinitionOverriding = false; + private boolean moduleStartUpParallel = true; + private boolean publishEventToParent = false; + private boolean enableIsle = true; + private boolean allowModuleOverriding = false; + private boolean ignoreModuleInstallFailure = false; + private boolean unregisterComponentWhenModuleInstallFailure = true; + private float parallelRefreshCoreCountFactor = 5.0f; + private long parallelRefreshTimeout = 60; + private long parallelRefreshCheckPeriod = 30; public String getActiveProfiles() { return activeProfiles; @@ -130,11 +130,11 @@ public void setParallelRefreshCheckPeriod(long parallelRefreshCheckPeriod) { this.parallelRefreshCheckPeriod = parallelRefreshCheckPeriod; } - public boolean isRemoveComponentWhenModuleInstallFailure() { - return removeComponentWhenModuleInstallFailure; + public boolean isUnregisterComponentWhenModuleInstallFailure() { + return unregisterComponentWhenModuleInstallFailure; } - public void setRemoveComponentWhenModuleInstallFailure(boolean removeComponentWhenModuleInstallFailure) { - this.removeComponentWhenModuleInstallFailure = removeComponentWhenModuleInstallFailure; + public void setUnregisterComponentWhenModuleInstallFailure(boolean unregisterComponentWhenModuleInstallFailure) { + this.unregisterComponentWhenModuleInstallFailure = unregisterComponentWhenModuleInstallFailure; } } diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index 3dd3f5ccd..8ddae72ff 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -92,12 +92,16 @@ protected void doProcess() throws Exception { throw new DeploymentException(ErrorCode.convert("01-11007", failedModuleNames)); } // remove component when module install failure - if(sofaModuleProperties.isRemoveComponentWhenModuleInstallFailure()){ + if(sofaModuleProperties.isUnregisterComponentWhenModuleInstallFailure()){ ComponentManager componentManager = application.getSofaRuntimeContext().getComponentManager(); Collection componentInfos = componentManager.getComponents(); for(ComponentInfo componentInfo : componentInfos) { - if(failedModuleNames.contains(componentInfo.getApplicationContext().getId())){ - componentManager.unregister(componentInfo); + try{ + if(failedModuleNames.contains(componentInfo.getApplicationContext().getId())){ + componentManager.unregister(componentInfo); + } + }catch (Exception e) { + throw new RuntimeException(ErrorCode.convert("01-11008", componentInfo.getName(), failedModuleNames.toString()), e); } } } diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java index dcdd849e7..70b53315d 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java @@ -21,6 +21,23 @@ import com.alipay.sofa.isle.deployment.DeploymentException; import com.alipay.sofa.isle.spring.config.SofaModuleProperties; import com.alipay.sofa.isle.stage.SpringContextInstallStage; +import com.alipay.sofa.runtime.SofaFramework; +import com.alipay.sofa.runtime.api.client.ReferenceClient; +import com.alipay.sofa.runtime.api.client.ServiceClient; +import com.alipay.sofa.runtime.client.impl.ClientFactoryImpl; +import com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager; +import com.alipay.sofa.runtime.ext.component.ExtensionPointComponent; +import com.alipay.sofa.runtime.ext.component.ExtensionPointImpl; +import com.alipay.sofa.runtime.service.client.ReferenceClientImpl; +import com.alipay.sofa.runtime.service.client.ServiceClientImpl; +import com.alipay.sofa.runtime.service.impl.BindingAdapterFactoryImpl; +import com.alipay.sofa.runtime.service.impl.BindingConverterFactoryImpl; +import com.alipay.sofa.runtime.spi.binding.BindingAdapter; +import com.alipay.sofa.runtime.spi.binding.BindingAdapterFactory; +import com.alipay.sofa.runtime.spi.client.ClientFactoryInternal; +import com.alipay.sofa.runtime.spi.component.*; +import com.alipay.sofa.runtime.spi.service.BindingConverter; +import com.alipay.sofa.runtime.spi.service.BindingConverterFactory; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,11 +49,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.core.env.Environment; import org.springframework.core.io.Resource; import org.springframework.test.context.junit4.SpringRunner; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author huzijie @@ -58,13 +75,14 @@ public void testQuickFailure() { } catch (Exception e) { Assert.assertTrue(e instanceof DeploymentException); Assert.assertTrue(e.getMessage().contains("01-11007")); - Assert.assertTrue(e.getMessage().contains("testFailModule")); + Assert.assertTrue(e.getMessage().contains("isle-test")); } moduleProperties.setIgnoreModuleInstallFailure(true); try { springContextInstallStage.process(); } catch (Exception e) { - Assert.fail(); + Assert.assertTrue(e.getMessage().contains("01-11008")); + Assert.assertTrue(e.getMessage().contains("testComponent")); } } @@ -72,12 +90,13 @@ public void testQuickFailure() { static class SpringContextInstallConfiguration { @Bean("SOFABOOT-APPLICATION") - public ApplicationRuntimeModel applicationRuntimeModel() { + public ApplicationRuntimeModel applicationRuntimeModel(SofaRuntimeManager sofaRuntimeManager) { ApplicationRuntimeModel model = new ApplicationRuntimeModel(); + model.setSofaRuntimeContext(sofaRuntimeManager.getSofaRuntimeContext()); model.addFailed(new DeploymentDescriptor() { @Override public String getModuleName() { - return "testFailModule"; + return "isle-test"; } @Override @@ -160,6 +179,17 @@ public int compareTo(DeploymentDescriptor o) { return 0; } }); + + Implementation implementation = new DefaultImplementation("test"); + ComponentInfo component = new ExtensionPointComponent(new ExtensionPointImpl( + "testComponent", null), model.getSofaRuntimeContext(), implementation); + ComponentInfo componentWithContext = new ExtensionPointComponent( + new ExtensionPointImpl("testComponentWithContext", null), + model.getSofaRuntimeContext(), implementation); + componentWithContext.setApplicationContext(sofaRuntimeManager + .getRootApplicationContext()); + model.getSofaRuntimeContext().getComponentManager().register(component); + model.getSofaRuntimeContext().getComponentManager().register(componentWithContext); return model; } @@ -180,5 +210,54 @@ public SofaModuleProperties sofaModuleProperties() { public AutowiredAnnotationBeanPostProcessor autowiredAnnotationBeanPostProcessor() { return new AutowiredAnnotationBeanPostProcessor(); } + + @Bean + @ConditionalOnMissingBean + public static BindingConverterFactory bindingConverterFactory() { + BindingConverterFactory bindingConverterFactory = new BindingConverterFactoryImpl(); + bindingConverterFactory + .addBindingConverters(getClassesByServiceLoader(BindingConverter.class)); + return bindingConverterFactory; + } + + @Bean + @ConditionalOnMissingBean + public static BindingAdapterFactory bindingAdapterFactory() { + BindingAdapterFactory bindingAdapterFactory = new BindingAdapterFactoryImpl(); + bindingAdapterFactory + .addBindingAdapters(getClassesByServiceLoader(BindingAdapter.class)); + return bindingAdapterFactory; + } + + @Bean + @ConditionalOnMissingBean + public static SofaRuntimeManager sofaRuntimeManager(Environment environment, + BindingConverterFactory bindingConverterFactory, + BindingAdapterFactory bindingAdapterFactory) { + ClientFactoryInternal clientFactoryInternal = new ClientFactoryImpl(); + SofaRuntimeManager sofaRuntimeManager = new StandardSofaRuntimeManager( + environment.getProperty("spring.application.name"), Thread.currentThread() + .getContextClassLoader(), clientFactoryInternal); + sofaRuntimeManager.getComponentManager().registerComponentClient( + ReferenceClient.class, + new ReferenceClientImpl(sofaRuntimeManager.getSofaRuntimeContext(), + bindingConverterFactory, bindingAdapterFactory)); + sofaRuntimeManager.getComponentManager().registerComponentClient( + ServiceClient.class, + new ServiceClientImpl(sofaRuntimeManager.getSofaRuntimeContext(), + bindingConverterFactory, bindingAdapterFactory)); + SofaFramework.registerSofaRuntimeManager(sofaRuntimeManager); + return sofaRuntimeManager; + } + + public static Set getClassesByServiceLoader(Class clazz) { + ServiceLoader serviceLoader = ServiceLoader.load(clazz); + + Set result = new HashSet<>(); + for (T t : serviceLoader) { + result.add(t); + } + return result; + } } } \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot/src/main/resources/sofa-boot/log-codes.properties b/sofa-boot-project/sofa-boot/src/main/resources/sofa-boot/log-codes.properties index f6744ac73..d6ed88719 100644 --- a/sofa-boot-project/sofa-boot/src/main/resources/sofa-boot/log-codes.properties +++ b/sofa-boot-project/sofa-boot/src/main/resources/sofa-boot/log-codes.properties @@ -59,6 +59,7 @@ 01-11005=Error occurred when get Spring Application Context refresh future 01-11006=Cannot register module deployment for module name '[%s]': replacing '[%s]' with '[%s]' 01-11007=Some module context(s) %s failed to refresh, please see /logs/sofa-runtime/common-error.log for further information, you could set 'com.alipay.sofa.boot.ignoreModuleInstallFailure=true' to ignore it +01-11008=Error occurred when unregister component [%s] of failure modules %s ##Module dependency error 01-12000=Modules that could not install(Mainly due to module dependency not satisfied) From 4518cce3d8f08b9938ba622cacbe742a51f0bb55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Thu, 8 Sep 2022 10:39:12 +0800 Subject: [PATCH 07/14] Add test case for removing the components when module install failure --- .../alipay/sofa/isle/stage/SpringContextInstallStage.java | 7 ++++--- .../sofa/isle/test/SpringContextInstallStageTest.java | 3 +-- .../src/main/resources/sofa-boot/log-codes.properties | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index 8ddae72ff..9eed0e81f 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -27,6 +27,7 @@ import com.alipay.sofa.isle.loader.DynamicSpringContextLoader; import com.alipay.sofa.isle.loader.SpringContextLoader; import com.alipay.sofa.isle.spring.config.SofaModuleProperties; +import com.alipay.sofa.runtime.api.ServiceRuntimeException; import com.alipay.sofa.runtime.api.component.ComponentName; import com.alipay.sofa.runtime.log.SofaLogger; import com.alipay.sofa.runtime.spi.component.ComponentInfo; @@ -94,14 +95,14 @@ protected void doProcess() throws Exception { // remove component when module install failure if(sofaModuleProperties.isUnregisterComponentWhenModuleInstallFailure()){ ComponentManager componentManager = application.getSofaRuntimeContext().getComponentManager(); - Collection componentInfos = componentManager.getComponents(); + Collection componentInfos = componentManager.getComponents().stream().filter(c -> c.getApplicationContext()!=null).collect(Collectors.toList()); for(ComponentInfo componentInfo : componentInfos) { try{ if(failedModuleNames.contains(componentInfo.getApplicationContext().getId())){ componentManager.unregister(componentInfo); } - }catch (Exception e) { - throw new RuntimeException(ErrorCode.convert("01-11008", componentInfo.getName(), failedModuleNames.toString()), e); + }catch (ServiceRuntimeException e) { + SofaLogger.error(ErrorCode.convert("01-03001", componentInfo.getName()), e); } } } diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java index 70b53315d..263646822 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java @@ -81,8 +81,7 @@ public void testQuickFailure() { try { springContextInstallStage.process(); } catch (Exception e) { - Assert.assertTrue(e.getMessage().contains("01-11008")); - Assert.assertTrue(e.getMessage().contains("testComponent")); + Assert.fail(); } } diff --git a/sofa-boot-project/sofa-boot/src/main/resources/sofa-boot/log-codes.properties b/sofa-boot-project/sofa-boot/src/main/resources/sofa-boot/log-codes.properties index d6ed88719..f6744ac73 100644 --- a/sofa-boot-project/sofa-boot/src/main/resources/sofa-boot/log-codes.properties +++ b/sofa-boot-project/sofa-boot/src/main/resources/sofa-boot/log-codes.properties @@ -59,7 +59,6 @@ 01-11005=Error occurred when get Spring Application Context refresh future 01-11006=Cannot register module deployment for module name '[%s]': replacing '[%s]' with '[%s]' 01-11007=Some module context(s) %s failed to refresh, please see /logs/sofa-runtime/common-error.log for further information, you could set 'com.alipay.sofa.boot.ignoreModuleInstallFailure=true' to ignore it -01-11008=Error occurred when unregister component [%s] of failure modules %s ##Module dependency error 01-12000=Modules that could not install(Mainly due to module dependency not satisfied) From dd8a793882ee67b131ff0b5ef47304f8b54359d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Thu, 8 Sep 2022 15:22:09 +0800 Subject: [PATCH 08/14] Add test case for removing the components when module install failure --- .../sofa/isle/stage/SpringContextInstallStage.java | 10 +++++----- .../isle/test/SpringContextInstallStageTest.java | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index 9eed0e81f..f7dcd0978 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -95,14 +95,14 @@ protected void doProcess() throws Exception { // remove component when module install failure if(sofaModuleProperties.isUnregisterComponentWhenModuleInstallFailure()){ ComponentManager componentManager = application.getSofaRuntimeContext().getComponentManager(); - Collection componentInfos = componentManager.getComponents().stream().filter(c -> c.getApplicationContext()!=null).collect(Collectors.toList()); + Collection componentInfos = componentManager.getComponents(); for(ComponentInfo componentInfo : componentInfos) { - try{ - if(failedModuleNames.contains(componentInfo.getApplicationContext().getId())){ + if(componentInfo.getApplicationContext() != null && failedModuleNames.contains(componentInfo.getApplicationContext().getId())){ + try{ componentManager.unregister(componentInfo); + }catch (ServiceRuntimeException e) { + SofaLogger.error(ErrorCode.convert("01-03001", componentInfo.getName()), e); } - }catch (ServiceRuntimeException e) { - SofaLogger.error(ErrorCode.convert("01-03001", componentInfo.getName()), e); } } } diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java index 263646822..36da1ac7f 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java @@ -28,6 +28,7 @@ import com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager; import com.alipay.sofa.runtime.ext.component.ExtensionPointComponent; import com.alipay.sofa.runtime.ext.component.ExtensionPointImpl; +import com.alipay.sofa.runtime.model.ComponentStatus; import com.alipay.sofa.runtime.service.client.ReferenceClientImpl; import com.alipay.sofa.runtime.service.client.ServiceClientImpl; import com.alipay.sofa.runtime.service.impl.BindingAdapterFactoryImpl; @@ -67,6 +68,9 @@ public class SpringContextInstallStageTest { @Autowired private SofaModuleProperties moduleProperties; + private static ComponentInfo component; + private static ComponentInfo componentWithContext; + @Test public void testQuickFailure() { try { @@ -80,6 +84,8 @@ public void testQuickFailure() { moduleProperties.setIgnoreModuleInstallFailure(true); try { springContextInstallStage.process(); + Assert.assertEquals(component.getState(), ComponentStatus.ACTIVATED); + Assert.assertEquals(componentWithContext.getState(), ComponentStatus.UNREGISTERED); } catch (Exception e) { Assert.fail(); } @@ -180,11 +186,10 @@ public int compareTo(DeploymentDescriptor o) { }); Implementation implementation = new DefaultImplementation("test"); - ComponentInfo component = new ExtensionPointComponent(new ExtensionPointImpl( - "testComponent", null), model.getSofaRuntimeContext(), implementation); - ComponentInfo componentWithContext = new ExtensionPointComponent( - new ExtensionPointImpl("testComponentWithContext", null), + component = new ExtensionPointComponent(new ExtensionPointImpl("testComponent", null), model.getSofaRuntimeContext(), implementation); + componentWithContext = new ExtensionPointComponent(new ExtensionPointImpl( + "testComponentWithContext", null), model.getSofaRuntimeContext(), implementation); componentWithContext.setApplicationContext(sofaRuntimeManager .getRootApplicationContext()); model.getSofaRuntimeContext().getComponentManager().register(component); From b0b003536cc21ec8479446f0461b2ac84eef99f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Tue, 13 Sep 2022 16:31:03 +0800 Subject: [PATCH 09/14] Add a function that can remove the corresponding components when module install failure --- .../isle/stage/SpringContextInstallStage.java | 45 +++++---- .../test/SpringContextInstallStageTest.java | 93 +------------------ .../component/impl/ComponentManagerImpl.java | 20 +++- .../spi/component/ComponentManager.java | 9 ++ 4 files changed, 51 insertions(+), 116 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index f7dcd0978..957c1c8d0 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -44,12 +44,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Future; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.stream.Collectors; /** @@ -87,25 +82,11 @@ protected void doProcess() throws Exception { throw new DeploymentException(ErrorCode.convert("01-11000"), t); } - if (!application.getFailed().isEmpty()) { - List failedModuleNames = application.getFailed().stream().map(DeploymentDescriptor::getModuleName).collect(Collectors.toList()); - if(!sofaModuleProperties.isIgnoreModuleInstallFailure()) { + if (!sofaModuleProperties.isIgnoreModuleInstallFailure()) { + if (!application.getFailed().isEmpty()) { + List failedModuleNames = application.getFailed().stream().map(DeploymentDescriptor::getModuleName).collect(Collectors.toList()); throw new DeploymentException(ErrorCode.convert("01-11007", failedModuleNames)); } - // remove component when module install failure - if(sofaModuleProperties.isUnregisterComponentWhenModuleInstallFailure()){ - ComponentManager componentManager = application.getSofaRuntimeContext().getComponentManager(); - Collection componentInfos = componentManager.getComponents(); - for(ComponentInfo componentInfo : componentInfos) { - if(componentInfo.getApplicationContext() != null && failedModuleNames.contains(componentInfo.getApplicationContext().getId())){ - try{ - componentManager.unregister(componentInfo); - }catch (ServiceRuntimeException e) { - SofaLogger.error(ErrorCode.convert("01-03001", componentInfo.getName()), e); - } - } - } - } } } @@ -346,6 +327,7 @@ protected void doRefreshSpringContext(DeploymentDescriptor deployment, } catch (Throwable t) { SofaLogger.error(ErrorCode.convert("01-11002", deployment.getName()), t); application.addFailed(deployment); + unRegisterComponent(application, ctx); } finally { deployment.deployFinish(); } @@ -356,6 +338,23 @@ protected void doRefreshSpringContext(DeploymentDescriptor deployment, } } + private void unRegisterComponent(ApplicationRuntimeModel application, + ConfigurableApplicationContext ctx) { + if (sofaModuleProperties.isUnregisterComponentWhenModuleInstallFailure()) { + ComponentManager componentManager = application.getSofaRuntimeContext() + .getComponentManager(); + Collection componentInfos = componentManager + .getComponentByApplication(ctx); + for (ComponentInfo componentInfo : componentInfos) { + try { + componentManager.unregister(componentInfo); + } catch (ServiceRuntimeException e) { + SofaLogger.error(ErrorCode.convert("01-03001", componentInfo.getName()), e); + } + } + } + } + private void publishContextAsSofaComponent(DeploymentDescriptor deployment, ApplicationRuntimeModel application, ApplicationContext context) { diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java index 36da1ac7f..dcdd849e7 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/test/java/com/alipay/sofa/isle/test/SpringContextInstallStageTest.java @@ -21,24 +21,6 @@ import com.alipay.sofa.isle.deployment.DeploymentException; import com.alipay.sofa.isle.spring.config.SofaModuleProperties; import com.alipay.sofa.isle.stage.SpringContextInstallStage; -import com.alipay.sofa.runtime.SofaFramework; -import com.alipay.sofa.runtime.api.client.ReferenceClient; -import com.alipay.sofa.runtime.api.client.ServiceClient; -import com.alipay.sofa.runtime.client.impl.ClientFactoryImpl; -import com.alipay.sofa.runtime.component.impl.StandardSofaRuntimeManager; -import com.alipay.sofa.runtime.ext.component.ExtensionPointComponent; -import com.alipay.sofa.runtime.ext.component.ExtensionPointImpl; -import com.alipay.sofa.runtime.model.ComponentStatus; -import com.alipay.sofa.runtime.service.client.ReferenceClientImpl; -import com.alipay.sofa.runtime.service.client.ServiceClientImpl; -import com.alipay.sofa.runtime.service.impl.BindingAdapterFactoryImpl; -import com.alipay.sofa.runtime.service.impl.BindingConverterFactoryImpl; -import com.alipay.sofa.runtime.spi.binding.BindingAdapter; -import com.alipay.sofa.runtime.spi.binding.BindingAdapterFactory; -import com.alipay.sofa.runtime.spi.client.ClientFactoryInternal; -import com.alipay.sofa.runtime.spi.component.*; -import com.alipay.sofa.runtime.spi.service.BindingConverter; -import com.alipay.sofa.runtime.spi.service.BindingConverterFactory; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,11 +32,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.core.env.Environment; import org.springframework.core.io.Resource; import org.springframework.test.context.junit4.SpringRunner; -import java.util.*; +import java.util.List; +import java.util.Map; /** * @author huzijie @@ -68,9 +50,6 @@ public class SpringContextInstallStageTest { @Autowired private SofaModuleProperties moduleProperties; - private static ComponentInfo component; - private static ComponentInfo componentWithContext; - @Test public void testQuickFailure() { try { @@ -79,13 +58,11 @@ public void testQuickFailure() { } catch (Exception e) { Assert.assertTrue(e instanceof DeploymentException); Assert.assertTrue(e.getMessage().contains("01-11007")); - Assert.assertTrue(e.getMessage().contains("isle-test")); + Assert.assertTrue(e.getMessage().contains("testFailModule")); } moduleProperties.setIgnoreModuleInstallFailure(true); try { springContextInstallStage.process(); - Assert.assertEquals(component.getState(), ComponentStatus.ACTIVATED); - Assert.assertEquals(componentWithContext.getState(), ComponentStatus.UNREGISTERED); } catch (Exception e) { Assert.fail(); } @@ -95,13 +72,12 @@ public void testQuickFailure() { static class SpringContextInstallConfiguration { @Bean("SOFABOOT-APPLICATION") - public ApplicationRuntimeModel applicationRuntimeModel(SofaRuntimeManager sofaRuntimeManager) { + public ApplicationRuntimeModel applicationRuntimeModel() { ApplicationRuntimeModel model = new ApplicationRuntimeModel(); - model.setSofaRuntimeContext(sofaRuntimeManager.getSofaRuntimeContext()); model.addFailed(new DeploymentDescriptor() { @Override public String getModuleName() { - return "isle-test"; + return "testFailModule"; } @Override @@ -184,16 +160,6 @@ public int compareTo(DeploymentDescriptor o) { return 0; } }); - - Implementation implementation = new DefaultImplementation("test"); - component = new ExtensionPointComponent(new ExtensionPointImpl("testComponent", null), - model.getSofaRuntimeContext(), implementation); - componentWithContext = new ExtensionPointComponent(new ExtensionPointImpl( - "testComponentWithContext", null), model.getSofaRuntimeContext(), implementation); - componentWithContext.setApplicationContext(sofaRuntimeManager - .getRootApplicationContext()); - model.getSofaRuntimeContext().getComponentManager().register(component); - model.getSofaRuntimeContext().getComponentManager().register(componentWithContext); return model; } @@ -214,54 +180,5 @@ public SofaModuleProperties sofaModuleProperties() { public AutowiredAnnotationBeanPostProcessor autowiredAnnotationBeanPostProcessor() { return new AutowiredAnnotationBeanPostProcessor(); } - - @Bean - @ConditionalOnMissingBean - public static BindingConverterFactory bindingConverterFactory() { - BindingConverterFactory bindingConverterFactory = new BindingConverterFactoryImpl(); - bindingConverterFactory - .addBindingConverters(getClassesByServiceLoader(BindingConverter.class)); - return bindingConverterFactory; - } - - @Bean - @ConditionalOnMissingBean - public static BindingAdapterFactory bindingAdapterFactory() { - BindingAdapterFactory bindingAdapterFactory = new BindingAdapterFactoryImpl(); - bindingAdapterFactory - .addBindingAdapters(getClassesByServiceLoader(BindingAdapter.class)); - return bindingAdapterFactory; - } - - @Bean - @ConditionalOnMissingBean - public static SofaRuntimeManager sofaRuntimeManager(Environment environment, - BindingConverterFactory bindingConverterFactory, - BindingAdapterFactory bindingAdapterFactory) { - ClientFactoryInternal clientFactoryInternal = new ClientFactoryImpl(); - SofaRuntimeManager sofaRuntimeManager = new StandardSofaRuntimeManager( - environment.getProperty("spring.application.name"), Thread.currentThread() - .getContextClassLoader(), clientFactoryInternal); - sofaRuntimeManager.getComponentManager().registerComponentClient( - ReferenceClient.class, - new ReferenceClientImpl(sofaRuntimeManager.getSofaRuntimeContext(), - bindingConverterFactory, bindingAdapterFactory)); - sofaRuntimeManager.getComponentManager().registerComponentClient( - ServiceClient.class, - new ServiceClientImpl(sofaRuntimeManager.getSofaRuntimeContext(), - bindingConverterFactory, bindingAdapterFactory)); - SofaFramework.registerSofaRuntimeManager(sofaRuntimeManager); - return sofaRuntimeManager; - } - - public static Set getClassesByServiceLoader(Class clazz) { - ServiceLoader serviceLoader = ServiceLoader.load(clazz); - - Set result = new HashSet<>(); - for (T t : serviceLoader) { - result.add(t); - } - return result; - } } } \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java index b411c4d4a..a36708668 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java @@ -27,12 +27,9 @@ import com.alipay.sofa.runtime.spi.component.ComponentInfo; import com.alipay.sofa.runtime.spi.component.ComponentManager; import com.alipay.sofa.runtime.spring.SpringContextComponent; +import org.springframework.context.ApplicationContext; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; @@ -242,6 +239,19 @@ public void resolvePendingResolveComponent(ComponentName componentName) { } } + @Override + public Collection getComponentByApplication(ApplicationContext application) { + List componentInfos = new ArrayList<>(); + + for (ComponentInfo componentInfo : registry.values()) { + if (Objects.equals(application, componentInfo.getApplicationContext())) { + componentInfos.add(componentInfo); + } + } + + return componentInfos; + } + private void typeRegistry(ComponentInfo componentInfo) { ComponentName name = componentInfo.getName(); if (name != null) { diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java index 96fdd8cf4..36ef5a958 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java @@ -19,6 +19,7 @@ import com.alipay.sofa.runtime.api.ServiceRuntimeException; import com.alipay.sofa.runtime.api.component.ComponentName; import com.alipay.sofa.runtime.model.ComponentType; +import org.springframework.context.ApplicationContext; import java.util.Collection; @@ -113,4 +114,12 @@ public interface ComponentManager { * @param componentName component name */ void resolvePendingResolveComponent(ComponentName componentName); + + /** + * get components by component application + * + * @param application component application + * @return components + */ + Collection getComponentByApplication(ApplicationContext application); } From 8d7acd1d9a362a444f939a4f460b8709b73064f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Tue, 13 Sep 2022 20:42:56 +0800 Subject: [PATCH 10/14] Add a function that can remove the corresponding components when module install failure --- .../com/alipay/sofa/isle/stage/SpringContextInstallStage.java | 2 +- .../sofa/runtime/component/impl/ComponentManagerImpl.java | 2 +- .../com/alipay/sofa/runtime/spi/component/ComponentManager.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index 957c1c8d0..133087cc9 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -344,7 +344,7 @@ private void unRegisterComponent(ApplicationRuntimeModel application, ComponentManager componentManager = application.getSofaRuntimeContext() .getComponentManager(); Collection componentInfos = componentManager - .getComponentByApplication(ctx); + .getComponentInfosByApplication(ctx); for (ComponentInfo componentInfo : componentInfos) { try { componentManager.unregister(componentInfo); diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java index a36708668..13755609f 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java @@ -240,7 +240,7 @@ public void resolvePendingResolveComponent(ComponentName componentName) { } @Override - public Collection getComponentByApplication(ApplicationContext application) { + public Collection getComponentInfosByApplication(ApplicationContext application) { List componentInfos = new ArrayList<>(); for (ComponentInfo componentInfo : registry.values()) { diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java index 36ef5a958..1290b8f16 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java @@ -121,5 +121,5 @@ public interface ComponentManager { * @param application component application * @return components */ - Collection getComponentByApplication(ApplicationContext application); + Collection getComponentInfosByApplication(ApplicationContext application); } From f09d825ff3cc612acc2209821310b0e9367fea45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Wed, 14 Sep 2022 10:53:02 +0800 Subject: [PATCH 11/14] Add a function that can remove the corresponding components when module install failure --- .../com/alipay/sofa/isle/stage/SpringContextInstallStage.java | 2 +- .../sofa/runtime/component/impl/ComponentManagerImpl.java | 2 +- .../com/alipay/sofa/runtime/spi/component/ComponentManager.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java index 133087cc9..7e0fddd66 100644 --- a/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java +++ b/sofa-boot-project/sofa-boot-core/isle-sofa-boot/src/main/java/com/alipay/sofa/isle/stage/SpringContextInstallStage.java @@ -344,7 +344,7 @@ private void unRegisterComponent(ApplicationRuntimeModel application, ComponentManager componentManager = application.getSofaRuntimeContext() .getComponentManager(); Collection componentInfos = componentManager - .getComponentInfosByApplication(ctx); + .getComponentInfosByApplicationContext(ctx); for (ComponentInfo componentInfo : componentInfos) { try { componentManager.unregister(componentInfo); diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java index 13755609f..7ad877531 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java @@ -240,7 +240,7 @@ public void resolvePendingResolveComponent(ComponentName componentName) { } @Override - public Collection getComponentInfosByApplication(ApplicationContext application) { + public Collection getComponentInfosByApplicationContext(ApplicationContext application) { List componentInfos = new ArrayList<>(); for (ComponentInfo componentInfo : registry.values()) { diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java index 1290b8f16..e5375f8f6 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/component/ComponentManager.java @@ -121,5 +121,5 @@ public interface ComponentManager { * @param application component application * @return components */ - Collection getComponentInfosByApplication(ApplicationContext application); + Collection getComponentInfosByApplicationContext(ApplicationContext application); } From 332679e9be19f001335219f1d7d8458eb4169d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Wed, 8 Feb 2023 17:31:27 +0800 Subject: [PATCH 12/14] update Spring Boot version from 2.7.3 to 2.7.8 --- pom.xml | 4 ++-- .../sofa-boot-starters/tracer-sofa-boot-starter/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 5ec70956e..0ade1a700 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ org.springframework.boot spring-boot-starter-parent - 2.7.3 + 2.7.8 @@ -37,7 +37,7 @@ SOFABoot Build - 3.16.2 + 3.17.0-SNAPSHOT ${revision} 1.6.7 diff --git a/sofa-boot-project/sofa-boot-starters/tracer-sofa-boot-starter/pom.xml b/sofa-boot-project/sofa-boot-starters/tracer-sofa-boot-starter/pom.xml index 23529c5cd..781538c41 100644 --- a/sofa-boot-project/sofa-boot-starters/tracer-sofa-boot-starter/pom.xml +++ b/sofa-boot-project/sofa-boot-starters/tracer-sofa-boot-starter/pom.xml @@ -92,8 +92,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j test From 07e45150501d35431898cba8eff76ca079384804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Thu, 9 Feb 2023 10:41:38 +0800 Subject: [PATCH 13/14] update Spring Boot version from 2.7.3 to 2.7.8 --- .../sofa-boot-starters/tracer-sofa-boot-starter/pom.xml | 4 ++-- sofa-boot-project/sofaboot-dependencies/pom.xml | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sofa-boot-project/sofa-boot-starters/tracer-sofa-boot-starter/pom.xml b/sofa-boot-project/sofa-boot-starters/tracer-sofa-boot-starter/pom.xml index 781538c41..23529c5cd 100644 --- a/sofa-boot-project/sofa-boot-starters/tracer-sofa-boot-starter/pom.xml +++ b/sofa-boot-project/sofa-boot-starters/tracer-sofa-boot-starter/pom.xml @@ -92,8 +92,8 @@ - com.mysql - mysql-connector-j + mysql + mysql-connector-java test diff --git a/sofa-boot-project/sofaboot-dependencies/pom.xml b/sofa-boot-project/sofaboot-dependencies/pom.xml index 627448c21..6d42a474e 100644 --- a/sofa-boot-project/sofaboot-dependencies/pom.xml +++ b/sofa-boot-project/sofaboot-dependencies/pom.xml @@ -45,6 +45,7 @@ 2.7.7 2.9.10 1.0.2.Final + 5.1.40 3.6.3.Final 4.0.1 @@ -575,6 +576,11 @@ swagger-jaxrs2 ${swagger.version} + + mysql + mysql-connector-java + ${mysql.version} + From 775534a72ffac06087caaf3f4e6fec8fc9837e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Thu, 9 Feb 2023 10:51:43 +0800 Subject: [PATCH 14/14] update Spring Boot version from 2.7.3 to 2.7.8 --- sofa-boot-project/sofaboot-dependencies/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/sofa-boot-project/sofaboot-dependencies/pom.xml b/sofa-boot-project/sofaboot-dependencies/pom.xml index 6d42a474e..ca491bc96 100644 --- a/sofa-boot-project/sofaboot-dependencies/pom.xml +++ b/sofa-boot-project/sofaboot-dependencies/pom.xml @@ -45,7 +45,6 @@ 2.7.7 2.9.10 1.0.2.Final - 5.1.40 3.6.3.Final 4.0.1