@@ -23,7 +23,7 @@ import scala.concurrent.duration.Duration
23
23
object Server extends HttpApp with JsonSupport with AppLogging {
24
24
25
25
// 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 ))
27
27
28
28
implicit val system : ActorSystem = ActorSystem (" delphi-registry" )
29
29
implicit val materializer : ActorMaterializer = ActorMaterializer ()
@@ -44,7 +44,7 @@ object Server extends HttpApp with JsonSupport with AppLogging {
44
44
{
45
45
log.debug(s " POST /register has been called, parameter is: $InstanceString" )
46
46
Await .result(Unmarshal (InstanceString ).to[Instance ] map {paramInstance =>
47
- val name = paramInstance.name.getOrElse( " None " )
47
+ val name = paramInstance.name
48
48
val newID : Long = {
49
49
if (instances.isEmpty){
50
50
0L
@@ -54,7 +54,7 @@ object Server extends HttpApp with JsonSupport with AppLogging {
54
54
}
55
55
}
56
56
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)
58
58
59
59
instances += instanceToRegister
60
60
log.info(s " Instance with name $name registered, ID $newID assigned. " )
@@ -87,7 +87,7 @@ object Server extends HttpApp with JsonSupport with AppLogging {
87
87
def fetchInstancesOfType () : server.Route = parameters(' ComponentType .as[String ]) { compTypeString =>
88
88
get {
89
89
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
91
91
val matchingInstancesList = List () ++ instances filter {instance => instance.componentType == compType}
92
92
93
93
complete {matchingInstancesList}
@@ -97,7 +97,7 @@ object Server extends HttpApp with JsonSupport with AppLogging {
97
97
def numberOfInstances () : server.Route = parameters(' ComponentType .as[String ]) { compTypeString =>
98
98
get {
99
99
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
101
101
val count : Int = instances count {instance => instance.componentType == compType}
102
102
complete{count.toString()}
103
103
}
@@ -106,8 +106,8 @@ object Server extends HttpApp with JsonSupport with AppLogging {
106
106
def getMatchingInstance () : server.Route = parameters(' ComponentType .as[String ]){ compTypeString =>
107
107
get{
108
108
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 ... " )
111
111
val matchingInstances = instances filter {instance => instance.componentType == compType}
112
112
if (matchingInstances.isEmpty){
113
113
log.warning(s " Could not find matching instance for type $compType . " )
0 commit comments