Search in sources :

Example 11 with VolumeGroup

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

the class VolumeGroupService method createVolumeGroup.

/**
 * Create a volume group
 *
 * @param param Parameters for creating a volume group
 * @brief Create new volume group
 * @return created volume group
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VolumeGroupRestRep createVolumeGroup(VolumeGroupCreateParam param) {
    ArgValidator.checkFieldNotEmpty(param.getName(), VOLUME_GROUP_NAME);
    checkDuplicateLabel(VolumeGroup.class, param.getName());
    Set<String> roles = param.getRoles();
    ArgValidator.checkFieldNotEmpty(roles, VOLUME_GROUP_ROLES);
    for (String role : roles) {
        ArgValidator.checkFieldValueFromEnum(role, VOLUME_GROUP_ROLES, VolumeGroup.VolumeGroupRole.class);
    }
    VolumeGroup volumeGroup = new VolumeGroup();
    volumeGroup.setId(URIUtil.createId(VolumeGroup.class));
    volumeGroup.setLabel(param.getName());
    volumeGroup.setDescription(param.getDescription());
    volumeGroup.addRoles(param.getRoles());
    // add parent if specified
    String msg = setParent(volumeGroup, param.getParent());
    if (msg != null && !msg.isEmpty()) {
        throw APIException.badRequests.volumeGroupCantBeCreated(volumeGroup.getLabel(), msg);
    }
    if (param.getRoles().contains(VolumeGroup.VolumeGroupRole.MOBILITY.name())) {
        ArgValidator.checkFieldNotEmpty(param.getMigrationType(), MIGRATION_TYPE);
        ArgValidator.checkFieldNotEmpty(param.getMigrationGroupBy(), MIGRATION_GROUP_BY);
        ArgValidator.checkFieldValueFromEnum(param.getMigrationType(), MIGRATION_TYPE, VolumeGroup.MigrationType.class);
        ArgValidator.checkFieldValueFromEnum(param.getMigrationGroupBy(), MIGRATION_GROUP_BY, VolumeGroup.MigrationGroupBy.class);
        volumeGroup.setMigrationType(param.getMigrationType());
        volumeGroup.setMigrationGroupBy(param.getMigrationGroupBy());
    }
    _dbClient.createObject(volumeGroup);
    auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP, true, null, volumeGroup.getId().toString(), volumeGroup.getLabel());
    return DbObjectMapper.map(volumeGroup);
}
Also used : VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 12 with VolumeGroup

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

the class VolumeGroupService method validateFullCopiesInRequest.

/**
 * Validate or creates the list of full copies in the request
 *
 * @param fullCopyVolumesInRequest the list of all full copy volumes to be processed as part of the request
 * @param fullCopyURIsInRequest the list of full copy URI's from the request object
 * @param copySetName the name of the copy set that identifies the set of full copies in the request
 * @param subGroups the name of the sub group that identifies the set of full copies in the request
 * @param volumeGroupUri the volume group URI
 * @return true if the request is partial, false if the request is full (includes all volumes in the application)
 */
private boolean validateFullCopiesInRequest(List<Volume> fullCopyVolumesInRequest, final List<URI> fullCopyURIsInRequest, String copySetName, List<String> subGroups, URI volumeGroupUri) {
    boolean partial = false;
    // validate that either copySetName or a volume list was sent in
    if (copySetName == null && (fullCopyURIsInRequest == null || fullCopyURIsInRequest.isEmpty())) {
        throw APIException.badRequests.invalidApplicationCopyOperationInput(ReplicaTypeEnum.FULL_COPY.toString());
    }
    VolumeGroup application = _dbClient.queryObject(VolumeGroup.class, volumeGroupUri);
    // if copy set name is used, get one clone volume from each sub group
    if (fullCopyURIsInRequest == null || fullCopyURIsInRequest.isEmpty()) {
        if (subGroups != null && !subGroups.isEmpty()) {
            partial = validateSubGroupsParam(subGroups, application);
        }
        Map<String, Volume> copySetVolumeMap = new HashMap<String, Volume>();
        List<Volume> volumesInApplication = ControllerUtils.getVolumeGroupVolumes(_dbClient, application);
        for (Volume volume : volumesInApplication) {
            String repGroupName = volume.getReplicationGroupInstance();
            if (volume.isVPlexVolume(_dbClient)) {
                Volume backedVol = VPlexUtil.getVPLEXBackendVolume(volume, true, _dbClient);
                if (backedVol != null) {
                    repGroupName = backedVol.getReplicationGroupInstance();
                }
            }
            if (volume.getFullCopies() != null) {
                for (String fullCopyUri : volume.getFullCopies()) {
                    Volume fullCopy = _dbClient.queryObject(Volume.class, URI.create(fullCopyUri));
                    if (StringUtils.equals(fullCopy.getFullCopySetName(), copySetName) && (!partial || subGroups.contains(repGroupName))) {
                        copySetVolumeMap.put(repGroupName, fullCopy);
                    }
                }
            }
        }
        if (copySetVolumeMap.isEmpty()) {
            throw APIException.badRequests.invalidCopySetNamesProvided(copySetName, ReplicaTypeEnum.FULL_COPY.toString());
        }
        fullCopyVolumesInRequest.addAll(copySetVolumeMap.values());
    } else {
        List<String> arrayGroupNames = new ArrayList<String>();
        Set<String> setNames = new HashSet<String>();
        for (URI fullCopyURI : fullCopyURIsInRequest) {
            String repGroupName = null;
            ArgValidator.checkFieldUriType(fullCopyURI, Volume.class, "volume");
            // Get the full copy.
            Volume fullCopyVolume = (Volume) BlockFullCopyUtils.queryFullCopyResource(fullCopyURI, uriInfo, false, _dbClient);
            if (fullCopyVolume.isVPlexVolume(_dbClient)) {
                Volume backedVol = VPlexUtil.getVPLEXBackendVolume(fullCopyVolume, true, _dbClient);
                if (backedVol != null) {
                    repGroupName = backedVol.getReplicationGroupInstance();
                }
            } else {
                repGroupName = fullCopyVolume.getReplicationGroupInstance();
            }
            // skip repeated array groups
            if (arrayGroupNames.contains(repGroupName)) {
                log.info("Skipping repetitive request for Full Copy array group {}. Full Copy: {}", repGroupName, fullCopyVolume.getLabel());
                continue;
            }
            arrayGroupNames.add(repGroupName);
            verifyReplicaForCopyRequest(fullCopyVolume, volumeGroupUri);
            fullCopyVolumesInRequest.add(fullCopyVolume);
            setNames.add(fullCopyVolume.getFullCopySetName());
        }
        if (setNames.size() > 1) {
            throw APIException.badRequests.multipleSetNamesProvided(ReplicaTypeEnum.FULL_COPY.toString());
        }
        Set<String> appSubGroups = CopyVolumeGroupUtils.getReplicationGroupNames(application, _dbClient);
        if (!appSubGroups.containsAll(arrayGroupNames)) {
            partial = true;
        }
    }
    return partial;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) HashMap(java.util.HashMap) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) ArrayList(java.util.ArrayList) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) HashSet(java.util.HashSet)

Example 13 with VolumeGroup

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

the class VolumeGroupService method getVolumeGroupFullCopiesForSet.

/**
 * List full copies for a volume group belonging to the provided copy set name
 *
 * @param volumeGroupId The URI of the volume group.
 * @param param VolumeGroupCopySetParam containing the copy set name
 *
 * @brief List full copies for a volume group belonging to the provided copy set name
 *
 * @return The list of full copies for the volume group belonging to the provided copy set name
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/full-copies/copy-sets")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public NamedVolumesList getVolumeGroupFullCopiesForSet(@PathParam("id") final URI volumeGroupId, final VolumeGroupCopySetParam param) {
    ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, "id");
    // Query Volume Group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    // validate that full copy set name is provided
    String fullCopySetName = param.getCopySetName();
    ArgValidator.checkFieldNotEmpty(fullCopySetName, COPY_SET_NAME_FIELD);
    // validate that the provided set name actually belongs to this Application
    VolumeGroupCopySetList fullCopySetNames = getVolumeGroupFullCopySets(volumeGroupId);
    if (!fullCopySetNames.getCopySets().contains(fullCopySetName)) {
        throw APIException.badRequests.setNameDoesNotBelongToVolumeGroup("Full Copy Set name", fullCopySetName, volumeGroup.getLabel());
    }
    NamedVolumesList fullCopyList = new NamedVolumesList();
    List<Volume> fullCopiesForSet = getClonesBySetName(fullCopySetName, volumeGroupId);
    for (Volume fullCopy : fullCopiesForSet) {
        fullCopyList.getVolumes().add(toNamedRelatedResource(fullCopy));
    }
    return fullCopyList;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) VolumeGroupCopySetList(com.emc.storageos.model.application.VolumeGroupCopySetList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with VolumeGroup

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

the class VolumeGroupService method getVolumeGroupChildren.

/**
 * get the children for this volume group
 *
 * @param dbClient
 *            db client for db queries
 * @param volumeGroup
 *            volume group to get children for
 * @return a list of volume groups
 */
private static List<VolumeGroup> getVolumeGroupChildren(DbClient dbClient, VolumeGroup volumeGroup) {
    List<VolumeGroup> result = new ArrayList<VolumeGroup>();
    final List<VolumeGroup> volumeGroups = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, VolumeGroup.class, ContainmentConstraint.Factory.getVolumesGroupsByVolumeGroupId(volumeGroup.getId()));
    for (VolumeGroup volGroup : volumeGroups) {
        result.add(volGroup);
    }
    return result;
}
Also used : VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) ArrayList(java.util.ArrayList)

Example 15 with VolumeGroup

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

the class VolumeGroupService method resynchronizeVolumeGroupFullCopy.

/**
 * Resynchronize the specified Volume group full copy.
 * - Resynchronizes full copy for all the array replication groups within this Application.
 * - If partial flag is specified, it resynchronizes full copy only for set of array replication groups.
 * A Full Copy from each array replication group can be provided to indicate which array replication
 * groups's full copies needs to be resynchronized.
 *
 * @prereq Create Volume group full copy as active.
 *
 * @param volumeGroupId The URI of the Volume group.
 * @param fullCopyURI The URI of the full copy.
 *
 * @brief Resynchronize Volume group full copy.
 *
 * @return TaskList
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/full-copies/resynchronize")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList resynchronizeVolumeGroupFullCopy(@PathParam("id") final URI volumeGroupId, final VolumeGroupFullCopyResynchronizeParam param) {
    ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, "id");
    // Query Volume Group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    TaskList taskList = new TaskList();
    // validate replica operation for volume group
    validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.FULL_COPY);
    // validate the requested full copies
    List<Volume> fullCopyVolumesInRequest = new ArrayList<Volume>();
    boolean partial = validateFullCopiesInRequest(fullCopyVolumesInRequest, param.getFullCopies(), param.getCopySetName(), param.getSubGroups(), volumeGroupId);
    /**
     * 1. VolumeGroupService Clone API accepts a Clone URI (to identify clone set and RG)
     * - then get All full copies belonging to same full copy set
     * - get full copy set name from the requested full copy
     * 2. If partial, there will be a List of Clone URIs (one from each RG)
     * 3. Group the full copies by Replication Group(RG)
     * 4. For each RG, invoke the ConsistencyGroup full copy API (CG uri, clone uri)
     * - a. Skip the CG/RG calls when thrown error and continue with other entries; create 'ERROR' Task for this call
     * - b. Finally return the Task List (RG tasks may finish at different times as they are different calls)
     */
    if (!partial) {
        Volume fullCopy = fullCopyVolumesInRequest.get(0);
        log.info("Full Copy operation requested for entire Application, Considering full copy {} in request.", fullCopy.getLabel());
        fullCopyVolumesInRequest.clear();
        fullCopyVolumesInRequest.addAll(getClonesBySetName(fullCopy.getFullCopySetName(), volumeGroup.getId()));
    } else {
        log.info("Full Copy operation requested for subset of array replication groups in Application.");
    }
    checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
    Map<String, Volume> repGroupToFullCopyMap = groupVolumesByReplicationGroup(fullCopyVolumesInRequest);
    for (Map.Entry<String, Volume> entry : repGroupToFullCopyMap.entrySet()) {
        String replicationGroup = entry.getKey();
        Volume fullCopy = entry.getValue();
        log.info("Processing Array Replication Group {}, Full Copy {}", replicationGroup, fullCopy.getLabel());
        try {
            // get CG URI
            URI cgURI = getConsistencyGroupForFullCopy(fullCopy);
            // Resynchronize the full copy. Note that it will take into account the
            // fact that the volume is in a ReplicationGroup
            // and all volumes in that ReplicationGroup will be resynchronized.
            taskList.getTaskList().addAll(_blockConsistencyGroupService.resynchronizeConsistencyGroupFullCopy(cgURI, fullCopy.getId()).getTaskList());
        } catch (InternalException | APIException e) {
            String errMsg = String.format("Error resynchronizing Array Replication Group %s, Full Copy %s", replicationGroup, fullCopy.getLabel());
            log.error(errMsg, e);
            TaskResourceRep task = BlockServiceUtils.createFailedTaskOnVolume(_dbClient, fullCopy, ResourceOperationTypeEnum.RESYNCHRONIZE_VOLUME_FULL_COPY, e);
            taskList.addTask(task);
        }
    }
    if (!partial) {
        auditOp(OperationTypeEnum.RESYNCHRONIZE_VOLUME_GROUP_FULL_COPY, true, AuditLogManager.AUDITOP_BEGIN, volumeGroup.getId().toString(), fullCopyVolumesInRequest.get(0).getLabel());
    }
    return taskList;
}
Also used : TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) 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