Skip to content

Commit 51418a2

Browse files
author
Johannes Duesing
committed
Merge branch 'develop' into feature/harmonizeLogs
2 parents 23330ec + a03ee27 commit 51418a2

27 files changed

+826
-119
lines changed

OpenAPISpecification.yaml

Lines changed: 119 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,106 @@ tags:
2020
containers
2121
- name: Docker Operations
2222
description: Operations on instances that are running in a docker container
23+
- name: User Management
24+
description: Operations related to the user database of Delphi-Management
2325
schemes:
2426
- https
2527
- http
2628
paths:
29+
/configuration:
30+
get:
31+
tags:
32+
- Meta
33+
summary: Retreives general configuration information
34+
description: Retrieves an object containing the most important configuration values of the registry. This contains the docker and traefik URIs.
35+
operationId: configurationInfo
36+
responses:
37+
'200':
38+
description: Configuration object
39+
schema:
40+
type: object
41+
properties:
42+
DockerHttpApi:
43+
type: string
44+
example: "172.0.2.1:9095"
45+
TraefikProxyUri:
46+
type: string
47+
example: "172.0.2.1:80"
48+
/users/authenticate:
49+
post:
50+
tags:
51+
- User Management
52+
summary: Authenticates a user and returns a valid JWT
53+
description: >-
54+
This endpoints validates the username and password that must
55+
be supplied in the Authorization header (using HTTP Basic Authentication).
56+
If valid, a JSON Web Token will be generated and returned, that may be used
57+
to authenticate the user for subsequent requests.
58+
operationId: authenticate
59+
parameters:
60+
- in: header
61+
name: Delphi-Authorization
62+
description: >-
63+
Valid JWT that autenticates the calling entity.
64+
type: string
65+
required: true
66+
- in: header
67+
name: Authorization
68+
description: >-
69+
HTTP Basic Authentication following the schema 'Basic <User:Password>
70+
where the concatination of username and password is Base64-Encoded.
71+
type: string
72+
required: true
73+
responses:
74+
'200':
75+
description: Supplied data is valid, a JWT is returned
76+
schema:
77+
type: string
78+
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
79+
'401':
80+
description: Unauthorized, invalid username / password supplied.
81+
/users/add:
82+
post:
83+
tags:
84+
- User Management
85+
summary: Adds a new users for the registry
86+
description: >-
87+
Adds a new user that is passed in the requests entity. The id of the user
88+
will be returned.
89+
operationId: addUser
90+
parameters:
91+
- in: body
92+
name: DelphiUser
93+
description: The user to add
94+
required: true
95+
schema:
96+
type: object
97+
required:
98+
- userName
99+
- secret
100+
- userType
101+
properties:
102+
userName:
103+
type: string
104+
example: MyUser
105+
secret:
106+
type: string
107+
example: 123Pass
108+
userType:
109+
type: string
110+
enum:
111+
- Admin
112+
- User
113+
- Component
114+
responses:
115+
'200':
116+
description: OK, user has been added, id is returned
117+
schema:
118+
type: integer
119+
format: int64
120+
example: 42
121+
'400':
122+
description: Bad request, name already exists
27123
/instances/register:
28124
post:
29125
tags:
@@ -374,12 +470,15 @@ paths:
374470
description: 'Bad request, your label exceeded the character limit'
375471
'404':
376472
description: 'Not found, the id you specified could not be found'
377-
/instances/{Id}/logs:
473+
'/instances/{Id}/logs':
378474
get:
379475
tags:
380476
- Basic Operations
381477
summary: Retrieve the logging output of the specified instance
382-
description: This command retrieves the docker container logging output for the specified instance, if the instance is in fact running inside a docker container.
478+
description: >-
479+
This command retrieves the docker container logging output for the
480+
specified instance, if the instance is in fact running inside a docker
481+
container.
383482
operationId: retreiveLogs
384483
parameters:
385484
- name: Id
@@ -395,22 +494,28 @@ paths:
395494
type: boolean
396495
responses:
397496
'200':
398-
description: Success, log string is being returned
497+
description: 'Success, log string is being returned'
399498
schema:
400499
type: string
401-
example: "I am logging output .."
500+
example: I am logging output ..
402501
'400':
403502
description: Selected instance not running inside docker container
404503
'404':
405504
description: Id not found on the server
406505
'500':
407506
description: Internal Server Error
408-
/instances/{Id}/attach:
507+
'/instances/{Id}/attach':
409508
get:
410509
tags:
411510
- Basic Operations
412511
summary: Stream logging output from instance
413-
description: 'This command streams the docker container logging output for the specified instance. NOTE: This is a websocket endpoint, so only valid websocket requests will be processed. Swagger does not provide sufficient support for websockets, so this documentation might be confusing as it defines a HTTP method, etc. The names of parameters and response-codes are valid though.'
512+
description: >-
513+
This command streams the docker container logging output for the
514+
specified instance. NOTE: This is a websocket endpoint, so only valid
515+
websocket requests will be processed. Swagger does not provide
516+
sufficient support for websockets, so this documentation might be
517+
confusing as it defines a HTTP method, etc. The names of parameters and
518+
response-codes are valid though.
414519
operationId: streamLogs
415520
parameters:
416521
- name: Id
@@ -426,7 +531,7 @@ paths:
426531
type: boolean
427532
responses:
428533
'200':
429-
description: Success, logs are being streamed via websocket connection.
534+
description: 'Success, logs are being streamed via websocket connection.'
430535
'400':
431536
description: Selected instance not running inside docker container
432537
'404':
@@ -747,13 +852,12 @@ paths:
747852
description: One of the ids was not found on the server
748853
'500':
749854
description: Internal server error
750-
/instances/{Id}/command:
855+
'/instances/{Id}/command':
751856
post:
752857
tags:
753858
- Docker Operations
754859
summary: Runs a command into a docker container
755-
description: >-
756-
This command runs a specified command inside a docker container.
860+
description: This command runs a specified command inside a docker container.
757861
operationId: command
758862
parameters:
759863
- in: path
@@ -773,23 +877,21 @@ paths:
773877
properties:
774878
Command:
775879
type: string
776-
example: "rm -rf *"
880+
example: rm -rf *
777881
Privileged:
778882
type: boolean
779883
User:
780884
type: string
781885
example: root
782886
responses:
783887
'200':
784-
description: 'OK'
888+
description: OK
785889
'400':
786-
description: >-
787-
Cannot run command, ID is no docker container.
890+
description: 'Cannot run command, ID is no docker container.'
788891
'404':
789-
description: Cannot run command, ID not found.
892+
description: 'Cannot run command, ID not found.'
790893
'500':
791-
description: Internal server error, unknown operation result DESCRIPTION
792-
894+
description: 'Internal server error, unknown operation result DESCRIPTION'
793895
definitions:
794896
InstanceLink:
795897
type: object

README.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ this repository is purely experimental!
1111

1212
## What is the registry component?
1313
The Delphi registry is a server that provides access to all information and operations needed to set up, run and manage the Delphi system. By default, the REST interface is exposed at *0.0.0.0:8087*, and contains endpoints for:
14+
1415
* Retrieving a list of all instances of a certain type (Crawler, WebApi, WebApp, ElasticSearch)
1516
* Retrieving the whole network graph (all instances and links between instances)
1617
* Deploying new instances of a certain type to a docker host
@@ -37,16 +38,32 @@ For Linux users, checkout Delphi Registry repository and execute the command
3738
```
3839
sudo bash ./Delphi_install.sh
3940
```
40-
inside the registry's root directory. This installation script will create the required repositories, build the docker images, and register them directly at the local docker registry.
41+
inside the ```/Setup``` directory. This installation script will create the required repositories, build the docker images, and register them directly at the local docker registry.
4142
The registry requires an initial instance of ElasticSearch to be running.
4243

44+
To allow access to Delphi components deployed via Docker, the registry supports the reverse-proxy [Traefik](https://traefik.io/). While it is running, it will automatically detected containers deployed by the registry, and provide access to them using the host specified in each instances' ```Host``` attribute.
45+
Windows users can install Traefik (using Docker) based on [this tutorial](https://docs.traefik.io/#the-traefik-quickstart-using-docker). For Linux users, Traefik will be installed and started by the installation script mentioned above.
46+
47+
**Note:** Traefik must be running inside the same Docker network as the containers it is associated with. By default the name for this network is expected to be ```delphi```. Windows users have to manually create it using ```docker network create delphi``` before starting Traefik. If you want to change this network name, please follow these steps:
48+
49+
1. Go to ```docker-compose.yml``` file (for Windows: Create during tutorial; for Linux found in ```/Setup```)
50+
51+
2. Change the item *services->traefik->networks* to your new network name
52+
53+
3. Change the item *networks->delphi->external:true* to *networks->your-network-name->external:true*. Save and close the file
54+
55+
4. Change the ````traefikDockerNetwork`` setting in the configuration file to your new network name (see section below for details)
56+
4357
## Adapt the configuration file
4458
Before you can start the application, you have to make sure your configuration file contains valid data. The file can be found at *src/main/scala/de/upb/cs/swt/delphi/instanceregistry/Configuration.scala*, and most of its attributes are string or integer values. The following table describes the attributes in more detail.
4559

4660
|Attribute | Type | Default Value |Explanation |
4761
| :---: | :---: | :---: | :--- |
4862
|```bindHost``` | ```String``` | ```"0.0.0.0"``` | Host address that the registry server should be bound to |
4963
|```bindPort``` | ```Int``` | ```8087``` | Port that the registry server should be reachable at |
64+
|```traefikBaseHost``` | ```String``` | ```"delphi.de"``` | The host part of the URL that traefik is configured to append to instance URLs. |
65+
|```traefikDockerNetwork``` | ```String``` | ```"delphi"``` | The Docker network Traefik is configured to use. |
66+
|```traefikUri``` | ```String``` | ```"http://172.17.0.1:80"``` | The URI that the Traefik reverse-proxy is hosted at.|
5067
|```defaultCrawlerPort``` | ```Int``` | ```8882``` | Port that Delphi Crawlers are reachable at. This may only be adapted if you manually changed the default port of crawlers before registering the respective image. |
5168
|```defaultWebApiPort``` | ```Int``` | ```8080``` | Port that Delphi WebAPIs are reachable at. This may only be adapted if you manually changed the default port of WebAPIs before registering the respective image. |
5269
|```defaultWebAppPort``` | ```Int``` | ```8085``` | Port that Delphi WebApps are reachable at. This may only be adapted if you manually changed the default port of WebApps before registering the respective image. |
@@ -58,14 +75,21 @@ Before you can start the application, you have to make sure your configuration f
5875
|```uriInLocalNetwork``` | ```String``` | ```"http://172.17.0.1:8087"``` | URI that the registry is reachable at for all docker containers. In most of the use-cases this is going to be the gateway of the default docker bridge.<br>**Note:** For OSX you have to set this value to the DNS name of the docker host, which is ```http://host.docker.internal:8087``` (If the registry is running on the host).|
5976
|```maxLabelLength``` | ```Int``` | ```50``` | Maximum number of characters for instance labels. Longer labels will be rejected.|
6077
|```dockerOperationTimeout``` | ```Timeout``` | ```Timeout(20 seconds)``` | Default timeout for docker operations. If any of the async Docker operations (deploy, stop, pause, ..) takes longer than this, it will be aborted.|
61-
|```defaultDockerUri``` | ```String``` | ```http://localhost:9095``` | Default uri to connect to docker. It will be used if the environment variable ```DELPHI_DOCKER_HOST``` is not specified.|
78+
|```dockerUri``` | ```String``` | ```http://localhost:9095``` | Default uri to connect to docker. It will be used if the environment variable ```DELPHI_DOCKER_HOST``` is not specified.|
6279
|```jwtSecretKey``` | ```String``` | ```changeme``` | Secret key to use for JWT signature (HS256). This setting can be overridden by specifying the ```JWT_SECRET``` environment variable.|
63-
|```useInMemoryDB``` | ```Boolean``` | ```true``` | If set to true, all instance data will be kept in memory instead of using a MySQL database.|
64-
|```databaseHost``` | ```String``` | ```"jdbc:mysql://localhost/"``` | Host that the MySQL database is reachable at (only necessary if *useInMemoryDB* is false).|
65-
|```databaseName``` | ```String``` | ```""``` | Name of the MySQL database to use (only necessary if *useInMemoryDB* is false).|
66-
|```databaseDriver``` | ```String``` | ```"com.mysql.jdbc.Driver"``` | Driver to use for the MySQL connection (only necessary if *useInMemoryDB* is false).|
67-
|```databaseUsername``` | ```String``` | ```""``` | Username to use for the MySQL connection (only necessary if *useInMemoryDB* is false).|
68-
|```databasePassword``` | ```String``` | ```""``` | Password to use for the MySQL connection (only necessary if *useInMemoryDB* is false).|
80+
|```useInMemoryInstanceDB``` | ```Boolean``` | ```true``` | If set to true, all instance data will be kept in memory instead of using a MySQL database.|
81+
|```instanceDatabaseHost``` | ```String``` | ```"jdbc:mysql://localhost/"``` | Host that the MySQL instance database is reachable at (only necessary if *useInMemoryInstanceDB* is false).|
82+
|```instanceDatabaseName``` | ```String``` | ```""``` | Name of the MySQL instance database to use (only necessary if *useInMemoryInstanceDB* is false).|
83+
|```instanceDatabaseDriver``` | ```String``` | ```"com.mysql.jdbc.Driver"``` | Driver to use for the MySQL connection (only necessary if *useInMemoryInstanceDB* is false).|
84+
|```instanceDatabaseUsername``` | ```String``` | ```""``` | Username to use for the MySQL instance DB connection (only necessary if *useInMemoryInstanceDB* is false).|
85+
|```instanceDatabasePassword``` | ```String``` | ```""``` | Password to use for the MySQL instance DB connection (only necessary if *useInMemoryInstanceDB* is false).|
86+
|```useInMemoryAuthDB``` | ```Boolean``` | ```true``` | If set to true, all user data will be kept in memory instead of using a MySQL database.|
87+
|```authDatabaseHost``` | ```String``` | ```"jdbc:mysql://localhost/"``` | Host that the MySQL users database is reachable at (only necessary if *useInMemoryAuthDB* is false).|
88+
|```authDatabaseName``` | ```String``` | ```""``` | Name of the MySQL user database to use (only necessary if *useInMemoryAuthDB* is false).|
89+
|```authDatabaseDriver``` | ```String``` | ```"com.mysql.jdbc.Driver"``` | Driver to use for the MySQL users DB connection (only necessary if *useInMemoryAuthDB* is false).|
90+
|```authDatabaseUsername``` | ```String``` | ```""``` | Username to use for the MySQL users DB connection (only necessary if *useInMemoryAuthDB* is false).|
91+
|```authDatabasePassword``` | ```String``` | ```""``` | Password to use for the MySQL users DB connection (only necessary if *useInMemoryAuthDB* is false).|
92+
|```authenticationValidFor``` | ```Int``` | ```30``` | Default duration that user tokens are valid for (in minutes).|
6993
|```maxTotalNoRequest``` | ```Int``` | ```2000``` | Maximum number of requests that are allowed to be executed during the current refresh period regardless of their origin.|
7094
|```maxIndividualIpReq``` | ```Int``` | ```200``` | Maximum number of requests that are allowed to be executed during the current refresh period for one specific origin ip.|
7195
|```ipLogRefreshRate``` | ```FiniteDuration``` | ```2.minutes``` | Duration of the log refresh period.|
@@ -104,7 +128,7 @@ docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 127.0.0.1:9095:123
104128
## Run the application
105129
There are two ways of running the registry application. You can either run the application directly, or build a docker image defined by the *build.sbt* file, and run a container based on this image. Either way, you have to set the correct configuration values before starting the application (see section **Adapt the configuration file** above for more information). Make sure the Docker images of all Delphi components are present at the host's registry, as described in the **Requirements** section.
106130

107-
**Note:** For OSX you have to set Java's ```prefereIPv4Stack``` option to ```true``` before executing any of the steps below. In order to do so, execute ```export JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"``` in the terminal before calling ```sbt```.
131+
**Note:** For OSX you have to set Java's ```prefereIPv4Stack``` option to ```true``` before executing any of the steps below. In order to do so, execute ```export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"``` in the terminal before calling ```sbt```.
108132

109133
### Run the registry directly
110134
If you want to execute the registry directly on your local machine, simply go to the root folder of the repository and execute ```sbt run```. The application will stream all logging output to the terminal. You can terminate any time by pressing *RETURN*.
@@ -140,7 +164,7 @@ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NDcxMDYzOTksIm5iZiI6MTU0NzEwNjM
140164
Using the above token, a valid call to the registry at ```localhost:8087``` using *curl* looks like this:
141165

142166
```
143-
curl -X POST -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NDcxMDYzOTksIm5iZiI6MTU0NzEwNjM5OSwiZXhwIjoxNTU0MDE0Nzk5LCJ1c2VyX2lkIjoiRGVidWdVc2VyIiwidXNlcl90eXBlIjoiQWRtaW4ifQ.TeDa8JkFANVEufPaxXv3AXSojcaiKdOlBKeU5cLaHpg" localhost:8087/deploy?ComponentType=WebApi
167+
curl -X POST -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1NDcxMDYzOTksIm5iZiI6MTU0NzEwNjM5OSwiZXhwIjoxNTU0MDE0Nzk5LCJ1c2VyX2lkIjoiRGVidWdVc2VyIiwidXNlcl90eXBlIjoiQWRtaW4ifQ.TeDa8JkFANVEufPaxXv3AXSojcaiKdOlBKeU5cLaHpg" -H "Content-type: application/json" -d '{"ComponentType":"WebApi"}' localhost:8087/instances/deploy
144168
```
145169

146170
## Contributing

0 commit comments

Comments
 (0)