Search in sources :

Example 16 with ResourceContainer

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!");
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) PCMModelHandler(org.iobserve.model.PCMModelHandler) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) URI(org.eclipse.emf.common.util.URI) System(org.palladiosimulator.pcm.system.System) Repository(org.palladiosimulator.pcm.repository.Repository) Allocation(org.palladiosimulator.pcm.allocation.Allocation) File(java.io.File) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 17 with ResourceContainer

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);
    }
}
Also used : ContainerAllocationEvent(org.iobserve.common.record.ContainerAllocationEvent) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 18 with ResourceContainer

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");
        }
    }
}
Also used : Allocation(org.palladiosimulator.pcm.allocation.Allocation) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) System(org.palladiosimulator.pcm.system.System) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 19 with ResourceContainer

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;
        }
    }
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) ResourceContainerPrivacy(org.palladiosimulator.pcm.resourceenvironmentprivacy.ResourceContainerPrivacy) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 20 with ResourceContainer

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();
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) ResourceContainerCloud(org.palladiosimulator.pcm.cloud.pcmcloud.resourceenvironmentcloud.ResourceContainerCloud) LinkingResource(org.palladiosimulator.pcm.resourceenvironment.LinkingResource) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Aggregations

ResourceContainer (org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)35 ResourceEnvironment (org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment)16 LinkingResource (org.palladiosimulator.pcm.resourceenvironment.LinkingResource)8 Test (org.junit.Test)7 AllocationContext (org.palladiosimulator.pcm.allocation.AllocationContext)7 ResourceContainerCloud (org.palladiosimulator.pcm.cloud.pcmcloud.resourceenvironmentcloud.ResourceContainerCloud)6 ComputeService (org.jclouds.compute.ComputeService)5 Allocation (org.palladiosimulator.pcm.allocation.Allocation)5 AssemblyContext (org.palladiosimulator.pcm.core.composition.AssemblyContext)5 URL (java.net.URL)3 ContainerAllocationEvent (org.iobserve.common.record.ContainerAllocationEvent)3 UnknownObjectException (java.rmi.activation.UnknownObjectException)2 ArrayList (java.util.ArrayList)2 SystemadaptationFactory (org.iobserve.planning.systemadaptation.SystemadaptationFactory)2 ProcessingResourceSpecification (org.palladiosimulator.pcm.resourceenvironment.ProcessingResourceSpecification)2 System (org.palladiosimulator.pcm.system.System)2 File (java.io.File)1 URI (org.eclipse.emf.common.util.URI)1 DDiagramElement (org.eclipse.sirius.diagram.DDiagramElement)1 DEdge (org.eclipse.sirius.diagram.DEdge)1