use of org.iobserve.model.correspondence.Part in project iobserve-analysis by research-iobserve.
the class BranchWithinBranchReference method createTheReferenceModel.
/**
* Creates the reference model.
*
* @param usageModelBuilder
* @param repositoryLookupModel
* @param correspondenceModel
* @param numberOfTransitionsOfExteriorBranch
* @param numberOfTransitionsOfInteriorBranches
* @param numberOfConcurrentUsers
* @param branchTransitionCounter
* @param listOfbranchTransitionCounterInterior
* @return
*/
private static UsageModel createTheReferenceModel(final UsageModelFactory usageModelBuilder, final RepositoryLookupModelProvider repositoryLookupModel, final CorrespondenceModel correspondenceModel, final int numberOfTransitionsOfExteriorBranch, final int numberOfTransitionsOfInteriorBranches, final int numberOfConcurrentUsers, final List<Integer> branchTransitionCounter, final List<List<Integer>> listOfbranchTransitionCounterInterior) {
// 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);
lastAction = start;
// The exterior branch is created
final org.palladiosimulator.pcm.usagemodel.Branch branch = UsageModelFactory.createBranch("", scenarioBehaviour);
UsageModelFactory.connect(lastAction, branch);
UsageModelFactory.connect(branch, stop);
// Creates branch transitions according to the random countOfBranchTransitions
for (int i = 0; i < numberOfTransitionsOfExteriorBranch; i++) {
final BranchTransition branchTransition = UsageModelFactory.createBranchTransition(branch);
final ScenarioBehaviour branchTransitionBehaviour = branchTransition.getBranchedBehaviour_BranchTransition();
branchTransition.setBranchProbability((double) branchTransitionCounter.get(i) / (double) numberOfConcurrentUsers);
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 Part part = CorrespondenceUtility.findPart(Repository.class, correspondenceModel);
final OperationSignature operation = CorrespondenceUtility.findModelElementForOperation(part, ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operation);
UsageModelFactory.addUserAction(branchTransitionBehaviour, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
} else {
throw new IllegalArgumentException("Illegal value of model element parameter");
}
// The interior branch is created
final org.palladiosimulator.pcm.usagemodel.Branch branchInterior = UsageModelFactory.createBranch("", branchTransitionBehaviour);
UsageModelFactory.connect(lastAction, branchInterior);
UsageModelFactory.connect(branchInterior, stopBranchTransition);
for (int j = 0; j < numberOfTransitionsOfInteriorBranches; j++) {
final BranchTransition branchTransitionInterior = UsageModelFactory.createBranchTransition(branchInterior);
final ScenarioBehaviour branchTransitionBehaviourInterior = branchTransitionInterior.getBranchedBehaviour_BranchTransition();
branchTransitionInterior.setBranchProbability((double) listOfbranchTransitionCounterInterior.get(i).get(j) / (double) branchTransitionCounter.get(i));
final Start startBranchTransitionInterior = UsageModelFactory.createAddStartAction("", branchTransitionBehaviourInterior);
final Stop stopBranchTransitionInterior = UsageModelFactory.createAddStopAction("", branchTransitionBehaviourInterior);
lastAction = startBranchTransitionInterior;
final OperationSignature operation = BranchWithinBranchReference.getOptionCorrespondent(correspondenceModel, j);
if (operation != null) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operation);
UsageModelFactory.addUserAction(branchTransitionBehaviourInterior, entryLevelSystemCall);
UsageModelFactory.connect(lastAction, entryLevelSystemCall);
lastAction = entryLevelSystemCall;
}
UsageModelFactory.connect(lastAction, stopBranchTransitionInterior);
}
}
return usageModel;
}
use of org.iobserve.model.correspondence.Part in project iobserve-analysis by research-iobserve.
the class SimpleSequenceReferenceHelper 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 CorrespondenceModel 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 UserSessionCollectionModel entryCallSequenceModel = new UserSessionCollectionModel(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;
// created
for (int i = 0; i < numberOfCalls; i++) {
final OperationSignature operation;
if (i >= 0 && i < 5) {
final Part part = CorrespondenceUtility.findPart(Repository.class, correspondenceModel);
operation = CorrespondenceUtility.findModelElementForOperation(part, ReferenceUsageModelBuilder.CLASS_SIGNATURE[i], ReferenceUsageModelBuilder.OPERATION_SIGNATURE[i]);
} else {
throw new IllegalArgumentException("Illegal value of model element parameter");
}
if (operation != null) {
final EntryLevelSystemCall entryLevelSystemCall = UsageModelFactory.createEntryLevelSystemCall(repositoryLookupModel, operation);
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(SimpleSequenceReferenceHelper.calculateTheNumberOfConcurrentUsers(entryCallSequenceModel.getUserSessions()));
return referenceElements;
}
use of org.iobserve.model.correspondence.Part in project iobserve-analysis by research-iobserve.
the class CreateCorrespondenceMain method main.
/**
* @param args
* arguments
*/
public static void main(final String[] args) {
CreateCorrespondenceMain.NAME_MAPS.put("Assembly_FrontendService", "jpetstore-frontend-service");
CreateCorrespondenceMain.NAME_MAPS.put("Assembly_AccountService", "jpetstore-account-service");
CreateCorrespondenceMain.NAME_MAPS.put("Assembly_CatalogService", "jpetstore-catalog-service");
CreateCorrespondenceMain.NAME_MAPS.put("Assembly_OdrderService", "jpetstore-order-service");
CreateCorrespondenceMain.NAME_MAPS.put("Assembly_AccountDatabase", "jpetstore-account-database");
CreateCorrespondenceMain.NAME_MAPS.put("Assembly_CatalogDatabase", "jpetstore-catalog-database");
CreateCorrespondenceMain.NAME_MAPS.put("Assembly_OrderDatabase", "jpetstore-order-database");
final String pcmDirectory = "/home/reiner/Projects/iObserve/experiments/distributed-jpetstore-experiment/pcm/JPetStore";
try {
final ModelImporter modelHandler = new ModelImporter(new File(pcmDirectory));
// final Repository repository = modelHandler.getRepositoryModel();
// final ResourceEnvironment environment = modelHandler.getResourceEnvironmentModel();
final System system = modelHandler.getSystemModel();
// final Allocation allocation = modelHandler.getAllocationModel();
final CorrespondenceModel correspondenceModel = CorrespondenceFactory.eINSTANCE.createCorrespondenceModel();
final Part part = CorrespondenceFactory.eINSTANCE.createPart();
correspondenceModel.getParts().add(part);
part.setModelType(system);
for (final AssemblyContext assembly : system.getAssemblyContexts__ComposedStructure()) {
final AssemblyEntry entry = CorrespondenceFactory.eINSTANCE.createAssemblyEntry();
final String value = CreateCorrespondenceMain.NAME_MAPS.get(assembly.getEntityName());
entry.setImplementationId(value);
entry.setAssembly(assembly);
part.getEntries().add(entry);
}
final URI outputURI = URI.createFileURI("/home/reiner/correspondence.correspondence");
CreateCorrespondenceMain.save(correspondenceModel, outputURI);
} catch (final IOException e) {
CreateCorrespondenceMain.LOGGER.error("Canot load all models {}", e.getLocalizedMessage());
}
}
use of org.iobserve.model.correspondence.Part in project iobserve-analysis by research-iobserve.
the class DeploymentModelUpdater method findOrCreate.
/**
* Find the corresponding part for the allocationModel or create a new part if no part exists.
* The method has a side effect, as the part is added to the correspondence model.
*
* @param correspondenceModel
* correspondence model
* @param allocationModel
* allocation model
* @return returns a part
*/
private Part findOrCreate(final CorrespondenceModel correspondenceModel, final Allocation allocationModel) {
for (final Part part : correspondenceModel.getParts()) {
if (part.getModelType().equals(allocationModel)) {
return part;
}
}
final Part part = CorrespondenceFactory.eINSTANCE.createPart();
part.setModelType(allocationModel);
correspondenceModel.getParts().add(part);
return part;
}
use of org.iobserve.model.correspondence.Part in project iobserve-analysis by research-iobserve.
the class DeploymentModelUpdater method execute.
/**
* Execute an deployment event.
*
* @param event
* one deployment event to be processed
* @throws NodeLookupException
* node lookup failed
* @throws DBException
* on db error
* @throws InvocationException
* on invocation errors
*/
@Override
protected void execute(final PCMDeployedEvent event) throws NodeLookupException, InvocationException, DBException {
DeploymentLock.lock();
ExperimentLoggingUtils.logEvent(event.getTimestamp(), EventTypes.DEPLOYMENT, ObservationPoint.MODEL_UPDATE_ENTRY);
this.logger.debug("Send event from {}", this.getInputPort().getPipe().getSourcePort().getOwningStage().getId());
this.logger.debug("Deployment model update: assemblyContext={} resourceContainer={} service={}", event.getAssemblyContext(), event.getResourceContainer(), event.getService());
final String allocationContextName = NameFactory.createAllocationContextName(event.getAssemblyContext(), event.getResourceContainer());
final List<AllocationContext> allocationContext = this.allocationModelResource.findObjectsByTypeAndProperty(AllocationContext.class, AllocationPackage.Literals.ALLOCATION_CONTEXT, "entityName", allocationContextName);
if (allocationContext.isEmpty()) {
this.logger.debug("Create allocation context (deploy) {}", event);
final Allocation allocationModel = this.allocationModelResource.getModelRootNode(Allocation.class, AllocationPackage.Literals.ALLOCATION);
final AllocationContext newAllocationContext = AllocationFactory.eINSTANCE.createAllocationContext();
newAllocationContext.setEntityName(allocationContextName);
newAllocationContext.setAssemblyContext_AllocationContext(event.getAssemblyContext());
newAllocationContext.setResourceContainer_AllocationContext(event.getResourceContainer());
allocationModel.getAllocationContexts_Allocation().add(newAllocationContext);
this.allocationModelResource.updatePartition(allocationModel);
final AllocationContext storedAllocationContext = this.allocationModelResource.resolve(newAllocationContext);
/**
* create correspondence model entry.
*/
final CorrespondenceModel correspondenceModel = this.correspondenceModelResource.getModelRootNode(CorrespondenceModel.class, CorrespondencePackage.Literals.CORRESPONDENCE_MODEL);
final Part part = this.findOrCreate(correspondenceModel, allocationModel);
final AllocationEntry entry = CorrespondenceFactory.eINSTANCE.createAllocationEntry();
entry.setAllocation(storedAllocationContext);
entry.setTechnology(event.getTechnology());
entry.setImplementationId(event.getUrl());
part.getEntries().add(entry);
this.correspondenceModelResource.updatePartition(correspondenceModel);
this.logger.debug("PUSHED CORRESPONDENCE {} {} {}", newAllocationContext.getEntityName(), event.getTechnology().getLiteral(), event.getUrl());
} else {
this.logger.error("Deployment failed: Allocation Context {} already exists in allocation model.", allocationContextName);
}
// signal deployment update
ExperimentLoggingUtils.logEvent(event.getTimestamp(), EventTypes.DEPLOYMENT, ObservationPoint.MODEL_UPDATE_EXIT);
DeploymentLock.unlock();
this.deployedNotifyOutputPort.send(event);
}
Aggregations