Skip to content

Commit

Permalink
initial commit of AWS generator
Browse files Browse the repository at this point in the history
  • Loading branch information
aedelmann committed May 4, 2016
1 parent 8989e77 commit 2cf90b9
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml
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 example-generators/org.eclipse.vorto.codegen.examples.aws/pom.xml
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>
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";
}
}
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»);
}
});
};
'''
}

}

0 comments on commit 2cf90b9

Please sign in to comment.