Search in sources :

Example 1 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour in project iobserve-analysis by research-iobserve.

the class UsageModelProviderTest method createThenUpdateThenReadUpdated.

@Override
@Test
public void createThenUpdateThenReadUpdated() {
    final ModelProvider<UsageModel> modelProvider = new ModelProvider<>(UsageModelProviderTest.graph);
    final TestModelBuilder testModelBuilder = new TestModelBuilder();
    final UsageModel writtenModel = testModelBuilder.getUsageModel();
    final UsageModel readModel;
    final UsageScenario writtenUsageScenarioGroup0 = testModelBuilder.getUsageScenarioGroup0();
    final ScenarioBehaviour writtenBuyBookScenarioBehaviour = testModelBuilder.getBuyBookScenarioBehaviour();
    final EntryLevelSystemCall writtenGetQueryCall = testModelBuilder.getGetQueryCall();
    final EntryLevelSystemCall writtenGetPriceCall = testModelBuilder.getGetPriceCall();
    modelProvider.createComponent(writtenModel);
    // Update the model by adding a loop for choosing several books
    final Loop shoppingLoop = UsagemodelFactory.eINSTANCE.createLoop();
    final PCMRandomVariable loopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
    final ScenarioBehaviour chooseBookBehaviour = UsagemodelFactory.eINSTANCE.createScenarioBehaviour();
    chooseBookBehaviour.setEntityName("Choose a book");
    chooseBookBehaviour.getActions_ScenarioBehaviour().add(writtenGetQueryCall);
    chooseBookBehaviour.getActions_ScenarioBehaviour().add(writtenGetPriceCall);
    writtenUsageScenarioGroup0.setEntityName("Updated " + writtenUsageScenarioGroup0.getEntityName());
    writtenBuyBookScenarioBehaviour.getActions_ScenarioBehaviour().remove(writtenGetQueryCall);
    writtenBuyBookScenarioBehaviour.getActions_ScenarioBehaviour().remove(writtenGetPriceCall);
    writtenBuyBookScenarioBehaviour.getActions_ScenarioBehaviour().add(shoppingLoop);
    writtenGetQueryCall.setScenarioBehaviour_AbstractUserAction(chooseBookBehaviour);
    writtenGetPriceCall.setScenarioBehaviour_AbstractUserAction(chooseBookBehaviour);
    shoppingLoop.setEntityName("Shopping loop");
    shoppingLoop.setScenarioBehaviour_AbstractUserAction(writtenBuyBookScenarioBehaviour);
    shoppingLoop.setBodyBehaviour_Loop(chooseBookBehaviour);
    shoppingLoop.setLoopIteration_Loop(loopIteration);
    loopIteration.setLoop_LoopIteration(shoppingLoop);
    loopIteration.setSpecification("2");
    modelProvider.updateComponent(UsageModel.class, writtenModel);
    readModel = modelProvider.readOnlyRootComponent(UsageModel.class);
    Assert.assertTrue(this.equalityHelper.equals(writtenModel, readModel));
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) EntryLevelSystemCall(org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) Test(org.junit.Test)

Example 2 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour in project iobserve-analysis by research-iobserve.

the class UsageModelFactory method createBranchTransition.

/**
 * Create empty {@link BranchTransition} with the given parent. A {@link ScenarioBehaviour} is
 * added to the body of the branch transition, in order to make it possible adding further model
 * elements.
 *
 * @param parent
 *            branch to add transition to
 * @return created branch transition
 */
public static BranchTransition createBranchTransition(final Branch parent) {
    // create branch transition
    final BranchTransition branchTransition = UsagemodelFactory.eINSTANCE.createBranchTransition();
    branchTransition.setBranch_BranchTransition(parent);
    parent.getBranchTransitions_Branch().add(branchTransition);
    // create body of branch transition
    final ScenarioBehaviour bodyScenarioBehaviour = UsageModelFactory.createScenarioBehaviour();
    branchTransition.setBranchedBehaviour_BranchTransition(bodyScenarioBehaviour);
    return branchTransition;
}
Also used : ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour) BranchTransition(org.palladiosimulator.pcm.usagemodel.BranchTransition)

Example 3 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour in project iobserve-analysis by research-iobserve.

the class UsageModelFactory method createUsageScenario.

/**
 * Create new usage scenario and add it to the passed usage model.
 *
 * @param name
 *            of the usage scenario
 * @param usageModel
 *            the usage scenario is added to
 * @return created usage scenario
 */
public static UsageScenario createUsageScenario(final String name, final UsageModel usageModel) {
    // create the usage scenario
    final UsageScenario usageScenario = UsagemodelFactory.eINSTANCE.createUsageScenario();
    usageScenario.setEntityName(name);
    usageScenario.setUsageModel_UsageScenario(usageModel);
    usageModel.getUsageScenario_UsageModel().add(usageScenario);
    // create a scenario behavior
    final ScenarioBehaviour scenarioBehaviour = UsageModelFactory.createScenarioBehaviour();
    usageScenario.setScenarioBehaviour_UsageScenario(scenarioBehaviour);
    return usageScenario;
}
Also used : UsageScenario(org.palladiosimulator.pcm.usagemodel.UsageScenario) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)

Example 4 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour in project iobserve-analysis by research-iobserve.

the class UsageModelFactory method createLoop.

/**
 * Create loop in given parent {@link ScenarioBehaviour}. A {@link ScenarioBehaviour} is added
 * to the body of the loop, in order to make it possible adding further model elements.
 *
 * @param name
 *            name of loop
 * @param parent
 *            parent
 * @return created loop
 */
public static Loop createLoop(final String name, final ScenarioBehaviour parent) {
    // create the loop
    final Loop loop = UsagemodelFactory.eINSTANCE.createLoop();
    loop.setEntityName(name);
    parent.getActions_ScenarioBehaviour().add(loop);
    // create the body scenario behavior
    final ScenarioBehaviour bodyScenarioBehaviour = UsageModelFactory.createScenarioBehaviour();
    loop.setBodyBehaviour_Loop(bodyScenarioBehaviour);
    return loop;
}
Also used : Loop(org.palladiosimulator.pcm.usagemodel.Loop) ScenarioBehaviour(org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)

Example 5 with ScenarioBehaviour

use of org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour in project iobserve-analysis by research-iobserve.

the class SimpleSequenceReference method getModel.

/**
 * Creates a reference model that contains a simple sequence of calls. Accordingly, user
 * sessions whose call sequences contain a simple call sequence are created. (RQ-1.1) It is also
 * used to evaluate the accuracy of workload specifications. Therefore, varying workload is
 * generated by random entry and exit times of the user sessions, a random number of user
 * sessions for a closed workload specification and a random mean inter arrival time for an open
 * workload specification (RQ-1.9)
 *
 * @param referenceUsageModelFileName
 *            file name of the reference model to store its result
 * @param repositoryLookupModel
 *            repository lookup model
 * @param correspondenceModel
 *            correspondence model
 * @param thinkTime
 *            of a closed workload.
 * @param isClosedWorkload
 *            decides whether a closed or an open workload is created
 * @return the reference usage model, a corresponding EntryCallSequenceModel and a reference
 *         workload
 * @throws IOException
 *             on error
 */
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModel, final ICorrespondence correspondenceModel, final int thinkTime, final boolean isClosedWorkload) throws IOException {
    // Creates 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 numberOfUsersSessions = TestHelper.getRandomInteger(200, 1);
    final int numberOfCalls = TestHelper.getRandomInteger(5, 1);
    final EntryCallSequenceModel entryCallSequenceModel = new EntryCallSequenceModel(TestHelper.getUserSessions(numberOfUsersSessions));
    final ReferenceElements referenceElements = 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);
    AbstractUserAction lastAction = start;
    Optional<Correspondent> correspondent;
    // created
    for (int i = 0; i < numberOfCalls; i++) {
        if (i >= 0 && i < 5) {
            correspondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
        } else {
            throw new IllegalArgumentException("Illegal value of model element parameter");
        }
        if (correspondent.isPresent()) {
            final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent.get());
            UsageModelFactory.addUserAction(scenarioBehaviour, entryLevelSystemCall);
            UsageModelFactory.connect(lastAction, entryLevelSystemCall);
            lastAction = entryLevelSystemCall;
        }
    }
    UsageModelFactory.connect(lastAction, stop);
    // 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 are set randomly
    // to evaluate a closed workload. For the evaluation of an open workload the mean inter
    // arrival time is set randomly
    int entryTime = 0;
    int exitTime = 1;
    final int meanInterArrivalTime = TestHelper.getRandomInteger(30, 1);
    for (int i = 0; i < entryCallSequenceModel.getUserSessions().size(); i++) {
        if (isClosedWorkload) {
            entryTime = TestHelper.getRandomInteger(30, 1);
            exitTime = entryTime + 1;
        } else {
            entryTime += meanInterArrivalTime;
            exitTime += meanInterArrivalTime;
        }
        for (int k = 0; k < numberOfCalls; k++) {
            EntryCallEvent entryCallEvent = null;
            if (k >= 0 && k < 5) {
                entryCallEvent = new EntryCallEvent(entryTime, exitTime, ReferenceUsageModelBuilder.OPERATION_SIGNATURE[k], ReferenceUsageModelBuilder.CLASS_SIGNATURE[k], 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, the EntryCallSequenceModel
    // and the workload 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. Alike, the by our approach calculated workload can be matched against the
    // reference workload. This is done by {@link
    // org.iobserve.analysis.userbehavior.test.WorkloadEvaluation}
    TestHelper.saveModel(usageModel, referenceUsageModelFileName);
    referenceElements.setEntryCallSequenceModel(entryCallSequenceModel);
    referenceElements.setUsageModel(usageModel);
    referenceElements.setMeanInterArrivalTime(meanInterArrivalTime + numberOfCalls * 2);
    referenceElements.setMeanConcurrentUserSessions(SimpleSequenceReference.calculateTheNumberOfConcurrentUsers(entryCallSequenceModel.getUserSessions()));
    return referenceElements;
}
Also used : 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) 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)

Aggregations

ScenarioBehaviour (org.palladiosimulator.pcm.usagemodel.ScenarioBehaviour)21 UsageScenario (org.palladiosimulator.pcm.usagemodel.UsageScenario)12 EntryLevelSystemCall (org.palladiosimulator.pcm.usagemodel.EntryLevelSystemCall)10 Start (org.palladiosimulator.pcm.usagemodel.Start)10 Stop (org.palladiosimulator.pcm.usagemodel.Stop)10 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)10 Correspondent (org.iobserve.model.correspondence.Correspondent)9 Loop (org.palladiosimulator.pcm.usagemodel.Loop)9 AbstractUserAction (org.palladiosimulator.pcm.usagemodel.AbstractUserAction)8 BranchTransition (org.palladiosimulator.pcm.usagemodel.BranchTransition)8 EntryCallSequenceModel (org.iobserve.analysis.data.EntryCallSequenceModel)7 PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)7 ReferenceElements (org.iobserve.analysis.userbehavior.ReferenceElements)6 EntryCallEvent (org.iobserve.stages.general.data.EntryCallEvent)4 ArrayList (java.util.ArrayList)3 Branch (org.palladiosimulator.pcm.usagemodel.Branch)3 HashMap (java.util.HashMap)2 Branch (org.iobserve.analysis.userbehavior.data.Branch)2 List (java.util.List)1 UserSession (org.iobserve.analysis.session.data.UserSession)1