importPackage(org.apache.log4j);
importPackage(com.cloupia.feature.netappController);
importPackage(com.cloupia.feature.netappController.forms);
importPackage(com.cloupia.lib.cIaaS.netapp);
importPackage(com.cloupia.lib.cIaaS.netapp.model);
importPackage(com.cloupia.model.cIM);
importPackage(com.cloupia.service.cIM.inframgr);
importPackage(java.lang);
importPackage(java.util);
function initiateModifyQuota(contextId, user, quotaType , hardDiskLimit , softDiskLimit , hardFileLimit ,
softFileLimit , thresholdLimit) {
var api = null;
var netAppSession = null;
var quota = null;
var identity = null;
try
{
identity = new NetAppClusterQtreeIdentity(contextId);
} catch (e)
{
logger.addError("Exception while parsing qtree identity.");
throw "Exception while parsing qtree identity."+e.message;
}
try
{
quota = StorageDataPersistenceUtil.getNetAppClusterQuotaInfoByTarget(identity.getIdentityKey());
if (quota == null)
{
logger.addError("Found no existing quota instance for : " + identity.getQtree());
throw "Found no existing quota instance for : " + identity.getQtree();
}
var account = InfrastructureDataUtil.getAccount(quota.getAccountName());
if (account == null)
{
throw "Invalid account name.";
}
var sDiskLimit = "-";
var hDiskLimit = "-";
var thresLimit = "-";
var sFileLimit = "-";
var hFileLimit = "-";
// Do Validations
if ((hardDiskLimit != null) && (hardDiskLimit.trim().length() > 0))
{
if(!hardDiskLimit.contains("-"))
{
var d = Double.valueOf(hardDiskLimit.trim()) * 1024;
var l = d * 1024;
hDiskLimit = java.lang.String.valueOf(Long.valueOf(l));
}
}
if ((hardFileLimit != null) && (hardFileLimit.trim().length() > 0))
{
if(!hardFileLimit.contains("-"))
hFileLimit = java.lang.String.valueOf(Long.valueOf(hardFileLimit.trim()));
}
if ((thresholdLimit != null) && (thresholdLimit.trim().length() > 0))
{
if(!thresholdLimit.contains("-"))
{
// thresLimit = String.valueOf(Long.valueOf(thresholdLimit.trim()) * 1024 * 1024);
var d = Double.valueOf(thresholdLimit.trim()) * 1024;
var l = d * 1024;
thresLimit = java.lang.String.valueOf(Long.valueOf(l));
}
}
if ((softDiskLimit != null) && (softDiskLimit.trim().length() > 0))
{
if(!softDiskLimit.contains("-"))
{
// sDiskLimit = String.valueOf(Long.valueOf(softDiskLimit.trim()) * 1024 * 1024);
var d = Double.valueOf(softDiskLimit.trim()) * 1024;
var l = d * 1024;
sDiskLimit = java.lang.String.valueOf(Long.valueOf(l));
}
}
if ((softFileLimit != null) && (softFileLimit.trim().length() > 0))
{
if(!softFileLimit.contains("-"))
sFileLimit = java.lang.String.valueOf(Long.valueOf(softFileLimit.trim()));
}
var qtree = "";
netAppSession = new NetAppSession(account, identity.getvServer());
api = new NetAppAPI(netAppSession);
var isStatusChanged = api.waitForStatus(quota.getVolume());
if (!isStatusChanged)
{
throw "Can not turn off quota. Invalid Volume Quota Status: " + api.getQuotaStatus(quota.getVolume());
}
if (api.getQuotaStatus(quota.getVolume()).equalsIgnoreCase("on"))
{
if (!api.turnQuotaOff(quota.getVolume()))
{
throw "Unable to turn off the quotas on volume " + quota.getVolume();
}
}
var status = api.modifyQuota(quotaType, quota.getQuotaTarget(), quota.getVolume(), qtree, hDiskLimit, hFileLimit,
thresLimit, sDiskLimit, sFileLimit);
if (status)
{
isStatusChanged = api.waitForStatus(quota.getVolume());
if (!isStatusChanged)
{
throw "Can not turn on quota. Invalid Volume Quota Status: " + api.getQuotaStatus(quota.getVolume());
}
// Adding sleep for 10 seconds
try
{
Thread.sleep(10000);
} catch (e)
{
logger.addError("Error "+e.message);
}
if (api.getQuotaStatus(quota.getVolume()).equalsIgnoreCase("off"))
{
if (!api.turnQuotaOn(quota.getVolume()))
{
throw "Unable to turn on the quotas on volume " + quota.getVolume();
}
}
} else
{
throw "Quota modify failed.";
}
performInventoryCollection(identity, account, api);
var quotaInfo = StorageDataPersistenceUtil.getNetAppClusterQuotaInfoByTarget(identity.getIdentityKey());
var volumeId = new NetAppClusterVolumeIdentity(identity.getDcName(),
identity.getAccountName(),identity.getFilerName(),identity.getvServer(), identity.getVolumeName());
var volume = StorageDataPersistenceUtil.getNetAppClusterVolumeByIdentity(volumeId
.getIdentityKey());
NetAppCMDBUtil.getInstance().change(user, ChangeRecord.CHANGE_TYPE_MODIFY,
"Quota modified on qtree " + identity.getQtree() + " on Volume " + identity.getVolumeName(), quotaInfo);
NetAppCMDBUtil.getInstance().change(user, ChangeRecord.CHANGE_TYPE_MODIFY,
"Modified:Modified Quota on qtree " + identity.getQtree() + " on Volume " + identity.getVolumeName(), volume);
logger.addInfo("Quota modified successfully");
} catch (e)
{
logger.addError("Error while modifing quota for Qtree=" + e.message);
throw e.message;
} finally
{
if (api != null)
{
api.close();
}
}
}
function performInventoryCollection(identity, account, api) {
var task = new NetAppInventoryCollectorTask();
try {
task.getVServerQuotasInventory(api, account, identity.getFilerName(), null, null, identity.getvServer());
} catch (e)
{
logger.addError("Inventory collection failed."+e.message);
}
}
var contextId = input.qtree_identity;
var user = "admin";
var quotaType = input.quotaType;
var hardDiskLimit = input.hardDiskLimit;
var softDiskLimit = input.softDiskLimit;
var hardFileLimit = input.hardFileLimit;
var softFileLimit = input.softFileLimit;
var thresholdLimit = input.thresholdLimit;
initiateModifyQuota(contextId,"admin",quotaType,hardDiskLimit,softDiskLimit,hardFileLimit,softFileLimit,thresholdLimit);
Additional Links: