Changeset 918 for DCWoRMS


Ignore:
Timestamp:
03/05/13 10:18:55 (12 years ago)
Author:
gosiaw
Message:

Handling energy estimation plugins changed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DCWoRMS/trunk/src/test/DEBBTranslator/xml/DCWoRMSDEBBUpdater.xsl

    r892 r918  
    22<xsl:stylesheet version="2.0" 
    33        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dcworms="DCWormsResSchema.xsd" 
    4         xmlns:debb2dcworms="../../debb2dcworms.xsd"> 
     4        xmlns:debb2dcworms="../../debb2dcworms.xsd" 
     5        xmlns:fun="http://whatever"> 
    56 
    67        <!-- Specification of the output document --> 
     
    146147        </xsl:template> 
    147148 
     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 
    148208        <xsl:template match="computingResource"> 
    149209                <xsl:copy copy-namespaces="no"> 
     
    154214                        <!-- parameter --> 
    155215                        <xsl:apply-templates select="parameter" /> 
     216                         
     217                        <xsl:variable name="resourceClass" select="@class"/> 
     218                        <xsl:variable name="resourceType" select="@type"/> 
     219                        <xsl:variable name="resourceName" select="@name"/> 
     220                         
     221                        <xsl:variable name="estimationPluginName" select="fun:getEnergyEstimator($resourceClass, $resourceType, $resourceName)"/> 
     222                        <xsl:variable name="hasProfile" select="profile != ''"/> 
     223                        <xsl:variable name="hasPowerProfile" select="profile/powerProfile != ''"/> 
     224 
     225                        <xsl:if test="$hasProfile = false() and $estimationPluginName != ''"> 
     226                                <xsl:element name="profile"> 
     227                                        <xsl:element name="powerProfile"> 
     228                                                <xsl:element name="energyEstimationPlugin"> 
     229                                                        <xsl:element name="name"> 
     230                                                                <xsl:value-of select="$estimationPluginName"/> 
     231                                                        </xsl:element> 
     232                                                </xsl:element> 
     233                                        </xsl:element> 
     234                                </xsl:element> 
     235                        </xsl:if> 
     236                         
    156237                        <!-- profile --> 
    157238                        <xsl:apply-templates select="profile" /> 
     
    163244        </xsl:template> 
    164245 
     246        <xsl:function name="fun:getEnergyEstimator"> 
     247                <xsl:param name="computingResourceClass"/> 
     248                <xsl:param name="computingResourceType"/> 
     249                <xsl:param name="computingResourceName"/> 
     250                 
     251                <xsl:variable name="estimatorName" select="$nestedDoc//energyEstimationPlugin[(resources/class=$computingResourceClass and resources/type=$computingResourceType and resources/name=$computingResourceName) or 
     252                (resources/class=$computingResourceClass and resources/type=$computingResourceType) or 
     253                (resources/class=$computingResourceClass and resources/name=$computingResourceName) or 
     254                resources/class=$computingResourceClass]/name"/> 
     255 
     256                <xsl:value-of select="$estimatorName"/> 
     257        </xsl:function> 
     258         
    165259        <xsl:template match="computingResource" mode="addResorceName"> 
    166260                <xsl:element name="resourceName"> 
     
    169263                </xsl:element> 
    170264        </xsl:template> 
     265 
     266        <xsl:template match="computingResource" mode="addEnergyEstimationPlugin"> 
     267                <xsl:element name="energyEstimationPlugin"> 
     268                        <xsl:value-of select="name"></xsl:value-of> 
     269                </xsl:element> 
     270        </xsl:template> 
    171271         
    172272        <xsl:template match="resourceUnit | parameter | location"> 
     
    177277                <xsl:copy copy-namespaces="no"> 
    178278                        <xsl:copy-of select="@*" /> 
     279                         
    179280                        <xsl:apply-templates select="powerProfile" /> 
    180281                </xsl:copy> 
     
    221322                                </xsl:otherwise> 
    222323                        </xsl:choose> 
     324                         
    223325                        <!-- Copy all children of powerProfile --> 
    224326                        <xsl:copy-of select="@*|node()" /> 
Note: See TracChangeset for help on using the changeset viewer.