source: DCWoRMS/branches/coolemall/simulator/xslt/debb/DCwormsDEBBUpdater.xsl @ 1228

Revision 1228, 14.2 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
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:copy-of select="@*" />
49                        <xsl:apply-templates select="//resources/computingResource" />
50                        <xsl:element name="scheduler">
51                                <xsl:attribute name="class">Cluster</xsl:attribute>
52                                <xsl:attribute name="name">cluster</xsl:attribute>
53                                <!-- In first version, for simplicity, we assume we have only one scheduler
54                                        and one scheduling plugin. If $additionalInformationFileName contains more
55                                        than one, the rest is ignored -->
56                                <xsl:apply-templates select="$nestedDoc//schedulingPlugin[1]" />
57                        </xsl:element>
58                </xsl:copy>
59        </xsl:template>
60
61        <xsl:template match="timeEstimationPlugin">
62                <xsl:element name="timeEstimationPlugin">
63                        <xsl:element name="name">
64                                <xsl:value-of select="name" />
65                        </xsl:element>
66                </xsl:element>
67        </xsl:template>
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                <xsl:element name="managedComputingResources">
83                        <!-- TODO: This parameter should be taken from somewhere. -->
84                        <xsl:attribute name="include">false</xsl:attribute>
85
86                        <!-- Find appropriate resources (identified by class, type and name(s))
87                                and add their names here -->
88                        <xsl:variable name="resourceClass">
89                                <xsl:value-of select="resources/class" />
90                        </xsl:variable>
91                        <xsl:variable name="resourceType">
92                                <xsl:value-of select="resources/type" />
93                        </xsl:variable>
94
95                        <!-- Not clear why it does not work this way :/ -->
96                        <!-- <xsl:variable name="resourceNames"><xsl:value-of select="resources/name"/></xsl:variable> -->
97                        <xsl:variable name="resourceNames"
98                                select="$nestedDoc//schedulingPlugin[name=$pluginName]/resources/name" />
99                       
100                        <xsl:choose>
101                                <!-- Resource names are present -->
102                                <xsl:when test="count($resourceNames) > 0">
103                                        <xsl:for-each select="$resourceNames">
104                                                <xsl:variable name="index" select="position()" />
105                                                <xsl:variable name="resourceName" select="." />
106                                               
107                                                <xsl:apply-templates select="$rootDoc//computingResource[(@name=$resourceName and @class=$resourceClass) or
108                                                        (@name=$resourceName and @class=$resourceClass and @type=$resourceType)]" mode="addManagedResorceName"/>
109                                        </xsl:for-each>
110                                </xsl:when>
111                                <!-- Resource names are NOT present -->                                 
112                                <xsl:otherwise>
113                                        <xsl:apply-templates select="$rootDoc//computingResource[(@class=$resourceClass) or
114                                                        (@class=$resourceClass and @type=$resourceType)]" mode="addManagedResorceName"/>                               
115                                </xsl:otherwise>
116                        </xsl:choose>   
117                </xsl:element>
118        </xsl:template>
119       
120        <xsl:template match="energyEstimationPlugin">
121                <xsl:element name="energyEstimationPlugin">
122                        <xsl:element name="name">
123                                <xsl:value-of select="name" />
124                        </xsl:element>
125                </xsl:element>
126        </xsl:template>
127
128
129        <xsl:template match="computingResourceTemplate | computingResource">
130                <xsl:copy copy-namespaces="no">
131                        <xsl:copy-of select="@*" />
132                        <!-- Find nested elements in appropriate order and copy them -->
133                       
134                        <!-- templateId -->
135                        <xsl:apply-templates select="templateId" />
136                       
137                        <!-- location -->
138                        <xsl:apply-templates select="location" />
139                        <!-- parameter -->
140                        <xsl:apply-templates select="parameter" />
141                                               
142                        <xsl:variable name="debbFullPath" select="fun:getFullPath(.)"/>
143                        <xsl:variable name="ancestors" select="ancestor::computingResourceTemplate"/>
144                               
145                       
146                        <xsl:if test="$debbFullPath != '' and name(.) = 'computingResource' and count($ancestors) = 0 and @name">
147                                <!-- fullPath parameter should be added only for computingResource nodes; for computingResourceTemplate it is not needed;
148                                for computingResource nodes embedded in computingResourceTemplate nodes fullPath is not needed either -->
149                                <xsl:element name="parameter">
150                                        <xsl:attribute name="name">fullPath</xsl:attribute>
151                                        <xsl:element name="value">
152                                                <xsl:value-of select="$debbFullPath" />
153                                        </xsl:element>
154                                </xsl:element>
155                        </xsl:if>                               
156                       
157                       
158                        <xsl:variable name="resourceClass" select="@class"/>
159                        <xsl:variable name="resourceType" select="@type"/>
160                        <xsl:variable name="resourceName" select="@name"/>
161                       
162                        <xsl:if test="not(templateId)">
163                                <!-- Don't add energyEstimationPlugin information if there is a template defined for the computingResource.
164                                 It will appear in the template. -->
165                                <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/>
166                                <xsl:variable name="hasProfile" select="profile != ''"/>
167       
168                                <xsl:if test="$hasProfile = false() and $estimationPluginName != ''">
169                                        <xsl:element name="profile">
170                                                <xsl:element name="powerProfile">
171                                                        <xsl:element name="energyEstimationPlugin">
172                                                                <xsl:element name="name">
173                                                                        <xsl:value-of select="$estimationPluginName"/>
174                                                                </xsl:element>
175                                                        </xsl:element>
176                                                </xsl:element>
177                                        </xsl:element>
178                                </xsl:if>
179                        </xsl:if>
180                       
181                        <!-- profile -->
182                        <xsl:apply-templates select="profile" />
183                        <!-- device -->
184                        <xsl:apply-templates select="device" />
185                        <!-- resourceUnit -->
186                        <xsl:apply-templates select="resourceUnit" />
187                       
188                        <!-- computingResource -->
189                        <xsl:apply-templates select="computingResource" />
190                                               
191                </xsl:copy>
192        </xsl:template>
193       
194       
195        <xsl:template match="device">
196                <xsl:copy copy-namespaces="no">
197                        <xsl:copy-of select="@*" />
198                        <!-- Find nested elements in appropriate order and copy them -->
199                       
200                        <!-- templateId -->
201                        <xsl:apply-templates select="templateId" />
202                       
203                        <!-- location -->
204                        <xsl:apply-templates select="location" />
205                        <!-- parameter -->
206                        <xsl:apply-templates select="parameter" />
207                                               
208                                                               
209                        <xsl:variable name="debbFullPath" select="fun:getFullPath(.)"/>
210                               
211                       
212                        <xsl:if test="$debbFullPath != '' and name(.) = 'device' and @name">
213                                <!-- fullPath parameter should be added only for computingResource nodes; for computingResourceTemplate it is not needed;
214                                for computingResource nodes embedded in computingResourceTemplate nodes fullPath is not needed either -->
215                                <xsl:element name="parameter">
216                                        <xsl:attribute name="name">fullPath</xsl:attribute>
217                                        <xsl:element name="value">
218                                                <xsl:value-of select="$debbFullPath" />
219                                        </xsl:element>
220                                </xsl:element>
221                        </xsl:if>       
222                       
223                        <xsl:variable name="resourceClass" select="@class"/>
224                        <xsl:variable name="resourceType" select="@type"/>
225                        <xsl:variable name="resourceName" select="@name"/>
226                       
227                        <xsl:if test="not(templateId)">
228                                <!-- Don't add energyEstimationPlugin information if there is a template defined for the computingResource.
229                                 It will appear in the template. -->
230                                <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/>
231                                <xsl:variable name="hasProfile" select="profile != ''"/>
232                                <xsl:variable name="hasPowerProfile" select="profile/powerProfile != ''"/>
233       
234                                <xsl:if test="$hasProfile = false() and $estimationPluginName != ''">
235                                        <xsl:element name="profile">
236                                                <xsl:element name="powerProfile">
237                                                        <xsl:element name="energyEstimationPlugin">
238                                                                <xsl:element name="name">
239                                                                        <xsl:value-of select="$estimationPluginName"/>
240                                                                </xsl:element>
241                                                        </xsl:element>
242                                                </xsl:element>
243                                        </xsl:element>
244                                </xsl:if>
245                        </xsl:if>
246                       
247                        <!-- profile -->
248                        <xsl:apply-templates select="profile" />
249                                               
250                </xsl:copy>
251        </xsl:template>
252       
253
254        <xsl:function name="fun:getEnergyEstimator">
255                <xsl:param name="computingResourceClass"/>
256                <xsl:param name="computingResourceType"/>
257                <xsl:param name="computingResourceName"/>
258               
259   
260                <xsl:variable name="estimatorName" >
261                        <xsl:choose>
262                                <xsl:when test="$nestedDoc//energyEstimationPlugin[resources/class=$computingResourceClass and resources/name=$computingResourceName]/name !=''">
263                                        <xsl:value-of select="$nestedDoc//energyEstimationPlugin[resources/class=$computingResourceClass and resources/name=$computingResourceName]/name"/>
264                                </xsl:when>
265                                <xsl:when test="$nestedDoc//energyEstimationPlugin[resources/class=$computingResourceClass]/name !=''">
266                                        <xsl:value-of  select="$nestedDoc//energyEstimationPlugin[resources/class=$computingResourceClass ]/name"/>
267                                </xsl:when>
268                                <xsl:otherwise>
269                                </xsl:otherwise>
270                        </xsl:choose>
271                </xsl:variable>
272                <xsl:value-of select="$estimatorName"/>
273        </xsl:function>
274       
275        <xsl:template match="computingResource" mode="addManagedResorceName">
276                <xsl:variable name="debbFullPath" select="fun:getFullPath(.)"/>
277                <xsl:choose>
278                        <xsl:when test="$debbFullPath != '' and @name">
279                                <xsl:element name="resourceName">
280                                        <xsl:value-of select="$debbFullPath"></xsl:value-of>
281                                </xsl:element>
282                        </xsl:when>
283                        <xsl:otherwise>
284                                <xsl:element name="resourceName">
285                                        <xsl:value-of select="@name"></xsl:value-of>
286                                </xsl:element>
287                        </xsl:otherwise>
288                </xsl:choose>
289        </xsl:template>
290       
291        <xsl:function name="fun:getFullPath">
292                <xsl:param name="currentComputingResource"/>
293                <xsl:variable name="ancestors" select="$currentComputingResource/ancestor::computingResource/@name"/>
294
295               
296                <xsl:variable name="fullPath">
297                        <xsl:for-each select="1 to count($ancestors)">
298                                <xsl:variable name="index" select="." />
299                                <xsl:value-of select="$ancestors[$index]"/>
300                                <xsl:text>/</xsl:text>
301                        </xsl:for-each>
302                        <xsl:value-of select="$currentComputingResource/@name"></xsl:value-of> 
303                </xsl:variable>
304               
305                <xsl:value-of select="$fullPath"/>
306        </xsl:function>
307       
308        <xsl:template match="resourceUnit | parameter | location">
309                <xsl:copy-of select="." copy-namespaces="no" />
310        </xsl:template>
311
312        <xsl:template match="profile">
313                <xsl:copy copy-namespaces="no">
314                        <xsl:copy-of select="@*" />
315                       
316                       
317                        <xsl:variable name="resourceClass" select="../@class"/>
318                        <xsl:variable name="resourceType" select="../@type"/>
319                        <xsl:variable name="resourceName" select="../@name"/>
320                       
321
322                        <!-- Don't add energyEstimationPlugin information if there is a template defined for the computingResource.
323                         It will appear in the template. -->
324                        <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/>
325                        <xsl:variable name="hasPowerProfile" select="powerProfile != ''"/>
326
327                        <xsl:if test="$hasPowerProfile = false() and $estimationPluginName != ''">
328                                        <xsl:element name="powerProfile">
329                                                <xsl:element name="energyEstimationPlugin">
330                                                        <xsl:element name="name">
331                                                                <xsl:value-of select="$estimationPluginName"/>
332                                                        </xsl:element>
333                                                </xsl:element>
334                                        </xsl:element>
335                        </xsl:if>
336                       
337                        <xsl:apply-templates select="powerProfile" />
338                        <xsl:apply-templates select="airThroughputProfile" />
339
340                </xsl:copy>
341        </xsl:template>
342
343        <xsl:template match="powerProfile">
344                <xsl:copy copy-namespaces="no">
345                        <xsl:variable name="resourceClass" select="../../@class"></xsl:variable>
346                        <xsl:variable name="resourceType" select="../../@type"></xsl:variable>
347                        <xsl:variable name="resourceNames" select="../../@name"></xsl:variable>
348
349                        <xsl:choose>
350                                <!-- Resource names are present -->
351                                <xsl:when test="count($resourceNames) > 0">
352                                        <xsl:for-each select="$resourceNames">
353                                                <xsl:variable name="index" select="position()" />
354                                                <xsl:variable name="resourceName" select="." />
355                                                <xsl:choose>
356                                                        <!-- Resource type is present -->
357                                                        <xsl:when test="$resourceType != ''">
358                                                                <xsl:apply-templates
359                                                                        select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType and resources/name=$resourceName]" />
360                                                        </xsl:when>
361                                                        <xsl:otherwise>
362                                                                <xsl:apply-templates
363                                                                        select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/name=$resourceName]" />
364                                                        </xsl:otherwise>
365                                                </xsl:choose>
366                                        </xsl:for-each>
367                                </xsl:when>
368                                <!-- No resource names -->
369                                <xsl:otherwise>
370                                        <xsl:choose>
371                                                <!-- Resource type is present -->
372                                                <xsl:when test="$resourceType != ''">
373                                                        <xsl:apply-templates
374                                                                select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType]" />
375                                                </xsl:when>
376                                                <xsl:otherwise>
377                                                        <xsl:apply-templates
378                                                                select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass]" />
379                                                </xsl:otherwise>
380                                        </xsl:choose>
381                                </xsl:otherwise>
382                        </xsl:choose>
383                       
384                        <!-- Copy all children of powerProfile -->
385                        <xsl:copy-of select="@*|node()" />
386                </xsl:copy>
387
388        </xsl:template>
389
390        <xsl:template match="airThroughputProfile">
391                <xsl:copy copy-namespaces="no">
392                        <!-- Copy all children of airThroughputProfile -->
393                        <xsl:copy-of select="@*|node()" />
394                </xsl:copy>             
395        </xsl:template>
396
397        <xsl:template match="templates">
398                <xsl:copy copy-namespaces="no">
399                        <xsl:apply-templates/> 
400                </xsl:copy>
401               
402        </xsl:template>
403       
404        <xsl:template match="@*|node()">
405                <xsl:copy>
406                        <xsl:apply-templates select="@*" />
407                        <xsl:apply-templates />
408                </xsl:copy>
409        </xsl:template>
410
411</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.