use of org.palladiosimulator.pcm.core.PCMRandomVariable in project iobserve-analysis by research-iobserve.
the class OverlappingIterationReference method getModel.
/**
* Creates a reference model that contains a loop element. The user sessions contain iterated
* call sequences that share overlapping calls. Thereby, one iterated sequence consists of more
* calls than the other. Thus, it can be checked whether the approach transforms the iterated
* call sequence that consists of more calls to a loop (RQ-1.4)
*
* @param referenceUsageModelFileName
* file name of the reference model to store its result
* @param repositoryLookupModelProvider
* repository model provider
* @param correspondenceModel
* correspondence model
*
* @return a reference usage model and corresponding user sessions
* @throws IOException
* on error
*/
public static ReferenceElements getModel(final String referenceUsageModelFileName, final RepositoryLookupModelProvider repositoryLookupModelProvider, final CorrespondenceModel correspondenceModel) 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 numberOfConcurrentUsers = TestHelper.getRandomInteger(200, 1);
// One of the iterated sequences is iterated twice and one is iterated three times. The
// number of iterations is set randomly.
final int loopCount1 = TestHelper.getRandomInteger(3, 2);
final int lengthOfSequence1 = 2 * loopCount1;
final int loopCount2;
if (loopCount1 == 3) {
loopCount2 = 2;
} else {
loopCount2 = 3;
}
final int lengthOfSequence2 = 2 * loopCount2;
final ReferenceElements referenceElements = new ReferenceElements();
final UserSessionCollectionModel entryCallSequenceModel = new UserSessionCollectionModel(TestHelper.getUserSessions(numberOfConcurrentUsers));
// 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.createStart("");
UsageModelFactory.addUserAction(scenarioBehaviour, start);
final Stop stop = UsageModelFactory.createStop("");
UsageModelFactory.addUserAction(scenarioBehaviour, stop);
// According to the randomly set number of iterations the sequence that is iterated three
// times is represented by a loop element. The other sequence is represented by a sequence
final Loop loop = UsageModelFactory.createLoop("", scenarioBehaviour);
if (lengthOfSequence1 >= lengthOfSequence2) {
UsageModelFactory.connect(start, loop);
final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
pcmLoopIteration.setSpecification(String.valueOf(loopCount1));
// Set number of loops
loop.setLoopIteration_Loop(pcmLoopIteration);
final Start loopStart = UsageModelFactory.createStart("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStart);
final Stop loopStop = UsageModelFactory.createStop("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStop);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 0, loopStart, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
UsageModelFactory.connect(lastAction, loopStop);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 3, loop, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 3, lastAction, scenarioBehaviour);
UsageModelFactory.connect(lastAction, stop);
} else {
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 0, start, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 0, lastAction, scenarioBehaviour);
UsageModelFactory.connect(lastAction, loop);
final PCMRandomVariable pcmLoopIteration = CoreFactory.eINSTANCE.createPCMRandomVariable();
pcmLoopIteration.setSpecification(String.valueOf(loopCount2));
// Set number of loops
loop.setLoopIteration_Loop(pcmLoopIteration);
final Start loopStart = UsageModelFactory.createStart("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStart);
final Stop loopStop = UsageModelFactory.createStop("");
UsageModelFactory.addUserAction(loop.getBodyBehaviour_Loop(), loopStop);
lastAction = loopStart;
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 2, lastAction, scenarioBehaviour);
lastAction = OverlappingIterationReference.createEntryLevelSystemCall(repositoryLookupModelProvider, correspondenceModel, 3, lastAction, scenarioBehaviour);
UsageModelFactory.connect(lastAction, loopStop);
UsageModelFactory.connect(loop, stop);
}
OverlappingIterationReference.createMatchingEntryAndExitEvents(entryCallSequenceModel, lengthOfSequence1, lengthOfSequence2, loopCount1, loopCount2);
// 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;
}
use of org.palladiosimulator.pcm.core.PCMRandomVariable in project iobserve-analysis by research-iobserve.
the class UsageModelDataFactory method createUsageModel.
/**
* Create a usage model.
*
* @return returns a usage model
*/
public static UsageModel createUsageModel() {
final UsageModel usageModel = UsagemodelFactory.eINSTANCE.createUsageModel();
// Think time
final PCMRandomVariable thinkTime = CoreFactory.eINSTANCE.createPCMRandomVariable();
thinkTime.setSpecification("5.0");
// Closed workload
final ClosedWorkload closedWorkload = UsagemodelFactory.eINSTANCE.createClosedWorkload();
closedWorkload.setPopulation(2);
closedWorkload.setThinkTime_ClosedWorkload(thinkTime);
// Scenario behavior
final ScenarioBehaviour buyBookScenarioBehaviour = UsageModelDataFactory.createScenarionBehaviorBuyaBook();
// Usage scenario
final UsageScenario usageScenarioGroup0 = UsagemodelFactory.eINSTANCE.createUsageScenario();
usageScenarioGroup0.setEntityName(UsageModelDataFactory.USAGE_SCENARIO_GROUP_0);
usageScenarioGroup0.setScenarioBehaviour_UsageScenario(buyBookScenarioBehaviour);
usageScenarioGroup0.setWorkload_UsageScenario(closedWorkload);
usageModel.getUsageScenario_UsageModel().add(usageScenarioGroup0);
return usageModel;
}
use of org.palladiosimulator.pcm.core.PCMRandomVariable in project iobserve-analysis by research-iobserve.
the class ResourceEnvironmentCloudFactory method createProcessingResource.
/**
* Creates a new processing resource specification for the given resource container.
*
* There is no check if the container already has a processing resource.
*
* @param nrOfCores
* the number of cores the processing resource should have
* @param processingRate
* the processing rate of the resource
* @param container
* the container in which to create the processing resource.
* @return a processing resource specification
* @throws ModelHandlingErrorException
* when something when wrong with the model handling
*/
public static ProcessingResourceSpecification createProcessingResource(final int nrOfCores, final double processingRate, final ResourceContainer container) throws ModelHandlingErrorException {
final ProcessingResourceSpecification processor = ResourceenvironmentFactory.eINSTANCE.createProcessingResourceSpecification();
final PCMRandomVariable pcmProcessingRate = CoreFactory.eINSTANCE.createPCMRandomVariable();
pcmProcessingRate.setSpecification(Double.toString(processingRate));
processor.setActiveResourceType_ActiveResourceSpecification(IPalladioResourceRepository.INSTANCE.resources().cpu());
processor.setId(EcoreUtil.generateUUID());
processor.setNumberOfReplicas(nrOfCores);
processor.setMTTF(0.0);
processor.setMTTR(0.0);
processor.setProcessingRate_ProcessingResourceSpecification(pcmProcessingRate);
processor.setRequiredByContainer(true);
processor.setResourceContainer_ProcessingResourceSpecification(container);
processor.setSchedulingPolicy(IPalladioResourceRepository.INSTANCE.resources().policyProcessorSharing());
return processor;
}
use of org.palladiosimulator.pcm.core.PCMRandomVariable in project iobserve-analysis by research-iobserve.
the class UsageModelProviderTest method createThenUpdateThenReadUpdated.
/**
* Test whether we can create, update and then read the object for the DB with committed
* correctly.
*
* @throws NodeLookupException
* @throws DBException
*/
@Test
public void createThenUpdateThenReadUpdated() throws NodeLookupException, DBException {
final Neo4JModelResource<UsageModel> resource = ModelProviderTestUtils.prepareResource("createThenUpdateThenReadUpdated", this.prefix, this.ePackage);
final UsageScenario writtenUsageScenarioGroup0 = UsageModelDataFactory.findUsageScenario(this.usageModel, UsageModelDataFactory.USAGE_SCENARIO_GROUP_0);
final ScenarioBehaviour writtenBuyBookScenarioBehaviour = UsageModelDataFactory.findBehavior(this.usageModel, UsageModelDataFactory.BUY_A_BOOK_BEHAVIOR);
final EntryLevelSystemCall writtenGetQueryCall = UsageModelDataFactory.findSystemCallbyName(this.usageModel, UsageModelDataFactory.USAGE_SCENARIO_GROUP_0, UsageModelDataFactory.BUY_A_BOOK_BEHAVIOR, UsageModelDataFactory.QUERY_CALL);
final EntryLevelSystemCall writtenGetPriceCall = UsageModelDataFactory.findSystemCallbyName(this.usageModel, UsageModelDataFactory.USAGE_SCENARIO_GROUP_0, UsageModelDataFactory.BUY_A_BOOK_BEHAVIOR, UsageModelDataFactory.PRICE_CALL);
resource.storeModelPartition(this.testModel);
// 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");
resource.updatePartition(this.testModel);
final UsageModel readModel = resource.getModelRootNode(UsageModel.class, this.eClass);
Assert.assertTrue(this.equalityHelper.comparePartition(this.testModel, readModel, readModel.eClass()));
resource.getGraphDatabaseService().shutdown();
}
use of org.palladiosimulator.pcm.core.PCMRandomVariable in project Palladio-Editors-Sirius by PalladioSimulator.
the class AddHDDProcessingResourceSpecification method getReadProcessingRate.
private PCMRandomVariable getReadProcessingRate() {
final PCMRandomVariable pcmRandomVariable = CoreFactory.eINSTANCE.createPCMRandomVariable();
pcmRandomVariable.setSpecification("");
final StochasticExpressionEditDialog dialog = new StochasticExpressionEditDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), TypeEnum.DOUBLE, pcmRandomVariable);
dialog.setDisplayTitle(SET_READ_PROCESSING_RATE);
dialog.open();
if (dialog.getResult() == null) {
return null;
}
pcmRandomVariable.setSpecification(dialog.getResultText());
return pcmRandomVariable;
}
Aggregations