use of netapp.manage.NaAPIFailedException 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();
}
}
use of netapp.manage.NaAPIFailedException 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();
}
}
use of netapp.manage.NaAPIFailedException in project coprhd-controller by CoprHD.
the class FlexFileShare method addCIFSAcl.
/**
* this function add new acl
*
* @param acl
*/
public void addCIFSAcl(CifsAcl acl) {
NaElement elem = new NaElement("cifs-share-access-control-create");
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 create CIFS Acl: " + acl;
log.error(msg, e);
throw new NetAppCException(msg, e, e.getErrno());
} catch (Exception e) {
String msg = "Failed to create CIFS Acl: " + acl;
log.error(msg, e);
throw new NetAppCException(msg, e);
}
}
use of netapp.manage.NaAPIFailedException in project coprhd-controller by CoprHD.
the class FileShare method setCIFSAcl.
public void setCIFSAcl(CifsAcl acl) {
NaElement elem = new NaElement("cifs-share-ace-set");
elem.addNewChild("share-name", acl.getShareName());
elem.addNewChild("access-rights", acl.getAccess().access());
if (acl.getUserName() != null) {
elem.addNewChild("user-name", acl.getUserName());
}
if (acl.getGroupName() != null) {
elem.addNewChild("unix-group-name", acl.getGroupName());
elem.addNewChild("is-unixgroup", "true");
}
try {
server.invokeElem(elem);
} catch (NaAPIFailedException e) {
String msg = "Failed to set CIFS Acl: " + acl;
log.error(msg, e);
throw new NetAppException(msg, e, e.getErrno());
} catch (Exception e) {
String msg = "Failed to set CIFS Acl: " + acl;
log.error(msg, e);
throw new NetAppException(msg, e);
}
}
use of netapp.manage.NaAPIFailedException in project coprhd-controller by CoprHD.
the class QuotaCommands method getQuotas.
public List<Quota> getQuotas() {
NaElement elem = new NaElement("quota-list-entries-iter");
try {
List<Quota> quotas = Lists.newArrayList();
NaElement result = server.invokeElem(elem);
List<NaElement> quotaElems = new ArrayList<NaElement>();
// Add the Quotas for first call
quotaElems.addAll((List<NaElement>) result.getChildByName("attributes-list").getChildren());
// Make further server invokes if more quotas are present
while (result.getChildByName("next-tag") != null) {
NaElement tempElem = new NaElement("quota-list-entries-iter");
tempElem.addNewChild("tag", result.getChildContent("next-tag"));
result = server.invokeElem(tempElem);
quotaElems.addAll((List<NaElement>) result.getChildByName("attributes-list").getChildren());
}
for (NaElement quotaElem : quotaElems) {
Quota quota = new Quota();
quota.setVolume(quotaElem.getChildContent("volume"));
quota.setQuotaTarget(quotaElem.getChildContent("quota-target"));
quota.setQuotaType(quotaElem.getChildContent("quota-type"));
quota.setQtree(quotaElem.getChildContent("qtree"));
quota.setDiskLimit(quotaElem.getChildContent("disk-limit"));
quota.setFileLimit(quotaElem.getChildContent("file-limit"));
quota.setSoftDiskLimit(quotaElem.getChildContent("soft-disk-limit"));
quota.setSoftFileLimit(quotaElem.getChildContent("soft-file-limit"));
quota.setThreshold(quotaElem.getChildContent("threshold"));
quotas.add(quota);
}
return quotas;
} catch (NaAPIFailedException e) {
if (e.getErrno() == NaErrno.EQUOTADOESNOTEXIST) {
return null;
}
throw createError(elem, e);
} catch (Exception e) {
throw createError(elem, e);
}
}
Aggregations