You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by sa...@apache.org on 2014/02/11 20:19:18 UTC

[1/5] Cleaned up cartridge-config.properties file and PersistenceManager related unwanted code, fixing STRATOS-274 and STRATOS-416

Updated Branches:
  refs/heads/master 469b8c6a0 -> c5939faf5


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/PersistenceManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/PersistenceManager.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/PersistenceManager.java
deleted file mode 100644
index 4caa60b..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/PersistenceManager.java
+++ /dev/null
@@ -1,892 +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.manager.utils;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
-import org.apache.stratos.manager.dao.DataCartridge;
-import org.apache.stratos.manager.dao.PortMapping;
-import org.apache.stratos.manager.dao.RepositoryCredentials;
-import org.apache.stratos.manager.deploy.service.Service;
-import org.apache.stratos.manager.repository.Repository;
-
-/**
- * This class is responsible for handling persistence
- * 
- */
-public class PersistenceManager {
-
-	private static final Log log = LogFactory.getLog(PersistenceManager.class);
-
-	public static void persistCartridgeInstanceInfo(String instanceIp, String clusterDomain, String clusterSubDomain,
-			String cartridgeType, String state) throws Exception {
-
-		Connection con = null;
-		PreparedStatement statement = null;
-		PreparedStatement updateStatement = null;
-		ResultSet resultSet = null;
-
-		boolean isUpdate = false;
-		int instanceId = 0;
-		try {
-			con = StratosDBUtils.getConnection();
-
-			// First check whether Ip exists..
-			String sql = "SELECT ID FROM CARTRIDGE_INSTANCE where INSTANCE_IP=? AND CARTRIDGE_TYPE=? "
-					+ " AND CLUSTER_DOMAIN=? AND CLUSTER_SUBDOMAIN=?";
-			statement = con.prepareStatement(sql);
-			statement.setString(1, instanceIp);
-			statement.setString(2, cartridgeType);
-			statement.setString(3, clusterDomain);
-			statement.setString(4, clusterSubDomain);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			if (resultSet.next()) {
-				isUpdate = true;
-				instanceId = resultSet.getInt("ID");
-			}
-
-			String persistQuery = null;
-			if (isUpdate) {
-				persistQuery = "UPDATE CARTRIDGE_INSTANCE SET STATE=?" + " WHERE ID=?";
-				updateStatement = con.prepareStatement(persistQuery);
-				updateStatement.setString(1, state);
-				updateStatement.setInt(2, instanceId);
-			} else {
-				persistQuery = "INSERT INTO CARTRIDGE_INSTANCE (INSTANCE_IP, CARTRIDGE_TYPE, STATE, CLUSTER_DOMAIN, CLUSTER_SUBDOMAIN)"
-						+ " VALUES (?, ?, ?, ?, ?)";
-				updateStatement = con.prepareStatement(persistQuery);
-				updateStatement.setString(1, instanceIp);
-				updateStatement.setString(2, cartridgeType);
-				updateStatement.setString(3, state);
-				updateStatement.setString(4, clusterDomain);
-				updateStatement.setString(5, clusterSubDomain);
-			}
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + persistQuery);
-			}
-			updateStatement.executeUpdate();
-			con.commit();
-		} catch (Exception e) {
-			if (con != null) {
-				try {
-					con.rollback();
-				} catch (SQLException e1) {
-					log.error("Failed to rollback", e);
-				}
-			}
-			;
-			log.error("Error", e);
-			throw e;
-		} finally {
-			StratosDBUtils.closeResultSet(resultSet);
-			StratosDBUtils.closeAllConnections(con, statement, updateStatement);
-		}
-	}
-
-	public static boolean isAlreadySubscribed(String cartridgeType, int tenantId) throws Exception {
-
-		Connection con = null;
-		PreparedStatement preparedStatement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT C.ALIAS FROM CARTRIDGE_SUBSCRIPTION C WHERE TENANT_ID = ? AND C.CARTRIDGE = ? AND C.STATE != 'UNSUBSCRIBED'";
-			preparedStatement = con.prepareStatement(sql);
-			preparedStatement.setInt(1, tenantId);
-			preparedStatement.setString(2, cartridgeType);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = preparedStatement.executeQuery();
-			if (resultSet.next()) {
-				String alias = resultSet.getString("ALIAS");
-				if (log.isDebugEnabled()) {
-					log.debug("Already subscribed to " + cartridgeType + " with alias " + alias);
-				}
-				return true;
-			} else {
-				return false;
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, preparedStatement, resultSet);
-		}
-	}
-
-	public static List<CartridgeSubscriptionInfo> retrieveSubscribedCartridges(int tenantId) throws Exception {
-
-		List<CartridgeSubscriptionInfo> subscribedCartridgeList = new ArrayList<CartridgeSubscriptionInfo>();
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT C.CARTRIDGE, C.ALIAS, C.CLUSTER_DOMAIN, C.CLUSTER_SUBDOMAIN, C.POLICY, C.STATE, "
-					+ "C.TENANT_ID, C.SUBSCRIPTION_ID, C.DATA_CARTRIDGE_ID, D.TYPE, D.USER_NAME, D.PASSWORD, "
-					+ "C.PROVIDER, C.HOSTNAME, C.MAPPED_DOMAIN, R.REPO_NAME FROM CARTRIDGE_SUBSCRIPTION C "
-					+ "LEFT JOIN DATA_CARTRIDGE D on D.DATA_CART_ID=C.DATA_CARTRIDGE_ID  "
-					+ "LEFT JOIN REPOSITORY R ON C.REPO_ID=R.REPO_ID WHERE TENANT_ID=? AND C.STATE != 'UNSUBSCRIBED' "
-					+ "ORDER BY C.SUBSCRIPTION_ID";
-			statement = con.prepareStatement(sql);
-			statement.setInt(1, tenantId);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			while (resultSet.next()) {
-				CartridgeSubscriptionInfo cartridge = new CartridgeSubscriptionInfo();
-				cartridge.setAlias(resultSet.getString("ALIAS"));
-				cartridge.setCartridge(resultSet.getString("CARTRIDGE"));
-				cartridge.setState(resultSet.getString("STATE"));
-				cartridge.setClusterDomain(resultSet.getString("CLUSTER_DOMAIN"));
-				cartridge.setClusterSubdomain(resultSet.getString("CLUSTER_SUBDOMAIN"));
-				cartridge.setProvider(resultSet.getString("PROVIDER"));
-				cartridge.setPolicy(resultSet.getString("POLICY"));
-				cartridge.setMappedDomain(resultSet.getString("MAPPED_DOMAIN"));
-				Repository repo = new Repository();
-				repo.setUrl(resultSet.getString("REPO_NAME"));
-				cartridge.setRepository(repo);
-				cartridge.setHostName(resultSet.getString("HOSTNAME"));
-				int dataCartridgeId = resultSet.getInt("DATA_CARTRIDGE_ID");
-				if (dataCartridgeId != 0) {
-					DataCartridge dataCartridge = new DataCartridge();
-					dataCartridge.setDataCartridgeType(resultSet.getString("TYPE"));
-					dataCartridge.setPassword(resultSet.getString("PASSWORD"));
-					dataCartridge.setUserName(resultSet.getString("USER_NAME"));
-					cartridge.setDataCartridge(dataCartridge);
-				}
-				subscribedCartridgeList.add(cartridge);
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-		return subscribedCartridgeList;
-	}
-
-	public static String getRepoURL(int tenantId, String cartridge) throws Exception {
-
-		String repoUrl = null;
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT REPO_NAME FROM REPOSITORY R, CARTRIDGE_SUBSCRIPTION C "
-					+ "WHERE C.REPO_ID=R.REPO_ID AND C.TENANT_ID=? AND C.CARTRIDGE=? "
-					+ "AND C.STATE != 'UNSUBSCRIBED' ";
-			statement = con.prepareStatement(sql);
-			statement.setInt(1, tenantId);
-			statement.setString(2, cartridge);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			if (resultSet.next()) {
-				repoUrl = resultSet.getString("REPO_NAME");
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-		return repoUrl;
-	}
-
-	public static RepositoryCredentials getRepoCredentials(int tenantId, String cartridge, String alias)
-			throws Exception {
-
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-		RepositoryCredentials repoCredentials = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT REPO_NAME,REPO_USER_NAME,REPO_USER_PASSWORD FROM REPOSITORY R, CARTRIDGE_SUBSCRIPTION C "
-					+ "WHERE C.REPO_ID=R.REPO_ID AND C.TENANT_ID=? AND C.CARTRIDGE=? AND C.STATE != 'UNSUBSCRIBED' ";
-			if (alias != null) {
-				sql = sql + " AND C.ALIAS=?";
-			}
-			statement = con.prepareStatement(sql);
-			statement.setInt(1, tenantId);
-			statement.setString(2, cartridge);
-			if (alias != null) {
-				statement.setString(3, alias);
-			}
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			while (resultSet.next()) {
-				repoCredentials = new RepositoryCredentials();
-				repoCredentials.setUrl(resultSet.getString("REPO_NAME"));
-				repoCredentials.setUserName(resultSet.getString("REPO_USER_NAME"));
-				repoCredentials.setPassword(RepoPasswordMgtUtil.decryptPassword(resultSet.getString("REPO_USER_PASSWORD"),null)); // TODO this is no longer supported
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-		return repoCredentials;
-	}
-
-	public static boolean isAliasAlreadyTaken(String alias, String cartridgeType) throws Exception {
-		boolean aliasAlreadyTaken = false;
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT SUBSCRIPTION_ID FROM CARTRIDGE_SUBSCRIPTION where ALIAS=? AND CARTRIDGE=? AND STATE != 'UNSUBSCRIBED'";
-			statement = con.prepareStatement(sql);
-			statement.setString(1, alias);
-			statement.setString(2, cartridgeType);
-			statement.setMaxRows(1);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			if (resultSet.next()) {
-				log.info("Already taken..");
-				aliasAlreadyTaken = true;
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-		return aliasAlreadyTaken;
-	}
-
-	public static int persistSubscription(CartridgeSubscriptionInfo cartridgeSubscriptionInfo) throws Exception {
-
-		int cartridgeSubscriptionId = 0;
-		int repoId = 0;
-		int dataCartridgeId = 0;
-		ResultSet res = null;
-		PreparedStatement insertSubscriptionStmt = null;
-		PreparedStatement insertRepoStmt = null;
-		PreparedStatement insertDataCartStmt = null;
-
-		Connection con = null;
-
-		// persist cartridge_subscription
-		try {
-			con = StratosDBUtils.getConnection();
-			// persist repo
-			if (cartridgeSubscriptionInfo.getRepository() != null) {
-				String encryptedRepoUserPassword = RepoPasswordMgtUtil.encryptPassword(cartridgeSubscriptionInfo.getRepository()
-						.getPassword(),cartridgeSubscriptionInfo.getSubscriptionKey());
-				String insertRepo = "INSERT INTO REPOSITORY (REPO_NAME,STATE,REPO_USER_NAME,REPO_USER_PASSWORD)"
-						+ " VALUES (?,?,?,?)";
-
-				insertRepoStmt = con.prepareStatement(insertRepo, Statement.RETURN_GENERATED_KEYS);
-				insertRepoStmt.setString(1, cartridgeSubscriptionInfo.getRepository().getUrl());
-				insertRepoStmt.setString(2, "ACTIVE");
-				insertRepoStmt.setString(3, cartridgeSubscriptionInfo.getRepository().getUserName());
-				insertRepoStmt.setString(4, encryptedRepoUserPassword);
-				if (log.isDebugEnabled()) {
-					log.debug("Executing insert: " + insertRepo);
-				}
-				insertRepoStmt.executeUpdate();
-				res = insertRepoStmt.getGeneratedKeys();
-				if (res.next()) {
-					repoId = res.getInt(1);
-				}
-				StratosDBUtils.closeResultSet(res);
-			}
-
-			// persist data cartridge
-			if (cartridgeSubscriptionInfo.getDataCartridge() != null) {
-				String insertDataCartridge = "INSERT INTO DATA_CARTRIDGE (TYPE,USER_NAME,PASSWORD,STATE)"
-						+ " VALUES (?,?,?,?)";
-				insertDataCartStmt = con.prepareStatement(insertDataCartridge, Statement.RETURN_GENERATED_KEYS);
-				insertDataCartStmt.setString(1, cartridgeSubscriptionInfo.getDataCartridge().getDataCartridgeType());
-				insertDataCartStmt.setString(2, cartridgeSubscriptionInfo.getDataCartridge().getUserName());
-				insertDataCartStmt.setString(3, cartridgeSubscriptionInfo.getDataCartridge().getPassword());
-				insertDataCartStmt.setString(4, "ACTIVE");
-				if (log.isDebugEnabled()) {
-					log.debug("Executing insert: " + insertDataCartridge);
-				}
-				insertDataCartStmt.executeUpdate();
-				res = insertDataCartStmt.getGeneratedKeys();
-				if (res.next()) {
-					dataCartridgeId = res.getInt(1);
-				}
-				StratosDBUtils.closeResultSet(res);
-			}
-
-			// TODO - Mapped domain is not used. Is it not used anymore?
-			String insertSubscription = "INSERT INTO CARTRIDGE_SUBSCRIPTION (TENANT_ID, CARTRIDGE, PROVIDER,"
-					+ "HOSTNAME, POLICY, CLUSTER_DOMAIN, CLUSTER_SUBDOMAIN, MGT_DOMAIN, MGT_SUBDOMAIN, STATE, "
-					+ "ALIAS, TENANT_DOMAIN, BASE_DIR, REPO_ID, DATA_CARTRIDGE_ID, SUBSCRIPTION_KEY)"
-					+ " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
-
-			insertSubscriptionStmt = con.prepareStatement(insertSubscription, Statement.RETURN_GENERATED_KEYS);
-			insertSubscriptionStmt.setInt(1, cartridgeSubscriptionInfo.getTenantId());
-			insertSubscriptionStmt.setString(2, cartridgeSubscriptionInfo.getCartridge());
-			insertSubscriptionStmt.setString(3, cartridgeSubscriptionInfo.getProvider());
-			insertSubscriptionStmt.setString(4, cartridgeSubscriptionInfo.getHostName());
-			insertSubscriptionStmt.setString(5, cartridgeSubscriptionInfo.getPolicy());
-			insertSubscriptionStmt.setString(6, cartridgeSubscriptionInfo.getClusterDomain());
-			insertSubscriptionStmt.setString(7, cartridgeSubscriptionInfo.getClusterSubdomain());
-			insertSubscriptionStmt.setString(8, cartridgeSubscriptionInfo.getMgtClusterDomain());
-			insertSubscriptionStmt.setString(9, cartridgeSubscriptionInfo.getMgtClusterSubDomain());
-			insertSubscriptionStmt.setString(10, cartridgeSubscriptionInfo.getState());
-			insertSubscriptionStmt.setString(11, cartridgeSubscriptionInfo.getAlias());
-			insertSubscriptionStmt.setString(12, cartridgeSubscriptionInfo.getTenantDomain());
-			insertSubscriptionStmt.setString(13, cartridgeSubscriptionInfo.getBaseDirectory());
-			insertSubscriptionStmt.setInt(14, repoId);
-			insertSubscriptionStmt.setInt(15, dataCartridgeId);
-			insertSubscriptionStmt.setString(16, cartridgeSubscriptionInfo.getSubscriptionKey());
-			if (log.isDebugEnabled()) {
-				log.debug("Executing insert: " + insertSubscription);
-			}
-			insertSubscriptionStmt.executeUpdate();
-			res = insertSubscriptionStmt.getGeneratedKeys();
-			if (res.next()) {
-				cartridgeSubscriptionId = res.getInt(1);
-			}
-
-			List<PortMapping> portMapping = cartridgeSubscriptionInfo.getPortMappings();
-			// persist port map
-			if (portMapping != null && !portMapping.isEmpty()) {
-				for (PortMapping portMap : portMapping) {
-					String insertPortMapping = "INSERT INTO PORT_MAPPING (SUBSCRIPTION_ID, TYPE, PRIMARY_PORT, PROXY_PORT, STATE)"
-							+ " VALUES (?,?,?,?,?)";
-
-					PreparedStatement insertPortsStmt = con.prepareStatement(insertPortMapping);
-					insertPortsStmt.setInt(1, cartridgeSubscriptionId);
-					insertPortsStmt.setString(2, portMap.getType());
-					insertPortsStmt.setString(3, portMap.getPrimaryPort());
-					insertPortsStmt.setString(4, portMap.getProxyPort());
-					insertPortsStmt.setString(5, "ACTIVE");
-					if (log.isDebugEnabled()) {
-						log.debug("Executing insert: " + insertPortMapping);
-					}
-					insertPortsStmt.executeUpdate();
-					StratosDBUtils.closeStatement(insertPortsStmt);
-				}
-			}
-			con.commit(); // Commit manually
-		} catch (Exception e) {
-			if (con != null) {
-				try {
-					con.rollback();
-				} catch (SQLException e1) {
-					log.error("Failed to rollback", e);
-				}
-			}
-			;
-			log.error(e.getMessage());
-			String msg = "Exception : " + e.getMessage();
-			log.error(msg, e);
-			throw new Exception("Subscription failed!", e);
-		} finally {
-			StratosDBUtils.closeResultSet(res);
-			StratosDBUtils.closeAllConnections(con, insertRepoStmt, insertDataCartStmt, insertSubscriptionStmt);
-		}
-		return cartridgeSubscriptionId;
-	}
-
-	public static String getHostNameForCartridgeName(int tenantId, String alias) throws Exception {
-
-		String hostName = null;
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT HOSTNAME FROM CARTRIDGE_SUBSCRIPTION where TENANT_ID=?"
-					+ " AND ALIAS=? AND STATE != 'UNSUBSCRIBED'";
-			statement = con.prepareStatement(sql);
-			statement.setInt(1, tenantId);
-			statement.setString(2, alias);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			if (resultSet.next()) {
-				hostName = resultSet.getString("HOSTNAME");
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-		return hostName;
-	}
-
-	public static CartridgeSubscriptionInfo getSubscription(String tenantDomain, String alias) throws Exception {
-
-		CartridgeSubscriptionInfo cartridgeSubscriptionInfo = null;
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT * FROM CARTRIDGE_SUBSCRIPTION C left join REPOSITORY R on "
-					+ "C.REPO_ID=R.REPO_ID left join DATA_CARTRIDGE D on "
-					+ "D.DATA_CART_ID=C.DATA_CARTRIDGE_ID WHERE ALIAS=? AND TENANT_DOMAIN=? AND C.STATE != 'UNSUBSCRIBED'";
-			statement = con.prepareStatement(sql);
-			statement.setString(1, alias);
-			statement.setString(2, tenantDomain);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			if (resultSet.next()) {
-				cartridgeSubscriptionInfo = new CartridgeSubscriptionInfo();
-				populateSubscription(cartridgeSubscriptionInfo, resultSet);
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-
-		return cartridgeSubscriptionInfo;
-	}
-
-	private static void populateSubscription(CartridgeSubscriptionInfo cartridgeSubscriptionInfo, ResultSet resultSet)
-			throws Exception {
-		String repoName = resultSet.getString("REPO_NAME");
-		String repoUserName = resultSet.getString("REPO_USER_NAME");
-		String repoPassword = resultSet.getString("REPO_USER_PASSWORD");
-		if (repoName != null) {
-			Repository repo = new Repository();
-			repo.setUrl(repoName);
-			repo.setUserName(repoUserName);
-			repo.setPassword(repoPassword);
-			cartridgeSubscriptionInfo.setRepository(repo);
-		}
-
-		int dataCartridgeId = resultSet.getInt("DATA_CARTRIDGE_ID");
-		if (dataCartridgeId != 0) {
-			DataCartridge dataCartridge = new DataCartridge();
-			dataCartridge.setDataCartridgeType(resultSet.getString("TYPE"));
-			dataCartridge.setPassword(resultSet.getString("PASSWORD"));
-			dataCartridge.setUserName(resultSet.getString("USER_NAME"));
-			cartridgeSubscriptionInfo.setDataCartridge(dataCartridge);
-		}
-		cartridgeSubscriptionInfo.setPortMappings(getPortMappings(resultSet.getInt("SUBSCRIPTION_ID")));
-		cartridgeSubscriptionInfo.setTenantId(resultSet.getInt("TENANT_ID"));
-		cartridgeSubscriptionInfo.setState(resultSet.getString("STATE"));
-		cartridgeSubscriptionInfo.setPolicy(resultSet.getString("POLICY"));
-		cartridgeSubscriptionInfo.setCartridge(resultSet.getString("CARTRIDGE"));
-		cartridgeSubscriptionInfo.setAlias(resultSet.getString("ALIAS"));
-		cartridgeSubscriptionInfo.setClusterDomain(resultSet.getString("CLUSTER_DOMAIN"));
-		cartridgeSubscriptionInfo.setClusterSubdomain(resultSet.getString("CLUSTER_SUBDOMAIN"));
-		cartridgeSubscriptionInfo.setMgtClusterDomain(resultSet.getString("MGT_DOMAIN"));
-		cartridgeSubscriptionInfo.setMgtClusterSubDomain(resultSet.getString("MGT_SUBDOMAIN"));
-		cartridgeSubscriptionInfo.setProvider(resultSet.getString("PROVIDER"));
-		cartridgeSubscriptionInfo.setHostName(resultSet.getString("HOSTNAME"));
-		cartridgeSubscriptionInfo.setTenantDomain(resultSet.getString("TENANT_DOMAIN"));
-		cartridgeSubscriptionInfo.setBaseDirectory(resultSet.getString("BASE_DIR"));
-		cartridgeSubscriptionInfo.setSubscriptionId(resultSet.getInt("SUBSCRIPTION_ID"));
-		cartridgeSubscriptionInfo.setMappedDomain(resultSet.getString("MAPPED_DOMAIN"));
-		cartridgeSubscriptionInfo.setSubscriptionKey(resultSet.getString("SUBSCRIPTION_KEY"));
-	}
-
-	private static List<PortMapping> getPortMappings(int subscriptionId) throws Exception {
-
-		List<PortMapping> portMappingList = new ArrayList<PortMapping>();
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT * FROM PORT_MAPPING WHERE SUBSCRIPTION_ID = ?";
-			statement = con.prepareStatement(sql);
-			statement.setInt(1, subscriptionId);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			while (resultSet.next()) {
-				PortMapping portMapping = new PortMapping();
-				portMapping.setPrimaryPort(resultSet.getString("PRIMARY_PORT"));
-				portMapping.setProxyPort(resultSet.getString("PROXY_PORT"));
-				portMapping.setType(resultSet.getString("TYPE"));
-				portMappingList.add(portMapping);
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-		return portMappingList;
-	}
-
-	public static void updateDomainMapping(int tenantId, String cartridgeAlias, String domain) throws Exception {
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "UPDATE CARTRIDGE_SUBSCRIPTION SET MAPPED_DOMAIN = ? WHERE TENANT_ID = ? AND ALIAS = ?";
-			statement = con.prepareStatement(sql);
-			statement.setString(1, domain);
-			statement.setInt(2, tenantId);
-			statement.setString(3, cartridgeAlias);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing update: " + sql);
-			}
-			statement.executeUpdate();
-			con.commit();
-		} catch (Exception s) {
-			if (con != null) {
-				try {
-					con.rollback();
-				} catch (SQLException e) {
-					log.error("Failed to rollback", e);
-				}
-			}
-			String msg = "Error: " + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-	}
-
-	public static List<CartridgeSubscriptionInfo> getSubscription(String repositoryURL) throws Exception {
-
-		List<CartridgeSubscriptionInfo> subscriptionList = new ArrayList<CartridgeSubscriptionInfo>();
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT * from CARTRIDGE_SUBSCRIPTION C, REPOSITORY R "
-					+ "where R.REPO_NAME LIKE ? AND C.REPO_ID = R.REPO_ID AND C.STATE != 'UNSUBSCRIBED'";
-			statement = con.prepareStatement(sql);
-			statement.setString(1, repositoryURL + "%");
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			while (resultSet.next()) {
-				CartridgeSubscriptionInfo cartridgeSubscriptionInfo = new CartridgeSubscriptionInfo();
-				populateSubscription(cartridgeSubscriptionInfo, resultSet);
-				subscriptionList.add(cartridgeSubscriptionInfo);
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-		return subscriptionList;
-	}
-
-    public static List<CartridgeSubscriptionInfo> getSubscriptionsForTenant (int tenantId) throws Exception {
-
-        List<CartridgeSubscriptionInfo> cartridgeSubscriptionInfos = null;
-        Connection con = null;
-        PreparedStatement statement = null;
-        ResultSet resultSet = null;
-
-        try {
-            con = StratosDBUtils.getConnection();
-            String sql = "SELECT * FROM CARTRIDGE_SUBSCRIPTION C left join REPOSITORY R on "
-                    + "C.REPO_ID=R.REPO_ID left join DATA_CARTRIDGE D on "
-                    + "D.DATA_CART_ID=C.DATA_CARTRIDGE_ID WHERE TENANT_ID=? AND C.STATE != 'UNSUBSCRIBED'";
-            statement = con.prepareStatement(sql);
-            statement.setInt(1, tenantId);
-            if (log.isDebugEnabled()) {
-                log.debug("Executing query: " + sql);
-            }
-
-            resultSet = statement.executeQuery();
-            cartridgeSubscriptionInfos = new ArrayList<CartridgeSubscriptionInfo>();
-            if (resultSet.next()) {
-                CartridgeSubscriptionInfo cartridgeSubscriptionInfo = new CartridgeSubscriptionInfo();
-                populateSubscription(cartridgeSubscriptionInfo, resultSet);
-                cartridgeSubscriptionInfos.add(cartridgeSubscriptionInfo);
-            }
-        } catch (Exception s) {
-            String msg = "Error while sql connection :" + s.getMessage();
-            log.error(msg, s);
-            throw s;
-
-        } finally {
-            StratosDBUtils.closeAllConnections(con, statement, resultSet);
-        }
-
-        return cartridgeSubscriptionInfos;
-    }
-
-
-    public static void updateSubscriptionState(int subscriptionId, String state) throws Exception {
-
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "UPDATE CARTRIDGE_SUBSCRIPTION SET STATE=? WHERE SUBSCRIPTION_ID=?";
-			statement = con.prepareStatement(sql);
-			statement.setString(1, state);
-			statement.setInt(2, subscriptionId);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing update: " + sql);
-			}
-			statement.executeUpdate();
-			con.commit();
-		} catch (Exception s) {
-			if (con != null) {
-				try {
-					con.rollback();
-				} catch (SQLException e) {
-					log.error("Failed to rollback", e);
-				}
-			}
-			;
-			String msg = "Error: " + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-	}
-
-	public static Map<String, String> getCartridgeInstanceInfo(String[] ips, String clusterDomain, String clusterSubdomain)
-            throws Exception {
-		Map<String, String> instanceIpToStateMap = new HashMap<String, String>();
-		
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-		
-		try {
-			con = StratosDBUtils.getConnection();
-			StringBuilder sqlBuilder = new StringBuilder(
-					"SELECT INSTANCE_IP, STATE FROM CARTRIDGE_INSTANCE WHERE INSTANCE_IP IN (");
-			for (int i = 0; i < ips.length; i++) {
-				if (i > 0) {
-					sqlBuilder.append(", ");
-				}
-				sqlBuilder.append("?");
-			}
-			sqlBuilder.append(") AND CLUSTER_DOMAIN=? AND CLUSTER_SUBDOMAIN=?");
-			String sql = sqlBuilder.toString();
-			
-			statement = con.prepareStatement(sql);
-			int i = 1;
-			for (int j = 0; j < ips.length; j++, i++) {
-				String ip = ips[j];
-				statement.setString(i, ip);
-			}
-			statement.setString(i++, clusterDomain);
-			statement.setString(i, clusterSubdomain);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			while (resultSet.next()) {
-				instanceIpToStateMap.put(resultSet.getString("INSTANCE_IP"), resultSet.getString("STATE"));
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw new Exception("Ann error occurred while listing cartridge information.");
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-		return instanceIpToStateMap;
-	}
-
-	
-
-	public static void updateInstanceState(String state, String[] ips, String clusterDomain, String clusterSubDomain, String cartridgeType)
-			throws Exception {
-
-		Connection con = null;
-		PreparedStatement statement = null;
-
-		if (ips != null && ips.length > 0) {
-			try {
-				con = StratosDBUtils.getConnection();
-				StringBuilder sqlBuilder = new StringBuilder(
-						"UPDATE CARTRIDGE_INSTANCE SET STATE=? WHERE INSTANCE_IP IN (");
-				for (int i = 0; i < ips.length; i++) {
-					if (i > 0) {
-						sqlBuilder.append(", ");
-					}
-					sqlBuilder.append("?");
-				}
-				sqlBuilder.append(") AND CLUSTER_DOMAIN=? AND CLUSTER_SUBDOMAIN=? AND CARTRIDGE_TYPE=?");
-				String sql = sqlBuilder.toString();
-				statement = con.prepareStatement(sql);
-				statement.setString(1, state);
-				int i = 2;
-				for (int j = 0; j < ips.length; j++, i++) {
-					String ip = ips[j];
-					statement.setString(i, ip);
-				}
-				statement.setString(i++, clusterDomain);
-				statement.setString(i++, clusterSubDomain);
-				statement.setString(i, cartridgeType);
-				if (log.isDebugEnabled()) {
-					log.debug("Executing query: " + sql);
-				}
-				statement.executeUpdate();
-				con.commit();
-			} catch (Exception s) {
-				if (con != null) {
-					try {
-						con.rollback();
-					} catch (SQLException e) {
-						log.error("Failed to rollback", e);
-					}
-				}
-				String msg = "Error: " + s.getMessage();
-				log.error(msg, s);
-				throw s;
-			} finally {
-				StratosDBUtils.closeAllConnections(con, statement);
-			}
-		}
-
-	}
-	
-	
-	public static CartridgeSubscriptionInfo getSubscriptionFromClusterId(String clusterId) throws Exception {
-
-		CartridgeSubscriptionInfo cartridgeSubscriptionInfo = null;
-		Connection con = null;
-		PreparedStatement statement = null;
-		ResultSet resultSet = null;
-
-		try {
-			con = StratosDBUtils.getConnection();
-			String sql = "SELECT * FROM CARTRIDGE_SUBSCRIPTION C left join REPOSITORY R on "
-					+ "C.REPO_ID=R.REPO_ID left join DATA_CARTRIDGE D on "
-					+ "D.DATA_CART_ID=C.DATA_CARTRIDGE_ID WHERE C.CLUSTER_DOMAIN=? AND C.STATE != 'UNSUBSCRIBED'";
-			statement = con.prepareStatement(sql);
-			statement.setString(1, clusterId);
-			if (log.isDebugEnabled()) {
-				log.debug("Executing query: " + sql);
-			}
-			resultSet = statement.executeQuery();
-			if (resultSet.next()) {
-				cartridgeSubscriptionInfo = new CartridgeSubscriptionInfo();
-				populateSubscription(cartridgeSubscriptionInfo, resultSet);
-			}
-		} catch (Exception s) {
-			String msg = "Error while sql connection :" + s.getMessage();
-			log.error(msg, s);
-			throw s;
-		} finally {
-			StratosDBUtils.closeAllConnections(con, statement, resultSet);
-		}
-
-		return cartridgeSubscriptionInfo;
-	}
-	
-	
-	public static void persistService(Service service) throws Exception {
-
-		Connection con = null;
-		PreparedStatement insertServiceStmt = null;
-
-		String insertServiceSQL = "INSERT INTO SERVICE (TYPE, AUTOSCALING_POLICY,DEPLOYMENT_POLICY,TENANT_RANGE,"
-				+ "CLUSTER_ID,HOST_NAME,SUBSCRIPTION_KEY)"
-				+ " VALUES (?,?,?,?,?,?,?)";
-
-		try {
-
-			con = StratosDBUtils.getConnection();
-			insertServiceStmt = con.prepareStatement(insertServiceSQL);
-			insertServiceStmt.setString(1, service.getType());
-			insertServiceStmt.setString(2, service.getAutoscalingPolicyName());
-			insertServiceStmt.setString(3, service.getDeploymentPolicyName());
-			insertServiceStmt.setString(4, service.getTenantRange());
-			insertServiceStmt.setString(5, service.getClusterId());
-			insertServiceStmt.setString(6, service.getHostName());
-			insertServiceStmt.setString(7, service.getSubscriptionKey());
-			insertServiceStmt.executeUpdate();
-			con.commit();
-			if (log.isDebugEnabled()) {
-				log.debug(" Service " + service.getType() + " is inserted into DB");
-			}
-		} catch (Exception e) {
-			String msg = "Error while sql connection :" + e.getMessage();
-			log.error(msg, e);
-			throw e;
-		} finally {
-			StratosDBUtils.closeStatement(insertServiceStmt);
-		}
-
-	} 
-	
-	
-	public static Service getServiceFromCartridgeType(String cartridgeType) {
-		return null;
-	}
-
-	
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/RepositoryFactory.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/RepositoryFactory.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/RepositoryFactory.java
deleted file mode 100644
index d4cb14d..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/RepositoryFactory.java
+++ /dev/null
@@ -1,131 +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.manager.utils;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.service.ApplicationManagementService;
-import org.wso2.carbon.utils.CarbonUtils;
-
-import java.io.File;
-
-/**
- * @author wso2
- * 
- */
-public class RepositoryFactory {
-
-	private static final Log log = LogFactory.getLog(ApplicationManagementService.class);
-
-	/*public synchronized Repository createRepository(String cartridgeName, String tenantDomain,
-	                                          String userName) throws Exception {
-
-		Repository repository = new Repository();
-		String repoName = tenantDomain + "/" + cartridgeName; // removed .git part
-		String repoUserName = userName + "@" + tenantDomain;
-
-		Process proc;
-		try {
-
-			String command =
-			                 CarbonUtils.getCarbonHome() + File.separator + "bin" + File.separator +
-			                         "manage-git-repo.sh " + "create " + repoUserName + " " +
-			                         tenantDomain + " " + cartridgeName + " " +
-			                         System.getProperty(CartridgeConstants.REPO_NOTIFICATION_URL) + " " +
-			                         System.getProperty(CartridgeConstants.GIT_HOST_NAME) +
-			                         " /";
-			proc = Runtime.getRuntime().exec(command);
-			log.info("executing manage-git-repo script..... command :" + command);
-			proc.waitFor();
-			log.info(" Repo is created ..... for user: " + userName + ", tenantName: " +
-			         tenantDomain + " ");
-			repository.setRepoName("git@" + System.getProperty(CartridgeConstants.GIT_HOST_NAME) + ":" +repoName);
-		} catch (Exception e) {
-			log.error(" Exception is occurred when executing manage-git-repo script. Reason :" +
-			          e.getMessage());
-			handleException(e.getMessage(), e);
-		}
-
-		return repository;
-
-	}*/
-
-	/*public synchronized void createGitFolderStructure(String tenantDomain, String cartridgeName,
-	                                            String[] dirArray) throws Exception {
-
-		log.info("In create Git folder structure...!");
-
-		StringBuffer dirBuffer = new StringBuffer();
-		for (String dir : dirArray) {
-			dirBuffer.append(dir).append(" ");
-		}
-
-		Process proc;
-		try {
-			String command =
-			                 CarbonUtils.getCarbonHome() + File.separator + "bin" + File.separator +
-			                         "git-folder-structure.sh " + tenantDomain + " " +
-			                         cartridgeName + " " + dirBuffer.toString() + " /";
-			proc = Runtime.getRuntime().exec(command);
-			log.info("executing manage-git-repo script..... command : " + command);
-			proc.waitFor();
-
-		} catch (Exception e) {
-			log.error(" Exception is occurred when executing manage-git-repo script. Reason :" +
-			          e.getMessage());
-			handleException(e.getMessage(), e);
-		}
-
-		log.info(" Folder structure  is created ..... ");
-
-	}*/
-	
-	public synchronized void destroyRepository(String cartridgeName, String tenantDomain,
-	                                          String userName) throws Exception {
-
-		String repoUserName = userName + "@" + tenantDomain;
-
-		Process proc;
-		try {
-
-			String command =
-			                 CarbonUtils.getCarbonHome() + File.separator + "bin" + File.separator +
-			                         "manage-git-repo.sh " + "destroy " + repoUserName + " " +
-			                         tenantDomain + " " + cartridgeName + 
-			                         " /";
-			proc = Runtime.getRuntime().exec(command);
-			log.info("executing manage-git-repo script (destroy)..... command :" + command);
-			proc.waitFor();
-			log.info(" Repo is destroyed ..... for user: " + userName + ", tenantName: " +
-			         tenantDomain + " ");
-		} catch (Exception e) {
-			log.error(" Exception is occurred when destroying git repo. Reason :" +
-			          e.getMessage());
-			handleException(e.getMessage(), e);
-		}
-
-	}
-
-	private void handleException(String msg, Exception e) throws Exception {
-		log.error(msg, e);
-		throw new Exception(msg, e);
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/StratosDBUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/StratosDBUtils.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/StratosDBUtils.java
deleted file mode 100644
index c884014..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/StratosDBUtils.java
+++ /dev/null
@@ -1,213 +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.manager.utils;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.tomcat.jdbc.pool.DataSource;
-import org.apache.tomcat.jdbc.pool.PoolProperties;
-
-public final class StratosDBUtils {
-
-	private static final Log log = LogFactory.getLog(StratosDBUtils.class);
-
-	private static volatile javax.sql.DataSource dataSource = null;
-
-	/**
-	 * Initializes the data source
-	 * 
-	 * @throws RuntimeException
-	 *             if an error occurs while loading DB configuration
-	 */
-	public static void initialize() throws Exception {
-		if (dataSource != null) {
-			return;
-		}
-
-		synchronized (StratosDBUtils.class) {
-			if (dataSource == null) {
-
-				String datasourceName = System.getProperty(CartridgeConstants.DB_DATASOURCE);
-
-				if (datasourceName != null && datasourceName.trim().length() > 0) {
-					if (log.isInfoEnabled()) {
-						log.info("Initializing data source: " + datasourceName);
-					}
-					try {
-						Context ctx = new InitialContext();
-						dataSource = (DataSource) ctx.lookup(datasourceName);
-						if (dataSource != null && log.isInfoEnabled()) {
-							log.info("Found data source: " + datasourceName + ", " + dataSource.getClass().getName());
-						}
-					} catch (NamingException e) {
-						throw new RuntimeException("Error while looking up the data source: " + datasourceName, e);
-					}
-				} else {
-					// FIXME Should we use system properties to get database
-					// details?
-					String dbUrl = System.getProperty(CartridgeConstants.DB_URL);
-					String driver = System.getProperty(CartridgeConstants.DB_DRIVER);
-					String username = System.getProperty(CartridgeConstants.DB_USERNAME);
-					String password = System.getProperty(CartridgeConstants.DB_PASSWORD);
-
-					if (dbUrl == null || driver == null || username == null || password == null) {
-						String msg = "Required DB configuration parameters are not specified.";
-						log.warn(msg);
-						throw new RuntimeException(msg);
-					}
-					
-					if (log.isInfoEnabled()) {
-						log.info("Initializing data source for JDBC URL: " + dbUrl);
-					}
-
-					PoolProperties p = new PoolProperties();
-					p.setUrl(dbUrl);
-					p.setDriverClassName(driver);
-					p.setUsername(username);
-					p.setPassword(password);
-					p.setJmxEnabled(true);
-					p.setTestWhileIdle(false);
-					p.setTestOnBorrow(true);
-					p.setValidationQuery("SELECT 1");
-					p.setTestOnReturn(false);
-					p.setValidationInterval(30000);
-					p.setTimeBetweenEvictionRunsMillis(30000);
-					p.setMaxActive(100);
-					p.setInitialSize(10);
-					p.setMaxWait(10000);
-					p.setRemoveAbandonedTimeout(60);
-					p.setMinEvictableIdleTimeMillis(30000);
-					p.setMinIdle(10);
-					p.setLogAbandoned(true);
-					p.setRemoveAbandoned(true);
-					p.setDefaultAutoCommit(false);
-					p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
-							+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
-					DataSource tomcatDatasource = new DataSource();
-					tomcatDatasource.setPoolProperties(p);
-
-					dataSource = tomcatDatasource;
-				}
-
-			}
-		}
-	}
-
-	/**
-	 * Utility method to get a new database connection
-	 * 
-	 * @return Connection
-	 * @throws java.sql.SQLException
-	 *             if failed to get Connection
-	 */
-	public static Connection getConnection() throws SQLException {
-		if (dataSource != null) {
-			return dataSource.getConnection();
-		}
-		throw new SQLException("Datasource is not configured properly.");
-	}
-
-	/**
-	 * Utility method to close the connection streams.
-	 * 
-	 * @param connection
-	 *            Connection
-	 * @param preparedStatement
-	 *            PreparedStatement
-	 * @param resultSet
-	 *            ResultSet
-	 */
-	public static void closeAllConnections(Connection connection, PreparedStatement preparedStatement,
-			ResultSet resultSet) {
-		closeResultSet(resultSet);
-		closeStatement(preparedStatement);
-		closeConnection(connection);
-	}
-
-	public static void closeAllConnections(Connection connection, PreparedStatement... preparedStatements) {
-		for (PreparedStatement preparedStatement : preparedStatements) {
-			closeStatement(preparedStatement);
-		}
-		closeConnection(connection);
-	}
-
-	/**
-	 * Close Connection
-	 * 
-	 * @param dbConnection
-	 *            Connection
-	 */
-	public static void closeConnection(Connection dbConnection) {
-		if (dbConnection != null) {
-			try {
-				dbConnection.close();
-			} catch (SQLException e) {
-				log.warn(
-						"Database error. Could not close database connection. Continuing with " + "others. - "
-								+ e.getMessage(), e);
-			}
-		}
-	}
-
-	/**
-	 * Close ResultSet
-	 * 
-	 * @param resultSet
-	 *            ResultSet
-	 */
-	public static void closeResultSet(ResultSet resultSet) {
-		if (resultSet != null) {
-			try {
-				resultSet.close();
-			} catch (SQLException e) {
-				log.warn("Database error. Could not close ResultSet  - " + e.getMessage(), e);
-			}
-		}
-
-	}
-
-	/**
-	 * Close PreparedStatement
-	 * 
-	 * @param preparedStatement
-	 *            PreparedStatement
-	 */
-	public static void closeStatement(PreparedStatement preparedStatement) {
-		if (preparedStatement != null) {
-			try {
-				preparedStatement.close();
-			} catch (SQLException e) {
-				log.warn(
-						"Database error. Could not close PreparedStatement. Continuing with" + " others. - "
-								+ e.getMessage(), e);
-			}
-		}
-
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/resources/META-INF/services.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.manager/src/main/resources/META-INF/services.xml
index 8435bf7..46656af 100644
--- a/components/org.apache.stratos.manager/src/main/resources/META-INF/services.xml
+++ b/components/org.apache.stratos.manager/src/main/resources/META-INF/services.xml
@@ -17,62 +17,7 @@
   #  under the License.
   -->
 <serviceGroup>
-	<service name="ApplicationManagementService" scope="transportsession">
-		<transports>
-			<transport>https</transport>
-		</transports>
-		<description>
-			Admin service for ADC activities
-		</description>
-		<parameter name="ServiceClass">org.apache.stratos.manager.service.ApplicationManagementService
-        </parameter>
-		<parameter name="enableMTOM">true</parameter>
-		<parameter name="adminService" locked="true">true</parameter>
-		<parameter name="hiddenService" locked="true">true</parameter>
-		<parameter name="AuthorizationAction" locked="true">
-			/permission/admin/manage/modify/webapp    </parameter>
-		<parameter name="DoAuthentication" locked="true">true</parameter>
-	</service>
-
-	<service name="RepoNotificationService" scope="transportsession">
-		<schema schemaNamespace="http://org.apache.axis2/xsd"
-			elementFormDefaultQualified="true" />
-		<transports>
-			<transport>https</transport>
-		</transports>
-		<description>
-			Admin service for receiving git repo update notifications
-		</description>
-		<parameter name="ServiceClass">org.apache.stratos.manager.service.RepoNotificationService
-        </parameter>
-		<parameter name="enableMTOM">true</parameter>
-		<parameter name="adminService" locked="true">false</parameter>
-		<parameter name="hiddenService" locked="true">false</parameter>
-		<parameter name="AuthorizationAction" locked="false">
-			/permission/admin/manage/modify/webapp
-    </parameter>
-	</service>
-
-
-	<service name="InstanceInformationManagementService" scope="transportsession">
-		<schema schemaNamespace="http://org.apache.axis2/xsd"
-			elementFormDefaultQualified="true" />
-		<transports>
-			<transport>https</transport>
-		</transports>
-		<description>
-			Exposes information related to internally created
-			repositories
-        </description>
-		<parameter name="ServiceClass">org.apache.stratos.manager.service.InstanceInformationManagementService</parameter>
-		<parameter name="enableMTOM">true</parameter>
-		<parameter name="adminService" locked="true">false</parameter>
-		<parameter name="hiddenService" locked="true">false</parameter>
-		<parameter name="AuthorizationAction" locked="false">
-			/permission/admin/manage/modify/webapp
-    	</parameter>
-	</service>
-
+	
     <service name="InstanceCleanupNotificationService" scope="transportsession">
 		<schema schemaNamespace="http://org.apache.axis2/xsd"
 			elementFormDefaultQualified="true" />

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/features/manager/stratos-mgt/org.apache.stratos.manager.server.feature/src/main/resources/conf/cartridge-config.properties
----------------------------------------------------------------------
diff --git a/features/manager/stratos-mgt/org.apache.stratos.manager.server.feature/src/main/resources/conf/cartridge-config.properties b/features/manager/stratos-mgt/org.apache.stratos.manager.server.feature/src/main/resources/conf/cartridge-config.properties
deleted file mode 100644
index 2f7c7f9..0000000
--- a/features/manager/stratos-mgt/org.apache.stratos.manager.server.feature/src/main/resources/conf/cartridge-config.properties
+++ /dev/null
@@ -1,64 +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.
-#
-#
-
-# Configuration properties
-
-sc.ip=stratos_ip
-autoscalerService.url=https://cc.wso2.com:9444/services/CloudControllerService/
-autoscaler.time.out=190000
-cartridge.agent.epr=https://stratos_ip:9447/services/CartridgeAgentService
-git.host.name=s2_hostname
-git.host.ip=stratos_ip
-git.repo.notification.url=https://sc.wso2.com:9445/services/RepoNotificationService/
-identity.server.url=https://sc.wso2.com:9447/services/RepoNotificationService/
-
-adc.jdbc.url=jdbc:h2:repository/database/WSO2S2_DB
-adc.jdbc.username=wso2carbon
-adc.jdbc.password=wso2carbon
-adc.jdbc.driver=org.h2.Driver
-
-mb.ip=mb.stratos.apache.org
-mb.port=5677
-cep.ip=cep.stratos.apache.org
-cep.port=7615
-
-feature.externalrepo.validation.enabled=true
-feature.internalrepo.enabled=false
-feature.multitenant.multiplesubscription.enabled=false
-
-internal.repo.username=admin
-internal.repo.password=admin
-
-append.script=SCRIPT_PATH/add_entry_zone_file.sh
-remove.script=SCRIPT_PATH/remove_entry_zone_file.sh
-bind.file.path=/etc/bind/db.STRATOS_DOMAIN
-elb.ip=stratos_ip
-
-bam.ip=stratos_ip
-bam.port=7714
-
-max.attempts=1000
-
-cartridge.key=KEYPATH
-
-repository.info.epr=https://stratos_ip:9445/services/RepositoryInformationService
-
-puppet.ip=127.0.0.1

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/features/manager/stratos-mgt/org.apache.stratos.manager.server.feature/src/main/resources/p2.inf
----------------------------------------------------------------------
diff --git a/features/manager/stratos-mgt/org.apache.stratos.manager.server.feature/src/main/resources/p2.inf b/features/manager/stratos-mgt/org.apache.stratos.manager.server.feature/src/main/resources/p2.inf
index 0c2b33e..ea2d86b 100644
--- a/features/manager/stratos-mgt/org.apache.stratos.manager.server.feature/src/main/resources/p2.inf
+++ b/features/manager/stratos-mgt/org.apache.stratos.manager.server.feature/src/main/resources/p2.inf
@@ -16,7 +16,6 @@
 # under the License.
 
 instructions.configure = \
-org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.apache.stratos.manager.server_${feature.version}/conf/cartridge-config.properties,target:${installFolder}/../../conf/cartridge-config.properties,overwrite:true);\
 org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.apache.stratos.manager.server_${feature.version}/conf/policies.xml,target:${installFolder}/../../conf/policies.xml,overwrite:true);\
 org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.apache.stratos.manager.server_${feature.version}/conf/etc/policies.xsd,target:${installFolder}/../../conf/etc/policies.xsd,overwrite:true);\
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties
----------------------------------------------------------------------
diff --git a/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties b/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties
index 4750702..53b50f2 100644
--- a/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties
+++ b/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties
@@ -21,44 +21,18 @@
 
 # Configuration properties
 #this file is in product
-sc.ip=stratos_ip
 autoscaler.service.url=https://as.stratos.apache.org:9446/services/AutoScalerService/
 cloud.controller.service.url=https://cc.stratos.apache.org:9444/services/CloudControllerService/
 autoscaler.time.out=190000
-cartridge.agent.epr=https://stratos_ip:9447/services/CartridgeAgentService
-git.host.name=s2_hostname
-git.host.ip=stratos_ip
-git.repo.notification.url=https://sc.stratos.apache.org:9445/services/RepoNotificationService/
-identity.server.url=https://sc.stratos.apache.org:9447/services/RepoNotificationService/
+puppet.ip=127.0.0.1
 
 adc.jdbc.url=jdbc:h2:repository/database/WSO2S2_DB
 adc.jdbc.username=wso2carbon
 adc.jdbc.password=wso2carbon
 adc.jdbc.driver=org.h2.Driver
 
-mb.ip=mb.stratos.apache.org
-mb.port=5677
-cep.ip=cep.stratos.apache.org
-cep.port=7615
-
 feature.externalrepo.validation.enabled=true
 feature.internalrepo.enabled=false
 feature.multitenant.multiplesubscription.enabled=false
 
-internal.repo.username=admin
-internal.repo.password=admin
-
-append.script=SCRIPT_PATH/add_entry_zone_file.sh
-remove.script=SCRIPT_PATH/remove_entry_zone_file.sh
-bind.file.path=/etc/bind/db.STRATOS_DOMAIN
-elb.ip=stratos_ip
-
-bam.ip=stratos_ip
-bam.port=7714
-
 max.attempts=1000
-
-cartridge.key=KEYPATH
-
-repository.info.epr=https://stratos_ip:9445/services/RepositoryInformationService
-


[2/5] git commit: Cleaned up cartridge-config.properties file and PersistenceManager related unwanted code, fixing STRATOS-274 and STRATOS-416

Posted by sa...@apache.org.
Cleaned up cartridge-config.properties file and PersistenceManager related unwanted code, fixing STRATOS-274 and STRATOS-416


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

Branch: refs/heads/master
Commit: 29bd106cd8faaec7decf234b3e81f508fd70cfa6
Parents: 2274042
Author: Sajith Kariyawasam <sa...@wso2.com>
Authored: Tue Feb 11 12:15:45 2014 +0530
Committer: Sajith Kariyawasam <sa...@wso2.com>
Committed: Tue Feb 11 12:15:45 2014 +0530

----------------------------------------------------------------------
 .../DataCartridgeSubscriptionConnector.java     |  12 +-
 .../internal/ADCManagementServerComponent.java  |   2 -
 .../InstanceInformationManagementService.java   |  58 --
 .../service/RepoNotificationService.java        | 128 ---
 .../subscription/CartridgeSubscription.java     |  71 +-
 .../utils/ApplicationManagementUtil.java        | 857 +-----------------
 .../manager/utils/CartridgeConstants.java       |  22 -
 .../manager/utils/PersistenceManager.java       | 892 -------------------
 .../manager/utils/RepositoryFactory.java        | 131 ---
 .../stratos/manager/utils/StratosDBUtils.java   | 213 -----
 .../src/main/resources/META-INF/services.xml    |  57 +-
 .../resources/conf/cartridge-config.properties  |  64 --
 .../src/main/resources/p2.inf                   |   1 -
 .../src/main/conf/cartridge-config.properties   |  28 +-
 14 files changed, 41 insertions(+), 2495 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java
index 6fcf654..4764f49 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java
@@ -49,16 +49,16 @@ public class DataCartridgeSubscriptionConnector extends CartridgeSubscriptionCon
         int attempts = 0;
         while (attempts < maxAttempts) {
             attempts++;
-            Cartridge cartridge = null;
-            try {
+            /*Cartridge cartridge = null;
+             try {
                 cartridge = ApplicationManagementUtil.getCartridgeInfo(
                         connectingCartridgeSubscription.getAlias(),
                         connectingCartridgeSubscription.getSubscriber().getTenantDomain());
 
             } catch (NotSubscribedException e) {
-                // This cannot happen here.
-            }
-            if (cartridge != null) {
+                
+            }*/
+            //if (cartridge != null) {
                 /*if (!cartridge.getStatus().equals("ACTIVE")) {
                     try {
                         Thread.sleep(3000);
@@ -72,7 +72,7 @@ public class DataCartridgeSubscriptionConnector extends CartridgeSubscriptionCon
                             connectingCartridgeSubscription);
                     break;
                 }*/
-            }
+            //}
 
             if(attempts == maxAttempts) {
                 String errorMsg = "Failed to connect " + cartridgeSubscription + " and " + connectingCartridgeSubscription;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ADCManagementServerComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ADCManagementServerComponent.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ADCManagementServerComponent.java
index 8c8f194..81c1dbe 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ADCManagementServerComponent.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/internal/ADCManagementServerComponent.java
@@ -26,7 +26,6 @@ import org.apache.stratos.manager.publisher.TenantSynchronizerTaskScheduler;
 import org.apache.stratos.manager.retriever.DataInsertionAndRetrievalManager;
 import org.apache.stratos.manager.topology.receiver.StratosManagerTopologyReceiver;
 import org.apache.stratos.manager.utils.CartridgeConfigFileReader;
-import org.apache.stratos.manager.utils.StratosDBUtils;
 import org.apache.stratos.messaging.broker.publish.EventPublisher;
 import org.apache.stratos.messaging.broker.subscribe.TopicSubscriber;
 import org.apache.stratos.messaging.util.Constants;
@@ -66,7 +65,6 @@ public class ADCManagementServerComponent {
     protected void activate(ComponentContext componentContext) throws Exception {
 		try {
 			CartridgeConfigFileReader.readProperties();
-			StratosDBUtils.initialize();
 			DataHolder.setEventPublisher(new EventPublisher(Constants.INSTANCE_NOTIFIER_TOPIC));
 
             // Schedule complete tenant event synchronizer

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/InstanceInformationManagementService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/InstanceInformationManagementService.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/InstanceInformationManagementService.java
deleted file mode 100644
index 93bf70c..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/InstanceInformationManagementService.java
+++ /dev/null
@@ -1,58 +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.manager.service;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.utils.PersistenceManager;
-
-public class InstanceInformationManagementService {
-
-	
-    private static final Log log = LogFactory.getLog(InstanceInformationManagementService.class);
-
-    /**
-    * Everytime an subscription is started up, this operation is invoked
-    *            (by the AgentService)
-    * @param instanceIp
-    * @param tenantId
-    * @param clusterDomain
-    * @param clusterSubDomain
-    * @param cartridge
-    * @param state
-    *
-    */
-    public void updateInstanceState(String instanceIp,
-                                  int tenantId,
-                                  String clusterDomain,
-                                  String clusterSubDomain,
-                                  String cartridge,
-                                  String state) {
-
-      log.info("Message receieved in Instance Info Service.." + instanceIp + tenantId + clusterDomain + clusterSubDomain
-               + cartridge + state);
-
-      try {
-        PersistenceManager.persistCartridgeInstanceInfo(instanceIp, clusterDomain, clusterSubDomain, cartridge, state);
-    } catch (Exception e) {
-       log.error("Exception is occurred in updating subscription state. Reason, " + e.getMessage());
-    }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/RepoNotificationService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/RepoNotificationService.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/RepoNotificationService.java
deleted file mode 100644
index efe36bb..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/RepoNotificationService.java
+++ /dev/null
@@ -1,128 +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.manager.service;
-
-import org.apache.axis2.clustering.ClusteringAgent;
-import org.apache.axis2.clustering.ClusteringFault;
-import org.apache.axis2.clustering.management.GroupManagementAgent;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
-import org.apache.stratos.manager.internal.DataHolder;
-import org.apache.stratos.manager.publisher.InstanceNotificationPublisher;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.apache.stratos.manager.utils.PersistenceManager;
-import org.wso2.carbon.core.deployment.SynchronizeGitRepositoryRequest;
-
-import java.util.List;
-import java.util.UUID;
-
-
-public class RepoNotificationService {
-
-    private static final Log log = LogFactory.getLog(RepoNotificationService.class);
-
-
-    public void notifyRepoUpdate(String tenantDomain, String cartridgeAlias) throws Exception {
-        // FIXME Throwing generic Exception is wrong
-        log.info("Updating repository of tenant : " + tenantDomain + " , cartridge: " +
-                cartridgeAlias);
-
-        CartridgeSubscriptionInfo subscription = null;
-        try {
-            subscription = PersistenceManager.getSubscription(tenantDomain, cartridgeAlias);
-        } catch (Exception e) {
-            String msg = "Failed to find subscription for " + cartridgeAlias + ". "
-                    + (e.getMessage() != null ? e.getMessage() : "");
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        if (subscription == null) {
-            String msg = "Tenant " + tenantDomain + " is not subscribed for " + cartridgeAlias;
-            log.error(msg);
-            throw new Exception("You have not subscribed for " + cartridgeAlias);
-        }
-
-        try {
-            handleRepoSynch(subscription);
-        } catch (Exception e) {
-            String msg = "Failed to synchronize the repository for " + cartridgeAlias + ". "
-                    + (e.getMessage() != null ? e.getMessage() : "");
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-    }
-
-    public void synchronize(String repositoryURL) throws Exception {
-
-        log.info(" repository URL received : " + repositoryURL);
-        List<CartridgeSubscriptionInfo> subscription = PersistenceManager.getSubscription(repositoryURL);
-        for (CartridgeSubscriptionInfo cartridgeSubscriptionInfo : subscription) {
-            handleRepoSynch(cartridgeSubscriptionInfo);
-        }
-    }
-
-    private void handleRepoSynch(CartridgeSubscriptionInfo subscription) throws Exception {
-        if (subscription == null) {
-            throw new Exception("Cannot synchronize repository. subscription is null");
-        }
-
-        if (CartridgeConstants.PROVIDER_NAME_WSO2.equals(subscription.getProvider())) {
-            createAndSendClusterMessage(subscription.getTenantId(), subscription.getTenantDomain(),
-                    UUID.randomUUID(), subscription.getClusterDomain(),
-                    subscription.getClusterSubdomain());
-
-        } else {
-            InstanceNotificationPublisher notificationHandler = new InstanceNotificationPublisher();
-            notificationHandler.sendArtifactUpdateEvent(subscription.getRepository(),
-                    subscription.getClusterDomain(),
-                    String.valueOf(subscription.getTenantId()));
-        }
-    }
-
-    private void createAndSendClusterMessage(int tenantId, String tenantDomain, UUID uuid,
-                                             String clusterDomain, String clusterSubdomain) {
-
-        SynchronizeGitRepositoryRequest request =
-                new SynchronizeGitRepositoryRequest(tenantId,
-                        tenantDomain,
-                        uuid);
-
-        ClusteringAgent clusteringAgent =
-                DataHolder.getServerConfigContext()
-                        .getAxisConfiguration().getClusteringAgent();
-        GroupManagementAgent groupMgtAgent =
-                clusteringAgent.getGroupManagementAgent(clusterDomain,
-                        clusterSubdomain);
-
-        try {
-            log.info("Sending Request to.. " + clusterDomain + " : " + clusterSubdomain);
-            groupMgtAgent.send(request);
-
-        } catch (ClusteringFault e) {
-            e.printStackTrace();
-        }
-
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java
index 241c02a..8b4d997 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java
@@ -19,23 +19,32 @@
 
 package org.apache.stratos.manager.subscription;
 
+import java.io.Serializable;
+import java.util.Map;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.Properties;
 import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
 import org.apache.stratos.manager.dao.Cluster;
-import org.apache.stratos.manager.exception.*;
+import org.apache.stratos.manager.exception.ADCException;
+import org.apache.stratos.manager.exception.AlreadySubscribedException;
+import org.apache.stratos.manager.exception.DuplicateCartridgeAliasException;
+import org.apache.stratos.manager.exception.InvalidCartridgeAliasException;
+import org.apache.stratos.manager.exception.InvalidRepositoryException;
+import org.apache.stratos.manager.exception.NotSubscribedException;
+import org.apache.stratos.manager.exception.PolicyException;
+import org.apache.stratos.manager.exception.RepositoryCredentialsRequiredException;
+import org.apache.stratos.manager.exception.RepositoryRequiredException;
+import org.apache.stratos.manager.exception.RepositoryTransportException;
+import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
 import org.apache.stratos.manager.payload.PayloadData;
 import org.apache.stratos.manager.repository.Repository;
 import org.apache.stratos.manager.subscriber.Subscriber;
 import org.apache.stratos.manager.subscription.tenancy.SubscriptionTenancyBehaviour;
 import org.apache.stratos.manager.utils.ApplicationManagementUtil;
 import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.apache.stratos.manager.utils.RepositoryFactory;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
-import org.apache.stratos.cloud.controller.pojo.Properties;
-
-import java.io.Serializable;
-import java.util.Map;
 
 public abstract class CartridgeSubscription implements Serializable {
 
@@ -227,53 +236,7 @@ public abstract class CartridgeSubscription implements Serializable {
      */
     protected void cleanupSubscription () throws ADCException {
 
-        try {
-            new RepositoryFactory().destroyRepository(alias, subscriber.getTenantDomain(),
-                    subscriber.getAdminUserName());
-            log.info("Repo is destroyed successfully.. ");
-
-        } catch (Exception e) {
-            String errorMsg = "Error in destroying repository for tenant " + subscriber.getTenantDomain() +
-                    "cartridge type " + type;
-            log.error(errorMsg);
-        }
-
-        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-        /*try {
-            PersistenceManager.updateSubscriptionState(subscriptionId, "UNSUBSCRIBED");
-
-        } catch (Exception e) {
-            String errorMsg = "Error in unscubscribing from cartridge, alias " + alias + ", tenant " +
-                    subscriber.getTenantDomain();
-            throw new ADCException(errorMsg, e);
-        }*/
-        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-        //TODO: FIXME: do we need this?
-        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-        /*new DNSManager().removeSubDomain(getCluster().getHostName());
-
-        try {
-            new RegistryManager().removeDomainMappingFromRegistry(getCluster().getHostName());
-
-        } catch (Exception e) {
-            String errorMsg = "Error in removing domain mapping, alias " + alias + ", tenant " +
-                    subscriber.getTenantDomain();
-            log.error(errorMsg, e);
-        }*/
-        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-        /*TopologyManagementService topologyMgtService = DataHolder.getTopologyMgtService();
-        String[] ips = topologyMgtService.getActiveIPs(type, getCluster().getClusterDomain(), getCluster().getClusterSubDomain());
-        try {
-            PersistenceManager.updateInstanceState("INACTIVE", ips, getCluster().getClusterDomain(), getCluster().getClusterSubDomain(), type);
-
-        } catch (Exception e) {
-            String errorMsg = "Error in updating state to INACTIVE";
-            log.error(errorMsg, e);
-        }*/
-
-        //this.setSubscriptionStatus(CartridgeConstants.UNSUBSCRIBED);
+        
     }
 
     public Map<String, String> getCustomPayloadEntries () {

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/ApplicationManagementUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/ApplicationManagementUtil.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/ApplicationManagementUtil.java
index b08d5d4..10d16d1 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/ApplicationManagementUtil.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/ApplicationManagementUtil.java
@@ -21,10 +21,16 @@ package org.apache.stratos.manager.utils;
 */
 
 
-import com.google.gson.Gson;
-import org.apache.axis2.clustering.ClusteringAgent;
-import org.apache.axis2.clustering.Member;
-import org.apache.axis2.clustering.management.GroupManagementAgent;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.rmi.RemoteException;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.commons.logging.Log;
@@ -40,36 +46,12 @@ import org.apache.stratos.manager.dao.DataCartridge;
 import org.apache.stratos.manager.dao.PortMapping;
 import org.apache.stratos.manager.dto.Cartridge;
 import org.apache.stratos.manager.dto.Policy;
-import org.apache.stratos.manager.dto.RepositoryInformation;
 import org.apache.stratos.manager.dto.SubscriptionInfo;
-import org.apache.stratos.manager.exception.*;
-import org.apache.stratos.manager.internal.DataHolder;
+import org.apache.stratos.manager.exception.ADCException;
+import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
 import org.apache.stratos.manager.repository.Repository;
-import org.apache.stratos.manager.service.RepositoryInfoBean;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.LsRemoteCommand;
-import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.api.errors.InvalidRemoteException;
-import org.eclipse.jgit.api.errors.TransportException;
-import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.storage.file.FileRepository;
-import org.eclipse.jgit.transport.CredentialsProvider;
-import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
-import org.wso2.carbon.utils.CarbonUtils;
 import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
 
-import javax.activation.DataHandler;
-import javax.activation.FileDataSource;
-import java.io.*;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.rmi.RemoteException;
-import java.text.DecimalFormat;
-import java.util.*;
-import java.util.regex.Pattern;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
 /**
  * This class contains utility methods used by ApplicationManagementService.
  */
@@ -78,459 +60,6 @@ public class ApplicationManagementUtil {
     private static Log log = LogFactory.getLog(ApplicationManagementUtil.class);
     //private static volatile CloudControllerServiceClient serviceClient;
 
-    /**
-     * Method used to createSubscription to cartridges.
-     */
-	public static SubscriptionInfo doSubscribe(String cartridgeType, String alias, String policy, String repoURL,
-			boolean privateRepo, String repoUsername, String repoPassword, String dataCartridgeType,
-			String dataCartridgeAlias, String username, int tenantId, String tenantDomain) throws ADCException,
-            PolicyException, UnregisteredCartridgeException, InvalidCartridgeAliasException,
-            DuplicateCartridgeAliasException, RepositoryRequiredException, AlreadySubscribedException,
-            RepositoryCredentialsRequiredException, InvalidRepositoryException, RepositoryTransportException {
-
-		String clusterDomain = "";
-        String clusterSubDomain = CartridgeConstants.DEFAULT_SUBDOMAIN;
-        String mgtClusterDomain = "";
-        String mgtClusterSubDomain = CartridgeConstants.DEFAULT_MGT_SUBDOMAIN;
-        CartridgeSubscriptionInfo subscription = null;
-        String mysqlPassword = null;
-        Repository repository = null;
-        DataCartridge dataCartridge = null;
-        String cartName = (alias != null && alias.trim().length() > 0) ? alias : cartridgeType;
-        String payloadZipFileName = "/tmp/" + UUID.randomUUID().toString() + ".zip";
-
-		log.info("Subscribing tenant [" + tenantId + "] with username [" + username + "] Cartridge Alias " + alias
-				+ ", Cartridge Type: " + cartridgeType + ", Repo URL: " + repoURL + ", Policy: " + policy);
-		
-		// Assign auto scaling only when necessary.
-		// Muti-tenant cartridge may not need a policy.
-		Policy autoScalingPolicy = null;
-		
-		CartridgeInfo cartridgeInfo;
-		try {
-			cartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(cartridgeType);
-		} catch (UnregisteredCartridgeException e) {
-			String message = cartridgeType
-					+ " is not a valid cartridge type. Please try again with a valid cartridge type.";
-			log.error(message);
-			throw e;
-		} catch (Exception e) {
-			String message = "Error getting info for " + cartridgeType;
-			log.error(message, e);
-			throw new ADCException(message, e);
-		}
-
-		validateCartridgeAlias(cartName, cartridgeType);
-		
-
-        if (cartridgeType.equals(CartridgeConstants.MYSQL_CARTRIDGE_NAME)) {
-        	
-        	autoScalingPolicy = PolicyHolder.getInstance().getDefaultPolicy();
-        	
-        	if (autoScalingPolicy == null) {
-        		throw new PolicyException("Could not load default auto-scaling policy.");
-        	}
-        	if (log.isDebugEnabled()) {
-    			log.debug("Selected Policy: " + new Gson().toJson(autoScalingPolicy));
-    		}
-        	
-            dataCartridge = new DataCartridge();
-            mysqlPassword = generatePassword();
-            dataCartridge.setPassword(mysqlPassword);
-            dataCartridge.setDataCartridgeType(cartridgeType);
-            dataCartridge.setUserName(CartridgeConstants.MYSQL_DEFAULT_USER);
-            clusterDomain = getDynamicClusterDomain(cartridgeType, cartName, cartridgeInfo);
-
-            /*egisterService(cartridgeType,
-                    clusterDomain,
-                    clusterSubDomain,
-                    createPayload(cartridgeInfo, cartName, autoScalingPolicy, repoURL, mysqlPassword, "localhost", payloadZipFileName, tenantId, tenantDomain),
-                    "*",
-                    cartName + "." + cartridgeInfo.getHostName(),
-                    setRegisterServiceProperties(autoScalingPolicy, tenantId,cartName));*/
-            deletePayloadFile(payloadZipFileName);
-        } else {
-        	
-			if (!new Boolean(System.getProperty(CartridgeConstants.FEATURE_INTERNAL_REPO_ENABLED))) {
-				if (log.isDebugEnabled()) {
-					log.debug("Internal repo feature is not enabled.");
-				}
-
-				if (repoURL == null || repoURL.trim().length() == 0) {
-					throw new RepositoryRequiredException("External repository required for subscription");
-				}
-			}
-
-			if (repoURL != null && repoURL.trim().length() > 0) {
-				if (log.isDebugEnabled()) {
-					log.debug("Repo URL entered: " + repoURL);
-				}
-				// Validate Remote Repository.
-				validateRepository(repoURL, repoUsername, repoPassword, privateRepo,
-						new Boolean(System.getProperty(CartridgeConstants.FEATURE_EXTERNAL_REPO_VAIDATION_ENABLED)));
-			}
-
-            try {
-                repository = manageRepository(repoURL, repoUsername, repoPassword, cartName, cartridgeInfo, username,
-                        tenantDomain);
-            } catch (Exception e) {
-                log.error(e.getMessage());
-                throw new ADCException(e);
-            }
-        	
-            // TODO: Check logic here
-            if (!cartridgeInfo.getMultiTenant()) {
-            	
-        		if (policy != null && policy.trim().length() > 0) {
-        			autoScalingPolicy = PolicyHolder.getInstance().getPolicy(policy);
-        		} else {
-        			autoScalingPolicy = PolicyHolder.getInstance().getDefaultPolicy();
-        		}
-        		if (autoScalingPolicy == null) {
-        			throw new PolicyException("Could not load auto-scaling policy.");
-        		}
-        		if (log.isDebugEnabled()) {
-        			log.debug("Selected Policy: " + new Gson().toJson(autoScalingPolicy));
-        		}
-
-                if (cartridgeInfo.getProvider().equalsIgnoreCase(CartridgeConstants.PROVIDER_NAME_WSO2)) { //carbon cartridge private jet mode
-
-                    clusterDomain = getDynamicClusterDomain(cartridgeType, cartName, cartridgeInfo);
-                   /* registerService(cartridgeType,
-                            clusterDomain,
-                            clusterSubDomain,
-                            createCarbonPayload(cartridgeInfo, cartName, alias, payloadZipFileName, tenantDomain, false),
-                            Integer.toString(tenantId),
-                            cartName + "." + cartridgeInfo.getHostName(),
-                            setRegisterServiceProperties(autoScalingPolicy,tenantId,cartName));*/
-                    deletePayloadFile(payloadZipFileName);
-
-                } else {
-                    clusterDomain = getDynamicClusterDomain(cartridgeType, cartName, cartridgeInfo);
-
-                    String mySQLPassword = null;
-                    String mySQLHostName = null;
-
-                    if (dataCartridgeType != null && dataCartridgeType.trim().length() > 0 && dataCartridgeAlias != null
-                            && dataCartridgeAlias.trim().length() > 0) {
-                        if (log.isInfoEnabled()) {
-                            log.info("Retrieving Data Cartridge info for connect ... Alias : " + dataCartridgeAlias
-                                    + ", Type: " + dataCartridgeType);
-                        }
-
-                        //TODO: Optimize following logic. Same logic is used in MySQLPasswordConfigurer
-                        int maxAttempts = Integer.parseInt(System.getProperty(CartridgeConstants.MAX_ATTEMPTS, "50"));
-                        int i = 0;
-
-                        while (i < maxAttempts) {
-                            i++;
-                            Cartridge c = null;
-                            try {
-                                c = getCartridgeInfo(dataCartridgeAlias, tenantDomain);
-                            } catch (NotSubscribedException e) {
-                                // This cannot happen here.
-                            }
-                            if (c != null) {
-                               /* if (!c.getStatus().equals("ACTIVE")) {
-                                    try {
-                                        Thread.sleep(3000);
-                                    } catch (InterruptedException ignore) {
-                                    }
-                                } else {
-                                    mySQLPassword = c.getPassword();
-                                    mySQLHostName = c.getIp();
-                                    break;
-                                }*/
-                            }
-                        }
-                        log.info(" MYSQL Cartridge info retrieved ");
-                    }
-
-                    /*registerService(cartridgeType,
-                            clusterDomain,
-                            clusterSubDomain,
-                            createPayload(cartridgeInfo, cartName, autoScalingPolicy, repoURL, mySQLPassword,
-                                    mySQLHostName, payloadZipFileName, tenantId, tenantDomain), "*",
-                            cartName + "." + cartridgeInfo.getHostName(),
-                            setRegisterServiceProperties(autoScalingPolicy,tenantId,cartName));*/
-                    deletePayloadFile(payloadZipFileName);
-                }
-
-            } else {
-            	
-            	boolean allowMultipleSubscription = new Boolean(
-						System.getProperty(CartridgeConstants.FEATURE_MULTI_TENANT_MULTIPLE_SUBSCRIPTION_ENABLED));
-
-				if (!allowMultipleSubscription) {
-					// If the cartridge is multi-tenant. We should not let users
-					// createSubscription twice.
-					boolean subscribed;
-					try {
-						subscribed = PersistenceManager.isAlreadySubscribed(cartridgeType, tenantId);
-					} catch (Exception e) {
-						String msg = "Error checking whether the cartridge type " + cartridgeType
-								+ " is already subscribed";
-						log.error(msg, e);
-						throw new ADCException(msg, e);
-					}
-					
-					if (subscribed) {
-						String msg = "Already subscribed to " + cartridgeType
-								+ ". This multi-tenant cartridge will not be available to createSubscription";
-						if (log.isDebugEnabled()) {
-							log.debug(msg);
-						}
-						throw new AlreadySubscribedException(msg, cartridgeType);
-					}
-				}
-
-                /*TopologyManagementService topologyService = DataHolder.getTopologyMgtService();
-                DomainContext[] domainContexts = topologyService.getDomainsAndSubdomains(cartridgeType, tenantId);
-                log.info("Retrieved " + domainContexts.length + " domain and corresponding subdomain pairs");
-
-                if (domainContexts.length > 0) {
-                	                        if(domainContexts.length > 2) {
-                	                            if(log.isDebugEnabled())
-                	                                log.debug("Too many domain sub domain pairs");
-                	                       }
-                	
-                	                        for (int i = 0 ; i < domainContexts.length ; i++) {
-                	                            if(domainContexts[i].getSubDomain().equalsIgnoreCase("mgt")) {
-                	                                mgtClusterDomain = domainContexts[i].getDomain();
-                	                                mgtClusterSubDomain = domainContexts[i].getSubDomain();
-                	                            }
-                	                          else
-                	                          {
-                	                              clusterDomain = domainContexts[i].getDomain();
-                	                              clusterSubDomain = domainContexts[i].getSubDomain();
-                	                          }
-                	                      }
-                } else {
-                	String msg = "Domain contexts not found for " + cartridgeType + " and tenant id " + tenantId;
-                    log.warn(msg);
-                    throw new ADCException(msg);
-                }*/
-            }
-        }
-
-        /*subscription =
-                createCartridgeSubscription(cartridgeInfo, autoScalingPolicy,
-                        cartridgeType, cartName, tenantId, tenantDomain,
-                        repository, clusterDomain, clusterSubDomain,
-                        mgtClusterDomain, mgtClusterSubDomain, dataCartridge);
-        */
-
-        try {
-			PersistenceManager.persistSubscription(subscription);
-		} catch (Exception e) {
-			throw new ADCException("Error Saving Subscription", e);
-		}
-        addDNSEntry(alias, cartridgeType);
-        return createSubscriptionResponse(subscription, repository);
-
-    }
-    
-    private static File getPayload(CartridgeInfo cartridgeInfo, String cartridgeName, Policy policy, String repoURL,
-                                   String mySQLPassword, String mySQLHost, String payloadZipFileName,
-                                   int tenantId, String tenantDomain) throws Exception {
-        String payloadString = "";
-
-        payloadString += "TENANT_RANGE=" + "*";
-        payloadString += ",TENANT_ID=" + tenantId;
-        payloadString +=
-            ",REPO_INFO_EPR=" +
-                    System.getProperty(CartridgeConstants.REPO_INFO_EPR);
-        payloadString +=
-                ",CARTRIDGE_AGENT_EPR=" +
-                        System.getProperty(CartridgeConstants.CARTRIDGE_AGENT_EPR);
-        payloadString += createPortMappingPayloadString(cartridgeInfo);
-        payloadString += ",HOST_NAME=" + cartridgeName + "." + cartridgeInfo.getHostName();
-        payloadString += ",MIN=" + policy.getMinAppInstances();
-        payloadString += ",MAX=" + policy.getMaxAppInstances();
-        payloadString += ",SERVICE=" + cartridgeInfo.getType();
-        payloadString += ",TENANT_CONTEXT=" + tenantDomain;
-        payloadString += ",CARTRIDGE_ALIAS=" + cartridgeName;
-
-        String gitRepoURL = null;
-        if (repoURL != null) {
-            gitRepoURL = repoURL;
-        } else {
-            gitRepoURL = "git@" + System.getProperty(CartridgeConstants.GIT_HOST_IP) + ":" + tenantDomain
-                    + System.getProperty("file.separator") + cartridgeName + ".git";
-        }
-        payloadString += ",GIT_REPO=" + gitRepoURL;
-        payloadString += ",APP_PATH=" + cartridgeInfo.getBaseDir();
-        payloadString += ",BAM_IP=" + System.getProperty(CartridgeConstants.BAM_IP);
-        payloadString += ",BAM_PORT=" + System.getProperty(CartridgeConstants.BAM_PORT);
-
-        // MYSQL params
-        payloadString += ",MYSQL_HOST=" + mySQLHost;
-        payloadString += ",MYSQL_USER=" + "root";
-        payloadString += ",MYSQL_PASSWORD=" + mySQLPassword;
-        
-        DecimalFormat df = new DecimalFormat("##.##");
-        df.setParseBigDecimal(true);
-
-        // Autoscaling params
-        payloadString += ",ALARMING_LOWER_RATE=" + df.format(policy.getAlarmingLowerRate());
-        payloadString += ",ALARMING_UPPER_RATE=" + df.format(policy.getAlarmingUpperRate());
-        payloadString += ",MAX_REQUESTS_PER_SEC=" + policy.getMaxRequestsPerSecond();
-        payloadString += ",ROUNDS_TO_AVERAGE=" + policy.getRoundsToAverage();
-        payloadString += ",SCALE_DOWN_FACTOR=" + df.format(policy.getScaleDownFactor());
-
-        log.info("** Payload ** " + payloadString);
-        
-        String payloadStringTempFile = "launch-params";
-
-        FileWriter fstream = new FileWriter(payloadStringTempFile);
-        BufferedWriter out = new BufferedWriter(fstream);
-        out.write(payloadString);
-        out.close();
-
-        FileOutputStream fos = new FileOutputStream(payloadZipFileName);
-        ZipOutputStream zos = new ZipOutputStream(fos);
-
-		addToZipFile(System.getProperty("user.dir"), payloadStringTempFile, zos);
-
-		File folder = new File(CarbonUtils.getCarbonHome()+
-				File.separator + "repository"
-				+ File.separator + "resources" + File.separator + "user-data");
-		for (File fileEntry : folder.listFiles()) {
-			if (!fileEntry.isDirectory()) {
-				addToZipFile(folder.getPath(), fileEntry.getName(), zos);
-			}
-		}
-
-        zos.close();
-        fos.close();
-
-        return new File(payloadZipFileName);
-    }
-
-    private static File getCarbonPayload (CartridgeInfo cartridgeInfo, String cartridgeName, String cartridgeAlias,
-                                          String payloadZipFileName, String tenantDomain, boolean isMultitenant) throws Exception {
-
-        String payloadString = "";
-        payloadString += "DEPLOYMENT=" + "default";  //TODO: Currently hard coded but can be either manager, worker or default.
-        //payloadString += ",DOMAIN=" + "s2.wso2.com";
-        payloadString += ",SERVICE=" + cartridgeInfo.getType();
-        //payloadString += ",TENANT_ID=" + tenantId;
-        payloadString += ",SC_IP=" + System.getProperty(CartridgeConstants.SC_IP);
-        payloadString += ",CARTRIDGE_ALIAS=" + cartridgeAlias;
-        payloadString += ",MULTITENANT=" + "false";
-
-        if(isMultitenant) { //not used at the moment
-            payloadString += ",DOMAIN=" + "wso2." + cartridgeInfo.getType() + ".domain";
-            payloadString += ",HOSTNAME=" + cartridgeInfo.getType() + ".s2.wso2.com";
-
-        } else {
-            payloadString += ",DOMAIN=" + cartridgeName + "." + cartridgeInfo.getHostName() + "." + cartridgeInfo.getType() +
-                    ".domain";
-            payloadString += ",HOSTNAME=" + cartridgeName + "." + cartridgeInfo.getHostName();
-        }
-
-        log.info("** Payload ** " + payloadString);
-
-        String payloadStringTempFile = "launch-params";
-
-        FileWriter fstream = new FileWriter(payloadStringTempFile);
-        BufferedWriter out = new BufferedWriter(fstream);
-        out.write(payloadString);
-        out.close();
-
-        FileOutputStream fos = new FileOutputStream(payloadZipFileName);
-        ZipOutputStream zos = new ZipOutputStream(fos);
-
-        addToZipFile(System.getProperty("user.dir"), payloadStringTempFile, zos);
-
-        zos.close();
-        fos.close();
-
-        return new File(payloadZipFileName);
-    }
-
-    private static String createPortMappingPayloadString(CartridgeInfo cartridgeInfo) {
-        // port mappings
-        StringBuilder portMapBuilder = new StringBuilder();
-        org.apache.stratos.cloud.controller.pojo.PortMapping[] portMappings = cartridgeInfo.getPortMappings();
-        for (org.apache.stratos.cloud.controller.pojo.PortMapping portMapping : portMappings) {
-            String port = portMapping.getPort();
-            String protocol = portMapping.getProtocol();
-            String proxyPort = portMapping.getProxyPort();
-            portMapBuilder.append(protocol).append(":").append(port).append(":").append(proxyPort).append("|");
-        }
-
-        // remove last "|" character
-        String portMappingString = portMapBuilder.toString();
-        String portMappingPayloadString = null;
-        if (portMappingString.charAt(portMappingString.length() - 1) == '|') {
-            portMappingPayloadString = portMappingString.substring(0, portMappingString.length() - 1);
-        } else {
-            portMappingPayloadString = portMappingString;
-        }
-
-        return ",PORTS=" + portMappingPayloadString;
-    }
-
-    private static void addToZipFile(String dir, String fileName, ZipOutputStream zos) throws FileNotFoundException,
-            IOException {
-
-        log.info("Writing '" + fileName + "' to zip file");
-
-        File file = new File(dir+File.separator+fileName);
-        FileInputStream fis = new FileInputStream(file);
-        ZipEntry zipEntry = new ZipEntry(fileName);
-        zos.putNextEntry(zipEntry);
-
-        byte[] bytes = new byte[1024];
-        int length;
-        while ((length = fis.read(bytes)) >= 0) {
-            zos.write(bytes, 0, length);
-        }
-
-        zos.closeEntry();
-        fis.close();
-    }
-
-    private static DataHandler createPayload(CartridgeInfo cartridgeInfo, String cartridgeName, Policy policy, String repoURL, String mySQLPwd, String mySQLHost,
-                                             String payloadZipFileName, int tenantId,
-                                             String tenantDomain)
-            throws ADCException {
-
-        FileDataSource dataSource = null;
-        File payloadFile = null;
-        try {
-            payloadFile = getPayload(cartridgeInfo, cartridgeName,
-            		policy, repoURL,
-                    mySQLPwd, mySQLHost, payloadZipFileName, tenantId, tenantDomain);
-            dataSource = new FileDataSource(payloadFile);
-        } catch (Exception e) {
-            String msg = "Exception : " + e.getMessage();
-            log.error(msg, e);
-            throw new ADCException("Subscribe failed ", e);
-        }
-        return new DataHandler(dataSource);
-    }
-
-    private static DataHandler createCarbonPayload (CartridgeInfo cartridgeInfo, String cartridgeName, String cartridgeAlias, String payloadZipFileName,
-                                                    String tenantDomain, boolean isMultitenant) throws ADCException {
-
-        FileDataSource dataSource = null;
-        File payloadFile = null;
-        try {
-            payloadFile = getCarbonPayload(cartridgeInfo, cartridgeName, cartridgeAlias, payloadZipFileName,
-                    tenantDomain, isMultitenant);
-            dataSource = new FileDataSource(payloadFile);
-
-        } catch (Exception e) {
-            String msg = "Exception : " + e.getMessage();
-            log.error(msg, e);
-            throw new ADCException("Subscribe failed ", e);
-        }
-
-        return new DataHandler(dataSource);
-    }
-
     protected static String getAppDeploymentDirPath(String cartridge, AxisConfiguration axisConfig) {
         return axisConfig.getRepository().getPath() + File.separator + cartridge;
     }
@@ -590,18 +119,6 @@ public class ApplicationManagementUtil {
         return portMappings;
     }
 
-    /*public static CloudControllerServiceClient getServiceClient() throws AxisFault {
-        if (serviceClient == null) {
-            synchronized (CloudControllerServiceClient.class) {
-                if (serviceClient == null) {
-                    serviceClient = new CloudControllerServiceClient(
-                            System.getProperty(CartridgeConstants.AUTOSCALER_SERVICE_URL));
-                }
-            }
-        }
-        return serviceClient;
-    }*/
-
     public static int getTenantId(ConfigurationContext configurationContext) {
         int tenantId = MultitenantUtils.getTenantId(configurationContext);
         if(log.isDebugEnabled()) {
@@ -610,120 +127,8 @@ public class ApplicationManagementUtil {
         return tenantId;
     }
 
-	public static void validateCartridgeAlias(String alias, String cartridgeType) throws InvalidCartridgeAliasException, DuplicateCartridgeAliasException, ADCException {
-		// Do not use quotes in messages, current UI JavaScript does not work if there are quotes
-		// TODO: Fix message display in UI
-		String patternString = "([a-z0-9]+([-][a-z0-9])*)+";
-        Pattern pattern = Pattern.compile(patternString);
-        
-        if (!pattern.matcher(alias).matches()) {
-        	String msg = "The alias " + alias + " can contain only alpha-numeric lowercase characters. Please enter a valid alias.";
-			log.error(msg);
-			throw new InvalidCartridgeAliasException(msg, cartridgeType, alias);
-        }
-		
-		boolean isAliasTaken = false;
-		try {			
-			isAliasTaken = PersistenceManager.isAliasAlreadyTaken(alias, cartridgeType);			
-		} catch (Exception e) {
-			String msg = "Exception : " + e.getMessage();
-			log.error(msg, e);
-			throw new ADCException("Error when checking alias is already taken", e);
-		}
 		
-		if (isAliasTaken) {
-			String msg = "The alias " + alias + " is already taken. Please try again with a different alias.";
-			log.error(msg);
-			throw new DuplicateCartridgeAliasException(msg, cartridgeType, alias);
-		}
-	}
 	
-	public static RepositoryInformation validateRepository(String repoURL, String repoUsername, String repoPassword,
-			boolean privateRepo, boolean testConnection) throws RepositoryRequiredException, ADCException,
-			RepositoryCredentialsRequiredException, InvalidRepositoryException, RepositoryTransportException {
-		RepositoryInformation repositoryInformation = new RepositoryInformation();
-		repositoryInformation.setRepoURL(repoURL);
-		if (log.isDebugEnabled()) {
-			log.debug("Validating Git Repository");
-		}
-
-		if (repoURL != null && repoURL.trim().length() > 0 && privateRepo) {
-			if (log.isDebugEnabled()) {
-				log.debug("External repo validation is a private repo: " + repoURL);
-			}
-			if (repoUsername == null || repoUsername.trim().length() == 0 || repoPassword == null
-					|| repoPassword.trim().length() == 0) {
-				throw new RepositoryCredentialsRequiredException(
-						"Username and Password are required for private repository");
-			}
-		}
-
-		if (!testConnection) {
-			if (log.isDebugEnabled()) {
-				log.debug("External repo validation is not enabled");
-			}
-			return repositoryInformation;
-		}
-
-		if (repoURL == null || repoURL.trim().length() == 0) {
-			// This means, no repo to validate.
-			return repositoryInformation;
-		}
-		
-		if (log.isDebugEnabled()) {
-			log.debug("External repo validation enabled");
-		}
-
-		// This assumes running on Linux.
-		String parentDirName = "/tmp/" + UUID.randomUUID().toString();
-		CredentialsProvider credentialsProvider = null;
-		if (repoUsername != null && repoUsername.trim().length() > 0 && repoPassword != null
-				&& repoPassword.trim().length() > 0) {
-			if (log.isDebugEnabled()) {
-				log.debug("External repo credentails are passed: " + repoUsername);
-			}
-			credentialsProvider = new UsernamePasswordCredentialsProvider(repoUsername, repoPassword.toCharArray());
-		}
-
-		// Initialize temp local file repo
-		FileRepository localRepo = null;
-		try {
-			File f = new File(parentDirName + "/.git");
-			localRepo = new FileRepository(f);
-			if (log.isDebugEnabled()) {
-				log.debug("Local File Repo: " + f.getAbsoluteFile());
-			}
-		} catch (IOException e) {
-			throw new ADCException("Error creating local file repo", e);
-		}
-
-		Git git = new Git(localRepo);
-		LsRemoteCommand cmd = git.lsRemote().setRemote(repoURL);
-		if (credentialsProvider != null) {
-			cmd.setCredentialsProvider(credentialsProvider);
-		}
-		try {
-			Collection<Ref> collection = cmd.call();
-			List<String> refNames = new ArrayList<String>();
-			if (collection != null) {
-				for (Ref ref : collection) {
-					if (log.isDebugEnabled()) {
-						log.debug(repoURL + ": " + ref.getName());
-					}
-					refNames.add(ref.getName());
-				}
-			}
-			repositoryInformation.setRefName(refNames.toArray(new String[refNames.size()]));
-		} catch (InvalidRemoteException e) {
-			throw new InvalidRepositoryException("Provided repository url is not valid", e);
-		} catch (TransportException e) {
-			throw new RepositoryTransportException("Transport error when checking remote repository", e);
-		} catch (GitAPIException e) {
-			throw new ADCException("Git API error when checking remote repository", e);
-		}
-		return repositoryInformation;
-	}
-
     public static String generatePassword() {
 
         final int PASSWORD_LENGTH = 8;
@@ -735,12 +140,7 @@ public class ApplicationManagementUtil {
 
     }
 
-    private static void deletePayloadFile(String payloadZipFileName) {
-        File payloadFile = new File(payloadZipFileName);
-        payloadFile.delete();
-        log.info(" Payload file is deleted. ");
-    }
-
+   
     public static java.util.Properties setRegisterServiceProperties(Policy policy, int tenantId, String alias) {
     	
     	DecimalFormat df = new DecimalFormat("##.##");
@@ -846,96 +246,8 @@ public class ApplicationManagementUtil {
         return subscriptionInfo;
     }
 
-    private static String getDynamicClusterDomain(String cartridgeType, String cartName,
-                                                  CartridgeInfo cartridgeInfo) {
-        return cartName + "." + cartridgeInfo.getHostName() + "." + cartridgeType +
-                ".domain";
-    }
-
-    private static Repository manageRepository(String repoURL, String repoUserName, String repoUserPassword,
-                                               String cartName, CartridgeInfo cartridgeInfo, String username,
-                                               String tenantDomain)
-            throws Exception {
-
-        Repository repository = new Repository();
-        if (repoURL != null && repoURL.trim().length() > 0) {
-            log.info("External REPO URL is provided as [" + repoURL +
-                    "]. Therefore not creating a new repo.");
-            //repository.setRepoName(repoURL.substring(0, repoURL.length()-4)); // remove .git part
-            repository.setUrl(repoURL);
-            repository.setUserName(repoUserName);
-            repository.setPassword(repoUserPassword);
-        } else {
-
-            //log.info("External REPO URL is not provided. Therefore creating a new repo. Adding to Executor");
-            log.info("External git repo url not provided for tenant "
-                    + tenantDomain + ", creating an git internal repository");
-
-            // for internal repos  internal git server username and password is used.
-            repository.setUserName(System.getProperty(CartridgeConstants.INTERNAL_GIT_USERNAME));
-            repository.setPassword(System.getProperty(CartridgeConstants.INTERNAL_GIT_PASSWORD));
-            /*repoCreationExecutor.execute(new RepositoryCreator(new RepositoryInfoBean(repoURL,
-                    cartName,
-                    tenantDomain,
-                    repository.getRepoUserName(),
-                    repository.getRepoUserPassword(),
-                    cartridgeInfo.getDeploymentDirs(),
-                    cartridgeInfo)));*/
-            new RepositoryCreator(new RepositoryInfoBean(repoURL,
-                    cartName,
-                    tenantDomain,
-                    repository.getUserName(),
-                    repository.getPassword(),
-                    cartridgeInfo.getDeploymentDirs(),
-                    cartridgeInfo)).createInternalRepository();
-            String repoName = tenantDomain + "/" + cartName;
-            repository.setUrl("https://" + System.getProperty(CartridgeConstants.GIT_HOST_NAME) + ":8443/git/" + repoName);
-
-        }
-        return repository;
-    }
-
-    public static Cartridge getCartridgeInfo(String alias, String tenantDomain) throws ADCException, NotSubscribedException {
-        log.info("Alias: " + alias);
-        if (alias == null) {
-            String msg = "Provided alias is empty";
-            log.error(msg);
-            throw new ADCException("Alias you provided is empty.");
-        }
-
-        CartridgeSubscriptionInfo sub;
-        try {
-            sub = PersistenceManager.getSubscription(tenantDomain, alias);
-        } catch (Exception e) {
-            String message = "Cannot get subscription info for " + tenantDomain + " and alias " + alias;
-            log.error(message, e);
-            throw new ADCException(message, e);
-        }
-        if (sub == null) {
-            String msg = "Info request for not subscribed cartridge";
-            log.error(msg);
-            throw new NotSubscribedException("You have not subscribed for " + alias, alias);
-        }
-
-        log.info("Cluster domain : " + sub.getClusterDomain() + " cartridge: " + sub.getCartridge());
-        
-        CartridgeInfo cartridgeInfo = null;
-        try {
-            cartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(sub.getCartridge());
-        } catch (Exception e) {
-            throw new ADCException("Cannot get cartridge info: " + sub.getCartridge(), e);
-        }
-
-        /*TopologyManagementService topologyMgtService = DataHolder.getTopologyMgtService();
-
-        String[] ips =
-                topologyMgtService.getActiveIPs(sub.getCartridge(),
-                        sub.getClusterDomain(),
-                        sub.getClusterSubdomain());
-        return populateCartridgeInfo(cartridgeInfo, sub, ips, tenantDomain);*/
-        return null;
-    }
-
+    
+    
     public static void registerService(String cartridgeType, String domain, String subDomain,
                                         StringBuilder payload, String tenantRange, String hostName,
                                         String autoscalingPoliyName, String deploymentPolicyName,
@@ -959,143 +271,6 @@ public class ApplicationManagementUtil {
         }
     }
 
-    public static Cartridge populateCartridgeInfo(CartridgeInfo cartridgeInfo, CartridgeSubscriptionInfo sub, String[] ips, String tenantDomain) throws ADCException {
-    	Cartridge cartridge = new Cartridge();
-        if (ips != null && ips.length > 0) {
-			if (log.isDebugEnabled()) {
-				log.debug("Found IPs: " + Arrays.toString(ips) + " for " + cartridgeInfo.getType() + ", "
-						+ sub.getAlias());
-			}
-			if (CartridgeConstants.DATA_CARTRIDGE_PROVIDER.equals(sub.getProvider())) {
-				// FIXME Temporary fix for SPI-301
-				//cartridge.setIp(ips[ips.length - 1]);
-				if (sub.getDataCartridge() != null) {
-					if (log.isDebugEnabled()) {
-						log.debug("Data Cartridge Info: " + sub.getDataCartridge().getUserName());
-					}
-					cartridge.setPassword(sub.getDataCartridge().getPassword());
-					cartridge.setDbUserName(sub.getDataCartridge().getUserName());
-				}
-			}
-			if (cartridgeInfo.getMultiTenant()) { // TODO refactor logic for carbon cartridges.
-				//cartridge.setStatus(CartridgeConstants.ACTIVE);
-				//cartridge.setActiveInstances(ips.length);
-			} else {
-				Map<String, String> instanceIpMap;
-				try {
-					instanceIpMap = PersistenceManager.getCartridgeInstanceInfo(ips, sub.getClusterDomain(),
-							sub.getClusterSubdomain());
-					//cartridge.setActiveInstances(ips.length);
-					//cartridge.setStatus(CartridgeConstants.ACTIVE);
-				} catch (Exception e) {
-					throw new ADCException("Error checking cartridge status");
-				}
-
-                if(cartridgeInfo.getProvider().equalsIgnoreCase(CartridgeConstants.PROVIDER_NAME_WSO2)) {
-                    //cartridge.setActiveInstances(ips.length);
-                    //cartridge.setStatus(CartridgeConstants.ACTIVE);
-                    /*List<Member> members = getMemberInstances(sub.getClusterDomain(), sub.getClusterSubdomain());
-                    if(members != null) {
-                        int activeInstancesCount = 0;
-                        for (Member member : members) {
-                            if (member != null && member.isActive() && member.getDomain().equals(sub.getClusterDomain())) {
-                                cartridge.setStatus(CartridgeConstants.ACTIVE);
-                                activeInstancesCount ++;
-                            }
-                        }
-                        cartridge.setActiveInstances(activeInstancesCount);
-                    }*/
-                }
-			}
-        } else {
-            log.warn("IPs have not returned through Topology Management for " + sub.getAlias());
-            //cartridge.setStatus(CartridgeConstants.SUBSCRIBED);
-        }
-        cartridge.setDisplayName(cartridgeInfo.getDisplayName());
-        cartridge.setDescription(cartridgeInfo.getDescription());
-        cartridge.setVersion(cartridgeInfo.getVersion());
-        cartridge.setMultiTenant(cartridgeInfo.getMultiTenant());
-
-        List<String> accessURLs = new ArrayList<String>();
-
-        if (cartridgeInfo.getPortMappings() != null) {
-            for (org.apache.stratos.cloud.controller.pojo.PortMapping portMapping : cartridgeInfo
-                    .getPortMappings()) {
-                if (portMapping != null) {
-					try {
-						int port = Integer.parseInt(portMapping.getProxyPort());
-	                	String protocol = portMapping.getProtocol();
-
-	                	if ("http".equals(protocol) && port == 80) {
-	                	    port = -1;
-	                	} else if ("https".equals(protocol) && port == 443) {
-	                	    port = -1;
-	                	}
-	                	
-	                	String file = "";
-	                	if (CartridgeConstants.PROVIDER_NAME_WSO2.equals(cartridgeInfo.getProvider()) && !cartridgeInfo.getMultiTenant()) {
-	                		// Carbon Private Jet Cartridges
-	                		file = "/t/" + tenantDomain;
-	                	}
-	                	
-	                	URL serverURL = new URL(protocol, sub.getHostName(), port, file);
-						accessURLs.add(serverURL.toExternalForm());
-					} catch (MalformedURLException e) {
-						if (log.isErrorEnabled()) {
-							log.error("Error getting access URL for " + cartridgeInfo.getType(), e);
-						}
-					} catch (NumberFormatException e) {
-						if (log.isErrorEnabled()) {
-							log.error("Error getting port of access URL for " + cartridgeInfo.getType(), e);
-						}
-					}
-                }
-            }
-        }
-
-        cartridge.setAccessURLs(accessURLs.toArray(new String[accessURLs.size()]));
-
-        cartridge.setCartridgeAlias(sub.getAlias());
-        cartridge.setCartridgeType(sub.getCartridge());
-        cartridge.setHostName(sub.getHostName());
-        //cartridge.setPolicy(sub.getPolicy());
-        Policy policy = PolicyHolder.getInstance().getPolicy(sub.getPolicy());
-        if (policy != null) {
-        //	cartridge.setPolicyDescription(policy.getDescription());
-        }
-        cartridge.setProvider(sub.getProvider());
-        cartridge.setMappedDomain(sub.getMappedDomain());
-
-        if (sub.getRepository() != null) {
-            cartridge.setRepoURL(convertRepoURL(sub.getRepository().getUrl()));
-        }
-        return cartridge;
-    }
-
-    private static List<Member> getMemberInstances(String domain, String subDomain) {
-
-        ClusteringAgent clusteringAgent = DataHolder.getServerConfigContext()
-                .getAxisConfiguration().getClusteringAgent();
-        GroupManagementAgent groupMgtAgent = clusteringAgent.getGroupManagementAgent(domain, subDomain);
-
-        if (groupMgtAgent == null) {
-            log.warn("Group Management Agent not found for domain : " + domain +
-                    ", sub domain : " + subDomain);
-            return null;
-        }
-
-        List<Member> members = groupMgtAgent.getMembers();
-        if (members == null || members.isEmpty()) {
-            return null;
-        }
-
-        return members;
-    }
+    
 
-    private static String checkCartridgeStatus(Map<String, String> instanceIpMap) {
-        if (instanceIpMap.values().contains(CartridgeConstants.ACTIVE)) {
-            return CartridgeConstants.ACTIVE;
-        } else
-            return CartridgeConstants.NOT_READY;
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29bd106c/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java
index 0130fb9..d56ba0b 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java
@@ -20,45 +20,24 @@
 package org.apache.stratos.manager.utils;
 
 public class CartridgeConstants {
-    public static final String SC_IP = "sc.ip";
 	public static final String AUTOSCALER_SERVICE_URL = "autoscaler.service.url";
     public static final String CLOUD_CONTROLLER_SERVICE_URL = "cloud.controller.service.url";
     public static final String ALIAS_NAMESPACE ="http://org.wso2.securevault/configuration";
     public static final String ALIAS_LOCALPART ="secretAlias";
     public static final String ALIAS_PREFIX ="svns";
-	public static final String CARTRIDGE_AGENT_EPR = "cartridge.agent.epr";
-	public static final String GIT_HOST_NAME = "git.host.name";
-	public static final String GIT_HOST_IP = "git.host.ip";
 	public static final String SUBSCRIPTION_ACTIVE = "SUBSCRIPTION_ACTIVE";
 	public static final String SUBSCRIPTION_INACTIVE = "SUBSCRIPTION_INACTIVE";
-	public static final String REPO_NOTIFICATION_URL = "git.repo.notification.url";
 	public static final String ACTIVE = "ACTIVE";
 	public static final String NOT_READY = "NOT-READY";
 	public static final String SUBSCRIBED = "SUBSCRIBED";
     public static final String UNSUBSCRIBED = "UNSUBSCRIBED";
-    public static final String MB_IP = "mb.ip";
-    public static final String MB_PORT = "mb.port";
-    public static final String CEP_IP = "cep.ip";
-    public static final String CEP_PORT = "cep.port";
     public static final String PUPPET_IP = "puppet.ip";
 
-
-	public static final String DB_DATASOURCE = "adc.datasource";
-	public static final String DB_URL = "adc.jdbc.url";
-	public static final String DB_DRIVER = "adc.jdbc.driver";
-	public static final String DB_USERNAME = "adc.jdbc.username";
-	public static final String DB_PASSWORD = "adc.jdbc.password";
-	public static final String BAM_IP = "bam.ip";
-	public static final String BAM_PORT = "bam.port";
 	public static final String SUDO_SH = "sudo sh";
 	public static final String APPEND_SCRIPT = "append.script";
 	public static final String REMOVE_SCRIPT = "remove.script";
 	public static final String BIND_FILE_PATH = "bind.file.path";
-	public static final String ELB_IP = "elb.ip";
-	public static final String REPO_KEY_PATH = "repo.key.path";
-	public static final String REPO_KEY = "repo.key";
 	public static final String MAX_ATTEMPTS = "max.attempts";
-	public static final String CARTRIDGE_KEY = "cartridge.key";
 	
 	public static final String FEATURE_EXTERNAL_REPO_VAIDATION_ENABLED = "feature.externalrepo.validation.enabled";
 	public static final String FEATURE_INTERNAL_REPO_ENABLED = "feature.internalrepo.enabled";
@@ -77,7 +56,6 @@ public class CartridgeConstants {
     public static final String SECURITY_KEY = "securityKey";
     public static final String DEFAULT_SECURITY_KEY = "tvnw63ufg9gh5111";
     public static final String DATA_CARTRIDGE_PROVIDER = "data";
-	public static final String REPO_INFO_EPR = "repository.info.epr";
 	public static final String INTERNAL_GIT_USERNAME = "internal.repo.username";
 	public static final String INTERNAL_GIT_PASSWORD = "internal.repo.password";
 


[5/5] git commit: Resolving conflict in ServiceUtils.java

Posted by sa...@apache.org.
Resolving conflict in ServiceUtils.java


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

Branch: refs/heads/master
Commit: c5939faf54ff1b5784c5f802e1146dd273387542
Parents: 0de4271 469b8c6
Author: Sajith Kariyawasam <sa...@wso2.com>
Authored: Wed Feb 12 00:38:36 2014 +0530
Committer: Sajith Kariyawasam <sa...@wso2.com>
Committed: Wed Feb 12 00:38:36 2014 +0530

----------------------------------------------------------------------
 .gitignore                                      |   3 +
 .../autoscaler/NetworkPartitionLbHolder.java    |  41 +-
 .../topology/AutoscalerTopologyReceiver.java    |  31 ++
 .../autoscaler/partition/PartitionManager.java  |  14 +
 .../java/org/apache/stratos/cli/CliTool.java    |   2 +-
 .../stratos/cli/CommandLineApplication.java     |  32 +-
 .../stratos/cli/RestCommandLineService.java     |  95 ++++-
 .../apache/stratos/cli/StratosApplication.java  |  24 +-
 .../stratos/cli/beans/cartridge/Cartridge.java  |   9 +
 .../DeployServiceDeploymentCommand.java         | 139 +++++++
 .../DescribeAutoScalingPolicyCommand.java       |   2 +-
 .../stratos/cli/commands/ExitCommand.java       |  12 -
 .../UndeployServiceDefinitionCommand.java       |  70 ++++
 .../apache/stratos/cli/utils/CliConstants.java  |  11 +-
 .../org.apache.stratos.cloud.controller/pom.xml |   3 -
 .../axiom/parser/CartridgeConfigParser.java     | 384 -------------------
 .../parser/CloudControllerConfigParser.java     |   2 +-
 .../cloud/controller/iaases/AWSEC2Iaas.java     | 114 ++++++
 .../controller/iaases/OpenstackNovaIaas.java    | 115 +++++-
 .../cloud/controller/iaases/VCloudIaas.java     |  24 ++
 .../impl/CloudControllerServiceImpl.java        | 104 ++++-
 .../cloud/controller/interfaces/Iaas.java       |  29 ++
 .../jcloud/ComputeServiceBuilderUtil.java       |   5 +
 .../cloud/controller/pojo/ClusterContext.java   |  53 ++-
 .../cloud/controller/pojo/IaasProvider.java     |   9 +
 .../cloud/controller/pojo/MemberContext.java    |  10 +
 .../runtime/FasterLookUpDataHolder.java         | 223 ++---------
 .../controller/topology/TopologyBuilder.java    |   6 +-
 .../topology/TopologyEventPublisher.java        |   4 +-
 .../controller/util/CloudControllerUtil.java    |  46 ++-
 .../OpenstackNovaPartitionValidator.java        |   2 +-
 .../axiom/FasterLookupDataHolderTest.java       |  92 +++++
 .../console/cartridge_info.jag                  |   9 +
 .../controllers/cartridgeDefintionSubmit.jag    |   2 +-
 .../console/controllers/loginSubmit.jag         |   3 +-
 .../console/index.jag                           |   1 -
 .../console/modules/pinch.min.js                |   4 +
 .../console/subscribe_cartridge.jag             |   6 +-
 .../themes/theme1/partials/cartridge_info.hbs   |  37 ++
 .../themes/theme1/partials/cartridges.hbs       |  18 +-
 .../console/themes/theme1/partials/header.hbs   |   2 +-
 .../themes/theme1/partials/mycartridges.hbs     |  18 +-
 .../theme1/partials/subscribe_cartridge.hbs     |  53 ++-
 .../themes/theme1/partials/tenant_new.hbs       |   4 +-
 .../themes/theme1/renderers/cartridge_info.js   |  42 ++
 .../theme1/renderers/subscribe_cartridge.js     |   8 +-
 .../console/themes/theme1/theme.js              |   7 +
 .../console/themes/theme1/ui/css/main.css       |   7 +-
 .../themes/theme1/ui/custom-fonts/style.css     |  25 +-
 .../console/util/utility.jag                    |   7 +
 .../apache/stratos/manager/dto/Cartridge.java   |  30 ++
 .../manager/lookup/LookupDataHolder.java        |  21 +
 .../manager/lookup/SubscriptionContext.java     |   2 +
 .../DataInsertionAndRetrievalManager.java       |  15 +
 .../utils/CartridgeSubscriptionUtils.java       |   4 +-
 .../messaging/domain/topology/Service.java      |   4 +-
 .../event/topology/ClusterRemovedEvent.java     |   8 +-
 .../stratos/messaging/util/Constants.java       |  11 +-
 .../stratos/rest/endpoint/mock/MockContext.java |   4 +
 .../rest/endpoint/mock/StratosTestAdmin.java    |   9 +-
 .../rest/endpoint/services/ServiceUtils.java    |  21 +-
 .../rest/endpoint/services/StratosAdmin.java    |  10 +
 .../main/webapp/stratos/WEB-INF/cxf-servlet.xml |   2 +-
 .../main/resources/CloudControllerService.wsdl  |   3 +-
 64 files changed, 1397 insertions(+), 710 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c5939faf/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------


[3/5] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos

Posted by sa...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos


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

Branch: refs/heads/master
Commit: 9af8ef7be38d27c52e84d1e7d69e730f52d97e40
Parents: 29bd106 2781d99
Author: Sajith Kariyawasam <sa...@wso2.com>
Authored: Tue Feb 11 12:16:06 2014 +0530
Committer: Sajith Kariyawasam <sa...@wso2.com>
Committed: Tue Feb 11 12:16:06 2014 +0530

----------------------------------------------------------------------
 .../cloud/controller/pojo/CartridgeConfig.java  |  10 +
 .../cloud/controller/pojo/CartridgeInfo.java    |  10 +
 .../apache/stratos/manager/dto/Cartridge.java   |  16 +-
 .../manager/CartridgeSubscriptionManager.java   |  10 +-
 .../service/ApplicationManagementService.java   |   2 +-
 .../subscription/CartridgeSubscription.java     |   9 +
 .../definition/CartridgeDefinitionBean.java     |   2 +
 .../bean/util/converter/PojoConverter.java      |   3 +
 .../rest/endpoint/services/ServiceUtils.java    |  53 +-
 .../rest/endpoint/services/StratosAdmin.java    |  21 +
 .../main/resources/CloudControllerService.wsdl  | 604 ++++++++++---------
 11 files changed, 424 insertions(+), 316 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/9af8ef7b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/CartridgeSubscription.java
----------------------------------------------------------------------


[4/5] git commit: Further code and config clean up

Posted by sa...@apache.org.
Further code and config clean up


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

Branch: refs/heads/master
Commit: 0de427179174987d0ef6a6bb6caaca206ca5c1d2
Parents: 9af8ef7
Author: Sajith Kariyawasam <sa...@wso2.com>
Authored: Wed Feb 12 00:30:24 2014 +0530
Committer: Sajith Kariyawasam <sa...@wso2.com>
Committed: Wed Feb 12 00:30:24 2014 +0530

----------------------------------------------------------------------
 .../DataCartridgeSubscriptionConnector.java     |  22 +-
 .../manager/CartridgeSubscriptionManager.java   |  15 +
 .../service/ApplicationManagementService.java   | 677 -------------------
 .../manager/utils/CartridgeConstants.java       |   1 -
 .../rest/endpoint/services/ServiceUtils.java    |  49 +-
 .../src/main/conf/cartridge-config.properties   |  14 -
 6 files changed, 62 insertions(+), 716 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0de42717/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java
index 4764f49..b376da4 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/connector/data/DataCartridgeSubscriptionConnector.java
@@ -19,17 +19,13 @@
 
 package org.apache.stratos.manager.connector.data;
 
+import java.util.Properties;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.manager.connector.CartridgeSubscriptionConnector;
-import org.apache.stratos.manager.dto.Cartridge;
 import org.apache.stratos.manager.exception.ADCException;
-import org.apache.stratos.manager.exception.NotSubscribedException;
 import org.apache.stratos.manager.subscription.CartridgeSubscription;
-import org.apache.stratos.manager.utils.ApplicationManagementUtil;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-
-import java.util.Properties;
 
 public class DataCartridgeSubscriptionConnector extends CartridgeSubscriptionConnector {
 
@@ -45,10 +41,10 @@ public class DataCartridgeSubscriptionConnector extends CartridgeSubscriptionCon
 
         Properties connectionProperties = new Properties();
 
-        int maxAttempts = Integer.parseInt(System.getProperty(CartridgeConstants.MAX_ATTEMPTS, "50"));
-        int attempts = 0;
-        while (attempts < maxAttempts) {
-            attempts++;
+       // int maxAttempts = Integer.parseInt(System.getProperty(CartridgeConstants.MAX_ATTEMPTS, "50"));
+        //int attempts = 0;
+       // while (attempts < maxAttempts) {
+            //attempts++;
             /*Cartridge cartridge = null;
              try {
                 cartridge = ApplicationManagementUtil.getCartridgeInfo(
@@ -74,12 +70,12 @@ public class DataCartridgeSubscriptionConnector extends CartridgeSubscriptionCon
                 }*/
             //}
 
-            if(attempts == maxAttempts) {
+            /*if(attempts == maxAttempts) {
                 String errorMsg = "Failed to connect " + cartridgeSubscription + " and " + connectingCartridgeSubscription;
                 log.error(errorMsg);
                 throw  new ADCException(errorMsg);
-            }
-        }
+            }*/
+        //}
 
         return connectionProperties;
     }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0de42717/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 4daa668..1b63890 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
@@ -288,4 +288,19 @@ public class CartridgeSubscriptionManager {
             throw new NotSubscribedException(errorMsg, alias);
         }
     }
+    
+    
+    /**
+     * 
+     * Returns a collection of Cartridge subscriptions for a particular tenant and a cartridge type
+     * 
+     * @param tenantId
+     * @param cartridgeType
+     * @return
+     */
+    public Collection<CartridgeSubscription> isCartridgeSubscribed(int tenantId, String cartridgeType) {
+    	
+    	DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
+        return dataInsertionAndRetrievalManager.getCartridgeSubscriptions(tenantId, cartridgeType);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0de42717/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/ApplicationManagementService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/ApplicationManagementService.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/ApplicationManagementService.java
deleted file mode 100644
index 503bcec..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/service/ApplicationManagementService.java
+++ /dev/null
@@ -1,677 +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.manager.service;
-
-import org.apache.axis2.AxisFault;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
-import org.apache.stratos.manager.client.CloudControllerServiceClient;
-import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
-import org.apache.stratos.manager.dto.*;
-import org.apache.stratos.manager.exception.*;
-import org.apache.stratos.manager.manager.CartridgeSubscriptionManager;
-import org.apache.stratos.manager.subscription.CartridgeSubscription;
-import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
-import org.apache.stratos.manager.utils.ApplicationManagementUtil;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.apache.stratos.manager.utils.PersistenceManager;
-import org.apache.stratos.manager.utils.PolicyHolder;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.core.AbstractAdmin;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.utils.DataPaginator;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Pattern;
-
-/**
- *
- *
- *
- */
-public class ApplicationManagementService extends AbstractAdmin {
-
-    private static final Log log = LogFactory.getLog(ApplicationManagementService.class);
-    //private RegistryManager registryManager = new RegistryManager();
-    private CartridgeSubscriptionManager cartridgeSubsciptionManager = new CartridgeSubscriptionManager();
-
-    /*
-     * Instantiate RepoNotificationService. Since this service is in the same 
-     * component (org.apache.stratos.manager), a new object is created.
-     * TODO: Is there a better way to get this service?
-     */
-    private RepoNotificationService repoNotificationService = new RepoNotificationService();
-
-	/**
-	 * Get Available Cartridges
-	 * 
-	 * @return Available Cartridges
-	 */
-	public Cartridge[] getAvailableCartridges(boolean multiTenant) throws ADCException {
-		List<Cartridge> cartridges = getAvailableCartridges(null, multiTenant);
-		// Following is very important when working with axis2
-		return cartridges.isEmpty() ? new Cartridge[0] : cartridges.toArray(new Cartridge[cartridges.size()]);
-	}
-
-	/**
-	 * Get Subscribed Cartridges
-	 * 
-	 * @return Subscribed Cartridges
-	 */
-	public Cartridge[] getSubscribedCartridges() throws ADCException {
-		checkSuperTenant();
-		List<Cartridge> cartridgeList = getSubscribedCartridges(null);
-		// Following is very important when working with axis2
-		return cartridgeList.isEmpty() ? new Cartridge[0] : cartridgeList.toArray(new Cartridge[cartridgeList.size()]);
-	}
-
-	/**
-	 * Get available cartridges
-	 */
-	public CartridgeWrapper getPagedAvailableCartridges(String cartridgeSearchString, int pageNumber, boolean multiTenant)
-			throws ADCException {
-		checkSuperTenant();
-		CartridgeWrapper cartridgeWrapper = new CartridgeWrapper();
-		List<Cartridge> cartridges = getAvailableCartridges(cartridgeSearchString, multiTenant);
-    	
-		// TODO Improve pagination
-		if (!cartridges.isEmpty()) {
-			// Paginate only if cartridges are there.
-			DataPaginator.doPaging(pageNumber, cartridges, cartridgeWrapper);
-		} else {
-			// Must set this value as axis2 stub client will return an array
-			// with length = 1 and null element if cartridges[] is null
-			cartridgeWrapper.set(cartridges);
-		}
-		return cartridgeWrapper;
-	}
-
-	private List<Cartridge> getAvailableCartridges(String cartridgeSearchString, Boolean multiTenant) throws ADCException {
-		List<Cartridge> cartridges = new ArrayList<Cartridge>();
-		
-		if (log.isDebugEnabled()) {
-			log.debug("Getting available cartridges. Search String: " + cartridgeSearchString + ", Multi-Tenant: " + multiTenant);
-		}
-		
-		boolean allowMultipleSubscription = new Boolean(
-				System.getProperty(CartridgeConstants.FEATURE_MULTI_TENANT_MULTIPLE_SUBSCRIPTION_ENABLED));
-
-		try {
-			Pattern searchPattern = getSearchStringPattern(cartridgeSearchString);
-
-			String[] availableCartridges = CloudControllerServiceClient.getServiceClient().getRegisteredCartridges();
-
-			if (availableCartridges != null) {
-				for (String cartridgeType : availableCartridges) {
-					CartridgeInfo cartridgeInfo = null;
-					try {
-						cartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(cartridgeType);
-					} catch (Exception e) {
-						if (log.isWarnEnabled()) {
-							log.warn("Error when calling getCartridgeInfo for " + cartridgeType + ", Error: "
-									+ e.getMessage());
-						}
-					}
-					if (cartridgeInfo == null) {
-						// This cannot happen. But continue
-						if (log.isDebugEnabled()) {
-							log.debug("Cartridge Info not found: " + cartridgeType);
-						}
-						continue;
-					}
-					
-					if (multiTenant != null && !multiTenant && cartridgeInfo.getMultiTenant()) {
-						// Need only Single-Tenant cartridges
-						continue;
-					} else if (multiTenant != null && multiTenant && !cartridgeInfo.getMultiTenant()) {
-						// Need only Multi-Tenant cartridges
-						continue;
-					}
-					
-					if (!cartridgeMatches(cartridgeInfo, searchPattern)) {
-						continue;
-					}
-					
-					Cartridge cartridge = new Cartridge();
-					cartridge.setCartridgeType(cartridgeType);
-					cartridge.setProvider(cartridgeInfo.getProvider());
-					cartridge.setDisplayName(cartridgeInfo.getDisplayName());
-					cartridge.setDescription(cartridgeInfo.getDescription());
-					cartridge.setVersion(cartridgeInfo.getVersion());
-					cartridge.setMultiTenant(cartridgeInfo.getMultiTenant());
-					//cartridge.setStatus(CartridgeConstants.NOT_SUBSCRIBED);
-					cartridge.setCartridgeAlias("-");
-					//cartridge.setActiveInstances(0);
-					cartridges.add(cartridge);
-					
-					if (cartridgeInfo.getMultiTenant() && !allowMultipleSubscription) {
-						// If the cartridge is multi-tenant. We should not let users
-						// createSubscription twice.
-						if (PersistenceManager.isAlreadySubscribed(cartridgeType,
-								ApplicationManagementUtil.getTenantId(getConfigContext()))) {
-							if (log.isDebugEnabled()) {
-								log.debug("Already subscribed to " + cartridgeType
-										+ ". This multi-tenant cartridge will not be available to createSubscription");
-							}
-							//cartridge.setStatus(CartridgeConstants.SUBSCRIBED);
-						}
-					}
-				}
-			} else {
-				if (log.isDebugEnabled()) {
-					log.debug("There are no available cartridges");
-				}
-			}
-		} catch (Exception e) {
-			String msg = "Error when getting available cartridges. " + e.getMessage();
-			log.error(msg, e);
-			throw new ADCException("An error occurred getting available cartridges ", e);
-		}
-
-		Collections.sort(cartridges);
-
-		if (log.isDebugEnabled()) {
-			log.debug("Returning available cartridges " + cartridges.size());
-		}
-
-		return cartridges;
-	}
-
-	/**
-	 * Get subscribed cartridges
-	 */
-	public CartridgeWrapper getPagedSubscribedCartridges(String cartridgeSearchString, int pageNumber)
-			throws ADCException {
-		checkSuperTenant();
-		CartridgeWrapper cartridgeWrapper = new CartridgeWrapper();
-		List<Cartridge> cartridges = getSubscribedCartridges(cartridgeSearchString);
-
-		// TODO Improve pagination
-		if (!cartridges.isEmpty()) {
-			// Paginate only if cartridges are there.
-			DataPaginator.doPaging(pageNumber, cartridges, cartridgeWrapper);
-		} else {
-			cartridgeWrapper.set(cartridges);
-		}
-		return cartridgeWrapper;
-	}
-
-	private List<Cartridge> getSubscribedCartridges(String cartridgeSearchString) throws ADCException {
-		List<Cartridge> cartridges = new ArrayList<Cartridge>();
-		
-		if (log.isDebugEnabled()) {
-			log.debug("Getting subscribed cartridges. Search String: " + cartridgeSearchString);
-		}
-
-		try {
-			Pattern searchPattern = getSearchStringPattern(cartridgeSearchString);
-
-			List<CartridgeSubscriptionInfo> subscriptionList = PersistenceManager
-					.retrieveSubscribedCartridges(ApplicationManagementUtil.getTenantId(getConfigContext()));
-
-			if (subscriptionList != null && !subscriptionList.isEmpty()) {
-				for (CartridgeSubscriptionInfo subscription : subscriptionList) {
-					CartridgeInfo cartridgeInfo = null;
-					try {
-						cartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(
-								subscription.getCartridge());
-					} catch (Exception e) {
-						if (log.isWarnEnabled()) {
-							log.warn("Error when calling getCartridgeInfo for " + subscription.getCartridge()
-									+ ", Error: " + e.getMessage());
-						}
-					}
-					if (cartridgeInfo == null) {
-						// This cannot happen. But continue
-						if (log.isDebugEnabled()) {
-							log.debug("Cartridge Info not found: " + subscription.getCartridge());
-						}
-						continue;
-					}
-					if (!cartridgeMatches(cartridgeInfo, subscription, searchPattern)) {
-						continue;
-					}
-					/*TopologyManagementService topologyMgtService = DataHolder.getTopologyMgtService();
-					String[] ips = topologyMgtService.getActiveIPs(subscription.getCartridge(),
-							subscription.getClusterDomain(), subscription.getClusterSubdomain());
-					Cartridge cartridge = ApplicationManagementUtil.populateCartridgeInfo(cartridgeInfo, subscription, ips, getTenantDomain());
-					cartridges.add(cartridge);*/
-				}
-			} else {
-				if (log.isDebugEnabled()) {
-					log.debug("There are no subscribed cartridges");
-				}
-			}
-		} catch (Exception e) {
-			String msg = "Error when getting subscribed cartridges. " + e.getMessage();
-			log.error(msg, e);
-			throw new ADCException("An Error occurred when getting subscribed cartridges.", e);
-		}
-
-		Collections.sort(cartridges);
-
-		if (log.isDebugEnabled()) {
-			log.debug("Returning subscribed cartridges " + cartridges.size());
-		}
-
-		return cartridges;
-	}
-
-    private Pattern getSearchStringPattern(String searchString) {
-        if (log.isDebugEnabled()) {
-            log.debug("Creating search pattern for " + searchString);
-        }
-        if (searchString != null) {
-            // Copied from org.wso2.carbon.webapp.mgt.WebappAdmin.doesWebappSatisfySearchString(WebApplication, String)
-            String regex = searchString.toLowerCase().replace("..?", ".?").replace("..*", ".*").replaceAll("\\?", ".?")
-                    .replaceAll("\\*", ".*?");
-            if (log.isDebugEnabled()) {
-                log.debug("Created regex: " + regex + " for search string " + searchString);
-            }
-
-            Pattern pattern = Pattern.compile(regex);
-            return pattern;
-        }
-        return null;
-    }
-
-    // TODO: Improve search method
-    private boolean cartridgeMatches(CartridgeInfo cartridgeInfo, Pattern pattern) {
-        if (pattern != null) {
-            boolean matches = false;
-            if (cartridgeInfo.getDisplayName() != null) {
-                matches = pattern.matcher(cartridgeInfo.getDisplayName().toLowerCase()).find();
-            }
-            if (!matches && cartridgeInfo.getDescription() != null) {
-                matches = pattern.matcher(cartridgeInfo.getDescription().toLowerCase()).find();
-            }
-            return matches;
-        }
-        return true;
-    }
-
-    private boolean cartridgeMatches(CartridgeInfo cartridgeInfo, CartridgeSubscriptionInfo cartridgeSubscriptionInfo, Pattern pattern) {
-        if (pattern != null) {
-            boolean matches = false;
-            if (cartridgeInfo.getDisplayName() != null) {
-                matches = pattern.matcher(cartridgeInfo.getDisplayName().toLowerCase()).find();
-            }
-            if (!matches && cartridgeInfo.getDescription() != null) {
-                matches = pattern.matcher(cartridgeInfo.getDescription().toLowerCase()).find();
-            }
-            if (!matches && cartridgeSubscriptionInfo.getCartridge() != null) {
-                matches = pattern.matcher(cartridgeSubscriptionInfo.getCartridge().toLowerCase()).find();
-            }
-            if (!matches && cartridgeSubscriptionInfo.getAlias() != null) {
-                matches = pattern.matcher(cartridgeSubscriptionInfo.getAlias().toLowerCase()).find();
-            }
-            return matches;
-        }
-        return true;
-    }
-    
-    public Cartridge getCartridgeInfo(String alias) throws ADCException, NotSubscribedException {
-    	checkSuperTenant();
-    	return ApplicationManagementUtil.getCartridgeInfo(alias, getTenantDomain());
-    }
-
-    public String[] getSubscribedCartridgeAliases() throws AxisFault {
-        try {
-            List<CartridgeSubscriptionInfo> subscriptionList = PersistenceManager
-                    .retrieveSubscribedCartridges(ApplicationManagementUtil.getTenantId(getConfigContext()));
-            List<String> subscribedAliases = new ArrayList<String>();
-            for (CartridgeSubscriptionInfo cartridgeSubscriptionInfo : subscriptionList) {
-
-                if(cartridgeSubscriptionInfo.getProvider().equalsIgnoreCase(CartridgeConstants.PROVIDER_NAME_WSO2) &&
-                        getCartridgeInfo(cartridgeSubscriptionInfo.getAlias()).isMultiTenant()) {
-
-                    subscribedAliases.add(cartridgeSubscriptionInfo.getCartridge());
-                } else {
-                    subscribedAliases.add(cartridgeSubscriptionInfo.getAlias());
-                }
-            }
-            if(subscribedAliases.size() == 0) {
-                return new String[]{""};
-            } else {
-                return subscribedAliases.toArray(new String[subscribedAliases.size()]);
-            }
-
-        } catch (Exception e) {
-            String msg = "Exception in getting subscribed cartridge aliases :" + e.getMessage();
-            log.error(msg, e);
-            throw new AxisFault("An error occurred while getting subscribed cartridge aliases", e);
-        }
-    }
-    
-	public PolicyDefinition[] getPolicyDefinitions() {
-		List<PolicyDefinition> policyDefinitions = PolicyHolder.getInstance().getPolicyDefinitions();
-		return policyDefinitions == null || policyDefinitions.isEmpty() ? new PolicyDefinition[0] : policyDefinitions
-				.toArray(new PolicyDefinition[policyDefinitions.size()]);
-	}
-
-	/**
-	 * Subscribe to a cartridge
-	 */
-	public SubscriptionInfo subscribe(String cartridgeType, String alias, String policy, String repoURL,
-			boolean privateRepo, String repoUsername, String repoPassword, String dataCartridgeType,
-			String dataCartridgeAlias) throws ADCException, PolicyException, UnregisteredCartridgeException,
-            InvalidCartridgeAliasException, DuplicateCartridgeAliasException, RepositoryRequiredException,
-            AlreadySubscribedException, RepositoryCredentialsRequiredException, InvalidRepositoryException,
-            RepositoryTransportException {
-
-		checkSuperTenant();
-
-		//return ApplicationManagementUtil.doSubscribe(cartridgeType, alias, policy, repoURL, privateRepo, repoUsername,
-		//		repoPassword, dataCartridgeType, dataCartridgeAlias, getUsername(),
-		//		ApplicationManagementUtil.getTenantId(getConfigContext()), getTenantDomain());
-
-        CartridgeSubscription cartridgeSubscription = cartridgeSubsciptionManager.subscribeToCartridge(cartridgeType,
-                alias.trim(), "economyPolicy", "economy-deployment", getTenantDomain(), ApplicationManagementUtil.getTenantId(configurationContext),
-                getUsername(), "git", repoURL, privateRepo, repoUsername, repoPassword, null);
-
-        if(dataCartridgeAlias != null && !dataCartridgeAlias.trim().isEmpty()) {
-
-            /*dataCartridgeAlias = dataCartridgeAlias.trim();
-
-            CartridgeSubscription connectingCartridgeSubscription = null;
-            try {
-                connectingCartridgeSubscription = cartridgeSubsciptionManager.getCartridgeSubscriptionForCluster(getTenantDomain(),
-                        dataCartridgeAlias);
-            } catch (NotSubscribedException e) {
-                log.error(e.getMessage(), e);
-            }
-            if (connectingCartridgeSubscription != null) {
-                // Publish tenant subscribed event
-                CartridgeSubscriptionUtils.publishTenantSubscribedEvent(getTenantId(), connectingCartridgeSubscription.getCartridgeInfo().getType());
-
-                try {
-                    cartridgeSubsciptionManager.connectCartridges(getTenantDomain(), cartridgeSubscription,
-                            connectingCartridgeSubscription.getAlias());
-
-                } catch (NotSubscribedException e) {
-                    log.error(e.getMessage(), e);
-
-                } catch (AxisFault axisFault) {
-                    log.error(axisFault.getMessage(), axisFault);
-                }
-            } else {
-                log.error("Failed to connect. No cartridge subscription found for tenant " +
-                        ApplicationManagementUtil.getTenantId(configurationContext) + " with alias " + alias);
-            } */
-        }
-
-        return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription);
-
-	}
-
-    /**
-     * Unsubscribing the cartridge
-     *
-     * @param alias name of the cartridge to be unsubscribed
-     */
-    public void unsubscribe(String alias) throws ADCException, NotSubscribedException {
-
-        checkSuperTenant();
-
-        // Find subscription of alias
-        CartridgeSubscriptionInfo subscription;
-        String errorMessage = String.format("Tenant %s is not subscribed for %s", getTenantDomain(), alias);
-        try {
-            subscription = PersistenceManager.getSubscription(getTenantDomain(), alias);
-            if(subscription == null) {
-                throw new ADCException(errorMessage);
-            }
-        } catch (Exception e) {
-            throw new ADCException(errorMessage);
-        }
-
-        // Un-subscribe from cartridge
-        cartridgeSubsciptionManager.unsubscribeFromCartridge(getTenantDomain(), alias);
-
-        // Publish tenant un-subscribed event
-        String serviceName = subscription.getCartridge();
-        CartridgeSubscriptionUtils.publishTenantUnSubscribedEvent(getTenantId(), serviceName);
-
-
-        /*CartridgeSubscriptionInfo subscription = null;
-        
-        try {
-			subscription = PersistenceManager.getSubscription(getTenantDomain(), alias);
-		} catch (Exception e) {
-			String msg = "Failed to get subscription for " + getTenantDomain() + " and alias " + alias;
-            log.error(msg, e);
-			throw new ADCException(msg, e);
-		}
-
-        if (subscription == null) {
-            String msg = "Tenant " + getTenantDomain() + " is not subscribed for " + alias;
-            log.error(msg);
-            throw new NotSubscribedException("You have not subscribed for " + alias, alias);
-        }
-        
-        try {
-            String clusterDomain = subscription.getClusterDomain();
-            String clusterSubDomain = subscription.getClusterSubdomain();
-
-            if (log.isDebugEnabled()) {
-                log.debug("Finding cartridge information for " + subscription.getCartridge());
-            }
-            CartridgeInfo cartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(subscription.getCartridge());
-            if (log.isDebugEnabled()) {
-                log.debug("Found " + cartridgeInfo.getDisplayName() + " for " + subscription.getCartridge());
-            }
-            if (!cartridgeInfo.getMultiTenant()) {
-                log.info("Terminating all instances of " + clusterDomain + " " + clusterSubDomain);
-                CloudControllerServiceClient.getServiceClient().terminateAllInstances(clusterDomain, clusterSubDomain);
-                log.info("All instances terminated.");
-                log.info("Unregistering services...");
-                CloudControllerServiceClient.getServiceClient().unregisterService(clusterDomain, clusterSubDomain);
-                log.info("Successfully terminated instances ..");
-            } else {
-                if (log.isInfoEnabled()) {
-                    log.info("Cartridge "
-                            + subscription.getCartridge()
-                            + " is a multi-tenant cartridge and therefore will not terminate all instances and unregister services");
-                }
-            }
-
-            new RepositoryFactory().destroyRepository(alias, getTenantDomain(), getUsername());
-            log.info("Repo is destroyed successfully.. ");
-
-            PersistenceManager.updateSubscriptionState(subscription.getSubscriptionId(), "UNSUBSCRIBED");
-            new DNSManager().removeSubDomain(subscription.getHostName());
-            registryManager.removeDomainMappingFromRegistry(subscription.getHostName());
-            TopologyManagementService topologyMgtService = DataHolder.getTopologyMgtService();
-			
-            String[] ips = topologyMgtService.getActiveIPs(subscription.getCartridge(),
-					subscription.getClusterDomain(), subscription.getClusterSubdomain());
-            PersistenceManager.updateInstanceState("INACTIVE", ips, subscription.getClusterDomain(), subscription.getClusterSubdomain(), subscription.getCartridge());
-
-        } catch (ADCException e) {
-        	log.error(e.getMessage(), e);
-        	throw e;
-        } catch (Exception e1) {
-            String msg1 = "Exception occurred :" + e1.getMessage();
-            log.error(msg1);
-            throw new ADCException("Unsubscribe failed for cartridge " + alias, e1);
-        }*/
-    }
-
-
-    public String addDomainMapping(String mappedDomain, String cartridgeAlias) throws ADCException, DomainMappingExistsException, NotSubscribedException {
-    	checkSuperTenant();
-    	// TODO Following was in CLI. Fix this
-		//		if (domain.indexOf('.') == -1) {
-		//			System.out.println("\nOwn domain should include a '.' ");
-		//		}
-
-        CartridgeSubscriptionInfo subscription = null;
-        String actualHost = null;
-        
-        try {
-			subscription = PersistenceManager.getSubscription(getTenantDomain(), cartridgeAlias);
-		} catch (Exception e) {
-			String msg = "Failed to get subscription for " + getTenantDomain() + " and alias " + cartridgeAlias;
-            log.error(msg, e);
-			throw new ADCException(msg, e);
-		}
-        if (subscription == null) {
-        	String msg = "Tenant " + getTenantDomain() + " is not subscribed for " + cartridgeAlias;
-            log.error(msg);
-            throw new NotSubscribedException("You have not subscribed for " + cartridgeAlias, cartridgeAlias);
-        }
-
-        try {
-        	actualHost = getActualHost(cartridgeAlias);
-            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-            //registryManager.addDomainMappingToRegistry(mappedDomain, actualHost);
-            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-            log.info("Domain mapping is added for " + mappedDomain + " tenant: " + getTenantDomain());
-            PersistenceManager.updateDomainMapping(
-                    ApplicationManagementUtil.getTenantId(getConfigContext()), cartridgeAlias, mappedDomain);
-        } catch (RegistryException e) {
-            String msg = "Unable to add the mapping due to registry transaction error";
-            log.error(msg, e);
-            throw new ADCException("Unable to add the mapping due to internal error!", e);
-        } catch (DomainMappingExistsException e) {
-            String msg = "Domain mapping already exists.";
-            log.error(msg, e);
-            throw e;
-        } catch (Exception e) {
-            String msg = "Error occurred. Reason : " + e.getMessage();
-            log.error(msg, e);
-            throw new ADCException(msg, e);
-        }
-        return actualHost;
-    }
-
-	private String getActualHost(String cartridgeName) throws Exception {
-		return PersistenceManager.getHostNameForCartridgeName(
-				ApplicationManagementUtil.getTenantId(getConfigContext()), cartridgeName);
-	}
-
-    public void removeDomainMapping(String cartridgeAlias) throws ADCException, NotSubscribedException {
-    	checkSuperTenant();
-        CartridgeSubscriptionInfo subscription = null;
-        String actualHost = null;
-        
-        try {
-			subscription = PersistenceManager.getSubscription(getTenantDomain(), cartridgeAlias);
-		} catch (Exception e) {
-			String msg = "Failed to get subscription for " + getTenantDomain() + " and alias " + cartridgeAlias;
-            log.error(msg, e);
-			throw new ADCException(msg, e);
-		}
-        if (subscription == null) {
-        	String msg = "Tenant " + getTenantDomain() + " is not subscribed for " + cartridgeAlias;
-            log.error(msg);
-            throw new NotSubscribedException("You have not subscribed for " + cartridgeAlias, cartridgeAlias);
-        }
-        
-        try {
-        	actualHost = getActualHost(cartridgeAlias);
-            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-            //registryManager.removeDomainMappingFromRegistry(actualHost);
-            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-            log.info("Domain mapping is removed for " + actualHost + " tenant: " + getTenantDomain());
-            PersistenceManager.updateDomainMapping(ApplicationManagementUtil.getTenantId(getConfigContext()),
-                    cartridgeAlias, null);
-        } catch (RegistryException e) {
-            String msg = "Unable to remove the mapping due to registry transaction error";
-            log.error(msg, e);
-            throw new ADCException("Unable to remove the mapping due to internal error!", e);
-        } catch (Exception e) {
-            String msg = "Error occurred. Reason : " + e.getMessage();
-            log.error(msg, e);
-            throw new ADCException(msg, e);
-        }
-    }
-
-	public void synchronizeRepository(String cartridgeAlias) throws ADCException, NotSubscribedException {
-		checkSuperTenant();
-        CartridgeSubscriptionInfo subscription = null;
-        
-        // Validating subscription
-        try {
-			subscription = PersistenceManager.getSubscription(getTenantDomain(), cartridgeAlias);
-		} catch (Exception e) {
-			String msg = "Failed to get subscription for " + getTenantDomain() + " and alias " + cartridgeAlias;
-            log.error(msg, e);
-			throw new ADCException(msg, e);
-		}
-        if (subscription == null) {
-        	String msg = "Tenant " + getTenantDomain() + " is not subscribed for " + cartridgeAlias;
-            log.error(msg);
-            throw new NotSubscribedException("You have not subscribed for " + cartridgeAlias, cartridgeAlias);
-        }
-		
-		try {
-			repoNotificationService.notifyRepoUpdate(getTenantDomain(), cartridgeAlias);
-		} catch (Exception e) {
-			throw new ADCException(e.getMessage() != null ? e.getMessage() : "Failed to synchronize repository", e);
-		}
-	}
-
-	public String getTenantDomain() {
-        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
-        return carbonContext.getTenantDomain();
-	}
-
-    public int getTenantId() {
-        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
-        return carbonContext.getTenantId();
-    }
-    
-	/**
-	 * Allow to check whether features are enabled in the back-end
-	 * 
-	 * @param key
-	 *            The propery key
-	 * @return {@code true} if feature is enabled
-	 */
-	public boolean isFeatureEnabled(String key) {
-		if (key != null && key.startsWith("feature.")) {
-			return new Boolean(System.getProperty(key));
-		}
-		return false;
-	}
-
-	
-	public RepositoryInformation testRepositoryConnection(String repoURL, String repoUsername, String repoPassword, boolean privateRepo)
-			throws RepositoryRequiredException, ADCException, RepositoryCredentialsRequiredException,
-			InvalidRepositoryException, RepositoryTransportException {
-		return ApplicationManagementUtil.validateRepository(repoURL, repoUsername, repoPassword, privateRepo, true);
-	}
-	
-	// TODO Remove following when we support cartridge subscription for Super-tenant
-	private void checkSuperTenant() throws ADCException {
-		if (log.isDebugEnabled()) {
-			log.debug("Checking whether super tenant accesses the service methods. Tenant ID: "
-					+ ApplicationManagementUtil.getTenantId(getConfigContext()) + ", Tenant Domain: " + getTenantDomain());
-		}
-		if (MultitenantConstants.SUPER_TENANT_ID == ApplicationManagementUtil.getTenantId(getConfigContext())) {
-			throw new ADCException("Super Tenant is not allowed to complete requested operation");
-		}
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0de42717/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java
index d56ba0b..f3ff654 100644
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/utils/CartridgeConstants.java
@@ -37,7 +37,6 @@ public class CartridgeConstants {
 	public static final String APPEND_SCRIPT = "append.script";
 	public static final String REMOVE_SCRIPT = "remove.script";
 	public static final String BIND_FILE_PATH = "bind.file.path";
-	public static final String MAX_ATTEMPTS = "max.attempts";
 	
 	public static final String FEATURE_EXTERNAL_REPO_VAIDATION_ENABLED = "feature.externalrepo.validation.enabled";
 	public static final String FEATURE_INTERNAL_REPO_ENABLED = "feature.internalrepo.enabled";

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0de42717/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index 8fd6d52..fc83700 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@ -18,16 +18,40 @@
 
 package org.apache.stratos.rest.endpoint.services;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+import java.util.regex.Pattern;
+
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
+import org.apache.stratos.cloud.controller.pojo.CartridgeConfig;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.LoadbalancerConfig;
+import org.apache.stratos.cloud.controller.pojo.Properties;
+import org.apache.stratos.cloud.controller.pojo.Property;
 import org.apache.stratos.manager.client.AutoscalerServiceClient;
 import org.apache.stratos.manager.client.CloudControllerServiceClient;
 import org.apache.stratos.manager.deploy.service.ServiceDeploymentManager;
 import org.apache.stratos.manager.dto.Cartridge;
 import org.apache.stratos.manager.dto.SubscriptionInfo;
-import org.apache.stratos.manager.exception.*;
+import org.apache.stratos.manager.exception.ADCException;
+import org.apache.stratos.manager.exception.AlreadySubscribedException;
+import org.apache.stratos.manager.exception.DuplicateCartridgeAliasException;
+import org.apache.stratos.manager.exception.InvalidCartridgeAliasException;
+import org.apache.stratos.manager.exception.InvalidRepositoryException;
+import org.apache.stratos.manager.exception.NotSubscribedException;
+import org.apache.stratos.manager.exception.PolicyException;
+import org.apache.stratos.manager.exception.RepositoryCredentialsRequiredException;
+import org.apache.stratos.manager.exception.RepositoryRequiredException;
+import org.apache.stratos.manager.exception.RepositoryTransportException;
+import org.apache.stratos.manager.exception.UnregisteredCartridgeException;
 import org.apache.stratos.manager.manager.CartridgeSubscriptionManager;
 import org.apache.stratos.manager.subscription.CartridgeSubscription;
 import org.apache.stratos.manager.subscription.DataCartridgeSubscription;
@@ -35,9 +59,6 @@ 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.PersistenceManager;
-import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
-import org.apache.stratos.cloud.controller.pojo.Properties;
 import org.apache.stratos.messaging.domain.topology.Cluster;
 import org.apache.stratos.messaging.domain.topology.Member;
 import org.apache.stratos.messaging.domain.topology.MemberStatus;
@@ -48,11 +69,6 @@ import org.apache.stratos.rest.endpoint.bean.autoscaler.policy.autoscale.Autosca
 import org.apache.stratos.rest.endpoint.bean.cartridge.definition.CartridgeDefinitionBean;
 import org.apache.stratos.rest.endpoint.bean.util.converter.PojoConverter;
 import org.apache.stratos.rest.endpoint.exception.RestAPIException;
-import org.apache.stratos.cloud.controller.pojo.*;
-
-
-import java.util.*;
-import java.util.regex.Pattern;
 
 public class ServiceUtils {
     private static Log log = LogFactory.getLog(ServiceUtils.class);
@@ -471,7 +487,7 @@ public class ServiceUtils {
                     if (cartridgeInfo.getMultiTenant() && !allowMultipleSubscription) {
                         // If the cartridge is multi-tenant. We should not let users
                         // createSubscription twice.
-                        if (PersistenceManager.isAlreadySubscribed(cartridgeType,
+                        if (isAlreadySubscribed(cartridgeType,
                                 ApplicationManagementUtil.getTenantId(configurationContext))) {
                             if (log.isDebugEnabled()) {
                                 log.debug("Already subscribed to " + cartridgeType
@@ -501,7 +517,18 @@ public class ServiceUtils {
         return cartridges;
     }
 
-    static List<Cartridge> getSubscriptions (String cartridgeSearchString, ConfigurationContext configurationContext) throws ADCException {
+    private static boolean isAlreadySubscribed(String cartridgeType,
+			int tenantId) {
+		
+    	Collection<CartridgeSubscription> subscriptionList = cartridgeSubsciptionManager.isCartridgeSubscribed(tenantId, cartridgeType);
+    	if(subscriptionList == null || subscriptionList.isEmpty()){
+    		return false;	
+    	}else {
+    		return true;
+    	}		
+	}
+
+	static List<Cartridge> getSubscriptions (String cartridgeSearchString, ConfigurationContext configurationContext) throws ADCException {
 
         List<Cartridge> cartridges = new ArrayList<Cartridge>();
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0de42717/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties
----------------------------------------------------------------------
diff --git a/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties b/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties
index 53b50f2..302b4c1 100644
--- a/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties
+++ b/products/stratos-manager/modules/distribution/src/main/conf/cartridge-config.properties
@@ -19,20 +19,6 @@
 #
 #
 
-# Configuration properties
-#this file is in product
 autoscaler.service.url=https://as.stratos.apache.org:9446/services/AutoScalerService/
 cloud.controller.service.url=https://cc.stratos.apache.org:9444/services/CloudControllerService/
-autoscaler.time.out=190000
 puppet.ip=127.0.0.1
-
-adc.jdbc.url=jdbc:h2:repository/database/WSO2S2_DB
-adc.jdbc.username=wso2carbon
-adc.jdbc.password=wso2carbon
-adc.jdbc.driver=org.h2.Driver
-
-feature.externalrepo.validation.enabled=true
-feature.internalrepo.enabled=false
-feature.multitenant.multiplesubscription.enabled=false
-
-max.attempts=1000