Search in sources :

Example 66 with VirtualPool

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

the class AbstractConsistencyGroupService method isSnapshotCreationpermissible.

/**
 * To Check Snapshot creation allowed on ViPR or not
 * @param consistencyGroup consistency grp instance
 * @return
 */
protected boolean isSnapshotCreationpermissible(BlockConsistencyGroup consistencyGroup) {
    String volType = null;
    boolean isPermissible = false;
    ScopedLabelSet tagSet = consistencyGroup.getTag();
    if (tagSet != null) {
        for (ScopedLabel tag : tagSet) {
            if (tag.getScope().equals("volume_types")) {
                volType = tag.getLabel();
                break;
            }
        }
    }
    if (volType != null) {
        VirtualPool vPool = getCinderHelper().getVpool(volType);
        if (vPool.getMaxNativeSnapshots() > 0) {
            isPermissible = true;
        }
    }
    return isPermissible;
}
Also used : ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet)

Example 67 with VirtualPool

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

the class CinderHelpers method getVpool.

/**
 * Get vpool from the given label
 *
 * @prereq none
 *
 * @param vpool_name
 *
 * @brief get vpool
 * @return vpool
 */
public VirtualPool getVpool(String vpoolName) {
    if (vpoolName == null)
        return null;
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(PrefixConstraint.Factory.getLabelPrefixConstraint(VirtualPool.class, vpoolName), uris);
    for (URI vpoolUri : uris) {
        VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolUri);
        if (vpool != null && vpool.getType().equals(VirtualPool.Type.block.name()))
            return vpool;
    }
    // no matching vpool found
    return null;
}
Also used : VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 68 with VirtualPool

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

the class ConsistencyGroupService method createConsistencyGroup.

/**
 * Create Consistency group
 *
 * @param openstackTenantId openstack tenant id
 * @param param pojo class to bind request
 * @param isV1Call cinder V1 api
 * @param header HTTP header
 * @brief Create Consistency group
 * @return Response
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createConsistencyGroup(@PathParam("tenant_id") String openstackTenantId, ConsistencyGroupCreateRequest param, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
    _log.info("Creating Consistency Group : " + param.consistencygroup.name);
    ConsistencyGroupCreateResponse cgResponse = new ConsistencyGroupCreateResponse();
    final Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
    final String volumeTypes = param.consistencygroup.volume_types;
    VirtualPool vPool = getCinderHelper().getVpool(volumeTypes);
    if (null != project && vPool != null) {
        if (!vPool.getMultivolumeConsistency()) {
            _log.error("Bad Request : Multi volume consistency is not enabled in the volume type {}", volumeTypes);
            return CinderApiUtils.createErrorResponse(400, "Bad Request : Multi volume consistency is not enabled");
        }
        // Validate name
        ArgValidator.checkFieldNotEmpty(param.consistencygroup.name, "name");
        checkForDuplicateName(param.consistencygroup.name, BlockConsistencyGroup.class);
        // Validate name not greater than 64 characters
        ArgValidator.checkFieldLengthMaximum(param.consistencygroup.name, CG_MAX_LIMIT, "name");
        // Create Consistency Group in db
        final BlockConsistencyGroup consistencyGroup = new BlockConsistencyGroup();
        consistencyGroup.setId(URIUtil.createId(BlockConsistencyGroup.class));
        consistencyGroup.setLabel(param.consistencygroup.name);
        consistencyGroup.setProject(new NamedURI(project.getId(), project.getLabel()));
        consistencyGroup.setTenant(project.getTenantOrg());
        consistencyGroup.setCreationTime(Calendar.getInstance());
        ScopedLabelSet tagSet = new ScopedLabelSet();
        consistencyGroup.setTag(tagSet);
        tagSet.add(new ScopedLabel("volume_types", volumeTypes));
        tagSet.add(new ScopedLabel("status", "available"));
        tagSet.add(new ScopedLabel("availability_zone", (param.consistencygroup.availability_zone != null) ? param.consistencygroup.availability_zone : "nova"));
        tagSet.add(new ScopedLabel("description", (param.consistencygroup.description != null) ? param.consistencygroup.description : "No Description"));
        tagSet.add(new ScopedLabel(project.getTenantOrg().getURI().toString(), CinderApiUtils.splitString(consistencyGroup.getId().toString(), ":", 3)));
        _dbClient.createObject(consistencyGroup);
        cgResponse.id = CinderApiUtils.splitString(consistencyGroup.getId().toString(), ":", 3);
        cgResponse.name = consistencyGroup.getLabel();
        return CinderApiUtils.getCinderResponse(cgResponse, header, true, CinderConstants.STATUS_OK);
    } else {
        return CinderApiUtils.createErrorResponse(400, "Bad Request : can't create consistency group due to invalid argument");
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) ConsistencyGroupCreateResponse(com.emc.storageos.cinder.model.ConsistencyGroupCreateResponse) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 69 with VirtualPool

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

the class QuotaHelper method populateVolumeTypeDefaultsForQuotaClass.

/*
     * This function populates the quotas map with the vpool default quotas
     * @param qMap - existing quotas hashmap
     * @param openstackTargetTenantId - target tenant for whose vpools we are populating
     * @param vPoolName - if we want to specifically populate a specific pool, we have to pass this.
     * @return updated quotas map
     */
public HashMap<String, String> populateVolumeTypeDefaultsForQuotaClass(HashMap<String, String> qMap, String openstackTargetTenantId, String vPoolName) {
    List<URI> vpools = _dbClient.queryByType(VirtualPool.class, true);
    for (URI vpool : vpools) {
        VirtualPool pool = _dbClient.queryObject(VirtualPool.class, vpool);
        _log.debug("Looking up vpool {}", pool.getLabel());
        if ((vPoolName != null) && (!vPoolName.equals(pool.getLabel().toString()))) {
            continue;
        }
        if (pool != null && pool.getType().equalsIgnoreCase(VirtualPool.Type.block.name())) {
            if (_permissionsHelper.tenantHasUsageACL(URI.create(openstackTargetTenantId), pool)) {
                for (CinderConstants.ResourceQuotaDefaults item : CinderConstants.ResourceQuotaDefaults.class.getEnumConstants()) {
                    if (!qMap.containsKey(item.getResource() + "_" + pool.getLabel())) {
                        qMap.put(item.getResource() + "_" + pool.getLabel(), String.valueOf(CinderConstants.DEFAULT_VOLUME_TYPE_QUOTA));
                    }
                }
            }
        }
    }
    return qMap;
}
Also used : VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) CinderConstants(com.emc.storageos.cinder.CinderConstants)

Example 70 with VirtualPool

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

the class QuotaHelper method getUsageStatistics.

/**
 * Get usage statistics in terms of quota attributes like gigabytes,snapshots, volumes.
 * The details include in_use,reserved,limit.
 *
 * @prereq none
 *
 * @param tenantId
 * @param quotaMap of project and vpools
 * @param proj project under consideration
 *
 * @brief get usage statistics in terms of project and volume types.
 * @return CinderUsage
 */
public CinderUsage getUsageStatistics(URI tenantId, HashMap<String, String> quotaMap, Project proj) {
    CinderUsage objCinderUsage = new CinderUsage();
    List<URI> vpools = _dbClient.queryByType(VirtualPool.class, true);
    for (URI vpool : vpools) {
        VirtualPool pool = _dbClient.queryObject(VirtualPool.class, vpool);
        _log.debug("Looking up vpool {}", pool.getLabel());
        if (pool != null && pool.getType().equalsIgnoreCase(VirtualPool.Type.block.name())) {
            if (_permissionsHelper.tenantHasUsageACL(tenantId, pool)) {
                UsageStats stats = getStorageStats(pool.getId(), proj.getId());
                UsageAndLimits objSpaceUsage = new UsageAndLimits();
                objSpaceUsage.setIn_use(stats.spaceUsed);
                objSpaceUsage.setLimit(Long.parseLong(quotaMap.get("gigabytes" + "_" + pool.getLabel())));
                UsageAndLimits objVolsUsage = new UsageAndLimits();
                objVolsUsage.setIn_use(stats.volumes);
                objVolsUsage.setLimit(Long.parseLong(quotaMap.get("volumes" + "_" + pool.getLabel())));
                UsageAndLimits objSnapsUsage = new UsageAndLimits();
                objSnapsUsage.setIn_use(stats.snapshots);
                objSnapsUsage.setLimit(Long.parseLong(quotaMap.get("snapshots" + "_" + pool.getLabel())));
                objCinderUsage.getQuota_set().put("gigabytes" + "_" + pool.getLabel(), objSpaceUsage);
                objCinderUsage.getQuota_set().put("snapshots" + "_" + pool.getLabel(), objSnapsUsage);
                objCinderUsage.getQuota_set().put("volumes" + "_" + pool.getLabel(), objVolsUsage);
            }
        }
    }
    // now get the usage information for the project
    UsageStats stats = getStorageStats(null, proj.getId());
    UsageAndLimits objSpaceUsage = new UsageAndLimits();
    objSpaceUsage.setIn_use(stats.spaceUsed);
    objSpaceUsage.setLimit(Long.parseLong(quotaMap.get("gigabytes")));
    UsageAndLimits objVolsUsage = new UsageAndLimits();
    objVolsUsage.setIn_use(stats.volumes);
    objVolsUsage.setLimit(Long.parseLong(quotaMap.get("volumes")));
    UsageAndLimits objSnapsUsage = new UsageAndLimits();
    objSnapsUsage.setIn_use(stats.snapshots);
    objSnapsUsage.setLimit(Long.parseLong(quotaMap.get("snapshots")));
    objCinderUsage.getQuota_set().put("gigabytes", objSpaceUsage);
    objCinderUsage.getQuota_set().put("snapshots", objSnapsUsage);
    objCinderUsage.getQuota_set().put("volumes", objVolsUsage);
    return objCinderUsage;
}
Also used : CinderUsage(com.emc.storageos.cinder.model.CinderUsage) UsageAndLimits(com.emc.storageos.cinder.model.UsageAndLimits) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) UsageStats(com.emc.storageos.cinder.model.UsageStats) URI(java.net.URI)

Aggregations

VirtualPool (com.emc.storageos.db.client.model.VirtualPool)339 URI (java.net.URI)189 ArrayList (java.util.ArrayList)122 Volume (com.emc.storageos.db.client.model.Volume)103 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)92 NamedURI (com.emc.storageos.db.client.model.NamedURI)88 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)88 StringSet (com.emc.storageos.db.client.model.StringSet)76 Project (com.emc.storageos.db.client.model.Project)65 StoragePool (com.emc.storageos.db.client.model.StoragePool)57 StringMap (com.emc.storageos.db.client.model.StringMap)53 HashMap (java.util.HashMap)52 Produces (javax.ws.rs.Produces)50 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)45 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)44 List (java.util.List)44 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)42 Path (javax.ws.rs.Path)42 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)37 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)37