From 2cf90b95b3d5c431709f479e0187ab5f479a2f4a Mon Sep 17 00:00:00 2001 From: aedelmann Date: Wed, 4 May 2016 22:51:46 +0800 Subject: [PATCH] initial commit of AWS generator --- .../META-INF/MANIFEST.MF | 13 +++++ .../build.properties | 5 ++ .../plugin.xml | 13 +++++ .../pom.xml | 23 +++++++++ .../eclipse/vorto/example/AWSGenerator.xtend | 30 ++++++++++++ .../GetThingShadowLambdaTemplate.xtend | 49 +++++++++++++++++++ 6 files changed, 133 insertions(+) create mode 100644 example-generators/org.eclipse.vorto.codegen.examples.aws/META-INF/MANIFEST.MF create mode 100644 example-generators/org.eclipse.vorto.codegen.examples.aws/build.properties create mode 100644 example-generators/org.eclipse.vorto.codegen.examples.aws/plugin.xml create mode 100644 example-generators/org.eclipse.vorto.codegen.examples.aws/pom.xml create mode 100644 example-generators/org.eclipse.vorto.codegen.examples.aws/src/org/eclipse/vorto/example/AWSGenerator.xtend create mode 100644 example-generators/org.eclipse.vorto.codegen.examples.aws/src/org/eclipse/vorto/example/GetThingShadowLambdaTemplate.xtend diff --git a/example-generators/org.eclipse.vorto.codegen.examples.aws/META-INF/MANIFEST.MF b/example-generators/org.eclipse.vorto.codegen.examples.aws/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..d8fdd21e0b --- /dev/null +++ b/example-generators/org.eclipse.vorto.codegen.examples.aws/META-INF/MANIFEST.MF @@ -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 diff --git a/example-generators/org.eclipse.vorto.codegen.examples.aws/build.properties b/example-generators/org.eclipse.vorto.codegen.examples.aws/build.properties new file mode 100644 index 0000000000..01e3906893 --- /dev/null +++ b/example-generators/org.eclipse.vorto.codegen.examples.aws/build.properties @@ -0,0 +1,5 @@ +source.. = src/,\ + xtend-gen/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/example-generators/org.eclipse.vorto.codegen.examples.aws/plugin.xml b/example-generators/org.eclipse.vorto.codegen.examples.aws/plugin.xml new file mode 100644 index 0000000000..2e660d12c7 --- /dev/null +++ b/example-generators/org.eclipse.vorto.codegen.examples.aws/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/example-generators/org.eclipse.vorto.codegen.examples.aws/pom.xml b/example-generators/org.eclipse.vorto.codegen.examples.aws/pom.xml new file mode 100644 index 0000000000..e116692540 --- /dev/null +++ b/example-generators/org.eclipse.vorto.codegen.examples.aws/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + org.eclipse.vorto + example-generators + 0.4.0-SNAPSHOT + + + org.eclipse.vorto.codegen.examples.aws + eclipse-plugin + + Vorto Example AWS Generator + + + + + org.eclipse.xtend + xtend-maven-plugin + + + + \ No newline at end of file diff --git a/example-generators/org.eclipse.vorto.codegen.examples.aws/src/org/eclipse/vorto/example/AWSGenerator.xtend b/example-generators/org.eclipse.vorto.codegen.examples.aws/src/org/eclipse/vorto/example/AWSGenerator.xtend new file mode 100644 index 0000000000..4f7c0f78fd --- /dev/null +++ b/example-generators/org.eclipse.vorto.codegen.examples.aws/src/org/eclipse/vorto/example/AWSGenerator.xtend @@ -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(); + 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"; + } +} diff --git a/example-generators/org.eclipse.vorto.codegen.examples.aws/src/org/eclipse/vorto/example/GetThingShadowLambdaTemplate.xtend b/example-generators/org.eclipse.vorto.codegen.examples.aws/src/org/eclipse/vorto/example/GetThingShadowLambdaTemplate.xtend new file mode 100644 index 0000000000..81a11f9278 --- /dev/null +++ b/example-generators/org.eclipse.vorto.codegen.examples.aws/src/org/eclipse/vorto/example/GetThingShadowLambdaTemplate.xtend @@ -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 { + + 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": "", + "endpointAddress": "" + } + + 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»); + } + }); + }; + ''' + } + +} \ No newline at end of file