use of com.emc.storageos.hds.model.FreeLun in project coprhd-controller by CoprHD.
the class HDSExportOperations method getVolumeLunMap.
/**
* @param volumeURIHLUs
* @return
* @throws Exception
*/
private Map<String, String> getVolumeLunMap(String systemId, String hsdObjectID, VolumeURIHLU[] volumeURIHLUs, HDSApiExportManager exportMgr) throws Exception {
List<FreeLun> freeLunList = exportMgr.getFreeLUNInfo(systemId, hsdObjectID);
log.info("There are {} freeLUN's available for HSD Id {}", freeLunList.size(), hsdObjectID);
Map<String, String> volumeHLUMap = new HashMap<String, String>();
int i = 0;
String lun = null;
for (VolumeURIHLU volumeURIHLU : volumeURIHLUs) {
BlockObject volume = BlockObject.fetch(dbClient, volumeURIHLU.getVolumeURI());
if (null == volumeURIHLU.getHLU() || "-1".equalsIgnoreCase(volumeURIHLU.getHLU())) {
if (i < freeLunList.size()) {
FreeLun freeLun = freeLunList.get(i);
lun = freeLun.getLun();
log.info("HLU is unassigned for volume {} and assinging lun {} from array.", volumeURIHLU.getVolumeURI(), lun);
i++;
} else {
// received request to create more volumes than the free luns available on the array.
log.info("No free LUN's available on HSD {}", hsdObjectID);
throw HDSException.exceptions.unableToProcessRequestDueToUnavailableFreeLUNs();
}
} else {
log.info("HLU {} is assigned for volume {} and using the free lun from array.", volumeURIHLU.getHLU(), volumeURIHLU.getVolumeURI());
lun = volumeURIHLU.getHLU();
}
volumeHLUMap.put(volume.getNativeId(), lun);
}
return volumeHLUMap;
}
use of com.emc.storageos.hds.model.FreeLun 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.FreeLun in project coprhd-controller by CoprHD.
the class HDSProtectionOperations method addDummyLunPath.
/**
* Adds Dummy Lun Path to Secondary Volume for pair creation
*
* @param client
* @param volume
* @throws Exception
*/
public void addDummyLunPath(HDSApiClient client, BlockObject volume) throws Exception {
StorageSystem system = dbClient.queryObject(StorageSystem.class, volume.getStorageController());
String systemObjectId = HDSUtils.getSystemObjectID(system);
ReentrantLock lock = null;
try {
/**
* This will take care synchronization between all cluster node.
* So that same time two different node can not add same lun to different volumes.
* This will not take care within the same node.
*/
locker.acquireLock(systemObjectId, HDSConstants.LOCK_WAIT_SECONDS);
/**
* We create and maintain lock instance per storage system.
* So that multiple thread can not add same lun number to different volumes on same storage system.
*/
lock = getLock(systemObjectId);
lock.lock();
log.info("Acquired Lock to add lun path");
HostStorageDomain hsd = getDummyHSDFromStorageSystem(client, systemObjectId);
if (null == hsd) {
log.info("Creating dummy HSD for ShadowImage");
// Get any port which belongs to the storage system.
URIQueryResultList storagePortURIs = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(system.getId()), storagePortURIs);
StoragePort storagePort = null;
Iterator<URI> storagePortsIter = storagePortURIs.iterator();
while (storagePortsIter.hasNext()) {
URI storagePortURI = storagePortsIter.next();
storagePort = dbClient.queryObject(StoragePort.class, storagePortURI);
if (storagePort != null && !storagePort.getInactive()) {
break;
}
}
if (storagePort != null) {
String portId = HDSUtils.getPortID(storagePort);
hsd = client.getHDSApiExportManager().addHostStorageDomain(systemObjectId, portId, HDSConstants.HOST_GROUP_DOMAIN_TYPE, null, HDSConstants.DUMMY_HSD, null, null, system.getModel());
log.info("Created dummy HSD on {} portid", portId);
}
}
List<FreeLun> freeLunList = client.getHDSApiExportManager().getFreeLUNInfo(systemObjectId, hsd.getObjectID());
log.debug("freeLunList.size :{}", freeLunList.size());
log.debug("Free lun:{}", freeLunList.get(0).getLun());
Map<String, String> deviceLunList = new HashMap<String, String>();
deviceLunList.put(volume.getNativeId(), freeLunList.get(0).getLun());
client.getHDSApiExportManager().addLUN(systemObjectId, hsd.getPortID(), hsd.getDomainID(), deviceLunList, system.getModel());
log.info("Completed addDummyLunPath method");
} finally {
if (lock != null) {
lock.unlock();
log.info("Released Lock to add lun path");
}
locker.releaseLock(systemObjectId);
}
}
Aggregations