Commit c36da2cd authored by Spiros Koulouzis's avatar Spiros Koulouzis

provision with API v0.0 works

parent ba93249a
......@@ -15,8 +15,15 @@
*/
package nl.uva.sne.drip.api.service;
import java.util.List;
import nl.uva.sne.drip.api.dao.ClusterCredentialsDao;
import nl.uva.sne.drip.commons.v1.types.ClusterCredentials;
import nl.uva.sne.drip.commons.v1.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
/**
......@@ -24,15 +31,33 @@ import org.springframework.stereotype.Service;
* @author S. Koulouzis
*/
@Service
@PreAuthorize("isAuthenticated()")
public class ClusterCredentialService {
@Autowired
private ClusterCredentialsDao dao;
/**
* @return the dao
*/
public ClusterCredentialsDao getDao() {
return dao;
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public ClusterCredentials findOne(String id) {
return dao.findOne(id);
}
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public List<ClusterCredentials> findAll() {
return dao.findAll();
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public ClusterCredentials delete(String id) {
ClusterCredentials cred = dao.findOne(id);
dao.delete(cred);
return cred;
}
public ClusterCredentials save(ClusterCredentials clusterCred) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
clusterCred.setOwner(owner);
return dao.save(clusterCred);
}
}
......@@ -40,6 +40,8 @@ import nl.uva.sne.drip.drip.converter.SimplePlanContainer;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
......@@ -131,7 +133,7 @@ public class PlannerService {
}
public String get(String id, String fromat) throws JSONException {
Plan plan = planDao.findOne(id);
Plan plan = findOne(id);
if (plan == null) {
throw new NotFoundException();
}
......@@ -139,7 +141,7 @@ public class PlannerService {
Map<String, Object> map = plan.getKeyValue();
Set<String> ids = plan.getLoweLevelPlanIDs();
for (String lowID : ids) {
Map<String, Object> lowLevelMap = planDao.findOne(lowID).getKeyValue();
Map<String, Object> lowLevelMap = findOne(lowID).getKeyValue();
if (lowLevelMap != null) {
map.putAll(lowLevelMap);
}
......@@ -161,9 +163,10 @@ public class PlannerService {
}
public String getToscaID(String id) {
return planDao.findOne(id).getToscaID();
return findOne(id).getToscaID();
}
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public List<Plan> findAll() {
List<Plan> all = planDao.findAll();
List<Plan> topLevel = new ArrayList<>();
......@@ -182,12 +185,17 @@ public class PlannerService {
return planDao.save(plan);
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Plan findOne(String lowiID) {
return planDao.findOne(lowiID);
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public Plan delete(String id) {
Plan plan = planDao.findOne(id);
if (plan == null) {
throw new NotFoundException();
}
planDao.delete(plan);
return plan;
}
......
......@@ -36,6 +36,7 @@ import nl.uva.sne.drip.api.dao.ProvisionInfoDao;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.CloudCredentialsNotFoundException;
import nl.uva.sne.drip.api.exception.ExceptionHandler;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.exception.PlanNotFoundException;
import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller;
......@@ -95,6 +96,9 @@ public class ProvisionService {
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public ProvisionInfo findOne(String id) {
ProvisionInfo provisionInfo = dao.findOne(id);
if (provisionInfo == null) {
throw new NotFoundException();
}
return provisionInfo;
}
......
......@@ -53,8 +53,9 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
/**
* This controller is responsible for deploying a cluster on provisoned resources.
*
* This controller is responsible for deploying a cluster on provisoned
* resources.
*
* @author S. Koulouzis
*/
@RestController
......@@ -75,10 +76,11 @@ public class DeployController {
private ClusterCredentialService clusterCredentialService;
/**
* Deploys a cluster on a provisioned resources.
* @param provisionID
* Deploys a cluster on a provisioned resources.
*
* @param provisionID
* @param clusterType
* @return the id of the cluster credentials
* @return the id of the cluster credentials
*/
@RequestMapping(value = "/deploy/{id}/", method = RequestMethod.GET, params = {"cluster"})
@RolesAllowed({UserService.USER, UserService.ADMIN})
......@@ -97,7 +99,7 @@ public class DeployController {
if (name.equals("credential")) {
String value = p.getValue();
clusterCred.setContents(value);
clusterCredentialService.getDao().save(clusterCred);
clusterCredentialService.save(clusterCred);
return clusterCred.getId();
}
}
......@@ -109,7 +111,8 @@ public class DeployController {
}
/**
* Gets the cluster credentials.
* Gets the cluster credentials.
*
* @param id
* @return the cluster credentials
*/
......@@ -117,7 +120,7 @@ public class DeployController {
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
ClusterCredentials get(@PathVariable("id") String id) {
ClusterCredentials clusterC = clusterCredentialService.getDao().findOne(id);
ClusterCredentials clusterC = clusterCredentialService.findOne(id);
if (clusterC == null) {
throw new NotFoundException();
}
......@@ -126,13 +129,14 @@ public class DeployController {
/**
* Gets the IDs of all the stored cluster credentials
* @return a list of all the IDs
*
* @return a list of all the IDs
*/
@RequestMapping(value = "/ids", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
List<String> getIds() {
List<ClusterCredentials> all = clusterCredentialService.getDao().findAll();
List<ClusterCredentials> all = clusterCredentialService.findAll();
List<String> ids = new ArrayList<>(all.size());
for (ClusterCredentials pi : all) {
ids.add(pi.getId());
......@@ -141,17 +145,18 @@ public class DeployController {
}
/**
* Deletes a cluster credential
* @param id. The id of the cluster credential
* @return the id f the deleted cluster credential
* Deletes a cluster credential
*
* @param id. The id of the cluster credential
* @return the id f the deleted cluster credential
*/
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String delete(@PathVariable("id") String id) {
ClusterCredentials cred = clusterCredentialService.getDao().findOne(id);
ClusterCredentials cred = clusterCredentialService.findOne(id);
if (cred != null) {
provisionService.delete(id);
clusterCredentialService.delete(id);
return "Deleted : " + id;
}
throw new NotFoundException();
......
......@@ -24,7 +24,7 @@ import org.springframework.data.annotation.Id;
*
* @author S. Koulouzis
*/
public class ClusterCredentials {
public class ClusterCredentials extends OwnedObject{
@Id
private String id;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment