Search in sources :

Example 1 with DeploymentDescriptor

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

the class ModuleLogOutputStage method logFailedModules.

private void logFailedModules(StringBuilder stringBuilder, List<DeploymentDescriptor> deploys) {
    stringBuilder.append("\n").append("Spring context initialize failed module list").append("(").append(deploys.size()).append(") >>>>>>>\n");
    for (Iterator<DeploymentDescriptor> i = deploys.iterator(); i.hasNext(); ) {
        DeploymentDescriptor dd = i.next();
        String treeSymbol = SYMBOLIC1;
        if (!i.hasNext()) {
            treeSymbol = SYMBOLIC2;
        }
        stringBuilder.append(treeSymbol).append(dd.getName()).append("\n");
    }
}
Also used : DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor)

Example 2 with DeploymentDescriptor

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

the class ModuleLogOutputStage method logInfoBeanCost.

private void logInfoBeanCost(StringBuilder stringBuilder, List<DeploymentDescriptor> deploys) {
    long totalTime = 0;
    long realStart = 0;
    long realEnd = 0;
    stringBuilder.append("\n").append("Spring bean load time cost list").append("(").append(deploys.size()).append(") >>>>>>>");
    StringBuilder sb = new StringBuilder();
    int size = deploys.size();
    for (int i = 0; i < size; ++i) {
        String prefix = (i == size - 1) ? SYMBOLIC2 : SYMBOLIC1;
        String indexPrefix = (i == size - 1) ? EMPTY_INDEX_PREFIX : INDENT_PREFIX;
        DeploymentDescriptor dd = deploys.get(i);
        BeanFactory beanFactory = ((ConfigurableApplicationContext) dd.getApplicationContext()).getBeanFactory();
        if (realStart == 0 || dd.getStartTime() < realStart) {
            realStart = dd.getStartTime();
        }
        if (realEnd == 0 || (dd.getStartTime() + dd.getElapsedTime()) > realEnd) {
            realEnd = dd.getStartTime() + dd.getElapsedTime();
        }
        totalTime += dd.getElapsedTime();
        if (beanFactory instanceof BeanLoadCostBeanFactory) {
            sb.append(prefix).append("[Module] ").append(dd.getName()).append(" [").append(dd.getElapsedTime()).append(" ms]\n");
            sb.append(((BeanLoadCostBeanFactory) beanFactory).outputBeanStats(indexPrefix));
        }
    }
    stringBuilder.append(" [totalTime = ").append(totalTime).append(" ms, realTime = ").append(realEnd - realStart).append(" ms]\n").append(sb);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) BeanLoadCostBeanFactory(com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) BeanLoadCostBeanFactory(com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory)

Example 3 with DeploymentDescriptor

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

the class SpringContextInstallStage method refreshSpringContext.

/**
 * start sofa module serial
 * @param application
 */
private void refreshSpringContext(ApplicationRuntimeModel application) {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        for (DeploymentDescriptor deployment : application.getResolvedDeployments()) {
            if (deployment.isSpringPowered() && !application.getFailed().contains(deployment)) {
                Thread.currentThread().setContextClassLoader(deployment.getClassLoader());
                doRefreshSpringContext(deployment, application);
            }
            if (!sofaModuleProperties.isIgnoreModuleInstallFailure()) {
                if (!application.getFailed().isEmpty()) {
                    break;
                }
            }
        }
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
Also used : DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor)

Example 4 with DeploymentDescriptor

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

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

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

the class ApplicationRuntimeModelTest method test.

@Test
public void test() throws Exception {
    // new ApplicationRuntimeModel Instance
    ApplicationRuntimeModel application = new ApplicationRuntimeModel();
    application.setAppName("testCase");
    application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
    // new DeploymentDescriptorConfiguration instance
    DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
    // add first SOFAIsle module
    Properties props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.common");
    URL jarUrl = new URL("jar:file:/whatever/path/demo.jar!/isle-module.config");
    DeploymentDescriptor dd = DeploymentBuilder.build(jarUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertTrue(dd instanceof JarDeploymentDescriptor);
    Assert.assertTrue(application.isModuleDeployment(dd));
    application.addDeployment(dd);
    // add second SOFAIsle module
    props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
    props.setProperty(SofaBootConstants.REQUIRE_MODULE, "com.alipay.util");
    URL fileUrl = new URL("file:/demo/path/isle-module.config");
    dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
    Assert.assertTrue(application.isModuleDeployment(dd));
    application.addDeployment(dd);
    // test DeploymentDescriptor which misses Module-Name property
    props = new Properties();
    props.setProperty(SofaBootConstants.REQUIRE_MODULE, "com.alipay.util");
    fileUrl = new URL("file:/demo/path/isle-module.config");
    dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
    Assert.assertFalse(application.isModuleDeployment(dd));
    // missing com.alipay.util module
    Assert.assertEquals(2, application.getDeployRegistry().getPendingEntries().size());
    Assert.assertTrue(Arrays.asList("com.alipay.util", "com.alipay.dal").contains(application.getDeployRegistry().getPendingEntries().get(0).getKey()));
    Assert.assertTrue(Arrays.asList("com.alipay.util", "com.alipay.dal").contains(application.getDeployRegistry().getPendingEntries().get(1).getKey()));
    Assert.assertEquals(null, application.getDeployRegistry().getEntry("com.alipay.util").getWaitsFor());
    Assert.assertEquals("com.alipay.util", application.getDeployRegistry().getEntry("com.alipay.dal").getWaitsFor().iterator().next().getKey());
    // add missing module
    props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.util");
    jarUrl = new URL("jar:file:/demo/path/demo.jar!/isle-module.config");
    dd = DeploymentBuilder.build(jarUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertTrue(dd instanceof JarDeploymentDescriptor);
    Assert.assertTrue(application.isModuleDeployment(dd));
    application.addDeployment(dd);
    Assert.assertEquals(0, application.getDeployRegistry().getPendingEntries().size());
}
Also used : DeploymentDescriptorConfiguration(com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration) FileDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor) JarDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.JarDeploymentDescriptor) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) DefaultModuleDeploymentValidator(com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator) Properties(java.util.Properties) JarDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.JarDeploymentDescriptor) FileDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor) URL(java.net.URL) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel) Test(org.junit.Test)

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