1 /* |
1 /* |
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the License "Eclipse Public License v1.0" |
5 * under the terms of the License "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: To update the build status to Diamonds with signals in case of build exceptions. |
14 * Description: To update the build status to Diamonds with signals in case of build exceptions. |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.helium.diamonds; |
18 package com.nokia.helium.diamonds; |
19 |
19 |
|
20 import java.text.SimpleDateFormat; |
|
21 import org.apache.tools.ant.types.DataType; |
|
22 import java.util.Hashtable; |
|
23 import java.util.Vector; |
|
24 import org.apache.log4j.Logger; |
20 import org.apache.tools.ant.Project; |
25 import org.apache.tools.ant.Project; |
21 import com.nokia.helium.core.ant.HlmExceptionHandler; |
26 import com.nokia.helium.core.ant.HlmExceptionHandler; |
22 import com.nokia.helium.core.PropertiesSource; |
|
23 import com.nokia.helium.core.TemplateInputSource; |
|
24 import com.nokia.helium.core.TemplateProcessor; |
|
25 import com.nokia.helium.signal.SignalStatus; |
27 import com.nokia.helium.signal.SignalStatus; |
26 import com.nokia.helium.signal.SignalStatusList; |
28 import com.nokia.helium.signal.SignalStatusList; |
27 |
|
28 import org.apache.log4j.Logger; |
|
29 |
|
30 import java.util.Hashtable; |
|
31 import java.util.Vector; |
|
32 import java.util.List; |
|
33 import java.io.File; |
|
34 import java.util.ArrayList; |
|
35 import java.text.SimpleDateFormat; |
|
36 import java.util.Properties; |
|
37 |
29 |
38 |
30 |
39 /** |
31 /** |
40 * Class to store the builds status and check the signal is present in the deferred signal list. |
32 * Class to store the builds status and check the signal is present in the deferred signal list. |
41 * if so get the signal informations like signal name, error message and target name. |
33 * if so get the signal informations like signal name, error message and target name. |
42 * With collected signal information and build status send the generated XML file to diamonds client class |
34 * With collected signal information and build status send the generated XML file to diamonds client class |
43 * to update the information into diamonds |
35 * to update the information into diamonds |
44 */ |
36 */ |
45 public class DiamondsExceptionStatusUpdate implements HlmExceptionHandler { |
37 public class DiamondsExceptionStatusUpdate extends DataType implements HlmExceptionHandler { |
46 private Logger log = Logger.getLogger(DiamondsExceptionStatusUpdate.class); |
38 private Logger log = Logger.getLogger(DiamondsExceptionStatusUpdate.class); |
47 |
39 |
48 /* Initiate build status to failed as this method will be invoked in case of exceptions only */ |
40 /* Initiate build status to failed as this method will be invoked in case of exceptions only */ |
49 private String buildStatus = "failed"; |
41 private String buildStatus = "failed"; |
50 |
42 |
51 private SimpleDateFormat timeFormat; |
43 private SimpleDateFormat timeFormat; |
52 |
44 |
53 private TemplateProcessor templateProcessor; |
|
54 |
|
55 private Hashtable<String, String> signalInformation = new Hashtable<String, String>(); |
45 private Hashtable<String, String> signalInformation = new Hashtable<String, String>(); |
56 |
46 |
57 private String outputFile,templateFile; |
47 private String outputFile,templateFile; |
58 |
48 |
59 private List<TemplateInputSource> sourceList = new ArrayList<TemplateInputSource>(); |
|
60 |
49 |
61 /** |
50 /** |
62 * Implements the Exception method to update build status and signal information to diamonds. |
51 * Implements the Exception method to update build status and signal information to diamonds. |
63 * @param project |
52 * @param project |
64 * @param module |
53 * @param module |
65 * @param e |
54 * @param e |
66 */ |
55 */ |
67 @SuppressWarnings("unchecked") |
56 @SuppressWarnings("unchecked") |
68 public void handleException(Project project, String module, Exception e) { |
57 public void handleException(Project project, Exception e) { |
69 templateProcessor = new TemplateProcessor(); |
58 Project prj = DiamondsListenerImpl.getProject(); |
70 Properties tempProperties = new Properties(); |
|
71 String templateDir = DiamondsConfig.getTemplateDir(); |
|
72 /* Initialize the diamond properties class to access the diamonds properties */ |
|
73 DiamondsProperties diamondsProperties = DiamondsConfig.getDiamondsProperties(); |
|
74 //Check, Is the diamonds listener is initialized? |
|
75 if (DiamondsListenerImpl.isInitialized()) { |
|
76 timeFormat = new SimpleDateFormat(DiamondsConfig.getDiamondsProperties().getProperty("tstampformat")); |
|
77 /* Initialize the diamond client class required to update the information into diamonds. */ |
|
78 DiamondsClient diamondsClient = new DiamondsClient(project |
|
79 .getProperty(diamondsProperties.getProperty("host")), |
|
80 project.getProperty(diamondsProperties |
|
81 .getProperty("port")), project |
|
82 .getProperty(diamondsProperties |
|
83 .getProperty("path")), project |
|
84 .getProperty(diamondsProperties |
|
85 .getProperty("mail"))); |
|
86 |
59 |
87 /* Check is the signal is in deferred signal list? |
60 try { |
88 * If so get the signal information like signal name, error message and target name |
61 if (DiamondsListenerImpl.isInitialized()) { |
89 * |
62 if (SignalStatusList.getDeferredSignalList().hasSignalInList()) { |
90 */ |
63 Vector<SignalStatus> signalList = SignalStatusList.getDeferredSignalList().getSignalStatusList(); |
91 if (SignalStatusList.getDeferredSignalList().hasSignalInList()) { |
64 timeFormat = new SimpleDateFormat(DiamondsConfig.getTimeFormat()); |
92 Vector<SignalStatus> signalList = SignalStatusList.getDeferredSignalList().getSignalStatusList(); |
65 log.debug("Build Status = " + buildStatus); |
93 timeFormat = new SimpleDateFormat(DiamondsConfig.getDiamondsProperties().getProperty("tstampformat")); |
66 int i = 0; |
94 log.debug("Build Status = " + buildStatus); |
67 for (SignalStatus status : signalList) { |
95 int i = 0; |
68 prj.setProperty("diamond.signal.name." + i, status.getName()); |
96 for (SignalStatus status : signalList) { |
69 prj.setProperty("diamond.error.message." + i, status.getName()); |
97 signalInformation.put("diamond.signal.name." + i, status.getName()); |
70 prj.setProperty("diamond.time.stamp." + i, new String(timeFormat.format(status.getTimestamp()))); |
98 signalInformation.put("diamond.error.message." + i, status.getMessage()); |
71 DiamondsListenerImpl.sendMessage("diamonds-signal"); |
99 signalInformation.put("diamond.time.stamp." + i,new String(timeFormat.format(status.getTimestamp()))); |
72 } |
100 i += 1; |
|
101 } |
73 } |
102 /* Generate the signal XML file required for diamonds to update the signal information, |
74 if (SignalStatusList.getNowSignalList().hasSignalInList()) { |
103 * using templateprocessor class |
75 Vector<SignalStatus> signalList = SignalStatusList.getNowSignalList().getSignalStatusList(); |
104 */ |
76 buildStatus = "failed"; |
105 templateFile = "diamonds_signal.xml.ftl"; |
77 timeFormat = new SimpleDateFormat(DiamondsConfig.getTimeFormat()); |
106 outputFile = DiamondsConfig.getOutputDir() + File.separator + "diamonds-signal.xml"; |
78 log.debug("Build Status = " + buildStatus); |
107 sourceList.add(new PropertiesSource("diamondSignal", signalInformation)); |
79 int i = 0; |
108 templateProcessor.convertTemplate(templateDir, templateFile, outputFile,sourceList); |
80 for (SignalStatus status : signalList) { |
109 |
81 prj.setProperty("diamond.signal.name." + i, status.getName()); |
110 /* send the generated XML file for diamonds client to update the signals information into Diamonds */ |
82 prj.setProperty("diamond.error.message." + i, status.getMessage()); |
111 log.debug("sending data to diamonds ..." + outputFile); |
83 prj.setProperty("diamond.time.stamp." + i,new String(timeFormat.format(status.getTimestamp()))); |
112 diamondsClient.sendData(outputFile, DiamondsConfig.getDiamondsProperties().getDiamondsBuildID()); |
84 i += 1; |
113 try { |
85 } |
114 DiamondsListenerImpl.mergeToFullResults(new File(outputFile)); |
86 DiamondsListenerImpl.sendMessage("diamonds.signal.message"); |
115 } catch (DiamondsException de) { |
|
116 log.error("Not able to merge into full results XML file " + de.getMessage(), de); |
|
117 } |
87 } |
|
88 prj.setProperty("build.status", buildStatus); |
|
89 DiamondsListenerImpl.sendMessage("diamonds.status.message"); |
118 } |
90 } |
119 /* Check, is the signal is in now signal list? |
91 } catch (DiamondsException dex) { |
120 * If so get the signal information like signal name, error message and target name |
92 log.debug("exception: ", dex); |
121 * |
|
122 */ |
|
123 if (SignalStatusList.getNowSignalList().hasSignalInList()) { |
|
124 Vector<SignalStatus> signalList = SignalStatusList.getNowSignalList().getSignalStatusList(); |
|
125 buildStatus = "failed"; |
|
126 timeFormat = new SimpleDateFormat(DiamondsConfig.getDiamondsProperties().getProperty("tstampformat")); |
|
127 log.debug("Build Status = " + buildStatus); |
|
128 int i = 0; |
|
129 for (SignalStatus status : signalList) { |
|
130 signalInformation.put("diamond.signal.name." + i, status.getName()); |
|
131 signalInformation.put("diamond.error.message." + i, status.getMessage()); |
|
132 signalInformation.put("diamond.time.stamp." + i,new String(timeFormat.format(status.getTimestamp()))); |
|
133 i += 1; |
|
134 } |
|
135 /* Generate the signal XML file required for diamonds to update the signal information, |
|
136 * using templateprocessor class |
|
137 */ |
|
138 templateFile = "diamonds_signal.xml.ftl"; |
|
139 outputFile = DiamondsConfig.getOutputDir() + File.separator + "diamonds-signal.xml"; |
|
140 sourceList.add(new PropertiesSource("diamondSignal", signalInformation)); |
|
141 templateProcessor.convertTemplate(templateDir, templateFile, outputFile,sourceList); |
|
142 |
|
143 /* send the generated XML file for diamonds client to update the signals information into Diamonds */ |
|
144 log.debug("sending data to diamonds ..." + outputFile); |
|
145 diamondsClient.sendData(outputFile, DiamondsConfig.getDiamondsProperties().getDiamondsBuildID()); |
|
146 try { |
|
147 DiamondsListenerImpl.mergeToFullResults(new File(outputFile)); |
|
148 } catch (DiamondsException de) { |
|
149 log.error("Not able to merge into full results XML file " + de.getMessage(), de); |
|
150 } |
|
151 } |
|
152 /* Generate the build status XML file required for diamonds to update the build status information, |
|
153 * using templateprocessor class. |
|
154 */ |
|
155 tempProperties.put("build.status", buildStatus); |
|
156 sourceList.add(new PropertiesSource("ant", project.getProperties())); |
|
157 sourceList.add(new PropertiesSource("diamonds", tempProperties)); |
|
158 outputFile = DiamondsConfig.getOutputDir() + File.separator + "diamonds-status.xml"; |
|
159 templateFile = "diamonds_status.xml.ftl"; |
|
160 templateProcessor.convertTemplate(templateDir, templateFile, outputFile, sourceList); |
|
161 |
|
162 /* send the generated XML file for diamonds client to update the build status into Diamonds */ |
|
163 log.debug("[DiamondsExceptionStatusUpdate] => sending data to diamonds ..." + outputFile); |
|
164 diamondsClient.sendData(outputFile, DiamondsConfig.getDiamondsProperties().getDiamondsBuildID()); |
|
165 try { |
|
166 DiamondsListenerImpl.mergeToFullResults(new File(outputFile)); |
|
167 } catch (DiamondsException de) { |
|
168 log.error("Not able to merge into full results XML file " + de.getMessage(), de); |
|
169 } |
|
170 } |
93 } |
171 |
|
172 } |
94 } |
173 } |
95 } |