EMS: for RD: Improved error reporting via AMQ messages to RD. Also added 'reference' in AMQ messages to RD.

This commit is contained in:
ipatini
2023-10-03 16:51:29 +03:00
parent f45a1eda81
commit f1b6a4f332
4 changed files with 42 additions and 20 deletions

View File

@@ -137,9 +137,9 @@ public class ClientInstallationRequestListener implements InitializingBean {
log.error("InstallationEventListener: ERROR: ", e);
try {
if (StringUtils.isNotBlank(requestId))
clientInstaller.sendClientInstallationReport(requestId, "ERROR: "+e.getMessage());
clientInstaller.sendErrorClientInstallationReport(requestId, "ERROR: "+e.getMessage());
else
clientInstaller.sendClientInstallationReport("UNKNOWN-REQUEST-ID", "ERROR: "+e.getMessage()+"\n"+message);
clientInstaller.sendErrorClientInstallationReport("UNKNOWN-REQUEST-ID", "ERROR: "+e.getMessage()+"\n"+message);
} catch (Throwable t) {
log.info("InstallationEventListener: EXCEPTION while sending Client installation report for incoming request: request={}, Exception: ", message, t);
}
@@ -209,11 +209,20 @@ public class ClientInstallationRequestListener implements InitializingBean {
}
private void processOnboardingRequest(Map<String,String> request) throws Exception {
String requestId = request.get("requestId").trim();
String requestId = request.getOrDefault("requestId", "").trim();
log.info("InstallationEventListener: New node ONBOARDING request with Id: {}", requestId);
if (StringUtils.isBlank(requestId)) {
clientInstaller.sendErrorClientInstallationReport("MISSING-REQUEST-ID", "INVALID REQUEST. MISSING REQUEST ID");
return;
}
log.debug("InstallationEventListener: Registering node due to ONBOARDING request with Id: {}", requestId);
nodeRegistration.registerNode(null, convertToNodeInfoMap(request), new TranslationContext(requestId));
try {
log.debug("InstallationEventListener: Registering node due to ONBOARDING request with Id: {}", requestId);
nodeRegistration.registerNode(null, convertToNodeInfoMap(request), new TranslationContext(requestId));
} catch (Exception e) {
log.warn("InstallationEventListener: EXCEPTION while executing ONBOARDING request with Id: {}\n", requestId, e);
clientInstaller.sendErrorClientInstallationReport(requestId, "ERROR: "+e.getMessage());
}
}
private Map<String, Object> convertToNodeInfoMap(Map<String, String> request) {

View File

@@ -27,6 +27,7 @@ import java.time.Instant;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
@@ -88,9 +89,9 @@ public class ClientInstaller implements InitializingBean {
// Send execution report to local broker
try {
resultStr = StringUtils.defaultIfBlank(resultStr, "ERROR: " + errorStr);
sendClientInstallationReport(taskCnt, task, resultStr);
sendSuccessClientInstallationReport(taskCnt, task, resultStr);
} catch (Throwable t) {
log.info("ClientInstaller: Exception caught while sending Client installation report for Task #{}: Exception: ", taskCnt, t);
log.info("ClientInstaller: EXCEPTION while sending Client installation report for Task #{}: Exception: ", taskCnt, t);
}
});
}
@@ -190,21 +191,21 @@ public class ClientInstaller implements InitializingBean {
return result;
}
public void sendClientInstallationReport(long taskCnt, @NonNull ClientInstallationTask task, String resultStr) throws JMSException {
log.trace("ClientInstaller: Preparing execution report event for Task #{}: result={}, task={}", taskCnt, resultStr, task);
public void sendSuccessClientInstallationReport(long taskCnt, @NonNull ClientInstallationTask task, String resultStr) throws JMSException {
log.trace("ClientInstaller: Preparing SUCCESS execution report event for Task #{}: result={}, task={}", taskCnt, resultStr, task);
LinkedHashMap<String, Object> executionReport = new LinkedHashMap<>(
createReportEventFromExecutionResults(taskCnt, task, resultStr));
log.info("ClientInstaller: Sending execution report for Task #{}: destination={}, report={}",
log.info("ClientInstaller: Sending SUCCESS execution report for Task #{}: destination={}, report={}",
taskCnt, properties.getClientInstallationReportsTopic(), executionReport);
brokerCepService.publishSerializable(
null, properties.getClientInstallationReportsTopic(), executionReport, true);
}
public void sendClientInstallationReport(String requestId, String resultStr) throws JMSException {
log.trace("ClientInstaller: Preparing execution report event for request: result={}, requestId={}", resultStr, requestId);
public void sendErrorClientInstallationReport(String requestId, String resultStr) throws JMSException {
log.trace("ClientInstaller: Preparing ERROR execution report event for request: result={}, requestId={}", resultStr, requestId);
LinkedHashMap<String, Object> executionReport = new LinkedHashMap<>(
createReportEvent(requestId, resultStr, Collections.emptyMap()));
log.info("ClientInstaller: Sending execution report for request: destination={}, report={}",
createReportEvent(requestId, null, resultStr, Collections.emptyMap()));
log.info("ClientInstaller: Sending ERROR execution report for request: destination={}, report={}",
properties.getClientInstallationReportsTopic(), executionReport);
brokerCepService.publishSerializable(
null, properties.getClientInstallationReportsTopic(), executionReport, true);
@@ -223,14 +224,19 @@ public class ClientInstaller implements InitializingBean {
});
log.debug("ClientInstaller: createReportEventFromExecutionResults: Task #{}: Node info collected: {}", taskCnt, nodeInfoMap);
String requestId = StringUtils.defaultIfBlank(task.getRequestId(), task.getId());
return createReportEvent(requestId, resultStr, nodeInfoMap);
return createReportEvent(requestId, task.getNodeRegistryEntry().getReference(), resultStr, nodeInfoMap);
}
private static Map<String, Object> createReportEvent(@NonNull String requestId, @NonNull String statusStr, Map<String, Object> nodeInfoMap) {
private static Map<String, Object> createReportEvent(@NonNull String requestId,
String reference,
@NonNull String statusStr,
Map<String, Object> nodeInfoMap)
{
return Map.of(
"requestId", requestId,
"reference", Objects.requireNonNullElse(reference, ""),
"status", statusStr,
"nodeInfo", nodeInfoMap,
"nodeInfo", nodeInfoMap!=null ? nodeInfoMap : Collections.emptyMap(),
"timestamp", Instant.now().toEpochMilli()
);
}

View File

@@ -66,8 +66,14 @@ public class NodeRegistrationController {
log.info("NodeRegistrationController.baguetteRegisterNode(): node-id: {}", nodeId);
log.debug("NodeRegistrationController.baguetteRegisterNode(): Node information: map={}", nodeMap);
String response = nodeRegistrationCoordinator.registerNode(request, nodeMap,
coordinator.getTranslationContextOfAppModel(coordinator.getCurrentAppModelId()));
String response;
try {
response = nodeRegistrationCoordinator.registerNode(request, nodeMap,
coordinator.getTranslationContextOfAppModel(coordinator.getCurrentAppModelId()));
} catch (Exception e) {
log.error("NodeRegistrationController.baguetteRegisterNode(): EXCEPTION while registering node: map={}\n", nodeMap, e);
response = "ERROR "+e.getMessage();
}
log.info("NodeRegistrationController.baguetteRegisterNode(): Node registered: node-id: {}", nodeId);
log.debug("NodeRegistrationController.baguetteRegisterNode(): node: {}, json: {}", nodeId, response);

View File

@@ -114,7 +114,8 @@ public class NodeRegistrationCoordinator implements InitializingBean {
entry = baguetteServer.registerClient(nodeMapFlattened);
} catch (Exception e) {
log.error("NodeRegistrationCoordinator.registerNode(): EXCEPTION while registering node: map={}\n", nodeMap, e);
return "ERROR "+e.getMessage();
//return "ERROR "+e.getMessage();
throw e;
}
// Continue processing according to ExecutionWare type