use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method attachAndMount.
/**
* Attaches and mounts every disk and datastore associated with the volumes in the export group.
* For each volume in the export group, the associated disk is attached to the host and any datastores backed by the
* volume are mounted
* to the host.
*
* @param exportGroupId
* export group that contains volumes
* @param hostId
* host to attach and mount to
* @param vcenterId
* vcenter that the host belongs to
* @param vcenterDatacenter
* vcenter datacenter that the host belongs to
* @param stepId
* the id of the workflow step
*/
public void attachAndMount(URI exportGroupId, URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_054);
Host esxHost = _dbClient.queryObject(Host.class, hostId);
Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupId);
VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
if (hostSystem == null) {
_log.info("Not able to find host " + esxHost.getLabel() + " in vCenter. Unable to attach disks and mount datastores");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
if (exportGroup != null && exportGroup.getVolumes() != null) {
_log.info("Refreshing storage");
storageAPI.refreshStorage();
Set<BlockObject> blockObjects = Sets.newHashSet();
for (String volume : exportGroup.getVolumes().keySet()) {
BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
blockObjects.add(blockObject);
for (HostScsiDisk entry : storageAPI.listScsiDisks()) {
if (VolumeWWNUtils.wwnMatches(VMwareUtils.getDiskWwn(entry), blockObject.getWWN())) {
if (VMwareUtils.isDiskOff(entry)) {
_log.info("Attach SCSI Lun " + entry.getCanonicalName() + " on host " + esxHost.getLabel());
storageAPI.attachScsiLun(entry);
}
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_055);
break;
}
}
}
int retries = 0;
while (retries++ < MAXIMUM_RESCAN_ATTEMPTS && !blockObjects.isEmpty()) {
_log.info("Rescanning VMFS for host " + esxHost.getLabel());
storageAPI.getStorageSystem().rescanVmfs();
_log.info("Waiting for {} milliseconds before checking for datastores", RESCAN_DELAY_MS);
Thread.sleep(RESCAN_DELAY_MS);
_log.info("Looking for datastores for {} volumes", blockObjects.size());
Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(hostSystem);
Iterator<BlockObject> objectIterator = blockObjects.iterator();
while (objectIterator.hasNext()) {
BlockObject blockObject = objectIterator.next();
if (blockObject != null) {
Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
if (datastore != null && VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
_log.info("Datastore {} is already mounted on {}", datastore.getName(), esxHost.getLabel());
objectIterator.remove();
} else if (datastore != null && !VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
_log.info("Mounting datastore {} on host {}", datastore.getName(), esxHost.getLabel());
storageAPI.mountDatastore(datastore);
objectIterator.remove();
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_056);
}
}
}
}
}
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error(ex.getMessage(), ex);
WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
}
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method verifyDatastore.
/**
* Verifies that datastores contained within an export group can be unmounted. It must not be entering maintenance mode or contain any
* virtual machines running on the given ESXi host.
*
* @param exportGroupId
* export group that contains volumes
* @param vcenterId
* vcenter that the host belongs to
* @param vcenterDatacenter
* vcenter datacenter that the host belongs to
* @param esxHostname
* the hostname of the ESXi host
*
* @param stepId
* the id of the workflow step
*/
public void verifyDatastore(URI exportGroupId, URI vCenterId, URI vcenterDatacenter, String esxHostname, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupId);
VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
HostSystem host = api.findHostSystem(vCenterDataCenter.getLabel(), esxHostname);
if (host == null) {
_log.info("Not able to find host " + esxHostname + " in vCenter. Unable to validate");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(host);
if (exportGroup != null && exportGroup.getVolumes() != null) {
for (String volume : exportGroup.getVolumes().keySet()) {
BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
if (datastore != null) {
ComputeSystemHelper.verifyDatastore(datastore, host);
}
}
}
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_029);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error(ex.getMessage(), ex);
WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
}
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class ComputeSystemHelper method getStorageToVolumeMap.
private static Map<URI, Map<URI, Integer>> getStorageToVolumeMap(DbClient dbClient, ExportGroup exportGroup, boolean protection) {
Map<URI, Map<URI, Integer>> map = new HashMap<URI, Map<URI, Integer>>();
StringMap volumes = exportGroup.getVolumes();
if (volumes == null) {
return map;
}
for (String uriString : volumes.keySet()) {
URI blockURI = URI.create(uriString);
BlockObject block = BlockObject.fetch(dbClient, blockURI);
// If this is an RP-based Block Snapshot, use the protection controller instead of the underlying block controller
URI storage = (block.getProtectionController() != null && protection && block.getId().toString().contains("BlockSnapshot")) ? block.getProtectionController() : block.getStorageController();
if (map.get(storage) == null) {
map.put(storage, new HashMap<URI, Integer>());
}
map.get(storage).put(blockURI, Integer.valueOf(volumes.get(uriString)));
}
return map;
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockIngestOrchestrator method markUnManagedVolumeInactive.
/**
* Algorithm:
*
* 1. Get the parent of the Current UMV
* 2. If parent is null AND current UMV doesn't have any replicas, its actually a UMV with no replicas.
* 3. Else run while loop to find out the ROOT of the current's Parent.
* 4. At the end of this while loop, we get the ROOT UMV, ROOT Block Object.
* 5. Invoke RunReplicasIngestedCheck
* a. Get the replicas of the ROOT UMV
* b. Find if all replicas Ingested
* c. If Yes, then update parent Replica Map [Parent --> Child]
* 1. For each Replica unmanaged volume, RUN STEP 5.
* d. Else Clear Parent Replica and come out.
* 6. If parent Replica map is not empty (parent-child ingested successfully)
* a. Set Parent Child relations
* b. Hold the data in Memory and don't persist to DB.
*
* @param unmanagedVolume current Processed UnManaged Volume
* @param blockObject current Processed Block Object
* @param unManagedVolumes
* @param createdObjects Already processed Block Objects in Memory
* @param taskStatusMap
* @param vplexIngestionMethod the VPLEX backend ingestion method
* @return
*/
@SuppressWarnings("deprecation")
protected boolean markUnManagedVolumeInactive(IngestionRequestContext requestContext, BlockObject currentBlockObject) {
UnManagedVolume currentUnmanagedVolume = requestContext.getCurrentUnmanagedVolume();
_logger.info("Running unmanagedvolume {} replica ingestion status", currentUnmanagedVolume.getNativeGuid());
boolean markUnManagedVolumeInactive = false;
// if the vplex ingestion method is vvol-only, we don't need to check replicas
if (VolumeIngestionUtil.isVplexVolume(currentUnmanagedVolume) && VplexBackendIngestionContext.INGESTION_METHOD_VVOL_ONLY.equals(requestContext.getVplexIngestionMethod())) {
_logger.info("This is a VPLEX virtual volume and the ingestion method is " + "virtual volume only. Skipping replica ingestion algorithm.");
return true;
}
StringSetMap unManagedVolumeInformation = currentUnmanagedVolume.getVolumeInformation();
List<String> parentVolumeNativeGUIDs = getParentVolumeNativeGUIDByRepType(unManagedVolumeInformation);
// TODO - may be move this to a single utility method
if (parentVolumeNativeGUIDs.isEmpty() && !VolumeIngestionUtil.checkUnManagedVolumeHasReplicas(currentUnmanagedVolume)) {
_logger.info("Simple unmanagedvolume without any replicas. Skipping replica ingestion algorithm.");
return true;
}
_logger.info("Running algorithm to find the root source volume for {}", currentUnmanagedVolume.getNativeGuid());
// Get the topmost parent object
if (!parentVolumeNativeGUIDs.isEmpty()) {
markUnManagedVolumeInactive = true;
for (String parentVolumeNativeGUID : parentVolumeNativeGUIDs) {
boolean allGood = false;
Map<BlockObject, List<BlockObject>> parentReplicaMap = new HashMap<BlockObject, List<BlockObject>>();
StringSet processedUnManagedGUIDS = new StringSet();
UnManagedVolume rootUnManagedVolume = currentUnmanagedVolume;
BlockObject rootBlockObject = currentBlockObject;
while (parentVolumeNativeGUID != null) {
_logger.info("Finding unmanagedvolume {} in vipr db", parentVolumeNativeGUID);
List<URI> parentUnmanagedUris = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeInfoNativeIdConstraint(parentVolumeNativeGUID));
if (!parentUnmanagedUris.isEmpty()) {
_logger.info("Found unmanagedvolume {} in vipr db", parentVolumeNativeGUID);
rootUnManagedVolume = _dbClient.queryObject(UnManagedVolume.class, parentUnmanagedUris.get(0));
unManagedVolumeInformation = rootUnManagedVolume.getVolumeInformation();
String blockObjectNativeGUID = rootUnManagedVolume.getNativeGuid().replace(VolumeIngestionUtil.UNMANAGEDVOLUME, VolumeIngestionUtil.VOLUME);
rootBlockObject = requestContext.getRootIngestionRequestContext().findCreatedBlockObject(blockObjectNativeGUID);
// If the root object is not found in locally createdObjects, check in DB.
if (rootBlockObject == null) {
rootBlockObject = VolumeIngestionUtil.getBlockObject(blockObjectNativeGUID, _dbClient);
}
// Get the parent unmanagedvolume for the current unmanagedvolume.
List<String> parents = getParentVolumeNativeGUIDByRepType(unManagedVolumeInformation);
if (parents.isEmpty()) {
parentVolumeNativeGUID = null;
_logger.info("No parent for current unmanagedvolume {}", rootUnManagedVolume.getNativeGuid());
} else {
parentVolumeNativeGUID = parents.get(0);
_logger.info("Found the parent {} for current unmanagedvolume {}", parentVolumeNativeGUID, rootUnManagedVolume.getNativeGuid());
}
// UnManaged Volumes, but the VPLEX device has not.
if ((null == parentVolumeNativeGUID) && VolumeIngestionUtil.isVplexBackendVolume(rootUnManagedVolume)) {
throw IngestionException.exceptions.vplexBackendVolumeHasNoParent(rootUnManagedVolume.getLabel());
}
} else {
_logger.info("unmanagedvolume not found looking for ingested volume {} in vipr db", parentVolumeNativeGUID);
// parent might be already ingested
// Native guid might correspond to ViPR object, find if there is still a unmanaged volume corresponding to the
// parent
parentUnmanagedUris = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeInfoNativeIdConstraint(parentVolumeNativeGUID.replace(VolumeIngestionUtil.VOLUME, VolumeIngestionUtil.UNMANAGEDVOLUME)));
if (!parentUnmanagedUris.isEmpty()) {
_logger.info("Found ingested volume {} in vipr db", parentVolumeNativeGUID);
rootUnManagedVolume = _dbClient.queryObject(UnManagedVolume.class, parentUnmanagedUris.get(0));
unManagedVolumeInformation = rootUnManagedVolume.getVolumeInformation();
rootBlockObject = VolumeIngestionUtil.getBlockObject(parentVolumeNativeGUID, _dbClient);
List<String> parents = getParentVolumeNativeGUIDByRepType(unManagedVolumeInformation);
if (parents.isEmpty()) {
parentVolumeNativeGUID = null;
} else {
parentVolumeNativeGUID = parents.get(0);
}
_logger.info("Found the parent {} for current unmanagedvolume {}", parentVolumeNativeGUID, rootUnManagedVolume.getNativeGuid());
// UnManaged Volumes, but the VPLEX device has not.
if ((null == parentVolumeNativeGUID) && VolumeIngestionUtil.isVplexBackendVolume(rootUnManagedVolume)) {
throw IngestionException.exceptions.vplexBackendVolumeHasNoParent(rootUnManagedVolume.getLabel());
}
} else {
_logger.info("Found a replica {} whose parent is already ingested with PUBLIC_ACCESS=true", parentVolumeNativeGUID);
// Find the ViPR object and put the block object and the parent in the map and break
List<BlockObject> replicas = new ArrayList<BlockObject>();
replicas.add(rootBlockObject);
parentReplicaMap.put(VolumeIngestionUtil.getBlockObject(parentVolumeNativeGUID.replace(VolumeIngestionUtil.UNMANAGEDVOLUME, VolumeIngestionUtil.VOLUME), _dbClient), replicas);
break;
}
}
}
if (null != rootBlockObject) {
_logger.info("Found root source volume {}", rootBlockObject.getNativeGuid());
}
if (null != rootUnManagedVolume) {
_logger.info("Found root unmanagedvolume {}", rootUnManagedVolume.getNativeGuid());
}
_logger.info("Running algorithm to check all replicas ingested for parent");
runReplicasIngestedCheck(rootUnManagedVolume, rootBlockObject, currentUnmanagedVolume, currentBlockObject, processedUnManagedGUIDS, parentReplicaMap, requestContext);
_logger.info("Ended algorithm to check all replicas ingested for parent");
List<UnManagedVolume> processedUnManagedVolumes = _dbClient.queryObject(UnManagedVolume.class, VolumeIngestionUtil.getUnManagedVolumeUris(processedUnManagedGUIDS, _dbClient));
if (!parentReplicaMap.isEmpty()) {
setupParentReplicaRelationships(currentUnmanagedVolume, parentReplicaMap, requestContext, processedUnManagedVolumes);
allGood = true;
}
if (!allGood) {
markUnManagedVolumeInactive = false;
}
}
} else {
Map<BlockObject, List<BlockObject>> parentReplicaMap = new HashMap<BlockObject, List<BlockObject>>();
StringSet processedUnManagedGUIDS = new StringSet();
UnManagedVolume rootUnManagedVolume = currentUnmanagedVolume;
BlockObject rootBlockObject = currentBlockObject;
if (null != rootBlockObject) {
_logger.info("Found root source volume {}", rootBlockObject.getNativeGuid());
}
if (null != rootUnManagedVolume) {
_logger.info("Found root unmanagedvolume {}", rootUnManagedVolume.getNativeGuid());
}
_logger.info("Running algorithm to check all replicas ingested for parent");
runReplicasIngestedCheck(rootUnManagedVolume, rootBlockObject, currentUnmanagedVolume, currentBlockObject, processedUnManagedGUIDS, parentReplicaMap, requestContext);
_logger.info("Ended algorithm to check all replicas ingested for parent");
List<UnManagedVolume> processedUnManagedVolumes = _dbClient.queryObject(UnManagedVolume.class, VolumeIngestionUtil.getUnManagedVolumeUris(processedUnManagedGUIDS, _dbClient));
if (!parentReplicaMap.isEmpty()) {
setupParentReplicaRelationships(currentUnmanagedVolume, parentReplicaMap, requestContext, processedUnManagedVolumes);
return true;
}
}
return markUnManagedVolumeInactive;
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockIngestOrchestrator method getFoundIngestedReplicaURIs.
/**
* Return the foundingestedreplica nativeguids.
*
* @param foundIngestedReplicas
* @param foundIngestedReplicaNativeGuids
*/
private void getFoundIngestedReplicaURIs(List<BlockObject> foundIngestedReplicas, StringSet foundIngestedReplicaNativeGuids) {
if (null != foundIngestedReplicas && !foundIngestedReplicas.isEmpty()) {
for (BlockObject blockObj : foundIngestedReplicas) {
_logger.info("getFoundIngestedReplicaURIs blockObj: " + blockObj);
foundIngestedReplicaNativeGuids.add(blockObj.getNativeGuid());
}
}
}
Aggregations