Skip to content

Commit be0fe92

Browse files
authored
Merge pull request #103 from delphi-hub/release/0.8.0
Release/0.8.0
2 parents e5721fa + 1eda9a5 commit be0fe92

File tree

189 files changed

+17322
-22871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+17322
-22871
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
*.class
22
*.log
3-
3+
public
44
/.idea/
55
/target/
66
/project/project/
77
/project/target/
8+
9+
client/.github/
10+
client/.travis.yml
11+
client/.vscode/

.travis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
language: scala
22
scala:
33
- 2.12.4
4+
5+
addons:
6+
apt:
7+
sources:
8+
- google-chrome
9+
packages:
10+
- google-chrome-stable
11+
12+
before_install:
13+
- npm install -g @angular/cli
414
script:
5-
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sbt ++$TRAVIS_SCALA_VERSION test; fi'
6-
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sbt ++$TRAVIS_SCALA_VERSION coverage test coverageReport coverageAggregate codacyCoverage; fi'
15+
- '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'
16+
- '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'
717
after_success:
818
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash <(curl -s https://codecov.io/bash); fi'

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ A management console for the Delphi platform.
55
We are currently in pre-alpha state! There is no release and the code in
66
this repository is purely experimental!
77

8-
|branch | status | codacy |
9-
| :---: | :---: | :---: |
10-
| 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)|
11-
| 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) |
8+
|branch | status | codacy | snyk |
9+
| :---: | :---: | :---: | :---: |
10+
| 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) |
11+
| 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) |
1212

1313
## What is the Delphi Management Console?
1414

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

2121
## How can I use it?
22+
To build the angular app for deployment make sure to have npm and the angular cli installed
23+
24+
```
25+
cd client && npm install && ng build --prod && cd ..
26+
```
27+
28+
For OS X users you need to expose the TCP port manually. The docker FAQ suggest it in this way:
29+
30+
```
31+
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
32+
```
2233

2334
For any deployed instance you need an administrator account to interact with the application.
2435
You can start your own instance by executing
36+
2537
```
2638
sbt run
2739
```

app/actors/ClientSocketActor.scala

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package actors
2+
import akka.actor._
3+
import actors.PublishSocketMessageActor.{AddOutActor, PublishMessage, StopMessage}
4+
import models.EventEnums.EventType
5+
import models.{EventJsonSupport, SocketMessage}
6+
import play.api.Logger
7+
import spray.json._
8+
9+
import scala.collection.mutable.HashSet
10+
import play.api.libs.json._
11+
import play.api.libs.functional.syntax._
12+
13+
object ClientSocketActor {
14+
def props(out: ActorRef, publisher: ActorRef): Props = Props(new ClientSocketActor(out, publisher))
15+
}
16+
17+
class ClientSocketActor(out: ActorRef, publisher: ActorRef) extends Actor with EventJsonSupport {
18+
19+
val myEvents: HashSet[EventType] = HashSet.empty[EventType]
20+
21+
implicit val messageReads: Reads[SocketMessage] = ((JsPath \ "event").read[EventType] and
22+
(JsPath \ "payload").readNullable[String])(SocketMessage.apply _)
23+
implicit val messageWrites: Writes[SocketMessage] = Json.writes[SocketMessage]
24+
25+
override def preStart() {
26+
Logger.debug("pre start called in client" + self)
27+
out ! "successfully registered"
28+
}
29+
30+
override def postStop() {
31+
Logger.debug("post stop called in client" + self)
32+
publisher ! StopMessage(self)
33+
}
34+
35+
def receive: PartialFunction[Any, Unit] = {
36+
case msg: String =>
37+
val json = Json.parse(msg)
38+
val result = json.validate[SocketMessage]
39+
result.fold(
40+
errors => {Logger.error("error parsing message to json" + msg + " with error " + errors)},
41+
socketMsg => {
42+
Logger.debug("successfully parsed socket message" + socketMsg)
43+
if (socketMsg.event == EventType.Heartbeat) {
44+
out ! "Heartbeat"
45+
} else {
46+
publisher ! AddOutActor(self, socketMsg.event)
47+
}
48+
}
49+
)
50+
51+
case SocketMessage(event, payload) =>
52+
Logger.debug("received socket message in client" + SocketMessage)
53+
if (!myEvents.contains(event)) {
54+
myEvents += event
55+
publisher ! AddOutActor(self, event)
56+
}
57+
58+
case PublishMessage(msg) =>
59+
Logger.debug("received publish message in client" + self)
60+
out ! msg.toJson(eventFormat).toString()
61+
}
62+
63+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package actors
2+
import akka.actor._
3+
import akka.http.scaladsl.model.ws.{Message, TextMessage, WebSocketRequest}
4+
import actors.PublishSocketMessageActor.{AddOutActor, PublishMessage, StopMessage}
5+
import akka.http.scaladsl.Http
6+
import akka.stream.Materializer
7+
import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
8+
import models.EventEnums.EventType
9+
import models.{EventJsonSupport, RegistryEvent}
10+
import play.api.Logger
11+
import spray.json._
12+
13+
import scala.collection.mutable
14+
import scala.collection.mutable.ListBuffer
15+
import scala.concurrent.Promise
16+
17+
object PublishSocketMessageActor {
18+
def props(irBasePath: String, mat: Materializer, actorSys: ActorSystem):Props = Props(new PublishSocketMessageActor(irBasePath, mat, actorSys))
19+
final case class AddOutActor(out: ActorRef, event: EventType)
20+
final case class PublishMessage(msg: RegistryEvent)
21+
final case class StopMessage(toStop: ActorRef)
22+
}
23+
24+
class PublishSocketMessageActor(irBasePath: String, mat: Materializer, actorSys: ActorSystem) extends Actor with EventJsonSupport {
25+
26+
val eventActorMap: mutable.HashMap[EventType, ListBuffer[ActorRef]] = new mutable.HashMap[EventType, ListBuffer[ActorRef]]()
27+
28+
override def preStart() {
29+
30+
Logger.debug("pre start called in publisher" + self)
31+
val flow: Flow[Message, Message, Promise[Option[Message]]] =
32+
Flow.fromSinkAndSourceMat(
33+
Sink.foreach[Message]{ msg =>
34+
self ! msg},
35+
Source(List(TextMessage("one"), TextMessage("two")))
36+
.concatMat(Source.maybe[Message])(Keep.right))(Keep.right)
37+
38+
39+
Http()(actorSys).singleWebSocketRequest(
40+
WebSocketRequest("ws://" + irBasePath + "/events"),
41+
flow)(mat)
42+
43+
44+
}
45+
46+
override def postStop() {
47+
Logger.debug("post stop called in publisher" + self)
48+
}
49+
50+
def receive: PartialFunction[Any, Unit] = {
51+
52+
case StopMessage(toStop) =>
53+
Logger.debug("stop received" + toStop)
54+
for ((k, v) <- eventActorMap) v -= toStop
55+
56+
case AddOutActor(out, event) =>
57+
Logger.debug("received add out actor" + out)
58+
if (!eventActorMap.contains(event)){
59+
eventActorMap += (event -> new ListBuffer[ActorRef]())
60+
}
61+
eventActorMap(event) += out
62+
63+
64+
case TextMessage.Strict(msg) =>
65+
Logger.debug("received something " + msg)
66+
val registryEvent = msg.parseJson.convertTo[RegistryEvent](eventFormat)
67+
self ! PublishMessage(registryEvent)
68+
69+
case PublishMessage(msg) =>
70+
Logger.debug("publish message called with message" + msg)
71+
if(eventActorMap.contains(msg.eventType)){
72+
73+
val list = eventActorMap(msg.eventType)
74+
list.foreach(actor => {
75+
Logger.debug("sending message to actor" + actor)
76+
actor ! PublishMessage(msg)
77+
})
78+
}
79+
}
80+
81+
}

app/controllers/ApiRouter.scala

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2018 The Delphi Team.
3+
* See the LICENCE file distributed with this work for additional
4+
* information regarding copyright ownership.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package controllers
20+
21+
import javax.inject.Inject
22+
import play.api.routing.Router.Routes
23+
import play.api.routing.SimpleRouter
24+
import play.api.routing.sird._
25+
26+
/**
27+
* Router used to manage access to all available API
28+
* Endpoints.
29+
* @param controller Controller components reference
30+
*/
31+
class ApiRouter @Inject()(irController: InstanceRegistryController, sysController: SystemInfoController)
32+
extends SimpleRouter
33+
{
34+
35+
override def routes: Routes = {
36+
case GET(p"/numberOfInstances" ? q"componentType=$componentType") => irController.numberOfInstances(componentType)
37+
case GET(p"/instances" ? q"componentType=$componentType") => irController.instances(componentType)
38+
case GET(p"/systemInfo") => sysController.getInfo()
39+
case GET(p"/network") => irController.getNetwork()
40+
case POST(p"/postInstance" ? q"componentType=$componentType"& q"name=$name") => irController.postInstance(componentType, name)
41+
case POST(p"/startInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/start", instanceID)
42+
case POST(p"/stopInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/stop", instanceID)
43+
case POST(p"/pauseInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/pause", instanceID)
44+
case POST(p"/resumeInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/resume", instanceID)
45+
case POST(p"/deleteInstance" ? q"instanceID=$instanceID") => irController.handleRequest(action="/delete", instanceID)
46+
47+
}
48+
}

app/controllers/AuthController.scala

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)