template-archive
template-archive copied to clipboard
Cicero-server not working offline: options are not passed to "Template.fromDirectory()" in "initTemplateInstance()"
Bug Report 🐛
When Template.fromDirectory()
is called within initTemplateInstance()
(in packages/cicero-server/app.js
), the options are not passed.
This in particular prevents to use cicero-server
offline.
Expected Behavior
When "offline" option is set true
in the request body, cicero-server
does not try to update external models.
Current Behavior
When "offline" option is set true
in the request body, cicero-server
tries anyway to update external models.
Steps to Reproduce
- Install
cicero-server
as explained in theReadme.md
- Do the
Draft request
call (it will download external models) - Go offline and do the following call:
curl --request POST \
--url http://localhost:6001/draft/latedeliveryandpenalty \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
"data": {
"$class": "org.accordproject.latedeliveryandpenalty.LateDeliveryAndPenaltyContract",
"contractId": "ecd6257e-2ffe-4ef1-8a5c-38ca9084a829",
"buyer": {
"$class": "org.accordproject.cicero.contract.AccordParty",
"partyId": "Dan"
},
"seller": {
"$class": "org.accordproject.cicero.contract.AccordParty",
"partyId": "Steve"
},
"forceMajeure": true,
"penaltyDuration": {
"$class": "org.accordproject.time.Duration",
"amount": 9,
"unit": "days"
},
"penaltyPercentage": 1000.5,
"capPercentage": 88,
"termination": {
"$class": "org.accordproject.time.Duration",
"amount": 5,
"unit": "weeks"
},
"fractionalPart": "days"
},
"options": {
"unquoteVariables": true,
"offline": true <------------------------------ ADDED OPTION
}
}'
- The following error is returned:
Error: Failed to load model file. Job: https://models.accordproject.org/accordproject/contract.cto Details: Error: getaddrinfo EAI_AGAIN models.accordproject.org
at PromisePoolExecutor.handleJobError [as errorHandler] (/usr/local/lib/node_modules/@accordproject/cicero-server/node_modules/@accordproject/concerto-core/lib/introspect/loaders/modelfiledownloader.js:31:11)
at /usr/local/lib/node_modules/@accordproject/cicero-server/node_modules/@supercharge/promise-pool/dist/promise-pool-executor.js:154:29
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Promise.all (index 0)
at async PromisePoolExecutor.drainActiveTasks (/usr/local/lib/node_modules/@accordproject/cicero-server/node_modules/@supercharge/promise-pool/dist/promise-pool-executor.js:187:9)
at async PromisePoolExecutor.drained (/usr/local/lib/node_modules/@accordproject/cicero-server/node_modules/@supercharge/promise-pool/dist/promise-pool-executor.js:177:9)
at async PromisePoolExecutor.start (/usr/local/lib/node_modules/@accordproject/cicero-server/node_modules/@supercharge/promise-pool/dist/promise-pool-executor.js:85:16)
at async APModelManager.updateExternalModels (/usr/local/lib/node_modules/@accordproject/cicero-server/node_modules/@accordproject/concerto-core/lib/modelmanager.js:276:36)
at async APModelManager.addAPModelFiles (/usr/local/lib/node_modules/@accordproject/cicero-server/node_modules/@accordproject/ergo-compiler/lib/apmodelmanager.js:102:40)
Possible Implementation
Change initTemplateInstance()
with something like:
async function initTemplateInstance(req) {
let options = {};
if(Object.prototype.hasOwnProperty.call(req.body,'options')) {
options = req.body.options;
}
const template = await Template.fromDirectory(`${process.env.CICERO_DIR}/${req.params.template}`, options);
return new Clause(template);
}
Thanks for the report. I agree that allowing Cicero server to be used offline would be useful. It sounds like adding a new environment variable to specify offline usage of the server would be a good idea?
Thanks for the report @mgiofinc 🙌
This support is now added for cicero-server
. See the new template loading function: cicero-server/app.js#L273. When we merge open PRs for other methods, all of them will allow you to pass options
in the request body.
Thanks for the update @mehmettokgoz.
Unfortunately it seems it only applies to /invoke/:template
, but not to /trigger/:template
, /parse/:template
and /draft/:template
.
Could it be extended also to them?
@mgiofinc Yes, that's right. I didn't refactor trigger
, parse
and draft
yet but they will be updated accordingly. Additionally, initialize
, normalize
, get
, compile,
and archive
methods have this support natively. You can see the implementations from cicero/pulls.
Hello and happy new year!
@mehmettokgoz I was wondering if it is there any update about the refactoring of /trigger/:template
, /parse/:template
and /draft/:template
.
Thanks in advance.
Hi! Is someone still working on this? If not can i ? Thanks...