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");
}
}
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);
}
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);
}
}
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);
}
}
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());
}
Aggregations