Home » Modeling » VIATRA » Viatra Documentation Example not working
|
Re: Viatra Documentation Example not working [message #1848683 is a reply to message #1848667] |
Mon, 13 December 2021 18:58 |
Zoltan Ujhelyi 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 #1848760 is a reply to message #1848693] |
Thu, 16 December 2021 08:04 |
atepheh kh 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
}
}
|
|
| | | | | | | |
Goto Forum:
Current Time: Sat Nov 02 00:12:34 GMT 2024
Powered by FUDForum. Page generated in 0.06376 seconds
|