use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockVplexVolumeIngestOrchestrator method ingestBackendVolumes.
/**
* Ingests the backend volumes and any related replicas.
*
* Calls ingestBlockObjects by getting a nested IngestStrategy
* for each backend volume or replica from the IngestStrategyFactory.
*
* @param backendRequestContext the VplexBackendIngestionContext for the parent virtual volume
*
* @throws IngestionException
*/
private void ingestBackendVolumes(IngestionRequestContext requestContext, VplexVolumeIngestionContext backendRequestContext) throws IngestionException {
while (backendRequestContext.hasNext()) {
UnManagedVolume associatedVolume = backendRequestContext.next();
String sourceClusterId = getClusterNameForVarray(backendRequestContext.getVarray(associatedVolume), requestContext.getStorageSystem());
String haClusterId = getClusterNameForVarray(backendRequestContext.getHaVarray(associatedVolume), requestContext.getStorageSystem());
_logger.info("the source cluster id is {} and the high availability cluster id is {}", sourceClusterId, haClusterId);
backendRequestContext.setHaClusterId(haClusterId);
_logger.info("Ingestion started for vplex backend volume {}", associatedVolume.getNativeGuid());
try {
validateBackendVolumeVpool(associatedVolume, backendRequestContext.getVpool(associatedVolume));
IngestStrategy ingestStrategy = ingestStrategyFactory.buildIngestStrategy(associatedVolume, IngestStrategyFactory.DISREGARD_PROTECTION);
@SuppressWarnings("unchecked") BlockObject blockObject = ingestStrategy.ingestBlockObjects(backendRequestContext, VolumeIngestionUtil.getBlockObjectClass(associatedVolume));
if (null == blockObject) {
// ingestion did not succeed, but in case it wasn't, throw one
throw IngestionException.exceptions.generalVolumeException(associatedVolume.getLabel(), "check the logs for more details");
}
// Note that a VPLEX backend volume could also be a snapshot target volume.
// When this is the case, the local volume ingest strategy is what will be
// retrieved and executed. As a result, the object returned will be a
// Volume instance not a BlockSnapshot instance. However, the local volume
// ingest strategy realizes that the volume may also be a snapshot target
// volume and creates the BlockSnapshot instance to represent the snapshot
// target volume and adds this BlockSnapshot instance to the created objects
// list. Because the BlockSnapshot and Volume instances will have the same
// native GUID, as they represent the same physical volume, we can't
// add the Volume to the created objects list as it would just replace
// the BlockSnapshot instance and only the Volume would get created. So,
// we first move the snapshot to the created snapshots list before adding
// the volume to the created objects list.
Map<String, BlockObject> createdObjectMap = backendRequestContext.getBlockObjectsToBeCreatedMap();
String blockObjectNativeGuid = blockObject.getNativeGuid();
if (createdObjectMap.containsKey(blockObjectNativeGuid)) {
BlockObject createdBlockObject = createdObjectMap.get(blockObjectNativeGuid);
if (createdBlockObject instanceof BlockSnapshot) {
_logger.info("Backend ingestion created block snapshot {}", blockObjectNativeGuid);
// The snapshot will be created with the backend volume project, so we
// need to update that to the frontend project.
((BlockSnapshot) createdBlockObject).setProject(new NamedURI(backendRequestContext.getFrontendProject().getId(), createdBlockObject.getLabel()));
backendRequestContext.getCreatedSnapshotMap().put(blockObjectNativeGuid, (BlockSnapshot) createdBlockObject);
createdObjectMap.put(blockObjectNativeGuid, blockObject);
} else {
// This should not happen. If there is an instance in the created
// objects list with the same guid as the ingested block object
// it must be that the backend volume is also a snapshot target
// volume and the strategy created the BlockSnapshot instance and
// added it to the created objects list.
_logger.warn("Unexpected object in created objects list during backend ingestion {}:{}", blockObjectNativeGuid, createdBlockObject.getLabel());
}
} else {
createdObjectMap.put(blockObjectNativeGuid, blockObject);
}
backendRequestContext.getProcessedUnManagedVolumeMap().put(associatedVolume.getNativeGuid(), backendRequestContext.getVolumeContext());
_logger.info("Ingestion ended for backend volume {}", associatedVolume.getNativeGuid());
} catch (Exception ex) {
_logger.error(ex.getLocalizedMessage());
backendRequestContext.rollback();
throw ex;
}
}
}
use of com.emc.storageos.db.client.model.BlockObject 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());
}
}
}
}
use of com.emc.storageos.db.client.model.BlockObject 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();
}
}
}
use of com.emc.storageos.db.client.model.BlockObject 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());
}
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockRPCGIngestDecorator method getAssociatedObjects.
@Override
protected List<BlockObject> getAssociatedObjects(BlockConsistencyGroup cg, Collection<BlockObject> allCGBlockObjects, IngestionRequestContext requestContext) throws Exception {
// Get all of the block objects that are in the protection set
RecoverPointVolumeIngestionContext rpContext = (RecoverPointVolumeIngestionContext) requestContext.getVolumeContext();
ProtectionSet pset = rpContext.getManagedProtectionSet();
if (pset == null) {
return null;
}
// All of the volumes in the CG are in the "objects to be updated" map in the RP context.
List<BlockObject> boList = new ArrayList<BlockObject>();
for (String volumeIdStr : pset.getVolumes()) {
for (DataObject dataObj : allCGBlockObjects) {
if (URIUtil.identical(dataObj.getId(), URI.create(volumeIdStr))) {
boList.add((BlockObject) dataObj);
}
}
}
return boList;
}
Aggregations