Search in sources :

Example 16 with DeploymentDescriptor

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

the class FailModuleTest method test.

@Test
public void test() {
    ApplicationRuntimeModel applicationRuntimeModel = (ApplicationRuntimeModel) applicationContext.getBean(SofaBootConstants.APPLICATION);
    // contains three Deployments
    Assert.assertEquals(3, applicationRuntimeModel.getAllDeployments().size());
    Assert.assertEquals(2, applicationRuntimeModel.getInstalled().size());
    Assert.assertEquals(1, applicationRuntimeModel.getFailed().size());
    // check module not in installed list
    DeploymentDescriptor failModule = applicationRuntimeModel.getFailed().get(0);
    Assert.assertEquals("com.alipay.sofa.fail", failModule.getModuleName());
    Assert.assertFalse(applicationRuntimeModel.getInstalled().contains(failModule));
}
Also used : DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with DeploymentDescriptor

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

the class FailModuleWithParallelTest method test.

@Test
public void test() {
    ApplicationRuntimeModel applicationRuntimeModel = (ApplicationRuntimeModel) applicationContext.getBean(SofaBootConstants.APPLICATION);
    // contains three Deployments
    Assert.assertEquals(3, applicationRuntimeModel.getAllDeployments().size());
    Assert.assertEquals(2, applicationRuntimeModel.getInstalled().size());
    Assert.assertEquals(1, applicationRuntimeModel.getFailed().size());
    // check module not in installed list
    DeploymentDescriptor failModule = applicationRuntimeModel.getFailed().get(0);
    Assert.assertEquals("com.alipay.sofa.fail", failModule.getModuleName());
    Assert.assertFalse(applicationRuntimeModel.getInstalled().contains(failModule));
}
Also used : DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with DeploymentDescriptor

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

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

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

the class ModuleHealthChecker method isHealthy.

@Override
public Health isHealthy() {
    Health.Builder builder = new Health.Builder();
    ApplicationRuntimeModel application = applicationContext.getBean(SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class);
    for (DeploymentDescriptor deploymentDescriptor : application.getInstalled()) {
        builder.withDetail(deploymentDescriptor.getName(), "passed");
    }
    for (DeploymentDescriptor deploymentDescriptor : application.getAllInactiveDeployments()) {
        builder.withDetail(deploymentDescriptor.getName(), "inactive");
    }
    for (DeploymentDescriptor deploymentDescriptor : application.getFailed()) {
        builder.withDetail(deploymentDescriptor.getName(), "failed");
    }
    if (application.getFailed().size() == 0) {
        return builder.status(Status.UP).build();
    } else {
        return builder.status(Status.DOWN).build();
    }
}
Also used : Health(org.springframework.boot.actuate.health.Health) DeploymentDescriptor(com.alipay.sofa.isle.deployment.DeploymentDescriptor) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel)

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