Skip to content

Commit

Permalink
chore: reuse env to configure database
Browse files Browse the repository at this point in the history
  • Loading branch information
D-D-H committed Oct 18, 2023
1 parent 64e01ad commit 86273e8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
13 changes: 9 additions & 4 deletions cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,21 @@ spec:
volumeMounts:
- name: jifa-pv
mountPath: "/jifa-storage"
env:
- name: MYSQL_HOST
value: mysql-service:3306
- name: MYSQL_DATABASE
value: jifa
- name: MYSQL_USER
value: root
- name: MYSQL_PASSWORD
value: password
args:
- --jifa.role=master
- --jifa.scheduling-strategy=elastic
- --jifa.storage-pvc-name=jifa-pvc
- --jifa.storage-path=/jifa-storage
- --jifa.worker-image=eclipsejifa/jifa:0.2.0-SNAPSHOT
- --jifa.database-host=mysql-service:3306
- --jifa.database-name=jifa
- --jifa.database-username=root
- --jifa.database-password=password
ports:
- name: jifa-port
containerPort: 8102
Expand Down
8 changes: 4 additions & 4 deletions server/server.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ static void setJvmOptions(BootRun bootRun) {

static void setDatabase(BootRun bootRun) {
// Note: adjust args here according to your environment
bootRun.args('--jifa.database-host=localhost:3306')
bootRun.args('--jifa.database-name=jifa')
bootRun.args('--jifa.database-username=root')
bootRun.args('--jifa.database-password=password')
bootRun.environment("MYSQL_HOST", "localhost:3306")
bootRun.environment("MYSQL_DATABASE", "jifa")
bootRun.environment("MYSQL_USER", "root")
bootRun.environment("MYSQL_PASSWORD", "password")
}

tasks.register('runStandaloneWorker', BootRun) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public class Configuration {
/**
* The database name
*/
private String databaseName = "jifa";
private String databaseName;

/**
* The database username
*/
private String databaseUsername;
private String databaseUser;

/**
* The database password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public DataSource getDataSource() {
DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName("com.mysql.cj.jdbc.Driver");
dataSourceBuilder.url(String.format("jdbc:mysql://%s/%s?createDatabaseIfNotExist=true", config.getDatabaseHost(), config.getDatabaseName()));
dataSourceBuilder.username(config.getDatabaseUsername());
dataSourceBuilder.username(config.getDatabaseUser());
dataSourceBuilder.password(config.getDatabasePassword());
return dataSourceBuilder.build();
} else if (isStandaloneWorker()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ public void scheduleAsync(long identity, long requestedMemSize, BiConsumer<Strin
.imagePullPolicy("Always")
.addVolumeMountsItem(new V1VolumeMount().name("jifa-pv").mountPath(config.getStoragePath().toString()))
.addEnvItem(new V1EnvVar().name(ELASTIC_WORKER_IDENTITY_ENV_KEY).value(Long.toString(identity)))
.addEnvItem(new V1EnvVar().name("MYSQL_HOST").value(config.getDatabaseHost()))
.addEnvItem(new V1EnvVar().name("MYSQL_DATABASE").value(config.getDatabaseName()))
.addEnvItem(new V1EnvVar().name("MYSQL_USER").value(config.getDatabaseUser()))
.addEnvItem(new V1EnvVar().name("MYSQL_PASSWORD").value(config.getDatabasePassword()))
.args(List.of(
"--jifa.role=elastic-worker",
"--jifa.storage-path=" + config.getStoragePath().toString(),
"--jifa.database-host=" + config.getDatabaseHost(),
"--jifa.database-name=" + config.getDatabaseName(),
"--jifa.database-username=" + config.getDatabaseUsername(),
"--jifa.database-password=" + config.getDatabasePassword()
))
"--jifa.storage-path=" + config.getStoragePath().toString()))
.addPortsItem(new V1ContainerPort().containerPort(DEFAULT_PORT))
.resources(resourceRequirements)
.startupProbe(healthCheck);
Expand Down
4 changes: 4 additions & 0 deletions server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
jifa:
role: standalone-worker
storage-path: ${user.home}/jifa-storage
database-host: ${MYSQL_HOST:}
database-name: ${MYSQL_DATABASE:}
database-user: ${MYSQL_USER:jifa}
database-password: ${MYSQL_PASSWORD:jifa}

spring:
servlet:
Expand Down

0 comments on commit 86273e8

Please sign in to comment.