@RequestMapping(value = "/{appName}/rules", method = RequestMethod.GET) public HttpEntity<Resources<AutoscalingRuleResource>> getRules(@PathVariable String appName) throws Exception { Map<String, AutoscalingRule> namedRules = autoscalingManager.getRules(appName).get(10, TimeUnit.MILLISECONDS); Collection<Link> links = new ArrayList<Link>(); for (Map.Entry<String, AutoscalingRule> namedRule : namedRules.entrySet()) { AutoscalingRuleResource rr = new AutoscalingRuleResource(); rr.setName(namedRule.getKey()); rr.setRule(namedRule.getValue()); rr.add( linkTo(AutoscaledAppController.class) .slash(appName) .slash("rules") .slash(namedRule.getKey()) .withSelfRel()); links.add( linkTo(AutoscaledAppController.class) .slash(appName) .slash("rules") .slash(namedRule.getKey()) .withRel("rule")); } List<AutoscalingRuleResource> rules = new ArrayList<AutoscalingRuleResource>(namedRules.size()); return new HttpEntity<Resources<AutoscalingRuleResource>>( new Resources<AutoscalingRuleResource>(rules, links)); }
@RequestMapping(value = "/{appName}/rules/{ruleName}", method = RequestMethod.GET) public HttpEntity<AutoscalingRuleResource> getRule( @PathVariable String appName, @PathVariable String ruleName) { // FIXME - implement me AutoscalingRuleResource rule = new AutoscalingRuleResource(); rule.setName(ruleName); return new HttpEntity<AutoscalingRuleResource>(rule); }
@RequestMapping(value = "/{appName}/rules", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public void createRule( @PathVariable String appName, @RequestBody AutoscalingRuleResource rule, UriComponentsBuilder builder, HttpServletResponse response) { autoscalingManager.addAutoscaleRule(appName, rule.getName(), rule.getRule()); String uriString = builder .path("/autoscaledapps/{appName}/rules/{ruleName}") .buildAndExpand(appName, rule.getName()) .toUriString(); response.setHeader("location", uriString); }