apache / openwhisk-wskdeploy

Apache OpenWhisk utility for deploying and managing OpenWhisk projects and packages
https://openwhisk.apache.org/
Apache License 2.0
77 stars 74 forks source link

Referencing code from a dependent package leads to error #966

Closed van-ibm closed 6 years ago

van-ibm commented 6 years ago

The scenario I'd like to support is referencing (i.e. reusing) code from another package. To do so, I simply create a dependency on the external package and reference the action:

    dependencies:
      jsonetl:
        location: github.com/van-ibm/openwhisk-jsonetl
    actions:
      request-all-orgs:
        function: Packages/jsonetl-master/dist/Request.js
        runtime: nodejs:8

A problem arises in the order of operations for downloading the package code. If you were to paste the above code into your manifest.yaml and wskdeploy, you'd get:

Error: manifestreader.go [93]: [ERROR_YAML_FILE_FORMAT_ERROR]: File: [manifest.yaml]:
==> open /Users/vanstaub/git-public/cloud-functions-usage-examples/Packages/jsonetl-master/dist/Request.js: no such file or directory

That's because the actions stanza evidently gets processed before the dependency stanza. So the referenced code does not yet exist on disk leading to the error. The simple fix is to first declare the dependency and then run wskdeploy --preview. Then add your actions after the package id downloaded. But a more ideal solution is to download the dependency first and then process the actions stanza.

mrutkows commented 6 years ago

@van-ibm the wskdeploy parser is not sequential; your problem appears to stem from the fact that you do not have a well-formed manifest (YAML). I tried:

packages:
    test3:
        dependencies:
          jsonetl:
            location: github.com/van-ibm/openwhisk-jsonetl
        actions:
          request-all-orgs:
            function: Packages/jsonetl-master/dist/Request.js
            runtime: nodejs:8

and it parsed and deployed just fine. I substituted a simple "hello" function inside the Request.js file.

Of course, I note in the sample you provided the actual dependency "jsonetl" was not referenced anywhere, so had no impact on deployment in this case.

van-ibm commented 6 years ago

The use case is that I want to reference the file Packages/jsonetl-master/dist/Request.js. By creating a mock Request.js you prevent the issue. Had you attempted the manifest as written without further modification, I expect the error would have occurred.

The purpose of the use case is to re-use the Packages/jsonetl-master/dist/Request.js and assign inputs to the action. Here's an example of doing so:

request-accounts:
        function: Packages/jsonetl-master/dist/Request.js
        runtime: nodejs:8
        inputs:
          _url: https://accountmanagement.bluemix.net/coe/v2/getaccounts
          _bearer: ${UAA_TOKEN}

The request-accounts action will always use the statically defined _url. You might then say, "Why not just supply _url as an input parameter upon invocation?" The answer is because once the action is part of a sequence, that input parameter is lost unless upstream actions continue to forward it. So this gives me a way to bake in parameters for actions that exist within sequences. If there is a better way to achieve this, I'm open to alternate approaches.

van-ibm commented 6 years ago

Another approach I've considered is having "echo" actions that set up the params in the manifest.yaml and simply return them. You'd then insert these echo actions just before the external package's action in a sequence. The reason I didn't originally favor it was that it doubles the number of actions (one echo plus the desire package action).

van-ibm commented 6 years ago

And after chatting with Carlos, I think I'm going to go with a different approach. Either echoing or Composer. Closing as working-as-designed.