This contains all common REST api services that work with source data system data, which has already been collected by other service tasks. This is an abstraction from the local data layer, and the source system data layer. All REST controllers should be generic to their purpose, and should not be specific to any given source system.
This project uses Spring Boot to package the api as an executable JAR with dependencies.

Build API

mvn install

Run the above command to package the collector into an executable JAR file.

API Properties File

The API layer needs a property file in following format:

# dashboard.properties
dbname=dashboard
dbusername=[MogoDb Database Username, defaults to empty]
dbpassword=[MongoDb Database Password, defaults to empty]
dbhost=[Host on which MongoDb is running, defaults to localhost]
dbport=[Port on which MongoDb is listening, defaults to 27017]

All the above values are optional. Even without the property file you must be able to run the api (assuming you have mongodb installed with no authorization). Note: When dbusername is not present or the value is empty then it skips the mongodb authorization part.

Run the API

After you have build your project, from the target folder run the below command

java -jar api.jar --spring.config.location=dashboard.properties

By default the server starts at port 8080 and uses the context path /api. These values are configurable by using the below 2 properties in dashboard.properties.

  server.contextPath=/api
  server.port=8080

For more information about the server configuration, see the Spring Boot documentation

Create

# from top-level project
mvn clean package -pl api docker:build

Run

  1. First start Mongodb
    For example:
    docker run -d -p 27017:27017 --name mongodb -v ./mongo:/data/db mongo:latest  mongod --smallfiles
    
  2. Create User
    • use db
      db.createUser({user: "db", pwd: "dbpass", roles: [{role: "readWrite", db: "dashboard"}]})
      
    • or from CLI:
      mongo 192.168.64.2/admin --eval 'db.getSiblingDB("db").createUser({user: "db", pwd: "dbpass", roles: [{role: "readWrite", db: "dashboard"}]})'
      
    • Refer to the link for more details.
    • Then running the API from docker is easy:
      docker run -t -p 8080:8080 --link mongodb:mongo -v ./logs:/hygieia/logs -i hygieia-api:latest
      

Environment variables

Environment variables for dashboard properties can be specified like:

docker run -t -p 8080:8080 -v ./logs:/hygieia/logs -e "SPRING_DATA_MONGODB_HOST=127.0.0.1" -i hygieia-api:latest
For more properties see the Dockerfile

List containers

View port by running

docker ps

API Access

Check with the following command: IP is the IP of docker machine and port is the Port for Hygieia API

   http://<docker-machine ip>:<docker port for hygieia_api>/api/dashboard