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

Revision 962, 10.7 KB checked in by gosiaw, 12 years ago (diff)

Order of elements in computingResource changed (templateId earlier than parameters)

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