use of org.palladiosimulator.pcm.allocation.AllocationContext in project iobserve-analysis by research-iobserve.
the class AllocationModelFactory method addAllocationContext.
/**
* Add an {@link AllocationContext} for the given {@link ResourceContainer} and
* {@link AssemblyContext} if they are absent to this model. No check for duplication is done!
*
* @param model
* allocation model
* @param resContainer
* container
* @param asmCtx
* assembly context
*/
public static void addAllocationContext(final Allocation model, final ResourceContainer resContainer, final AssemblyContext asmCtx) {
final AllocationFactory factory = AllocationFactory.eINSTANCE;
final AllocationContext allocationCtx = factory.createAllocationContext();
allocationCtx.setEntityName(asmCtx.getEntityName());
allocationCtx.setAssemblyContext_AllocationContext(asmCtx);
allocationCtx.setResourceContainer_AllocationContext(resContainer);
model.getAllocationContexts_Allocation().add(allocationCtx);
}
use of org.palladiosimulator.pcm.allocation.AllocationContext in project iobserve-analysis by research-iobserve.
the class AllocationGeneration method generateAllocationContext.
/*
*
*/
private AllocationContext generateAllocationContext(final AssemblyContext assemblyContext) {
final AllocationContext allocationContext = AllocationGeneration.ALLOCATION_FACTORY.createAllocationContext();
allocationContext.setAssemblyContext_AllocationContext(assemblyContext);
final int randomIndex = ThreadLocalRandom.current().nextInt(this.resContainer.length);
allocationContext.setResourceContainer_AllocationContext(this.resContainer[randomIndex]);
allocationContext.setEntityName(assemblyContext.getEntityName() + " @ " + this.resContainer[randomIndex].getEntityName());
return allocationContext;
}
use of org.palladiosimulator.pcm.allocation.AllocationContext in project iobserve-analysis by research-iobserve.
the class AllocationModification method initResContainer2AllocationContext.
private void initResContainer2AllocationContext() {
this.resContainer2AllocationContext = new HashMap<>();
this.assemblyCon2AllocationContext = new HashMap<>();
for (final AllocationContext ac : this.allocationModel.getAllocationContexts_Allocation()) {
final ResourceContainer resCon = ac.getResourceContainer_AllocationContext();
if (!this.resContainer2AllocationContext.containsKey(resCon.getId())) {
this.resContainer2AllocationContext.put(resCon.getId(), new LinkedList<AllocationContext>());
}
this.resContainer2AllocationContext.get(resCon.getId()).add(ac);
final AssemblyContext assemblyCon = ac.getAssemblyContext_AllocationContext();
if (!this.assemblyCon2AllocationContext.containsKey(assemblyCon.getId())) {
this.assemblyCon2AllocationContext.put(assemblyCon.getId(), ac);
} else {
throw new RuntimeException("An assembly context was found twice during assembly context analysis!");
}
}
}
use of org.palladiosimulator.pcm.allocation.AllocationContext in project iobserve-analysis by research-iobserve.
the class AllocationModification method modifyAllocationFixTerminations.
/**
* @param terminatedResContainers
* @return
*/
public int modifyAllocationFixTerminations(final List<ResourceContainer> terminatedResContainers) {
int migrationsMade = 0;
for (final ResourceContainer terminatedResCon : terminatedResContainers) {
if (this.resContainer2AllocationContext.containsKey(terminatedResCon.getId())) {
for (final AllocationContext allocation : this.resContainer2AllocationContext.get(terminatedResCon.getId())) {
this.migrateToRandomResourceContainer(allocation);
migrationsMade++;
}
}
}
return migrationsMade;
}
use of org.palladiosimulator.pcm.allocation.AllocationContext in project iobserve-analysis by research-iobserve.
the class AllocationModification method modifyAllocationMigrate.
/**
* @param migarions
* @return
*/
public int modifyAllocationMigrate(final int migarions) {
int migrationsMade = 0;
final Set<AllocationContext> usedAllocationContexts = new HashSet<>();
final EList<AllocationContext> allocationContexts = this.allocationModel.getAllocationContexts_Allocation();
for (int i = 0; i < migarions; i++) {
AllocationContext ac = null;
for (int j = 0; ac != null && j < allocationContexts.size() * 10; j++) {
final int randomIndex = ThreadLocalRandom.current().nextInt(allocationContexts.size());
if (!usedAllocationContexts.contains(allocationContexts.get(randomIndex))) {
ac = allocationContexts.get(randomIndex);
}
if (ac != null) {
this.migrateToRandomResourceContainer(ac);
migrationsMade++;
}
}
}
return migrationsMade;
}
Aggregations