Skip to content

Commit 2dfe279

Browse files
authored
Merge pull request #12 from delphi-hub/feature/adapt-swagger-model
The Instance object for the API no longer uses all Option-Types
2 parents 8b9c9c9 + b487458 commit 2dfe279

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/Server.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import scala.concurrent.duration.Duration
2323
object Server extends HttpApp with JsonSupport with AppLogging {
2424

2525
//Default ES instance for testing
26-
private val instances = mutable.HashSet (Instance(Some(0), Some("elasticsearch://localhost"), Some(9200), Some("Default ElasticSearch Instance"), Some(ComponentType.ElasticSearch)))
26+
private val instances = mutable.HashSet (Instance(Some(0), "elasticsearch://localhost", 9200, "Default ElasticSearch Instance", ComponentType.ElasticSearch))
2727

2828
implicit val system : ActorSystem = ActorSystem("delphi-registry")
2929
implicit val materializer : ActorMaterializer = ActorMaterializer()
@@ -44,7 +44,7 @@ object Server extends HttpApp with JsonSupport with AppLogging {
4444
{
4545
log.debug(s"POST /register has been called, parameter is: $InstanceString")
4646
Await.result(Unmarshal(InstanceString).to[Instance] map {paramInstance =>
47-
val name = paramInstance.name.getOrElse("None")
47+
val name = paramInstance.name
4848
val newID : Long = {
4949
if(instances.isEmpty){
5050
0L
@@ -54,7 +54,7 @@ object Server extends HttpApp with JsonSupport with AppLogging {
5454
}
5555
}
5656

57-
val instanceToRegister = Instance(iD = Some(newID), iP = paramInstance.iP, portnumber = paramInstance.portnumber, name = paramInstance.name, componentType = paramInstance.componentType)
57+
val instanceToRegister = Instance(iD = Some(newID), host = paramInstance.host, portnumber = paramInstance.portnumber, name = paramInstance.name, componentType = paramInstance.componentType)
5858

5959
instances += instanceToRegister
6060
log.info(s"Instance with name $name registered, ID $newID assigned.")
@@ -87,7 +87,7 @@ object Server extends HttpApp with JsonSupport with AppLogging {
8787
def fetchInstancesOfType () : server.Route = parameters('ComponentType.as[String]) { compTypeString =>
8888
get {
8989
log.debug(s"GET /instances?ComponentType=$compTypeString has been called")
90-
val compType : Option[ComponentType] = ComponentType.values.find(v => v.toString == compTypeString).map(v => Some(v)).getOrElse(None)
90+
val compType : ComponentType = ComponentType.values.find(v => v.toString == compTypeString).orNull
9191
val matchingInstancesList = List() ++ instances filter {instance => instance.componentType == compType}
9292

9393
complete {matchingInstancesList}
@@ -97,7 +97,7 @@ object Server extends HttpApp with JsonSupport with AppLogging {
9797
def numberOfInstances() : server.Route = parameters('ComponentType.as[String]) { compTypeString =>
9898
get {
9999
log.debug(s"GET /numberOfInstances?ComponentType=$compTypeString has been called")
100-
val compType : Option[ComponentType] = ComponentType.values.find(v => v.toString == compTypeString).map(v => Some(v)).getOrElse(None)
100+
val compType : ComponentType = ComponentType.values.find(v => v.toString == compTypeString).orNull
101101
val count : Int = instances count {instance => instance.componentType == compType}
102102
complete{count.toString()}
103103
}
@@ -106,8 +106,8 @@ object Server extends HttpApp with JsonSupport with AppLogging {
106106
def getMatchingInstance() : server.Route = parameters('ComponentType.as[String]){ compTypeString =>
107107
get{
108108
log.debug(s"GET /matchingInstance?ComponentType=$compTypeString has been called")
109-
val compType : Option[ComponentType] = ComponentType.values.find(v => v.toString == compTypeString).map(v => Some(v)).getOrElse(None)
110-
log.info(s"Looking for instance of type ${compType.getOrElse("None")} ...")
109+
val compType : ComponentType = ComponentType.values.find(v => v.toString == compTypeString).orNull
110+
log.info(s"Looking for instance of type $compType ...")
111111
val matchingInstances = instances filter {instance => instance.componentType == compType}
112112
if(matchingInstances.isEmpty){
113113
log.warning(s"Could not find matching instance for type $compType .")

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/io/swagger/client/model/Instance.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
2626

2727
final case class Instance (
2828
iD: Option[Long],
29-
iP: Option[String],
30-
portnumber: Option[Long],
31-
name: Option[String],
29+
host: String,
30+
portnumber: Long,
31+
name: String,
3232
/* Component Type */
33-
componentType: Option[InstanceEnums.ComponentType]
33+
componentType: InstanceEnums.ComponentType
3434
)
3535

3636
object InstanceEnums {

0 commit comments

Comments
 (0)