Ver código fonte

HPCC-12914 Change esp log settings when ESP is running

By this fix, an admin user may change ESP log settings for a
running ESP through a new ESP service: WSESPControl. For
example, the user may change ESP log level. If the
controlPort is not set in environment.xml, the espcontrol
should be loaded and on port 8010. Turn espcontrol off only
if the admin sets controlPort == 0.

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
wangkx 10 anos atrás
pai
commit
8f961f6239

+ 2 - 0
esp/platform/espp.hpp

@@ -143,6 +143,8 @@ public:
     }
 
     void setLogLevel(LogLevel level) { m_logLevel = level; }
+    void setLogRequests(bool logReq) { m_logReq = logReq; }
+    void setLogResponses(bool logResp) { m_logResp = logResp; }
 
     LogLevel getLogLevel() { return m_logLevel; }
     bool getLogRequests() { return m_logReq; }

+ 2 - 0
esp/scm/esp.ecm

@@ -169,7 +169,9 @@ interface IEspContainer : extends IInterface
     virtual void setLogLevel(LogLevel level) = 0;
     virtual LogLevel getLogLevel() = 0;
     virtual bool getLogRequests() = 0;
+    virtual void setLogRequests(bool logReq) = 0;
     virtual bool getLogResponses() = 0;
+    virtual void setLogResponses(bool logResp) = 0;
     virtual void log(LogLevel level, const char*,...) __attribute__((format(printf, 3, 4))) = 0;
     virtual unsigned getSlowProcessingTime() = 0;
     virtual void setFrameTitle(const char* title) = 0;

+ 1 - 0
esp/scm/espscm.cmake

@@ -42,6 +42,7 @@ set ( ESPSCM_SRCS
       ws_packageprocess.ecm
       ws_esdlconfig.ecm
       ws_loggingservice.ecm
+      ws_espcontrol.ecm
     )
 
 foreach ( loop_var ${ESPSCM_SRCS} )

+ 39 - 0
esp/scm/ws_espcontrol.ecm

@@ -0,0 +1,39 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2015 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.
+############################################################################## */
+
+EspInclude(common);
+
+ESPrequest [nil_remove] SetLoggingRequest
+{
+    int LoggingLevel;
+    bool LogRequests;
+    bool LogResponses;
+};
+
+ESPresponse [exceptions_inline, nil_remove, http_encode(0)] SetLoggingResponse
+{
+    int Status;
+    string Message;
+};
+
+ESPservice [ version("1.00"), default_client_version("1.00"), exceptions_inline("./smc_xslt/exceptions.xslt")] WSESPControl
+{
+    ESPmethod SetLogging(SetLoggingRequest, SetLoggingResponse);
+};
+
+SCMexportdef(WSESPControl);
+SCMapi(WSESPControl) IClientWSESPControl *createWSESPControlClient();

+ 1 - 0
esp/services/CMakeLists.txt

@@ -32,3 +32,4 @@ HPCC_ADD_SUBDIRECTORY (WsDeploy "PLATFORM")
 HPCC_ADD_SUBDIRECTORY (ws_packageprocess "PLATFORM")
 HPCC_ADD_SUBDIRECTORY (ws_esdlconfig "PLATFORM")
 HPCC_ADD_SUBDIRECTORY (esdl_svc_engine "PLATFORM")
+HPCC_ADD_SUBDIRECTORY (espcontrol "PLATFORM")

+ 59 - 0
esp/services/espcontrol/CMakeLists.txt

@@ -0,0 +1,59 @@
+################################################################################
+#    HPCC SYSTEMS software Copyright (C) 2015 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.
+################################################################################
+
+
+# Component: ws_espcontrol
+#####################################################
+# Description:
+# ------------
+#    Cmake Input File for ws_espcontrol
+#####################################################
+
+project( ws_espcontrol )
+
+include(${HPCC_SOURCE_DIR}/esp/scm/espscm.cmake)
+
+set (    SRCS
+         ${ESPSCM_GENERATED_DIR}/ws_espcontrol_esp.cpp
+         ws_espcontrolplugin.cpp
+         ws_espcontrolservice.cpp
+    )
+
+include_directories (
+         ./../..
+         ./../../platform
+         ./../../../system/include
+         ./../../../system/jlib
+         ./../../../system/xmllib
+         ./../../../system/security/securesocket
+         ./../../../system/security/LdapSecurity
+         ./../../../system/security/shared
+         ./../../clients
+         ./../../bindings
+         ./../../bindings/SOAP/xpp
+         ./../../smc/SMCLib
+    )
+
+ADD_DEFINITIONS( -D_USRDLL )
+
+HPCC_ADD_LIBRARY( ws_espcontrol SHARED ${SRCS} )
+install ( TARGETS ws_espcontrol DESTINATION ${OSSDIR}/lib )
+target_link_libraries ( ws_espcontrol
+         jlib
+         xmllib
+         esphttp
+         securesocket
+    )

+ 78 - 0
esp/services/espcontrol/ws_espcontrolplugin.cpp

@@ -0,0 +1,78 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2015 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.
+############################################################################## */
+
+#pragma warning (disable : 4786)
+
+//ESP Bindings
+#include "http/platform/httpprot.hpp"
+
+//ESP Service
+#include "ws_espcontrolservice.hpp"
+
+#include "espplugin.hpp"
+
+extern "C"
+{
+
+//when we aren't loading dynamically
+// Change the function names when we stick with dynamic loading.
+ESP_FACTORY IEspService * esp_service_factory(const char *name, const char* type, IPropertyTree *cfg, const char *process)
+{
+    if (strcmp(type, "WSESPControl")==0)
+    {
+        CWSESPControlEx* service = new CWSESPControlEx;
+        service->init(cfg, process, name);
+        return service;
+    }
+    return NULL;
+}
+
+
+
+ESP_FACTORY IEspRpcBinding * esp_binding_factory(const char *name, const char* type, IPropertyTree *cfg, const char *process)
+{
+    if (strcmp(type, "ws_espcontrolSoapBinding")==0)
+    {
+        CWSESPControlSoapBinding* binding = new CWSESPControlSoapBinding(cfg, name, process);
+        return binding;
+    }
+
+    return NULL;
+}
+
+
+
+ESP_FACTORY IEspProtocol * esp_protocol_factory(const char *name, const char* type, IPropertyTree *cfg, const char *process)
+{
+    if (strcmp(type, "http_protocol")==0)
+    {
+        return new CHttpProtocol;
+    }
+    else if(strcmp(type, "secure_http_protocol") == 0)
+    {
+        IPropertyTree *sslSettings;
+        sslSettings = cfg->getPropTree(StringBuffer("Software/EspProcess[@name=\"").append(process).append("\"]").append("/EspProtocol[@name=\"").append(name).append("\"]").str());
+        if(sslSettings != NULL)
+        {
+            return new CSecureHttpProtocol(sslSettings);
+        }
+    }
+
+    return NULL;
+}
+
+};

+ 53 - 0
esp/services/espcontrol/ws_espcontrolservice.cpp

@@ -0,0 +1,53 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2015 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.
+############################################################################## */
+
+#ifdef _USE_OPENLDAP
+#include "ldapsecurity.ipp"
+#endif
+
+#include "ws_espcontrolservice.hpp"
+#include "jlib.hpp"
+#include "exception_util.hpp"
+
+bool CWSESPControlEx::onSetLogging(IEspContext& context, IEspSetLoggingRequest& req, IEspSetLoggingResponse& resp)
+{
+    try
+    {
+#ifdef _USE_OPENLDAP
+        CLdapSecManager* secmgr = dynamic_cast<CLdapSecManager*>(context.querySecManager());
+        if(secmgr && !secmgr->isSuperUser(context.queryUser()))
+            throw MakeStringException(ECLWATCH_SUPER_USER_ACCESS_DENIED, "Failed to change log settings. Permission denied.");
+#endif
+
+        if (!m_container)
+            throw MakeStringException(ECLWATCH_INTERNAL_ERROR, "Failed to access container.");
+
+        if (!req.getLoggingLevel_isNull())
+            m_container->setLogLevel(req.getLoggingLevel());
+        if (!req.getLogRequests_isNull())
+            m_container->setLogRequests(req.getLogRequests());
+        if (!req.getLogResponses_isNull())
+            m_container->setLogResponses(req.getLogResponses());
+        resp.setStatus(0);
+        resp.setMessage("Logging settings are updated.");
+    }
+    catch(IException* e)
+    {
+        FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR);
+    }
+    return true;
+}

+ 37 - 0
esp/services/espcontrol/ws_espcontrolservice.hpp

@@ -0,0 +1,37 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2015 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.
+############################################################################## */
+
+#ifndef _ESPWIZ_ws_espcontrol_HPP__
+#define _ESPWIZ_ws_espcontrol_HPP__
+
+#include "ws_espcontrol_esp.ipp"
+
+class CWSESPControlEx : public CWSESPControl
+{
+    IEspContainer* m_container;
+public:
+    IMPLEMENT_IINTERFACE;
+
+    virtual void setContainer(IEspContainer * container)
+    {
+        m_container = container;
+    }
+
+    virtual bool onSetLogging(IEspContext &context, IEspSetLoggingRequest &req, IEspSetLoggingResponse &resp);
+};
+
+#endif //_ESPWIZ_ws_espcontrol_HPP__

+ 7 - 0
initfiles/componentfiles/configxml/esp.xsd.in

@@ -707,6 +707,13 @@
                 </xs:appinfo>
               </xs:annotation>
             </xs:attribute>
+            <xs:attribute name="controlPort" type="xs:nonNegativeInteger" use="optional" default="8010">
+                <xs:annotation>
+                    <xs:appinfo>
+                        <tooltip>Sets the network port for ESP control</tooltip>
+                    </xs:appinfo>
+                </xs:annotation>
+            </xs:attribute>
             <xs:attribute name="logLevel" type="xs:nonNegativeInteger" use="optional" default="1">
                 <xs:annotation>
                     <xs:appinfo>

+ 22 - 16
initfiles/componentfiles/configxml/esp.xsl

@@ -45,10 +45,16 @@
         <xsl:otherwise>\:</xsl:otherwise>
     </xsl:choose>   
    </xsl:variable>
-   
+
     <xsl:variable name="espProcess" select="/Environment/Software/EspProcess[@name=$process]"/>
-    
-    
+    <xsl:variable name="controlPortSetting" select="/Environment/Software/EspProcess[@name=$process]/@controlPort"/>
+    <xsl:variable name="controlPort">
+        <xsl:choose>
+            <xsl:when test="string($controlPortSetting) = ''">8010</xsl:when>
+            <xsl:otherwise><xsl:value-of select="$controlPortSetting"/></xsl:otherwise>
+        </xsl:choose>
+    </xsl:variable>
+
     <xsl:template match="/Environment">
         <xsl:copy>
             <Software>
@@ -130,11 +136,7 @@
                 <EspProtocol>
                     <xsl:attribute name="name">http</xsl:attribute>
                     <xsl:attribute name="type">http_protocol</xsl:attribute>
-                    <xsl:attribute name="plugin">
-                       <xsl:call-template name="makeServicePluginName">
-                          <xsl:with-param name="plugin" select="'esphttp'"/>
-                       </xsl:call-template>
-                    </xsl:attribute>
+                    <xsl:attribute name="plugin">esphttp</xsl:attribute>
                     <xsl:attribute name="maxRequestEntityLength">
                         <xsl:value-of select="$maxRequestEntityLength"/>
                     </xsl:attribute>
@@ -143,11 +145,7 @@
             <!-- insert https protocol, if a certificate has been specified for it-->
             <xsl:if test="EspBinding[@protocol='https']">
                 <EspProtocol name="https" type="secure_http_protocol">
-                    <xsl:attribute name="plugin">
-                       <xsl:call-template name="makeServicePluginName">
-                          <xsl:with-param name="plugin" select="'esphttp'"/>
-                       </xsl:call-template>
-                    </xsl:attribute>
+                    <xsl:attribute name="plugin">esphttp</xsl:attribute>
                     <xsl:attribute name="maxRequestEntityLength">
                         <xsl:value-of select="$maxRequestEntityLength"/>
                     </xsl:attribute>
@@ -166,6 +164,17 @@
                     </verify>
                 </EspProtocol>
             </xsl:if>
+            <xsl:if test="string($controlPort) != '0'">
+                <xsl:variable name="serviceName" select="concat('WSESPControl_', $process)"/>
+                <xsl:variable name="servicePlugin">
+                    <xsl:call-template name="makeServicePluginName">
+                        <xsl:with-param name="plugin" select="'ws_espcontrol'"/>
+                    </xsl:call-template>
+                </xsl:variable>
+                <xsl:variable name="bindName" select="concat('WSESPControl_Binding_', $process)"/>
+                <EspService name="{$serviceName}" type="WSESPControl" plugin="{$servicePlugin}"/>
+                <EspBinding name="{$bindName}" service="{$serviceName}" protocol="http" type="ws_espcontrolSoapBinding" plugin="{$servicePlugin}" netAddress="0.0.0.0" port="{$controlPort}"/>
+            </xsl:if>
             <xsl:variable name="importedServiceDefinitionFiles">
                 <xsl:call-template name="importServiceDefinitionFiles">
                     <xsl:with-param name="filesList" select="$serviceFilesList"/>
@@ -443,14 +452,11 @@
     
     <xsl:template name="makeServicePluginName">
         <xsl:param name="plugin"/>
-        <xsl:value-of select="$plugin"/>
-        <!--
         <xsl:choose>
             <xsl:when test="$isLinuxInstance">lib<xsl:value-of select="$plugin"/>.so</xsl:when>
             <xsl:otherwise>
                 <xsl:value-of select="$plugin"/>.dll</xsl:otherwise>
         </xsl:choose>
-        -->
     </xsl:template>