瀏覽代碼

HPCC-16612 Add Std.File.GetEspURL to standard library

Exposes the full URL (including HTTP scheme and port number) of an ESP process in the current cluster

Signed-off-by: Dan S. Camper <dan.camper@lexisnexisrisk.com>
Dan S. Camper 7 年之前
父節點
當前提交
f031e3d2c4

+ 22 - 1
ecllibrary/std/File.ecl

@@ -41,7 +41,7 @@ EXPORT FsLogicalFileNameRecord := lib_fileservices.FsLogicalFileNameRecord;
  * @field rowcount      Number of rows in the file.
  * @modified            Timestamp when the file was last modified;
  * @owner               The username of the owner who ran the job to create this file.
- * @cluster             The cluster that this file was created on. 
+ * @cluster             The cluster that this file was created on.
  */
 
 EXPORT FsLogicalFileInfoRecord := lib_fileservices.FsLogicalFileInfoRecord;
@@ -924,4 +924,25 @@ EXPORT varstring fPromoteSuperFileList(set of varstring superNames, varstring ad
 EXPORT PromoteSuperFileList(set of varstring superNames, varstring addHead='', boolean delTail=FALSE, boolean createOnlyOne=FALSE, boolean reverse=FALSE) :=
     lib_fileservices.FileServices.PromoteSuperFileList(superNames, addHead, delTail, createOnlyOne, reverse);
 
+/**
+ * Returns the full URL to an ESP server process
+ *
+ * @param username      String containing a username to use for authenticated
+ *                      access to the ESP process; an empty string value
+ *                      indicates that no user authentication is required;
+ *                      OPTIONAL, defaults to an empty string
+ * @param userPW        String containing the password to be used with the
+ *                      user cited in the username argument; if username is
+ *                      empty then this will be ignored; OPTIONAL, defaults
+ *                      to an empty string
+ *
+ * @return              A string containing the full URL (including HTTP scheme
+ *                      and port) to an ESP server process; if more than one
+ *                      process is defined then the first found process will
+ *                      be returned; will return an empty string if an ESP
+ *                      server process cannot be found
+ */
+EXPORT varstring GetEspURL(const varstring username = '', const varstring userPW = '') :=
+    lib_fileservices.FileServices.GetEspURL(username, userPW);
+
 END;

+ 29 - 0
ecllibrary/teststd/File/TestGetEspURL.ecl

@@ -0,0 +1,29 @@
+/*##############################################################################
+## HPCC SYSTEMS software Copyright (C) 2017 HPCC Systems®.  All rights reserved.
+############################################################################## */
+
+IMPORT Std.File;
+
+EXPORT TestGetEspURL := MODULE
+
+    EXPORT TestRuntime := MODULE
+        // Override USER and USER_PW if authenticated access is needed
+        SHARED USER := '';
+        SHARED USER_PW := '';
+
+        SHARED buildString := SOAPCALL
+            (
+                File.GetEspURL(USER, USER_PW) + '/WsSMC',
+                'Activity',
+                {
+                    STRING sortby       {XPATH('SortBy')} := 'Name',
+                    STRING descending   {XPATH('Descending')} := '1'
+                },
+                DATASET({STRING activityBuild {XPATH('Build')}}),
+                XPATH('ActivityResponse')
+            );
+
+        EXPORT TestActivity01 := ASSERT(buildString[1].activityBuild != '');
+    END;
+
+END; 

+ 65 - 1
plugins/fileservices/fileservices.cpp

@@ -39,13 +39,14 @@
 #define USE_DALIDFS
 #define SDS_LOCK_TIMEOUT  10000
 
-#define FILESERVICES_VERSION "FILESERVICES 2.1.3"
+#define FILESERVICES_VERSION "FILESERVICES 2.1.4"
 
 static const char * compatibleVersions[] = {
     "FILESERVICES 2.1  [a68789cfb01d00ef6dc362e52d5eac0e]", // linux version
     "FILESERVICES 2.1.1",
     "FILESERVICES 2.1.2",
     "FILESERVICES 2.1.3",
+    "FILESERVICES 2.1.4",
     NULL };
 
 static const char * EclDefinition =
@@ -134,6 +135,7 @@ static const char * EclDefinition =
 "  varstring GetLogicalFileAttribute(const varstring lfn,const varstring attrname) : c,context,entrypoint='fsfGetLogicalFileAttribute'; \n"
 "  ProtectLogicalFile(const varstring lfn,boolean set=true) : c,context,entrypoint='fsProtectLogicalFile'; \n"
 "  DfuPlusExec(const varstring cmdline) : c,context,entrypoint='fsDfuPlusExec'; \n"
+"  varstring GetEspURL(const varstring username = '', const varstring userPW = '') : c,once,entrypoint='fsGetEspURL'; \n"
 "END;";
 
 #define WAIT_SECONDS 30
@@ -2509,4 +2511,66 @@ FILESERVICES_API void FILESERVICES_CALL fsDfuPlusExec(ICodeContext * ctx,const c
     }
 }
 
+FILESERVICES_API char * FILESERVICES_CALL fsGetEspURL(const char *username, const char *userPW)
+{
+    Owned<IConstEnvironment> daliEnv = openDaliEnvironment();
+    Owned<IPropertyTree> env = getEnvironmentTree(daliEnv);
+
+    if (env.get())
+    {
+        StringBuffer espURL;
+        StringBuffer espInstanceComputerName;
+        StringBuffer bindingProtocol;
+        StringBuffer xpath;
+        StringBuffer instanceAddress;
+        StringBuffer espServiceType;
+        StringBuffer credentials;
+
+        Owned<IPropertyTreeIterator> espProcessIter = env->getElements("Software/EspProcess");
+        ForEach(*espProcessIter)
+        {
+            Owned<IPropertyTreeIterator> espBindingIter = espProcessIter->query().getElements("EspBinding");
+            ForEach(*espBindingIter)
+            {
+                espBindingIter->query().getProp("@service",espURL.clear());
+                xpath.setf("Software/EspService[@name=\"%s\"]/Properties/@type", espURL.str());
+
+                if(env->getProp(xpath.str(), espServiceType.clear()))
+                {
+                    if (strieq(espServiceType.str(),"WsSMC"))
+                    {
+                        if (espBindingIter->query().getProp("@protocol",bindingProtocol.clear()))
+                        {
+                            Owned<IPropertyTreeIterator> espInstanceIter = espProcessIter->query().getElements("Instance");
+                            ForEach(*espInstanceIter)
+                            {
+                                if (espInstanceIter->query().getProp("@computer",espInstanceComputerName.clear()))
+                                {
+                                    xpath.setf("Hardware/Computer[@name=\"%s\"]/@netAddress",espInstanceComputerName.str());
+                                    if (env->getProp(xpath.str(),instanceAddress.clear()))
+                                    {
+                                        if (username && username[0] && userPW && userPW[0])
+                                            credentials.setf("%s:%s@", username, userPW);
+                                        else if (username && username[0])
+                                            credentials.setf("%s@", username);
+
+                                        if (streq(instanceAddress.str(),"."))
+                                            instanceAddress = fsfResolveHostName(instanceAddress.str());
+
+                                        espURL.setf("%s://%s%s:%d", bindingProtocol.str(), credentials.str(), instanceAddress.str(), espBindingIter->query().getPropInt("@port",8010));
+
+                                        return espURL.detach();
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    return NULL;
+}
+
 

+ 1 - 0
plugins/fileservices/fileservices.hpp

@@ -142,6 +142,7 @@ FILESERVICES_API void  FILESERVICES_CALL fsCreateExternalDirectory(ICodeContext
 FILESERVICES_API char * FILESERVICES_CALL fsfGetLogicalFileAttribute(ICodeContext * ctx,const char *lfn,const char *attrname);
 FILESERVICES_API void FILESERVICES_CALL fsProtectLogicalFile(ICodeContext * ctx,const char *lfn,bool set);
 FILESERVICES_API void FILESERVICES_CALL fsDfuPlusExec(ICodeContext * ctx,const char *_cmd);
+FILESERVICES_API char * FILESERVICES_CALL fsGetEspURL(const char *username, const char *userPW);
 
 }