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