Search in sources :

Example 6 with DBException

use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.

the class Neo4JModelResource method resolve.

/**
 * Resolve proxy object.
 *
 * @param proxyObject
 *            resolve proxy object
 * @param <T>
 *            type
 * @throws InvocationException
 *             when called with a null object
 * @throws DBException
 *             on database issues
 *
 * @return returns the resolved objects
 */
@Override
@SuppressWarnings("unchecked")
public <T extends EObject> T resolve(final T proxyObject) throws InvocationException, DBException {
    if (proxyObject == null) {
        throw new InvocationException("Object reference is null, cannot resolve.");
    }
    if (proxyObject.eIsProxy()) {
        try (Transaction tx = this.graphDatabaseService.beginTx()) {
            final Node realNode = ModelGraphFactory.findNode(this.graphDatabaseService, proxyObject);
            if (realNode == null) {
                throw new DBException(String.format("Object '%s' has no representing node.", ModelGraphFactory.getIdentification(proxyObject)));
            }
            final Map<Node, EObject> nodesToCreatedObjects = new HashMap<>();
            this.queryModelFacility.readContainedNodesRecursively(realNode, nodesToCreatedObjects);
            final EObject realObject = nodesToCreatedObjects.get(realNode);
            for (final EAttribute attribute : proxyObject.eClass().getEAllAttributes()) {
                proxyObject.eSet(attribute, realObject.eGet(attribute));
            }
            for (final EReference reference : proxyObject.eClass().getEAllReferences()) {
                if (reference.isMany()) {
                    final EList<EObject> manyReference = (EList<EObject>) realObject.eGet(reference);
                    ((EList<EObject>) proxyObject.eGet(reference)).addAll(manyReference);
                } else {
                    final EObject singleReference = (EObject) realObject.eGet(reference);
                    ((EObject) proxyObject).eSet(reference, singleReference);
                }
            }
            tx.success();
        } catch (final TransactionFailureException ex) {
            Neo4JModelResource.LOGGER.error("Cannot create transaction to resolve data.");
        }
        return proxyObject;
    } else {
        return proxyObject;
    }
}
Also used : DBException(org.iobserve.model.persistence.DBException) EAttribute(org.eclipse.emf.ecore.EAttribute) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) EList(org.eclipse.emf.common.util.EList) Transaction(org.neo4j.graphdb.Transaction) HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference)

Example 7 with DBException

use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.

the class QueryModelFacility method scanSingleContainmentReference.

private void scanSingleContainmentReference(final Relationship relationship, final Map<Node, EObject> nodesToCreatedObjects) throws DBException {
    final Node targetNode = relationship.getEndNode();
    if (!nodesToCreatedObjects.containsKey(targetNode)) {
        if (ModelGraphFactory.isProxyNode(targetNode)) {
            throw new DBException(String.format("Proxy object in the containment hierarchy is an internal error. Relationship %s and node %s", relationship.getProperty(ModelProviderUtil.REF_NAME), targetNode.getProperty(ModelGraphFactory.EMF_INTERNAL_ID)));
        } else {
            final EObject targetObject = ModelObjectFactory.createObject(targetNode, this.factories);
            this.scanContainmentReferences(targetNode, nodesToCreatedObjects);
            nodesToCreatedObjects.put(targetNode, targetObject);
        }
    }
}
Also used : DBException(org.iobserve.model.persistence.DBException) Node(org.neo4j.graphdb.Node) EObject(org.eclipse.emf.ecore.EObject)

Example 8 with DBException

use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.

the class TEntryEventSequence method execute.

@Override
protected void execute(final UserSessionCollectionModel entryCallSequenceModel) throws DBException {
    // Resets the current usage model
    final UsageModel model = this.usageModelProvider.getAndLockModelRootNode(UsageModel.class, UsagemodelPackage.Literals.USAGE_MODEL);
    int numberOfUserGroups = model.getUsageScenario_UsageModel().size();
    TEntryEventSequence.LOGGER.debug("EntryEventSequence found: numberOfUserGroups before: {}", numberOfUserGroups);
    // Executes the user behavior modeling procedure
    final UserBehaviorTransformation behaviorModeling = new UserBehaviorTransformation(entryCallSequenceModel, numberOfUserGroups, this.varianceOfUserGroups, this.closedWorkload, this.thinkTime, this.repositoryLookupModel, this.correspondenceModel);
    try {
        behaviorModeling.modelUserBehavior();
        model.getUsageScenario_UsageModel().clear();
        model.getUserData_UsageModel().clear();
        final UsageModel newModel = behaviorModeling.getPcmUsageModel();
        model.getUsageScenario_UsageModel().addAll(newModel.getUsageScenario_UsageModel());
        model.getUserData_UsageModel().addAll(newModel.getUserData_UsageModel());
        numberOfUserGroups = model.getUsageScenario_UsageModel().size();
        TEntryEventSequence.LOGGER.debug("Model changed: numberOfUserGroups after: {}", numberOfUserGroups);
    } catch (final IOException e) {
        e.printStackTrace();
    }
    // Sets the new usage model within iObserve
    this.usageModelProvider.clearResource();
    try {
        this.usageModelProvider.storeModelPartition(model);
    } catch (final DBException e) {
        e.printStackTrace();
    }
    this.outputPort.send(behaviorModeling.getPcmUsageModel());
    this.outputPortSnapshot.send(false);
}
Also used : DBException(org.iobserve.model.persistence.DBException) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) IOException(java.io.IOException) UserBehaviorTransformation(org.iobserve.analysis.behavior.karlsruhe.UserBehaviorTransformation)

Example 9 with DBException

use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.

the class ModelGraphFactory method deleteLinkedProxyNodes.

/**
 * Delete proxy nodes connected to the sourceNode, iff they have only the relationship to the
 * sourceNode. Else delete the relationship.
 *
 * @param sourceNode
 *            source node
 * @throws DBException
 *             on db errors
 */
private static void deleteLinkedProxyNodes(final Node sourceNode) throws DBException {
    for (final Relationship relationship : sourceNode.getRelationships(Direction.OUTGOING)) {
        final Node targetNode = relationship.getEndNode();
        if (ModelGraphFactory.isProxyNode(targetNode)) {
            final Iterator<Relationship> proxyRelationships = targetNode.getRelationships(Direction.INCOMING).iterator();
            /**
             * check for more than one incoming.
             */
            if (proxyRelationships.hasNext()) {
                proxyRelationships.next();
                if (proxyRelationships.hasNext()) {
                    /**
                     * two incoming, remove just the relationship.
                     */
                    relationship.delete();
                } else {
                    /**
                     * one relationship; delete relationship and node.
                     */
                    relationship.delete();
                    targetNode.delete();
                }
            } else {
                throw new DBException("There is an relationship form a -> b, but b has no incoming relationship. Consistency error.");
            }
        }
    }
}
Also used : DBException(org.iobserve.model.persistence.DBException) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node)

Example 10 with DBException

use of org.iobserve.model.persistence.DBException in project iobserve-analysis by research-iobserve.

the class PrivacyViolationDetectionServiceMain method createTeetimeConfiguration.

@Override
protected PipelineConfiguration createTeetimeConfiguration() throws ConfigurationException {
    /**
     * load models.
     */
    try {
        final ModelImporter modelHandler = new ModelImporter(this.parameterConfiguration.getModelInitDirectory());
        /**
         * initialize database.
         */
        final IModelResource<CorrespondenceModel> correspondenceModelResource = this.loadResourceAndInitDB(CorrespondencePackage.eINSTANCE, modelHandler.getCorrespondenceModel());
        final IModelResource<Repository> repositoryModelResource = this.loadResourceAndInitDB(RepositoryPackage.eINSTANCE, modelHandler.getRepositoryModel());
        final IModelResource<ResourceEnvironment> resourceEnvironmentModelResource = this.loadResourceAndInitDB(ResourceenvironmentPackage.eINSTANCE, modelHandler.getResourceEnvironmentModel());
        final IModelResource<System> systemModelResource = this.loadResourceAndInitDB(SystemPackage.eINSTANCE, modelHandler.getSystemModel());
        final IModelResource<Allocation> allocationModelResource = this.loadResourceAndInitDB(AllocationPackage.eINSTANCE, modelHandler.getAllocationModel());
        final IModelResource<DataProtectionModel> privacyModelResource = this.loadResourceAndInitDB(PrivacyPackage.eINSTANCE, modelHandler.getPrivacyModel());
        return new PipelineConfiguration(this.kiekerConfiguration, correspondenceModelResource, repositoryModelResource, resourceEnvironmentModelResource, systemModelResource, allocationModelResource, privacyModelResource, this.parameterConfiguration.getWarningFile(), this.parameterConfiguration.getAlarmsFile(), this.parameterConfiguration.getModelDumpDirectory());
    } catch (final DBException | IOException e) {
        throw new ConfigurationException(e);
    }
}
Also used : DBException(org.iobserve.model.persistence.DBException) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) DataProtectionModel(org.iobserve.model.privacy.DataProtectionModel) CorrespondenceModel(org.iobserve.model.correspondence.CorrespondenceModel) IOException(java.io.IOException) System(org.palladiosimulator.pcm.system.System) ModelImporter(org.iobserve.model.ModelImporter) Repository(org.palladiosimulator.pcm.repository.Repository) Allocation(org.palladiosimulator.pcm.allocation.Allocation) ConfigurationException(kieker.common.exception.ConfigurationException)

Aggregations

DBException (org.iobserve.model.persistence.DBException)11 IOException (java.io.IOException)3 LinkedHashSet (java.util.LinkedHashSet)3 EObject (org.eclipse.emf.ecore.EObject)3 InvocationException (org.iobserve.model.persistence.neo4j.InvocationException)3 Node (org.neo4j.graphdb.Node)3 Allocation (org.palladiosimulator.pcm.allocation.Allocation)3 AllocationContext (org.palladiosimulator.pcm.allocation.AllocationContext)3 Repository (org.palladiosimulator.pcm.repository.Repository)3 ResourceEnvironment (org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment)3 System (org.palladiosimulator.pcm.system.System)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ModelImporter (org.iobserve.model.ModelImporter)2 CorrespondenceModel (org.iobserve.model.correspondence.CorrespondenceModel)2 Neo4JModelResource (org.iobserve.model.persistence.neo4j.Neo4JModelResource)2 DataProtectionModel (org.iobserve.model.privacy.DataProtectionModel)2 AssemblyContext (org.palladiosimulator.pcm.core.composition.AssemblyContext)2 File (java.io.File)1 List (java.util.List)1