marklogic-community / roxy

Deployment tool for MarkLogic applications. Also provides optional unit test and XQuery MVC structure
Other
87 stars 66 forks source link

Use only one XDBC server per host for all Roxy xquery.. #201

Closed grtjn closed 7 years ago

grtjn commented 10 years ago

Roxy currently relies on QConsole. The rumour goes QConsole is going to change. Instead of changing along (yet again), perhaps better to change strategy, and rely on XDBC server instead. With the new Configuration Manager built in MarkLogic 6+, an XDBC server can be bootstrapped from outside.

grtjn commented 10 years ago

Sample code to bootstrap a Roxy-xcc server:

let $options := 
  <options xmlns="xdmp:http">
    <authentication>
      <username>{$ml.user}</username>
      <password>{$ml.pass}</password>
    </authentication>
    <headers>
      <Content-type>application/xml</Content-type>
    </headers>
  </options>

let $packages :=
  xdmp:http-get("http://localhost:8002/manage/v2/packages", $options)[2]
  (:
    <package-list total="1" start="1" page-length="10" xmlns="http://marklogic.com/manage/package/list">
      <package-name>Roxy</package-name>
    </package-list>
  :)

let $roxy-package-exists :=
  $packages/*/*:package-name = 'Roxy'

let $create-roxy-package :=
  if (not($roxy-package-exists)) then
    xdmp:http-post("http://localhost:8002/manage/v2/packages?pkgname=Roxy", $options)[2]
    (:
      <resp>
        <msg>Created Roxy</msg>
        <package>http://localhost:8002/manage/v2/packages/Roxy</package>
      </resp>
    :)
  else ()

let $org-roxy-package-zip :=
  xdmp:http-get("http://localhost:8002/manage/v2/packages/Roxy?view=package&amp;format=zip", $options)[2]
  (:
    <parts xmlns="xdmp:zip">
      <part uncompressed-size="501" compressed-size="208" encrypted="false" last-modified="2014-04-15T11:49:56">metadata.xml</part>
    </parts>
  :)
let $org-roxy-package-metadata :=
  xdmp:zip-get($org-roxy-package-zip, "metadata.xml")
  (:
    <pkg:metadata xmlns:pkg="http://marklogic.com/manage/package">
      <pkg:package-version>2.0</pkg:package-version>
      <user xmlns="http://marklogic.com/manage/package">josten</user>
      <group xmlns="http://marklogic.com/manage/package">Default</group>
      <host xmlns="http://marklogic.com/manage/package">macpro-2463.fritz.box</host>
      <timestamp xmlns="http://marklogic.com/manage/package">2014-04-15T11:29:50.368471+02:00</timestamp>
      <platform xmlns="http://marklogic.com/manage/package">macosx</platform>
    </pkg:metadata>
  :)
let $new-roxy-package :=
<package-xdbc-server xmlns:cts="http://marklogic.com/cts" xmlns="http://marklogic.com/manage/package/servers">
  <metadata xmlns:srv="http://marklogic.com/manage/package/servers">
    <package-version>2.0</package-version>
    <user>{$ml.user}</user>
    <group>{$org-roxy-package-metadata//*:group/data(.)}</group>
    <host>{$org-roxy-package-metadata//*:host/data(.)}</host>
    <timestamp>{current-dateTime()}</timestamp>
    <platform>{$org-roxy-package-metadata//*:platform/data(.)}</platform>
  </metadata>
  <config>
    <server-type>xdbc-server</server-type>
    <group-name>{$org-roxy-package-metadata//*:group/data(.)}</group-name>
    <name>Roxy-xcc</name>
    <package-xdbc-properties>
      <root>/</root>
      <enabled>true</enabled>
      <port>8999</port>
      <display-last-login>false</display-last-login>
      <address>0.0.0.0</address>
      <backlog>256</backlog>
      <threads>32</threads>
      <request-timeout>30</request-timeout>
      <keep-alive-timeout>5</keep-alive-timeout>
      <session-timeout>3600</session-timeout>
      <max-time-limit>3600</max-time-limit>
      <default-time-limit>600</default-time-limit>
      <multi-version-concurrency-control>contemporaneous</multi-version-concurrency-control>
      <distribute-timestamps>fast</distribute-timestamps>
      <authentication>digest</authentication>
      <internal-security>true</internal-security>
      <concurrent-request-limit>0</concurrent-request-limit>
      <log-errors>true</log-errors>
      <debug-allow>true</debug-allow>
      <profile-allow>true</profile-allow>
      <output-sgml-character-entities>none</output-sgml-character-entities>
      <output-encoding>UTF-8</output-encoding>
      <output-method>default</output-method>
      <output-byte-order-mark>default</output-byte-order-mark>
      <output-cdata-section-namespace-uri/>
      <output-cdata-section-localname/>
      <output-doctype-public/>
      <output-doctype-system/>
      <output-escape-uri-attributes>default</output-escape-uri-attributes>
      <output-include-content-type>default</output-include-content-type>
      <output-indent>default</output-indent>
      <output-indent-untyped>default</output-indent-untyped>
      <output-media-type/>
      <output-normalization-form>none</output-normalization-form>
      <output-omit-xml-declaration>default</output-omit-xml-declaration>
      <output-standalone>omit</output-standalone>
      <output-undeclare-prefixes>default</output-undeclare-prefixes>
      <output-version/>
      <output-include-default-attributes>default</output-include-default-attributes>
      <default-xquery-version>1.0-ml</default-xquery-version>
      <pre-commit-trigger-depth>1000</pre-commit-trigger-depth>
      <pre-commit-trigger-limit>10000</pre-commit-trigger-limit>
      <schemas/>
      <namespaces/>
      <request-blackouts/>
      <collation>http://marklogic.com/collation/</collation>
      <ssl-certificate-template>0</ssl-certificate-template>
      <ssl-allow-sslv3>true</ssl-allow-sslv3>
      <ssl-allow-tls>true</ssl-allow-tls>
      <ssl-hostname/>
      <ssl-ciphers>ALL:!LOW:@STRENGTH</ssl-ciphers>
      <ssl-require-client-certificate>true</ssl-require-client-certificate>
      <ssl-client-certificate-authorities/>
    </package-xdbc-properties>
    <links>
      <group-name>{$org-roxy-package-metadata//*:group/data(.)}</group-name>
      <database>Documents</database>
    </links>
  </config>
</package-xdbc-server>

let $upload-new-roxy-package :=
  xdmp:http-post("http://localhost:8002/manage/v2/packages/Roxy",
    <options xmlns="xdmp:http">{
      $options/*,
      <data>{xdmp:quote($new-roxy-package)}</data>
    }</options>
  )[2]
  (:
    <resp>
      <succeeded>true</succeeded>
      <msg>Inserted server 'Roxy-xcc' in group 'Default'</msg>
    </resp>
  :)

let $roxy-package-diffs-exists :=
exists(
xdmp:http-get("http://localhost:8002/manage/v2/packages/Roxy?view=differences", $options)[2]
  (:
<pkg:package-diff xmlns:pkg="http://marklogic.com/manage/package">
  <package-xdbc-server xmlns="http://marklogic.com/manage/package/servers">
    <metadata>
      <package-version>2.0</package-version>
      <user>josten</user>
      <group>Default</group>
      <host>macpro-2463.fritz.box</host>
      <timestamp>2014-04-15T12:15:00.912316+02:00</timestamp>
      <platform>macosx</platform>
    </metadata>
    <config>
      <server-type>xdbc-server</server-type>
      <group-name>Default</group-name>
      <pkg:delta>
  <pkg:add>
    <name xmlns:cts="http://marklogic.com/cts">Roxy-xcc</name>
  </pkg:add>
      </pkg:delta>
      <package-xdbc-properties>
  <enabled>true</enabled>
  <root>/</root>
  <pkg:delta>
    <pkg:del>
      <port>8072</port>
    </pkg:del>
    <pkg:add>
      <port xmlns:cts="http://marklogic.com/cts">8999</port>
    </pkg:add>
  </pkg:delta>
  <display-last-login>false</display-last-login>
  <address>0.0.0.0</address>
  <backlog>256</backlog>
  <threads>32</threads>
  <request-timeout>30</request-timeout>
  <keep-alive-timeout>5</keep-alive-timeout>
  <session-timeout>3600</session-timeout>
  <max-time-limit>3600</max-time-limit>
  <default-time-limit>600</default-time-limit>
  <pre-commit-trigger-depth>1000</pre-commit-trigger-depth>
  <pre-commit-trigger-limit>10000</pre-commit-trigger-limit>
  <collation>http://marklogic.com/collation/</collation>
  <authentication>digest</authentication>
  <internal-security>true</internal-security>
  <concurrent-request-limit>0</concurrent-request-limit>
  <log-errors>true</log-errors>
  <debug-allow>true</debug-allow>
  <profile-allow>true</profile-allow>
  <default-xquery-version>1.0-ml</default-xquery-version>
  <multi-version-concurrency-control>contemporaneous</multi-version-concurrency-control>
  <distribute-timestamps>fast</distribute-timestamps>
  <output-sgml-character-entities>none</output-sgml-character-entities>
  <output-encoding>UTF-8</output-encoding>
  <output-method>default</output-method>
  <output-byte-order-mark>default</output-byte-order-mark>
  <output-cdata-section-namespace-uri/>
  <output-cdata-section-localname/>
  <output-doctype-public/>
  <output-doctype-system/>
  <output-escape-uri-attributes>default</output-escape-uri-attributes>
  <output-include-content-type>default</output-include-content-type>
  <output-indent>default</output-indent>
  <output-indent-untyped>default</output-indent-untyped>
  <output-media-type/>
  <output-normalization-form>none</output-normalization-form>
  <output-omit-xml-declaration>default</output-omit-xml-declaration>
  <output-standalone>omit</output-standalone>
  <output-undeclare-prefixes>default</output-undeclare-prefixes>
  <output-version/>
  <output-include-default-attributes>default</output-include-default-attributes>
  <schemas/>
  <namespaces/>
  <module-locations/>
  <request-blackouts/>
  <ssl-certificate-template>0</ssl-certificate-template>
  <ssl-allow-sslv3>true</ssl-allow-sslv3>
  <ssl-allow-tls>true</ssl-allow-tls>
  <ssl-hostname/>
  <ssl-ciphers>ALL:!LOW:@STRENGTH</ssl-ciphers>
  <ssl-require-client-certificate>true</ssl-require-client-certificate>
  <ssl-client-certificate-authorities/>
      </package-xdbc-properties>
      <links>
  <group-name>Default</group-name>
  <database>Documents</database>
      </links>
    </config>
  </package-xdbc-server>
</pkg:package-diff>
:)
//*:delta)

let $install-new-roxy-package :=
  if ($roxy-package-diffs-exists) then
    xdmp:http-post("http://localhost:8002/manage/v2/packages/Roxy/install", $options)[2]
    (:
      <install-status xmlns="http://marklogic.com/manage/package">
        <success>true</success>
        <restart>false</restart>
        <ticket-id>/tickets/ticket/11856236119101354375</ticket-id>
        <ticket-uri>/manage/v2/tickets/11856236119101354375</ticket-uri>
        <revert-uri>/manage/v2/tickets/11856236119101354375/revert</revert-uri>
      </install-status>
    :)
  else ()

return
  if ($install-new-roxy-package//*:restart = "true") then
    "Manual restart of MarkLogic Server required!" (: a.o. to release port if port number was changed :)
  else
    "Roxy XDBC server ready for use!"
grtjn commented 10 years ago

8999 might not be the best choice. The demo servers don't expose anything beyond 8100. Perhaps 8099? ;-)

grtjn commented 10 years ago

Related to issue #26, which is already solved, but doesn't provide a way to do an initial bootstrap of an xcc for Roxy.

grtjn commented 10 years ago

Important current draw-back to a shared xcc port is that MLCP doesn't support targeting multiple databases through one xcc port. I frequently use MLCP through Roxy (ml local mlcp ...), which doesn't work with the shared-xcc for that reason.

Will have to wait for an improved MLCP. And maybe the enhanced app servers of ML8 will also help..

grtjn commented 7 years ago

I think this ticket is outdated. How about just closing with won't fix? Slush-ml-node uses shared-xcc when possible, and Roxy has moved to using 8000 REST api for ML8+..