use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method getVolumeGroups.
/**
* List volume groups.
*
* @brief List all volume groups
* @return A reference to VolumeGroupList.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VolumeGroupList getVolumeGroups() {
VolumeGroupList volumeGroupList = new VolumeGroupList();
List<URI> ids = _dbClient.queryByType(VolumeGroup.class, true);
Iterator<VolumeGroup> iter = _dbClient.queryIterativeObjects(VolumeGroup.class, ids);
StorageOSUser user = getUserFromContext();
if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN)) {
while (iter.hasNext()) {
VolumeGroup vg = iter.next();
volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(vg));
}
} else {
log.info("checking tenant");
// otherwise, filter by only authorized to use
URI tenant = URI.create(user.getTenantId());
while (iter.hasNext()) {
VolumeGroup vg = iter.next();
List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, vg);
if (volumes == null || volumes.isEmpty()) {
// if no volume in the application yet, the application is visible to all tenants
volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(vg));
} else {
Volume firstVol = volumes.get(0);
URI volTenant = firstVol.getTenant().getURI();
if (volTenant.equals(tenant)) {
volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(vg));
}
}
}
}
return volumeGroupList;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method updateVolumeGroup.
/**
* Update a volume group
*
* @param id volume group id
* @param param volume group update parameters
* @brief Change information for volume group
* @return TaskList
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList updateVolumeGroup(@PathParam("id") final URI id, final VolumeGroupUpdateParam param) {
ArgValidator.checkFieldUriType(id, VolumeGroup.class, "id");
VolumeGroup volumeGroup = (VolumeGroup) queryResource(id);
if (volumeGroup.getInactive()) {
throw APIException.badRequests.volumeGroupCantBeUpdated(volumeGroup.getLabel(), "The Volume Group has been deleted");
}
boolean isChanged = false;
String vgName = param.getName();
if (vgName != null && !vgName.isEmpty() && !vgName.equalsIgnoreCase(volumeGroup.getLabel())) {
checkDuplicateLabel(VolumeGroup.class, vgName);
volumeGroup.setLabel(vgName);
isChanged = true;
}
String description = param.getDescription();
if (description != null && !description.isEmpty()) {
volumeGroup.setDescription(description);
isChanged = true;
}
String parent = param.getParent();
if (parent != null && !parent.isEmpty()) {
String msg = setParent(volumeGroup, parent);
if (msg != null && !msg.isEmpty()) {
throw APIException.badRequests.volumeGroupCantBeUpdated(volumeGroup.getLabel(), msg);
}
isChanged = true;
}
if (isChanged) {
_dbClient.updateObject(volumeGroup);
}
String taskId = UUID.randomUUID().toString();
TaskList taskList = new TaskList();
Operation op = null;
if (!param.hasEitherAddOrRemoveVolumes() && !param.hasEitherAddOrRemoveHosts() && !param.hasEitherAddOrRemoveClusters()) {
op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UPDATE_VOLUME_GROUP);
op.ready();
volumeGroup.getOpStatus().createTaskStatus(taskId, op);
_dbClient.updateObject(volumeGroup);
TaskResourceRep task = toTask(volumeGroup, taskId, op);
taskList.getTaskList().add(task);
return taskList;
}
List<VolumeGroupUtils> utils = getVolumeGroupUtils(volumeGroup);
for (VolumeGroupUtils util : utils) {
util.validateUpdateVolumesInVolumeGroup(_dbClient, param, volumeGroup);
}
for (VolumeGroupUtils util : utils) {
util.updateVolumesInVolumeGroup(_dbClient, param, volumeGroup, taskId, taskList);
}
auditOp(OperationTypeEnum.UPDATE_VOLUME_GROUP, true, AuditLogManager.AUDITOP_BEGIN, volumeGroup.getId().toString(), volumeGroup.getLabel());
return taskList;
}
Aggregations