blob: 244e542b65bad564345495686c83fa8f82e04f47 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package models;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public class Configuration {
private static final Logger LOGGER = Logger.getLogger(Configuration.class);
private static final DateTimeFormatter subdirDate = DateTimeFormat.forPattern("yy-MM");
private static File vmStoreBasePath;
private static File vmStoreProdPath;
private static String dbUri;
private static String dbUsername;
private static String dbPassword;
public static boolean load() throws IOException {
// Load configuration from java properties file
Properties prop = new Properties();
InputStream in = new FileInputStream("./config.properties");
try {
prop.load(in);
} finally {
in.close();
}
vmStoreBasePath = new File(prop.getProperty("vmstore.path"));
vmStoreProdPath = new File(vmStoreBasePath, "prod");
dbUri = prop.getProperty("db.uri");
dbUsername = prop.getProperty("db.username");
dbPassword = prop.getProperty("db.password");
// Currently all fields are mandatory but there might be optional settings in the future
return vmStoreBasePath != null && dbUri != null && dbUsername != null && dbPassword != null;
}
// Static ("real") fields
public static File getVmStoreBasePath() {
return vmStoreBasePath;
}
public static String getDbUri() {
return dbUri;
}
public static String getDbUsername() {
return dbUsername;
}
public static String getDbPassword() {
return dbPassword;
}
public static File getVmStoreProdPath() {
return vmStoreProdPath;
}
// Dynamically Computed fields
public static File getCurrentVmStorePath() {
return new File(vmStoreProdPath, subdirDate.print(System.currentTimeMillis()));
}
}
|