Search in sources :

Example 1 with ServerInstanceContext

use of com.kixeye.chassis.bootstrap.aws.ServerInstanceContext in project chassis by Kixeye.

the class ConfigurationBuilderTest method buildConfigurationInAws.

@Test
public void buildConfigurationInAws() {
    String az = "testaz";
    String instanceId = RandomStringUtils.randomAlphabetic(10);
    String region = Regions.DEFAULT_REGION.getName();
    ServerInstanceContext serverInstanceContext = EasyMock.createMock(ServerInstanceContext.class);
    EasyMock.expect(serverInstanceContext.getAvailabilityZone()).andReturn(az);
    EasyMock.expect(serverInstanceContext.getInstanceId()).andReturn(instanceId);
    EasyMock.expect(serverInstanceContext.getRegion()).andReturn(region);
    EasyMock.expect(serverInstanceContext.getPrivateIp()).andReturn("127.0.0.1");
    EasyMock.expect(serverInstanceContext.getPublicIp()).andReturn(null);
    EasyMock.replay(serverInstanceContext);
    Configuration configuration = configurationBuilder.withServerInstanceContext(serverInstanceContext).build();
    Assert.assertEquals(az, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_AVAILABILITY_ZONE.getPropertyName()));
    Assert.assertEquals(instanceId, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_ID.getPropertyName()));
    Assert.assertEquals(region, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_REGION.getPropertyName()));
    Assert.assertEquals("127.0.0.1", configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_PRIVATE_IP.getPropertyName()));
    Assert.assertEquals(null, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_PUBLIC_IP.getPropertyName()));
    EasyMock.verify(serverInstanceContext);
}
Also used : ServerInstanceContext(com.kixeye.chassis.bootstrap.aws.ServerInstanceContext) Configuration(org.apache.commons.configuration.Configuration) Test(org.junit.Test)

Example 2 with ServerInstanceContext

use of com.kixeye.chassis.bootstrap.aws.ServerInstanceContext in project chassis by Kixeye.

the class BootstrapConfiguration method applicationConfiguration.

@Bean
@SuppressWarnings("resource")
public AbstractConfiguration applicationConfiguration() throws ClassNotFoundException {
    AppMetadata appMetadata = appMetadata();
    ServerInstanceContext serverInstanceContext = serverInstanceContext();
    if (appEnvironment == null && serverInstanceContext != null) {
        appEnvironment = serverInstanceContext.getEnvironment();
    }
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(appMetadata.getName(), appEnvironment, addSystemConfigs, reflections());
    configurationBuilder.withConfigurationProvider(configurationProvider());
    configurationBuilder.withServerInstanceContext(serverInstanceContext());
    configurationBuilder.withApplicationProperties(appMetadata.getPropertiesResourceLocation());
    configurationBuilder.withScanModuleConfigurations(scanModuleConfigurations);
    configurationBuilder.withAppVersion(appMetadata.getDeclaringClass().getPackage().getImplementationVersion());
    AbstractConfiguration configuration = configurationBuilder.build();
    if (serverInstanceContext != null) {
        serverInstanceContext.setAppName(appMetadata.getName());
        serverInstanceContext.setVersion(configuration.getString(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName()));
    }
    return configuration;
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConfigurationBuilder(com.kixeye.chassis.bootstrap.configuration.ConfigurationBuilder) ServerInstanceContext(com.kixeye.chassis.bootstrap.aws.ServerInstanceContext) Bean(org.springframework.context.annotation.Bean)

Aggregations

ServerInstanceContext (com.kixeye.chassis.bootstrap.aws.ServerInstanceContext)2 ConfigurationBuilder (com.kixeye.chassis.bootstrap.configuration.ConfigurationBuilder)1 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)1 Configuration (org.apache.commons.configuration.Configuration)1 Test (org.junit.Test)1 Bean (org.springframework.context.annotation.Bean)1