Comments (10)
I was mainly sharing my runScript task as a workaround :) (and for other uses ;)
from ml-gradle.
@dmcassel @grtjn How about the following design for a user:
- ml-schemas/qbv is now a "special" folder, similar to ml-schemas/tde.
- A file in the "qbv" directory should be either an sjs or xqy script that ends with
generateView("mySchema", "myView")
(user can pass in any args they want to that method).
When the user deploys their app or loads schemas, ml-gradle will then send each script to /v1/eval, which will return an XML plan:query-based-view
. ml-gradle then sends that to /v1/documents to insert the schema - or the eval call does that as well.
I think collections.properties
and permissions.properties
would then be applied to the XML view that's sent to /v1/documents. Though the special QBV collection will automatically be added, just like what's done for a TDE template.
That seem like a good design?
from ml-gradle.
Good idea @dmcassel - just curious, do you have a custom task or anything that does this already?
This would be a nice addition for all the Optic-based testing we do on our connectors too; we typically only use TDE's. Having this would make it easier to include QBV's for testing, to at least sanity check that those work fine too.
from ml-gradle.
@rjrudin I don't have a custom task yet. This idea came from exploring the QBV feature and thinking about how to deploy it. I can picture a custom task that would include the query and do the insert, but I haven't written one.
from ml-gradle.
We have deployed QBVs by pre-generating them in QC or such, although we have a Task that can evaluate adhoc queries too (I'll share below). Once generated, you can put them in ml-schemas/qbv/ (folder is arbitrary I think). Put a collections.properties next to it which adds 'http://marklogic.com/xdmp/qbv'. permissions.properties works in the same way as with TDEs, although it is suggested to use/add 'query-view-admin'. mlLS works well after that.
Here my runScript task, which expects either -Pxquery={path} or -Pjavascript={path}, and also supports a -Poutput={path}. It is not well tested, but seems to work fine so far:
def decodeMultipart(responseEntity) {
def boundary = responseEntity.getHeaders().getFirst('Content-Type').replaceAll(/^.*boundary=(.*)$/, '$1')
def parts = responseEntity.getBody().replace('\r\n', '\n').replace('\r', '\n').split('--' + boundary)
def body = ''
parts.each {
def splits = it.split('\n\n')
if (splits.length > 1) {
body = body + splits[1];
}
}
return body
}
def runScript(xquery, jscript) {
def url = mlHost + ":" + mlAppServicesPort + '/v1/eval'
logger.lifecycle('Running script ' + (xquery ?: jscript))
try {
def manageConfig = getProject().property("mlManageConfig")
if (mlAppServicesSimpleSsl == 'true') {
manageConfig.setScheme("https")
manageConfig.setConfigureSimpleSsl(true)
} else {
manageConfig.setScheme("http")
manageConfig.setConfigureSimpleSsl(false)
}
def manageClient = new com.marklogic.mgmt.ManageClient(manageConfig)
def code = resolveTokens(new File(xquery ?: jscript).getText('UTF-8'))
def body = decodeMultipart(manageClient.postForm("/v1/eval", xquery ? "xquery" : "javascript", code))
logger.debug("Success: ${body}")
return body
} catch (java.net.ConnectException ex) {
logger.warn("Host not reachable: "+ mlHost + ":" + mlAppServicesPort)
} catch (Exception ex) {
logger.error("Running script failed:" + ex.getMessage())
}
}
task runScript(group: project.name) {
doLast {
def xquery = project.findProperty("xquery")
def jscript = project.findProperty("jscript")
if (xquery == '' && jscript == '') {
logger.error('-' * 30)
logger.error('ERR: No script provided. Use -Pxquery=.. or -Pjscript=.. to provide a script.')
}
def body = runScript(xquery, jscript)
def file = project.findProperty("output")
if (file) {
logger.lifecycle("Results written to " + file)
new File(file).write(body)
} else {
print body
}
}
}
from ml-gradle.
We have deployed QBVs by pre-generating them in QC or such, although we have a Task that can evaluate adhoc queries too (I'll share below). Once generated, you can put them in ml-schemas/qbv/ (folder is arbitrary I think). Put a collections.properties next to it which adds 'http://marklogic.com/xdmp/qbv'. permissions.properties works in the same way as with TDEs, although it is suggested to use/add 'query-view-admin'. mlLS works well after that.
I considered the idea of using QC to generate, then writing the results and using mlLoadSchemas
to deploy. While that would work, the what we'd have in git is an artifact, rather than code we could reasonably work with. If we wanted to make a modification to the QBV, the file in git would be the artifact rather than the original query.
What you provided is interesting for ad hoc queries; thanks!
from ml-gradle.
Yeah, you want to have the code in the repo as well. We wanted to have both. That is the reason why I came up with the runScript task. We put the code in src/main/runScripts/. You can still decide to copy-paste it into QC, and run it from there.
But I can see why generating, and including it in deployment automatically would be convenient.
from ml-gradle.
@dmcassel @grtjn - I've created a PR for this feature in the ml-javaclient-util project. Check it out and let me know if you have any thoughts: marklogic/ml-javaclient-util#182
from ml-gradle.
@BillFarber I haven't tested it, but from the code I think it looks great -- thanks for taking this on!
from ml-gradle.
This is all implemented in ml-javaclient-util.
from ml-gradle.
Related Issues (20)
- Add a test case to an existing test suite HOT 3
- Cannot set app server authentication to "digestbasic" HOT 1
- mlNewProject fails in 4.5.0 when no authentication information exists HOT 3
- Feature Request: back up db and restore db tasks HOT 1
- mlDeploy failed due to LDAP validation error HOT 1
- Document how to generate an options file when using MLCP HOT 1
- Upgrade Spring to 5.3.26 to address CVE 2023-20860
- Automatically generate temp certificate HOT 2
- mlDeploy unable to handle misconfigured module database HOT 1
- CorbTask not working with Corb 2.5.1, 2.5.2, 2.5.3, nor 2.5.4 HOT 3
- Issue with Specifying Relative Module Paths in build.gradle HOT 3
- Feature request - append for mlBundle HOT 5
- mlBundle - example project - remove Plugin from reference HOT 1
- MlcpTask fails when switching to MarkLogic version 11.1.0 HOT 1
- Can't add secure credential with certificates HOT 2
- username required on mlInit HOT 3
- logOutputUri on MlcpTask fails when build directory does not exist
- Update MLCP example project for MLCP 11.2.0 HOT 1
- Gradle plugins not able to resolve plugins dependencies HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ml-gradle.