Skip to content

Commit

Permalink
Merge pull request #103 from delphi-hub/release/0.8.0
Browse files Browse the repository at this point in the history
Release/0.8.0
  • Loading branch information
bhermann authored Feb 4, 2019
2 parents e5721fa + 1eda9a5 commit be0fe92
Show file tree
Hide file tree
Showing 189 changed files with 17,322 additions and 22,871 deletions.
6 changes: 5 additions & 1 deletion .gitignore
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/
14 changes: 12 additions & 2 deletions .travis.yml
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'
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ A management console for the Delphi platform.
We are currently in pre-alpha state! There is no release and the code in
this repository is purely experimental!

|branch | status | codacy |
| :---: | :---: | :---: |
| master | [![Build Status](https://travis-ci.org/delphi-hub/delphi-management.svg?branch=master)](https://travis-ci.org/delphi-hub/delphi-management) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0a50d2132e6b46adb6f6eb36b6ddc4e7)](https://www.codacy.com/app/delphi-hub/delphi-management?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=delphi-hub/delphi-management&amp;utm_campaign=Badge_Grade)|
| develop | [![Build Status](https://travis-ci.org/delphi-hub/delphi-management.svg?branch=develop)](https://travis-ci.org/delphi-hub/delphi-management) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0a50d2132e6b46adb6f6eb36b6ddc4e7?branch=develop)](https://www.codacy.com/app/delphi-hub/delphi-management?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=delphi-hub/delphi-management&amp;utm_campaign=Badge_Grade) |
|branch | status | codacy | snyk |
| :---: | :---: | :---: | :---: |
| master | [![Build Status](https://travis-ci.org/delphi-hub/delphi-management.svg?branch=master)](https://travis-ci.org/delphi-hub/delphi-management) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0a50d2132e6b46adb6f6eb36b6ddc4e7)](https://www.codacy.com/app/delphi-hub/delphi-management?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=delphi-hub/delphi-management&amp;utm_campaign=Badge_Grade)| [![Known Vulnerabilities](https://snyk.io/test/github/delphi-hub/delphi-management/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/delphi-hub/delphi-management/?targetFile=build.sbt) |
| develop | [![Build Status](https://travis-ci.org/delphi-hub/delphi-management.svg?branch=develop)](https://travis-ci.org/delphi-hub/delphi-management) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0a50d2132e6b46adb6f6eb36b6ddc4e7?branch=develop)](https://www.codacy.com/app/delphi-hub/delphi-management?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=delphi-hub/delphi-management&amp;utm_campaign=Badge_Grade) | [![Known Vulnerabilities](https://snyk.io/test/github/delphi-hub/delphi-management/develop/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/delphi-hub/delphi-management/develop/?targetFile=build.sbt) |

## What is the Delphi Management Console?

Expand All @@ -19,9 +19,21 @@ It is a web application to allow administrators to control the crawling process.
It takes commands from authenticated administrators over the web interface and issues the appropriate steps in the crawler.

## How can I use it?
To build the angular app for deployment make sure to have npm and the angular cli installed

```
cd client && npm install && ng build --prod && cd ..
```

For OS X users you need to expose the TCP port manually. The docker FAQ suggest it in this way:

```
docker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 127.0.0.1:9095:9095 bobrik/socat TCP-LISTEN:9095,fork UNIX-CONNECT:/var/run/docker.sock
```

For any deployed instance you need an administrator account to interact with the application.
You can start your own instance by executing

```
sbt run
```
Expand Down
63 changes: 63 additions & 0 deletions app/actors/ClientSocketActor.scala
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()
}

}
81 changes: 81 additions & 0 deletions app/actors/PublishSocketMessageActor.scala
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)
})
}
}

}
48 changes: 48 additions & 0 deletions app/controllers/ApiRouter.scala
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)

}
}
128 changes: 0 additions & 128 deletions app/controllers/AuthController.scala

This file was deleted.

Loading

0 comments on commit be0fe92

Please sign in to comment.