Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » VIATRA » How can I monitor my application using EMF and VIATRA query language?
How can I monitor my application using EMF and VIATRA query language? [message #1849830] Thu, 03 February 2022 17:07 Go to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hello dears,
I am new to VIATRA and modeling.
I want to implement a runtime model but I am confused. Actually I have a website and I want to monitor it using VIATRA Query.
I know how to create my model in EMF and how to generate related code. I know how to load model to .vql file and write query.

How can I monitor my model using EMF Model and VIATRA? I mean what is the steps? First I have to use my EMF Model API to create my runtime model and initialize it using my website information and then use generated VIATRA Query API to query to my model?

Please guide me :)

Thanks.

Re: How can I monitor my application using EMF and VIATRA query language? [message #1849840 is a reply to message #1849830] Fri, 04 February 2022 07:58 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

thanks for your interest in VIATRA. Sadly, I have to say, VIATRA is not capable in itself to monitor external services but can augment the capabilities of such monitoring systems.

The important aspect to consider is that VIATRA Query is used to query models (most commonly EMF models but can be extended to support others), but does not consider how that model was created or kept up-to-date. On the other hand, if your create an EMF-based model representation of your infrastructure and use the events received from the monitoring system to mark some elements not available in the model, you could use VIATRA queries to make visible some additional information, e.g. following the modelled dependency relationships you could figure out the set of affected services of an outage.

I hope this was helpful,
Zoltán
Re: How can I monitor my application using EMF and VIATRA query language? [message #1849875 is a reply to message #1849840] Sun, 06 February 2022 20:02 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hello,
Thanks for your reply.

I created a model using EMF and generate its code. By using my model APIs, I create an Object and initialize it. Now I want to load my object to Viatra query engine and query on it. How can I load my object?
For example If my model object name is web, I should use code below to initialize my engine?

// phase 1: (managed) ViatraQueryEngine
ViatraQueryEngine engine = ViatraQueryEngine.on(new EMFScope(web));


[Updated on: Mon, 07 February 2022 08:18]

Report message to a moderator

Re: How can I monitor my application using EMF and VIATRA query language? [message #1849880 is a reply to message #1849875] Mon, 07 February 2022 09:30 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

I am not sure whether I understand your question, but if you mean you are creating the EMF objects in-memory and they are not added to any resource or resource set, you can initialize the EMFScope object with one or more EObject instances that can represent the model roots. Note that new objects created after the engine is initialized should be present in the containment hierarchy otherwise the engine will not know about them.

Alternatively, if you are interested in how to access the resource set of an open editor, you might have a look at how the model connectors provided in VIATRA work: https://git.eclipse.org/c/viatra/org.eclipse.viatra.git/tree/query/plugins/org.eclipse.viatra.query.runtime.ui/src/org/eclipse/viatra/query/runtime/ui/modelconnector/EMFModelConnector.java#n102

Hope this helps, if not, please feel free to ask for clarification.

Best regards,
Zoltán
Re: How can I monitor my application using EMF and VIATRA query language? [message #1849886 is a reply to message #1849880] Mon, 07 February 2022 14:51 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hello,
Thanks for your attention.

I want use VIATRA for capturing safty properties of my real environment. I created my model using EMF. To be able to initialize my model at runtime, I create my model using its generated APIs.
Now I want to do query on my model but I don't know how to do this.
Am I on the wrong way?

To clarify what I really mean, I attached a simple code below.

Thanks

  • Attachment: MyProject.zip
    (Size: 159.67KB, Downloaded 226 times)
Re: How can I monitor my application using EMF and VIATRA query language? [message #1849891 is a reply to message #1849886] Mon, 07 February 2022 17:07 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

looking at your code, the answer is that instead of loading the model from a resource, you could do something as follows (I did not compile it, so there might be slight issues):
ResourceSet rs = new ResourceSetImpl();
Resource resource = rs.createResource(URI.createURI("uri name")); // as long as you are not planning to save the model, it is not important what the URI is

MainPage main = ...; // Use the code you have already created
...

resource.getContents().add(main); // If I have read your metamodel correctly, this should be enough as all other model elements are reachable with containment references starting from main; if not, add them as well


After that point, the created ResourceSet can be used as the model scope for the query engine.

Best regards,
Zoltán
Re: How can I monitor my application using EMF and VIATRA query language? [message #1849898 is a reply to message #1849891] Mon, 07 February 2022 19:43 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Thanks for your reply.
This code didn't work. and I get this error:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.eclipse.emf.ecore.resource.Resource.getContents()" because "resource" is null
	at com.myapplication.runtime.model.RuntimeModel.createModel(RuntimeModel.java:44)
	at com.myapplication.runtime.model.Main.main(Main.java:8)


Respectfully,
Atepheh

[Updated on: Mon, 07 February 2022 19:45]

Report message to a moderator

Re: How can I monitor my application using EMF and VIATRA query language? [message #1849911 is a reply to message #1849898] Tue, 08 February 2022 12:15 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

the error means the initialization of the resource failed, but I don't know what might be the issue without context. I'd check whether you have indeed used `rs.createResource` instead of `rs.getResource` - the latter might return a null resource.

Best regards,
Zoltán
Re: How can I monitor my application using EMF and VIATRA query language? [message #1850032 is a reply to message #1849911] Fri, 11 February 2022 15:07 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hello dear,
I fixed the "resource is null" error by using the following code:
ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml",new XMIResourceFactoryImpl());
Resource resource = rs.createResource(URI.createURI("test.xml"));

// create my model
MainPage main = ...
Webpage web = factory.createWebpage();
web.getMainpage().add(main);
		
resource.getContents().add(web);
scope = new EMFScope(resource);

But now, when I want to initialize ViatraQueryEngine with scope I facing with this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/collections/impl/map/mutable/UnifiedMap
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at org.eclipse.viatra.query.runtime.matchers.util.EclipseCollectionsFactory.createMultiLookup(EclipseCollectionsFactory.java:125)
	at org.eclipse.viatra.query.runtime.matchers.util.CollectionsFactory.createMultiLookup(CollectionsFactory.java:122)
	at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.<init>(ViatraQueryEngineImpl.java:104)
	at org.eclipse.viatra.query.runtime.api.ViatraQueryEngineManager.getQueryEngine(ViatraQueryEngineManager.java:104)
	at org.eclipse.viatra.query.runtime.api.ViatraQueryEngineManager.getQueryEngine(ViatraQueryEngineManager.java:84)
	at org.eclipse.viatra.query.runtime.api.ViatraQueryEngine.on(ViatraQueryEngine.java:68)
	at com.myapplication.runtime.model.RuntimeModel.queryOnModel(RuntimeModel.java:64)
	at com.myapplication.runtime.model.RuntimeModel.createModel(RuntimeModel.java:56)
	at com.myapplication.runtime.model.Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: org.eclipse.collections.impl.map.mutable.UnifiedMap
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	... 36 more

  • Attachment: MyProject.zip
    (Size: 160.84KB, Downloaded 234 times)

[Updated on: Fri, 11 February 2022 17:18]

Report message to a moderator

Re: How can I monitor my application using EMF and VIATRA query language? [message #1850054 is a reply to message #1850032] Mon, 14 February 2022 07:21 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
I fixed this issue with adding "org.eclipse.collections" to my plugin dependencies.
Re: How can I monitor my application using EMF and VIATRA query language? [message #1850060 is a reply to message #1850054] Mon, 14 February 2022 11:03 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

sorry for the late answer, if you are running a standalone Java application, it does not consider transitive dependencies from plug-in definitions, and the solution is either to run the application as an Eclipse plugin or to add the missing dependency directly (as you have done). However, if you are planning to use VIATRA in a standalone environment, instead of the plugin-based architecture we recommend using Maven or Gradle and add the dependency as described in https://www.eclipse.org/viatra/documentation/query-tools.html#viatra-maven-plugin.

Best regards,
Zoltán
Re: How can I monitor my application using EMF and VIATRA query language? [message #1850063 is a reply to message #1850054] Mon, 14 February 2022 14:01 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hello,
when I want to prepare the the engine via snippet code below, I faced with this error:
// phase 1: ViatraQueryEngine
ViatraQueryEngine engine = ViatraQueryEngine.on(scope);
// prepare engine 
WebsiteQuery.instance().prepare(engine); //This line has Error

Error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/viatra/query/runtime/base/itc/igraph/ITcDataSource
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at org.eclipse.viatra.query.runtime.emf.EMFEngineContext.getNavHelper(EMFEngineContext.java:56)
	at org.eclipse.viatra.query.runtime.emf.EMFEngineContext.getQueryRuntimeContext(EMFEngineContext.java:77)
	at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getQueryBackend(ViatraQueryEngineImpl.java:292)
	at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getResultProviderInternal(ViatraQueryEngineImpl.java:577)
	at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getResultProviderInternal(ViatraQueryEngineImpl.java:564)
	at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getResultProvider(ViatraQueryEngineImpl.java:553)
	at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getMatcher(ViatraQueryEngineImpl.java:219)
	at org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl.getMatcher(ViatraQueryEngineImpl.java:204)
	at com.viatra.website.monitoring.query.NumberOfRedClick$Matcher.on(NumberOfRedClick.java:264)
	at com.myapplication.runtime.model.RuntimeModel.queryOnModel(RuntimeModel.java:69)
	at com.myapplication.runtime.model.RuntimeModel.createModel(RuntimeModel.java:57)
	at com.myapplication.runtime.model.Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: org.eclipse.viatra.query.runtime.base.itc.igraph.ITcDataSource
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	... 21 more

Do you know how can I fix it?

Respectfully,
Atepheh
Re: How can I monitor my application using EMF and VIATRA query language? [message #1850068 is a reply to message #1850063] Mon, 14 February 2022 15:50 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

this is exactly the same issue as with the 'org.eclipse.collections' dependency - add the 'org.eclipse.viatra.query.runtime.base.itc' bundle as a dependency as well.

If you want a complete list of possible dependencies, have a look at the definition of the viatra-query-runtime module (https://git.eclipse.org/c/viatra/org.eclipse.viatra.git/tree/maven/viatra-query-runtime/pom.xml).

Best regards,
Zoltán
Re: How can I monitor my application using EMF and VIATRA query language? [message #1850107 is a reply to message #1850068] Wed, 16 February 2022 07:16 Go to previous message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hello,
Thanks dear Zoltán for your support. The error fixed.

Respectfully,
Atepheh

Previous Topic:Viatra Documentation Example not working
Next Topic:Determinism in event-driven transformation
Goto Forum:
  


Current Time: Mon Dec 09 21:00:47 GMT 2024

Powered by FUDForum. Page generated in 0.04824 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top