Search in sources :

Example 6 with NaAPIFailedException

use of netapp.manage.NaAPIFailedException in project coprhd-controller by CoprHD.

the class QuotaCommands method getQuota.

public Quota getQuota(String volume, String quotaTarget, String quotaType, String qtree) {
    NaElement elem = new NaElement("quota-get-entry");
    elem.addNewChild("volume", volume);
    elem.addNewChild("quota-target", quotaTarget);
    elem.addNewChild("quota-type", quotaType);
    elem.addNewChild("qtree", qtree);
    try {
        NaElement result = server.invokeElem(elem);
        Quota quota = new Quota();
        quota.setVolume(volume);
        quota.setQuotaTarget(quotaTarget);
        quota.setQuotaType(quotaType);
        quota.setQtree(qtree);
        quota.setDiskLimit(result.getChildContent("disk-limit"));
        quota.setFileLimit(result.getChildContent("file-limit"));
        quota.setSoftDiskLimit(result.getChildContent("soft-disk-limit"));
        quota.setSoftFileLimit(result.getChildContent("soft-file-limit"));
        quota.setThreshold(result.getChildContent("threshold"));
        return quota;
    } catch (NaAPIFailedException e) {
        if (e.getErrno() == NaErrno.EQUOTADOESNOTEXIST) {
            return null;
        }
        throw createError(elem, e);
    } catch (Exception e) {
        throw createError(elem, e);
    }
}
Also used : NaAPIFailedException(netapp.manage.NaAPIFailedException) Quota(com.iwave.ext.netapp.model.Quota) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException)

Example 7 with NaAPIFailedException

use of netapp.manage.NaAPIFailedException 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 8 with NaAPIFailedException

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

the class NetappManagerImpl method destroyLunOnFiler.

/**
     * This method destroys a lun on the netapp filer
     * @param lunName -- name of the lun to be destroyed
     */
@Override
@DB
public void destroyLunOnFiler(String lunName) throws InvalidParameterValueException, ServerException {
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    LunVO lun = _lunDao.findByName(lunName);
    if (lun == null)
        throw new InvalidParameterValueException("Cannot find lun");
    NetappVolumeVO vol = _volumeDao.acquireInLockTable(lun.getVolumeId());
    if (vol == null) {
        s_logger.warn("Failed to lock volume id= " + lun.getVolumeId());
        return;
    }
    NaServer s = null;
    try {
        s = getServer(vol.getIpAddress(), vol.getUsername(), vol.getPassword());
        if (s_logger.isDebugEnabled())
            s_logger.debug("Request --> destroyLun " + ":serverIp:" + vol.getIpAddress());
        try {
            //Unmap lun
            NaElement xi2 = new NaElement("lun-unmap");
            xi2.addNewChild("initiator-group", lunName);
            xi2.addNewChild("path", lun.getPath() + lun.getLunName());
            s.invokeElem(xi2);
        } catch (NaAPIFailedException naf) {
            if (naf.getErrno() == 9016)
                s_logger.warn("no map exists excpn 9016 caught in deletelun, continuing with delete");
        }
        //destroy lun
        NaElement xi = new NaElement("lun-destroy");
        xi.addNewChild("force", "true");
        xi.addNewChild("path", lun.getPath() + lun.getLunName());
        s.invokeElem(xi);
        //destroy igroup
        NaElement xi1 = new NaElement("igroup-destroy");
        //xi1.addNewChild("force","true");
        xi1.addNewChild("initiator-group-name", lunName);
        s.invokeElem(xi1);
        _lunDao.remove(lun.getId());
        txn.commit();
    } catch (UnknownHostException uhe) {
        txn.rollback();
        s_logger.warn("Failed to delete lun", uhe);
        throw new ServerException("Failed to delete lun", uhe);
    } catch (IOException ioe) {
        txn.rollback();
        s_logger.warn("Failed to delete lun", ioe);
        throw new ServerException("Failed to delete lun", ioe);
    } catch (NaAPIFailedException naf) {
        if (naf.getErrno() == 9017) {
            //no such group exists excpn
            s_logger.warn("no such group exists excpn 9017 caught in deletelun, continuing with delete");
            _lunDao.remove(lun.getId());
            txn.commit();
        } else if (naf.getErrno() == 9029) {
            //LUN maps for this initiator group exist
            s_logger.warn("LUN maps for this initiator group exist errno 9029 caught in deletelun, continuing with delete");
            _lunDao.remove(lun.getId());
            txn.commit();
        } else {
            txn.rollback();
            s_logger.warn("Failed to delete lun", naf);
            throw new ServerException("Failed to delete lun", naf);
        }
    } catch (NaException nae) {
        txn.rollback();
        s_logger.warn("Failed to delete lun", nae);
        throw new ServerException("Failed to delete lun", nae);
    } finally {
        if (vol != null) {
            _volumeDao.releaseFromLockTable(vol.getId());
        }
        if (s != null)
            s.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) NaAPIFailedException(netapp.manage.NaAPIFailedException) 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) DB(com.cloud.utils.db.DB)

Example 9 with NaAPIFailedException

use of netapp.manage.NaAPIFailedException in project coprhd-controller by CoprHD.

the class FlexFileShare method setCIFSAcl.

public void setCIFSAcl(CifsAcl acl) {
    NaElement elem = new NaElement("cifs-share-access-control-modify");
    elem.addNewChild("share", acl.getShareName());
    elem.addNewChild("permission", acl.getAccess().access());
    if (acl.getUserName() != null) {
        elem.addNewChild("user-or-group", acl.getUserName());
    }
    if (acl.getGroupName() != null) {
        elem.addNewChild("user-or-group", acl.getGroupName());
    }
    try {
        server.invokeElem(elem);
    } catch (NaAPIFailedException e) {
        String msg = "Failed to set CIFS Acl: " + acl;
        log.error(msg, e);
        throw new NetAppCException(msg, e, e.getErrno());
    } catch (Exception e) {
        String msg = "Failed to set CIFS Acl: " + acl;
        log.error(msg, e);
        throw new NetAppCException(msg, e);
    }
}
Also used : NaAPIFailedException(netapp.manage.NaAPIFailedException) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException)

Aggregations

NaAPIFailedException (netapp.manage.NaAPIFailedException)9 NaElement (netapp.manage.NaElement)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 IOException (java.io.IOException)4 ServerException (java.rmi.ServerException)4 NaException (netapp.manage.NaException)4 NaServer (netapp.manage.NaServer)4 DB (com.cloud.utils.db.DB)3 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)3 UnknownHostException (java.net.UnknownHostException)3 Quota (com.iwave.ext.netapp.model.Quota)2 ResourceInUseException (com.cloud.exception.ResourceInUseException)1 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1