stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From isu...@apache.org
Subject git commit: fixing a bug in SM side in Topology Model update in unsubscribing
Date Thu, 06 Feb 2014 13:14:43 GMT
Updated Branches:
  refs/heads/master 10fda6e85 -> c89680e32


fixing a bug in SM side in Topology Model update in unsubscribing


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

Branch: refs/heads/master
Commit: c89680e3262b8ab51c3a174714f47dcddfadbb30
Parents: 10fda6e
Author: Isuru <isuruh@wso2.com>
Authored: Thu Feb 6 18:42:55 2014 +0530
Committer: Isuru <isuruh@wso2.com>
Committed: Thu Feb 6 18:42:55 2014 +0530

----------------------------------------------------------------------
 .../manager/CartridgeSubscriptionManager.java   |  33 +---
 .../model/TopologyClusterInformationModel.java  | 176 ++++---------------
 .../StratosManagerTopologyReceiver.java         |  44 ++---
 3 files changed, 57 insertions(+), 196 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c89680e3/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
index ab4ffa0..318b5f7 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
@@ -37,6 +37,7 @@ import org.apache.stratos.manager.subscription.tenancy.SubscriptionMultiTenantBe
 import org.apache.stratos.manager.subscription.tenancy.SubscriptionSingleTenantBehaviour;
 import org.apache.stratos.manager.subscription.tenancy.SubscriptionTenancyBehaviour;
 import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
+import org.apache.stratos.manager.topology.model.TopologyClusterInformationModel;
 import org.apache.stratos.manager.utils.ApplicationManagementUtil;
 import org.apache.stratos.manager.utils.CartridgeConstants;
 import org.apache.stratos.manager.utils.RepoPasswordMgtUtil;
@@ -388,31 +389,15 @@ public class CartridgeSubscriptionManager {
     public void unsubscribeFromCartridge (String tenantDomain, String alias)
             throws ADCException, NotSubscribedException {
 
-        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-        /*CartridgeSubscription cartridgeSubscription = getCartridgeSubscriptionForCluster(tenantDomain,
alias);
-
-        if(cartridgeSubscription != null) {
-            cartridgeSubscription.removeSubscription();
-
-            // Publish tenant un-subscribed event to message broker
-            CartridgeSubscriptionUtils.publishTenantUnSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
-                    cartridgeSubscription.getCartridgeInfo().getType());
-        }
-        else {
-            if(log.isDebugEnabled()) {
-                log.debug("No cartridge subscription found with alias " + alias + " for tenant
" + tenantDomain);
-            }
-        }*/
-        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-        //fix properly
         DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
 
         CartridgeSubscription cartridgeSubscription = dataInsertionAndRetrievalManager.getCartridgeSubscription(CarbonContext.getThreadLocalCarbonContext().getTenantId(),
alias);
         if(cartridgeSubscription != null) {
             cartridgeSubscription.removeSubscription();
 
-            //set status as 'UNSUBSCRIBED'
-            //cartridgeSubscription.setSubscriptionStatus(CartridgeConstants.UNSUBSCRIBED);
+            // Remove the information from Topology Model
+            TopologyClusterInformationModel.getInstance().removeCluster(cartridgeSubscription.getSubscriber().getTenantId(),
+                    cartridgeSubscription.getType(), cartridgeSubscription.getAlias());
 
             // remove subscription
             try {
@@ -424,16 +409,6 @@ public class CartridgeSubscriptionManager {
                 throw new ADCException(errorMsg, e);
             }
 
-            // update with new state
-            /*try {
-                dataInsertionAndRetrievalManager.cacheAndPersistSubcription(cartridgeSubscription);
-
-            } catch (PersistenceManagerException e) {
-                String errorMsg = "Error updating subscription for tenant " + tenantDomain
+ ", alias " + cartridgeSubscription.getAlias();
-                log.error(errorMsg);
-                throw new ADCException(errorMsg, e);
-            }*/
-
             // Publish tenant un-subscribed event to message broker
             CartridgeSubscriptionUtils.publishTenantUnSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
                     cartridgeSubscription.getCartridgeInfo().getType());

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c89680e3/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/model/TopologyClusterInformationModel.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/model/TopologyClusterInformationModel.java
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/model/TopologyClusterInformationModel.java
index 232e8a9..82d0a16 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/model/TopologyClusterInformationModel.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/model/TopologyClusterInformationModel.java
@@ -31,9 +31,6 @@ public class TopologyClusterInformationModel {
     private static final Log log = LogFactory.getLog(TopologyClusterInformationModel.class);
 
     private Map<Integer, Set<CartridgeTypeContext>> tenantIdToCartridgeTypeContextMap;
-    //private Map<TenantIdAndAliasTopologyKey, Cluster> tenantIdAndAliasTopologyKeyToClusterMap;
-    //private Map<Integer, List<Cluster>> tenantIdToClusterMap;
-    //private Map<TenantIdAndTypeTopologyKey , List<Cluster>> tenantIdAndTypeTopologyKeyToClusterMap;
     private static TopologyClusterInformationModel topologyClusterInformationModel;
 
     //locks
@@ -42,9 +39,6 @@ public class TopologyClusterInformationModel {
     private static volatile ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
 
     private TopologyClusterInformationModel() {
-        //tenantIdAndAliasTopologyKeyToClusterMap = new HashMap<TenantIdAndAliasTopologyKey,
Cluster>();
-        //tenantIdAndTypeTopologyKeyToClusterMap = new HashMap<TenantIdAndTypeTopologyKey,
List<Cluster>>();
-        //tenantIdToClusterMap = new HashMap<Integer, List<Cluster>>();
         tenantIdToCartridgeTypeContextMap = new HashMap<Integer, Set<CartridgeTypeContext>>();
     }
 
@@ -60,40 +54,6 @@ public class TopologyClusterInformationModel {
         return topologyClusterInformationModel;
     }
 
-    /*public void addCluster (int tenantId, String cartridgeType, String subscriptionAlias,
Cluster cluster) {
-
-        List<Cluster> clusters;
-        writeLock.lock();
-
-        try {
-            //[Tenant Id + Subscription Alias] -> Cluster map
-            tenantIdAndAliasTopologyKeyToClusterMap.putSubscription(new TenantIdAndAliasTopologyKey(tenantId,
subscriptionAlias), cluster);
-
-            //Tenant Id -> Cluster map
-            clusters = tenantIdToClusterMap.get(tenantId);
-            if(clusters == null) {
-                clusters = new ArrayList<Cluster>();
-                clusters.add(cluster);
-                tenantIdToClusterMap.putSubscription(tenantId, clusters);
-            } else {
-                clusters.add(cluster);
-            }
-
-            //[Tenant Id + Cartridge Type] -> Cluster map
-            clusters = tenantIdAndTypeTopologyKeyToClusterMap.get(new TenantIdAndTypeTopologyKey(tenantId,
cartridgeType));
-            if(clusters == null) {
-                clusters = new ArrayList<Cluster>();
-                clusters.add(cluster);
-                tenantIdAndTypeTopologyKeyToClusterMap.putSubscription(new TenantIdAndTypeTopologyKey(tenantId,
cartridgeType), clusters);
-            } else {
-                clusters.add(cluster);
-            }
-
-        } finally {
-            writeLock.unlock();
-        }
-    } */
-
     public void addCluster (int tenantId, String cartridgeType, String subscriptionAlias,
Cluster cluster) {
 
         Set<CartridgeTypeContext> cartridgeTypeContextSet = null;
@@ -132,6 +92,10 @@ public class TopologyClusterInformationModel {
                     //add to the cartridgeTypeContextSet
                     cartridgeTypeContextSet.add(cartridgeTypeContext);
 
+                    if (log.isDebugEnabled()) {
+                        log.debug("New cluster added " + cluster.toString());
+                    }
+
                 } else {
                     //iterate through the set
                     /*Iterator<SubscriptionAliasContext> aliasIterator = subscriptionAliasContextSet.iterator();
@@ -149,6 +113,10 @@ public class TopologyClusterInformationModel {
 
                     //now, add the new cluster object
                     subscriptionAliasContextSet.add(new SubscriptionAliasContext(subscriptionAlias,
cluster));
+
+                    if (log.isDebugEnabled()) {
+                        log.debug("Exiting cluster updated " + cluster.toString());
+                    }
                 }
 
             } else {
@@ -174,6 +142,10 @@ public class TopologyClusterInformationModel {
 
                 //link the CartridgeTypeContext set to the [tenant Id -> CartridgeTypeContext]
map
                 tenantIdToCartridgeTypeContextMap.put(tenantId, cartridgeTypeContextSet);
+
+                if (log.isDebugEnabled()) {
+                    log.debug("New cluster added " + cluster.toString());
+                }
             }
 
         } finally {
@@ -210,6 +182,12 @@ public class TopologyClusterInformationModel {
                         //see if the set contains a SubscriptionAliasContext instance with
the given alias
                         SubscriptionAliasContext subscriptionAliasContext = aliasIterator.next();
                         if (subscriptionAliasContext.equals(new SubscriptionAliasContext(subscriptionAlias,
null))) {
+
+                            if (log.isDebugEnabled()) {
+                                log.debug("Matching cluster found for tenant " + tenantId
+ ", type " + cartridgeType +
+                                        ", subscription alias " + subscriptionAlias + ":
" + subscriptionAliasContext.getCluster().toString());
+                            }
+
                             return subscriptionAliasContext.getCluster();
                         }
                     }
@@ -266,7 +244,13 @@ public class TopologyClusterInformationModel {
 
                             clusterSet = new HashSet<Cluster>();
                             while (aliasCtxIterator.hasNext()) {
-                                clusterSet.add(aliasCtxIterator.next().getCluster());
+                                Cluster cluster = aliasCtxIterator.next().getCluster();
+                                // add the cluster to the set
+                                clusterSet.add(cluster);
+
+                                if (log.isDebugEnabled()) {
+                                    log.debug("Matching cluster found for tenant " + tenantId
+ ", type " + cartridgeType + " : " + cluster.toString());
+                                }
                             }
                         }
                     }
@@ -280,40 +264,6 @@ public class TopologyClusterInformationModel {
         return clusterSet;
     }
 
-    /*public Set<Cluster> getClusters (int tenantId) {
-
-        Set<CartridgeTypeContext> cartridgeTypeContextSet = null;
-        Set<SubscriptionAliasContext> subscriptionAliasContextSet = null;
-        Set<Cluster> clusterSet = null;
-
-        readLock.lock();
-        try {
-            cartridgeTypeContextSet = tenantIdToCartridgeTypeContextMap.get(tenantId);
-            if(cartridgeTypeContextSet != null) {
-                CartridgeTypeContext cartridgeTypeContext = null;
-                //iterate through the set
-                Iterator<CartridgeTypeContext> typeCtxIterator = cartridgeTypeContextSet.iterator();
-                while (typeCtxIterator.hasNext()) {
-                    //see if the set contains a CartridgeTypeContext instance with the given
cartridge type
-                }
-
-                if (subscriptionAliasContextSet != null) {
-                    //iterate and convert to Cluster set
-                    Iterator<SubscriptionAliasContext> aliasCtxIterator = subscriptionAliasContextSet.iterator();
-                    clusterSet = new HashSet<Cluster>();
-                    while (aliasCtxIterator.hasNext()) {
-                        clusterSet.add(aliasCtxIterator.next().getCluster());
-                    }
-                }
-            }
-
-        } finally {
-            readLock.unlock();
-        }
-
-        return clusterSet;
-    }*/
-
     public void removeCluster (int tenantId, String cartridgeType, String subscriptionAlias)
{
 
         Set<CartridgeTypeContext> cartridgeTypeContextSet = null;
@@ -345,6 +295,12 @@ public class TopologyClusterInformationModel {
                         if (subscriptionAliasContext.getSubscriptionAlias().equals(subscriptionAlias))
{
                             //remove the existing one
                             aliasIterator.remove();
+
+                            if (log.isDebugEnabled()) {
+                                log.debug("Removed cluster for tenant " + tenantId + ", type
" + cartridgeType +
+                                        ", subscription alias " + subscriptionAlias);
+                            }
+
                             break;
                         }
                     }
@@ -430,74 +386,4 @@ public class TopologyClusterInformationModel {
             return subscriptionAlias.hashCode();
         }
     }
-
-    private class TenantIdAndAliasTopologyKey {
-
-        private int tenantId;
-        private String subscriptionAlias;
-
-        public TenantIdAndAliasTopologyKey (int tenantId, String subscriptionAlias) {
-
-            this.tenantId = tenantId;
-            this.subscriptionAlias = subscriptionAlias;
-        }
-
-        public boolean equals(Object other) {
-
-            if(this == other) {
-                return true;
-            }
-            if(!(other instanceof TenantIdAndAliasTopologyKey)) {
-                return false;
-            }
-
-            TenantIdAndAliasTopologyKey that = (TenantIdAndAliasTopologyKey)other;
-            return ((this.tenantId == that.tenantId) && (this.subscriptionAlias ==
that.subscriptionAlias));
-        }
-
-        public int hashCode () {
-
-            int subscriptionAliasHashCode = 0;
-            if(subscriptionAlias != null) {
-                subscriptionAliasHashCode = subscriptionAlias.hashCode();
-            }
-
-            return (tenantId * 3 + subscriptionAliasHashCode * 5);
-        }
-    }
-
-    public class TenantIdAndTypeTopologyKey {
-
-        private int tenantId;
-        private String subscriptionAlias;
-
-        public TenantIdAndTypeTopologyKey (int tenantId, String subscriptionAlias) {
-
-            this.tenantId = tenantId;
-            this.subscriptionAlias = subscriptionAlias;
-        }
-
-        public boolean equals(Object other) {
-
-            if(this == other) {
-                return true;
-            }
-            if(!(other instanceof TenantIdAndTypeTopologyKey)) {
-                return false;
-            }
-
-            TenantIdAndTypeTopologyKey that = (TenantIdAndTypeTopologyKey)other;
-            return ((this.tenantId == that.tenantId) && (this.subscriptionAlias ==
that.subscriptionAlias));
-        }
-
-        public int hashCode () {
-
-            int subscriptionAliasHashCode = 0;
-            if(subscriptionAlias != null) {
-                subscriptionAliasHashCode = subscriptionAlias.hashCode();
-            }
-
-            return (tenantId * 3 + subscriptionAliasHashCode * 5);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c89680e3/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyReceiver.java
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyReceiver.java
index e23b2d4..6c90c35 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyReceiver.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/topology/receiver/StratosManagerTopologyReceiver.java
@@ -128,28 +128,28 @@ public class StratosManagerTopologyReceiver implements Runnable {
         });
 
         //Cluster Removed event listner
-        processorChain.addEventListener(new ClusterRemovedEventListener() {
-            @Override
-            protected void onEvent(Event event) {
-
-                log.info("********** [ClusterRemovedEventListener] Received: " + event.getClass()
+ " **********");
-
-                ClusterRemovedEvent clusterRemovedEvent = (ClusterRemovedEvent) event;
-
-                Set<CartridgeSubscription> cartridgeSubscriptions =
-                        getCartridgeSubscription(clusterRemovedEvent.getClusterId());
-
-                if(cartridgeSubscriptions != null) {
-
-                    // iterate
-                    for (CartridgeSubscription cartridgeSubscription : cartridgeSubscriptions)
{
-                        //add the information to Topology Cluster Info. model
-                        TopologyClusterInformationModel.getInstance().removeCluster(cartridgeSubscription.getSubscriber().getTenantId(),
-                                cartridgeSubscription.getType(), cartridgeSubscription.getAlias());
-                    }
-                }
-            }
-        });
+//        processorChain.addEventListener(new ClusterRemovedEventListener() {
+//            @Override
+//            protected void onEvent(Event event) {
+//
+//                log.info("********** [ClusterRemovedEventListener] Received: " + event.getClass()
+ " **********");
+//
+//                ClusterRemovedEvent clusterRemovedEvent = (ClusterRemovedEvent) event;
+//
+//                Set<CartridgeSubscription> cartridgeSubscriptions =
+//                        getCartridgeSubscription(clusterRemovedEvent.getClusterId());
+//
+//                if(cartridgeSubscriptions != null) {
+//
+//                    // iterate
+//                    for (CartridgeSubscription cartridgeSubscription : cartridgeSubscriptions)
{
+//                        //add the information to Topology Cluster Info. model
+//                        TopologyClusterInformationModel.getInstance().removeCluster(cartridgeSubscription.getSubscriber().getTenantId(),
+//                                cartridgeSubscription.getType(), cartridgeSubscription.getAlias());
+//                    }
+//                }
+//            }
+//        });
         
         
       //Instance Spawned event listner


Mime
View raw message