Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Core 2.2 Runtime #4172

Merged
merged 7 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ansible/files/runtimes.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@
}
]
},
"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": "application/zip"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be "application/octet-stream"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"attachmentType": "application/zip"
"attachmentType": "application/octet-stream"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chetanmeh can you review this change?

All of the attachments in the manifest are text/plain which iirc is because we store all blobs as 64 encoded text. So should this also be plain/text?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually is text/plain

}
}
],
"blackboxes": [
{
"prefix": "openwhisk",
Expand Down
3 changes: 2 additions & 1 deletion core/controller/src/main/resources/apiv1swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
107 changes: 107 additions & 0 deletions docs/actions-dotnet.md
Original file line number Diff line number Diff line change
@@ -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.
rabbah marked this conversation as resolved.
Show resolved Hide resolved
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!"
}
```
1 change: 1 addition & 0 deletions docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added tests/dat/actions/unicode.tests/dotnet-2.2.bin
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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