Hi Kernal Team,
In RegistryCleanUpTask we need to load all the tenant's registry and delete
some expired registry resources.
I think it may lead to OOM issue if we load all the tenants in a loop since
it takes 30 minutes (default) to unload a tenant.
Can we forcefully unload tenants once the deletion is done in the loop
using PrivilegedCarbonContext.unloadTenant() method?
Is there a way to check whether a tenant is not utilized at a given time?
Following is the sample code of RegistryCleanUpTask.
Registry registry;
Collection identityDataResource;
try {
Tenant[] tenants =
IdentityMgtServiceComponent.getRealmService().getTenantManager().getAllTenants();
for (int i = 0; i < tenants.length + 1; i++) {
Tenant tenant;
if ( i == tenants.length) {
tenant = new Tenant();
tenant.setDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
tenant.setId(MultitenantConstants.SUPER_TENANT_ID);
} else {
tenant = tenants[i];
}
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain());
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId());
try {
registry = IdentityMgtServiceComponent.getRegistryService().
getConfigSystemRegistry(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
identityDataResource = (Collection)
registry.get(CONFIRMATION_REGISTRY_RESOURCE_PATH);
String[] identityResourcesPaths =
identityDataResource.getChildren();
for (int j = 0; j < identityResourcesPaths.length; j++) {
try {
Resource currentResource =
registry.get(identityResourcesPaths[j]);
if (currentResource instanceof Collection) {
Collection secondaryStoreCollection =
(Collection) currentResource;
String[] secondaryStoreResourcePaths =
secondaryStoreCollection.getChildren();
for (int k = 0; k <
secondaryStoreResourcePaths.length; k++) {
checkAndDeleteRegistryResource(registry,
secondaryStoreResourcePaths[k]);
}
} else {
checkAndDeleteRegistryResource(registry,
identityResourcesPaths[j]);
}
} catch (RegistryException e) {
log.error("Error while retrieving resource at " +
identityResourcesPaths[j], e);
}
}
} catch (ResourceNotFoundException e) {
if(log.isDebugEnabled()){
log.debug("No resource found for tenant " +
tenant.getDomain(), e);
}
} catch (RegistryException e) {
if(log.isDebugEnabled()){
log.debug("Error while deleting the expired
confirmation code.", e);
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
} catch (UserStoreException e) {
if(log.isDebugEnabled()){
log.debug("Error while getting the tenant manager.", e);
}
}
Thanks
Isura.
--
*Isura Dilhara Karunaratne*
Senior Software Engineer | WSO2
Email: [email protected]
Mob : +94 772 254 810
Blog : http://isurad.blogspot.com/
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev