Uploaded image for project: 'Couchbase C client library libcouchbase'
  1. Couchbase C client library libcouchbase
  2. CCBC-1289

Travel Sample Application equivalent

    XMLWordPrintable

Details

    Description

      Port the Travel Sample Application backend server REST API to LCB 3.2.0, including multi-tenant support using Scopes and Collections. In short, the goal is to support all of the methods of the Swagger API specification, so the frontend-v2 can just use this version of the backend (as it would any other backend) to demonstrate a libcouchbase implementation of the same features.

      NOTES

      1. An incremental approach is preferred so we can get something out there soon and improve later.
      2. CCBC-1427 was spawned to suggest that we refactor a bit more to implement a fully async sample.

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            Hakim Cassimally Sorry for the late reply, but only thing I can think of is that it was a transient issue with the state of one of the dependencies and it has since been resolved. I can no longer reproduce that problem either. It was clearly a Vue dependency conflict previously, but nothing I've tried since has been able to reproduce the problem.

            ray.cardillo Ray Cardillo added a comment - Hakim Cassimally Sorry for the late reply, but only thing I can think of is that it was a transient issue with the state of one of the dependencies and it has since been resolved. I can no longer reproduce that problem either. It was clearly a Vue dependency conflict previously, but nothing I've tried since has been able to reproduce the problem.
            maria.shodunke Maria Shodunke added a comment - - edited

            Hey Ray Cardillo , wonder if you can help, I've been trying to test the `backend` docker setup since the FE seems to be working.

            The current Dockerfile https://github.com/couchbaselabs/try-cb-lcb/blob/master/Dockerfile doesn't install any of the dependencies required for the project (i.e libcouchbase, cjson etc), so I tried to use the `apk` package manager (as the kore image seems to be based on Alpine Linux) to install them. Unfortunately, I was not able to install the `libjwt` package, doesn’t seem to be available? https://repology.org/project/libjwt/versions 

            To mitigate this I tried to use an Ubuntu based docker image instead and was able to install all the required dependencies, including `libjwt`.

            FROM ubuntu:20.04
             
            ENV TZ=America/Los_Angeles
            RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
             
            LABEL maintainer="Couchbase"
             
            RUN mkdir -p /try-cb-lcb
             
            ADD . /try-cb-lcb
             
            WORKDIR /try-cb-lcb
             
            RUN apt-get update -y && apt-get install -y \
                software-properties-common \
                build-essential \
                libssl-dev libjwt-dev libcjson-dev \
                kore jq curl wget
             
            # Configure APT repository for libcouchbase
            RUN wget https://packages.couchbase.com/clients/c/repos/deb/couchbase.key \
                && apt-key add ./couchbase.key \
                && rm ./couchbase.key \
                && apt-add-repository "deb https://packages.couchbase.com/clients/c/repos/deb/ubuntu2004 focal focal/main" \
                && apt-get update
             
            # Install libcouchbase
            RUN apt-get install -y libcouchbase3 \
                libcouchbase-dev libcouchbase3-tools \
                libcouchbase-dbg libcouchbase3-libev \
                libcouchbase3-libevent
             
            RUN kodev clean && kodev build
             
            # Expose ports
            EXPOSE 8080
             
            # Set the entrypoint
            ENTRYPOINT ["./wait-for-couchbase.sh", "kore", "-c", "conf/try-cb-lcb.conf"]
            

             

            However, I get a compilation error:

             ------
             > [9/9] RUN kodev clean && kodev build:
             #13 0.623 src/api-user-flights.c:132:36: error: unknown type name '__unused'; did you mean 'ossl_unused'?
             #13 0.623 132 | static void flight_upsert_callback(__unused lcb_INSTANCE *instance, void *cookie, const lcb_RESPSTORE *resp)
             #13 0.623 | ^~~~~~~~
             #13 0.623 | ossl_unused
             #13 0.652 src/api-user-flights.c: In function 'upsert_new_flight':
             #13 0.652 src/api-user-flights.c:182:62: error: 'flight_upsert_callback' undeclared (first use in this function)
             #13 0.652 182 | store_delegate->callback = (tcblcb_RESPDELEGATE_CALLBACK)flight_upsert_callback;
             #13 0.652 | ^~~~~~~~~~~~~~~~~~~~~~
             #13 0.652 src/api-user-flights.c:182:62: note: each undeclared identifier is reported only once for each function it appears in
             #13 0.655 src/api-user-flights.c: At top level:
             #13 0.655 src/api-user-flights.c:214:37: error: unknown type name '__unused'; did you mean 'ossl_unused'?
             #13 0.655 214 | static void booking_subdoc_callback(__unused lcb_INSTANCE *instance, void *cookie, const lcb_RESPSUBDOC *resp)
             #13 0.655 | ^~~~~~~~
             #13 0.655 | ossl_unused
             #13 0.687 src/api-user-flights.c: In function 'add_user_booking':
             #13 0.687 src/api-user-flights.c:285:63: error: 'booking_subdoc_callback' undeclared (first use in this function)
             #13 0.687 285 | subdoc_delegate->callback = (tcblcb_RESPDELEGATE_CALLBACK)booking_subdoc_callback;
             #13 0.687 | ^~~~~~~~~~~~~~~~~~~~~~~
             #13 0.689 In file included from src/api-user-flights.c:26:
             #13 0.689 src/api-user-flights.c: In function 'tcblcb_api_user_flights_put':
             #13 0.689 src/util.h:87:53: error: invalid use of void expression
             #13 0.689 87 | #define IfFalseGotoDone(value, msg) IfTrueGotoDone((!(value)), msg)
             #13 0.689 | ^
             #13 0.689 src/util.h:82:5: note: in definition of macro 'IfTrueGotoDone'
             #13 0.689 82 | if (value) { \
             #13 0.689 | ^~~~~
             #13 0.689 src/api-user-flights.c:415:5: note: in expansion of macro 'IfFalseGotoDone'
             #13 0.689 415 | IfFalseGotoDone(
             #13 0.689 | ^~~~~~~~~~~~~~~
             #13 0.690 src/util.h:87:53: error: invalid use of void expression
             #13 0.690 87 | #define IfFalseGotoDone(value, msg) IfTrueGotoDone((!(value)), msg)
             #13 0.690 | ^
             #13 0.690 src/util.h:82:5: note: in definition of macro 'IfTrueGotoDone'
             #13 0.690 82 | if (value)
            { \ #13 0.690 | ^~~~~ #13 0.690 src/api-user-flights.c:422:5: note: in expansion of macro 'IfFalseGotoDone' #13 0.690 422 | IfFalseGotoDone( #13 0.690 | ^~~~~~~~~~~~~~~ #13 0.693 src/api-user-flights.c: At top level: #13 0.693 src/api-user-flights.c:471:41: error: unknown type name '__unused'; did you mean 'ossl_unused'? #13 0.693 471 | static void get_flight_booking_callback(__unused lcb_INSTANCE *instance, void *cookie, const lcb_RESPGET *resp) #13 0.693 | ^~~~~~~~ #13 0.693 | ossl_unused #13 0.726 src/api-user-flights.c: In function 'get_flight_booking': #13 0.726 src/api-user-flights.c:540:60: error: 'get_flight_booking_callback' undeclared (first use in this function); did you mean 'get_flight_booking'? #13 0.726 540 | get_delegate->callback = (tcblcb_RESPDELEGATE_CALLBACK)get_flight_booking_callback; #13 0.726 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ #13 0.726 | get_flight_booking #13 0.727 src/api-user-flights.c: In function 'user_bookings_subdoc_callback': #13 0.727 src/api-user-flights.c:602:66: warning: passing argument 1 of 'cJSON_GetStringValue' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] #13 0.727 602 | const char *booking_id_string = cJSON_GetStringValue(booking_id); #13 0.727 | ^~~~~~~~~~ #13 0.727 In file included from src/try-cb-lcb.h:30, #13 0.727 from src/api-user-flights.c:25: #13 0.727 /usr/include/cjson/cJSON.h:177:22: note: expected 'cJSON *' \{aka 'struct cJSON *'}
            but argument is of type 'const cJSON *' {aka 'const struct cJSON *'}
             #13 0.727 177 | CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item);
             #13 0.727 | ^~~~~~~~~~~~~~~~~~~~
             #13 0.727 In file included from src/api-user-flights.c:26:
             #13 0.727 src/api-user-flights.c:610:18: warning: too many arguments for format [-Wformat-extra-args]
             #13 0.727 610 | LogDebug("User bookings subdoc result was EMPTY", NULL);
             #13 0.727 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             #13 0.727 src/util.h:41:51: note: in definition of macro 'LogDebug'
             #13 0.727 41 | #define LogDebug(format, ...) kore_log(LOG_DEBUG, format, _VA_ARGS_);
             #13 0.727 | ^~~~~~
             #13 0.729 src/api-user-flights.c: In function 'tcblcb_api_user_flights_get':
             #13 0.729 src/util.h:87:53: error: invalid use of void expression
             #13 0.729 87 | #define IfFalseGotoDone(value, msg) IfTrueGotoDone((!(value)), msg)
             #13 0.729 | ^
             #13 0.729 src/util.h:82:5: note: in definition of macro 'IfTrueGotoDone'
             #13 0.729 82 | if (value) { \
             #13 0.729 | ^~~~~
             #13 0.729 src/api-user-flights.c:735:9: note: in expansion of macro 'IfFalseGotoDone'
             #13 0.729 735 | IfFalseGotoDone(
             #13 0.729 | ^~~~~~~~~~~~~~~
             #13 0.729 src/util.h:87:53: error: invalid use of void expression
             #13 0.729 87 | #define IfFalseGotoDone(value, msg) IfTrueGotoDone((!(value)), msg)
             #13 0.729 | ^
             #13 0.729 src/util.h:82:5: note: in definition of macro 'IfTrueGotoDone'
             #13 0.729 82 | if (value) { \
             #13 0.729 | ^~~~~
             #13 0.729 src/api-user-flights.c:742:9: note: in expansion of macro 'IfFalseGotoDone'
             #13 0.729 742 | IfFalseGotoDone(
             #13 0.729 | ^~~~~~~~~~~~~~~
             #13 0.742 building try-cb-lcb (dev)
             #13 0.742 CFLAGS=-Wall -Wpedantic -Wextra -Wshadow -fPIC -Isrc -Isrc/includes -I/usr/include -DKORE_USE_PGSQL -DKORE_USE_TASKS -I/usr/include/postgresql -g -DDEBUG 
             #13 0.742 LDFLAGS=-lcouchbase -lcjson -ljwt -shared 
             #13 0.742 building asset swagger.yaml
             #13 0.742 building asset swagger.json
             #13 0.742 compiling api-user-flights.c
             #13 0.742 kore build: subprocess trouble, check output
             ------
             executor failed running [/bin/sh -c kodev clean && kodev build]: exit code: 1

            Not sure why this happens in the linux docker environment because when I run on my actual host machine (Mac OSX), I don’t get these compilation errors.

            Do let me know if anything stands out in the Dockerfile that could be incorrect. Also if you see anything that stands out in the actual build output please let me know.

            Will park this for now as I’m also looking into the Ruby travel-sample app, but let me know if anything comes to mind! 

            https://github.com/maria-robobug/try-cb-lcb/tree/docker-fix (my forked repo if anyone wants to have a look)

            maria.shodunke Maria Shodunke added a comment - - edited Hey Ray Cardillo , wonder if you can help, I've been trying to test the `backend` docker setup since the FE seems to be working. The current Dockerfile https://github.com/couchbaselabs/try-cb-lcb/blob/master/Dockerfile  doesn't install any of the dependencies required for the project (i.e libcouchbase, cjson etc), so I tried to use the `apk` package manager (as the kore image seems to be based on Alpine Linux) to install them. Unfortunately, I was not able to install the `libjwt` package, doesn’t seem to be available? https://repology.org/project/libjwt/versions   To mitigate this I tried to use an Ubuntu based docker image instead and was able to install all the required dependencies, including `libjwt`. FROM ubuntu: 20.04   ENV TZ=America/Los_Angeles RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone   LABEL maintainer= "Couchbase"   RUN mkdir -p / try -cb-lcb   ADD . / try -cb-lcb   WORKDIR / try -cb-lcb   RUN apt-get update -y && apt-get install -y \ software-properties-common \ build-essential \ libssl-dev libjwt-dev libcjson-dev \ kore jq curl wget   # Configure APT repository for libcouchbase RUN wget https: //packages.couchbase.com/clients/c/repos/deb/couchbase.key \ && apt-key add ./couchbase.key \ && rm ./couchbase.key \ && apt-add-repository "deb https://packages.couchbase.com/clients/c/repos/deb/ubuntu2004 focal focal/main" \ && apt-get update   # Install libcouchbase RUN apt-get install -y libcouchbase3 \ libcouchbase-dev libcouchbase3-tools \ libcouchbase-dbg libcouchbase3-libev \ libcouchbase3-libevent   RUN kodev clean && kodev build   # Expose ports EXPOSE 8080   # Set the entrypoint ENTRYPOINT [ "./wait-for-couchbase.sh" , "kore" , "-c" , "conf/try-cb-lcb.conf" ]   However, I get a compilation error: ------ > [ 9 / 9 ] RUN kodev clean && kodev build: # 13 0.623 src/api-user-flights.c: 132 : 36 : error: unknown type name '__unused' ; did you mean 'ossl_unused' ? # 13 0.623 132 | static void flight_upsert_callback(__unused lcb_INSTANCE *instance, void *cookie, const lcb_RESPSTORE *resp) # 13 0.623 | ^~~~~~~~ # 13 0.623 | ossl_unused # 13 0.652 src/api-user-flights.c: In function 'upsert_new_flight' : # 13 0.652 src/api-user-flights.c: 182 : 62 : error: 'flight_upsert_callback' undeclared (first use in this function) # 13 0.652 182 | store_delegate->callback = (tcblcb_RESPDELEGATE_CALLBACK)flight_upsert_callback; # 13 0.652 | ^~~~~~~~~~~~~~~~~~~~~~ # 13 0.652 src/api-user-flights.c: 182 : 62 : note: each undeclared identifier is reported only once for each function it appears in # 13 0.655 src/api-user-flights.c: At top level: # 13 0.655 src/api-user-flights.c: 214 : 37 : error: unknown type name '__unused' ; did you mean 'ossl_unused' ? # 13 0.655 214 | static void booking_subdoc_callback(__unused lcb_INSTANCE *instance, void *cookie, const lcb_RESPSUBDOC *resp) # 13 0.655 | ^~~~~~~~ # 13 0.655 | ossl_unused # 13 0.687 src/api-user-flights.c: In function 'add_user_booking' : # 13 0.687 src/api-user-flights.c: 285 : 63 : error: 'booking_subdoc_callback' undeclared (first use in this function) # 13 0.687 285 | subdoc_delegate->callback = (tcblcb_RESPDELEGATE_CALLBACK)booking_subdoc_callback; # 13 0.687 | ^~~~~~~~~~~~~~~~~~~~~~~ # 13 0.689 In file included from src/api-user-flights.c: 26 : # 13 0.689 src/api-user-flights.c: In function 'tcblcb_api_user_flights_put' : # 13 0.689 src/util.h: 87 : 53 : error: invalid use of void expression # 13 0.689 87 | #define IfFalseGotoDone(value, msg) IfTrueGotoDone((!(value)), msg) # 13 0.689 | ^ # 13 0.689 src/util.h: 82 : 5 : note: in definition of macro 'IfTrueGotoDone' # 13 0.689 82 | if (value) { \ # 13 0.689 | ^~~~~ # 13 0.689 src/api-user-flights.c: 415 : 5 : note: in expansion of macro 'IfFalseGotoDone' # 13 0.689 415 | IfFalseGotoDone( # 13 0.689 | ^~~~~~~~~~~~~~~ # 13 0.690 src/util.h: 87 : 53 : error: invalid use of void expression # 13 0.690 87 | #define IfFalseGotoDone(value, msg) IfTrueGotoDone((!(value)), msg) # 13 0.690 | ^ # 13 0.690 src/util.h: 82 : 5 : note: in definition of macro 'IfTrueGotoDone' # 13 0.690 82 | if (value) { \ # 13 0.690 | ^~~~~ # 13 0.690 src/api-user-flights.c: 422 : 5 : note: in expansion of macro 'IfFalseGotoDone' # 13 0.690 422 | IfFalseGotoDone( # 13 0.690 | ^~~~~~~~~~~~~~~ # 13 0.693 src/api-user-flights.c: At top level: # 13 0.693 src/api-user-flights.c: 471 : 41 : error: unknown type name '__unused' ; did you mean 'ossl_unused' ? # 13 0.693 471 | static void get_flight_booking_callback(__unused lcb_INSTANCE *instance, void *cookie, const lcb_RESPGET *resp) # 13 0.693 | ^~~~~~~~ # 13 0.693 | ossl_unused # 13 0.726 src/api-user-flights.c: In function 'get_flight_booking' : # 13 0.726 src/api-user-flights.c: 540 : 60 : error: 'get_flight_booking_callback' undeclared (first use in this function); did you mean 'get_flight_booking' ? # 13 0.726 540 | get_delegate->callback = (tcblcb_RESPDELEGATE_CALLBACK)get_flight_booking_callback; # 13 0.726 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ # 13 0.726 | get_flight_booking # 13 0.727 src/api-user-flights.c: In function 'user_bookings_subdoc_callback' : # 13 0.727 src/api-user-flights.c: 602 : 66 : warning: passing argument 1 of 'cJSON_GetStringValue' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] # 13 0.727 602 | const char *booking_id_string = cJSON_GetStringValue(booking_id); # 13 0.727 | ^~~~~~~~~~ # 13 0.727 In file included from src/ try -cb-lcb.h: 30 , # 13 0.727 from src/api-user-flights.c: 25 : # 13 0.727 /usr/include/cjson/cJSON.h: 177 : 22 : note: expected 'cJSON *' \{aka 'struct cJSON *' } but argument is of type 'const cJSON *' {aka 'const struct cJSON *' } # 13 0.727 177 | CJSON_PUBLIC( char *) cJSON_GetStringValue(cJSON *item); # 13 0.727 | ^~~~~~~~~~~~~~~~~~~~ # 13 0.727 In file included from src/api-user-flights.c: 26 : # 13 0.727 src/api-user-flights.c: 610 : 18 : warning: too many arguments for format [-Wformat-extra-args] # 13 0.727 610 | LogDebug( "User bookings subdoc result was EMPTY" , NULL); # 13 0.727 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 13 0.727 src/util.h: 41 : 51 : note: in definition of macro 'LogDebug' # 13 0.727 41 | #define LogDebug(format, ...) kore_log(LOG_DEBUG, format, _VA_ARGS_); # 13 0.727 | ^~~~~~ # 13 0.729 src/api-user-flights.c: In function 'tcblcb_api_user_flights_get' : # 13 0.729 src/util.h: 87 : 53 : error: invalid use of void expression # 13 0.729 87 | #define IfFalseGotoDone(value, msg) IfTrueGotoDone((!(value)), msg) # 13 0.729 | ^ # 13 0.729 src/util.h: 82 : 5 : note: in definition of macro 'IfTrueGotoDone' # 13 0.729 82 | if (value) { \ # 13 0.729 | ^~~~~ # 13 0.729 src/api-user-flights.c: 735 : 9 : note: in expansion of macro 'IfFalseGotoDone' # 13 0.729 735 | IfFalseGotoDone( # 13 0.729 | ^~~~~~~~~~~~~~~ # 13 0.729 src/util.h: 87 : 53 : error: invalid use of void expression # 13 0.729 87 | #define IfFalseGotoDone(value, msg) IfTrueGotoDone((!(value)), msg) # 13 0.729 | ^ # 13 0.729 src/util.h: 82 : 5 : note: in definition of macro 'IfTrueGotoDone' # 13 0.729 82 | if (value) { \ # 13 0.729 | ^~~~~ # 13 0.729 src/api-user-flights.c: 742 : 9 : note: in expansion of macro 'IfFalseGotoDone' # 13 0.729 742 | IfFalseGotoDone( # 13 0.729 | ^~~~~~~~~~~~~~~ # 13 0.742 building try -cb-lcb (dev) # 13 0.742 CFLAGS=-Wall -Wpedantic -Wextra -Wshadow -fPIC -Isrc -Isrc/includes -I/usr/include -DKORE_USE_PGSQL -DKORE_USE_TASKS -I/usr/include/postgresql -g -DDEBUG # 13 0.742 LDFLAGS=-lcouchbase -lcjson -ljwt -shared # 13 0.742 building asset swagger.yaml # 13 0.742 building asset swagger.json # 13 0.742 compiling api-user-flights.c # 13 0.742 kore build: subprocess trouble, check output ------ executor failed running [/bin/sh -c kodev clean && kodev build]: exit code: 1 Not sure why this happens in the linux docker environment because when I run on my actual host machine (Mac OSX), I don’t get these compilation errors. Do let me know if anything stands out in the Dockerfile that could be incorrect. Also if you see anything that stands out in the actual build output please let me know. Will park this for now as I’m also looking into the Ruby travel-sample app, but let me know if anything comes to mind!  https://github.com/maria-robobug/try-cb-lcb/tree/docker-fix  (my forked repo if anyone wants to have a look)
            ray.cardillo Ray Cardillo added a comment - - edited

            Maria Shodunke I didn't try building on anything other than macOS at the moment, but from the errors I saw here, I suspect the problem is that gcc doesn't use C11 by default. To fix this, make the following change to the cflags in the conf/build.conf file shared section up top.

            Change this line:

            # The flags below are shared between flavors
            cflags=-Wall -Wpedantic -Wextra -Wshadow
            

            To this (notice we're adding the option (-std=c11):

            # The flags below are shared between flavors
            cflags=-std=c11 -Wall -Wpedantic -Wextra -Wshadow
            


            If this doesn't do the trick then maybe we can do a quick Zoom meeting or I can review your branch and take a more careful look.

            ray.cardillo Ray Cardillo added a comment - - edited Maria Shodunke I didn't try building on anything other than macOS at the moment, but from the errors I saw here, I suspect the problem is that gcc doesn't use C11 by default. To fix this, make the following change to the cflags in the conf/build.conf file shared section up top. Change this line: # The flags below are shared between flavors cflags=-Wall -Wpedantic -Wextra -Wshadow To this (notice we're adding the option ( -std=c11 ): # The flags below are shared between flavors cflags=-std=c11 -Wall -Wpedantic -Wextra -Wshadow If this doesn't do the trick then maybe we can do a quick Zoom meeting or I can review your branch and take a more careful look.

            Ray Cardillo, Maria Shodunke and I have made progress, latest PR is https://github.com/raycardillo/try-cb-lcb/commit/d107feeaeb769a123b4a070cf3276f7ccce92b19 with my fixes for Ubuntu Linux / Docker build, and Ray's fixes for local OSX.

            Assigning to me to re-test and verify the OSX fixes and merge!

            hakim.cassimally Hakim Cassimally added a comment - Ray Cardillo , Maria Shodunke  and I have made progress, latest PR is https://github.com/raycardillo/try-cb-lcb/commit/d107feeaeb769a123b4a070cf3276f7ccce92b19  with my fixes for Ubuntu Linux / Docker build, and Ray's fixes for local OSX. Assigning to me to re-test and verify the OSX fixes and merge!

            Changes made after PR, closing, will open some arising tickets to tidy up e.g. sample-application.adoc on docs side.

            hakim.cassimally Hakim Cassimally added a comment - Changes made after PR, closing, will open some arising tickets to tidy up e.g. sample-application.adoc on docs side.

            People

              hakim.cassimally Hakim Cassimally
              richard.smedley Richard Smedley
              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