|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| package org.globus.cas.impl.bootstrap; |
|
12 |
| |
|
13 |
| import java.io.IOException; |
|
14 |
| import java.io.FileInputStream; |
|
15 |
| import java.io.FileNotFoundException; |
|
16 |
| |
|
17 |
| import java.util.Properties; |
|
18 |
| |
|
19 |
| import org.globus.cas.impl.databaseAccess.CasDBOptions; |
|
20 |
| import org.globus.cas.impl.databaseAccess.CasDBStorage; |
|
21 |
| import org.globus.cas.impl.databaseAccess.CasDBException; |
|
22 |
| |
|
23 |
| public class SetupDatabase { |
|
24 |
| |
|
25 |
| static final String bootstrapProp = "bootstrapFilename"; |
|
26 |
| |
|
27 |
| static final String mesg = |
|
28 |
| " Usage: cas-server-bootstrap [<options>] -d <dbPropFile> \n" |
|
29 |
| + " [ -implicit | -b <bootstrapFile> ]" |
|
30 |
| + "\n Options are -help Prints this help message\n" |
|
31 |
| + " -debug Runs with debug trace\n" |
|
32 |
| + " -d <dbPropFile> : File name with database properties as follows\n" |
|
33 |
| + " \"dbDriver=\"<database driver name \n" |
|
34 |
| + " \"dbConnectionURL=\"<database connection URL\n" |
|
35 |
| + " \"dbUserName=\"<Username to access database\n" |
|
36 |
| + " \"dbPassword=\"<Password for the above username\n" |
|
37 |
| + " -b <bootstrapFile> : Populates data with user data. File with \n" |
|
38 |
| + " data to bootstrap database with.\n" |
|
39 |
| + " -implicit : Populates database with CAS server implicit data and\n" |
|
40 |
| + " service/action and namespace relevant to FTP"; |
|
41 |
| |
|
42 |
0
| public static void main(String[] args) throws Exception {
|
|
43 |
| |
|
44 |
0
| boolean debug = false;
|
|
45 |
0
| boolean implicit = false;
|
|
46 |
0
| String dbPropFilename = null;
|
|
47 |
0
| String bootstrapFilename = null;
|
|
48 |
| |
|
49 |
0
| for (int i=0; i<args.length; i++) {
|
|
50 |
| |
|
51 |
0
| if (args[i].equals("-debug")) {
|
|
52 |
0
| debug = true;
|
|
53 |
| } |
|
54 |
| |
|
55 |
0
| if (args[i].equals("-help")) {
|
|
56 |
0
| System.out.println(mesg);
|
|
57 |
0
| System.exit(0);
|
|
58 |
| } |
|
59 |
| |
|
60 |
0
| if (args[i].equals("-d")) {
|
|
61 |
0
| if (args.length == i+1) {
|
|
62 |
0
| System.err.println("Error: -d option should have database"
|
|
63 |
| + " properties file name"); |
|
64 |
0
| System.err.println(mesg);
|
|
65 |
0
| System.exit(-1);
|
|
66 |
| } |
|
67 |
0
| dbPropFilename = args[i+1];
|
|
68 |
| } |
|
69 |
| |
|
70 |
0
| if (args[i].equals("-implicit")) {
|
|
71 |
0
| implicit = true;
|
|
72 |
| } |
|
73 |
| |
|
74 |
0
| if (args[i].equals("-b")) {
|
|
75 |
0
| if (args.length == i+1) {
|
|
76 |
0
| System.err.println("Error: -b option should have bootstrap"
|
|
77 |
| + "file name"); |
|
78 |
0
| System.err.println(mesg);
|
|
79 |
0
| System.exit(-1);
|
|
80 |
| } |
|
81 |
0
| bootstrapFilename = args[i+1];
|
|
82 |
| } |
|
83 |
| } |
|
84 |
| |
|
85 |
0
| if ((!implicit) && (bootstrapFilename == null)) {
|
|
86 |
0
| System.err.println("Error: Neither implicit bootstrap requested "
|
|
87 |
| + "nor user data provided"); |
|
88 |
0
| System.err.println(mesg);
|
|
89 |
0
| System.exit(-1);
|
|
90 |
| } |
|
91 |
| |
|
92 |
0
| if (dbPropFilename == null) {
|
|
93 |
0
| System.err.println("Error: -d option with database properties file"
|
|
94 |
| + " needs to be specified"); |
|
95 |
0
| System.err.println(mesg);
|
|
96 |
0
| System.exit(-1);
|
|
97 |
| } |
|
98 |
| |
|
99 |
0
| Properties prop = new Properties();
|
|
100 |
0
| try {
|
|
101 |
0
| prop.load(new FileInputStream(dbPropFilename));
|
|
102 |
| } catch (FileNotFoundException fnfe) { |
|
103 |
0
| System.err.println("Error: Database properties file "
|
|
104 |
| + dbPropFilename + " not found"); |
|
105 |
0
| if (debug) {
|
|
106 |
0
| System.err.println(fnfe);
|
|
107 |
| } |
|
108 |
0
| System.exit(-1);
|
|
109 |
| } catch (IOException ioe) { |
|
110 |
0
| System.err.println("Error loading file " + dbPropFilename + "\n"
|
|
111 |
| + ioe.getMessage()); |
|
112 |
0
| if (debug) {
|
|
113 |
0
| System.err.println(ioe);
|
|
114 |
| } |
|
115 |
0
| System.exit(-1);
|
|
116 |
| } |
|
117 |
0
| CasDBOptions casDbOption =
|
|
118 |
| new CasDBOptions(prop.getProperty("dbDriver"), |
|
119 |
| prop.getProperty("dbConnectionURL"), |
|
120 |
| prop.getProperty("dbUsername"), |
|
121 |
| prop.getProperty("dbPassword")); |
|
122 |
0
| String val = prop.getProperty("activeConnections");
|
|
123 |
0
| if (val != null) {
|
|
124 |
0
| if (debug) {
|
|
125 |
0
| System.out.println("Active connections " + val);
|
|
126 |
| } |
|
127 |
0
| casDbOption.setActiveConnections((new Integer(val)).intValue());
|
|
128 |
| } |
|
129 |
| |
|
130 |
0
| val = prop.getProperty("onExhaustAction");
|
|
131 |
0
| if (val != null) {
|
|
132 |
0
| if (debug) {
|
|
133 |
0
| System.out.println("On exhaust action " + val);
|
|
134 |
| } |
|
135 |
0
| casDbOption.setOnExhaustAction((new Integer(val)).byteValue());
|
|
136 |
| } |
|
137 |
| |
|
138 |
0
| val = prop.getProperty("maxWait");
|
|
139 |
0
| if (val != null) {
|
|
140 |
0
| if (debug) {
|
|
141 |
0
| System.out.println("max value " + val);
|
|
142 |
| } |
|
143 |
0
| casDbOption.setMaxWait((new Integer(val)).longValue());
|
|
144 |
| } |
|
145 |
| |
|
146 |
0
| val = prop.getProperty("idleConnections");
|
|
147 |
0
| if (val != null) {
|
|
148 |
0
| if (debug) {
|
|
149 |
0
| System.out.println("idle connections " + val);
|
|
150 |
| } |
|
151 |
0
| casDbOption.setIdleConnections((new Integer(val)).intValue());
|
|
152 |
| } |
|
153 |
| |
|
154 |
0
| try {
|
|
155 |
0
| CasDBStorage.setupDBConnection(casDbOption);
|
|
156 |
| } catch (CasDBException exp) { |
|
157 |
0
| System.err.println("Erorr initializing database "
|
|
158 |
| + exp.getMessage()); |
|
159 |
0
| if (debug) {
|
|
160 |
0
| System.err.println(exp);
|
|
161 |
| } |
|
162 |
0
| System.exit(-1);
|
|
163 |
| } |
|
164 |
0
| if (debug) {
|
|
165 |
0
| System.out.println("Database initialized");
|
|
166 |
| } |
|
167 |
| |
|
168 |
0
| if (implicit) {
|
|
169 |
0
| try {
|
|
170 |
0
| PopulateImplicitObjectData.populateDb();
|
|
171 |
| } catch (Exception exp) { |
|
172 |
0
| System.err.println("Error populating db with CAS server "
|
|
173 |
| + "implicit data \n" + exp.getMessage()); |
|
174 |
0
| if (debug) {
|
|
175 |
0
| System.err.println(exp);
|
|
176 |
| } |
|
177 |
0
| System.exit(-1);
|
|
178 |
| } |
|
179 |
0
| System.out.println("Database has been populated with CAS server"
|
|
180 |
| + " implicit data"); |
|
181 |
0
| try {
|
|
182 |
0
| PopulateImplicitFTPData.populateDb();
|
|
183 |
| } catch (Exception exp) { |
|
184 |
0
| System.err.println("Error populating db with FTP "
|
|
185 |
| + "implicit data \n" + exp.getMessage()); |
|
186 |
0
| if (debug) {
|
|
187 |
0
| System.err.println(exp);
|
|
188 |
| } |
|
189 |
0
| System.exit(-1);
|
|
190 |
| } |
|
191 |
0
| System.out.println("Database has been populated with FTP "
|
|
192 |
| + " implicit data"); |
|
193 |
| } |
|
194 |
| |
|
195 |
0
| if (bootstrapFilename != null) {
|
|
196 |
0
| if (debug) {
|
|
197 |
0
| System.out.println("Populating database with data from "
|
|
198 |
| + " following bootstrap file " |
|
199 |
| + bootstrapFilename); |
|
200 |
| } |
|
201 |
0
| try {
|
|
202 |
0
| PopulateUserData.populateDb(bootstrapFilename);
|
|
203 |
| } catch (Exception exp) { |
|
204 |
0
| System.err.println("Error populating CAS server database with "
|
|
205 |
| + "user data from " + bootstrapFilename |
|
206 |
| + "\n" + exp.getMessage()); |
|
207 |
0
| if (debug) {
|
|
208 |
0
| System.err.println(exp);
|
|
209 |
| } |
|
210 |
0
| System.exit(-1);
|
|
211 |
| } |
|
212 |
0
| System.out.println("Database has been populated with user data");
|
|
213 |
| } else { |
|
214 |
0
| if (debug) {
|
|
215 |
0
| System.out.println("No bootstrap file name specified");
|
|
216 |
| } |
|
217 |
| } |
|
218 |
0
| System.out.println("Bootstrap completed.");
|
|
219 |
| } |
|
220 |
| } |