Skip to content

Commit

Permalink
Remove SwiftyJSON (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShihabMehboob authored and sjanuary committed Sep 18, 2018
1 parent f37c882 commit 2d76575
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Authors ordered by first contribution:
- Sian January (https://github.com/sjanuary)
- Kye Maloy (https://github.com/kyemaloy97)
- Jonathan Spruce (https://github.com/jonathan-spruce)
- Shihab Mehboob (https://github.com/ShihabMehboob)
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ let package = Package(
.package(url: "https://github.com/IBM-Swift/Kitura-WebSocket.git", from: "2.0.0"),
.package(url: "https://github.com/IBM-Swift/SwiftyRequest.git", from: "1.0.0"),
.package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", from: "6.0.0"),
.package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", from: "17.0.0"),
.package(url: "https://github.com/RuntimeTools/omr-agentcore", .exact("3.2.4-swift4")),
],
targets: [
.target(name: "SwiftMetrics", dependencies: ["agentcore", "hcapiplugin", "envplugin", "cpuplugin", "memplugin", "CloudFoundryEnv"]),
.target(name: "SwiftMetricsKitura", dependencies: ["SwiftMetrics", "Kitura"]),
.target(name: "SwiftBAMDC", dependencies: ["SwiftMetricsKitura", "SwiftyRequest", "Kitura-WebSocket"]),
.target(name: "SwiftMetricsBluemix", dependencies: ["SwiftMetricsKitura","SwiftBAMDC","SwiftyJSON"]),
.target(name: "SwiftMetricsBluemix", dependencies: ["SwiftMetricsKitura","SwiftBAMDC"]),
.target(name: "SwiftMetricsDash", dependencies: ["SwiftMetricsBluemix"]),
.target(name: "SwiftMetricsREST", dependencies: ["SwiftMetricsKitura"]),
.target(name: "SwiftMetricsPrometheus", dependencies:["SwiftMetricsKitura"]),
Expand Down
40 changes: 25 additions & 15 deletions Sources/SwiftMetricsBluemix/SwiftMetricsBluemix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import CloudFoundryEnv
import SwiftyRequest
import SwiftMetrics
import SwiftMetricsKitura
import SwiftyJSON
import SwiftBAMDC

fileprivate struct HttpStats {
Expand Down Expand Up @@ -443,21 +442,32 @@ public class SwiftMetricsBluemix {

// Update local config from autoscaling service
private func updateConfiguration(response: Data) {
let jsonData = JSON(data: response)
Log.debug("[Auto-scaling Agent] attempting to update configuration with \(jsonData)")
if (jsonData == nil) {
isAgentEnabled = false
return
}
if (jsonData["metricsConfig"]["agent"] == nil) {
isAgentEnabled = false
return
} else {
isAgentEnabled = true
enabledMetrics=jsonData["metricsConfig"]["agent"].arrayValue.map({$0.stringValue})
do {
let json = try JSONDecoder().decode(ConfigResponse.self, from: response)
Log.debug("[Auto-scaling Agent] attempting to update configuration with \(json)")
if json.metricsConfig.agent.isEmpty {
isAgentEnabled = false
return
} else {
isAgentEnabled = true
self.enabledMetrics = json.metricsConfig.agent
}
self.reportInterval = json.reportInterval
Log.exit("[Auto-scaling Agent] Updated configuration - enabled metrics: \(enabledMetrics), report interval: \(reportInterval) seconds")
} catch {
isAgentEnabled = false
return
}
reportInterval=jsonData["reportInterval"].intValue
Log.exit("[Auto-scaling Agent] Updated configuration - enabled metrics: \(enabledMetrics), report interval: \(reportInterval) seconds")
}

}

// Response struct for the configuration
public struct ConfigResponse: Codable {
var metricsConfig: metrics
var reportInterval: Int

struct metrics: Codable {
var agent: [String]
}
}
1 change: 0 additions & 1 deletion Sources/SwiftMetricsDash/SwiftMetricsDash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Kitura
import SwiftMetricsKitura
import SwiftMetricsBluemix
import SwiftMetrics
import SwiftyJSON
import KituraNet
import KituraWebSocket
import Foundation
Expand Down

0 comments on commit 2d76575

Please sign in to comment.