3232
3333import javax .sql .DataSource ;
3434
35- import org .bson .Document ;
3635import org .slf4j .Logger ;
3736import org .slf4j .LoggerFactory ;
3837import org .springframework .beans .factory .annotation .Autowired ;
3938import org .springframework .beans .factory .annotation .Value ;
40- import org .springframework .data .mongodb .core .MongoTemplate ;
4139import org .springframework .data .redis .core .RedisCallback ;
4240import org .springframework .data .redis .core .RedisTemplate ;
4341import 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 )) {
0 commit comments