use of com.emc.storageos.vnxe.models.VNXUnityQuotaConfig in project coprhd-controller by CoprHD.
the class VNXUnityUnManagedObjectDiscoverer method discoverAllTreeQuotas.
public void discoverAllTreeQuotas(AccessProfile accessProfile, DbClient dbClient, PartitionManager partitionManager) {
StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
VNXeApiClient apiClient = getVnxUnityClient(accessProfile);
log.info("discoverAllTreeQuotas for storage system {} - start", storageSystem.getId());
unManagedTreeQuotaInsert = new ArrayList<UnManagedFileQuotaDirectory>();
unManagedTreeQuotaUpdate = new ArrayList<UnManagedFileQuotaDirectory>();
List<VNXUnityTreeQuota> treeQuotas = apiClient.getAllTreeQuotas();
for (VNXUnityTreeQuota quota : treeQuotas) {
log.info("Discovered fS tree quota {}", quota.toString());
VNXeFileSystem fs = null;
if (quota.getFilesystem() != null) {
fs = apiClient.getFileSystemByFSId(quota.getFilesystem().getId());
String fsNativeGUID = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber(), fs.getId());
try {
if (checkStorageFileSystemExistsInDB(fsNativeGUID, dbClient)) {
log.info("Skipping file system {} as it is already managed by ViPR", fsNativeGUID);
continue;
}
String nativeUnmanagedGUID = NativeGUIDGenerator.generateNativeGuidForPreExistingQuotaDirectory(storageSystem.getSystemType(), storageSystem.getSerialNumber(), quota.getId());
VNXUnityQuotaConfig qc = apiClient.getQuotaConfigById(quota.getQuotaConfigId());
UnManagedFileQuotaDirectory unManagedFileQuotaDirectory = getExistingUnManagedQuotaDirectory(dbClient, nativeUnmanagedGUID);
boolean existingUnManagedQD = true;
if (unManagedFileQuotaDirectory == null) {
unManagedFileQuotaDirectory = new UnManagedFileQuotaDirectory();
existingUnManagedQD = false;
unManagedFileQuotaDirectory.setId(URIUtil.createId(UnManagedFileQuotaDirectory.class));
}
unManagedFileQuotaDirectory.setLabel(quota.getPath().substring(1));
unManagedFileQuotaDirectory.setNativeGuid(nativeUnmanagedGUID);
unManagedFileQuotaDirectory.setParentFSNativeGuid(fsNativeGUID);
unManagedFileQuotaDirectory.setSize(quota.getHardLimit());
Long size = quota.getHardLimit() > 0 ? quota.getHardLimit() : fs.getSizeAllocated();
Long softLimit = 0L;
if (quota.getSoftLimit() > 0) {
softLimit = quota.getSoftLimit() * 100 / size;
int softGrace = qc.getGracePeriod() / (24 * 60 * 60);
unManagedFileQuotaDirectory.setSoftGrace(softGrace);
}
unManagedFileQuotaDirectory.setSoftLimit(softLimit.intValue());
unManagedFileQuotaDirectory.setNotificationLimit(0);
unManagedFileQuotaDirectory.setNativeId(quota.getId());
if (!existingUnManagedQD) {
unManagedTreeQuotaInsert.add(unManagedFileQuotaDirectory);
} else {
unManagedTreeQuotaUpdate.add(unManagedFileQuotaDirectory);
}
} catch (IOException e) {
log.error("IOException occured in discoverAllTreeQuotas()", e);
}
}
}
if (!unManagedTreeQuotaInsert.isEmpty()) {
// Add UnManagedFileSystem
partitionManager.insertInBatches(unManagedTreeQuotaInsert, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_FILEQUOTADIR);
unManagedTreeQuotaInsert.clear();
}
if (!unManagedTreeQuotaUpdate.isEmpty()) {
// Update UnManagedFilesystem
partitionManager.updateInBatches(unManagedTreeQuotaUpdate, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_FILEQUOTADIR);
unManagedTreeQuotaUpdate.clear();
}
}
Aggregations