use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.
the class ModelModificationFactory method createNewModel.
/**
* Create a new model.
*
* @param commandLine
* command line parameters
* @throws InitializationException
* when handler do not initialize
* @throws IOException
* on io errors
*/
public static void createNewModel(final CommandLine commandLine) throws InitializationException, IOException {
ModelModificationFactory.LOGGER.info("Modifying model!");
final URI inputModels = URI.createFileURI(commandLine.getOptionValue("i"));
final URI outputLocation = URI.createFileURI(commandLine.getOptionValue("o"));
ModelModificationFactory.LOGGER.info("Copying models to new location.");
PCMModelHandler modelProviders = new PCMModelHandler(new File(inputModels.toFileString()));
final URI copyURI = ModelModificationFactory.copyRepoToOutput(outputLocation, modelProviders);
modelProviders = new PCMModelHandler(new File(copyURI.toFileString()));
final Allocation allocationModel = modelProviders.getAllocationModel();
final ResourceEnvironment resourceEnvironmentModel = modelProviders.getResourceEnvironmentModel();
final System systemModel = modelProviders.getSystemModel();
final Repository repositoryModel = modelProviders.getRepositoryModel();
final ResourceEnvironmentModification resEnvMod = new ResourceEnvironmentModification(resourceEnvironmentModel);
ModelModificationFactory.LOGGER.info("Terminating Server");
final List<ResourceContainer> terminatedResourceContainers = resEnvMod.modifyResEnvTerminate(Integer.parseInt(commandLine.getOptionValue("ac")));
ModelModificationFactory.LOGGER.info("Acquiring Server");
resEnvMod.modifyResEnvAcquire(Integer.parseInt(commandLine.getOptionValue("ac")));
ModelModificationFactory.LOGGER.info("Fixing Allocation after terminating");
AllocationModification allocMod = new AllocationModification(allocationModel, systemModel, resourceEnvironmentModel);
final int terminationMigrations = allocMod.modifyAllocationFixTerminations(terminatedResourceContainers);
ModelModificationFactory.LOGGER.info("Deallocating Components");
final SystemModification sysMod = new SystemModification(systemModel, repositoryModel);
final List<AssemblyContext> deallocatedACs = sysMod.modifySystemDeallocations(Integer.parseInt(commandLine.getOptionValue("de")));
ModelModificationFactory.LOGGER.info("Fixing Allocation after deallocating");
allocMod = new AllocationModification(allocationModel, systemModel, resourceEnvironmentModel);
allocMod.modifyAllocationFixDeallocations(deallocatedACs);
// LOG.info("Exchanging Components");
// sysMod.modifySystem_ChangeComp(Integer.parseInt(commandLine.getOptionValue("cr")));
ModelModificationFactory.LOGGER.info("Allocating new Components");
final List<AssemblyContext> allocatedACs = sysMod.modifySystemAllocate(Integer.parseInt(commandLine.getOptionValue("al")));
ModelModificationFactory.LOGGER.info("Creating Allocation for new components");
allocMod = new AllocationModification(allocationModel, systemModel, resourceEnvironmentModel);
allocMod.modifyAllocationFixAllocations(allocatedACs);
ModelModificationFactory.LOGGER.info("Creating migrations");
allocMod = new AllocationModification(allocationModel, systemModel, resourceEnvironmentModel);
final int totalMigrations = Integer.parseInt(commandLine.getOptionValue("al"));
// allocationMigrations
final int migrationsToPerform = totalMigrations - terminationMigrations;
if (migrationsToPerform > 0) {
ModelModificationFactory.LOGGER.info("Migrations to Perform: {}", migrationsToPerform);
allocMod.modifyAllocationMigrate(migrationsToPerform);
} else {
ModelModificationFactory.LOGGER.info(String.format("All migrations (%d) are already perfomed by Server-Termination (%d)!", totalMigrations, migrationsToPerform));
}
ModelModificationFactory.LOGGER.info("Saving models!");
modelProviders.save(outputLocation);
ModelModificationFactory.LOGGER.info("Modification done!");
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.
the class SynthesizeAllocationEventStage method execute.
@Override
protected void execute(final PCMDeployedEvent event) throws Exception {
final ResourceContainer resourceContainer = ResourceEnvironmentModelFactory.getResourceContainerByName(this.resourceEnvironmentModelGraphProvider.readOnlyRootComponent(ResourceEnvironment.class), event.getService()).get();
if (resourceContainer != null) {
/**
* execution environment exists. Can deploy.
*/
event.setResourceContainer(resourceContainer);
this.deployedOutputPort.send(event);
} else {
/**
* If the resource container with this serverName is not available, send an event to
* TAllocation (creating the resource container) and forward the deployment event to
* TDeployment (deploying on created resource container).
*/
this.allocationOutputPort.send(new ContainerAllocationEvent(event.getUrl()));
this.deployedRelayOutputPort.send(event);
}
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.
the class UndeploymentModelUpdater method execute.
/**
* This method is triggered for every undeployment event.
*
* @param event
* undeployment event
*/
@Override
protected void execute(final PCMUndeployedEvent event) {
// get the model entity name
final String entityName = event.getCorrespondent().getPcmEntityName();
// build the assembly context name
final String assemblyContextName = entityName + "_" + event.getService();
final ResourceContainer resourceContainer = event.getResourceContainer();
// get assembly context by name or create it if necessary.
final System system = this.systemModelGraphProvider.readOnlyRootComponent(org.palladiosimulator.pcm.system.System.class);
final Optional<AssemblyContext> optAssemblyContext = SystemModelFactory.getAssemblyContextByName(system, assemblyContextName);
if (optAssemblyContext.isPresent()) {
// update the allocation graph
final Allocation allocationModel = this.allocationModelGraphProvider.readOnlyRootComponent(Allocation.class);
AllocationModelFactory.removeAllocationContext(allocationModel, resourceContainer, optAssemblyContext.get());
this.allocationModelGraphProvider.updateComponent(Allocation.class, allocationModel);
// signal allocation update
this.outputPort.send(event);
} else {
if (resourceContainer != null) {
this.logger.warn("AssemblyContext " + assemblyContextName + " for " + resourceContainer.getEntityName() + " not found! \n");
} else {
this.logger.warn("AssemblyContext " + assemblyContextName + " not found and no resource container specified.\n");
}
}
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.
the class GeoLocation method execute.
@Override
protected void execute(final PCMDeployedEvent element) throws Exception {
// TODO this might be better implemented using query functions addressing RescourceContainer
final ResourceEnvironment resourceEnvironment = this.resourceEnvironmentModelProvider.readRootComponent(ResourceEnvironment.class);
final EList<ResourceContainer> resContainers = resourceEnvironment.getResourceContainer_ResourceEnvironment();
for (final ResourceContainer resContainer : resContainers) {
if (resContainer.getEntityName().equals(element.getService()) && resContainer instanceof ResourceContainerPrivacy) {
final ResourceContainerPrivacy resContainerPrivacy = (ResourceContainerPrivacy) resContainer;
final int geolocation = resContainerPrivacy.getGeolocation();
if (geolocation != element.getCountryCode()) {
resContainerPrivacy.setGeolocation(element.getCountryCode());
this.outputPort.send(element);
}
break;
}
}
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.
the class ModelTransformer method clearCloudResourcesFromResourceEnv.
private void clearCloudResourcesFromResourceEnv() {
final ResourceEnvironment environment = this.resourceEnvironmentModel;
final List<ResourceContainer> resourceContainers = environment.getResourceContainer_ResourceEnvironment();
for (final Iterator<ResourceContainer> iter = resourceContainers.iterator(); iter.hasNext(); ) {
final ResourceContainer container = iter.next();
if (container instanceof ResourceContainerCloud) {
iter.remove();
}
}
final LinkingResource linkingResource = ModelHelper.getInternetLinkingResource(environment);
linkingResource.getConnectedResourceContainers_LinkingResource().clear();
}
Aggregations