|
1 | 1 | package at.ac.tuwien.infosys.aic13.cloudscale.configuration;
|
2 | 2 |
|
| 3 | +import java.io.IOException; |
| 4 | +import java.io.InputStream; |
| 5 | +import java.util.Properties; |
3 | 6 | import java.util.logging.Level;
|
4 | 7 |
|
5 |
| -import org.slf4j.Logger; |
6 |
| -import org.slf4j.LoggerFactory; |
7 |
| - |
8 | 8 | import at.ac.tuwien.infosys.aic13.cloudscale.events.TestEvent;
|
9 | 9 | import at.ac.tuwien.infosys.cloudscale.annotations.CloudScaleConfigurationProvider;
|
10 | 10 | import at.ac.tuwien.infosys.cloudscale.configuration.CloudScaleConfiguration;
|
|
16 | 16 | * @author e0756024 <[email protected]>
|
17 | 17 | */
|
18 | 18 | public class ConfigurationProvider {
|
19 |
| - |
20 |
| - @SuppressWarnings("unused") |
21 |
| - private static final Logger log = LoggerFactory.getLogger(ConfigurationProvider.class); |
22 |
| - |
23 |
| - @CloudScaleConfigurationProvider |
24 |
| - public static CloudScaleConfiguration getConfiguration() { |
25 |
| -// return localConfig(); |
26 |
| - return getEC2Config(); |
27 |
| - } |
28 |
| - |
29 |
| - /** |
30 |
| - * @return config for local testing |
31 |
| - */ |
32 |
| - @SuppressWarnings("unused") |
33 |
| - private static CloudScaleConfiguration localConfig() { |
34 |
| - |
35 |
| - CloudScaleConfiguration cfg = new CloudScaleConfigurationBuilder() |
36 |
| - .withLogging(Level.WARNING) |
37 |
| - .with(new ScalingPolicyAlternative()) |
38 |
| - .withMonitoring(true) |
39 |
| - .withMonitoringEvents(TestEvent.class) |
40 |
| - .build(); |
41 | 19 |
|
42 |
| - //check every 60 seconds |
43 |
| - cfg.common().setScaleDownIntervalInSec(60); |
| 20 | + @CloudScaleConfigurationProvider |
| 21 | + public static CloudScaleConfiguration getConfiguration() { |
| 22 | + switch(getProperties().getProperty("g3p3.cloudScale.configurationProvider", "local")){ |
| 23 | + case "ec2": |
| 24 | + System.out.println("Using EC2-CloudScale Config (AHXIGO)."); |
| 25 | + return getEC2Config(); |
| 26 | + case "local": |
| 27 | + default: |
| 28 | + System.out.println("Using local CLoudScale Config (IT6Q81)."); |
| 29 | + return localConfig(); |
| 30 | + } |
| 31 | + } |
44 | 32 |
|
45 |
| - return cfg; |
| 33 | + private static Properties getProperties() { |
| 34 | + Properties properties = new Properties(); |
| 35 | + InputStream in = ConfigurationProvider.class.getClassLoader().getResourceAsStream( |
| 36 | + "aic13g3p3.properties"); |
| 37 | + try { |
| 38 | + properties.load(in); |
| 39 | + in.close(); |
| 40 | + } catch (IOException e) { |
| 41 | + System.err.println("Error while loading file 'aic13g3p3.properties' (025F2E). "+ e.getMessage()); |
| 42 | + } |
| 43 | + return properties; |
| 44 | + } |
46 | 45 |
|
47 |
| - } |
48 |
| - |
49 |
| - private static CloudScaleConfiguration getEC2Config() { |
50 |
| - |
51 |
| - final String AWS_CONFIG = "aws.properties"; |
52 |
| - final String AWS_ENDPOINT = "ec2.ap-southeast-1.amazonaws.com"; |
53 |
| - final String AWS_INSTANCE_TYPE = "t1.micro"; |
54 |
| - final String AWS_KEY = "awscs"; |
55 |
| - final String AWS_IMAGE_NAME = "CloudScale_v0.3.2 G3P3"; |
56 |
| - |
57 |
| - // CHANGE ME |
58 |
| - final String MQ_HOSTNAME = "ec2-54-251-13-247.ap-southeast-1.compute.amazonaws.com"; |
59 |
| - final int MQ_PORT = 61616; |
60 |
| - |
61 |
| - EC2CloudPlatformConfiguration ec2Config = new EC2CloudPlatformConfiguration(); |
62 |
| - ec2Config.setAwsConfigFile(ClassLoader.getSystemResource(AWS_CONFIG).getPath()); |
63 |
| - ec2Config.setAwsEndpoint(AWS_ENDPOINT); |
64 |
| - ec2Config.setInstanceType(AWS_INSTANCE_TYPE); |
65 |
| - ec2Config.setSshKey(AWS_KEY); |
66 |
| - ec2Config.setImageName(AWS_IMAGE_NAME); |
67 |
| - |
68 |
| - CloudScaleConfiguration config = new CloudScaleConfigurationBuilder() |
69 |
| - .with(ec2Config) |
70 |
| - .with(new ScalingPolicyAlternative()) |
71 |
| - .withMQServer(MQ_HOSTNAME, MQ_PORT) |
72 |
| - .withMonitoring(true) |
73 |
| - .withLogging(Level.OFF) |
74 |
| - .build(); |
75 |
| - |
76 |
| - config.common().setScaleDownIntervalInSec(20); |
77 |
| - |
78 |
| - return config; |
79 |
| - } |
| 46 | + /** |
| 47 | + * @return config for local testing |
| 48 | + */ |
| 49 | + private static CloudScaleConfiguration localConfig() { |
| 50 | + |
| 51 | + CloudScaleConfiguration cfg = new CloudScaleConfigurationBuilder() |
| 52 | + .withLogging(Level.WARNING) |
| 53 | + .with(new ScalingPolicyAlternative()).withMonitoring(true) |
| 54 | + .withMonitoringEvents(TestEvent.class).build(); |
| 55 | + |
| 56 | + // check every 60 seconds |
| 57 | + cfg.common().setScaleDownIntervalInSec(60); |
| 58 | + |
| 59 | + return cfg; |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + private static CloudScaleConfiguration getEC2Config() { |
| 64 | + |
| 65 | + final String AWS_CONFIG = "aws.properties"; |
| 66 | + final String AWS_ENDPOINT = "ec2.ap-southeast-1.amazonaws.com"; |
| 67 | + final String AWS_INSTANCE_TYPE = "t1.micro"; |
| 68 | + final String AWS_KEY = "awscs"; |
| 69 | + final String AWS_IMAGE_NAME = "CloudScale_v0.3.2 G3P3"; |
| 70 | + |
| 71 | + // CHANGE ME |
| 72 | + final String MQ_HOSTNAME = "ec2-54-251-13-247.ap-southeast-1.compute.amazonaws.com"; |
| 73 | + final int MQ_PORT = 61616; |
| 74 | + |
| 75 | + EC2CloudPlatformConfiguration ec2Config = new EC2CloudPlatformConfiguration(); |
| 76 | + ec2Config.setAwsConfigFile(ClassLoader.getSystemResource(AWS_CONFIG) |
| 77 | + .getPath()); |
| 78 | + ec2Config.setAwsEndpoint(AWS_ENDPOINT); |
| 79 | + ec2Config.setInstanceType(AWS_INSTANCE_TYPE); |
| 80 | + ec2Config.setSshKey(AWS_KEY); |
| 81 | + ec2Config.setImageName(AWS_IMAGE_NAME); |
| 82 | + |
| 83 | + CloudScaleConfiguration config = new CloudScaleConfigurationBuilder() |
| 84 | + .with(ec2Config).with(new ScalingPolicyAlternative()) |
| 85 | + .withMQServer(MQ_HOSTNAME, MQ_PORT).withMonitoring(true) |
| 86 | + .withLogging(Level.OFF).build(); |
| 87 | + |
| 88 | + config.common().setScaleDownIntervalInSec(20); |
| 89 | + |
| 90 | + return config; |
| 91 | + } |
80 | 92 | }
|
0 commit comments