Browse Source

Return additional information to conductor upon exception

Change-Id: Ie01ee67eb8feccfb87577672f554cb19f7ed9bef
Stan Lagun 5 years ago
parent
commit
c9a6497d01
2 changed files with 31 additions and 7 deletions
  1. 30
    6
      WindowsAgent/PlanExecutor.cs
  2. 1
    1
      WindowsAgent/Program.cs

+ 30
- 6
WindowsAgent/PlanExecutor.cs View File

@@ -44,8 +44,9 @@ namespace Mirantis.Murano.WindowsAgent
44 44
 				{
45 45
 					currentResults = JsonConvert.DeserializeObject<List<ExecutionResult>>(File.ReadAllText(resultPath));
46 46
 				}
47
-				catch
47
+				catch(Exception exception)
48 48
 				{
49
+					Log.WarnException("Cannot deserialize previous execution result", exception);
49 50
 					currentResults = new List<ExecutionResult>();
50 51
 				}
51 52
 
@@ -57,15 +58,18 @@ namespace Mirantis.Murano.WindowsAgent
57 58
 				runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
58 59
 				if (plan.Scripts != null)
59 60
 				{
61
+					var index = 0;
60 62
 					foreach (var script in plan.Scripts)
61 63
 					{
62 64
 						runSpaceInvoker.Invoke(Encoding.UTF8.GetString(Convert.FromBase64String(script)));
65
+						Log.Debug("Loaded script #{0}", ++index);
63 66
 					}
64 67
 				}
65 68
 
66 69
 				while (plan.Commands != null && plan.Commands.Any())
67 70
 				{
68 71
 					var command = plan.Commands.First();
72
+					Log.Debug("Preparing to execute command {0}", command.Name);
69 73
 
70 74
 					var pipeline = runSpace.CreatePipeline();
71 75
 					var psCommand = new Command(command.Name);
@@ -83,9 +87,11 @@ namespace Mirantis.Murano.WindowsAgent
83 87
 							t => string.Format("{0}={1}", t.Key, t.Value == null ? "null" : t.Value.ToString()))));
84 88
 
85 89
 					pipeline.Commands.Add(psCommand);
90
+
86 91
 					try
87 92
 					{
88 93
 						var result = pipeline.Invoke();
94
+						Log.Debug("Command {0} executed", command.Name);
89 95
 						if (result != null)
90 96
 						{
91 97
 							currentResults.Add(new ExecutionResult {
@@ -96,10 +102,27 @@ namespace Mirantis.Murano.WindowsAgent
96 102
 					}
97 103
 					catch (Exception exception)
98 104
 					{
99
-						currentResults.Add(new ExecutionResult {
105
+						object additionInfo = null;
106
+						if (exception is ActionPreferenceStopException)
107
+						{
108
+							var apse = exception as ActionPreferenceStopException;
109
+							if (apse.ErrorRecord != null)
110
+							{
111
+								additionInfo = new {
112
+									ScriptStackTrace = apse.ErrorRecord.ScriptStackTrace,
113
+									PositionMessage = apse.ErrorRecord.InvocationInfo.PositionMessage
114
+								};
115
+								exception = apse.ErrorRecord.Exception;
116
+							}
117
+						}
118
+
119
+
120
+						Log.WarnException("Exception while executing command " + command.Name, exception);
121
+						currentResults.Add(new ExecutionResult
122
+						{
100 123
 							IsException = true,
101 124
 							Result = new[] {
102
-								exception.GetType().FullName, exception.Message
125
+								exception.GetType().FullName, exception.Message, command.Name, additionInfo
103 126
 							}
104 127
 						});
105 128
 						break;
@@ -129,13 +152,13 @@ namespace Mirantis.Murano.WindowsAgent
129 152
 					}
130 153
 				}
131 154
 				File.WriteAllText(resultPath, executionResult);
132
-
133 155
 			}
134
-			catch (Exception ex)
156
+			catch (Exception exception)
135 157
 			{
158
+				Log.WarnException("Exception while processing execution plan", exception);
136 159
 				File.WriteAllText(resultPath, JsonConvert.SerializeObject(new ExecutionResult {
137 160
 					IsException = true,
138
-					Result = ex.Message
161
+					Result = exception.Message
139 162
 				}, Formatting.Indented));
140 163
 			}
141 164
 			finally
@@ -149,6 +172,7 @@ namespace Mirantis.Murano.WindowsAgent
149 172
 					catch
150 173
 					{}
151 174
 				}
175
+				Log.Debug("Finished execution execution plan");
152 176
 			}
153 177
 		}
154 178
 

+ 1
- 1
WindowsAgent/Program.cs View File

@@ -30,7 +30,7 @@ namespace Mirantis.Murano.WindowsAgent
30 30
 		{
31 31
 			base.OnStart(args);
32 32
 
33
-			Log.Info("Version 0.5");
33
+			Log.Info("Version 0.5.2");
34 34
 
35 35
 			this.rabbitMqClient = new RabbitMqClient();
36 36
 

Loading…
Cancel
Save