/** * Edits a cluster * * @param name the cluster's name */ @RequestMapping(value = "/clusters/{name}", method = RequestMethod.PUT) public Cluster updateCluster( @PathVariable("name") final String name, @RequestParam(value = "name", required = true) final String newName) { Cluster cluster = clusterRepo.findByName(name).orElseThrow(NotFoundException::new); cluster.setName(newName); clusterRepo.save(cluster); return cluster; }
/** * Adds a new cluster * * @param name the cluster's name */ @RequestMapping(value = "/clusters", method = RequestMethod.POST) public Cluster addCluster( @RequestParam(value = "name", required = true) final String name, @RequestParam(value = "vagrant", required = true) final String provider) { Cluster cluster = new Cluster(); cluster.setName(name); cluster.setProvider(provider); clusterRepo.save(cluster); return cluster; }
/** * Returns all clusters * * @return all clusters */ @RequestMapping(value = "/clusters", method = RequestMethod.GET) public Collection<Cluster> clusters() { Collection<Cluster> clusters = clusterRepo.findAll(); for (Cluster cluster : clusters) { ClusterStrategy strategy = strategyFactory.getStrategy(ClusterStrategy.class, cluster.getProvider()); for (Node node : cluster.getNodes()) { try { node.setStatus(strategy.getNodeStatus(node)); } catch (IOException e) { e.printStackTrace(); } } } return clusters; }
/** * Returns the clustj with the given name * * @param name the name of the cluster * @return the cluster with the given name */ @RequestMapping(value = "/clusters/{name}", method = RequestMethod.GET) public Cluster cluster(@PathVariable(value = "name") String name) { return clusterRepo.findByName(name).orElseThrow(NotFoundException::new); }
/** * Deletes a cluster * * @param name the cluster's name */ @RequestMapping(value = "/clusters/{name}", method = RequestMethod.DELETE) public void deleteCluster(@PathVariable("name") final String name) { Cluster cluster = clusterRepo.findByName(name).orElseThrow(NotFoundException::new); clusterRepo.delete(cluster); }