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));
}
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));
}
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;
}
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;
}
}
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;
}
Aggregations