use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.
the class HDSExportOperations method addInitiators.
@Override
public void addInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiators, List<URI> targetURIList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} addInitiator START...", storage.getSerialNumber());
HDSApiClient hdsApiClient = null;
String systemObjectID = null;
List<HostStorageDomain> hsdsToCreate = null;
List<HostStorageDomain> hsdsWithInitiators = null;
try {
log.info("addInitiator: Export mask id: {}", exportMaskURI);
if (volumeURIs != null) {
log.info("addInitiator: volumes : {}", Joiner.on(',').join(volumeURIs));
}
log.info("addInitiator: initiators : {}", Joiner.on(',').join(initiators));
log.info("addInitiator: targets : {}", Joiner.on(",").join(targetURIList));
hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
systemObjectID = HDSUtils.getSystemObjectID(storage);
ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
List<StoragePort> ports = dbClient.queryObject(StoragePort.class, targetURIList, true);
if (checkIfMixedTargetPortTypeSelected(ports)) {
log.error("Unsupported Host as it has both FC & iSCSI Initiators");
throw HDSException.exceptions.unsupportedConfigurationFoundInHost();
}
// @TODO register new initiators by adding them to host on HiCommand DM.
// Currently, HiCommand is not supporting this. Need to see how we can handle.
String hostName = getHostNameForInitiators(initiators);
String hostMode = null, hostModeOption = null;
Pair<String, String> hostModeInfo = getHostModeInfo(storage, initiators);
if (hostModeInfo != null) {
hostMode = hostModeInfo.first;
hostModeOption = hostModeInfo.second;
}
if (targetURIList != null && !targetURIList.isEmpty()) {
Set<URI> newTargetPorts = new HashSet<>(targetURIList);
Set<URI> existingTargetPortsInMask = new HashSet<>();
if (exportMask.getStoragePorts() != null) {
existingTargetPortsInMask = new HashSet<>(targetURIList);
Collection<URI> targetPorts = Collections2.transform(exportMask.getStoragePorts(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
existingTargetPortsInMask.retainAll(targetPorts);
}
newTargetPorts.removeAll(existingTargetPortsInMask);
log.info("list of new storage target ports {}", newTargetPorts);
log.info("list of existing storage target ports available in export masks {}", existingTargetPortsInMask);
// Case 1 is handled here for the new initiators & new target ports.
if (!newTargetPorts.isEmpty()) {
// If the HLU's are already configured on this target port, then an exception is thrown.
// User should make sure that all volumes should have same HLU across all target HSD's.
VolumeURIHLU[] volumeURIHLUs = getVolumeURIHLUFromExportMask(exportMask);
if (0 < volumeURIHLUs.length) {
List<URI> portList = new ArrayList<>(newTargetPorts);
hsdsToCreate = processTargetPortsToFormHSDs(hdsApiClient, storage, portList, hostName, exportMask, hostModeInfo, systemObjectID);
// Step 1: Create all HSD's using batch operation.
List<HostStorageDomain> hsdResponseList = hdsApiClient.getHDSBatchApiExportManager().addHostStorageDomains(systemObjectID, hsdsToCreate, storage.getModel());
if (null == hsdResponseList || hsdResponseList.isEmpty()) {
log.error("Batch HSD creation failed to add new initiators. Aborting operation...");
throw HDSException.exceptions.notAbleToAddHSD(storage.getSerialNumber());
}
// Step 2: Add initiators to all HSD's.
Iterator<StoragePort> storagePortIterator = dbClient.queryIterativeObjects(StoragePort.class, newTargetPorts);
List<StoragePort> stPortList = new ArrayList<>();
while (storagePortIterator.hasNext()) {
StoragePort stPort = storagePortIterator.next();
if (stPort != null && !stPort.getInactive()) {
stPortList.add(stPort);
}
}
hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, stPortList, initiators, storage.getModel());
// Step 3: Add volumes to all HSD's.
List<Path> allHSDPaths = executeBatchHSDAddVolumesCommand(hdsApiClient, systemObjectID, hsdsWithInitiators, volumeURIHLUs, storage.getModel());
if (null != allHSDPaths && !allHSDPaths.isEmpty()) {
updateExportMaskDetailInDB(hsdsWithInitiators, allHSDPaths, exportMask, storage, volumeURIHLUs);
}
} else {
log.info("There are no volumes on this exportmask: {} to add to new initiator", exportMaskURI);
}
}
// existing HSD to access the volumes already exported in the exportmask.
if (!existingTargetPortsInMask.isEmpty()) {
// Step 1: Collect all HSDs from export mask
StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
if (null != deviceDataMap && !deviceDataMap.isEmpty()) {
List<HostStorageDomain> hsdResponseList = new ArrayList<>();
Set<String> hsdObjectIdSet = deviceDataMap.keySet();
for (String hsdObjectId : hsdObjectIdSet) {
HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectId);
if (null == hsd) {
throw HDSException.exceptions.notAbleToFindHostStorageDomain(hsdObjectId);
}
hsdResponseList.add(hsd);
}
// Step 2: Add initiators to all HSD's.
Iterator<StoragePort> storagePortIterator = dbClient.queryIterativeObjects(StoragePort.class, existingTargetPortsInMask, true);
List<StoragePort> stPortList = new ArrayList<>();
while (storagePortIterator.hasNext()) {
StoragePort stPort = storagePortIterator.next();
if (stPort != null) {
stPortList.add(stPort);
}
}
hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, stPortList, initiators, storage.getModel());
} else {
log.info("There are no hsd information in exportMask to add initiators");
}
}
}
taskCompleter.ready(dbClient);
} catch (Exception ex) {
try {
log.info("Exception occurred while adding new initiators: {}", ex.getMessage());
if (null != hsdsWithInitiators && !hsdsWithInitiators.isEmpty()) {
hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectID, hsdsWithInitiators, storage.getModel());
} else {
if (null != hsdsToCreate && !hsdsToCreate.isEmpty()) {
List<HostStorageDomain> allHSDs = hdsApiClient.getHDSApiExportManager().getHostStorageDomains(systemObjectID);
List<HostStorageDomain> partialHSDListToRemove = getPartialHSDListToDelete(allHSDs, hsdsToCreate);
hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectID, partialHSDListToRemove, storage.getModel());
}
}
log.error(String.format("addInitiator failed - maskURI: %s", exportMaskURI.toString()), ex);
} catch (Exception ex1) {
log.error("Exception occurred while deleting unsuccessful HSDs on system: {}", systemObjectID, ex1.getMessage());
} finally {
ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(ResourceOperationTypeEnum.ADD_EXPORT_INITIATOR.getName(), ex.getMessage());
taskCompleter.error(dbClient, serviceError);
}
}
log.info("{} addInitiator END...", storage.getSerialNumber());
}
use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.
the class HDSMirrorOperations method deleteSingleVolumeMirror.
/**
* Deletes mirror instance from StorageSystem
*/
@Override
public void deleteSingleVolumeMirror(StorageSystem storageSystem, URI mirror, TaskCompleter taskCompleter) throws DeviceControllerException {
try {
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Mirror Start - Array:%s", storageSystem.getSerialNumber()));
Set<String> thickLogicalUnitIdList = new HashSet<String>();
Set<String> thinLogicalUnitIdList = new HashSet<String>();
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
String systemObjectID = HDSUtils.getSystemObjectID(storageSystem);
BlockMirror mirrorObj = dbClient.queryObject(BlockMirror.class, mirror);
logMsgBuilder.append(String.format("%nMirror:%s", mirrorObj.getLabel()));
String logicalUnitObjectId = HDSUtils.getLogicalUnitObjectId(mirrorObj.getNativeId(), storageSystem);
LogicalUnit logicalUnit = hdsApiClient.getLogicalUnitInfo(systemObjectID, logicalUnitObjectId);
if (logicalUnit == null) {
// related volume state (if any) has been deleted. skip
// processing, if already deleted from array.
log.info(String.format("Mirror %s already deleted: ", mirrorObj.getNativeId()));
// HDSMirrorOperations.removeReferenceFromSourceVolume(dbClient, mirrorObj);
dbClient.markForDeletion(mirrorObj);
} else {
if (mirrorObj.getThinlyProvisioned()) {
thinLogicalUnitIdList.add(logicalUnitObjectId);
} else {
thickLogicalUnitIdList.add(logicalUnitObjectId);
}
log.info(logMsgBuilder.toString());
if (!thickLogicalUnitIdList.isEmpty()) {
String asyncThickLUsJobId = hdsApiClient.deleteThickLogicalUnits(systemObjectID, thickLogicalUnitIdList, storageSystem.getModel());
if (null != asyncThickLUsJobId) {
ControllerServiceImpl.enqueueJob(new QueueJob(new HDSBlockMirrorDeleteJob(asyncThickLUsJobId, mirrorObj.getStorageController(), taskCompleter)));
} else {
throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the delete mirror call");
}
}
if (!thinLogicalUnitIdList.isEmpty()) {
String asyncThinHDSJobId = hdsApiClient.deleteThinLogicalUnits(systemObjectID, thinLogicalUnitIdList, storageSystem.getModel());
if (null != asyncThinHDSJobId) {
ControllerServiceImpl.enqueueJob(new QueueJob(new HDSBlockMirrorDeleteJob(asyncThinHDSJobId, mirrorObj.getStorageController(), taskCompleter)));
} else {
throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the delete mirror call");
}
}
}
log.info("Delete Mirror End - Array: {} Mirror: {}", storageSystem.getSerialNumber(), mirror);
} catch (Exception e) {
log.error("Problem in deleteSingleVolumeMirror: ", e);
ServiceError error = DeviceControllerErrors.hds.methodFailed("deleteSingleVolumeMirror", e.getMessage());
taskCompleter.error(dbClient, error);
}
}
use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.
the class HDSProtectionOperations method deleteShadowImagePair.
/**
* Deletes shadowImage Pair
*
* @param storageSystem
* @param source
* @param target
* @throws Exception
*/
public void deleteShadowImagePair(StorageSystem storageSystem, Volume source, Volume target) throws Exception {
log.info("Delete pair operation started");
HDSApiClient apiClient = HDSUtils.getHDSApiClient(hdsApiFactory, storageSystem);
HDSApiProtectionManager apiProtectionManager = apiClient.getHdsApiProtectionManager();
Map<String, String> repliMap = apiProtectionManager.getReplicationRelatedObjectIds(source.getNativeId(), target.getNativeId());
log.info("Replication Obj Ids :{}", repliMap);
String replicationGroupObjId = repliMap.get(HDSConstants.REPLICATION_GROUP_OBJ_ID);
String replicationInfoObjId = repliMap.get(HDSConstants.REPLICATION_INFO_OBJ_ID);
apiProtectionManager.deleteShadowImagePair(replicationGroupObjId, replicationInfoObjId, storageSystem.getModel());
log.info("Delete pair operation completed");
}
use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.
the class HDSProtectionOperations method createSecondaryVolumeForSnapshot.
/**
* Creates Snapshot Volume
*
* @param storageSystem
* @param sourceVolume
* @param snapshotObj
* @throws Exception
*/
public void createSecondaryVolumeForSnapshot(StorageSystem storageSystem, Volume sourceVolume, BlockSnapshot snapshotObj) throws Exception {
log.info("SecondaryVolume for snapshot creation operation started");
String taskId = UUID.randomUUID().toString();
TaskCompleter taskCompleter = new BlockSnapshotCreateCompleter(Arrays.asList(snapshotObj.getId()), taskId);
String asyncTaskMessageId = null;
HDSApiClient hdsApiClient = HDSUtils.getHDSApiClient(hdsApiFactory, storageSystem);
String systemObjectID = HDSUtils.getSystemObjectID(storageSystem);
asyncTaskMessageId = hdsApiClient.createSnapshotVolume(systemObjectID, sourceVolume.getCapacity(), storageSystem.getModel());
if (asyncTaskMessageId != null) {
HDSJob createHDSJob = new HDSBlockCreateSnapshotJob(asyncTaskMessageId, snapshotObj.getStorageController(), taskCompleter);
hdsCommandHelper.waitForAsyncHDSJob(createHDSJob);
} else {
throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the create snapshot volume call");
}
log.info("SecondaryVolume for snapshot creation operation completed successfully");
}
use of com.emc.storageos.hds.api.HDSApiClient in project coprhd-controller by CoprHD.
the class HDSProtectionOperations method modifyShadowImagePair.
/**
* Modifies pair operation to split|resync|restore
*
* @param storageSystem
* @param sourceVolumeNativeId
* @param targetVolumeNativeId
* @param operationType
* @throws Exception
*/
public boolean modifyShadowImagePair(StorageSystem storageSystem, String sourceVolumeNativeId, String targetVolumeNativeId, HDSApiProtectionManager.ShadowImageOperationType operationType) throws Exception {
HDSApiClient apiClient = HDSUtils.getHDSApiClient(hdsApiFactory, storageSystem);
HDSApiProtectionManager apiProtectionManager = apiClient.getHdsApiProtectionManager();
log.info("{} pair operation started", operationType.name());
Map<String, String> repliMap = apiProtectionManager.getReplicationRelatedObjectIds(sourceVolumeNativeId, targetVolumeNativeId);
log.info("Replication Obj Ids :{}", repliMap);
String replicationGroupObjId = repliMap.get(HDSConstants.REPLICATION_GROUP_OBJ_ID);
String replicationInfoObjId = repliMap.get(HDSConstants.REPLICATION_INFO_OBJ_ID);
ReplicationInfo replicationInfo = apiProtectionManager.modifyShadowImagePair(replicationGroupObjId, replicationInfoObjId, operationType, storageSystem.getModel());
log.info("{} pair operation completed", operationType.name());
return (replicationInfo != null);
}
Aggregations