source: DCWoRMS/branches/coolemall/src/test/DEBBTranslator/xml/DCWoRMSDEBBUpdater.xsl @ 955

Revision 955, 10.6 KB checked in by gosiaw, 12 years ago (diff)

Bug connected with adding information about energy estimation plugins corrected.

  • 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: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                        <!-- resourceUnit -->
146                        <xsl:apply-templates select="resourceUnit" />
147                        <!-- parameter -->
148                        <xsl:apply-templates select="parameter" />
149                       
150                        <xsl:variable name="debbFullPath" select="fun:getFullPath(.)"/>
151                        <xsl:if test="$debbFullPath != ''">
152                                <xsl:element name="parameter">
153                                        <xsl:attribute name="name">fullPath</xsl:attribute>
154                                        <xsl:element name="value">
155                                                <xsl:value-of select="$debbFullPath" />
156                                        </xsl:element>
157                                </xsl:element>
158                        </xsl:if>                               
159                       
160                       
161                        <xsl:variable name="resourceClass" select="@class"/>
162                        <xsl:variable name="resourceType" select="@type"/>
163                        <xsl:variable name="resourceName" select="@name"/>
164                       
165                        <xsl:if test="not(templateId)">
166                                <!-- Don't add energyEstimationPlugin information if there is a template defined for the computingResource.
167                                 It will appear in the template. -->
168                                <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/>
169                                <xsl:variable name="hasProfile" select="profile != ''"/>
170                                <xsl:variable name="hasPowerProfile" select="profile/powerProfile != ''"/>
171       
172                                <xsl:if test="$hasProfile = false() and $estimationPluginName != ''">
173                                        <xsl:element name="profile">
174                                                <xsl:element name="powerProfile">
175                                                        <xsl:element name="energyEstimationPlugin">
176                                                                <xsl:element name="name">
177                                                                        <xsl:value-of select="$estimationPluginName"/>
178                                                                </xsl:element>
179                                                        </xsl:element>
180                                                </xsl:element>
181                                        </xsl:element>
182                                </xsl:if>
183                        </xsl:if>
184                       
185                       
186                        <!-- profile -->
187                        <xsl:apply-templates select="profile" />
188                        <!-- location -->
189                        <xsl:apply-templates select="location" />
190                       
191                        <!-- computingResource -->
192                        <xsl:apply-templates select="computingResource" />
193                       
194                        <!-- templateId -->
195                        <xsl:apply-templates select="templateId" />
196                       
197                </xsl:copy>
198        </xsl:template>
199
200        <xsl:function name="fun:getEnergyEstimator">
201                <xsl:param name="computingResourceClass"/>
202                <xsl:param name="computingResourceType"/>
203                <xsl:param name="computingResourceName"/>
204               
205                <xsl:variable name="estimatorName" select="$nestedDoc//energyEstimationPlugin[(resources/class=$computingResourceClass and resources/type=$computingResourceType and resources/name=$computingResourceName) or
206                (resources/class=$computingResourceClass and resources/type=$computingResourceType) or
207                (resources/class=$computingResourceClass and resources/name=$computingResourceName) or
208                resources/class=$computingResourceClass]/name"/>
209
210                <xsl:value-of select="$estimatorName"/>
211        </xsl:function>
212       
213        <xsl:template match="computingResource" mode="addManagedResorceName">
214                <xsl:element name="resourceName">
215                        <!-- <xsl:value-of select="../@name"></xsl:value-of> -->
216                        <xsl:value-of select="@name"></xsl:value-of>
217                </xsl:element>
218        </xsl:template>
219
220        <xsl:template match="computingResource" mode="addEnergyEstimationPlugin">
221                <xsl:element name="energyEstimationPlugin">
222                        <xsl:value-of select="name"></xsl:value-of>
223                </xsl:element>
224        </xsl:template>
225       
226        <xsl:function name="fun:getFullPath">
227                <xsl:param name="currentComputingResource"/>
228                <xsl:variable name="ancestors" select="$currentComputingResource/ancestor::computingResource/@name"/>
229
230               
231                <xsl:variable name="fullPath">
232                        <xsl:text>/</xsl:text>
233                        <xsl:for-each select="1 to count($ancestors)">
234                                <xsl:variable name="index" select="." />
235                                <xsl:value-of select="$ancestors[$index]"/>
236                                <xsl:text>/</xsl:text>
237                        </xsl:for-each>
238                        <xsl:value-of select="$currentComputingResource/@name"></xsl:value-of> 
239                </xsl:variable>
240               
241                <xsl:value-of select="$fullPath"/>
242        </xsl:function>
243       
244        <xsl:template match="resourceUnit | parameter | location">
245                <xsl:copy-of select="." copy-namespaces="no" />
246        </xsl:template>
247
248        <xsl:template match="profile">
249                <xsl:copy copy-namespaces="no">
250                        <xsl:copy-of select="@*" />
251                       
252                        <xsl:apply-templates select="powerProfile" />
253                </xsl:copy>
254        </xsl:template>
255
256        <xsl:template match="powerProfile">
257                <xsl:copy copy-namespaces="no">
258                        <xsl:variable name="resourceClass" select="../../@class"></xsl:variable>
259                        <xsl:variable name="resourceType" select="../../@type"></xsl:variable>
260                        <xsl:variable name="resourceNames" select="../../@name"></xsl:variable>
261
262                        <xsl:choose>
263                                <!-- Resource names are present -->
264                                <xsl:when test="count($resourceNames) > 0">
265                                        <xsl:for-each select="$resourceNames">
266                                                <xsl:variable name="index" select="position()" />
267                                                <xsl:variable name="resourceName" select="." />
268                                                <xsl:choose>
269                                                        <!-- Resource type is present -->
270                                                        <xsl:when test="$resourceType != ''">
271                                                                <xsl:apply-templates
272                                                                        select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType and resources/name=$resourceName]" />
273                                                        </xsl:when>
274                                                        <xsl:otherwise>
275                                                                <xsl:apply-templates
276                                                                        select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/name=$resourceName]" />
277                                                        </xsl:otherwise>
278                                                </xsl:choose>
279                                        </xsl:for-each>
280                                </xsl:when>
281                                <!-- No resource names -->
282                                <xsl:otherwise>
283                                        <xsl:choose>
284                                                <!-- Resource type is present -->
285                                                <xsl:when test="$resourceType != ''">
286                                                        <xsl:apply-templates
287                                                                select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType]" />
288                                                </xsl:when>
289                                                <xsl:otherwise>
290                                                        <xsl:apply-templates
291                                                                select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass]" />
292                                                </xsl:otherwise>
293                                        </xsl:choose>
294                                </xsl:otherwise>
295                        </xsl:choose>
296                       
297                        <!-- Copy all children of powerProfile -->
298                        <xsl:copy-of select="@*|node()" />
299                </xsl:copy>
300
301        </xsl:template>
302
303        <xsl:template match="templates">
304                <xsl:copy copy-namespaces="no">
305                        <xsl:apply-templates/> 
306                </xsl:copy>
307               
308        </xsl:template>
309       
310        <xsl:template match="@*|node()">
311                <xsl:copy>
312                        <xsl:apply-templates select="@*" />
313                        <xsl:apply-templates />
314                </xsl:copy>
315        </xsl:template>
316
317</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.