use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer 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.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.
the class AllocationModification method migrateToRandomResourceContainer.
/*
*
*/
private void migrateToRandomResourceContainer(final AllocationContext allocation) {
final int randomIndex = ThreadLocalRandom.current().nextInt(this.resContainer.length);
final ResourceContainer replaceResCon = this.resContainer[randomIndex];
allocation.setResourceContainer_AllocationContext(replaceResCon);
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.
the class ResourceEnvironmentModification method modifyResEnvTerminate.
/**
* @param terminations
* @return
*/
public List<ResourceContainer> modifyResEnvTerminate(final int terminations) {
final List<ResourceContainer> removedResourceContainers = new ArrayList<>();
final EList<ResourceContainer> resourceContainers = this.resourceEnvironment.getResourceContainer_ResourceEnvironment();
for (int i = 0; i < terminations; i++) {
final int randomIndex = ThreadLocalRandom.current().nextInt(resourceContainers.size());
final ResourceContainer removedResCon = resourceContainers.remove(randomIndex);
removedResourceContainers.add(removedResCon);
if (ResourceEnvironmentModification.LOGGER.isInfoEnabled()) {
ResourceEnvironmentModification.LOGGER.info("REMOVING: \tResourceContainer: \t" + removedResCon.getId());
}
}
return removedResourceContainers;
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.
the class AllocationFinishedStage method execute.
/**
* Forwards the deployment event after the allocation is finished.
*
* @throws Exception
* exception
*/
@Override
protected void execute() throws Exception {
final ResourceContainer resourceContainer = this.allocationFinishedInputPort.receive();
final PCMDeployedEvent deployedEvent = this.deployedInputPort.receive();
if (resourceContainer != null) {
this.allocations.add(resourceContainer);
}
if (deployedEvent != null) {
this.deployments.add(deployedEvent);
}
if (this.allocations.size() > 0 && this.deployments.size() > 0) {
final PCMDeployedEvent deployed = this.deployments.poll();
deployed.setResourceContainer(resourceContainer);
this.deployedOutputPort.send(deployed);
}
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.
the class AllocationStage method execute.
/**
* This method is triggered for every allocation event.
*
* @param event
* one allocation event to be processed
* @throws MalformedURLException
* malformed url exception
* @throws UnknownObjectException
* in case the allocation event is of an unknown type
*/
@Override
protected void execute(final IAllocationEvent event) throws MalformedURLException, UnknownObjectException {
final URL url;
if (event instanceof ContainerAllocationEvent) {
url = new URL(((ContainerAllocationEvent) event).getUrl());
} else {
throw new UnknownObjectException(event.getClass() + " is not supported by the allocation filter.");
}
final String hostName = url.getHost();
final Optional<ResourceContainer> resourceContainer = ResourceEnvironmentModelFactory.getResourceContainerByName(this.resourceEnvironmentModelGraphProvider.readOnlyRootComponent(ResourceEnvironment.class), hostName);
if (!resourceContainer.isPresent()) {
/**
* new provider: update the resource environment graph.
*/
final ResourceEnvironment resourceEnvironmentModelGraph = this.resourceEnvironmentModelGraphProvider.readOnlyRootComponent(ResourceEnvironment.class);
final ResourceContainer newResourceContainer = ResourceEnvironmentModelFactory.createResourceContainer(resourceEnvironmentModelGraph, hostName);
resourceEnvironmentModelGraph.getResourceContainer_ResourceEnvironment().add(newResourceContainer);
this.resourceEnvironmentModelGraphProvider.updateComponent(ResourceEnvironment.class, resourceEnvironmentModelGraph);
/**
* signal allocation update.
*/
this.allocationNotifyOutputPort.send(newResourceContainer);
this.allocationOutputPort.send(event);
} else {
/**
* error allocation already happened.
*/
this.logger.debug("ResourceContainer %s was available." + hostName);
final List<ProcessingResourceSpecification> procResSpec = resourceContainer.get().getActiveResourceSpecifications_ResourceContainer();
for (int i = 0; i < procResSpec.size(); i++) {
final String nodeGroupName = procResSpec.get(i).getActiveResourceType_ActiveResourceSpecification().getEntityName();
this.logger.debug(nodeGroupName);
}
/**
* Notify with existing container.
*/
this.allocationNotifyOutputPort.send(resourceContainer.get());
}
}
Aggregations