Added subscription domain events extension scripts and added tenant domain name as an argument
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/d6843ebe Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/d6843ebe Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/d6843ebe Branch: refs/heads/master Commit: d6843ebecd00d9fa8ea7fcec029c4d56aa7599d9 Parents: b61c4fc Author: Imesh Gunaratne <[email protected]> Authored: Wed May 7 09:13:12 2014 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Wed May 7 09:13:12 2014 +0530 ---------------------------------------------------------------------- .../stratos/cartridge/agent/CartridgeAgent.java | 46 +++++++++++++++++--- .../cartridge/agent/util/ExtensionUtils.java | 14 +++--- .../extensions/subscription-domain-added.sh | 28 ++++++++++++ .../extensions/subscription-domain-removed.sh | 28 ++++++++++++ 4 files changed, 105 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d6843ebe/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java index bb8e71f..5537637 100644 --- a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java +++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/CartridgeAgent.java @@ -34,6 +34,7 @@ import org.apache.stratos.cartridge.agent.event.publisher.CartridgeAgentEventPub import org.apache.stratos.cartridge.agent.util.CartridgeAgentConstants; import org.apache.stratos.cartridge.agent.util.CartridgeAgentUtils; import org.apache.stratos.cartridge.agent.util.ExtensionUtils; +import org.apache.stratos.messaging.domain.tenant.Tenant; 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; @@ -47,6 +48,7 @@ import org.apache.stratos.messaging.listener.tenant.SubscriptionDomainsAddedEven import org.apache.stratos.messaging.listener.tenant.SubscriptionDomainsRemovedEventListener; import org.apache.stratos.messaging.message.receiver.instance.notifier.InstanceNotifierEventReceiver; import org.apache.stratos.messaging.message.receiver.tenant.TenantEventReceiver; +import org.apache.stratos.messaging.message.receiver.tenant.TenantManager; import java.util.List; import java.util.concurrent.Executors; @@ -173,17 +175,37 @@ public class CartridgeAgent implements Runnable { tenantEventReceiver.addEventListener(new SubscriptionDomainsAddedEventListener() { @Override protected void onEvent(Event event) { - SubscriptionDomainAddedEvent subscriptionDomainAddedEvent = (SubscriptionDomainAddedEvent)event; - ExtensionUtils.executeSubscriptionDomainAddedExtension(subscriptionDomainAddedEvent.getDomainName(), - subscriptionDomainAddedEvent.getApplicationContext()); + try { + SubscriptionDomainAddedEvent subscriptionDomainAddedEvent = (SubscriptionDomainAddedEvent) event; + ExtensionUtils.executeSubscriptionDomainAddedExtension( + subscriptionDomainAddedEvent.getTenantId(), + findTenantDomain(subscriptionDomainAddedEvent.getTenantId()), + subscriptionDomainAddedEvent.getDomainName(), + subscriptionDomainAddedEvent.getApplicationContext()); + } + catch (Exception e) { + if(log.isErrorEnabled()) { + log.error("Could not process subscription domain added event", e); + } + } } }); tenantEventReceiver.addEventListener(new SubscriptionDomainsRemovedEventListener() { @Override protected void onEvent(Event event) { - SubscriptionDomainRemovedEvent subscriptionDomainRemovedEvent = (SubscriptionDomainRemovedEvent)event; - ExtensionUtils.executeSubscriptionDomainRemovedExtension(subscriptionDomainRemovedEvent.getDomainName()); + try { + SubscriptionDomainRemovedEvent subscriptionDomainRemovedEvent = (SubscriptionDomainRemovedEvent) event; + ExtensionUtils.executeSubscriptionDomainRemovedExtension( + subscriptionDomainRemovedEvent.getTenantId(), + findTenantDomain(subscriptionDomainRemovedEvent.getTenantId()), + subscriptionDomainRemovedEvent.getDomainName()); + } + catch (Exception e) { + if(log.isErrorEnabled()) { + log.error("Could not process subscription domain removed event", e); + } + } } }); @@ -203,6 +225,20 @@ public class CartridgeAgent implements Runnable { } } + private String findTenantDomain(int tenantId) { + try { + TenantManager.acquireReadLock(); + Tenant tenant = TenantManager.getInstance().getTenant(tenantId); + if(tenant == null) { + throw new RuntimeException(String.format("Tenant could not be found: [tenant-id] %d", tenantId)); + } + return tenant.getTenantDomain(); + } + finally { + TenantManager.releaseReadLock(); + } + } + protected void validateRequiredSystemProperties() { String jndiPropertiesDir = System.getProperty(CartridgeAgentConstants.JNDI_PROPERTIES_DIR); if(StringUtils.isBlank(jndiPropertiesDir)) { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d6843ebe/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java index 5bd922d..a29cc8b 100644 --- a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java +++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java @@ -133,12 +133,13 @@ public class ExtensionUtils { } } - public static void executeSubscriptionDomainAddedExtension(String domain, String applicationContext) { + public static void executeSubscriptionDomainAddedExtension(int tenantId, String tenantDomain, String domainName, String applicationContext) { try { if(log.isDebugEnabled()) { - log.debug("Executing subscription domain added extension: [domain] %s [application-context] %s"); + log.debug(String.format("Executing subscription domain added extension: [tenant-id] %d [tenant-domain] %s " + + "[domain-name] %s [application-context] %s", tenantId, tenantDomain, domainName, applicationContext)); } - String command = prepareCommand(CartridgeAgentConstants.SUBSCRIPTION_DOMAIN_ADDED_SH + " " + domain + " " + applicationContext); + String command = prepareCommand(CartridgeAgentConstants.SUBSCRIPTION_DOMAIN_ADDED_SH + " " + domainName + " " + applicationContext); CommandUtils.executeCommand(command); } catch (Exception e) { @@ -146,12 +147,13 @@ public class ExtensionUtils { } } - public static void executeSubscriptionDomainRemovedExtension(String domain) { + public static void executeSubscriptionDomainRemovedExtension(int tenantId, String tenantDomain, String domainName) { try { if(log.isDebugEnabled()) { - log.debug("Executing subscription domain removed extension: [domain] %s"); + log.debug(String.format("Executing subscription domain removed extension: [tenant-id] %d [tenant-domain] %s " + + "[domain-name] %s [application-context] %s", tenantId, tenantDomain, domainName)); } - String command = prepareCommand(CartridgeAgentConstants.SUBSCRIPTION_DOMAIN_ADDED_SH + " " + domain); + String command = prepareCommand(CartridgeAgentConstants.SUBSCRIPTION_DOMAIN_REMOVED_SH + " " + domainName); CommandUtils.executeCommand(command); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d6843ebe/products/cartridge-agent/modules/distribution/src/main/extensions/subscription-domain-added.sh ---------------------------------------------------------------------- diff --git a/products/cartridge-agent/modules/distribution/src/main/extensions/subscription-domain-added.sh b/products/cartridge-agent/modules/distribution/src/main/extensions/subscription-domain-added.sh new file mode 100644 index 0000000..0ae36f5 --- /dev/null +++ b/products/cartridge-agent/modules/distribution/src/main/extensions/subscription-domain-added.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# 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. +# +# -------------------------------------------------------------- +# This extension script will be executed when a subscription domain added +# event is received by the cartridge agent. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo "Subscription domain added: [tenant-id] $1 [tenant-domain] $2 [domain-name] $3 [application-context] $4" | tee -a $log \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d6843ebe/products/cartridge-agent/modules/distribution/src/main/extensions/subscription-domain-removed.sh ---------------------------------------------------------------------- diff --git a/products/cartridge-agent/modules/distribution/src/main/extensions/subscription-domain-removed.sh b/products/cartridge-agent/modules/distribution/src/main/extensions/subscription-domain-removed.sh new file mode 100644 index 0000000..76480bc --- /dev/null +++ b/products/cartridge-agent/modules/distribution/src/main/extensions/subscription-domain-removed.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# 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. +# +# -------------------------------------------------------------- +# This extension script will be executed when a subscription domain removed +# event is received by the cartridge agent. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo "Subscription domain added: [tenant-id] $1 [tenant-domain] $2 [domain-name] $3" | tee -a $log \ No newline at end of file
