use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.
the class EntryCallSequence method execute.
@Override
protected void execute() {
final ISessionEvent sessionEvent = this.sessionEventInputPort.receive();
if (sessionEvent != null) {
if (sessionEvent instanceof SessionStartEvent) {
this.sessions.put(UserSession.createUserSessionId(sessionEvent), new UserSession(sessionEvent.getHostname(), sessionEvent.getSessionId()));
}
if (sessionEvent instanceof SessionEndEvent) {
final UserSession session = this.sessions.get(UserSession.createUserSessionId(sessionEvent));
if (session != null) {
this.userSessionOutputPort.send(session);
this.sessions.remove(sessionEvent.getSessionId());
}
}
}
final PayloadAwareEntryCallEvent event = this.entryCallInputPort.receive();
if (event != null) {
/**
* add the event to the corresponding user session in case the user session is not yet
* available, create one.
*/
final String userSessionId = UserSession.createUserSessionId(event);
UserSession userSession = this.sessions.get(userSessionId);
if (userSession == null) {
userSession = new UserSession(event.getHostname(), event.getSessionId());
this.sessions.put(userSessionId, userSession);
// TODO this should trigger a warning.
}
userSession.add(event, true);
}
// this.removeExpiredSessions();
}
use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.
the class TEntryCallSequenceWithPCM method execute.
@Override
protected void execute(final PayloadAwareEntryCallEvent event) {
/**
* check if operationEvent is from an known object
*/
if (CorrespondenceUtility.findModelElementForOperation(this.correspondenceModel, Repository.class, event.getClassSignature(), event.getOperationSignature()) != null) {
// add the event to the corresponding user session
// in case the user session is not yet available, create one
final String userSessionId = UserSession.createUserSessionId(event);
UserSession userSession = this.sessions.get(userSessionId);
if (userSession == null) {
userSession = new UserSession(event.getHostname(), event.getSessionId());
this.sessions.put(userSessionId, userSession);
}
// do not sort since TEntryEventSequence will sort any ways
userSession.add(event, false);
// collect all user sessions which have more elements as a defined threshold and send
// them
// to the next filter
final List<UserSession> listToSend = this.sessions.values().stream().filter(session -> session.size() > TEntryCallSequenceWithPCM.USER_SESSION_THRESHOLD).collect(Collectors.toList());
if (!listToSend.isEmpty()) {
this.outputPort.send(new UserSessionCollectionModel(listToSend));
}
}
}
use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.
the class DynamicBehaviorModelTable method addInformation.
@Override
public void addInformation(final PayloadAwareEntryCallEvent event) {
final String eventSignature = this.getSignatureFromEvent(event);
final List<CallInformation> newCallInformations = new ArrayList<>();
try {
for (int i = 0; i < event.getParameters().length; i++) {
final String value = String.valueOf(this.parameterValueDoubleMapper.mapValue(event.getParameters()[i], event.getValues()[i]));
newCallInformations.add(new CallInformation(event.getParameters()[i], value));
}
// adding if no transition added yet
if (!this.signatures.containsKey(eventSignature)) {
this.addSignature(eventSignature);
}
final List<AggregatedCallInformation> aggCallInformations = this.signatures.get(eventSignature).getSecond();
for (final CallInformation newCallInformation : newCallInformations) {
// add new CallInfromation to the aggregation correctly
final Optional<AggregatedCallInformation> match = aggCallInformations.stream().filter(aggCallInformation -> aggCallInformation.belongsTo(newCallInformation)).collect(new SingleOrNoneCollector<AggregatedCallInformation>());
if (match.isPresent()) {
match.get().addCallInformation(newCallInformation);
} else {
// add new Callinformation
final AggregatedCallInformation newAggregatedCallInformation = new AggregatedCallInformation(this.strategy, newCallInformation);
aggCallInformations.add(newAggregatedCallInformation);
}
}
} catch (final IllegalArgumentException e) {
DynamicBehaviorModelTable.LOGGER.error("Exception while adding information to behavior table", e);
}
}
use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.
the class SessionToBehaviorModelTransformation method convert.
/**
* Convert a user session into a behavior model.
*
* @param session
* user session
* @return returns a behavior model
*/
public BehaviorModel convert(final UserSession session) {
final BehaviorModel model = new BehaviorModel();
model.setName(this.prefix);
final List<EntryCallEvent> entryCalls = session.getEvents();
final Iterator<EntryCallEvent> iterator = entryCalls.iterator();
// Assume list has at least one element
if (iterator.hasNext()) {
EntryCallNode lastNode = this.createNode((PayloadAwareEntryCallEvent) iterator.next());
EntryCallNode currentNode;
while (iterator.hasNext()) {
currentNode = this.createNode((PayloadAwareEntryCallEvent) iterator.next());
model.addNode(currentNode, true);
model.addEdge(new EntryCallEdge(lastNode, currentNode), false);
lastNode = currentNode;
}
return model;
} else {
SessionToBehaviorModelTransformation.LOGGER.error("Empty user session creates empty model");
return model;
}
}
use of org.iobserve.stages.general.data.PayloadAwareEntryCallEvent in project iobserve-analysis by research-iobserve.
the class BehaviorModelDeserialization method deserialize.
public BehaviorModelGED deserialize() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
final JsonNode tree = mapper.readTree(this.input);
if (!(tree instanceof ObjectNode)) {
throw new IOException("Wrong format");
}
final ObjectNode jsonModel = (ObjectNode) tree;
final BehaviorModelGED model = new BehaviorModelGED();
// Read nodes
final JsonNode jsonNode = jsonModel.get("nodes");
final Iterator<String> nodeIterator = jsonNode.fieldNames();
while (nodeIterator.hasNext()) {
final String operationSignature = nodeIterator.next();
model.getNodes().put(operationSignature, new BehaviorModelNode(operationSignature));
}
// Read edges
final JsonNode jsonEdges = jsonModel.get("edges");
final Iterator<JsonNode> edgeIterator = jsonEdges.elements();
while (edgeIterator.hasNext()) {
final JsonNode jsonEdge = edgeIterator.next();
final String source = jsonEdge.get("source").get("name").asText();
final String target = jsonEdge.get("target").get("name").asText();
final BehaviorModelNode sourceMatch = model.getNodes().get(source);
final BehaviorModelNode targetMatch = model.getNodes().get(target);
final BehaviorModelEdge newEdge = new BehaviorModelEdge(sourceMatch, targetMatch);
model.getEdges().add(newEdge);
sourceMatch.getOutgoingEdges().put(targetMatch, newEdge);
targetMatch.getIngoingEdges().put(sourceMatch, newEdge);
// Read event groups
final JsonNode jsonEventGroups = jsonEdge.get("eventGroups");
final Iterator<JsonNode> eventGroupIterator = jsonEventGroups.elements();
while (eventGroupIterator.hasNext()) {
final JsonNode jsonEventGroup = eventGroupIterator.next();
final Iterator<JsonNode> eventIterator = jsonEventGroup.get("events").elements();
final List<PayloadAwareEntryCallEvent> events = new ArrayList<>();
while (eventIterator.hasNext()) {
final JsonNode jsonEvent = eventIterator.next();
final String operationSignature = jsonEvent.get("operationSignature").asText();
final String[] parameters = mapper.treeToValue(jsonEvent.get("parameters"), String[].class);
final String[] values = mapper.treeToValue(jsonEvent.get("values"), String[].class);
final PayloadAwareEntryCallEvent event = new PayloadAwareEntryCallEvent(0, 0, operationSignature, operationSignature, "", "", parameters, values, 0);
events.add(event);
}
final EventGroup group = new EventGroup(events.get(0).getParameters());
group.getEvents().addAll(events);
newEdge.getEventGroups().add(group);
}
}
return model;
}
Aggregations