-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from delphi-hub/release/0.8.0
Release/0.8.0
- Loading branch information
Showing
189 changed files
with
17,322 additions
and
22,871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
*.class | ||
*.log | ||
|
||
public | ||
/.idea/ | ||
/target/ | ||
/project/project/ | ||
/project/target/ | ||
|
||
client/.github/ | ||
client/.travis.yml | ||
client/.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
language: scala | ||
scala: | ||
- 2.12.4 | ||
|
||
addons: | ||
apt: | ||
sources: | ||
- google-chrome | ||
packages: | ||
- google-chrome-stable | ||
|
||
before_install: | ||
- npm install -g @angular/cli | ||
script: | ||
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sbt ++$TRAVIS_SCALA_VERSION test; fi' | ||
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sbt ++$TRAVIS_SCALA_VERSION coverage test coverageReport coverageAggregate codacyCoverage; fi' | ||
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sbt ++$TRAVIS_SCALA_VERSION test; cd client && npm install && ng build --prod && npm run test -- --no-progress --browsers=ChromeHeadlessCI --source-map=false && cd .. ; fi' | ||
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sbt ++$TRAVIS_SCALA_VERSION coverage test coverageReport coverageAggregate codacyCoverage; cd client && npm install && ng build --prod && npm run test -- --no-progress --browsers=ChromeHeadlessCI --source-map=false && cd .. ; fi' | ||
after_success: | ||
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash <(curl -s https://codecov.io/bash); fi' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package actors | ||
import akka.actor._ | ||
import actors.PublishSocketMessageActor.{AddOutActor, PublishMessage, StopMessage} | ||
import models.EventEnums.EventType | ||
import models.{EventJsonSupport, SocketMessage} | ||
import play.api.Logger | ||
import spray.json._ | ||
|
||
import scala.collection.mutable.HashSet | ||
import play.api.libs.json._ | ||
import play.api.libs.functional.syntax._ | ||
|
||
object ClientSocketActor { | ||
def props(out: ActorRef, publisher: ActorRef): Props = Props(new ClientSocketActor(out, publisher)) | ||
} | ||
|
||
class ClientSocketActor(out: ActorRef, publisher: ActorRef) extends Actor with EventJsonSupport { | ||
|
||
val myEvents: HashSet[EventType] = HashSet.empty[EventType] | ||
|
||
implicit val messageReads: Reads[SocketMessage] = ((JsPath \ "event").read[EventType] and | ||
(JsPath \ "payload").readNullable[String])(SocketMessage.apply _) | ||
implicit val messageWrites: Writes[SocketMessage] = Json.writes[SocketMessage] | ||
|
||
override def preStart() { | ||
Logger.debug("pre start called in client" + self) | ||
out ! "successfully registered" | ||
} | ||
|
||
override def postStop() { | ||
Logger.debug("post stop called in client" + self) | ||
publisher ! StopMessage(self) | ||
} | ||
|
||
def receive: PartialFunction[Any, Unit] = { | ||
case msg: String => | ||
val json = Json.parse(msg) | ||
val result = json.validate[SocketMessage] | ||
result.fold( | ||
errors => {Logger.error("error parsing message to json" + msg + " with error " + errors)}, | ||
socketMsg => { | ||
Logger.debug("successfully parsed socket message" + socketMsg) | ||
if (socketMsg.event == EventType.Heartbeat) { | ||
out ! "Heartbeat" | ||
} else { | ||
publisher ! AddOutActor(self, socketMsg.event) | ||
} | ||
} | ||
) | ||
|
||
case SocketMessage(event, payload) => | ||
Logger.debug("received socket message in client" + SocketMessage) | ||
if (!myEvents.contains(event)) { | ||
myEvents += event | ||
publisher ! AddOutActor(self, event) | ||
} | ||
|
||
case PublishMessage(msg) => | ||
Logger.debug("received publish message in client" + self) | ||
out ! msg.toJson(eventFormat).toString() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package actors | ||
import akka.actor._ | ||
import akka.http.scaladsl.model.ws.{Message, TextMessage, WebSocketRequest} | ||
import actors.PublishSocketMessageActor.{AddOutActor, PublishMessage, StopMessage} | ||
import akka.http.scaladsl.Http | ||
import akka.stream.Materializer | ||
import akka.stream.scaladsl.{Flow, Keep, Sink, Source} | ||
import models.EventEnums.EventType | ||
import models.{EventJsonSupport, RegistryEvent} | ||
import play.api.Logger | ||
import spray.json._ | ||
|
||
import scala.collection.mutable | ||
import scala.collection.mutable.ListBuffer | ||
import scala.concurrent.Promise | ||
|
||
object PublishSocketMessageActor { | ||
def props(irBasePath: String, mat: Materializer, actorSys: ActorSystem):Props = Props(new PublishSocketMessageActor(irBasePath, mat, actorSys)) | ||
final case class AddOutActor(out: ActorRef, event: EventType) | ||
final case class PublishMessage(msg: RegistryEvent) | ||
final case class StopMessage(toStop: ActorRef) | ||
} | ||
|
||
class PublishSocketMessageActor(irBasePath: String, mat: Materializer, actorSys: ActorSystem) extends Actor with EventJsonSupport { | ||
|
||
val eventActorMap: mutable.HashMap[EventType, ListBuffer[ActorRef]] = new mutable.HashMap[EventType, ListBuffer[ActorRef]]() | ||
|
||
override def preStart() { | ||
|
||
Logger.debug("pre start called in publisher" + self) | ||
val flow: Flow[Message, Message, Promise[Option[Message]]] = | ||
Flow.fromSinkAndSourceMat( | ||
Sink.foreach[Message]{ msg => | ||
self ! msg}, | ||
Source(List(TextMessage("one"), TextMessage("two"))) | ||
.concatMat(Source.maybe[Message])(Keep.right))(Keep.right) | ||
|
||
|
||
Http()(actorSys).singleWebSocketRequest( | ||
WebSocketRequest("ws://" + irBasePath + "/events"), | ||
flow)(mat) | ||
|
||
|
||
} | ||
|
||
override def postStop() { | ||
Logger.debug("post stop called in publisher" + self) | ||
} | ||
|
||
def receive: PartialFunction[Any, Unit] = { | ||
|
||
case StopMessage(toStop) => | ||
Logger.debug("stop received" + toStop) | ||
for ((k, v) <- eventActorMap) v -= toStop | ||
|
||
case AddOutActor(out, event) => | ||
Logger.debug("received add out actor" + out) | ||
if (!eventActorMap.contains(event)){ | ||
eventActorMap += (event -> new ListBuffer[ActorRef]()) | ||
} | ||
eventActorMap(event) += out | ||
|
||
|
||
case TextMessage.Strict(msg) => | ||
Logger.debug("received something " + msg) | ||
val registryEvent = msg.parseJson.convertTo[RegistryEvent](eventFormat) | ||
self ! PublishMessage(registryEvent) | ||
|
||
case PublishMessage(msg) => | ||
Logger.debug("publish message called with message" + msg) | ||
if(eventActorMap.contains(msg.eventType)){ | ||
|
||
val list = eventActorMap(msg.eventType) | ||
list.foreach(actor => { | ||
Logger.debug("sending message to actor" + actor) | ||
actor ! PublishMessage(msg) | ||
}) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2018 The Delphi Team. | ||
* See the LICENCE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package controllers | ||
|
||
import javax.inject.Inject | ||
import play.api.routing.Router.Routes | ||
import play.api.routing.SimpleRouter | ||
import play.api.routing.sird._ | ||
|
||
/** | ||
* Router used to manage access to all available API | ||
* Endpoints. | ||
* @param controller Controller components reference | ||
*/ | ||
class ApiRouter @Inject()(irController: InstanceRegistryController, sysController: SystemInfoController) | ||
extends SimpleRouter | ||
{ | ||
|
||
override def routes: Routes = { | ||
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) | ||
case POST(p"/pauseInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/pause", instanceID) | ||
case POST(p"/resumeInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/resume", instanceID) | ||
case POST(p"/deleteInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/delete", instanceID) | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.