<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.1"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:fo="http://http://www.w3.org/1999/XSL/Format">


<xsl:output method="html"/>
<xsl:variable name="countersVar" select="document( '/cluman/handleDumpCounters' )"/>

<xsl:template name="ChooseBgcolorAttribute">
  <xsl:param name="ServerCounter"/>
  <xsl:param name="TargetRole"/>
  <xsl:param name="Status"/>
  <xsl:attribute name="bgcolor">
    <xsl:choose>
      <xsl:when test="$TargetRole/RoleTrouble[Severity]/Severity = 3">#FF0000</xsl:when>
      <xsl:when test="$TargetRole/RoleTrouble[Severity]/Severity = 2">#FFFF99</xsl:when>
      <xsl:when test="$TargetRole/RoleTrouble[Severity]/Severity = 1">#9999FF</xsl:when>
      <xsl:otherwise>#FFFFFF</xsl:otherwise>
    </xsl:choose>
  </xsl:attribute>
</xsl:template>

<xsl:template name="ExtraCountersHeaders">
  <xsl:param name="ServerCounter"/>
  <xsl:param name="TargetRole"/>
  <xsl:for-each select="$ServerCounter/ServerCounters/*[RoleName = $TargetRole]/*[StatName]">
    <th>
      <font size="1"><xsl:value-of select="StatName"/></font>
    </th>
  </xsl:for-each>
</xsl:template>

<xsl:template name="ExtraCounters">
  <xsl:param name="ServerCounter"/>
  <xsl:param name="TargetRole"/>
  <xsl:for-each select="$ServerCounter/ServerCounters/*[RoleName = $TargetRole/RoleName]/*[StatName]">
    <td>
      <xsl:variable name="test1" select="PrimaryValueType/text()"/>
      <A>
        <xsl:attribute name="HREF">/cluman/handleProcInfo/<xsl:value-of select="$TargetRole/Thaid"/>/<xsl:value-of select="$TargetRole/RoleNumberInThaid"/></xsl:attribute>
      <xsl:value-of select="format-number(*[name() = $test1],'0.#')"/>
      </A>
    </td>
  </xsl:for-each>
</xsl:template>

<xsl:template name="Counters" >
  <xsl:param name="ServerCounter"/>
  <xsl:param name="TargetRole"/>
  <td>
    <xsl:value-of select="number($ServerCounter/ServerCounters/*[RoleName = $TargetRole]/FreeSwap) div 1024"/>
  </td>
  <td>
    <xsl:value-of select="$ServerCounter/ServerCounters/*[RoleName = $TargetRole]/CPUIdle"/>
  </td>
  <td>
    <xsl:value-of select="number($ServerCounter/ServerCounters/*[RoleName = $TargetRole]/ProcessSize) div 1024"/>
  </td>
</xsl:template>

<xsl:template match="/">
    <html>
      <body>
<code>
  <table><tr>
  <td nowrap="1">[ <A HREF="/cluman/">CluMan Home</A> ]</td>
  <td nowrap="1">[ <A HREF="/clumanload/listSectors?sort=5" target="Ihost Load">Ihost Load Page</A> ] </td>
  <td nowrap="1">[ <A HREF="/cluman/aaaaahandleShowHostsByType">Detail Status Page</A> ]</td>
  <td nowrap="1">[ <A HREF="/cluman/handleShowVersions">Software Versions</A> ] </td>
  <td nowrap="1">[ <A HREF="/cluman/handleStartAll?goto=handleShowHostsByType">start</A> / 
<A HREF="/cluman/handleStopAll?goto=handleShowHostsByType">stop</A> All Servers ] </td>
</tr></table>
</code>
<p/>
<pre>Page refreshed at: <xsl:value-of select="ClusterRoles/RequestTime"/></pre>
          <p/>
          <table border="1">
            <tr>
              <th><FONT SIZE="2">Role</FONT></th>
              <th><FONT SIZE="2">Thaid</FONT></th>
              <th><FONT SIZE="2">Status</FONT></th>
              <th><FONT SIZE="2">Crashes</FONT></th>
              <th><FONT SIZE="1">Free Swap(KB)</FONT></th>
              <th><FONT SIZE="1">CPU Idle Percent</FONT></th>
              <th><FONT SIZE="1">Process size (KB)</FONT></th>
              <th><FONT SIZE="1">Trouble</FONT></th>

            </tr>
            <xsl:for-each select="ClusterRoles/RolesByType/Role">
              <xsl:sort select="RoleTrouble/Severity"/>
              <tr>
                <xsl:call-template name="ChooseBgcolorAttribute">
                  <xsl:with-param name="ServerCounter" select="$countersVar"/>
                  <xsl:with-param name="TargetRole" select="."/>
                  <xsl:with-param name="Status"><xsl:value-of select="Status"/></xsl:with-param>
                </xsl:call-template>
                <td>
                  <xsl:attribute name="nowrap">1</xsl:attribute>
                  <A>
                    <xsl:attribute name="NAME">
                      <xsl:value-of select="RoleName"/>
                    </xsl:attribute>
                  </A>
                  <A>
                    <xsl:attribute name="HREF">
                      http://<xsl:value-of select="Ip"/>:<xsl:value-of select="Port"/>
                  </xsl:attribute>
                  <xsl:value-of select="RoleName"/>
                </A>
                <xsl:text> </xsl:text>
                <A>
                  <xsl:attribute name="HREF">
                    /cluman/handleGetLog/<xsl:value-of select="Thaid"/>/<xsl:value-of select="RoleNumberInThaid"/>?logLength=100
                  </xsl:attribute>
                  log
                </A>
              </td>

              <td>
                <xsl:attribute name="nowrap">1</xsl:attribute>
                <A>
                  <xsl:attribute name="HREF">/cluman/handleHostDetail/<xsl:value-of select="Thaid"/>#<xsl:value-of select="RoleName"/></xsl:attribute>
                  <xsl:value-of select="Thaid"/>
                </A>
                <xsl:text> </xsl:text>

                <A>
                  <xsl:attribute name="HREF">telnet://<xsl:value-of select="AdminUserName"></xsl:value-of>@<xsl:value-of select="Ip"></xsl:value-of></xsl:attribute>shell</A>
              </td>
              <td>
                <xsl:attribute name="nowrap">1</xsl:attribute>
                <xsl:value-of select="Status"/> 
                <xsl:for-each select="RoleTrouble[Severity]">
                  <xsl:sort order="descending" select="Severity"/>
                  <!-- <xsl:value-of select="Cause"/> -->
                </xsl:for-each>
                <xsl:text> </xsl:text>
                <A><xsl:attribute name="HREF">/cluman/handleRoleAction/<xsl:value-of select="Thaid"/>/<xsl:value-of select="RoleNumberInThaid"/>?action=<xsl:choose>
                      <xsl:when test="RoleIsWorking">stop</xsl:when>
                      <xsl:otherwise>start</xsl:otherwise>
                    </xsl:choose>&amp;goto=handleShowHostsByType
                  </xsl:attribute><xsl:choose>
                      <xsl:when test="RoleIsWorking">
                        stop
                      </xsl:when>
                      <xsl:otherwise>
                        start
                      </xsl:otherwise>
                    </xsl:choose>
                </A>
              </td>
              <td>
                <xsl:value-of select="NumCrashes"/>
              </td>
              <xsl:call-template name="Counters">
                <xsl:with-param name="ServerCounter" select="$countersVar"/>
                <xsl:with-param name="TargetRole"><xsl:value-of select="RoleName"/></xsl:with-param>
              </xsl:call-template>
              <td>
                <xsl:for-each select="RoleTrouble[Severity]">
                  <xsl:sort order="descending" select="Severity"/>
                  <xsl:value-of select="Cause"/><br/>
                </xsl:for-each>
              </td>
            </tr>
          </xsl:for-each>
        </table>
    </body>
  </html>
  </xsl:template>
  
</xsl:stylesheet>
