You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/01/04 05:52:17 UTC
[09/13] stratos git commit: Refining stratos manager component and
removing unused code
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/listener/TenantUserRoleCreator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/listener/TenantUserRoleCreator.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/listener/TenantUserRoleCreator.java
deleted file mode 100644
index 7a574bb..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/listener/TenantUserRoleCreator.java
+++ /dev/null
@@ -1,119 +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.listener;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.beans.TenantInfoBean;
-import org.apache.stratos.common.exception.ApacheStratosException;
-import org.apache.stratos.common.listeners.TenantMgtListener;
-import org.apache.stratos.manager.internal.DataHolder;
-import org.apache.stratos.manager.user.mgt.exception.UserManagerException;
-import org.apache.stratos.manager.utils.UserRoleCreator;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.user.api.UserStoreException;
-import org.wso2.carbon.user.api.UserStoreManager;
-import org.wso2.carbon.user.api.UserRealm;
-
-/**
- * Listener for Tenant create event to create a new Role
- */
-public class TenantUserRoleCreator implements TenantMgtListener {
-
- private static final Log log = LogFactory.getLog(TenantUserRoleCreator.class);
-
- /**
- * Create an 'user' role at tenant creation time
- * @param tenantInfo TenantInfoBean
- * @throws org.apache.stratos.common.exception.ApacheStratosException
- */
- @Override
- public void onTenantCreate(TenantInfoBean tenantInfo) throws ApacheStratosException {
-
- try {
-
- PrivilegedCarbonContext.startTenantFlow();
- PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
- carbonContext.setTenantDomain(tenantInfo.getTenantDomain());
- carbonContext.setTenantId(tenantInfo.getTenantId());
- //Get tenant UserRealm & UserStoreManager
- UserRealm userRealm = DataHolder.getRealmService().getTenantUserRealm(tenantInfo.getTenantId());
- UserStoreManager userStoreManager = userRealm.getUserStoreManager();
- //Call Util class to create the user role
-
- UserRoleCreator.createTenantUserRole(userStoreManager);
-
- } catch (UserStoreException e) {
- String msg = "Error while retrieving the user store for tenant: "+ tenantInfo.getTenantDomain();
- log.error(msg, e);
- throw new ApacheStratosException(e.getMessage(), e);
- } catch (UserManagerException e) {
- String msg = "Error while creating the user role in tenant: "+ tenantInfo.getTenantDomain();
- log.error(msg, e);
- throw new ApacheStratosException(e.getMessage(), e);
- } finally {
- PrivilegedCarbonContext.endTenantFlow();
- }
-
- }
-
-
- @Override
- public void onTenantUpdate(TenantInfoBean tenantInfo) throws ApacheStratosException {
-
- }
-
- @Override
- public void onTenantDelete(int tenantId) {
-
- }
-
- @Override
- public void onTenantRename(int tenantId, String oldDomainName, String newDomainName)
- throws ApacheStratosException {
-
- }
-
- @Override
- public void onTenantInitialActivation(int tenantId) throws ApacheStratosException {
-
- }
-
- @Override
- public void onTenantActivation(int tenantId) throws ApacheStratosException {
-
- }
-
- @Override
- public void onTenantDeactivation(int tenantId) throws ApacheStratosException {
-
- }
-
- @Override
- public void onSubscriptionPlanChange(int tenentId, String oldPlan, String newPlan)
- throws ApacheStratosException {
-
- }
-
- @Override
- public int getListenerOrder() {
- return 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/ClusterIdToSubscription.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/ClusterIdToSubscription.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/ClusterIdToSubscription.java
deleted file mode 100644
index a994a73..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/ClusterIdToSubscription.java
+++ /dev/null
@@ -1,102 +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.lookup;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.subscription.CartridgeSubscription;
-
-import java.io.Serializable;
-import java.util.*;
-
-public class ClusterIdToSubscription implements Serializable {
-
- private static final Log log = LogFactory.getLog(ClusterIdToSubscription.class);
-
- // Map: Cluster Id (Domain) -> Set<CartridgeSubscription>
- private Map<String, Set<CartridgeSubscription>> clusterIdToCartridgeSubscription;
-
- public ClusterIdToSubscription() {
- clusterIdToCartridgeSubscription = new HashMap<String, Set<CartridgeSubscription>>();
- }
-
- public void addSubscription (CartridgeSubscription cartridgeSubscription) {
-
- //clusterIdToCartridgeSubscription.put(cartridgeSubscription.getClusterDomain(), cartridgeSubscription);
- String clusterDomain = cartridgeSubscription.getClusterDomain();
- if (clusterIdToCartridgeSubscription.containsKey(clusterDomain)) {
- Set<CartridgeSubscription> existingSubscriptions = clusterIdToCartridgeSubscription.get(clusterDomain);
- // if an existing subscription is present, remove it
- if(existingSubscriptions.remove(cartridgeSubscription)){
- if(log.isDebugEnabled()) {
- log.debug("Removed the existing Cartridge Subscription for cluster id " + clusterDomain + " in [Cluster Id -> Set<CartridgeSubscription>] map");
- }
- }
- // add or update
- existingSubscriptions.add(cartridgeSubscription);
- if(log.isDebugEnabled()) {
- log.debug("Added Cartridge Subscription for cluster id " + clusterDomain + " in [Cluster Id -> Set<CartridgeSubscription>] map");
- }
-
- } else {
- // create a new set and add it
- Set<CartridgeSubscription> subscriptions = new HashSet<CartridgeSubscription>();
- subscriptions.add(cartridgeSubscription);
- clusterIdToCartridgeSubscription.put(clusterDomain, subscriptions);
- if(log.isDebugEnabled()) {
- log.debug("Added Cartridge Subscription for cluster id " + clusterDomain + " in [Cluster Id -> Set<CartridgeSubscription>] map");
- }
- }
- }
-
- public Set<CartridgeSubscription> getSubscription (String clusterId) {
-
- return clusterIdToCartridgeSubscription.get(clusterId);
- }
-
- public void removeSubscription (String clusterId, String subscriptionAlias) {
-
- // remove Subscription from clusterIdToCartridgeSubscription map
- Set<CartridgeSubscription> existingSubscriptions = clusterIdToCartridgeSubscription.get(clusterId);
- if (existingSubscriptions != null && !existingSubscriptions.isEmpty()) {
- // iterate through the set
- Iterator<CartridgeSubscription> iterator = existingSubscriptions.iterator();
- while (iterator.hasNext()) {
- CartridgeSubscription cartridgeSubscription = iterator.next();
- // if a matching CartridgeSubscription is found, remove
- if (cartridgeSubscription.getAlias().equals(subscriptionAlias)) {
- iterator.remove();
- if (log.isDebugEnabled()) {
- log.debug("Deleted the subscription for cluster id " + clusterId + " from [Cluster Id -> Set<CartridgeSubscription>] map");
- }
- break;
- }
- }
- }
-
- // if the Subscriptions set is empty now, remove it from cartridgeTypeToSubscriptions map
- if (existingSubscriptions == null || existingSubscriptions.isEmpty()) {
- clusterIdToCartridgeSubscription.remove(clusterId);
- if (log.isDebugEnabled()) {
- log.debug("Deleted the subscriptions set for cluster id " + clusterId + " from [Cluster Id -> Set<CartridgeSubscription>] map");
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/LookupDataHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/LookupDataHolder.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/LookupDataHolder.java
deleted file mode 100644
index de66815..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/LookupDataHolder.java
+++ /dev/null
@@ -1,210 +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.lookup;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.subscription.CartridgeSubscription;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Set;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-public class LookupDataHolder implements Serializable {
-
- private static final Log log = LogFactory.getLog(LookupDataHolder.class);
-
- private ClusterIdToSubscription clusterIdToSubscription;
- private TenantIdToSubscriptionContext tenantIdToSubscriptionContext;
- private RepoUrlToCartridgeSubscriptions repoUrlToCartridgeSubscriptions;
- private static volatile LookupDataHolder lookupDataHolder;
-
- //locks
- private static volatile ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
- private static volatile ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
- private static volatile ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
-
- private LookupDataHolder () {
- clusterIdToSubscription = new ClusterIdToSubscription();
- tenantIdToSubscriptionContext = new TenantIdToSubscriptionContext();
- repoUrlToCartridgeSubscriptions = new RepoUrlToCartridgeSubscriptions();
- }
-
- public static LookupDataHolder getInstance () {
-
- if (lookupDataHolder == null) {
- synchronized (LookupDataHolder.class) {
- if (lookupDataHolder == null) {
- lookupDataHolder = new LookupDataHolder();
- }
- }
- }
- return lookupDataHolder;
- }
-
- public void putSubscription (CartridgeSubscription cartridgeSubscription) {
-
- // add or update
- clusterIdToSubscription.addSubscription(cartridgeSubscription);
-
- repoUrlToCartridgeSubscriptions.addSubscription(cartridgeSubscription);
-
- // check if an existing SubscriptionContext is available
- SubscriptionContext existingSubscriptionCtx = tenantIdToSubscriptionContext.getSubscriptionContext(cartridgeSubscription.getSubscriber().getTenantId());
- if(existingSubscriptionCtx != null) {
- if (log.isDebugEnabled()) {
- log.debug("Existing SubscriptionContext found for tenant " + cartridgeSubscription.getSubscriber().getTenantId());
- }
- existingSubscriptionCtx.addSubscription(cartridgeSubscription);
-
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Existing SubscriptionContext not found for tenant " + cartridgeSubscription.getSubscriber().getTenantId());
- }
- //create a new subscription context and add the subscription
- SubscriptionContext subscriptionContext = new SubscriptionContext();
- subscriptionContext.addSubscription(cartridgeSubscription);
- tenantIdToSubscriptionContext.addSubscriptionContext(cartridgeSubscription.getSubscriber().getTenantId(), subscriptionContext);
- }
-
- }
-
- public void removeSubscription (int tenantId, String type, String subscriptionAlias, String clusterId, String repoUrl) {
-
- tenantIdToSubscriptionContext.removeSubscriptionContext(tenantId, type, subscriptionAlias);
- clusterIdToSubscription.removeSubscription(clusterId, subscriptionAlias);
- repoUrlToCartridgeSubscriptions.removeSubscription(repoUrl, subscriptionAlias);
- }
-
- public Collection<CartridgeSubscription> getSubscriptions (String cartridgeType) {
-
- Collection<SubscriptionContext> subscriptionContexts = tenantIdToSubscriptionContext.getSubscriptionContexts();
- if (subscriptionContexts == null) {
- // no subscriptions
- return null;
- }
-
- Collection<CartridgeSubscription> cartridgeSubscriptions = new ArrayList<CartridgeSubscription>();
- // iterate through the SubscriptionContexts
- for (SubscriptionContext subscriptionContext : subscriptionContexts) {
- // check if CartridgeSubscriptions exist for the given type, in each SubscriptionContext instance
- Collection<CartridgeSubscription> cartridgeSubscriptionsOfType = subscriptionContext.getSubscriptionsOfType(cartridgeType);
- if (cartridgeSubscriptionsOfType != null && !cartridgeSubscriptionsOfType.isEmpty()) {
- // collect the relevant CartridgeSubscriptions
- cartridgeSubscriptions.addAll(cartridgeSubscriptionsOfType);
- }
- }
-
- return cartridgeSubscriptions;
- }
-
- public Collection<CartridgeSubscription> getSubscriptions (int tenantId) {
-
- SubscriptionContext subscriptionContext = tenantIdToSubscriptionContext.getSubscriptionContext(tenantId);
- if (subscriptionContext == null) {
- // no subscriptions
- return null;
- }
-
- return subscriptionContext.getSubscriptions();
-
- }
-
- public CartridgeSubscription getSubscriptionForAlias (String subscriptionAlias) {
-
- Collection<SubscriptionContext> subscriptionContexts = tenantIdToSubscriptionContext.getSubscriptionContexts();
- if (subscriptionContexts == null) {
- // no subscriptions
- return null;
- }
-
- CartridgeSubscription cartridgeSubscription;
-
- for (SubscriptionContext subscriptionContext : subscriptionContexts) {
- cartridgeSubscription = subscriptionContext.getSubscriptionForAlias(subscriptionAlias);
- // check if the retrieved subscription is not null and return
- if (cartridgeSubscription != null) {
- return cartridgeSubscription;
- }
- }
-
- return null;
- }
-
- public Collection<CartridgeSubscription> getSubscriptionForType (int tenantId, String cartridgeType) {
-
- SubscriptionContext subscriptionContext = tenantIdToSubscriptionContext.getSubscriptionContext(tenantId);
- if (subscriptionContext == null) {
- // no subscriptions
- return null;
- }
-
- return subscriptionContext.getSubscriptionsOfType(cartridgeType);
- }
-
- public CartridgeSubscription getSubscriptionForAlias (int tenantId, String subscriptionAlias) {
-
- SubscriptionContext subscriptionContext = tenantIdToSubscriptionContext.getSubscriptionContext(tenantId);
- if (subscriptionContext == null) {
- // no subscriptions
- if (log.isDebugEnabled()) {
- log.debug("No SubscriptionContext found for tenant " + tenantId + ", subscription alias " + subscriptionAlias);
- }
- return null;
- }
-
- return subscriptionContext.getSubscriptionForAlias(subscriptionAlias);
-
- }
-
- public Set<CartridgeSubscription> getSubscription (String clusterId) {
-
- return clusterIdToSubscription.getSubscription(clusterId);
-
- }
-
- public Set<CartridgeSubscription> getSubscriptionsForRepoUrl (String repoUrl) {
-
- return repoUrlToCartridgeSubscriptions.getSubscriptions(repoUrl);
-
- }
-
- public void acquireWriteLock () {
-
- writeLock.lock();
- }
-
- public void releaseWriteLock () {
-
- writeLock.unlock();
- }
-
- public void acquireReadLock () {
-
- readLock.lock();
- }
-
- public void releaseReadLock () {
-
- readLock.unlock();
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/RepoUrlToCartridgeSubscriptions.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/RepoUrlToCartridgeSubscriptions.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/RepoUrlToCartridgeSubscriptions.java
deleted file mode 100644
index d0d7396..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/RepoUrlToCartridgeSubscriptions.java
+++ /dev/null
@@ -1,116 +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.lookup;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.subscription.CartridgeSubscription;
-
-import java.util.*;
-
-public class RepoUrlToCartridgeSubscriptions {
-
- private static final Log log = LogFactory.getLog(RepoUrlToCartridgeSubscriptions.class);
-
- // Map: Repository URL -> Set<CartridgeSubscription>
- private Map<String, Set<CartridgeSubscription>> repoUrlToCartridgeSubscriptions;
-
- public RepoUrlToCartridgeSubscriptions() {
- repoUrlToCartridgeSubscriptions = new HashMap<String, Set<CartridgeSubscription>>();
- }
-
- public void addSubscription (CartridgeSubscription cartridgeSubscription) {
-
- if (cartridgeSubscription.getRepository() == null) {
- if (log.isDebugEnabled()) {
- log.debug("No repository URL found for Cartridge Subscription for alias " + cartridgeSubscription.getAlias() +
- ", not adding to [Repo URL -> Set<CartridgeSubscription>] map");
- }
- return;
- }
-
- String repoUrl = cartridgeSubscription.getRepository().getUrl();
-
- if (repoUrlToCartridgeSubscriptions.containsKey(repoUrl)) {
- Set<CartridgeSubscription> existingSubscriptions = repoUrlToCartridgeSubscriptions.get(repoUrl);
- // if an existing subscription is present, remove it
- if(existingSubscriptions.remove(cartridgeSubscription)){
- if(log.isDebugEnabled()) {
- log.debug("Removed the existing Cartridge Subscription for repo URL " + repoUrl + " in [Repo URL -> Set<CartridgeSubscription>] map");
- }
- }
- // add or update
- existingSubscriptions.add(cartridgeSubscription);
- if(log.isDebugEnabled()) {
- log.debug("Added Cartridge Subscription for repo URL " + repoUrl + " in [Repo URL -> Set<CartridgeSubscription>] map");
- }
-
- } else {
- // create a new set and add it
- Set<CartridgeSubscription> subscriptions = new HashSet<CartridgeSubscription>();
- subscriptions.add(cartridgeSubscription);
- repoUrlToCartridgeSubscriptions.put(repoUrl, subscriptions);
- if(log.isDebugEnabled()) {
- log.debug("Added Cartridge Subscription for repo URL " + repoUrl + " in [Repo URL -> Set<CartridgeSubscription>] map");
- }
- }
- }
-
- public Set<CartridgeSubscription> getSubscriptions(String repoUrl) {
-
- return repoUrlToCartridgeSubscriptions.get(repoUrl);
- }
-
- public void removeSubscription (String repoUrl, String subscriptionAlias) {
-
- if (repoUrl == null) {
- if (log.isDebugEnabled()) {
- log.debug("Repository URL is null for subscription alias " + subscriptionAlias);
- }
- return;
- }
-
- // remove Subscription from repoUrlToCartridgeSubscriptions map
- Set<CartridgeSubscription> existingSubscriptions = repoUrlToCartridgeSubscriptions.get(repoUrl);
- if (existingSubscriptions != null && !existingSubscriptions.isEmpty()) {
- // iterate through the set
- Iterator<CartridgeSubscription> iterator = existingSubscriptions.iterator();
- while (iterator.hasNext()) {
- CartridgeSubscription cartridgeSubscription = iterator.next();
- // if a matching CartridgeSubscription is found, remove
- if (cartridgeSubscription.getAlias().equals(subscriptionAlias)) {
- iterator.remove();
- if (log.isDebugEnabled()) {
- log.debug("Deleted the subscription for repo URL " + repoUrl + " from [Repo URL -> Set<CartridgeSubscription>] map");
- }
- break;
- }
- }
- }
-
- // if the Subscriptions set is empty now, remove it from cartridgeTypeToSubscriptions map
- if (existingSubscriptions == null || existingSubscriptions.isEmpty()) {
- repoUrlToCartridgeSubscriptions.remove(repoUrl);
- if (log.isDebugEnabled()) {
- log.debug("Deleted the subscriptions set for repo URL " + repoUrl + " from [Repo URL -> Set<CartridgeSubscription>] map");
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/SubscriptionContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/SubscriptionContext.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/SubscriptionContext.java
deleted file mode 100644
index 61e6ed6..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/SubscriptionContext.java
+++ /dev/null
@@ -1,138 +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.lookup;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.manager.subscription.CartridgeSubscription;
-
-import java.io.Serializable;
-import java.util.*;
-
-public class SubscriptionContext implements Serializable {
-
- private static final Log log = LogFactory.getLog(SubscriptionContext.class);
-
- // Map: Cartridge Type -> Set<CartridgeSubscription>
- private Map<String, Set<CartridgeSubscription>> cartridgeTypeToSubscriptions;
-
- // Map: Subscription Alias -> CartridgeSubscription
- private Map<String, CartridgeSubscription> aliasToSubscription;
-
- public SubscriptionContext () {
-
- cartridgeTypeToSubscriptions = new HashMap<String, Set<CartridgeSubscription>>();
- aliasToSubscription = new HashMap<String, CartridgeSubscription>();
- }
-
- public void addSubscription (CartridgeSubscription cartridgeSubscription) {
-
- String cartridgeType = cartridgeSubscription.getType();
- if (cartridgeTypeToSubscriptions.containsKey(cartridgeType)) {
- Set<CartridgeSubscription> existingSubscriptions = cartridgeTypeToSubscriptions.get(cartridgeType);
- // if an existing subscription is present, remove it
- if(existingSubscriptions.remove(cartridgeSubscription)){
- if(log.isDebugEnabled()) {
- log.debug("Removed the existing Cartridge Subscription for type " + cartridgeType + ", alias " + cartridgeSubscription.getAlias() +
- " in [Cartridge Type -> Set<CartridgeSubscription>] map");
- }
- }
- // add or update
- existingSubscriptions.add(cartridgeSubscription);
- if(log.isDebugEnabled()) {
- log.debug("Added Cartridge Subscription for type " + cartridgeType + ", alias " + cartridgeSubscription.getAlias() +
- " in [Cartridge Type -> Set<CartridgeSubscription>] map");
- }
-
- } else {
- // create a new set and add it
- Set<CartridgeSubscription> subscriptions = new HashSet<CartridgeSubscription>();
- subscriptions.add(cartridgeSubscription);
- cartridgeTypeToSubscriptions.put(cartridgeType, subscriptions);
- }
-
- // put Subscription to aliasToSubscription map
- if (aliasToSubscription.put(cartridgeSubscription.getAlias(), cartridgeSubscription) != null) {
- if(log.isDebugEnabled()) {
- log.debug("Overwrote the existing Cartridge Subscription for alias " + cartridgeSubscription.getAlias() +
- " in [Subscription Alias -> CartridgeSubscription] map");
- }
- }
- }
-
- public Collection<CartridgeSubscription> getSubscriptions () {
-
- return aliasToSubscription.values();
- }
-
- public Collection<CartridgeSubscription> getSubscriptionsOfType (String cartridgeType) {
-
- return cartridgeTypeToSubscriptions.get(cartridgeType);
- }
-
-
-
- public CartridgeSubscription getSubscriptionForAlias (String subscriptionAlias) {
-
- return aliasToSubscription.get(subscriptionAlias);
- }
-
- public void deleteSubscription (String type, String subscriptionAlias) {
-
- // remove Subscription from cartridgeTypeToSubscriptions map
- Set<CartridgeSubscription> existingSubscriptions = cartridgeTypeToSubscriptions.get(type);
- if (existingSubscriptions != null && !existingSubscriptions.isEmpty()) {
- // iterate through the set
- Iterator<CartridgeSubscription> iterator = existingSubscriptions.iterator();
- while (iterator.hasNext()) {
- CartridgeSubscription cartridgeSubscription = iterator.next();
- // if a matching CartridgeSubscription is found, remove
- if (cartridgeSubscription.getAlias().equals(subscriptionAlias)) {
- iterator.remove();
- if (log.isDebugEnabled()) {
- log.debug("Deleted the subscription for alias " + subscriptionAlias + " and type " + type + " from [Type -> Set<CartridgeSubscription>] map");
- }
- break;
- }
- }
- }
-
- // if the Subscriptions set is empty now, remove it from cartridgeTypeToSubscriptions map
- if (existingSubscriptions == null || existingSubscriptions.isEmpty()) {
- cartridgeTypeToSubscriptions.remove(type);
- if (log.isDebugEnabled()) {
- log.debug("Deleted the subscriptions set for type " + type + " from [Type -> Set<CartridgeSubscription>] map");
- }
- }
-
- // remove from aliasToSubscription map
- if (aliasToSubscription.remove(subscriptionAlias) != null) {
- if (log.isDebugEnabled()) {
- log.debug("Deleted the subscription for alias " + subscriptionAlias + " from [Alias -> CartridgeSubscription] map");
- }
- }
- }
-
- public boolean isEmpty () {
-
- return cartridgeTypeToSubscriptions.isEmpty() && aliasToSubscription.isEmpty();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/TenantIdToSubscriptionContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/TenantIdToSubscriptionContext.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/TenantIdToSubscriptionContext.java
deleted file mode 100644
index 0912d83..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/lookup/TenantIdToSubscriptionContext.java
+++ /dev/null
@@ -1,70 +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.lookup;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-public class TenantIdToSubscriptionContext {
-
- private static final Log log = LogFactory.getLog(TenantIdToSubscriptionContext.class);
-
- // Map: tenant Id -> SubscriptionContext
- private Map<Integer, SubscriptionContext> tenantIdToSubscriptionContext;
-
- public TenantIdToSubscriptionContext() {
- tenantIdToSubscriptionContext = new HashMap<Integer, SubscriptionContext>();
- }
-
- public Collection<SubscriptionContext> getSubscriptionContexts () {
-
- return tenantIdToSubscriptionContext.values();
- }
-
- public SubscriptionContext getSubscriptionContext (int tenantId) {
-
- return tenantIdToSubscriptionContext.get(tenantId);
- }
-
- public void addSubscriptionContext (int tenantId, SubscriptionContext subscriptionContext) {
-
- tenantIdToSubscriptionContext.put(tenantId, subscriptionContext);
- }
-
- public void removeSubscriptionContext (int tenantId, String type, String subscriptionAlias) {
-
- if (tenantIdToSubscriptionContext.containsKey(tenantId)) {
- SubscriptionContext subscriptionContext = tenantIdToSubscriptionContext.get(tenantId);
- subscriptionContext.deleteSubscription(type, subscriptionAlias);
-
- // delete the SubscriptionContext instance for the tenant if it carries no information
- if (subscriptionContext.isEmpty()) {
- tenantIdToSubscriptionContext.remove(tenantId);
- if (log.isDebugEnabled()) {
- log.debug("Deleted the subscriptionContext instance for tenant " + tenantId);
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/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
deleted file mode 100644
index d2a92e1..0000000
--- a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
+++ /dev/null
@@ -1,803 +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.manager;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.stub.domain.CartridgeInfo;
-import org.apache.stratos.cloud.controller.stub.domain.Persistence;
-import org.apache.stratos.cloud.controller.stub.CloudControllerServiceCartridgeNotFoundExceptionException;
-import org.apache.stratos.common.Properties;
-import org.apache.stratos.common.Property;
-import org.apache.stratos.manager.client.CloudControllerServiceClient;
-import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
-import org.apache.stratos.manager.deploy.service.Service;
-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.lb.category.*;
-import org.apache.stratos.manager.repository.Repository;
-import org.apache.stratos.manager.retriever.DataInsertionAndRetrievalManager;
-import org.apache.stratos.manager.subscriber.Subscriber;
-import org.apache.stratos.manager.subscription.*;
-import org.apache.stratos.manager.subscription.factory.CartridgeSubscriptionFactory;
-import org.apache.stratos.manager.subscription.filter.LBCreationSubscriptionFilter;
-import org.apache.stratos.manager.subscription.filter.SubscriptionFilter;
-import org.apache.stratos.manager.subscription.tenancy.SubscriptionMultiTenantBehaviour;
-import org.apache.stratos.manager.subscription.tenancy.SubscriptionSingleTenantBehaviour;
-import org.apache.stratos.manager.subscription.tenancy.SubscriptionTenancyBehaviour;
-import org.apache.stratos.manager.subscription.utils.CartridgeSubscriptionUtils;
-import org.apache.stratos.manager.topology.model.TopologyClusterInformationModel;
-import org.apache.stratos.manager.utils.ApplicationManagementUtil;
-import org.apache.stratos.manager.utils.CartridgeConstants;
-import org.apache.stratos.manager.utils.RepoPasswordMgtUtil;
-import org.apache.stratos.messaging.broker.publish.EventPublisher;
-import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.Member;
-import org.apache.stratos.messaging.event.tenant.SubscriptionDomainAddedEvent;
-import org.apache.stratos.messaging.event.tenant.SubscriptionDomainRemovedEvent;
-import org.apache.stratos.messaging.util.Util;
-import org.wso2.carbon.context.CarbonContext;
-import org.apache.stratos.manager.publisher.CartridgeSubscriptionDataPublisher;
-
-import java.util.*;
-
-
-/**
- * Manager class for the purpose of managing CartridgeSubscriptionInfo subscriptions, groupings, etc.
- */
-public class CartridgeSubscriptionManager {
-
- private static Log log = LogFactory.getLog(CartridgeSubscriptionManager.class);
- //private static DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
-
- public GroupSubscription createGroupSubscription (String groupName, String groupAlias, int tenantId)
- throws GroupSubscriptionException {
-
- DataInsertionAndRetrievalManager dataInsertionAndRetrievalMgr = new DataInsertionAndRetrievalManager();
- GroupSubscription groupSubscription;
-
- try {
- groupSubscription = dataInsertionAndRetrievalMgr.getGroupSubscription(tenantId, groupName, groupAlias);
-
- } catch (PersistenceManagerException e) {
- throw new GroupSubscriptionException(e);
- }
-
- if (groupSubscription != null) {
- // Group Subscription already exists with same Group name and alias
- throw new GroupSubscriptionException("Group Subscription already exists with name [ " + groupName + " ], alias [ " + groupAlias + " ]");
- }
-
- return new GroupSubscription(groupName, groupAlias);
- }
-
- public ApplicationSubscription createApplicationSubscription (String appId, int tenantId) throws ApplicationSubscriptionException {
-
- if (log.isDebugEnabled()) {
- log.debug("create Application Subscription for appId: " + appId + " and tenantId: " + tenantId);
- }
-
- DataInsertionAndRetrievalManager dataInsertionAndRetrievalMgr = new DataInsertionAndRetrievalManager();
- ApplicationSubscription appSubscription;
-
- try {
- appSubscription = dataInsertionAndRetrievalMgr.getApplicationSubscription(tenantId, appId);
-
- } catch (PersistenceManagerException e) {
- log.error("failed to retrieve application Subscription for appId: " + appId + " and tenantId: " + tenantId + " e:" + e);
- throw new ApplicationSubscriptionException(e);
- }
-
- if (appSubscription != null) {
- // Composite App Subscription already exists with same app id
- log.error("app Id already exists, failed to createappSubscription for appId: " + appId + " and tenantId: " + tenantId);
- throw new ApplicationSubscriptionException("Composite App Subscription already exists with Id [ " + appId + " ]");
- } else {
-
- if (log.isDebugEnabled()) {
- log.debug("creating new application subscription for app:" + appId );
- }
-
- appSubscription = new ApplicationSubscription(appId);
- // persist
- try {
- this.persistApplicationSubscription(appSubscription);
- } catch (ADCException e) {
- // TODO Auto-generated catch block
- log.error("Failed to persist applicaiton subscription for appId: " + appId +
- " and tenantId: " + tenantId + " e:" + e);
- }
- }
-
- return new ApplicationSubscription(appId);
- }
-
- public void removeApplicationSubscription (String appId, int tenantId) throws ApplicationSubscriptionException {
-
- if (log.isDebugEnabled()) {
- log.debug("remove Application Subscription for appId: " + appId + " and tenantId: " + tenantId);
- }
-
- DataInsertionAndRetrievalManager dataInsertionAndRetrievalMgr = new DataInsertionAndRetrievalManager();
- ApplicationSubscription appSubscription = null;
-
- try {
- appSubscription = dataInsertionAndRetrievalMgr.getApplicationSubscription(tenantId, appId);
-
- } catch (PersistenceManagerException e) {
- log.error("failed to retrieve Application Subscription for appId: " + appId + " and tenantId: " + tenantId + "with exception:" + e);
- throw new ApplicationSubscriptionException(e);
- }
-
- if (appSubscription != null) {
-
- try {
- dataInsertionAndRetrievalMgr.removeApplicationSubscription(tenantId, appId);
- } catch (PersistenceManagerException e) {
- log.error("failed to remove Application Subscription for appId: " + appId + " and tenantId: " + tenantId + " with exception:" + e);
- throw new ApplicationSubscriptionException(e);
- }
-
- if (log.isDebugEnabled()) {
- log.debug("successfully removed Application Subscription for appId: " + appId + " and tenantId: " + tenantId);
- }
-
- }
- }
-
- public ApplicationSubscription getApplicationSubscription (String appId, int tenantId) throws ApplicationSubscriptionException {
- if (log.isDebugEnabled()) {
- log.debug("get Application Subscription for appId: " + appId + " and tenantId: " + tenantId);
- }
-
- DataInsertionAndRetrievalManager dataInsertionAndRetrievalMgr = new DataInsertionAndRetrievalManager();
- ApplicationSubscription appSubscription = null;
-
- try {
- appSubscription = dataInsertionAndRetrievalMgr.getApplicationSubscription(tenantId, appId);
-
- } catch (PersistenceManagerException e) {
- log.error("failed to Application Subscription for appId: " + appId + " and tenantId: " + tenantId + " e:" + e);
- throw new ApplicationSubscriptionException(e);
- }
-
- return appSubscription;
- }
-
- public CartridgeSubscription createCartridgeSubscription (SubscriptionData subscriptionData) throws ADCException,
- InvalidCartridgeAliasException, DuplicateCartridgeAliasException, PolicyException, UnregisteredCartridgeException,
- RepositoryRequiredException, RepositoryCredentialsRequiredException, RepositoryTransportException,
- AlreadySubscribedException, InvalidRepositoryException {
-
-
- CartridgeSubscriptionUtils.validateCartridgeAlias(subscriptionData.getTenantId(), subscriptionData.getCartridgeType(), subscriptionData.getCartridgeAlias());
-
- CartridgeInfo cartridgeInfo;
- try {
- cartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(subscriptionData.getCartridgeType());
-
- } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
- String message = subscriptionData.getCartridgeType() + " is not a valid cartridgeSubscription type. Please try again with a valid cartridgeSubscription type.";
- log.error(message);
- throw new ADCException(message, e);
-
- } catch (Exception e) {
- String message = "Error getting info for " + subscriptionData.getCartridgeType();
- log.error(message, e);
- throw new ADCException(message, e);
- }
-
- // subscribe to relevant service cartridge
- CartridgeSubscription serviceCartridgeSubscription = subscribe (subscriptionData, cartridgeInfo, null);
-
- return serviceCartridgeSubscription;
- }
-
- public void persistCartridgeSubscription (CartridgeSubscription cartridgeSubscription) throws ADCException {
-
- try {
- new DataInsertionAndRetrievalManager().cacheAndPersistSubcription(cartridgeSubscription);
-
- } catch (PersistenceManagerException e) {
- String errorMsg = "Error saving subscription for tenant " +
- cartridgeSubscription.getSubscriber().getTenantDomain() + ", alias " + cartridgeSubscription.getType();
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
-
- log.info("Successful Subscription: " + cartridgeSubscription.toString());
-
- // Publish tenant subscribed event to message broker
- Set<String> clusterIds = new HashSet<String>();
- clusterIds.add(cartridgeSubscription.getCluster().getClusterDomain());
- CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
- cartridgeSubscription.getCartridgeInfo().getType(), clusterIds);
- }
-
- public void persistGroupSubscription (GroupSubscription groupSubscription) throws ADCException {
-
- try {
- new DataInsertionAndRetrievalManager().persistGroupSubscription(groupSubscription);
-
- } catch (PersistenceManagerException e) {
- throw new ADCException(e);
- }
- }
-
- public void persistApplicationSubscription (ApplicationSubscription compositeAppSubscription) throws ADCException {
-
- try {
- new DataInsertionAndRetrievalManager().persistApplicationSubscription(compositeAppSubscription);
-
- } catch (PersistenceManagerException e) {
- throw new ADCException(e);
- }
- }
-
- /**
- *
- * @param subscriptionData
- * @return
- * @throws Exception since the caller doesn't react upon specific exceptions, simply throw Generic Exception class.
- */
- public static SubscriptionInfo subscribeToCartridgeWithProperties(SubscriptionData subscriptionData) throws Exception {
-
- // validate cartridge alias
- CartridgeSubscriptionUtils.validateCartridgeAlias(subscriptionData.getTenantId(), subscriptionData.getCartridgeType(), subscriptionData.getCartridgeAlias());
-
- CartridgeInfo cartridgeInfo;
- try {
- cartridgeInfo = CloudControllerServiceClient.getServiceClient().getCartridgeInfo(subscriptionData.getCartridgeType());
-
- } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
- String message = subscriptionData.getCartridgeType() + " is not a valid cartridgeSubscription type. Please try again with a valid cartridgeSubscription type.";
- log.error(message);
- throw new ADCException(message, e);
-
- } catch (Exception e) {
- String message = "Error getting info for " + subscriptionData.getCartridgeType();
- log.error(message, e);
- throw new ADCException(message, e);
- }
-
- // For MT subscriptions check whether there are active instances
- if(cartridgeInfo.getMultiTenant() && !activeInstancesAvailable(subscriptionData)) {
- String msg = "No active instances are found for cartridge [" + subscriptionData.getCartridgeType() + "]";
- log.error(msg);
- throw new ADCException(msg);
- }
-
- // check if this subscription requires Persistence Mapping, and its supported by the cartridge definition
- Properties persistenceMappingProperties = null;
- if (subscriptionData.getPersistanceContext() != null) {
- persistenceMappingProperties = getPersistenceMappingProperties(subscriptionData.getPersistanceContext(), cartridgeInfo);
- }
-
- Properties serviceCartridgeSubscriptionProperties = null;
- Properties propertiesReturnedByFilters = new Properties();
-
- List<SubscriptionFilter> subscriptionFilters = new ArrayList<SubscriptionFilter>();
- subscriptionFilters.add(new LBCreationSubscriptionFilter());
-
- for (SubscriptionFilter subscriptionFilter : subscriptionFilters) {
- // execute filters
- appendProperties(propertiesReturnedByFilters, subscriptionFilter.execute(cartridgeInfo, subscriptionData));
-
- }
-
- // subscribe to relevant service cartridge
- CartridgeSubscription serviceCartridgeSubscription = subscribe (subscriptionData, cartridgeInfo, getLBClusterId(propertiesReturnedByFilters));
-
- if (subscriptionData.getProperties() != null) {
- serviceCartridgeSubscriptionProperties = subscriptionData.getProperties();
- } else {
-
- serviceCartridgeSubscriptionProperties = new Properties();
- }
-
- // add properties returned by filters
- if (propertiesReturnedByFilters.getProperties() != null && propertiesReturnedByFilters.getProperties().length > 0) {
- for (Property prop : propertiesReturnedByFilters.getProperties()) {
-
- serviceCartridgeSubscriptionProperties.addProperty(prop);
- }
- }
-
- // Persistence Mapping related properties
- if (persistenceMappingProperties != null && persistenceMappingProperties.getProperties().length > 0) {
- // add the properties to send to CC via register method
- for (Property persistenceMappingProperty : persistenceMappingProperties.getProperties()) {
- serviceCartridgeSubscriptionProperties.addProperty(persistenceMappingProperty);
- }
- }
-
- // register service cartridge subscription
- return registerCartridgeSubscription(serviceCartridgeSubscription, serviceCartridgeSubscriptionProperties, subscriptionData.getPersistence());
- }
-
- private static String getLBClusterId(Properties propertiesReturnedByFilters) {
- if (propertiesReturnedByFilters != null
- && propertiesReturnedByFilters.getProperties() != null) {
- for (Property prop : propertiesReturnedByFilters.getProperties()) {
- if (prop == null) {
- continue;
- }
- if (prop.getName().equals(CartridgeConstants.LB_CLUSTER_ID)) {
- return String.valueOf(prop.getValue());
- }
- }
- }
- return null;
- }
-
- private static void appendProperties(
- Properties propertiesReturnedByFilters, Properties newProperties) {
-
- if (newProperties.getProperties() == null) {
- return;
- }
- for (Property property : newProperties.getProperties()) {
- if (property != null) {
-
- propertiesReturnedByFilters.addProperty(property);
- }
- }
-
- }
-
- private static boolean activeInstancesAvailable(SubscriptionData subscriptionData) {
- Cluster cluster = TopologyClusterInformationModel.getInstance().getCluster(subscriptionData.getCartridgeType());
- if(cluster != null) {
- Collection<Member> members = cluster.getMembers();
- for (Member member : members) {
- if(member.isActive()) {
- if(log.isDebugEnabled()) {
- log.debug("Active member found for cluster [" + cluster +"]");
- }
- return true;
- }
- }
- }
- if(log.isDebugEnabled()) {
- log.debug("Active member not found for cluster [" + cluster +"]");
- }
- return false;
- }
-
-
-
- private static CartridgeSubscription subscribe (SubscriptionData subscriptionData, CartridgeInfo cartridgeInfo, String lbClusterId)
-
- throws ADCException, InvalidCartridgeAliasException,
- DuplicateCartridgeAliasException, PolicyException, UnregisteredCartridgeException, RepositoryRequiredException, RepositoryCredentialsRequiredException,
- RepositoryTransportException, AlreadySubscribedException, InvalidRepositoryException {
-
-
- // Decide tenancy behaviour
- SubscriptionTenancyBehaviour tenancyBehaviour;
- if(cartridgeInfo.getMultiTenant()) {
- tenancyBehaviour = new SubscriptionMultiTenantBehaviour();
- } else {
- tenancyBehaviour = new SubscriptionSingleTenantBehaviour();
- }
-
- // Create the CartridgeSubscription instance
- CartridgeSubscription cartridgeSubscription = CartridgeSubscriptionFactory.getCartridgeSubscriptionInstance(cartridgeInfo, tenancyBehaviour);
-
-
- // For MT cartridges subscription key should not be generated for every subscription,
- // instead use the already generated key at the time of service deployment
- String subscriptionKey = null;
- if(cartridgeInfo.getMultiTenant()) {
- try {
- Service service = new DataInsertionAndRetrievalManager().getService(subscriptionData.getCartridgeType());
- if(service != null) {
- subscriptionKey = service.getSubscriptionKey();
- }else {
- String msg = "Could not find service for cartridge type [" + subscriptionData.getCartridgeType() + "] " ;
- log.error(msg);
- throw new ADCException(msg);
- }
- } catch (Exception e) {
- String msg = "Exception has occurred in get service for cartridge type [" + subscriptionData.getCartridgeType() + "] " ;
- log.error(msg);
- throw new ADCException(msg, e);
- }
- }else {
- // Generate and set the key
- subscriptionKey = CartridgeSubscriptionUtils.generateSubscriptionKey();
-
- }
-
- cartridgeSubscription.setSubscriptionKey(subscriptionKey);
-
- if(log.isDebugEnabled()) {
- log.debug("Repository with url: " + subscriptionData.getRepositoryURL() +
- " username: " + subscriptionData.getRepositoryUsername() +
- " Type: " + subscriptionData.getRepositoryType());
- }
-
- // Create subscriber
- Subscriber subscriber = new Subscriber(subscriptionData.getTenantAdminUsername(), subscriptionData.getTenantId(), subscriptionData.getTenantDomain());
- cartridgeSubscription.setSubscriber(subscriber);
- cartridgeSubscription.setAlias(subscriptionData.getCartridgeAlias());
-
- // Create repository
- Repository repository = cartridgeSubscription.manageRepository(subscriptionData.getRepositoryURL(), subscriptionData.getRepositoryUsername(),
- subscriptionData.getRepositoryPassword(),
- subscriptionData.isPrivateRepository());
-
- // Update repository attributes
- if(repository != null) {
-
- repository.setCommitEnabled(subscriptionData.isCommitsEnabled());
-
- // Encrypt repository password
- String encryptedRepoPassword;
- String repositoryPassword = repository.getPassword();
- if(repositoryPassword != null && !repositoryPassword.isEmpty()) {
- encryptedRepoPassword = RepoPasswordMgtUtil.encryptPassword(repositoryPassword, subscriptionKey);
- } else {
- encryptedRepoPassword = "";
- }
- repository.setPassword(encryptedRepoPassword);
-
- }
-
- // set the LB cluster id relevant to this service cluster
- cartridgeSubscription.setLbClusterId(lbClusterId);
-
- //create subscription
- cartridgeSubscription.createSubscription(subscriber, subscriptionData.getCartridgeAlias(), subscriptionData.getAutoscalingPolicyName(),
- subscriptionData.getDeploymentPolicyName(), repository);
-
- // publishing to bam
- CartridgeSubscriptionDataPublisher.publish(
- subscriptionData.getTenantId(),
- subscriptionData.getTenantAdminUsername(),
- subscriptionData.getCartridgeAlias(),
- subscriptionData.getCartridgeType(),
- subscriptionData.getRepositoryURL(),
- cartridgeInfo.getMultiTenant(),
- subscriptionData.getAutoscalingPolicyName(),
- subscriptionData.getDeploymentPolicyName(),
- cartridgeSubscription.getCluster().getClusterDomain(),
- cartridgeSubscription.getHostName(),
- cartridgeSubscription.getMappedDomain(), "Subscribed");
-
- // Add whether the subscription is enabled upstream git commits
- if(cartridgeSubscription.getPayloadData() != null) {
- cartridgeSubscription.getPayloadData().add(CartridgeConstants.COMMIT_ENABLED, String.valueOf(subscriptionData.isCommitsEnabled()));
- }
-
- if(subscriptionData.getProperties() != null){
- for(Property property : subscriptionData.getProperties().getProperties()){
- if (property.getName().startsWith(CartridgeConstants.CUSTOM_PAYLOAD_PARAM_NAME_PREFIX)) {
- String payloadParamName = property.getName();
- cartridgeSubscription.getPayloadData().add(payloadParamName.substring(
- payloadParamName.indexOf(".") + 1), String.valueOf(property.getValue()));
- }
- }
- }
-
- log.info("Tenant [" + subscriptionData.getTenantId() + "] with username [" + subscriptionData.getTenantAdminUsername() +
- " subscribed to " + "] Cartridge with Alias " + subscriptionData.getCartridgeAlias() + ", Cartridge Type: " +
- subscriptionData.getCartridgeType() + ", Repo URL: " + subscriptionData.getRepositoryURL() + ", Autoscale Policy: " +
- subscriptionData.getAutoscalingPolicyName() + ", Deployment Policy: " + subscriptionData.getDeploymentPolicyName());
-
- return cartridgeSubscription;
- }
-
- /**
- * Registers the cartridge subscription for the given CartridgeSubscriptionInfo object
- *
- * @param cartridgeSubscription CartridgeSubscription subscription
- *
- * @param persistence
- * @return SubscriptionInfo object populated with relevant information
- * @throws ADCException
- * @throws UnregisteredCartridgeException
- */
- public static SubscriptionInfo registerCartridgeSubscription(CartridgeSubscription cartridgeSubscription, Properties properties, Persistence persistence)
- throws ADCException, UnregisteredCartridgeException {
-
- CartridgeSubscriptionInfo cartridgeSubscriptionInfo = cartridgeSubscription.registerSubscription(properties, persistence);
-
- //set status as 'SUBSCRIBED'
- cartridgeSubscription.setSubscriptionStatus(CartridgeConstants.SUBSCRIBED);
-
- try {
- new DataInsertionAndRetrievalManager().cacheAndPersistSubcription(cartridgeSubscription);
-
- } catch (PersistenceManagerException e) {
- String errorMsg = "Error saving subscription for tenant " +
- cartridgeSubscription.getSubscriber().getTenantDomain() + ", alias " + cartridgeSubscription.getType();
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
-
- log.info("Successful Subscription: " + cartridgeSubscription.toString());
-
- // Publish tenant subscribed event to message broker
- Set<String> clusterIds = new HashSet<String>();
- clusterIds.add(cartridgeSubscription.getCluster().getClusterDomain());
- CartridgeSubscriptionUtils.publishTenantSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(), cartridgeSubscription.getCartridgeInfo().getType(), clusterIds);
-
- return ApplicationManagementUtil.
- createSubscriptionResponse(cartridgeSubscriptionInfo, cartridgeSubscription.getRepository());
- }
-
- public static void addSubscriptionDomain(int tenantId, String subscriptionAlias, String domainName, String applicationContext)
- throws ADCException {
-
- CartridgeSubscription cartridgeSubscription;
- try {
- cartridgeSubscription = getCartridgeSubscription(tenantId, subscriptionAlias);
- if(cartridgeSubscription == null) {
- throw new ADCException("Cartridge subscription not found");
- }
-
- if(!isSubscriptionDomainValid(domainName)) {
- throw new ADCException(String.format("Domain name %s already registered", domainName));
- }
-
- cartridgeSubscription.addSubscriptionDomain(new SubscriptionDomain(domainName, applicationContext));
- new DataInsertionAndRetrievalManager().cacheAndPersistSubcription(cartridgeSubscription);
-
- } catch (PersistenceManagerException e) {
- String errorMsg = "Could not add domain to cartridge subscription: [tenant-id] " + tenantId + " [subscription-alias] " + subscriptionAlias +
- " [domain-name] " + domainName + " [application-context] " + applicationContext;
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
-
- log.info("Successfully added domains to cartridge subscription: [tenant-id] " + tenantId + " [subscription-alias] " + subscriptionAlias +
- " [domain-name] " + domainName + " [application-context] " +applicationContext);
-
-
- Set<String> clusterIds = new HashSet<String>();
- clusterIds.add(cartridgeSubscription.getCluster().getClusterDomain());
- SubscriptionDomainAddedEvent event = new SubscriptionDomainAddedEvent(tenantId, cartridgeSubscription.getType(),
- clusterIds, domainName, applicationContext);
- String topic = Util.getMessageTopicName(event);
- EventPublisher eventPublisher = EventPublisherPool.getPublisher(topic);
- eventPublisher.publish(event);
- }
-
- public static void removeSubscriptionDomain(int tenantId, String subscriptionAlias, String domainName) throws ADCException, DomainSubscriptionDoesNotExist {
-
- CartridgeSubscription cartridgeSubscription;
- try {
- cartridgeSubscription = getCartridgeSubscription(tenantId, subscriptionAlias);
- if(cartridgeSubscription == null) {
- throw new DomainSubscriptionDoesNotExist("Cartridge subscription not found", domainName);
- }
- cartridgeSubscription.removeSubscriptionDomain(domainName);
- new DataInsertionAndRetrievalManager().cacheAndPersistSubcription(cartridgeSubscription);
-
- } catch (PersistenceManagerException e) {
- String errorMsg = "Could not remove domain from cartridge subscription: [tenant-id] " + tenantId + " [subscription-alias] " + subscriptionAlias +
- " [domain-name] " + domainName;
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
-
- log.info("Successfully removed domain from cartridge subscription: [tenant-id] " + tenantId + " [subscription-alias] " + subscriptionAlias +
- " [domain-name] " + domainName);
-
-
-
- Set<String> clusterIds = new HashSet<String>();
- clusterIds.add(cartridgeSubscription.getCluster().getClusterDomain());
- SubscriptionDomainRemovedEvent event = new SubscriptionDomainRemovedEvent(tenantId, cartridgeSubscription.getType(),
- clusterIds, domainName);
- String topic = Util.getMessageTopicName(event);
- EventPublisher eventPublisher = EventPublisherPool.getPublisher(topic);
- eventPublisher.publish(event);
- }
-
- public static List<SubscriptionDomain> getSubscriptionDomains(int tenantId, String subscriptionAlias)
- throws ADCException {
-
- try {
- CartridgeSubscription cartridgeSubscription = getCartridgeSubscription(tenantId, subscriptionAlias);
- if(cartridgeSubscription == null) {
- throw new ADCException("Cartridge subscription not found");
- }
-
- //return (List<SubscriptionDomain>) cartridgeSubscription.getSubscriptionDomains();
- return new ArrayList<SubscriptionDomain>(cartridgeSubscription.getSubscriptionDomains());
- } catch (Exception e) {
- String errorMsg = "Could not get domains of cartridge subscription: [tenant-id] " + tenantId + " [subscription-alias] " + subscriptionAlias;
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
- }
-
- public static SubscriptionDomain getSubscriptionDomain(int tenantId, String subscriptionAlias, String domain)
- throws ADCException {
-
- try {
- CartridgeSubscription cartridgeSubscription = getCartridgeSubscription(tenantId, subscriptionAlias);
- if(cartridgeSubscription == null) {
- throw new ADCException("Cartridge subscription not found");
- }
-
- return cartridgeSubscription.getSubscriptionDomain(domain);
- } catch (Exception e) {
- String errorMsg = "Could not check [domain] "+domain+" against cartridge subscription: [tenant-id] "
- + tenantId + " [subscription-alias] " + subscriptionAlias;
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
- }
-
- public static boolean isSubscriptionDomainValid(String domainName) throws ADCException {
- try {
- if(log.isDebugEnabled()) {
- log.debug(String.format("Validating domain: %s", domainName));
- }
- org.wso2.carbon.user.core.tenant.TenantManager tenantManager = DataHolder.getRealmService().getTenantManager();
- org.wso2.carbon.user.api.Tenant[] tenants = tenantManager.getAllTenants();
- if((tenants != null) && (tenants.length > 0)) {
- DataInsertionAndRetrievalManager manager = new DataInsertionAndRetrievalManager();
- for (org.wso2.carbon.user.api.Tenant tenant : tenants) {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Reading subscriptions for tenant: [tenant-id] %d [tenant-domain] %s",
- tenant.getId(), tenant.getDomain()));
- }
- Collection<CartridgeSubscription> subscriptions = manager.getCartridgeSubscriptions(tenant.getId());
- if (subscriptions == null) {
- continue;
- }
- for (CartridgeSubscription subscription : subscriptions) {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Reading domain names in subscription: [alias] %s [domain-names] %s",
- subscription.getAlias(), subscription.getSubscriptionDomains()));
- }
- if (subscription.subscriptionDomainExists(domainName)) {
- return false;
- }
- }
- }
- }
- if(log.isDebugEnabled()) {
- log.debug(String.format("Domain name %s is valid", domainName));
- }
- return true;
- } catch (Exception e) {
- String errorMsg = "Could not validate domain: " + domainName;
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
- }
-
- public static Collection<CartridgeSubscription> getCartridgeSubscriptions (int tenantId, String type) throws ADCException {
-
- if (type == null || type.isEmpty()) {
- return new DataInsertionAndRetrievalManager().getCartridgeSubscriptions(tenantId);
-
- } else {
- return new DataInsertionAndRetrievalManager().getCartridgeSubscriptions(tenantId, type);
- }
- }
-
- public static CartridgeSubscription getCartridgeSubscription (int tenantId, String subscriptionAlias) {
-
- return new DataInsertionAndRetrievalManager().getCartridgeSubscription(tenantId, subscriptionAlias);
- }
-
- /**
- * Unsubscribe from a Cartridge
- *
- * @param tenantDomain Tenant's domain
- * @param alias Alias given at subscription time
- * @throws ADCException
- * @throws NotSubscribedException
- */
- public static void unsubscribeFromCartridge (String tenantDomain, String alias)
- throws ADCException, NotSubscribedException {
-
- DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
-
- CartridgeSubscription cartridgeSubscription = dataInsertionAndRetrievalManager.getCartridgeSubscription(CarbonContext.getThreadLocalCarbonContext().getTenantId(), alias);
- if(cartridgeSubscription != null) {
- cartridgeSubscription.removeSubscription();
-
- // Remove the information from Topology Model
- // Not needed now. TopologyModel is now changed so that information is taken from subscriptions
- //TopologyClusterInformationModel.getInstance().removeCluster(cartridgeSubscription.getSubscriber().getTenantId(),
- // cartridgeSubscription.getType(), cartridgeSubscription.getAlias());
-
- // remove subscription
- try {
- dataInsertionAndRetrievalManager.removeSubscription(cartridgeSubscription.getSubscriber().getTenantId(), alias);
-
- } catch (PersistenceManagerException e) {
- String errorMsg = "Error removing subscription for tenant " + tenantDomain + ", alias " + cartridgeSubscription.getAlias();
- log.error(errorMsg);
- throw new ADCException(errorMsg, e);
- }
-
- // Publish tenant un-subscribed event to message broker
-
- Set<String> clusterIds = new HashSet<String>();
- clusterIds.add(cartridgeSubscription.getCluster().getClusterDomain());
- CartridgeSubscriptionUtils.publishTenantUnSubscribedEvent(
- cartridgeSubscription.getSubscriber().getTenantId(),
- cartridgeSubscription.getCartridgeInfo().getType(), clusterIds);
-
- // publishing to the unsubscribed event details to bam
- CartridgeSubscriptionDataPublisher.publish(cartridgeSubscription
- .getSubscriber().getTenantId(), cartridgeSubscription
- .getSubscriber().getAdminUserName(), cartridgeSubscription
- .getAlias(), cartridgeSubscription.getType(),
- "",
- cartridgeSubscription.getCartridgeInfo().getMultiTenant(),
- cartridgeSubscription.getAutoscalingPolicyName(),
- cartridgeSubscription.getDeploymentPolicyName(),
- cartridgeSubscription.getCluster().getClusterDomain(),
- cartridgeSubscription.getHostName(), cartridgeSubscription
- .getMappedDomain(), "unsubscribed");
- }
- else {
- String errorMsg = "No cartridge subscription found with [alias] " + alias + " for [tenant] " + tenantDomain;
- log.error(errorMsg);
- throw new NotSubscribedException(errorMsg, alias);
- }
- }
-
- private static Properties getPersistenceMappingProperties (PersistenceContext persistenceCtxt, CartridgeInfo cartridgeInfo) throws ADCException {
-
- if (!cartridgeInfo.isPersistenceSpecified()) {
- // Persistence Mapping not supported in the cartridge definition - error
- String errorMsg = "Persistence Mapping not supported by the cartridge type " + cartridgeInfo.getType();
- log.error(errorMsg);
- throw new ADCException(errorMsg);
- }
-
- Properties persistenceMappingProperties = new Properties();
- persistenceMappingProperties.setProperties(new Property[]{persistenceCtxt.getPersistanceRequiredProperty(), persistenceCtxt.getSizeProperty(),
- persistenceCtxt.getDeleteOnTerminationProperty(), persistenceCtxt.getVolumeIdProperty()});
-
- return persistenceMappingProperties;
- }
-
- /**
- *
- * Returns a collection of Cartridge subscriptions for a particular tenant and a cartridge type
- *
- * @param tenantId
- * @param cartridgeType
- * @return
- */
- public static Collection<CartridgeSubscription> isCartridgeSubscribed(int tenantId, String cartridgeType) {
-
- DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
- return dataInsertionAndRetrievalManager.getCartridgeSubscriptions(tenantId, cartridgeType);
- }
-
- public Collection<CartridgeSubscription> getCartridgeSubscriptionsForType (String cartridgeType) {
-
- return new DataInsertionAndRetrievalManager().getCartridgeSubscriptions(cartridgeType);
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/TenantSynchronizerTaskScheduler.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/TenantSynchronizerTaskScheduler.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/TenantSynchronizerTaskScheduler.java
new file mode 100644
index 0000000..57530a0
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/TenantSynchronizerTaskScheduler.java
@@ -0,0 +1,76 @@
+/*
+ * 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.messaging;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.ntask.common.TaskException;
+import org.wso2.carbon.ntask.core.TaskInfo;
+import org.wso2.carbon.ntask.core.TaskManager;
+import org.wso2.carbon.ntask.core.service.TaskService;
+
+import java.util.HashMap;
+
+/**
+ * Tenant synchronizer task scheduler for scheduling the tenant synchronizer task
+ * using carbon task service.
+ */
+public class TenantSynchronizerTaskScheduler {
+
+ private static final Log log = LogFactory.getLog(TenantSynzhronizerTask.class);
+
+ private static final String TENANT_SYNC_TASK_TYPE = "TENANT_SYNC_TASK_TYPE";
+ private static final String TENANT_SYNC_TASK_NAME = "TENANT_SYNC_TASK";
+ private static final String DEFAULT_CRON = "1 * * * * ? *";
+
+ public static void schedule(TaskService taskService) {
+ TaskManager taskManager = null;
+ try {
+
+ if (!taskService.getRegisteredTaskTypes().contains(TENANT_SYNC_TASK_TYPE)) {
+ // Register task type
+ taskService.registerTaskType(TENANT_SYNC_TASK_TYPE);
+
+ // Register task
+ taskManager = taskService.getTaskManager(TENANT_SYNC_TASK_TYPE);
+ TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo(DEFAULT_CRON);
+ TaskInfo taskInfo = new TaskInfo(TENANT_SYNC_TASK_NAME,
+ TenantSynzhronizerTask.class.getName(),
+ new HashMap<String, String>(), triggerInfo);
+ taskManager.registerTask(taskInfo);
+ if(log.isDebugEnabled()) {
+ log.debug(String.format("Tenant synchronization task scheduled: %s", TENANT_SYNC_TASK_NAME));
+ }
+ }
+
+ } catch (Exception e) {
+ if (taskManager != null) {
+ try {
+ taskManager.deleteTask(TENANT_SYNC_TASK_NAME);
+ } catch (TaskException te) {
+ if (log.isErrorEnabled()) {
+ log.error(te);
+ }
+ }
+ }
+ throw new RuntimeException(String.format("Could not schedule tenant synchronization task: %s", TENANT_SYNC_TASK_NAME), e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/TenantSynzhronizerTask.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/TenantSynzhronizerTask.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/TenantSynzhronizerTask.java
new file mode 100644
index 0000000..2b354c4
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/TenantSynzhronizerTask.java
@@ -0,0 +1,122 @@
+/*
+ * 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.messaging;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.manager.internal.ServiceReferenceHolder;
+import org.apache.stratos.messaging.broker.publish.EventPublisher;
+import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
+import org.apache.stratos.messaging.domain.tenant.Tenant;
+import org.apache.stratos.messaging.event.tenant.CompleteTenantEvent;
+import org.apache.stratos.messaging.util.Util;
+import org.wso2.carbon.ntask.core.Task;
+import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
+import org.wso2.carbon.user.core.tenant.TenantManager;
+
+import java.util.*;
+
+/**
+ * Tenant synchronizer task for publishing complete tenant event periodically
+ * to message broker.
+ */
+public class TenantSynzhronizerTask implements Task {
+
+ private static final Log log = LogFactory.getLog(TenantSynzhronizerTask.class);
+
+ @Override
+ public void init() {
+ }
+
+ @Override
+ public void execute() {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Publishing complete tenant event"));
+ }
+ Tenant tenant;
+ List<Tenant> tenants = new ArrayList<Tenant>();
+ TenantManager tenantManager = ServiceReferenceHolder.getRealmService().getTenantManager();
+ org.wso2.carbon.user.api.Tenant[] carbonTenants = tenantManager.getAllTenants();
+ for (org.wso2.carbon.user.api.Tenant carbonTenant : carbonTenants) {
+ // Create tenant
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Tenant found: [tenant-id] %d [tenant-domain] %s",
+ carbonTenant.getId(), carbonTenant.getDomain()));
+ }
+ tenant = new Tenant(carbonTenant.getId(), carbonTenant.getDomain());
+
+ if (!org.apache.stratos.messaging.message.receiver.tenant.TenantManager.getInstance()
+ .tenantExists(carbonTenant.getId())) {
+ // if the tenant is not already there in TenantManager,
+ // trigger TenantCreatedEvent
+ TenantInfoBean tenantBean = new TenantInfoBean();
+ tenantBean.setTenantId(carbonTenant.getId());
+ tenantBean.setTenantDomain(carbonTenant.getDomain());
+ //TenantMgtUtil.triggerAddTenant(tenantBean);
+ // add tenant to Tenant Manager
+ org.apache.stratos.messaging.message.receiver.tenant.TenantManager.getInstance()
+ .addTenant(tenant);
+ }
+
+ // Add subscriptions
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // List<CartridgeSubscriptionInfo> cartridgeSubscriptions =
+ // PersistenceManager.getSubscriptionsForTenant(tenant.getTenantId());
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Collection<CartridgeSubscription> cartridgeSubscriptions =
+// new DataInsertionAndRetrievalManager().getCartridgeSubscriptions(tenant.getTenantId());
+// if (cartridgeSubscriptions != null && !cartridgeSubscriptions.isEmpty()) {
+// for (CartridgeSubscription cartridgeSubscription : cartridgeSubscriptions) {
+// if (log.isDebugEnabled()) {
+// log.debug(String.format("Tenant subscription found: [tenant-id] %d [tenant-domain] %s [service] %s",
+// carbonTenant.getId(), carbonTenant.getDomain(),
+// cartridgeSubscription.getType()));
+// }
+// HashSet<String> clusterIds = new HashSet<String>();
+// clusterIds.add(cartridgeSubscription.getCluster().getClusterDomain());
+// Subscription subscription =
+// new Subscription(
+// cartridgeSubscription.getType(),
+// clusterIds);
+// for (SubscriptionDomain subscriptionDomain : cartridgeSubscription.getSubscriptionDomains()) {
+// subscription.addSubscriptionDomain(subscriptionDomain.getDomainName(),
+// subscriptionDomain.getApplicationContext());
+// }
+// tenant.addSubscription(subscription);
+// }
+// }
+ tenants.add(tenant);
+ }
+ CompleteTenantEvent event = new CompleteTenantEvent(tenants);
+ String topic = Util.getMessageTopicName(event);
+ EventPublisher eventPublisher = EventPublisherPool.getPublisher(topic);
+ eventPublisher.publish(event);
+ } catch (Exception e) {
+ if (log.isErrorEnabled()) {
+ log.error("Could not publish complete tenant event", e);
+ }
+ }
+ }
+
+ @Override
+ public void setProperties(Map<String, String> stringStringMap) {
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/79c69e77/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/publisher/InstanceNotificationPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/publisher/InstanceNotificationPublisher.java b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/publisher/InstanceNotificationPublisher.java
new file mode 100644
index 0000000..c82e644
--- /dev/null
+++ b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/messaging/publisher/InstanceNotificationPublisher.java
@@ -0,0 +1,70 @@
+/*
+ * 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.messaging.publisher;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.messaging.broker.publish.EventPublisher;
+import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
+import org.apache.stratos.messaging.event.Event;
+import org.apache.stratos.messaging.event.instance.notifier.ArtifactUpdatedEvent;
+import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupClusterEvent;
+import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupMemberEvent;
+import org.apache.stratos.messaging.util.Util;
+
+/**
+ * Creating the relevant instance notification event and publish it to the
+ * instances.
+ */
+public class InstanceNotificationPublisher {
+ private static final Log log = LogFactory.getLog(InstanceNotificationPublisher.class);
+
+ public InstanceNotificationPublisher() {
+ }
+
+ private void publish(Event event) {
+ String topic = Util.getMessageTopicName(event);
+ EventPublisher depsyncEventPublisher = EventPublisherPool.getPublisher(topic);
+ depsyncEventPublisher.publish(event);
+ }
+
+ /**
+ * Publishing the artifact update event to the instances
+ *
+ * @param clusterId
+ * @param tenantId
+ * @param repoUrl
+ * @param repoUsername
+ * @param repoPassword
+ * @param isCommitEnabled
+ */
+ public void publishArtifactUpdatedEvent(String clusterId, String tenantId, String repoUrl, String repoUsername,
+ String repoPassword, boolean isCommitEnabled) {
+
+ ArtifactUpdatedEvent artifactUpdateEvent = new ArtifactUpdatedEvent();
+ artifactUpdateEvent.setClusterId(clusterId);
+ artifactUpdateEvent.setRepoUserName(repoUsername);
+ artifactUpdateEvent.setRepoPassword(repoPassword);
+ artifactUpdateEvent.setRepoURL(repoUrl);
+ artifactUpdateEvent.setTenantId(tenantId);
+ artifactUpdateEvent.setCommitEnabled(isCommitEnabled);
+
+ publish(artifactUpdateEvent);
+ }
+}