Skip to content

Commit

Permalink
Rolled back constants file deletion
Browse files Browse the repository at this point in the history
Signed-off-by: HimajaDhanyamraju2 <[email protected]>
  • Loading branch information
HimajaDhanyamraju2 committed Jul 12, 2024
1 parent 9db2946 commit 2ca9fe3
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import io.mosip.kernel.idgenerator.constant.HibernatePersistenceConstant;
import io.mosip.kernel.idgenerator.constant.HealthConstants;
import io.mosip.kernel.uingenerator.constant.UINHealthConstants;
import io.mosip.kernel.uingenerator.constant.UinGeneratorConstant;
import io.netty.handler.codec.http.HttpResponse;
import io.vertx.core.AsyncResult;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void databaseHealthChecker(Promise<Status> future) {
try {
Class.forName(driver);
} catch (ClassNotFoundException exception) {
final JsonObject result = resultBuilder.create().add(HealthConstants.ERROR, exception.getMessage())
final JsonObject result = resultBuilder.create().add(UINHealthConstants.ERROR, exception.getMessage())
.build();
future.complete(Status.KO(result));
}
Expand All @@ -113,15 +113,15 @@ public void databaseHealthChecker(Promise<Status> future) {

if (rs.next()) {
final JsonObject result = resultBuilder.create()
.add(HealthConstants.DATABASE, conn.getMetaData().getDatabaseProductName())
.add(HealthConstants.HELLO, JdbcUtils.getResultSetValue(rs, 1)).build();
.add(UINHealthConstants.DATABASE, conn.getMetaData().getDatabaseProductName())
.add(UINHealthConstants.HELLO, JdbcUtils.getResultSetValue(rs, 1)).build();
future.complete(Status.OK(result));

}
}
}
} catch (SQLException exception) {
final JsonObject result = resultBuilder.create().add(HealthConstants.ERROR, exception.getMessage())
final JsonObject result = resultBuilder.create().add(UINHealthConstants.ERROR, exception.getMessage())
.build();
future.complete(Status.KO(result));
}
Expand All @@ -137,12 +137,12 @@ public void dispSpaceHealthChecker(Promise<Status> future) {
final long diskFreeInBytes = this.currentWorkingDirPath.getUsableSpace();
if (diskFreeInBytes >= THRESHOLD) {
final JsonObject result = resultBuilder.create()
.add(HealthConstants.TOTAL, this.currentWorkingDirPath.getTotalSpace())
.add(HealthConstants.FREE, diskFreeInBytes).add(HealthConstants.THRESHOLD, THRESHOLD).build();
.add(UINHealthConstants.TOTAL, this.currentWorkingDirPath.getTotalSpace())
.add(UINHealthConstants.FREE, diskFreeInBytes).add(UINHealthConstants.THRESHOLD, THRESHOLD).build();
future.complete(Status.OK(result));
} else {
final JsonObject result = resultBuilder.create().add(HealthConstants.ERROR,
String.format(HealthConstants.THRESHOLD_ERROR, diskFreeInBytes, THRESHOLD)).build();
final JsonObject result = resultBuilder.create().add(UINHealthConstants.ERROR,
String.format(UINHealthConstants.THRESHOLD_ERROR, diskFreeInBytes, THRESHOLD)).build();
future.complete(Status.KO(result));
}

Expand All @@ -156,11 +156,11 @@ public void dispSpaceHealthChecker(Promise<Status> future) {
*/
public void verticleHealthHandler(Promise<Status> future, Vertx vertx) {

vertx.eventBus().send(UinGeneratorConstant.UIN_GENERATOR_ADDRESS, HealthConstants.PING, response -> {
vertx.eventBus().send(UinGeneratorConstant.UIN_GENERATOR_ADDRESS, UINHealthConstants.PING, response -> {

if (response.succeeded()) {
final JsonObject result = resultBuilder.create()
.add(HealthConstants.RESPONSE, response.result().body()).build();
.add(UINHealthConstants.RESPONSE, response.result().body()).build();
future.complete(Status.OK(result));
} else {
future.complete(Status.KO());
Expand Down Expand Up @@ -246,9 +246,9 @@ private void createResponse(JsonObject json, HttpServerResponse response) {
status = 500;
}

json.put(HealthConstants.DETAILS, new JsonObject());
json.put(UINHealthConstants.DETAILS, new JsonObject());

JsonArray checks = json.getJsonArray(HealthConstants.CHECKS);
JsonArray checks = json.getJsonArray(UINHealthConstants.CHECKS);

if (status == 200 && checks.isEmpty()) {
// Special case, no procedure installed.
Expand All @@ -270,24 +270,24 @@ private void createResponse(JsonObject json, HttpServerResponse response) {
private void createResponse(JsonObject json, JsonArray checks) {
for (int i = 0; i < checks.size(); i++) {
JsonObject jsonobject = checks.getJsonObject(i);
String id = jsonobject.getString(HealthConstants.ID);
String id = jsonobject.getString(UINHealthConstants.ID);
BaseHealthCheckModel healthCheckModel = new BaseHealthCheckModel();
healthCheckModel.setStatus(jsonobject.getString(HealthConstants.STATUS));
healthCheckModel.setStatus(jsonobject.getString(UINHealthConstants.STATUS));
JsonObject result = null;
try {
if (jsonobject.containsKey(HealthConstants.DATA)) {
healthCheckModel.setDetails(jsonobject.getJsonObject(HealthConstants.DATA).getMap());
if (jsonobject.containsKey(UINHealthConstants.DATA)) {
healthCheckModel.setDetails(jsonobject.getJsonObject(UINHealthConstants.DATA).getMap());
result = new JsonObject(objectMapper.writeValueAsString(healthCheckModel));

} else {
result = new JsonObject(objectMapper.writeValueAsString(healthCheckModel));
result.remove(HealthConstants.DETAILS);
result.remove(UINHealthConstants.DETAILS);
}
} catch (JsonProcessingException e) {
LOGGER.error(e.getMessage());
}

json.getJsonObject(HealthConstants.DETAILS).put(id, result);
json.getJsonObject(UINHealthConstants.DETAILS).put(id, result);

}
}
Expand All @@ -305,12 +305,12 @@ public synchronized HealthCheckHandler unregister(String name) {
* @return True if has Error;else False
*/
private boolean hasErrors(JsonObject json) {
JsonObject data = json.getJsonObject(HealthConstants.DATA);
JsonObject data = json.getJsonObject(UINHealthConstants.DATA);
if (data != null && data.getBoolean("procedure-execution-failure", false)) {
return true;
}

JsonArray checks = json.getJsonArray(HealthConstants.CHECKS);
JsonArray checks = json.getJsonArray(UINHealthConstants.CHECKS);
if (checks != null) {
for (int i = 0; i < checks.size(); i++) {
JsonObject check = checks.getJsonObject(i);
Expand All @@ -330,9 +330,9 @@ private boolean hasErrors(JsonObject json) {
* @return Encoded Json String
*/
private String encode(JsonObject json) {
final String outcome = json.getString(HealthConstants.OUTCOME);
json.remove(HealthConstants.OUTCOME);
json.put(HealthConstants.STATUS, outcome);
final String outcome = json.getString(UINHealthConstants.OUTCOME);
json.remove(UINHealthConstants.OUTCOME);
json.put(UINHealthConstants.STATUS, outcome);
return json.encode();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.mosip.kernel.idgenerator.constant;
package io.mosip.kernel.uingenerator.constant;

public class HealthConstants {
public class UINHealthConstants {
/**
* The string field ERROR
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.springframework.context.ApplicationContext;

import io.mosip.kernel.idgenerator.constant.HealthConstants;
import io.mosip.kernel.uingenerator.constant.UINHealthConstants;
import io.mosip.kernel.uingenerator.constant.UinGeneratorConstant;
import io.mosip.kernel.uingenerator.generator.UinProcesser;
import io.vertx.core.AbstractVerticle;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void start() {
}else {
LOGGER.info("Generated and persisted uins lock is true.");
}
receivedMessage.reply(HealthConstants.ACTIVE);
receivedMessage.reply(UINHealthConstants.ACTIVE);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package io.mosip.kernel.vidgenerator.constant;

public class VIDHealthConstants {
/**
* The string field ERROR
*/
public static final String ERROR = "error";
/**
* The string field ACTIVE
*/
public static final String ACTIVE = "active";
/**
* The string field NOT_ACTIVE
*/
public static final String NOT_ACTIVE = "not active";
/**
* The string field PING
*/
public static final String PING = "ping";
/**
* The string field DATABASE
*/
public static final String DATABASE = "database";
/**
* The string field HELLO
*/
public static final String HELLO = "hello";
/**
* The string field TOTAL
*/
public static final String TOTAL = "total";
/**
* The string field THRESHOLD
*/
public static final String THRESHOLD = "threshold";
/**
* The string field FREE
*/
public static final String FREE = "free";
/**
* The string field RESPONSE
*/
public static final String RESPONSE = "response";
/**
* The string field THRESHOLD_ERROR
*/
public static final String THRESHOLD_ERROR = "Free disk space below threshold. Available: %d bytes (threshold: %d bytes)";
/**
* The string field DETAILS
*/
public static final String DETAILS = "details";
/**
* The string field DATA
*/
public static final String DATA = "data";
/**
* The string field CHECKS
*/
public static final String CHECKS = "checks";
/**
* The string field ID
*/
public static final String ID = "id";
/**
* The string field STATUS
*/
public static final String STATUS = "status";
/**
* The string field OUTCOME
*/
public static final String OUTCOME = "outcome";

}

0 comments on commit 2ca9fe3

Please sign in to comment.