use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class ProjectService method updateQuota.
/**
* Updates quota and available capacity before quota is exhausted
*
* @param id the URN of a ViPR Project.
* @param param new values for the quota
* @prereq none
* @brief Update quota and available capacity
* @return QuotaInfo Quota metrics.
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/quota")
public QuotaInfo updateQuota(@PathParam("id") URI id, QuotaUpdateParam param) throws DatabaseException {
Project project = getProjectById(id, true);
project.setQuotaEnabled(param.getEnable());
if (param.getEnable()) {
long quota_gb = (param.getQuotaInGb() != null) ? param.getQuotaInGb() : project.getQuota();
ArgValidator.checkFieldMinimum(quota_gb, 0, "quota_gb", "GB");
// Verify that the quota of this project does not exit quota for its tenant
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
if (tenant.getQuotaEnabled()) {
long totalProjects = CapacityUtils.totalProjectQuota(_dbClient, tenant.getId()) - project.getQuota() + quota_gb;
if (totalProjects > tenant.getQuota()) {
throw APIException.badRequests.invalidParameterProjectQuotaInvalidatesTenantQuota(tenant.getQuota());
}
}
project.setQuota(quota_gb);
}
_dbClient.persistObject(project);
return getQuota(project);
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class ProjectService method unassignVNasServersFromProject.
/**
* Unassigns VNAS server from project.
*
* @param id the URN of a ViPR Project
* @param param Assign virtual NAS server parameters
* @prereq none
* @brief Unassign VNAS servers from project
* @return No data returned in response body
* @throws BadRequestException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/unassign-vnas-servers")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ALL, ACL.OWN })
public Response unassignVNasServersFromProject(@PathParam("id") URI id, VirtualNasParam param) {
checkCompatibleVersion();
Project project = getProjectById(id, true);
Set<String> vNasIds = param.getVnasServers();
if (vNasIds != null && !vNasIds.isEmpty()) {
StringSet vnasServers = project.getAssignedVNasServers();
if (!vnasServers.containsAll(vNasIds)) {
throw APIException.badRequests.vNasServersNotAssociatedToProject();
}
if (vnasServers != null && !vnasServers.isEmpty()) {
for (String vId : vNasIds) {
URI vnasURI = URI.create(vId);
VirtualNAS vnas = _permissionsHelper.getObjectById(vnasURI, VirtualNAS.class);
ArgValidator.checkEntity(vnas, vnasURI, isIdEmbeddedInURL(vnasURI));
if (vnasServers.contains(vId)) {
vnas.dissociateProject(id.toString());
_dbClient.updateObject(vnas);
project.getAssignedVNasServers().remove(vId);
}
}
_dbClient.updateObject(project);
_log.info("Successfully unassigned the VNAS servers from project : {} ", project.getLabel());
} else {
throw APIException.badRequests.noVNasServersAssociatedToProject(project.getLabel());
}
} else {
throw APIException.badRequests.invalidEntryForProjectVNAS();
}
return Response.ok().build();
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class ProjectService method getProjectById.
/**
* Get project object from id
*
* @param id the URN of a ViPR Project
* @return
*/
private Project getProjectById(URI id, boolean checkInactive) {
if (id == null) {
return null;
}
Project ret = _permissionsHelper.getObjectById(id, Project.class);
ArgValidator.checkEntity(ret, id, isIdEmbeddedInURL(id), checkInactive);
return ret;
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class ProjectService method getRoleAssignmentsResponse.
private ACLAssignments getRoleAssignmentsResponse(URI id) {
Project project = getProjectById(id, false);
ACLAssignments response = new ACLAssignments();
response.setAssignments(_permissionsHelper.convertToACLEntries(project.getAcls()));
return response;
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class RPBlockServiceApiImpl method upgradeToMetroPointVolume.
/**
* Upgrade a local block volume to a protected RP volume
*
* @param volume the existing volume being protected.
* @param newVpool the requested virtual pool
* @param taskId the task identifier
* @throws InternalException
*/
private void upgradeToMetroPointVolume(Volume volume, VirtualPool newVpool, VirtualPoolChangeParam vpoolChangeParam, String taskId) throws InternalException {
_log.info(String.format("Upgrade [%s] to MetroPoint", volume.getLabel()));
Project project = _dbClient.queryObject(Project.class, volume.getProject());
// Now that we have a handle on the current vpool, let's set the new vpool on the volume.
// The volume will not be persisted just yet but we need to have the new vpool to
// properly make placement decisions and to add reference to the new vpool to the
// recommendation objects that will be created.
URI currentVpool = volume.getVirtualPool();
volume.setVirtualPool(newVpool.getId());
List<Recommendation> recommendations = getRecommendationsForVirtualPoolChangeRequest(volume, newVpool, vpoolChangeParam, null);
volume.setVirtualPool(currentVpool);
if (recommendations.isEmpty()) {
throw APIException.badRequests.noStorageFoundForVolume();
}
// Get the volume's varray
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, volume.getVirtualArray());
// Generate a VolumeCreate object that contains the information that createVolumes likes to consume.
VolumeCreate param = new VolumeCreate(volume.getLabel(), String.valueOf(volume.getCapacity()), 1, newVpool.getId(), volume.getVirtualArray(), volume.getProject().getURI());
VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, 1);
capabilities.put(VirtualPoolCapabilityValuesWrapper.BLOCK_CONSISTENCY_GROUP, volume.getConsistencyGroup());
TaskList taskList = new TaskList();
createTaskForVolume(volume, ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VPOOL, taskList, taskId);
Map<VpoolUse, List<Recommendation>> recommendationMap = new HashMap<VpoolUse, List<Recommendation>>();
recommendationMap.put(VpoolUse.ROOT, recommendations);
createVolumes(param, project, varray, newVpool, recommendationMap, taskList, taskId, capabilities);
}
Aggregations