-
Notifications
You must be signed in to change notification settings - Fork 66
Allow execute_query with app_name set to ml.app-name #661
Comments
I marked it as bug as the missing app_name feature is pretty severe. We could further improve on this, by discovering the rest-port from app_name. I think I did something similar with capturing of app-builder projects, which are rest-based too.. |
Even nicer would be having an invoke_query command, which takes modules-uri, and list of name/value pairs. Could make use of /v1/invoke, but would mean ML8+ support only. xcc invoke was never implemented from the looks of it.. |
Added functionality to adjust replica setup when scaling out. This includes redistribution of replicas by creating new ones where needed and marking the old ones for delete. Additional functions for cleaning up once the new replicas are sync replication.
Updated default replica count to 1, which is the minimum. Use downcase vs explicit strings.
Updated default replica count to 1, which is the minimum. Use downcase vs explicit strings.
The above mentioned patch only works for rest and hybrid projects, and app-level auth might interfere as well. A more robust method is this: def execute_query_8(query, properties = {})
if properties[:app_name] != nil && properties[:app_name] != @properties["ml.app-name"]
raise ExitException.new("Executing queries with an app_name (currently) not supported with ML8+")
end
headers = {
"Content-Type" => "application/x-www-form-urlencoded"
}
params = {
:locale => LOCALE,
:tzoffset => "-18000"
}
port = @qconsole_port
if properties[:app_name] != nil
params[:xquery] = %Q{
xquery version "1.0-ml";
let $query := <query><![CDATA[#{query}]]></query>
return xdmp:eval(
string($query),
(),
<options xmlns="xdmp:eval">
<database>{xdmp:database("#{@properties["ml.content-db"]}")}</database>
<modules>{xdmp:database("#{@properties["ml.modules-db"]}")}</modules>
</options>
)
}
else
params[:xquery] = query
end
if properties[:db_name] != nil
params[:database] = properties[:db_name]
end
r = go "#{@protocol}://#{@hostname}:#{port}/v1/eval", "post", headers, params
raise ExitException.new(JSON.pretty_generate(JSON.parse(r.body))) if r.body.match(/\{"error"/)
r
end |
Tested above with this code: def test
logger.info "Execute query with no params:"
r = execute_query(
%Q{
xquery version "1.0-ml";
"content-db: " || xdmp:database-name(xdmp:database()),
"modules-db: " || xdmp:database-name(xdmp:modules-database()),
"schemas-db: " || xdmp:database-name(xdmp:schema-database()),
"trigger-db: " || xdmp:database-name(xdmp:triggers-database())
}
)
r.body = parse_body r.body
logger.info r.body
logger.info ""
logger.info "Execute query with db_name param:"
r = execute_query(
%Q{
xquery version "1.0-ml";
"content-db: " || xdmp:database-name(xdmp:database()),
"modules-db: " || xdmp:database-name(xdmp:modules-database()),
"schemas-db: " || xdmp:database-name(xdmp:schema-database()),
"trigger-db: " || xdmp:database-name(xdmp:triggers-database())
},
{ :db_name => @properties['ml.content-db'] }
)
r.body = parse_body r.body
logger.info r.body
logger.info ""
logger.info "Execute query with app_name param:"
r = execute_query(
%Q{
xquery version "1.0-ml";
"content-db: " || xdmp:database-name(xdmp:database()),
"modules-db: " || xdmp:database-name(xdmp:modules-database()),
"schemas-db: " || xdmp:database-name(xdmp:schema-database()),
"trigger-db: " || xdmp:database-name(xdmp:triggers-database())
},
{ :app_name => @properties['ml.app-name'] }
)
r.body = parse_body r.body
logger.info r.body
logger.info ""
end |
It should probably also take modules-root into account, but I leave that as exercise.. |
We might also want to print a note that it might behave differently than it used to do if using app_name. A call to |
Also, the eval negates the database param.. |
Looking back through history, Roxy never used XCC eval, but has always relied on QC for eval in the past. My comment on xdmp:server returning wrong id has always applied, and can be neglected in that sense. It is a valid short-coming of Roxy, but one that has always existed. And the eval indeed ignores the database param, but that is appropriate. One is supposed to call execute_query with either an app_name or a db_name, not both. If db_name is provided, the xdmp:eval is skipped, and query gets evaluated directly, while taking database param into account.. |
…ovide appropriate context
…ovide appropriate context
Fixed #661: wrap app_name query in xdmp:eval to provide appropriate context
Fixed in dev |
I changed execute_query_8 as shown below, and that allows me to at least invoke modules of current project with for instance:
Patch for server_config.rb:
The text was updated successfully, but these errors were encountered: