Search in sources :

Example 31 with BlockObjectRestRep

use of com.emc.storageos.model.block.BlockObjectRestRep in project coprhd-controller by CoprHD.

the class BlockStorageUtils method getBlockResources.

/**
 * Retrieve a list of block resources based on the resource ids provided. This will gather
 * the appropriate resources based on the resource type of the ids provided.
 *
 * @param resourceIds of the resources to retrieve.
 * @param parentId of a continuous copy. This will be null for all other resource types.
 * @return list of block resources
 */
public static List<BlockObjectRestRep> getBlockResources(List<URI> resourceIds, URI parentId) {
    List<BlockObjectRestRep> blockResources = Lists.newArrayList();
    List<URI> blockVolumes = new ArrayList<URI>();
    List<URI> blockSnapshots = new ArrayList<URI>();
    List<URI> blockContinuousCopies = new ArrayList<URI>();
    for (URI resourceId : resourceIds) {
        ResourceType volumeType = ResourceType.fromResourceId(resourceId.toString());
        switch(volumeType) {
            case VOLUME:
                blockVolumes.add(resourceId);
                break;
            case BLOCK_SNAPSHOT:
                blockSnapshots.add(resourceId);
                break;
            case BLOCK_CONTINUOUS_COPY:
                blockContinuousCopies.add(resourceId);
                break;
            default:
                break;
        }
    }
    if (!blockVolumes.isEmpty()) {
        blockResources.addAll(getVolumes(blockVolumes));
    }
    if (!blockSnapshots.isEmpty()) {
        blockResources.addAll(getBlockSnapshots(blockSnapshots));
    }
    if (!blockContinuousCopies.isEmpty()) {
        blockResources.addAll(getBlockContinuousCopies(blockContinuousCopies, parentId));
    }
    return blockResources;
}
Also used : ArrayList(java.util.ArrayList) ResourceType(com.emc.sa.util.ResourceType) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) URI(java.net.URI)

Example 32 with BlockObjectRestRep

use of com.emc.storageos.model.block.BlockObjectRestRep in project coprhd-controller by CoprHD.

the class CreateBlockSnapshotService method checkAndPurgeObsoleteSnapshots.

/**
 * Check retention policy and delete obsolete snapshots if necessary
 *
 * @param volumeOrCgId - volume id or consistency group id
 */
private void checkAndPurgeObsoleteSnapshots(String volumeOrCgId) {
    if (!isRetentionRequired()) {
        return;
    }
    List<RetainedReplica> replicas = findObsoleteReplica(volumeOrCgId);
    for (RetainedReplica replica : replicas) {
        if (replica.getAssociatedReplicaIds() == null || replica.getAssociatedReplicaIds().isEmpty())
            continue;
        for (String obsoleteSnapshotId : replica.getAssociatedReplicaIds()) {
            info("Deactivating snapshot %s since it exceeds max number of snapshots allowed", obsoleteSnapshotId);
            if (ConsistencyUtils.isVolumeStorageType(storageType)) {
                if (BlockProvider.SNAPSHOT_SESSION_TYPE_VALUE.equals(type)) {
                    BlockSnapshotSessionRestRep obsoloteCopy = getClient().blockSnapshotSessions().get(uri(obsoleteSnapshotId));
                    info("Deactivating snapshot session %s", obsoloteCopy.getName());
                    execute(new DeactivateBlockSnapshotSession(uri(obsoleteSnapshotId)));
                } else {
                    BlockObjectRestRep obsoleteCopy = BlockStorageUtils.getVolume(uri(obsoleteSnapshotId));
                    info("Deactivating snapshot %s", obsoleteCopy.getName());
                    execute(new DeactivateBlockSnapshot(uri(obsoleteSnapshotId), VolumeDeleteTypeEnum.FULL));
                }
            } else {
                if (BlockProvider.CG_SNAPSHOT_SESSION_TYPE_VALUE.equals(type)) {
                    BlockSnapshotSessionRestRep obsoloteCopy = getClient().blockSnapshotSessions().get(uri(obsoleteSnapshotId));
                    info("Deactivating snapshot session %s", obsoloteCopy.getName());
                    ConsistencyUtils.removeSnapshotSession(uri(volumeOrCgId), uri(obsoleteSnapshotId));
                } else {
                    BlockObjectRestRep obsoleteCopy = BlockStorageUtils.getVolume(uri(obsoleteSnapshotId));
                    info("Deactivating snapshot %s", obsoleteCopy.getName());
                    ConsistencyUtils.removeSnapshot(uri(volumeOrCgId), uri(obsoleteSnapshotId));
                }
            }
        }
        getModelClient().delete(replica);
    }
}
Also used : BlockSnapshotSessionRestRep(com.emc.storageos.model.block.BlockSnapshotSessionRestRep) DeactivateBlockSnapshotSession(com.emc.sa.service.vipr.block.tasks.DeactivateBlockSnapshotSession) DeactivateBlockSnapshot(com.emc.sa.service.vipr.block.tasks.DeactivateBlockSnapshot) RetainedReplica(com.emc.storageos.db.client.model.uimodels.RetainedReplica) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep)

Example 33 with BlockObjectRestRep

use of com.emc.storageos.model.block.BlockObjectRestRep in project coprhd-controller by CoprHD.

the class CreateBlockSnapshotService method execute.

@Override
public void execute() {
    Tasks<? extends DataObjectRestRep> tasks = null;
    if (ConsistencyUtils.isVolumeStorageType(storageType)) {
        for (BlockObjectRestRep volume : volumes) {
            checkAndPurgeObsoleteSnapshots(volume.getId().toString());
            if (BlockProvider.SNAPSHOT_SESSION_TYPE_VALUE.equals(type)) {
                tasks = execute(new CreateBlockSnapshotSession(volume.getId(), nameParam, linkedSnapshotName, linkedSnapshotCount, linkedSnapshotCopyMode));
            } else {
                tasks = execute(new CreateBlockSnapshot(volume.getId(), type, nameParam, readOnly));
            }
            addAffectedResources(tasks);
            addRetainedReplicas(volume.getId(), tasks.getTasks());
        }
    } else {
        for (String consistencyGroupId : volumeIds) {
            checkAndPurgeObsoleteSnapshots(consistencyGroupId);
            if (BlockProvider.CG_SNAPSHOT_SESSION_TYPE_VALUE.equals(type)) {
                tasks = ConsistencyUtils.createSnapshotSession(uri(consistencyGroupId), nameParam, linkedSnapshotName, linkedSnapshotCount, linkedSnapshotCopyMode);
            } else {
                tasks = ConsistencyUtils.createSnapshot(uri(consistencyGroupId), nameParam, readOnly);
            }
            addAffectedResources(tasks);
            addRetainedReplicas(uri(consistencyGroupId), tasks.getTasks());
        }
    }
}
Also used : CreateBlockSnapshot(com.emc.sa.service.vipr.block.tasks.CreateBlockSnapshot) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) CreateBlockSnapshotSession(com.emc.sa.service.vipr.block.tasks.CreateBlockSnapshotSession)

Example 34 with BlockObjectRestRep

use of com.emc.storageos.model.block.BlockObjectRestRep in project coprhd-controller by CoprHD.

the class CreateBlockVolumeForHostHelper method exportVolumes.

public List<BlockObjectRestRep> exportVolumes(List<URI> volumeIds) {
    List<URI> batchVolumeIds = Lists.newArrayList();
    int batchCount = 0;
    Iterator<URI> ids = volumeIds.iterator();
    while (ids.hasNext()) {
        batchCount++;
        URI id = ids.next();
        batchVolumeIds.add(id);
        if (batchCount == EXPORT_CHUNK_SIZE || !ids.hasNext()) {
            // See if an existing export exists for the host ports
            ExportGroupRestRep export = null;
            if (cluster != null) {
                export = BlockStorageUtils.findExportByCluster(cluster, project, virtualArray, null);
            } else {
                export = BlockStorageUtils.findExportByHost(host, project, virtualArray, null);
            }
            // If did not find export group for the host/cluster, try find existing empty export with
            // host/cluster name
            boolean createExport = export == null;
            boolean isEmptyExport = export != null && BlockStorageUtils.isEmptyExport(export);
            String exportName = cluster != null ? cluster.getLabel() : host.getHostName();
            if (export == null) {
                export = BlockStorageUtils.findExportsByName(exportName, project, virtualArray);
                isEmptyExport = export != null && BlockStorageUtils.isEmptyExport(export);
                createExport = export == null || !isEmptyExport;
                // If there is an existing non-empty export with the same name, append a time stamp to the name to make it unique
                if (export != null && !isEmptyExport) {
                    exportName = exportName + BlockStorageUtils.UNDERSCORE + new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());
                }
            }
            // If the export does not exist or there is a non-empty export with the same name, create a new one
            if (createExport) {
                URI exportId = null;
                if (cluster != null) {
                    exportId = BlockStorageUtils.createClusterExport(project, virtualArray, batchVolumeIds, hlu, cluster, new HashMap<URI, Integer>(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                } else {
                    exportId = BlockStorageUtils.createHostExport(project, virtualArray, batchVolumeIds, hlu, host, new HashMap<URI, Integer>(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                }
                logInfo("create.block.volume.create.export", exportId);
            } else // Add the volume to the existing export
            {
                BlockStorageUtils.addVolumesToExport(batchVolumeIds, hlu, export.getId(), new HashMap<URI, Integer>(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                // If not, add them.
                if (isEmptyExport) {
                    if (cluster != null) {
                        BlockStorageUtils.addClusterToExport(export.getId(), cluster.getId(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                    } else {
                        BlockStorageUtils.addHostToExport(export.getId(), host.getId(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                    }
                }
                logInfo("create.block.volume.update.export", export.getId());
            }
            batchVolumeIds.clear();
            batchCount = 0;
        }
    }
    if (host != null) {
        ExecutionUtils.addAffectedResource(host.getId().toString());
    } else if (cluster != null) {
        ExecutionUtils.addAffectedResource(cluster.getId().toString());
    }
    // The volume is created and exported, clear the rollback steps so it will still be available if any other
    // further steps fail
    ExecutionUtils.clearRollback();
    // Get the volumes after exporting, volumes would not have WWNs until after export in VPLEX
    List<BlockObjectRestRep> volumes = BlockStorageUtils.getBlockResources(volumeIds);
    return volumes;
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) Date(java.util.Date) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) SimpleDateFormat(java.text.SimpleDateFormat)

Example 35 with BlockObjectRestRep

use of com.emc.storageos.model.block.BlockObjectRestRep in project coprhd-controller by CoprHD.

the class BlockStorageUtils method verifyVolumeDependencies.

/**
 * Verify that list of volume doesn't contain any dependencies (snapshot, full copies, continuous copy)
 *
 * @param volumeIds of the volumes to validate dependencies
 */
public static void verifyVolumeDependencies(List<URI> volumeIds, URI projectId) {
    List<URI> allBlockResources = Lists.newArrayList(volumeIds);
    for (URI volumeId : volumeIds) {
        BlockObjectRestRep volume = getVolume(volumeId);
        allBlockResources.addAll(getSrdfTargetVolumes(volume));
        allBlockResources.addAll(getRpTargetVolumes(volume));
    }
    execute(new VerifyVolumeDependencies(allBlockResources, projectId));
}
Also used : URI(java.net.URI) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) VerifyVolumeDependencies(com.emc.sa.service.vipr.block.tasks.VerifyVolumeDependencies)

Aggregations

BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)60 URI (java.net.URI)30 Host (com.emc.storageos.db.client.model.Host)8 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)8 ArrayList (java.util.ArrayList)8 DiskDrive (com.iwave.ext.windows.model.wmi.DiskDrive)7 ExportGroupRestRep (com.emc.storageos.model.block.export.ExportGroupRestRep)5 Datastore (com.vmware.vim25.mo.Datastore)5 Map (java.util.Map)5 ExecutionException (com.emc.sa.engine.ExecutionException)4 DeactivateHost (com.emc.sa.service.vipr.compute.tasks.DeactivateHost)4 DiscoverHost (com.emc.sa.service.vipr.compute.tasks.DiscoverHost)4 GetHost (com.emc.sa.service.vipr.tasks.GetHost)4 AssetOption (com.emc.vipr.model.catalog.AssetOption)4 HashMap (java.util.HashMap)4 HostRestRep (com.emc.storageos.model.host.HostRestRep)3 BlockVirtualPoolRestRep (com.emc.storageos.model.vpool.BlockVirtualPoolRestRep)3 TimeoutException (com.emc.vipr.client.exceptions.TimeoutException)3 ViPRException (com.emc.vipr.client.exceptions.ViPRException)3 Disk (com.iwave.ext.windows.model.Disk)3