viatra / viatra-cps-benchmark

Performance benchmark using the VIATRA CPS demonstrator
Eclipse Public License 1.0
5 stars 2 forks source link

M2M transformation for Xtext Cps model #17

Open LeeYufang opened 7 years ago

LeeYufang commented 7 years ago

Hi, Good afternoon, sorry to disturb you. I generate the xtext cps model file which can be edited in the xtext editor and I want to operate M2M transformation with it. Can I use the "Explicit traceability (id = incr.expl)" of m2m transformation? or I must use a batch transformation? Do you have an example of it? Thanks and hope for your reply.

abelhegedus commented 7 years ago

As discussed in https://www.eclipse.org/forums/index.php/t/1088118/ you cannot use VIATRA Query (and therefore incr.expl) reliably on a model edited directly in an Xtext editor.

The most reliable approach would be to use a batch transformation that is either executed manually or triggered through some event (e.g. workspace resource change or Eclipse builder) and if you want to use VIATRA Queries, you must initialize the transformation at the beginning of each execution and dispose of the engine at the end of the execution.

LeeYufang commented 7 years ago

(1). For my understanding, I can use the "viatra batch transformation" or "BatchTransformationEiq" to operate m2m transformation with the xtext cps model , am I right?

(2). If (1) is right, both the "viatra batch transformation" and "BatchTransformationEiq" use the traceability model, the cps model and deployment model will be added in the traceability model through the "load resouces" operation. When I edit the xtext cps file in the xtext editor, I must switch the xtext editor to the traceability editor to operate the m2m transformation. Can I have a way to operate the m2m transformation with the xtext cps model by "viatra batch transformation" or "BatchTransformationEiq" without switching editor? Can you give me some references?

abelhegedus commented 7 years ago

(1). For my understanding, I can use the "viatra batch transformation" or "BatchTransformationEiq" to operate m2m transformation with the xtext cps model , am I right?

Yes.

(2). If (1) is right, both the "viatra batch transformation" and "BatchTransformationEiq" use the traceability model, the cps model and deployment model will be added in the traceability model through the "load resouces" operation. When I edit the xtext cps file in the xtext editor, I must switch the xtext editor to the traceability editor to operate the m2m transformation. Can I have a way to operate the m2m transformation with the xtext cps model by "viatra batch transformation" or "BatchTransformationEiq" without switching editor? Can you give me some references?

You should load/create the traceability model and the deployment model root as part of the execution of the transformation. E.g.:

  1. the user saves the Xtext editor
  2. your code listens to resource changed events on the given file
  3. that listener either accesses the resource set of the live editor or creates a new one
  4. load/get the CPS model from the resource set
  5. create the traceability and deployment models and their resources
  6. set the traceability model to CPS root reference
  7. call the transformation
  8. save the deployment resource
  9. dispose the transformation
LeeYufang commented 7 years ago

For "6. set the traceability model to CPS root reference", do you mean the operation of seting CPS and Deployment references of traceability model in the properties viewin in https://github.com/viatra/viatra-docs/blob/master/Viatra-batch-transformations.adoc? I want to implement this operation by coding, can you give me some suggestion?

abelhegedus commented 7 years ago

For "6. set the traceability model to CPS root reference", do you mean the operation of seting CPS and Deployment references of traceability model in the properties viewin in https://github.com/viatra/viatra-docs/blob/master/Viatra-batch-transformations.adoc? I want to implement this operation by coding, can you give me some suggestion?

Yes, you should set these references from code. See the CPSModelBuilderUtil used by the tests for example.


CyberPhysicalSystem cps = /* your model root */;
Deployment dep = DeploymentFactory.eINSTANCE.createDeployment();
CPSToDeployment c2d = TraceabilityFactory.eINSTANCE.createCPSToDeployment();
c2d.setCPS(cps);
c2d.setDeployment(dep);
LeeYufang commented 7 years ago

Thanks for your reply. I have implemented the process of loading xtext cps file and then transforming it to deployment and traceability by VIATRA Batch transformation. The codes work well upon windows operation, but not on linux operation. I am confused about that.

Here are my main codes: ` // load xtext cps file Injector injector = Guice.createInjector(new CyberphysicalsystemRuntimeModule()); XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE); // get cps model URI uri = URI.createURI(cpsFilepath, true); Resource resource = resourceSet.getResource(uri, true); CyberPhysicalSystem cpsModel = (CyberPhysicalSystem) (resource.getContents().get(0));

// create deployment and traceability model are written as your comments above and add the related // resource into resourceSet Deployment dep = DeploymentFactory.eINSTANCE.createDeployment(); Resource deploymentResource = resourceSet.createResource(URI.createFileURI(deploymentFile)); deploymentResource.getContents().add(deploymentModel); CPSToDeployment c2d = TraceabilityFactory.eINSTANCE.createCPSToDeployment(); c2d.setCPS(cps); c2d.setDeployment(dep); Resource traceResource = resourceSet.createResource(URI.createFileURI(traceFile)); traceResource.getContents().add(traceModel); // VIATRA batch transforamtion

// save deploymentResource.save(null); traceResource.save(null);`

(1). In the above codes, I used the URI.createFileURI(traceFile) and URI.createFileURI(deploymentFile), it do operate the save operation, but no files generated upon linux operation. On windows operation system it works well, and I load the generated model files both the deployment model and traceability model are normal. In my opnion, I should use URI.createFileURI(traceFile) and URI.createFileURI(deploymentFile), because the parameter is a file path string. In (1), why it does not generate model files on linux operation system, and how can I modify my codes to make it save the model files?

(2). If I change the createFileURI() to createPlatformResourceURI(traceFile, true) and createPlatformResourceURI(deploymentFile, true), save operation will generate model files, but if I load the generated files, the deployment model is null, the traceability is normal. This happens both on linux operation system and windows operation system. If the model files are generated by createPlatformResourceURI(), why I can not load them? can you give me some explaination?

abelhegedus commented 7 years ago
  1. Did you check that at the end of the transformation the EMF models are correct? (meaning the traceability model contains traces and the deployment model contains hosts, apps, etc.)
  2. On Linux, did you check the file system and not just the Eclipse workspace? Eclipse will sometimes not show new files that are not created through the workspace API.
  3. How do you create the "traceFile" and "deploymentFile" values? Can you show me an example (use <user> or <redacted> to hide personal or project name specific parts if needed)? It may be that the path is valid in Windows, but not on Linux. E.g. you use backward slashes or drive letters. It may also be that the location resolves differently (in case of relative paths).
  4. Are you using the same "traceFile" and "deploymentFile" values for createFileURI and createPlatformResourceURI? As in the first case the URI is created using the value as a file location while in the later it must be relative to the workspace root using project names.

In general, if you have different behaviour on Linux and Windows, you probably have some Windows specific detail in the code that prepares the URIs.