Search in sources :

Example 51 with VolumeGroup

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;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 52 with VolumeGroup

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;
}
Also used : VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

VolumeGroup (com.emc.storageos.db.client.model.VolumeGroup)52 Volume (com.emc.storageos.db.client.model.Volume)35 Produces (javax.ws.rs.Produces)29 Path (javax.ws.rs.Path)27 URI (java.net.URI)26 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)21 ArrayList (java.util.ArrayList)20 TaskList (com.emc.storageos.model.TaskList)15 GET (javax.ws.rs.GET)15 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)14 Consumes (javax.ws.rs.Consumes)13 POST (javax.ws.rs.POST)13 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)12 NamedVolumesList (com.emc.storageos.model.block.NamedVolumesList)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)10 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)9 VolumeGroupCopySetList (com.emc.storageos.model.application.VolumeGroupCopySetList)9 NamedURI (com.emc.storageos.db.client.model.NamedURI)8 SnapshotList (com.emc.storageos.model.SnapshotList)8 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)8