use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ResourceContainerActionFactory method setSourceResourceContainer.
private static ResourceContainerAction setSourceResourceContainer(final ResourceContainerAction action, final String resourceContainerID) {
final ResourceEnvironment resEnvModel = ActionFactory.getRuntimeModels().getResourceEnvironmentModel();
final ResourceContainer resourceContainer = ActionFactory.getResourceContainer(resourceContainerID, resEnvModel);
action.setSourceResourceContainer(resourceContainer);
return action;
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ModelHelper method getInternetLinkingResource.
/**
* Searches the resource environment for a linking resource with name 'Internet' and returns it,
* or creates it if it does not exist.
*
* @param environment
* the resource environment to search
* @return the found linking resource or the newly created one
*/
public static LinkingResource getInternetLinkingResource(final ResourceEnvironment environment) {
final List<LinkingResource> linkingResources = environment.getLinkingResources__ResourceEnvironment();
final Optional<LinkingResource> internetLink = linkingResources.stream().filter(link -> link.getEntityName().contains(ModelHelper.INTERNET_LINKING_RESOURCE_NAME)).findFirst();
final LinkingResource linkingResource = internetLink.orElseGet(() -> {
try {
return org.iobserve.model.factory.ResourceEnvironmentCloudFactory.createLinkingResource(environment, null, ModelHelper.INTERNET_LINKING_RESOURCE_NAME);
} catch (final ModelHandlingErrorException e) {
return null;
}
});
return linkingResource;
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment in project iobserve-analysis by research-iobserve.
the class ModelGenerationFactory method generateAndSaveResourceEnvironment.
private static ResourceEnvironment generateAndSaveResourceEnvironment(final CommandLine commandLine, final URI outputLocation, final String modelName) {
final ResourceEnvironmentGeneration resEnvGen = new ResourceEnvironmentGeneration(modelName);
final ResourceEnvironment resEnvModel = resEnvGen.craeteResourceEnvironment(Integer.parseInt(commandLine.getOptionValue("r")));
final ResourceEnvironmentModelHandler resEnvModelProvider = new ResourceEnvironmentModelHandler();
final URI resEnvModelURI = URI.createFileURI(outputLocation.toFileString() + File.separator + resEnvModel.getEntityName() + ".resourceenvironment");
resEnvModelProvider.save(resEnvModelURI, resEnvModel);
return resEnvModel;
}
use of org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment 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.ResourceEnvironment 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;
}
}
}
Aggregations