Search in sources :

Example 31 with NamedURI

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

the class DefaultBlockSnapshotSessionApiImpl method prepareSnapshotForSession.

/**
 * {@inheritDoc}
 */
@Override
public BlockSnapshot prepareSnapshotForSession(BlockObject sourceObj, String snapsetLabel, String label) {
    BlockSnapshot snapshot = new BlockSnapshot();
    snapshot.setId(URIUtil.createId(BlockSnapshot.class));
    URI cgUri = sourceObj.getConsistencyGroup();
    if (cgUri != null) {
        snapshot.setConsistencyGroup(cgUri);
    }
    snapshot.setSourceNativeId(sourceObj.getNativeId());
    snapshot.setParent(new NamedURI(sourceObj.getId(), sourceObj.getLabel()));
    snapshot.setLabel(label);
    snapshot.setStorageController(sourceObj.getStorageController());
    snapshot.setSystemType(sourceObj.getSystemType());
    snapshot.setVirtualArray(sourceObj.getVirtualArray());
    snapshot.setProtocol(new StringSet());
    snapshot.getProtocol().addAll(sourceObj.getProtocol());
    Project sourceProject = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(sourceObj, _dbClient);
    snapshot.setProject(new NamedURI(sourceProject.getId(), sourceObj.getLabel()));
    snapshot.setSnapsetLabel(ResourceOnlyNameGenerator.removeSpecialCharsForName(snapsetLabel, SmisConstants.MAX_SNAPSHOT_NAME_LENGTH));
    snapshot.setTechnologyType(BlockSnapshot.TechnologyType.NATIVE.name());
    _dbClient.createObject(snapshot);
    return snapshot;
}
Also used : Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 32 with NamedURI

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

the class VPlexBlockSnapshotSessionApiImpl method prepareSnapshotsForSession.

/**
 * {@inheritDoc}
 */
@Override
public List<Map<URI, BlockSnapshot>> prepareSnapshotsForSession(List<BlockObject> sourceObjList, int sourceCount, int newTargetCount, String newTargetsName, boolean inApplication) {
    // The snapshots are generally prepared with information from the
    // source side backend volume, which is the volume being snapped.
    // The passed source object will be a volume, else would not have
    // made it this far.
    List<BlockObject> srcSideBackendVolumes = new ArrayList<>();
    for (BlockObject sourceObj : sourceObjList) {
        srcSideBackendVolumes.add(VPlexUtil.getVPLEXBackendVolume((Volume) sourceObj, true, _dbClient));
    }
    BlockSnapshotSessionApi snapSessionImpl = getImplementationForBackendSystem(srcSideBackendVolumes.get(0).getStorageController());
    List<Map<URI, BlockSnapshot>> snapshotMap = snapSessionImpl.prepareSnapshotsForSession(srcSideBackendVolumes, sourceCount, newTargetCount, newTargetsName, inApplication);
    // However, the project is from the VPLEX volume.
    Project sourceProject = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(sourceObjList.get(0), _dbClient);
    for (Map<URI, BlockSnapshot> snapshots : snapshotMap) {
        for (BlockSnapshot snapshot : snapshots.values()) {
            snapshot.setProject(new NamedURI(sourceProject.getId(), sourceObjList.get(0).getLabel()));
            _dbClient.updateObject(snapshot);
        }
    }
    return snapshotMap;
}
Also used : Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Map(java.util.Map) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 33 with NamedURI

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

the class VPlexBlockSnapshotSessionApiImpl method prepareSnapshotForSession.

/**
 * {@inheritDoc}
 */
@Override
public BlockSnapshot prepareSnapshotForSession(BlockObject sourceObj, String snapsetLabel, String instanceLabel) {
    // The snapshot is generally prepared with information from the
    // source side backend volume, which is the volume being snapped.
    // The passed source object will be a volume, else would not have
    // made it this far.
    Volume srcSideBackendVolume = VPlexUtil.getVPLEXBackendVolume((Volume) sourceObj, true, _dbClient);
    BlockSnapshotSessionApi snapSessionImpl = getImplementationForBackendSystem(srcSideBackendVolume.getStorageController());
    BlockSnapshot snapshot = snapSessionImpl.prepareSnapshotForSession(srcSideBackendVolume, snapsetLabel, instanceLabel);
    // However, the project is from the VPLEX volume.
    Project sourceProject = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(sourceObj, _dbClient);
    snapshot.setProject(new NamedURI(sourceProject.getId(), sourceObj.getLabel()));
    _dbClient.updateObject(snapshot);
    return snapshot;
}
Also used : Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot)

Example 34 with NamedURI

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

the class BlockSnapshotSessionManager method linkTargetVolumesToSnapshotSession.

/**
 * Implements a request to create and link new target volumes to the
 * BlockSnapshotSession instance with the passed URI.
 *
 * @param snapSessionURI The URI of a BlockSnapshotSession instance.
 * @param param The linked target information.
 *
 * @return A TaskResourceRep.
 */
public TaskList linkTargetVolumesToSnapshotSession(URI snapSessionURI, SnapshotSessionLinkTargetsParam param) {
    s_logger.info("START link new targets for snapshot session {}", snapSessionURI);
    // Get the snapshot session.
    BlockSnapshotSession snapSession = BlockSnapshotSessionUtils.querySnapshotSession(snapSessionURI, _uriInfo, _dbClient, true);
    BlockObject snapSessionSourceObj = null;
    List<BlockObject> snapSessionSourceObjs = getAllSnapshotSessionSources(snapSession);
    snapSessionSourceObj = snapSessionSourceObjs.get(0);
    // Get the project for the snapshot session source object.
    Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(snapSessionSourceObj, _dbClient);
    BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
    boolean inApplication = false;
    if (snapSessionSourceObj instanceof Volume && ((Volume) snapSessionSourceObj).getApplication(_dbClient) != null) {
        inApplication = true;
    } else if (snapSessionSourceObj instanceof BlockSnapshot) {
        BlockSnapshot sourceSnap = (BlockSnapshot) snapSessionSourceObj;
        NamedURI namedUri = sourceSnap.getParent();
        if (!NullColumnValueGetter.isNullNamedURI(namedUri)) {
            Volume source = _dbClient.queryObject(Volume.class, namedUri.getURI());
            if (source != null && source.getApplication(_dbClient) != null) {
                inApplication = true;
            }
        }
    }
    // Get the target information.
    int newLinkedTargetsCount = param.getNewLinkedTargets().getCount();
    String newTargetsName = param.getNewLinkedTargets().getTargetName();
    String newTargetsCopyMode = param.getNewLinkedTargets().getCopyMode();
    if (newTargetsCopyMode == null) {
        newTargetsCopyMode = BlockSnapshot.CopyMode.nocopy.name();
    }
    // Validate that the requested new targets can be linked to the snapshot session.
    snapSessionApiImpl.validateLinkNewTargetsRequest(snapSessionSourceObj, project, newLinkedTargetsCount, newTargetsName, newTargetsCopyMode);
    // Prepare the BlockSnapshot instances to represent the new linked targets.
    List<Map<URI, BlockSnapshot>> snapshots = snapSessionApiImpl.prepareSnapshotsForSession(snapSessionSourceObjs, 0, newLinkedTargetsCount, newTargetsName, inApplication);
    // Create a unique task identifier.
    String taskId = UUID.randomUUID().toString();
    TaskList response = new TaskList();
    List<DataObject> preparedObjects = new ArrayList<>();
    // Create a task for the snapshot session.
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.LINK_SNAPSHOT_SESSION_TARGETS);
    _dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
    snapSession.getOpStatus().put(taskId, op);
    response.getTaskList().add(toTask(snapSession, taskId));
    List<List<URI>> snapSessionSnapshotURIs = new ArrayList<>();
    for (Map<URI, BlockSnapshot> snapshotMap : snapshots) {
        // Set Copy Mode
        for (Entry<URI, BlockSnapshot> entry : snapshotMap.entrySet()) {
            entry.getValue().setCopyMode(newTargetsCopyMode);
        }
        preparedObjects.addAll(snapshotMap.values());
        Set<URI> uris = snapshotMap.keySet();
        snapSessionSnapshotURIs.add(Lists.newArrayList(uris));
    }
    // persist copyMode changes
    _dbClient.updateObject(preparedObjects);
    // Create and link new targets to the snapshot session.
    try {
        snapSessionApiImpl.linkNewTargetVolumesToSnapshotSession(snapSessionSourceObj, snapSession, snapSessionSnapshotURIs, newTargetsCopyMode, taskId);
    } catch (Exception e) {
        String errorMsg = format("Failed to link new targets for snapshot session %s: %s", snapSessionURI, e.getMessage());
        ServiceCoded sc = null;
        if (e instanceof ServiceCoded) {
            sc = (ServiceCoded) e;
        } else {
            sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        }
        cleanupFailure(response.getTaskList(), preparedObjects, errorMsg, taskId, sc);
        throw e;
    }
    // Create the audit log entry.
    auditOp(OperationTypeEnum.LINK_SNAPSHOT_SESSION_TARGET, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
    s_logger.info("FINISH link new targets for snapshot session {}", snapSessionURI);
    return response;
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) List(java.util.List) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) BlockObject(com.emc.storageos.db.client.model.BlockObject) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Map(java.util.Map) HashMap(java.util.HashMap)

Example 35 with NamedURI

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

the class RemoteReplicationIngestor method runRemoteReplicationStepsOnTarget.

/**
 * If unmanaged volume is a Target Volume, then 1. Find if source is ingested 2. If yes, then
 * find whether expected targets of this source had been ingested already excluding the current
 * target. 3. If yes, establish links between source and targets. 4. If not,then make sure
 * unmanaged volume hasn't been deleted.
 *
 * @param unManagedVolume
 * @param volume
 * @param unManagedVolumes
 * @param type
 * @return
 */
@SuppressWarnings("deprecation")
private static boolean runRemoteReplicationStepsOnTarget(UnManagedVolume unManagedVolume, Volume volume, List<UnManagedVolume> unManagedVolumes, String type, DbClient dbClient) {
    boolean removeUnManagedVolume = false;
    StringSetMap unManagedVolumeInformation = unManagedVolume.getVolumeInformation();
    String sourceUnManagedVolumeId = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.REMOTE_MIRROR_SOURCE_VOLUME.toString(), unManagedVolumeInformation);
    _logger.info("Type {} Source Native Guid {}", type, sourceUnManagedVolumeId);
    String sourceVolumeId = sourceUnManagedVolumeId.replace(VolumeIngestionUtil.UNMANAGEDVOLUME, VolumeIngestionUtil.VOLUME);
    List<URI> sourceUris = dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeNativeGuidConstraint(sourceVolumeId));
    String copyMode = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.REMOTE_COPY_MODE.toString(), unManagedVolumeInformation);
    String raGroup = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.REMOTE_MIRROR_RDF_GROUP.toString(), unManagedVolumeInformation);
    volume.setSrdfCopyMode(copyMode);
    volume.setSrdfGroup(URI.create(raGroup));
    if (sourceUris.isEmpty()) {
        _logger.info("Source {} Not found for target {}", sourceVolumeId, volume.getId());
    } else {
        // check whether all targets of the source are ingested
        List<URI> sourceUnmanagedUris = dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeInfoNativeIdConstraint(sourceUnManagedVolumeId));
        if (!sourceUnmanagedUris.isEmpty()) {
            UnManagedVolume sourceUnManagedVolume = dbClient.queryObject(UnManagedVolume.class, sourceUnmanagedUris.get(0));
            if (null != sourceUnManagedVolume) {
                StringSet targetUnManagedVolumeGuids = sourceUnManagedVolume.getVolumeInformation().get(SupportedVolumeInformation.REMOTE_MIRRORS.toString());
                if (null != targetUnManagedVolumeGuids && !targetUnManagedVolumeGuids.isEmpty()) {
                    StringSet targetVolumeNativeGuids = VolumeIngestionUtil.getListofVolumeIds(targetUnManagedVolumeGuids);
                    List<URI> targetUris = VolumeIngestionUtil.getVolumeUris(targetVolumeNativeGuids, dbClient);
                    targetUris.add(volume.getId());
                    _logger.info("Expected targets Size {} , found {} ", targetUnManagedVolumeGuids.size(), targetUris.size());
                    _logger.debug("Expected Targets {} : Found {}", Joiner.on("\t").join(targetVolumeNativeGuids), Joiner.on("\t").join(targetUris));
                    List<Volume> modifiedVolumes = new ArrayList<Volume>();
                    if (targetUris.size() == targetUnManagedVolumeGuids.size()) {
                        // if all other targets are ingested, then
                        Volume sourceVolume = dbClient.queryObject(Volume.class, sourceUris.get(0));
                        // check whether the source Volume's VPool is actually having this target Volume's varray
                        // specified as remote
                        VirtualPool sourceVPool = dbClient.queryObject(VirtualPool.class, sourceVolume.getVirtualPool());
                        Map<URI, VpoolRemoteCopyProtectionSettings> settings = sourceVPool.getRemoteProtectionSettings(sourceVPool, dbClient);
                        if (null == settings || settings.size() == 0 || !settings.containsKey(volume.getVirtualArray())) {
                            _logger.info("Target Volume's VArray {} is not matching already ingested source volume virtual pool's remote VArray ", volume.getVirtualArray());
                            return false;
                        }
                        sourceVolume.setSrdfTargets(VolumeIngestionUtil.convertUrisToStrings(targetUris));
                        _logger.info("Clearing internal flag for source volume {} found", sourceVolume.getNativeGuid());
                        sourceVolume.clearInternalFlags(INTERNAL_VOLUME_FLAGS);
                        _logger.debug("Set srdf target for source volume {} found", sourceVolume.getId());
                        modifiedVolumes.add(sourceVolume);
                        // source unmanagedVolume
                        sourceUnManagedVolume.setInactive(true);
                        unManagedVolumes.add(sourceUnManagedVolume);
                        // this target unmanaged volume
                        volume.setSrdfParent(new NamedURI(sourceVolume.getId(), sourceVolume.getLabel()));
                        _logger.debug("target volume  set parent", volume.getId());
                        removeUnManagedVolume = true;
                        // handle other target volumes
                        List<Volume> targetVolumes = dbClient.queryObject(Volume.class, targetUris);
                        for (Volume targetVolume : targetVolumes) {
                            _logger.debug("Set parent for remaining target volume {}", targetVolume.getId());
                            targetVolume.setSrdfParent(new NamedURI(sourceVolume.getId(), sourceVolume.getLabel()));
                            targetVolume.clearInternalFlags(INTERNAL_VOLUME_FLAGS);
                        }
                        modifiedVolumes.addAll(targetVolumes);
                        // target unmanaged volumes
                        List<UnManagedVolume> targetUnManagedVolumes = dbClient.queryObject(UnManagedVolume.class, VolumeIngestionUtil.getUnManagedVolumeUris(targetUnManagedVolumeGuids, dbClient));
                        for (UnManagedVolume targetUnManagedVol : targetUnManagedVolumes) {
                            _logger.debug("Set Target unmanaged volume inactive {}", targetUnManagedVol.getId());
                            targetUnManagedVol.setInactive(true);
                            unManagedVolumes.add(targetUnManagedVol);
                        }
                        dbClient.persistObject(modifiedVolumes);
                        _logger.info("Target Volume successfully ingested with remote replication links", volume.getNativeGuid());
                    } else {
                        // set volume flag to false
                        _logger.info("Expected Targets not found for source Volume {}", sourceUnManagedVolumeId);
                    }
                } else {
                    _logger.info("Targets information not found on source volume {}." + "This could happen when parallel ingests are tried or the actual volume got deleted on array.", sourceUnManagedVolumeId);
                }
            }
        }
    }
    return removeUnManagedVolume;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) NamedURI(com.emc.storageos.db.client.model.NamedURI) ArrayList(java.util.ArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet)

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