1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.neo4j.server.startup.healthcheck;
21
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.util.Properties;
25
26 import org.neo4j.server.configuration.Configurator;
27
28 public class Neo4jPropertiesMustExistRule implements StartupHealthCheckRule
29 {
30 private static final String EMPTY_STRING = "";
31 private boolean passed = false;
32 private boolean ran = false;
33 protected String failureMessage = EMPTY_STRING;
34
35 public boolean execute(Properties properties) {
36 ran = true;
37
38 String configFilename = properties.getProperty( Configurator.NEO_SERVER_CONFIG_FILE_KEY);
39
40 Properties configProperties = new Properties();
41 FileInputStream inputStream = null;
42 try
43 {
44 inputStream = new FileInputStream( configFilename );
45 configProperties.load( inputStream );
46 }
47 catch ( IOException e )
48 {
49 failureMessage = String.format("Failed to load configuration properties from [%s]", configFilename);
50 return false;
51 }
52 finally
53 {
54 if ( inputStream != null )
55 {
56 try
57 {
58 inputStream.close();
59 }
60 catch ( IOException e )
61 {
62 }
63 }
64 }
65
66 passed = validateProperties( configProperties );
67 return passed;
68 }
69
70 protected boolean validateProperties( Properties configProperties )
71 {
72
73 return true;
74 }
75
76 public String getFailureMessage() {
77 if(passed) {
78 return EMPTY_STRING;
79 }
80
81 if(!ran) {
82 return String.format("%s has not been run", getClass().getName());
83 } else {
84 return failureMessage;
85 }
86 }
87 }