@@ -120,7 +120,7 @@ object InstanceRegistry extends InstanceJsonSupport with AppLogging {
120
120
def register (configuration : Configuration ): Try [Long ] = {
121
121
val instance = createInstance(None , configuration.bindPort, configuration.instanceName)
122
122
123
- Await .result(postInstance(instance, configuration.instanceRegistryUri + " /register" ) map { response =>
123
+ Await .result(postInstance(instance, configuration.instanceRegistryUri + " /instances/ register" ) map { response =>
124
124
if (response.status == StatusCodes .OK ) {
125
125
Await .result(Unmarshal (response.entity).to[String ] map { assignedID =>
126
126
val id = assignedID.toLong
@@ -149,7 +149,7 @@ object InstanceRegistry extends InstanceJsonSupport with AppLogging {
149
149
} else {
150
150
val request = HttpRequest (method = HttpMethods .GET ,
151
151
configuration.instanceRegistryUri +
152
- s " /matchingInstance?Id= ${configuration.assignedID.getOrElse(- 1 )}& ComponentType=ElasticSearch" )
152
+ s " /instances/ ${configuration.assignedID.getOrElse(- 1 )}/matchingInstance? ComponentType=ElasticSearch" )
153
153
154
154
Await .result(Http (system).singleRequest(request.withHeaders(RawHeader (" Authorization" ,s " Bearer ${AuthProvider .generateJwt()}" ))) map { response =>
155
155
response.status match {
@@ -189,12 +189,17 @@ object InstanceRegistry extends InstanceJsonSupport with AppLogging {
189
189
Failure (new RuntimeException (" Cannot post matching result to Instance Registry, assigned ElasticSearch instance has no ID." ))
190
190
} else {
191
191
val idToPost = configuration.elasticsearchInstance.id.getOrElse(- 1L )
192
+
193
+ val matchingData = JsObject (" MatchingSuccessful" -> JsBoolean (isElasticSearchReachable),
194
+ " SenderId" -> JsNumber (configuration.assignedID.getOrElse(- 1L )))
195
+
192
196
val request = HttpRequest (
193
197
method = HttpMethods .POST ,
194
- configuration.instanceRegistryUri +
195
- s " /matchingResult?CallerId= ${configuration.assignedID.getOrElse(- 1 )}&MatchedInstanceId= $idToPost&MatchingSuccessful= $isElasticSearchReachable" )
198
+ configuration.instanceRegistryUri + s " /instances/ $idToPost/matchingResult " )
196
199
197
- Await .result(Http (system).singleRequest(request.withHeaders(RawHeader (" Authorization" ,s " Bearer ${AuthProvider .generateJwt()}" ))) map { response =>
200
+ Await .result(Http (system).singleRequest(request
201
+ .withHeaders(RawHeader (" Authorization" ,s " Bearer ${AuthProvider .generateJwt()}" ))
202
+ .withEntity(ContentTypes .`application/json`, ByteString (matchingData.toJson.toString))) map { response =>
198
203
if (response.status == StatusCodes .OK ) {
199
204
log.info(s " Successfully posted matching result to Instance Registry. " )
200
205
Success ()
@@ -219,7 +224,8 @@ object InstanceRegistry extends InstanceJsonSupport with AppLogging {
219
224
} else {
220
225
val id : Long = configuration.assignedID.getOrElse(- 1L )
221
226
222
- val request = HttpRequest (method = HttpMethods .POST , configuration.instanceRegistryUri + s " /deregister?Id= $id" )
227
+ val request = HttpRequest (method = HttpMethods .POST , configuration.instanceRegistryUri +
228
+ s " /instances/ $id/deregister " )
223
229
224
230
Await .result(Http (system).singleRequest(request.withHeaders(RawHeader (" Authorization" ,s " Bearer ${AuthProvider .generateJwt()}" ))) map { response =>
225
231
if (response.status == StatusCodes .OK ) {
@@ -241,9 +247,11 @@ object InstanceRegistry extends InstanceJsonSupport with AppLogging {
241
247
242
248
def postInstance (instance : Instance , uri : String )(): Future [HttpResponse ] = {
243
249
try {
244
- val request = HttpRequest (method = HttpMethods .POST , uri = uri, entity = instance.toJson(instanceFormat).toString() )
250
+ val request = HttpRequest (method = HttpMethods .POST , uri = uri)
245
251
// Use generic name for startup, no id present at this point
246
- Http (system).singleRequest(request.withHeaders(RawHeader (" Authorization" ,s " Bearer ${AuthProvider .generateJwt(useGenericName = true )}" )))
252
+ Http (system).singleRequest(request
253
+ .withHeaders(RawHeader (" Authorization" ,s " Bearer ${AuthProvider .generateJwt(useGenericName = true )}" ))
254
+ .withEntity(ContentTypes .`application/json`, ByteString (instance.toJson(instanceFormat).toString)))
247
255
} catch {
248
256
case dx : DeserializationException =>
249
257
log.warning(s " Failed to deregister to Instance Registry, exception: $dx" )
@@ -256,58 +264,6 @@ object InstanceRegistry extends InstanceJsonSupport with AppLogging {
256
264
Instance (id, InetAddress .getLocalHost.getHostAddress,
257
265
controlPort, name, ComponentType .WebApi , None , InstanceState .Running , List .empty[String ], List .empty[InstanceLink ], List .empty[InstanceLink ])
258
266
259
- def reportStart (id : String , configuration : Configuration ): Try [ResponseEntity ] = {
260
- val request = HttpRequest (method = HttpMethods .GET , configuration.instanceRegistryUri + " /reportStart" )
261
- Await .result(Http (system).singleRequest(request) map { response =>
262
- if (response.status == StatusCodes .OK ) {
263
- Success (response.entity)
264
- }
265
- else {
266
- val statuscode = response.status
267
- log.warning(s " Failed to perform reportStart, server returned $statuscode" )
268
- Failure (new RuntimeException (s " Failed to perform reportStart, server returned $statuscode" ))
269
- }
270
- } recover { case ex =>
271
- log.warning(s " Failed to perform reportStart, exception: $ex" )
272
- Failure (new RuntimeException (s " Failed to perform reportStart, server returned, exception: $ex" ))
273
- }, Duration .Inf )
274
- }
275
-
276
- def reportFailure (id : String , configuration : Configuration ): Try [ResponseEntity ] = {
277
-
278
- val request = HttpRequest (method = HttpMethods .GET , configuration.instanceRegistryUri + " /reportFailure" )
279
- Await .result(Http (system).singleRequest(request) map { response =>
280
- if (response.status == StatusCodes .OK ) {
281
- Success (response.entity)
282
- }
283
- else {
284
- val statuscode = response.status
285
- log.warning(s " Failed to perform reportFailure, server returned $statuscode" )
286
- Failure (new RuntimeException (s " Failed to perform reportFailure, server returned $statuscode" ))
287
- }
288
- } recover { case ex =>
289
- log.warning(s " Failed to perform reportFailure, server returned, exception: $ex" )
290
- Failure (new RuntimeException (s " Failed to perform reportFailure, server returned, exception: $ex" ))
291
- }, Duration .Inf )
292
- }
293
-
294
- def reportStop (id : String , configuration : Configuration ): Try [ResponseEntity ] = {
295
-
296
- val request = HttpRequest (method = HttpMethods .GET , configuration.instanceRegistryUri + " /reportStop" )
297
- Await .result(Http (system).singleRequest(request) map { response =>
298
- if (response.status == StatusCodes .OK ) {
299
- Success (response.entity)
300
- }
301
- else {
302
- val statuscode = response.status
303
- log.warning(s " Failed to perform reportStop, server returned $statuscode" )
304
- Failure (new RuntimeException (s " Failed to perform reportStop, server returned $statuscode" ))
305
- }
306
- } recover { case ex =>
307
- log.warning(s " Failed to perform reportStop, server returned, exception: $ex" )
308
- Failure (new RuntimeException (s " Failed to perform reportStop, server returned, exception: $ex" ))
309
- }, Duration .Inf )
310
- }
311
267
312
268
object ReportOperationType extends Enumeration {
313
269
val Start : Value = Value (" Start" )
@@ -317,11 +273,11 @@ object InstanceRegistry extends InstanceJsonSupport with AppLogging {
317
273
def toOperationUriString (operation : ReportOperationType .Value , id : Long ): String = {
318
274
operation match {
319
275
case Start =>
320
- s " /reportStart?Id= $id"
276
+ s " /instances/ $id/reportStart "
321
277
case Stop =>
322
- s " /reportStop?Id= $id"
278
+ s " /instances/ $id/reportStop "
323
279
case _ =>
324
- s " /reportFailure?Id= $id"
280
+ s " /instances/ $id/reportFailure "
325
281
}
326
282
}
327
283
}
0 commit comments