Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » VIATRA » Viatra Documentation Example not working
Viatra Documentation Example not working [message #1848667] Mon, 13 December 2021 15:16 Go to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hello,

I read "GETTING STARTED WITH VIATRA" tutorial and try to execute "4.2 Event-driven Transformations" section, but I faced with some errors.

I fixed all of them except one.

For code below I got this error: "The method or field depElement is undefined for the type Optional<Match>"

val depHost = engine.cps2depTrace.getOneArbitraryMatch(cps2dep, null, hostInstance, null).depElement as DeploymentHost

Would you please help me how can I fix this error?
Re: Viatra Documentation Example not working [message #1848683 is a reply to message #1848667] Mon, 13 December 2021 18:58 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

the error message is very strange, as it can only happen if the Xtend is not available to figure out that the call `cps2depTrace,getOneArbitraryDependencyMatch(...)` should return Optional<Cps2DepTrace.Match> but it still knows the class Csp2DepTrace - this should not happen if everything works right, as both of these classes are generated at the same time.

One thing that comes to my mind about this issue is that it might be some temporary issue. You could try to clean your workspace (by using the Clean command from the Project menu), and then waiting for automatic builder to generate and compile everything.

If that is not fixing the things, I would look at (1) the mentioned classes are generated from the given patterns, and (2) the generated code is available in the classpath of the project with the transformation code.

Hope this was helpful. If not, feel free to ask for clarification with more details about the issue.

Best regards,
Zoltán
Re: Viatra Documentation Example not working [message #1848692 is a reply to message #1848683] Tue, 14 December 2021 07:53 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Thanks for your attention.

I cleaned and rebuilt the project but nothing changed.

In cps2depTrace class that is generated from cps2depTrace pattern there is not 'getOneArbitraryDependencyMatch(...)' method. I only have 'getOneArbitraryMatch(...)' method.

public Optional<Cps2depTrace.Match> getOneArbitraryMatch(final CPSToDeployment pCps2dep, final CPS2DeploymentTrace pTrace, final Identifiable pCpsElement, final DeploymentElement pDepElement) {
return rawGetOneArbitraryMatch(new Object[]{pCps2dep, pTrace, pCpsElement, pDepElement});
}


Re: Viatra Documentation Example not working [message #1848693 is a reply to message #1848692] Tue, 14 December 2021 09:01 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

sorry, that was the method I wanted to write, the dependency part was a typo on my side. This is how the generated code should look like and it looks correct.

The only other ideas I have are to close the editor with the transformation and try to reopen it or try to edit its contents to see whether these updates remove the issue. But I have no way to reproduce the issue, making it very hard to provide some more constructive feedback.

Best regards,
Zoltán

Re: Viatra Documentation Example not working [message #1848760 is a reply to message #1848693] Thu, 16 December 2021 08:04 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
I tried to implement this example on another machine (Ubuntu 20.4) and I got the same error.

This is my codes:

CPSXformM2M.vql
package org.eclipse.viatra.examples.cps.queries

import "http://org.eclipse.viatra/model/cps"
import "http://org.eclipse.viatra/model/deployment"
import "http://org.eclipse.viatra/model/cps-traceability"

pattern hostInstance(hostInstance : HostInstance) {
    HostInstance(hostInstance);
}

pattern applicationInstance(
	appType : ApplicationType, 
	appInstance : ApplicationInstance
){
    HostInstance.applications(_, appInstance);
    ApplicationType.instances(appType, appInstance);
}

pattern allocatedDeploymentApplication(
	depHost : DeploymentHost, 
	depApp : DeploymentApplication
) {
    DeploymentHost.applications(depHost, depApp);
}

pattern cps2depTrace(
	cps2dep : CPSToDeployment, 
	trace : CPS2DeploymentTrace, 
	cpsElement : Identifiable, 
	depElement : DeploymentElement
) {
    CPSToDeployment.traces(cps2dep, trace);
    CPS2DeploymentTrace.cpsElements(trace, cpsElement);
    CPS2DeploymentTrace.deploymentElements(trace, depElement);
}



CPS2DeploymentTransformationViatra.xtend
package org.eclipse.viatra.examples.cps.viatra.incr

import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine
import org.eclipse.viatra.query.runtime.emf.EMFScope
import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.IModelManipulations
import org.eclipse.viatra.transformation.runtime.emf.rules.eventdriven.EventDrivenTransformationRuleFactory
import org.eclipse.viatra.transformation.runtime.emf.rules.eventdriven.EventDrivenTransformationRule
import org.eclipse.viatra.transformation.runtime.emf.transformation.eventdriven.EventDrivenTransformation
import org.eclipse.viatra.transformation.runtime.emf.modelmanipulation.SimpleModelManipulations
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.viatra.examples.cps.queries.CpsXformM2M
import org.eclipse.viatra.examples.cps.deployment.DeploymentPackage
import org.eclipse.viatra.examples.cps.traceability.TraceabilityPackage
import org.eclipse.viatra.examples.cps.traceability.CPSToDeployment
import org.eclipse.viatra.examples.cps.queries.HostInstance
import org.eclipse.viatra.transformation.evm.specific.crud.CRUDActivationStateEnum
import org.eclipse.viatra.transformation.evm.specific.Lifecycles
import org.eclipse.viatra.examples.cps.queries.ApplicationInstance
import org.eclipse.viatra.examples.cps.deployment.DeploymentHost
import org.eclipse.viatra.examples.cps.deployment.DeploymentApplication
import org.eclipse.viatra.examples.cps.traceability.CPS2DeploymentTrace
import org.eclipse.viatra.transformation.evm.specific.resolver.InvertedDisappearancePriorityConflictResolver

class CPS2DeploymentTransformationViatra {

    /* Transformation-related extensions */
    extension EventDrivenTransformation transformation
    
    /* Transformation rule-related extensions */
    extension EventDrivenTransformationRuleFactory = new EventDrivenTransformationRuleFactory
    extension IModelManipulations manipulation
    
    /* VIATRA Query group */
	val extension CpsXformM2M cpsXformM2M = CpsXformM2M.instance
	
	/* EMF metamodels */
	val extension DeploymentPackage depPackage = DeploymentPackage::eINSTANCE
	val extension TraceabilityPackage trPackage = TraceabilityPackage::eINSTANCE

    protected ViatraQueryEngine engine
    protected Resource resource
    //protected EventDrivenTransformationRule<?,?> exampleRule

	val CPSToDeployment cps2dep
	
	new(CPSToDeployment cps2dep, ViatraQueryEngine engine) {
	    this.cps2dep = cps2dep
	    this.resource = cps2dep.deployment.eResource
	    this.engine = engine
	    prepare(engine)
	    createTransformation
	}

    public def execute() {
        transformation.executionSchema.startUnscheduledExecution
    }
    
    
    val hostRule = createRule(HostInstance.Matcher.querySpecification)
    	.action(CRUDActivationStateEnum.CREATED) [
		    val hostinstance = hostInstance
		    val nodeIp = hostInstance.nodeIp
		    println('''Mapping host with IP: «nodeIp»''')
		    /* Create new DeploymentHost element in output model */
		    val host = cps2dep.deployment.createChild(deployment_Hosts, deploymentHost) => [
		        set(deploymentHost_Ip, nodeIp)
		    ]
		    /* Create trace entry */
		    cps2dep.createChild(CPSToDeployment_Traces, CPS2DeploymentTrace) => [
		        addTo(CPS2DeploymentTrace_CpsElements, hostinstance)
		        addTo(CPS2DeploymentTrace_DeploymentElements, host)
		    ]
		]
		.action(CRUDActivationStateEnum.UPDATED) [
		    /* find associated DeploymentHost element */
		    val depHost = engine.cps2depTrace
		                        .getOneArbitraryMatch(cps2dep, null, hostInstance, null)
		                        .depElement as DeploymentHost
		    val hostIp = depHost.ip
		    println('''Updating mapped host with IP: «hostIp»''')
		    /* update IP attribute */
		    val nodeIp = hostInstance.nodeIp
		    depHost.set(deploymentHost_Ip, nodeIp)
		    println('''Updated mapped host with IP: «nodeIp»''')
		]
		.action(CRUDActivationStateEnum.DELETED) [
		    /* Find trace element */
		    val traceMatch = engine.cps2depTrace
		                        .getOneArbitraryMatch(cps2dep, null, hostInstance, null)
		    val hostIp = hostInstance.nodeIp
		    println('''Removing host with IP: «hostIp»''')
		    /* Remove DeploymentHost element */
		    cps2dep.deployment.remove(deployment_Hosts, traceMatch.depElement)
		    /* Remove trace */
		    cps2dep.remove(CPSToDeployment_Traces, traceMatch.trace)
		    println('''Removed host with IP: «hostIp»''')
		].addLifeCycle(Lifecycles.getDefault(true, true)).build
    
    
    val applicationRule = createRule(ApplicationInstance.Matcher.querySpecification)
		.action(CRUDActivationStateEnum.CREATED) [
		    /* Find associated DeploymentHost for the HostInstance this application is allocated to */
		    val depHost = engine.cps2depTrace.getAllValuesOfdepElement(null, null, appInstance.allocatedTo).filter(
		        DeploymentHost).head
		    val appinstance = appInstance
		    val appId = appInstance.identifier
		    println('''Mapping application with ID: «appId»''')
		    /* Create DeploymentApplication application in host */
		    val app = depHost.createChild(deploymentHost_Applications, deploymentApplication) => [
		        set(deploymentApplication_Id, appId)
		    ]
		    /* create trace entry */
		    cps2dep.createChild(CPSToDeployment_Traces, CPS2DeploymentTrace) => [
		        addTo(CPS2DeploymentTrace_CpsElements, appinstance)
		        addTo(CPS2DeploymentTrace_DeploymentElements, app)
		    ]
		    println('''Mapped application with ID: «appId»''')
		].action(CRUDActivationStateEnum.UPDATED) [
		    /* find associated DeploymentApplication */
		    val depApp = engine.cps2depTrace.getOneArbitraryMatch(cps2dep, null, appInstance, null).
		        depElement as DeploymentApplication
		    /* Update ID */
		    if (depApp.id != appInstance.identifier)
		        depApp.set(deploymentApplication_Id, appInstance.identifier)
		].action(CRUDActivationStateEnum.DELETED) [
		    /* find associated DeploymentApplication */
		    val trace = engine.cps2depTrace.getAllValuesOftrace(null, appInstance, null).head as CPS2DeploymentTrace
		    val depApp = trace.deploymentElements.head as DeploymentApplication
		    /* Remove application from host */
		    engine.allocatedDeploymentApplication.getAllValuesOfdepHost(depApp).head.remove(deploymentHost_Applications, depApp)
		    /* Remove traces */
		    cps2dep.remove(CPSToDeployment_Traces, trace)
		].addLifeCycle(Lifecycles.getDefault(true, true)).build
    
    

    private def createTransformation() {
	    //Initialize model manipulation API
	    this.manipulation = new SimpleModelManipulations(engine)
	
	    //Initialize event-driven transformation
	    val fixedPriorityResolver = new InvertedDisappearancePriorityConflictResolver
	    fixedPriorityResolver.setPriority(hostRule.ruleSpecification, 1)
	    fixedPriorityResolver.setPriority(applicationRule.ruleSpecification, 2)
	
	    transformation = EventDrivenTransformation.forEngine(engine)
	        .setConflictResolver(fixedPriorityResolver)
	        .addRule(hostRule)
	        .addRule(applicationRule)
	        .build
    }
    


    // Dispose model transformation
    def dispose() {
        if (transformation !== null) {
            transformation.dispose
        }
        transformation = null
        return
    }
}
Re: Viatra Documentation Example not working [message #1848764 is a reply to message #1848760] Thu, 16 December 2021 10:00 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

could you please share your entire project structure related to the tutorial (you can use the archive export wizard of Eclipse). Given the problem is most likely related to some classpath issues, it is almost impossible to guess what is the problem just looking at some source files.

Best regards,
Zoltán
Re: Viatra Documentation Example not working [message #1848768 is a reply to message #1848764] Thu, 16 December 2021 11:12 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hi,
You can find the file in attachment.

Thanks for your support,
Atepheh
  • Attachment: Atepheh.zip
    (Size: 136.66KB, Downloaded 124 times)

[Updated on: Thu, 16 December 2021 11:16]

Report message to a moderator

Re: Viatra Documentation Example not working [message #1848802 is a reply to message #1848768] Fri, 17 December 2021 14:24 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi,

thanks for the code. I managed to see that you have found a bug in the tutorial (that was caused by not correctly updating it after VIATRA version 2.0). At that point, the return value of getOneArbitraryMatch was changed from *Match to Optional<*Match>, and the corresponding usage should have been updated.

I had to update the calls like the following one (around line 74):

.action(CRUDActivationStateEnum.UPDATED) [
/* find associated DeploymentHost element */
val depHost = engine.cps2depTrace
.getOneArbitraryMatch(cps2dep, null, hostInstance, null)
.orElseThrow
.depElement as DeploymentHost

Another change I had to do to make everything compile to update the final status of the cps2dep variable in line 44 - that should write as `var CPSToDeployment cps2dep`

We will update the tutorial shortly to fix these issues, and sorry for the inconvenience.

Best regards,
Zoltán
Re: Viatra Documentation Example not working [message #1848804 is a reply to message #1848802] Fri, 17 December 2021 14:48 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hi,
Thanks for your response and support.
The issue fixed.

Respectfully,
Atepheh
Re: Viatra Documentation Example not working [message #1848809 is a reply to message #1848804] Fri, 17 December 2021 16:42 Go to previous messageGo to next message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
Hi,
would you please help me how to "Executing the transformation". I follow the steps but there are some differences.
From the wizard, I create a "CPS Demonstrator Example", but I couldn't find Toggle Transformation.

Respectfully,
Atepheh
Re: Viatra Documentation Example not working [message #1848822 is a reply to message #1848809] Sat, 18 December 2021 15:34 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 392
Registered: July 2015
Senior Member
Hi Atopheh,

if you have successfully added the command and menu contribution items to the plugin.xml as written in the tutorial, a menu item called 'Transform' should be present in the editor pop-up menu after when the current selection is a single CPS to Deployment element (as done in your case). If the element does not show, it could be one of the following things:

* There is a kind of error in the plugin.xml file that prohibits parsing the contents. Check whether there is an exception related to this part in the logs.
* The ID of the command (`com.incquerylabs.course.cps.viatra.batch.ui.command` in the example) does not match of the reference in the menu extension point.
* You could try to remove the "visibleWhen" parts from the menu item - that would cause the item to appear in all popup menus (even in cases where it would not work, as the command expects the current selection being a CPS2DeploymentTrace element), and then it would be sure that the source of the problem is the condition described there.

One other thing to note: make sure you restart the runtime Eclipse instance each time after you modify and save the plugin.xml file as the changes are not getting loaded otherwise.
Re: Viatra Documentation Example not working [message #1848842 is a reply to message #1848822] Mon, 20 December 2021 19:19 Go to previous message
atepheh kh is currently offline atepheh khFriend
Messages: 17
Registered: December 2021
Junior Member
No Message Body

[Updated on: Thu, 23 December 2021 14:34]

Report message to a moderator

Previous Topic:No matches found while there is an expected result
Next Topic:How can I monitor my application using EMF and VIATRA query language?
Goto Forum:
  


Current Time: Sat Nov 02 00:12:34 GMT 2024

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

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

Back to the top