Search in sources :

Example 6 with DeploymentDescriptorConfiguration

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

Example 7 with DeploymentDescriptorConfiguration

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

the class SofaModuleProfileCheckerTest method test.

@Test
public void test() throws Exception {
    // new DeploymentDescriptorConfiguration instance
    DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
    // test dev profile
    Properties props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
    props.setProperty(SofaBootConstants.MODULE_PROFILE, "dev");
    URL fileUrl = new URL("file:/demo/path/isle-module.config");
    DeploymentDescriptor dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertTrue(sofaModuleProfileChecker.acceptModule(dd));
    // test product profile
    props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
    props.setProperty(SofaBootConstants.MODULE_PROFILE, "product");
    fileUrl = new URL("file:/demo/path/isle-module.config");
    dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertTrue(sofaModuleProfileChecker.acceptModule(dd));
    // test !dev profile
    props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
    props.setProperty(SofaBootConstants.MODULE_PROFILE, "!dev");
    fileUrl = new URL("file:/demo/path/isle-module.config");
    dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertFalse(sofaModuleProfileChecker.acceptModule(dd));
    // test test,grey profile
    props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
    props.setProperty(SofaBootConstants.MODULE_PROFILE, "dev,grey");
    fileUrl = new URL("file:/demo/path/isle-module.config");
    dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertTrue(sofaModuleProfileChecker.acceptModule(dd));
    // test test,grey profile
    props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
    props.setProperty(SofaBootConstants.MODULE_PROFILE, "test,grey");
    fileUrl = new URL("file:/demo/path/isle-module.config");
    dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertFalse(sofaModuleProfileChecker.acceptModule(dd));
    // test no profile, default pass
    props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.dal");
    fileUrl = new URL("file:/demo/path/isle-module.config");
    dd = DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader());
    Assert.assertTrue(sofaModuleProfileChecker.acceptModule(dd));
}
Also used : DeploymentDescriptorConfiguration(com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Properties(java.util.Properties) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) URL(java.net.URL) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with DeploymentDescriptorConfiguration

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

the class TestModelCreatingStage method getAllDeployments.

@Override
protected void getAllDeployments(ApplicationRuntimeModel application) throws IOException {
    for (String prefix : modulePrefixes) {
        Enumeration<URL> urls = appClassLoader.getResources(prefix + "/" + SofaBootConstants.SOFA_MODULE_FILE);
        if (urls == null || !urls.hasMoreElements()) {
            continue;
        }
        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 9 with DeploymentDescriptorConfiguration

use of com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration 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 10 with DeploymentDescriptorConfiguration

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

the class DeploymentExceptionTest method test.

@Test(expected = DeploymentException.class)
public void test() throws Exception {
    // create ApplicationRuntimeModel with dependency problem
    ApplicationRuntimeModel application = new ApplicationRuntimeModel();
    application.setAppName("testCase");
    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.test");
    props.setProperty(SofaBootConstants.REQUIRE_MODULE, "com.alipay.dependency");
    URL fileUrl = new URL("file:/demo/path/isle-module.config");
    application.addDeployment(DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader()));
    // mock ApplicationContext
    AbstractApplicationContext applicationContext = mock(AbstractApplicationContext.class);
    when(applicationContext.getBean(SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class)).thenReturn(application);
    ConfigurableEnvironment environment = mock(ConfigurableEnvironment.class);
    when(applicationContext.getEnvironment()).thenReturn(environment);
    when(environment.getProperty(SofaBootConstants.APP_NAME_KEY)).thenReturn("testCase");
    new SpringContextInstallStage(applicationContext, new SofaModuleProperties()).process();
}
Also used : DeploymentDescriptorConfiguration(com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringContextInstallStage(com.alipay.sofa.isle.stage.SpringContextInstallStage) DefaultModuleDeploymentValidator(com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Properties(java.util.Properties) URL(java.net.URL) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Test(org.junit.Test)

Aggregations

DeploymentDescriptorConfiguration (com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration)14 Properties (java.util.Properties)14 DeploymentDescriptor (com.alipay.sofa.isle.deployment.DeploymentDescriptor)12 URL (java.net.URL)12 SofaModuleProperties (com.alipay.sofa.isle.spring.config.SofaModuleProperties)8 Test (org.junit.Test)8 ApplicationRuntimeModel (com.alipay.sofa.isle.ApplicationRuntimeModel)6 DefaultModuleDeploymentValidator (com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator)6 UrlResource (org.springframework.core.io.UrlResource)6 FileDeploymentDescriptor (com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor)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 File (java.io.File)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ApplicationContext (org.springframework.context.ApplicationContext)2