Skip to content

Update stable features into master #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ac62649
Adapted instance registry client to reflect the interface change in e…
Nov 4, 2018
d2f3ac7
Adapted instance model to reflect latest changes: attribute 'labels' …
Nov 5, 2018
c2441e8
Merge pull request #33 from delphi-hub/feature/newMatchingInterface
bhermann Nov 8, 2018
cfac628
Added api request limit by ip functionality #8
Nov 13, 2018
37c836d
Merge pull request #35 from delphi-hub/Feature/8/RequestLimit
bhermann Nov 16, 2018
13ca827
Adapted api to latest changes of the registry api
Nov 22, 2018
d2ddb34
Inserted missing file header
Nov 26, 2018
4dbb9df
Merge pull request #36 from delphi-hub/feature/linksAsAttributes
bhermann Nov 27, 2018
5cce2b1
Introducing JWT based authentication for communication with registry
Dec 12, 2018
706cac9
Added error handling on result size greater than max result window
Dec 19, 2018
8760666
Added test case for failure on large input result
Dec 19, 2018
59f1f83
Added fork to build.sbt
Dec 19, 2018
85ccf77
Use id as name for JWT where applicable
Dec 19, 2018
300caa1
Fixed application not terminating when connected to registry
Dec 19, 2018
8876011
Removed unused file
Jan 3, 2019
2af18c1
Merge pull request #40 from delphi-hub/Feature/39/TriggeredExe
bhermann Jan 4, 2019
90cc6e3
Codestyle: Inserted spaces before plus operator
Jan 4, 2019
8ce9788
Merge pull request #41 from delphi-hub/feature/authentication
bhermann Jan 4, 2019
32b8a6f
Adapted registry interface to newest API version
Jan 22, 2019
34a97f8
Merge pull request #38 from delphi-hub/bug/34/ResultsSizeError
bhermann Feb 4, 2019
a186175
Fixed variable name being uppercase (codestyle)
Feb 7, 2019
6c50461
Merge pull request #42 from delphi-hub/feature/newRegistryAPI
bhermann Feb 7, 2019
4bd6e3f
update build.sbt file
mgupta0421 May 24, 2019
e4791da
Merge pull request #43 from delphi-hub/feature/vulnerability
bhermann May 24, 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.idea
project/target
target
local-path
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ libraryDependencies ++= Seq(
"com.sksamuel.elastic4s" %% "elastic4s-http-streams" % elastic4sVersion,
)

libraryDependencies += "com.pauldijou" %% "jwt-core" % "1.0.0"

libraryDependencies += "org.parboiled" %% "parboiled" % "2.1.4"
libraryDependencies += "io.spray" %% "spray-json" % "1.3.3"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.4"
Expand Down Expand Up @@ -54,7 +56,9 @@ scalastyleConfig := baseDirectory.value / "project" / "scalastyle-config.xml"
// Pinning secure versions of insecure transitive libraryDependencies
// Please update when updating dependencies above (including Play plugin)
libraryDependencies ++= Seq(
"com.fasterxml.jackson.core" % "jackson-databind" % "2.9.7"
"com.fasterxml.jackson.core" % "jackson-databind" % "2.9.9"
)

trapExit := false
fork := true
connectInput := true
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.1.1
sbt.version=1.2.7
80 changes: 80 additions & 0 deletions src/it/scala/de/upb/cs/swt/delphi/webapi/RequestLimitCheck.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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 de.upb.cs.swt.delphi.webapi

import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpRequest, HttpResponse}
import akka.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec}
import spray.json._

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.util.{Failure, Success}

/**
* @author Hariharan.
*/
class RequestLimitCheck extends WordSpec with Matchers with BeforeAndAfterAll with JsonSupport {
val delphiRoutes = DelphiRoutes()
val serverBinding: Future[Http.ServerBinding] = Http()
.bindAndHandle(delphiRoutes, "localhost", 8085)

override protected def beforeAll(): Unit = {
serverBinding.onComplete {
case Success(server) =>
println(s"Server started at http://${server.localAddress.getHostString}:${server.localAddress.getPort}/")
case Failure(e) =>
e.printStackTrace()
sys.exit(0)
}
}


"Requests" should {
"throttle when limit reached" in {
def responseFuture: Future[HttpResponse] = Http()
.singleRequest(HttpRequest(uri = "http://localhost:8085/version"))

//Completing request limit
for (i <- (1 to maxIndividualReq)) {
Await.result(responseFuture, 1.second)
}
case class LimitMsg(msg: String)
implicit val msgFormat = jsonFormat1(LimitMsg)

val limitReachedFuture = responseFuture
limitReachedFuture.onComplete {
case Success(res) => {
val msgPromise = Unmarshal(res.entity).to[LimitMsg]
msgPromise.onComplete {
case Success(limitMsg) => {
assertResult("Request limit exceeded")(limitMsg.msg)
}
case Failure(exception) => {
fail(exception)
}
}
}
case Failure(exception) => {
fail(exception)
}
}
Await.result(system.terminate(), 5.seconds)
}
}
}
19 changes: 13 additions & 6 deletions src/it/scala/de/upb/cs/swt/delphi/webapi/SearchQueryTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@

package de.upb.cs.swt.delphi.webapi

import de.upb.cs.swt.delphi.webapi.search.{QueryRequest, SearchQuery}
import de.upb.cs.swt.delphi.webapi.search.{QueryRequest, SearchError, SearchQuery}
import org.scalatest.{FlatSpec, Matchers}

import scala.util.Success
import scala.util.Failure

class SearchQueryTest extends FlatSpec with Matchers {
"Search query" should "check for fields" in {
"Search query" should "fail on large request limit" in {
val configuration = new Configuration()
val q = new SearchQuery(configuration, new FeatureQuery(configuration))

val response = q.search(QueryRequest("[if_icmpeq (opcode:159)]>1"))
response shouldBe a [Success[_]]
val size = 20000
val response = q.search(QueryRequest("[dstore_1 (opcode:72)]<1", Some(size)))
response match {
case Failure(exception) => {
exception shouldBe a[SearchError]
}
case _ => {
fail("Limit exceeded should fail")
}
}
}
}
114 changes: 88 additions & 26 deletions src/main/scala/de/upb/cs/swt/delphi/instancemanagement/Instance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,134 @@
// limitations under the License.

package de.upb.cs.swt.delphi.instancemanagement

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import de.upb.cs.swt.delphi.instancemanagement.InstanceEnums.{ComponentType, InstanceState}
import spray.json.{DefaultJsonProtocol, DeserializationException, JsString, JsValue, JsonFormat}

trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
/**
* Trait defining the implicit JSON formats needed to work with Instances
*/
trait InstanceJsonSupport extends SprayJsonSupport with DefaultJsonProtocol with InstanceLinkJsonSupport {

implicit val componentTypeFormat : JsonFormat[InstanceEnums.ComponentType] = new JsonFormat[InstanceEnums.ComponentType] {
//Custom JSON format for an ComponentType
implicit val componentTypeFormat : JsonFormat[ComponentType] = new JsonFormat[ComponentType] {

def write(compType : InstanceEnums.ComponentType) = JsString(compType.toString)
/**
* Custom write method for serializing an ComponentType
* @param compType The ComponentType to serialize
* @return JsString containing the serialized value
*/
def write(compType : ComponentType) = JsString(compType.toString)

def read(value: JsValue) : InstanceEnums.ComponentType = value match {
/**
* Custom read method for deserialization of an ComponentType
* @param value JsValue to deserialize (must be a JsString)
* @return ComponentType that has been read
* @throws DeserializationException Exception thrown when JsValue is in incorrect format
*/
def read(value: JsValue) : ComponentType = value match {
case JsString(s) => s match {
case "Crawler" => InstanceEnums.ComponentType.Crawler
case "WebApi" => InstanceEnums.ComponentType.WebApi
case "WebApp" => InstanceEnums.ComponentType.WebApp
case "DelphiManagement" => InstanceEnums.ComponentType.DelphiManagement
case "ElasticSearch" => InstanceEnums.ComponentType.ElasticSearch
case "Crawler" => ComponentType.Crawler
case "WebApi" => ComponentType.WebApi
case "WebApp" => ComponentType.WebApp
case "DelphiManagement" => ComponentType.DelphiManagement
case "ElasticSearch" => ComponentType.ElasticSearch
case x => throw DeserializationException(s"Unexpected string value $x for component type.")
}
case y => throw DeserializationException(s"Unexpected type $y while deserializing component type.")
case y => throw DeserializationException(s"Unexpected type $y during deserialization component type.")
}
}

implicit val stateFormat : JsonFormat[InstanceEnums.State] = new JsonFormat[InstanceEnums.State] {
//Custom JSON format for an InstanceState
implicit val stateFormat : JsonFormat[InstanceState] = new JsonFormat[InstanceState] {

def write(compType : InstanceEnums.State) = JsString(compType.toString)
/**
* Custom write method for serializing an InstanceState
* @param state The InstanceState to serialize
* @return JsString containing the serialized value
*/
def write(state : InstanceState) = JsString(state.toString)

def read(value: JsValue) : InstanceEnums.State = value match {
/**
* Custom read method for deserialization of an InstanceState
* @param value JsValue to deserialize (must be a JsString)
* @return InstanceState that has been read
* @throws DeserializationException Exception thrown when JsValue is in incorrect format
*/
def read(value: JsValue) : InstanceState = value match {
case JsString(s) => s match {
case "Running" => InstanceEnums.InstanceState.Running
case "Stopped" => InstanceEnums.InstanceState.Stopped
case "Failed" => InstanceEnums.InstanceState.Failed
case "Paused" => InstanceEnums.InstanceState.Paused
case "NotReachable" => InstanceEnums.InstanceState.NotReachable
case "Running" => InstanceState.Running
case "Stopped" => InstanceState.Stopped
case "Failed" => InstanceState.Failed
case "Paused" => InstanceState.Paused
case "NotReachable" => InstanceState.NotReachable
case "Deploying" => InstanceState.Deploying
case x => throw DeserializationException(s"Unexpected string value $x for instance state.")
}
case y => throw DeserializationException(s"Unexpected type $y while deserializing instance state.")
case y => throw DeserializationException(s"Unexpected type $y during deserialization instance state.")
}
}

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

/**
* The instance type used for transmitting data about an instance from an to the registry
* @param id Id of the instance. This is an Option[Long], as an registering instance will not yet have an id.
* @param host Host of the instance.
* @param portNumber Port the instance is reachable at.
* @param name Name of the instance
* @param componentType ComponentType of the instance.
* @param dockerId The docker container id of the instance. This is an Option[String], as not all instance have to be docker containers.
* @param instanceState State of the instance
*/
final case class Instance (
id: Option[Long],
host: String,
portNumber: Long,
name: String,
componentType: InstanceEnums.ComponentType,
componentType: ComponentType,
dockerId: Option[String],
instanceState: InstanceEnums.State
instanceState: InstanceState,
labels: List[String],
linksTo: List[InstanceLink],
linksFrom: List[InstanceLink]
)

/**
* Enumerations concerning instances
*/
object InstanceEnums {

//Type to use when working with component types
type ComponentType = ComponentType.Value

/**
* ComponentType enumeration defining the valid types of delphi components
*/
object ComponentType extends Enumeration {
val Crawler : Value = Value("Crawler")
val ElasticSearch : Value = Value("ElasticSearch")
val WebApi : Value = Value("WebApi")
val WebApp : Value = Value("WebApp")
val DelphiManagement : Value = Value("DelphiManagement")
val ElasticSearch : Value = Value("ElasticSearch")
}
type State = InstanceState.Value

//Type to use when working with instance states
type InstanceState = InstanceState.Value

/**
* InstanceState enumeration defining the valid states for instances of delphi components
*/
object InstanceState extends Enumeration {
val Deploying : Value = Value("Deploying")
val Running : Value = Value("Running")
val Paused : Value = Value("Paused")
val Stopped : Value = Value("Stopped")
val Failed : Value = Value("Failed")
val Paused : Value = Value("Paused")
val NotReachable : Value = Value("NotReachable")
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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 de.upb.cs.swt.delphi.instancemanagement

import LinkEnums.LinkState
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import spray.json.{DefaultJsonProtocol, DeserializationException, JsString, JsValue, JsonFormat}

trait InstanceLinkJsonSupport extends SprayJsonSupport with DefaultJsonProtocol {

implicit val linkStateFormat: JsonFormat[LinkState] = new JsonFormat[LinkState] {
override def read(value: JsValue): LinkState = value match {
case JsString(s) => s match {
case "Assigned" => LinkState.Assigned
case "Outdated" => LinkState.Outdated
case "Failed" => LinkState.Failed
case x => throw DeserializationException(s"Unexpected string value $x for LinkState.")
}
case y => throw DeserializationException(s"Unexpected type $y during deserialization of LinkState")
}

override def write(linkState: LinkState): JsValue = JsString(linkState.toString)
}

implicit val instanceLinkFormat: JsonFormat[InstanceLink] =
jsonFormat3(InstanceLink)
}


final case class InstanceLink(idFrom: Long, idTo:Long, linkState: LinkState)

object LinkEnums {
type LinkState = LinkState.Value

object LinkState extends Enumeration {
val Assigned: Value = Value("Assigned")
val Failed: Value = Value("Failed")
val Outdated: Value = Value("Outdated")
}
}
Loading