Search in sources :

Example 26 with DeploymentDescriptor

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

the class SpringContextInstallStage method installSpringContext.

protected void installSpringContext(ApplicationRuntimeModel application, SpringContextLoader springContextLoader) {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    for (DeploymentDescriptor deployment : application.getResolvedDeployments()) {
        if (deployment.isSpringPowered()) {
            SofaLogger.info("Start install " + application.getAppName() + "'s module: " + deployment.getName());
            try {
                Thread.currentThread().setContextClassLoader(deployment.getClassLoader());
                springContextLoader.loadSpringContext(deployment, application);
            } catch (Throwable t) {
                SofaLogger.error(ErrorCode.convert("01-11001", deployment.getName()), t);
                application.addFailed(deployment);
            } finally {
                Thread.currentThread().setContextClassLoader(oldClassLoader);
            }
        }
    }
}
Also used : DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor)

Example 27 with DeploymentDescriptor

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

the class SpringContextInstallStage method refreshSpringContextParallel.

/**
 * start sofa module parallel
 *
 * @param application
 */
private void refreshSpringContextParallel(ApplicationRuntimeModel application) {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    List<DeploymentDescriptor> coreRoots = new ArrayList<>();
    int coreSize = (int) (CPU_COUNT * sofaModuleProperties.getParallelRefreshCoreCountFactor());
    long taskTimeout = sofaModuleProperties.getParallelRefreshTimeout();
    long period = sofaModuleProperties.getParallelRefreshCheckPeriod();
    ThreadPoolExecutor executor = new SofaThreadPoolExecutor(coreSize, coreSize, 60, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(DEFAULT_REFRESH_TASK_QUEUE_SIZE), new NamedThreadFactory("sofa-module-start"), new ThreadPoolExecutor.CallerRunsPolicy(), "sofa-module-start", SofaBootConstants.SOFABOOT_SPACE_NAME, taskTimeout, period, TimeUnit.SECONDS);
    try {
        for (DeploymentDescriptor deployment : application.getResolvedDeployments()) {
            DependencyTree.Entry entry = application.getDeployRegistry().getEntry(deployment.getModuleName());
            if (entry != null && entry.getDependencies() == null) {
                coreRoots.add(deployment);
            }
        }
        refreshSpringContextParallel(coreRoots, application.getResolvedDeployments().size(), application, executor);
    } finally {
        executor.shutdown();
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
Also used : NamedThreadFactory(com.alipay.sofa.boot.util.NamedThreadFactory) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SofaThreadPoolExecutor(com.alipay.sofa.common.thread.SofaThreadPoolExecutor) DependencyTree(com.alipay.sofa.isle.deployment.DependencyTree) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SofaThreadPoolExecutor(com.alipay.sofa.common.thread.SofaThreadPoolExecutor)

Example 28 with DeploymentDescriptor

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

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 29 with DeploymentDescriptor

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

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)

Example 30 with DeploymentDescriptor

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

the class IsleBeansEndpoint method getModuleApplicationContexts.

private Map<String, ContextBeans> getModuleApplicationContexts(ApplicationRuntimeModel applicationRuntimeModel) {
    Map<String, ContextBeans> contexts = new HashMap<>();
    List<DeploymentDescriptor> installedModules = applicationRuntimeModel.getInstalled();
    installedModules.forEach(descriptor -> {
        ApplicationContext applicationContext = descriptor.getApplicationContext();
        if (applicationContext instanceof ConfigurableApplicationContext) {
            ContextBeans contextBeans = describing((ConfigurableApplicationContext) applicationContext, descriptor.getSpringParent());
            if (contextBeans != null) {
                contexts.put(descriptor.getModuleName(), contextBeans);
            }
        }
    });
    return contexts;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) HashMap(java.util.HashMap) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor)

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