Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 218 additions & 8 deletions OpenAPISpecification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ paths:
on the server.
operationId: matchingInstance
parameters:
- in: query
name: Id
description: Id of the instance that is requesting a dependency
required: true
type: integer
format: int64
- name: ComponentType
in: query
description: Type of the instance to be retrieved
Expand All @@ -110,6 +116,31 @@ paths:
$ref: '#/definitions/Instance'
'400':
description: Invalid status value
/instance:
get:
tags:
- Basic Operations
summary: Get the instance with the specified id
description: >-
This command retrieves the instance with the specified id from the server.
If that id is not present, 404 will be returned.
operationId: instance
parameters:
- in: query
name: Id
description: Id of the instance
required: true
type: integer
format: int64
responses:
'200':
description: The instance that was requested
schema:
$ref: '#/definitions/Instance'
'404':
description: The id was not found on the server
'500':
description: Internal server error
/instances:
get:
tags:
Expand Down Expand Up @@ -185,7 +216,13 @@ paths:
operationId: matchInstance
parameters:
- in: query
name: Id
name: CallerId
description: The ID of the instance that is calling this endpoint
required: true
type: integer
format: int64
- in: query
name: MatchedInstanceId
description: The ID of the instance that the sender was matched to.
required: true
type: integer
Expand All @@ -208,7 +245,8 @@ paths:
- Basic Operations
summary: Gets the list of events associated to the specified instance
description: >-
This command retrieves a list of events that are associated to the instance with the specified id.
This command retrieves a list of events that are associated to the
instance with the specified id.
operationId: eventList
parameters:
- name: Id
Expand All @@ -226,6 +264,98 @@ paths:
$ref: '#/definitions/Event'
'404':
description: Instance not found
/linksFrom:
get:
tags:
- Basic Operations
summary: Retrieves outgoing links from an instance
description: >-
This command retreives a list of outgoing links from the instance with
the specified id.
operationId: linksFrom
parameters:
- name: Id
in: query
description: Id of the instance
required: true
type: integer
format: int64
responses:
'200':
description: List of InstanceLinks from the specified instance
schema:
type: array
items:
$ref: '#/definitions/InstanceLink'
'404':
description: Instance not found
/linksTo:
get:
tags:
- Basic Operations
summary: Retrieves incoming links to an instance
description: >-
This command retreives a list of incoming links from the instance with
the specified id.
operationId: linksTo
parameters:
- name: Id
in: query
description: Id of the instance
required: true
type: integer
format: int64
responses:
'200':
description: List of InstanceLinks to the specified instance
schema:
type: array
items:
$ref: '#/definitions/InstanceLink'
'404':
description: Instance not found
/network:
get:
tags:
- Basic Operations
summary: Retrieves the current instance network
description: >-
Retrieves the instance network, meaning a list of all instances as well
as a list of all links currently registered at the registry.
operationId: network
responses:
'200':
description: The instance network
schema:
$ref: '#/definitions/InstanceNetwork'
/addLabel:
post:
tags:
- Basic Operations
summary: Add a label to the instance with the specified id
description: >-
This command will add the specified label to the instance with the
specified id.
operationId: addLabel
parameters:
- name: Id
in: query
description: Id of the instance
required: true
type: integer
format: int64
- name: Label
in: query
description: The label to add to the instance
required: true
type: string
responses:
'200':
description: Label successfully added
'400':
description: 'Bad request, your label exceeded the character limit'
'404':
description: 'Not found, the id you specified could not be found'
/deploy:
post:
tags:
Expand Down Expand Up @@ -417,9 +547,11 @@ paths:
- Docker Operations
summary: Stops the specified instances' docker container
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'.
This command stops the specified instance. If the instance is running
inside a docker container, the container will be stopped. If not, the
instance will be gracefully shut down by calling its /stop endpoint.
Will change the instance state to 'Stopped' for docker containers, will
remove the instance for non-docker instances.
operationId: stop
parameters:
- in: query
Expand All @@ -432,9 +564,7 @@ paths:
'202':
description: 'Accepted, the operation will be completed in the future.'
'400':
description: >-
Bad request, the instance with the specified ID is either already
stopped or not deployed as a docker container at all.
description: 'Bad request, the instance with the specified ID is already stopped.'
'404':
description: ID not found on server
'500':
Expand Down Expand Up @@ -495,7 +625,80 @@ paths:
description: ID not found on server
'500':
description: Internal server error
/assignInstance:
post:
tags:
- Docker Operations
summary: Assignes a new dependency to the specified instance
description: >-
This command assignes a new dependency to the instance with the
specified id. Internally, this will stop the instance, assign the new
dependency and start the instance again. This is why this is only
applicable to docker instances.
operationId: assignInstance
parameters:
- in: query
name: Id
description: The ID of the instance whichs dependency should be updated
required: true
type: integer
format: int64
- in: query
name: assignedInstanceId
description: The ID of the instance that should be assigned as dependency
required: true
type: integer
format: int64
responses:
'202':
description: 'Accepted, the operation will be completed in the future.'
'400':
description: >-
Bad request, the instance with the specified ID is no running inside
a docker container or the assigned instance is of the wrong
component type.
'404':
description: One of the ids was not found on the server
'500':
description: Internal server error
definitions:
InstanceNetwork:
type: object
required:
- instances
- links
properties:
instances:
type: array
items:
$ref: '#/definitions/Instance'
links:
type: array
items:
$ref: '#/definitions/InstanceLink'
InstanceLink:
type: object
required:
- idFrom
- idTo
- linkState
properties:
idFrom:
type: integer
format: int64
example: 0
idTo:
type: integer
format: int64
example: 42
linkState:
type: string
description: Valid states for an InstanceLink
example: Assigned
enum:
- Assigned
- Outdated
- Failed
Event:
type: object
required:
Expand Down Expand Up @@ -557,3 +760,10 @@ definitions:
- Stopped
- Paused
- NotReachable
labels:
type: array
items:
type: string
example:
- private
- debug
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ To obtain these images, checkout the respective repositories ([here](https://git
sbt docker:publishLocal
```
inside their root directory. This will build the docker images and register them directly at the local docker registry.
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*.

## Contributing

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package de.upb.cs.swt.delphi.instanceregistry

class Configuration( ) {
//Where to host the http server
val bindHost: String = "0.0.0.0"
val bindPort: Int = 8087


val recoveryFileName : String = "dump.temp"

//Default ports for the Delphi components
val defaultCrawlerPort: Int = 8882
val defaultWebApiPort: Int = 8080
val defaultWepAppPort: Int = 8085

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

//Where the initial ElasticSearch instance is located at
val defaultElasticSearchInstanceHost: String = "elasticsearch://172.17.0.1"
val defaultElasticSearchInstancePort: Int = 9200

//Where this registry can be contacted at inside the LAN
val uriInLocalNetwork: String = "http://172.17.0.1:8087"

val maxLabelLength: Int = 50

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,15 @@ class ContainerCommands(connection: DockerConnection) extends JsonSupport with C
def logs(
containerId: String
)(implicit ec: ExecutionContext): Source[String, NotUsed] = {
val query = Query("all")
val request = Get(buildUri(containersPath / containerId / "logs", query))
val query = Query("stdout" -> "true" )
val request = Get(buildUri(containersPath / containerId.substring(0,11) / "logs", query))

val flow =
Flow[HttpResponse].map {
case HttpResponse(StatusCodes.OK, _, HttpEntity.Chunked(_, chunks), _) =>
chunks.map(_.data().utf8String)
case HttpResponse(StatusCodes.NotFound, _, _, _) =>
case HttpResponse(StatusCodes.NotFound, _, HttpEntity.Strict(_, data), _) =>
log.warning(s"DOCKER LOGS FAILED: ${data.utf8String}")
throw ContainerNotFoundException(containerId)
case response =>
unknownResponse(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class DockerActor(connection: DockerConnection) extends Actor with ActorLogging
}

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

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

case logs(containerId: String) =>
log.info(s"Fetching Container logs")
container.logs(containerId)
log.info(s"Fetching Container logs")
sender ! container.logs(containerId)

case x => log.warning("Received unknown message: [{}] ", x)
}
Expand Down
Loading