use of com.iwave.ext.netapp.model.Quota 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);
}
}
use of com.iwave.ext.netapp.model.Quota 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);
}
}
use of com.iwave.ext.netapp.model.Quota in project coprhd-controller by CoprHD.
the class MiscTests method test8.
@Test
public void test8() {
List<Quota> quotas = netAppFacade.listQuotas();
for (Quota quota : quotas) {
System.out.println("Quota:");
System.out.println(" quotaTarget: " + quota.getQuotaTarget());
System.out.println(" quotaType: " + quota.getQuotaType());
System.out.println(" volume: " + quota.getVolume());
System.out.println(" qtree: " + quota.getQtree());
System.out.println(" diskUsed: " + quota.getDiskUsed());
System.out.println(" diskLimit: " + quota.getDiskLimit());
System.out.println(" softDiskLimit: " + quota.getSoftDiskLimit());
System.out.println(" threshold: " + quota.getThreshold());
System.out.println(" filesUsed: " + quota.getFilesUsed());
System.out.println(" fileLimit: " + quota.getFileLimit());
System.out.println(" softFileLimit: " + quota.getSoftFileLimit());
System.out.println(" vfiler: " + quota.getVfiler());
}
}
use of com.iwave.ext.netapp.model.Quota in project coprhd-controller by CoprHD.
the class QuotaCommands method quotaReport.
public List<Quota> quotaReport(String path, String volume) {
NaElement elem = new NaElement("quota-report");
if (StringUtils.isNotBlank(path)) {
elem.addNewChild("path", path);
}
if (StringUtils.isNotBlank(volume)) {
elem.addNewChild("volume", volume);
}
NaElement resultElem = null;
try {
resultElem = server.invokeElem(elem);
} catch (Exception e) {
throw createError(elem, e);
}
List<Quota> quotas = Lists.newArrayList();
for (NaElement e : (List<NaElement>) resultElem.getChildren()) {
if ("error".equalsIgnoreCase(e.getName())) {
String errno = e.getChildContent("errno");
String reason = e.getChildContent("reason");
String message = String.format("%s: %s", errno, reason);
throw new NetAppException(message);
} else if ("quotas".equalsIgnoreCase(e.getName())) {
for (NaElement quotaElem : (List<NaElement>) e.getChildren()) {
Quota quota = new Quota();
quota.setQtree(quotaElem.getChildContent("tree"));
quota.setDiskLimit(quotaElem.getChildContent("disk-limit"));
quota.setDiskUsed(quotaElem.getChildContent("disk-used"));
quota.setFileLimit(quotaElem.getChildContent("file-limit"));
quota.setFilesUsed(quotaElem.getChildContent("files-used"));
quota.setQuotaTarget(quotaElem.getChildContent("quota-target"));
quota.setQuotaType(quotaElem.getChildContent("quota-type"));
quota.setSoftDiskLimit(quotaElem.getChildContent("soft-disk-limit"));
quota.setSoftFileLimit(quotaElem.getChildContent("soft-file-limit"));
quota.setThreshold(quotaElem.getChildContent("threshold"));
quota.setVfiler(quotaElem.getChildContent("vfiler"));
quota.setVolume(quotaElem.getChildContent("volume"));
// users
NaElement quotaUsersElem = (NaElement) quotaElem.getChildByName("quota-users");
if (quotaUsersElem != null) {
for (NaElement quotaUserElem : (List<NaElement>) quotaUsersElem.getChildren()) {
QuotaUser quotaUser = new QuotaUser();
quotaUser.setUserId(quotaUserElem.getChildContent("quota-user-id"));
quotaUser.setUserName(quotaUserElem.getChildContent("quota-user-name"));
quotaUser.setUserType(quotaUserElem.getChildContent("quota-user-type"));
quota.getQuotaUsers().add(quotaUser);
}
}
quotas.add(quota);
}
}
}
return quotas;
}
use of com.iwave.ext.netapp.model.Quota in project coprhd-controller by CoprHD.
the class NetAppClusterModeCommIntf method discoverUmanagedFileQuotaDirectory.
private void discoverUmanagedFileQuotaDirectory(AccessProfile profile) {
URI storageSystemId = profile.getSystemId();
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
if (null == storageSystem) {
return;
}
NetAppClusterApi netAppCApi = new NetAppClusterApi.Builder(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword()).https(true).build();
try {
// Retrieve all the qtree info.
List<Qtree> qtrees = netAppCApi.listQtrees();
List<Quota> quotas;
try {
// Currently there are no API's available to check the quota status in general
// TODO check weather quota is on before doing this call
quotas = netAppCApi.listQuotas();
} catch (Exception e) {
_logger.error("Error while fetching quotas", e.getMessage());
return;
}
if (quotas != null) {
Map<String, Qtree> qTreeNameQTreeMap = new HashMap<>();
qtrees.forEach(qtree -> {
if (qtree.getQtree() != null && !qtree.getQtree().equals("")) {
qTreeNameQTreeMap.put(qtree.getVolume() + qtree.getQtree(), qtree);
}
});
List<UnManagedFileQuotaDirectory> unManagedFileQuotaDirectories = new ArrayList<>();
List<UnManagedFileQuotaDirectory> existingUnManagedFileQuotaDirectories = new ArrayList<>();
String tempVolume = null;
String tempQuotaTree = null;
String tempQuotaTarget = null;
for (Quota quota : quotas) {
/* Temporary fix TODO
* Fix for situations where QuotaTree is null
* Extracting QuotaTree id from quotaTarget.
*/
if ("".equals(quota.getQtree())) {
tempQuotaTarget = quota.getQuotaTarget();
tempVolume = quota.getVolume();
if (!"".equals(tempVolume)) {
Pattern pattern = Pattern.compile(tempVolume + "/(.*$)");
Matcher matcher = pattern.matcher(tempQuotaTarget);
if (matcher.find()) {
tempQuotaTree = matcher.group(1);
}
if ("".equals(tempQuotaTree)) {
continue;
}
quota.setQtree(tempQuotaTree);
} else {
continue;
}
}
String fsNativeId;
if (quota.getVolume().startsWith(VOL_ROOT)) {
fsNativeId = quota.getVolume();
} else {
fsNativeId = VOL_ROOT + quota.getVolume();
}
if (fsNativeId.contains(ROOT_VOL)) {
_logger.info("Ignore and not discover root filesystem on NTP array");
continue;
}
String fsNativeGUID = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber(), fsNativeId);
String nativeGUID = NativeGUIDGenerator.generateNativeGuidForQuotaDir(storageSystem.getSystemType(), storageSystem.getSerialNumber(), quota.getQtree(), quota.getVolume());
String nativeUnmanagedGUID = NativeGUIDGenerator.generateNativeGuidForUnManagedQuotaDir(storageSystem.getSystemType(), storageSystem.getSerialNumber(), quota.getQtree(), quota.getVolume());
if (checkStorageQuotaDirectoryExistsInDB(nativeGUID)) {
continue;
}
UnManagedFileQuotaDirectory unManagedFileQuotaDirectory = new UnManagedFileQuotaDirectory();
unManagedFileQuotaDirectory.setId(URIUtil.createId(UnManagedFileQuotaDirectory.class));
unManagedFileQuotaDirectory.setLabel(quota.getQtree());
unManagedFileQuotaDirectory.setNativeGuid(nativeUnmanagedGUID);
unManagedFileQuotaDirectory.setParentFSNativeGuid(fsNativeGUID);
unManagedFileQuotaDirectory.setNativeId("/vol/" + quota.getVolume() + "/" + quota.getQtree());
if ("enabled".equals(qTreeNameQTreeMap.get(quota.getVolume() + quota.getQtree()).getOplocks())) {
unManagedFileQuotaDirectory.setOpLock(true);
}
unManagedFileQuotaDirectory.setSize(Long.valueOf(quota.getDiskLimit()));
if (!checkUnManagedQuotaDirectoryExistsInDB(nativeUnmanagedGUID)) {
unManagedFileQuotaDirectories.add(unManagedFileQuotaDirectory);
} else {
existingUnManagedFileQuotaDirectories.add(unManagedFileQuotaDirectory);
}
}
if (!unManagedFileQuotaDirectories.isEmpty()) {
_partitionManager.insertInBatches(unManagedFileQuotaDirectories, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILEQUOTADIR);
}
if (!existingUnManagedFileQuotaDirectories.isEmpty()) {
_partitionManager.updateAndReIndexInBatches(existingUnManagedFileQuotaDirectories, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILEQUOTADIR);
}
}
} catch (NetAppException ve) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
}
_logger.error("discoverStorage failed. Storage system: " + storageSystemId);
throw ve;
} catch (Exception e) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
}
_logger.error("discoverStorage failed. Storage system: " + storageSystemId, e);
throw NetAppException.exceptions.discoveryFailed(storageSystemId.toString(), e);
}
}
Aggregations