Open APIs

 View Only
  • 1.  Running CTK against Document Management API Sample Implementation

    TM Forum Member
    Posted Mar 28, 2022 10:26
    I am facing two problems

    One being that I am unable to connect the sample implementation to mongodb. I am using the dockerfile provided to create a container of the app and using docker-compose, Im running the container alongside mongo and mongo express. As the sample does not create the tmf database, I create the database using the mongo express client and restart the containers. However I am still unable to connect and receive the following error on sending request to the sample server.

    {
      "code": 1,
      "reason": "Internal Server Error",
      "message": "Internal database error"
    }

    The second issue is regarding the ctk. I do not know how to set up the config. Is there a tutorial?

    docker-compose.yml

    version: '3.8'
    services:
      mongo:
        image: mongo:latest
        environment:
          MONGO_INITDB_ROOT_USERNAME: mongodb
          MONGO_INITDB_ROOT_PASSWORD: mongodb
          # MONGO_INITDB_DATABASE: tmf
        volumes:
          - tmf_mongo:/data/db
          # - '.mongodb/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro'
        ports:
          - '27017:27017'
        restart: unless-stopped

      mongo-express:
        image: mongo-express:latest
        restart: always
        ports:
          - 8081:8081
        environment:
          ME_CONFIG_MONGODB_ADMINUSERNAME: mongodb
          ME_CONFIG_MONGODB_ADMINPASSWORD: mongodb
          ME_CONFIG_MONGODB_URL: mongodb://mongodb:mongodb@mongo:27017/

      app:
        build: .
        ports:
          - 8080:8080
        depends_on:
          - mongo
        command: [ "./wait-for", "mongo:27017", "--timeout=300", "--",  "node", "index.js" ]

    volumes:
      tmf_mongo:

    sample-app config.json (not ctk)

    {
    "db_prot": "mongodb",
    "db_user": "mongodb",
    "db_password": "mongodb",
    "db_host": "mongo",
    "db_port": 27017,
    "db_name": "tmf",
    "alarm_host": "http://localhost:10011",
    "alarm_url_hal": "/api/",

    "strict_schema": true
    }


    ------------------------------
    Ahmed Jalwan Waheed
    Dhivehi Raajjeyge Gulhun Plc
    ------------------------------


  • 2.  RE: Running CTK against Document Management API Sample Implementation

    TM Forum Member
    Posted Mar 30, 2022 00:24
    Hi @Ahmed Jalwan Waheed

    I looked into your compose file and the configuration looks good. There is no need for mongo-express since the ri will create the database automatically once the request comes in and successfully connects to the database. I will paste here the docker-compose file together with the dockerfile that we use for testing the ris so you can compare. Notice that the environment variable MONGO_URL set in the dockerfile superseeds the configuration variables in the config.json file present in the ri folder. With the following files you should be able to run the reference implementation. If the same error still persists it would be helpful to see your docker file so I can replicate your environment.

    Answering your second question about the ctk. In order to run the ctk you only need to point the url from the config.json file to where the api is running. An example is provided below with the attributes set to work with the given compose files. Note that the url attribute points to localhost:8642 which is the port defined in the docker-compose file. After setting up this variable you can run the ctk using one of the helper scripts provided at the root of the folder, for example "sh Mac-Linux-RUNCTK.sh". Once the ctk runs the results will be available on the results.html file.

    config.json found at the root of the ctk folder
    {
        "url": " http://localhost:8642/tmf-api/alarmManagement/v4/",
        "headers": {
            "Accept": "application/json",
            "Content-Type": "application/json"
        },
        "payloads": {
            "Alarm": {
                "POST": {
                    "payload": {
                        "alarmRaisedTime": "2019-07-03T03:32:17.235Z",
                        "alarmType": "environmentalAlarm",
                        "alarmedObject": {
                            "id": "93051825"
                        },
                        "perceivedSeverity": "minor",
                        "probableCause": "rectifierLowVoltage",
                        "sourceSystemId": "ems-1",
                        "state": "raised"
                    }
                }
            }
        }
    }​


    Docker-compose
    version: "3.9"
    services:
      mongo:
        image: mongo:latest
        environment:
          MONGO_INITDB_ROOT_USERNAME: mongodb
          MONGO_INITDB_ROOT_PASSWORD: mongodb
        volumes:
          - tmf_mongo:/data/db
        ports:
          - "27017:27017"
        restart: unless-stopped
      tmf642:
        build: .
        ports: ['8642:8080']
        stdin_open: true
        tty: true
    volumes:
      tmf_mongo:
    ​
    ​Docker file 
    FROM alpine:3.12.0
    
    # Create app directory
    WORKDIR /usr/src/app
    
    # Install app dependencies
    # A wildcard is used to ensure both package.json AND package-lock.json are copied
    # where available (npm@5+)
    COPY package*.json ./
    RUN apk add --update nodejs npm
    
    RUN npm install
    # If you are building your code for production
    # RUN npm ci --only=production
    
    # Bundle app source
    COPY . .
    
    ENV MONGO_URL=mongodb://mongo:27017/tmf
    
    EXPOSE 8080
    CMD [ "node", "index.js" ]
    
    ​



    ------------------------------
    Victor Rodriguez
    TM Forum
    ------------------------------



  • 3.  RE: Running CTK against Document Management API Sample Implementation

    TM Forum Member
    Posted Mar 30, 2022 10:53
    Thank you so much for your reply Victor!

    I have worked on this a few more times without any edits to the dockerfile. Last time I added a wait-for shell script to make the container start after mongodb but I think its not needed. This time I have noticed some interesting things. When I send a POST request through postman to http://localhost:8080/tmf-api/document/v4/document I receive an error from the sample app with the code name 'AuthenticationFailed' and some details like `failed to connect to server [mongo:27017]`
    ENV MONGO_URL=mongodb://admin:pass@mongo:27017/tmf​
    This is the environment variable set in the docker file. I have also tested the app with other values for MONGO_URL Previously I have used the same username and password I have set for the root user for mongodb in my docker-compose file. I changed to admin:pass as every time I run the container mongo-express outputs a message saying basicAuth is set to admin:pass but this did not work either. Maybe admin:pass is the basicAuth for mongo-express. I have also included the url without any username and password like this.
    mongodb://mongo:27017/tmf​


    Dockerfile

    FROM alpine:3.12.0
    
    # Create app directory
    WORKDIR /usr/src/app
    
    # Install app dependencies
    # A wildcard is used to ensure both package.json AND package-lock.json are copied
    # where available (npm@5+)
    COPY package*.json ./
    RUN apk add --update nodejs npm
    
    RUN npm install
    # If you are building your code for production
    # RUN npm ci --only=production
    
    # Bundle app source
    COPY . .
    
    ENV MONGO_URL=mongodb://mongodb:mongodb@mongo:27017/tmf
    
    EXPOSE 8080
    CMD [ "node", "index.js" ]


    config.json (sample app)

    {
    "db_prot": "mongodb",
    "db_user": "mongodb",
    "db_password": "mongodb",
    "db_host": "mongo",
    "db_port": 27017,
    "db_name": "tmf",
    "alarm_host": "http://localhost:10011",
    "alarm_url_hal": "/api/",
    
    "strict_schema": true
    }

    docker-compose.yml

    version: '3.8'
    services:
      mongo:
        image: mongo:latest
        environment:
          MONGO_INITDB_ROOT_USERNAME: mongodb
          MONGO_INITDB_ROOT_PASSWORD: mongodb
          # MONGO_INITDB_DATABASE: tmf
        volumes:
          - tmf_mongo:/data/db
          # - '.mongodb/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro'
        ports:
          - '27017:27017'
        restart: unless-stopped
    
      mongo-express:
        image: mongo-express:latest
        restart: always
        ports:
          - 8081:8081
        environment:
          ME_CONFIG_MONGODB_ADMINUSERNAME: mongodb
          ME_CONFIG_MONGODB_ADMINPASSWORD: mongodb
          ME_CONFIG_MONGODB_URL: mongodb://mongodb:mongodb@mongo:27017/
    
      app:
        build: .
        ports:
          - 8080:8080
        depends_on:
          - mongo
    
    volumes:
      tmf_mongo:​




    ------------------------------
    Ahmed Jalwan Waheed
    Dhivehi Raajjeyge Gulhun Plc
    ------------------------------



  • 4.  RE: Running CTK against Document Management API Sample Implementation

    TM Forum Member
    Posted Apr 19, 2022 01:20
    Edited by Ahmed Jalwan Waheed Apr 19, 2022 01:23
    @Victor Mari Rodriguez I was not able to find what was wrong, but I am trying to implement the API. When a user sends a get request to /documents without specifying a limit in parameters, should the response include all the document items? Or can I specify a maximum no of items to be returned.

    ------------------------------
    Ahmed Jalwan Waheed
    Dhivehi Raajjeyge Gulhun Plc
    ------------------------------



  • 5.  RE: Running CTK against Document Management API Sample Implementation

    TM Forum Member
    Posted Apr 24, 2022 07:41
    Hi Ahmed
    The purpose of limit is to specify the number of items to be returned.
    If you don't specify a limit, then the implementation should in principle return all matching items (but there could be millions, or even 100,000,000s, so you are likely to run out of memory) . An implementation might choose to set an arbitrary limit, or to return an error condition, in such cases.

    ------------------------------
    Jonathan Goldberg
    Amdocs Management Limited
    Any opinions and statements made by me on this forum are purely personal, and do not necessarily reflect the position of the TM Forum or my employer.
    ------------------------------