1 | <?xml version="1.0" encoding="UTF-8"?> |
---|
2 | <xsl:stylesheet version="2.0" |
---|
3 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dcworms="DCWormsResSchema.xsd" |
---|
4 | xmlns:debb2dcworms="../../debb2dcworms.xsd" |
---|
5 | xmlns:fun="http://whatever"> |
---|
6 | |
---|
7 | <!-- Specification of the output document --> |
---|
8 | <xsl:output method="xml" version="1.0" encoding="UTF-8" |
---|
9 | indent="yes" /> |
---|
10 | |
---|
11 | <!-- Root of the DCWoRMS XML document --> |
---|
12 | <xsl:variable name="rootDoc" select="/" /> |
---|
13 | |
---|
14 | <!-- Information about schedulers and estimators --> |
---|
15 | <xsl:param name="additionalInformationFileName" select="additionalInformationFileName" /> |
---|
16 | |
---|
17 | |
---|
18 | <xsl:variable name="nestedDoc" |
---|
19 | select="document($additionalInformationFileName)" /> |
---|
20 | |
---|
21 | <xsl:template match="/"> |
---|
22 | <xsl:comment> |
---|
23 | This is DEBB information (taken from PLM XML and DEBBComponent |
---|
24 | files), updated by schedulers and estimators. Moreover, all elements |
---|
25 | are sorted and appear in correct order, according to the schema. |
---|
26 | </xsl:comment> |
---|
27 | <xsl:comment> |
---|
28 | Schedulers and estimators information is loaded from |
---|
29 | <xsl:value-of select="$additionalInformationFileName" /> |
---|
30 | file |
---|
31 | </xsl:comment> |
---|
32 | |
---|
33 | <xsl:apply-templates select="environment" /> |
---|
34 | |
---|
35 | </xsl:template> |
---|
36 | |
---|
37 | <xsl:template match="environment"> |
---|
38 | <xsl:copy> |
---|
39 | <xsl:copy-of select="@*" /> |
---|
40 | <xsl:apply-templates select="$nestedDoc//timeEstimationPlugin" /> |
---|
41 | <xsl:apply-templates select="resources" /> |
---|
42 | <xsl:apply-templates select="templates"/> |
---|
43 | </xsl:copy> |
---|
44 | </xsl:template> |
---|
45 | |
---|
46 | <xsl:template match="resources"> |
---|
47 | <xsl:copy copy-namespaces="no"> |
---|
48 | <xsl:apply-templates select="//resources/computingResource" /> |
---|
49 | <xsl:element name="scheduler"> |
---|
50 | <xsl:attribute name="class">Cluster</xsl:attribute> |
---|
51 | <xsl:attribute name="name">cluster</xsl:attribute> |
---|
52 | <!-- In first version, for simplicity, we assume we have only one scheduler |
---|
53 | and one scheduling plugin. If $additionalInformationFileName contains more |
---|
54 | than one, the rest is ignored --> |
---|
55 | <xsl:apply-templates select="$nestedDoc//schedulingPlugin[1]" /> |
---|
56 | </xsl:element> |
---|
57 | </xsl:copy> |
---|
58 | </xsl:template> |
---|
59 | |
---|
60 | <xsl:template match="timeEstimationPlugin"> |
---|
61 | <xsl:element name="timeEstimationPlugin"> |
---|
62 | <xsl:element name="name"> |
---|
63 | <xsl:value-of select="name" /> |
---|
64 | </xsl:element> |
---|
65 | </xsl:element> |
---|
66 | </xsl:template> |
---|
67 | |
---|
68 | |
---|
69 | <xsl:template match="schedulingPlugin"> |
---|
70 | <xsl:variable name="pluginName" select="name" /> |
---|
71 | <xsl:element name="schedulingPlugin"> |
---|
72 | <xsl:element name="name"> |
---|
73 | <xsl:value-of select="$pluginName" /> |
---|
74 | </xsl:element> |
---|
75 | <xsl:if test="frequency != ''"> |
---|
76 | <xsl:element name="frequency"> |
---|
77 | <xsl:value-of select="frequency" /> |
---|
78 | </xsl:element> |
---|
79 | </xsl:if> |
---|
80 | </xsl:element> |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | <xsl:element name="managedComputingResources"> |
---|
85 | <!-- TODO: This parameter should be taken from somewhere. --> |
---|
86 | <xsl:attribute name="include">false</xsl:attribute> |
---|
87 | |
---|
88 | <!-- Find appropriate resources (identified by class, type and name(s)) |
---|
89 | and add their names here --> |
---|
90 | <xsl:variable name="resourceClass"> |
---|
91 | <xsl:value-of select="resources/class" /> |
---|
92 | </xsl:variable> |
---|
93 | <!-- <xsl:value-of select="$resourceClass"/> --> |
---|
94 | <xsl:variable name="resourceType"> |
---|
95 | <xsl:value-of select="resources/type" /> |
---|
96 | </xsl:variable> |
---|
97 | <!-- <xsl:value-of select="$resourceType"/> --> |
---|
98 | |
---|
99 | <!-- Not clear why it does not work this way :/ --> |
---|
100 | <!-- <xsl:variable name="resourceNames"><xsl:value-of select="resources/name"/></xsl:variable> --> |
---|
101 | <xsl:variable name="resourceNames" |
---|
102 | select="$nestedDoc//schedulingPlugin[name=$pluginName]/resources/name" /> |
---|
103 | |
---|
104 | <xsl:choose> |
---|
105 | <!-- Resource names are present --> |
---|
106 | <xsl:when test="count($resourceNames) > 0"> |
---|
107 | <xsl:for-each select="$resourceNames"> |
---|
108 | <xsl:variable name="index" select="position()" /> |
---|
109 | <xsl:variable name="resourceName" select="." /> |
---|
110 | |
---|
111 | <xsl:apply-templates select="$rootDoc//computingResource[(@name=$resourceName and @class=$resourceClass) or |
---|
112 | (@name=$resourceName and @class=$resourceClass and @type=$resourceType)]" mode="addManagedResorceName"/> |
---|
113 | </xsl:for-each> |
---|
114 | </xsl:when> |
---|
115 | <!-- Resource names are NOT present --> |
---|
116 | <xsl:otherwise> |
---|
117 | <xsl:apply-templates select="$rootDoc//computingResource[(@class=$resourceClass) or |
---|
118 | (@class=$resourceClass and @type=$resourceType)]" mode="addManagedResorceName"/> |
---|
119 | </xsl:otherwise> |
---|
120 | </xsl:choose> |
---|
121 | </xsl:element> |
---|
122 | </xsl:template> |
---|
123 | |
---|
124 | <xsl:function name="fun:hasManagedResources"> |
---|
125 | <xsl:param name="resourceClass"/> |
---|
126 | <xsl:param name="resourceTypes"/> |
---|
127 | <xsl:param name="resourceNames"/> |
---|
128 | |
---|
129 | |
---|
130 | </xsl:function> |
---|
131 | |
---|
132 | <xsl:template match="energyEstimationPlugin"> |
---|
133 | <xsl:element name="energyEstimationPlugin"> |
---|
134 | <xsl:element name="name"> |
---|
135 | <xsl:value-of select="name" /> |
---|
136 | </xsl:element> |
---|
137 | </xsl:element> |
---|
138 | </xsl:template> |
---|
139 | |
---|
140 | |
---|
141 | <xsl:template match="computingResourceTemplate | computingResource"> |
---|
142 | <xsl:copy copy-namespaces="no"> |
---|
143 | <xsl:copy-of select="@*" /> |
---|
144 | <!-- Find nested elements in appropriate order and copy them --> |
---|
145 | |
---|
146 | <!-- templateId --> |
---|
147 | <xsl:apply-templates select="templateId" /> |
---|
148 | |
---|
149 | <!-- resourceUnit --> |
---|
150 | <xsl:apply-templates select="resourceUnit" /> |
---|
151 | <!-- parameter --> |
---|
152 | <xsl:apply-templates select="parameter" /> |
---|
153 | |
---|
154 | <xsl:variable name="debbFullPath" select="fun:getFullPath(.)"/> |
---|
155 | <xsl:variable name="ancestors" select="ancestor::computingResourceTemplate"/> |
---|
156 | |
---|
157 | |
---|
158 | <xsl:if test="$debbFullPath != '' and name(.) = 'computingResource' and count($ancestors) = 0"> |
---|
159 | <!-- fullPath parameter should be added only for computingResource nodes; for computingResourceTemplate it is not needed; |
---|
160 | for computingResource nodes embedded in computingResourceTemplate nodes fullPath is not needed either --> |
---|
161 | <xsl:element name="parameter"> |
---|
162 | <xsl:attribute name="name">fullPath</xsl:attribute> |
---|
163 | <xsl:element name="value"> |
---|
164 | <xsl:value-of select="$debbFullPath" /> |
---|
165 | </xsl:element> |
---|
166 | </xsl:element> |
---|
167 | </xsl:if> |
---|
168 | |
---|
169 | |
---|
170 | <xsl:variable name="resourceClass" select="@class"/> |
---|
171 | <xsl:variable name="resourceType" select="@type"/> |
---|
172 | <xsl:variable name="resourceName" select="@name"/> |
---|
173 | |
---|
174 | <xsl:if test="not(templateId)"> |
---|
175 | <!-- Don't add energyEstimationPlugin information if there is a template defined for the computingResource. |
---|
176 | It will appear in the template. --> |
---|
177 | <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/> |
---|
178 | <xsl:variable name="hasProfile" select="profile != ''"/> |
---|
179 | <xsl:variable name="hasPowerProfile" select="profile/powerProfile != ''"/> |
---|
180 | |
---|
181 | <xsl:if test="$hasProfile = false() and $estimationPluginName != ''"> |
---|
182 | <xsl:element name="profile"> |
---|
183 | <xsl:element name="powerProfile"> |
---|
184 | <xsl:element name="energyEstimationPlugin"> |
---|
185 | <xsl:element name="name"> |
---|
186 | <xsl:value-of select="$estimationPluginName"/> |
---|
187 | </xsl:element> |
---|
188 | </xsl:element> |
---|
189 | </xsl:element> |
---|
190 | </xsl:element> |
---|
191 | </xsl:if> |
---|
192 | </xsl:if> |
---|
193 | |
---|
194 | |
---|
195 | <!-- profile --> |
---|
196 | <xsl:apply-templates select="profile" /> |
---|
197 | <!-- location --> |
---|
198 | <xsl:apply-templates select="location" /> |
---|
199 | |
---|
200 | <!-- computingResource --> |
---|
201 | <xsl:apply-templates select="computingResource" /> |
---|
202 | |
---|
203 | </xsl:copy> |
---|
204 | </xsl:template> |
---|
205 | |
---|
206 | <xsl:function name="fun:getEnergyEstimator"> |
---|
207 | <xsl:param name="computingResourceClass"/> |
---|
208 | <xsl:param name="computingResourceType"/> |
---|
209 | <xsl:param name="computingResourceName"/> |
---|
210 | |
---|
211 | <xsl:variable name="estimatorName" select="$nestedDoc//energyEstimationPlugin[(resources/class=$computingResourceClass and resources/type=$computingResourceType and resources/name=$computingResourceName) or |
---|
212 | (resources/class=$computingResourceClass and resources/type=$computingResourceType) or |
---|
213 | (resources/class=$computingResourceClass and resources/name=$computingResourceName) or |
---|
214 | resources/class=$computingResourceClass]/name"/> |
---|
215 | |
---|
216 | <xsl:value-of select="$estimatorName"/> |
---|
217 | </xsl:function> |
---|
218 | |
---|
219 | <xsl:template match="computingResource" mode="addManagedResorceName"> |
---|
220 | <xsl:element name="resourceName"> |
---|
221 | <!-- <xsl:value-of select="../@name"></xsl:value-of> --> |
---|
222 | <xsl:value-of select="@name"></xsl:value-of> |
---|
223 | </xsl:element> |
---|
224 | </xsl:template> |
---|
225 | |
---|
226 | <xsl:template match="computingResource" mode="addEnergyEstimationPlugin"> |
---|
227 | <xsl:element name="energyEstimationPlugin"> |
---|
228 | <xsl:value-of select="name"></xsl:value-of> |
---|
229 | </xsl:element> |
---|
230 | </xsl:template> |
---|
231 | |
---|
232 | <xsl:function name="fun:getFullPath"> |
---|
233 | <xsl:param name="currentComputingResource"/> |
---|
234 | <xsl:variable name="ancestors" select="$currentComputingResource/ancestor::computingResource/@name"/> |
---|
235 | |
---|
236 | |
---|
237 | <xsl:variable name="fullPath"> |
---|
238 | <xsl:text>/</xsl:text> |
---|
239 | <xsl:for-each select="1 to count($ancestors)"> |
---|
240 | <xsl:variable name="index" select="." /> |
---|
241 | <xsl:value-of select="$ancestors[$index]"/> |
---|
242 | <xsl:text>/</xsl:text> |
---|
243 | </xsl:for-each> |
---|
244 | <xsl:value-of select="$currentComputingResource/@name"></xsl:value-of> |
---|
245 | </xsl:variable> |
---|
246 | |
---|
247 | <xsl:value-of select="$fullPath"/> |
---|
248 | </xsl:function> |
---|
249 | |
---|
250 | <xsl:template match="resourceUnit | parameter | location"> |
---|
251 | <xsl:copy-of select="." copy-namespaces="no" /> |
---|
252 | </xsl:template> |
---|
253 | |
---|
254 | <xsl:template match="profile"> |
---|
255 | <xsl:copy copy-namespaces="no"> |
---|
256 | <xsl:copy-of select="@*" /> |
---|
257 | |
---|
258 | <xsl:apply-templates select="powerProfile" /> |
---|
259 | <xsl:apply-templates select="airThroughputProfile" /> |
---|
260 | <xsl:apply-templates select="waterThroughputProfile" /> |
---|
261 | </xsl:copy> |
---|
262 | </xsl:template> |
---|
263 | |
---|
264 | <xsl:template match="powerProfile"> |
---|
265 | <xsl:copy copy-namespaces="no"> |
---|
266 | <xsl:variable name="resourceClass" select="../../@class"></xsl:variable> |
---|
267 | <xsl:variable name="resourceType" select="../../@type"></xsl:variable> |
---|
268 | <xsl:variable name="resourceNames" select="../../@name"></xsl:variable> |
---|
269 | |
---|
270 | <xsl:choose> |
---|
271 | <!-- Resource names are present --> |
---|
272 | <xsl:when test="count($resourceNames) > 0"> |
---|
273 | <xsl:for-each select="$resourceNames"> |
---|
274 | <xsl:variable name="index" select="position()" /> |
---|
275 | <xsl:variable name="resourceName" select="." /> |
---|
276 | <xsl:choose> |
---|
277 | <!-- Resource type is present --> |
---|
278 | <xsl:when test="$resourceType != ''"> |
---|
279 | <xsl:apply-templates |
---|
280 | select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType and resources/name=$resourceName]" /> |
---|
281 | </xsl:when> |
---|
282 | <xsl:otherwise> |
---|
283 | <xsl:apply-templates |
---|
284 | select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/name=$resourceName]" /> |
---|
285 | </xsl:otherwise> |
---|
286 | </xsl:choose> |
---|
287 | </xsl:for-each> |
---|
288 | </xsl:when> |
---|
289 | <!-- No resource names --> |
---|
290 | <xsl:otherwise> |
---|
291 | <xsl:choose> |
---|
292 | <!-- Resource type is present --> |
---|
293 | <xsl:when test="$resourceType != ''"> |
---|
294 | <xsl:apply-templates |
---|
295 | select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType]" /> |
---|
296 | </xsl:when> |
---|
297 | <xsl:otherwise> |
---|
298 | <xsl:apply-templates |
---|
299 | select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass]" /> |
---|
300 | </xsl:otherwise> |
---|
301 | </xsl:choose> |
---|
302 | </xsl:otherwise> |
---|
303 | </xsl:choose> |
---|
304 | |
---|
305 | <!-- Copy all children of powerProfile --> |
---|
306 | <xsl:copy-of select="@*|node()" /> |
---|
307 | </xsl:copy> |
---|
308 | |
---|
309 | </xsl:template> |
---|
310 | |
---|
311 | <xsl:template match="airThroughputProfile"> |
---|
312 | <xsl:copy copy-namespaces="no"> |
---|
313 | <!-- Copy all children of airThroughputProfile --> |
---|
314 | <xsl:copy-of select="@*|node()" /> |
---|
315 | </xsl:copy> |
---|
316 | </xsl:template> |
---|
317 | |
---|
318 | <xsl:template match="waterThroughputProfile"> |
---|
319 | <xsl:copy copy-namespaces="no"> |
---|
320 | <!-- Copy all children of waterThroughputProfile --> |
---|
321 | <xsl:copy-of select="@*|node()" /> |
---|
322 | </xsl:copy> |
---|
323 | </xsl:template> |
---|
324 | |
---|
325 | <xsl:template match="templates"> |
---|
326 | <xsl:copy copy-namespaces="no"> |
---|
327 | <xsl:apply-templates/> |
---|
328 | </xsl:copy> |
---|
329 | |
---|
330 | </xsl:template> |
---|
331 | |
---|
332 | <xsl:template match="@*|node()"> |
---|
333 | <xsl:copy> |
---|
334 | <xsl:apply-templates select="@*" /> |
---|
335 | <xsl:apply-templates /> |
---|
336 | </xsl:copy> |
---|
337 | </xsl:template> |
---|
338 | |
---|
339 | </xsl:stylesheet> |
---|