Search in sources :

Example 16 with UnManagedVolume

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

the class IngestExportStrategy method ingestExportMasks.

/**
 * After volume object gets created successfully locally, now start
 * running ingest associated masks of the volume
 */
public <T extends BlockObject> T ingestExportMasks(UnManagedVolume unManagedVolume, T blockObject, IngestionRequestContext requestContext) throws IngestionException {
    _logger.info("ingesting export masks for requestContext " + requestContext.getCurrentUnmanagedVolume());
    if (null != requestContext.getExportGroup()) {
        if (null != unManagedVolume.getUnmanagedExportMasks() && !unManagedVolume.getUnmanagedExportMasks().isEmpty()) {
            List<URI> unManagedMaskUris = new ArrayList<URI>(Collections2.transform(unManagedVolume.getUnmanagedExportMasks(), CommonTransformerFunctions.FCTN_STRING_TO_URI));
            List<UnManagedExportMask> unManagedMasks = _dbClient.queryObject(UnManagedExportMask.class, unManagedMaskUris);
            int originalSize = unManagedMasks.size();
            MutableInt masksIngestedCount = new MutableInt(0);
            // Ingest Associated Masks
            ingestExportOrchestrator.ingestExportMasks(requestContext, unManagedVolume, blockObject, unManagedMasks, masksIngestedCount);
            _logger.info("{} of {} unmanaged export masks were ingested", masksIngestedCount, originalSize);
            List<String> errorMessages = requestContext.getErrorMessagesForVolume(unManagedVolume.getNativeGuid());
            // If the internal flags are set, return the block object
            if (blockObject.checkInternalFlags(Flag.PARTIALLY_INGESTED)) {
                _logger.info("block object {} is partially ingested", blockObject.forDisplay());
                // check if none of the export masks are ingested
                if (masksIngestedCount.intValue() == 0) {
                    if (null != errorMessages && !errorMessages.isEmpty()) {
                        throw IngestionException.exceptions.unmanagedVolumeMasksNotIngestedAdditionalInfo(unManagedVolume.getLabel(), Joiner.on(", ").join(errorMessages));
                    } else {
                        throw IngestionException.exceptions.unmanagedVolumeMasksNotIngested(unManagedVolume.getLabel());
                    }
                } else {
                    // If the unmanaged volume is not marked for deletion, then it should be updated with the changes done.
                    requestContext.addDataObjectToUpdate(unManagedVolume, unManagedVolume);
                    _logger.info("all export masks of unmanaged volume {} have been ingested, " + "but the volume is still marked as partially ingested, returning block object {}", unManagedVolume.forDisplay(), blockObject.forDisplay());
                    return blockObject;
                }
            }
            if (unManagedVolume.getUnmanagedExportMasks().size() != originalSize) {
                // delete this volume only if the masks are ingested.
                if (VolumeIngestionUtil.canDeleteUnManagedVolume(unManagedVolume)) {
                    _logger.info("Marking UnManaged Volume {} inactive as it doesn't have any associated unmanaged export masks ", unManagedVolume.getNativeGuid());
                    boolean isRPVolume = VolumeIngestionUtil.checkUnManagedResourceIsRecoverPointEnabled(unManagedVolume);
                    // if its RP volume and non RP exported, then check whether the RP CG is fully ingested
                    if (isRPVolume && VolumeIngestionUtil.checkUnManagedResourceIsNonRPExported(unManagedVolume)) {
                        _logger.info("unmanaged volume {} is both RecoverPoint protected and exported to another Host or Cluster", unManagedVolume.forDisplay());
                        Set<DataObject> updateObjects = requestContext.getDataObjectsToBeUpdatedMap().get(unManagedVolume.getNativeGuid());
                        if (updateObjects == null) {
                            updateObjects = new HashSet<DataObject>();
                            requestContext.getDataObjectsToBeUpdatedMap().put(unManagedVolume.getNativeGuid(), updateObjects);
                        }
                        List<UnManagedVolume> ingestedUnManagedVolumes = requestContext.findAllUnManagedVolumesToBeDeleted();
                        ingestedUnManagedVolumes.add(unManagedVolume);
                        UnManagedProtectionSet umpset = VolumeIngestionUtil.getUnManagedProtectionSetForUnManagedVolume(requestContext, unManagedVolume, _dbClient);
                        // unmanaged volume has already been ingested. In this case, try to get it from the managed volume
                        if (umpset == null) {
                            umpset = VolumeIngestionUtil.getUnManagedProtectionSetForManagedVolume(requestContext, blockObject, _dbClient);
                        }
                        // If fully ingested, then setup the RP CG too.
                        if (VolumeIngestionUtil.validateAllVolumesInCGIngested(ingestedUnManagedVolumes, umpset, requestContext, _dbClient)) {
                            VolumeIngestionUtil.validateRPVolumesAlignWithIngestVpool(requestContext, umpset, _dbClient);
                            VolumeIngestionUtil.setupRPCG(requestContext, umpset, unManagedVolume, updateObjects, _dbClient);
                        } else {
                            // else mark the volume as internal. This will be marked visible when the RP CG is ingested
                            blockObject.addInternalFlags(BlockRecoverPointIngestOrchestrator.INTERNAL_VOLUME_FLAGS);
                        }
                    }
                    unManagedVolume.setInactive(true);
                    requestContext.getUnManagedVolumesToBeDeleted().add(unManagedVolume);
                } else {
                    // If the unmanaged volume is not marked for deletion, then it should be updated with the changes done.
                    requestContext.addDataObjectToUpdate(unManagedVolume, unManagedVolume);
                }
                return blockObject;
            } else {
                if (null != errorMessages && !errorMessages.isEmpty()) {
                    Collections.sort(errorMessages);
                    throw IngestionException.exceptions.unmanagedVolumeMasksNotIngestedAdditionalInfo(unManagedVolume.getLabel(), "\n\n" + Joiner.on("\n\n").join(errorMessages));
                } else {
                    throw IngestionException.exceptions.unmanagedVolumeMasksNotIngested(unManagedVolume.getLabel());
                }
            }
        }
    }
    return blockObject;
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) DataObject(com.emc.storageos.db.client.model.DataObject) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) MutableInt(org.apache.commons.lang.mutable.MutableInt) UnManagedExportMask(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedExportMask)

Example 17 with UnManagedVolume

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

the class IngestVolumesExportedSchedulingThread method run.

@Override
public void run() {
    try {
        _requestContext.reset();
        URI varrayId = null;
        while (_requestContext.hasNext()) {
            UnManagedVolume unManagedVolume = _requestContext.next();
            _logger.info("Ingestion starting for exported unmanaged volume {}", unManagedVolume.getNativeGuid());
            if (null == varrayId) {
                varrayId = _requestContext.getVarray(unManagedVolume).getId();
            }
            TaskResourceRep resourceRep = _taskMap.get(unManagedVolume.getId().toString());
            String taskId = resourceRep != null ? resourceRep.getOpId() : null;
            try {
                URI storageSystemUri = unManagedVolume.getStorageSystemUri();
                StorageSystem system = _requestContext.getStorageSystemCache().get(storageSystemUri.toString());
                if (null == system) {
                    system = _dbClient.queryObject(StorageSystem.class, storageSystemUri);
                    _requestContext.getStorageSystemCache().put(storageSystemUri.toString(), system);
                }
                // Build the Strategy , which contains reference to Block object & export orchestrators
                IngestStrategy ingestStrategy = _ingestStrategyFactory.buildIngestStrategy(unManagedVolume, !IngestStrategyFactory.DISREGARD_PROTECTION);
                @SuppressWarnings("unchecked") BlockObject blockObject = ingestStrategy.ingestBlockObjects(_requestContext, VolumeIngestionUtil.getBlockObjectClass(unManagedVolume));
                if (null == blockObject) {
                    throw IngestionException.exceptions.generalVolumeException(unManagedVolume.getLabel(), "check the logs for more details");
                }
                _requestContext.getBlockObjectsToBeCreatedMap().put(blockObject.getNativeGuid(), blockObject);
                _requestContext.getProcessedUnManagedVolumeMap().put(unManagedVolume.getNativeGuid(), _requestContext.getVolumeContext());
                _logger.info("Volume ingestion completed successfully for exported unmanaged volume {} (export ingestion will follow)", unManagedVolume.getNativeGuid());
            } catch (APIException ex) {
                _logger.error("error: " + ex.getLocalizedMessage(), ex);
                _dbClient.error(UnManagedVolume.class, _requestContext.getCurrentUnManagedVolumeUri(), taskId, ex);
                _requestContext.getVolumeContext().rollback();
            } catch (Exception ex) {
                _logger.error("error: " + ex.getLocalizedMessage(), ex);
                _dbClient.error(UnManagedVolume.class, _requestContext.getCurrentUnManagedVolumeUri(), taskId, IngestionException.exceptions.generalVolumeException(unManagedVolume.getLabel(), ex.getLocalizedMessage()));
                _requestContext.getVolumeContext().rollback();
            }
        }
        _logger.info("Ingestion of all the unmanaged volumes has completed.");
        // next ingest the export masks for the unmanaged volumes which have been fully ingested
        _logger.info("Ingestion of unmanaged export masks for all requested volumes starting.");
        ingestBlockExportMasks(_requestContext, _taskMap);
        for (VolumeIngestionContext volumeContext : _requestContext.getProcessedUnManagedVolumeMap().values()) {
            // If there is a CG involved in the ingestion, organize, pollenate, and commit.
            _unManagedVolumeService.commitIngestedCG(_requestContext, volumeContext.getUnmanagedVolume());
            // commit the volume itself
            volumeContext.commit();
        }
        for (BlockObject bo : _requestContext.getObjectsIngestedByExportProcessing()) {
            _logger.info("Ingestion Wrap Up: Creating BlockObject {} (hash {})", bo.forDisplay(), bo.hashCode());
            _dbClient.createObject(bo);
        }
        for (UnManagedVolume umv : _requestContext.getUnManagedVolumesToBeDeleted()) {
            _logger.info("Ingestion Wrap Up: Deleting UnManagedVolume {} (hash {})", umv.forDisplay(), umv.hashCode());
            _dbClient.updateObject(umv);
        }
        // Update the related objects if any after successful export mask ingestion
        for (Entry<String, Set<DataObject>> updatedObjectsEntry : _requestContext.getDataObjectsToBeUpdatedMap().entrySet()) {
            if (updatedObjectsEntry != null) {
                _logger.info("Ingestion Wrap Up: Updating objects for UnManagedVolume URI " + updatedObjectsEntry.getKey());
                for (DataObject dob : updatedObjectsEntry.getValue()) {
                    if (dob.getInactive()) {
                        _logger.info("Ingestion Wrap Up: Deleting DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
                    } else {
                        _logger.info("Ingestion Wrap Up: Updating DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
                    }
                    _dbClient.updateObject(dob);
                }
            }
        }
        // Create the related objects if any after successful export mask ingestion
        for (Set<DataObject> createdObjects : _requestContext.getDataObjectsToBeCreatedMap().values()) {
            if (createdObjects != null && !createdObjects.isEmpty()) {
                for (DataObject dob : createdObjects) {
                    _logger.info("Ingestion Wrap Up: Creating DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
                    _dbClient.createObject(dob);
                }
            }
        }
        ExportGroup exportGroup = _requestContext.getExportGroup();
        if (_requestContext.isExportGroupCreated()) {
            _logger.info("Ingestion Wrap Up: Creating ExportGroup {} (hash {})", exportGroup.forDisplay(), exportGroup.hashCode());
            _dbClient.createObject(exportGroup);
        } else {
            _logger.info("Ingestion Wrap Up: Updating ExportGroup {} (hash {})", exportGroup.forDisplay(), exportGroup.hashCode());
            _dbClient.updateObject(exportGroup);
        }
        // record the events after they have been persisted
        for (BlockObject volume : _requestContext.getObjectsIngestedByExportProcessing()) {
            _unManagedVolumeService.recordVolumeOperation(_dbClient, _unManagedVolumeService.getOpByBlockObjectType(volume), Status.ready, volume.getId());
        }
    } catch (InternalException e) {
        _logger.error("InternalException occurred due to: {}", e);
        throw e;
    } catch (Exception e) {
        _logger.error("Unexpected exception occurred due to: {}", e);
        throw APIException.internalServerErrors.genericApisvcError(ExceptionUtils.getExceptionMessage(e), e);
    } finally {
        // it, then we should clean it up in the database (CTRL-8520)
        if ((null != _requestContext) && _requestContext.isExportGroupCreated() && _requestContext.getObjectsIngestedByExportProcessing().isEmpty()) {
            _logger.info("Ingestion Wrap Up: an export group was created, but no volumes were ingested into it");
            if (_requestContext.getExportGroup().getVolumes() == null || _requestContext.getExportGroup().getVolumes().isEmpty()) {
                _logger.info("Ingestion Wrap Up: since no volumes are present, marking {} for deletion", _requestContext.getExportGroup().getLabel());
                _dbClient.markForDeletion(_requestContext.getExportGroup());
            }
        }
    }
}
Also used : Set(java.util.Set) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DataObject(com.emc.storageos.db.client.model.DataObject) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) VolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 18 with UnManagedVolume

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

the class IngestVolumesExportedSchedulingThread method ingestBlockExportMasks.

/**
 * Ingest block export masks for the already-ingested Volumes.
 *
 * @param requestContext the IngestionRequestContext
 * @param taskMap a Map of UnManagedVolume ids to TaskResourceReps
 */
private void ingestBlockExportMasks(IngestionRequestContext requestContext, Map<String, TaskResourceRep> taskMap) {
    for (String unManagedVolumeGUID : requestContext.getProcessedUnManagedVolumeMap().keySet()) {
        BlockObject processedBlockObject = requestContext.getProcessedBlockObject(unManagedVolumeGUID);
        VolumeIngestionContext volumeContext = requestContext.getVolumeContext(unManagedVolumeGUID);
        UnManagedVolume processedUnManagedVolume = volumeContext.getUnmanagedVolume();
        URI unManagedVolumeUri = processedUnManagedVolume.getId();
        TaskResourceRep resourceRep = taskMap.get(processedUnManagedVolume.getId().toString());
        String taskId = resourceRep != null ? resourceRep.getOpId() : null;
        try {
            if (processedBlockObject == null) {
                _logger.warn("The ingested block object is null. Skipping ingestion of export masks for unmanaged volume {}", unManagedVolumeGUID);
                throw IngestionException.exceptions.generalVolumeException(processedUnManagedVolume.getLabel(), "check the logs for more details");
            }
            // Build the Strategy , which contains reference to Block object & export orchestrators
            IngestExportStrategy ingestStrategy = _ingestStrategyFactory.buildIngestExportStrategy(processedUnManagedVolume);
            BlockObject blockObject = ingestStrategy.ingestExportMasks(processedUnManagedVolume, processedBlockObject, requestContext);
            if (null == blockObject) {
                throw IngestionException.exceptions.generalVolumeException(processedUnManagedVolume.getLabel(), "check the logs for more details");
            }
            if (null == blockObject.getCreationTime()) {
                // only add objects to create if they were created this round of ingestion,
                // creationTime will be null unless the object has already been saved to the db
                requestContext.getObjectsIngestedByExportProcessing().add(blockObject);
            }
            // If the ingested object is internal, flag an error. If it's an RP volume, it's exempt from this check.
            if (blockObject.checkInternalFlags(Flag.PARTIALLY_INGESTED) && !(blockObject instanceof Volume && ((Volume) blockObject).getRpCopyName() != null)) {
                StringBuffer taskStatus = requestContext.getTaskStatusMap().get(processedUnManagedVolume.getNativeGuid());
                String taskMessage = "";
                if (taskStatus == null) {
                    // No task status found. Put in a default message.
                    taskMessage = String.format("Not all the parent/replicas of unmanaged volume %s have been ingested", processedUnManagedVolume.getLabel());
                } else {
                    taskMessage = taskStatus.toString();
                }
                _dbClient.error(UnManagedVolume.class, processedUnManagedVolume.getId(), taskId, IngestionException.exceptions.unmanagedVolumeIsNotVisible(processedUnManagedVolume.getLabel(), taskMessage));
            } else {
                _dbClient.ready(UnManagedVolume.class, processedUnManagedVolume.getId(), taskId, INGESTION_SUCCESSFUL_MSG);
            }
        } catch (APIException ex) {
            _logger.warn(ex.getLocalizedMessage(), ex);
            _dbClient.error(UnManagedVolume.class, unManagedVolumeUri, taskId, ex);
            volumeContext.rollback();
        } catch (Exception ex) {
            _logger.warn(ex.getLocalizedMessage(), ex);
            _dbClient.error(UnManagedVolume.class, unManagedVolumeUri, taskId, IngestionException.exceptions.generalVolumeException(processedUnManagedVolume.getLabel(), ex.getLocalizedMessage()));
            volumeContext.rollback();
        }
    }
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) 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) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 19 with UnManagedVolume

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

the class IngestVolumesUnexportedSchedulingThread method run.

@Override
public void run() {
    _requestContext.reset();
    while (_requestContext.hasNext()) {
        UnManagedVolume unManagedVolume = _requestContext.next();
        String taskId = _taskMap.get(unManagedVolume.getId().toString());
        try {
            _logger.info("Ingestion starting for unmanaged volume {}", unManagedVolume.getNativeGuid());
            List<URI> volList = new ArrayList<URI>();
            volList.add(_requestContext.getCurrentUnManagedVolumeUri());
            VolumeIngestionUtil.checkIngestionRequestValidForUnManagedVolumes(volList, _requestContext.getVpool(unManagedVolume), _dbClient);
            IngestStrategy ingestStrategy = _ingestStrategyFactory.buildIngestStrategy(unManagedVolume, !IngestStrategyFactory.DISREGARD_PROTECTION);
            @SuppressWarnings("unchecked") BlockObject blockObject = ingestStrategy.ingestBlockObjects(_requestContext, VolumeIngestionUtil.getBlockObjectClass(unManagedVolume));
            if (null == blockObject) {
                throw IngestionException.exceptions.generalVolumeException(unManagedVolume.getLabel(), "check the logs for more details");
            }
            _logger.info("Ingestion completed successfully for unmanaged volume {}", unManagedVolume.getNativeGuid());
            _requestContext.getBlockObjectsToBeCreatedMap().put(blockObject.getNativeGuid(), blockObject);
            _requestContext.getProcessedUnManagedVolumeMap().put(unManagedVolume.getNativeGuid(), _requestContext.getVolumeContext());
        } catch (APIException ex) {
            _logger.error("APIException occurred", ex);
            _dbClient.error(UnManagedVolume.class, _requestContext.getCurrentUnManagedVolumeUri(), taskId, ex);
            _requestContext.getVolumeContext().rollback();
        } catch (Exception ex) {
            _logger.error("Exception occurred", ex);
            _dbClient.error(UnManagedVolume.class, _requestContext.getCurrentUnManagedVolumeUri(), taskId, IngestionException.exceptions.generalVolumeException(unManagedVolume.getLabel(), ex.getLocalizedMessage()));
            _requestContext.getVolumeContext().rollback();
        }
    }
    try {
        // update the task status
        for (String unManagedVolumeGUID : _requestContext.getProcessedUnManagedVolumeMap().keySet()) {
            VolumeIngestionContext volumeContext = _requestContext.getProcessedUnManagedVolumeMap().get(unManagedVolumeGUID);
            UnManagedVolume unManagedVolume = volumeContext.getUnmanagedVolume();
            String taskMessage = "";
            String taskId = _taskMap.get(unManagedVolume.getId().toString());
            boolean ingestedSuccessfully = false;
            if (unManagedVolume.getInactive()) {
                ingestedSuccessfully = true;
                taskMessage = INGESTION_SUCCESSFUL_MSG;
            } else {
                // check in the created objects for corresponding block object without any internal flags set
                BlockObject createdObject = _requestContext.findCreatedBlockObject(unManagedVolumeGUID.replace(VolumeIngestionUtil.UNMANAGEDVOLUME, VolumeIngestionUtil.VOLUME));
                _logger.info("checking partial ingestion status of block object " + createdObject);
                if ((null != createdObject) && (!createdObject.checkInternalFlags(Flag.PARTIALLY_INGESTED) || // If this is an ingested RP volume in an uningested protection set, the ingest is successful.
                (createdObject instanceof Volume && ((Volume) createdObject).checkForRp() && ((Volume) createdObject).getProtectionSet() == null)) || // If this is a successfully processed VPLEX backend volume, it will have the INTERNAL_OBJECT Flag
                (VolumeIngestionUtil.isVplexBackendVolume(unManagedVolume) && createdObject.checkInternalFlags(Flag.INTERNAL_OBJECT))) {
                    _logger.info("successfully partially ingested block object {} ", createdObject.forDisplay());
                    ingestedSuccessfully = true;
                    taskMessage = INGESTION_SUCCESSFUL_MSG;
                } else {
                    _logger.info("block object {} was not (partially) ingested successfully", createdObject);
                    ingestedSuccessfully = false;
                    StringBuffer taskStatus = _requestContext.getTaskStatusMap().get(unManagedVolume.getNativeGuid());
                    if (taskStatus == null) {
                        // No task status found. Put in a default message.
                        taskMessage = String.format("Not all the parent/replicas of unmanaged volume %s have been ingested", unManagedVolume.getLabel());
                    } else {
                        taskMessage = taskStatus.toString();
                    }
                }
            }
            if (ingestedSuccessfully) {
                _dbClient.ready(UnManagedVolume.class, unManagedVolume.getId(), taskId, taskMessage);
            } else {
                _dbClient.error(UnManagedVolume.class, unManagedVolume.getId(), taskId, IngestionException.exceptions.unmanagedVolumeIsNotVisible(unManagedVolume.getLabel(), taskMessage));
            }
            // Commit any ingested CG
            _unManagedVolumeService.commitIngestedCG(_requestContext, unManagedVolume);
            // Commit the volume's internal resources
            volumeContext.commit();
            // Commit this volume's updated data objects if any after ingestion
            Set<DataObject> updatedObjects = _requestContext.getDataObjectsToBeUpdatedMap().get(unManagedVolumeGUID);
            if (updatedObjects != null && !updatedObjects.isEmpty()) {
                for (DataObject dob : updatedObjects) {
                    _logger.info("Ingestion Wrap Up: Updating DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
                    _dbClient.updateObject(dob);
                }
            }
            // Commit this volume's created data objects if any after ingestion
            Set<DataObject> createdObjects = _requestContext.getDataObjectsToBeCreatedMap().get(unManagedVolumeGUID);
            if (createdObjects != null && !createdObjects.isEmpty()) {
                for (DataObject dob : createdObjects) {
                    _logger.info("Ingestion Wrap Up: Creating DataObject {} (hash {})", dob.forDisplay(), dob.hashCode());
                    _dbClient.createObject(dob);
                }
            }
        }
    } catch (InternalException e) {
        throw e;
    } catch (Exception e) {
        _logger.debug("Unexpected ingestion exception:", e);
        throw APIException.internalServerErrors.genericApisvcError(ExceptionUtils.getExceptionMessage(e), e);
    }
    for (BlockObject bo : _requestContext.getBlockObjectsToBeCreatedMap().values()) {
        _logger.info("Ingestion Wrap Up: Creating BlockObject {} (hash {})", bo.forDisplay(), bo.hashCode());
        _dbClient.createObject(bo);
    }
    for (UnManagedVolume umv : _requestContext.getUnManagedVolumesToBeDeleted()) {
        _logger.info("Ingestion Wrap Up: Deleting UnManagedVolume {} (hash {})", umv.forDisplay(), umv.hashCode());
        _dbClient.updateObject(umv);
    }
    // record the events after they have been persisted
    for (BlockObject volume : _requestContext.getBlockObjectsToBeCreatedMap().values()) {
        _unManagedVolumeService.recordVolumeOperation(_dbClient, _unManagedVolumeService.getOpByBlockObjectType(volume), Status.ready, volume.getId());
    }
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DataObject(com.emc.storageos.db.client.model.DataObject) 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) VolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 20 with UnManagedVolume

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

the class BlockVplexCGIngestDecorator method decorateCG.

@Override
public void decorateCG(BlockConsistencyGroup cg, Collection<BlockObject> associatedObjects, IngestionRequestContext requestContext, UnManagedVolume unManagedVolume) throws Exception {
    if (null == associatedObjects || associatedObjects.isEmpty()) {
        logger.info("No associated BlockObject's found for cg {}", cg.getLabel());
        return;
    }
    for (BlockObject blockObj : associatedObjects) {
        StringSetMap systemCGs = cg.getSystemConsistencyGroups();
        // No entries yet in the system consistency groups list. That's OK, we'll create it.
        if (null == systemCGs || systemCGs.isEmpty()) {
            cg.setSystemConsistencyGroups(new StringSetMap());
        }
        // This volume is not in a CG of this type
        if (NullColumnValueGetter.isNullValue(blockObj.getReplicationGroupInstance())) {
            logger.info("BlockObject {} doesn't have replicationGroup name {}. No need to set system cg information.", blockObj.getNativeGuid());
            continue;
        }
        boolean found = false;
        // Look through the existing entries in the CG and see if we find a match.
        for (Entry<String, AbstractChangeTrackingSet<String>> systemCGEntry : systemCGs.entrySet()) {
            if (systemCGEntry.getKey().equalsIgnoreCase(blockObj.getStorageController().toString())) {
                if (checkIfCGNameAlreadyExists(systemCGEntry.getValue(), blockObj.getReplicationGroupInstance())) {
                    logger.info(String.format("Found BlockObject %s,%s system details in cg %s", blockObj.getNativeGuid(), blockObj.getReplicationGroupInstance(), cg.getLabel()));
                    found = true;
                    break;
                }
            }
        }
        // If we didn't find this storage:cg combo, let's add it.
        if (!found) {
            logger.info(String.format("Adding BlockObject %s/%s in CG %s", blockObj.getNativeGuid(), blockObj.getReplicationGroupInstance(), cg.getLabel()));
            if (blockObj instanceof Volume) {
                Volume volume = (Volume) blockObj;
                if (volume.getAssociatedVolumes() != null && volume.getAssociatedVolumes().size() > 1) {
                    // Since this is a distributed volume, ensure there is a CG entry for each cluster
                    String cgName = BlockConsistencyGroupUtils.fetchCgName(volume.getReplicationGroupInstance());
                    cg.addSystemConsistencyGroup(volume.getStorageController().toString(), BlockConsistencyGroupUtils.buildClusterCgName(BlockConsistencyGroupUtils.CLUSTER_1, cgName));
                    cg.addSystemConsistencyGroup(volume.getStorageController().toString(), BlockConsistencyGroupUtils.buildClusterCgName(BlockConsistencyGroupUtils.CLUSTER_2, cgName));
                    logger.info(String.format("Found BlockObject [%s] is a Distributed VPLEX volume. " + "Adding cg entry [%s] for both cluster1 and cluster2.", blockObj.getNativeGuid(), cgName));
                } else {
                    cg.addSystemConsistencyGroup(volume.getStorageController().toString(), volume.getReplicationGroupInstance());
                }
            }
        }
        // the virtual volume's replicationGroupInstance reference.  This does not impact the backing volumes.
        if (blockObj instanceof Volume) {
            Volume volume = (Volume) blockObj;
            logger.info(String.format("Moving replication group instance name %s on virtual volume %s to backingReplicationGroupInstance", volume.getReplicationGroupInstance(), volume.getLabel()));
            volume.setBackingReplicationGroupInstance(volume.getReplicationGroupInstance());
            volume.setReplicationGroupInstance(NullColumnValueGetter.getNullStr());
            requestContext.addDataObjectToUpdate(volume, unManagedVolume);
            if (volume.getAssociatedVolumes() != null) {
                // setting BlockConsistencyGroup on the backend volumes
                for (String volumeUriStr : volume.getAssociatedVolumes()) {
                    BlockObject backendVolume = requestContext.findDataObjectByType(Volume.class, URI.create(volumeUriStr), true);
                    if (backendVolume != null) {
                        logger.info("Setting BlockConsistencyGroup {} on VPLEX backend Volume {}", cg.forDisplay(), backendVolume.forDisplay());
                        backendVolume.setConsistencyGroup(cg.getId());
                    // this volume is already set for creation by its parent volume context
                    // so there's no need to add it into an updated objects collection at this point
                    }
                }
            }
        }
        if (!cg.getTypes().contains(Types.VPLEX.toString())) {
            cg.getTypes().add(Types.VPLEX.toString());
        }
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) BlockObject(com.emc.storageos.db.client.model.BlockObject) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Aggregations

UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)146 StringSet (com.emc.storageos.db.client.model.StringSet)66 URI (java.net.URI)53 Volume (com.emc.storageos.db.client.model.Volume)48 ArrayList (java.util.ArrayList)48 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)33 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)31 BlockObject (com.emc.storageos.db.client.model.BlockObject)30 HashMap (java.util.HashMap)29 HashSet (java.util.HashSet)24 NamedURI (com.emc.storageos.db.client.model.NamedURI)19 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)19 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)18 DataObject (com.emc.storageos.db.client.model.DataObject)13 UnManagedExportMask (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedExportMask)13 CIMObjectPath (javax.cim.CIMObjectPath)13 UnManagedProtectionSet (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet)12 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)11 Map (java.util.Map)11 StringMap (com.emc.storageos.db.client.model.StringMap)10