@@ -19,7 +19,6 @@ import Dispatch
19
19
import LoggerAPI
20
20
import Configuration
21
21
import CloudFoundryEnv
22
- import SwiftyRequest
23
22
import SwiftMetrics
24
23
import SwiftMetricsKitura
25
24
import SwiftBAMDC
@@ -386,34 +385,47 @@ public class SwiftMetricsBluemix {
386
385
Log . debug ( " [Auto-scaling Agent] Attempting to send metrics to \( sendMetricsPath) " )
387
386
388
387
389
- let request = RestRequest ( method: . post, url: sendMetricsPath)
390
- request. headerParameters = [ " Content-Type " : " application/json " , " Authorization " : " Basic \( authorization) " ]
388
+ guard let url = URL ( string: sendMetricsPath) else {
389
+ Log . error ( " [Auto-scaling Agent] Invalid URL " )
390
+ return
391
+ }
392
+ var request = URLRequest ( url: url)
393
+ request. httpMethod = " POST "
394
+ request. setValue ( " application/json " , forHTTPHeaderField: " Content-Type " )
395
+ request. setValue ( " Basic \( authorization) " , forHTTPHeaderField: " Authorization " )
391
396
do {
392
- request. messageBody = try JSONSerialization . data ( withJSONObject: asOBJ, options: . prettyPrinted)
397
+ request. httpBody = try JSONSerialization . data ( withJSONObject: asOBJ, options: . prettyPrinted)
393
398
} catch {
394
399
print ( " Error converting input to JSON object to post. " )
395
400
}
396
- request . response { ( data, response, error) in
401
+ let task = URLSession . shared . dataTask ( with : request ) { data, response, error in
397
402
Log . debug ( " [Auto-scaling Agent] sendMetrics:Request: \( String ( describing: request) ) " )
398
403
Log . debug ( " [Auto-scaling Agent] sendMetrics:Response: \( String ( describing: response) ) " )
399
404
Log . debug ( " [Auto-scaling Agent] sendMetrics:Data: \( String ( describing: data) ) " )
400
405
Log . debug ( " [Auto-scaling Agent] sendMetrics:Error: \( String ( describing: error) ) " )
401
406
}
407
+ task. resume ( )
402
408
403
409
}
404
410
405
411
private func notifyStatus( ) {
406
412
let notifyStatusPath = " \( host) :443/services/agent/status/ \( appID) "
407
413
Log . debug ( " [Auto-scaling Agent] Attempting notifyStatus request to \( notifyStatusPath) " )
408
414
409
- let request = RestRequest ( method: . put, url: notifyStatusPath)
410
- request. headerParameters = [ " Authorization " : " Basic \( authorization) " ]
411
- request. response { ( data, response, error) in
415
+ guard let url = URL ( string: notifyStatusPath) else {
416
+ Log . error ( " [Auto-scaling Agent] Invalid URL " )
417
+ return
418
+ }
419
+ var request = URLRequest ( url: url)
420
+ request. httpMethod = " PUT "
421
+ request. setValue ( " Basic \( authorization) " , forHTTPHeaderField: " Authorization " )
422
+ let task = URLSession . shared. dataTask ( with: request) { data, response, error in
412
423
Log . debug ( " [Auto-scaling Agent] notifyStatus:Request: \( String ( describing: request) ) " )
413
424
Log . debug ( " [Auto-scaling Agent] notifyStatus:Response: \( String ( describing: response) ) " )
414
425
Log . debug ( " [Auto-scaling Agent] notifyStatus:Data: \( String ( describing: data) ) " )
415
426
Log . debug ( " [Auto-scaling Agent] notifyStatus:Error: \( String ( describing: error) ) " )
416
427
}
428
+ task. resume ( )
417
429
418
430
}
419
431
@@ -423,9 +435,15 @@ public class SwiftMetricsBluemix {
423
435
let refreshConfigPath = " \( host) :443/v1/agent/config/ \( serviceID) / \( appID) ?appType=swift "
424
436
Log . debug ( " [Auto-scaling Agent] Attempting requestConfig request to \( refreshConfigPath) " )
425
437
426
- let request = RestRequest ( method: . get, url: refreshConfigPath)
427
- request. headerParameters = [ " Content-Type " : " application/json " , " Authorization " : " Basic \( authorization) " ]
428
- request. response { ( data, response, error) in
438
+ guard let url = URL ( string: refreshConfigPath) else {
439
+ Log . error ( " [Auto-scaling Agent] Invalid URL " )
440
+ return
441
+ }
442
+ var request = URLRequest ( url: url)
443
+ request. httpMethod = " GET "
444
+ request. setValue ( " application/json " , forHTTPHeaderField: " Content-Type " )
445
+ request. setValue ( " Basic \( authorization) " , forHTTPHeaderField: " Authorization " )
446
+ let task = URLSession . shared. dataTask ( with: request) { data, response, error in
429
447
Log . debug ( " [Auto-scaling Agent] requestConfig:Request: \( String ( describing: request) ) " )
430
448
Log . debug ( " [Auto-scaling Agent] requestConfig:Response: \( String ( describing: response) ) " )
431
449
Log . debug ( " [Auto-scaling Agent] requestConfig:Data: \( String ( describing: data) ) " )
@@ -437,6 +455,7 @@ public class SwiftMetricsBluemix {
437
455
print ( " Error updating configuration. Data doesn't exist. " )
438
456
}
439
457
}
458
+ task. resume ( )
440
459
441
460
}
442
461
0 commit comments