Search in sources :

Example 11 with ApplicationRuntimeModel

use of com.alipay.sofa.isle.ApplicationRuntimeModel 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 12 with ApplicationRuntimeModel

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

Example 13 with ApplicationRuntimeModel

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

the class IsleBeansEndpoint method beans.

@ReadOperation
@Override
public ApplicationBeans beans() {
    ApplicationBeans applicationBeans = super.beans();
    ApplicationRuntimeModel applicationRuntimeModel = context.getBean(SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class);
    Map<String, ContextBeans> moduleApplicationContexts = getModuleApplicationContexts(applicationRuntimeModel);
    applicationBeans.getContexts().putAll(moduleApplicationContexts);
    return applicationBeans;
}
Also used : ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Example 14 with ApplicationRuntimeModel

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

the class ModuleLogOutputStage method doProcess.

@Override
protected void doProcess() throws Exception {
    ApplicationRuntimeModel application = applicationContext.getBean(SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class);
    StringBuilder stringBuilder = new StringBuilder();
    logInstalledModules(stringBuilder, application.getInstalled());
    logFailedModules(stringBuilder, application.getFailed());
    logInfoBeanCost(stringBuilder, application.getInstalled());
    SofaLogger.info(stringBuilder.toString());
}
Also used : ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel)

Example 15 with ApplicationRuntimeModel

use of com.alipay.sofa.isle.ApplicationRuntimeModel 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

ApplicationRuntimeModel (com.alipay.sofa.isle.ApplicationRuntimeModel)22 Test (org.junit.Test)14 DeploymentDescriptor (com.alipay.sofa.isle.deployment.DeploymentDescriptor)10 DefaultModuleDeploymentValidator (com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator)8 DeploymentDescriptorConfiguration (com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration)6 Properties (java.util.Properties)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 FileDeploymentDescriptor (com.alipay.sofa.isle.deployment.impl.FileDeploymentDescriptor)4 SofaModuleProperties (com.alipay.sofa.isle.spring.config.SofaModuleProperties)4 URL (java.net.URL)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)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 ModelCreatingStage (com.alipay.sofa.isle.stage.ModelCreatingStage)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