Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-37042

Eventing CLI tools (cURL and couchbase-cli) should be able import Functions exported by the other tool

    XMLWordPrintable

Details

    Description

      As alluded to MB-37040 all modes of exporting a function UI, cURL and couchbase-cli should be cross compatible.

      In other words an export via the on of the following UI, cURL or couchbase-cli  should be able to be imported by any of  the other two other methods.

      Given a function/handler for Eventing Function/Handler named "once_daily" it could be any Function - we then export the function 3 ways to three different files

      1. UI button to "once_daily.ui.export.json"
       
      Use the UI's export button in the Eventing tab and rename this file to once_daily.ui.export.json
       
      2. CURL CLI method to "once_daily.curl.export.json"
       
      curl -X GET  -s http://${CB_USERNAME}:${CB_PASSWORD}@localhost:8096/api/v1/functions/once_daily --output once_daily.curl.export.json
       
      3. couchbase-cli CLI method to "once_daily.couchbase-cli.export.json"
       
      couchbase-cli eventing-function-setup -c localhost -u $CB_USERNAME -p $CB_PASSWORD --export --name once_daily --file once_daily.couchbase-cli.export.json
      

      Here we see that the UI and the cURL exports are identical

      	# ls -ltr *.json
      	-rw-r--r--@ 1 jon.strabala  staff  5565 Nov 23 13:19 once_daily.ui.export.json
      	-rw-r--r--  1 jon.strabala  staff  5565 Nov 23 13:36 once_daily.couchbase-cli.export.json
      	-rw-r--r--  1 jon.strabala  staff  5814 Nov 23 16:22 once_daily.curl.export.json
      	# sum *.json
      	25681 6 once_daily.couchbase-cli.export.json
      	21396 6 once_daily.curl.export.json
      	25681 6 once_daily.ui.export.json
      	# diff once_daily.couchbase-cli.export.json once_daily.couchbase-cli.export.json
      	# 
      

      So we see two unique formats #1 (the UI and couchbase-cli format) and #2 (the cURL format).

      Now lets try a 'cross import' via the UI, cURL, and couchbase-cli

      1. The UI seems to work for both variants, e.g. it can import any of the files we just made.
       
              Use the UI's import button in the Eventing tab across all three files (and delete)
       
      	  once_daily.couchbase-cli.export.json 
      	  once_daily.ui.export.json
      	  once_daily.curl.export.json 
       
      2. CURL CLI try to "cross load" either once_daily.couchbase-cli.export.json or once_daily.ui.export.jso
       
      	curl -s -X POST -d @./once_daily.couchbase-cli.export.json  -s http://${CB_USERNAME}:${CB_PASSWORD}@localhost:8096/api/v1/functions/once_daily
      	{
      	 "name": "ERR_UNMARSHAL_PLD",
      	 "code": 16,
      	 "description": "Unable to unmarshal payload",
      	 "attributes": null,
      	 "runtime_info": {
      	  "code": 16,
      	  "info": "Failed to unmarshal payload err: json: cannot unmarshal array into Go value of type servicemanager.application"
      	 }
      	}
       
      3. couchbase-cli CLI try to "cross load" once_daily.curl.export.json
       
      	couchbase-cli eventing-function-setup -c localhost -u $CB_USERNAME -p $CB_PASSWORD --import --name verifier_01w_inst01 --file once_daily.curl.export.json
      	ERROR: name - ERR_UNMARSHAL_PLD
      	ERROR: code - 16
      	ERROR: description - Unable to unmarshal payload
      	ERROR: attributes - None
      	ERROR: runtime_info - {'code': 16, 'info': 'Failed to unmarshal payload err: json: cannot unmarshal object into Go value of type []servicemanager.application'}
      

      Summary

      The UI seems capable of importing either format (all exported files), however the CLI tools cURL and couchbase-cli can not "cross load" the other format.

      Attachments

        Issue Links

          For Gerrit Dashboard: MB-37042
          # Subject Branch Project Status CR V

          Activity

            jon.strabala Jon Strabala added a comment -

            (mistake in the description - I used the wrong function name)

            3. couchbase-cli CLI try to "cross load" once_daily.curl.export.json
             
            couchbase-cli eventing-function-setup -c localhost -u $CB_USERNAME -p $CB_PASSWORD --import --name once_daily --file once_daily.curl.export.json
            ERROR: name - ERR_UNMARSHAL_PLD
            ERROR: code - 16
            ERROR: description - Unable to unmarshal payload
            ERROR: attributes - None
            ERROR: runtime_info - {'code': 16, 'info': 'Failed to unmarshal payload err: json: cannot unmarshal object into Go value of type []servicemanager.application'}
            HQ-0460:TEST jon.strabala$ 
            

            jon.strabala Jon Strabala added a comment - (mistake in the description - I used the wrong function name) 3. couchbase-cli CLI try to "cross load" once_daily.curl.export.json   couchbase-cli eventing-function-setup -c localhost -u $CB_USERNAME -p $CB_PASSWORD --import --name once_daily --file once_daily.curl.export.json ERROR: name - ERR_UNMARSHAL_PLD ERROR: code - 16 ERROR: description - Unable to unmarshal payload ERROR: attributes - None ERROR: runtime_info - {'code': 16, 'info': 'Failed to unmarshal payload err: json: cannot unmarshal object into Go value of type []servicemanager.application'} HQ-0460:TEST jon.strabala$

            The problem is that UI and CLI versions wrap handlers with an array ([{}, {}]) while the cURL endpoint does not. Unfortunately, it is legacy UI code that wraps the single exported handler in an unnecessary array but we can't change it now as people may have old handlers exported. Hence, we need to update the curl endpoint to strip a single unexpected array nesting.

            siri Sriram Melkote (Inactive) added a comment - The problem is that UI and CLI versions wrap handlers with an array ( [{}, {}] ) while the cURL endpoint does not. Unfortunately, it is legacy UI code that wraps the single exported handler in an unnecessary array but we can't change it now as people may have old handlers exported. Hence, we need to update the curl endpoint to strip a single unexpected array nesting.
            jeelan.poola Jeelan Poola added a comment -

            This is simple change in REST layer and we want to fix this in 6.6.0

            jeelan.poola Jeelan Poola added a comment - This is simple change in REST layer and we want to fix this in 6.6.0

            Build couchbase-server-7.0.0-1896 contains eventing commit f0db73e with commit message:
            MB-37042: Pass valid json string for unmarshalling

            build-team Couchbase Build Team added a comment - Build couchbase-server-7.0.0-1896 contains eventing commit f0db73e with commit message: MB-37042 : Pass valid json string for unmarshalling

            Build couchbase-server-6.6.0-7567 contains eventing commit 10e24f5 with commit message:
            MB-37042: Pass valid json string for unmarshalling

            build-team Couchbase Build Team added a comment - Build couchbase-server-6.6.0-7567 contains eventing commit 10e24f5 with commit message: MB-37042 : Pass valid json string for unmarshalling

            verified on  6.6.0 build 7839, added test as well

            vikas.chaudhary Vikas Chaudhary added a comment - verified on  6.6.0 build 7839, added test as well

            People

              ankit.prabhu Ankit Prabhu
              jon.strabala Jon Strabala
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty