Skip to content

Commit

Permalink
Merge pull request #186 from anotherchrisberry/cloud-metrics
Browse files Browse the repository at this point in the history
add cloudMetrics endpoints
  • Loading branch information
anotherchrisberry committed Mar 23, 2016
2 parents 73808b0 + 311f77b commit 59ac427
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import retrofit.http.GET
import retrofit.http.Headers
import retrofit.http.Path
import retrofit.http.Query
import retrofit.http.QueryMap

interface ClouddriverService {

Expand Down Expand Up @@ -211,4 +212,19 @@ interface ClouddriverService {

@GET('/networks/{cloudProvider}')
List<Map> getNetworks(@Path("cloudProvider") String cloudProvider)

@GET('/cloudMetrics/{cloudProvider}/{account}/{region}')
List<Map> findAllCloudMetrics(@Path("cloudProvider") String cloudProvider,
@Path("account") String account,
@Path("region") String region,
@QueryMap Map<String, String> filters)

@GET('/cloudMetrics/{cloudProvider}/{account}/{region}/{metricName}/statistics')
Map getCloudMetricStatistics(@Path("cloudProvider") String cloudProvider,
@Path("account") String account,
@Path("region") String region,
@Path("metricName") String metricName,
@Query("startTime") Long startTime,
@Query("endTime") Long endTime,
@QueryMap Map<String, String> filters)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2016 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.gate.controllers

import com.netflix.spinnaker.gate.services.CloudMetricService
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@CompileStatic
@RequestMapping("/cloudMetrics")
@RestController
class CloudMetricController {

@Autowired
CloudMetricService cloudMetricService

@RequestMapping(value = "/{cloudProvider}/{account}/{region}", method = RequestMethod.GET)
List<Map> findAll(@PathVariable String cloudProvider,
@PathVariable String account,
@PathVariable String region,
@RequestParam Map<String, String> filters) {

cloudMetricService.findAll(cloudProvider, account, region, filters)
}

@RequestMapping(value = "/{cloudProvider}/{account}/{region}/{metricName}/statistics", method = RequestMethod.GET)
Map getStatistics(@PathVariable String cloudProvider,
@PathVariable String account,
@PathVariable String region,
@PathVariable String metricName,
@RequestParam(required = false) Long startTime,
@RequestParam(required = false) Long endTime,
@RequestParam Map<String, String> filters) {

cloudMetricService.getStatistics(cloudProvider, account, region, metricName, startTime, endTime, filters)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2016 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.gate.services

import com.netflix.spinnaker.gate.services.commands.HystrixFactory
import com.netflix.spinnaker.gate.services.internal.ClouddriverService
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@CompileStatic
@Component
class CloudMetricService {

private static final String GROUP = "cloudMetrics"

@Autowired
ClouddriverService clouddriverService

List<Map> findAll(String cloudProvider, String account, String region, Map<String, String> filters) {
HystrixFactory.newListCommand(GROUP, "$GROUP:$account:$region:findAll") {
clouddriverService.findAllCloudMetrics(cloudProvider, account, region, filters)
} execute()
}

Map getStatistics(String cloudProvider, String account, String region, String metricName,
Long startTime, Long endTime, Map<String, String> filters) {
HystrixFactory.newMapCommand(GROUP, "$GROUP:$account:$region:getStatistics") {
clouddriverService.getCloudMetricStatistics(cloudProvider, account, region, metricName, startTime, endTime, filters)
} execute()
}
}

0 comments on commit 59ac427

Please sign in to comment.