Skip to content

Commit 4006d6c

Browse files
authored
Merge pull request #33 from delphi-hub/feature/instanceLinks
Added data model representation for links between instances
2 parents bb77ce1 + 2fe9128 commit 4006d6c

File tree

15 files changed

+1204
-158
lines changed

15 files changed

+1204
-158
lines changed

OpenAPISpecification.yaml

Lines changed: 218 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ paths:
9292
on the server.
9393
operationId: matchingInstance
9494
parameters:
95+
- in: query
96+
name: Id
97+
description: Id of the instance that is requesting a dependency
98+
required: true
99+
type: integer
100+
format: int64
95101
- name: ComponentType
96102
in: query
97103
description: Type of the instance to be retrieved
@@ -110,6 +116,31 @@ paths:
110116
$ref: '#/definitions/Instance'
111117
'400':
112118
description: Invalid status value
119+
/instance:
120+
get:
121+
tags:
122+
- Basic Operations
123+
summary: Get the instance with the specified id
124+
description: >-
125+
This command retrieves the instance with the specified id from the server.
126+
If that id is not present, 404 will be returned.
127+
operationId: instance
128+
parameters:
129+
- in: query
130+
name: Id
131+
description: Id of the instance
132+
required: true
133+
type: integer
134+
format: int64
135+
responses:
136+
'200':
137+
description: The instance that was requested
138+
schema:
139+
$ref: '#/definitions/Instance'
140+
'404':
141+
description: The id was not found on the server
142+
'500':
143+
description: Internal server error
113144
/instances:
114145
get:
115146
tags:
@@ -185,7 +216,13 @@ paths:
185216
operationId: matchInstance
186217
parameters:
187218
- in: query
188-
name: Id
219+
name: CallerId
220+
description: The ID of the instance that is calling this endpoint
221+
required: true
222+
type: integer
223+
format: int64
224+
- in: query
225+
name: MatchedInstanceId
189226
description: The ID of the instance that the sender was matched to.
190227
required: true
191228
type: integer
@@ -208,7 +245,8 @@ paths:
208245
- Basic Operations
209246
summary: Gets the list of events associated to the specified instance
210247
description: >-
211-
This command retrieves a list of events that are associated to the instance with the specified id.
248+
This command retrieves a list of events that are associated to the
249+
instance with the specified id.
212250
operationId: eventList
213251
parameters:
214252
- name: Id
@@ -226,6 +264,98 @@ paths:
226264
$ref: '#/definitions/Event'
227265
'404':
228266
description: Instance not found
267+
/linksFrom:
268+
get:
269+
tags:
270+
- Basic Operations
271+
summary: Retrieves outgoing links from an instance
272+
description: >-
273+
This command retreives a list of outgoing links from the instance with
274+
the specified id.
275+
operationId: linksFrom
276+
parameters:
277+
- name: Id
278+
in: query
279+
description: Id of the instance
280+
required: true
281+
type: integer
282+
format: int64
283+
responses:
284+
'200':
285+
description: List of InstanceLinks from the specified instance
286+
schema:
287+
type: array
288+
items:
289+
$ref: '#/definitions/InstanceLink'
290+
'404':
291+
description: Instance not found
292+
/linksTo:
293+
get:
294+
tags:
295+
- Basic Operations
296+
summary: Retrieves incoming links to an instance
297+
description: >-
298+
This command retreives a list of incoming links from the instance with
299+
the specified id.
300+
operationId: linksTo
301+
parameters:
302+
- name: Id
303+
in: query
304+
description: Id of the instance
305+
required: true
306+
type: integer
307+
format: int64
308+
responses:
309+
'200':
310+
description: List of InstanceLinks to the specified instance
311+
schema:
312+
type: array
313+
items:
314+
$ref: '#/definitions/InstanceLink'
315+
'404':
316+
description: Instance not found
317+
/network:
318+
get:
319+
tags:
320+
- Basic Operations
321+
summary: Retrieves the current instance network
322+
description: >-
323+
Retrieves the instance network, meaning a list of all instances as well
324+
as a list of all links currently registered at the registry.
325+
operationId: network
326+
responses:
327+
'200':
328+
description: The instance network
329+
schema:
330+
$ref: '#/definitions/InstanceNetwork'
331+
/addLabel:
332+
post:
333+
tags:
334+
- Basic Operations
335+
summary: Add a label to the instance with the specified id
336+
description: >-
337+
This command will add the specified label to the instance with the
338+
specified id.
339+
operationId: addLabel
340+
parameters:
341+
- name: Id
342+
in: query
343+
description: Id of the instance
344+
required: true
345+
type: integer
346+
format: int64
347+
- name: Label
348+
in: query
349+
description: The label to add to the instance
350+
required: true
351+
type: string
352+
responses:
353+
'200':
354+
description: Label successfully added
355+
'400':
356+
description: 'Bad request, your label exceeded the character limit'
357+
'404':
358+
description: 'Not found, the id you specified could not be found'
229359
/deploy:
230360
post:
231361
tags:
@@ -417,9 +547,11 @@ paths:
417547
- Docker Operations
418548
summary: Stops the specified instances' docker container
419549
description: >-
420-
This command stops the docker container of the instance with the
421-
specified ID. The instance will be properly shut down by calling its
422-
/stop command first. Will change the instance state to 'Stopped'.
550+
This command stops the specified instance. If the instance is running
551+
inside a docker container, the container will be stopped. If not, the
552+
instance will be gracefully shut down by calling its /stop endpoint.
553+
Will change the instance state to 'Stopped' for docker containers, will
554+
remove the instance for non-docker instances.
423555
operationId: stop
424556
parameters:
425557
- in: query
@@ -432,9 +564,7 @@ paths:
432564
'202':
433565
description: 'Accepted, the operation will be completed in the future.'
434566
'400':
435-
description: >-
436-
Bad request, the instance with the specified ID is either already
437-
stopped or not deployed as a docker container at all.
567+
description: 'Bad request, the instance with the specified ID is already stopped.'
438568
'404':
439569
description: ID not found on server
440570
'500':
@@ -495,7 +625,80 @@ paths:
495625
description: ID not found on server
496626
'500':
497627
description: Internal server error
628+
/assignInstance:
629+
post:
630+
tags:
631+
- Docker Operations
632+
summary: Assignes a new dependency to the specified instance
633+
description: >-
634+
This command assignes a new dependency to the instance with the
635+
specified id. Internally, this will stop the instance, assign the new
636+
dependency and start the instance again. This is why this is only
637+
applicable to docker instances.
638+
operationId: assignInstance
639+
parameters:
640+
- in: query
641+
name: Id
642+
description: The ID of the instance whichs dependency should be updated
643+
required: true
644+
type: integer
645+
format: int64
646+
- in: query
647+
name: assignedInstanceId
648+
description: The ID of the instance that should be assigned as dependency
649+
required: true
650+
type: integer
651+
format: int64
652+
responses:
653+
'202':
654+
description: 'Accepted, the operation will be completed in the future.'
655+
'400':
656+
description: >-
657+
Bad request, the instance with the specified ID is no running inside
658+
a docker container or the assigned instance is of the wrong
659+
component type.
660+
'404':
661+
description: One of the ids was not found on the server
662+
'500':
663+
description: Internal server error
498664
definitions:
665+
InstanceNetwork:
666+
type: object
667+
required:
668+
- instances
669+
- links
670+
properties:
671+
instances:
672+
type: array
673+
items:
674+
$ref: '#/definitions/Instance'
675+
links:
676+
type: array
677+
items:
678+
$ref: '#/definitions/InstanceLink'
679+
InstanceLink:
680+
type: object
681+
required:
682+
- idFrom
683+
- idTo
684+
- linkState
685+
properties:
686+
idFrom:
687+
type: integer
688+
format: int64
689+
example: 0
690+
idTo:
691+
type: integer
692+
format: int64
693+
example: 42
694+
linkState:
695+
type: string
696+
description: Valid states for an InstanceLink
697+
example: Assigned
698+
enum:
699+
- Assigned
700+
- Outdated
701+
- Failed
499702
Event:
500703
type: object
501704
required:
@@ -557,3 +760,10 @@ definitions:
557760
- Stopped
558761
- Paused
559762
- NotReachable
763+
labels:
764+
type: array
765+
items:
766+
type: string
767+
example:
768+
- private
769+
- debug

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ To obtain these images, checkout the respective repositories ([here](https://git
3939
sbt docker:publishLocal
4040
```
4141
inside their root directory. This will build the docker images and register them directly at the local docker registry.
42+
The registry requires an initial instance of ElasticSearch to be running. The default location for this is *elasticsearch://172.17.0.1:9200*, however this can be changed in the *Configuration.scala* file at *src/main/scala/de/upb/cs/swt/delphi/instanceregistry*.
4243

4344
## Contributing
4445

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
package de.upb.cs.swt.delphi.instanceregistry
22

33
class Configuration( ) {
4+
//Where to host the http server
45
val bindHost: String = "0.0.0.0"
56
val bindPort: Int = 8087
7+
8+
69
val recoveryFileName : String = "dump.temp"
710

11+
//Default ports for the Delphi components
812
val defaultCrawlerPort: Int = 8882
913
val defaultWebApiPort: Int = 8080
1014
val defaultWepAppPort: Int = 8085
1115

16+
//Names of the docker images for the Delphi components
1217
val crawlerDockerImageName: String = "delphi-crawler:1.0.0-SNAPSHOT"
1318
val webApiDockerImageName: String = "delphi-webapi:1.0.0-SNAPSHOT"
1419
val webAppDockerImageName: String = "delphi-webapp:1.0.0-SNAPSHOT"
1520

21+
//Where the initial ElasticSearch instance is located at
22+
val defaultElasticSearchInstanceHost: String = "elasticsearch://172.17.0.1"
23+
val defaultElasticSearchInstancePort: Int = 9200
24+
25+
//Where this registry can be contacted at inside the LAN
26+
val uriInLocalNetwork: String = "http://172.17.0.1:8087"
1627

28+
val maxLabelLength: Int = 50
1729

1830
}
1931

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,15 @@ class ContainerCommands(connection: DockerConnection) extends JsonSupport with C
185185
def logs(
186186
containerId: String
187187
)(implicit ec: ExecutionContext): Source[String, NotUsed] = {
188-
val query = Query("all")
189-
val request = Get(buildUri(containersPath / containerId / "logs", query))
188+
val query = Query("stdout" -> "true" )
189+
val request = Get(buildUri(containersPath / containerId.substring(0,11) / "logs", query))
190190

191191
val flow =
192192
Flow[HttpResponse].map {
193193
case HttpResponse(StatusCodes.OK, _, HttpEntity.Chunked(_, chunks), _) =>
194194
chunks.map(_.data().utf8String)
195-
case HttpResponse(StatusCodes.NotFound, _, _, _) =>
195+
case HttpResponse(StatusCodes.NotFound, _, HttpEntity.Strict(_, data), _) =>
196+
log.warning(s"DOCKER LOGS FAILED: ${data.utf8String}")
196197
throw ContainerNotFoundException(containerId)
197198
case response =>
198199
unknownResponse(response)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class DockerActor(connection: DockerConnection) extends Actor with ActorLogging
3434
}
3535

3636
case create(componentType, instanceId, containerName) =>
37-
val containerConfig = ContainerConfig(Image = DockerImage.getImageName(componentType), Env = Seq(s"INSTANCE_ID=$instanceId", "DELPHI_IR_URI=http://172.17.0.1:8087"))
37+
val containerConfig = ContainerConfig(Image = DockerImage.getImageName(componentType),
38+
Env = Seq(s"INSTANCE_ID=$instanceId", s"DELPHI_IR_URI=${Registry.configuration.uriInLocalNetwork}"))
3839

3940
val createCommand = Try(Await.result(container.create(containerConfig, containerName), Duration.Inf))
4041
createCommand match {
@@ -104,8 +105,8 @@ class DockerActor(connection: DockerConnection) extends Actor with ActorLogging
104105
}
105106

106107
case logs(containerId: String) =>
107-
log.info(s"Fetching Container logs")
108-
container.logs(containerId)
108+
log.info(s"Fetching Container logs")
109+
sender ! container.logs(containerId)
109110

110111
case x => log.warning("Received unknown message: [{}] ", x)
111112
}

0 commit comments

Comments
 (0)