Search in sources :

Example 6 with NaException

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

the class NetappManagerImpl method returnSnapshotSchedule.

/**
     * Utility method to return snapshot schedule for a volume
     * @param vol -- volume for the snapshot schedule creation
     * @return -- the snapshot schedule
     * @throws ServerException
     */
private String returnSnapshotSchedule(NetappVolumeVO vol) throws ServerException {
    NaElement xi = new NaElement("snapshot-get-schedule");
    xi.addNewChild("volume", vol.getVolumeName());
    NaServer s = null;
    try {
        s = getServer(vol.getIpAddress(), vol.getUsername(), vol.getPassword());
        NaElement xo = s.invokeElem(xi);
        String weeks = xo.getChildContent("weeks");
        String days = xo.getChildContent("days");
        String hours = xo.getChildContent("hours");
        String minutes = xo.getChildContent("minutes");
        String whichHours = xo.getChildContent("which-hours");
        String whichMinutes = xo.getChildContent("which-minutes");
        StringBuilder sB = new StringBuilder();
        sB.append(weeks).append(" ").append(days).append(" ").append(hours).append("@").append(whichHours).append(" ").append(minutes).append("@").append(whichMinutes);
        return sB.toString();
    } 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) NaException(netapp.manage.NaException) NaServer(netapp.manage.NaServer) IOException(java.io.IOException) NaElement(netapp.manage.NaElement)

Example 7 with NaException

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

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

the class NetappManagerImpl method createVolumeOnFiler.

/**
     * This method creates a volume on netapp filer
     * @param ipAddress -- ip address of the filer
     * @param aggName -- name of aggregate
     * @param poolName -- name of pool
     * @param volName -- name of volume
     * @param volSize -- size of volume to be created
     * @param snapshotPolicy -- associated snapshot policy for volume
     * @param snapshotReservation -- associated reservation for snapshots
     * @param username -- username
     * @param password -- password
     * @throws UnknownHostException
     * @throws InvalidParameterValueException
     */
@Override
@DB
public void createVolumeOnFiler(String ipAddress, String aggName, String poolName, String volName, String volSize, String snapshotPolicy, Integer snapshotReservation, String username, String password) throws UnknownHostException, ServerException, InvalidParameterValueException {
    if (s_logger.isDebugEnabled())
        s_logger.debug("Request --> createVolume " + "serverIp:" + ipAddress);
    boolean snapPolicy = false;
    boolean snapshotRes = false;
    boolean volumeCreated = false;
    NaServer s = getServer(ipAddress, username, password);
    NaElement xi = new NaElement("volume-create");
    xi.addNewChild("volume", volName);
    xi.addNewChild("containing-aggr-name", aggName);
    xi.addNewChild("size", volSize);
    NaElement xi1 = new NaElement("snapshot-set-reserve");
    if (snapshotReservation != null) {
        snapshotRes = true;
        xi1.addNewChild("percentage", snapshotReservation.toString());
        xi1.addNewChild("volume", volName);
    }
    NaElement xi2 = new NaElement("snapshot-set-schedule");
    if (snapshotPolicy != null) {
        snapPolicy = true;
        String weeks = null;
        String days = null;
        String hours = null;
        String whichHours = null;
        String minutes = null;
        String whichMinutes = null;
        StringTokenizer s1 = new StringTokenizer(snapshotPolicy, " ");
        if (s1.hasMoreTokens()) {
            weeks = s1.nextToken();
        }
        if (weeks != null && s1.hasMoreTokens()) {
            days = s1.nextToken();
        }
        if (days != null && s1.hasMoreTokens()) {
            String[] hoursArr = s1.nextToken().split("@");
            hours = hoursArr[0];
            whichHours = hoursArr[1];
        }
        if (hours != null && s1.hasMoreTokens()) {
            String[] minsArr = s1.nextToken().split("@");
            minutes = minsArr[0];
            whichMinutes = minsArr[1];
        }
        if (weeks != null)
            xi2.addNewChild("weeks", weeks);
        if (days != null)
            xi2.addNewChild("days", days);
        if (hours != null)
            xi2.addNewChild("hours", hours);
        if (minutes != null)
            xi2.addNewChild("minutes", minutes);
        xi2.addNewChild("volume", volName);
        if (whichHours != null)
            xi2.addNewChild("which-hours", whichHours);
        if (whichMinutes != null)
            xi2.addNewChild("which-minutes", whichMinutes);
    }
    Long volumeId = null;
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    NetappVolumeVO volume = null;
    volume = _volumeDao.findVolume(ipAddress, aggName, volName);
    if (volume != null) {
        throw new InvalidParameterValueException("The volume for the given ipAddress/aggregateName/volumeName tuple already exists");
    }
    PoolVO pool = _poolDao.findPool(poolName);
    if (pool == null) {
        throw new InvalidParameterValueException("Cannot find pool " + poolName);
    }
    pool = _poolDao.acquireInLockTable(pool.getId());
    if (pool == null) {
        s_logger.warn("Failed to acquire lock on pool " + poolName);
        throw new ConcurrentModificationException("Failed to acquire lock on pool " + poolName);
    }
    volume = new NetappVolumeVO(ipAddress, aggName, pool.getId(), volName, volSize, "", 0, username, password, 0, pool.getName());
    volume = _volumeDao.persist(volume);
    volumeId = volume.getId();
    try {
        s.invokeElem(xi);
        volumeCreated = true;
        if (snapshotRes) {
            s.invokeElem(xi1);
            volume.setSnapshotReservation(snapshotReservation);
            _volumeDao.update(volumeId, volume);
        }
        if (snapPolicy) {
            s.invokeElem(xi2);
            volume.setSnapshotPolicy(snapshotPolicy);
            _volumeDao.update(volumeId, volume);
        }
        txn.commit();
    } catch (NaException nae) {
        //zapi call failed, log and throw e
        s_logger.warn("Failed to create volume on the netapp filer:", nae);
        txn.rollback();
        if (volumeCreated) {
            try {
                //deletes created volume on filer
                deleteRogueVolume(volName, s);
            } catch (NaException e) {
                s_logger.warn("Failed to cleanup created volume whilst rolling back on the netapp filer:", e);
                throw new ServerException("Unable to create volume via cloudtools." + "Failed to cleanup created volume on netapp filer whilst rolling back on the cloud db:", e);
            } catch (IOException e) {
                s_logger.warn("Failed to cleanup created volume whilst rolling back on the netapp filer:", e);
                throw new ServerException("Unable to create volume via cloudtools." + "Failed to cleanup created volume on netapp filer whilst rolling back on the cloud db:", e);
            }
        }
        throw new ServerException("Unable to create volume", nae);
    } catch (IOException ioe) {
        s_logger.warn("Failed to create volume on the netapp filer:", ioe);
        txn.rollback();
        if (volumeCreated) {
            try {
                //deletes created volume on filer
                deleteRogueVolume(volName, s);
            } catch (NaException e) {
                s_logger.warn("Failed to cleanup created volume whilst rolling back on the netapp filer:", e);
                throw new ServerException("Unable to create volume via cloudtools." + "Failed to cleanup created volume on netapp filer whilst rolling back on the cloud db:", e);
            } catch (IOException e) {
                s_logger.warn("Failed to cleanup created volume whilst rolling back on the netapp filer:", e);
                throw new ServerException("Unable to create volume via cloudtools." + "Failed to cleanup created volume on netapp filer whilst rolling back on the cloud db:", e);
            }
        }
        throw new ServerException("Unable to create volume", ioe);
    } finally {
        if (s != null)
            s.close();
        if (pool != null)
            _poolDao.releaseFromLockTable(pool.getId());
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) ServerException(java.rmi.ServerException) NaServer(netapp.manage.NaServer) IOException(java.io.IOException) NaElement(netapp.manage.NaElement) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StringTokenizer(java.util.StringTokenizer) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NaException(netapp.manage.NaException) DB(com.cloud.utils.db.DB)

Aggregations

IOException (java.io.IOException)8 ServerException (java.rmi.ServerException)8 NaElement (netapp.manage.NaElement)8 NaException (netapp.manage.NaException)8 NaServer (netapp.manage.NaServer)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