Search in sources :

Example 1 with VolumeGroup

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

the class ControllerUtils method getApplicationForCG.

/**
 * gets the application volume group for this CG and group name if it exists
 *
 * @param dbClient
 *            dbClient to query objects from db
 * @param consistencyGroup
 *            consistency group object
 * @param cgNameOnArray
 *            cg name to check
 * @return a VolumeGroup object or null if this CG and group name are not associated with an application
 */
public static VolumeGroup getApplicationForCG(DbClient dbClient, BlockConsistencyGroup consistencyGroup, String cgNameOnArray) {
    VolumeGroup volumeGroup = null;
    URIQueryResultList uriQueryResultList = new URIQueryResultList();
    dbClient.queryByConstraint(getVolumesByConsistencyGroup(consistencyGroup.getId()), uriQueryResultList);
    Iterator<Volume> volumeIterator = dbClient.queryIterativeObjects(Volume.class, uriQueryResultList);
    while (volumeIterator.hasNext()) {
        Volume volume = volumeIterator.next();
        if (NullColumnValueGetter.isNotNullValue(volume.getReplicationGroupInstance()) && volume.getReplicationGroupInstance().equals(cgNameOnArray)) {
            volumeGroup = volume.getApplication(dbClient);
            if (volumeGroup != null) {
                break;
            }
        }
    }
    return volumeGroup;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 2 with VolumeGroup

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

the class ControllerUtils method getApplicationsForFullCopies.

/**
 * get the list of applications for a list of full copy volumes
 *
 * @param fcVolumeIds full copy volume ids
 * @param dbClient
 * @return
 */
public static List<URI> getApplicationsForFullCopies(List<URI> fcVolumeIds, DbClient dbClient) {
    Set<URI> volumeGroupIds = new HashSet<URI>();
    Iterator<Volume> fcVolumes = dbClient.queryIterativeObjects(Volume.class, fcVolumeIds);
    while (fcVolumes.hasNext()) {
        Volume fcVolume = fcVolumes.next();
        if (!NullColumnValueGetter.isNullURI(fcVolume.getAssociatedSourceVolume())) {
            BlockObject sourceObj = BlockObject.fetch(dbClient, fcVolume.getAssociatedSourceVolume());
            if (sourceObj instanceof Volume) {
                for (String appId : ((Volume) sourceObj).getVolumeGroupIds()) {
                    volumeGroupIds.add(URI.create(appId));
                }
            }
        }
    }
    Iterator<VolumeGroup> volumeGroups = dbClient.queryIterativeObjects(VolumeGroup.class, volumeGroupIds);
    List<URI> applicationIds = new ArrayList<URI>();
    while (volumeGroups.hasNext()) {
        VolumeGroup app = volumeGroups.next();
        if (app.getRoles().contains(VolumeGroup.VolumeGroupRole.COPY.toString())) {
            applicationIds.add(app.getId());
        }
    }
    return applicationIds;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet)

Example 3 with VolumeGroup

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

the class TenantsService method listVolumeGroups.

/**
 * List volume groups the user is authorized to see
 *
 * @param id the URN of a ViPR Tenant/Subtenant
 * @prereq none
 * @brief List volume groups
 * @return List of volume groups
 */
@GET
@Path("/{id}/volume-groups")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VolumeGroupList listVolumeGroups(@PathParam("id") URI id) {
    // tenant id and user permission will get validated in listProjects()
    ProjectList projectList = listProjects(id);
    Set<URI> projects = new HashSet<URI>();
    for (NamedRelatedResourceRep projectRep : projectList.getProjects()) {
        projects.add(projectRep.getId());
    }
    // for each project, get all volumes. Collect volume group ids for all volumes
    StringSet volumeGroups = new StringSet();
    for (URI project : projects) {
        URIQueryResultList list = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(project), list);
        Iterator<Volume> resultsIt = _dbClient.queryIterativeObjects(Volume.class, list);
        while (resultsIt.hasNext()) {
            volumeGroups.addAll(resultsIt.next().getVolumeGroupIds());
        }
    }
    // form Volume Group list response
    VolumeGroupList volumeGroupList = new VolumeGroupList();
    for (String vg : volumeGroups) {
        VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, URI.create(vg));
        volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(volumeGroup));
    }
    return volumeGroupList;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) ProjectList(com.emc.storageos.model.project.ProjectList) StringSet(com.emc.storageos.db.client.model.StringSet) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with VolumeGroup

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

the class RPBlockServiceApiImpl method updateVolumesInVolumeGroup.

/**
 * {@inheritDoc}
 */
@Override
public void updateVolumesInVolumeGroup(VolumeGroupVolumeList addVolumes, List<Volume> removeVolumes, URI applicationId, String taskId) {
    VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, applicationId);
    ApplicationAddVolumeList addVolumeList = null;
    List<URI> removeVolumesURI = null;
    RPController controller = null;
    URI protSystemUri = null;
    Volume firstVolume = null;
    if (addVolumes != null && addVolumes.getVolumes() != null && !addVolumes.getVolumes().isEmpty()) {
        addVolumeList = addVolumesToApplication(addVolumes, volumeGroup);
        List<URI> vols = addVolumeList.getVolumes();
        if (vols != null && !vols.isEmpty()) {
            firstVolume = _dbClient.queryObject(Volume.class, vols.get(0));
        }
    }
    if (removeVolumes != null && !removeVolumes.isEmpty()) {
        removeVolumesURI = getValidVolumesToRemoveFromCG(removeVolumes);
        if (firstVolume == null) {
            firstVolume = removeVolumes.get(0);
        }
    }
    if ((addVolumeList != null && !addVolumeList.getVolumes().isEmpty()) || (removeVolumesURI != null && !removeVolumesURI.isEmpty())) {
        protSystemUri = firstVolume.getProtectionController();
        ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, protSystemUri);
        controller = getController(RPController.class, system.getSystemType());
        controller.updateApplication(protSystemUri, addVolumeList, removeVolumesURI, volumeGroup.getId(), taskId);
    } else {
        // No need to call to controller. update the application task
        Operation op = volumeGroup.getOpStatus().get(taskId);
        op.ready();
        volumeGroup.getOpStatus().updateTaskStatus(taskId, op);
        _dbClient.updateObject(volumeGroup);
    }
}
Also used : ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) RPController(com.emc.storageos.protectioncontroller.RPController) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem)

Example 5 with VolumeGroup

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

the class AbstractBlockServiceApiImpl method prepareSnapshots.

/**
 * Prepares the snapshots for a snapshot request.
 *
 * @param volumes
 *            The volumes for which snapshots are to be created.
 * @param snapshotType
 *            The snapshot technology type.
 * @param snapshotName
 *            The snapshot name.
 * @param snapshotURIs
 *            [OUT] The URIs for the prepared snapshots.
 * @param taskId
 *            The unique task identifier
 *
 * @return The list of snapshots
 */
@Override
public List<BlockSnapshot> prepareSnapshots(List<Volume> volumes, String snapshotType, String snapshotName, List<URI> snapshotURIs, String taskId) {
    List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
    int count = 1;
    for (Volume volume : volumes) {
        // Attempt to create distinct labels here when creating >1 volumes (ScaleIO requirement)
        String rgName = volume.getReplicationGroupInstance();
        VolumeGroup application = volume.getApplication(_dbClient);
        if (volume.isVPlexVolume(_dbClient)) {
            Volume backendVol = VPlexUtil.getVPLEXBackendVolume(volumes.get(0), true, _dbClient);
            if (backendVol != null && !backendVol.getInactive()) {
                rgName = backendVol.getReplicationGroupInstance();
            }
        }
        String label = snapshotName;
        if (NullColumnValueGetter.isNotNullValue(rgName) && application != null) {
            // There can be multiple RGs in a CG, in such cases generate unique name
            if (volumes.size() > 1) {
                label = String.format("%s-%s-%s", snapshotName, rgName, count++);
            } else {
                label = String.format("%s-%s", snapshotName, rgName);
            }
        } else if (volumes.size() > 1) {
            label = String.format("%s-%s", snapshotName, count++);
        }
        BlockSnapshot snapshot = prepareSnapshotFromVolume(volume, snapshotName, label);
        snapshot.setTechnologyType(snapshotType);
        snapshot.setOpStatus(new OpStatusMap());
        Operation op = new Operation();
        op.setResourceType(ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT);
        snapshot.getOpStatus().createTaskStatus(taskId, op);
        snapshotURIs.add(snapshot.getId());
        snapshots.add(snapshot);
    }
    _dbClient.createObject(snapshots);
    return snapshots;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Operation(com.emc.storageos.db.client.model.Operation) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

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