@RequestMapping(value = "/admin/accounts/{accountId}/pools", method = RequestMethod.POST)
 @ResponseBody
 public PoolConfigurationModel createAccountPool(
     @PathVariable("accountId") Long accountId, @RequestBody String poolSettingJson) {
   Long poolId = poolDao.createPool(accountId, poolSettingJson);
   nodeManagementExecutor.start(poolDao.readPoolById(poolId).poolSettings);
   return poolDao.readPoolById(poolId);
 }
 @RequestMapping(
     value = "/admin/accounts/{accountId}/pools/{poolId}/delete",
     method = RequestMethod.POST)
 @ResponseBody
 public boolean deleteAccountPool(
     @PathVariable("accountId") Long accountId, @PathVariable("poolId") Long poolConfigurationId) {
   nodeManagementExecutor.stop(poolDao.readPoolById(poolConfigurationId).poolSettings);
   return poolDao.deletePool(poolConfigurationId, accountId);
 }
 @RequestMapping(value = "/admin/accounts/{accountId}/pools/{poolId}", method = RequestMethod.POST)
 @ResponseBody
 public boolean updateAccountPool(
     @PathVariable("accountId") Long accountId,
     @PathVariable("poolId") Long poolConfigurationId,
     @RequestBody String newPoolSettingJson) {
   boolean updated = poolDao.updatePool(poolConfigurationId, accountId, newPoolSettingJson);
   nodeManagementExecutor.update(poolDao.readPoolById(poolConfigurationId).poolSettings);
   return updated;
 }
 /** @return poolConfigurationId => poolStatus map with a single entry. */
 @RequestMapping(value = "/admin/pools/{poolId}/status", method = RequestMethod.GET)
 @ResponseBody
 public Map<Long, PoolStatus> getPoolStatus(@PathVariable("poolId") Long poolConfigurationId) {
   PoolConfigurationModel poolConfiguration = poolDao.readPoolById(poolConfigurationId);
   HashMap<Long, PoolStatus> resultMap = new HashMap<Long, PoolStatus>();
   resultMap.put(poolConfigurationId, _getPoolStatus(poolConfiguration));
   return resultMap;
 }
 @RequestMapping(
     value = "/admin/pools/{poolId}/nodes/{nodeId}/delete",
     method = RequestMethod.POST)
 @ResponseBody
 public void nodeDelete(
     @PathVariable("poolId") Long poolConfigurationId, @PathVariable("nodeId") Long nodeId) {
   PoolSettings poolSettings = poolDao.readPoolById(poolConfigurationId).getPoolSettings();
   poolManagerApi.deleteNode(poolSettings, nodeId, null);
 }
 @RequestMapping(
     value = "/admin/pools/{poolId}/decisions/{decisionId}/abort",
     method = RequestMethod.POST)
 @ResponseBody
 public void abortPoolDecision(
     @PathVariable("poolId") Long poolConfigurationId,
     @PathVariable("decisionId") Long decisionId) {
   PoolSettings poolSettings = poolDao.readPoolById(poolConfigurationId).getPoolSettings();
   poolManagerApi.abortDecision(poolSettings, decisionId);
 }
 @RequestMapping(
     value = "/admin/accounts/{accountId}/pools/{poolId}/status",
     method = RequestMethod.GET)
 @ResponseBody
 public PoolStatus getAccountPoolStatus(
     @PathVariable("accountId") Long accountId, @PathVariable("poolId") Long poolConfigurationId) {
   PoolConfigurationModel poolConfiguration =
       poolDao.readPoolByIdAndAccountId(poolConfigurationId, accountId);
   return _getPoolStatus(poolConfiguration);
 }
 @RequestMapping(
     value = "/admin/accounts/{accountId}/pools/{poolId}/clean",
     method = RequestMethod.POST)
 @ResponseBody
 public void cleanAccountPool(
     @PathVariable("accountId") Long accountId, @PathVariable("poolId") Long poolConfigurationId) {
   PoolSettings poolSettings =
       poolDao.readPoolByIdAndAccountId(poolConfigurationId, accountId).getPoolSettings();
   poolManagerApi.cleanPool(poolSettings);
 }
 @RequestMapping(
     value = "/admin/accounts/{accountId}/pools/{poolId}/nodes/{nodeId}/bootstrap",
     method = RequestMethod.POST)
 @ResponseBody
 public void nodeBootstrap(
     @PathVariable("accountId") Long accountId,
     @PathVariable("poolId") Long poolConfigurationId,
     @PathVariable("nodeId") Long nodeId) {
   PoolSettings poolSettings =
       poolDao.readPoolByIdAndAccountId(poolConfigurationId, accountId).getPoolSettings();
   poolManagerApi.bootstrapNode(poolSettings, nodeId, null);
 }
 @RequestMapping(
     value = "/admin/pools/{poolId}/decisions/{decisionId}/approved/{approved}",
     method = RequestMethod.POST)
 @ResponseBody
 public void updatePoolDecisionApproval(
     @PathVariable("poolId") Long poolConfigurationId,
     @PathVariable("decisionId") Long decisionId,
     @PathVariable("approved") Boolean approved) {
   logger.debug(
       "> update pool decision approval > poolConfigurationId [{}], decisionId [{}], approved [{}]",
       poolConfigurationId,
       decisionId,
       approved);
   PoolSettings poolSettings = poolDao.readPoolById(poolConfigurationId).getPoolSettings();
   poolManagerApi.updateDecisionApproval(poolSettings, decisionId, approved);
 }
 @ModelAttribute("poolSettings")
 public PoolSettings getPoolSettings(
     /*@PathVariable("accountId") Long accountId,
     @PathVariable("poolId") Long poolId */ HttpServletRequest request) {
   //        return getAccountPool( accountId, poolId ).getPoolSettings();
   Map pathVariables =
       (Map)
           request.getAttribute(
               "org.springframework.web.servlet.HandlerMapping.uriTemplateVariables");
   if (pathVariables.containsKey("accountId") && pathVariables.containsKey("poolId")) {
     long accountId = Long.parseLong((String) pathVariables.get("accountId"));
     long poolId = Long.parseLong((String) pathVariables.get("poolId"));
     return poolDao.readPoolByIdAndAccountId(poolId, accountId).getPoolSettings();
   } else {
     return null;
   }
 }
  /** @return poolConfigurationId => poolStatus map. */
  @RequestMapping(value = "/admin/pools/status", method = RequestMethod.GET)
  @ResponseBody
  public Map<Long, PoolStatus> getPoolsStatus() {
    Map<Long /* poolConfigurationId */, PoolStatus> resultMap = new HashMap<Long, PoolStatus>();
    // get pool status for all pools
    Collection<PoolStatus> poolStatuses = poolManagerApi.listStatuses();
    // map every status found to its pool configuration
    List<PoolConfigurationModel> poolConfigurationModels = poolDao.readPools();
    for (PoolConfigurationModel poolConfiguration : poolConfigurationModels) {
      Long poolConfigurationId = poolConfiguration.getId();

      for (PoolStatus poolStatus : poolStatuses) {
        if (poolStatus.getPoolId().equals(poolConfiguration.getPoolSettings().getUuid())) {
          resultMap.put(poolConfigurationId, poolStatus);
        }
      }
    }

    return resultMap;
  }
 @RequestMapping(value = "/admin/pools/{poolId}/cloud/nodes", method = RequestMethod.GET)
 @ResponseBody
 public List<NodeMappings> getCloudNodes(@PathVariable("poolId") Long poolConfigurationId) {
   PoolSettings poolSettings = poolDao.readPoolById(poolConfigurationId).getPoolSettings();
   return poolManagerApi.listCloudNodes(poolSettings);
 }
 @RequestMapping(value = "/admin/pools/{poolId}/errors/delete", method = RequestMethod.POST)
 @ResponseBody
 public void deletePoolErrors(@PathVariable("poolId") Long poolConfigurationId) {
   PoolSettings poolSettings = poolDao.readPoolById(poolConfigurationId).getPoolSettings();
   poolManagerApi.deleteErrors(poolSettings);
 }
 @RequestMapping(value = "/admin/pools", method = RequestMethod.GET)
 @ResponseBody
 public List<PoolConfigurationModel> getPools() {
   return poolDao.readPools();
 }
 @RequestMapping(value = "/admin/accounts/{accountId}/pools", method = RequestMethod.GET)
 @ResponseBody
 public List<PoolConfigurationModel> getAccountPools(@PathVariable("accountId") Long accountId) {
   return poolDao.readPools(accountId);
 }
 @RequestMapping(value = "/admin/pools/{poolId}/tasks", method = RequestMethod.GET)
 @ResponseBody
 public List<TaskModel> getPoolTasks(@PathVariable("poolId") Long poolConfigurationId) {
   PoolSettings poolSettings = poolDao.readPoolById(poolConfigurationId).getPoolSettings();
   return poolManagerApi.listRunningTasks(poolSettings);
 }