You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/12/11 07:15:37 UTC
[1/3] git commit: renaming TopologyClusterModel to
TopologyClusterInformationModel and fixing a bug in InstanceStatusProcessor
Updated Branches:
refs/heads/master f8bd48ac0 -> 656160317
renaming TopologyClusterModel to TopologyClusterInformationModel and fixing a bug in InstanceStatusProcessor
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/122a4217
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/122a4217
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/122a4217
Branch: refs/heads/master
Commit: 122a4217655c634f44fd0269c5286ea489782bf8
Parents: 85abff7
Author: Isuru <is...@wso2.com>
Authored: Wed Dec 11 11:44:16 2013 +0530
Committer: Isuru <is...@wso2.com>
Committed: Wed Dec 11 11:44:16 2013 +0530
----------------------------------------------------------------------
.../processor/InstanceStatusProcessor.java | 11 +-
.../model/TopologyClusterInformationModel.java | 477 +++++++++++++++++++
.../topology/model/TopologyClusterModel.java | 477 -------------------
3 files changed, 483 insertions(+), 482 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/122a4217/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/event/processor/InstanceStatusProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/event/processor/InstanceStatusProcessor.java b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/event/processor/InstanceStatusProcessor.java
index 0f274de..d034962 100644
--- a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/event/processor/InstanceStatusProcessor.java
+++ b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/event/processor/InstanceStatusProcessor.java
@@ -22,7 +22,7 @@ package org.apache.stratos.adc.mgt.topology.event.processor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.adc.mgt.dao.CartridgeSubscriptionInfo;
-import org.apache.stratos.adc.mgt.topology.model.TopologyClusterModel;
+import org.apache.stratos.adc.mgt.topology.model.TopologyClusterInformationModel;
import org.apache.stratos.adc.mgt.utils.PersistenceManager;
import org.apache.stratos.messaging.domain.topology.Cluster;
import org.apache.stratos.messaging.event.topology.MemberActivatedEvent;
@@ -53,6 +53,7 @@ public class InstanceStatusProcessor extends TopologyEventProcessor {
public void process(Message message) {
//new InstanceStatusListenerThread(message).start();
+ doProcessing(message);
//go to next processor in the chain
if(nextTopologyEventProcessor != null) {
nextTopologyEventProcessor.process(message);
@@ -82,7 +83,7 @@ public class InstanceStatusProcessor extends TopologyEventProcessor {
if(cartridgeSubscriptionInfo != null) {
Cluster cluster = TopologyManager.getTopology().
getService(cartridgeSubscriptionInfo.getCartridge()).getCluster(clusterDomain);
- TopologyClusterModel.getInstance().addCluster(cartridgeSubscriptionInfo.getTenantId(),
+ TopologyClusterInformationModel.getInstance().addCluster(cartridgeSubscriptionInfo.getTenantId(),
cartridgeSubscriptionInfo.getCartridge(),
cartridgeSubscriptionInfo.getAlias(), cluster);
}
@@ -99,7 +100,7 @@ public class InstanceStatusProcessor extends TopologyEventProcessor {
if(cartridgeSubscriptionInfo != null) {
Cluster cluster = TopologyManager.getTopology().
getService(cartridgeSubscriptionInfo.getCartridge()).getCluster(clusterDomain);
- TopologyClusterModel.getInstance().addCluster(cartridgeSubscriptionInfo.getTenantId(),
+ TopologyClusterInformationModel.getInstance().addCluster(cartridgeSubscriptionInfo.getTenantId(),
cartridgeSubscriptionInfo.getCartridge(),
cartridgeSubscriptionInfo.getAlias(), cluster);
}
@@ -116,7 +117,7 @@ public class InstanceStatusProcessor extends TopologyEventProcessor {
if(cartridgeSubscriptionInfo != null) {
Cluster cluster = TopologyManager.getTopology().
getService(cartridgeSubscriptionInfo.getCartridge()).getCluster(clusterDomain);
- TopologyClusterModel.getInstance().addCluster(cartridgeSubscriptionInfo.getTenantId(),
+ TopologyClusterInformationModel.getInstance().addCluster(cartridgeSubscriptionInfo.getTenantId(),
cartridgeSubscriptionInfo.getCartridge(),
cartridgeSubscriptionInfo.getAlias(), cluster);
}
@@ -132,7 +133,7 @@ public class InstanceStatusProcessor extends TopologyEventProcessor {
if(cartridgeSubscriptionInfo != null) {
Cluster cluster = TopologyManager.getTopology().
getService(cartridgeSubscriptionInfo.getCartridge()).getCluster(clusterDomain);
- TopologyClusterModel.getInstance().addCluster(cartridgeSubscriptionInfo.getTenantId(),
+ TopologyClusterInformationModel.getInstance().addCluster(cartridgeSubscriptionInfo.getTenantId(),
cartridgeSubscriptionInfo.getCartridge(),
cartridgeSubscriptionInfo.getAlias(), cluster);
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/122a4217/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/model/TopologyClusterInformationModel.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/model/TopologyClusterInformationModel.java b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/model/TopologyClusterInformationModel.java
new file mode 100644
index 0000000..f41d1fe
--- /dev/null
+++ b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/model/TopologyClusterInformationModel.java
@@ -0,0 +1,477 @@
+/*
+ * 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.adc.mgt.topology.model;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+
+import java.util.*;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+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
+ private static volatile ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ private static volatile ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
+ 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>>();
+ }
+
+ public static TopologyClusterInformationModel getInstance () {
+ if(topologyClusterInformationModel == null) {
+ synchronized (TopologyClusterInformationModel.class) {
+ if (topologyClusterInformationModel == null) {
+ topologyClusterInformationModel = new 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.put(new TenantIdAndAliasTopologyKey(tenantId, subscriptionAlias), cluster);
+
+ //Tenant Id -> Cluster map
+ clusters = tenantIdToClusterMap.get(tenantId);
+ if(clusters == null) {
+ clusters = new ArrayList<Cluster>();
+ clusters.add(cluster);
+ tenantIdToClusterMap.put(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.put(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;
+ Set<SubscriptionAliasContext> subscriptionAliasContextSet = null;
+
+ writeLock.lock();
+ try {
+ //check if a set of CartridgeTypeContext instances already exist for given tenant Id
+ 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
+ cartridgeTypeContext = typeCtxIterator.next();
+ if (cartridgeTypeContext.getType().equals(cartridgeType)){
+ //if so, get the SubscriptionAliasContext set
+ subscriptionAliasContextSet = cartridgeTypeContext.getSubscriptionAliasContextSet();
+ break;
+ }
+ }
+ //check if a SubscriptionAliasContext set is not found
+ if(subscriptionAliasContextSet == null) {
+ //no SubscriptionAliasContext instance
+ //create a new SubscriptionAliasContext instance
+ SubscriptionAliasContext subscriptionAliasContext = new SubscriptionAliasContext(subscriptionAlias,
+ cluster);
+ //create a SubscriptionAliasContext set
+ subscriptionAliasContextSet = new HashSet<SubscriptionAliasContext>();
+ //add the created SubscriptionAliasContext instance to SubscriptionAliasContext set
+ subscriptionAliasContextSet.add(subscriptionAliasContext);
+ //set it to the CartridgeTypeContext instance
+ cartridgeTypeContext = new CartridgeTypeContext(cartridgeType);
+ cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
+ //add to the cartridgeTypeContextSet
+ cartridgeTypeContextSet.add(cartridgeTypeContext);
+
+ } else {
+ //iterate through the set
+ Iterator<SubscriptionAliasContext> aliasIterator = subscriptionAliasContextSet.iterator();
+ while (aliasIterator.hasNext()) {
+ //see if the set contains a SubscriptionAliasContext instance with the given alias
+ SubscriptionAliasContext subscriptionAliasContext = aliasIterator.next();
+ if (subscriptionAliasContext.getSubscriptionAlias().equals(subscriptionAlias)) {
+ //remove the existing one
+ aliasIterator.remove();
+ break;
+ }
+ }
+ //now, add the new cluster object
+ subscriptionAliasContextSet.add(new SubscriptionAliasContext(subscriptionAlias, cluster));
+ }
+
+ } else {
+ //no entries for this tenant, go from down to top creating relevant objects and populating them
+ //create a new SubscriptionAliasContext instance
+ SubscriptionAliasContext subscriptionAliasContext = new SubscriptionAliasContext(subscriptionAlias,
+ cluster);
+ //create a SubscriptionAliasContext set
+ subscriptionAliasContextSet = new HashSet<SubscriptionAliasContext>();
+ //add the created SubscriptionAliasContext instance to SubscriptionAliasContext set
+ subscriptionAliasContextSet.add(subscriptionAliasContext);
+
+ //create a new CartridgeTypeContext instance
+ CartridgeTypeContext cartridgeTypeContext = new CartridgeTypeContext(cartridgeType);
+ //link the SubscriptionAliasContextSet to it
+ cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
+
+ //Create CartridgeTypeContext instance
+ cartridgeTypeContextSet = new HashSet<CartridgeTypeContext>();
+ //link the SubscriptionAliasContext set to CartridgeTypeContext instance
+ cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
+
+ //link the CartridgeTypeContext set to the [tenant Id -> CartridgeTypeContext] map
+ tenantIdToCartridgeTypeContextMap.put(tenantId, cartridgeTypeContextSet);
+ }
+
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ public Cluster getCluster (int tenantId, String cartridgeType, String subscriptionAlias) {
+
+ Set<CartridgeTypeContext> cartridgeTypeContextSet = null;
+ Set<SubscriptionAliasContext> subscriptionAliasContextSet = null;
+
+ readLock.lock();
+ try {
+ //check if a set of CartridgeTypeContext instances already exist for given tenant Id
+ 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
+ cartridgeTypeContext = typeCtxIterator.next();
+ if (cartridgeTypeContext.getType().equals(cartridgeType)){
+ //if so, get the SubscriptionAliasContext set
+ subscriptionAliasContextSet = cartridgeTypeContext.getSubscriptionAliasContextSet();
+ break;
+ }
+ }
+ if(subscriptionAliasContextSet != null) {
+ //iterate through the set
+ Iterator<SubscriptionAliasContext> aliasIterator = subscriptionAliasContextSet.iterator();
+ while (aliasIterator.hasNext()) {
+ //see if the set contains a SubscriptionAliasContext instance with the given alias
+ SubscriptionAliasContext subscriptionAliasContext = aliasIterator.next();
+ if (subscriptionAliasContext.getSubscriptionAlias().equals(subscriptionAlias)) {
+ return subscriptionAliasContext.getCluster();
+ }
+ }
+ }
+ }
+
+ } finally {
+ readLock.unlock();
+ }
+
+ return null;
+ }
+
+ public Set<Cluster> getClusters (int tenantId, String cartridgeType) {
+
+ Set<CartridgeTypeContext> cartridgeTypeContextSet = null;
+ Set<SubscriptionAliasContext> subscriptionAliasContextSet = null;
+ Set<Cluster> clusterSet = null;
+
+ readLock.lock();
+ try {
+ cartridgeTypeContextSet = tenantIdToCartridgeTypeContextMap.get(tenantId);
+ if(cartridgeTypeContextSet != null) {
+ //iterate through the set
+ Iterator<CartridgeTypeContext> typeCtxIterator = cartridgeTypeContextSet.iterator();
+ while (typeCtxIterator.hasNext()) {
+ //iterate and get each of SubscriptionAliasContext sets
+ CartridgeTypeContext cartridgeTypeContext = typeCtxIterator.next();
+ subscriptionAliasContextSet = cartridgeTypeContext.getSubscriptionAliasContextSet();
+
+ 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 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;
+ Set<SubscriptionAliasContext> subscriptionAliasContextSet = null;
+
+ writeLock.lock();
+ try {
+ //check if a set of CartridgeTypeContext instances already exist for given tenant Id
+ 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
+ cartridgeTypeContext = typeCtxIterator.next();
+ if (cartridgeTypeContext.getType().equals(cartridgeType)){
+ //if so, get the SubscriptionAliasContext set
+ subscriptionAliasContextSet = cartridgeTypeContext.getSubscriptionAliasContextSet();
+ break;
+ }
+ }
+ if(subscriptionAliasContextSet != null) {
+ //iterate through the set
+ Iterator<SubscriptionAliasContext> aliasIterator = subscriptionAliasContextSet.iterator();
+ while (aliasIterator.hasNext()) {
+ //see if the set contains a SubscriptionAliasContext instance with the given alias
+ SubscriptionAliasContext subscriptionAliasContext = aliasIterator.next();
+ if (subscriptionAliasContext.getSubscriptionAlias().equals(subscriptionAlias)) {
+ //remove the existing one
+ aliasIterator.remove();
+ break;
+ }
+ }
+ }
+ }
+
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ private class CartridgeTypeContext {
+
+ private String type;
+ private Set<SubscriptionAliasContext> subscriptionAliasContextSet;
+
+ public CartridgeTypeContext (String type) {
+ this.type = type;
+ }
+
+ public void setSubscriptionAliasContextSet (Set<SubscriptionAliasContext> subscriptionAliasContextSet) {
+ this.subscriptionAliasContextSet = subscriptionAliasContextSet;
+ }
+
+ public String getType () {
+ return type;
+ }
+
+ public Set<SubscriptionAliasContext> getSubscriptionAliasContextSet () {
+ return subscriptionAliasContextSet;
+ }
+
+ public boolean equals(Object other) {
+
+ if(this == other) {
+ return true;
+ }
+ if(!(other instanceof CartridgeTypeContext)) {
+ return false;
+ }
+
+ CartridgeTypeContext that = (CartridgeTypeContext)other;
+ return this.type.equals(that.type);
+ }
+
+ public int hashCode () {
+ return type.hashCode();
+ }
+ }
+
+ private class SubscriptionAliasContext {
+
+ private String subscriptionAlias;
+ private Cluster cluster;
+
+ public SubscriptionAliasContext(String subscriptionAlias, Cluster cluster) {
+ this.subscriptionAlias = subscriptionAlias;
+ this.cluster = cluster;
+ }
+
+ public String getSubscriptionAlias () {
+ return subscriptionAlias;
+ }
+
+ public Cluster getCluster () {
+ return cluster;
+ }
+
+ public boolean equals(Object other) {
+
+ if(this == other) {
+ return true;
+ }
+ if(!(other instanceof SubscriptionAliasContext)) {
+ return false;
+ }
+
+ SubscriptionAliasContext that = (SubscriptionAliasContext)other;
+ return this.subscriptionAlias.equals(that.subscriptionAlias);
+ }
+
+ public int hashCode () {
+ 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/122a4217/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/model/TopologyClusterModel.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/model/TopologyClusterModel.java b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/model/TopologyClusterModel.java
deleted file mode 100644
index 52e75cc..0000000
--- a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/topology/model/TopologyClusterModel.java
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
- * 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.adc.mgt.topology.model;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-
-import java.util.*;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-public class TopologyClusterModel {
-
- private static final Log log = LogFactory.getLog(TopologyClusterModel.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 TopologyClusterModel topologyClusterModel;
-
- //locks
- private static volatile ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
- private static volatile ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
- private static volatile ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
-
- private TopologyClusterModel() {
- //tenantIdAndAliasTopologyKeyToClusterMap = new HashMap<TenantIdAndAliasTopologyKey, Cluster>();
- //tenantIdAndTypeTopologyKeyToClusterMap = new HashMap<TenantIdAndTypeTopologyKey, List<Cluster>>();
- //tenantIdToClusterMap = new HashMap<Integer, List<Cluster>>();
- tenantIdToCartridgeTypeContextMap = new HashMap<Integer, Set<CartridgeTypeContext>>();
- }
-
- public static TopologyClusterModel getInstance () {
- if(topologyClusterModel == null) {
- synchronized (TopologyClusterModel.class) {
- if (topologyClusterModel == null) {
- topologyClusterModel = new TopologyClusterModel();
- }
- }
- }
-
- return topologyClusterModel;
- }
-
- /*public void addCluster (int tenantId, String cartridgeType, String subscriptionAlias, Cluster cluster) {
-
- List<Cluster> clusters;
- writeLock.lock();
-
- try {
- //[Tenant Id + Subscription Alias] -> Cluster map
- tenantIdAndAliasTopologyKeyToClusterMap.put(new TenantIdAndAliasTopologyKey(tenantId, subscriptionAlias), cluster);
-
- //Tenant Id -> Cluster map
- clusters = tenantIdToClusterMap.get(tenantId);
- if(clusters == null) {
- clusters = new ArrayList<Cluster>();
- clusters.add(cluster);
- tenantIdToClusterMap.put(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.put(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;
- Set<SubscriptionAliasContext> subscriptionAliasContextSet = null;
-
- writeLock.lock();
- try {
- //check if a set of CartridgeTypeContext instances already exist for given tenant Id
- 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
- cartridgeTypeContext = typeCtxIterator.next();
- if (cartridgeTypeContext.getType().equals(cartridgeType)){
- //if so, get the SubscriptionAliasContext set
- subscriptionAliasContextSet = cartridgeTypeContext.getSubscriptionAliasContextSet();
- break;
- }
- }
- //check if a SubscriptionAliasContext set is not found
- if(subscriptionAliasContextSet == null) {
- //no SubscriptionAliasContext instance
- //create a new SubscriptionAliasContext instance
- SubscriptionAliasContext subscriptionAliasContext = new SubscriptionAliasContext(subscriptionAlias,
- cluster);
- //create a SubscriptionAliasContext set
- subscriptionAliasContextSet = new HashSet<SubscriptionAliasContext>();
- //add the created SubscriptionAliasContext instance to SubscriptionAliasContext set
- subscriptionAliasContextSet.add(subscriptionAliasContext);
- //set it to the CartridgeTypeContext instance
- cartridgeTypeContext = new CartridgeTypeContext(cartridgeType);
- cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
- //add to the cartridgeTypeContextSet
- cartridgeTypeContextSet.add(cartridgeTypeContext);
-
- } else {
- //iterate through the set
- Iterator<SubscriptionAliasContext> aliasIterator = subscriptionAliasContextSet.iterator();
- while (aliasIterator.hasNext()) {
- //see if the set contains a SubscriptionAliasContext instance with the given alias
- SubscriptionAliasContext subscriptionAliasContext = aliasIterator.next();
- if (subscriptionAliasContext.getSubscriptionAlias().equals(subscriptionAlias)) {
- //remove the existing one
- aliasIterator.remove();
- break;
- }
- }
- //now, add the new cluster object
- subscriptionAliasContextSet.add(new SubscriptionAliasContext(subscriptionAlias, cluster));
- }
-
- } else {
- //no entries for this tenant, go from down to top creating relevant objects and populating them
- //create a new SubscriptionAliasContext instance
- SubscriptionAliasContext subscriptionAliasContext = new SubscriptionAliasContext(subscriptionAlias,
- cluster);
- //create a SubscriptionAliasContext set
- subscriptionAliasContextSet = new HashSet<SubscriptionAliasContext>();
- //add the created SubscriptionAliasContext instance to SubscriptionAliasContext set
- subscriptionAliasContextSet.add(subscriptionAliasContext);
-
- //create a new CartridgeTypeContext instance
- CartridgeTypeContext cartridgeTypeContext = new CartridgeTypeContext(cartridgeType);
- //link the SubscriptionAliasContextSet to it
- cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
-
- //Create CartridgeTypeContext instance
- cartridgeTypeContextSet = new HashSet<CartridgeTypeContext>();
- //link the SubscriptionAliasContext set to CartridgeTypeContext instance
- cartridgeTypeContext.setSubscriptionAliasContextSet(subscriptionAliasContextSet);
-
- //link the CartridgeTypeContext set to the [tenant Id -> CartridgeTypeContext] map
- tenantIdToCartridgeTypeContextMap.put(tenantId, cartridgeTypeContextSet);
- }
-
- } finally {
- writeLock.unlock();
- }
- }
-
- public Cluster getCluster (int tenantId, String cartridgeType, String subscriptionAlias) {
-
- Set<CartridgeTypeContext> cartridgeTypeContextSet = null;
- Set<SubscriptionAliasContext> subscriptionAliasContextSet = null;
-
- readLock.lock();
- try {
- //check if a set of CartridgeTypeContext instances already exist for given tenant Id
- 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
- cartridgeTypeContext = typeCtxIterator.next();
- if (cartridgeTypeContext.getType().equals(cartridgeType)){
- //if so, get the SubscriptionAliasContext set
- subscriptionAliasContextSet = cartridgeTypeContext.getSubscriptionAliasContextSet();
- break;
- }
- }
- if(subscriptionAliasContextSet != null) {
- //iterate through the set
- Iterator<SubscriptionAliasContext> aliasIterator = subscriptionAliasContextSet.iterator();
- while (aliasIterator.hasNext()) {
- //see if the set contains a SubscriptionAliasContext instance with the given alias
- SubscriptionAliasContext subscriptionAliasContext = aliasIterator.next();
- if (subscriptionAliasContext.getSubscriptionAlias().equals(subscriptionAlias)) {
- return subscriptionAliasContext.getCluster();
- }
- }
- }
- }
-
- } finally {
- readLock.unlock();
- }
-
- return null;
- }
-
- public Set<Cluster> getClusters (int tenantId, String cartridgeType) {
-
- Set<CartridgeTypeContext> cartridgeTypeContextSet = null;
- Set<SubscriptionAliasContext> subscriptionAliasContextSet = null;
- Set<Cluster> clusterSet = null;
-
- readLock.lock();
- try {
- cartridgeTypeContextSet = tenantIdToCartridgeTypeContextMap.get(tenantId);
- if(cartridgeTypeContextSet != null) {
- //iterate through the set
- Iterator<CartridgeTypeContext> typeCtxIterator = cartridgeTypeContextSet.iterator();
- while (typeCtxIterator.hasNext()) {
- //iterate and get each of SubscriptionAliasContext sets
- CartridgeTypeContext cartridgeTypeContext = typeCtxIterator.next();
- subscriptionAliasContextSet = cartridgeTypeContext.getSubscriptionAliasContextSet();
-
- 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 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;
- Set<SubscriptionAliasContext> subscriptionAliasContextSet = null;
-
- writeLock.lock();
- try {
- //check if a set of CartridgeTypeContext instances already exist for given tenant Id
- 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
- cartridgeTypeContext = typeCtxIterator.next();
- if (cartridgeTypeContext.getType().equals(cartridgeType)){
- //if so, get the SubscriptionAliasContext set
- subscriptionAliasContextSet = cartridgeTypeContext.getSubscriptionAliasContextSet();
- break;
- }
- }
- if(subscriptionAliasContextSet != null) {
- //iterate through the set
- Iterator<SubscriptionAliasContext> aliasIterator = subscriptionAliasContextSet.iterator();
- while (aliasIterator.hasNext()) {
- //see if the set contains a SubscriptionAliasContext instance with the given alias
- SubscriptionAliasContext subscriptionAliasContext = aliasIterator.next();
- if (subscriptionAliasContext.getSubscriptionAlias().equals(subscriptionAlias)) {
- //remove the existing one
- aliasIterator.remove();
- break;
- }
- }
- }
- }
-
- } finally {
- writeLock.unlock();
- }
- }
-
- private class CartridgeTypeContext {
-
- private String type;
- private Set<SubscriptionAliasContext> subscriptionAliasContextSet;
-
- public CartridgeTypeContext (String type) {
- this.type = type;
- }
-
- public void setSubscriptionAliasContextSet (Set<SubscriptionAliasContext> subscriptionAliasContextSet) {
- this.subscriptionAliasContextSet = subscriptionAliasContextSet;
- }
-
- public String getType () {
- return type;
- }
-
- public Set<SubscriptionAliasContext> getSubscriptionAliasContextSet () {
- return subscriptionAliasContextSet;
- }
-
- public boolean equals(Object other) {
-
- if(this == other) {
- return true;
- }
- if(!(other instanceof CartridgeTypeContext)) {
- return false;
- }
-
- CartridgeTypeContext that = (CartridgeTypeContext)other;
- return this.type.equals(that.type);
- }
-
- public int hashCode () {
- return type.hashCode();
- }
- }
-
- private class SubscriptionAliasContext {
-
- private String subscriptionAlias;
- private Cluster cluster;
-
- public SubscriptionAliasContext(String subscriptionAlias, Cluster cluster) {
- this.subscriptionAlias = subscriptionAlias;
- this.cluster = cluster;
- }
-
- public String getSubscriptionAlias () {
- return subscriptionAlias;
- }
-
- public Cluster getCluster () {
- return cluster;
- }
-
- public boolean equals(Object other) {
-
- if(this == other) {
- return true;
- }
- if(!(other instanceof SubscriptionAliasContext)) {
- return false;
- }
-
- SubscriptionAliasContext that = (SubscriptionAliasContext)other;
- return this.subscriptionAlias.equals(that.subscriptionAlias);
- }
-
- public int hashCode () {
- 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);
- }
- }
-}
[2/3] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-stratos into topology_mgr
Posted by is...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos into topology_mgr
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/fdabc1d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/fdabc1d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/fdabc1d8
Branch: refs/heads/master
Commit: fdabc1d88f356fcbc2c17a5f40c8a16a40de6286
Parents: 122a421 e178cc2
Author: Isuru <is...@wso2.com>
Authored: Wed Dec 11 11:44:24 2013 +0530
Committer: Isuru <is...@wso2.com>
Committed: Wed Dec 11 11:44:24 2013 +0530
----------------------------------------------------------------------
.../autoscaler/api/AutoScalerServiceImpl.java | 39 +-
.../deployment/policy/DeploymentPolicy.java | 22 +-
.../interfaces/AutoScalerServiceInterface.java | 5 +-
.../internal/AutoscalerServerComponent.java | 217 ++++--
.../autoscaler/partition/PartitionManager.java | 26 +-
.../partition/deployers/PartitionDeployer.java | 2 +-
.../autoscaler/policy/PolicyManager.java | 122 ++--
.../deployers/AutoscalerPolicyDeployer.java | 7 +-
.../deployers/DeploymentPolicyDeployer.java | 6 +-
.../policy/model/AutoscalePolicy.java | 5 +-
.../autoscaler/policy/model/LoadAverage.java | 7 +-
.../autoscaler/policy/model/LoadThresholds.java | 5 +-
.../policy/model/MemoryConsumption.java | 7 +-
.../policy/model/RequestsInFlight.java | 7 +-
.../autoscaler/registry/RegistryManager.java | 21 +-
.../autoscaler/util/AutoScalerConstants.java | 2 +
.../stratos/autoscaler/util/AutoscalerUtil.java | 2 +
.../stratos/autoscaler/util/Deserializer.java | 96 +++
...oadBalancerInFlightRequestCountNotifier.java | 25 +-
.../messaging/domain/topology/Cluster.java | 27 +
.../messaging/domain/topology/Member.java | 7 +
.../messaging/domain/topology/MemberStatus.java | 3 +
.../util/bean/type/map/MapAdapter.java | 52 ++
.../util/bean/type/map/MapEntryType.java | 32 +
.../messaging/util/bean/type/map/MapType.java | 28 +
.../endpoint/bean/util/type/map/MapAdapter.java | 52 ++
.../bean/util/type/map/MapEntryType.java | 32 +
.../endpoint/bean/util/type/map/MapType.java | 28 +
tools/stratos-installer/conf/setup.conf | 80 +-
.../stratos-installer/config/sc/bin/stratos.sh | 301 --------
.../config/sc/repository/conf/axis2/axis2.xml | 724 -------------------
.../repository/conf/cartridge-config.properties | 23 +-
.../sc/repository/conf/etc/logging-config.xml | 40 -
.../config/sc/repository/conf/log4j.properties | 171 -----
tools/stratos-installer/setup.sh | 231 ++----
tools/stratos-installer/start-servers.sh | 2 +-
36 files changed, 803 insertions(+), 1653 deletions(-)
----------------------------------------------------------------------
[3/3] git commit: Merge branch 'topology_mgr'
Posted by is...@apache.org.
Merge branch 'topology_mgr'
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/65616031
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/65616031
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/65616031
Branch: refs/heads/master
Commit: 656160317464b387050ed7f8ac2d04ca042bcda4
Parents: f8bd48a fdabc1d
Author: Isuru <is...@wso2.com>
Authored: Wed Dec 11 11:45:20 2013 +0530
Committer: Isuru <is...@wso2.com>
Committed: Wed Dec 11 11:45:20 2013 +0530
----------------------------------------------------------------------
.../processor/InstanceStatusProcessor.java | 11 +-
.../model/TopologyClusterInformationModel.java | 477 +++++++++++++++++++
.../topology/model/TopologyClusterModel.java | 477 -------------------
3 files changed, 483 insertions(+), 482 deletions(-)
----------------------------------------------------------------------