Search in sources :

Example 51 with BlockObject

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

the class VPlexBlockSnapshotSessionApiImpl method validateRelinkSnapshotSessionTargets.

/**
 * {@inheritDoc}
 */
@Override
public void validateRelinkSnapshotSessionTargets(BlockObject snapSessionSourceObj, BlockSnapshotSession tgtSnapSession, Project project, List<URI> snapshotURIs, UriInfo uriInfo) {
    URI sourceURI = snapSessionSourceObj.getId();
    if (URIUtil.isType(sourceURI, Volume.class)) {
        // Get the platform specific implementation for the source side
        // backend storage system and call the validation routine.
        Volume vplexVolume = (Volume) snapSessionSourceObj;
        BlockObject srcSideBackendVolume = VPlexUtil.getVPLEXBackendVolume(vplexVolume, true, _dbClient);
        BlockSnapshotSessionApi snapSessionImpl = getImplementationForBackendSystem(srcSideBackendVolume.getStorageController());
        snapSessionImpl.validateRelinkSnapshotSessionTargets(srcSideBackendVolume, tgtSnapSession, project, snapshotURIs, uriInfo);
        // If the targets to be re-linked are in replication groups, then all targets
        // in the group will be re-linked. So, we need to find all snapshots that will
        // be re-linked. First make sure we only have a single snapshot per replication
        // group so we don't process any twice.
        List<URI> filteredSnapshotURIs = new ArrayList<URI>();
        if (tgtSnapSession.hasConsistencyGroup() && NullColumnValueGetter.isNotNullValue(tgtSnapSession.getReplicationGroupInstance())) {
            filteredSnapshotURIs.addAll(ControllerUtils.ensureOneSnapshotPerReplicationGroup(snapshotURIs, _dbClient));
        } else {
            filteredSnapshotURIs.addAll(snapshotURIs);
        }
        List<BlockSnapshot> allSnapshots = new ArrayList<BlockSnapshot>();
        for (URI snapshotURI : snapshotURIs) {
            BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotURI);
            allSnapshots.addAll(ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient));
        }
        // Since it is possible to expose a VPLEX backend snapshot as a VPLEX volume,
        // it is possible that a linked target being re-linked has been exposed as a
        // VPLEX volume. If that is the case, then what this essentially amounts to
        // is that the linked target is being restored with the data from the target
        // session. As such, the same restrictions for restoring a snapshot session apply
        // here, but not for the snapshot session source objects, and instead for the
        // VPLEX volumes built on top of the linked targets.
        List<Volume> vplexVolumesBuiltOnSnapshots = VPlexUtil.getVPlexVolumesBuiltOnSnapshots(allSnapshots, _dbClient);
        for (Volume vplexVolumesBuiltOnSnapshot : vplexVolumesBuiltOnSnapshots) {
            // Check for pending tasks on the VPLEX source volume.
            checkForPendingTasks(vplexVolumesBuiltOnSnapshot, vplexVolumesBuiltOnSnapshot.getTenant().getURI());
            // Verify no active mirrors on the VPLEX volume.
            verifyActiveMirrors(vplexVolumesBuiltOnSnapshot);
        }
    } else {
        // so should never be called.
        throw APIException.methodNotAllowed.notSupportedForVplexVolumes();
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 52 with BlockObject

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

the class VPlexBlockSnapshotSessionApiImpl method validateUnlinkSnapshotSessionTargets.

/**
 * {@inheritDoc}
 */
@Override
public void validateUnlinkSnapshotSessionTargets(BlockSnapshotSession snapSession, BlockObject snapSessionSourceObj, Project project, Map<URI, Boolean> targetMap, UriInfo uriInfo) {
    URI sourceURI = snapSessionSourceObj.getId();
    if (URIUtil.isType(sourceURI, Volume.class)) {
        // Get the platform specific implementation for the source side
        // backend storage system and call the validation routine.
        Volume vplexVolume = (Volume) snapSessionSourceObj;
        BlockObject srcSideBackendVolume = VPlexUtil.getVPLEXBackendVolume(vplexVolume, true, _dbClient);
        BlockSnapshotSessionApi snapSessionImpl = getImplementationForBackendSystem(srcSideBackendVolume.getStorageController());
        snapSessionImpl.validateUnlinkSnapshotSessionTargets(snapSession, srcSideBackendVolume, project, targetMap, uriInfo);
        // block operations on a non-VPLEX volume.
        for (Entry<URI, Boolean> targetEntry : targetMap.entrySet()) {
            URI snapshotURI = targetEntry.getKey();
            Boolean deleteTarget = targetEntry.getValue();
            if (Boolean.FALSE == deleteTarget) {
                // block operations on a non-VPLEX volume.
                throw APIException.badRequests.mustDeleteTargetsOnUnlinkForVPlex();
            } else {
                // Don't allow if there is a VPLEX volume built on the linked target volume.
                // The VPLEX volume must be deleted first.
                BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotURI);
                String snapshotNativeGuid = snapshot.getNativeGuid();
                List<Volume> volumesWithSameNativeGuid = CustomQueryUtility.getActiveVolumeByNativeGuid(_dbClient, snapshotNativeGuid);
                if (!volumesWithSameNativeGuid.isEmpty()) {
                    // There should only be one and it should be a backend volume for
                    // a VPLEX volume.
                    List<Volume> vplexVolumes = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Volume.class, AlternateIdConstraint.Factory.getVolumeByAssociatedVolumesConstraint(volumesWithSameNativeGuid.get(0).getId().toString()));
                    throw APIException.badRequests.cantDeleteSnapshotExposedByVolume(snapshot.getLabel().toString(), vplexVolumes.get(0).getLabel());
                }
            }
        }
    } else {
        // so should never be called.
        throw APIException.methodNotAllowed.notSupportedForVplexVolumes();
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 53 with BlockObject

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

the class ExportUtils method getItlsForInitiator.

/**
 * Gets the list of exports (ITL) for one initiator. The list contains all the volumes and snapshots
 * that are exported to the initiator together with the target ports and the zones when zoning
 * was performed.
 *
 * @param initiator the initiator
 * @param dbClient an instance of {@link DbClient}
 * @param permissionsHelper an instance of {@link PermissionsHelper}
 * @param user a pointer to the logged in user
 * @return the list of ITLs for one initiator
 */
public static ITLRestRepList getItlsForInitiator(Initiator initiator, DbClient dbClient, PermissionsHelper permissionsHelper, StorageOSUser user) throws DatabaseException {
    ITLRestRepList list = new ITLRestRepList();
    Map<ExportMask, List<ExportGroup>> exportMasks = null;
    exportMasks = getInitiatorExportMasks(initiator, dbClient, permissionsHelper, user);
    BlockObject blockObject = null;
    List<StoragePort> ports = null;
    List<StoragePort> initiatorPorts = null;
    Map<StoragePort, List<FCZoneReference>> zoneRefs = null;
    String hlu = "";
    Map<String, BlockObject> blockObjects = getBlockObjectsForMasks(exportMasks.keySet(), dbClient);
    for (ExportMask exportMask : exportMasks.keySet()) {
        _log.info("Finding ITLs for initiator {} in export mask {}", initiator.getInitiatorPort(), exportMask.getMaskName());
        ports = getStoragePorts(exportMask, dbClient);
        initiatorPorts = getInitiatorPorts(exportMask, initiator, ports, dbClient);
        zoneRefs = getInitiatorsZoneReferences(initiator, initiatorPorts, dbClient);
        for (String doUri : exportMask.getVolumes().keySet()) {
            hlu = exportMask.getVolumes().get(doUri);
            blockObject = blockObjects.get(doUri);
            if (blockObject != null) {
                list.getExportList().addAll(getItlsForMaskInitiator(dbClient, exportMasks.get(exportMask), exportMask, initiator, hlu, blockObject, initiatorPorts, zoneRefs));
            }
        }
    }
    _log.info("{} ITLs were found for initiator {}.", list.getExportList().size(), initiator.getInitiatorPort());
    return list;
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) StoragePort(com.emc.storageos.db.client.model.StoragePort) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 54 with BlockObject

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

the class ExportUtils method getBlockObjectsForMasks.

private static Map<String, BlockObject> getBlockObjectsForMasks(Collection<ExportMask> exportMasks, DbClient dbClient) {
    Map<String, BlockObject> blockObjects = new HashMap<String, BlockObject>();
    List<URI> masksURIs = getMaskVolumeURI(exportMasks);
    List<URI> volUris = new ArrayList<URI>();
    List<URI> snapUris = new ArrayList<URI>();
    for (URI uri : masksURIs) {
        if (URIUtil.isType(uri, BlockSnapshot.class)) {
            snapUris.add(uri);
        } else if (URIUtil.isType(uri, Volume.class)) {
            volUris.add(uri);
        }
    }
    Iterator<Volume> vols = dbClient.queryIterativeObjects(Volume.class, volUris, true);
    while (vols.hasNext()) {
        Volume vol = vols.next();
        blockObjects.put(vol.getId().toString(), vol);
    }
    Iterator<BlockSnapshot> snaps = dbClient.queryIterativeObjects(BlockSnapshot.class, snapUris, true);
    while (snaps.hasNext()) {
        BlockSnapshot snap = snaps.next();
        blockObjects.put(snap.getId().toString(), snap);
    }
    return blockObjects;
}
Also used : HashMap(java.util.HashMap) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 55 with BlockObject

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

the class ExportUtils method getBlockObjectInitiatorTargets.

/**
 * Returns initiators-to-target-storage-ports pairing for all initiators to which
 * the block object (volume or snapshot) was exported.
 *
 * @param id the URN of a ViPR block object
 * @param dbClient dbClient an instance of {@link DbClient}
 * @param idEmbeddedInURL
 * @return initiators-to-target-storage-ports pairing for all initiators to which
 *         the block object (volume or snapshot) was exported.
 */
public static ITLRestRepList getBlockObjectInitiatorTargets(URI id, DbClient dbClient, boolean idEmbeddedInURL) {
    BlockObject blockObject = getBlockObject(id, dbClient);
    ArgValidator.checkEntityNotNull(blockObject, id, idEmbeddedInURL);
    ITLRestRepList list = new ITLRestRepList();
    Map<ExportMask, List<ExportGroup>> exportMasks = getBlockObjectExportMasks(blockObject, dbClient);
    Collection<Initiator> initiators = null;
    List<StoragePort> ports = null;
    List<StoragePort> initiatorPorts = null;
    BlockObject bo = Volume.fetchExportMaskBlockObject(dbClient, blockObject.getId());
    if (bo != null) {
        Map<StoragePort, List<FCZoneReference>> zoneRefs = null;
        for (ExportMask exportMask : exportMasks.keySet()) {
            // now process the initiators - Every initiator must see the volume
            initiators = getInitiators(exportMask, dbClient);
            _log.debug("Found {} initiators in export mask {}", initiators.size(), exportMask.getMaskName());
            ports = getStoragePorts(exportMask, dbClient);
            _log.debug("Found {} storage ports in export mask {}", ports.size(), exportMask.getMaskName());
            String hlu = exportMask.getVolumes().get(bo.getId().toString());
            _log.debug("Start pairing initiators and targets in export mask {}.", exportMask.getMaskName());
            for (Initiator initiator : initiators) {
                initiatorPorts = getInitiatorPorts(exportMask, initiator, ports, dbClient);
                zoneRefs = getInitiatorsZoneReferencesForBlockObject(initiator, initiatorPorts, bo, dbClient);
                list.getExportList().addAll(getItlsForMaskInitiator(dbClient, exportMasks.get(exportMask), exportMask, initiator, hlu, blockObject, initiatorPorts, zoneRefs));
            }
        }
    }
    _log.info("{} ITLs were found for block object {}.", list.getExportList().size(), blockObject.getLabel());
    return list;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) StoragePort(com.emc.storageos.db.client.model.StoragePort) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Aggregations

BlockObject (com.emc.storageos.db.client.model.BlockObject)341 URI (java.net.URI)222 ArrayList (java.util.ArrayList)152 Volume (com.emc.storageos.db.client.model.Volume)141 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)109 NamedURI (com.emc.storageos.db.client.model.NamedURI)82 HashMap (java.util.HashMap)82 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)69 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)65 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)60 ExportMask (com.emc.storageos.db.client.model.ExportMask)56 HashSet (java.util.HashSet)56 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)48 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)45 CIMObjectPath (javax.cim.CIMObjectPath)44 Initiator (com.emc.storageos.db.client.model.Initiator)43 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 List (java.util.List)40 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)38 StringSet (com.emc.storageos.db.client.model.StringSet)36