use of com.emc.storageos.volumecontroller.impl.validators.hds.AbstractHDSValidator in project coprhd-controller by CoprHD.
the class HDSExportOperations method removeInitiators.
@Override
public void removeInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<Initiator> initiators, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
long startTime = System.currentTimeMillis();
log.info("{} removeInitiator START...", storage.getSerialNumber());
try {
log.info("removeInitiator: Export mask id: {}", exportMaskURI);
if (volumeURIList != null) {
log.info("removeInitiator: volumes : {}", Joiner.on(',').join(volumeURIList));
}
log.info("removeInitiator: initiators : {}", Joiner.on(',').join(initiators));
log.info("removeInitiator: targets : {}", Joiner.on(',').join(targets));
if (null == initiators || initiators.isEmpty()) {
log.info("No initiators found to remove {}", exportMaskURI);
taskCompleter.ready(dbClient);
return;
}
ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
// Get the context from the task completer, in case this is a rollback.
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(exportMask);
ctx.setBlockObjects(volumeURIList, dbClient);
ctx.setInitiators(initiators);
// Allow exceptions to be thrown when not rolling back
ctx.setAllowExceptions(!isRollback);
AbstractHDSValidator removeInitiatorFromMaskValidator = (AbstractHDSValidator) validator.removeInitiators(ctx);
removeInitiatorFromMaskValidator.validate();
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
String systemObjectID = HDSUtils.getSystemObjectID(storage);
StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
if (null != deviceDataMap && !deviceDataMap.isEmpty()) {
Set<String> hsdObjectIDSet = deviceDataMap.keySet();
for (String hsdObjectID : hsdObjectIDSet) {
HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectID);
if (null == hsd) {
log.warn("Not able to remove initiators as HSD {} couldn't find on array.", hsdObjectID);
continue;
}
List<String> fcInitiators = getFCInitiatorsExistOnHSD(hsd, initiators);
List<String> iSCSIInitiators = getISCSIInitiatorsExistOnHSD(hsd, initiators);
boolean isLastFCInitiator = (fcInitiators.size() == 1 && null != hsd.getWwnList() && hsd.getWwnList().size() == fcInitiators.size());
boolean isLastISCSIInitiator = (iSCSIInitiators.size() == 1 && null != hsd.getIscsiList() && hsd.getIscsiList().size() == iSCSIInitiators.size());
// If Initiator is last one, remove the HSD
if (isLastFCInitiator || isLastISCSIInitiator) {
exportMgr.deleteHostStorageDomain(systemObjectID, hsd.getObjectID(), storage.getModel());
exportMask.getDeviceDataMap().remove(hsd.getObjectID());
} else {
if (null != fcInitiators && !fcInitiators.isEmpty()) {
// remove FC initiators from HSD.
exportMgr.deleteWWNsFromHostStorageDomain(systemObjectID, hsd.getObjectID(), fcInitiators, storage.getModel());
}
if (null != iSCSIInitiators && !iSCSIInitiators.isEmpty()) {
// remove ISCSInames from HSD.
exportMgr.deleteISCSIsFromHostStorageDomain(systemObjectID, hsd.getObjectID(), iSCSIInitiators, storage.getModel());
}
}
}
dbClient.updateObject(exportMask);
// update the task status after processing all HSD's.
taskCompleter.ready(dbClient);
} else {
log.info("No Host groups found on exportMask {}", exportMaskURI);
// No HSD's found in exportMask.
taskCompleter.ready(dbClient);
}
} catch (Exception e) {
log.error(String.format("removeInitiator failed - maskURI: %s", exportMaskURI.toString()), e);
ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(ResourceOperationTypeEnum.DELETE_EXPORT_INITIATOR.getName(), e.getMessage());
taskCompleter.error(dbClient, serviceError);
} finally {
long totalTime = System.currentTimeMillis() - startTime;
log.info(String.format("findExportMasks took %f seconds", (double) totalTime / (double) 1000));
}
log.info("{} removeInitiator END...", storage.getSerialNumber());
}
use of com.emc.storageos.volumecontroller.impl.validators.hds.AbstractHDSValidator in project coprhd-controller by CoprHD.
the class HDSExportOperations method removeVolumes.
@Override
public void removeVolumes(StorageSystem storage, URI exportMaskURI, List<URI> volumes, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} removeVolumes START...", storage.getSerialNumber());
try {
log.info("removeVolumes: Export mask id: {}", exportMaskURI);
log.info("removeVolumes: volumes: {}", Joiner.on(',').join(volumes));
if (initiatorList != null) {
log.info("removeVolumes: impacted initiators: {}", Joiner.on(",").join(initiatorList));
}
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
String systemObjectID = HDSUtils.getSystemObjectID(storage);
ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
if (CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
log.info("HSD's are not found in the exportMask {} device DataMap.", exportMask.getId());
taskCompleter.ready(dbClient);
}
// Get the context from the task completer, in case this is a rollback.
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(exportMask);
ctx.setBlockObjects(volumes, dbClient);
ctx.setInitiators(initiatorList);
// Allow exceptions to be thrown when not rolling back
ctx.setAllowExceptions(!isRollback);
AbstractHDSValidator removeVolumeFromMaskValidator = (AbstractHDSValidator) validator.removeVolumes(ctx);
removeVolumeFromMaskValidator.validate();
StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
Set<String> hsdList = deviceDataMap.keySet();
List<Path> pathObjectIdList = new ArrayList<Path>();
if (null == hsdList || hsdList.isEmpty()) {
throw HDSException.exceptions.notAbleToFindHostStorageDomain(systemObjectID);
}
if (null != exportMask && !exportMask.getInactive()) {
for (String hsdObjectId : hsdList) {
HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectId);
if (null == hsd) {
log.warn("Couldn't find the HSD {} to remove volume from ExportMask", hsdObjectId);
continue;
}
if (null != hsd.getPathList() && !hsd.getPathList().isEmpty()) {
pathObjectIdList.addAll(getPathObjectIdsFromHsd(hsd, volumes));
}
}
if (!pathObjectIdList.isEmpty()) {
hdsApiClient.getHDSBatchApiExportManager().deleteLUNPathsFromStorageSystem(systemObjectID, pathObjectIdList, storage.getModel());
} else {
log.info("No volumes found on system: {}", systemObjectID);
}
}
// Update the status after deleting the volume from all HSD's.
taskCompleter.ready(dbClient);
} catch (Exception e) {
log.error(String.format("removeVolume failed - maskURI: %s", exportMaskURI.toString()), e);
ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(e.getMessage(), e);
taskCompleter.error(dbClient, serviceError);
}
log.info("{} removeVolumes END...", storage.getSerialNumber());
}
use of com.emc.storageos.volumecontroller.impl.validators.hds.AbstractHDSValidator in project coprhd-controller by CoprHD.
the class HDSExportOperations method deleteExportMask.
@Override
public void deleteExportMask(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} deleteExportMask START...", storage.getSerialNumber());
List<HostStorageDomain> hsdToDeleteList = new ArrayList<HostStorageDomain>();
try {
log.info("deleteExportMask: Export mask id: {}", exportMaskURI);
if (volumeURIList != null) {
log.info("deleteExportMask: volumes: {}", Joiner.on(',').join(volumeURIList));
}
if (targetURIList != null) {
log.info("deleteExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
}
if (initiatorList != null) {
log.info("deleteExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
}
// Get the context from the task completer, in case this is a rollback.
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(exportMask);
ctx.setBlockObjects(volumeURIList, dbClient);
ctx.setInitiators(initiatorList);
// Allow exceptions to be thrown when not rolling back
ctx.setAllowExceptions(!isRollback);
AbstractHDSValidator deleteMaskValidator = (AbstractHDSValidator) validator.exportMaskDelete(ctx);
deleteMaskValidator.validate();
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
String systemObjectId = HDSUtils.getSystemObjectID(storage);
StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
if (null != deviceDataMap && !deviceDataMap.isEmpty()) {
Set<String> hsdObjectIdList = deviceDataMap.keySet();
for (String hsdObjectIdFromDb : hsdObjectIdList) {
HostStorageDomain hsdObj = exportMgr.getHostStorageDomain(systemObjectId, hsdObjectIdFromDb);
if (null != hsdObj) {
hsdToDeleteList.add(hsdObj);
}
}
if (!hsdToDeleteList.isEmpty()) {
hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectId, hsdToDeleteList, storage.getModel());
}
// By this time, we have removed all HSD's created in this mask.
taskCompleter.ready(dbClient);
} else {
String message = String.format("ExportMask %s does not have a configured HSD's, " + "indicating that this export may not have been created " + "successfully. Marking the delete operation ready.", exportMaskURI.toString());
log.info(message);
taskCompleter.ready(dbClient);
return;
}
} catch (Exception e) {
log.error("Unexpected error: deleteExportMask failed.", e);
ServiceError error = DeviceControllerErrors.hds.methodFailed("deleteExportMask", e.getMessage());
taskCompleter.error(dbClient, error);
}
log.info("{} deleteExportMask END...", storage.getSerialNumber());
}
Aggregations