Updated Branches: refs/heads/master c6829cdfb -> 4e0e95681
Implemented tenant event publishing functionality in stratos manager Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/4e0e9568 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/4e0e9568 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/4e0e9568 Branch: refs/heads/master Commit: 4e0e9568125cb3639d0fff86545541884fe66d72 Parents: c6829cd Author: Imesh Gunaratne <[email protected]> Authored: Sat Dec 7 10:45:52 2013 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Sat Dec 7 10:45:52 2013 +0530 ---------------------------------------------------------------------- components/org.apache.stratos.adc.mgt/pom.xml | 17 ++- .../internal/ADCManagementServerComponent.java | 61 ++++++++-- .../mgt/internal/ServiceReferenceHolder.java | 51 +++++++++ .../adc/mgt/publisher/TenantEventPublisher.java | 114 +++++++++++++++++++ .../TenantSynchronizerTaskScheduler.java | 76 +++++++++++++ .../mgt/publisher/TenantSynzhronizerTask.java | 74 ++++++++++++ .../common/listeners/TenantMgtListener.java | 2 + .../keystore/mgt/KeystoreTenantMgtListener.java | 4 + .../internal/LoadBalancerServiceComponent.java | 19 ++-- .../event/tenant/CompleteTenantEvent.java | 42 +++++++ .../tenant/CompleteTenantMessageProcessor.java | 8 +- .../message/receiver/tenant/TenantManager.java | 7 ++ .../sender/listener/EmailSenderListener.java | 10 +- .../mgt/services/TenantMgtAdminService.java | 9 ++ .../stratos/tenant/mgt/util/TenantMgtUtil.java | 9 +- .../theme/mgt/util/ThemeLoadingListener.java | 20 ++-- 16 files changed, 481 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.adc.mgt/pom.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.adc.mgt/pom.xml b/components/org.apache.stratos.adc.mgt/pom.xml index df8aa32..83fb1b9 100644 --- a/components/org.apache.stratos.adc.mgt/pom.xml +++ b/components/org.apache.stratos.adc.mgt/pom.xml @@ -100,12 +100,17 @@ <artifactId>junit</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - <version>3.1</version> - </dependency> - </dependencies> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>org.apache.stratos</groupId> + <artifactId>org.apache.stratos.common</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> <build> <plugins> http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/internal/ADCManagementServerComponent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/internal/ADCManagementServerComponent.java b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/internal/ADCManagementServerComponent.java index 97b5e05..13d75fe 100644 --- a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/internal/ADCManagementServerComponent.java +++ b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/internal/ADCManagementServerComponent.java @@ -21,6 +21,8 @@ package org.apache.stratos.adc.mgt.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.adc.mgt.listener.InstanceStatusListener; +import org.apache.stratos.adc.mgt.publisher.TenantEventPublisher; +import org.apache.stratos.adc.mgt.publisher.TenantSynchronizerTaskScheduler; import org.apache.stratos.adc.mgt.utils.CartridgeConfigFileReader; import org.apache.stratos.adc.mgt.utils.StratosDBUtils; import org.apache.stratos.adc.topology.mgt.service.TopologyManagementService; @@ -28,13 +30,13 @@ import org.apache.stratos.messaging.broker.publish.EventPublisher; import org.apache.stratos.messaging.broker.subscribe.TopicSubscriber; import org.apache.stratos.messaging.util.Constants; import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.ntask.core.service.TaskService; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.ConfigurationContextService; /** - * @scr.component name= - * "org.wso2.carbon.hosting.mgt.internal.ADCManagementServerComponent" + * @scr.component name="org.wso2.carbon.hosting.mgt.internal.ADCManagementServerComponent" * immediate="true" * @scr.reference name="config.context.service" * interface="org.wso2.carbon.utils.ConfigurationContextService" @@ -56,29 +58,52 @@ import org.wso2.carbon.utils.ConfigurationContextService; * cardinality="1..1" policy="dynamic" * bind="setTopologyManagementService" * unbind="unsetTopologyManagementService" + * @scr.reference name="ntask.component" interface="org.wso2.carbon.ntask.core.service.TaskService" + * cardinality="1..1" policy="dynamic" bind="setTaskService" + * unbind="unsetTaskService" */ public class ADCManagementServerComponent { private static final Log log = LogFactory.getLog(ADCManagementServerComponent.class); - - protected void activate(ComponentContext componentContext) throws Exception { - if (log.isInfoEnabled()) { - log.info("ADC Management Server Component activated"); - } + protected void activate(ComponentContext componentContext) throws Exception { try { CartridgeConfigFileReader.readProperties(); StratosDBUtils.initialize(); DataHolder.setEventPublisher(new EventPublisher(Constants.ARTIFACT_SYNCHRONIZATION_TOPIC)); - - //initialting the subscriber + + // Schedule complete tenant event synchronizer + if(log.isDebugEnabled()) { + log.debug("Scheduling tenant synchronizer task..."); + } + TenantSynchronizerTaskScheduler.schedule(ServiceReferenceHolder.getInstance().getTaskService()); + + // Register tenant event publisher + if(log.isDebugEnabled()) { + log.debug("Starting tenant event publisher..."); + } + TenantEventPublisher tenantEventPublisher = new TenantEventPublisher(); + componentContext.getBundleContext().registerService( + org.apache.stratos.common.listeners.TenantMgtListener.class.getName(), + tenantEventPublisher, null); + + // Start instance status topic subscriber + if(log.isDebugEnabled()) { + log.debug("Starting instance status topic subscriber..."); + } TopicSubscriber subscriber = new TopicSubscriber(Constants.INSTANCE_STATUS_TOPIC); subscriber.setMessageListener(new InstanceStatusListener()); Thread tsubscriber = new Thread(subscriber); tsubscriber.start(); + + if (log.isInfoEnabled()) { + log.info("ADC management server component is activated"); + } } catch (Exception e) { - log.fatal("Error while initializing the ADC Management Server Component", e); + if(log.isFatalEnabled()) { + log.fatal("Could not activate ADC management server component", e); + } } } @@ -105,7 +130,7 @@ public class ADCManagementServerComponent { try { DataHolder.setRegistry(registryService.getGovernanceSystemRegistry()); } catch (Exception e) { - log.error("Cannot retrieve governance Registry", e); + log.error("Cannot retrieve governance registry", e); } } @@ -118,4 +143,18 @@ public class ADCManagementServerComponent { protected void unsetTopologyManagementService(TopologyManagementService topologyMgtService) { } + + protected void setTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Setting the task service"); + } + ServiceReferenceHolder.getInstance().setTaskService(taskService); + } + + protected void unsetTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Un-setting the task service"); + } + ServiceReferenceHolder.getInstance().setTaskService(null); + } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/internal/ServiceReferenceHolder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/internal/ServiceReferenceHolder.java b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/internal/ServiceReferenceHolder.java new file mode 100644 index 0000000..bbf6999 --- /dev/null +++ b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/internal/ServiceReferenceHolder.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.adc.mgt.internal; + +import org.wso2.carbon.ntask.core.service.TaskService; + +/** + * Service reference holder. + */ +public class ServiceReferenceHolder { + private static volatile ServiceReferenceHolder instance = null; + private TaskService taskService; + + private ServiceReferenceHolder() { } + + public static ServiceReferenceHolder getInstance() { + if (instance == null) { + synchronized (ServiceReferenceHolder .class){ + if (instance == null) { + instance = new ServiceReferenceHolder(); + } + } + } + return instance; + } + + public void setTaskService(TaskService taskService) { + this.taskService = taskService; + } + + public TaskService getTaskService() { + return taskService; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantEventPublisher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantEventPublisher.java b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantEventPublisher.java new file mode 100644 index 0000000..91c7bee --- /dev/null +++ b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantEventPublisher.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.adc.mgt.publisher; + +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.StratosException; +import org.apache.stratos.common.listeners.TenantMgtListener; +import org.apache.stratos.messaging.broker.publish.EventPublisher; +import org.apache.stratos.messaging.domain.tenant.Tenant; +import org.apache.stratos.messaging.event.tenant.TenantCreatedEvent; +import org.apache.stratos.messaging.event.tenant.TenantRemovedEvent; +import org.apache.stratos.messaging.event.tenant.TenantUpdatedEvent; +import org.apache.stratos.messaging.util.Constants; + +/** + * Tenant event publisher to publish tenant events to the message broker by + * listening to the tenant manager. + */ +public class TenantEventPublisher implements TenantMgtListener { + + private static final Log log = LogFactory.getLog(TenantEventPublisher.class); + private static final int EXEC_ORDER = 1; + + + @Override + public void onTenantCreate(TenantInfoBean tenantInfo) throws StratosException { + try { + if(log.isDebugEnabled()) { + log.debug(String.format("Publishing tenant created event: [tenant-id] %d [tenant-domain] %s", tenantInfo.getTenantId(), tenantInfo.getTenantDomain())); + } + Tenant tenant = new Tenant(tenantInfo.getTenantId(), tenantInfo.getTenantDomain()); + TenantCreatedEvent event = new TenantCreatedEvent(tenant); + EventPublisher eventPublisher = new EventPublisher(Constants.TENANT_TOPIC); + eventPublisher.publish(event); + } + catch (Exception e) { + log.error("Could not publish tenant created event", e); + } + } + + @Override + public void onTenantUpdate(TenantInfoBean tenantInfo) throws StratosException { + try { + if(log.isInfoEnabled()) { + log.info(String.format("Publishing tenant updated event: [tenant-id] %d [tenant-domain] %s", tenantInfo.getTenantId(), tenantInfo.getTenantDomain())); + } + TenantUpdatedEvent event = new TenantUpdatedEvent(tenantInfo.getTenantId(), tenantInfo.getTenantDomain()); + EventPublisher eventPublisher = new EventPublisher(Constants.TENANT_TOPIC); + eventPublisher.publish(event); + } + catch (Exception e) { + log.error("Could not publish tenant updated event"); + } + } + + @Override + public void onTenantDelete(int tenantId) { + try { + if(log.isInfoEnabled()) { + log.info(String.format("Publishing tenant removed event: [tenant-id] %d", tenantId)); + } + TenantRemovedEvent event = new TenantRemovedEvent(tenantId); + EventPublisher eventPublisher = new EventPublisher(Constants.TENANT_TOPIC); + eventPublisher.publish(event); + } + catch (Exception e) { + log.error("Could not publish tenant removed event"); + } + } + + @Override + public void onTenantRename(int tenantId, String oldDomainName, String newDomainName) throws StratosException { + } + + @Override + public void onTenantInitialActivation(int tenantId) throws StratosException { + } + + @Override + public void onTenantActivation(int tenantId) throws StratosException { + } + + @Override + public void onTenantDeactivation(int tenantId) throws StratosException { + } + + @Override + public void onSubscriptionPlanChange(int tenantId, String oldPlan, String newPlan) throws StratosException { + } + + @Override + public int getListenerOrder() { + return EXEC_ORDER; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantSynchronizerTaskScheduler.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantSynchronizerTaskScheduler.java b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantSynchronizerTaskScheduler.java new file mode 100644 index 0000000..f8f8795 --- /dev/null +++ b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/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.adc.mgt.publisher; + +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/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantSynzhronizerTask.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantSynzhronizerTask.java b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantSynzhronizerTask.java new file mode 100644 index 0000000..62c5103 --- /dev/null +++ b/components/org.apache.stratos.adc.mgt/src/main/java/org/apache/stratos/adc/mgt/publisher/TenantSynzhronizerTask.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.adc.mgt.publisher; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.adc.mgt.internal.DataHolder; +import org.apache.stratos.messaging.broker.publish.EventPublisher; +import org.apache.stratos.messaging.domain.tenant.Tenant; +import org.apache.stratos.messaging.event.tenant.CompleteTenantEvent; +import org.apache.stratos.messaging.util.Constants; +import org.wso2.carbon.ntask.core.Task; +import org.wso2.carbon.user.core.tenant.TenantManager; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * 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.isInfoEnabled()) { + log.info(String.format("Publishing complete tenant event")); + } + List<Tenant> tenants = new ArrayList<Tenant>(); + TenantManager tenantManager = DataHolder.getRealmService().getTenantManager(); + org.wso2.carbon.user.api.Tenant[] carbonTenants = tenantManager.getAllTenants(); + for(org.wso2.carbon.user.api.Tenant carbonTenant : carbonTenants) { + tenants.add(new Tenant(carbonTenant.getId(), carbonTenant.getDomain())); + } + CompleteTenantEvent event = new CompleteTenantEvent(tenants); + EventPublisher eventPublisher = new EventPublisher(Constants.TENANT_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/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/listeners/TenantMgtListener.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/listeners/TenantMgtListener.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/listeners/TenantMgtListener.java index 4a9a316..7e60ffc 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/listeners/TenantMgtListener.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/listeners/TenantMgtListener.java @@ -27,6 +27,8 @@ public interface TenantMgtListener { public void onTenantUpdate(TenantInfoBean tenantInfo) throws StratosException; + public void onTenantDelete(int tenantId); + public void onTenantRename(int tenantId, String oldDomainName, String newDomainName)throws StratosException; http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java b/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java index 38830fa..be91f38 100644 --- a/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java +++ b/components/org.apache.stratos.keystore.mgt/src/main/java/org/apache/stratos/keystore/mgt/KeystoreTenantMgtListener.java @@ -52,6 +52,10 @@ public class KeystoreTenantMgtListener implements TenantMgtListener { // It is not required to implement this method for keystore mgt. } + public void onTenantDelete(int tenantId) { + // It is not required to implement this method for keystore mgt. + } + public void onTenantRename(int tenantId, String oldDomainName, String newDomainName) throws StratosException { // It is not required to implement this method for keystore mgt. http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java index a3e46e9..15f9600 100644 --- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java @@ -108,6 +108,7 @@ public class LoadBalancerServiceComponent { // Configure synapse settings LoadBalancerConfiguration configuration = LoadBalancerConfiguration.getInstance(); SynapseConfigurator.configure(configuration); + // Configure cep settings CEPConfigurator.configure(configuration); @@ -148,11 +149,13 @@ public class LoadBalancerServiceComponent { } activated = true; - if (log.isDebugEnabled()) { - log.debug("LoadBalancerServiceComponent is activated "); + if (log.isInfoEnabled()) { + log.info("Load balancer service component is activated "); + } + } catch (Exception e) { + if(log.isFatalEnabled()) { + log.fatal("Failed to activate load balancer service component", e); } - } catch (Throwable e) { - log.error("Failed to activate LoadBalancerServiceComponent", e); } } @@ -166,7 +169,7 @@ public class LoadBalancerServiceComponent { .getSynapseEnvironment()); } } catch (Exception e) { - log.warn("Couldn't remove the EndpointDeployer"); + log.warn("Couldn't remove the endpoint deployer"); } // Terminate topology receiver topologyReceiver.terminate(); @@ -268,10 +271,10 @@ public class LoadBalancerServiceComponent { .getConfigurationContext().getAxisConfiguration(), synapseEnvironmentService.getSynapseEnvironment()); if (log.isDebugEnabled()) { - log.debug("Endpoint Admin bundle is activated "); + log.debug("Endpoint admin bundle is activated "); } } catch (Throwable e) { - log.error("Failed to activate Endpoint Admin bundle ", e); + log.error("Failed to activate endpoint admin bundle ", e); } } } @@ -349,7 +352,7 @@ public class LoadBalancerServiceComponent { try { unregisterDeployer(axisConfig, env); } catch (Exception e) { - log.warn("Couldn't remove the EndpointDeployer"); + log.warn("Couldn't remove the endpoint deployer"); } } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/CompleteTenantEvent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/CompleteTenantEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/CompleteTenantEvent.java new file mode 100644 index 0000000..7e665b4 --- /dev/null +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/tenant/CompleteTenantEvent.java @@ -0,0 +1,42 @@ +/* + * 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.messaging.event.tenant; + +import org.apache.stratos.messaging.domain.tenant.Tenant; + +import java.util.List; + +/** + * This event is fired periodically with all the available tenants. It would be a + * starting point for subscribers to initialize the list of tenants before receiving + * other tenant events. + */ +public class CompleteTenantEvent { + + private List<Tenant> tenants; + + public CompleteTenantEvent(List<Tenant> tenants) { + this.tenants = tenants; + } + + public List<Tenant> getTenants() { + return tenants; + } +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/CompleteTenantMessageProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/CompleteTenantMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/CompleteTenantMessageProcessor.java index caf72f4..5090853 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/CompleteTenantMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/CompleteTenantMessageProcessor.java @@ -21,7 +21,7 @@ package org.apache.stratos.messaging.message.processor.tenant; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.stratos.messaging.event.tenant.TenantCreatedEvent; +import org.apache.stratos.messaging.event.tenant.CompleteTenantEvent; import org.apache.stratos.messaging.message.processor.MessageProcessor; import org.apache.stratos.messaging.message.receiver.tenant.TenantManager; import org.apache.stratos.messaging.util.Util; @@ -44,18 +44,18 @@ public class CompleteTenantMessageProcessor extends MessageProcessor { @Override public boolean process(String type, String message, Object object) { - if (TenantCreatedEvent.class.getName().equals(type)) { + if (CompleteTenantEvent.class.getName().equals(type)) { // Return if tenant manager has already initialized if(TenantManager.getInstance().isInitialized()) { return false; } // Parse complete message and build event - TenantCreatedEvent event = (TenantCreatedEvent) Util.jsonToObject(message, TenantCreatedEvent.class); + CompleteTenantEvent event = (CompleteTenantEvent) Util.jsonToObject(message, CompleteTenantEvent.class); try { TenantManager.acquireWriteLock(); - TenantManager.getInstance().addTenant(event.getTenant()); + TenantManager.getInstance().addTenants(event.getTenants()); if(log.isInfoEnabled()) { log.info("Tenant initialized"); } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/tenant/TenantManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/tenant/TenantManager.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/tenant/TenantManager.java index 230d0b3..c15b73c 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/tenant/TenantManager.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/tenant/TenantManager.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.stratos.messaging.domain.tenant.Tenant; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -98,6 +99,12 @@ public class TenantManager { this.tenantDomainTenantMap.put(tenant.getTenantDomain(), tenant); } + public void addTenants(List<Tenant> tenants) { + for(Tenant tenant : tenants) { + addTenant(tenant); + } + } + public Tenant getTenant(int tenantId) { return this.tenantIdTenantMap.get(tenantId); } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.tenant.mgt.email.sender/src/main/java/org/apache/stratos/tenant/mgt/email/sender/listener/EmailSenderListener.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.tenant.mgt.email.sender/src/main/java/org/apache/stratos/tenant/mgt/email/sender/listener/EmailSenderListener.java b/components/org.apache.stratos.tenant.mgt.email.sender/src/main/java/org/apache/stratos/tenant/mgt/email/sender/listener/EmailSenderListener.java index 58688c3..6025202 100644 --- a/components/org.apache.stratos.tenant.mgt.email.sender/src/main/java/org/apache/stratos/tenant/mgt/email/sender/listener/EmailSenderListener.java +++ b/components/org.apache.stratos.tenant.mgt.email.sender/src/main/java/org/apache/stratos/tenant/mgt/email/sender/listener/EmailSenderListener.java @@ -67,22 +67,26 @@ public class EmailSenderListener implements TenantMgtListener { } } + public void onTenantDelete(int tenantId) { + // Do nothing + } + public void onTenantInitialActivation(int tenantId) throws StratosException { // send the notification message to the tenant admin TenantMgtEmailSenderUtil.notifyTenantInitialActivation(tenantId); } public void onTenantActivation(int tenantId) throws StratosException { - // Do nothing. + // Do nothing } public void onTenantDeactivation(int tenantId) throws StratosException { - // Do nothing. + // Do nothing } public void onSubscriptionPlanChange(int tenentId, String oldPlan, String newPlan) throws StratosException { - // Do nothing. + // Do nothing } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java index 487959a..4f159f5 100644 --- a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java +++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java @@ -495,5 +495,14 @@ public class TenantMgtAdminService extends AbstractAdmin { log.error(msg, e); throw new Exception(msg, e); } + + //Notify tenant delete to all listeners + try { + TenantMgtUtil.triggerDeleteTenant(tenantId); + } catch (StratosException e) { + String msg = "Error in notifying tenant delete"; + log.error(msg, e); + throw new Exception(msg, e); + } } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java index bd7d685..ec3edd0 100644 --- a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java +++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java @@ -102,7 +102,7 @@ public class TenantMgtUtil { * Triggers an update for the tenant for TenantMgtListener * * @param tenantInfoBean tenantInfoBean - * @throws org.wso2.carbon.stratos.common.exception.StratosException, if update failed + * @throws org.apache.stratos.common.exception.StratosException, if update failed */ public static void triggerUpdateTenant( TenantInfoBean tenantInfoBean) throws StratosException { @@ -111,6 +111,13 @@ public class TenantMgtUtil { tenantMgtListener.onTenantUpdate(tenantInfoBean); } } + + public static void triggerDeleteTenant(int tenantId) throws StratosException { + for (TenantMgtListener tenantMgtListener : + TenantMgtServiceComponent.getTenantMgtListeners()) { + tenantMgtListener.onTenantDelete(tenantId); + } + } public static void triggerTenantInitialActivation( TenantInfoBean tenantInfoBean) throws StratosException { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4e0e9568/components/org.apache.stratos.theme.mgt/src/main/java/org/apache/stratos/theme/mgt/util/ThemeLoadingListener.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.theme.mgt/src/main/java/org/apache/stratos/theme/mgt/util/ThemeLoadingListener.java b/components/org.apache.stratos.theme.mgt/src/main/java/org/apache/stratos/theme/mgt/util/ThemeLoadingListener.java index c3bcd2f..6013a55 100644 --- a/components/org.apache.stratos.theme.mgt/src/main/java/org/apache/stratos/theme/mgt/util/ThemeLoadingListener.java +++ b/components/org.apache.stratos.theme.mgt/src/main/java/org/apache/stratos/theme/mgt/util/ThemeLoadingListener.java @@ -42,12 +42,16 @@ public class ThemeLoadingListener implements TenantMgtListener { } public void onTenantUpdate(TenantInfoBean tenantInfo) throws StratosException { - // doing nothing + // do nothing } - + + public void onTenantDelete(int tenantId) { + // do nothing + } + public void onTenantRename(int tenantId, String oldDomainName, String newDomainName) throws StratosException { - // doing nothing + // do nothing } public int getListenerOrder() { @@ -55,23 +59,21 @@ public class ThemeLoadingListener implements TenantMgtListener { } public void onTenantInitialActivation(int tenantId) throws StratosException { - // doing nothing - + // do nothing } public void onTenantActivation(int tenantId) throws StratosException { - // doing nothing + // do nothing } public void onTenantDeactivation(int tenantId) throws StratosException { - // doing nothing + // do nothing } public void onSubscriptionPlanChange(int tenentId, String oldPlan, String newPlan) throws StratosException { - // doing nothing - + // do nothing } }
