Преглед на файлове

Merge pull request #10847 from afishbeck/roxieWsEclWorkunit

HPCC-13347 Add roxie workunit support to WsEcl

Reviewed-By: Kevin Wang <kevin.wang@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman преди 7 години
родител
ревизия
afcaedc681
променени са 4 файла, в които са добавени 90 реда и са изтрити 28 реда
  1. 55 18
      esp/services/ws_ecl/ws_ecl_service.cpp
  2. 2 2
      esp/services/ws_ecl/ws_ecl_service.hpp
  3. 20 6
      esp/xslt/wsecl3_form.xsl
  4. 13 2
      esp/xslt/wsecl3_xmltest.xsl

+ 55 - 18
esp/services/ws_ecl/ws_ecl_service.cpp

@@ -1665,9 +1665,12 @@ int CWsEclBinding::getXmlTestForm(IEspContext &context, CHttpRequest* request, C
     return 0;
 };
 
-inline StringBuffer &buildWsEclTargetUrl(StringBuffer &url, WsEclWuInfo &wsinfo, const char *type, const char *params)
+inline StringBuffer &buildWsEclTargetUrl(StringBuffer &url, WsEclWuInfo &wsinfo, bool createWorkunit, const char *type, const char *params)
 {
-    url.append("/WsEcl/").append(type).append('/');
+    url.append("/WsEcl/").append(type);
+    if (createWorkunit)
+        url.append("run");
+    url.append('/');
     if (wsinfo.qsetname.length() && wsinfo.queryname.length())
         url.append("query/").append(wsinfo.qsetname.get()).append('/').append(wsinfo.queryname.get());
     else
@@ -1730,7 +1733,14 @@ int CWsEclBinding::getXmlTestForm(IEspContext &context, CHttpRequest* request, C
     xform->setParameter("inhouseUser", inhouse ? "true()" : "false()");
 
     StringBuffer url;
-    xform->setStringParameter("destination", buildWsEclTargetUrl(url, wsinfo, formtype, params.str()).str());
+    xform->setStringParameter("destination", buildWsEclTargetUrl(url, wsinfo, false, formtype, params.str()).str());
+
+    bool isRoxieReq = wsecl->connMap.getValue(wsinfo.qsetname.get())!=NULL;
+    if (isRoxieReq)
+    {
+        xform->setStringParameter("showJobType", "true()");
+        xform->setStringParameter("createWorkunitDestination", buildWsEclTargetUrl(url.clear(), wsinfo, true, formtype, params.str()).str());
+    }
 
     StringBuffer page;
     xform->transform(page);
@@ -1782,7 +1792,15 @@ int CWsEclBinding::getJsonTestForm(IEspContext &context, CHttpRequest* request,
     xform->setParameter("inhouseUser", inhouse ? "true()" : "false()");
 
     StringBuffer url;
-    xform->setStringParameter("destination", buildWsEclTargetUrl(url, wsinfo, formtype, params.str()).str());
+    xform->setStringParameter("destination", buildWsEclTargetUrl(url, wsinfo, false, formtype, params.str()).str());
+
+    bool isRoxieReq = wsecl->connMap.getValue(wsinfo.qsetname.get())!=NULL;
+    if (isRoxieReq)
+    {
+        xform->setStringParameter("showJobType", "true()");
+        xform->setStringParameter("createWorkunitDestination", buildWsEclTargetUrl(url, wsinfo, true, formtype, params.str()).str());
+    }
+
 
     StringBuffer page;
     xform->transform(page);
@@ -2026,19 +2044,19 @@ void CWsEclBinding::sendRoxieRequest(const char *target, StringBuffer &req, Stri
     }
 }
 
-int CWsEclBinding::onSubmitQueryOutput(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo, const char *format)
+int CWsEclBinding::onSubmitQueryOutput(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo, const char *format, bool forceCreateWorkunit)
 {
     StringBuffer status;
     StringBuffer output;
 
     SCMStringBuffer clustertype;
     const char *contentType="application/xml";
-    bool isRoxieReq = wsecl->connMap.getValue(wsinfo.qsetname.get())!=NULL;
+    bool callRoxieQuery = !forceCreateWorkunit && wsecl->connMap.getValue(wsinfo.qsetname.get())!=NULL;
     bool outputJSON = (format && strieq(format, "json"));
     const char *jsonp = context.queryRequestParameters()->queryProp("jsonp");
     bool trim = context.queryRequestParameters()->getPropBool(".trim", true);
     bool trim2 = context.queryRequestParameters()->getPropBool("trim", true);
-    if (isRoxieReq && outputJSON)
+    if (callRoxieQuery && outputJSON)
     {
         StringBuffer jsonmsg;
         getWsEclJsonRequest(jsonmsg, context, request, wsinfo, "json", NULL, REQSF_TRIM, false);
@@ -2060,7 +2078,7 @@ int CWsEclBinding::onSubmitQueryOutput(IEspContext &context, CHttpRequest* reque
             xmlflags |= WWV_USE_DISPLAY_XSLT;
         if (!format || !streq(format, "expanded"))
             xmlflags |= WWV_OMIT_SCHEMAS;
-        if (!isRoxieReq)
+        if (!callRoxieQuery)
             submitWsEclWorkunit(context, wsinfo, soapmsg.str(), output, xmlflags, request, outputJSON ? MarkupFmt_JSON : MarkupFmt_XML);
         else
         {
@@ -2090,7 +2108,7 @@ int CWsEclBinding::onSubmitQueryOutput(IEspContext &context, CHttpRequest* reque
     return 0;
 }
 
-int CWsEclBinding::onSubmitQueryOutputView(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo)
+int CWsEclBinding::onSubmitQueryOutputView(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo, bool forceCreateWorkunit)
 {
     IConstWorkUnit *wu = wsinfo.ensureWorkUnit();
 
@@ -2111,7 +2129,7 @@ int CWsEclBinding::onSubmitQueryOutputView(IEspContext &context, CHttpRequest* r
     StringBuffer xsltfile(getCFD());
     xsltfile.append("xslt/wsecl3_result.xslt");
     const char *view = context.queryRequestParameters()->queryProp("view");
-    if (strieq(clustertype.str(), "roxie"))
+    if (!forceCreateWorkunit && strieq(clustertype.str(), "roxie"))
     {
         sendRoxieRequest(wsinfo.qsetname.get(), soapmsg, output, status, wsinfo.queryname, false, "text/xml", request);
         Owned<IWuWebView> web = createWuWebView(*wu, wsinfo.qsetname.get(), wsinfo.queryname.get(), getCFD(), true, queryXsltConfig());
@@ -2454,7 +2472,7 @@ int CWsEclBinding::onGet(CHttpRequest* request, CHttpResponse* response)
         if (strieq(methodName, "async"))
         {
             parms->setProp("_async", 1);
-            methodName.set("submit");
+            methodName.set("run");
         }
 
         if(strieq(methodName.str(), "res"))
@@ -2550,9 +2568,9 @@ int CWsEclBinding::onGet(CHttpRequest* request, CHttpResponse* response)
             response->setStatus("200 OK");
             response->send();
         }
-        else if (!stricmp(methodName.str(), "submit"))
+        else if (strieq(methodName, "submit") || strieq(methodName, "run"))
         {
-            context->addTraceSummaryValue(LogMin, "wseclMode", "submit");
+            context->addTraceSummaryValue(LogMin, "wseclMode", methodName);
 
             StringBuffer wuid;
             StringBuffer qs;
@@ -2565,9 +2583,9 @@ int CWsEclBinding::onGet(CHttpRequest* request, CHttpResponse* response)
             setResponseFormatByName(context, format);
 
             WsEclWuInfo wsinfo(wuid.str(), qs.str(), qid.str(), context->queryUserId(), context->queryPassword());
-            return onSubmitQueryOutput(*context, request, response, wsinfo, format.str());
+            return onSubmitQueryOutput(*context, request, response, wsinfo, format.str(), strieq(methodName, "run"));
         }
-        else if (!stricmp(methodName.str(), "xslt"))
+        else if (strieq(methodName.str(), "xslt") || strieq(methodName, "runxslt"))
         {
             context->addTraceSummaryValue(LogMin, "wseclMode", "xslt");
 
@@ -2578,7 +2596,7 @@ int CWsEclBinding::onGet(CHttpRequest* request, CHttpResponse* response)
             splitLookupInfo(parms, thepath, wuid, qs, qid);
             WsEclWuInfo wsinfo(wuid.str(), qs.str(), qid.str(), context->queryUserId(), context->queryPassword());
 
-            return onSubmitQueryOutputView(*context, request, response, wsinfo);
+            return onSubmitQueryOutputView(*context, request, response, wsinfo, strieq(methodName, "runxslt"));
         }
         else if (!stricmp(methodName.str(), "example"))
         {
@@ -2683,8 +2701,18 @@ void CWsEclBinding::handleJSONPost(CHttpRequest *request, CHttpResponse *respons
 
         StringBuffer action;
         nextPathNode(thepath, action);
+
+        bool forceCreateWorkunit = false;
         if (strieq(action, "async"))
             parms->setProp("_async", 1);
+        else if (strieq(action, "soaprun"))
+            forceCreateWorkunit = true;
+        else if (strieq(action, "asyncrun"))
+        {
+            parms->setProp("_async", 1);
+            forceCreateWorkunit = true;
+        }
+
 
         StringBuffer lookup;
         nextPathNode(thepath, lookup);
@@ -2715,7 +2743,7 @@ void CWsEclBinding::handleJSONPost(CHttpRequest *request, CHttpResponse *respons
             DBGLOG("json request: %s", content.str());
 
         StringBuffer status;
-        if (wsecl->connMap.getValue(queryset.str()))
+        if (!forceCreateWorkunit && wsecl->connMap.getValue(queryset.str()))
             sendRoxieRequest(queryset.str(), content, jsonresp, status, queryname.str(), trim, "application/json", request);
         else
         {
@@ -2794,8 +2822,17 @@ int CWsEclBinding::HandleSoapRequest(CHttpRequest* request, CHttpResponse* respo
 
     StringBuffer action;
     nextPathNode(thepath, action);
+
+    bool forceCreateWorkunit = false;
     if (strieq(action, "async"))
         parms->setProp("_async", 1);
+    else if (strieq(action, "soaprun"))
+        forceCreateWorkunit = true;
+    else if (strieq(action, "asyncrun"))
+    {
+        parms->setProp("_async", 1);
+        forceCreateWorkunit = true;
+    }
 
     StringBuffer lookup;
     nextPathNode(thepath, lookup);
@@ -2828,7 +2865,7 @@ int CWsEclBinding::HandleSoapRequest(CHttpRequest* request, CHttpResponse* respo
     else
         xmlflags |= WWV_OMIT_SCHEMAS;
 
-    if (wsecl->connMap.getValue(target))
+    if (!forceCreateWorkunit && wsecl->connMap.getValue(target))
     {
         bool trim = ctx->queryRequestParameters()->getPropBool(".trim", true);
         StringBuffer content(request->queryContent());

+ 2 - 2
esp/services/ws_ecl/ws_ecl_service.hpp

@@ -215,8 +215,8 @@ public:
     void buildSampleResponseXml(StringBuffer& msg, IEspContext &context, CHttpRequest* request, WsEclWuInfo &wsinfo);
     void getSoapMessage(StringBuffer& soapmsg, IEspContext &context, CHttpRequest* request, WsEclWuInfo &wsinfo, unsigned flags, bool validate);
     int onGetSoapBuilder(IEspContext &context, CHttpRequest* request, CHttpResponse* response,  WsEclWuInfo &wsinfo);
-    int onSubmitQueryOutput(IEspContext &context, CHttpRequest* request, CHttpResponse* response,    WsEclWuInfo &wsinfo, const char *format);
-    int onSubmitQueryOutputView(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo);
+    int onSubmitQueryOutput(IEspContext &context, CHttpRequest* request, CHttpResponse* response,    WsEclWuInfo &wsinfo, const char *format, bool forceCreateWorkunit);
+    int onSubmitQueryOutputView(IEspContext &context, CHttpRequest* request, CHttpResponse* response, WsEclWuInfo &wsinfo, bool forceCreateWorkunit);
 
     int submitWsEclWorkunit(IEspContext & context, WsEclWuInfo &wsinfo, IPropertyTree *reqTree, StringBuffer &out, unsigned flags, CHttpRequest *httpreq, TextMarkupFormat fmt=MarkupFmt_XML, const char *viewname=NULL, const char *xsltname=NULL);
     int submitWsEclWorkunit(IEspContext & context, WsEclWuInfo &wsinfo, const char *xml, StringBuffer &out, unsigned flags, CHttpRequest *httpreq, TextMarkupFormat fmt=MarkupFmt_XML, const char *viewname=NULL, const char *xsltname=NULL);

+ 20 - 6
esp/xslt/wsecl3_form.xsl

@@ -143,6 +143,15 @@ function setESPFormAction()  // reqType: 0: regular form, 1: soap, 2: form param
     if (!form)  return false;
 
     var actval = document.getElementById('submit_type');
+    var subval = 'submit';
+    var subxslt = 'xslt';
+    var jobType = document.getElementById('job_type');
+    if (jobType && jobType.value=="WORKUNIT")
+    {
+       subval = 'run';
+       subxslt = 'runxslt';
+    }
+
     var actionpath = "/jserror";
     if (actval && actval.value)
     {
@@ -150,18 +159,17 @@ function setESPFormAction()  // reqType: 0: regular form, 1: soap, 2: form param
             actionpath = "]]></xsl:text><xsl:value-of disable-output-escaping="yes" select="concat('/WsEcl/forms/soap/query/', $queryPath, '/', $methodName)"/><xsl:text disable-output-escaping="yes"><![CDATA[";
         else if (actval.value=="esp_json")
             actionpath = "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/WsEcl/forms/json/query/', $queryPath, '/', $methodName)"/><xsl:text disable-output-escaping="yes"><![CDATA[";
-        else if (actval.value=="run_xslt")
-            actionpath = "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/WsEcl/xslt/query/', $queryPath, '/', $methodName)"/><xsl:text disable-output-escaping="yes"><![CDATA[";
         else if (actval.value=="proxy_xml")
             actionpath = "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/WsEcl/proxy/query/', $queryPath, '/', $methodName, '/xml?view=xml&amp;display')"/><xsl:text disable-output-escaping="yes"><![CDATA[";
         else if (actval.value=="xml")
-            actionpath = "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/WsEcl/submit/query/', $queryPath, '/', $methodName, '/xml?view=xml&amp;display')"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+            actionpath = "/WsEcl/" + subval + "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/query/', $queryPath, '/', $methodName, '/xml?view=xml&amp;display')"/><xsl:text disable-output-escaping="yes"><![CDATA[";
         else if (actval.value=="json")
-            actionpath = "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/WsEcl/submit/query/', $queryPath, '/', $methodName, '/json')"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+            actionpath = "/WsEcl/" + subval + "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/query/', $queryPath, '/', $methodName, '/json')"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+        else if (actval.value=="run_xslt")
+            actionpath = "/WsEcl/" + subxslt + "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/query/', $queryPath, '/', $methodName)"/><xsl:text disable-output-escaping="yes"><![CDATA[";
         else
-            actionpath= "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/WsEcl/xslt/query/', $queryPath, '/', $methodName, '?view=')"/><xsl:text disable-output-escaping="yes"><![CDATA["+actval.value;
+            actionpath= "/WsEcl/" + subval + "]]></xsl:text><xsl:value-of disable-output-escaping="yes"  select="concat('/query/', $queryPath, '/', $methodName, '?view=')"/><xsl:text disable-output-escaping="yes"><![CDATA["+actval.value;
     }
-    //alert("actionpath = " + actionpath);
     var dest = document.getElementById('esp_dest');
     if (actionpath=="bookmark")
          doBookmark(form);
@@ -318,6 +326,12 @@ function switchInputForm()
 
                 <tr class='commands'>
                   <td align='left'>
+                  <xsl:if test="$includeRoxieOptions=1">
+                    <select id="job_type">
+                      <option value="QUERY">Call Query</option>
+                      <option value="WORKUNIT">Create Workunit</option>
+                    </select>&nbsp;
+                  </xsl:if>
                     <select id="submit_type" name="submit_type">
                         <xsl:for-each select="/FormInfo/CustomViews/Result">
                             <option><xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute><xsl:value-of select="."/></option>

+ 13 - 2
esp/xslt/wsecl3_xmltest.xsl

@@ -24,6 +24,8 @@
 
     <xsl:param name="inhouseUser" select="false()"/>
     <xsl:param name="showhttp" select="false()"/>
+    <xsl:param name="showJobType" select="false()"/>
+    <xsl:param name="createWorkunitDestination" select="'empty'"/>
     <!-- ===============================================================================-->
     <xsl:template match="/">
     <html>
@@ -356,12 +358,15 @@ function onSendRequest()
        var doc = parseXmlString(document.getElementById("req_body").value);
        if (!doc) return;
    }
-   
+
     // clear
     document.getElementById("resp_body").value = "";
     document.getElementById("resp_header").value = "";
-    
+
     var url = "]]></xsl:text><xsl:value-of select="$destination"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+    if (document.getElementById("job_type").value == "WORKUNIT")
+        url = "]]></xsl:text><xsl:value-of select="$createWorkunitDestination"/><xsl:text disable-output-escaping="yes"><![CDATA[";
+
     var user = document.getElementById("username").value;
     var passwd = document.getElementById("password").value;
     loadXMLDoc(url,user,passwd);
@@ -809,6 +814,12 @@ var gMethodName = "<xsl:value-of select="$methodName"/>";;
                 </tr>
                     <tr>
                         <td align="center" colspan="2"> 
+                           <xsl:if test="$showJobType">
+                              <select id="job_type">
+                                 <option value="QUERY">Call Query</option>
+                                 <option value="WORKUNIT">Create Workunit</option>
+                              </select>&nbsp;
+                            </xsl:if>
                             <input type="button" id="sendButton" value="Send Request" onclick="onSendRequest()"/>  <input type="checkbox" checked="true" id="check_req"> Check well-formness before send</input>
                         </td>
                     </tr>