Skip to content

Commit c18698a

Browse files
tommaso-borgatomchoma
authored andcommitted
PostgreSQL deprecated: use RedHatPostgreSQL and OfficialPostgreSQL
1 parent 84e1b3e commit c18698a

File tree

5 files changed

+600
-6
lines changed

5 files changed

+600
-6
lines changed

builder/src/main/java/cz/xtf/builder/db/AbstractDatabase.java

+71-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package cz.xtf.builder.db;
22

3+
import java.util.Collections;
34
import java.util.HashMap;
5+
import java.util.List;
46
import java.util.Map;
57

68
import cz.xtf.builder.builders.ApplicationBuilder;
@@ -11,6 +13,9 @@
1113
import cz.xtf.builder.builders.pod.PersistentVolumeClaim;
1214

1315
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";
1419
protected final String username;
1520
protected final String password;
1621
protected final String dbName;
@@ -26,12 +31,49 @@ public abstract class AbstractDatabase extends DefaultStatefulAuxiliary {
2631
protected boolean withReadinessProbe;
2732
protected boolean withStartupProbe;
2833

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+
2971
public AbstractDatabase(String symbolicName, String dataDir) {
30-
this("testuser", "testpwd", "testdb", symbolicName, dataDir);
72+
this(DEFAULT_USERNAME, DEFAULT_PASSWORD, DEFAULT_DATABASE_NAME, symbolicName, dataDir);
3173
}
3274

3375
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);
3577

3678
this.withLivenessProbe = withLivenessProbe;
3779
this.withReadinessProbe = withReadinessProbe;
@@ -54,12 +96,13 @@ public AbstractDatabase(String symbolicName, String dataDir, boolean withLivenes
5496
}
5597

5698
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);
58100
}
59101

60102
public AbstractDatabase(String symbolicName, String dataDir, PersistentVolumeClaim pvc, boolean withLivenessProbe,
61103
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);
63106
}
64107

65108
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
73116

74117
public AbstractDatabase(String symbolicName, String dataDir, PersistentVolumeClaim pvc, boolean withLivenessProbe,
75118
boolean withReadinessProbe, boolean withStartupProbe) {
76-
this("testuser", "testpwd", "testdb", symbolicName, dataDir, pvc);
119+
this(DEFAULT_USERNAME, DEFAULT_PASSWORD, DEFAULT_DATABASE_NAME, symbolicName, dataDir, pvc);
77120

78121
this.withLivenessProbe = withLivenessProbe;
79122
this.withReadinessProbe = withReadinessProbe;
@@ -148,14 +191,28 @@ public Map<String, String> getImageVariables() {
148191
return vars;
149192
}
150193

194+
public List<String> getImageArgs() {
195+
return Collections.emptyList();
196+
}
197+
198+
public String getServiceAccount() {
199+
return null;
200+
}
201+
151202
public String getDeploymentConfigName() {
203+
if (deploymentConfigName != null) {
204+
return deploymentConfigName;
205+
}
152206
if (openShiftName == null) {
153207
openShiftName = dbName.toLowerCase() + "-" + getSymbolicName().toLowerCase();
154208
}
155209
return openShiftName;
156210
}
157211

158212
public String getEnvVarPrefix() {
213+
if (envVarPrefix != null) {
214+
return envVarPrefix;
215+
}
159216
return dbName.toUpperCase() + "_" + getSymbolicName().toUpperCase();
160217
}
161218

@@ -183,11 +240,19 @@ public DeploymentConfigBuilder configureDeployment(ApplicationBuilder appBuilder
183240

184241
public DeploymentConfigBuilder configureDeployment(ApplicationBuilder appBuilder, boolean synchronous) {
185242
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+
}
187249
if (synchronous) {
188250
builder.onConfigurationChange();
189251
builder.synchronousDeployment();
190252
}
253+
if (getServiceAccount() != null) {
254+
builder.podTemplate().addServiceAccount(getServiceAccount());
255+
}
191256

192257
configureContainer(builder.podTemplate().container());
193258

builder/src/main/java/cz/xtf/builder/db/AbstractSQLDatabase.java

+28
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@
1212

1313
public abstract class AbstractSQLDatabase extends AbstractDatabase implements SQLExecutor {
1414

15+
public AbstractSQLDatabase(
16+
String symbolicName,
17+
String dataDir,
18+
PersistentVolumeClaim pvc,
19+
String username,
20+
String password,
21+
String dbName,
22+
boolean configureEnvironment,
23+
boolean withLivenessProbe,
24+
boolean withReadinessProbe,
25+
boolean withStartupProbe,
26+
String deploymentConfigName,
27+
String envVarPrefix) {
28+
super(
29+
symbolicName,
30+
dataDir,
31+
pvc,
32+
username,
33+
password,
34+
dbName,
35+
configureEnvironment,
36+
withLivenessProbe,
37+
withReadinessProbe,
38+
withStartupProbe,
39+
deploymentConfigName,
40+
envVarPrefix);
41+
}
42+
1543
public AbstractSQLDatabase(String symbolicName, String dataDir, boolean withLivenessProbe, boolean withReadinessProbe) {
1644
super(symbolicName, dataDir, withLivenessProbe, withReadinessProbe);
1745
}

0 commit comments

Comments
 (0)