Search in sources :

Example 21 with DeploymentDescriptor

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

the class ModelCreatingStage method getAllDeployments.

protected void getAllDeployments(ApplicationRuntimeModel application) throws IOException, DeploymentException {
    Enumeration<URL> urls = appClassLoader.getResources(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)) {
                validateDuplicateModule(application.addDeployment(dd), 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) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Properties(java.util.Properties) URL(java.net.URL)

Example 22 with DeploymentDescriptor

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

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

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

the class ModuleLogOutputStage method logInstalledModules.

private void logInstalledModules(StringBuilder stringBuilder, List<DeploymentDescriptor> deploys) {
    long totalTime = 0;
    long realStart = 0;
    long realEnd = 0;
    stringBuilder.append("\n").append("Spring context initialize success module list").append("(").append(deploys.size()).append(") >>>>>>>");
    StringBuilder sb = new StringBuilder();
    for (Iterator<DeploymentDescriptor> i = deploys.iterator(); i.hasNext(); ) {
        DeploymentDescriptor dd = i.next();
        String outTreeSymbol = SYMBOLIC1;
        String innerTreeSymbol1 = SYMBOLIC3;
        String innerTreeSymbol2 = SYMBOLIC4;
        if (!i.hasNext()) {
            outTreeSymbol = SYMBOLIC2;
            innerTreeSymbol1 = SYMBOLIC5;
            innerTreeSymbol2 = SYMBOLIC6;
        }
        sb.append(outTreeSymbol).append(dd.getName()).append(" [").append(dd.getElapsedTime()).append(" ms]\n");
        totalTime += dd.getElapsedTime();
        for (Iterator<String> j = dd.getInstalledSpringXml().iterator(); j.hasNext(); ) {
            String xmlPath = j.next();
            String innerTreeSymbol = innerTreeSymbol1;
            if (!j.hasNext()) {
                innerTreeSymbol = innerTreeSymbol2;
            }
            sb.append(innerTreeSymbol).append(xmlPath).append("\n");
        }
        if (realStart == 0 || dd.getStartTime() < realStart) {
            realStart = dd.getStartTime();
        }
        if (realEnd == 0 || (dd.getStartTime() + dd.getElapsedTime()) > realEnd) {
            realEnd = dd.getStartTime() + dd.getElapsedTime();
        }
    }
    stringBuilder.append(" [totalTime = ").append(totalTime).append(" ms, realTime = ").append(realEnd - realStart).append(" ms]\n").append(sb);
}
Also used : DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor)

Example 24 with DeploymentDescriptor

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

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

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

the class SpringContextInstallStage method refreshSpringContextParallel.

private void refreshSpringContextParallel(List<DeploymentDescriptor> rootDeployments, int totalSize, final ApplicationRuntimeModel application, final ThreadPoolExecutor executor) {
    if (rootDeployments == null || rootDeployments.size() == 0) {
        return;
    }
    final CountDownLatch latch = new CountDownLatch(totalSize);
    List<Future> futures = new CopyOnWriteArrayList<>();
    for (final DeploymentDescriptor deployment : rootDeployments) {
        refreshSpringContextParallel(deployment, application, executor, latch, futures);
    }
    try {
        latch.await();
    } catch (InterruptedException e) {
        throw new RuntimeException(ErrorCode.convert("01-11004"), e);
    }
    for (Future future : futures) {
        try {
            future.get();
        } catch (Throwable e) {
            throw new RuntimeException(ErrorCode.convert("01-11005"), e);
        }
    }
}
Also used : DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) Future(java.util.concurrent.Future) CountDownLatch(java.util.concurrent.CountDownLatch) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

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