Search in sources :

Example 1 with PayloadAwareEntryCallEvent

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();
}
Also used : PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) SessionStartEvent(org.iobserve.common.record.SessionStartEvent) SessionEndEvent(org.iobserve.common.record.SessionEndEvent) UserSession(org.iobserve.analysis.session.data.UserSession) ISessionEvent(org.iobserve.common.record.ISessionEvent)

Example 2 with PayloadAwareEntryCallEvent

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));
        }
    }
}
Also used : CorrespondenceUtility(org.iobserve.model.CorrespondenceUtility) UserSessionCollectionModel(org.iobserve.analysis.data.UserSessionCollectionModel) List(java.util.List) AbstractConsumerStage(teetime.framework.AbstractConsumerStage) UserSession(org.iobserve.analysis.session.data.UserSession) Map(java.util.Map) CorrespondenceModel(org.iobserve.model.correspondence.CorrespondenceModel) HashMap(java.util.HashMap) Repository(org.palladiosimulator.pcm.repository.Repository) Collectors(java.util.stream.Collectors) OutputPort(teetime.framework.OutputPort) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) Repository(org.palladiosimulator.pcm.repository.Repository) UserSessionCollectionModel(org.iobserve.analysis.data.UserSessionCollectionModel) UserSession(org.iobserve.analysis.session.data.UserSession)

Example 3 with PayloadAwareEntryCallEvent

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);
    }
}
Also used : CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Pair(org.apache.commons.math3.util.Pair) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayList(java.util.ArrayList) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) IRepresentativeStrategy(org.iobserve.analysis.behavior.models.data.configuration.IRepresentativeStrategy) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) List(java.util.List) SingleOrNoneCollector(org.iobserve.analysis.behavior.SingleOrNoneCollector) CallInformation(org.iobserve.analysis.behavior.models.extended.CallInformation) Map(java.util.Map) Optional(java.util.Optional) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList)

Example 4 with PayloadAwareEntryCallEvent

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;
    }
}
Also used : PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) EntryCallEdge(org.iobserve.analysis.behavior.models.extended.EntryCallEdge) EntryCallNode(org.iobserve.analysis.behavior.models.extended.EntryCallNode) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) BehaviorModel(org.iobserve.analysis.behavior.models.extended.BehaviorModel)

Example 5 with PayloadAwareEntryCallEvent

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;
}
Also used : BehaviorModelNode(org.iobserve.service.behavior.analysis.model.BehaviorModelNode) BehaviorModelEdge(org.iobserve.service.behavior.analysis.model.BehaviorModelEdge) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) EventGroup(org.iobserve.service.behavior.analysis.model.EventGroup) BehaviorModelGED(org.iobserve.service.behavior.analysis.model.BehaviorModelGED) PayloadAwareEntryCallEvent(org.iobserve.stages.general.data.PayloadAwareEntryCallEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)11 ArrayList (java.util.ArrayList)6 List (java.util.List)4 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 UserSession (org.iobserve.analysis.session.data.UserSession)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Arrays (java.util.Arrays)2 Optional (java.util.Optional)2 Pair (org.apache.commons.math3.util.Pair)2 SingleOrNoneCollector (org.iobserve.analysis.behavior.SingleOrNoneCollector)2 CallInformation (org.iobserve.analysis.behavior.models.extended.CallInformation)2 BehaviorModelGED (org.iobserve.service.behavior.analysis.model.BehaviorModelGED)2 BehaviorModelNode (org.iobserve.service.behavior.analysis.model.BehaviorModelNode)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2