Search in sources :

Example 21 with ResourceContainer

use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.

the class InitializeDeploymentVisualization method getTechnology.

/**
 * Help function for getting the technology used for communication. Therefore get the
 * {@link ResourceContainer}s on which the two communicating {@link AssemblyContext}s are
 * deployed. This information is stored in the {@link Allocation} model. Then find the
 * {@link LinkingResource} in the {@link ResourceEnvironment} model, that connect these
 * {@link ResourceContainer}s.
 *
 * @param connector
 *            assembly connector
 * @param linkingResources
 *            list of linking resources
 * @return technology used for communication, entity name of linking resource
 */
private String getTechnology(final AssemblyConnector connector, final List<LinkingResource> linkingResources) {
    final String assemblyContextSourceId = connector.getProvidingAssemblyContext_AssemblyConnector().getId();
    final String assemblyContextTargetId = connector.getRequiringAssemblyContext_AssemblyConnector().getId();
    /**
     * ID of resource container on which source (regarding communication) assembly context is
     * deployed
     */
    final String resourceSourceId = this.findResourceIdByAssemblyContextId(assemblyContextSourceId);
    /**
     * ID of resource container on which target (regarding communication) assembly context is
     * deployed
     */
    final String resourceTargetId = this.findResourceIdByAssemblyContextId(assemblyContextTargetId);
    /**
     * technology of communication
     */
    String technology = null;
    if (resourceSourceId != null && resourceTargetId != null) {
        for (int l = 0; l < linkingResources.size(); l++) {
            final LinkingResource linkingResource = linkingResources.get(l);
            if (linkingResource instanceof LinkingResourceImpl) {
                final List<ResourceContainer> connectedResourceConts = linkingResource.getConnectedResourceContainers_LinkingResource();
                final List<String> connectedResourceContsIds = new ArrayList<>();
                for (int k = 0; k < connectedResourceConts.size(); k++) {
                    connectedResourceContsIds.add(connectedResourceConts.get(k).getId());
                }
                if (connectedResourceContsIds.contains(resourceSourceId) && connectedResourceContsIds.contains(resourceTargetId)) {
                    technology = linkingResource.getEntityName();
                }
            }
        }
    }
    return technology;
}
Also used : LinkingResource(org.palladiosimulator.pcm.resourceenvironment.LinkingResource) ArrayList(java.util.ArrayList) LinkingResourceImpl(org.palladiosimulator.pcm.resourceenvironment.impl.LinkingResourceImpl) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 22 with ResourceContainer

use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.

the class InitializeDeploymentVisualization method initialize.

/**
 * Populates the database of the deployment visualization initially and respects the changelog
 * constraints of iobserve-ui-deployment. It takes information from the system model, the
 * allocation model and the resource environment model and creates corresponding visualization
 * components, e.g. nodes and services.
 *
 * @throws IOException
 *             when post request fails
 */
public void initialize() throws IOException {
    // set up the system model and take parts from it
    final org.palladiosimulator.pcm.system.System systemModel = this.systemModelGraphProvider.readOnlyRootComponent(org.palladiosimulator.pcm.system.System.class);
    final List<AssemblyContext> assemblyContexts = systemModel.getAssemblyContexts__ComposedStructure();
    // set up the allocation model and take parts from it
    final List<String> allocationIds = this.allocationModelGraphProvider.readComponentByType(Allocation.class);
    // an allocation model contains exactly one allocation, therefore .get(0)
    final String allocationId = allocationIds.get(0);
    final Allocation allocation = this.allocationModelGraphProvider.readOnlyComponentById(Allocation.class, allocationId);
    final List<AllocationContext> allocationContexts = allocation.getAllocationContexts_Allocation();
    // set up the resource environment model and take parts from it
    final ResourceEnvironment resourceEnvironmentModel = this.resourceEnvironmentModelGraphProvider.readOnlyRootComponent(ResourceEnvironment.class);
    final List<LinkingResource> linkingResources = resourceEnvironmentModel.getLinkingResources__ResourceEnvironment();
    final List<ResourceContainer> resourceContainers = resourceEnvironmentModel.getResourceContainer_ResourceEnvironment();
    // sending created components to visualization (in predefined order stated in changelog
    // constraints)
    /**
     * system
     */
    SendHttpRequest.post(this.systemService.createSystem(systemModel), this.systemUrl, this.changelogUrl);
    /**
     * node group and node
     */
    for (int i = 0; i < resourceContainers.size(); i++) {
        final ResourceContainer resourceContainer = resourceContainers.get(i);
        SendHttpRequest.post(Changelog.create(this.nodegroupService.createNodegroup(this.systemService.getSystemId())), this.systemUrl, this.changelogUrl);
        SendHttpRequest.post(Changelog.create(this.nodeService.createNode(resourceContainer, this.systemService.getSystemId(), this.nodegroupService.getNodegroupId())), this.systemUrl, this.changelogUrl);
    }
    /**
     * service and service instance
     */
    for (int i = 0; i < assemblyContexts.size(); i++) {
        final AssemblyContext assemblyContext = assemblyContexts.get(i);
        SendHttpRequest.post(Changelog.create(this.serviceService.createService(assemblyContext, this.systemService.getSystemId())), this.systemUrl, this.changelogUrl);
    }
    for (int i = 0; i < allocationContexts.size(); i++) {
        final AllocationContext allocationContext = allocationContexts.get(i);
        final String resourceContainerId = allocationContext.getResourceContainer_AllocationContext().getId();
        final AssemblyContext assemblyContext = allocationContext.getAssemblyContext_AllocationContext();
        final String assemblyContextId = allocationContext.getAssemblyContext_AllocationContext().getId();
        SendHttpRequest.post(Changelog.create(this.serviceinstanceService.createServiceInstance(assemblyContext, this.systemService.getSystemId(), resourceContainerId, assemblyContextId)), this.systemUrl, this.changelogUrl);
    }
    /**
     * communication and communication instance
     */
    final List<Connector> connectors = systemModel.getConnectors__ComposedStructure();
    for (int i = 0; i < connectors.size(); i++) {
        final Connector connector = connectors.get(i);
        // we are only interested in AssemblyConnectors
        if (connector instanceof AssemblyConnector) {
            final String technology = this.getTechnology((AssemblyConnector) connector, linkingResources);
            SendHttpRequest.post(Changelog.create(this.communicationService.createCommunication((AssemblyConnector) connector, this.systemService.getSystemId(), technology)), this.systemUrl, this.changelogUrl);
            SendHttpRequest.post(Changelog.create(this.communicationinstanceService.createCommunicationInstance((AssemblyConnector) connector, this.systemService.getSystemId(), this.communicationService.getCommunicationId())), this.systemUrl, this.changelogUrl);
        } else {
            InitializeDeploymentVisualization.LOGGER.debug("no AssemblyConnector: connector.getEntityName()");
        }
    }
}
Also used : AssemblyConnector(org.palladiosimulator.pcm.core.composition.AssemblyConnector) Connector(org.palladiosimulator.pcm.core.composition.Connector) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) LinkingResource(org.palladiosimulator.pcm.resourceenvironment.LinkingResource) AssemblyConnector(org.palladiosimulator.pcm.core.composition.AssemblyConnector) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) AllocationContext(org.palladiosimulator.pcm.allocation.AllocationContext) Allocation(org.palladiosimulator.pcm.allocation.Allocation) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 23 with ResourceContainer

use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.

the class ResourceContainerActionFactory method createReplicateAction.

/**
 * Create replicate action.
 *
 * @param runtimeServer
 *            source server
 * @param reDeploymentServer
 *            target server
 * @return the action
 */
public static ReplicateAction createReplicateAction(final DeploymentNode runtimeServer, final DeploymentNode reDeploymentServer) {
    final SystemadaptationFactory factory = SystemadaptationFactory.eINSTANCE;
    final ReplicateAction action = factory.createReplicateAction();
    ResourceContainerActionFactory.setSourceResourceContainer(action, runtimeServer.getResourceContainerID());
    final Allocation runtimeAllocModel = ActionFactory.getRuntimeModels().getAllocationModel();
    for (final ComponentNode component : runtimeServer.getContainingComponents()) {
        final AllocationContext oldAllocationContext = ActionFactory.getAllocationContext(component.getAllocationContextID(), runtimeAllocModel);
        action.getSourceAllocationContext().add(oldAllocationContext);
    }
    final Allocation reDeplAllocModel = ActionFactory.getRedeploymentModels().getAllocationModel();
    for (final ComponentNode component : reDeploymentServer.getContainingComponents()) {
        final AllocationContext newAllocationContext = ActionFactory.getAllocationContext(component.getAllocationContextID(), reDeplAllocModel);
        action.getSourceAllocationContext().add(newAllocationContext);
    }
    final ResourceEnvironment resEnvModel = ActionFactory.getRedeploymentModels().getResourceEnvironmentModel();
    final ResourceContainer newResourceContainer = ActionFactory.getResourceContainer(reDeploymentServer.getResourceContainerID(), resEnvModel);
    action.setNewResourceContainer(newResourceContainer);
    return action;
}
Also used : AllocationContext(org.palladiosimulator.pcm.allocation.AllocationContext) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) Allocation(org.palladiosimulator.pcm.allocation.Allocation) SystemadaptationFactory(org.iobserve.planning.systemadaptation.SystemadaptationFactory) ComponentNode(org.iobserve.analysis.data.graph.ComponentNode) ReplicateAction(org.iobserve.planning.systemadaptation.ReplicateAction) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 24 with ResourceContainer

use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer in project iobserve-analysis by research-iobserve.

the class AllocateActionScript method execute.

@Override
public void execute() throws RunScriptOnNodesException, IOException {
    final ResourceContainer container = this.action.getNewAllocationContext().getResourceContainer_AllocationContext();
    final ResourceContainerCloud cloudContainer = this.getResourceContainerCloud(container);
    final ComputeService client = this.getComputeServiceForContainer(cloudContainer);
    final String assemblyContextName = this.action.getSourceAssemblyContext().getEntityName();
    // nothing
    if (!this.data.getAllocatedContexts().contains(assemblyContextName)) {
        client.runScriptOnNodesMatching(node -> node.getGroup().equals(cloudContainer.getGroupName()), this.getAllocateScript(this.action.getSourceAssemblyContext()));
        this.data.getAllocatedContexts().add(assemblyContextName);
    // TODO add possibility to open up ports defined in a config file
    }
}
Also used : ResourceContainerCloud(org.palladiosimulator.pcm.cloud.pcmcloud.resourceenvironmentcloud.ResourceContainerCloud) ComputeService(org.jclouds.compute.ComputeService) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 25 with ResourceContainer

use of org.palladiosimulator.pcm.resourceenvironment.ResourceContainer 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!");
        }
    }
}
Also used : AllocationContext(org.palladiosimulator.pcm.allocation.AllocationContext) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) 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