Search in sources :

Example 1 with DefaultModuleDeploymentValidator

use of com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator 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)

Example 2 with DefaultModuleDeploymentValidator

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

the class BeanHierarchyTest method test.

@Test
public void test() throws Exception {
    ApplicationRuntimeModel application = new ApplicationRuntimeModel();
    application.setAppName(this.getClass().getName());
    application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
    DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
    Properties props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.module");
    File moduleDirectory = new File("target/test-classes/module/sofa-module.properties");
    DeploymentDescriptor dd = DeploymentBuilder.build(moduleDirectory.toURI().toURL(), props, deploymentDescriptorConfiguration, this.getClass().getClassLoader());
    Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
    Assert.assertTrue(application.isModuleDeployment(dd));
    application.addDeployment(dd);
    refreshApplication(application);
    BeanFactory beanFactory = ((ConfigurableApplicationContext) dd.getApplicationContext()).getBeanFactory();
    for (BeanStat bn : ((BeanLoadCostBeanFactory) beanFactory).getBeanStats()) {
        if (bn.getBeanClassName().contains("testService")) {
            Assert.assertEquals(3, bn.getChildren().size());
            for (BeanStat cbn : bn.getChildren()) {
                if (cbn.getChildren().size() > 1) {
                    Assert.assertEquals(3, cbn.getChildren().size());
                }
            }
        }
    }
    ApplicationContext applicationContext = application.getResolvedDeployments().get(0).getApplicationContext();
    String moduleName = applicationContext.getId();
    Assert.assertEquals("com.alipay.module", moduleName);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) DeploymentDescriptorConfiguration(com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration) FileDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Properties(java.util.Properties) FileDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BeanLoadCostBeanFactory(com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) BeanLoadCostBeanFactory(com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory) BeanStat(com.alipay.sofa.boot.startup.BeanStat) DefaultModuleDeploymentValidator(com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator) File(java.io.File) Test(org.junit.Test)

Example 3 with DefaultModuleDeploymentValidator

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

the class ModelCreatingStage method doProcess.

@Override
protected void doProcess() throws Exception {
    ApplicationRuntimeModel application = new ApplicationRuntimeModel();
    application.setAppName(appName);
    SofaRuntimeManager sofaRuntimeManager = applicationContext.getBean(SofaRuntimeManager.class);
    application.setSofaRuntimeContext(sofaRuntimeManager.getSofaRuntimeContext());
    application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
    getAllDeployments(application);
    applicationContext.getBeanFactory().registerSingleton(SofaBootConstants.APPLICATION, application);
}
Also used : DefaultModuleDeploymentValidator(com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator) SofaRuntimeManager(com.alipay.sofa.runtime.spi.component.SofaRuntimeManager) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel)

Example 4 with DefaultModuleDeploymentValidator

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

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)

Example 5 with DefaultModuleDeploymentValidator

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

the class BeanHierarchyTest method test.

@Test
public void test() throws Exception {
    ApplicationRuntimeModel application = new ApplicationRuntimeModel();
    application.setAppName(this.getClass().getName());
    application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
    DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
    Properties props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.module");
    File moduleDirectory = new File("target/test-classes/module/sofa-module.properties");
    DeploymentDescriptor dd = DeploymentBuilder.build(moduleDirectory.toURI().toURL(), props, deploymentDescriptorConfiguration, this.getClass().getClassLoader());
    Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
    Assert.assertTrue(application.isModuleDeployment(dd));
    application.addDeployment(dd);
    refreshApplication(application);
    BeanFactory beanFactory = ((ConfigurableApplicationContext) dd.getApplicationContext()).getBeanFactory();
    for (BeanStat bn : ((BeanLoadCostBeanFactory) beanFactory).getBeanStats()) {
        if (bn.getBeanClassName().contains("testService")) {
            Assert.assertEquals(3, bn.getChildren().size());
            for (BeanStat cbn : bn.getChildren()) {
                if (cbn.getChildren().size() > 1) {
                    Assert.assertEquals(3, cbn.getChildren().size());
                }
            }
        }
    }
    ApplicationContext applicationContext = application.getResolvedDeployments().get(0).getApplicationContext();
    String moduleName = applicationContext.getId();
    Assert.assertEquals("com.alipay.module", moduleName);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) DeploymentDescriptorConfiguration(com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration) FileDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Properties(java.util.Properties) FileDeploymentDescriptor(com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BeanLoadCostBeanFactory(com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) BeanLoadCostBeanFactory(com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory) BeanStat(com.alipay.sofa.boot.startup.BeanStat) DefaultModuleDeploymentValidator(com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator) File(java.io.File) Test(org.junit.Test)

Aggregations

ApplicationRuntimeModel (com.alipay.sofa.isle.ApplicationRuntimeModel)8 DefaultModuleDeploymentValidator (com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator)8 DeploymentDescriptorConfiguration (com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration)6 Properties (java.util.Properties)6 Test (org.junit.Test)6 DeploymentDescriptor (com.alipay.sofa.isle.deployment.DeploymentDescriptor)4 FileDeploymentDescriptor (com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor)4 SofaModuleProperties (com.alipay.sofa.isle.spring.config.SofaModuleProperties)4 URL (java.net.URL)4 BeanStat (com.alipay.sofa.boot.startup.BeanStat)2 JarDeploymentDescriptor (com.alipay.sofa.isle.deployment.impl.JarDeploymentDescriptor)2 BeanLoadCostBeanFactory (com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory)2 SpringContextInstallStage (com.alipay.sofa.isle.stage.SpringContextInstallStage)2 SofaRuntimeManager (com.alipay.sofa.runtime.spi.component.SofaRuntimeManager)2 File (java.io.File)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)2