Skip to content

Commit 8b8bcf5

Browse files
committed
NodeServer: added debug logging; Hello added to cli (issue #3)
1 parent 1aea511 commit 8b8bcf5

3 files changed

Lines changed: 143 additions & 25 deletions

File tree

Synapse.NodeService.HttpClient/NodeServiceHttpApiClient.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ public NodeServiceHttpApiClient(string baseUrl, string messageFormatType = "appl
1818
}
1919

2020

21+
public string Hello() { return HelloAsync().Result; }
22+
23+
public async Task<string> HelloAsync()
24+
{
25+
string requestUri = $"{_rootPath}/hello";
26+
return await GetAsync<string>( requestUri );
27+
}
28+
29+
public string WhoAmI() { return WhoAmIAsync().Result; }
30+
31+
public async Task<string> WhoAmIAsync()
32+
{
33+
string requestUri = $"{_rootPath}/hello/whoami";
34+
return await GetAsync<string>( requestUri );
35+
}
36+
37+
2138
public ExecuteResult StartPlanFile(int planInstanceId, bool dryRun, string filePath)
2239
{
2340
return StartPlanAsync( planInstanceId, dryRun, filePath ).Result;

Synapse.NodeService.cli/Program.cs

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

4444
public Program()
4545
{
46+
_methods.Add( "hello", "Hello" );
47+
_methods.Add( "hi", "Hello" );
48+
_methods.Add( "whoami", "WhoAmI" );
49+
_methods.Add( "who", "WhoAmI" );
4650
_methods.Add( "start", "StartPlanFile" );
4751
_methods.Add( "s", "StartPlanFile" );
4852
_methods.Add( "cancel", "CancelPlan" );
@@ -153,6 +157,8 @@ protected override void WriteHelpAndExit(string errorMessage = null)
153157
Console.WriteLine( "{0,-15}Parm help: synapse.node.cli {1}httpAction{2} help.", "", "{", "}" );
154158
Console.WriteLine( "{0,-15}URL: url:http://{1}host:port{2}/synapse/node\r\n", "", "{", "}" );
155159
Console.WriteLine( " - httpActions:", "" );
160+
Console.WriteLine( " - Hello|hi Returns 'Hello World'.", "" );
161+
Console.WriteLine( " - WhoAmI|who Returns NodeServer User Context.", "" );
156162
Console.WriteLine( " - Start|s Start a new Plan Instance.", "" );
157163
Console.WriteLine( " - Cancel|c Cancel a Plan Instance.", "" );
158164
Console.WriteLine( " - Drainstop|dst Prevents the node from receiving incoming requests;", "" );

Synapse.NodeService/Classes/SynapseNodeServer.cs

Lines changed: 120 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ public static void InitPlanScheduler()
3232

3333
public string Hello()
3434
{
35+
string context = GetContext( nameof( Hello ) );
36+
SynapseNodeService.Logger.Debug( context );
3537
return "Hello from SynapseNodeServer, World!";
3638
}
3739

38-
public string WhosHere()
40+
public string WhoAmI()
3941
{
40-
return "WhosHere from SynapseNodeServer, World!";
42+
string context = GetContext( nameof( WhoAmI ) );
43+
SynapseNodeService.Logger.Debug( context );
44+
return "WhoAmI from SynapseNodeServer, World!";
4145
}
4246

4347
public ExecuteResult StartPlan(string planInstanceId, bool dryRun, Plan plan)
@@ -60,22 +64,44 @@ public ExecuteResult StartPlan(string planInstanceId, bool dryRun, Plan plan)
6064

6165
public void StartPlanAsync(string planInstanceId, bool dryRun, Plan plan)
6266
{
63-
int planInstId = int.Parse( planInstanceId );
64-
65-
SynapseNodeService.Logger.Info( $"StartPlanAsync: InstanceId: {planInstId}, Name: {plan.Name}" );
67+
string context = GetContext( nameof( StartPlanAsync ),
68+
nameof( plan ), plan.Name, nameof( dryRun ), dryRun, nameof( planInstanceId ), planInstanceId );
6669

67-
PlanRuntimePod p = new PlanRuntimePod( plan, dryRun, null, planInstId );
68-
_scheduler.StartPlan( p ); //_scheduler.StartPlan( null, dryRun, plan );
70+
try
71+
{
72+
SynapseNodeService.Logger.Debug( context );
73+
int planInstId = int.Parse( planInstanceId );
74+
PlanRuntimePod p = new PlanRuntimePod( plan, dryRun, null, planInstId );
75+
_scheduler.StartPlan( p ); //_scheduler.StartPlan( null, dryRun, plan );
76+
}
77+
catch( Exception ex )
78+
{
79+
SynapseNodeService.Logger.Error(
80+
Utilities.UnwindException( context, ex, asSingleLine: true ) );
81+
throw;
82+
}
6983
}
7084

7185
public void CancelPlan(string planInstanceId)
7286
{
73-
int planInstId = int.Parse( planInstanceId );
74-
bool found = _scheduler.CancelPlan( planInstId );
75-
string foundMsg = found ?
76-
"Found executing Plan and signaled Cancel request." :
77-
"Could not find executing Plan; Plan may have already completed execution.";
78-
SynapseNodeService.Logger.Info( $"CancelPlan {planInstId}: {foundMsg}" );
87+
string context = GetContext( nameof( CancelPlan ), nameof( planInstanceId ), planInstanceId );
88+
89+
try
90+
{
91+
SynapseNodeService.Logger.Debug( context );
92+
int planInstId = int.Parse( planInstanceId );
93+
bool found = _scheduler.CancelPlan( planInstId );
94+
string foundMsg = found ?
95+
"Found executing Plan and signaled Cancel request." :
96+
"Could not find executing Plan; Plan may have already completed execution.";
97+
SynapseNodeService.Logger.Info( $"CancelPlan {planInstId}: {foundMsg}" );
98+
}
99+
catch( Exception ex )
100+
{
101+
SynapseNodeService.Logger.Error(
102+
Utilities.UnwindException( context, ex, asSingleLine: true ) );
103+
throw;
104+
}
79105
}
80106

81107
private static void Scheduler_PlanCompleted(object sender, PlanCompletedEventArgs e)
@@ -85,28 +111,97 @@ private static void Scheduler_PlanCompleted(object sender, PlanCompletedEventArg
85111

86112
public void Drainstop(bool shutdown)
87113
{
88-
SynapseNodeService.Logger.Info( $"Drainstop starting, CurrentQueueDepth: {_scheduler.CurrentQueueDepth}. Shutdown when complete: {shutdown}." );
89-
_scheduler.Drainstop();
90-
SynapseNodeService.Logger.Info( $"Drainstop complete, CurrentQueueDepth: {_scheduler.CurrentQueueDepth}" );
91-
if( shutdown )
114+
string context = GetContext( nameof( Drainstop ), nameof( shutdown ), shutdown );
115+
116+
try
117+
{
118+
SynapseNodeService.Logger.Debug( context );
119+
SynapseNodeService.Logger.Info( $"Drainstop starting, CurrentQueueDepth: {_scheduler.CurrentQueueDepth}. Shutdown when complete: {shutdown}." );
120+
_scheduler.Drainstop();
121+
SynapseNodeService.Logger.Info( $"Drainstop complete, CurrentQueueDepth: {_scheduler.CurrentQueueDepth}" );
122+
if( shutdown )
123+
{
124+
SynapseNodeService.Logger.Info( $"Drainstop initiating Shutdown." );
125+
DrainstopCallback?.Invoke();
126+
}
127+
}
128+
catch( Exception ex )
92129
{
93-
SynapseNodeService.Logger.Info( $"Drainstop initiating Shutdown." );
94-
DrainstopCallback?.Invoke();
130+
SynapseNodeService.Logger.Error(
131+
Utilities.UnwindException( context, ex, asSingleLine: true ) );
132+
throw;
95133
}
96134
}
97135

98136
public void Undrainstop()
99137
{
100-
SynapseNodeService.Logger.Info( $"Undrainstop starting, CurrentQueueDepth: {_scheduler.CurrentQueueDepth}" );
101-
_scheduler.Undrainstop();
102-
SynapseNodeService.Logger.Info( $"Undrainstop complete, CurrentQueueDepth: {_scheduler.CurrentQueueDepth}" );
138+
string context = GetContext( nameof( Undrainstop ));
139+
140+
try
141+
{
142+
SynapseNodeService.Logger.Debug( context );
143+
SynapseNodeService.Logger.Info( $"Undrainstop starting, CurrentQueueDepth: {_scheduler.CurrentQueueDepth}" );
144+
_scheduler.Undrainstop();
145+
SynapseNodeService.Logger.Info( $"Undrainstop complete, CurrentQueueDepth: {_scheduler.CurrentQueueDepth}" );
146+
}
147+
catch( Exception ex )
148+
{
149+
SynapseNodeService.Logger.Error(
150+
Utilities.UnwindException( context, ex, asSingleLine: true ) );
151+
throw;
152+
}
153+
}
154+
155+
public bool GetIsDrainstopComplete()
156+
{
157+
string context = GetContext( nameof( GetIsDrainstopComplete ) );
158+
159+
try
160+
{
161+
SynapseNodeService.Logger.Debug( context );
162+
return _scheduler.IsDrainstopComplete;
163+
}
164+
catch( Exception ex )
165+
{
166+
SynapseNodeService.Logger.Error(
167+
Utilities.UnwindException( context, ex, asSingleLine: true ) );
168+
throw;
169+
}
103170
}
104171

105-
public bool GetIsDrainstopComplete() { return _scheduler.IsDrainstopComplete; }
172+
public int GetCurrentQueueDepth()
173+
{
174+
string context = GetContext( nameof( GetCurrentQueueDepth ) );
106175

107-
public int GetCurrentQueueDepth() { return _scheduler.CurrentQueueDepth; }
176+
try
177+
{
178+
SynapseNodeService.Logger.Debug( context );
179+
return _scheduler.CurrentQueueDepth;
180+
}
181+
catch( Exception ex )
182+
{
183+
SynapseNodeService.Logger.Error(
184+
Utilities.UnwindException( context, ex, asSingleLine: true ) );
185+
throw;
186+
}
187+
}
108188

109-
public List<string> GetCurrentQueueItems() { return _scheduler.CurrentQueue; }
189+
public List<string> GetCurrentQueueItems()
190+
{
191+
string context = GetContext( nameof( GetCurrentQueueItems ) );
192+
193+
try
194+
{
195+
SynapseNodeService.Logger.Debug( context );
196+
return _scheduler.CurrentQueue;
197+
}
198+
catch( Exception ex )
199+
{
200+
SynapseNodeService.Logger.Error(
201+
Utilities.UnwindException( context, ex, asSingleLine: true ) );
202+
throw;
203+
}
204+
}
110205
#endregion
111206

112207

0 commit comments

Comments
 (0)