Search in sources :

Example 36 with DeploymentDescriptor

use of com.alipay.sofa.isle.deployment.DeploymentDescriptor in project sofa-boot by sofastack.

the class BeanHierarchyTest method refreshApplication.

private void refreshApplication(ApplicationRuntimeModel application) throws Exception {
    DefaultListableBeanFactory rootBeanFactory = new DefaultListableBeanFactory();
    ConfigurableApplicationContext rootApplicationContext = new GenericApplicationContext(rootBeanFactory);
    rootApplicationContext.refresh();
    SofaModuleProperties sofaModuleProperties = new SofaModuleProperties();
    sofaModuleProperties.setBeanLoadCost(1);
    rootBeanFactory.registerSingleton("sofaModuleProperties", sofaModuleProperties);
    rootBeanFactory.registerSingleton(SofaBootConstants.PROCESSORS_OF_ROOT_APPLICATION_CONTEXT, new HashMap<>());
    SpringContextLoader springContextLoader = new DynamicSpringContextLoader(rootApplicationContext);
    for (DeploymentDescriptor dd : application.getResolvedDeployments()) {
        if (dd.isSpringPowered()) {
            springContextLoader.loadSpringContext(dd, application);
            ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) dd.getApplicationContext();
            dd.startDeploy();
            ctx.refresh();
            dd.deployFinish();
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringContextLoader(com.alipay.sofa.isle.loader.SpringContextLoader) DynamicSpringContextLoader(com.alipay.sofa.isle.loader.DynamicSpringContextLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) FileDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) DynamicSpringContextLoader(com.alipay.sofa.isle.loader.DynamicSpringContextLoader) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties)

Example 37 with DeploymentDescriptor

use of com.alipay.sofa.isle.deployment.DeploymentDescriptor in project sofa-boot by sofastack.

the class FileDeploymentDescriptorWhiteSpacePathTest method test.

@Test
public void test() throws Exception {
    ClassLoader classLoader = this.getClass().getClassLoader();
    Enumeration<URL> urls = classLoader.getResources("white space/" + SofaBootConstants.SOFA_MODULE_FILE);
    while (urls != null && urls.hasMoreElements()) {
        URL url = urls.nextElement();
        DeploymentDescriptor dd = DeploymentBuilder.build(url, null, null, classLoader);
        Assert.assertTrue(dd.isSpringPowered());
    }
}
Also used : DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) URL(java.net.URL) Test(org.junit.Test)

Example 38 with DeploymentDescriptor

use of com.alipay.sofa.isle.deployment.DeploymentDescriptor in project sofa-boot by sofastack.

the class TestModelCreatingStage method getAllDeployments.

@Override
protected void getAllDeployments(ApplicationRuntimeModel application) throws IOException {
    Enumeration<URL> urls = appClassLoader.getResources("META-INF/" + SofaBootConstants.SOFA_MODULE_FILE);
    if (urls == null || !urls.hasMoreElements()) {
        return;
    }
    while (urls.hasMoreElements()) {
        URL url = urls.nextElement();
        UrlResource urlResource = new UrlResource(url);
        Properties props = new Properties();
        props.load(urlResource.getInputStream());
        DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
        DeploymentDescriptor dd = DeploymentBuilder.build(url, props, deploymentDescriptorConfiguration, appClassLoader);
        if (application.isModuleDeployment(dd)) {
            if (sofaModuleProfileChecker.acceptModule(dd)) {
                application.addDeployment(dd);
            } else {
                application.addInactiveDeployment(dd);
            }
        }
    }
}
Also used : DeploymentDescriptorConfiguration(com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration) UrlResource(org.springframework.core.io.UrlResource) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) Properties(java.util.Properties) URL(java.net.URL)

Aggregations

DeploymentDescriptor (com.alipay.sofa.isle.deployment.DeploymentDescriptor)38 DeploymentDescriptorConfiguration (com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration)12 URL (java.net.URL)12 Properties (java.util.Properties)12 Test (org.junit.Test)12 ApplicationRuntimeModel (com.alipay.sofa.isle.ApplicationRuntimeModel)10 SofaModuleProperties (com.alipay.sofa.isle.spring.config.SofaModuleProperties)8 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)8 FileDeploymentDescriptor (com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 UrlResource (org.springframework.core.io.UrlResource)6 DefaultModuleDeploymentValidator (com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator)4 BeanLoadCostBeanFactory (com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 BeanFactory (org.springframework.beans.factory.BeanFactory)4 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)4 ApplicationContext (org.springframework.context.ApplicationContext)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 BeanStat (com.alipay.sofa.boot.startup.BeanStat)2 NamedThreadFactory (com.alipay.sofa.boot.util.NamedThreadFactory)2