Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d6552a5
added cytoscape dependency
janniclas Nov 17, 2018
7c4809f
created model service and dummy graph view
janniclas Nov 22, 2018
3a455a9
fixed duplicate method name in store service
janniclas Nov 22, 2018
7721987
added networks endpoint to scala play server to query an array of all…
janniclas Nov 23, 2018
e44ebbb
fixed a bug regarding a duplicate method name
janniclas Nov 23, 2018
f5a21d9
fixed a bug where the publishEventName is not set if the eventtype is…
janniclas Nov 23, 2018
762ecf1
included the model service into the application's lifecycle. created …
janniclas Nov 23, 2018
f2b4f1b
fixed bug in socket service which permits handling of event payloads
janniclas Nov 23, 2018
749a84f
alpha version of network visualization ( no edge remove)
janniclas Nov 23, 2018
14f258a
added elasticsearch logo
janniclas Nov 23, 2018
d807ba3
pulled typesaftey update for socket service
Nov 30, 2018
3b857f1
using parameterized types in socket service
Nov 30, 2018
d34cb44
publishing a change object instead of a plain array of changed object…
Dec 3, 2018
a17ba99
graph service and component are now able to handle remove of elements
Dec 3, 2018
3a58c8a
uncommented unfinished code
janniclas Dec 13, 2018
f42aebd
merged develop branch
janniclas Dec 13, 2018
fefc048
Merge branch 'develop' into feature/modelService
janniclas Dec 13, 2018
0776a80
removed the graph functionality to create a base version of the model…
janniclas Dec 27, 2018
4b81926
merged cleanup feature branch
janniclas Dec 27, 2018
caac428
updated package.json version to start versioning according to milestones
janniclas Dec 27, 2018
a1d1fcb
fixed compile errors regarding incorrect typescript version and missi…
janniclas Dec 27, 2018
6a64bfb
minor changes to store and model service.
janniclas Dec 30, 2018
47f4cef
stopped logging the heartbeat message
janniclas Dec 30, 2018
eb3dcd7
code cleanup and comments
janniclas Dec 30, 2018
4a381c1
added comments to store class
janniclas Dec 30, 2018
f2f1b3b
commented the model service
janniclas Dec 30, 2018
eabfb48
fixed stupid typo
janniclas Dec 30, 2018
6b0310b
updated test cases to fit new modelservice
janniclas Dec 30, 2018
8b78d56
reintroduced graph view compnent which accidently got deleted in the …
Jan 2, 2019
2cee45d
Merge branch 'develop' into feature/modelService
janniclas Jan 3, 2019
a1b4501
updated event model class according to the changes in the instance re…
janniclas Jan 3, 2019
3b6add0
created standalone method for socket message parsing
janniclas Jan 10, 2019
43ae875
resturctured socket message parsing.
janniclas Jan 13, 2019
8650cb5
now subscribes and logs link state changed events
janniclas Jan 13, 2019
8be509d
added InstanceLinkPayload model to handle the instanceChanged events
janniclas Jan 13, 2019
595063c
minor changes in logging and type check of socket messages
janniclas Jan 13, 2019
831afb3
Merge branch 'feature/cytoscape' into feature/modelService
janniclas Jan 13, 2019
2b5e1e1
removed graph view after merge of graphview branch
janniclas Jan 13, 2019
5f6ca5a
updated dependencies
janniclas Jan 13, 2019
5018daa
added handling for instance link state change
janniclas Jan 13, 2019
46d8d46
Merge branch 'develop' into feature/modelService
janniclas Jan 14, 2019
acb052a
hotfix for the bug causing an instance to be deleted wether the dialo…
janniclas Jan 15, 2019
a4585d2
Merge branch 'feature/modelService' of github.com:delphi-hub/delphi-m…
janniclas Jan 15, 2019
905426a
minor changes to dialog implementation to test behavior on firefox
janniclas Jan 15, 2019
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
1 change: 1 addition & 0 deletions app/controllers/ApiRouter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ApiRouter @Inject()(irController: InstanceRegistryController, sysControlle
case GET(p"/numberOfInstances" ? q"componentType=$componentType") => irController.numberOfInstances(componentType)
case GET(p"/instances" ? q"componentType=$componentType") => irController.instances(componentType)
case GET(p"/systemInfo") => sysController.getInfo()
case GET(p"/network") => irController.getNetwork()
case POST(p"/postInstance" ? q"componentType=$componentType"& q"name=$name") => irController.postInstance(componentType, name)
case POST(p"/startInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/start", instanceID)
case POST(p"/stopInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/stop", instanceID)
Expand Down
13 changes: 12 additions & 1 deletion app/controllers/InstanceRegistryController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package controllers

import akka.actor.{ActorRef, ActorSystem}
import javax.inject.Inject
import play.api.Configuration
import play.api.{Configuration, Logger}
import play.api.libs.concurrent.CustomExecutionContext
import play.api.libs.json._
import play.api.libs.ws.WSClient
Expand Down Expand Up @@ -80,6 +80,17 @@ class InstanceRegistryController @Inject()(implicit system: ActorSystem, mat: Ma
}
}

def getNetwork(): Action[AnyContent] = Action.async {
ws.url(instanceRegistryUri + "/network").get().map { response =>
// TODO: possible handling of parsing the data can be done here
Logger.debug(response.body)
if (response.status == 200) {
Ok(response.body)
} else {
new Status(response.status)
}
}(myExecutionContext)
}

def numberOfInstances(componentType: String) : Action[AnyContent] = Action.async {
// TODO: handle what should happen if the instance registry is not reachable.
Expand Down
68 changes: 47 additions & 21 deletions app/models/Event.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.model.DateTime
import models.EventEnums.EventType
import models.InstanceEnums.ComponentType
import play.api.libs.json.{Reads, Writes}
Expand Down Expand Up @@ -80,9 +81,31 @@ trait EventJsonSupport extends SprayJsonSupport with DefaultJsonProtocol with In
}

}
//Custom JSON format for event TimeStamp.
implicit val timestampFormat: JsonFormat[DateTime] = new JsonFormat[DateTime] {
/**
* Custom write method for serialization of DateTime
* @param obj DateTime object to serialize
* @throws DeserializationException Exception in case of wrong input
*/
override def write(obj: DateTime) = JsString(obj.toIsoDateTimeString())
/**
* Custom read method for deserialization of DateTime
* @param json JsValue that is to be deserialized
* @throws DeserializationException Exception when JsValue is in incorrect format
*/
override def read(json: JsValue): DateTime = json match {
case JsString(value) =>
DateTime.fromIsoDateTimeString(value) match {
case Some(date) => date
case _ => throw DeserializationException("Failed to parse date time [" + value + "].")
}
case _ => throw DeserializationException("Failed to parse json string [" + json + "].")
}
}

//JSON format for RegistryEvents
implicit val eventFormat : JsonFormat[RegistryEvent] = jsonFormat2(RegistryEvent)
implicit val eventFormat : JsonFormat[RegistryEvent] = jsonFormat3(RegistryEvent)

//JSON format for an NumbersChangedPayload
implicit val numbersChangedPayloadFormat: JsonFormat[NumbersChangedPayload] = jsonFormat2(NumbersChangedPayload)
Expand All @@ -96,18 +119,20 @@ trait EventJsonSupport extends SprayJsonSupport with DefaultJsonProtocol with In

//JSON format for an InstanceLinkPayload
implicit val instanceLinkPayloadFormat: JsonFormat[InstanceLinkPayload] =
jsonFormat1(InstanceLinkPayload)
jsonFormat3(InstanceLinkPayload)

}

/**
* The RegistryEvent used for communicating with the management application
* @param eventType Type of the event
* @param payload Payload of the event, depends on the type
* @param timestamp TimeStamp of the event
*/
final case class RegistryEvent (
eventType: EventType.Value,
payload: RegistryEventPayload
payload: RegistryEventPayload,
timestamp: DateTime
)

/**
Expand All @@ -119,59 +144,59 @@ object RegistryEventFactory {
* Creates a new NumbersChangedEvent. Sets EventType and payload accordingly.
* @param componentType ComponentType which's numbers have been updated
* @param newNumber New number of components of the specified type
* @return RegistryEvent with the respective type and payload.
* @return RegistryEvent with the respective respective type, payload and current timestamp.
*/
def createNumbersChangedEvent(componentType: ComponentType, newNumber: Int) : RegistryEvent =
RegistryEvent(EventType.NumbersChangedEvent, NumbersChangedPayload(componentType, newNumber))
RegistryEvent(EventType.NumbersChangedEvent, NumbersChangedPayload(componentType, newNumber), DateTime.now)

/**
* Creates a new InstanceAddedEvent. Sets EventType and payload accordingly.
* @param instance Instance that has been added.
* @return RegistryEvent with the respective type and payload.
* @return RegistryEvent with the respective type, payload and current timestamp.
*/
def createInstanceAddedEvent(instance: Instance) : RegistryEvent =
RegistryEvent(EventType.InstanceAddedEvent, InstancePayload(instance))
RegistryEvent(EventType.InstanceAddedEvent, InstancePayload(instance), DateTime.now)

/**
* Creates a new InstanceRemovedEvent. Sets EventType and payload accordingly.
* @param instance Instance that has been removed.
* @return RegistryEvent with the respective type and payload.
* @return RegistryEvent with the respective type, payload and current timestamp.
*/
def createInstanceRemovedEvent(instance: Instance) : RegistryEvent =
RegistryEvent(EventType.InstanceRemovedEvent, InstancePayload(instance))
RegistryEvent(EventType.InstanceRemovedEvent, InstancePayload(instance), DateTime.now)

/**
* Creates a new StateChangedEvent. Sets EventType and payload accordingly.
* @param instance Instance which's state was changed.
* @return RegistryEvent with tht respective type and payload.
* @return RegistryEvent with tht respective type, payload and current timestamp.
*/
def createStateChangedEvent(instance: Instance) : RegistryEvent =
RegistryEvent(EventType.StateChangedEvent, InstancePayload(instance))
RegistryEvent(EventType.StateChangedEvent, InstancePayload(instance), DateTime.now)

/**
* Creates a new DockerOperationErrorEvent. Sets EventType and payload accordingly.
* @param affectedInstance Option[Instance] containing the instance that may be affected
* @param message Error message
* @return RegistryEvent with the respective type and payload.
* @return RegistryEvent with the respective respective type, payload and current timestamp.
*/
def createDockerOperationErrorEvent(affectedInstance: Option[Instance], message: String) : RegistryEvent =
RegistryEvent(EventType.DockerOperationErrorEvent, DockerOperationErrorPayload(affectedInstance, message))
RegistryEvent(EventType.DockerOperationErrorEvent, DockerOperationErrorPayload(affectedInstance, message),DateTime.now)

/**
* Creates a new LinkAddedEvent. Sets EventType and payload accordingly
* @param link Link that was added
* @return RegistryEvent with the respective type and payload
* @return RegistryEvent with the respective type, payload and current timestamp.
*/
def createLinkAddedEvent(link: InstanceLink) : RegistryEvent =
RegistryEvent(EventType.LinkAddedEvent, InstanceLinkPayload(link))
def createLinkAddedEvent(link: InstanceLink, instanceFrom: Instance, instanceTo: Instance) : RegistryEvent =
RegistryEvent(EventType.LinkAddedEvent, InstanceLinkPayload(link, instanceFrom, instanceTo),DateTime.now)

/**
* Creates a new LinkStateChangedEvent. Sets EventType and payload accordingly.
* @param link Link whichs state has been changed
* @return RegistryEvent with the respective type and payload
* @return RegistryEvent with the respective type, payload and current timestamp.
*/
def createLinkStateChangedEvent(link: InstanceLink) : RegistryEvent =
RegistryEvent(EventType.LinkStateChangedEvent, InstanceLinkPayload(link))
def createLinkStateChangedEvent(link: InstanceLink, instanceFrom: Instance, instanceTo: Instance) : RegistryEvent =
RegistryEvent(EventType.LinkStateChangedEvent, InstanceLinkPayload(link, instanceFrom, instanceTo),DateTime.now)
}

/**
Expand Down Expand Up @@ -209,7 +234,8 @@ final case class DockerOperationErrorPayload(affectedInstance: Option[Instance],
* link that was added / changed.
* @param link Link that caused the event
*/
final case class InstanceLinkPayload(link: InstanceLink) extends RegistryEventPayload
final case class InstanceLinkPayload(link: InstanceLink, instanceFrom: Instance, instanceTo: Instance)
extends RegistryEventPayload


/**
Expand All @@ -235,5 +261,5 @@ object EventEnums {

implicit val EventTypeReads: Reads[EventType] = Reads.enumNameReads(EventType)
implicit val EventTypeWrites: Writes[EventType] = Writes.enumNameWrites
}
}
}
24 changes: 13 additions & 11 deletions app/models/Instance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import spray.json.{DefaultJsonProtocol, DeserializationException, JsString, JsVa
/**
* Trait defining the implicit JSON formats needed to work with Instances
*/
trait InstanceJsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
trait InstanceJsonSupport extends SprayJsonSupport with DefaultJsonProtocol with InstanceLinkJsonSupport {

//Custom JSON format for an ComponentType
implicit val componentTypeFormat : JsonFormat[ComponentType] = new JsonFormat[ComponentType] {
Expand Down Expand Up @@ -69,7 +69,7 @@ trait InstanceJsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
}

//JSON format for Instances
implicit val instanceFormat : JsonFormat[Instance] = jsonFormat8(Instance)
implicit val instanceFormat : JsonFormat[Instance] = jsonFormat10(Instance)
}

/**
Expand All @@ -83,15 +83,17 @@ trait InstanceJsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
* @param instanceState State of the instance
*/
final case class Instance (
id: Option[Long],
host: String,
portNumber: Long,
name: String,
componentType: ComponentType,
dockerId: Option[String],
instanceState: InstanceState,
labels: List[String]
)
id: Option[Long],
host: String,
portNumber: Long,
name: String,
componentType: ComponentType,
dockerId: Option[String],
instanceState: InstanceState,
labels: List[String],
linksTo: List[InstanceLink],
linksFrom: List[InstanceLink]
)

/**
* Enumerations concerning instances
Expand Down
Loading