Search in sources :

Example 1 with DBException

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

the class NonAdaptiveModelProbeController method computeAvailableProbes.

/**
 * Compute available probes.
 *
 * @return returns a map of {@link AllocationContext}s and their relevant
 *         {@link OperationSignature}s
 * @throws DBException
 */
private Map<AllocationContext, Set<OperationSignature>> computeAvailableProbes() throws DBException {
    final Repository repositoryModel = this.repositoryResource.getModelRootNode(Repository.class, RepositoryPackage.Literals.REPOSITORY);
    final List<AllocationContext> allocations = this.allocationResource.collectAllObjectsByType(AllocationContext.class, AllocationPackage.Literals.ALLOCATION_CONTEXT);
    final Map<AllocationContext, Set<OperationSignature>> availableProbes = new HashMap<>();
    this.logger.debug("Found " + allocations.size() + " allocation context entries");
    for (final AllocationContext allocation : allocations) {
        final Set<OperationSignature> allocationMethods = new LinkedHashSet<>();
        try {
            final AssemblyContext assemblyContext = this.systemModelResource.resolve(allocation.getAssemblyContext_AllocationContext());
            final RepositoryComponent component = this.repositoryResource.resolve(assemblyContext.getEncapsulatedComponent__AssemblyContext());
            final List<ProvidedRole> providingRoles = component.getProvidedRoles_InterfaceProvidingEntity();
            for (final ProvidedRole providedRole : providingRoles) {
                this.logger.debug("Providing roles: " + providingRoles);
                final String roleName = providedRole.getEntityName();
                for (final Interface iface : repositoryModel.getInterfaces__Repository()) {
                    if (iface instanceof OperationInterface) {
                        if (roleName.contains(iface.getEntityName())) {
                            this.logger.debug("Matching operation interfaces: " + ((OperationInterface) iface).getSignatures__OperationInterface());
                            // found interface
                            allocationMethods.addAll(((OperationInterface) iface).getSignatures__OperationInterface());
                        }
                    }
                }
            }
        } catch (InvocationException | DBException e) {
            this.logger.error("Could not resolve elements of the PCM during the computation of the available probes", e);
        }
        availableProbes.put(allocation, allocationMethods);
    }
    return availableProbes;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DBException(org.iobserve.model.persistence.DBException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashMap(java.util.HashMap) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) OperationInterface(org.palladiosimulator.pcm.repository.OperationInterface) AllocationContext(org.palladiosimulator.pcm.allocation.AllocationContext) Repository(org.palladiosimulator.pcm.repository.Repository) ProvidedRole(org.palladiosimulator.pcm.repository.ProvidedRole) OperationSignature(org.palladiosimulator.pcm.repository.OperationSignature) InvocationException(org.iobserve.model.persistence.neo4j.InvocationException) RepositoryComponent(org.palladiosimulator.pcm.repository.RepositoryComponent) OperationInterface(org.palladiosimulator.pcm.repository.OperationInterface) Interface(org.palladiosimulator.pcm.repository.Interface)

Example 2 with DBException

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

the class WhitelistFilter method computeForbiddenIps.

private Set<String> computeForbiddenIps(final Map<AllocationContext, Set<OperationSignature>> warnedMethods) {
    final Set<AllocationContext> allocationSet = new LinkedHashSet<>();
    allocationSet.addAll(warnedMethods.keySet());
    final Set<String> blacklistSet = new HashSet<>();
    for (final AllocationContext allocation : allocationSet) {
        try {
            blacklistSet.add(this.resourceEnvironmentResource.resolve(allocation.getResourceContainer_AllocationContext()).getEntityName());
        } catch (InvocationException | DBException e) {
            this.logger.error("Could not resolve resource container during the computation of the IP of the black list from: " + allocation, e);
        }
    }
    return blacklistSet;
}
Also used : AllocationContext(org.palladiosimulator.pcm.allocation.AllocationContext) LinkedHashSet(java.util.LinkedHashSet) DBException(org.iobserve.model.persistence.DBException) InvocationException(org.iobserve.model.persistence.neo4j.InvocationException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with DBException

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

the class AnalysisMain method createTeetimeConfiguration.

@Override
protected AnalysisConfiguration createTeetimeConfiguration() throws ConfigurationException {
    /**
     * Configure model handling.
     */
    if (this.parameterConfiguration.isPcmFeature()) {
        try {
            final ModelImporter modelHandler = new ModelImporter(this.parameterConfiguration.getModelInitDirectory());
            /**
             * initialize neo4j graphs.
             */
            final Neo4JModelResource<CorrespondenceModel> correspondenceModelResource = new Neo4JModelResource<>(CorrespondencePackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "correspondence"));
            correspondenceModelResource.storeModelPartition(modelHandler.getCorrespondenceModel());
            final Neo4JModelResource<Repository> repositoryModelResource = new Neo4JModelResource<>(RepositoryPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "repository"));
            repositoryModelResource.storeModelPartition(modelHandler.getRepositoryModel());
            final Neo4JModelResource<ResourceEnvironment> resourceEnvironmentModelResource = new Neo4JModelResource<>(ResourceenvironmentPackage.eINSTANCE, // add
            new File(this.parameterConfiguration.getModelDatabaseDirectory(), "resourceenvironment"));
            resourceEnvironmentModelResource.storeModelPartition(modelHandler.getResourceEnvironmentModel());
            final Neo4JModelResource<System> systemModelResource = new Neo4JModelResource<>(SystemPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "system"));
            systemModelResource.storeModelPartition(modelHandler.getSystemModel());
            final Neo4JModelResource<Allocation> allocationModelResource = new Neo4JModelResource<>(AllocationPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "allocation"));
            allocationModelResource.storeModelPartition(modelHandler.getAllocationModel());
            final Neo4JModelResource<UsageModel> usageModelResource = new Neo4JModelResource<>(UsagemodelPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "usageModel"));
            usageModelResource.storeModelPartition(modelHandler.getUsageModel());
            final Neo4JModelResource<DataProtectionModel> privacyModelResource = new Neo4JModelResource<>(PrivacyPackage.eINSTANCE, new File(this.parameterConfiguration.getModelDatabaseDirectory(), "privacy"));
            privacyModelResource.storeModelPartition(modelHandler.getPrivacyModel());
            // get systemId
            final System systemModel = systemModelResource.getModelRootNode(System.class, SystemPackage.Literals.SYSTEM);
            this.kiekerConfiguration.setProperty(ConfigurationKeys.SYSTEM_ID, systemModel.getId());
            return new AnalysisConfiguration(this.kiekerConfiguration, repositoryModelResource, resourceEnvironmentModelResource, systemModelResource, allocationModelResource, usageModelResource, correspondenceModelResource);
        } catch (final IOException e) {
            // TODO should be replaced by logger
            // NOPMD
            java.lang.System.err.println("Cannot load all models " + e.getLocalizedMessage());
            // required
            return null;
        } catch (final DBException e) {
            // TODO should be replaced by logger
            // NOPMD
            java.lang.System.err.println("Cannot store all models in DB " + e.getLocalizedMessage());
            // required
            return null;
        }
    } else {
        return new AnalysisConfiguration(this.kiekerConfiguration);
    }
}
Also used : Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) 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) UsageModel(org.palladiosimulator.pcm.usagemodel.UsageModel) File(java.io.File)

Example 4 with DBException

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

the class NetworkLink method execute.

/**
 * Execute this filter.
 *
 * @param event
 *            event to use
 * @throws NodeLookupException
 * @throws DBException
 *             on db errors
 */
@Override
protected void execute(final TraceMetadata event) throws NodeLookupException, DBException {
    final ResourceEnvironment resourceEnvironment = this.resourceEnvironmentModelResource.getAndLockModelRootNode(ResourceEnvironment.class, ResourceenvironmentPackage.Literals.RESOURCE_ENVIRONMENT);
    final System system = this.systemModelResource.getModelRootNode(System.class, SystemPackage.Literals.SYSTEM);
    final Allocation allocation = this.allocationModelResource.getModelRootNode(Allocation.class, AllocationPackage.Literals.ALLOCATION);
    NetworkLink.collectUnLinkedResourceContainer(resourceEnvironment).stream().forEach(unLinkedResCont -> {
        NetworkLink.getAsmContextDeployedOnContainer(allocation, unLinkedResCont).stream().map(asmCtx -> NetworkLink.getConnectedAsmCtx(system, asmCtx)).map(listAsmCtxToConnect -> NetworkLink.collectResourceContainer(allocation, listAsmCtxToConnect)).map(listResContToConnectTo -> NetworkLink.getLinkingResources(resourceEnvironment, listResContToConnectTo)).flatMap(l -> l.stream()).collect(Collectors.toList()).stream().forEach(link -> link.getConnectedResourceContainers_LinkingResource().add(unLinkedResCont));
    });
    this.resourceEnvironmentModelResource.updatePartition(resourceEnvironment);
}
Also used : Logger(org.slf4j.Logger) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) ResourceenvironmentPackage(org.palladiosimulator.pcm.resourceenvironment.ResourceenvironmentPackage) AssemblyConnector(org.palladiosimulator.pcm.core.composition.AssemblyConnector) LoggerFactory(org.slf4j.LoggerFactory) NodeLookupException(org.iobserve.model.persistence.neo4j.NodeLookupException) Connector(org.palladiosimulator.pcm.core.composition.Connector) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) Collectors(java.util.stream.Collectors) Allocation(org.palladiosimulator.pcm.allocation.Allocation) DBException(org.iobserve.model.persistence.DBException) List(java.util.List) Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) AbstractConsumerStage(teetime.framework.AbstractConsumerStage) LinkingResource(org.palladiosimulator.pcm.resourceenvironment.LinkingResource) Optional(java.util.Optional) System(org.palladiosimulator.pcm.system.System) AllocationPackage(org.palladiosimulator.pcm.allocation.AllocationPackage) SystemPackage(org.palladiosimulator.pcm.system.SystemPackage) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer) ResourceEnvironment(org.palladiosimulator.pcm.resourceenvironment.ResourceEnvironment) Allocation(org.palladiosimulator.pcm.allocation.Allocation) System(org.palladiosimulator.pcm.system.System)

Example 5 with DBException

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

the class MemoryModelResource method deleteObject.

@SuppressWarnings("unchecked")
@Override
public <T> void deleteObject(final EObject object) throws DBException {
    final EObject container = object.eContainer();
    final EStructuralFeature feature = object.eContainingFeature();
    if (feature.isMany()) {
        if (!((EList<EObject>) container.eGet(feature)).remove(object)) {
            throw new DBException("Object does not exist in database.");
        }
    } else {
        container.eSet(feature, null);
    }
}
Also used : DBException(org.iobserve.model.persistence.DBException) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

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