Explorar o código

HPCC-25351 Add WsResources service and ServiceQuery method

A new ESP service WsResources is added. For now, the service
has one method which reports the information about services
in a cloud environment.

Revise based on review
1. Only report public services
2. Remove the code for reporting the target attribute
3. Default the @tls to false
4. Rename ws_container to ws_resources
5. Rename ResourcesAccess to ResourceQueryAccess
6. Change the code to always build this service plugin,
   including for bare metal environment.

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
wangkx %!s(int64=4) %!d(string=hai) anos
pai
achega
3a0537eaae

+ 1 - 0
esp/applications/eclwatch/application.yaml

@@ -16,4 +16,5 @@ application:
    - ws_esdlconfig
    - ws_store
    - ws_codesign
+   - ws_resources
    - WSDali

+ 5 - 0
esp/applications/eclwatch/ldap_authorization_map.yaml

@@ -146,6 +146,11 @@ ldap:
          -  path: ConfigAccess
             resource: ConfigAccess
             description: Access to super computer environment
+      ws_resources:
+         Feature:
+         -  path: ResourceQueryAccess
+            resource: ResourceQueryAccess
+            description: Access to resources
       WsPackageProcess: []
       ws_account: []
       ws_access: []

+ 2 - 0
esp/applications/eclwatch/plugins.yaml

@@ -20,6 +20,7 @@ service_plugins:
   WsTopology: ws_topology
   WsWorkunits: ws_workunits
   ws_codesign: ws_codesign
+  ws_resources: ws_resources
   WSDali: ws_dali
 
 binding_plugins:
@@ -40,5 +41,6 @@ binding_plugins:
   WsSMC: ws_smc
   WSESPControl: wsespcontrol
   ws_codesign: ws_codesign
+  ws_resources: ws_resources
   WSDali: ws_dali
 

+ 1 - 0
esp/scm/espscm.cmake

@@ -49,6 +49,7 @@ set ( ESPSCM_SRCS
       ws_codesign.ecm
       ws_decoupledlogging.ecm
       ws_dali.ecm
+      ws_resources.ecm
     )
 
 foreach ( loop_var ${ESPSCM_SRCS} )

+ 1 - 0
esp/scm/smcscm.cmake

@@ -41,6 +41,7 @@ set ( ESPSCM_SRCS
       ws_esdlconfig.ecm
       ws_elk.ecm
       ws_codesign.ecm
+      ws_resources.ecm
     )
 
 foreach ( loop_var ${ESPSCM_SRCS} )

+ 44 - 0
esp/scm/ws_resources.ecm

@@ -0,0 +1,44 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2021 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.
+############################################################################## */
+
+ESPStruct HPCCService
+{
+    string Name;
+    string Type;
+    unsigned Port;
+    bool TLSSecure;
+};
+
+ESPrequest ServiceQueryRequest
+{
+    string Type;
+    string Name;
+};
+
+ESPresponse [nil_remove, exceptions_inline] ServiceQueryResponse
+{
+    ESParray<ESPstruct HPCCService, Service> Services;
+};
+
+ESPservice [auth_feature("ResourceQueryAccess:ACCESS"), noforms, version("1.00"), exceptions_inline("./smc_xslt/exceptions.xslt")] WsResources
+{
+    ESPmethod [auth_feature("ResourceQueryAccess:READ")] ServiceQuery(ServiceQueryRequest, ServiceQueryResponse);
+};
+
+SCMexportdef(WsResources);
+
+SCMapi(WsResources) IClientWsResources *createWsResourcesClient();

+ 1 - 0
esp/services/CMakeLists.txt

@@ -38,6 +38,7 @@ HPCC_ADD_SUBDIRECTORY (espcontrol "PLATFORM")
 HPCC_ADD_SUBDIRECTORY (ws_elk "PLATFORM")
 HPCC_ADD_SUBDIRECTORY (ws_store "PLATFORM")
 HPCC_ADD_SUBDIRECTORY (ws_codesign "PLATFORM")
+HPCC_ADD_SUBDIRECTORY (ws_resources "PLATFORM")
 HPCC_ADD_SUBDIRECTORY (ws_dali "PLATFORM")
 if (NOT CONTAINERIZED)
   HPCC_ADD_SUBDIRECTORY (ws_config "PLATFORM")

+ 74 - 0
esp/services/ws_resources/CMakeLists.txt

@@ -0,0 +1,74 @@
+################################################################################
+#    HPCC SYSTEMS software Copyright (C) 2021 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_resources 
+
+#####################################################
+# Description:
+# ------------
+#    Cmake Input File for ws_resources
+#####################################################
+
+
+project( ws_resources ) 
+
+include(${HPCC_SOURCE_DIR}/esp/scm/smcscm.cmake)
+
+set (    SRCS 
+         ${ESPSCM_GENERATED_DIR}/ws_resources_esp.cpp 
+         ws_resourcesPlugin.cpp 
+         ws_resourcesService.cpp 
+    )
+
+include_directories ( 
+         ${HPCC_SOURCE_DIR}/esp/platform
+         ${HPCC_SOURCE_DIR}/esp/bindings
+         ${HPCC_SOURCE_DIR}/esp/bindings/SOAP/xpp
+         ${HPCC_SOURCE_DIR}/esp/clients
+         ${HPCC_SOURCE_DIR}/esp/smc/SMCLib
+         ${HPCC_SOURCE_DIR}/system/include
+         ${HPCC_SOURCE_DIR}/system/jlib
+         ${HPCC_SOURCE_DIR}/system/xmllib
+         ${HPCC_SOURCE_DIR}/system/security/securesocket
+         ${HPCC_SOURCE_DIR}/system/security/LdapSecurity
+         ${HPCC_SOURCE_DIR}/system/security/shared
+         ${HPCC_SOURCE_DIR}/system/mp
+         ${HPCC_SOURCE_DIR}/common/environment
+         ${HPCC_SOURCE_DIR}/common/thorhelper
+         ${HPCC_SOURCE_DIR}/dali/base
+         ${HPCC_SOURCE_DIR}/dali/sasha
+    )
+
+ADD_DEFINITIONS( -D_USRDLL -DWS_RESOURCES_EXPORTS )
+
+HPCC_ADD_LIBRARY( ws_resources SHARED ${SRCS} )
+add_dependencies ( ws_resources espscm )
+install ( TARGETS ws_resources RUNTIME DESTINATION ${EXEC_DIR} LIBRARY DESTINATION ${LIB_DIR} )
+target_link_libraries ( ws_resources
+         jlib
+         xmllib
+         esphttp
+         SMCLib
+         )
+
+IF (USE_OPENSSL)
+    target_link_libraries ( ws_resources
+    	securesocket
+    )
+ENDIF()
+
+

+ 26 - 0
esp/services/ws_resources/sourcedoc.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+################################################################################
+#    HPCC SYSTEMS software Copyright (C) 2021 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.
+################################################################################
+-->
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
+<section>
+    <title>esp/services/ws_resources</title>
+
+    <para>
+        The esp/services/ws_resources directory contains the sources for the esp/services/ws_resources library.
+    </para>
+</section>

+ 64 - 0
esp/services/ws_resources/ws_resourcesPlugin.cpp

@@ -0,0 +1,64 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2021 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)
+
+#include "ws_resources_esp.ipp"
+
+//ESP Bindings
+#include "http/platform/httpprot.hpp"
+
+//ESP Service
+#include "ws_resourcesService.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 (strieq(type, "ws_resources"))
+   {
+      CWsResourcesEx* service = new CWsResourcesEx;
+      service->init(cfg, process, name);
+      return service;
+   }
+   return nullptr;
+}
+
+ESP_FACTORY IEspRpcBinding* esp_binding_factory(const char* name, const char* type, IPropertyTree* cfg, const char* process)
+{
+    //binding names ending in _http are being added so the names can be made more consistent and can therefore be automatically generated
+    //  the name also better reflects that these bindings are for all HTTP based protocols, not just SOAP
+    //  both "SoapBinding" and "_http" names instantiate the same objects.
+   if (strieq(type, "ws_resourcesSoapBinding") || strieq(type, "ws_resources_http"))
+   {
+        return new CWsResourcesSoapBinding(cfg, name, process);
+   }
+
+   return nullptr;
+}
+
+ESP_FACTORY IEspProtocol* esp_protocol_factory(const char* name, const char* type, IPropertyTree* cfg, const char* process)
+{
+    return http_protocol_factory(name, type, cfg, process);
+}
+
+};

+ 34 - 0
esp/services/ws_resources/ws_resourcesService.cpp

@@ -0,0 +1,34 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2021 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)
+
+#include "ws_resourcesService.hpp"
+#include "exception_util.hpp"
+
+bool CWsResourcesEx::onServiceQuery(IEspContext& context, IEspServiceQueryRequest& req, IEspServiceQueryResponse& resp)
+{
+    try
+    {
+        tpWrapper.getServices(context.getClientVersion(), req.getType(), req.getName(), resp.getServices());
+    }
+    catch(IException* e)
+    {
+        FORWARDEXCEPTION(context, e,  ECLWATCH_INTERNAL_ERROR);
+    }
+    return false;
+}

+ 40 - 0
esp/services/ws_resources/ws_resourcesService.hpp

@@ -0,0 +1,40 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2021 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_resources_HPP__
+#define _ESPWIZ_ws_resources_HPP__
+
+#ifdef _USE_OPENLDAP
+#include "ldapsecurity.ipp"
+#endif
+
+#include "ws_resources_esp.ipp"
+#include "TpWrapper.hpp"
+
+class CWsResourcesEx : public CWsResources
+{
+    CTpWrapper tpWrapper;
+
+public:
+    virtual ~CWsResourcesEx() {};
+    virtual void init(IPropertyTree* cfg, const char* process, const char* service) override {};
+
+    virtual bool onServiceQuery(IEspContext& context, IEspServiceQueryRequest& req, IEspServiceQueryResponse& resp) override;
+};
+
+#endif //_ESPWIZ_ws_resources_HPP__
+

+ 2 - 1
esp/smc/SMCLib/CMakeLists.txt

@@ -28,7 +28,8 @@ include(${HPCC_SOURCE_DIR}/esp/scm/smcscm.cmake)
 
 set (    SRCS
          ${HPCC_SOURCE_DIR}/dali/sasha/sacmd.cpp
-         ${ESPSCM_GENERATED_DIR}/ws_topology_esp.cpp 
+         ${ESPSCM_GENERATED_DIR}/ws_topology_esp.cpp
+         ${ESPSCM_GENERATED_DIR}/ws_resources_esp.cpp
          LogicFileWrapper.cpp 
          TpWrapper.cpp 
          WUXMLInfo.cpp

+ 30 - 0
esp/smc/SMCLib/TpWrapper.cpp

@@ -1970,6 +1970,36 @@ void CTpWrapper::getAttPath(const char* Path,StringBuffer& returnStr)
     JBASE64_Decode(Path, returnStr);
 }
 
+void CTpWrapper::getServices(double version, const char* serviceType, const char* serviceName, IArrayOf<IConstHPCCService>& services)
+{
+    Owned<IPropertyTreeIterator> itr = queryComponentConfig().getElements("services");
+    ForEach(*itr)
+    {
+        IPropertyTree& service = itr->query();
+        //Only show the public services for now
+        if (!service.getPropBool("@public"))
+            continue;
+
+        const char* type = service.queryProp("@type");
+        if (isEmptyString(type) || (!isEmptyString(serviceType) && !strieq(serviceType, type)))
+            continue;
+
+        const char* name = service.queryProp("@name");
+        if (isEmptyString(name) || (!isEmptyString(serviceName) && !strieq(serviceName, name)))
+            continue;
+
+        Owned<IEspHPCCService> svc = createHPCCService();
+        svc->setName(name);
+        svc->setType(type);
+        svc->setPort(service.getPropInt("@port"));
+        if (service.getPropBool("@tls"))
+            svc->setTLSSecure(true);
+        services.append(*svc.getLink());
+        if (!isEmptyString(serviceName))
+            break;
+    }
+}
+
 extern TPWRAPPER_API ISashaCommand* archiveOrRestoreWorkunits(StringArray& wuids, IProperties* params, bool archive, bool dfu)
 {
     StringBuffer sashaAddress;

+ 2 - 0
esp/smc/SMCLib/TpWrapper.hpp

@@ -39,6 +39,7 @@
 #include "danqs.hpp"
 #include "environment.hpp"
 #include "ws_topology.hpp"
+#include "ws_resources.hpp"
 #include <string>
 #include <set>
 #include "sacmd.hpp"
@@ -189,6 +190,7 @@ public:
     void queryTargetClusters(double version, const char* clusterType, const char* clusterName, IArrayOf<IEspTpTargetCluster>& clusterList);
     void getTargetClusterList(IArrayOf<IEspTpLogicalCluster>& clusters, const char* clusterType = NULL, const char* clusterName = NULL);
     void queryTargetClusterProcess(double version, const char* processName, const char* clusterType, IArrayOf<IConstTpCluster>& list);
+    void getServices(double version, const char* serviceType, const char* serviceName, IArrayOf<IConstHPCCService>& list);
 
     IPropertyTree* getEnvironment(const char* xpath);
 };