Created dotnet2.0 Builder Image and Added /v2/specialized Endpoint to dotnet2.0 Envrionment (#1001)

This commit is contained in:
Paras Patidar
2019-05-15 16:35:55 +08:00
committed by Ta-Ching Chen
parent 56fa8fe766
commit 4632269314
35 changed files with 1973 additions and 5 deletions
+98 -1
View File
@@ -4,11 +4,16 @@ using System.Collections.Generic;
using Nancy;
using System.IO;
using System;
using Nancy.IO;
using Fission.DotNetCore.Utilty;
using Fission.DotNetCore.Model;
using Nancy.Extensions;
namespace Fission.DotNetCore
{
public class ExecutorModule : NancyModule
{
private static string PackagePath = string.Empty;
#if DEBUG
private const string CODE_PATH = "/tmp/func.cs";
#else
@@ -20,6 +25,7 @@ namespace Fission.DotNetCore
public ExecutorModule()
{
Post("/specialize", args => Specialize());
Post("/v2/specialize", args => Specializev2());
Get("/", _ => Run());
Post("/", _ => Run());
Put("/", _ => Run());
@@ -28,6 +34,94 @@ namespace Fission.DotNetCore
Delete("/", _ => Run());
}
private object Specializev2()
{
Console.WriteLine("Call Reached at /v2/specialize");
try
{
var errors = new List<string>();
var oinfo = new List<string>();
var _request = Request;
var _body = Request.Body;
// Request.Body.Position = 0; use it only if requst has already been read before that
var _requestBodystring = RequestStream.FromStream(Request.Body).AsString();
Console.WriteLine($"Request received by endpoint from builder : {_requestBodystring}");
BuilderRequest builderRequest = EnvironmentHelper.Instance.GetBuilderRequest(_requestBodystring);
if (builderRequest == null)
{
Console.WriteLine("Error : Unbale to parse builder request!!");
throw new Exception("Error : Unbale to parse builder request!!");
}
string functionPath = string.Empty;
// functionPath = Path.Combine(builderRequest.filepath, $"{builderRequest.functionName}.cs");
PackagePath = builderRequest.filepath;
//following will enable us to skip --entrypoint flag during function creation
if (!string.IsNullOrWhiteSpace(builderRequest.functionName))
{
functionPath = Path.Combine(builderRequest.filepath, $"{builderRequest.functionName}.cs");
}
else
{
functionPath = Path.Combine(builderRequest.filepath, EnvironmentHelper.Instance.environmentSettings.functionBodyFileName);
}
Console.WriteLine($"Going to read function body from path : {functionPath}");
if (File.Exists(functionPath))
{
var code = File.ReadAllText(functionPath);
try
{
FissionCompiler fissionCompiler = new FissionCompiler(builderRequest.filepath);
_userFunc = fissionCompiler.Compilev2(code, out errors, out oinfo);
}
catch (Exception ex)
{
Console.WriteLine($"Error getting _userFunc :{ex.Message} , Trace : {ex.StackTrace}");
}
if (_userFunc == null)
{
var errstr = string.Join(Environment.NewLine, errors);
_logger.WriteError(errstr);
Console.WriteLine($"Error _userFunc is null :{errstr}");
var response = (Response)errstr;
response.StatusCode = HttpStatusCode.InternalServerError;
return response;
}
else
{
//try to retrun few details
var infostr = string.Join(Environment.NewLine, oinfo);
_logger.WriteInfo(infostr);
var response = (Response)infostr;
response.StatusCode = HttpStatusCode.OK;
return response;
}
}
else
{
var errstr = $"Unable to locate code at '{functionPath}'";
_logger.WriteError(errstr);
var response = (Response)errstr;
response.StatusCode = HttpStatusCode.InternalServerError;
return response;
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception occured {ex.Message} | {ex.StackTrace}");
var errstr = $"Exception occured {ex.Message} | {ex.StackTrace}";
_logger.WriteError(errstr);
var response = (Response)errstr;
response.StatusCode = HttpStatusCode.InternalServerError;
return response;
}
}
private object Specialize()
{
var errors = new List<string>();
@@ -67,7 +161,10 @@ namespace Fission.DotNetCore
try
{
return _userFunc.Invoke(FissionContext.Build(Request, new Logger()));
var context = FissionContext.Build(Request, new Logger());
//set the package path ,as that will be required to get appsetting files from package
context.PackagePath = PackagePath;
return _userFunc.Invoke(context);
}
catch (Exception e)
{