Skip to content

Commit e3afa2e

Browse files
committed
refactor: remove MongoDB health check from Admin-API
- Removed MongoDB dependency and configuration (Admin-API doesn't use MongoDB) - Removed MongoDB health check from HealthService - Removed unnecessary base branch fetch step from commit-lint workflow - MongoDB is only used by FHIR-API, not Admin-API
1 parent c3dc907 commit e3afa2e

4 files changed

Lines changed: 2 additions & 62 deletions

File tree

.github/workflows/commit-lint.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ jobs:
1717
submodules: true
1818
fetch-depth: 0
1919

20-
- name: Fetch base branch
21-
run: git fetch origin ${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}
22-
2320
- name: Setup Node.js
2421
uses: actions/setup-node@v4
2522
with:

pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@
200200
<artifactId>spring-session-data-redis</artifactId>
201201

202202
</dependency>
203-
<dependency>
204-
<groupId>org.springframework.boot</groupId>
205-
<artifactId>spring-boot-starter-data-mongodb</artifactId>
206-
</dependency>
207203
<dependency>
208204
<groupId>org.mockito</groupId>
209205
<artifactId>mockito-core</artifactId>

src/main/java/com/iemr/admin/service/health/HealthService.java

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@
3232

3333
import javax.sql.DataSource;
3434

35-
import org.bson.Document;
3635
import org.slf4j.Logger;
3736
import org.slf4j.LoggerFactory;
3837
import org.springframework.beans.factory.annotation.Autowired;
3938
import org.springframework.beans.factory.annotation.Value;
40-
import org.springframework.data.mongodb.core.MongoTemplate;
4139
import org.springframework.data.redis.core.RedisCallback;
4240
import org.springframework.data.redis.core.RedisTemplate;
4341
import org.springframework.stereotype.Service;
@@ -55,9 +53,6 @@ public class HealthService {
5553
@Autowired(required = false)
5654
private RedisTemplate<String, Object> redisTemplate;
5755

58-
@Autowired(required = false)
59-
private MongoTemplate mongoTemplate;
60-
6156
@Value("${spring.datasource.url:unknown}")
6257
private String dbUrl;
6358

@@ -67,15 +62,6 @@ public class HealthService {
6762
@Value("${spring.redis.port:6379}")
6863
private int redisPort;
6964

70-
@Value("${spring.data.mongodb.host:localhost}")
71-
private String mongoHost;
72-
73-
@Value("${spring.data.mongodb.port:27017}")
74-
private int mongoPort;
75-
76-
@Value("${spring.data.mongodb.database:amrit}")
77-
private String mongoDatabase;
78-
7965
public Map<String, Object> checkHealth() {
8066
Map<String, Object> healthStatus = new LinkedHashMap<>();
8167
Map<String, Object> components = new LinkedHashMap<>();
@@ -97,15 +83,6 @@ public Map<String, Object> checkHealth() {
9783
}
9884
}
9985

100-
// Check MongoDB connectivity if configured
101-
if (mongoTemplate != null) {
102-
Map<String, Object> mongoStatus = checkMongoDBHealth();
103-
components.put("mongodb", mongoStatus);
104-
if (!isHealthy(mongoStatus)) {
105-
overallHealth = false;
106-
}
107-
}
108-
10986
healthStatus.put("status", overallHealth ? "UP" : "DOWN");
11087
healthStatus.put("timestamp", Instant.now().toString());
11188
healthStatus.put("components", components);
@@ -161,22 +138,7 @@ private Map<String, Object> checkRedisHealth() {
161138
});
162139
}
163140

164-
private Map<String, Object> checkMongoDBHealth() {
165-
Map<String, Object> details = new LinkedHashMap<>();
166-
details.put("type", "MongoDB");
167-
details.put("host", mongoHost);
168-
details.put("port", mongoPort);
169-
details.put("database", mongoDatabase);
170-
171-
return performHealthCheck("MongoDB", details, () -> {
172-
Document pingResult = mongoTemplate.getDb().runCommand(new Document("ping", 1));
173-
if (pingResult != null && pingResult.getDouble("ok") == 1.0) {
174-
String version = getMongoDBVersion();
175-
return new HealthCheckResult(true, version, null);
176-
}
177-
return new HealthCheckResult(false, null, "Ping returned unexpected response");
178-
});
179-
}
141+
180142

181143
/**
182144
* Common health check execution pattern to reduce code duplication.
@@ -245,17 +207,7 @@ private String getRedisVersion() {
245207
return null;
246208
}
247209

248-
private String getMongoDBVersion() {
249-
try {
250-
Document buildInfo = mongoTemplate.getDb().runCommand(new Document("buildInfo", 1));
251-
if (buildInfo != null && buildInfo.containsKey("version")) {
252-
return buildInfo.getString("version");
253-
}
254-
} catch (Exception e) {
255-
logger.debug("Could not retrieve MongoDB version: {}", e.getMessage());
256-
}
257-
return null;
258-
}
210+
259211

260212
private String extractHost(String jdbcUrl) {
261213
if (jdbcUrl == null || "unknown".equals(jdbcUrl)) {

src/main/resources/application.properties

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,3 @@ swymed-edituser-url=swymed-base-url/SwymedWebApi/api/Contact
7474

7575
calibrationPageSize=5
7676
biological-screening-device-url=http://localhost:8096/ezdx-hub-connect-srv
77-
78-
## MongoDB Configuration
79-
spring.data.mongodb.host=mongodb-container
80-
spring.data.mongodb.port=27017
81-
spring.data.mongodb.database=amrit

0 commit comments

Comments
 (0)