Repository: stratos Updated Branches: refs/heads/4.0.0-grouping a520063c7 -> 60429f496
creating super tenant flows when writing/reading to/from registry Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/60429f49 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/60429f49 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/60429f49 Branch: refs/heads/4.0.0-grouping Commit: 60429f4964f0b61a55cfa34bd0dd8b896fa0d91c Parents: a520063 Author: Isuru Haththotuwa <[email protected]> Authored: Mon Nov 3 18:18:10 2014 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Mon Nov 3 18:18:10 2014 +0530 ---------------------------------------------------------------------- .../autoscaler/registry/RegistryManager.java | 99 ++++++++++++++------ 1 file changed, 68 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/60429f49/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java index af2f795..534d57d 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java @@ -152,57 +152,94 @@ public class RegistryManager { public void persistApplication (Application application) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext - .getThreadLocalCarbonContext(); - ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); - ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.APPLICATIONS_RESOURCE + - "/" + application.getUniqueIdentifier(); - persist(application, resourcePath); - if(log.isDebugEnabled()) { - log.debug("Application [ " + application.getUniqueIdentifier() + - " ] persisted successfully in the Autoscaler Registry"); + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + + String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.APPLICATIONS_RESOURCE + + "/" + application.getUniqueIdentifier(); + persist(application, resourcePath); + if(log.isDebugEnabled()) { + log.debug("Application [ " + application.getUniqueIdentifier() + + " ] persisted successfully in the Autoscaler Registry"); + } + + } finally { + PrivilegedCarbonContext.endTenantFlow(); } } public String [] getApplicationResourcePaths () { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext - .getThreadLocalCarbonContext(); - ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); - ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - Object obj = retrieve(AutoScalerConstants.AUTOSCALER_RESOURCE + - AutoScalerConstants.APPLICATIONS_RESOURCE); + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); - if (obj != null) { - if (obj instanceof String []) { - return (String []) obj; - } else { - log.warn("Expected object type not found for Applications in Registry"); - return null; + Object obj = retrieve(AutoScalerConstants.AUTOSCALER_RESOURCE + + AutoScalerConstants.APPLICATIONS_RESOURCE); + + if (obj != null) { + if (obj instanceof String []) { + return (String []) obj; + } else { + log.warn("Expected object type not found for Applications in Registry"); + return null; + } } + + } finally { + PrivilegedCarbonContext.endTenantFlow(); } + return null; } public Application getApplication (String applicationResourcePath) { - Object obj = retrieve(applicationResourcePath); - if (obj != null) { - if (obj instanceof Application) { - return (Application) obj; - } else { - log.warn("Expected object type not found for Application " + applicationResourcePath + " in Registry"); - return null; + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + + Object obj = retrieve(applicationResourcePath); + + if (obj != null) { + if (obj instanceof Application) { + return (Application) obj; + } else { + log.warn("Expected object type not found for Application " + applicationResourcePath + " in Registry"); + return null; + } } + + } finally { + PrivilegedCarbonContext.endTenantFlow(); } + return null; } public void removeApplication (String applicationId) { - delete(AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.APPLICATIONS_RESOURCE + - "/" + applicationId); + + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + + delete(AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.APPLICATIONS_RESOURCE + + "/" + applicationId); + + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } public void persistServiceGroup(ServiceGroup servicegroup) {
