Skip to content

Commit

Permalink
Merge pull request #170 from rwth-acis/release/1.3.0
Browse files Browse the repository at this point in the history
Release/1.3.0
  • Loading branch information
lakhoune authored Jul 9, 2023
2 parents db1ebc1 + 02559ca commit 70edb13
Show file tree
Hide file tree
Showing 11 changed files with 15,548 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 17
- name: Set up node
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/i5/las2peer/api/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,22 @@ public Serializable invokeInternally(ServiceNameVersion service, String method,
*/
public void monitorEvent(Object from, MonitoringEvent event, String message, boolean includeActingUser);

/**
* Writes an XES event message to the l2p system using node observers. Also
* makes data
* available to MobSOS.
*
* @param event Differentiates between different log messages. Use
* MonitoringEvent.SERVICE_CUSTOM_MESSAGE_XXX as parameter.
* @param message A message.
* @param caseId The case id of the XES event.
* @param activityName The activity name of the XES event.
* @param resourceId The resource id of the XES event.
* @param resourceType The resource type of the XES event.
*/
public void monitorXESEvent(MonitoringEvent event, String message, String caseId, String activityName,
String resourceId, String resourceType);

// Class loading

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ public void monitorEvent(Object from, MonitoringEvent event, String message, boo

}

@Override
public void monitorXESEvent(MonitoringEvent event, String message, String caseId, String activityName,
String resourceId, String resourceType) {
String sourceAgentId = serviceAgent != null ? serviceAgent.getIdentifier() : null;
node.observerNotice(event, node.getNodeId(), sourceAgentId, null, null, message, caseId, activityName,
resourceId, resourceType);
}

@Override
public UserAgent createUserAgent(String passphrase) throws AgentOperationFailedException {
try {
Expand Down
20 changes: 20 additions & 0 deletions core/src/main/java/i5/las2peer/logging/L2pLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,26 @@ public void log(Long timestamp, MonitoringEvent event, String sourceNode, String
log(observerLevel, logLine.toString());
}

@Override
public void logXESEvent(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId,
String destinationNode, String destinationAgentId, String remarks, String caseId, String activityName,
String resourceId, String resourceType) {
StringBuilder logLine = new StringBuilder();
logLine.append(event + " (" + event.getCode() + ")\t");
logLine.append(appendPart(sourceNode));
logLine.append(appendPart(sourceAgentId));
logLine.append(appendPart(destinationNode));
logLine.append(appendPart(destinationAgentId));
logLine.append(appendPart(remarks));
logLine.append(appendPart(caseId));
logLine.append(appendPart(activityName));
logLine.append(appendPart(resourceId));
logLine.append(appendPart(resourceType));
// with default levels this hides the output from console and only writes it to
// logfile
log(observerLevel, logLine.toString());
}

/**
* Simple method for one log line entry. Null will be printed as "-". All values will be followed by a tab char.
*
Expand Down
27 changes: 27 additions & 0 deletions core/src/main/java/i5/las2peer/logging/NodeObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,31 @@ public interface NodeObserver {
public void log(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId,
String destinationNode, String destinationAgentId, String remarks);

/**
* Each call represents one event to log by this observer.
* All parameters except the time stamp and the event may be null.
* Additionally, this method logs the caseId, activityName, resourceId and
* resourceType of the event.
*
*
* @param timestamp UNIX time stamp of the event
* @param event the event to log
* @param sourceNode a source (p2p) node of the event (e.g. message
* sender)
* @param sourceAgentId a source (las2peer) agent of the event (e.g.
* message sender)
* @param destinationNode a destination (p2p) node for the event (e.g.
* message receiver)
* @param destinationAgentId a destination (las2peer) agent of the event (e.g.
* message receiver)
* @param remarks (optional) additional remarks
* @param caseId caseId of the event
* @param activityName activityName of the event
* @param resourceId resourceId of the event
* @param resourceType resourceType of the event
*/
public void logXESEvent(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId,
String destinationNode, String destinationAgentId, String remarks, String caseId, String activityName,
String resourceId, String resourceType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,71 @@ public void log(Long timestamp, MonitoringEvent event, String sourceNode, String
}

/**
* Checks whether the queue is ready to be flushed, either due to reaching the limit or because enough time has
*
* Processes the incoming data by generating a {@link XESEventMessage} of it.
* This
* {@link XESEventMessage} will
* be stored in an array of {@link MonitoringMessage}s, which will be send via a
* {@link i5.las2peer.communication.Message} to the Processing Service.
*
*/
@Override
public void logXESEvent(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId,
String destinationNode, String destinationAgentId, String remarks, String caseId, String activityName,
String resourceId, String resourceType) {
if (sourceNode == null) {
return; // We do not log events without a source node into a database with different
// sources;-)
}

/*
* Temporary fix to exclude the very frequent messages from monitoring
* in order to not spam too much into the monitoring db.
*/
if (event == MonitoringEvent.ARTIFACT_FETCH_STARTED || event == MonitoringEvent.ARTIFACT_RECEIVED
|| event == MonitoringEvent.AGENT_GET_STARTED || event == MonitoringEvent.AGENT_GET_SUCCESS
|| event == MonitoringEvent.MESSAGE_SENDING || event == MonitoringEvent.ARTIFACT_FETCH_FAILED
|| event == MonitoringEvent.MESSAGE_RECEIVED_ANSWER || event == MonitoringEvent.MESSAGE_FORWARDING
|| event == MonitoringEvent.MESSAGE_RECEIVED) {
return;
}

monitoringMessages[messagesCount++] = new XESEventMessage(timestamp, event, sourceNode, sourceAgentId,
destinationNode, destinationAgentId, remarks, caseId, activityName, resourceId, resourceType);

if (readyToSend()) {
checkInit();
if (initializedDone) {
messagesCount = 0;
sendMessages();
} else {
messagesCount = 0;
System.out.println("Monitoring: Problems with initializing Agents..");
}
}

// We can only send our last message if the node is closing, so we will have to
// assume that all services are
// shutdown
// when a node is closed (seems to be a fair bet)
if (event == MonitoringEvent.NODE_SHUTDOWN) {
if (initializedDone) {
// To remove "old" messages since they are not overwritten
int counter = messagesCount;
while (counter < monitoringMessages.length) {
monitoringMessages[counter] = null;
counter++;
}
sendMessages();
} else {
System.out.println("Monitoring: Problems with initializing Agents..");
}
}
}

/**
* Checks whether the queue is ready to be flushed, either due to reaching the
* limit or because enough time has
* passed
*
* @return true is ready to flush
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package i5.las2peer.logging.monitoring;

import i5.las2peer.api.logging.MonitoringEvent;

/**
*
* This class stores a message that was logged by the monitoring module of
* las2peer. An Array of instances of this class
* is send via a {@link i5.las2peer.communication.Message} to the central
* monitoring node.
*
*
*
*/
public class XESEventMessage extends MonitoringMessage {

private static final long serialVersionUID = -1481584785721621545L;

private String caseId;
private String activityName;
private String resourceId;
private String resourceType;

/**
*
* Constructor of a XESEventMessage. This is a subclass of
* {@link i5.las2peer.logging.monitoring.MonitoringMessage} with additional
* fields for XES event log.
*
* @param timestamp A timestamp for this message
* @param event A monitoring event identifier
* @param sourceNode A source node
* @param sourceAgentId A source agent id
* @param destinationNode A destination node
* @param destinationAgentId A destination agent id
* @param remarks Any additional information about this message
* @param caseId caseId of the event
* @param activityName activityName of the event
* @param resourceId resourceId of the event
* @param resourceType resourceType of the event (e.g. user, service, bot,
* etc.)
*/
public XESEventMessage(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId,
String destinationNode, String destinationAgentId, String remarks, String caseId, String activityName,
String resourceId, String resourceType) {
super(timestamp, event, sourceNode, sourceAgentId, destinationNode, destinationAgentId, remarks);

this.caseId = caseId;
this.activityName = activityName;
this.resourceId = resourceId;
this.resourceType = resourceType;
}

public String getCaseId() {
return caseId;
}

public String getActivityName() {
return activityName;
}

public String getResourceId() {
return resourceId;
}

public String getResourceType() {
return resourceType;
}

}
31 changes: 31 additions & 0 deletions core/src/main/java/i5/las2peer/p2p/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,37 @@ public void observerNotice(MonitoringEvent event, Object sourceNode, String sour
}
}

/**
* Logs an event to all observers.
*
* @param event The event for this notification.
* @param sourceNode A source node for this event
* @param sourceAgentId A source agent id for this event
* @param destinationNode A destination node for this event
* @param destinationAgentId A destination agent id for this event
* @param remarks Some free text note or description about this
* event.
* @param caseId caseId of the event
* @param activityName activityName of the event
* @param resourceId resourceId of the event
* @param resourceType resourceType of the event
*/
public void observerNotice(MonitoringEvent event, Object sourceNode, String sourceAgentId, Object destinationNode,
String destinationAgentId, String remarks, String caseId, String activityName, String resourceId,
String resourceType) {
long timestamp = new Date().getTime();
String sourceNodeRepresentation = getNodeRepresentation(sourceNode);
String destinationNodeRepresentation = getNodeRepresentation(destinationNode);
for (NodeObserver ob : observers) {
if (ob == serviceLogger && (Math.abs(event.getCode()) < 7500 || Math.abs(event.getCode()) >= 7600)) {
// custom logger shall only log service messages
continue;
}
ob.logXESEvent(timestamp, event, sourceNodeRepresentation, sourceAgentId, destinationNodeRepresentation,
destinationAgentId, remarks, caseId, activityName, resourceId, resourceType);
}
}

/**
* Derive a String representation for a node from the given identifier object. The type of the object depends on the
* setting of the current node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ public void log(Long timestamp, MonitoringEvent event, String sourceNode, String
messages.add(timestamp + " " + event + " " + sourceNode + " " + sourceAgentId + " " + destinationNode
+ " " + destinationAgentId + " " + remarks);
}

public void logXESEvent(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId,
String destinationNode, String destinationAgentId, String remarks, String caseId,
String activityName,
String resourceId, String resourceType) {
// TODO Auto-generated method stub
}
});

context.monitorEvent(this, MonitoringEvent.SERVICE_CUSTOM_ERROR_1, "testMessage", true);
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
las2peer.revision=1.2
las2peer.build.number=4
las2peer.revision=1.3
las2peer.build.number=0
java.version=17
junit.version=4.13.1
jersey.version=2.35
Expand Down
Loading

0 comments on commit 70edb13

Please sign in to comment.