Search in sources :

Example 46 with NamedURI

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

the class CinderCloneOperations method createSingleClone.

/*
     * (non-Javadoc)
     * 
     * @see com.emc.storageos.volumecontroller.CloneOperations#createSingleClone(
     * com.emc.storageos.db.client.model.StorageSystem, java.net.URI, java.net.URI,
     * java.lang.Boolean,
     * com.emc.storageos.volumecontroller.TaskCompleter)
     */
@Override
public void createSingleClone(StorageSystem storageSystem, URI sourceObject, URI cloneVolume, Boolean createInactive, TaskCompleter taskCompleter) {
    log.info("START createSingleClone operation");
    boolean isVolumeClone = true;
    try {
        BlockObject sourceObj = BlockObject.fetch(dbClient, sourceObject);
        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();
            isVolumeClone = false;
        } else {
            // This is a default flow
            tenantUri = ((Volume) sourceObj).getTenant().getURI();
            isVolumeClone = true;
        }
        Volume cloneObj = dbClient.queryObject(Volume.class, cloneVolume);
        StoragePool targetPool = dbClient.queryObject(StoragePool.class, cloneObj.getPool());
        TenantOrg tenantOrg = dbClient.queryObject(TenantOrg.class, tenantUri);
        // String cloneLabel = generateLabel(tenantOrg, cloneObj);
        CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storageSystem.getActiveProviderURI(), dbClient);
        log.info("Getting the cinder APi for the provider with id " + storageSystem.getActiveProviderURI());
        CinderApi cinderApi = cinderApiFactory.getApi(storageSystem.getActiveProviderURI(), ep);
        String volumeId = "";
        if (isVolumeClone) {
            volumeId = cinderApi.cloneVolume(cloneObj.getLabel(), (cloneObj.getCapacity() / (1024 * 1024 * 1024)), targetPool.getNativeId(), sourceObj.getNativeId());
        } else {
            volumeId = cinderApi.createVolumeFromSnapshot(cloneObj.getLabel(), (cloneObj.getCapacity() / (1024 * 1024 * 1024)), targetPool.getNativeId(), sourceObj.getNativeId());
        }
        log.debug("Creating volume with the id " + volumeId + " on Openstack cinder node");
        if (volumeId != null) {
            // Cinder volume/snapshot clones are not sync with source, so
            // set the replication state as DETACHED
            cloneObj.setReplicaState(ReplicationState.DETACHED.name());
            dbClient.persistObject(cloneObj);
            Map<String, URI> volumeIds = new HashMap<String, URI>();
            volumeIds.put(volumeId, cloneObj.getId());
            ControllerServiceImpl.enqueueJob(new QueueJob(new CinderSingleVolumeCreateJob(volumeId, cloneObj.getLabel(), storageSystem.getId(), CinderConstants.ComponentType.volume.name(), ep, taskCompleter, targetPool.getId(), volumeIds)));
        }
    } catch (InternalException e) {
        String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, sourceObject, cloneVolume);
        log.error(errorMsg, e);
        taskCompleter.error(dbClient, e);
    } catch (Exception e) {
        String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, sourceObject, cloneVolume);
        log.error(errorMsg, e);
        ServiceError serviceError = DeviceControllerErrors.cinder.operationFailed("createSingleClone", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) NamedURI(com.emc.storageos.db.client.model.NamedURI) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CinderApi(com.emc.storageos.cinder.api.CinderApi) CinderSingleVolumeCreateJob(com.emc.storageos.volumecontroller.impl.cinder.job.CinderSingleVolumeCreateJob) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Volume(com.emc.storageos.db.client.model.Volume) CinderEndPointInfo(com.emc.storageos.cinder.CinderEndPointInfo) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 47 with NamedURI

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

the class ReplicaDeviceController method prepareClone.

private Volume prepareClone(Volume volume, String repGroupName, String cloneSetName) {
    // create clone for the source
    Volume clone = new Volume();
    clone.setId(URIUtil.createId(Volume.class));
    clone.setLabel(volume.getLabel() + "-" + repGroupName);
    clone.setPool(volume.getPool());
    clone.setStorageController(volume.getStorageController());
    clone.setSystemType(volume.getSystemType());
    clone.setProject(new NamedURI(volume.getProject().getURI(), clone.getLabel()));
    clone.setTenant(new NamedURI(volume.getTenant().getURI(), clone.getLabel()));
    clone.setVirtualPool(volume.getVirtualPool());
    clone.setVirtualArray(volume.getVirtualArray());
    clone.setProtocol(new StringSet());
    clone.getProtocol().addAll(volume.getProtocol());
    clone.setThinlyProvisioned(volume.getThinlyProvisioned());
    clone.setOpStatus(new OpStatusMap());
    clone.setAssociatedSourceVolume(volume.getId());
    clone.setReplicationGroupInstance(repGroupName);
    // For clones of new volumes added to Application, get the clone set name and set it
    if (cloneSetName != null) {
        clone.setFullCopySetName(cloneSetName);
    }
    StringSet fullCopies = volume.getFullCopies();
    if (fullCopies == null) {
        fullCopies = new StringSet();
        volume.setFullCopies(fullCopies);
    }
    fullCopies.add(clone.getId().toString());
    _dbClient.createObject(clone);
    _dbClient.updateObject(volume);
    return clone;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) StringSet(com.emc.storageos.db.client.model.StringSet) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap)

Example 48 with NamedURI

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

the class ReplicaDeviceController method prepareSnapshot.

private BlockSnapshot prepareSnapshot(Volume volume, String repGroupName) {
    BlockSnapshot snapshot = new BlockSnapshot();
    snapshot.setId(URIUtil.createId(BlockSnapshot.class));
    URI cgUri = volume.getConsistencyGroup();
    if (cgUri != null) {
        snapshot.setConsistencyGroup(cgUri);
    }
    snapshot.setSourceNativeId(volume.getNativeId());
    snapshot.setParent(new NamedURI(volume.getId(), volume.getLabel()));
    snapshot.setReplicationGroupInstance(repGroupName);
    snapshot.setStorageController(volume.getStorageController());
    snapshot.setSystemType(volume.getSystemType());
    snapshot.setVirtualArray(volume.getVirtualArray());
    snapshot.setProtocol(new StringSet());
    snapshot.getProtocol().addAll(volume.getProtocol());
    NamedURI project = volume.getProject();
    // get the project from VPLEX volume as backend volume have different project set with internal flag.
    if (Volume.checkForVplexBackEndVolume(_dbClient, volume)) {
        Volume vplexVolume = Volume.fetchVplexVolume(_dbClient, volume);
        project = vplexVolume.getProject();
    }
    snapshot.setProject(new NamedURI(project.getURI(), project.getName()));
    String existingSnapSnapSetLabel = ControllerUtils.getSnapSetLabelFromExistingSnaps(repGroupName, volume.getStorageController(), _dbClient);
    if (null == existingSnapSnapSetLabel) {
        log.warn("Not able to find any snapshots with group {}", repGroupName);
        existingSnapSnapSetLabel = repGroupName;
    }
    snapshot.setSnapsetLabel(existingSnapSnapSetLabel);
    Set<String> existingLabels = ControllerUtils.getSnapshotLabelsFromExistingSnaps(repGroupName, volume, _dbClient);
    LabelFormatFactory labelFormatFactory = new LabelFormatFactory();
    LabelFormat labelFormat = labelFormatFactory.getLabelFormat(existingLabels);
    snapshot.setLabel(labelFormat.next());
    snapshot.setTechnologyType(BlockSnapshot.TechnologyType.NATIVE.name());
    _dbClient.createObject(snapshot);
    return snapshot;
}
Also used : LabelFormat(com.emc.storageos.volumecontroller.impl.utils.labels.LabelFormat) NamedURI(com.emc.storageos.db.client.model.NamedURI) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) StringSet(com.emc.storageos.db.client.model.StringSet) LabelFormatFactory(com.emc.storageos.volumecontroller.impl.utils.labels.LabelFormatFactory) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 49 with NamedURI

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

the class ReplicaDeviceController method createMirror.

/**
 * 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 vPoolURI
 * @param recommendedPoolURI Pool that should be used to create the mirror
 * @param volumeLabel
 * @param repGroupName
 * @return BlockMirror (persisted)
 */
private BlockMirror createMirror(Volume volume, URI vPoolURI, URI recommendedPoolURI, String volumeLabel, String repGroupName) {
    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());
    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(vPoolURI);
    createdMirror.setSyncState(SynchronizationState.UNKNOWN.toString());
    createdMirror.setSyncType(BlockMirror.MIRROR_SYNC_TYPE);
    createdMirror.setThinlyProvisioned(volume.getThinlyProvisioned());
    createdMirror.setReplicationGroupInstance(repGroupName);
    _dbClient.createObject(createdMirror);
    addMirrorToVolume(volume, createdMirror);
    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 50 with NamedURI

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

the class StorageScheduler method prepareFullCopyVolumeFromVolume.

private static Volume prepareFullCopyVolumeFromVolume(DbClient dbClient, String name, Volume sourceVolume, VolumeRecommendation recommendation, int volumeCounter, VirtualPoolCapabilityValuesWrapper capabilities, Boolean createInactive) {
    long size = sourceVolume.getCapacity();
    long preAllocateSize = 0;
    if (null != sourceVolume.getThinVolumePreAllocationSize()) {
        preAllocateSize = sourceVolume.getThinVolumePreAllocationSize();
    }
    NamedURI projectUri = sourceVolume.getProject();
    Project project = dbClient.queryObject(Project.class, projectUri);
    URI vArrayUri = sourceVolume.getVirtualArray();
    VirtualArray vArray = dbClient.queryObject(VirtualArray.class, vArrayUri);
    URI vPoolUri = sourceVolume.getVirtualPool();
    VirtualPool vPool = dbClient.queryObject(VirtualPool.class, vPoolUri);
    String label = name + (volumeCounter > 0 ? ("-" + volumeCounter) : "");
    Volume volume = prepareVolume(dbClient, null, size, preAllocateSize, project, vArray, vPool, recommendation, label, null, capabilities, createInactive);
    // Since this is a full copy, update it with URI of the source volume
    volume.setAssociatedSourceVolume(sourceVolume.getId());
    StringSet associatedFullCopies = sourceVolume.getFullCopies();
    if (associatedFullCopies == null) {
        associatedFullCopies = new StringSet();
        sourceVolume.setFullCopies(associatedFullCopies);
    }
    associatedFullCopies.add(volume.getId().toString());
    dbClient.persistObject(volume);
    dbClient.persistObject(sourceVolume);
    addVolumeCapacityToReservedCapacityMap(dbClient, volume);
    return volume;
}
Also used : Project(com.emc.storageos.db.client.model.Project) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) NamedURI(com.emc.storageos.db.client.model.NamedURI) Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

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