Skip to content

Commit 9f46e4b

Browse files
authored
Merge pull request #142 from PSMRI/fix-release-3.6.2
Rebase 3.6.2 on 3.6.1
2 parents 6e856d1 + 8edc363 commit 9f46e4b

5 files changed

Lines changed: 668 additions & 31 deletions

File tree

pom.xml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304

305305

306306
<build>
307-
<finalName>${artifactId}-${version}</finalName>
307+
<finalName>${project.artifactId}-${project.version}</finalName>
308308

309309
<plugins>
310310
<plugin>
@@ -348,6 +348,32 @@
348348
<artifactId>maven-jar-plugin</artifactId>
349349
<version>3.0.2</version>
350350
</plugin>
351+
<plugin>
352+
<groupId>io.github.git-commit-id</groupId>
353+
<artifactId>git-commit-id-maven-plugin</artifactId>
354+
<version>9.0.2</version>
355+
<executions>
356+
<execution>
357+
<id>get-the-git-infos</id>
358+
<goals>
359+
<goal>revision</goal>
360+
</goals>
361+
<phase>initialize</phase>
362+
</execution>
363+
</executions>
364+
<configuration>
365+
<generateGitPropertiesFile>true</generateGitPropertiesFile>
366+
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
367+
<includeOnlyProperties>
368+
<property>^git.branch$</property>
369+
<property>^git.commit.id.abbrev$</property>
370+
<property>^git.build.version$</property>
371+
<property>^git.build.time$</property>
372+
</includeOnlyProperties>
373+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
374+
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
375+
</configuration>
376+
</plugin>
351377
<plugin>
352378
<groupId>org.springframework.boot</groupId>
353379
<artifactId>spring-boot-maven-plugin</artifactId>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* AMRIT – Accessible Medical Records via Integrated Technology
3+
* Integrated EHR (Electronic Health Records) Solution
4+
*
5+
* Copyright (C) "Piramal Swasthya Management and Research Institute"
6+
*
7+
* This file is part of AMRIT.
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program. If not, see https://www.gnu.org/licenses/.
21+
*/
22+
23+
package com.iemr.tm.controller.health;
24+
25+
import java.time.Instant;
26+
import java.util.Map;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
import org.springframework.http.HttpStatus;
30+
import org.springframework.http.ResponseEntity;
31+
import org.springframework.web.bind.annotation.GetMapping;
32+
import org.springframework.web.bind.annotation.RequestMapping;
33+
import org.springframework.web.bind.annotation.RestController;
34+
import com.iemr.tm.service.health.HealthService;
35+
import io.swagger.v3.oas.annotations.Operation;
36+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
37+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
38+
import io.swagger.v3.oas.annotations.tags.Tag;
39+
40+
@RestController
41+
@RequestMapping("/health")
42+
@Tag(name = "Health Check", description = "APIs for checking infrastructure health status")
43+
public class HealthController {
44+
45+
private static final Logger logger = LoggerFactory.getLogger(HealthController.class);
46+
47+
private final HealthService healthService;
48+
49+
public HealthController(HealthService healthService) {
50+
this.healthService = healthService;
51+
}
52+
53+
@GetMapping
54+
@Operation(summary = "Check infrastructure health",
55+
description = "Returns the health status of MySQL, Redis, and other configured services")
56+
@ApiResponses({
57+
@ApiResponse(responseCode = "200", description = "Services are UP or DEGRADED (operational with warnings)"),
58+
@ApiResponse(responseCode = "503", description = "One or more critical services are DOWN")
59+
})
60+
public ResponseEntity<Map<String, Object>> checkHealth() {
61+
logger.info("Health check endpoint called");
62+
63+
try {
64+
Map<String, Object> healthStatus = healthService.checkHealth();
65+
String overallStatus = (String) healthStatus.get("status");
66+
67+
// Return 503 only if DOWN; 200 for both UP and DEGRADED (DEGRADED = operational with warnings)
68+
HttpStatus httpStatus = "DOWN".equals(overallStatus) ? HttpStatus.SERVICE_UNAVAILABLE : HttpStatus.OK;
69+
70+
logger.debug("Health check completed with status: {}", overallStatus);
71+
return new ResponseEntity<>(healthStatus, httpStatus);
72+
73+
} catch (Exception e) {
74+
logger.error("Unexpected error during health check", e);
75+
76+
Map<String, Object> errorResponse = Map.of(
77+
"status", "DOWN",
78+
"timestamp", Instant.now().toString()
79+
);
80+
81+
return new ResponseEntity<>(errorResponse, HttpStatus.SERVICE_UNAVAILABLE);
82+
}
83+
}
84+
}

src/main/java/com/iemr/tm/controller/version/VersionController.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,59 +21,59 @@
2121
*/
2222
package com.iemr.tm.controller.version;
2323

24-
import java.io.BufferedReader;
2524
import java.io.IOException;
2625
import java.io.InputStream;
27-
import java.io.InputStreamReader;
26+
import java.util.LinkedHashMap;
27+
import java.util.Map;
28+
import java.util.Properties;
2829

2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
3132

33+
import org.springframework.http.MediaType;
34+
import org.springframework.http.ResponseEntity;
3235
import org.springframework.web.bind.annotation.GetMapping;
33-
import org.springframework.web.bind.annotation.RequestMapping;
34-
import org.springframework.web.bind.annotation.RequestMethod;
3536
import org.springframework.web.bind.annotation.RestController;
3637

37-
import com.iemr.tm.utils.response.OutputResponse;
38-
3938
import io.swagger.v3.oas.annotations.Operation;
4039

4140
@RestController
4241
public class VersionController {
4342

44-
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
43+
private final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
44+
45+
private static final String UNKNOWN_VALUE = "unknown";
4546

4647
@Operation(summary = "Get version information")
47-
@GetMapping(value = "/version")
48-
public String versionInformation() {
49-
OutputResponse output = new OutputResponse();
48+
@GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
49+
public ResponseEntity<Map<String, String>> versionInformation() {
50+
Map<String, String> response = new LinkedHashMap<>();
5051
try {
5152
logger.info("version Controller Start");
52-
output.setResponse(readGitProperties());
53+
Properties gitProperties = loadGitProperties();
54+
response.put("buildTimestamp", gitProperties.getProperty("git.build.time", UNKNOWN_VALUE));
55+
response.put("version", gitProperties.getProperty("git.build.version", UNKNOWN_VALUE));
56+
response.put("branch", gitProperties.getProperty("git.branch", UNKNOWN_VALUE));
57+
response.put("commitHash", gitProperties.getProperty("git.commit.id.abbrev", UNKNOWN_VALUE));
5358
} catch (Exception e) {
54-
output.setError(e);
59+
logger.error("Failed to load version information", e);
60+
response.put("buildTimestamp", UNKNOWN_VALUE);
61+
response.put("version", UNKNOWN_VALUE);
62+
response.put("branch", UNKNOWN_VALUE);
63+
response.put("commitHash", UNKNOWN_VALUE);
5564
}
56-
5765
logger.info("version Controller End");
58-
return output.toString();
59-
}
60-
61-
private String readGitProperties() throws Exception {
62-
ClassLoader classLoader = getClass().getClassLoader();
63-
InputStream inputStream = classLoader.getResourceAsStream("git.properties");
64-
65-
return readFromInputStream(inputStream);
66+
return ResponseEntity.ok(response);
6667
}
6768

68-
private String readFromInputStream(InputStream inputStream)
69-
throws IOException {
70-
StringBuilder resultStringBuilder = new StringBuilder();
71-
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
72-
String line;
73-
while ((line = br.readLine()) != null) {
74-
resultStringBuilder.append(line).append("\n");
69+
private Properties loadGitProperties() throws IOException {
70+
Properties properties = new Properties();
71+
try (InputStream input = getClass().getClassLoader()
72+
.getResourceAsStream("git.properties")) {
73+
if (input != null) {
74+
properties.load(input);
7575
}
7676
}
77-
return resultStringBuilder.toString();
77+
return properties;
7878
}
7979
}

0 commit comments

Comments
 (0)