Skip to content

Commit 283a297

Browse files
committed
Merge branch 'develop' of https://github.com/delphi-hub/delphi-registry into authTest
# Conflicts: # OpenAPISpecification.yaml
2 parents 1ed2c50 + b2675db commit 283a297

File tree

6 files changed

+125
-93
lines changed

6 files changed

+125
-93
lines changed

OpenAPISpecification.yaml

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ paths:
3131
tags:
3232
- Meta
3333
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.
34+
description: >-
35+
Retrieves an object containing the most important configuration values
36+
of the registry. This contains the docker and traefik URIs.
3537
operationId: configurationInfo
3638
responses:
3739
'200':
@@ -41,69 +43,52 @@ paths:
4143
properties:
4244
DockerHttpApi:
4345
type: string
44-
example: "172.0.2.1:9095"
46+
example: '172.0.2.1:9095'
4547
TraefikProxyUri:
4648
type: string
47-
example: "172.0.2.1:80"
48-
/users:
49-
get:
50-
tags:
51-
- User Management
52-
summary: Get all users
53-
description: >-
54-
This command retrieves a list of all users that are created at
55-
the user. All users are being returned.
56-
operationId: allUser
57-
responses:
58-
'200':
59-
description: List of users
60-
schema:
61-
type: array
62-
items:
63-
$ref: '#/definitions/User'
64-
'400':
65-
description: Invalid value
49+
example: '172.0.2.1:80'
6650
/users/authenticate:
6751
post:
6852
tags:
6953
- User Management
7054
summary: Authenticates a user and returns a valid JWT
7155
description: >-
72-
This endpoints validates the username and password that must
73-
be supplied in the Authorization header (using HTTP Basic Authentication).
74-
If valid, a JSON Web Token will be generated and returned, that may be used
75-
to authenticate the user for subsequent requests.
56+
This endpoints validates the username and password that must be
57+
supplied in the Authorization header (using HTTP Basic Authentication).
58+
If valid, a JSON Web Token will be generated and returned, that may be
59+
used to authenticate the user for subsequent requests.
7660
operationId: authenticate
7761
parameters:
7862
- in: header
7963
name: Delphi-Authorization
80-
description: >-
81-
Valid JWT that autenticates the calling entity.
64+
description: Valid JWT that autenticates the calling entity.
8265
type: string
8366
required: true
8467
- in: header
8568
name: Authorization
8669
description: >-
87-
HTTP Basic Authentication following the schema 'Basic <User:Password>
88-
where the concatination of username and password is Base64-Encoded.
70+
HTTP Basic Authentication following the schema 'Basic
71+
<User:Password> where the concatination of username and password is
72+
Base64-Encoded.
8973
type: string
9074
required: true
9175
responses:
9276
'200':
93-
description: Supplied data is valid, a JWT is returned
77+
description: 'Supplied data is valid, a JWT is returned'
9478
schema:
9579
type: string
96-
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
80+
example: >-
81+
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
9782
'401':
98-
description: Unauthorized, invalid username / password supplied.
83+
description: 'Unauthorized, invalid username / password supplied.'
9984
/users/add:
10085
post:
10186
tags:
10287
- User Management
10388
summary: Adds a new users for the registry
10489
description: >-
105-
Adds a new user that is passed in the requests entity. The id of the user
106-
will be returned.
90+
Adds a new user that is passed in the requests entity. The id of the
91+
user will be returned.
10792
operationId: addUser
10893
parameters:
10994
- in: body
@@ -131,60 +116,70 @@ paths:
131116
- Component
132117
responses:
133118
'200':
134-
description: OK, user has been added, id is returned
119+
description: 'OK, user has been added, id is returned'
135120
schema:
136121
type: integer
137122
format: int64
138123
example: 42
139124
'400':
140-
description: Bad request, name already exists
141-
125+
description: 'Bad request, name already exists'
126+
/users:
127+
get:
128+
tags:
129+
- User Management
130+
summary: Gets a list of all registered users
131+
description: >-
132+
Returns a list of all users registered at the registry. Requires caller to have admin privileges.
133+
operationId: allUsers
134+
responses:
135+
'200':
136+
description: "OK, list of users is being returned"
137+
schema:
138+
type: array
139+
items:
140+
$ref: '#/definitions/User'
142141
/users/{Id}:
143-
post:
142+
get:
144143
tags:
145144
- User Management
146-
summary: Get a user with id
145+
summary: Gets the user with the specified id
147146
description: >-
148-
Get a particular user with its id. The user will be returned.
149-
operationId: getUser
147+
Returns the user with the specified id, if that id is present at the registry.
148+
operationId: retrieveUser
150149
parameters:
151150
- in: path
152151
name: Id
153-
description: Id of the user
154152
required: true
153+
description: Id of the user to retrieve
155154
type: integer
156155
format: int64
157156
responses:
158157
'200':
159-
description: Single user data
158+
description: "OK, user is being returned"
160159
schema:
161160
$ref: '#/definitions/User'
162161
'404':
163-
description: User id was not found on the server.
164-
162+
description: "Id not found"
165163
/users/{Id}/remove:
166164
post:
167165
tags:
168166
- User Management
169-
summary: Remove a user
167+
summary: Removes the user with the specified id
170168
description: >-
171-
Remove a user with its id. If the operation is successful it
172-
will return success message.
169+
Removes the user with the specified id, if that id is present at the registry.
173170
operationId: removeUser
174171
parameters:
175-
- name: Id
176-
in: path
177-
description: The ID of the user to be deleted.
172+
- in: path
173+
name: Id
178174
required: true
175+
description: Id of the user to remove
179176
type: integer
180177
format: int64
181178
responses:
182179
'200':
183-
description: user successfully removed
184-
'400':
185-
description: User id does not exist.
186-
'500':
187-
description: An internal server error occurred.
180+
description: "OK, user has been removed"
181+
'404':
182+
description: "Id not found"
188183
/instances/register:
189184
post:
190185
tags:
@@ -222,7 +217,7 @@ paths:
222217
summary: Get all instances of the specified type
223218
description: >-
224219
This command retrieves a list of all instances that are registered at
225-
the registry and that have the specified type. If no type is specified,
220+
the registry and that have the specified type. If no type is specified,
226221
all instances are being returned.
227222
operationId: instanceOfType
228223
parameters:
@@ -681,7 +676,7 @@ paths:
681676
This command informs the registry about an instance that was stopped
682677
manually, meaning not via calling /stop on the instance registry. This
683678
is only applicable to instances running inside a docker container, as
684-
non-container instances would deregister themselves when stopped.
679+
non-container instances would deregister themselves when stopped.
685680
operationId: reportStop
686681
parameters:
687682
- name: Id
@@ -880,7 +875,7 @@ paths:
880875
description: >-
881876
This command assignes a new dependency to the instance with the
882877
specified id. Internally, this will stop the instance, assign the new
883-
dependency and start the instance again. This is why this is only
878+
dependency and start the instance again. This is why this is only
884879
applicable to docker instances.
885880
operationId: assignInstance
886881
parameters:
@@ -951,6 +946,27 @@ paths:
951946
'500':
952947
description: 'Internal server error, unknown operation result DESCRIPTION'
953948
definitions:
949+
User:
950+
type: object
951+
required:
952+
- userName
953+
- secret
954+
- userType
955+
properties:
956+
id:
957+
type: integer
958+
format: int64
959+
userName:
960+
type: string
961+
example: Ben
962+
secret:
963+
type: string
964+
example: 0DE19F6FAAFB7CF372172CEA658800999A75DB9E79AF5F378F274E47DF810CEE
965+
userType:
966+
type: string
967+
enum:
968+
- User
969+
- Admin
954970
InstanceLink:
955971
type: object
956972
required:
@@ -991,21 +1007,6 @@ definitions:
9911007
- StateChangedEvent
9921008
payload:
9931009
type: object
994-
User:
995-
type: object
996-
properties:
997-
id:
998-
type: integer
999-
format: int64
1000-
userName:
1001-
type: string
1002-
example: MyUser
1003-
userType:
1004-
type: string
1005-
enum:
1006-
- Admin
1007-
- User
1008-
- Component
10091010
Instance:
10101011
type: object
10111012
required:

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,35 @@ The Delphi registry is a server that provides access to all information and oper
1818
* Starting / Stopping / Pausing / Resuming / Deleting instances deployed on the docker host
1919
* Re-Assigning dependencies to instances (e.g. assigning a certain ElasticSearch instance to a Crawler)
2020

21+
## Quick Setup (Linux)
22+
Potentially there two different machines involved in the registry setup, the Docker host machine (*Docker Host*) and the machine the registry is hosted at (*Registry Host*). However, you can also use the same machine for hosting both applications.
23+
24+
On the *Docker Host*, execute the following steps:
25+
26+
1) Clone this repository to your machine
27+
2) Execute the setup script ```Setup/Delphi_install.sh```
28+
3) Deploy [ElasticSearch](https://www.elastic.co/de/products/elasticsearch) by executing ```docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.6.0```
29+
4) Expose your Docker HTTP api on port 9095
30+
* Execute ```sudo nano /lib/systemd/system/docker.service```
31+
* Change the line that starts with ```ExecStart``` to look like this: ```ExecStart=/usr/bin/dockerd -H fd:// -H=tcp://0.0.0.0:9095```
32+
* Save your changes and execute ```systemctl daemon-reload``` and ```sudo service docker restart```
33+
5) Note down the IP address of your machine in the LAN ( execute ```ifconfig``` )
34+
35+
36+
On the *Registry Host*, execute the following steps:
37+
38+
1) Clone this repository to your local machine
39+
2) Note down the IP address of your machine in the LAN ( execute ```ifconfig``` )
40+
3) Edit the configuration file located at ```src/main/scala/de/upb/cs/swt/delphi/instanceregistry/Configuration.scala```
41+
* Set ```traefikUri``` to ```http://<DOCKER-HOST-IP-HERE>:80```
42+
* Set ```defaultElasticSearchInstanceHost``` to ```http://<DOCKER-HOST-IP-HERE>```
43+
* Set ```uriInLocalNetwork``` to ```http://<REGISTRY-HOST-IP-HERE>:8087```
44+
* Set ```dockerUri``` to ```http://<DOCKER-HOST-IP-HERE>:9095```
45+
* Set ```jwtSecretKey``` to a secret password not known to anybody else
46+
4) Save your changes. Navigate to the root folder of the repository and execute the application by calling ```sbt run```
47+
48+
The setup of the registry is now complete. You should now be able to connect to the registry component at ```http://<REGISTRY-HOST-IP-HERE>:8087```. You can verify your setup by calling ```curl <REGISTRY-HOST-IP-HERE>:8087/configuration```, which should lead to a ```401 Unauthorized``` response. To find out more about how to authorize yourself, please have look at the **Authorization** section of this document.
49+
2150
## Requirements
2251
In order to compile or execute the instance registry, you must have the latest version of the *Scala Build Tool* (SBT) installed. You can get it [here](https://www.scala-sbt.org/).
2352

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/RequestHandler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class RequestHandler(configuration: Configuration, authDao: AuthDAO, instanceDao
295295

296296
deployResult match {
297297
case Failure(ex) =>
298-
log.warning(s"Failed to deploy container, docker host not reachable.")
298+
log.warning(s"Failed to deploy container, docker host not reachable. Message ${ex.getMessage}")
299299
instanceDao.removeInstance(id)
300300
fireDockerOperationErrorEvent(None, s"Deploy failed with message: ${ex.getMessage}")
301301
Failure(new RuntimeException(s"Failed to deploy container, docker host not reachable (${ex.getMessage})."))

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/connection/Server.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ class Server(handler: RequestHandler) extends HttpApp
11791179
/**
11801180
* Registers a new user at the registry.
11811181
*
1182-
* @param UserString
1182+
* @param UserString Json object describing the user
11831183
* @return
11841184
*/
11851185
def addUser(UserString: String): server.Route = Route.seal{
@@ -1236,7 +1236,7 @@ class Server(handler: RequestHandler) extends HttpApp
12361236
* Returns an user with the specified id. Id is passed as query argument named 'Id' (so the resulting call is
12371237
* /users/42)
12381238
*
1239-
* @param id
1239+
* @param id id of the user to retrieve
12401240
* @return
12411241
*/
12421242
def retrieveUser(id: Long): server.Route = Route.seal{
@@ -1261,7 +1261,7 @@ class Server(handler: RequestHandler) extends HttpApp
12611261
* Remove an user with the specified id. Id is passed as query argument named 'Id' (so the resulting call is
12621262
* /users/remove/42)
12631263
*
1264-
* @param id
1264+
* @param id id of the user to remove
12651265
* @return
12661266
*/
12671267
def removeUser(id: Long): server.Route = Route.seal{

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/daos/DatabaseInstanceDAO.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,18 @@ class DatabaseInstanceDAO (configuration : Configuration) extends InstanceDAO wi
286286
override def addLink(link: InstanceLink) : Try[Unit] = {
287287
if(hasInstance(link.idFrom) && hasInstance(link.idTo)){
288288

289+
//If new link is in state 'Assigned': Set any link that previously was assigned to 'outdated'
290+
//IMPORTANT: Only works bc every component has exactly one dependency!
291+
if(link.linkState == LinkState.Assigned){
292+
for (prevLink <- getLinksFrom(link.idFrom, Some(LinkState.Assigned))){
293+
updateLink(InstanceLink(prevLink.idFrom, prevLink.idTo, LinkState.Outdated))
294+
}
295+
}
296+
289297
if(getLinksFrom(link.idFrom).exists(l => l.idTo == link.idTo)){
290298
//There already is a link between the two instances. Update it instead of adding a new one
291299
updateLink(link)
292300
} else {
293-
//If new link is in state 'Assigned': Set any link that previously was assigned to 'outdated'
294-
//IMPORTANT: Only works bc every component has exactly one dependency!
295-
if(link.linkState == LinkState.Assigned){
296-
for (prevLink <- getLinksFrom(link.idFrom, Some(LinkState.Assigned))){
297-
updateLink(InstanceLink(prevLink.idFrom, prevLink.idTo, LinkState.Outdated))
298-
}
299-
}
300301
addLinkFromInstanceLink(link)
301302
}
302303
Success()

0 commit comments

Comments
 (0)