You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/12/14 11:47:59 UTC

[GitHub] csantanapr closed pull request #4172: .NET Core 2.2 Runtime

csantanapr closed pull request #4172: .NET Core 2.2 Runtime
URL: https://github.com/apache/incubator-openwhisk/pull/4172
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ansible/files/runtimes.json b/ansible/files/runtimes.json
index 9bc28dfda5..6a47db352c 100644
--- a/ansible/files/runtimes.json
+++ b/ansible/files/runtimes.json
@@ -238,6 +238,23 @@
                     "tag": "latest"
                 }
             }
+        ],
+        "dotnet": [
+            {
+                "kind": "dotnet:2.2",
+                "default": true,
+                "deprecated": false,
+                "requireMain": true,
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "action-dotnet-v2.2",
+                    "tag": "latest"
+                },
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
+            }
         ]
     },
     "blackboxes": [
diff --git a/core/controller/src/main/resources/apiv1swagger.json b/core/controller/src/main/resources/apiv1swagger.json
index cefdb99639..9596867e56 100644
--- a/core/controller/src/main/resources/apiv1swagger.json
+++ b/core/controller/src/main/resources/apiv1swagger.json
@@ -1902,7 +1902,8 @@
                         "go:1.11",
                         "sequence",
                         "swift:3.1.1",
-                        "swift:4.1"
+                        "swift:4.1",
+                        "dotnet:2.2"
                     ],
                     "description": "the type of action"
                 },
diff --git a/docs/actions-dotnet.md b/docs/actions-dotnet.md
new file mode 100644
index 0000000000..2e96b972f5
--- /dev/null
+++ b/docs/actions-dotnet.md
@@ -0,0 +1,107 @@
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+## Creating and invoking .NET Core actions
+
+The following sections guide you through creating and invoking a single .NET Core action.
+
+In order to compile, test and archive .NET Core projects, you must have the [.NET Core SDK](https://www.microsoft.com/net/download) installed locally and the environment variable `DOTNET_HOME` set to the location where the `dotnet` executable can be found.
+
+A .NET Core action is a .NET Core class library with a method called `Main` that has the exact signature as follows:
+
+```csharp
+public Newtonsoft.Json.Linq.JObject Main(Newtonsoft.Json.Linq.JObject);
+```
+
+For example, create a C# project called `Apache.OpenWhisk.Example.Dotnet`:
+
+```bash
+dotnet new classlib -n Apache.OpenWhisk.Example.Dotnet -lang "C#"
+cd Apache.OpenWhisk.Example.Dotnet
+```
+
+Install the [Newtonsoft.Json](https://www.newtonsoft.com/json) NuGet package as follows:
+
+```bash
+dotnet add package Newtonsoft.Json -v 12.0.1
+```
+
+Now create a file called `Hello.cs` with the following content:
+
+```csharp
+using System;
+using Newtonsoft.Json.Linq;
+
+namespace Apache.OpenWhisk.Example.Dotnet
+{
+    public class Hello
+    {
+        public JObject Main(JObject args)
+        {
+            string name = "stranger";
+            if (args.ContainsKey("name")) {
+                name = args["name"].ToString();
+            }
+            JObject message = new JObject();
+            message.Add("greeting", new JValue($"Hello, {name}!"));
+            return (message);
+        }
+    }
+}
+```
+
+Publish the project as follows:
+
+```bash
+dotnet publish -c Release -o out
+```
+
+Zip the published files as follows:
+
+```bash
+cd out
+zip -r -0 helloDotNet.bin *
+```
+
+### Create the .NET Core Action
+
+You need to specify the name of the function handler using `--main` argument.
+The value for `main` needs to be in the following format:
+`{Assembly}::{Class Full Name}::{Method}`, e.q.,
+`Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main`
+
+To use on a deployment of OpenWhisk that contains the runtime as a kind:
+
+```bash
+wsk action update helloDotNet helloDotNet.bin --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:2.2
+```
+
+### Invoke the .NET Core Action
+
+Action invocation is the same for .NET Core actions as it is for Swift and JavaScript actions:
+
+```bash
+wsk action invoke --result helloDotNet --param name World
+```
+
+```json
+  {
+      "greeting": "Hello World!"
+  }
+```
diff --git a/docs/actions.md b/docs/actions.md
index b181ad69c2..f03e708a35 100644
--- a/docs/actions.md
+++ b/docs/actions.md
@@ -61,6 +61,7 @@ paths more suitable. Or, you can [create a new runtime](actions-new.md).
 * [Python](actions-python.md)
 * [Ruby](actions-ruby.md)
 * [Swift](actions-swift.md)
+* [.NET Core](actions-dotnet.md)
 * [Docker and native binaries](actions-docker.md)
 
 Multiple actions from different languages may be composed together to create a longer processing
diff --git a/tests/dat/actions/unicode.tests/dotnet-2.2.bin b/tests/dat/actions/unicode.tests/dotnet-2.2.bin
new file mode 100644
index 0000000000..f3949eef58
Binary files /dev/null and b/tests/dat/actions/unicode.tests/dotnet-2.2.bin differ
diff --git a/tests/dat/actions/unicode.tests/src/dotnet2.2/Apache.OpenWhisk.UnicodeTests.Dotnet/Apache.OpenWhisk.UnicodeTests.Dotnet.csproj b/tests/dat/actions/unicode.tests/src/dotnet2.2/Apache.OpenWhisk.UnicodeTests.Dotnet/Apache.OpenWhisk.UnicodeTests.Dotnet.csproj
new file mode 100644
index 0000000000..c67fa66a2f
--- /dev/null
+++ b/tests/dat/actions/unicode.tests/src/dotnet2.2/Apache.OpenWhisk.UnicodeTests.Dotnet/Apache.OpenWhisk.UnicodeTests.Dotnet.csproj
@@ -0,0 +1,27 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+<Project Sdk="Microsoft.NET.Sdk">
+
+    <PropertyGroup>
+        <TargetFramework>netcoreapp2.2</TargetFramework>
+    </PropertyGroup>
+
+    <ItemGroup>
+      <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
+    </ItemGroup>
+
+</Project>
diff --git a/tests/dat/actions/unicode.tests/src/dotnet2.2/Apache.OpenWhisk.UnicodeTests.Dotnet/Unicode.cs b/tests/dat/actions/unicode.tests/src/dotnet2.2/Apache.OpenWhisk.UnicodeTests.Dotnet/Unicode.cs
new file mode 100644
index 0000000000..6963b869d8
--- /dev/null
+++ b/tests/dat/actions/unicode.tests/src/dotnet2.2/Apache.OpenWhisk.UnicodeTests.Dotnet/Unicode.cs
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using Newtonsoft.Json.Linq;
+
+namespace Apache.OpenWhisk.UnicodeTests.Dotnet
+{
+    public class Unicode
+    {
+        public JObject Main(JObject args)
+        {
+            string delimiter = args["delimiter"].ToString();
+            JObject message = new JObject();
+            string output = $"{delimiter} ☃ {delimiter}";
+            message.Add("winter", new JValue(output));
+            Console.WriteLine(output);
+            return (message);
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/dat/actions/unicode.tests/src/dotnet2.2/openwhisk-unicodetests-dotnet.sln b/tests/dat/actions/unicode.tests/src/dotnet2.2/openwhisk-unicodetests-dotnet.sln
new file mode 100644
index 0000000000..92e2e067b7
--- /dev/null
+++ b/tests/dat/actions/unicode.tests/src/dotnet2.2/openwhisk-unicodetests-dotnet.sln
@@ -0,0 +1,33 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.OpenWhisk.UnicodeTests.Dotnet", "Apache.OpenWhisk.UnicodeTests.Dotnet\Apache.OpenWhisk.UnicodeTests.Dotnet.csproj", "{B905FD2E-6975-411E-B139-36747747F524}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{B905FD2E-6975-411E-B139-36747747F524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{B905FD2E-6975-411E-B139-36747747F524}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{B905FD2E-6975-411E-B139-36747747F524}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{B905FD2E-6975-411E-B139-36747747F524}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+EndGlobal
diff --git a/tests/src/test/scala/system/basic/WskUnicodeTests.scala b/tests/src/test/scala/system/basic/WskUnicodeTests.scala
index 611d8baa64..33680518af 100644
--- a/tests/src/test/scala/system/basic/WskUnicodeTests.scala
+++ b/tests/src/test/scala/system/basic/WskUnicodeTests.scala
@@ -52,7 +52,9 @@ class WskUnicodeTests extends TestHelpers with WskTestHelpers with JsHelpers wit
   def main(kind: String): Option[String] = {
     kind match {
       case "java" => Some("Unicode")
-      case _      => None
+      case s if (s.contains("dotnet")) =>
+        Some("Apache.OpenWhisk.UnicodeTests.Dotnet::Apache.OpenWhisk.UnicodeTests.Dotnet.Unicode::Main")
+      case _ => None
     }
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services