Adding in new file to handle artifact loading from registry when tenant loads


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/0c837be9
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/0c837be9
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/0c837be9

Branch: refs/heads/tenant-isolation-feature
Commit: 0c837be9482d4b8581b3f9391a389e0354ffefbf
Parents: 8e5cba6
Author: Shiro <[email protected]>
Authored: Fri Oct 3 01:56:17 2014 +0530
Committer: Shiro <[email protected]>
Committed: Fri Oct 3 01:56:17 2014 +0530

----------------------------------------------------------------------
 .../internal/TenantArtifactLoader.java          | 83 ++++++++++++++++++++
 1 file changed, 83 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/0c837be9/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/TenantArtifactLoader.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/TenantArtifactLoader.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/TenantArtifactLoader.java
new file mode 100644
index 0000000..2b22073
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/TenantArtifactLoader.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one 
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+ * KIND, either express or implied.  See the License for the 
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.autoscaler.internal;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.stratos.autoscaler.partition.PartitionManager;
+import org.apache.stratos.autoscaler.policy.PolicyManager;
+import org.wso2.carbon.context.CarbonContext;
+import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver;
+
+
+public class TenantArtifactLoader extends 
AbstractAxis2ConfigurationContextObserver
+{
+       public void creatingConfigurationContext(int tenantId) {
+    }
+
+    public void createdConfigurationContext(ConfigurationContext 
configContext) {
+       if(!checkIfArtifactsAreInSync()){
+               updateArtifacts();
+        }
+    }
+
+    public void terminatingConfigurationContext(ConfigurationContext 
configCtx) {      
+       clearArtifacts();
+    }
+
+    public void terminatedConfigurationContext(ConfigurationContext configCtx) 
{
+    }
+    
+    private boolean checkIfArtifactsAreInSync()
+    {
+       int tenantId = 
CarbonContext.getThreadLocalCarbonContext().getTenantId();
+       
+       // check whether tenant Id is present in inMemModels 
+       return 
(PolicyManager.getInstance().isTenantPolicyDetailsInInformationModel(tenantId) 
&& 
+                       
PartitionManager.getInstance().isTenantPolicyDetailsInInformationModel(tenantId));
+    }
+    
+    private void updateArtifacts()
+    {
+       // Adding the registry stored partitions to the information model
+        PartitionManager.getInstance().loadPartitionsToInformationModel();
+        
+        // Adding the network partitions stored in registry to the information 
model
+        
PartitionManager.getInstance().loadNetworkPartitionsToInformationModel();
+        
+        // Adding the registry stored autoscaling policies to the information 
model
+        PolicyManager.getInstance().loadASPoliciesToInformationModel();
+        
+        // Adding the registry stored deployment policies to the information 
model
+        PolicyManager.getInstance().loadDeploymentPoliciesToInformationModel();
+    }
+    
+    private void clearArtifacts()
+    {
+       int currentTenantId = 
CarbonContext.getThreadLocalCarbonContext().getTenantId();
+       
+       // Adding the registry stored partitions to the information model
+        
PartitionManager.getInstance().removePartitionsFromInformationModel(currentTenantId);
+               
+        // Adding the registry stored autoscaling policies to the information 
model
+        
PolicyManager.getInstance().removeASPoliciesFromInformationModel(currentTenantId);
+        
+        // Adding the registry stored deployment policies to the information 
model
+        
PolicyManager.getInstance().removeDeploymentPoliciesFromInformationModel(currentTenantId);
+    }
+}

Reply via email to