use of org.palladiosimulator.pcm.usagemodel.AbstractUserAction in project Palladio-Editors-Sirius by PalladioSimulator.
the class ReconnectSourceOfUsageFlow method execute.
@Override
public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {
AbstractUserAction oldSource = (AbstractUserAction) parameters.get("source");
AbstractUserAction newSource = (AbstractUserAction) parameters.get("target");
DRepresentationElement otherEnd = (DRepresentationElement) parameters.get("otherEnd");
// disallow self looping
if (!otherEnd.getTarget().equals(newSource)) {
newSource.setSuccessor((AbstractUserActionImpl) otherEnd.getTarget());
oldSource.setSuccessor(null);
}
}
use of org.palladiosimulator.pcm.usagemodel.AbstractUserAction 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;
}
use of org.palladiosimulator.pcm.usagemodel.AbstractUserAction 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 ICorrespondence 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 Optional<Correspondent> optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
if (optionCorrespondent.isPresent()) {
final Correspondent correspondent = optionCorrespondent.get();
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
} else {
throw new IllegalArgumentException("Illegal value of model element parameter");
}
if (lengthOfBranchSequence == 2) {
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(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 Optional<Correspondent> optionCorrespondent;
switch(i) {
case 0:
optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[1], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[1]);
break;
case 1:
optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[2], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[2]);
break;
case 2:
optionCorrespondent = correspondenceModel.getCorrespondent(ReferenceUsageModelBuilder.CLASS_SIGNATURE[0], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[0]);
break;
default:
throw new IllegalArgumentException("Illegal value of model element parameter");
}
if (optionCorrespondent.isPresent()) {
final Correspondent correspondent = optionCorrespondent.get();
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, correspondent);
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
UsageModelFactory.connect(lastAction, loopStop);
UsageModelFactory.connect(loop, stopBranchTransition);
}
return branch;
}
use of org.palladiosimulator.pcm.usagemodel.AbstractUserAction in project iobserve-analysis by research-iobserve.
the class UserBehaviorEvaluation method getModelElements.
/**
* Extracts for a scenario behavior the model elements.
*
* @param scenarioBehaviour
* whose model elements are extracted
* @param modelElements
* the list to that the model elements are added
*/
private static void getModelElements(final ScenarioBehaviour scenarioBehaviour, final List<ModelElement> modelElements) {
final List<AbstractUserAction> actionsOfScenarioBehaviour = scenarioBehaviour.getActions_ScenarioBehaviour();
AbstractUserAction nextActionOfScenarioBehaviour = actionsOfScenarioBehaviour.get(0);
// element
while (nextActionOfScenarioBehaviour != null) {
if (nextActionOfScenarioBehaviour.getClass().equals(StartImpl.class)) {
final ModelElement modelElement = new ModelElement(true, false, false, false, false, "", "", 0);
modelElements.add(modelElement);
} else if (nextActionOfScenarioBehaviour.getClass().equals(StopImpl.class)) {
final ModelElement modelElement = new ModelElement(false, true, false, false, false, "", "", 0);
modelElements.add(modelElement);
} else if (nextActionOfScenarioBehaviour.getClass().equals(EntryLevelSystemCallImpl.class)) {
final EntryLevelSystemCall call = (EntryLevelSystemCall) nextActionOfScenarioBehaviour;
final ModelElement modelElement = new ModelElement(false, false, true, false, false, call.getEntityName(), "", 0);
modelElements.add(modelElement);
} else if (nextActionOfScenarioBehaviour.getClass().equals(LoopImpl.class)) {
final Loop loop = (Loop) nextActionOfScenarioBehaviour;
final ModelElement modelElement = new ModelElement(false, false, false, false, true, "", loop.getLoopIteration_Loop().getSpecification(), 0);
modelElements.add(modelElement);
UserBehaviorEvaluation.getModelElements(loop.getBodyBehaviour_Loop(), modelElements);
} else if (nextActionOfScenarioBehaviour.getClass().equals(BranchImpl.class)) {
final Branch branch = (Branch) nextActionOfScenarioBehaviour;
// Because the branch transitions of the usage models are not always in the same
// order, we order the branch transitions by the entity name of their first
// EntryLevelSystemCall. In doing so, the model elements of each usage model are
// added in the same order independently of the ordering of the usage model. The
// ordering of the branch transitions does not affect the accuracy of an usage model
// and is created randomly within the usage model and can not be influenced.
final List<BranchTransition> branchTransitionsSorted = UserBehaviorEvaluation.sortBranchTransitions(branch.getBranchTransitions_Branch());
for (int i = 0; i < branchTransitionsSorted.size(); i++) {
final ModelElement modelElement = new ModelElement(false, false, false, true, false, "", "", branchTransitionsSorted.get(i).getBranchProbability());
modelElements.add(modelElement);
UserBehaviorEvaluation.getModelElements(branchTransitionsSorted.get(i).getBranchedBehaviour_BranchTransition(), modelElements);
}
}
// Gets the successor model element
nextActionOfScenarioBehaviour = nextActionOfScenarioBehaviour.getSuccessor();
}
}
use of org.palladiosimulator.pcm.usagemodel.AbstractUserAction in project iobserve-analysis by research-iobserve.
the class TUsageModelToBehaviorModel method findLoopStart.
/**
* Find first {@link EntryLevelSystemCall} element of a {@link Loop} body.
*
* @param loop
* loop
* @return first found {@link EntryLevelSystemCall}, if found
*/
private Optional<EntryCallNode> findLoopStart(final AbstractUserAction action) {
if (action instanceof Stop) {
// LoopStart not found
return Optional.empty();
} else if (action instanceof EntryLevelSystemCall) {
// found loop start
final EntryLevelSystemCall entryLevelSystemCall = (EntryLevelSystemCall) action;
final EntryCallNode entryCallNode = this.createEntryCallNode(entryLevelSystemCall);
return Optional.of(entryCallNode);
} else if (action instanceof Loop) {
// search nested scenario
final Loop loop = (Loop) action;
final List<AbstractUserAction> userActions = loop.getBodyBehaviour_Loop().getActions_ScenarioBehaviour();
if (userActions.size() > 0) {
return this.findLoopStart(userActions.get(0));
} else {
return Optional.empty();
}
} else if (action instanceof Branch) {
// will always found before
return Optional.empty();
} else {
// next action
return this.findLoopStart(action.getSuccessor());
}
}
Aggregations