Search in sources :

Example 6 with ResourceEnvironment

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

the class ResourceEnvironmentModelProviderTest method createThenReadContaining.

@Override
@Test
public void createThenReadContaining() {
    final ModelProvider<ResourceEnvironment> modelProvider = new ModelProvider<>(ResourceEnvironmentModelProviderTest.graph);
    final ResourceEnvironment writtenModel = new TestModelBuilder().getResourceEnvironment();
    final ResourceContainer writtenContainer = writtenModel.getResourceContainer_ResourceEnvironment().get(0);
    final ResourceEnvironment readModel;
    modelProvider.createComponent(writtenModel);
    readModel = (ResourceEnvironment) modelProvider.readOnlyContainingComponentById(ResourceContainer.class, writtenContainer.getId());
    Assert.assertTrue(this.equalityHelper.equals(writtenModel, readModel));
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer) Test(org.junit.Test)

Example 7 with ResourceEnvironment

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

the class ResourceEnvironmentModelProviderTest method createThenCloneThenRead.

@Override
@Test
public void createThenCloneThenRead() {
    final ModelProvider<ResourceEnvironment> modelProvider1 = new ModelProvider<>(ResourceEnvironmentModelProviderTest.graph);
    final ModelProvider<ResourceEnvironment> modelProvider2;
    final ResourceEnvironment writtenModel = new TestModelBuilder().getResourceEnvironment();
    final ResourceEnvironment readModel;
    final Graph graph2;
    modelProvider1.createComponent(writtenModel);
    graph2 = modelProvider1.cloneNewGraphVersion(ResourceEnvironment.class);
    modelProvider2 = new ModelProvider<>(graph2);
    readModel = modelProvider2.readOnlyRootComponent(ResourceEnvironment.class);
    graph2.getGraphDatabaseService().shutdown();
    Assert.assertTrue(this.equalityHelper.equals(writtenModel, readModel));
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) Test(org.junit.Test)

Example 8 with ResourceEnvironment

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

the class ModelProvider method createNodes.

/**
 * Helper method for writing: Writes the given component into the provider's {@link #graph}
 * recursively. Calls to this method have to be performed from inside a {@link Transaction}.
 *
 * @param component
 *            Component to save
 * @param containmentsAndDatatypes
 *            Set of EObjects contained in the root preferably created by
 *            {@link #getAllContainmentsAndDatatypes(EObject, HashSet)}
 * @param objectsToCreatedNodes
 *            Initially empty map of EObjects to already created correspondent nodes to make
 *            sure nodes are written just once
 * @return Root node of the component's graph
 */
private Node createNodes(final EObject component, final Set<EObject> containmentsAndDatatypes, final Map<EObject, Node> objectsToCreatedNodes) {
    // Create a label representing the type of the component
    final Label label = Label.label(ModelProviderUtil.getTypeName(component.eClass()));
    Node node = null;
    // Check if node has already been created
    final EAttribute idAttr = component.eClass().getEIDAttribute();
    if (idAttr != null) {
        node = this.graph.getGraphDatabaseService().findNode(label, ModelProvider.ID, component.eGet(idAttr));
    } else if (component instanceof PrimitiveDataType) {
        node = this.graph.getGraphDatabaseService().findNode(label, ModelProvider.TYPE, ((PrimitiveDataType) component).getType().name());
    } else if (component instanceof UsageModel || component instanceof ResourceEnvironment) {
        final ResourceIterator<Node> nodes = this.graph.getGraphDatabaseService().findNodes(Label.label(component.eClass().getName()));
        if (nodes.hasNext()) {
            node = nodes.next();
        }
    } else {
        // For components that cannot be found in the graph (e.g. due to missing id) but have
        // been created in this recursion
        node = objectsToCreatedNodes.get(component);
    }
    // If there is no node yet, create one
    if (node == null) {
        node = this.graph.getGraphDatabaseService().createNode(label);
        objectsToCreatedNodes.put(component, node);
        // Create a URI to enable proxy resolving
        final URI uri = ((BasicEObjectImpl) component).eProxyURI();
        if (uri == null) {
            node.setProperty(ModelProvider.EMF_URI, ModelProviderUtil.getUriString(component));
        } else {
            node.setProperty(ModelProvider.EMF_URI, uri.toString());
        }
        // Save attributes as node properties
        for (final EAttribute attr : component.eClass().getEAllAttributes()) {
            final Object value = component.eGet(attr);
            if (value != null) {
                node.setProperty(attr.getName(), value.toString());
            }
        }
        // otherwise we just store the blank node as a proxy
        if (containmentsAndDatatypes.contains(component)) {
            for (final EReference ref : component.eClass().getEAllReferences()) {
                final Object refReprensation = component.eGet(ref);
                // 0..* refs are represented as a list and 1 refs are represented directly
                if (refReprensation instanceof EList<?>) {
                    final EList<?> refs = (EList<?>) component.eGet(ref);
                    for (int i = 0; i < refs.size(); i++) {
                        final Object o = refs.get(i);
                        final Node refNode = this.createNodes((EObject) o, containmentsAndDatatypes, objectsToCreatedNodes);
                        final Relationship rel = node.createRelationshipTo(refNode, ModelProviderUtil.getRelationshipType(ref, o));
                        rel.setProperty(ModelProvider.REF_NAME, ref.getName());
                        rel.setProperty(ModelProvider.REF_POS, i);
                    }
                } else {
                    if (refReprensation != null) {
                        final Node refNode = this.createNodes((EObject) refReprensation, containmentsAndDatatypes, objectsToCreatedNodes);
                        final Relationship rel = node.createRelationshipTo(refNode, ModelProviderUtil.getRelationshipType(ref, refReprensation));
                        rel.setProperty(ModelProvider.REF_NAME, ref.getName());
                        rel.setProperty(ModelProvider.REF_POS, 0);
                    }
                }
            }
        }
    }
    return node;
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) URI(org.eclipse.emf.common.util.URI) BasicEObjectImpl(org.eclipse.emf.ecore.impl.BasicEObjectImpl) EAttribute(org.eclipse.emf.ecore.EAttribute) PrimitiveDataType(org.palladiosimulator.pcm.repository.PrimitiveDataType) EList(org.eclipse.emf.common.util.EList) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) Relationship(org.neo4j.graphdb.Relationship) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference)

Example 9 with ResourceEnvironment

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

the class AnalysisMain method createConfiguration.

@Override
protected AnalysisConfiguration createConfiguration(final Configuration configuration) throws ConfigurationException {
    /**
     * Configure model handling.
     */
    // old model providers without neo4j
    final PCMModelHandler modelFileHandler = new PCMModelHandler(this.modelInitDirectory);
    final ICorrespondence correspondenceModel = modelFileHandler.getCorrespondenceModel();
    /**
     * initialize neo4j graphs.
     */
    final GraphLoader graphLoader = new GraphLoader(this.modelDatabaseDirectory);
    Graph repositoryModelGraph = graphLoader.initializeRepositoryModelGraph(modelFileHandler.getRepositoryModel());
    Graph resourceEnvironmentGraph = graphLoader.initializeResourceEnvironmentModelGraph(modelFileHandler.getResourceEnvironmentModel());
    Graph allocationModelGraph = graphLoader.initializeAllocationModelGraph(modelFileHandler.getAllocationModel());
    Graph systemModelGraph = graphLoader.initializeSystemModelGraph(modelFileHandler.getSystemModel());
    Graph usageModelGraph = graphLoader.initializeUsageModelGraph(modelFileHandler.getUsageModel());
    /**
     * load neo4j graphs.
     */
    repositoryModelGraph = graphLoader.createRepositoryModelGraph();
    resourceEnvironmentGraph = graphLoader.createResourceEnvironmentModelGraph();
    allocationModelGraph = graphLoader.createAllocationModelGraph();
    systemModelGraph = graphLoader.createSystemModelGraph();
    usageModelGraph = graphLoader.createUsageModelGraph();
    /**
     * new graphModelProvider.
     */
    final IModelProvider<Repository> repositoryModelProvider = new ModelProvider<>(repositoryModelGraph);
    final IModelProvider<ResourceEnvironment> resourceEnvironmentModelProvider = new ModelProvider<>(resourceEnvironmentGraph);
    final IModelProvider<Allocation> allocationModelProvider = new ModelProvider<>(allocationModelGraph);
    final IModelProvider<org.palladiosimulator.pcm.system.System> systemModelProvider = new ModelProvider<>(systemModelGraph);
    final IModelProvider<UsageModel> usageModelProvider = new ModelProvider<>(usageModelGraph);
    // get systemId
    final org.palladiosimulator.pcm.system.System systemModel = systemModelProvider.readOnlyRootComponent(org.palladiosimulator.pcm.system.System.class);
    final String systemId = systemModel.getId();
    try {
        /**
         * URLs for sending updates to the deployment visualization.
         */
        // TODO this should be moved to the visualization sinks
        final String[] sinks = configuration.getStringArrayProperty(ConfigurationKeys.CONTAINER_MANAGEMENT_SINK, ",");
        if (sinks.length > 0) {
            final InitializeDeploymentVisualization deploymentVisualization = new InitializeDeploymentVisualization(this.containerManagementVisualizationBaseUrl, systemId, allocationModelProvider, systemModelProvider, resourceEnvironmentModelProvider);
            deploymentVisualization.initialize();
        }
        return new AnalysisConfiguration(configuration, repositoryModelProvider, resourceEnvironmentModelProvider, allocationModelProvider, systemModelProvider, usageModelProvider, correspondenceModel);
    } catch (final MalformedURLException e) {
        AbstractServiceMain.LOGGER.debug("URL construction for deployment visualization failed.", e);
        return null;
    } catch (final IOException e) {
        AbstractServiceMain.LOGGER.debug("Deployment visualization could not connect to visualization service.", e);
        return null;
    }
}
Also used : ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) MalformedURLException(java.net.MalformedURLException) IModelProvider(org.iobserve.model.provider.neo4j.IModelProvider) ModelProvider(org.iobserve.model.provider.neo4j.ModelProvider) Allocation(org.palladiosimulator.pcm.allocation.Allocation) ICorrespondence(org.iobserve.model.correspondence.ICorrespondence) AnalysisConfiguration(org.iobserve.analysis.configurations.AnalysisConfiguration) PCMModelHandler(org.iobserve.model.PCMModelHandler) IOException(java.io.IOException) Repository(org.palladiosimulator.pcm.repository.Repository) Graph(org.iobserve.model.provider.neo4j.Graph) GraphLoader(org.iobserve.model.provider.neo4j.GraphLoader) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel)

Example 10 with ResourceEnvironment

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

the class ResourceContainerActionFactory method createAcquireAction.

/**
 * Create a acquire action.
 *
 * @param reDeploymentServer
 *            the node where components can be deployed on
 * @return the action
 */
public static AcquireAction createAcquireAction(final DeploymentNode reDeploymentServer) {
    final SystemadaptationFactory factory = SystemadaptationFactory.eINSTANCE;
    final AcquireAction action = factory.createAcquireAction();
    final ResourceEnvironment reDeplResEnvModel = ActionFactory.getRedeploymentModels().getResourceEnvironmentModel();
    final ResourceContainer resourceContainer = ActionFactory.getResourceContainer(reDeploymentServer.getResourceContainerID(), reDeplResEnvModel);
    action.setSourceResourceContainer(resourceContainer);
    return action;
}
Also used : AcquireAction(org.iobserve.planning.systemadaptation.AcquireAction) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) SystemadaptationFactory(org.iobserve.planning.systemadaptation.SystemadaptationFactory) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Aggregations

ResourceEnvironment (org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment)55 ResourceContainer (org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)23 Test (org.junit.Test)15 CostRepository (de.uka.ipd.sdq.pcm.cost.CostRepository)12 Allocation (org.palladiosimulator.pcm.allocation.Allocation)12 LinkingResource (org.palladiosimulator.pcm.resourceenvironment.LinkingResource)12 VMType (org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.VMType)11 CloudProfile (org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudProfile)8 ResourceContainerCloud (org.palladiosimulator.pcm.cloud.pcmcloud.resourceenvironmentcloud.ResourceContainerCloud)8 System (org.palladiosimulator.pcm.system.System)8 CloudProvider (org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudProvider)7 CloudResourceType (org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudResourceType)7 EObject (org.eclipse.emf.ecore.EObject)6 ProcessingResourceSpecification (org.palladiosimulator.pcm.resourceenvironment.ProcessingResourceSpecification)6 UsageModel (org.palladiosimulator.pcm.usagemodel.UsageModel)6 IOException (java.io.IOException)5 URI (org.eclipse.emf.common.util.URI)5 PCMModelHandler (org.iobserve.model.PCMModelHandler)5 ResourceEnvironmentModelHandler (org.iobserve.model.provider.file.ResourceEnvironmentModelHandler)5 AllocationContext (org.palladiosimulator.pcm.allocation.AllocationContext)5