[845] | 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" |
---|
[918] | 4 | xmlns:debb2dcworms="../../debb2dcworms.xsd" |
---|
| 5 | xmlns:fun="http://whatever"> |
---|
[845] | 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="@*" /> |
---|
[876] | 40 | <xsl:apply-templates select="$nestedDoc//timeEstimationPlugin" /> |
---|
[845] | 41 | <xsl:apply-templates select="resources" /> |
---|
| 42 | </xsl:copy> |
---|
| 43 | </xsl:template> |
---|
| 44 | |
---|
| 45 | <xsl:template match="resources"> |
---|
| 46 | <xsl:copy copy-namespaces="no"> |
---|
| 47 | <xsl:apply-templates select="//resources/computingResource" /> |
---|
| 48 | <xsl:element name="scheduler"> |
---|
| 49 | <xsl:attribute name="class">Cluster</xsl:attribute> |
---|
| 50 | <xsl:attribute name="name">cluster</xsl:attribute> |
---|
[890] | 51 | <!-- In first version, for simplicity, we assume we have only one scheduler |
---|
| 52 | and one scheduling plugin. If $additionalInformationFileName contains more |
---|
| 53 | than one, the rest is ignored --> |
---|
[889] | 54 | <xsl:apply-templates select="$nestedDoc//schedulingPlugin[1]" /> |
---|
[845] | 55 | </xsl:element> |
---|
| 56 | </xsl:copy> |
---|
| 57 | </xsl:template> |
---|
[890] | 58 | |
---|
[876] | 59 | <xsl:template match="timeEstimationPlugin"> |
---|
| 60 | <xsl:element name="timeEstimationPlugin"> |
---|
| 61 | <xsl:element name="name"> |
---|
| 62 | <xsl:value-of select="name" /> |
---|
| 63 | </xsl:element> |
---|
| 64 | </xsl:element> |
---|
| 65 | </xsl:template> |
---|
[845] | 66 | |
---|
[890] | 67 | |
---|
[845] | 68 | <xsl:template match="schedulingPlugin"> |
---|
[890] | 69 | <xsl:variable name="pluginName" select="name" /> |
---|
[845] | 70 | <xsl:element name="schedulingPlugin"> |
---|
| 71 | <xsl:element name="name"> |
---|
[890] | 72 | <xsl:value-of select="$pluginName" /> |
---|
[845] | 73 | </xsl:element> |
---|
| 74 | <xsl:if test="frequency != ''"> |
---|
| 75 | <xsl:element name="frequency"> |
---|
[890] | 76 | <xsl:value-of select="frequency" /> |
---|
[845] | 77 | </xsl:element> |
---|
| 78 | </xsl:if> |
---|
| 79 | </xsl:element> |
---|
| 80 | <xsl:element name="managedComputingResources"> |
---|
| 81 | <!-- TODO: This parameter should be taken from somewhere. --> |
---|
| 82 | <xsl:attribute name="include">false</xsl:attribute> |
---|
[890] | 83 | |
---|
| 84 | <!-- Find appropriate resources (identified by class, type and name(s)) |
---|
| 85 | and add their names here --> |
---|
| 86 | <xsl:variable name="resourceClass"> |
---|
| 87 | <xsl:value-of select="resources/class" /> |
---|
| 88 | </xsl:variable> |
---|
| 89 | <!-- <xsl:value-of select="$resourceClass"/> --> |
---|
| 90 | <xsl:variable name="resourceType"> |
---|
| 91 | <xsl:value-of select="resources/type" /> |
---|
| 92 | </xsl:variable> |
---|
| 93 | <!-- <xsl:value-of select="$resourceType"/> --> |
---|
[891] | 94 | |
---|
[890] | 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" /> |
---|
[876] | 99 | |
---|
[847] | 100 | <xsl:choose> |
---|
[890] | 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 | <xsl:choose> |
---|
| 107 | <!-- Resource type is present --> |
---|
| 108 | <xsl:when test="$resourceType != ''"> |
---|
| 109 | <xsl:apply-templates |
---|
| 110 | select="$rootDoc//computingResource[@class=$resourceClass and @type=$resourceType and @name=$resourceName]" |
---|
| 111 | mode="addResorceName" /> |
---|
| 112 | </xsl:when> |
---|
| 113 | <xsl:otherwise> |
---|
| 114 | <xsl:apply-templates |
---|
| 115 | select="$rootDoc//computingResource[@class=$resourceClass and @name=$resourceName]" |
---|
| 116 | mode="addResorceName" /> |
---|
| 117 | </xsl:otherwise> |
---|
| 118 | </xsl:choose> |
---|
| 119 | </xsl:for-each> |
---|
[847] | 120 | </xsl:when> |
---|
[890] | 121 | <!-- No resource names --> |
---|
[847] | 122 | <xsl:otherwise> |
---|
[890] | 123 | <xsl:choose> |
---|
| 124 | <!-- Resource type is present --> |
---|
| 125 | <xsl:when test="$resourceType != ''"> |
---|
| 126 | <xsl:apply-templates |
---|
| 127 | select="$rootDoc//computingResource[@class=$resourceClass and @type=$resourceType]" |
---|
| 128 | mode="addResorceName" /> |
---|
| 129 | </xsl:when> |
---|
| 130 | <xsl:otherwise> |
---|
| 131 | <xsl:apply-templates |
---|
| 132 | select="$rootDoc//computingResource[@class=$resourceClass]" |
---|
| 133 | mode="addResorceName" /> |
---|
| 134 | </xsl:otherwise> |
---|
| 135 | </xsl:choose> |
---|
[847] | 136 | </xsl:otherwise> |
---|
| 137 | </xsl:choose> |
---|
[845] | 138 | </xsl:element> |
---|
| 139 | </xsl:template> |
---|
| 140 | |
---|
[876] | 141 | <xsl:template match="energyEstimationPlugin"> |
---|
[880] | 142 | <xsl:element name="energyEstimationPlugin"> |
---|
| 143 | <xsl:element name="name"> |
---|
| 144 | <xsl:value-of select="name" /> |
---|
| 145 | </xsl:element> |
---|
| 146 | </xsl:element> |
---|
[876] | 147 | </xsl:template> |
---|
[890] | 148 | |
---|
[918] | 149 | <!-- <xsl:template match="energyEstimationPlugin"> |
---|
| 150 | <xsl:variable name="pluginName" select="name" /> |
---|
| 151 | |
---|
| 152 | Find appropriate resources (identified by class, type and name(s)) |
---|
| 153 | and add their names here |
---|
| 154 | <xsl:variable name="resourceClass"> |
---|
| 155 | <xsl:value-of select="resources/class" /> |
---|
| 156 | </xsl:variable> |
---|
| 157 | <xsl:value-of select="$resourceClass"/> |
---|
| 158 | <xsl:variable name="resourceType"> |
---|
| 159 | <xsl:value-of select="resources/type" /> |
---|
| 160 | </xsl:variable> |
---|
| 161 | <xsl:value-of select="$resourceType"/> |
---|
| 162 | |
---|
| 163 | Not clear why it does not work this way :/ |
---|
| 164 | <xsl:variable name="resourceNames"><xsl:value-of select="resources/name"/></xsl:variable> |
---|
| 165 | <xsl:variable name="resourceNames" |
---|
| 166 | select="$nestedDoc//energyEstimationPlugin[name=$pluginName]/resources/name" /> |
---|
| 167 | |
---|
| 168 | <xsl:choose> |
---|
| 169 | Resource names are present |
---|
| 170 | <xsl:when test="count($resourceNames) > 0"> |
---|
| 171 | <xsl:for-each select="$resourceNames"> |
---|
| 172 | <xsl:variable name="index" select="position()" /> |
---|
| 173 | <xsl:variable name="resourceName" select="." /> |
---|
| 174 | <xsl:choose> |
---|
| 175 | Resource type is present |
---|
| 176 | <xsl:when test="$resourceType != ''"> |
---|
| 177 | <xsl:apply-templates |
---|
| 178 | select="$rootDoc//computingResource[@class=$resourceClass and @type=$resourceType and @name=$resourceName]" |
---|
| 179 | mode="addEnergyEstimationPlugin" /> |
---|
| 180 | </xsl:when> |
---|
| 181 | <xsl:otherwise> |
---|
| 182 | <xsl:apply-templates |
---|
| 183 | select="$rootDoc//computingResource[@class=$resourceClass and @name=$resourceName]" |
---|
| 184 | mode="addEnergyEstimationPlugin" /> |
---|
| 185 | </xsl:otherwise> |
---|
| 186 | </xsl:choose> |
---|
| 187 | </xsl:for-each> |
---|
| 188 | </xsl:when> |
---|
| 189 | No resource names |
---|
| 190 | <xsl:otherwise> |
---|
| 191 | <xsl:choose> |
---|
| 192 | Resource type is present |
---|
| 193 | <xsl:when test="$resourceType != ''"> |
---|
| 194 | <xsl:apply-templates |
---|
| 195 | select="$rootDoc//computingResource[@class=$resourceClass and @type=$resourceType]" |
---|
| 196 | mode="addEnergyEstimationPlugin" /> |
---|
| 197 | </xsl:when> |
---|
| 198 | <xsl:otherwise> |
---|
| 199 | <xsl:apply-templates |
---|
| 200 | select="$rootDoc//computingResource[@class=$resourceClass]" |
---|
| 201 | mode="addEnergyEstimationPlugin" /> |
---|
| 202 | </xsl:otherwise> |
---|
| 203 | </xsl:choose> |
---|
| 204 | </xsl:otherwise> |
---|
| 205 | </xsl:choose> |
---|
| 206 | </xsl:template> --> |
---|
| 207 | |
---|
[845] | 208 | <xsl:template match="computingResource"> |
---|
| 209 | <xsl:copy copy-namespaces="no"> |
---|
| 210 | <xsl:copy-of select="@*" /> |
---|
| 211 | <!-- Find nested elements in appropriate order and copy them --> |
---|
| 212 | <!-- resourceUnit --> |
---|
| 213 | <xsl:apply-templates select="resourceUnit" /> |
---|
| 214 | <!-- parameter --> |
---|
| 215 | <xsl:apply-templates select="parameter" /> |
---|
[918] | 216 | |
---|
[919] | 217 | <xsl:variable name="debbFullPath" select="fun:getFullPath(.)"/> |
---|
| 218 | <xsl:if test="$debbFullPath != ''"> |
---|
| 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 | |
---|
[918] | 228 | <xsl:variable name="resourceClass" select="@class"/> |
---|
| 229 | <xsl:variable name="resourceType" select="@type"/> |
---|
| 230 | <xsl:variable name="resourceName" select="@name"/> |
---|
| 231 | |
---|
| 232 | <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/> |
---|
| 233 | <xsl:variable name="hasProfile" select="profile != ''"/> |
---|
| 234 | <xsl:variable name="hasPowerProfile" select="profile/powerProfile != ''"/> |
---|
| 235 | |
---|
| 236 | <xsl:if test="$hasProfile = false() and $estimationPluginName != ''"> |
---|
| 237 | <xsl:element name="profile"> |
---|
| 238 | <xsl:element name="powerProfile"> |
---|
| 239 | <xsl:element name="energyEstimationPlugin"> |
---|
| 240 | <xsl:element name="name"> |
---|
| 241 | <xsl:value-of select="$estimationPluginName"/> |
---|
| 242 | </xsl:element> |
---|
| 243 | </xsl:element> |
---|
| 244 | </xsl:element> |
---|
| 245 | </xsl:element> |
---|
| 246 | </xsl:if> |
---|
| 247 | |
---|
[845] | 248 | <!-- profile --> |
---|
[890] | 249 | <xsl:apply-templates select="profile" /> |
---|
[845] | 250 | <!-- location --> |
---|
| 251 | <xsl:apply-templates select="location" /> |
---|
| 252 | <!-- computingResource --> |
---|
| 253 | <xsl:apply-templates select="computingResource" /> |
---|
| 254 | </xsl:copy> |
---|
| 255 | </xsl:template> |
---|
| 256 | |
---|
[918] | 257 | <xsl:function name="fun:getEnergyEstimator"> |
---|
| 258 | <xsl:param name="computingResourceClass"/> |
---|
| 259 | <xsl:param name="computingResourceType"/> |
---|
| 260 | <xsl:param name="computingResourceName"/> |
---|
| 261 | |
---|
| 262 | <xsl:variable name="estimatorName" select="$nestedDoc//energyEstimationPlugin[(resources/class=$computingResourceClass and resources/type=$computingResourceType and resources/name=$computingResourceName) or |
---|
| 263 | (resources/class=$computingResourceClass and resources/type=$computingResourceType) or |
---|
| 264 | (resources/class=$computingResourceClass and resources/name=$computingResourceName) or |
---|
| 265 | resources/class=$computingResourceClass]/name"/> |
---|
| 266 | |
---|
| 267 | <xsl:value-of select="$estimatorName"/> |
---|
| 268 | </xsl:function> |
---|
| 269 | |
---|
[846] | 270 | <xsl:template match="computingResource" mode="addResorceName"> |
---|
| 271 | <xsl:element name="resourceName"> |
---|
[890] | 272 | <!-- <xsl:value-of select="../@name"></xsl:value-of> --> |
---|
| 273 | <xsl:value-of select="@name"></xsl:value-of> |
---|
[846] | 274 | </xsl:element> |
---|
[892] | 275 | </xsl:template> |
---|
[918] | 276 | |
---|
| 277 | <xsl:template match="computingResource" mode="addEnergyEstimationPlugin"> |
---|
| 278 | <xsl:element name="energyEstimationPlugin"> |
---|
| 279 | <xsl:value-of select="name"></xsl:value-of> |
---|
| 280 | </xsl:element> |
---|
| 281 | </xsl:template> |
---|
[892] | 282 | |
---|
[919] | 283 | <xsl:function name="fun:getFullPath"> |
---|
| 284 | <xsl:param name="currentComputingResource"/> |
---|
| 285 | <xsl:variable name="ancestors" select="$currentComputingResource/ancestor::computingResource/@name"/> |
---|
| 286 | |
---|
| 287 | <xsl:variable name="fullPath"> |
---|
| 288 | <xsl:text>/</xsl:text> |
---|
| 289 | <xsl:for-each select="1 to count($ancestors)"> |
---|
| 290 | <xsl:variable name="index" select="." /> |
---|
| 291 | <xsl:value-of select="$ancestors[$index]"/> |
---|
| 292 | <xsl:text>/</xsl:text> |
---|
| 293 | </xsl:for-each> |
---|
| 294 | <xsl:value-of select="$currentComputingResource/@name"></xsl:value-of> |
---|
| 295 | </xsl:variable> |
---|
| 296 | |
---|
| 297 | <xsl:value-of select="$fullPath"/> |
---|
| 298 | </xsl:function> |
---|
| 299 | |
---|
[890] | 300 | <xsl:template match="resourceUnit | parameter | location"> |
---|
[845] | 301 | <xsl:copy-of select="." copy-namespaces="no" /> |
---|
| 302 | </xsl:template> |
---|
| 303 | |
---|
[880] | 304 | <xsl:template match="profile"> |
---|
| 305 | <xsl:copy copy-namespaces="no"> |
---|
| 306 | <xsl:copy-of select="@*" /> |
---|
[918] | 307 | |
---|
[880] | 308 | <xsl:apply-templates select="powerProfile" /> |
---|
[890] | 309 | </xsl:copy> |
---|
[880] | 310 | </xsl:template> |
---|
[845] | 311 | |
---|
[890] | 312 | <xsl:template match="powerProfile"> |
---|
[880] | 313 | <xsl:copy copy-namespaces="no"> |
---|
[881] | 314 | <xsl:variable name="resourceClass" select="../../@class"></xsl:variable> |
---|
| 315 | <xsl:variable name="resourceType" select="../../@type"></xsl:variable> |
---|
[891] | 316 | <xsl:variable name="resourceNames" select="../../@name"></xsl:variable> |
---|
[890] | 317 | |
---|
[881] | 318 | <xsl:choose> |
---|
[891] | 319 | <!-- Resource names are present --> |
---|
| 320 | <xsl:when test="count($resourceNames) > 0"> |
---|
| 321 | <xsl:for-each select="$resourceNames"> |
---|
| 322 | <xsl:variable name="index" select="position()" /> |
---|
| 323 | <xsl:variable name="resourceName" select="." /> |
---|
| 324 | <xsl:choose> |
---|
| 325 | <!-- Resource type is present --> |
---|
| 326 | <xsl:when test="$resourceType != ''"> |
---|
| 327 | <xsl:apply-templates |
---|
| 328 | select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType and resources/name=$resourceName]" /> |
---|
| 329 | </xsl:when> |
---|
| 330 | <xsl:otherwise> |
---|
| 331 | <xsl:apply-templates |
---|
| 332 | select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/name=$resourceName]" /> |
---|
| 333 | </xsl:otherwise> |
---|
| 334 | </xsl:choose> |
---|
| 335 | </xsl:for-each> |
---|
[881] | 336 | </xsl:when> |
---|
[891] | 337 | <!-- No resource names --> |
---|
[881] | 338 | <xsl:otherwise> |
---|
[891] | 339 | <xsl:choose> |
---|
| 340 | <!-- Resource type is present --> |
---|
| 341 | <xsl:when test="$resourceType != ''"> |
---|
| 342 | <xsl:apply-templates |
---|
| 343 | select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType]" /> |
---|
| 344 | </xsl:when> |
---|
| 345 | <xsl:otherwise> |
---|
| 346 | <xsl:apply-templates |
---|
| 347 | select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass]" /> |
---|
| 348 | </xsl:otherwise> |
---|
| 349 | </xsl:choose> |
---|
[881] | 350 | </xsl:otherwise> |
---|
[892] | 351 | </xsl:choose> |
---|
[918] | 352 | |
---|
[892] | 353 | <!-- Copy all children of powerProfile --> |
---|
[890] | 354 | <xsl:copy-of select="@*|node()" /> |
---|
| 355 | </xsl:copy> |
---|
[880] | 356 | |
---|
[890] | 357 | </xsl:template> |
---|
| 358 | |
---|
| 359 | <xsl:template match="@*|node()"> |
---|
| 360 | <xsl:copy> |
---|
| 361 | <xsl:apply-templates select="@*" /> |
---|
| 362 | <xsl:apply-templates /> |
---|
| 363 | </xsl:copy> |
---|
| 364 | </xsl:template> |
---|
| 365 | |
---|
[845] | 366 | </xsl:stylesheet> |
---|