Skip to content

Commit c2fbb9c

Browse files
authored
Development: Add Helios push based lifecycle monitoring with manual DB migration status events (#10873)
1 parent f49fe81 commit c2fbb9c

File tree

7 files changed

+41
-3
lines changed

7 files changed

+41
-3
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ dependencies {
365365
implementation "org.springframework.security:spring-security-messaging:${spring_security_version}"
366366
implementation "org.springframework.security:spring-security-ldap:${spring_security_version}"
367367

368+
// Helios push-based status updates
369+
implementation "de.tum.cit.aet:helios-status-spring-starter:${helios_status_version}"
370+
368371
implementation "org.opensaml:opensaml-saml-api:${opensaml_version}"
369372
implementation "org.opensaml:opensaml-saml-impl:${opensaml_version}"
370373

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ netty_version=4.1.118.Final
3737
mysql_version=9.3.0
3838
micrometer_version=1.15.1
3939
snakeyaml_version=2.4
40+
helios_status_version=1.1.0
4041

4142
# testing
4243
# make sure both versions are compatible

src/main/java/de/tum/cit/aet/artemis/core/config/LiquibaseConfiguration.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static tech.jhipster.config.JHipsterConstants.SPRING_PROFILE_TEST;
55

66
import java.sql.SQLException;
7+
import java.util.Optional;
78

89
import javax.sql.DataSource;
910

@@ -24,6 +25,7 @@
2425
import org.springframework.core.env.Profiles;
2526

2627
import de.tum.cit.aet.artemis.core.config.migration.DatabaseMigration;
28+
import de.tum.cit.aet.helios.HeliosClient;
2729
import liquibase.Scope;
2830
import liquibase.SingletonScopeManager;
2931
import liquibase.integration.spring.SpringLiquibase;
@@ -41,15 +43,18 @@ public class LiquibaseConfiguration {
4143

4244
private final BuildProperties buildProperties;
4345

46+
private final Optional<HeliosClient> optionalHeliosClient;
47+
4448
private DataSource dataSource;
4549

4650
private DatabaseMigration databaseMigration;
4751

4852
private String currentVersionString;
4953

50-
public LiquibaseConfiguration(Environment env, BuildProperties buildProperties) {
54+
public LiquibaseConfiguration(Environment env, BuildProperties buildProperties, Optional<HeliosClient> optionalHeliosClient) {
5155
this.env = env;
5256
this.buildProperties = buildProperties;
57+
this.optionalHeliosClient = optionalHeliosClient;
5358
}
5459

5560
/**
@@ -69,7 +74,7 @@ public SpringLiquibase liquibase(@LiquibaseDataSource ObjectProvider<DataSource>
6974
this.currentVersionString = buildProperties.getVersion();
7075

7176
if (!env.acceptsProfiles(Profiles.of(SPRING_PROFILE_TEST))) {
72-
this.databaseMigration = new DatabaseMigration(currentVersionString, dataSource);
77+
this.databaseMigration = new DatabaseMigration(currentVersionString, dataSource, optionalHeliosClient);
7378
databaseMigration.checkMigrationPath();
7479
}
7580

@@ -133,9 +138,11 @@ public void storeCurrentVersionToDatabase(ApplicationReadyEvent event) {
133138

134139
preparedStatement.executeUpdate();
135140
connection.commit(); // Ensure the transaction is committed.
141+
optionalHeliosClient.ifPresent(HeliosClient::pushDbMigrationFinished);
136142
}
137143
catch (SQLException e) {
138144
log.error("Failed to store the current version to the database", e);
145+
optionalHeliosClient.ifPresent(HeliosClient::pushDbMigrationFailed);
139146
throw new RuntimeException("Error updating the application version in the database", e);
140147
}
141148
}

src/main/java/de/tum/cit/aet/artemis/core/config/migration/DatabaseMigration.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.sql.Statement;
55
import java.util.ArrayList;
66
import java.util.List;
7+
import java.util.Optional;
78

89
import javax.sql.DataSource;
910

@@ -13,6 +14,8 @@
1314

1415
import com.vdurmont.semver4j.Semver;
1516

17+
import de.tum.cit.aet.helios.HeliosClient;
18+
1619
/**
1720
* Represents a migration path that defines the necessary steps for database migration before
1821
* updating to a new major version. This class is pivotal in ensuring that administrators install
@@ -93,9 +96,12 @@ public class DatabaseMigration {
9396

9497
private String previousVersionString;
9598

96-
public DatabaseMigration(String currentVersionString, DataSource dataSource) {
99+
private final Optional<HeliosClient> optionalHeliosClient;
100+
101+
public DatabaseMigration(String currentVersionString, DataSource dataSource, Optional<HeliosClient> optionalHeliosClient) {
97102
this.currentVersionString = currentVersionString;
98103
this.dataSource = dataSource;
104+
this.optionalHeliosClient = optionalHeliosClient;
99105

100106
// Initialize migration paths here in the correct order
101107
migrationPaths.add(new MigrationPath("5.12.9")); // required for migration to 6.0.0 until 7.0.0
@@ -120,6 +126,7 @@ public void checkMigrationPath() {
120126

121127
if (previousVersionString == null) {
122128
log.info("Migration path check: Not necessary");
129+
optionalHeliosClient.ifPresent(HeliosClient::pushDbMigrationStarted);
123130
return;
124131
}
125132

@@ -129,6 +136,7 @@ public void checkMigrationPath() {
129136
if (currentVersion.isGreaterThanOrEqualTo(path.upgradeVersion) && currentVersion.isLowerThan(path.nextUpgradeVersion)) {
130137
if (previousVersion.isLowerThan(path.requiredVersion)) {
131138
log.error(path.errorMessage);
139+
optionalHeliosClient.ifPresent(HeliosClient::pushDbMigrationFailed);
132140
System.exit(15);
133141
}
134142
else if (previousVersion.isEqualTo(path.requiredVersion)) {
@@ -138,6 +146,8 @@ else if (previousVersion.isEqualTo(path.requiredVersion)) {
138146
}
139147
}
140148
}
149+
150+
optionalHeliosClient.ifPresent(HeliosClient::pushDbMigrationStarted);
141151
}
142152

143153
/**
@@ -234,6 +244,7 @@ private void updateInitialChecksum(String newVersion) {
234244
}
235245
catch (SQLException e) {
236246
log.error("Cannot update checksum for initial schema migration: {}", e.getMessage());
247+
optionalHeliosClient.ifPresent(HeliosClient::pushDbMigrationFailed);
237248
System.exit(11);
238249
}
239250
}
@@ -262,6 +273,7 @@ private Statement createStatement() throws SQLException {
262273
}
263274
catch (Exception e) {
264275
log.error("Cannot connect to the database {} (This typically indicates that the database is not running or there are permission issues", e.getMessage());
276+
optionalHeliosClient.ifPresent(HeliosClient::pushDbMigrationFailed);
265277
System.exit(10);
266278
}
267279
return null;

src/main/resources/config/application-buildagent.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ management:
107107
eureka:
108108
client:
109109
enabled: true
110+
111+
helios:
112+
status:
113+
enabled: false

src/main/resources/config/application-dev.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,7 @@ artemis:
134134
enabled: false # Disable sending any telemetry information to the telemetry service by setting this to false
135135
sendAdminDetails: false # Include the admins email and name in the telemetry data. Set to false to disable
136136
destination: https://telemetry.artemis.cit.tum.de
137+
138+
helios:
139+
status:
140+
enabled: false

src/main/resources/config/application.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,10 @@ eureka:
370370
git-version: ${git.commit.id.describe:}
371371
git-commit: ${git.commit.id.abbrev:}
372372
git-branch: ${git.branch:}
373+
374+
# Helios configuration
375+
# It is enabled and all the values are set by the ansible
376+
# Refer to the ansible repository https://github.com/ls1intum/artemis-ansible
377+
helios:
378+
status:
379+
enabled: false

0 commit comments

Comments
 (0)