Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sap.cds.feature.console.connectivity;

import com.sap.cds.feature.console.info.Path;
import com.sap.cds.feature.console.service.CommandEventContext;
import com.sap.cds.feature.console.service.InfoEventContext;
import com.sap.cds.feature.console.service.RemoteMonitoringService;
Expand All @@ -24,8 +25,16 @@ public RemoteMonitoringHandler(RemoteMonitoringServer server) {
@On
private void handleInfoEvent(InfoEventContext context) {
logger.debug("Handling info '{}'", context.getEvent());
this.remoteMonitoringServer.broadcastToPath(
context.getInfoEvent().toJson(), RemoteMonitoringServer.PATH_LOGS);

String path = context.getInfoEvent().getPath();

if (path.startsWith(Path.OUTBOX)) {
this.remoteMonitoringServer.broadcastToPath(
context.getInfoEvent().toJson(), RemoteMonitoringServer.PATH_TASKS);
} else {
this.remoteMonitoringServer.broadcastToPath(
context.getInfoEvent().toJson(), RemoteMonitoringServer.PATH_LOGS);
}

context.setCompleted();
}
Expand All @@ -36,5 +45,4 @@ private void handleDashboardCommandEvent(CommandEventContext context) {
logger.debug("Handling command '{}'", context.getEvent());
context.setCompleted();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class RemoteMonitoringServer extends WebSocketServer {
private static final Logger logger = LoggerFactory.getLogger(RemoteMonitoringServer.class);
public static final String PATH_CAP_CONSOLE = "/cap-console";
public static final String PATH_LOGS = PATH_CAP_CONSOLE + "/logs";
public static final String PATH_TASKS = PATH_CAP_CONSOLE + "/tasks";

private final Map<String, Set<WebSocket>> clientsByPaths = new ConcurrentHashMap<>();
private static final ObjectMapper objectMapper = new ObjectMapper();
Expand Down Expand Up @@ -132,13 +133,14 @@ public void onStart() {
}

private void welcomeClient(WebSocket conn, String path) {
RemoteLogData welcomeMsg = new RemoteLogData.Builder()
.level("INFO")
.logger("system")
.thread(Thread.currentThread().getName())
.type("welcome")
.message("Welcome to CAP console Remote Monitoring.")
.build();
RemoteLogData welcomeMsg =
new RemoteLogData.Builder()
.level("INFO")
.logger("system")
.thread(Thread.currentThread().getName())
.type("welcome")
.message("Welcome to CAP console Remote Monitoring.")
.build();

InfoEvent infoEvent = InfoEvent.createRemoteLog(path, welcomeMsg);
conn.send(infoEvent.toJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ protected void emitInfoEvent(Supplier<InfoEvent> infoProducer) {
}
getRemoteMonitoringService().emit(event);
} catch (Exception e) {
sendErrorNotification("Data Access Error", e.getMessage());
String errorMessage = e.getMessage() != null ? e.getMessage() : e.getClass().getName();
sendErrorNotification("Data Access Error", errorMessage);
logger.error("Could not emit remote-monitoring info event!", e);
}
}
Expand All @@ -72,33 +73,44 @@ public void sendSuccessNotification(String header, String notification, Object..
}

public void sendErrorNotification(String header, String notification, Object... args) {
RemoteLogData logData = new RemoteLogData.Builder()
.type(header)
.logger("system")
.thread(Thread.currentThread().getName())
.level("error")
.message(String.format(notification, args))
.ts(System.currentTimeMillis())
.build();
RemoteLogData logData =
new RemoteLogData.Builder()
.type(header)
.logger("system")
.thread(Thread.currentThread().getName())
.level("error")
.message(String.format(notification, args))
.ts(System.currentTimeMillis())
.build();

InfoEvent event = InfoEvent.createRemoteLog(Path.CONSOLE_NOTIFICATION, logData);
getRemoteMonitoringService().emit(event);
}

public void sendNotification(NotificationType type, String notification, Object... args) {
RemoteLogData logData = new RemoteLogData.Builder()
.type(type.name())
.logger("system")
.thread(Thread.currentThread().getName())
.level("info")
.message(String.format(notification, args))
.ts(System.currentTimeMillis())
.build();
RemoteLogData logData =
new RemoteLogData.Builder()
.type(type.name())
.logger("system")
.thread(Thread.currentThread().getName())
.level("info")
.message(String.format(notification, args))
.ts(System.currentTimeMillis())
.build();

InfoEvent event = InfoEvent.createRemoteLog(Path.CONSOLE_NOTIFICATION, logData);
getRemoteMonitoringService().emit(event);
}

public static void inRemoteMonitoringContext(Runnable action) {
REMOTE_MONITORING_EVENT.set(true);
try {
action.run();
} finally {
REMOTE_MONITORING_EVENT.set(false);
}
}

public static boolean isInRemoteMonitoringContext() {
return REMOTE_MONITORING_EVENT.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

public final class Path {

private Path() {

}
private Path() {}

public static final String CONSOLE = "console";
public static final String REMOTE_MONITORING = "remote-monitoring";
Expand All @@ -20,4 +18,6 @@ private Path() {
public static final String TRACES_OUTPUT = TRACES + ".output";
public static final String TRACES_EVENTS = TRACES + ".events";

public static final String OUTBOX = "outbox";
public static final String OUTBOX_TENANTS = OUTBOX + ".tenants";
}
Loading
Loading