Skip to content

Commit bd0f7d3

Browse files
author
Johannes Duesing
committed
Added endpoint to retreive configuration information (traefik uri)
Updated readme with the config values. Updated Api specification
1 parent 1ca6111 commit bd0f7d3

File tree

7 files changed

+86
-27
lines changed

7 files changed

+86
-27
lines changed

OpenAPISpecification.yaml

+42-17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ schemes:
2424
- https
2525
- http
2626
paths:
27+
/configuration:
28+
get:
29+
tags:
30+
- Meta
31+
summary: Retreives general configuration information
32+
description: Retrieves an object containing the most important configuration values of the registry. This contains the docker and traefik URIs.
33+
operationId: configurationInfo
34+
responses:
35+
'200':
36+
description: Configuration object
37+
schema:
38+
type: object
39+
properties:
40+
DockerHttpApi:
41+
type: string
42+
example: "172.0.2.1:9095"
43+
TraefikProxyUri:
44+
type: string
45+
example: "172.0.2.1:80"
2746
/instances/register:
2847
post:
2948
tags:
@@ -374,12 +393,15 @@ paths:
374393
description: 'Bad request, your label exceeded the character limit'
375394
'404':
376395
description: 'Not found, the id you specified could not be found'
377-
/instances/{Id}/logs:
396+
'/instances/{Id}/logs':
378397
get:
379398
tags:
380399
- Basic Operations
381400
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.
401+
description: >-
402+
This command retrieves the docker container logging output for the
403+
specified instance, if the instance is in fact running inside a docker
404+
container.
383405
operationId: retreiveLogs
384406
parameters:
385407
- name: Id
@@ -395,22 +417,28 @@ paths:
395417
type: boolean
396418
responses:
397419
'200':
398-
description: Success, log string is being returned
420+
description: 'Success, log string is being returned'
399421
schema:
400422
type: string
401-
example: "I am logging output .."
423+
example: I am logging output ..
402424
'400':
403425
description: Selected instance not running inside docker container
404426
'404':
405427
description: Id not found on the server
406428
'500':
407429
description: Internal Server Error
408-
/instances/{Id}/attach:
430+
'/instances/{Id}/attach':
409431
get:
410432
tags:
411433
- Basic Operations
412434
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.'
435+
description: >-
436+
This command streams the docker container logging output for the
437+
specified instance. NOTE: This is a websocket endpoint, so only valid
438+
websocket requests will be processed. Swagger does not provide
439+
sufficient support for websockets, so this documentation might be
440+
confusing as it defines a HTTP method, etc. The names of parameters and
441+
response-codes are valid though.
414442
operationId: streamLogs
415443
parameters:
416444
- name: Id
@@ -426,7 +454,7 @@ paths:
426454
type: boolean
427455
responses:
428456
'200':
429-
description: Success, logs are being streamed via websocket connection.
457+
description: 'Success, logs are being streamed via websocket connection.'
430458
'400':
431459
description: Selected instance not running inside docker container
432460
'404':
@@ -747,13 +775,12 @@ paths:
747775
description: One of the ids was not found on the server
748776
'500':
749777
description: Internal server error
750-
/instances/{Id}/command:
778+
'/instances/{Id}/command':
751779
post:
752780
tags:
753781
- Docker Operations
754782
summary: Runs a command into a docker container
755-
description: >-
756-
This command runs a specified command inside a docker container.
783+
description: This command runs a specified command inside a docker container.
757784
operationId: command
758785
parameters:
759786
- in: path
@@ -773,23 +800,21 @@ paths:
773800
properties:
774801
Command:
775802
type: string
776-
example: "rm -rf *"
803+
example: rm -rf *
777804
Privileged:
778805
type: boolean
779806
User:
780807
type: string
781808
example: root
782809
responses:
783810
'200':
784-
description: 'OK'
811+
description: OK
785812
'400':
786-
description: >-
787-
Cannot run command, ID is no docker container.
813+
description: 'Cannot run command, ID is no docker container.'
788814
'404':
789-
description: Cannot run command, ID not found.
815+
description: 'Cannot run command, ID not found.'
790816
'500':
791-
description: Internal server error, unknown operation result DESCRIPTION
792-
817+
description: 'Internal server error, unknown operation result DESCRIPTION'
793818
definitions:
794819
InstanceLink:
795820
type: object

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ Before you can start the application, you have to make sure your configuration f
4747
| :---: | :---: | :---: | :--- |
4848
|```bindHost``` | ```String``` | ```"0.0.0.0"``` | Host address that the registry server should be bound to |
4949
|```bindPort``` | ```Int``` | ```8087``` | Port that the registry server should be reachable at |
50+
|```traefikBaseHost``` | ```String``` | ```"delphi.cs.upb.de"``` | The host part of the URL that traefik is configured to append to instance URLs. |
51+
|```traefikDockerNetwork``` | ```String``` | ```"web"``` | The Docker network Traefik is configured to use. |
52+
|```traefikUri``` | ```String``` | ```"http://172.17.0.1:80"``` | The URI that the Traefik reverse-proxy is hosted at.|
5053
|```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. |
5154
|```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. |
5255
|```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,7 +61,7 @@ Before you can start the application, you have to make sure your configuration f
5861
|```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).|
5962
|```maxLabelLength``` | ```Int``` | ```50``` | Maximum number of characters for instance labels. Longer labels will be rejected.|
6063
|```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.|
64+
|```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.|
6265
|```jwtSecretKey``` | ```String``` | ```changeme``` | Secret key to use for JWT signature (HS256). This setting can be overridden by specifying the ```JWT_SECRET``` environment variable.|
6366
|```useInMemoryDB``` | ```Boolean``` | ```true``` | If set to true, all instance data will be kept in memory instead of using a MySQL database.|
6467
|```databaseHost``` | ```String``` | ```"jdbc:mysql://localhost/"``` | Host that the MySQL database is reachable at (only necessary if *useInMemoryDB* is false).|

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Configuration( ) {
1212
//Traefik data
1313
val traefikBaseHost: String = "delphi.cs.upb.de"
1414
val traefikDockerNetwork: String = "web"
15+
val traefikUri: String = "http://172.17.0.1:80"
1516

1617

1718
val recoveryFileName : String = "dump.temp"
@@ -36,7 +37,7 @@ class Configuration( ) {
3637
val maxLabelLength: Int = 50
3738

3839
val dockerOperationTimeout: Timeout = Timeout(20 seconds)
39-
val defaultDockerUri: String = "http://localhost:9095"
40+
val dockerUri: String = sys.env.getOrElse("DELPHI_DOCKER_HOST", "http://localhost:9095")
4041

4142
val jwtSecretKey: String = sys.env.getOrElse("JWT_SECRET", "changeme")
4243

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/Docker/DockerConnection.scala

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ import scala.concurrent.Future
1212
object DockerConnection {
1313

1414

15-
def fromEnvironment(configuration: Configuration)(implicit system: ActorSystem, materializer: Materializer): DockerConnection = {
16-
def env(key: String): Option[String] = sys.env.get(key).filter(_.nonEmpty)
17-
18-
val host = env("DELPHI_DOCKER_HOST").getOrElse {
19-
configuration.defaultDockerUri
20-
}
21-
DockerHttpConnection(host)
15+
def fromEnvironment(configuration: Configuration) (implicit system: ActorSystem, mat: Materializer): DockerConnection = {
16+
DockerHttpConnection(configuration.dockerUri)
2217
}
2318
}
2419

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

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ class RequestHandler(configuration: Configuration, instanceDao: InstanceDAO, con
121121
instanceDao.getEventsFor(id)
122122
}
123123

124+
def generateConfigurationInfo(): ConfigurationInfo = {
125+
ConfigurationInfo(DockerHttpUri = configuration.dockerUri, TraefikProxyUri = configuration.traefikUri)
126+
}
127+
124128
def getMatchingInstanceOfType(callerId: Long, compType: ComponentType): (OperationResult.Value, Try[Instance]) = {
125129
log.info(s"Started matching: Instance with id $callerId is looking for instance of type $compType.")
126130
if (!instanceDao.hasInstance(callerId)) {

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import akka.stream.scaladsl.{Flow, Sink, Source}
1010
import de.upb.cs.swt.delphi.instanceregistry.authorization.AccessTokenEnums.UserType
1111
import de.upb.cs.swt.delphi.instanceregistry.authorization.{AccessToken, AuthProvider}
1212
import de.upb.cs.swt.delphi.instanceregistry.io.swagger.client.model.InstanceEnums.ComponentType
13-
import de.upb.cs.swt.delphi.instanceregistry.io.swagger.client.model.{EventJsonSupport, Instance, InstanceJsonSupport, InstanceLinkJsonSupport}
13+
import de.upb.cs.swt.delphi.instanceregistry.io.swagger.client.model._
1414
import de.upb.cs.swt.delphi.instanceregistry.requestLimiter.{IpLogActor, RequestLimitScheduler}
1515
import de.upb.cs.swt.delphi.instanceregistry.{AppLogging, Registry, RequestHandler}
1616
import spray.json.JsonParser.ParsingException
@@ -26,6 +26,7 @@ class Server(handler: RequestHandler) extends HttpApp
2626
with InstanceJsonSupport
2727
with EventJsonSupport
2828
with InstanceLinkJsonSupport
29+
with ConfigurationInfoJsonSupport
2930
with AppLogging {
3031

3132
implicit val system: ActorSystem = Registry.system
@@ -130,6 +131,9 @@ class Server(handler: RequestHandler) extends HttpApp
130131
} ~
131132
path("events") {
132133
streamEvents()
134+
} ~
135+
path("configuration") {
136+
configurationInfo()
133137
}
134138

135139

@@ -412,6 +416,23 @@ class Server(handler: RequestHandler) extends HttpApp
412416
}
413417
}
414418

419+
/**
420+
* Returns general configuration information containing the docker uri and the traefik host
421+
*
422+
* @return ConfigurationInfo object
423+
*/
424+
def configurationInfo(): server.Route = {
425+
authenticateOAuth2[AccessToken]("Secure Site", AuthProvider.authenticateOAuthRequire(_, userType = UserType.Admin)) { token =>
426+
get {
427+
log.debug(s"GET /configuration has been called")
428+
429+
complete {
430+
handler.generateConfigurationInfo().toJson(ConfigurationInfoFormat).toString
431+
}
432+
}
433+
}
434+
}
435+
415436
/**
416437
* Deploys a new container of the specified type. Also adds the resulting instance to the database. The mandatory
417438
* parameter 'ComponentType' is passed as a query argument. The optional parameter 'InstanceName' may also be passed as
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package de.upb.cs.swt.delphi.instanceregistry.io.swagger.client.model
2+
3+
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
4+
import spray.json.{DefaultJsonProtocol, JsonFormat}
5+
6+
trait ConfigurationInfoJsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
7+
implicit val ConfigurationInfoFormat: JsonFormat[ConfigurationInfo] = jsonFormat2(ConfigurationInfo)
8+
}
9+
10+
final case class ConfigurationInfo (DockerHttpUri: String, TraefikProxyUri: String)

0 commit comments

Comments
 (0)