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

Revision 1302, 16.4 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                                <xsl:with-param name="parResourceClass" select="$resourceClass" />             
186                        </xsl:apply-templates>
187                                               
188                        <!-- resourceUnit -->
189                        <xsl:apply-templates select="resourceUnit" />
190                       
191                        <!-- computingResource -->
192                        <xsl:apply-templates select="computingResource" />
193                                               
194                </xsl:copy>
195        </xsl:template>
196       
197       
198        <xsl:template match="device">
199                <xsl:param name="parResourceClass"/>
200                <xsl:copy copy-namespaces="no">
201                        <xsl:copy-of select="@*" />
202                        <!-- Find nested elements in appropriate order and copy them -->
203                       
204                        <!-- templateId -->
205                        <xsl:apply-templates select="templateId" />
206                       
207                        <!-- location -->
208                        <xsl:apply-templates select="location" />
209                        <!-- parameter -->
210                        <xsl:apply-templates select="parameter" />
211                                               
212                                                               
213                        <xsl:variable name="debbFullPath" select="fun:getFullPath(.)"/>
214                               
215                       
216                        <xsl:if test="$debbFullPath != '' and name(.) = 'device' and @name">
217                                <!-- fullPath parameter should be added only for computingResource nodes; for computingResourceTemplate it is not needed;
218                                for computingResource nodes embedded in computingResourceTemplate nodes fullPath is not needed either -->
219                                <xsl:element name="parameter">
220                                        <xsl:attribute name="name">fullPath</xsl:attribute>
221                                        <xsl:element name="value">
222                                                <xsl:value-of select="$debbFullPath" />
223                                        </xsl:element>
224                                </xsl:element>
225                        </xsl:if>       
226                       
227                        <xsl:variable name="resourceClass" select="@class"/>
228                        <!--
229                        <xsl:variable name="resourceType" select="@type"/>                     
230                         -->
231                        <xsl:variable name="resourceType">
232                                <xsl:value-of select="concat($parResourceClass, $resourceClass)" />
233                        </xsl:variable>
234                        <xsl:variable name="resourceName" select="@name"/>
235                       
236                        <xsl:if test="not(templateId)">
237                                <!-- Don't add energyEstimationPlugin information if there is a template defined for the computingResource.
238                                 It will appear in the template. -->
239                                <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/>
240                                <xsl:variable name="hasProfile" select="profile != ''"/>
241       
242                                <xsl:if test="$hasProfile = false() and $estimationPluginName != ''">
243                                        <xsl:element name="profile">
244                                                <xsl:element name="powerProfile">
245                                                        <xsl:element name="energyEstimationPlugin">
246                                                                <xsl:element name="name">
247                                                                        <xsl:value-of select="$estimationPluginName"/>
248                                                                </xsl:element>
249                                                        </xsl:element>
250                                                </xsl:element>
251                                        </xsl:element>
252                                </xsl:if>
253                        </xsl:if>
254                       
255                        <!-- profile -->
256                        <xsl:apply-templates select="profile" mode="device">
257                                <xsl:with-param name="parResourceClass" select="$parResourceClass" />   
258                        </xsl:apply-templates>
259                                               
260                </xsl:copy>
261        </xsl:template>
262       
263
264        <xsl:function name="fun:getEnergyEstimator">
265                <xsl:param name="resourceClass"/>
266                <xsl:param name="resourceType"/>
267                <xsl:param name="resourceName"/>
268               
269   
270                <xsl:variable name="estimatorName" >
271                        <xsl:choose>
272                                <xsl:when test="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resource/type=$resourceType and resources/name=$resourceName]/name !=''">
273                                        <xsl:value-of select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resource/type=$resourceType and resources/name=$resourceName]/name"/>
274                                </xsl:when>
275                                <xsl:when test="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType]/name !=''">
276                                        <xsl:value-of select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType]/name"/>
277                                </xsl:when>
278                                <xsl:when test="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/name=$resourceName]/name !=''">
279                                        <xsl:value-of select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/name=$resourceName]/name"/>
280                                </xsl:when>
281                                <xsl:when test="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass]/name !=''">
282                                        <xsl:value-of  select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass ]/name"/>
283                                </xsl:when>
284                                <xsl:otherwise>
285                                </xsl:otherwise>
286                        </xsl:choose>
287                </xsl:variable>
288                <xsl:value-of select="$estimatorName"/>
289        </xsl:function>
290       
291        <xsl:template match="computingResource" mode="addManagedResorceName">
292                <xsl:variable name="debbFullPath" select="fun:getFullPath(.)"/>
293                <xsl:choose>
294                        <xsl:when test="$debbFullPath != '' and @name">
295                                <xsl:element name="resourceName">
296                                        <xsl:value-of select="$debbFullPath"></xsl:value-of>
297                                </xsl:element>
298                        </xsl:when>
299                        <xsl:otherwise>
300                                <xsl:element name="resourceName">
301                                        <xsl:value-of select="@name"></xsl:value-of>
302                                </xsl:element>
303                        </xsl:otherwise>
304                </xsl:choose>
305        </xsl:template>
306       
307        <xsl:function name="fun:getFullPath">
308                <xsl:param name="currentComputingResource"/>
309                <xsl:variable name="ancestors" select="$currentComputingResource/ancestor::computingResource/@name"/>
310
311               
312                <xsl:variable name="fullPath">
313                        <xsl:for-each select="1 to count($ancestors)">
314                                <xsl:variable name="index" select="." />
315                                <xsl:value-of select="$ancestors[$index]"/>
316                                <xsl:text>/</xsl:text>
317                        </xsl:for-each>
318                        <xsl:value-of select="$currentComputingResource/@name"></xsl:value-of> 
319                </xsl:variable>
320               
321                <xsl:value-of select="$fullPath"/>
322        </xsl:function>
323       
324        <xsl:template match="resourceUnit | parameter | location">
325                <xsl:copy-of select="." copy-namespaces="no" />
326        </xsl:template>
327
328        <xsl:template match="profile">
329                <xsl:copy copy-namespaces="no">
330                        <xsl:copy-of select="@*" />
331                       
332                       
333                        <xsl:variable name="resourceClass" select="../@class"/>
334                        <xsl:variable name="resourceType" select="../@type"/>
335                        <xsl:variable name="resourceName" select="../@name"/>
336                       
337
338                        <!-- Don't add energyEstimationPlugin information if there is a template defined for the computingResource.
339                         It will appear in the template. -->
340                        <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/>
341                        <xsl:variable name="hasPowerProfile" select="powerProfile != ''"/>
342
343                        <xsl:if test="$hasPowerProfile = false() and $estimationPluginName != ''">
344                                        <xsl:element name="powerProfile">
345                                                <xsl:element name="energyEstimationPlugin">
346                                                        <xsl:element name="name">
347                                                                <xsl:value-of select="$estimationPluginName"/>
348                                                        </xsl:element>
349                                                </xsl:element>
350                                        </xsl:element>
351                        </xsl:if>
352                       
353                        <xsl:apply-templates select="powerProfile" />
354                        <xsl:apply-templates select="airThroughputProfile" />
355
356                </xsl:copy>
357        </xsl:template>
358
359        <xsl:template match="profile" mode="device">
360                <xsl:param name="parResourceClass"/>
361                <xsl:copy copy-namespaces="no">
362                        <xsl:copy-of select="@*" />
363                       
364                       
365                        <xsl:variable name="resourceClass" select="../@class"/>
366                        <!--
367                        <xsl:variable name="resourceType" select="@type"/>                     
368                         -->
369                        <xsl:variable name="resourceType">
370                                <xsl:value-of select="concat($parResourceClass, $resourceClass)" />
371                        </xsl:variable>
372                        <xsl:variable name="resourceName" select="../@name"/>
373                       
374
375                        <!-- Don't add energyEstimationPlugin information if there is a template defined for the computingResource.
376                         It will appear in the template. -->
377                        <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/>
378                        <xsl:variable name="hasPowerProfile" select="powerProfile != ''"/>
379
380                        <xsl:if test="$hasPowerProfile = false() and $estimationPluginName != ''">
381                                        <xsl:element name="powerProfile">
382                                                <xsl:element name="energyEstimationPlugin">
383                                                        <xsl:element name="name">
384                                                                <xsl:value-of select="$estimationPluginName"/>
385                                                        </xsl:element>
386                                                </xsl:element>
387                                        </xsl:element>
388                        </xsl:if>
389                       
390                        <xsl:apply-templates select="powerProfile" />
391                        <xsl:apply-templates select="airThroughputProfile" />
392
393                </xsl:copy>
394        </xsl:template>
395       
396        <xsl:template match="powerProfile">
397                <xsl:copy copy-namespaces="no">
398                        <xsl:variable name="resourceClass" select="../../@class"></xsl:variable>
399                        <xsl:variable name="resourceType" select="../../@type"></xsl:variable>
400                        <xsl:variable name="resourceNames" select="../../@name"></xsl:variable>
401
402                        <xsl:choose>
403                                <!-- Resource names are present -->
404                                <xsl:when test="count($resourceNames) > 0">
405                                        <xsl:for-each select="$resourceNames">
406                                                <xsl:variable name="index" select="position()" />
407                                                <xsl:variable name="resourceName" select="." />
408                                                <xsl:choose>
409                                                        <!-- Resource type is present -->
410                                                        <xsl:when test="$resourceType != ''">
411                                                                <xsl:apply-templates
412                                                                        select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType and resources/name=$resourceName]" />
413                                                        </xsl:when>
414                                                        <xsl:otherwise>
415                                                                <xsl:apply-templates
416                                                                        select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/name=$resourceName]" />
417                                                        </xsl:otherwise>
418                                                </xsl:choose>
419                                        </xsl:for-each>
420                                </xsl:when>
421                                <!-- No resource names -->
422                                <xsl:otherwise>
423                                        <xsl:choose>
424                                                <!-- Resource type is present -->
425                                                <xsl:when test="$resourceType != ''">
426                                                        <xsl:apply-templates
427                                                                select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType]" />
428                                                </xsl:when>
429                                                <xsl:otherwise>
430                                                        <xsl:apply-templates
431                                                                select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass]" />
432                                                </xsl:otherwise>
433                                        </xsl:choose>
434                                </xsl:otherwise>
435                        </xsl:choose>
436                       
437                        <!-- Copy all children of powerProfile -->
438                        <xsl:copy-of select="@*|node()" />
439                </xsl:copy>
440
441        </xsl:template>
442
443        <xsl:template match="airThroughputProfile">
444                <xsl:copy copy-namespaces="no">
445                        <!-- Copy all children of airThroughputProfile -->
446                        <xsl:copy-of select="@*|node()" />
447                </xsl:copy>             
448        </xsl:template>
449
450        <xsl:template match="templates">
451                <xsl:copy copy-namespaces="no">
452                        <xsl:apply-templates/> 
453                </xsl:copy>
454               
455        </xsl:template>
456       
457        <xsl:template match="@*|node()">
458                <xsl:copy>
459                        <xsl:apply-templates select="@*" />
460                        <xsl:apply-templates />
461                </xsl:copy>
462        </xsl:template>
463
464</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.