Search in sources :

Example 1 with Neo4JModelResource

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

the class EvalProxyDBTest method test.

@Test
public void test() throws IOException, DBException {
    new File(EvalProxyDBTest.MODEL_ONE).delete();
    // create model
    final Root modelOne = TestModelData.createModelOne();
    final Two modelTwo = TestModelData.createModelTwo();
    final Registry resourceRegistry = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map = resourceRegistry.getExtensionToFactoryMap();
    map.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.setResourceFactoryRegistry(resourceRegistry);
    // put in resources
    final Resource resourceOne = resourceSet.createResource(URI.createFileURI(EvalProxyDBTest.MODEL_ONE));
    resourceOne.getContents().add(modelOne);
    final Resource resourceTwo = resourceSet.createResource(URI.createFileURI(EvalProxyDBTest.MODEL_TWO));
    resourceTwo.getContents().add(modelTwo);
    // save models
    resourceOne.save(null);
    resourceTwo.save(null);
    // store in DB
    final Neo4JModelResource<Root> dbResourceOne = ModelProviderTestUtils.prepareResource("testStoreGraphCreate1", this.prefix, TwoPackage.eINSTANCE);
    dbResourceOne.storeModelPartition(modelOne);
    final Neo4JModelResource<Two> dbResourceTwo = ModelProviderTestUtils.prepareResource("testStoreGraphCreate2", this.prefix, TwoPackage.eINSTANCE);
    dbResourceTwo.storeModelPartition(modelTwo);
    // retrieve model two
    final Two retrievedModelTwo = dbResourceTwo.getModelRootNode(Two.class, TwoPackage.Literals.TWO);
    this.checkProxies("A", retrievedModelTwo);
    ModelNeo4JUtil.printModel(retrievedModelTwo);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Root(org.iobserve.model.test.storage.one.Root) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) Resource(org.eclipse.emf.ecore.resource.Resource) Registry(org.eclipse.emf.ecore.resource.Resource.Factory.Registry) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Two(org.iobserve.model.test.storage.two.Two) File(java.io.File) Test(org.junit.Test)

Example 2 with Neo4JModelResource

use of org.iobserve.model.persistence.neo4j.Neo4JModelResource 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 3 with Neo4JModelResource

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

the class DeploymentModelUpdaterTest method prepareGraph.

/**
 * Prepare graph for model.
 *
 * @param name
 *            test directory name
 *
 * @return the prepared graph
 */
protected <T extends EObject> Neo4JModelResource<T> prepareGraph(final EPackage ePackage, final String name) {
    final File graphBaseDir = new File("testdb/" + this.getClass().getCanonicalName() + "/" + name);
    this.removeDirectory(graphBaseDir);
    return new Neo4JModelResource<>(ePackage, graphBaseDir);
}
Also used : Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) File(java.io.File)

Example 4 with Neo4JModelResource

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

the class UserBehaviorTransformationTest method testBranchWithinLoop.

/**
 * TODO this test is dysfunctional as models are missing Test branch within a loop.
 *
 * @throws IOException
 *             when reading and writing files.
 * @throws DBException
 */
// @Test
public void testBranchWithinLoop() throws IOException, DBException {
    final Neo4JModelResource<Repository> repositoryModelProvider = new Neo4JModelResource<>(RepositoryPackage.eINSTANCE, new File("x"));
    final RepositoryLookupModelProvider repositoryLookupModel = new RepositoryLookupModelProvider(repositoryModelProvider.getAndLockModelRootNode(Repository.class, RepositoryPackage.Literals.REPOSITORY));
    final int numberOfIterations = 500;
    final int stepSize = 1;
    final List<AccuracyResults> results = new ArrayList<>();
    for (int i = 1; i <= numberOfIterations; i += stepSize) {
        final int numberOfUserGroups = UserBehaviorTransformationTest.NUMBER_OF_USER_GROUPS;
        final int varianceOfUserGroups = 0;
        final int thinkTime = UserBehaviorTransformationTest.THINK_TIME;
        final boolean isClosedWorkload = UserBehaviorTransformationTest.CLOSED_WORKLOAD;
        final ReferenceElements referenceElements = SimpleSequenceReferenceHelper.getModel(UserBehaviorTransformationTest.REFERENCE_USAGE_MODEL, repositoryLookupModel, null, thinkTime, isClosedWorkload);
        final UserBehaviorTransformation behaviorModeling = new UserBehaviorTransformation(referenceElements.getEntryCallSequenceModel(), numberOfUserGroups, varianceOfUserGroups, isClosedWorkload, thinkTime, repositoryLookupModel, null);
        behaviorModeling.modelUserBehavior();
        final AccuracyResults accuracyResults = UserBehaviorEvaluation.matchUsageModels(behaviorModeling.getPcmUsageModel(), referenceElements.getUsageModel());
        results.add(accuracyResults);
        final double relativeMeasurementError = WorkloadEvaluationHelper.calculateRME(behaviorModeling.getPcmUsageModel(), referenceElements);
        if (UserBehaviorTransformationTest.LOGGER.isDebugEnabled()) {
            UserBehaviorTransformationTest.LOGGER.debug("RME " + relativeMeasurementError);
        }
        TestHelper.saveModel(behaviorModeling.getPcmUsageModel(), UserBehaviorTransformationTest.OUTPUT_USAGE_MODEL);
        if (UserBehaviorTransformationTest.LOGGER.isDebugEnabled()) {
            UserBehaviorTransformationTest.LOGGER.debug("Iteration :" + i + "/" + numberOfIterations);
        }
    }
    TestHelper.writeAccuracyResults(results);
}
Also used : Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) ArrayList(java.util.ArrayList) Repository(org.palladiosimulator.pcm.repository.Repository) UserBehaviorTransformation(org.iobserve.analysis.behavior.karlsruhe.UserBehaviorTransformation) File(java.io.File) RepositoryLookupModelProvider(org.iobserve.model.provider.deprecated.RepositoryLookupModelProvider)

Aggregations

File (java.io.File)4 Neo4JModelResource (org.iobserve.model.persistence.neo4j.Neo4JModelResource)4 Repository (org.palladiosimulator.pcm.repository.Repository)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Registry (org.eclipse.emf.ecore.resource.Resource.Factory.Registry)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)1 UserBehaviorTransformation (org.iobserve.analysis.behavior.karlsruhe.UserBehaviorTransformation)1 ModelImporter (org.iobserve.model.ModelImporter)1 CorrespondenceModel (org.iobserve.model.correspondence.CorrespondenceModel)1 DBException (org.iobserve.model.persistence.DBException)1 DataProtectionModel (org.iobserve.model.privacy.DataProtectionModel)1 RepositoryLookupModelProvider (org.iobserve.model.provider.deprecated.RepositoryLookupModelProvider)1 Root (org.iobserve.model.test.storage.one.Root)1 Two (org.iobserve.model.test.storage.two.Two)1 Test (org.junit.Test)1 Allocation (org.palladiosimulator.pcm.allocation.Allocation)1