summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Lagun <slagun@mirantis.com>2013-08-29 11:10:35 +0400
committerStan Lagun <slagun@mirantis.com>2013-08-29 11:10:35 +0400
commitc9a6497d010a46f484343b582d53c1db7c502b61 (patch)
treece5d6a741497273d81b9d1dbe6009bbabbcd7565
parent61c1732341ac495b00a952dc814490789686ff17 (diff)
Return additional information to conductor upon exception
Notes
Notes (review): Verified+2: Jenkins Approved+1: Alexander Tivelkov <ativelkov@mirantis.com> Code-Review+2: Alexander Tivelkov <ativelkov@mirantis.com> Submitted-by: Jenkins Submitted-at: Thu, 29 Aug 2013 08:16:26 +0000 Reviewed-on: https://review.openstack.org/44225 Project: stackforge/murano-agent Branch: refs/heads/release-0.2
-rw-r--r--WindowsAgent/PlanExecutor.cs36
-rw-r--r--WindowsAgent/Program.cs2
2 files changed, 31 insertions, 7 deletions
diff --git a/WindowsAgent/PlanExecutor.cs b/WindowsAgent/PlanExecutor.cs
index 1ea851e..e9a4ad1 100644
--- a/WindowsAgent/PlanExecutor.cs
+++ b/WindowsAgent/PlanExecutor.cs
@@ -44,8 +44,9 @@ namespace Mirantis.Murano.WindowsAgent
44 { 44 {
45 currentResults = JsonConvert.DeserializeObject<List<ExecutionResult>>(File.ReadAllText(resultPath)); 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 currentResults = new List<ExecutionResult>(); 50 currentResults = new List<ExecutionResult>();
50 } 51 }
51 52
@@ -57,15 +58,18 @@ namespace Mirantis.Murano.WindowsAgent
57 runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted"); 58 runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
58 if (plan.Scripts != null) 59 if (plan.Scripts != null)
59 { 60 {
61 var index = 0;
60 foreach (var script in plan.Scripts) 62 foreach (var script in plan.Scripts)
61 { 63 {
62 runSpaceInvoker.Invoke(Encoding.UTF8.GetString(Convert.FromBase64String(script))); 64 runSpaceInvoker.Invoke(Encoding.UTF8.GetString(Convert.FromBase64String(script)));
65 Log.Debug("Loaded script #{0}", ++index);
63 } 66 }
64 } 67 }
65 68
66 while (plan.Commands != null && plan.Commands.Any()) 69 while (plan.Commands != null && plan.Commands.Any())
67 { 70 {
68 var command = plan.Commands.First(); 71 var command = plan.Commands.First();
72 Log.Debug("Preparing to execute command {0}", command.Name);
69 73
70 var pipeline = runSpace.CreatePipeline(); 74 var pipeline = runSpace.CreatePipeline();
71 var psCommand = new Command(command.Name); 75 var psCommand = new Command(command.Name);
@@ -83,9 +87,11 @@ namespace Mirantis.Murano.WindowsAgent
83 t => string.Format("{0}={1}", t.Key, t.Value == null ? "null" : t.Value.ToString())))); 87 t => string.Format("{0}={1}", t.Key, t.Value == null ? "null" : t.Value.ToString()))));
84 88
85 pipeline.Commands.Add(psCommand); 89 pipeline.Commands.Add(psCommand);
90
86 try 91 try
87 { 92 {
88 var result = pipeline.Invoke(); 93 var result = pipeline.Invoke();
94 Log.Debug("Command {0} executed", command.Name);
89 if (result != null) 95 if (result != null)
90 { 96 {
91 currentResults.Add(new ExecutionResult { 97 currentResults.Add(new ExecutionResult {
@@ -96,10 +102,27 @@ namespace Mirantis.Murano.WindowsAgent
96 } 102 }
97 catch (Exception exception) 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 IsException = true, 123 IsException = true,
101 Result = new[] { 124 Result = new[] {
102 exception.GetType().FullName, exception.Message 125 exception.GetType().FullName, exception.Message, command.Name, additionInfo
103 } 126 }
104 }); 127 });
105 break; 128 break;
@@ -129,13 +152,13 @@ namespace Mirantis.Murano.WindowsAgent
129 } 152 }
130 } 153 }
131 File.WriteAllText(resultPath, executionResult); 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 File.WriteAllText(resultPath, JsonConvert.SerializeObject(new ExecutionResult { 159 File.WriteAllText(resultPath, JsonConvert.SerializeObject(new ExecutionResult {
137 IsException = true, 160 IsException = true,
138 Result = ex.Message 161 Result = exception.Message
139 }, Formatting.Indented)); 162 }, Formatting.Indented));
140 } 163 }
141 finally 164 finally
@@ -149,6 +172,7 @@ namespace Mirantis.Murano.WindowsAgent
149 catch 172 catch
150 {} 173 {}
151 } 174 }
175 Log.Debug("Finished execution execution plan");
152 } 176 }
153 } 177 }
154 178
diff --git a/WindowsAgent/Program.cs b/WindowsAgent/Program.cs
index c6e4409..007f419 100644
--- a/WindowsAgent/Program.cs
+++ b/WindowsAgent/Program.cs
@@ -30,7 +30,7 @@ namespace Mirantis.Murano.WindowsAgent
30 { 30 {
31 base.OnStart(args); 31 base.OnStart(args);
32 32
33 Log.Info("Version 0.5"); 33 Log.Info("Version 0.5.2");
34 34
35 this.rabbitMqClient = new RabbitMqClient(); 35 this.rabbitMqClient = new RabbitMqClient();
36 36