use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.
the class HDSMetaVolumeOperations method expandVolumeAsMetaVolume.
@Override
public void expandVolumeAsMetaVolume(StorageSystem storageSystem, StoragePool storagePool, Volume metaHead, List<String> newMetaMembers, String metaType, MetaVolumeTaskCompleter metaVolumeTaskCompleter) throws Exception {
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
String systemObjectID = HDSUtils.getSystemObjectID(storageSystem);
LogicalUnit metaHeadVolume = hdsApiClient.getLogicalUnitInfo(systemObjectID, HDSUtils.getLogicalUnitObjectId(metaHead.getNativeId(), storageSystem));
String metaHeadLdevId = null;
List<String> metaMembersLdevObjectIds = new ArrayList<String>();
// Step 1: Get LDEV id's of the meta members and format them
if (null != newMetaMembers && !newMetaMembers.isEmpty()) {
for (String metaMember : newMetaMembers) {
if (null != metaMember) {
String asyncTaskMessageId = hdsApiClient.formatLogicalUnit(systemObjectID, metaMember);
if (asyncTaskMessageId == null) {
throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the expand volume call");
}
HDSJob formatLUJob = new HDSJob(asyncTaskMessageId, storageSystem.getId(), metaVolumeTaskCompleter.getVolumeTaskCompleter(), "formatLogicalUnit");
invokeMethodSynchronously(hdsApiFactory, asyncTaskMessageId, formatLUJob);
}
LogicalUnit metaMemberVolume = hdsApiClient.getLogicalUnitInfo(systemObjectID, metaMember);
if (null != metaMemberVolume && !metaMemberVolume.getLdevList().isEmpty()) {
for (LDEV ldev : metaMemberVolume.getLdevList()) {
// Format the logical unit. This is synchronous operation
// should wait it the operation completes.
metaMembersLdevObjectIds.add(ldev.getObjectID());
}
}
}
}
log.info("New Meta member LDEV ids: {}", metaMembersLdevObjectIds);
// Step 2: Get LDEV id of the meta volume head.
if (null != metaHeadVolume && null != metaHeadVolume.getLdevList()) {
for (LDEV ldev : metaHeadVolume.getLdevList()) {
// will be created during expansion of volume.
if (getLDEVID(ldev.getObjectID()).equalsIgnoreCase(metaHead.getNativeId())) {
metaHeadLdevId = ldev.getObjectID();
break;
}
}
}
// Step 3: Create LUSE Volume using metaHead LDEV & meta
// members LDEV Ids.
LogicalUnit logicalUnit = hdsApiClient.createLUSEVolume(systemObjectID, metaHeadLdevId, metaMembersLdevObjectIds);
if (null != logicalUnit) {
long capacityInBytes = Long.valueOf(logicalUnit.getCapacityInKB()) * 1024L;
metaHead.setProvisionedCapacity(capacityInBytes);
metaHead.setAllocatedCapacity(capacityInBytes);
dbClient.persistObject(metaHead);
}
}
use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.
the class HDSStorageDevice method doCleanupMetaMembers.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.BlockStorageDevice#doCleanupMetaMembers(com.emc.storageos.db.client.model.StorageSystem,
* com.emc.storageos.db.client.model.Volume,
* com.emc.storageos.volumecontroller.impl.block.taskcompleter.CleanupMetaVolumeMembersCompleter)
*/
@Override
public void doCleanupMetaMembers(StorageSystem storageSystem, Volume volume, CleanupMetaVolumeMembersCompleter cleanupCompleter) throws DeviceControllerException {
// Remove meta member volumes from storage device
try {
log.info(String.format("doCleanupMetaMembers Start - Array: %s, Volume: %s", storageSystem.getSerialNumber(), volume.getLabel()));
// Load meta volume members from WF data
String sourceStepId = cleanupCompleter.getSourceStepId();
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getUsername(), storageSystem.getSmisPassword());
List<String> metaMembers = (ArrayList<String>) WorkflowService.getInstance().loadStepData(sourceStepId);
if (metaMembers != null && !metaMembers.isEmpty()) {
log.info(String.format("doCleanupMetaMembers: Members stored for meta volume: %n %s", metaMembers));
// Check if volumes still exist in array and if it is not composite member (already
// added to the meta volume)
Set<String> volumeIds = new HashSet<String>();
for (String logicalUnitObjectId : metaMembers) {
LogicalUnit logicalUnit = hdsApiClient.getLogicalUnitInfo(HDSUtils.getSystemObjectID(storageSystem), logicalUnitObjectId);
if (logicalUnit != null) {
log.debug("doCleanupMetaMembers: Volume: " + logicalUnitObjectId + ", Usage of volume: " + logicalUnit.getComposite());
if (logicalUnit.getComposite() != HDSConstants.COMPOSITE_ELEMENT_MEMBER) {
volumeIds.add(logicalUnitObjectId);
}
}
}
if (volumeIds.isEmpty()) {
log.info("doCleanupMetaMembers: No meta members to cleanup in array.");
cleanupCompleter.ready(dbClient);
} else {
log.info(String.format("doCleanupMetaMembers: Members to cleanup in array: %n %s", volumeIds));
// Prepare parameters and call method to delete meta members from array
HDSCleanupMetaVolumeMembersJob hdsJobCompleter = null;
// When "cleanup" is separate workflow step, call async (for example rollback
// step in volume expand)
// Otherwise, call synchronously (for example when cleanup is part of meta
// volume create rollback)
String asyncMessageId = hdsApiClient.deleteThickLogicalUnits(HDSUtils.getSystemObjectID(storageSystem), volumeIds, storageSystem.getModel());
if (asyncMessageId == null) {
throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the delete volume call");
}
if (cleanupCompleter.isWFStep()) {
if (asyncMessageId != null) {
ControllerServiceImpl.enqueueJob(new QueueJob(new HDSCleanupMetaVolumeMembersJob(asyncMessageId, storageSystem.getId(), volume.getId(), cleanupCompleter)));
}
} else {
// invoke synchronously
hdsJobCompleter = new HDSCleanupMetaVolumeMembersJob(asyncMessageId, storageSystem.getId(), volume.getId(), cleanupCompleter);
((HDSMetaVolumeOperations) metaVolumeOperations).invokeMethodSynchronously(hdsApiFactory, asyncMessageId, hdsJobCompleter);
}
}
} else {
log.info("doCleanupMetaMembers: No meta members stored for meta volume. Nothing to cleanup in array.");
cleanupCompleter.ready(dbClient);
}
} catch (Exception e) {
log.error("Problem in doCleanupMetaMembers: ", e);
ServiceError error = DeviceControllerErrors.smis.methodFailed("doCleanupMetaMembers", e.getMessage());
cleanupCompleter.error(dbClient, error);
}
log.info(String.format("doCleanupMetaMembers End - Array: %s, Volume: %s", storageSystem.getSerialNumber(), volume.getLabel()));
}
use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.
the class HDSAbstractCreateVolumeJob method updateStatus.
/**
* Called to update the job status when the volume create job completes.
* <p/>
* This is common update code for volume create operations.
*
* @param jobContext The job context.
*/
@Override
public void updateStatus(JobContext jobContext) throws Exception {
List<LogicalUnit> luList = null;
DbClient dbClient = jobContext.getDbClient();
try {
if (_status == JobStatus.IN_PROGRESS) {
return;
}
int volumeCount = 0;
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
HDSApiClient hdsApiClient = jobContext.getHdsApiFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
// from pool's reserved capacity map.
if (_status == JobStatus.SUCCESS || _status == JobStatus.FAILED) {
StoragePool storagePool = dbClient.queryObject(StoragePool.class, storagePoolURI);
HDSUtils.updateStoragePoolCapacity(dbClient, hdsApiClient, storagePool);
StringMap reservationMap = storagePool.getReservedCapacityMap();
for (URI volumeId : getTaskCompleter().getIds()) {
// remove from reservation map
reservationMap.remove(volumeId.toString());
}
dbClient.persistObject(storagePool);
}
boolean isThinVolumeRequest = checkThinVolumesRequest(getTaskCompleter().getIds(), dbClient);
if (_status == JobStatus.SUCCESS) {
List<URI> volumes = new ArrayList<URI>();
luList = getLuListBasedOnModel(storageSystem, _javaResult, isThinVolumeRequest);
Iterator<LogicalUnit> luListItr = luList.iterator();
Calendar now = Calendar.getInstance();
while (luListItr.hasNext()) {
LogicalUnit logicalUnit = luListItr.next();
URI volumeId = getTaskCompleter().getId(volumeCount++);
volumes.add(volumeId);
processVolume(volumeId, logicalUnit, dbClient, hdsApiClient, now, logMsgBuilder);
}
} else if (_status == JobStatus.FAILED) {
for (URI id : getTaskCompleter().getIds()) {
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, id.toString()));
BlockObject object = BlockObject.fetch(dbClient, id);
if (object != null) {
object.setInactive(true);
dbClient.persistObject(object);
}
}
}
_log.info(logMsgBuilder.toString());
} catch (Exception e) {
_log.error("Caught an exception while trying to updateStatus for HDSCreateVolumeJob", e);
setErrorStatus("Encountered an internal error during volume create job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.
the class HDSAbstractCreateVolumeJob method changeVolumeName.
/**
* Method will modify the name of a given volume to a generate name.
*
* @param dbClient [in] - Client instance for reading/writing from/to DB
* @param client [in] - HDSApiClient used for reading/writing from/to HiCommand DM.
* @param volume [in] - Volume object
*/
protected void changeVolumeName(DbClient dbClient, HDSApiClient client, Volume volume, String name) {
try {
_log.info(String.format("Attempting to add volume label %s to %s", name, volume.getWWN()));
StorageSystem system = dbClient.queryObject(StorageSystem.class, volume.getStorageController());
String systemObjectId = HDSUtils.getSystemObjectID(system);
LogicalUnit logicalUnit = client.getLogicalUnitInfo(systemObjectId, HDSUtils.getLogicalUnitObjectId(volume.getNativeId(), system));
if (null != logicalUnit && null != logicalUnit.getLdevList() && !logicalUnit.getLdevList().isEmpty()) {
Iterator<LDEV> ldevItr = logicalUnit.getLdevList().iterator();
if (ldevItr.hasNext()) {
LDEV ldev = ldevItr.next();
ObjectLabel objectLabel = client.addVolumeLabel(ldev.getObjectID(), name);
volume.setDeviceLabel(objectLabel.getLabel());
dbClient.persistObject(volume);
}
} else {
_log.info("No LDEV's found on volume: {}", volume.getWWN());
}
_log.info(String.format("Volume label has been added to volume %s", volume.getWWN()));
} catch (DatabaseException e) {
_log.error("Encountered an error while trying to set the volume name", e);
} catch (Exception e) {
_log.error("Encountered an error while trying to set the volume name", e);
}
}
use of com.emc.storageos.hds.model.LogicalUnit in project coprhd-controller by CoprHD.
the class HDSBlockCreateSnapshotJob method changeSnapshotName.
/**
* Method will modify the name of a given volume to a generate name.
*
* @param dbClient [in] - Client instance for reading/writing from/to DB
* @param client [in] - HDSApiClient used for reading/writing from/to HiCommand DM.
* @param snapshotObj [in] - Volume object
*/
private void changeSnapshotName(DbClient dbClient, HDSApiClient client, BlockSnapshot snapshotObj) {
try {
Volume source = dbClient.queryObject(Volume.class, snapshotObj.getParent());
// Get the tenant name from the volume
TenantOrg tenant = dbClient.queryObject(TenantOrg.class, source.getTenant().getURI());
String tenantName = tenant.getLabel();
// that was successfully created
if (_nameGeneratorRef.get() == null) {
_nameGeneratorRef.compareAndSet(null, (NameGenerator) ControllerServiceImpl.getBean("defaultNameGenerator"));
}
String generatedName = _nameGeneratorRef.get().generate(tenantName, snapshotObj.getLabel(), snapshotObj.getId().toString(), '-', HDSConstants.MAX_VOLUME_NAME_LENGTH);
log.info(String.format("Attempting to add snapshot label %s to %s", generatedName, snapshotObj.getNativeId()));
StorageSystem system = dbClient.queryObject(StorageSystem.class, snapshotObj.getStorageController());
String systemObjectId = HDSUtils.getSystemObjectID(system);
LogicalUnit logicalUnit = client.getLogicalUnitInfo(systemObjectId, HDSUtils.getLogicalUnitObjectId(snapshotObj.getNativeId(), system));
if (null != logicalUnit && null != logicalUnit.getLdevList() && !logicalUnit.getLdevList().isEmpty()) {
Iterator<LDEV> ldevItr = logicalUnit.getLdevList().iterator();
if (ldevItr.hasNext()) {
LDEV ldev = ldevItr.next();
ObjectLabel objectLabel = client.addVolumeLabel(ldev.getObjectID(), generatedName);
snapshotObj.setDeviceLabel(objectLabel.getLabel());
dbClient.persistObject(snapshotObj);
}
} else {
log.info("No LDEV's found on volume: {}", snapshotObj.getNativeId());
}
log.info(String.format("snapshot label has been added to snapshot %s", snapshotObj.getNativeId()));
} catch (Exception e) {
log.error("Encountered an error while trying to set the snapshot name", e);
}
}
Aggregations