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

Revision 1000, 10.8 KB checked in by gosiaw, 12 years ago (diff)

fullPath parameters are not added for computingResourceTemplate elements

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