Piscal processing work
This commit is contained in:
@@ -8,6 +8,5 @@ namespace LeafWeb.Core.Remote
|
||||
PiscalStatus GetLeafInputStatus(PiscalLeafInput leafInput);
|
||||
IEnumerable<PiscalLeafOutputFile> RetrieveLeafOutput(PiscalLeafInput leafInput);
|
||||
void CleanupLeafProcess(PiscalLeafInput leafInput);
|
||||
string GetErrorMessage(PiscalLeafInput leafInput);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Utility;
|
||||
|
||||
namespace LeafWeb.Core.Remote
|
||||
{
|
||||
public class PiscalLeafInput
|
||||
{
|
||||
private static readonly IMapper Mapper;
|
||||
public int LeafInputId { get; set; }
|
||||
public string PhotosyntheticType { get; set; }
|
||||
public string DirectoryName { get; set; }
|
||||
public PiscalLeafInputFile[] InputFiles { get; set; }
|
||||
|
||||
static PiscalLeafInput()
|
||||
{
|
||||
var config =
|
||||
new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<LeafInput, PiscalLeafInput>()
|
||||
.ForMember(dest => dest.DirectoryName,
|
||||
opt => opt.MapFrom(src => PiscalUtility.GetPiscalDirectoryName(src)))
|
||||
.ForMember(dest => dest.LeafInputId, opt => opt.MapFrom(src => src.Id))
|
||||
.ForMember(dest => dest.InputFiles, opt => opt.MapFrom(src => src.InputFiles.Select(f => new PiscalLeafInputFile(f)).ToArray()))
|
||||
.ForMember(
|
||||
dest => dest.PhotosyntheticType,
|
||||
opt => opt.MapFrom(src => src.PhotosynthesisType.Id.WhitespaceToUnderscore()));
|
||||
});
|
||||
Mapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
public PiscalLeafInput() { }
|
||||
|
||||
public PiscalLeafInput(LeafInput leafInput)
|
||||
{
|
||||
Mapper.Map(leafInput, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,9 @@
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using AutoMapper;
|
||||
using LeafWeb.Core.Entities;
|
||||
using LeafWeb.Core.Utility;
|
||||
|
||||
namespace LeafWeb.Core.Remote
|
||||
{
|
||||
public class PiscalLeafInput
|
||||
{
|
||||
private static readonly IMapper Mapper;
|
||||
public int LeafInputId { get; set; }
|
||||
public string PhotosyntheticType { get; set; }
|
||||
public string DirectoryName { get; set; }
|
||||
public PiscalLeafInputFile[] InputFiles { get; set; }
|
||||
|
||||
static PiscalLeafInput()
|
||||
{
|
||||
var config =
|
||||
new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<LeafInput, PiscalLeafInput>()
|
||||
.ForMember(dest => dest.DirectoryName,
|
||||
opt => opt.MapFrom(src => PiscalUtility.GetPiscalDirectoryName(src)))
|
||||
.ForMember(dest => dest.LeafInputId, opt => opt.MapFrom(src => src.Id))
|
||||
.ForMember(dest => dest.InputFiles, opt => opt.MapFrom(src => src.InputFiles.Select(f => new PiscalLeafInputFile(f)).ToArray()))
|
||||
.ForMember(
|
||||
dest => dest.PhotosyntheticType,
|
||||
opt => opt.MapFrom(src => src.PhotosynthesisType.Id.WhitespaceToUnderscore()));
|
||||
});
|
||||
Mapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
public PiscalLeafInput() { }
|
||||
|
||||
public PiscalLeafInput(LeafInput leafInput)
|
||||
{
|
||||
Mapper.Map(leafInput, this);
|
||||
}
|
||||
}
|
||||
|
||||
public class PiscalLeafInputFile
|
||||
{
|
||||
private static readonly IMapper Mapper;
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using LeafWeb.Core.Utility;
|
||||
using NLog;
|
||||
using Renci.SshNet;
|
||||
|
||||
namespace LeafWeb.Core.Remote
|
||||
@@ -14,10 +15,11 @@ namespace LeafWeb.Core.Remote
|
||||
private const string RemoteScriptPath = BaseDirectory + "/piscal_manager.sh";
|
||||
private readonly PasswordConnectionInfo _connectionInfo;
|
||||
|
||||
private const string StatusSuccess = "success";
|
||||
private const string StatusComplete = "complete";
|
||||
private const string StatusRunning = "running";
|
||||
private const string StatusNotStarted = "not started";
|
||||
private const string StatusError = "error";
|
||||
|
||||
Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public PiscalSshClient(string connectionString)
|
||||
{
|
||||
@@ -45,10 +47,10 @@ namespace LeafWeb.Core.Remote
|
||||
using (var scp = GetScpClient())
|
||||
foreach (var file in leafInput.InputFiles)
|
||||
{
|
||||
var inputPath = $"{directory}/{file.Filename}";
|
||||
var inputPath = $"{directory}/input/{file.Filename}";
|
||||
using (var stream = new MemoryStream(file.Contents))
|
||||
{
|
||||
Console.WriteLine(inputPath);
|
||||
_logger.Trace("Copying " + inputPath);
|
||||
scp.Connect();
|
||||
scp.Upload(stream, inputPath);
|
||||
scp.Disconnect();
|
||||
@@ -66,8 +68,7 @@ namespace LeafWeb.Core.Remote
|
||||
using (var ssh = GetSshClient())
|
||||
{
|
||||
ssh.Connect();
|
||||
var commandText = $"{RemoteScriptPath} -d {leafInput.DirectoryName} -p {leafInput.PhotosyntheticType}";
|
||||
Console.Write(commandText);
|
||||
var commandText = $"{RemoteScriptPath} -d {leafInput.DirectoryName} -p {leafInput.PhotosyntheticType} -s";
|
||||
var command = ssh.CreateCommand(commandText);
|
||||
command.Execute();
|
||||
ssh.Disconnect();
|
||||
@@ -75,7 +76,7 @@ namespace LeafWeb.Core.Remote
|
||||
if (command.ExitStatus != 0)
|
||||
throw new PiscalClientException(command.Result);
|
||||
|
||||
Console.Write(command.Result);
|
||||
_logger.Debug(command.Result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,12 +88,12 @@ namespace LeafWeb.Core.Remote
|
||||
{
|
||||
case StatusRunning:
|
||||
return PiscalStatus.Running;
|
||||
case StatusSuccess:
|
||||
return PiscalStatus.Success;
|
||||
case StatusComplete:
|
||||
return PiscalStatus.Complete;
|
||||
case StatusNotStarted:
|
||||
return PiscalStatus.NotStarted;
|
||||
default:
|
||||
return PiscalStatus.Error;
|
||||
throw new PiscalClientException("Unknown status: " + statusRaw[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +102,7 @@ namespace LeafWeb.Core.Remote
|
||||
using (var ssh = GetSshClient())
|
||||
{
|
||||
ssh.Connect();
|
||||
var commandText = $"{RemoteScriptPath} -d {leafInput.DirectoryName} -s";
|
||||
var commandText = $"{RemoteScriptPath} -d {leafInput.DirectoryName}";
|
||||
var command = ssh.CreateCommand(commandText);
|
||||
command.Execute();
|
||||
ssh.Disconnect();
|
||||
@@ -123,7 +124,7 @@ namespace LeafWeb.Core.Remote
|
||||
{
|
||||
// get output files
|
||||
var status = GetLeafInputStatusRaw(leafInput);
|
||||
if (status[0] != StatusSuccess)
|
||||
if (status[0] != StatusComplete)
|
||||
throw new PiscalClientException("output not available, status is " + status[0]);
|
||||
|
||||
var filePaths = status.Skip(1);
|
||||
@@ -149,23 +150,9 @@ namespace LeafWeb.Core.Remote
|
||||
scp.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetErrorMessage(PiscalLeafInput leafInput)
|
||||
{
|
||||
var status = GetLeafInputStatusRaw(leafInput);
|
||||
if (status[0] != StatusError)
|
||||
return string.Empty;
|
||||
|
||||
var errorLines = status.Skip(1).ToArray();
|
||||
return errorLines.Join(Environment.NewLine);
|
||||
}
|
||||
|
||||
|
||||
public void CleanupLeafProcess(PiscalLeafInput leafInput)
|
||||
{
|
||||
var status = GetLeafInputStatusRaw(leafInput);
|
||||
if (status[0] == StatusRunning)
|
||||
throw new PiscalClientException("Trying to cleanup a running process");
|
||||
|
||||
using (var ssh = GetSshClient())
|
||||
{
|
||||
ssh.Connect();
|
||||
|
||||
@@ -2,9 +2,8 @@ namespace LeafWeb.Core.Remote
|
||||
{
|
||||
public enum PiscalStatus
|
||||
{
|
||||
Running,
|
||||
Success,
|
||||
NotStarted,
|
||||
Error
|
||||
NotStarted, // Process has not been started
|
||||
Running, // Process is currently executing
|
||||
Complete, // Process has completed
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user