Search in sources :

Example 21 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class TEntryCallSequenceFilter method execute.

@Override
protected void execute(final EntryCallSequenceModel entryCallSequenceModel) throws Exception {
    final List<UserSession> sessions = entryCallSequenceModel.getUserSessions().stream().map(this::filterSession).collect(Collectors.toList());
    final EntryCallSequenceModel filteredEntryCallSequenceModel = new EntryCallSequenceModel(sessions);
    this.outputPort.send(filteredEntryCallSequenceModel);
}
Also used : UserSession(org.iobserve.analysis.session.data.UserSession) EntryCallSequenceModel(org.iobserve.analysis.data.EntryCallSequenceModel)

Example 22 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class TBehaviorModelPreperation method executeEntryCallSequenceModel.

/**
 * Execute case object instanceof EntryCallSequenceModel.
 *
 * @param entryCallSequenceModel
 *            entryCallSequenceModel
 */
private void executeEntryCallSequenceModel(final EntryCallSequenceModel entryCallSequenceModel) {
    if (this.behaviorModelTable == null) {
        this.sequenceModelCache.add(entryCallSequenceModel);
    } else {
        final List<UserSession> userSessions = entryCallSequenceModel.getUserSessions();
        for (final UserSession userSession : userSessions) {
            final BehaviorModelTable modelTable = this.behaviorModelTable.getClearedCopy(this.keepEmptyTransitions);
            final List<EntryCallEvent> entryCalls = userSession.getEvents();
            EntryCallEvent lastCall = null;
            for (final EntryCallEvent eventCall : entryCalls) {
                final boolean isAllowed = modelTable.isAllowedSignature(eventCall);
                if (lastCall != null && isAllowed) {
                    modelTable.addTransition(lastCall, eventCall);
                    modelTable.addInformation(eventCall);
                } else if (isAllowed) {
                    // only called at first valid event
                    // (condition lastCall == null is not needed
                    modelTable.addInformation(eventCall);
                }
                lastCall = isAllowed ? eventCall : lastCall;
            }
            this.outputPort.send(modelTable);
        }
    }
}
Also used : BehaviorModelTable(org.iobserve.analysis.clustering.filter.models.BehaviorModelTable) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) UserSession(org.iobserve.analysis.session.data.UserSession)

Example 23 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class BranchWithinLoopReference method getModel.

/**
 * It creates a reference usage model that contains branches within loops. Accordingly, user
 * sessions whose call sequences differ from each other are iterated in a row. Thereby, at each
 * iteration of a branched call sequences the probabilities have to be equal because otherwise
 * it would not be an iteration (RQ-1.8)
 *
 * @param referenceUsageModelFileName
 *            reference usage model file name
 * @param repositoryLookupModel
 *            repository model builder
 * @param correspondenceModel
 *            correspondence model
 *
 * @return reference usage model and corresponding user sessions
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, final ICorrespondence correspondenceModel) throws IOException {
    // The number of model element parameters are created randomly. The number of user sessions
    // must be created accordingly to the number of branch transitions, because it must be
    // ensured that at each iteration of an branch the branch transition probabilities are
    // equal. This can be achieved by the same number of user sessions representing the branch
    // transition at each iteration
    final int numberOfLoops = TestHelper.getRandomInteger(3, 3);
    final int numberOfConcurrentUsers = (int) Math.pow(2, numberOfLoops) * 5;
    final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    final ReferenceElements testElements = new ReferenceElements();
    // In the following the reference usage model is created
    final UsageModel usageModel = UsageModelFactory.createUsageModel();
    final UsageScenario usageScenario = UsageModelFactory.createUsageScenario("", usageModel);
    final ScenarioBehaviour scenarioBehaviour = usageScenario.getScenarioBehaviour_UsageScenario();
    final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
    final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
    final AbstractUserAction lastAction = start;
    // The loop element is created that contains the iterated branch
    final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
    final ScenarioBehaviour loopScenarioBehaviour = loop.getBodyBehaviour_Loop();
    UsageModelFactory.connect(lastAction, loop);
    final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
    pcmLoopIteration.setSpecification(String.valueOf(numberOfLoops));
    // Set number of loops
    loop.setLoopIteration_Loop(pcmLoopIteration);
    UsageModelFactory.connect(loop, stop);
    final Start loopStart = UsageModelFactory.createAddStartAction("", loopScenarioBehaviour);
    final Stop loopStop = UsageModelFactory.createAddStopAction("", loopScenarioBehaviour);
    // The branch that is contained within the loop element is created
    final org.palladiosimulator.pcm.usagemodel.Branch branch = UsageModelFactory.createBranch("", loopScenarioBehaviour);
    UsageModelFactory.connect(loopStart, branch);
    // The branch transition 1 is created
    final BranchTransition branchTransition1 = BranchWithinLoopReference.createBranchTransition(2, repositoryLookupModel, branch, correspondenceModel);
    // The branch transition 2 is created
    final BranchTransition branchTransition2 = BranchWithinLoopReference.createBranchTransition(3, repositoryLookupModel, branch, correspondenceModel);
    final Optional<Correspondent> optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4]);
    if (optionCorrespondent.isPresent()) {
        final Correspondent correspondent = optionCorrespondent.get();
        final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
        UsageModelFactory.addUserAction(loopScenarioBehaviour, entryLevelSystemCall);
        UsageModelFactory.connect(branch, entryLevelSystemCall);
        UsageModelFactory.connect(entryLevelSystemCall, loopStop);
    }
    // User sessions according to the reference usage model are created. Thereby, it must be
    // ensured that each iteration of the branch the branch probabilities stay the same because
    // the branch is iterated. This can be achieved by an equal number of user sessions for each
    // branch transition at each iteration of the branch
    int countOfCallEvent3 = 0;
    int countOfCallEvent4 = 0;
    int entryTime = 1;
    int exitTime = 2;
    boolean branchDecision = false;
    // At each iteration the user sessions are distributed equally between the branch
    // transitions to ensure that the probabilities of the branch transitions stay equally
    final Map<Integer, List<List<UserSession>>> userSessionGroups = new HashMap<>();
    final List<List<UserSession>> startList = new ArrayList<>();
    startList.add(entryCallSequenceModel.getUserSessions());
    userSessionGroups.put(0, startList);
    // The loop that contains the branch
    for (int j = 0; j < numberOfLoops; j++) {
        countOfCallEvent3 = 0;
        countOfCallEvent4 = 0;
        final List<List<UserSession>> newUserSessionGroups = new ArrayList<>();
        // Ensures that the user sessions distribution stays equally
        for (int k = 0; k < userSessionGroups.get(j).size(); k++) {
            for (int i = 0; i < 2; i++) {
                final List<UserSession> userSessions = new ArrayList<>();
                newUserSessionGroups.add(userSessions);
            }
            final int indexGroupCallEvent3 = newUserSessionGroups.size() - 2;
            final int indexGroupCallEvent4 = newUserSessionGroups.size() - 1;
            for (int i = 0; i < userSessionGroups.get(j).get(k).size(); i++) {
                if (newUserSessionGroups.get(indexGroupCallEvent3).size() > newUserSessionGroups.get(indexGroupCallEvent4).size()) {
                    branchDecision = false;
                } else {
                    branchDecision = true;
                }
                // The branch within the loop
                if (branchDecision) {
                    BranchWithinLoopReference.createEntryCall(entryTime, exitTime, 2, k, j, i, userSessionGroups, newUserSessionGroups, indexGroupCallEvent3);
                    countOfCallEvent3++;
                    entryTime += 2;
                    exitTime += 2;
                } else {
                    BranchWithinLoopReference.createEntryCall(entryTime, exitTime, 3, k, j, i, userSessionGroups, newUserSessionGroups, indexGroupCallEvent4);
                    countOfCallEvent4++;
                    entryTime += 2;
                    exitTime += 2;
                }
                final EntryCallEvent entryCallEvent5 = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4], ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], String.valueOf(i), "hostname");
                userSessionGroups.get(j).get(k).get(i).add(entryCallEvent5, true);
                entryTime -= 2;
                exitTime -= 2;
            }
        }
        userSessionGroups.put(j + 1, newUserSessionGroups);
        entryTime += 2;
        exitTime += 2;
    }
    // Sets the likelihoods of branch transitions
    final double likelihoodOfCallEvent3 = (double) countOfCallEvent3 / (double) numberOfConcurrentUsers;
    final double likelihoodOfCallEvent4 = (double) countOfCallEvent4 / (double) numberOfConcurrentUsers;
    branchTransition1.setBranchProbability(likelihoodOfCallEvent3);
    branchTransition2.setBranchProbability(likelihoodOfCallEvent4);
    // Saves the reference usage model and sets the usage model and the EntryCallSequenceModel
    // as the reference elements. Our approach is now executed with the EntryCallSequenceModel
    // and the resulting usage model can be matched against the reference usage model
    TestHelper.saveModel(usageModel, referenceUsageModelFileName);
    testElements.setEntryCallSequenceModel(entryCallSequenceModel);
    testElements.setUsageModel(usageModel);
    return testElements;
}
Also used : Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EntryCallSequenceModel(org.iobserve.analysis.data.EntryCallSequenceModel) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UserSession(org.iobserve.analysis.session.data.UserSession) ReferenceElements(org.iobserve.analysis.userbehavior.ReferenceElements) ArrayList(java.util.ArrayList) List(java.util.List) Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition) Correspondent(org.iobserve.model.correspondence.Correspondent)

Example 24 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class BranchModelCreator method createCallBranchModel.

/**
 * It creates a BranchModel from an EntryCallSequenceModel. At that the single sequences are
 * aggregated to a tree-like structure: Equal sequences are summarized to one sequence,
 * alternative sequences are represented via branches.
 *
 * @param entryCallSequenceModel
 *            whose call sequences are aggregated to a coherent CallBranchModel
 * @return a BranchModel corresponding to the passed EntryCallSequenceModel
 */
public BranchModel createCallBranchModel(final EntryCallSequenceModel entryCallSequenceModel) {
    // Sets the user group's specific workload intensity and likelihood
    final BranchModel branchModel = new BranchModel(entryCallSequenceModel.getWorkloadIntensity(), entryCallSequenceModel.getLikelihoodOfUserGroup());
    final List<UserSession> userSessions = entryCallSequenceModel.getUserSessions();
    // The initial branch that contains the root node
    // Every sequence passes this branch -> likelihood of reaching this branch is 1
    final Branch rootBranch = new Branch();
    rootBranch.setBranchLikelihood(1);
    rootBranch.setBranchId(1);
    rootBranch.setTreeLevel(0);
    // Descending sort by call sequence length
    Collections.sort(userSessions, BranchModelCreator.SORT_USER_SESSION_BY_CALL_SEQUENCE_SIZE);
    // Initializes the root sequence with the longest call sequence
    this.setBranchSequence(rootBranch, userSessions.get(0).getEvents(), 0);
    int numberOfBranches = 1;
    // loops over all userSession without the first user session that initialized the rootBranch
    for (int j = 1; j < userSessions.size(); j++) {
        final UserSession userSession = userSessions.get(j);
        // The branchGuide guides through the tree structure. It determines the recent regarded
        // branch
        final List<Integer> branchGuide = new ArrayList<>();
        // The position states the recent position within the branch sequence
        int positionInBranch = 0;
        for (int i = 0; i <= userSession.getEvents().size(); i++) {
            // Determines which branch is currently examined
            final Branch examinedBranch = this.getExaminedBranch(branchGuide, rootBranch);
            if (i < userSession.getEvents().size()) {
                final EntryCallEvent callEvent = userSession.getEvents().get(i);
                // currently examined branch
                if (this.checkPositionMatchInBranch(callEvent, examinedBranch, positionInBranch)) {
                    this.incrementCountOfBranchElement(examinedBranch, positionInBranch);
                    positionInBranch++;
                    continue;
                }
                // a child branch
                if (this.isPositionLastElementInBranchSequence(examinedBranch, positionInBranch)) {
                    final int indexOfMatchingChildBranch = this.getIndexOfMatchingChildBranch(callEvent, examinedBranch);
                    if (indexOfMatchingChildBranch > -1) {
                        // Continue with the same call event but switching to the new branch
                        branchGuide.add(indexOfMatchingChildBranch);
                        // NOCS
                        i--;
                        positionInBranch = 0;
                        continue;
                    }
                }
                // No match could be found --> Split branch into child branches
                numberOfBranches = this.splitBranch(examinedBranch, positionInBranch, numberOfBranches, false, userSession, i);
                break;
            } else {
                // End of sequence -> looking for an exit element
                if (this.checkIfBranchSequenceTerminates(examinedBranch, positionInBranch)) {
                    this.incrementCountOfBranchElement(examinedBranch, positionInBranch);
                    break;
                }
                // Checks if there is an exit branch
                if (this.isPositionLastElementInBranchSequence(examinedBranch, positionInBranch)) {
                    final int indexOfMatchingChildBranch = this.getIndexOfMatchingExitBranch(examinedBranch);
                    if (indexOfMatchingChildBranch > -1) {
                        // Iterate the exit state adding but switching to the new branch
                        branchGuide.add(indexOfMatchingChildBranch);
                        // NOCS
                        i--;
                        positionInBranch = 0;
                        continue;
                    }
                }
                // No matching exit element found --> Split branch into child branches
                numberOfBranches = this.splitBranch(examinedBranch, positionInBranch, numberOfBranches, true, null, 0);
                break;
            }
        }
    }
    branchModel.setRootBranch(rootBranch);
    branchModel.setNumberOfBranches(numberOfBranches);
    return branchModel;
}
Also used : Branch(org.iobserve.analysis.userbehavior.data.Branch) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) UserSession(org.iobserve.analysis.session.data.UserSession) ArrayList(java.util.ArrayList) BranchModel(org.iobserve.analysis.userbehavior.data.BranchModel)

Example 25 with UserSession

use of org.iobserve.analysis.session.data.UserSession in project iobserve-analysis by research-iobserve.

the class ClusteringPrePostProcessing method getCallCountModel.

/**
 * Transforms the passed user sessions to counts of called operation signatures that can be used
 * for the similarity calculation of the user group clustering. The objective is to transform
 * each user session to a list that contains the number of calls of each distinct operation
 * signature. It parses through the entry call sequences of each user session and counts the
 * calls of each distinct operation signature. The result is a list of user sessions whose call
 * sequence is represented as counts of calls.
 *
 * @param userSessions
 *            are transformed to counts of calls
 * @param listOfDistinctOperationSignatures
 *            are the distinct operation signatures whose calls are counted for each user
 *            session
 * @return the passed user sessions as counts of calls
 */
public List<UserSessionAsCountsOfCalls> getCallCountModel(final List<UserSession> userSessions, final List<String> listOfDistinctOperationSignatures) {
    final List<UserSessionAsCountsOfCalls> callCountModel = new ArrayList<>();
    // during the user session
    for (final UserSession userSession : userSessions) {
        final UserSessionAsCountsOfCalls absoluteCountOfCalls = new UserSessionAsCountsOfCalls(userSession.getSessionId(), listOfDistinctOperationSignatures.size());
        final List<EntryCallEvent> callSequence = userSession.getEvents();
        for (int i = 0; i < callSequence.size(); i++) {
            final String currentCall = callSequence.get(i).getOperationSignature();
            final int indexOfCurrentCall = listOfDistinctOperationSignatures.indexOf(currentCall);
            absoluteCountOfCalls.getAbsoluteCountOfCalls()[indexOfCurrentCall] = absoluteCountOfCalls.getAbsoluteCountOfCalls()[indexOfCurrentCall] + 1;
        }
        callCountModel.add(absoluteCountOfCalls);
    }
    return callCountModel;
}
Also used : UserSessionAsCountsOfCalls(org.iobserve.analysis.userbehavior.data.UserSessionAsCountsOfCalls) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) UserSession(org.iobserve.analysis.session.data.UserSession) ArrayList(java.util.ArrayList)

Aggregations

UserSession (org.iobserve.analysis.session.data.UserSession)39 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)16 ArrayList (java.util.ArrayList)14 UserSessionCollectionModel (org.iobserve.analysis.data.UserSessionCollectionModel)8 EntryCallSequenceModel (org.iobserve.analysis.data.EntryCallSequenceModel)5 HashMap (java.util.HashMap)3 List (java.util.List)3 PayloadAwareEntryCallEvent (org.iobserve.stages.general.data.PayloadAwareEntryCallEvent)3 Random (java.util.Random)2 PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)2 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)2 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)2 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)2 Loop (org.palladiosimulator.pcm.usagemodel.Loop)2 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)2 Start (org.palladiosimulator.pcm.usagemodel.Start)2 Stop (org.palladiosimulator.pcm.usagemodel.Stop)2 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)2 UsageScenario (org.palladiosimulator.pcm.usagemodel.UsageScenario)2 HashSet (java.util.HashSet)1