Search in sources :

Example 1 with FreeLun

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;
}
Also used : FreeLun(com.emc.storageos.hds.model.FreeLun) HashMap(java.util.HashMap) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) BlockObject(com.emc.storageos.db.client.model.BlockObject) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 2 with FreeLun

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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FreeLun(com.emc.storageos.hds.model.FreeLun) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) Get(com.emc.storageos.hds.model.Get) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 3 with FreeLun

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);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) FreeLun(com.emc.storageos.hds.model.FreeLun) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

FreeLun (com.emc.storageos.hds.model.FreeLun)3 HashMap (java.util.HashMap)3 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)2 URI (java.net.URI)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 BlockObject (com.emc.storageos.db.client.model.BlockObject)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 StoragePort (com.emc.storageos.db.client.model.StoragePort)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 Get (com.emc.storageos.hds.model.Get)1 StorageArray (com.emc.storageos.hds.model.StorageArray)1 VolumeURIHLU (com.emc.storageos.volumecontroller.impl.VolumeURIHLU)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 JavaResult (org.milyn.payload.JavaResult)1