-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
example-generators/org.eclipse.vorto.codegen.examples.aws/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: AWSGenerator | ||
Bundle-SymbolicName: org.eclipse.vorto.example.awsgenerator;singleton:=true | ||
Bundle-Version: 1.0.0.qualifier | ||
Require-Bundle: org.eclipse.vorto.core, | ||
com.google.guava, | ||
org.eclipse.xtext.xbase.lib, | ||
org.eclipse.xtend.lib, | ||
org.eclipse.xtend.lib.macro, | ||
org.eclipse.vorto.codegen | ||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 | ||
Bundle-ActivationPolicy: lazy |
5 changes: 5 additions & 0 deletions
5
example-generators/org.eclipse.vorto.codegen.examples.aws/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source.. = src/,\ | ||
xtend-gen/ | ||
bin.includes = META-INF/,\ | ||
.,\ | ||
plugin.xml |
13 changes: 13 additions & 0 deletions
13
example-generators/org.eclipse.vorto.codegen.examples.aws/plugin.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<plugin> | ||
<extension | ||
id="org.eclipse.vorto.example.AWSGenerator" | ||
name="org.eclipse.vorto.example.AWSGenerator" | ||
point="org.eclipse.vorto.codegen.org_eclipse_vorto_codegen_Generators"> | ||
<client | ||
class="org.eclipse.vorto.example.AWSGenerator" | ||
menuLabel="AWSGenerator"> | ||
</client> | ||
</extension> | ||
|
||
</plugin> |
23 changes: 23 additions & 0 deletions
23
example-generators/org.eclipse.vorto.codegen.examples.aws/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.eclipse.vorto</groupId> | ||
<artifactId>example-generators</artifactId> | ||
<version>0.4.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>org.eclipse.vorto.codegen.examples.aws</artifactId> | ||
<packaging>eclipse-plugin</packaging> | ||
|
||
<name>Vorto Example AWS Generator</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.eclipse.xtend</groupId> | ||
<artifactId>xtend-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
30 changes: 30 additions & 0 deletions
30
...s/org.eclipse.vorto.codegen.examples.aws/src/org/eclipse/vorto/example/AWSGenerator.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.eclipse.vorto.example | ||
|
||
import org.eclipse.vorto.codegen.api.ChainedCodeGeneratorTask | ||
import org.eclipse.vorto.codegen.api.GenerationResultZip | ||
import org.eclipse.vorto.codegen.api.GeneratorTaskFromFileTemplate | ||
import org.eclipse.vorto.codegen.api.IMappingContext | ||
import org.eclipse.vorto.codegen.api.IVortoCodeGenerator | ||
import org.eclipse.vorto.core.api.model.informationmodel.InformationModel | ||
|
||
class AWSGenerator implements IVortoCodeGenerator { | ||
|
||
override generate(InformationModel infomodel, IMappingContext mappingContext) { | ||
var output = new GenerationResultZip(infomodel,getServiceKey()); | ||
var generator = new ChainedCodeGeneratorTask<InformationModel>(); | ||
for (fbProperty : infomodel.properties) { | ||
var status = fbProperty.type.functionblock.status; | ||
if (status != null) { | ||
for (statusProperty : status.properties) { | ||
generator.addTask(new GeneratorTaskFromFileTemplate(new GetThingShadowLambdaTemplate(statusProperty.name))) | ||
} | ||
} | ||
} | ||
generator.generate(infomodel,mappingContext,output); | ||
return output | ||
} | ||
|
||
override getServiceKey() { | ||
return "awsgenerator"; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...rto.codegen.examples.aws/src/org/eclipse/vorto/example/GetThingShadowLambdaTemplate.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.eclipse.vorto.example | ||
|
||
import org.eclipse.vorto.codegen.api.IFileTemplate | ||
import org.eclipse.vorto.core.api.model.informationmodel.InformationModel | ||
|
||
class GetThingShadowLambdaTemplate implements IFileTemplate<InformationModel> { | ||
|
||
private String statusProperty; | ||
|
||
new(String statusProperty) { | ||
this.statusProperty = statusProperty; | ||
} | ||
|
||
override getFileName(InformationModel context) { | ||
return "GetThingShadowLambda_"+statusProperty+".js" | ||
} | ||
|
||
override getPath(InformationModel context) { | ||
return "nutrunner-aws/lambda"; | ||
} | ||
|
||
override getContent(InformationModel context) { | ||
''' | ||
var config = { | ||
"thingName": "<PUT THING NAME HERE>", | ||
"endpointAddress": "<PUT YOUR ENDPOINT URL HERE>" | ||
} | ||
var AWS = require('aws-sdk'); | ||
var iotdata = new AWS.IotData({endpoint: config.endpointAddress}); | ||
exports.handler = function(event, context, callback) { | ||
iotdata.getThingShadow({ | ||
thingName: config.thingName | ||
},function(err, data) { | ||
if (err) { | ||
context.fail(err); | ||
} else { | ||
var jsonPayload = JSON.parse(data.payload); | ||
var «statusProperty» = jsonPayload.state.reported["«statusProperty»"]; | ||
console.log('«statusProperty»: ' + «statusProperty»); | ||
callback(null,«statusProperty»); | ||
} | ||
}); | ||
}; | ||
''' | ||
} | ||
|
||
} |