-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from anotherchrisberry/cloud-metrics
add cloudMetrics endpoints
- Loading branch information
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/CloudMetricController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/CloudMetricService.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |