Search in sources :

Example 51 with NamedURI

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

the class StorageScheduler method prepareVolume.

/**
 * Prepare Volume for an unprotected traditional block volume.
 *
 * @param volume pre-created volume (optional)
 * @param size volume size
 * @param project project requested
 * @param neighborhood varray requested
 * @param vpool vpool requested
 * @param placement recommendation for placement
 * @param label volume label
 * @param consistencyGroup cg ID
 * @param createInactive
 *
 * @return a persisted volume
 */
public static Volume prepareVolume(DbClient dbClient, Volume volume, long size, long thinVolumePreAllocationSize, Project project, VirtualArray neighborhood, VirtualPool vpool, VolumeRecommendation placement, String label, BlockConsistencyGroup consistencyGroup, VirtualPoolCapabilityValuesWrapper cosCapabilities, Boolean createInactive) {
    // In the case of a new volume that wasn't pre-created, make sure that volume doesn't already exist
    if (volume == null) {
        List<Volume> volumeList = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, Volume.class, ContainmentPrefixConstraint.Factory.getFullMatchConstraint(Volume.class, "project", project.getId(), label));
        if (!volumeList.isEmpty()) {
            throw APIException.badRequests.duplicateLabel(label);
        }
    }
    boolean newVolume = false;
    StoragePool pool = null;
    if (volume == null) {
        newVolume = true;
        volume = new Volume();
        volume.setId(URIUtil.createId(Volume.class));
        volume.setOpStatus(new OpStatusMap());
    } else {
        // Reload volume object from DB
        volume = dbClient.queryObject(Volume.class, volume.getId());
    }
    volume.setSyncActive(!Boolean.valueOf(createInactive));
    volume.setLabel(label);
    volume.setCapacity(size);
    if (0 != thinVolumePreAllocationSize) {
        volume.setThinVolumePreAllocationSize(thinVolumePreAllocationSize);
    }
    volume.setThinlyProvisioned(VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vpool.getSupportedProvisioningType()));
    volume.setVirtualPool(vpool.getId());
    volume.setProject(new NamedURI(project.getId(), volume.getLabel()));
    volume.setTenant(new NamedURI(project.getTenantOrg().getURI(), volume.getLabel()));
    volume.setVirtualArray(neighborhood.getId());
    URI poolId = placement.getCandidatePools().get(0);
    if (null != poolId) {
        pool = dbClient.queryObject(StoragePool.class, poolId);
        if (null != pool) {
            volume.setProtocol(new StringSet());
            volume.getProtocol().addAll(VirtualPoolUtil.getMatchingProtocols(vpool.getProtocols(), pool.getProtocols()));
        }
    }
    URI storageControllerUri = placement.getCandidateSystems().get(0);
    StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, storageControllerUri);
    String systemType = storageSystem.checkIfVmax3() ? DiscoveredDataObject.Type.vmax3.name() : storageSystem.getSystemType();
    volume.setSystemType(systemType);
    volume.setStorageController(storageControllerUri);
    volume.setPool(poolId);
    if (consistencyGroup != null) {
        volume.setConsistencyGroup(consistencyGroup.getId());
        if (!consistencyGroup.isProtectedCG()) {
            String rgName = consistencyGroup.getCgNameOnStorageSystem(volume.getStorageController());
            if (rgName == null) {
                // for new CG
                rgName = consistencyGroup.getLabel();
            } else {
                // if other volumes in the same CG are in an application, add this volume to the same application
                VolumeGroup volumeGroup = ControllerUtils.getApplicationForCG(dbClient, consistencyGroup, rgName);
                if (volumeGroup != null) {
                    volume.getVolumeGroupIds().add(volumeGroup.getId().toString());
                }
            }
            volume.setReplicationGroupInstance(rgName);
        }
    }
    if (null != cosCapabilities.getAutoTierPolicyName()) {
        URI autoTierPolicyUri = getAutoTierPolicy(poolId, cosCapabilities.getAutoTierPolicyName(), dbClient);
        if (null != autoTierPolicyUri) {
            volume.setAutoTieringPolicyUri(autoTierPolicyUri);
        }
    }
    if (vpool.getDedupCapable() != null) {
        volume.setIsDeduplicated(vpool.getDedupCapable());
    }
    if (newVolume) {
        dbClient.createObject(volume);
    } else {
        dbClient.updateAndReindexObject(volume);
    }
    return volume;
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 52 with NamedURI

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

the class StorageScheduler method initializeMirror.

/**
 * Adds a BlockMirror structure for a Volume. It also calls addMirrorToVolume to
 * link the mirror into the volume's mirror set.
 *
 * @param volume Volume
 * @param vPool
 * @param recommendedPoolURI Pool that should be used to create the mirror
 * @param volumeLabel
 * @param dbClient
 * @return BlockMirror (persisted)
 */
public static BlockMirror initializeMirror(Volume volume, VirtualPool vPool, URI recommendedPoolURI, String volumeLabel, DbClient dbClient) {
    BlockMirror createdMirror = new BlockMirror();
    createdMirror.setSource(new NamedURI(volume.getId(), volume.getLabel()));
    createdMirror.setId(URIUtil.createId(BlockMirror.class));
    URI cgUri = volume.getConsistencyGroup();
    if (!NullColumnValueGetter.isNullURI(cgUri)) {
        createdMirror.setConsistencyGroup(cgUri);
    }
    createdMirror.setLabel(volumeLabel);
    createdMirror.setStorageController(volume.getStorageController());
    createdMirror.setSystemType(volume.getSystemType());
    createdMirror.setVirtualArray(volume.getVirtualArray());
    // Hence for timebeing, we are setting the source policy in mirror.
    if (!NullColumnValueGetter.isNullURI(volume.getAutoTieringPolicyUri())) {
        createdMirror.setAutoTieringPolicyUri(volume.getAutoTieringPolicyUri());
    }
    createdMirror.setProtocol(new StringSet());
    createdMirror.getProtocol().addAll(volume.getProtocol());
    createdMirror.setCapacity(volume.getCapacity());
    createdMirror.setProject(new NamedURI(volume.getProject().getURI(), createdMirror.getLabel()));
    createdMirror.setTenant(new NamedURI(volume.getTenant().getURI(), createdMirror.getLabel()));
    createdMirror.setPool(recommendedPoolURI);
    createdMirror.setVirtualPool(vPool.getId());
    createdMirror.setSyncState(SynchronizationState.UNKNOWN.toString());
    createdMirror.setSyncType(BlockMirror.MIRROR_SYNC_TYPE);
    createdMirror.setThinlyProvisioned(volume.getThinlyProvisioned());
    dbClient.createObject(createdMirror);
    addMirrorToVolume(volume, createdMirror, dbClient);
    return createdMirror;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) NamedURI(com.emc.storageos.db.client.model.NamedURI) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 53 with NamedURI

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

the class StorageScheduler method prepareEmptyVolume.

/**
 * Prepare a new volume object in the database that can be tracked and overridden as the volume goes through the
 * placement process.
 *
 * @param dbClient dbclient
 * @param size size of volume
 * @param project project
 * @param varray virtual array
 * @param vpool virtual pool
 * @param label base volume label
 * @param volNumber a temporary label for this volume to mark which one it is
 * @param volumesRequested how many volumes were requested overall
 * @return a Volume object
 */
public static Volume prepareEmptyVolume(DbClient dbClient, long size, Project project, VirtualArray varray, VirtualPool vpool, String label, int volNumber, int volumesRequested) {
    Volume volume = new Volume();
    volume.setId(URIUtil.createId(Volume.class));
    String volumeLabel = AbstractBlockServiceApiImpl.generateDefaultVolumeLabel(label, volNumber, volumesRequested);
    List<Volume> volumeList = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, Volume.class, ContainmentPrefixConstraint.Factory.getFullMatchConstraint(Volume.class, "project", project.getId(), volumeLabel));
    if (!volumeList.isEmpty()) {
        throw APIException.badRequests.duplicateLabel(volumeLabel);
    }
    volume.setLabel(volumeLabel);
    volume.setCapacity(size);
    volume.setThinlyProvisioned(VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vpool.getSupportedProvisioningType()));
    volume.setVirtualPool(vpool.getId());
    volume.setProject(new NamedURI(project.getId(), volume.getLabel()));
    volume.setTenant(new NamedURI(project.getTenantOrg().getURI(), volume.getLabel()));
    volume.setVirtualArray(varray.getId());
    volume.setOpStatus(new OpStatusMap());
    if (vpool.getDedupCapable() != null) {
        volume.setIsDeduplicated(vpool.getDedupCapable());
    }
    dbClient.createObject(volume);
    return volume;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap)

Example 54 with NamedURI

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

the class BlockMapper method map.

/**
 * Maps a BlockSnapshotSession instance to its Rest representation.
 *
 * @param dbClient A reference to a database client.
 * @param from An instance of BlockSnapshotSession.
 *
 * @return An instance of BlockSnapshotSessionRestRep
 */
public static BlockSnapshotSessionRestRep map(DbClient dbClient, BlockSnapshotSession from) {
    if (from == null) {
        return null;
    }
    BlockSnapshotSessionRestRep to = new BlockSnapshotSessionRestRep();
    // Map base class fields.
    mapDataObjectFields(from, to);
    // Map snapshot session consistency group.
    URI consistencyGroup = from.getConsistencyGroup();
    if (consistencyGroup != null) {
        to.setConsistencyGroup(toRelatedResource(ResourceTypeEnum.BLOCK_CONSISTENCY_GROUP, consistencyGroup));
    }
    // Map snapshot session parent i.e., the snapshot session source.
    NamedURI parentNamedURI = from.getParent();
    if (parentNamedURI != null) {
        URI parentURI = parentNamedURI.getURI();
        // It may be possible that the source for the snapshot
        // session is a backend source volume for a VPLEX volume
        // if we support creating snapshot sessions for VPLEX
        // volumes backed by storage that supports snapshot sessions.
        // In this case, the parent we want to reflect in the response
        // is the VPLEX volume.
        URIQueryResultList results = new URIQueryResultList();
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeByAssociatedVolumesConstraint(parentURI.toString()), results);
        Iterator<URI> resultsIter = results.iterator();
        if (resultsIter.hasNext()) {
            parentURI = resultsIter.next();
        }
        // volume for an array snapshot, which is a BlockSnapshot.
        if (URIUtil.isType(parentURI, Volume.class)) {
            to.setParent(toRelatedResource(ResourceTypeEnum.VOLUME, parentURI));
        } else {
            to.setParent(toRelatedResource(ResourceTypeEnum.BLOCK_SNAPSHOT, parentURI));
        }
    }
    // Map project
    NamedURI projectURI = from.getProject();
    if (projectURI != null) {
        to.setProject(toRelatedResource(ResourceTypeEnum.PROJECT, projectURI.getURI()));
    }
    // Map storage controller
    URI storageURI = from.getStorageController();
    if (storageURI != null) {
        to.setStorageController(storageURI);
    }
    // Map linked targets.
    StringSet linkedTargetIds = from.getLinkedTargets();
    if ((linkedTargetIds != null) && (!linkedTargetIds.isEmpty())) {
        List<RelatedResourceRep> linkedTargetReps = new ArrayList<RelatedResourceRep>();
        for (String linkedTargetId : linkedTargetIds) {
            URI linkedTargetURI = URI.create(linkedTargetId);
            // Linked targets are instances of BlockSnapshot.
            linkedTargetReps.add(toRelatedResource(ResourceTypeEnum.BLOCK_SNAPSHOT, linkedTargetURI));
        }
        to.setLinkedTargets(linkedTargetReps);
    }
    // Map session label.
    to.setSessionLabel(from.getSessionLabel());
    // Map replication group name.
    to.setReplicationGroupInstance(from.getReplicationGroupInstance());
    // Map session set name.
    to.setSessionSetName(from.getSessionSetName());
    return to;
}
Also used : BlockSnapshotSessionRestRep(com.emc.storageos.model.block.BlockSnapshotSessionRestRep) RelatedResourceRep(com.emc.storageos.model.RelatedResourceRep) VirtualArrayRelatedResourceRep(com.emc.storageos.model.VirtualArrayRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 55 with NamedURI

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

the class XIVCloneOperations method createSingleClone.

@SuppressWarnings("rawtypes")
@Override
public void createSingleClone(StorageSystem storageSystem, URI sourceVolume, URI cloneVolume, Boolean createInactive, TaskCompleter taskCompleter) {
    _log.info("START createSingleClone operation");
    SmisException serviceCode = null;
    CIMArgument[] outArgs = new CIMArgument[5];
    try {
        BlockObject sourceObj = BlockObject.fetch(_dbClient, sourceVolume);
        URI tenantUri = null;
        if (sourceObj instanceof BlockSnapshot) {
            // In case of snapshot, get the tenant from its parent volume
            NamedURI parentVolUri = ((BlockSnapshot) sourceObj).getParent();
            Volume parentVolume = _dbClient.queryObject(Volume.class, parentVolUri);
            tenantUri = parentVolume.getTenant().getURI();
        } else {
            tenantUri = ((Volume) sourceObj).getTenant().getURI();
        }
        Volume cloneObj = _dbClient.queryObject(Volume.class, cloneVolume);
        StoragePool targetPool = _dbClient.queryObject(StoragePool.class, cloneObj.getPool());
        TenantOrg tenantOrg = _dbClient.queryObject(TenantOrg.class, tenantUri);
        String cloneLabel = _nameGenerator.generate(tenantOrg.getLabel(), cloneObj.getLabel(), cloneObj.getId().toString(), '-', SmisConstants.MAX_VOLUME_NAME_LENGTH);
        CIMObjectPath sourceVolumePath = _cimPath.getBlockObjectPath(storageSystem, sourceObj);
        CIMArgument[] inArgs = _helper.getCloneInputArguments(cloneLabel, sourceVolumePath, storageSystem, targetPool, createInactive);
        _helper.callReplicationSvc(storageSystem, SmisConstants.CREATE_ELEMENT_REPLICA, inArgs, outArgs);
    } catch (Exception e) {
        String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, sourceVolume, cloneVolume);
        _log.error(errorMsg, e);
        serviceCode = DeviceControllerExceptions.smis.createFullCopyFailure(errorMsg, e);
    } finally {
        try {
            // update clone and pool
            // clone will be set to inactive if no return from provider
            _smisStorageDevicePostProcessor.processCloneCreation(storageSystem, cloneVolume, outArgs, (CloneCreateCompleter) taskCompleter);
        } catch (Exception e) {
            String errorMsg = "Exception on creating clone of " + sourceVolume;
            _log.error(errorMsg, e);
            // set serviceCode only if no previous exception
            if (serviceCode == null) {
                serviceCode = DeviceControllerExceptions.smis.createFullCopyFailure(errorMsg, e);
            }
        }
        if (serviceCode != null) {
            taskCompleter.error(_dbClient, serviceCode);
            throw serviceCode;
        }
    }
}
Also used : SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) StoragePool(com.emc.storageos.db.client.model.StoragePool) NamedURI(com.emc.storageos.db.client.model.NamedURI) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CIMObjectPath(javax.cim.CIMObjectPath) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) Volume(com.emc.storageos.db.client.model.Volume) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) BlockObject(com.emc.storageos.db.client.model.BlockObject) CIMArgument(javax.cim.CIMArgument)

Aggregations

NamedURI (com.emc.storageos.db.client.model.NamedURI)196 URI (java.net.URI)98 Volume (com.emc.storageos.db.client.model.Volume)74 StringSet (com.emc.storageos.db.client.model.StringSet)65 Project (com.emc.storageos.db.client.model.Project)54 ArrayList (java.util.ArrayList)46 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)43 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)42 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)36 Test (org.junit.Test)32 StoragePool (com.emc.storageos.db.client.model.StoragePool)31 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)31 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)27 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)26 StringMap (com.emc.storageos.db.client.model.StringMap)26 List (java.util.List)23 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)20 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)20 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)18 FileShare (com.emc.storageos.db.client.model.FileShare)17