Skip to content

Commit 2d76575

Browse files
ShihabMehboobsjanuary
authored andcommitted
Remove SwiftyJSON (#191)
1 parent f37c882 commit 2d76575

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Authors ordered by first contribution:
1111
- Sian January (https://github.com/sjanuary)
1212
- Kye Maloy (https://github.com/kyemaloy97)
1313
- Jonathan Spruce (https://github.com/jonathan-spruce)
14+
- Shihab Mehboob (https://github.com/ShihabMehboob)

Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ let package = Package(
3838
.package(url: "https://github.com/IBM-Swift/Kitura-WebSocket.git", from: "2.0.0"),
3939
.package(url: "https://github.com/IBM-Swift/SwiftyRequest.git", from: "1.0.0"),
4040
.package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", from: "6.0.0"),
41-
.package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", from: "17.0.0"),
4241
.package(url: "https://github.com/RuntimeTools/omr-agentcore", .exact("3.2.4-swift4")),
4342
],
4443
targets: [
4544
.target(name: "SwiftMetrics", dependencies: ["agentcore", "hcapiplugin", "envplugin", "cpuplugin", "memplugin", "CloudFoundryEnv"]),
4645
.target(name: "SwiftMetricsKitura", dependencies: ["SwiftMetrics", "Kitura"]),
4746
.target(name: "SwiftBAMDC", dependencies: ["SwiftMetricsKitura", "SwiftyRequest", "Kitura-WebSocket"]),
48-
.target(name: "SwiftMetricsBluemix", dependencies: ["SwiftMetricsKitura","SwiftBAMDC","SwiftyJSON"]),
47+
.target(name: "SwiftMetricsBluemix", dependencies: ["SwiftMetricsKitura","SwiftBAMDC"]),
4948
.target(name: "SwiftMetricsDash", dependencies: ["SwiftMetricsBluemix"]),
5049
.target(name: "SwiftMetricsREST", dependencies: ["SwiftMetricsKitura"]),
5150
.target(name: "SwiftMetricsPrometheus", dependencies:["SwiftMetricsKitura"]),

Sources/SwiftMetricsBluemix/SwiftMetricsBluemix.swift

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import CloudFoundryEnv
2222
import SwiftyRequest
2323
import SwiftMetrics
2424
import SwiftMetricsKitura
25-
import SwiftyJSON
2625
import SwiftBAMDC
2726

2827
fileprivate struct HttpStats {
@@ -443,21 +442,32 @@ public class SwiftMetricsBluemix {
443442

444443
// Update local config from autoscaling service
445444
private func updateConfiguration(response: Data) {
446-
let jsonData = JSON(data: response)
447-
Log.debug("[Auto-scaling Agent] attempting to update configuration with \(jsonData)")
448-
if (jsonData == nil) {
449-
isAgentEnabled = false
450-
return
451-
}
452-
if (jsonData["metricsConfig"]["agent"] == nil) {
453-
isAgentEnabled = false
454-
return
455-
} else {
456-
isAgentEnabled = true
457-
enabledMetrics=jsonData["metricsConfig"]["agent"].arrayValue.map({$0.stringValue})
445+
do {
446+
let json = try JSONDecoder().decode(ConfigResponse.self, from: response)
447+
Log.debug("[Auto-scaling Agent] attempting to update configuration with \(json)")
448+
if json.metricsConfig.agent.isEmpty {
449+
isAgentEnabled = false
450+
return
451+
} else {
452+
isAgentEnabled = true
453+
self.enabledMetrics = json.metricsConfig.agent
454+
}
455+
self.reportInterval = json.reportInterval
456+
Log.exit("[Auto-scaling Agent] Updated configuration - enabled metrics: \(enabledMetrics), report interval: \(reportInterval) seconds")
457+
} catch {
458+
isAgentEnabled = false
459+
return
458460
}
459-
reportInterval=jsonData["reportInterval"].intValue
460-
Log.exit("[Auto-scaling Agent] Updated configuration - enabled metrics: \(enabledMetrics), report interval: \(reportInterval) seconds")
461461
}
462+
463+
}
462464

465+
// Response struct for the configuration
466+
public struct ConfigResponse: Codable {
467+
var metricsConfig: metrics
468+
var reportInterval: Int
469+
470+
struct metrics: Codable {
471+
var agent: [String]
472+
}
463473
}

Sources/SwiftMetricsDash/SwiftMetricsDash.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import Kitura
1818
import SwiftMetricsKitura
1919
import SwiftMetricsBluemix
2020
import SwiftMetrics
21-
import SwiftyJSON
2221
import KituraNet
2322
import KituraWebSocket
2423
import Foundation

0 commit comments

Comments
 (0)