From c9a6497d010a46f484343b582d53c1db7c502b61 Mon Sep 17 00:00:00 2001 From: Stan Lagun Date: Thu, 29 Aug 2013 11:10:35 +0400 Subject: [PATCH] Return additional information to conductor upon exception Change-Id: Ie01ee67eb8feccfb87577672f554cb19f7ed9bef --- WindowsAgent/PlanExecutor.cs | 36 ++++++++++++++++++++++++++++++------ WindowsAgent/Program.cs | 2 +- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/WindowsAgent/PlanExecutor.cs b/WindowsAgent/PlanExecutor.cs index 1ea851ea..e9a4ad12 100644 --- a/WindowsAgent/PlanExecutor.cs +++ b/WindowsAgent/PlanExecutor.cs @@ -44,8 +44,9 @@ namespace Mirantis.Murano.WindowsAgent { currentResults = JsonConvert.DeserializeObject>(File.ReadAllText(resultPath)); } - catch + catch(Exception exception) { + Log.WarnException("Cannot deserialize previous execution result", exception); currentResults = new List(); } @@ -57,15 +58,18 @@ namespace Mirantis.Murano.WindowsAgent runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted"); if (plan.Scripts != null) { + var index = 0; foreach (var script in plan.Scripts) { runSpaceInvoker.Invoke(Encoding.UTF8.GetString(Convert.FromBase64String(script))); + Log.Debug("Loaded script #{0}", ++index); } } while (plan.Commands != null && plan.Commands.Any()) { var command = plan.Commands.First(); + Log.Debug("Preparing to execute command {0}", command.Name); var pipeline = runSpace.CreatePipeline(); var psCommand = new Command(command.Name); @@ -83,9 +87,11 @@ namespace Mirantis.Murano.WindowsAgent t => string.Format("{0}={1}", t.Key, t.Value == null ? "null" : t.Value.ToString())))); pipeline.Commands.Add(psCommand); + try { var result = pipeline.Invoke(); + Log.Debug("Command {0} executed", command.Name); if (result != null) { currentResults.Add(new ExecutionResult { @@ -96,10 +102,27 @@ namespace Mirantis.Murano.WindowsAgent } catch (Exception exception) { - currentResults.Add(new ExecutionResult { + object additionInfo = null; + if (exception is ActionPreferenceStopException) + { + var apse = exception as ActionPreferenceStopException; + if (apse.ErrorRecord != null) + { + additionInfo = new { + ScriptStackTrace = apse.ErrorRecord.ScriptStackTrace, + PositionMessage = apse.ErrorRecord.InvocationInfo.PositionMessage + }; + exception = apse.ErrorRecord.Exception; + } + } + + + Log.WarnException("Exception while executing command " + command.Name, exception); + currentResults.Add(new ExecutionResult + { IsException = true, Result = new[] { - exception.GetType().FullName, exception.Message + exception.GetType().FullName, exception.Message, command.Name, additionInfo } }); break; @@ -129,13 +152,13 @@ namespace Mirantis.Murano.WindowsAgent } } File.WriteAllText(resultPath, executionResult); - } - catch (Exception ex) + catch (Exception exception) { + Log.WarnException("Exception while processing execution plan", exception); File.WriteAllText(resultPath, JsonConvert.SerializeObject(new ExecutionResult { IsException = true, - Result = ex.Message + Result = exception.Message }, Formatting.Indented)); } finally @@ -149,6 +172,7 @@ namespace Mirantis.Murano.WindowsAgent catch {} } + Log.Debug("Finished execution execution plan"); } } diff --git a/WindowsAgent/Program.cs b/WindowsAgent/Program.cs index c6e4409f..007f419e 100644 --- a/WindowsAgent/Program.cs +++ b/WindowsAgent/Program.cs @@ -30,7 +30,7 @@ namespace Mirantis.Murano.WindowsAgent { base.OnStart(args); - Log.Info("Version 0.5"); + Log.Info("Version 0.5.2"); this.rabbitMqClient = new RabbitMqClient();