Browse Source

HPCC-22741 TopoServer support in init, systemd, environment and configmgr

Signed-off-by: Michael Gardner <michael.gardner@lexisnexisrisk.com>

HPCC-22741 PR changes and read settings file under runtime dir

Signed-off-by: Michael Gardner <michael.gardner@lexisnexisrisk.com>
Michael Gardner 5 years ago
parent
commit
bc7337d94e

+ 3 - 1
initfiles/bash/etc/systemd/system/CMakeLists.txt

@@ -29,7 +29,8 @@ set(componentList
     sasha
     thor
     thorslave
-    backupnode)
+    backupnode
+    toposerver)
 
 set(dafilesrv "dafilesrv" "-L ${LOG_PATH} -I %i -D" "")
 set(dali "daserver" "--daemon %i" "dafilesrv.service")
@@ -43,6 +44,7 @@ set(sasha "saserver" "--daemon %i" "dafilesrv.service")
 set(thor "thormaster_lcr" "--daemon %i MASTER=\${THORMASTER}:\${THORMASTERPORT}" "dafilesrv.service")
 set(thorslave "thorslave_lcr" "--daemon %i master=\${THORMASTER}:\${THORMASTERPORT} slave=.:\${SLAVEPORT} slavenum=\${SLAVENUM} logDir=${LOG_PATH}/\${THORNAME}" "dafilesrv.service")
 set(backupnode "backup.sh" "" "")
+set(toposerver "toposerver" "--daemon %i" "dafilesrv.service")
 
 foreach(component ${componentList})
     list(GET "${component}" 0 processName)

+ 1 - 0
initfiles/bin/CMakeLists.txt

@@ -27,6 +27,7 @@ GENERATE_BASH(processor ${bash-vars} "init_esp.in" outFiles)
 GENERATE_BASH(processor ${bash-vars} "init_roxie.in" outFiles)
 GENERATE_BASH(processor ${bash-vars} "init_sasha.in" outFiles)
 GENERATE_BASH(processor ${bash-vars} "init_thorslave.in" outFiles)
+GENERATE_BASH(processor ${bash-vars} "init_toposerver.in" outFiles)
 ADD_CUSTOM_TARGET(ProcessFiles-initfiles-bin ALL DEPENDS ${outFiles})
 
 configure_file(init_backupnode.in init_backupnode @ONLY)

+ 64 - 0
initfiles/bin/init_toposerver.in

@@ -0,0 +1,64 @@
+#!/bin/bash
+################################################################################
+#    HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+################################################################################
+
+###<REPLACE>###
+
+source ${INSTALL_DIR}/sbin/hpcc_setenv
+PID_NAME="${PID_DIR}/$(basename $PWD).pid"
+source ${INSTALL_DIR}/etc/init.d/hpcc_common
+
+component=$(basename $PWD)
+dir.getByName lock
+lock="$dir_return"
+export logfile="${LOG_DIR}/${component}/init_${component}_$(date +%Y_%m_%d_%H_%M_%S).log"
+
+export SENTINEL="toposerver.sentinel"
+log "Removing $SENTINEL"
+rm -f ${SENTINEL}
+
+SNMPID=$$
+
+killed()
+{
+    kill_process ${PID_NAME} toposerver 15 ${SENTINEL}
+    if [[ $? -eq 1 ]]; then
+        log "could not kill $component"
+    else
+        log "$component Stopped"
+        unlock ${LOCK_DIR}/$component/${component}.lock
+    fi
+    exit 255
+}
+
+trap "killed" SIGINT SIGTERM SIGKILL
+log "Calling toposerver 1>/dev/null 2>/dev/null &"
+toposerver 1>/dev/null 2>/dev/null &
+echo $! > $PID_NAME
+wait
+log "Removing $PID_NAME"
+rm $PID_NAME
+while [[ -e ${SENTINEL} ]]; do
+    sleep 5
+    if [[ -e ${SENTINEL} ]]; then
+        log "Calling toposerver 1>/dev/null 2>/dev/null &"
+        toposerver 1>/dev/null 2>/dev/null &
+        echo $! > $PID_NAME
+        wait
+        log "Removing $PID_NAME"
+        rm $PID_NAME
+    fi
+done

+ 3 - 0
initfiles/componentfiles/configxml/CMakeLists.txt

@@ -28,6 +28,7 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/thor.xsl ${CMAKE_CURRENT_BINARY_DIR}/
 configure_file(environment.xsd.in environment.xsd @ONLY)
 configure_file(cgencomplist_linux.xml.in cgencomplist_linux.xml @ONLY)
 configure_file(cgencomplist_win.xml.in cgencomplist_win.xml @ONLY)
+configure_file(toposerver.xsd.in toposerver.xsd @ONLY)
 
 if("${HPCC_PROJECT_ABBR}" STREQUAL "CC")
     configure_file("buildset${HPCC_PROJECT_ABBR}.xml.in" "buildset.xml")
@@ -104,6 +105,8 @@ FOREACH( iFILES
     ${CMAKE_CURRENT_SOURCE_DIR}/sparkThor.xsd
     ${CMAKE_CURRENT_BINARY_DIR}/sparkThor.xsl
     ${CMAKE_CURRENT_BINARY_DIR}/spark-defaults.xsl
+    ${CMAKE_CURRENT_BINARY_DIR}/toposerver.xsd
+    ${CMAKE_CURRENT_SOURCE_DIR}/toposerver.xsl
 )
     Install ( FILES ${iFILES} DESTINATION componentfiles/configxml COMPONENT Runtime)
 ENDFOREACH ( iFILES )

+ 6 - 1
initfiles/componentfiles/configxml/buildsetCC.xml.in

@@ -48,7 +48,12 @@
                 path="componentfiles/backupnode"
                 processName="BackupNodeProcess"
                 schema="backupnode.xsd"/>
-"            <BuildSet installSet="deploy_map.xml"
+            <BuildSet installSet="deploy_map.xml"
+                name="toposerver"
+                path="componentfiles/toposerver"
+                processName="TopoServerProcess"
+                schema="toposerver.xsd"/>
+            <BuildSet installSet="deploy_map.xml"
                 name="sparkthor"
                 path="componentfiles/sparkthor"
                 processName="SparkThorProcess"

+ 3 - 0
initfiles/componentfiles/configxml/cgencomplist_linux.xml.in

@@ -42,6 +42,9 @@
         <File name="eclccserver.xsl" method="xslt" destName="eclccserver.xml"/>
         <File name="eclcc.xsl" method="xslt" destName="eclcc.ini"/>
     </Component>
+  <Component name="toposerver" processName='TopoServerProcess' schema='toposerver.xsd'>
+    <File name="toposerver.xsl" method="xslt" destName="toposerver.xml"/>
+  </Component>
   <Component name="eclscheduler" processName='EclSchedulerProcess' schema='eclscheduler.xsd'>
     <File name="eclscheduler.xsl" method="xslt" destName="eclscheduler.xml"/>
   </Component>

+ 3 - 0
initfiles/componentfiles/configxml/cgencomplist_win.xml.in

@@ -42,6 +42,9 @@
     <File name="eclccserver.xsl" method="xslt" destName="eclccserver.xml"/>
     <File name="eclcc.xsl" method="xslt" destName="eclcc.ini"/>
   </Component>
+  <Component name="toposerver" processName='TopoServerProcess' schema='toposerver.xsd'>
+    <File name="toposerver.xsl" method="xslt" destName="toposerver.xml"/>
+  </Component>
   <Component name="eclscheduler" processName='EclSchedulerProcess' schema='eclscheduler.xsd'>
     <File name="eclscheduler.xsl" method="xslt" destName="eclscheduler.xml"/>
   </Component>

+ 124 - 0
initfiles/componentfiles/configxml/toposerver.xsd.in

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+################################################################################
+#    HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+################################################################################
+-->
+
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+    <xs:include schemaLocation="environment.xsd"/>
+    <xs:element name="TopoServerProcess">
+        <xs:complexType>
+        <!--DOC-Autobuild-code-->
+	 <xs:annotation>
+	    <xs:appinfo>
+		<docid>topo.server</docid>
+	    </xs:appinfo>
+	 </xs:annotation>  
+            <xs:sequence>
+                <xs:element name="Instance" maxOccurs="unbounded">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <viewType>Instance</viewType>
+                        </xs:appinfo>
+                    </xs:annotation>
+                    <xs:complexType>
+                        <xs:attribute name="computer" type="computerType" use="required">
+                            <xs:annotation>
+                                <xs:appinfo>
+                                    <colIndex>1</colIndex>
+                                </xs:appinfo>
+                            </xs:annotation>
+                        </xs:attribute>
+                        <xs:attribute name="netAddress" type="xs:string" use="optional">
+                            <xs:annotation>
+                                <xs:appinfo>
+                                    <viewType>readonly</viewType>
+                                    <colIndex>2</colIndex>
+                                </xs:appinfo>
+                            </xs:annotation>
+                        </xs:attribute>
+                        <xs:attribute name="directory" type="absolutePath" use="optional" default="c$\toposerver">
+                            <xs:annotation>
+                                <xs:appinfo>
+                                    <viewType>hidden</viewType>
+                                    <colIndex>3</colIndex>
+                                </xs:appinfo>
+                            </xs:annotation>
+                        </xs:attribute>
+                    </xs:complexType>
+                </xs:element>
+            </xs:sequence>
+            <xs:attribute name="build" type="buildType" use="required">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <tooltip>The build name to be deployed</tooltip>
+                        <viewType>hidden</viewType>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="buildSet" type="buildSetType" use="required">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <viewType>hidden</viewType>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="name" type="xs:string" use="optional" default="mytoposerver">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <tooltip>Name for this process</tooltip>
+                        <required>true</required>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="description" type="xs:string" use="optional" default="Topology Server process">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <tooltip>Description for this process</tooltip>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="port" type="xs:nonNegativeInteger" default="9004">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <tooltip>Base port to use for master</tooltip>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="traceLevel" type="xs:nonNegativeInteger" default="1">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <tooltip>Trace level for logging</tooltip>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="stdlog" type="xs:boolean" default="true">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <tooltip>Standard log</tooltip>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="logdir" type="xs:string" default="@LOG_PATH@/mytoposerver">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <tooltip>Default log directory</tooltip>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:attribute>
+        </xs:complexType>
+    </xs:element>
+</xs:schema>

+ 93 - 0
initfiles/componentfiles/configxml/toposerver.xsl

@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+################################################################################
+#    HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+################################################################################
+-->
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ 
+<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
+        
+<xsl:param name="process" select="'toposerver'"/>
+<xsl:param name="instance" select="'s1'"/>
+<xsl:param name="isLinuxInstance" select="0"/>
+<xsl:param name="outputFilePath" select="'toposerver.xml'"/>
+<xsl:param name="tempPath" select="'c:\temp\'"/>
+
+<xsl:variable name="oldPathSeparator">
+    <xsl:choose>
+        <xsl:when test="$isLinuxInstance = 1">\:</xsl:when>
+        <xsl:otherwise>'/$'</xsl:otherwise>
+    </xsl:choose>   
+</xsl:variable>
+
+
+<xsl:variable name="newPathSeparator">
+    <xsl:choose>
+        <xsl:when test="$isLinuxInstance = 1">/$</xsl:when>
+        <xsl:otherwise>'\:'</xsl:otherwise>
+    </xsl:choose>   
+</xsl:variable>
+
+
+<xsl:variable name="newPathSeparatorChar">
+    <xsl:choose>
+        <xsl:when test="$isLinuxInstance = 1">'/'</xsl:when>
+        <xsl:otherwise>'\'</xsl:otherwise>
+    </xsl:choose>   
+</xsl:variable>
+
+
+<xsl:variable name="toposerverNode" select="/Environment/Software/TopoServerProcess[@name=$process]"/>
+<xsl:variable name="instanceNode" select="$toposerverNode/Instance[@name=$instance]"/>
+
+
+<xsl:template match="/">
+   <xsl:if test="not($toposerverNode)">
+      <xsl:message terminate="yes">Topology Server '<xsl:value-of select="$process"/>' is undefined!</xsl:message>
+   </xsl:if>
+   <xsl:if test="not($instanceNode)">
+      <xsl:message terminate="yes">Invalid instance '<xsl:value-of select="$instance"/></xsl:message>
+   </xsl:if>
+   <xsl:apply-templates select="$toposerverNode"/>
+</xsl:template>
+
+
+<xsl:template match="TopoServerProcess">
+   <TopoServerProcess>
+      <xsl:apply-templates select="@*[string(.) != '']"/>
+      <xsl:copy-of select="/Environment/Software/Directories"/>
+   </TopoServerProcess>
+</xsl:template>
+
+
+<!--propagate the attributes that need to be copied verbatim -->
+<xsl:template match="@build|@name">
+   <xsl:copy-of select="."/>
+</xsl:template>
+
+
+<!--eat attributes not needed to be generated or those which would be processed somewhere else -->
+<xsl:template match="@buildSet|@description"/>
+
+<!--propagate any unrecognized attributes to output-->
+<xsl:template match="@*">
+   <xsl:copy-of select="."/>
+</xsl:template>
+
+<xsl:template match="text()"/>
+
+</xsl:stylesheet>

+ 19 - 1
initfiles/etc/DIR_NAME/environment.xml.in

@@ -898,6 +898,19 @@
              name="s1"
              netAddress="."/>
   </EclSchedulerProcess>
+  <TopoServerProcess build="_"
+                     buildSet="toposerver"
+                     description="Topology Server process"
+                     logdir="${LOG_PATH}/mytoposerver"
+                     name="mytoposerver"
+                     port="9004"
+                     stdlog="true"
+                     traceLevel="1">
+   <Instance computer="localhost"
+             directory="${RUNTIME_PATH}/mytoposerver"
+             name="s1"
+             netAddress="."/>
+  </TopoServerProcess>
   @SPARK_ENV_S@
   <SparkThorProcess build="_"
                     buildSet="sparkthor"
@@ -912,7 +925,7 @@
                     SPARK_WORKER_MEMORY="1G"
                     SPARK_WORKER_PORT="7071">
    <Instance computer="localhost"
-             directory="/var/lib/HPCCSystems/mysparkthor"
+             directory="${RUNTIME_PATH}/mysparkthor"
              name="s1"
              netAddress="."/>
    </SparkThorProcess>
@@ -1257,6 +1270,11 @@
                    resource="WsLoggingAccess"/>
     </Properties>
    </BuildSet>
+   <BuildSet installSet="deploy_map.xml"
+             name="toposerver"
+             path="componentfiles/toposerver"
+             processName="TopoServerProcess"
+             schema="toposerver.xsd"/>
    @SPARK_ENV_S@
    <BuildSet installSet="deploy_map.xml"
              name="sparkthor"

+ 44 - 5
roxie/topo/toposerver.cpp

@@ -27,6 +27,8 @@
 #include "jexcept.hpp"
 #include "jlog.hpp"
 #include "jmd5.hpp"
+#include "jfile.hpp"
+#include "jptree.hpp"
 
 /**
  * While billed as a topology server (and used for that by Roxie), this service actually remembers and
@@ -70,6 +72,7 @@ const unsigned timeoutHeartbeatInterval = 10000;
 const unsigned topologyReportInterval = 10000;
 bool aborted = false;
 Semaphore stopping;
+StringBuffer topologyFile;
 
 extern "C" void caughtSIGPIPE(int sig)
 {
@@ -299,13 +302,47 @@ int main(int argc, const char *argv[])
         else
             globals->loadProp(argv[i], true);  // We ignore unrecognized options for now
     }
-    traceLevel = globals->getPropInt("--traceLevel", 1);
-    topoPort = globals->getPropInt("--port", TOPO_SERVER_PORT);
-    if (globals->getPropBool("--stdlog", traceLevel != 0))
+
+    // locate settings xml file in runtime dir
+    char currentDirectory[_MAX_DIR];
+    if (!getcwd(currentDirectory, sizeof(currentDirectory)))
+    {
+        perror("getcwd failure");
+        return EXIT_FAILURE;
+    }
+    topologyFile.set(currentDirectory);
+    addNonEmptyPathSepChar(topologyFile);
+    topologyFile.append(PATHSEPCHAR).append("toposerver.xml");
+    IPropertyTree *topology;
+    if (checkFileExists(topologyFile.str()))
+        topology = createPTreeFromXMLFile(topologyFile.str(), ipt_lowmem);
+    else
+        topology = createPTreeFromXMLString(
+            "<TopoServerProcess port='9004' traceLevel='1'>"
+            "</TopoServerProcess>"
+            , ipt_lowmem
+            );
+    if (globals->hasProp("--traceLevel"))
+        topology->setProp("@traceLevel", globals->queryProp("--traceLevel"));
+    if (globals->hasProp("--port"))
+        topology->setProp("@port", globals->queryProp("--port"));
+    if (globals->hasProp("--stdlog"))
+        topology->setProp("@stdlog", globals->queryProp("--stdlog"));
+    if (globals->hasProp("--logdir"))
+        topology->setProp("@logdir", globals->queryProp("--logdir"));
+
+
+    // take ownership of sentinel file
+    Owned<IFile> sentinelFile = createSentinelTarget();
+    removeSentinelFile(sentinelFile);
+
+    traceLevel = topology->getPropInt("@traceLevel", 1);
+    topoPort = topology->getPropInt("@port", TOPO_SERVER_PORT);
+    if (topology->getPropBool("@stdlog", traceLevel != 0))
         queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_time | MSGFIELD_milliTime | MSGFIELD_thread | MSGFIELD_prefix);
     else
         removeLog();
-    const char *logdir = globals->queryProp("--logdir");
+    const char *logdir = topology->queryProp("@logdir");
     if (logdir)
     {
         Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator(logdir, "toposerver");
@@ -316,10 +353,12 @@ int main(int argc, const char *argv[])
     }
     if (traceLevel)
         DBGLOG("Topology server starting");
-
+    
+    writeSentinelFile(sentinelFile);
     doServer();
     if (traceLevel)
         DBGLOG("Topology server stopping");
+    removeSentinelFile(sentinelFile);
     ExitModuleObjects();
     return 0;
 }