use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.
the class HDSApiExportManager method constructRemoveISCSIQuery.
/**
* Construct the iSCSINames Query by adding multiple WWNs.
* This query should be used to add the iSCSI initiators to the iSCSI HSD.
*
* @param systemId
* @param hsdId
* @param wwnList
* @return
*/
private String constructRemoveISCSIQuery(String systemId, String hsdId, List<String> scsiNameList, String model) {
Map<String, Object> attributeMap = new HashMap<String, Object>();
StorageArray array = new StorageArray(systemId);
Delete deleteOp = new Delete(HDSConstants.ISCSI_NAME_FOR_HSD_TARGET);
attributeMap.put(HDSConstants.STORAGEARRAY, array);
attributeMap.put(HDSConstants.DELETE, deleteOp);
attributeMap.put(HDSConstants.MODEL, model);
HostStorageDomain hsd = new HostStorageDomain(hsdId);
attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, hsd);
List<ISCSIName> iSCSIObjList = new ArrayList<ISCSIName>();
if (null != scsiNameList && !scsiNameList.isEmpty()) {
for (String iScsiName : scsiNameList) {
ISCSIName iSCSIName = new ISCSIName(iScsiName, null);
iSCSIObjList.add(iSCSIName);
}
}
attributeMap.put(HDSConstants.ISCSINAME_LIST, iSCSIObjList);
String removeISCSINamesToHSDQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.REMOVE_ISCSI_NAME_FROM_HSD_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
return removeISCSINamesToHSDQuery;
}
use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.
the class HDSApiExportManager method getFreeLUNInfo.
/**
* Return the Free Lun's available for a Given HSD in a System.
*
* @throws Exception
*/
public List<FreeLun> getFreeLUNInfo(String systemId, String hsdId) throws Exception {
InputStream responseStream = null;
HostStorageDomain hostStorageDomain = null;
List<FreeLun> freeLunList = null;
try {
Map<String, Object> attributeMap = new HashMap<String, Object>();
StorageArray array = new StorageArray(systemId);
Get getOp = new Get(HDSConstants.STORAGEARRAY);
attributeMap.put(HDSConstants.STORAGEARRAY, array);
HostStorageDomain hsd = new HostStorageDomain(hsdId);
FreeLun freeLun = new FreeLun();
attributeMap.put(HDSConstants.GET, getOp);
attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, hsd);
attributeMap.put(HDSConstants.FREELUN, freeLun);
String getFreeLunQueryInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_FREE_LUN_INFO_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
log.info("Query to get FreeLUN's of a HostStorageDomain: {}", getFreeLunQueryInputXML);
URI endpointURI = hdsApiClient.getBaseURI();
ClientResponse response = hdsApiClient.post(endpointURI, getFreeLunQueryInputXML);
if (HttpStatus.SC_OK == response.getStatus()) {
responseStream = response.getEntityInputStream();
JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
verifyErrorPayload(javaResult);
hostStorageDomain = javaResult.getBean(HostStorageDomain.class);
if (null != hostStorageDomain && null != hostStorageDomain.getFreeLunList()) {
freeLunList = hostStorageDomain.getFreeLunList();
} else {
throw HDSException.exceptions.notAbleToGetFreeLunInfoForHSD(hsdId, systemId);
}
} else {
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to get FreeLun info for HostStorageDomain due to invalid response %1$s from server", response.getStatus()));
}
} finally {
if (null != responseStream) {
try {
responseStream.close();
} catch (IOException e) {
log.warn("IOException occurred while closing the response stream");
}
}
}
return freeLunList;
}
use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.
the class HDSBatchApiExportManager method addHostStorageDomains.
/**
* This method makes http POST call with a payload of bulk
* HostStorageDomains.
*
* @param systemId
* - SystemObjectID.
* @param hostGroups
* - List of HostStorageDomain objects.
* @return - Returns a List of created HostStorageDomain on Array.
* @throws Exception
* - In case processing errors.
*/
public List<HostStorageDomain> addHostStorageDomains(String systemId, List<HostStorageDomain> hostGroups, String model) throws Exception {
InputStream responseStream = null;
List<HostStorageDomain> hsdList = null;
try {
Map<String, Object> attributeMap = new HashMap<String, Object>();
StorageArray array = new StorageArray(systemId);
Add addOp = new Add(HDSConstants.HOST_STORAGE_DOMAIN);
attributeMap.put(HDSConstants.STORAGEARRAY, array);
attributeMap.put(HDSConstants.ADD, addOp);
attributeMap.put(HDSConstants.MODEL, model);
attributeMap.put(HDSConstants.HOSTGROUP_LIST, hostGroups);
String addHSDToSystemQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.BATCH_ADD_HSDS_TO_SYSTEM_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
log.info("Batch query to create HostStorageDomains: {}", addHSDToSystemQuery);
URI endpointURI = hdsApiClient.getBaseURI();
ClientResponse response = hdsApiClient.post(endpointURI, addHSDToSystemQuery);
if (HttpStatus.SC_OK == response.getStatus()) {
responseStream = response.getEntityInputStream();
JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
verifyErrorPayload(javaResult);
hsdList = (List<HostStorageDomain>) javaResult.getBean(HDSConstants.HSD_RESPONSE_BEAN_ID);
if (null == hsdList || hsdList.isEmpty()) {
throw HDSException.exceptions.notAbleToAddHSD(systemId);
}
} else {
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to add HostStorageDomains due to invalid response %1$s from server", response.getStatus()));
}
} finally {
if (null != responseStream) {
try {
responseStream.close();
} catch (IOException e) {
log.warn("IOException occurred while closing the response stream addHostStorageDomains");
}
}
}
return hsdList;
}
use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.
the class HDSBatchApiExportManager method deleteBatchHostStorageDomains.
/**
* This method makes a HTTP POST call to delete all HostStorageDomain's
* using a batch query.
*
* @param systemId
* - Represents storage system ObjectID.
* @param hsdList
* - List of HostStorageDomain objects to delete.
* @param model - Model of the system
*
* @throws Exception
*/
public void deleteBatchHostStorageDomains(String systemId, List<HostStorageDomain> hsdList, String model) throws Exception {
InputStream responseStream = null;
try {
List<HostStorageDomain> unDeletedHSDs = new ArrayList<>();
unDeletedHSDs.addAll(hsdList);
boolean operationSucceeds = false;
int retryCount = 0;
StringBuilder errorDescriptionBuilder = new StringBuilder();
while (!operationSucceeds && retryCount < MAX_RETRIES) {
retryCount++;
String deleteHSDsQuery = constructDeleteHSDsQuery(systemId, unDeletedHSDs, model);
log.info("Batch Query to delete HSD's: {}", deleteHSDsQuery);
URI endpointURI = hdsApiClient.getBaseURI();
ClientResponse response = hdsApiClient.post(endpointURI, deleteHSDsQuery);
if (HttpStatus.SC_OK == response.getStatus()) {
responseStream = response.getEntityInputStream();
JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
try {
verifyErrorPayload(javaResult);
// If no exception then operation succeeds
operationSucceeds = true;
} catch (HDSException hdsException) {
Error error = javaResult.getBean(Error.class);
if (error != null && (error.getDescription().contains("2010") || error.getDescription().contains("5132") || error.getDescription().contains("7473"))) {
log.error("Error response recieved from HiCommandManger: {}", error.getDescription());
log.info("Exception from HICommand Manager recieved during delete operation, retrying operation {} time", retryCount);
errorDescriptionBuilder.append("error ").append(retryCount).append(" : ").append(error.getDescription()).append("-#####-");
// Wait for a minute before retry
Thread.sleep(60000);
unDeletedHSDs.clear();
unDeletedHSDs.addAll(hsdList.stream().filter(hsd -> getHostStorageDomain(systemId, hsd.getObjectID()) != null).collect(Collectors.toList()));
if (unDeletedHSDs.isEmpty()) {
// Operation succeeded
operationSucceeds = true;
log.info("Deleted {} LUN paths from system:{}", hsdList.size(), systemId);
} else {
// Retry the operation again if retry count not exceeded
continue;
}
} else {
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomains due to invalid response from server. Error Code - %s Error Message - %s", error.getCode(), error.getDescription()));
}
}
} else {
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomains due to invalid response %1$s from server", response.getStatus()));
}
}
if (!operationSucceeds) {
// Delete operation failed ever after repeated retries
throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomains due to repeated errors from HiCommand server, errors description are as %s", errorDescriptionBuilder.toString()));
}
} finally {
if (null != responseStream) {
try {
responseStream.close();
} catch (IOException e) {
log.warn("IOException occurred while closing the response stream");
}
}
}
log.info("Batch Query to delete HSD's completed.");
}
use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.
the class HDSExportMaskInitiatorsValidator method validate.
@Override
public boolean validate() throws Exception {
log.info("Initiating initiators validation of HDS ExportMask: {}", id);
try {
ExportMask exportMask = getExportMask();
StorageSystem system = getStorage();
if (exportMask != null && !CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
Set<String> hsdList = exportMask.getDeviceDataMap().keySet();
HDSApiClient client = getClientFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(system), system.getSmisUserName(), system.getSmisPassword());
HDSApiExportManager exportManager = client.getHDSApiExportManager();
String maskName = null;
String systemObjectID = HDSUtils.getSystemObjectID(system);
Set<String> volumesInExportMask = new HashSet<>();
Set<String> initiatorsInExportMask = new HashSet<>();
if (!CollectionUtils.isEmpty(exportMask.getUserAddedVolumes())) {
volumesInExportMask.addAll(exportMask.getUserAddedVolumes().keySet());
}
if (!CollectionUtils.isEmpty(exportMask.getUserAddedInitiators())) {
initiatorsInExportMask.addAll(exportMask.getUserAddedInitiators().keySet());
}
log.info("Volumes {} in Export Mask {}", volumesInExportMask, exportMask.forDisplay());
log.info("Initiators {} in Export Mask {}", initiatorsInExportMask, exportMask.forDisplay());
for (String hsdObjectIdFromDb : hsdList) {
Set<String> discoveredVolumes = new HashSet<>();
HostStorageDomain hsd = exportManager.getHostStorageDomain(systemObjectID, hsdObjectIdFromDb);
if (null == hsd) {
continue;
}
maskName = (null == hsd.getName()) ? hsd.getNickname() : hsd.getName();
// Get volumes and initiators from storage system
discoveredVolumes.addAll(HDSUtils.getVolumesFromHSD(hsd, system).keySet());
log.info("Volumes {} discovered from array for the HSD {}", discoveredVolumes, maskName);
Set<String> additionalVolumesOnArray = Sets.difference(discoveredVolumes, volumesInExportMask);
if (!CollectionUtils.isEmpty(additionalVolumesOnArray)) {
getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "volumes", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalVolumesOnArray));
}
}
checkForErrors();
}
} catch (Exception ex) {
log.error("Unexpected exception validating ExportMask initiators: " + ex.getMessage(), ex);
if (getValidatorConfig().isValidationEnabled()) {
throw DeviceControllerException.exceptions.unexpectedCondition("Unexpected exception validating ExportMask initiators: " + ex.getMessage());
}
}
return true;
}
Aggregations