Skip to content

Commit 1aea511

Browse files
committed
Node.Cli: all primary functions as working, a few minor things to finish (err handling/logging, hello methods)
1 parent 9a1d223 commit 1aea511

3 files changed

Lines changed: 67 additions & 5 deletions

File tree

Synapse.NodeService.HttpClient/NodeServiceHttpApiClient.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
24
using System.Threading.Tasks;
35

4-
using Synapse.Core;
56
using Synapse.Common.WebApi;
6-
using System.Collections.Generic;
7+
using Synapse.Core;
8+
using Synapse.Core.Utilities;
79

810
namespace Synapse.Services
911
{
@@ -16,6 +18,40 @@ public NodeServiceHttpApiClient(string baseUrl, string messageFormatType = "appl
1618
}
1719

1820

21+
public ExecuteResult StartPlanFile(int planInstanceId, bool dryRun, string filePath)
22+
{
23+
return StartPlanAsync( planInstanceId, dryRun, filePath ).Result;
24+
}
25+
26+
public async Task<ExecuteResult> StartPlanFileAsync(int planInstanceId, bool dryRun, string filePath)
27+
{
28+
if( File.Exists( filePath ) )
29+
{
30+
Plan plan = YamlHelpers.DeserializeFile<Plan>( filePath );
31+
string requestUri = $"{_rootPath}/execute/{planInstanceId}/?action=start&dryRun={dryRun}";
32+
return await PostAsync<Plan, ExecuteResult>( plan, requestUri );
33+
}
34+
else
35+
throw new FileNotFoundException( "Unable to start Plan.", filePath );
36+
}
37+
38+
public ExecuteResult StartPlan(int planInstanceId, bool dryRun, string filePath)
39+
{
40+
return StartPlanAsync( planInstanceId, dryRun, filePath ).Result;
41+
}
42+
43+
public async Task<ExecuteResult> StartPlanAsync(int planInstanceId, bool dryRun, string filePath)
44+
{
45+
if( File.Exists( filePath ) )
46+
{
47+
Plan plan = YamlHelpers.DeserializeFile<Plan>( filePath );
48+
string requestUri = $"{_rootPath}/execute/{planInstanceId}/?action=start&dryRun={dryRun}";
49+
return await PostAsync<Plan, ExecuteResult>( plan, requestUri );
50+
}
51+
else
52+
throw new FileNotFoundException( "Unable to start Plan.", filePath );
53+
}
54+
1955
public ExecuteResult StartPlan(int planInstanceId, bool dryRun, Plan plan)
2056
{
2157
return StartPlanAsync( planInstanceId, dryRun, plan ).Result;

Synapse.NodeService.cli/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ static void Main(string[] args)
4343

4444
public Program()
4545
{
46-
_methods.Add( "start", "StartPlan" );
47-
_methods.Add( "s", "StartPlan" );
46+
_methods.Add( "start", "StartPlanFile" );
47+
_methods.Add( "s", "StartPlanFile" );
4848
_methods.Add( "cancel", "CancelPlan" );
4949
_methods.Add( "c", "CancelPlan" );
5050
_methods.Add( "drainstop", "Drainstop" );

Synapse.NodeService/Classes/SynapseNodeServer.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using Synapse.Core;
33
using Synapse.Core.Runtime;
44
using System.Collections.Generic;
5+
using System.Text;
6+
using Synapse.Common.WebApi;
57

68
namespace Synapse.Services
79
{
@@ -40,7 +42,20 @@ public string WhosHere()
4042

4143
public ExecuteResult StartPlan(string planInstanceId, bool dryRun, Plan plan)
4244
{
43-
return plan.Start( null, dryRun );
45+
string context = GetContext( nameof( StartPlan ),
46+
nameof( plan ), plan.Name, nameof( dryRun ), dryRun, nameof( planInstanceId ), planInstanceId );
47+
48+
try
49+
{
50+
SynapseNodeService.Logger.Debug( context );
51+
return plan.Start( null, dryRun );
52+
}
53+
catch( Exception ex )
54+
{
55+
SynapseNodeService.Logger.Error(
56+
Utilities.UnwindException( context, ex, asSingleLine: true ) );
57+
throw;
58+
}
4459
}
4560

4661
public void StartPlanAsync(string planInstanceId, bool dryRun, Plan plan)
@@ -93,5 +108,16 @@ public void Undrainstop()
93108

94109
public List<string> GetCurrentQueueItems() { return _scheduler.CurrentQueue; }
95110
#endregion
111+
112+
113+
string GetContext(string context, params object[] parms)
114+
{
115+
StringBuilder c = new StringBuilder();
116+
c.Append( $"{context}(" );
117+
for( int i = 0; i < parms.Length; i += 2 )
118+
c.Append( $"{parms[i]}: {parms[i + 1]}, " );
119+
120+
return $"{c.ToString().TrimEnd( ',', ' ' )})";
121+
}
96122
}
97123
}

0 commit comments

Comments
 (0)