validateAll.xsl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. ################################################################################
  4. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. ################################################################################
  18. -->
  19. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  20. xmlns:xs="http://www.w3.org/2001/XMLSchema" xml:space="default"
  21. xmlns:seisint="http://seisint.com" exclude-result-prefixes="seisint">
  22. <xsl:output method="xml" indent="yes"/>
  23. <xsl:variable name="apos">'</xsl:variable>
  24. <xsl:template match="/Environment">
  25. <xsl:apply-templates select="Hardware/Computer"/>
  26. <xsl:apply-templates select="Software/ThorCluster"/>
  27. <xsl:apply-templates select="Software/Topology"/>
  28. <xsl:apply-templates select="Software"/>
  29. </xsl:template>
  30. <xsl:template match="Environment/Software/*">
  31. <xsl:for-each select="descendant-or-self::*[name()='Cluster']">
  32. <xsl:variable select="@name" name="elem"/>
  33. <xsl:if test= "count(preceding-sibling::*[@name=$elem]) = 0 and count(following-sibling::*[@name=$elem]) &gt; 0">
  34. <xsl:variable select="count(following-sibling::*[@name=$elem])+1" name="numOccurrences"/>
  35. <xsl:call-template name="validationMessage">
  36. <xsl:with-param name="msg" select="concat('/Environment/Software/Topology/Cluster[@name=',$elem,']',' occurs ', $numOccurrences, ' times. Max occurrence must be 1.')"/>
  37. </xsl:call-template>
  38. </xsl:if>
  39. </xsl:for-each>
  40. <xsl:variable select="@name" name="elem1"/>
  41. <xsl:if test="(translate($elem1,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-',''))" >
  42. <xsl:call-template name="validationMessage">
  43. <xsl:with-param name="msg" select=" concat('Invalid character[@name=' ,$elem1, ']') "/>
  44. </xsl:call-template>
  45. </xsl:if>
  46. </xsl:template>
  47. <xsl:template match="Computer">
  48. <xsl:variable name="instanceIp" select="@netAddress"/>
  49. <xsl:variable name="hasInstance" select="/Environment/DeployComponents/*/Instance[@netAddress=$instanceIp]"/>
  50. <xsl:choose>
  51. <xsl:when test="$hasInstance">
  52. <xsl:variable name="dafileSrvNode" select="/Environment/DeployComponents/*[name()='DafilesrvProcess']/Instance[@netAddress=$instanceIp]"/>
  53. <xsl:choose>
  54. <xsl:when test="not($dafileSrvNode)">
  55. <xsl:call-template name="validationMessage">
  56. <xsl:with-param name="msg" select="concat('The computer ', $apos, $instanceIp, $apos, ' does not have a DafileSrvProcess Instance!')"/>
  57. </xsl:call-template>
  58. </xsl:when>
  59. </xsl:choose>
  60. </xsl:when>
  61. </xsl:choose>
  62. </xsl:template>
  63. <xsl:template match="ThorCluster">
  64. <xsl:variable name="thorMasterNode" select="./ThorMasterProcess[@computer]"/>
  65. <xsl:choose>
  66. <xsl:when test="$thorMasterNode">
  67. <xsl:if test="string(@localThor) = 'true' and count(./ThorSlaveProcess[@computer!=$thorMasterNode/@computer]) > 0">
  68. <xsl:call-template name="validationMessage">
  69. <xsl:with-param name="msg" select="'Thor attribute localThor cannot be true when the master and slave processes are on different nodes!'"/>
  70. </xsl:call-template>
  71. </xsl:if>
  72. </xsl:when>
  73. </xsl:choose>
  74. </xsl:template>
  75. <xsl:template name="validationMessage">
  76. <xsl:param name="type" select="'error'"/>
  77. <xsl:param name="compType"/>
  78. <xsl:param name="compName"/>
  79. <xsl:param name="msg"/>
  80. <!--ask deployment tool to display this validation error -->
  81. <!--format is like: error:EspProcess:esp1:This is a message.-->
  82. <xsl:variable name="encodedMsg" select="concat($type, ':', $compType, ':', $compName, ':', $msg)"/>
  83. <xsl:choose>
  84. <xsl:when test="function-available('seisint:validationMessage')">
  85. <xsl:variable name="dummy" select="seisint:validationMessage($encodedMsg)"/>
  86. </xsl:when>
  87. <xsl:otherwise>
  88. <xsl:call-template name="message">
  89. <xsl:with-param name="text" select="concat('Validation for ', $compType, ' named ', $compName, ': ', $msg)"/>
  90. </xsl:call-template>
  91. </xsl:otherwise>
  92. </xsl:choose>
  93. </xsl:template>
  94. <xsl:template name="message">
  95. <xsl:param name="text"/>
  96. <xsl:choose>
  97. <xsl:when test="function-available('seisint:message')">
  98. <xsl:variable name="dummy" select="seisint:message($text)"/>
  99. </xsl:when>
  100. <xsl:otherwise>
  101. <xsl:message terminate="no">
  102. <xsl:value-of select="$text"/>
  103. </xsl:message>
  104. </xsl:otherwise>
  105. </xsl:choose>
  106. </xsl:template>
  107. </xsl:stylesheet>