Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cicero-server not working offline: options are not passed to "Template.fromDirectory()" in "initTemplateInstance()" #734

Open
mgiofinc opened this issue Mar 21, 2022 · 7 comments
Labels
Difficulty: Starter Good First Issue :octocat: Good for newcomers Type: Documentation 📝 Information and guides for clarification Type: Feature Request 🛍️ New feature or request

Comments

@mgiofinc
Copy link

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

  1. Install cicero-server as explained in the Readme.md
  2. Do the Draft request call (it will download external models)
  3. 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
    }
}'
  1. 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);
}
@dselman dselman added Type: Feature Request 🛍️ New feature or request Good First Issue :octocat: Good for newcomers Type: Documentation 📝 Information and guides for clarification Difficulty: Starter labels Mar 21, 2022
@dselman
Copy link
Contributor

dselman commented Mar 21, 2022

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?

@mehmettokgoz
Copy link
Contributor

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.

@mgiofinc
Copy link
Author

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?

@mehmettokgoz
Copy link
Contributor

@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.

@mgiofinc
Copy link
Author

mgiofinc commented Jan 3, 2023

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.

@AMalfez
Copy link

AMalfez commented Oct 15, 2023

Hi!
Is someone still working on this?
If not can i ?
Thanks...

@thepiyush-303
Copy link

Hello,
I would love to contribute in this organization.
can I ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Starter Good First Issue :octocat: Good for newcomers Type: Documentation 📝 Information and guides for clarification Type: Feature Request 🛍️ New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants