Search in sources :

Example 21 with PCMRandomVariable

use of org.palladiosimulator.pcm.core.PCMRandomVariable in project iobserve-analysis by research-iobserve.

the class PcmUsageModelBuilder method createLoop.

/**
 * Creates for a loop element a corresponding PCM loop including a corresponding usage scenario.
 *
 * @param scenarioBehaviour
 *            to that the PCM loop is added
 * @param loopElement
 *            that is transformed to a PCM loop
 * @return a PCM loop
 */
private Loop createLoop(final ScenarioBehaviour scenarioBehaviour, final LoopElement loopElement) {
    final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
    final ScenarioBehaviour loopScenarioBehaviour = this.transformSequenceToScenarioBehavior(0, loopElement.getLoopSequence(), null);
    // Set behavior of the loop
    loop.setBodyBehaviour_Loop(loopScenarioBehaviour);
    final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
    pcmLoopIteration.setSpecification(String.valueOf(loopElement.getLoopCount()));
    // Set number of loops
    loop.setLoopIteration_Loop(pcmLoopIteration);
    return loop;
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable)

Example 22 with PCMRandomVariable

use of org.palladiosimulator.pcm.core.PCMRandomVariable in project iobserve-analysis by research-iobserve.

the class SimpleLoopReference method getModel.

/**
 * Creates a reference model that contains a loop element. Accordingly, user sessions whose call
 * sequences contain iterated calls are created.(RQ-1.3)
 *
 * @param referenceUsageModelFileName
 *            reference usage model file name
 * @param repositoryLookupModelProvider
 *            repository model provider
 * @param correspondenceModel
 *            correspondence model
 *
 * @return the reference usage model and a corresponding EntryCallSequenceModel
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModelProvider, final ICorrespondence correspondenceModel) throws IOException {
    // Create a random number of user sessions and random model element parameters. The user
    // sessions' behavior will be created according to the reference usage model and
    // subsequently the user sessions are used to create a usage model. The created usage model
    // is matched against the reference usage model
    final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 1);
    final int loopCount = TestHelper.getRandomInteger(5, 2);
    final int numberOfIteratedCalls = TestHelper.getRandomInteger(5, 1);
    final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    final ReferenceElements referenceElements = new ReferenceElements();
    // In the following the reference usage model is created
    AbstractUserAction lastAction;
    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);
    // A loop is created and the loop count is set
    final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
    UsageModelFactory.connect(start, loop);
    final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
    pcmLoopIteration.setSpecification(String.valueOf(loopCount));
    loop.setLoopIteration_Loop(pcmLoopIteration);
    UsageModelFactory.connect(loop, stop);
    // The EntryLevelSystemCalls that are iterated are added to the loop element
    final Start loopStart = UsageModelFactory.createAddStartAction("", loop.getBodyBehaviour_Loop());
    final Stop loopStop = UsageModelFactory.createAddStopAction("", loop.getBodyBehaviour_Loop());
    lastAction = loopStart;
    Optional<Correspondent> optionCorrespondent;
    // iterated calls to the loop
    for (int i = 0; i < numberOfIteratedCalls; i++) {
        if (i >= 0 && i < 5) {
            optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
        } else {
            throw new IllegalArgumentException("Illegal value of model element parameter");
        }
        if (optionCorrespondent.isPresent()) {
            final Correspondent correspondent = optionCorrespondent.get();
            final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondent);
            UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), entryLevelSystemCall);
            UsageModelFactory.connect(lastAction, entryLevelSystemCall);
            lastAction = entryLevelSystemCall;
        }
    }
    UsageModelFactory.connect(lastAction, loopStop);
    // According to the reference usage model user sessions are created that exactly represent
    // the user behavior of the reference usage model. The entry and exit times enable that the
    // calls within the user sessions are ordered according to the reference usage model
    int entryTime = 1;
    int exitTime = 2;
    for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
        entryTime = 1;
        exitTime = 2;
        // number of iterated calls
        for (int k = 0; k < loopCount; k++) {
            for (int j = 0; j < numberOfIteratedCalls; j++) {
                EntryCallEvent entryCallEvent = null;
                if (j >= 0 && j < 5) {
                    entryCallEvent = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[j], ReferenceUsageModelBuilder.CLASS_SIGNATURE[j], String.valueOf(i), "hostname");
                } else {
                    throw new IllegalArgumentException("Illegal value of model element parameter");
                }
                entryCallSequenceModel.getUserSessions().get(i).add(entryCallEvent, true);
                entryTime = entryTime + 2;
                exitTime = exitTime + 2;
            }
        }
    }
    // 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);
    referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
    referenceElements.setUsageModel(usageModel);
    return referenceElements;
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) 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) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) Correspondent(org.iobserve.model.correspondence.Correspondent) ReferenceElements(org.iobserve.analysis.userbehavior.ReferenceElements)

Example 23 with PCMRandomVariable

use of org.palladiosimulator.pcm.core.PCMRandomVariable in project Palladio-Editors-Sirius by PalladioSimulator.

the class AddHDDProcessingResourceSpecification method execute.

@Override
public void execute(final Collection<? extends EObject> selections, final Map<String, Object> parameters) {
    final Object parameter = parameters.get(NEW_HDD_PROCESSING_RESOURCE_SPECIFICATION);
    if (parameter == null || !(parameter instanceof HDDProcessingResourceSpecification)) {
        return;
    }
    final HDDProcessingResourceSpecification hddProcessingResourceSpecification = (HDDProcessingResourceSpecification) parameter;
    // 1. dialog
    final ProcessingResourceType prt = getResourceType(hddProcessingResourceSpecification);
    if (prt != null) {
        hddProcessingResourceSpecification.setActiveResourceType_ActiveResourceSpecification(prt);
    } else {
        return;
    }
    // set processing rate always to 1
    final PCMRandomVariable processingRate = CoreFactory.eINSTANCE.createPCMRandomVariable();
    processingRate.setSpecification("1");
    hddProcessingResourceSpecification.setProcessingRate_ProcessingResourceSpecification(processingRate);
    // 4. dialog
    final SchedulingPolicy sp = getSchedulingPolicy(hddProcessingResourceSpecification);
    if (sp != null) {
        hddProcessingResourceSpecification.setSchedulingPolicy(sp);
    } else {
        return;
    }
}
Also used : HDDProcessingResourceSpecification(org.palladiosimulator.pcm.resourceenvironment.HDDProcessingResourceSpecification) EObject(org.eclipse.emf.ecore.EObject) ProcessingResourceType(org.palladiosimulator.pcm.resourcetype.ProcessingResourceType) SchedulingPolicy(org.palladiosimulator.pcm.resourcetype.SchedulingPolicy) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable)

Example 24 with PCMRandomVariable

use of org.palladiosimulator.pcm.core.PCMRandomVariable in project iobserve-analysis by research-iobserve.

the class LoopWithinBranchReference method createBranch.

/**
 * Creates a branch and branch transitions according to the random countOfBranchTransitions.
 *
 * @param scenarioBehaviour
 * @param repositoryLookupModel
 * @param correspondenceModel
 * @param numberOfBranchTransitions
 * @param lengthOfBranchSequence
 * @param countOfLoop
 * @return
 */
private static Branch createBranch(final RepositoryLookupModelProvider repositoryLookupModel, final ScenarioBehaviour scenarioBehaviour, final CorrespondenceModel correspondenceModel, final int numberOfBranchTransitions, final int lengthOfBranchSequence, final int countOfLoop) {
    final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
    final Branch branch = UsageModelFactory.createBranch("", scenarioBehaviour);
    final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
    UsageModelFactory.connect(start, branch);
    UsageModelFactory.connect(branch, stop);
    AbstractUserAction lastAction = start;
    // For each branch transition its calls are added to the branch transition
    for (int i = 0; i < numberOfBranchTransitions; i++) {
        final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branch);
        final ScenarioBehaviour branchTransitionBehaviour = branchTransition.getBranchedBehaviour_BranchTransition();
        final Start startBranchTransition = UsageModelFactory.createStart("");
        UsageModelFactory.addUserAction(branchTransitionBehaviour, startBranchTransition);
        final Stop stopBranchTransition = UsageModelFactory.createStop("");
        UsageModelFactory.addUserAction(branchTransitionBehaviour, stopBranchTransition);
        lastAction = startBranchTransition;
        if (i >= 0 && i < 3) {
            final OperationSignature operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
            if (operationSignature != null) {
                final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operationSignature);
                UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
                UsageModelFactory.connect(lastAction, entryLevelSystemCall);
                lastAction = entryLevelSystemCall;
            }
        } else {
            throw new IllegalArgumentException("Illegal value of model element parameter");
        }
        if (lengthOfBranchSequence == 2) {
            final OperationSignature operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[4], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[4]);
            if (operationSignature != null) {
                final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operationSignature);
                UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
                UsageModelFactory.connect(lastAction, entryLevelSystemCall);
                lastAction = entryLevelSystemCall;
            }
        }
        // Within the branch transition a loop element is created
        final Loop loop = UsageModelFactory.createLoop("", branchTransitionBehaviour);
        UsageModelFactory.connect(lastAction, loop);
        final PCMRandomVariable pcmLoop2Iteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
        pcmLoop2Iteration.setSpecification(String.valueOf(countOfLoop));
        loop.setLoopIteration_Loop(pcmLoop2Iteration);
        final Start loopStart = UsageModelFactory.createStart("");
        UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStart);
        final Stop loopStop = UsageModelFactory.createStop("");
        UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStop);
        lastAction = loopStart;
        // The calls that are iterated are added to the loop
        final OperationSignature operationSignature;
        switch(i) {
            case 0:
                operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[1], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[1]);
                break;
            case 1:
                operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[2], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[2]);
                break;
            case 2:
                operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[0], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[0]);
                break;
            default:
                throw new IllegalArgumentException("Illegal value of model element parameter");
        }
        if (operationSignature != null) {
            final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operationSignature);
            UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), entryLevelSystemCall);
            UsageModelFactory.connect(lastAction, entryLevelSystemCall);
            lastAction = entryLevelSystemCall;
        }
        UsageModelFactory.connect(lastAction, loopStop);
        UsageModelFactory.connect(loop, stopBranchTransition);
    }
    return branch;
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) Repository(org.palladiosimulator.pcm.repository.Repository) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) OperationSignature(org.palladiosimulator.pcm.repository.OperationSignature) Branch(org.palladiosimulator.pcm.usagemodel.Branch) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition)

Example 25 with PCMRandomVariable

use of org.palladiosimulator.pcm.core.PCMRandomVariable in project iobserve-analysis by research-iobserve.

the class SimpleLoopReferenceHelper method getModel.

/**
 * Creates a reference model that contains a loop element. Accordingly, user sessions whose call
 * sequences contain iterated calls are created.(RQ-1.3)
 *
 * @param referenceUsageModelFileName
 *            reference usage model file name
 * @param repositoryLookupModelProvider
 *            repository model provider
 * @param correspondenceModel
 *            correspondence model
 *
 * @return the reference usage model and a corresponding EntryCallSequenceModel
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModelProvider, final CorrespondenceModel correspondenceModel) throws IOException {
    // Create a random number of user sessions and random model element parameters. The user
    // sessions' behavior will be created according to the reference usage model and
    // subsequently the user sessions are used to create a usage model. The created usage model
    // is matched against the reference usage model
    final int numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 1);
    final int loopCount = TestHelper.getRandomInteger(5, 2);
    final int numberOfIteratedCalls = TestHelper.getRandomInteger(5, 1);
    final UserSessionCollectionModel entryCallSequenceModel = new UserSessionCollectionModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
    final ReferenceElements referenceElements = new ReferenceElements();
    // In the following the reference usage model is created
    AbstractUserAction lastAction;
    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);
    // A loop is created and the loop count is set
    final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
    UsageModelFactory.connect(start, loop);
    final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
    pcmLoopIteration.setSpecification(String.valueOf(loopCount));
    loop.setLoopIteration_Loop(pcmLoopIteration);
    UsageModelFactory.connect(loop, stop);
    // The EntryLevelSystemCalls that are iterated are added to the loop element
    final Start loopStart = UsageModelFactory.createAddStartAction("", loop.getBodyBehaviour_Loop());
    final Stop loopStop = UsageModelFactory.createAddStopAction("", loop.getBodyBehaviour_Loop());
    lastAction = loopStart;
    // iterated calls to the loop
    for (int i = 0; i < numberOfIteratedCalls; i++) {
        if (i >= 0 && i < 5) {
            final OperationSignature operationSignature = CorrespondenceUtility.findModelElementForOperation(correspondenceModel, Repository.class, ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
            if (operationSignature != null) {
                final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModelProvider, operationSignature);
                UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), entryLevelSystemCall);
                UsageModelFactory.connect(lastAction, entryLevelSystemCall);
                lastAction = entryLevelSystemCall;
            }
        } else {
            throw new IllegalArgumentException("Illegal value of model element parameter");
        }
    }
    UsageModelFactory.connect(lastAction, loopStop);
    // According to the reference usage model user sessions are created that exactly represent
    // the user behavior of the reference usage model. The entry and exit times enable that the
    // calls within the user sessions are ordered according to the reference usage model
    int entryTime = 1;
    int exitTime = 2;
    for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
        entryTime = 1;
        exitTime = 2;
        // number of iterated calls
        for (int k = 0; k < loopCount; k++) {
            for (int j = 0; j < numberOfIteratedCalls; j++) {
                EntryCallEvent entryCallEvent = null;
                if (j >= 0 && j < 5) {
                    entryCallEvent = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[j], ReferenceUsageModelBuilder.CLASS_SIGNATURE[j], String.valueOf(i), "hostname");
                } else {
                    throw new IllegalArgumentException("Illegal value of model element parameter");
                }
                entryCallSequenceModel.getUserSessions().get(i).add(entryCallEvent, true);
                entryTime = entryTime + 2;
                exitTime = exitTime + 2;
            }
        }
    }
    // 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);
    referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
    referenceElements.setUsageModel(usageModel);
    return referenceElements;
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) Start(org.palladiosimulator.pcm.usagemodel.Start) Stop(org.palladiosimulator.pcm.usagemodel.Stop) EntryCallEvent(org.iobserve.stages.general.data.EntryCallEvent) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) AbstractUserAction(org.palladiosimulator.pcm.usagemodel.AbstractUserAction) UserSessionCollectionModel(org.iobserve.analysis.data.UserSessionCollectionModel) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) OperationSignature(org.palladiosimulator.pcm.repository.OperationSignature) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) ReferenceElements(org.iobserve.analysis.test.userbehavior.ReferenceElements)

Aggregations

PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)28 ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)15 Loop (org.palladiosimulator.pcm.usagemodel.Loop)14 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)11 UsageScenario (org.palladiosimulator.pcm.usagemodel.UsageScenario)11 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)10 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)10 Start (org.palladiosimulator.pcm.usagemodel.Start)10 Stop (org.palladiosimulator.pcm.usagemodel.Stop)10 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)6 StochasticExpressionEditDialog (org.palladiosimulator.editors.commons.dialogs.stoex.StochasticExpressionEditDialog)5 EntryCallSequenceModel (org.iobserve.analysis.data.EntryCallSequenceModel)4 UserSessionCollectionModel (org.iobserve.analysis.data.UserSessionCollectionModel)4 ReferenceElements (org.iobserve.analysis.test.userbehavior.ReferenceElements)4 ReferenceElements (org.iobserve.analysis.userbehavior.ReferenceElements)4 Correspondent (org.iobserve.model.correspondence.Correspondent)4 OperationSignature (org.palladiosimulator.pcm.repository.OperationSignature)4 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)4 ClosedWorkload (org.palladiosimulator.pcm.usagemodel.ClosedWorkload)3 ArrayList (java.util.ArrayList)2