use of org.palladiosimulator.pcm.usagemodel.Start in project iobserve-analysis by research-iobserve.
the class PcmUsageModelBuilder method transformSequenceToScenarioBehavior.
/**
* Creates a scenario behavior corresponding to the passed sequence. The sequence can be a
* branch sequence or a loop sequence. It creates a sequence of entry level system calls
* including loops within the sequence. It sets the successors and predecessors.
*
* @param indexOfScenario
* states the index of the created scenario within the usage scenario
* @param sequence
* that is transformed to a scenario behavior
* @param branch
* contains the child branches of the branch whose behavior is created
* @return the created scenario behavior
*/
private // NOCS
ScenarioBehaviour transformSequenceToScenarioBehavior(// NOCS
final int indexOfScenario, final List<ISequenceElement> sequence, final Branch branch) {
final ScenarioBehaviour scenarioBehaviour = UsageModelFactory.createScenarioBehaviour();
final Start start = UsageModelFactory.createAddStartAction("", scenarioBehaviour);
final Stop stop = UsageModelFactory.createAddStopAction("", scenarioBehaviour);
EntryLevelSystemCall lastESysCall = UsageModelFactory.createEmptyEntryLevelSystemCall();
boolean isLastElementACall = false;
Loop lastLoop = UsageModelFactory.createEmptyLoop();
boolean isLastElementALoop = false;
org.palladiosimulator.pcm.usagemodel.Branch lastLoopBranch = UsagemodelFactory.eINSTANCE.createBranch();
boolean isLastElementALoopBranch = false;
org.palladiosimulator.pcm.usagemodel.Branch lastBranch = UsagemodelFactory.eINSTANCE.createBranch();
boolean isLastElementABranch = false;
/**
* Loops over all elements of the sequence and creates a corresponding scenario behavior by
* connecting the elements via successor and predecessor connections.
*/
for (final ISequenceElement branchElement : sequence) {
// Element is a entryLevelSystemCall
if (branchElement.getClass().equals(CallElement.class)) {
EntryLevelSystemCall eSysCall = null;
// Workaround TODO
final String operationSignature = branchElement.getOperationSignature().replaceAll("\\(.*\\)", "()");
final String[] operationSplit = operationSignature.split(" ");
final Optional<Correspondent> optionCorrespondent = this.correspondenceModel.getCorrespondent(branchElement.getClassSignature(), operationSplit[operationSplit.length - 1]);
if (optionCorrespondent.isPresent()) {
final Correspondent correspondent = optionCorrespondent.get();
if (PcmUsageModelBuilder.LOGGER.isDebugEnabled()) {
PcmUsageModelBuilder.LOGGER.debug("Usage: Found Correspondent: {}", correspondent.getPcmEntityName() + " " + correspondent.getPcmOperationName());
}
eSysCall = UsageModelFactory.createEntryLevelSystemCall(this.repositoryLookupModel, correspondent);
}
if (eSysCall != null) {
if (isLastElementACall) {
UsageModelFactory.connect(lastESysCall, eSysCall);
} else if (isLastElementALoop) {
UsageModelFactory.connect(lastLoop, eSysCall);
} else if (isLastElementALoopBranch) {
UsageModelFactory.connect(lastLoopBranch, eSysCall);
} else if (isLastElementABranch) {
UsageModelFactory.connect(lastBranch, eSysCall);
} else {
UsageModelFactory.connect(start, eSysCall);
}
UsageModelFactory.addUserAction(scenarioBehaviour, eSysCall);
lastESysCall = eSysCall;
isLastElementACall = true;
isLastElementALoop = false;
isLastElementALoopBranch = false;
isLastElementABranch = false;
}
} else if (branchElement.getClass().equals(LoopElement.class)) {
// Element is a loop
final Loop loop = this.createLoop(scenarioBehaviour, (LoopElement) branchElement);
if (isLastElementACall) {
UsageModelFactory.connect(lastESysCall, loop);
} else if (isLastElementALoop) {
UsageModelFactory.connect(lastLoop, loop);
} else if (isLastElementALoopBranch) {
UsageModelFactory.connect(lastLoopBranch, loop);
} else if (isLastElementABranch) {
UsageModelFactory.connect(lastBranch, loop);
} else {
UsageModelFactory.connect(start, loop);
}
lastLoop = loop;
isLastElementALoop = true;
isLastElementACall = false;
isLastElementALoopBranch = false;
isLastElementABranch = false;
} else if (branchElement.getClass().equals(LoopBranchElement.class)) {
// Element is a
// looped Branch
final org.palladiosimulator.pcm.usagemodel.Branch loopBranch = this.createLoopBranch(scenarioBehaviour, (LoopBranchElement) branchElement);
if (isLastElementACall) {
UsageModelFactory.connect(lastESysCall, loopBranch);
} else if (isLastElementALoop) {
UsageModelFactory.connect(lastLoop, loopBranch);
} else if (isLastElementALoopBranch) {
UsageModelFactory.connect(lastLoopBranch, loopBranch);
} else if (isLastElementABranch) {
UsageModelFactory.connect(lastBranch, loopBranch);
} else {
UsageModelFactory.connect(start, loopBranch);
}
lastLoopBranch = loopBranch;
isLastElementALoopBranch = true;
isLastElementACall = false;
isLastElementALoop = false;
isLastElementABranch = false;
} else if (branchElement.getClass().equals(BranchElement.class)) {
// Element is a
// Branch
final org.palladiosimulator.pcm.usagemodel.Branch branchInter = this.createBranch(scenarioBehaviour, (BranchElement) branchElement);
if (isLastElementACall) {
UsageModelFactory.connect(lastESysCall, branchInter);
} else if (isLastElementALoop) {
UsageModelFactory.connect(lastLoop, branchInter);
} else if (isLastElementALoopBranch) {
UsageModelFactory.connect(lastLoopBranch, branchInter);
} else if (isLastElementABranch) {
UsageModelFactory.connect(lastBranch, branchInter);
} else {
UsageModelFactory.connect(start, branchInter);
}
lastBranch = branchInter;
isLastElementABranch = true;
isLastElementALoopBranch = false;
isLastElementACall = false;
isLastElementALoop = false;
} else {
break;
}
}
// checks if the branch got child branches
if (branch == null) {
if (isLastElementACall) {
UsageModelFactory.connect(lastESysCall, stop);
} else if (isLastElementALoop) {
UsageModelFactory.connect(lastLoop, stop);
} else if (isLastElementALoopBranch) {
UsageModelFactory.connect(lastLoopBranch, stop);
} else if (isLastElementABranch) {
UsageModelFactory.connect(lastBranch, stop);
} else {
UsageModelFactory.connect(start, stop);
}
} else {
final org.palladiosimulator.pcm.usagemodel.Branch branchUM = this.createChildBranch(scenarioBehaviour, indexOfScenario, branch);
if (branchUM != null) {
if (isLastElementACall) {
UsageModelFactory.connect(lastESysCall, branchUM);
UsageModelFactory.connect(branchUM, stop);
} else if (isLastElementALoop) {
UsageModelFactory.connect(lastLoop, branchUM);
UsageModelFactory.connect(branchUM, stop);
} else if (isLastElementALoopBranch) {
UsageModelFactory.connect(lastLoopBranch, branchUM);
UsageModelFactory.connect(branchUM, stop);
} else if (isLastElementABranch) {
UsageModelFactory.connect(lastBranch, branchUM);
UsageModelFactory.connect(branchUM, stop);
} else {
UsageModelFactory.connect(start, branchUM);
UsageModelFactory.connect(branchUM, stop);
}
} else {
if (isLastElementACall) {
UsageModelFactory.connect(lastESysCall, stop);
} else if (isLastElementALoop) {
UsageModelFactory.connect(lastLoop, stop);
} else if (isLastElementALoopBranch) {
UsageModelFactory.connect(lastLoopBranch, stop);
} else if (isLastElementABranch) {
UsageModelFactory.connect(lastBranch, stop);
} else {
UsageModelFactory.connect(start, stop);
}
}
}
return scenarioBehaviour;
}
use of org.palladiosimulator.pcm.usagemodel.Start 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;
}
Aggregations