Skip to content

Commit 3b30246

Browse files
Merge pull request #27 from delphi-hub/feature/dockerApiImplementation
Implementation of docker functionality in the Instance Registry
2 parents 561a05a + f31ae8e commit 3b30246

21 files changed

+1922
-249
lines changed

OpenAPISpecification.yaml

Lines changed: 85 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ paths:
240240
post:
241241
tags:
242242
- Docker Operations
243-
summary: Reports the successful start of an instances to the registry
243+
summary: Reports the successful start of an instance to the registry
244244
description: >-
245245
This command informs the registry about an instance that successfully
246246
reached the state 'Running'. This is only applicable to instances
@@ -250,7 +250,7 @@ paths:
250250
operationId: reportStart
251251
parameters:
252252
- in: query
253-
name: InstanceID
253+
name: Id
254254
description: The ID of the instance that was started
255255
required: true
256256
type: integer
@@ -259,7 +259,36 @@ paths:
259259
'200':
260260
description: Report successfully processed.
261261
'400':
262-
description: Bad request, the instance with the specified ID is not deployed as a docker container.
262+
description: >-
263+
Bad request, the instance with the specified ID is not deployed as a
264+
docker container.
265+
'404':
266+
description: ID not found on server
267+
'500':
268+
description: Internal server error
269+
/reportStop:
270+
post:
271+
tags:
272+
- Docker Operations
273+
summary: Reports the manual stop of an instances to the registry
274+
description: >-
275+
This command informs the registry about an instance that was stopped manually, meaning not via calling /stop on the instance registry. This is only applicable to instances
276+
running inside a docker container, as non-container instances would deregister themselves when stopped.
277+
operationId: reportStop
278+
parameters:
279+
- in: query
280+
name: Id
281+
description: The ID of the instance that was stopped
282+
required: true
283+
type: integer
284+
format: int64
285+
responses:
286+
'200':
287+
description: Report successfully processed.
288+
'400':
289+
description: >-
290+
Bad request, the instance with the specified ID is not deployed as a
291+
docker container.
263292
'404':
264293
description: ID not found on server
265294
'500':
@@ -280,7 +309,7 @@ paths:
280309
operationId: reportFailure
281310
parameters:
282311
- in: query
283-
name: InstanceID
312+
name: Id
284313
description: The ID of the instance that encountered the failure
285314
required: true
286315
type: integer
@@ -294,7 +323,9 @@ paths:
294323
'200':
295324
description: Report successfully processed.
296325
'400':
297-
description: Bad request, the instance with the specified ID is not deployed as a docker container.
326+
description: >-
327+
Bad request, the instance with the specified ID is not deployed as a
328+
docker container.
298329
'404':
299330
description: ID not found on server
300331
'500':
@@ -304,20 +335,24 @@ paths:
304335
tags:
305336
- Docker Operations
306337
summary: Pauses the specified instances' docker container
307-
description: This command pauses the docker container of the instance with the specified ID. Will change the instance state from 'Running' to 'Paused'
338+
description: >-
339+
This command pauses the docker container of the instance with the
340+
specified ID. Will change the instance state from 'Running' to 'Paused'
308341
operationId: pause
309342
parameters:
310343
- in: query
311-
name: InstanceID
344+
name: Id
312345
description: The ID of the instance to be paused
313346
required: true
314347
type: integer
315348
format: int64
316349
responses:
317350
'202':
318-
description: Accepted, the operation will be completed in the future.
351+
description: 'Accepted, the operation will be completed in the future.'
319352
'400':
320-
description: Bad request, the instance with the specified ID is either not running or not deployed as a docker container at all.
353+
description: >-
354+
Bad request, the instance with the specified ID is either not
355+
running or not deployed as a docker container at all.
321356
'404':
322357
description: ID not found on server
323358
'500':
@@ -327,20 +362,25 @@ paths:
327362
tags:
328363
- Docker Operations
329364
summary: Resumes the specified instances' docker container
330-
description: This command resumes the execution of the docker container of the instance with the specified ID. Will change the instance state from 'Paused' to 'Running'.
365+
description: >-
366+
This command resumes the execution of the docker container of the
367+
instance with the specified ID. Will change the instance state from
368+
'Paused' to 'Running'.
331369
operationId: resume
332370
parameters:
333371
- in: query
334-
name: InstanceID
372+
name: Id
335373
description: The ID of the instance to be resumed
336374
required: true
337375
type: integer
338376
format: int64
339377
responses:
340378
'202':
341-
description: Accepted, the operation will be completed in the future.
379+
description: 'Accepted, the operation will be completed in the future.'
342380
'400':
343-
description: Bad request, the instance with the specified ID is either not paused or not deployed as a docker container at all.
381+
description: >-
382+
Bad request, the instance with the specified ID is either not paused
383+
or not deployed as a docker container at all.
344384
'404':
345385
description: ID not found on server
346386
'500':
@@ -350,20 +390,25 @@ paths:
350390
tags:
351391
- Docker Operations
352392
summary: Stops the specified instances' docker container
353-
description: This command stops the docker container of the instance with the specified ID. The instance will be properly shut down by calling its /stop command first. Will change the instance state to 'Stopped'.
393+
description: >-
394+
This command stops the docker container of the instance with the
395+
specified ID. The instance will be properly shut down by calling its
396+
/stop command first. Will change the instance state to 'Stopped'.
354397
operationId: stop
355398
parameters:
356399
- in: query
357-
name: InstanceID
400+
name: Id
358401
description: The ID of the instance to be stopped
359402
required: true
360403
type: integer
361404
format: int64
362405
responses:
363406
'202':
364-
description: Accepted, the operation will be completed in the future.
407+
description: 'Accepted, the operation will be completed in the future.'
365408
'400':
366-
description: Bad request, the instance with the specified ID is either already stopped or not deployed as a docker container at all.
409+
description: >-
410+
Bad request, the instance with the specified ID is either already
411+
stopped or not deployed as a docker container at all.
367412
'404':
368413
description: ID not found on server
369414
'500':
@@ -373,20 +418,25 @@ paths:
373418
tags:
374419
- Docker Operations
375420
summary: Starts the specified instances' docker container
376-
description: This command starts the docker container of the instance with the specified ID. Will change the instance state from 'Stopped' to 'Running'.
421+
description: >-
422+
This command starts the docker container of the instance with the
423+
specified ID. Will change the instance state from 'Stopped' to
424+
'Running'.
377425
operationId: start
378426
parameters:
379427
- in: query
380-
name: InstanceID
428+
name: Id
381429
description: The ID of the instance to be started
382430
required: true
383431
type: integer
384432
format: int64
385433
responses:
386434
'202':
387-
description: Accepted, the operation will be completed in the future.
435+
description: 'Accepted, the operation will be completed in the future.'
388436
'400':
389-
description: Bad request, the instance with the specified ID is either not stopped or not deployed as a docker container at all.
437+
description: >-
438+
Bad request, the instance with the specified ID is either not
439+
stopped or not deployed as a docker container at all.
390440
'404':
391441
description: ID not found on server
392442
'500':
@@ -396,28 +446,37 @@ paths:
396446
tags:
397447
- Docker Operations
398448
summary: Deletes the specified instances' docker container
399-
description: This command deletes the docker container of the instance with the specified ID. The container needs to be stopped first. This will remove any data the instance registry holds about the instance.
449+
description: >-
450+
This command deletes the docker container of the instance with the
451+
specified ID. The container needs to be stopped first. This will remove
452+
any data the instance registry holds about the instance.
400453
operationId: delete
401454
parameters:
402455
- in: query
403-
name: InstanceID
456+
name: Id
404457
description: The ID of the instance to be deleted
405458
required: true
406459
type: integer
407460
format: int64
408461
responses:
409462
'202':
410-
description: Accepted, the operation will be completed in the future.
463+
description: 'Accepted, the operation will be completed in the future.'
411464
'400':
412-
description: Bad request, the instance with the specified ID is either not stopped or not deployed as a docker container at all.
465+
description: >-
466+
Bad request, the instance with the specified ID is either not
467+
stopped or not deployed as a docker container at all.
413468
'404':
414469
description: ID not found on server
415470
'500':
416471
description: Internal server error
417472
definitions:
418473
Instance:
419474
type: object
420-
required: [host, portNumber, name, componentType]
475+
required:
476+
- host
477+
- portNumber
478+
- name
479+
- componentType
421480
properties:
422481
id:
423482
type: integer
@@ -455,4 +514,3 @@ definitions:
455514
- Stopped
456515
- Paused
457516
- NotReachable
458-

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ class Configuration( ) {
44
val bindHost: String = "0.0.0.0"
55
val bindPort: Int = 8087
66
val recoveryFileName : String = "dump.temp"
7+
8+
val defaultCrawlerPort: Int = 8882
9+
val defaultWebApiPort: Int = 8080
10+
val defaultWepAppPort: Int = 8085
11+
12+
val crawlerDockerImageName: String = "delphi-crawler:1.0.0-SNAPSHOT"
13+
val webApiDockerImageName: String = "delphi-webapi:1.0.0-SNAPSHOT"
14+
val webAppDockerImageName: String = "delphi-webapp:1.0.0-SNAPSHOT"
15+
16+
17+
718
}
819

920

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package de.upb.cs.swt.delphi.instanceregistry.Docker
2+
3+
import akka.NotUsed
4+
import akka.http.scaladsl.model.{HttpResponse, StatusCodes}
5+
import akka.http.scaladsl.unmarshalling.Unmarshal
6+
import akka.stream.Materializer
7+
import akka.stream.scaladsl.{Sink, Source}
8+
import de.upb.cs.swt.delphi.instanceregistry.AppLogging
9+
10+
import scala.concurrent.{ExecutionContext, Future}
11+
12+
trait Commands extends AppLogging{
13+
def unknownResponse(response: HttpResponse)(implicit ec: ExecutionContext, mat: Materializer): Source[Nothing, NotUsed] = {
14+
import akka.http.scaladsl.unmarshalling.PredefinedFromEntityUnmarshallers._
15+
16+
Source.fromFuture(Unmarshal(response.entity).to[String](stringUnmarshaller, ec, mat).map { entity =>
17+
if (response.status == StatusCodes.InternalServerError) {
18+
//println("exception")
19+
20+
throw new ServerErrorException(response.status, entity)
21+
} else {
22+
throw new UnknownResponseException(response.status, entity)
23+
}
24+
})
25+
}
26+
27+
def unknownResponseFuture(response: HttpResponse)(implicit ec: ExecutionContext, mat: Materializer): Future[Nothing] = {
28+
unknownResponse(response).runWith(Sink.head)
29+
}
30+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package de.upb.cs.swt.delphi.instanceregistry.Docker
2+
3+
sealed trait ContainerId {
4+
def value: String
5+
}
6+
7+
case class ContainerName(name: String) extends ContainerId {
8+
override def value = name
9+
10+
override def toString = name
11+
}
12+
13+
case class CreateContainerResponse(Id: String, Warnings: Option[String])
14+
15+
case class ContainerStatus(
16+
Command: String,
17+
Id: String,
18+
Image: String,
19+
Names: Seq[String],
20+
Labels: Map[String, String],
21+
Status: String
22+
)
23+
24+
case class ContainerConfig(
25+
Image: String,
26+
Entrypoint: Option[Seq[String]] = None,
27+
Cmd: Seq[String] = Seq.empty,
28+
Env: Seq[String] = Seq.empty)
29+
30+
case class Networks(
31+
IPAddress: String
32+
)
33+
34+
object PortBinding {
35+
def apply(HostPort: Int): PortBinding = new PortBinding(HostPort = HostPort)
36+
}
37+
38+
case class PortBinding(HostIp: String = "0.0.0.0",
39+
HostPort: Int)

0 commit comments

Comments
 (0)