1
1
package cz .xtf .builder .db ;
2
2
3
+ import java .util .Collections ;
3
4
import java .util .HashMap ;
5
+ import java .util .List ;
4
6
import java .util .Map ;
5
7
6
8
import cz .xtf .builder .builders .ApplicationBuilder ;
11
13
import cz .xtf .builder .builders .pod .PersistentVolumeClaim ;
12
14
13
15
public abstract class AbstractDatabase extends DefaultStatefulAuxiliary {
16
+ private static final String DEFAULT_USERNAME = "testuser" ;
17
+ private static final String DEFAULT_PASSWORD = "testpwd" ;
18
+ private static final String DEFAULT_DATABASE_NAME = "testdb" ;
14
19
protected final String username ;
15
20
protected final String password ;
16
21
protected final String dbName ;
@@ -26,12 +31,49 @@ public abstract class AbstractDatabase extends DefaultStatefulAuxiliary {
26
31
protected boolean withReadinessProbe ;
27
32
protected boolean withStartupProbe ;
28
33
34
+ private String deploymentConfigName ;
35
+ private String envVarPrefix ;
36
+
37
+ public void setDeploymentConfigName (String deploymentConfigName ) {
38
+ this .deploymentConfigName = deploymentConfigName ;
39
+ }
40
+
41
+ public void setEnvVarPrefix (String envVarPrefix ) {
42
+ this .envVarPrefix = envVarPrefix ;
43
+ }
44
+
45
+ public AbstractDatabase (
46
+ String symbolicName ,
47
+ String dataDir ,
48
+ PersistentVolumeClaim pvc ,
49
+ String username ,
50
+ String password ,
51
+ String dbName ,
52
+ boolean configureEnvironment ,
53
+ boolean withLivenessProbe ,
54
+ boolean withReadinessProbe ,
55
+ boolean withStartupProbe ,
56
+ String deploymentConfigName ,
57
+ String envVarPrefix ) {
58
+ super (symbolicName , dataDir , pvc );
59
+ this .symbolicName = symbolicName ;
60
+ this .username = (username == null || username .isEmpty ()) ? DEFAULT_USERNAME : username ;
61
+ this .password = (password == null || password .isEmpty ()) ? DEFAULT_PASSWORD : password ;
62
+ this .dbName = (dbName == null || dbName .isEmpty ()) ? DEFAULT_DATABASE_NAME : dbName ;
63
+ this .withLivenessProbe = withLivenessProbe ;
64
+ this .withReadinessProbe = withReadinessProbe ;
65
+ this .withStartupProbe = withStartupProbe ;
66
+ this .configureEnvironment = configureEnvironment ;
67
+ this .deploymentConfigName = deploymentConfigName ;
68
+ this .envVarPrefix = envVarPrefix ;
69
+ }
70
+
29
71
public AbstractDatabase (String symbolicName , String dataDir ) {
30
- this ("testuser" , "testpwd" , "testdb" , symbolicName , dataDir );
72
+ this (DEFAULT_USERNAME , DEFAULT_PASSWORD , DEFAULT_DATABASE_NAME , symbolicName , dataDir );
31
73
}
32
74
33
75
public AbstractDatabase (String symbolicName , String dataDir , boolean withLivenessProbe , boolean withReadinessProbe ) {
34
- this ("testuser" , "testpwd" , "testdb" , symbolicName , dataDir );
76
+ this (DEFAULT_USERNAME , DEFAULT_PASSWORD , DEFAULT_DATABASE_NAME , symbolicName , dataDir );
35
77
36
78
this .withLivenessProbe = withLivenessProbe ;
37
79
this .withReadinessProbe = withReadinessProbe ;
@@ -54,12 +96,13 @@ public AbstractDatabase(String symbolicName, String dataDir, boolean withLivenes
54
96
}
55
97
56
98
public AbstractDatabase (String symbolicName , String dataDir , PersistentVolumeClaim pvc ) {
57
- this ("testuser" , "testpwd" , "testdb" , symbolicName , dataDir , pvc );
99
+ this (DEFAULT_USERNAME , DEFAULT_PASSWORD , DEFAULT_DATABASE_NAME , symbolicName , dataDir , pvc );
58
100
}
59
101
60
102
public AbstractDatabase (String symbolicName , String dataDir , PersistentVolumeClaim pvc , boolean withLivenessProbe ,
61
103
boolean withReadinessProbe ) {
62
- this ("testuser" , "testpwd" , "testdb" , symbolicName , dataDir , pvc , withLivenessProbe , withReadinessProbe );
104
+ this (DEFAULT_USERNAME , DEFAULT_PASSWORD , DEFAULT_DATABASE_NAME , symbolicName , dataDir , pvc , withLivenessProbe ,
105
+ withReadinessProbe );
63
106
}
64
107
65
108
public AbstractDatabase (String username , String password , String dbName , String symbolicName , String dataDir ,
@@ -73,7 +116,7 @@ public AbstractDatabase(String username, String password, String dbName, String
73
116
74
117
public AbstractDatabase (String symbolicName , String dataDir , PersistentVolumeClaim pvc , boolean withLivenessProbe ,
75
118
boolean withReadinessProbe , boolean withStartupProbe ) {
76
- this ("testuser" , "testpwd" , "testdb" , symbolicName , dataDir , pvc );
119
+ this (DEFAULT_USERNAME , DEFAULT_PASSWORD , DEFAULT_DATABASE_NAME , symbolicName , dataDir , pvc );
77
120
78
121
this .withLivenessProbe = withLivenessProbe ;
79
122
this .withReadinessProbe = withReadinessProbe ;
@@ -148,14 +191,28 @@ public Map<String, String> getImageVariables() {
148
191
return vars ;
149
192
}
150
193
194
+ public List <String > getImageArgs () {
195
+ return Collections .emptyList ();
196
+ }
197
+
198
+ public String getServiceAccount () {
199
+ return null ;
200
+ }
201
+
151
202
public String getDeploymentConfigName () {
203
+ if (deploymentConfigName != null ) {
204
+ return deploymentConfigName ;
205
+ }
152
206
if (openShiftName == null ) {
153
207
openShiftName = dbName .toLowerCase () + "-" + getSymbolicName ().toLowerCase ();
154
208
}
155
209
return openShiftName ;
156
210
}
157
211
158
212
public String getEnvVarPrefix () {
213
+ if (envVarPrefix != null ) {
214
+ return envVarPrefix ;
215
+ }
159
216
return dbName .toUpperCase () + "_" + getSymbolicName ().toUpperCase ();
160
217
}
161
218
@@ -183,11 +240,19 @@ public DeploymentConfigBuilder configureDeployment(ApplicationBuilder appBuilder
183
240
184
241
public DeploymentConfigBuilder configureDeployment (ApplicationBuilder appBuilder , boolean synchronous ) {
185
242
final DeploymentConfigBuilder builder = appBuilder .deploymentConfig (getDeploymentConfigName ());
186
- builder .podTemplate ().container ().fromImage (getImageName ()).envVars (getImageVariables ()).port (getPort ());
243
+ ContainerBuilder containerBuilder = builder .podTemplate ().container ().fromImage (getImageName ())
244
+ .envVars (getImageVariables ())
245
+ .port (getPort ());
246
+ if (getImageArgs () != null ) {
247
+ getImageArgs ().forEach (containerBuilder ::args );
248
+ }
187
249
if (synchronous ) {
188
250
builder .onConfigurationChange ();
189
251
builder .synchronousDeployment ();
190
252
}
253
+ if (getServiceAccount () != null ) {
254
+ builder .podTemplate ().addServiceAccount (getServiceAccount ());
255
+ }
191
256
192
257
configureContainer (builder .podTemplate ().container ());
193
258
0 commit comments