Search in sources :

Example 36 with VolumeGroup

use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.

the class VolumeGroupService method getSnapshotSessionsGroupedBySnapSessionset.

/**
 * Validate resources and return a list of snapshot sessions for set name
 *
 * If partial, validate snapshot sessions in VolumeGroupSnapshotOperationParam belonging to multiple sets
 * If full, find all snapshot sessions for the set name in the provided snapshot session
 *
 * @param volumeGroupId
 * @param param VolumeGroupSnapshotSessionOperationParam
 * @return list of snapshot sessions
 */
private List<BlockSnapshotSession> getSnapshotSessionsGroupedBySnapSessionset(final URI volumeGroupId, VolumeGroupSnapshotSessionOperationParam param) {
    ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, "id");
    // Query volume group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    // validate replica operation for volume group
    validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT_SESSION);
    List<URI> snapshotsInRequest = new ArrayList<URI>();
    boolean partialRequest = false;
    if (param.getSnapshotSessions() != null && !param.getSnapshotSessions().isEmpty()) {
        // validate only one snapshot URI is provided for full request
        if (!param.getPartial() && param.getSnapshotSessions().size() > 1) {
            throw APIException.badRequests.invalidNumberOfReplicas(ReplicaTypeEnum.SNAPSHOT.toString());
        }
        snapshotsInRequest.addAll(param.getSnapshotSessions());
        partialRequest = param.getPartial();
    } else {
        ArgValidator.checkFieldNotEmpty(param.getCopySetName(), COPY_SET_NAME_FIELD);
        if (param.getSubGroups() != null && !param.getSubGroups().isEmpty()) {
            partialRequest = validateSubGroupsParam(param.getSubGroups(), volumeGroup);
        }
        URIQueryResultList snapshotIds = new URIQueryResultList();
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getBlockSnapshotSessionsBySetName(param.getCopySetName()), snapshotIds);
        Iterator<BlockSnapshotSession> iter = _dbClient.queryIterativeObjects(BlockSnapshotSession.class, snapshotIds);
        if (partialRequest) {
            // get one snapshot per sub group requested
            List<Volume> volumesInApplication = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
            Map<URI, Volume> volumesMap = new HashMap<URI, Volume>();
            for (Volume volume : volumesInApplication) {
                volumesMap.put(volume.getId(), volume);
            }
            while (iter.hasNext()) {
                BlockSnapshotSession snapshot = iter.next();
                Volume parent = volumesMap.get(snapshot.getParent().getURI());
                if (parent != null && param.getSubGroups().contains(parent.getReplicationGroupInstance())) {
                    snapshotsInRequest.add(iter.next().getId());
                }
            }
        } else {
            // for non-partial, we only need one snapshot in the snapshot set
            if (iter.hasNext()) {
                snapshotsInRequest.add(iter.next().getId());
            }
        }
    }
    List<BlockSnapshotSession> snapSessions = new ArrayList<BlockSnapshotSession>();
    Set<String> setNames = new HashSet<String>();
    for (URI sessionURI : snapshotsInRequest) {
        ArgValidator.checkFieldUriType(sessionURI, BlockSnapshotSession.class, SNAPSHOT_SESSION_FIELD);
        // Get the snapshot session
        BlockSnapshotSession session = BlockSnapshotSessionUtils.querySnapshotSession(sessionURI, uriInfo, _dbClient, true);
        // validate that source of the provided snapshot session is part of the volume group
        validateSnapSessionBelongsToApplication(session, volumeGroup);
        String setName = session.getSessionSetName();
        setNames.add(setName);
        if (partialRequest) {
            snapSessions.add(session);
        } else {
            log.info("Snapshot Session operation requested for entire Application, Considering session {} in request.", session.getLabel());
            // get the snapshot sessions for the volume group
            List<BlockSnapshotSession> volumeGroupSessions = getVolumeGroupSnapshotSessions(volumeGroup);
            for (BlockSnapshotSession vgSession : volumeGroupSessions) {
                if (setName.equals(vgSession.getSessionSetName())) {
                    snapSessions.add(vgSession);
                }
            }
        }
    }
    if (setNames.size() > 1) {
        throw APIException.badRequests.multipleSetNamesProvided(ReplicaTypeEnum.SNAPSHOT_SESSION.toString());
    }
    return snapSessions;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) HashSet(java.util.HashSet)

Example 37 with VolumeGroup

use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.

the class VolumeGroupService method getVolumeGroupSnapshots.

/**
 * List snapshots for a volume group
 *
 * @prereq none
 * @param volumeGroupId The URI of the volume group.
 * @brief List snapshots for a volume group
 * @return SnapshotList
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getVolumeGroupSnapshots(@PathParam("id") final URI volumeGroupId) {
    // query volume group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    // validate replica operation for volume group
    validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
    // get all volumes
    List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
    // get the snapshots for each volume in the group
    SnapshotList snapshotList = new SnapshotList();
    for (Volume volume : volumes) {
        if (volume.isVPlexVolume(_dbClient)) {
            volume = VPlexUtil.getVPLEXBackendVolume(volume, true, _dbClient);
            if (volume == null || volume.getInactive()) {
                log.warn("Cannot find backend volume for VPLEX volume {}", volume.getLabel());
            }
        }
        URIQueryResultList snapshotURIs = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volume.getId()), snapshotURIs);
        if (!snapshotURIs.iterator().hasNext()) {
            continue;
        }
        List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, snapshotURIs);
        for (BlockSnapshot snapshot : snapshots) {
            if (snapshot != null && !snapshot.getInactive()) {
                snapshotList.getSnapList().add(toNamedRelatedResource(snapshot));
            }
        }
    }
    return snapshotList;
}
Also used : SnapshotList(com.emc.storageos.model.SnapshotList) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 38 with VolumeGroup

use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.

the class VolumeGroupService method setParent.

private String setParent(VolumeGroup volumeGroup, String parent) {
    String errorMsg = null;
    // add parent if specified
    if (parent != null && !parent.isEmpty()) {
        if (URIUtil.isValid(parent)) {
            URI parentId = URI.create(parent);
            ArgValidator.checkFieldUriType(parentId, VolumeGroup.class, "parent");
            VolumeGroup parentVG = _dbClient.queryObject(VolumeGroup.class, parentId);
            if (parentVG == null || parentVG.getInactive()) {
                errorMsg = "The parent volume group does not exist";
            } else {
                volumeGroup.setParent(parentId);
            }
        } else if (NullColumnValueGetter.isNullValue(parent)) {
            volumeGroup.setParent(NullColumnValueGetter.getNullURI());
        } else {
            List<VolumeGroup> parentVg = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, VolumeGroup.class, PrefixConstraint.Factory.getLabelPrefixConstraint(VolumeGroup.class, parent));
            if (parentVg == null || parentVg.isEmpty()) {
                errorMsg = "The parent volume group does not exist";
            } else {
                volumeGroup.setParent(parentVg.iterator().next().getId());
            }
        }
    }
    return errorMsg;
}
Also used : VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) NamedVolumeGroupsList(com.emc.storageos.model.block.NamedVolumeGroupsList) HostList(com.emc.storageos.model.host.HostList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ClusterList(com.emc.storageos.model.host.cluster.ClusterList) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) List(java.util.List) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) VolumeGroupCopySetList(com.emc.storageos.model.application.VolumeGroupCopySetList) SnapshotList(com.emc.storageos.model.SnapshotList) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)

Example 39 with VolumeGroup

use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.

the class VolumeGroupService method getClusters.

/**
 * Get application clusters
 *
 * @param id Application Id
 * @brief List clusters for an application
 * @return ClusterList
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/clusters")
public ClusterList getClusters(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, VolumeGroup.class, "id");
    VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, id);
    ClusterList result = new ClusterList();
    List<Cluster> clusters = getVolumeGroupClusters(_dbClient, volumeGroup);
    for (Cluster cluster : clusters) {
        result.getClusters().add(toNamedRelatedResource(cluster));
    }
    return result;
}
Also used : ClusterList(com.emc.storageos.model.host.cluster.ClusterList) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) Cluster(com.emc.storageos.db.client.model.Cluster) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with VolumeGroup

use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.

the class BlockFullCopyManager method createFullCopy.

/**
 * Manages a request to create a full copy from the block object with the
 * passed URI. The URI must reference a volume or snapshot. For supported
 * platforms, if the source is a volume and it is in a consistency group,
 * full copies will be created for all volumes in the consistency group.
 *
 * @param sourceURI The URI of the source volume or snapshot.
 * @param param The request data specifying the parameters for the request.
 *
 * @return TaskList
 *
 * @throws InternalException
 */
public TaskList createFullCopy(URI sourceURI, VolumeFullCopyCreateParam param) throws InternalException {
    s_logger.info("START create full copy for source {}", sourceURI);
    // Create a unique task identifier.
    String taskId = UUID.randomUUID().toString();
    List<BlockObject> fcSourceObjList = null;
    BlockFullCopyApi fullCopyApiImpl = null;
    // Get the volume/snapshot.
    BlockObject fcSourceObj = BlockFullCopyUtils.queryFullCopyResource(sourceURI, _uriInfo, true, _dbClient);
    // Get the requested full copy count.
    int count = param.getCount() == null ? 1 : param.getCount();
    // Get the full copy name.
    String name = TimeUtils.formatDateForCurrent(param.getName());
    // Get whether or not the full copy should be created inactive.
    // Check if the request calls for activation of the full copy
    boolean createInactive = param.getCreateInactive() == null ? Boolean.FALSE : param.getCreateInactive();
    // if Volume is part of Application (COPY type VolumeGroup)
    VolumeGroup volumeGroup = (fcSourceObj instanceof Volume) ? ((Volume) fcSourceObj).getApplication(_dbClient) : null;
    boolean partialRequest = fcSourceObj.checkInternalFlags(Flag.VOLUME_GROUP_PARTIAL_REQUEST);
    VirtualArray varray = null;
    if (volumeGroup != null && !partialRequest) {
        s_logger.info("Volume {} is part of Application, Creating full copy for all volumes in the Application.", sourceURI);
        // get all volumes
        List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
        // if RP get source or target volumes
        if (volumes != null && !volumes.isEmpty() && Volume.checkForRP(_dbClient, volumes.iterator().next().getId())) {
            List<Volume> rpVolumes = RPHelper.getVolumesForSite(param.getVarrayId(), param.getVpoolId(), volumes);
            volumes.clear();
            volumes.addAll(rpVolumes);
        }
        // group volumes by Array Group
        Map<String, List<Volume>> arrayGroupToVolumesMap = ControllerUtils.groupVolumesByArrayGroup(volumes, _dbClient);
        fcSourceObjList = new ArrayList<BlockObject>();
        for (String arrayGroupName : arrayGroupToVolumesMap.keySet()) {
            List<Volume> volumeList = arrayGroupToVolumesMap.get(arrayGroupName);
            s_logger.debug("Processing Array Replication Group {}, volumes: {}", arrayGroupName, volumeList.size());
            fcSourceObj = volumeList.iterator().next();
            s_logger.debug("volume selected :{}", fcSourceObj.getNativeGuid());
            // Get the project for the full copy source object.
            Project project = BlockFullCopyUtils.queryFullCopySourceProject(fcSourceObj, _dbClient);
            // verify the virtual array.
            varray = BlockServiceUtils.verifyVirtualArrayForRequest(project, fcSourceObj.getVirtualArray(), _uriInfo, _permissionsHelper, _dbClient);
            // Get the platform specific block full copy implementation.
            fullCopyApiImpl = getPlatformSpecificFullCopyImpl(fcSourceObj);
            // Get the list of all block objects for which we need to
            // create full copies. For example, when creating a full copy
            // for a volume in a consistency group, we may create full
            // copies for all volumes in the consistency group.
            List<BlockObject> fcSourceObjListPerArrayGroup = fullCopyApiImpl.getAllSourceObjectsForFullCopyRequest(fcSourceObj);
            // Validate the full copy request.
            validateFullCopyCreateRequest(fcSourceObjListPerArrayGroup, project, name, count, createInactive, fullCopyApiImpl);
            fcSourceObjList.addAll(fcSourceObjListPerArrayGroup);
        }
    } else {
        // Get the project for the full copy source object.
        Project project = BlockFullCopyUtils.queryFullCopySourceProject(fcSourceObj, _dbClient);
        // verify the virtual array.
        varray = BlockServiceUtils.verifyVirtualArrayForRequest(project, fcSourceObj.getVirtualArray(), _uriInfo, _permissionsHelper, _dbClient);
        // Get the platform specific block full copy implementation.
        fullCopyApiImpl = getPlatformSpecificFullCopyImpl(fcSourceObj);
        // Get the list of all block objects for which we need to
        // create full copies. For example, when creating a full copy
        // for a volume in a consistency group, we may create full
        // copies for all volumes in the consistency group.
        fcSourceObjList = fullCopyApiImpl.getAllSourceObjectsForFullCopyRequest(fcSourceObj);
        // Validate the full copy request.
        validateFullCopyCreateRequest(fcSourceObjList, project, name, count, createInactive, fullCopyApiImpl);
    }
    // Create the full copies
    TaskList taskList = fullCopyApiImpl.create(fcSourceObjList, varray, name, createInactive, count, taskId);
    s_logger.info("FINISH create full copy for source {}", sourceURI);
    return taskList;
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) TaskList(com.emc.storageos.model.TaskList) Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) List(java.util.List) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) BlockObject(com.emc.storageos.db.client.model.BlockObject)

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