Search in sources :

Example 1 with NaServer

use of netapp.manage.NaServer in project cloudstack by apache.

the class NetappManagerImpl method associateLun.

/**
     * This method associates a lun to a particular igroup
     * @param iqn
     * @param iGroup
     * @param lunName
     */
@Override
public String[] associateLun(String guestIqn, String lunName) throws ServerException, InvalidParameterValueException {
    NaElement xi2;
    //get lun id from path
    String[] splitLunName = lunName.split("-");
    String[] returnVal = new String[3];
    if (splitLunName.length != 2)
        throw new InvalidParameterValueException("The lun id is malformed");
    String lunIdStr = splitLunName[1];
    Long lId = new Long(lunIdStr);
    LunVO lun = _lunDao.findById(lId);
    if (lun == null)
        throw new InvalidParameterValueException("Cannot find LUN " + lunName);
    NetappVolumeVO vol = _volumeDao.findById(lun.getVolumeId());
    //assert(vol != null);
    returnVal[0] = lunIdStr;
    returnVal[1] = lun.getTargetIqn();
    returnVal[2] = vol.getIpAddress();
    NaServer s = null;
    try {
        s = getServer(vol.getIpAddress(), vol.getUsername(), vol.getPassword());
        if (s_logger.isDebugEnabled())
            s_logger.debug("Request --> associateLun " + ":serverIp:" + vol.getIpAddress());
        //add iqn to the group
        xi2 = new NaElement("igroup-add");
        xi2.addNewChild("force", "true");
        xi2.addNewChild("initiator", guestIqn);
        xi2.addNewChild("initiator-group-name", lunName);
        s.invokeElem(xi2);
        return returnVal;
    } catch (UnknownHostException uhe) {
        s_logger.warn("Unable to associate LUN ", uhe);
        throw new ServerException("Unable to associate LUN", uhe);
    } catch (NaAPIFailedException naf) {
        if (naf.getErrno() == 9008) {
            //initiator group already contains node
            return returnVal;
        }
        s_logger.warn("Unable to associate LUN ", naf);
        throw new ServerException("Unable to associate LUN", naf);
    } catch (NaException nae) {
        s_logger.warn("Unable to associate LUN ", nae);
        throw new ServerException("Unable to associate LUN", nae);
    } catch (IOException ioe) {
        s_logger.warn("Unable to associate LUN ", ioe);
        throw new ServerException("Unable to associate LUN", ioe);
    } finally {
        if (s != null)
            s.close();
    }
}
Also used : ServerException(java.rmi.ServerException) UnknownHostException(java.net.UnknownHostException) NaServer(netapp.manage.NaServer) IOException(java.io.IOException) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NaException(netapp.manage.NaException)

Example 2 with NaServer

use of netapp.manage.NaServer in project cloudstack by apache.

the class NetappManagerImpl method destroyVolumeOnFiler.

/**
     * This method destroys the volume on netapp filer
     * @param ipAddress -- ip address of filer
     * @param aggrName -- name of containing aggregate
     * @param volName -- name of volume to destroy
     * @throws ResourceInUseException
     * @throws NaException
     * @throws NaAPIFailedException
     */
@Override
@DB
public void destroyVolumeOnFiler(String ipAddress, String aggrName, String volName) throws ServerException, InvalidParameterValueException, ResourceInUseException {
    NaElement xi0;
    NaElement xi1;
    NetappVolumeVO volume = null;
    volume = _volumeDao.findVolume(ipAddress, aggrName, volName);
    if (volume == null) {
        s_logger.warn("The volume does not exist in our system");
        throw new InvalidParameterValueException("The given tuple:" + ipAddress + "," + aggrName + "," + volName + " doesn't exist in our system");
    }
    List<LunVO> lunsOnVol = _lunDao.listLunsByVolId(volume.getId());
    if (lunsOnVol != null && lunsOnVol.size() > 0) {
        s_logger.warn("There are luns on the volume");
        throw new ResourceInUseException("There are luns on the volume");
    }
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    PoolVO pool = _poolDao.findById(volume.getPoolId());
    if (pool == null) {
        throw new InvalidParameterValueException("Failed to find pool for given volume");
    //FIXME: choose a better exception. this is a db integrity exception
    }
    pool = _poolDao.acquireInLockTable(pool.getId());
    if (pool == null) {
        throw new ConcurrentModificationException("Failed to acquire lock on pool " + volume.getPoolId());
    }
    NaServer s = null;
    try {
        s = getServer(volume.getIpAddress(), volume.getUsername(), volume.getPassword());
        //bring the volume down
        xi0 = new NaElement("volume-offline");
        xi0.addNewChild("name", volName);
        s.invokeElem(xi0);
        //now destroy it
        xi1 = new NaElement("volume-destroy");
        xi1.addNewChild("name", volName);
        s.invokeElem(xi1);
        //now delete from our records
        _volumeDao.remove(volume.getId());
        txn.commit();
    } catch (UnknownHostException uhe) {
        s_logger.warn("Unable to delete volume on filer ", uhe);
        throw new ServerException("Unable to delete volume on filer", uhe);
    } catch (NaAPIFailedException naf) {
        s_logger.warn("Unable to delete volume on filer ", naf);
        if (naf.getErrno() == 13040) {
            s_logger.info("Deleting the volume: " + volName);
            _volumeDao.remove(volume.getId());
            txn.commit();
        }
        throw new ServerException("Unable to delete volume on filer", naf);
    } catch (NaException nae) {
        txn.rollback();
        s_logger.warn("Unable to delete volume on filer ", nae);
        throw new ServerException("Unable to delete volume on filer", nae);
    } catch (IOException ioe) {
        txn.rollback();
        s_logger.warn("Unable to delete volume on filer ", ioe);
        throw new ServerException("Unable to delete volume on filer", ioe);
    } finally {
        if (pool != null) {
            _poolDao.releaseFromLockTable(pool.getId());
        }
        if (s != null)
            s.close();
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) ServerException(java.rmi.ServerException) UnknownHostException(java.net.UnknownHostException) NaServer(netapp.manage.NaServer) IOException(java.io.IOException) NaElement(netapp.manage.NaElement) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) NaAPIFailedException(netapp.manage.NaAPIFailedException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceInUseException(com.cloud.exception.ResourceInUseException) NaException(netapp.manage.NaException) DB(com.cloud.utils.db.DB)

Example 3 with NaServer

use of netapp.manage.NaServer in project cloudstack by apache.

the class NetappManagerImpl method disassociateLun.

/**
     * This method disassociates a lun from the igroup on the filer
     * @param iGroup -- igroup name
     * @param lunName -- lun name
     */
@Override
public void disassociateLun(String iGroup, String lunName) throws ServerException, InvalidParameterValueException {
    NaElement xi;
    LunVO lun = _lunDao.findByName(lunName);
    if (lun == null)
        throw new InvalidParameterValueException("Cannot find LUN " + lunName);
    NetappVolumeVO vol = _volumeDao.findById(lun.getVolumeId());
    NaServer s = null;
    try {
        s = getServer(vol.getIpAddress(), vol.getUsername(), vol.getPassword());
        if (s_logger.isDebugEnabled())
            s_logger.debug("Request --> disassociateLun " + ":serverIp:" + vol.getIpAddress());
        xi = new NaElement("igroup-remove");
        xi.addNewChild("force", "true");
        xi.addNewChild("initiator", iGroup);
        xi.addNewChild("initiator-group-name", lunName);
        s.invokeElem(xi);
    } catch (UnknownHostException uhe) {
        throw new ServerException("Failed to disassociate lun", uhe);
    } catch (IOException ioe) {
        throw new ServerException("Failed to disassociate lun", ioe);
    } catch (NaException nae) {
        throw new ServerException("Failed to disassociate lun", nae);
    } finally {
        if (s != null)
            s.close();
    }
}
Also used : ServerException(java.rmi.ServerException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NaException(netapp.manage.NaException) NaServer(netapp.manage.NaServer) IOException(java.io.IOException) NaElement(netapp.manage.NaElement)

Example 4 with NaServer

use of netapp.manage.NaServer in project cloudstack by apache.

the class NetappManagerImpl method createLunOnFiler.

/**
     * This method creates a lun on the netapp filer
     * @param poolName -- name of the pool
     * @param lunSize -- size of the lun to be created
     * @return -- lun path
     * @throws IOException
     * @throws ResourceAllocationException
     * @throws NaException
     */
@Override
@DB
public String[] createLunOnFiler(String poolName, Long lunSize) throws ServerException, InvalidParameterValueException, ResourceAllocationException {
    String[] result = new String[3];
    StringBuilder lunName = new StringBuilder("lun-");
    LunVO lun = null;
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    PoolVO pool = _poolDao.findPool(poolName);
    if (pool == null) {
        throw new InvalidParameterValueException("Cannot find pool " + poolName);
    }
    if (lunSize <= 0) {
        throw new InvalidParameterValueException("Please specify a valid lun size in Gb");
    }
    String algorithm = pool.getAlgorithm();
    NetappVolumeVO selectedVol = null;
    //sanity check
    int numVolsInPool = _volumeDao.listVolumes(poolName).size();
    if (numVolsInPool == 0) {
        throw new InvalidParameterValueException("No volumes exist in the given pool");
    }
    pool = _poolDao.acquireInLockTable(pool.getId());
    if (pool == null) {
        s_logger.warn("Failed to acquire lock on the pool " + poolName);
        return result;
    }
    NaServer s = null;
    try {
        if (algorithm == null || algorithm.equals(Algorithm.roundrobin.toString())) {
            selectedVol = _netappAllocator.chooseVolumeFromPool(poolName, lunSize);
        } else if (algorithm.equals(Algorithm.leastfull.toString())) {
            selectedVol = _netappAllocator.chooseLeastFullVolumeFromPool(poolName, lunSize);
        }
        if (selectedVol == null) {
            throw new ServerException("Could not find a suitable volume to create lun on");
        }
        if (s_logger.isDebugEnabled())
            s_logger.debug("Request --> createLun " + "serverIp:" + selectedVol.getIpAddress());
        StringBuilder exportPath = new StringBuilder("/vol/");
        exportPath.append(selectedVol.getVolumeName());
        exportPath.append("/");
        lun = new LunVO(exportPath.toString(), selectedVol.getId(), lunSize, "", "");
        lun = _lunDao.persist(lun);
        //Lun id created: 6 digits right justified eg. 000045
        String lunIdStr = String.valueOf(lun.getId());
        String zeroStr = "000000";
        int length = lunIdStr.length();
        int offset = 6 - length;
        StringBuilder lunIdOnPath = new StringBuilder();
        lunIdOnPath.append(zeroStr.substring(0, offset));
        lunIdOnPath.append(lunIdStr);
        exportPath.append("lun-").append(lunIdOnPath.toString());
        lunName.append(lunIdOnPath.toString());
        //update lun name
        lun.setLunName(lunName.toString());
        _lunDao.update(lun.getId(), lun);
        NaElement xi;
        NaElement xi1;
        //This prevents integer overflow
        long lSizeBytes = 1L * lunSize * 1024 * 1024 * 1024;
        Long lunSizeBytes = new Long(lSizeBytes);
        s = getServer(selectedVol.getIpAddress(), selectedVol.getUsername(), selectedVol.getPassword());
        //create lun
        xi = new NaElement("lun-create-by-size");
        xi.addNewChild("ostype", "linux");
        xi.addNewChild("path", exportPath.toString());
        xi.addNewChild("size", (lunSizeBytes.toString()));
        s.invokeElem(xi);
        try {
            //now create an igroup
            xi1 = new NaElement("igroup-create");
            xi1.addNewChild("initiator-group-name", lunName.toString());
            xi1.addNewChild("initiator-group-type", "iscsi");
            xi1.addNewChild("os-type", "linux");
            s.invokeElem(xi1);
        } catch (NaAPIFailedException e) {
            if (e.getErrno() == 9004) {
                //igroup already exists hence no error
                s_logger.warn("Igroup already exists");
            }
        }
        //get target iqn
        NaElement xi4 = new NaElement("iscsi-node-get-name");
        NaElement xo = s.invokeElem(xi4);
        String iqn = xo.getChildContent("node-name");
        lun.setTargetIqn(iqn);
        _lunDao.update(lun.getId(), lun);
        //create lun mapping
        //now map the lun to the igroup
        NaElement xi3 = new NaElement("lun-map");
        xi3.addNewChild("force", "true");
        xi3.addNewChild("initiator-group", lunName.toString());
        xi3.addNewChild("path", lun.getPath() + lun.getLunName());
        xi3.addNewChild("lun-id", lunIdStr);
        s.invokeElem(xi3);
        txn.commit();
        //set the result
        //lunname
        result[0] = lunName.toString();
        //iqn
        result[1] = iqn;
        result[2] = selectedVol.getIpAddress();
        return result;
    } catch (NaAPIFailedException naf) {
        if (naf.getErrno() == 9023) {
            //lun is already mapped to this group
            //lunname;
            result[0] = lunName.toString();
            //iqn
            result[1] = lun.getTargetIqn();
            result[2] = selectedVol.getIpAddress();
            return result;
        }
        if (naf.getErrno() == 9024) {
            //another lun mapped at this group
            //lunname;
            result[0] = lunName.toString();
            //iqn
            result[1] = lun.getTargetIqn();
            result[2] = selectedVol.getIpAddress();
            return result;
        }
    } catch (NaException nae) {
        txn.rollback();
        throw new ServerException("Unable to create LUN", nae);
    } catch (IOException ioe) {
        txn.rollback();
        throw new ServerException("Unable to create LUN", ioe);
    } finally {
        if (pool != null) {
            _poolDao.releaseFromLockTable(pool.getId());
        }
        if (s != null) {
            s.close();
        }
    }
    return result;
}
Also used : ServerException(java.rmi.ServerException) NaServer(netapp.manage.NaServer) IOException(java.io.IOException) NaElement(netapp.manage.NaElement) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) NaAPIFailedException(netapp.manage.NaAPIFailedException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NaException(netapp.manage.NaException) DB(com.cloud.utils.db.DB)

Example 5 with NaServer

use of netapp.manage.NaServer in project cloudstack by apache.

the class NetappManagerImpl method returnAvailableVolumeSize.

/**
     * This method returns the available size on the volume in terms of bytes
     * @param volName -- name of volume
     * @param userName -- username
     * @param password -- password
     * @param serverIp -- ip address of filer
     * @throws UnknownHostException
     * @return-- available size on the volume in terms of bytes; return -1 if volume is offline
     * @throws ServerException
     */
@Override
public long returnAvailableVolumeSize(String volName, String userName, String password, String serverIp) throws ServerException {
    long availableSize = 0;
    NaElement xi = new NaElement("volume-list-info");
    xi.addNewChild("volume", volName);
    NaServer s = null;
    String volumeState = null;
    try {
        s = getServer(serverIp, userName, password);
        NaElement xo = s.invokeElem(xi);
        List volList = xo.getChildByName("volumes").getChildren();
        Iterator volIter = volList.iterator();
        while (volIter.hasNext()) {
            NaElement volInfo = (NaElement) volIter.next();
            availableSize = volInfo.getChildLongValue("size-available", -1);
            volumeState = volInfo.getChildContent("state");
        }
        if (volumeState != null) {
            //return -1 if volume is offline
            return volumeState.equalsIgnoreCase("online") ? availableSize : -1;
        } else {
            // as good as volume offline
            return -1;
        }
    } catch (NaException nae) {
        s_logger.warn("Failed to get volume size ", nae);
        throw new ServerException("Failed to get volume size", nae);
    } catch (IOException ioe) {
        s_logger.warn("Failed to get volume size ", ioe);
        throw new ServerException("Failed to get volume size", ioe);
    } finally {
        if (s != null)
            s.close();
    }
}
Also used : ServerException(java.rmi.ServerException) Iterator(java.util.Iterator) NaException(netapp.manage.NaException) NaServer(netapp.manage.NaServer) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) NaElement(netapp.manage.NaElement)

Aggregations

NaServer (netapp.manage.NaServer)10 IOException (java.io.IOException)8 ServerException (java.rmi.ServerException)8 NaElement (netapp.manage.NaElement)8 NaException (netapp.manage.NaException)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 DB (com.cloud.utils.db.DB)4 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)4 UnknownHostException (java.net.UnknownHostException)4 NaAPIFailedException (netapp.manage.NaAPIFailedException)4 ConcurrentModificationException (java.util.ConcurrentModificationException)2 ResourceInUseException (com.cloud.exception.ResourceInUseException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1