Add retry to connection attempts for the PiscalSshClient
This commit is contained in:
@@ -10,4 +10,12 @@
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
</providers>
|
||||
</entityFramework>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
+10
-4
@@ -32,11 +32,9 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="AutoMapper, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="AutoMapper.Net4, Version=3.3.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\AutoMapper.3.3.1\lib\net40\AutoMapper.Net4.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="CsvHelper, Version=12.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\CsvHelper.12.2.1\lib\net45\CsvHelper.dll</HintPath>
|
||||
@@ -60,18 +58,26 @@
|
||||
<Reference Include="MlkPwgen, Version=0.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MlkPwgen.0.3.0\lib\net45\MlkPwgen.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Polly, Version=7.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Polly.7.1.1\lib\netstandard1.1\Polly.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Renci.SshNet, Version=2016.1.0.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\References\Renci.SshNet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.Composition" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
|
||||
@@ -5,7 +5,9 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using log4net;
|
||||
using LeafWeb.Core.Utility;
|
||||
using Polly;
|
||||
using Renci.SshNet;
|
||||
using Renci.SshNet.Common;
|
||||
|
||||
namespace LeafWeb.Core.Remote
|
||||
{
|
||||
@@ -22,6 +24,9 @@ namespace LeafWeb.Core.Remote
|
||||
|
||||
private readonly ILog _logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private readonly int _connectionRetryCount = 3;
|
||||
private readonly Policy _connectRetryPolicy;
|
||||
|
||||
public PiscalSshClient(string connectionString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(connectionString))
|
||||
@@ -32,7 +37,12 @@ namespace LeafWeb.Core.Remote
|
||||
var username = conn["username"] as string;
|
||||
var password = conn["password"] as string;
|
||||
_connectionInfo = new PasswordConnectionInfo(_host, username, password);
|
||||
}
|
||||
|
||||
_connectRetryPolicy = Policy
|
||||
.Handle<SshConnectionException>()
|
||||
.Retry(_connectionRetryCount,
|
||||
(ex, i) => _logger.Warn($"Retry {i} after exception: {ex.Message}"));
|
||||
}
|
||||
|
||||
private SshClient GetSshClient()
|
||||
{
|
||||
@@ -43,12 +53,12 @@ namespace LeafWeb.Core.Remote
|
||||
{
|
||||
return new ScpClient(_connectionInfo);
|
||||
}
|
||||
|
||||
private void Connect(PiscalLeafInput leafInput, BaseClient scp)
|
||||
|
||||
private void Connect(PiscalLeafInput leafInput, BaseClient client)
|
||||
{
|
||||
try
|
||||
{
|
||||
scp.Connect();
|
||||
_connectRetryPolicy.Execute(client.Connect);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -62,7 +72,7 @@ namespace LeafWeb.Core.Remote
|
||||
{
|
||||
try
|
||||
{
|
||||
client.Disconnect();
|
||||
_connectRetryPolicy.Execute(client.Disconnect);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -77,9 +87,10 @@ namespace LeafWeb.Core.Remote
|
||||
// create directory
|
||||
using (var sshClient = GetSshClient())
|
||||
{
|
||||
sshClient.Connect();
|
||||
var runCommand = sshClient.RunCommand($"mkdir {BaseDirectory}/{leafInput.PiscalDirectoryName}");
|
||||
Connect(leafInput, sshClient);
|
||||
sshClient.RunCommand($"mkdir {BaseDirectory}/{leafInput.PiscalDirectoryName}");
|
||||
sshClient.RunCommand($"mkdir {BaseDirectory}/{leafInput.PiscalDirectoryName}/input");
|
||||
Disconnect(leafInput, sshClient);
|
||||
}
|
||||
// copy files
|
||||
using (var scp = GetScpClient())
|
||||
@@ -103,8 +114,6 @@ namespace LeafWeb.Core.Remote
|
||||
if (string.IsNullOrEmpty(leafInput.PhotosyntheticType))
|
||||
throw new PiscalClientException(leafInput.LeafInputId, "No PhotosyntheticType set");
|
||||
|
||||
//var inputDirectory = $"{BaseDirectory}/{leafInput.PiscalDirectoryName}";
|
||||
|
||||
CopyLeafInput(leafInput);
|
||||
|
||||
// begin processing
|
||||
@@ -180,7 +189,7 @@ namespace LeafWeb.Core.Remote
|
||||
// get output files
|
||||
var status = GetLeafInputStatusRaw(leafInput);
|
||||
if (status[0] != StatusComplete)
|
||||
throw new PiscalClientException(leafInput.LeafInputId, "output not available, status is " + status[0]);
|
||||
throw new PiscalClientException(leafInput.LeafInputId, "Output not available, status is not StatusComplete, instead is currently " + status[0]);
|
||||
|
||||
var filePaths = status.Skip(1);
|
||||
|
||||
|
||||
+34
-2
@@ -6,7 +6,39 @@
|
||||
<package id="fasterflect" version="2.1.3" targetFramework="net45" />
|
||||
<package id="log4net" version="2.0.8" targetFramework="net45" />
|
||||
<package id="MathNet.Numerics" version="4.5.1" targetFramework="net45" />
|
||||
<package id="Microsoft.CSharp" version="4.5.0" targetFramework="net45" />
|
||||
<package id="Microsoft.CSharp" version="4.6.0" targetFramework="net45" />
|
||||
<package id="Microsoft.NETCore.Platforms" version="3.0.0" targetFramework="net45" />
|
||||
<package id="MlkPwgen" version="0.3.0" targetFramework="net45" />
|
||||
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
|
||||
<package id="NETStandard.Library" version="2.0.3" targetFramework="net45" />
|
||||
<package id="Polly" version="7.1.1" targetFramework="net45" />
|
||||
<package id="System.Collections" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Globalization" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.IO" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.IO.Compression" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Linq" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Net.Http" version="4.3.4" targetFramework="net45" />
|
||||
<package id="System.Net.Primitives" version="4.3.1" targetFramework="net45" />
|
||||
<package id="System.ObjectModel" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Reflection" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Runtime" version="4.3.1" targetFramework="net45" />
|
||||
<package id="System.Runtime.Extensions" version="4.3.1" targetFramework="net45" />
|
||||
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Text.RegularExpressions" version="4.3.1" targetFramework="net45" />
|
||||
<package id="System.Threading" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net45" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net45" />
|
||||
<package id="System.Xml.ReaderWriter" version="4.3.1" targetFramework="net45" />
|
||||
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -54,6 +54,10 @@
|
||||
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -437,6 +437,10 @@
|
||||
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845DCD8080CC91" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<location path="umbraco">
|
||||
|
||||
@@ -203,8 +203,8 @@
|
||||
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Polly, Version=6.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Polly.6.1.0\lib\netstandard1.1\Polly.dll</HintPath>
|
||||
<Reference Include="Polly, Version=7.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Polly.7.1.1\lib\netstandard1.1\Polly.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Semver, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\semver.1.1.2\lib\net451\Semver.dll</HintPath>
|
||||
@@ -241,8 +241,8 @@
|
||||
<Reference Include="System.Threading.Tasks.Dataflow, Version=4.6.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Dataflow.4.7.0\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.DataVisualization" />
|
||||
<Reference Include="System.Web.Entity" />
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<package id="NETStandard.Library" version="1.6.1" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
|
||||
<package id="Owin" version="1.0" targetFramework="net452" />
|
||||
<package id="Polly" version="6.1.0" targetFramework="net452" />
|
||||
<package id="Polly" version="7.1.1" targetFramework="net452" />
|
||||
<package id="semver" version="1.1.2" targetFramework="net452" />
|
||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net452" />
|
||||
<package id="System.Collections" version="4.3.0" targetFramework="net452" />
|
||||
@@ -92,7 +92,7 @@
|
||||
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net452" />
|
||||
<package id="System.Threading.Tasks.Dataflow" version="4.7.0" targetFramework="net452" />
|
||||
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net452" />
|
||||
<package id="System.ValueTuple" version="4.4.0" targetFramework="net452" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net452" />
|
||||
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net452" />
|
||||
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net452" />
|
||||
<package id="Umbraco.ModelsBuilder" version="3.0.10" targetFramework="net452" />
|
||||
|
||||
Reference in New Issue
Block a user