You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/05 12:32:46 UTC
[09/34] adding changes to adc components
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/pom.xml b/components/org.apache.stratos.adc.topology.mgt/2.1.3/pom.xml
new file mode 100644
index 0000000..9b9bcce
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/pom.xml
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-components-parent</artifactId>
+ <version>2.0.0</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.adc.topology.mgt</artifactId>
+ <packaging>bundle</packaging>
+ <version>2.1.3</version>
+ <name>Apache Stratos - Topology Management</name>
+ <url>http://apache.org</url>
+
+ <dependencies>
+ <!-- <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.mediation.initializer</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency> -->
+ <!-- <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.mediation.dependency.mgt</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency> -->
+ <dependency>
+ <groupId>org.apache.synapse</groupId>
+ <artifactId>synapse-core</artifactId>
+ <version>${synapse.core.version}</version>
+ </dependency>
+ <!--dependency>
+ <groupId>org.apache.axis2.wso2</groupId>
+ <artifactId>axis2</artifactId>
+ <version>1.6.1.wso2v9</version>
+ </dependency-->
+ <dependency>
+ <groupId>org.apache.axis2</groupId>
+ <artifactId>axis2-kernel</artifactId>
+ <version>${axis2.kernel.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.logging</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.utils</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.core</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.lb.common</artifactId>
+ <version>4.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.ntask.core</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.andes.wso2</groupId>
+ <artifactId>andes-client</artifactId>
+ <version>0.13.wso2v3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs.wso2</groupId>
+ <artifactId>geronimo-jms_1.1_spec</artifactId>
+ <version>${orbit.version.geronimo-jms_1.1_spec}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <!-- <Private-Package>
+ org.wso2.carbon.stratos.topology.mgt.service.impl.*
+ </Private-Package> -->
+ <Export-Package>
+ org.apache.stratos.adc.topology.mgt.subscriber.*,
+ org.apache.stratos.adc.topology.mgt.service.*,
+ org.apache.stratos.adc.topology.mgt.group.mgt.*,
+ org.apache.stratos.adc.topology.mgt.serviceobjects.*
+ </Export-Package>
+ <Import-Package>
+ org.apache.stratos.lb.common.*; version=4.1.3,
+ org.apache.stratos.registry.core.service; version=1.0.1,
+ *;resolution:=optional
+ </Import-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/builder/TopologySyncher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/builder/TopologySyncher.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/builder/TopologySyncher.java
new file mode 100644
index 0000000..71acee0
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/builder/TopologySyncher.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. 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.topology.mgt.builder;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.group.mgt.GroupMgtAgentBuilder;
+import org.apache.stratos.adc.topology.mgt.util.ConfigHolder;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.ServiceConfiguration;
+import org.apache.stratos.lb.common.conf.structure.Node;
+import org.apache.stratos.lb.common.conf.structure.NodeBuilder;
+
+
+public class TopologySyncher implements Runnable {
+
+ @SuppressWarnings("rawtypes")
+ private BlockingQueue sharedQueue;
+ private static final Log log = LogFactory.getLog(TopologySyncher.class);
+
+ public TopologySyncher(@SuppressWarnings("rawtypes") BlockingQueue queue){
+
+ sharedQueue = queue;
+
+ }
+
+ public void run() {
+
+ LoadBalancerConfiguration lbconfig = LoadBalancerConfiguration.getInstance();
+
+ //FIXME Currently there has to be at least one dummy cluster defined in the loadbalancer conf
+ // in order to proper initialization of TribesClusteringAgent.
+ generateGroupMgtAgents(lbconfig);
+
+ while (true) {
+ try {
+
+ Object obj;
+ String msg = null;
+
+ obj = sharedQueue.take();
+ msg = (String) obj;
+
+ ConfigHolder data = ConfigHolder.getInstance();
+
+ Node topologyNode = NodeBuilder.buildNode(msg);
+
+ List<ServiceConfiguration> currentServiceConfigs = lbconfig.createServicesConfig(topologyNode);
+
+ data.setServiceConfigs(lbconfig.getServiceNameToServiceConfigurations());
+ generateGroupMgtAgents(lbconfig);
+ resetGroupMgtAgents(lbconfig, currentServiceConfigs);
+
+ } catch (InterruptedException ignore) {
+ }
+ }
+
+ }
+
+ /**
+ * @param lbconfig
+ */
+ private void generateGroupMgtAgents(LoadBalancerConfiguration lbconfig) {
+ for (List<ServiceConfiguration> serviceConfigsList : lbconfig.getServiceNameToServiceConfigurations()
+ .values()) {
+
+ for (ServiceConfiguration serviceConfiguration : serviceConfigsList) {
+ GroupMgtAgentBuilder.createGroupMgtAgent(serviceConfiguration.getDomain(),
+ serviceConfiguration.getSubDomain());
+ }
+ }
+ }
+
+ private void resetGroupMgtAgents(LoadBalancerConfiguration lbConfig,
+ List<ServiceConfiguration> currentServiceConfigs) {
+
+ for (Iterator<?> iterator = lbConfig.getServiceConfigurations().values().iterator(); iterator.hasNext();) {
+ @SuppressWarnings("unchecked")
+ Map<String, ServiceConfiguration> valuesMap = (Map<String, ServiceConfiguration>) iterator.next();
+
+ for (Iterator<ServiceConfiguration> iterator2 = valuesMap.values().iterator(); iterator2.hasNext();) {
+ ServiceConfiguration oldServiceConfig = (ServiceConfiguration) iterator2.next();
+
+ if (!currentServiceConfigs.contains(oldServiceConfig)) {
+ // if the ServiceConfiguration is not there any more in the latest topology
+ lbConfig.removeServiceConfiguration(oldServiceConfig.getDomain(), oldServiceConfig.getSubDomain());
+ GroupMgtAgentBuilder.resetGroupMgtAgent(oldServiceConfig.getDomain(), oldServiceConfig.getSubDomain());
+ }
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/exception/TopologyMgtException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/exception/TopologyMgtException.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/exception/TopologyMgtException.java
new file mode 100644
index 0000000..51faeb8
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/exception/TopologyMgtException.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.topology.mgt.exception;
+
+public class TopologyMgtException extends RuntimeException {
+
+ private static final long serialVersionUID = -663839410798538370L;
+
+ public TopologyMgtException(String msg) {
+ super(msg);
+ }
+
+ public TopologyMgtException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+ public TopologyMgtException(Throwable cause) {
+ super(cause);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/group/mgt/GroupMgtAgentBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/group/mgt/GroupMgtAgentBuilder.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/group/mgt/GroupMgtAgentBuilder.java
new file mode 100644
index 0000000..1ef804f
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/group/mgt/GroupMgtAgentBuilder.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. 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.topology.mgt.group.mgt;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.axis2.clustering.ClusteringAgent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.util.ConfigHolder;
+import org.apache.synapse.SynapseException;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
+import org.apache.stratos.lb.common.conf.util.HostContext;
+import org.apache.stratos.lb.common.conf.util.TenantDomainContext;
+
+public class GroupMgtAgentBuilder {
+
+ private static LoadBalancerConfiguration lbConfig;
+ /**
+ * Key - host name
+ * Value - {@link HostContext}
+ */
+ private static Map<String, HostContext> hostContexts = new HashMap<String, HostContext>();
+
+ private static final Log log = LogFactory.getLog(GroupMgtAgentBuilder.class);
+
+ public static void createGroupMgtAgents() {
+ lbConfig = ConfigHolder.getInstance().getLbConfig();
+ hostContexts = lbConfig.getHostContextMap();
+
+ ClusteringAgent clusteringAgent = ConfigHolder.getInstance().getAxisConfiguration().getClusteringAgent();
+ if (clusteringAgent == null) {
+ throw new SynapseException("Axis2 ClusteringAgent not defined in axis2.xml");
+ }
+
+ // Add the Axis2 GroupManagement agents
+ if (hostContexts != null) {
+ // iterate through each host context
+ for (HostContext hostCtxt : hostContexts.values()) {
+ // each host can has multiple Tenant Contexts, iterate through them
+ for (TenantDomainContext tenantCtxt : hostCtxt.getTenantDomainContexts()) {
+
+ String domain = tenantCtxt.getDomain();
+ String subDomain = tenantCtxt.getSubDomain();
+
+ if (clusteringAgent.getGroupManagementAgent(domain, subDomain) == null) {
+ clusteringAgent.addGroupManagementAgent(new SubDomainAwareGroupManagementAgent(
+ subDomain),
+ domain, subDomain, -1);
+ log.info("Group management agent added to cluster domain: " +
+ domain + " and sub domain: " + subDomain);
+ }
+ }
+ }
+ }
+ }
+
+ public static void createGroupMgtAgent(String domain, String subDomain) {
+
+ ClusteringAgent clusteringAgent = ConfigHolder.getInstance().getAxisConfiguration().getClusteringAgent();
+ if (clusteringAgent == null) {
+ throw new SynapseException("Axis2 ClusteringAgent not defined in axis2.xml");
+ }
+
+ if (clusteringAgent.getGroupManagementAgent(domain, subDomain) == null) {
+ clusteringAgent.addGroupManagementAgent(new SubDomainAwareGroupManagementAgent(
+ subDomain),
+ domain, subDomain, -1);
+ log.info("Group management agent added to cluster domain: " +
+ domain + " and sub domain: " + subDomain);
+ }
+ }
+
+ public static void resetGroupMgtAgent(String domain, String subDomain) {
+
+ ClusteringAgent clusteringAgent =
+ ConfigHolder.getInstance().getAxisConfiguration().getClusteringAgent();
+
+ if (clusteringAgent == null) {
+ throw new SynapseException("Axis2 Clustering Agent not defined in axis2.xml");
+ }
+
+ // checks the existence.
+ if (clusteringAgent.getGroupManagementAgent(domain, subDomain) != null) {
+
+ clusteringAgent.resetGroupManagementAgent(domain, subDomain);
+
+ log.info("Group management agent of cluster domain: " +
+ domain + " and sub domain: " + subDomain+" is removed.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/group/mgt/SubDomainAwareGroupManagementAgent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/group/mgt/SubDomainAwareGroupManagementAgent.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/group/mgt/SubDomainAwareGroupManagementAgent.java
new file mode 100644
index 0000000..d674c4c
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/group/mgt/SubDomainAwareGroupManagementAgent.java
@@ -0,0 +1,32 @@
+package org.apache.stratos.adc.topology.mgt.group.mgt;
+
+import org.apache.axis2.clustering.Member;
+import org.apache.axis2.clustering.management.DefaultGroupManagementAgent;
+
+/**
+ * This GroupManagementAgent can handle group membership based on cluster sub-domains
+ */
+public class SubDomainAwareGroupManagementAgent extends DefaultGroupManagementAgent {
+
+ private String subDomain;
+
+ public SubDomainAwareGroupManagementAgent(String subDomain) {
+ this.subDomain = subDomain;
+ }
+
+ @Override
+ public void applicationMemberAdded(Member member) {
+ String subDomain = member.getProperties().getProperty("subDomain");
+ if (subDomain == null || subDomain.equals(this.subDomain)) {
+ super.applicationMemberAdded(member);
+ }
+ }
+
+ @Override
+ public void applicationMemberRemoved(Member member) {
+ String subDomain = member.getProperties().getProperty("subDomain");
+ if (subDomain == null || subDomain.equals(this.subDomain)) {
+ super.applicationMemberRemoved(member);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/internal/TopologyMgtDSComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/internal/TopologyMgtDSComponent.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/internal/TopologyMgtDSComponent.java
new file mode 100644
index 0000000..2500485
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/internal/TopologyMgtDSComponent.java
@@ -0,0 +1,290 @@
+/*
+ * Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.topology.mgt.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.builder.TopologySyncher;
+import org.apache.stratos.adc.topology.mgt.service.TopologyManagementService;
+import org.apache.stratos.adc.topology.mgt.service.impl.TopologyManagementServiceImpl;
+import org.apache.stratos.adc.topology.mgt.subscriber.TopologySubscriber;
+import org.apache.stratos.adc.topology.mgt.util.ConfigHolder;
+import org.apache.stratos.adc.topology.mgt.util.TopologyConstants;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.utils.ConfigurationContextService;
+import org.apache.stratos.lb.common.service.LoadBalancerConfigurationService;
+import org.wso2.carbon.ntask.core.service.TaskService;
+
+//* @scr.reference name="synapse.config.service"
+//* interface="org.wso2.carbon.mediation.initializer.services.SynapseConfigurationService"
+//* cardinality="1..1" policy="dynamic" bind="setSynapseConfigurationService"
+//* unbind="unsetSynapseConfigurationService"
+//* @scr.reference name="registry.service"
+//* interface="org.wso2.carbon.registry.core.service.RegistryService"
+//* cardinality="1..1" policy="dynamic"
+//* bind="setRegistryService" unbind="unsetRegistryService"
+//* @scr.reference name="dependency.mgt.service"
+//* interface="org.wso2.carbon.mediation.dependency.mgt.services.DependencyManagementService"
+//* cardinality="0..1" policy="dynamic"
+//* bind="setDependencyManager" unbind="unsetDependencyManager"
+//* @scr.reference name="user.realmservice.default"
+//* interface="org.wso2.carbon.user.core.service.RealmService"
+//* cardinality="1..1" policy="dynamic" bind="setRealmService"
+//* unbind="unsetRealmService"
+
+/**
+ * @scr.component name="topology.mgt.service" immediate="true"
+ * @scr.reference name="configuration.context.service"
+ * interface="org.wso2.carbon.utils.ConfigurationContextService" cardinality="1..1"
+ * policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
+ * @scr.reference name="org.apache.stratos.lb.common"
+ * interface="org.apache.stratos.lb.common.service.LoadBalancerConfigurationService"
+ * cardinality="1..1" policy="dynamic" bind="setLoadBalancerConfigurationService"
+ * unbind="unsetLoadBalancerConfigurationService"
+ * @scr.reference name="ntask.component" interface="org.wso2.carbon.ntask.core.service.TaskService"
+ * cardinality="1..1" policy="dynamic" bind="setTaskService" unbind="unsetTaskService"
+ */
+@SuppressWarnings({"UnusedDeclaration", "JavaDoc"})
+public class TopologyMgtDSComponent {
+
+ private static final Log log = LogFactory.getLog(TopologyMgtDSComponent.class);
+
+// private boolean activated = false;
+
+ protected void activate(ComponentContext ctxt) {
+ try {
+ // start consumer
+ // initialize TopologyBuilder Consumer
+ if (System.getProperty("mb.server.ip") != null) {
+ Thread topologyConsumer = new Thread(new TopologySyncher(ConfigHolder.getInstance().getSharedTopologyDiffQueue()));
+ // start consumer
+ topologyConsumer.start();
+
+ TopologySubscriber.subscribe(TopologyConstants.TOPIC_NAME);
+ }
+
+
+ BundleContext bundleContext = ctxt.getBundleContext();
+ bundleContext.registerService(TopologyManagementService.class.getName(),
+ new TopologyManagementServiceImpl(), null);
+
+ log.debug("******* Topology Mgt Service bundle is activated ******* ");
+ } catch (Throwable e) {
+ log.error("******* Topology Mgt Service Service bundle is failed to activate ****", e);
+ }
+// log.info("**************************************");
+// for (String str : ConfigHolder.getInstance().getLbConfig().getServiceDomains()) {
+// log.info(str);
+// }
+// log.info("**************************************");
+
+// if(!activated){
+// GroupMgtAgentBuilder.createGroupMgtAgents();
+// activated = true;
+// }
+
+
+ // topology synching task activation
+// TaskManager tm = null;
+// try {
+// // topology sync
+// ConfigHolder.getInstance().getTaskService()
+// .registerTaskType(TopologyConstants.TOPOLOGY_SYNC_TASK_TYPE);
+//
+// tm =
+// ConfigHolder.getInstance().getTaskService()
+// .getTaskManager(TopologyConstants.TOPOLOGY_SYNC_TASK_TYPE);
+//
+// TriggerInfo triggerInfo = new TriggerInfo(TopologyConstants.TOPOLOGY_SYNC_CRON);
+// TaskInfo taskInfo =
+// new TaskInfo(TopologyConstants.TOPOLOGY_SYNC_TASK_NAME,
+// TopologySubscriberTask.class.getName(),
+// new HashMap<String, String>(), triggerInfo);
+// tm.registerTask(taskInfo);
+//
+// // start consumer
+// // initialize TopologyBuilder Consumer
+// Thread topologyConsumer = new Thread(new TopologyBuilder(ConfigHolder.getInstance().getSharedTopologyDiffQueue()));
+// // start consumer
+// topologyConsumer.start();
+//
+// } catch (Exception e) {
+// String msg = "Error scheduling task: " + TopologyConstants.TOPOLOGY_SYNC_TASK_NAME;
+// log.error(msg, e);
+// if (tm != null) {
+// try {
+// tm.deleteTask(TopologyConstants.TOPOLOGY_SYNC_TASK_NAME);
+// } catch (TaskException e1) {
+// log.error(e1);
+// }
+// }
+// throw new TopologyMgtException(msg, e);
+// }
+ }
+
+ protected void deactivate(ComponentContext context) {}
+
+ protected void setConfigurationContextService(ConfigurationContextService cfgCtxService) {
+ ConfigHolder.getInstance().setAxisConfiguration(
+ cfgCtxService.getServerConfigContext().getAxisConfiguration());
+ }
+
+ protected void unsetConfigurationContextService(ConfigurationContextService cfgCtxService) {
+ ConfigHolder.getInstance().setAxisConfiguration(null);
+ }
+
+// protected void setSynapseConfigurationService(
+// SynapseConfigurationService synapseConfigurationService) {
+//
+// ConfigHolder.getInstance().setSynapseConfiguration(
+// synapseConfigurationService.getSynapseConfiguration());
+// }
+//
+// protected void unsetSynapseConfigurationService(
+// SynapseConfigurationService synapseConfigurationService) {
+//
+// ConfigHolder.getInstance().setSynapseConfiguration(null);
+// }
+
+ /**
+ * Here we receive an event about the creation of a SynapseEnvironment. If this is
+ * SuperTenant we have to wait until all the other constraints are met and actual
+ * initialization is done in the activate method. Otherwise we have to do the activation here.
+ *
+ * @param synapseEnvironmentService SynapseEnvironmentService which contains information
+ * about the new Synapse Instance
+ */
+// protected void setSynapseEnvironmentService(
+// SynapseEnvironmentService synapseEnvironmentService) {
+// boolean alreadyCreated = ConfigHolder.getInstance().getSynapseEnvironmentServices().
+// containsKey(synapseEnvironmentService.getTenantId());
+//
+// ConfigHolder.getInstance().addSynapseEnvironmentService(
+// synapseEnvironmentService.getTenantId(),
+// synapseEnvironmentService);
+// if (activated) {
+// if (!alreadyCreated) {
+// try {
+// registerDeployer(synapseEnvironmentService.getConfigurationContext().getAxisConfiguration(),
+// synapseEnvironmentService.getSynapseEnvironment());
+// if (log.isDebugEnabled()) {
+// log.debug("Endpoint Admin bundle is activated ");
+// }
+// } catch (Throwable e) {
+// log.error("Failed to activate Endpoint Admin bundle ", e);
+// }
+// }
+// }
+// }
+
+// /**
+// * Here we receive an event about Destroying a SynapseEnvironment. This can be the super tenant
+// * destruction or a tenant destruction.
+// *
+// * @param synapseEnvironmentService synapseEnvironment
+// */
+// protected void unsetSynapseEnvironmentService(
+// SynapseEnvironmentService synapseEnvironmentService) {
+// ConfigHolder.getInstance().removeSynapseEnvironmentService(
+// synapseEnvironmentService.getTenantId());
+// }
+//
+// protected void setRegistryService(RegistryService regService) {
+// if (log.isDebugEnabled()) {
+// log.debug("RegistryService bound to the endpoint component");
+// }
+// try {
+// ConfigHolder.getInstance().setConfigRegistry(regService.getConfigSystemRegistry());
+// ConfigHolder.getInstance().setGovernanceRegistry(regService.getGovernanceSystemRegistry());
+// } catch (RegistryException e) {
+// log.error("Couldn't retrieve the registry from the registry service");
+// }
+// }
+//
+// protected void unsetRegistryService(RegistryService regService) {
+// if (log.isDebugEnabled()) {
+// log.debug("RegistryService unbound from the endpoint component");
+// }
+// ConfigHolder.getInstance().setConfigRegistry(null);
+// }
+//
+// protected void setDependencyManager(DependencyManagementService dependencyMgr) {
+// if (log.isDebugEnabled()) {
+// log.debug("Dependency management service bound to the endpoint component");
+// }
+// ConfigHolder.getInstance().setDependencyManager(dependencyMgr);
+// }
+//
+// protected void unsetDependencyManager(DependencyManagementService dependencyMgr) {
+// if (log.isDebugEnabled()) {
+// log.debug("Dependency management service unbound from the endpoint component");
+// }
+// ConfigHolder.getInstance().setDependencyManager(null);
+// }
+//
+// protected void setSynapseRegistrationsService(
+// SynapseRegistrationsService synapseRegistrationsService) {
+//
+// }
+
+// protected void unsetSynapseRegistrationsService(
+// SynapseRegistrationsService synapseRegistrationsService) {
+// int tenantId = synapseRegistrationsService.getTenantId();
+// if (ConfigHolder.getInstance().getSynapseEnvironmentServices().containsKey(tenantId)) {
+// SynapseEnvironment env = ConfigHolder.getInstance().
+// getSynapseEnvironmentService(tenantId).getSynapseEnvironment();
+//
+// ConfigHolder.getInstance().removeSynapseEnvironmentService(
+// synapseRegistrationsService.getTenantId());
+//
+// AxisConfiguration axisConfig = synapseRegistrationsService.getConfigurationContext().
+// getAxisConfiguration();
+// if (axisConfig != null) {
+// try {
+// unregisterDeployer(axisConfig, env);
+// } catch (Exception e) {
+// log.warn("Couldn't remove the EndpointDeployer");
+// }
+// }
+// }
+// }
+
+// protected void setRealmService(RealmService realmService) {
+// ConfigHolder.getInstance().setRealmService(realmService);
+// }
+//
+// protected void unsetRealmService(RealmService realmService) {
+// ConfigHolder.getInstance().setRealmService(null);
+// }
+//
+ protected void setLoadBalancerConfigurationService(LoadBalancerConfigurationService lbConfigSer){
+ ConfigHolder.getInstance().setLbConfigService(lbConfigSer);
+ }
+
+ protected void unsetLoadBalancerConfigurationService(LoadBalancerConfigurationService lbConfigSer){
+ ConfigHolder.getInstance().setLbConfigService(null);
+ }
+
+ protected void setTaskService(TaskService taskService) {
+ ConfigHolder.getInstance().setTaskService(taskService);
+ }
+
+ protected void unsetTaskService(TaskService taskService) {
+ ConfigHolder.getInstance().setTaskService(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/service/TopologyManagementService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/service/TopologyManagementService.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/service/TopologyManagementService.java
new file mode 100644
index 0000000..9b490e9
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/service/TopologyManagementService.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.topology.mgt.service;
+
+import org.apache.stratos.adc.topology.mgt.serviceobjects.DomainContext;
+
+/**
+ * This exposes details regarding up-to-date topology
+ *
+ */
+public interface TopologyManagementService {
+
+ /**
+ * Provide service cluster domains corresponds to the given information.
+ * @param cartridgeType cartridge type
+ * @param tenantId tenant id
+ * @return String array of service cluster domains
+ */
+ String[] getDomains(String cartridgeType, int tenantId);
+
+ /**
+ * Provide service cluster sub domains corresponds to the given information.
+ * @param cartridgeType cartridge type
+ * @param tenantId tenant id
+ * @return String array of service cluster sub domains
+ */
+ String[] getSubDomains(String cartridgeType, int tenantId);
+
+// /**
+// * Provide public IPs corresponds to the given information.
+// * @param cartridgeType cartridge type
+// * @param tenantId tenant id
+// * @return String array of public IPs
+// */
+// String[] getActiveIPs(String cartridgeType, int tenantId);
+
+ /**
+ * Provide public IPs corresponds to the given information.
+ * @param cartridgeType cartridge type
+ * @param domain service cluster domain
+ * @param subDomain service cluster sub domain
+ * @return String array of public IPs
+ */
+ String[] getActiveIPs(String cartridgeType, String domain, String subDomain);
+
+ /**
+ * Provide domains and the relevant subdomains corresponding to the given information
+ *
+ * @param cartridgeType cartridge type
+ * @param tenantId tenant id
+ * @return DomainContext instances array of domains and sub domains
+ */
+ DomainContext[] getDomainsAndSubdomains (String cartridgeType, int tenantId);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/service/impl/TopologyManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/service/impl/TopologyManagementServiceImpl.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/service/impl/TopologyManagementServiceImpl.java
new file mode 100644
index 0000000..9b976cf
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/service/impl/TopologyManagementServiceImpl.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.topology.mgt.service.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stratos.adc.topology.mgt.service.TopologyManagementService;
+import org.apache.stratos.adc.topology.mgt.serviceobjects.DomainContext;
+import org.apache.stratos.adc.topology.mgt.util.ConfigHolder;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.ServiceConfiguration;
+import org.apache.stratos.lb.common.conf.util.LoadBalancerConfigUtil;
+
+public class TopologyManagementServiceImpl implements TopologyManagementService {
+
+ ConfigHolder data = ConfigHolder.getInstance();
+
+ public String[] getDomains(String cartridgeType, int tenantId) {
+ List<String> domains = new ArrayList<String>();
+ if(data.getServiceConfigs() != null){
+ List<ServiceConfiguration> serviceConfigs = data.getServiceConfigs().get(cartridgeType);
+ if(serviceConfigs != null){
+
+ for (ServiceConfiguration serviceConfiguration : serviceConfigs) {
+
+ List<Integer> tenantIds = LoadBalancerConfigUtil.getTenantIds(serviceConfiguration.getTenantRange());
+ if(!tenantIds.isEmpty() && (tenantIds.contains(tenantId) || tenantIds.contains(0))){
+ if (!domains.contains(serviceConfiguration.getDomain())) {
+ domains.add(serviceConfiguration.getDomain());
+ }
+ }
+ }
+ }
+ }
+ return domains.toArray(new String[domains.size()]);
+ }
+
+ public String[] getSubDomains(String cartridgeType, int tenantId) {
+ List<String> subDomains = new ArrayList<String>();
+ if(data.getServiceConfigs() != null){
+ List<ServiceConfiguration> serviceConfigs = data.getServiceConfigs().get(cartridgeType);
+ if(serviceConfigs != null){
+
+ for (ServiceConfiguration serviceConfiguration : serviceConfigs) {
+
+ List<Integer> tenantIds = LoadBalancerConfigUtil.getTenantIds(serviceConfiguration.getTenantRange());
+ if(!tenantIds.isEmpty() && (tenantIds.contains(tenantId) || tenantIds.contains(0))){
+ if (!subDomains.contains(serviceConfiguration.getSubDomain())) {
+ subDomains.add(serviceConfiguration.getSubDomain());
+ }
+ }
+ }
+ }
+ }
+ return subDomains.toArray(new String[subDomains.size()]);
+ }
+
+ public String[] getActiveIPs(String cartridgeType, String domain, String subDomain) {
+ List<String> publicIps = new ArrayList<String>();
+
+ if(domain == null || subDomain == null){
+ return new String[0];
+ }
+
+ if(data.getServiceConfigs() != null){
+ List<ServiceConfiguration> serviceConfigs = data.getServiceConfigs().get(cartridgeType);
+ if(serviceConfigs != null){
+
+ for (ServiceConfiguration serviceConfiguration : serviceConfigs) {
+
+ if(domain.equals(serviceConfiguration.getDomain()) && subDomain.equals(serviceConfiguration.getSubDomain())){
+
+ String ipStr = serviceConfiguration.getPublicIp();
+ if(ipStr != null && !ipStr.isEmpty()){
+ for (String ip : ipStr.split(",")) {
+ if (!publicIps.contains(ip)) {
+ publicIps.add(ip);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return publicIps.toArray(new String[publicIps.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.wso2.carbon.stratos.topology.mgt.service.TopologyManagementService#getDomainsAndSubdomains(java.lang.String, int)
+ */
+ public DomainContext[] getDomainsAndSubdomains(String cartridgeType, int tenantId) {
+ List<DomainContext> domainContexts = new ArrayList<DomainContext>();
+
+ if(data.getServiceConfigs() != null){
+ List<ServiceConfiguration> serviceConfigs = data.getServiceConfigs().get(cartridgeType);
+ if(serviceConfigs != null){
+
+ for (ServiceConfiguration serviceConfiguration : serviceConfigs) {
+
+ List<Integer> tenantIds = LoadBalancerConfigUtil.getTenantIds(serviceConfiguration.getTenantRange());
+ if(!tenantIds.isEmpty() && (tenantIds.contains(tenantId) || tenantIds.contains(0))){
+ DomainContext domainCtx = new DomainContext(serviceConfiguration.getDomain(), serviceConfiguration.getSubDomain());
+ if (!domainContexts.contains(domainCtx)) {
+ domainContexts.add(domainCtx);
+ }
+ }
+ }
+ }
+ }
+ return domainContexts.toArray(new DomainContext[domainContexts.size()]);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/serviceobjects/DomainContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/serviceobjects/DomainContext.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/serviceobjects/DomainContext.java
new file mode 100644
index 0000000..54357d2
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/serviceobjects/DomainContext.java
@@ -0,0 +1,90 @@
+/**
+ * Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.topology.mgt.serviceobjects;
+
+/**
+ * Class to hold domain and subdomain details
+ *
+ */
+public class DomainContext {
+
+ private String domain;
+ private String subDomain;
+
+ /**
+ * Constructor
+ *
+ * @param domain domain name
+ * @param subDomain subdomain name
+ */
+ public DomainContext (String domain, String subDomain) {
+ this.domain = domain;
+ this.subDomain = subDomain;
+ }
+
+ /**
+ * Returns the domain
+ *
+ * @return the domain
+ */
+ public String getDomain() {
+ return domain;
+ }
+
+ /**
+ * Returns the sub domain
+ *
+ * @return the subDomain
+ */
+ public String getSubDomain() {
+ return subDomain;
+ }
+
+ /**
+ * Overridden equals method
+ */
+ public boolean equals (Object object) {
+ if (object == null)
+ return false;
+ if (object == this)
+ return true;
+ if (!(object instanceof DomainContext))
+ return false;
+
+ DomainContext domainCtx = (DomainContext)object;
+ if(this.getDomain().equals(domainCtx.getDomain()) &&
+ this.getSubDomain().equals(domainCtx.getSubDomain()))
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * Overridden hashCode method
+ */
+ public int hashCode () {
+ int domainHash = 0;
+ int subDomainHash = 0;
+
+ if(domain != null)
+ domainHash = domain.hashCode();
+ if(subDomain != null)
+ subDomainHash = subDomain.hashCode();
+
+ return domainHash + subDomainHash;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopicHealthChecker.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopicHealthChecker.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopicHealthChecker.java
new file mode 100644
index 0000000..de8f9df
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopicHealthChecker.java
@@ -0,0 +1,67 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.topology.mgt.subscriber;
+
+import javax.jms.TopicSubscriber;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This health checker runs forever, and is responsible for re-establishing a connection
+ * between SC and CC.
+ */
+public class TopicHealthChecker implements Runnable{
+
+ private static final Log log = LogFactory.getLog(TopicHealthChecker.class);
+ private String topicName;
+ private TopicSubscriber subscriber;
+
+ public TopicHealthChecker(String topicName, TopicSubscriber subscriber) {
+ this.topicName = topicName;
+ this.subscriber = subscriber;
+ }
+
+ @Override
+ public void run() {
+ log.info("Topic Health Checker is running... ");
+
+ while (true) {
+ try {
+ subscriber.getTopic();
+
+ // health checker runs in every 30s
+ Thread.sleep(30000);
+
+ } catch (Exception e) {
+ // implies connection is not established
+ // sleep for 5s and retry
+ try {
+ log.info("Health checker failed and will retry to establish a connection after a 5s.");
+ Thread.sleep(5000);
+ break;
+ } catch (InterruptedException ignore) {
+ }
+ }
+
+ }
+
+ TopologySubscriber.subscribe(topicName);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologyListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologyListener.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologyListener.java
new file mode 100644
index 0000000..57289d7
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologyListener.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.topology.mgt.subscriber;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.util.ConfigHolder;
+
+public class TopologyListener implements MessageListener {
+
+ private static final Log log = LogFactory.getLog(TopologyListener.class);
+
+ @SuppressWarnings("unchecked")
+ public void onMessage(Message message) {
+ TextMessage receivedMessage = (TextMessage) message;
+ try {
+
+ ConfigHolder.getInstance().getSharedTopologyDiffQueue().add(receivedMessage.getText());
+
+ } catch (JMSException e) {
+ log.error(e.getMessage(), e);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriber.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriber.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriber.java
new file mode 100644
index 0000000..97bf94f
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriber.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.topology.mgt.subscriber;
+
+import java.util.Properties;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.util.TopologyConstants;
+
+public class TopologySubscriber {
+
+ private static final Log log = LogFactory.getLog(TopologySubscriber.class);
+
+ public static void subscribe(String topicName) {
+ Properties initialContextProperties = new Properties();
+ TopicSubscriber topicSubscriber = null;
+ TopicSession topicSession = null;
+ TopicConnection topicConnection = null;
+ InitialContext initialContext = null;
+
+ initialContextProperties.put("java.naming.factory.initial",
+ "org.wso2.andes.jndi.PropertiesFileInitialContextFactory");
+
+ String mbServerIp =
+ System.getProperty(TopologyConstants.MB_SERVER_IP) == null
+ ? TopologyConstants.DEFAULT_MB_SERVER_IP
+ : System.getProperty(TopologyConstants.MB_SERVER_IP);
+
+ String connectionString =
+ "amqp://admin:admin@clientID/carbon?brokerlist='tcp://" +
+ mbServerIp + "'&reconnect='true'";
+ initialContextProperties.put("connectionfactory.qpidConnectionfactory", connectionString);
+
+ try {
+ initialContext = new InitialContext(initialContextProperties);
+ TopicConnectionFactory topicConnectionFactory =
+ (TopicConnectionFactory) initialContext.lookup("qpidConnectionfactory");
+ topicConnection = topicConnectionFactory.createTopicConnection();
+ topicConnection.start();
+ topicSession =
+ topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Topic topic = topicSession.createTopic(topicName);
+ topicSubscriber =
+ topicSession.createSubscriber(topic);
+
+ topicSubscriber.setMessageListener(new TopologyListener());
+
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+
+ try {
+ if (topicSubscriber != null) {
+ topicSubscriber.close();
+ }
+
+ if (topicSession != null) {
+ topicSession.close();
+ }
+
+ if (topicConnection != null) {
+ topicConnection.close();
+ }
+ } catch (JMSException e1) {
+ // ignore
+ }
+
+ } finally {
+ // start the health checker
+ Thread healthChecker = new Thread(new TopicHealthChecker(topicName, topicSubscriber));
+ healthChecker.start();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriberTask.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriberTask.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriberTask.java
new file mode 100644
index 0000000..525de89
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/subscriber/TopologySubscriberTask.java
@@ -0,0 +1 @@
+package org.apache.stratos.adc.topology.mgt.subscriber;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/ConfigHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/ConfigHolder.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/ConfigHolder.java
new file mode 100644
index 0000000..a45aa8f
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/ConfigHolder.java
@@ -0,0 +1,197 @@
+/**
+ * Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.topology.mgt.util;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.adc.topology.mgt.exception.TopologyMgtException;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
+import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.ServiceConfiguration;
+import org.apache.stratos.lb.common.service.LoadBalancerConfigurationService;
+import org.wso2.carbon.ntask.core.service.TaskService;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+import org.wso2.carbon.user.core.service.RealmService;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ *
+ */
+public class ConfigHolder {
+
+ private static ConfigHolder instance;
+ private static final Log log = LogFactory.getLog(ConfigHolder.class);
+
+ private SynapseConfiguration synapseConfiguration;
+ private ConfigurationContext configCtxt;
+ private AxisConfiguration axisConfiguration;
+ private UserRegistry configRegistry;
+ private UserRegistry governanceRegistry;
+ private TaskService taskService;
+ private BlockingQueue sharedTopologyDiffQueue = new LinkedBlockingQueue();
+ private String previousMessage;
+ private Map<String, List<ServiceConfiguration>> serviceNameToServiceConfigurations;
+// private DependencyManagementService dependencyManager;
+ private LoadBalancerConfigurationService lbConfigService;
+
+
+// private Map<Integer, SynapseEnvironmentService> synapseEnvironmentServices =
+// new HashMap<Integer, SynapseEnvironmentService>();
+
+ public RealmService getRealmService() {
+ return realmService;
+ }
+
+ public void setRealmService(RealmService realmService) {
+ this.realmService = realmService;
+ }
+
+ private RealmService realmService;
+
+ private ConfigHolder() {
+ }
+
+ public static ConfigHolder getInstance() {
+ if (instance == null) {
+ instance = new ConfigHolder();
+ }
+ return instance;
+ }
+
+ public SynapseConfiguration getSynapseConfiguration() throws TopologyMgtException{
+ assertNull("SynapseConfiguration", synapseConfiguration);
+ return synapseConfiguration;
+ }
+
+ public void setSynapseConfiguration(SynapseConfiguration synapseConfiguration) {
+ this.synapseConfiguration = synapseConfiguration;
+ }
+
+ public AxisConfiguration getAxisConfiguration() throws TopologyMgtException {
+ assertNull("AxisConfiguration", axisConfiguration);
+ return axisConfiguration;
+ }
+
+ public void setAxisConfiguration(AxisConfiguration axisConfiguration) {
+ this.axisConfiguration = axisConfiguration;
+ }
+
+ public UserRegistry getConfigRegistry() throws TopologyMgtException {
+ assertNull("Registry", configRegistry);
+ return configRegistry;
+ }
+
+ public void setConfigRegistry(UserRegistry configRegistry) {
+ this.configRegistry = configRegistry;
+ }
+
+//// public DependencyManagementService getDependencyManager() {
+//// return dependencyManager;
+//// }
+//
+// public void setDependencyManager(DependencyManagementService dependencyManager) {
+// this.dependencyManager = dependencyManager;
+// }
+
+ private void assertNull(String name, Object object) throws TopologyMgtException {
+ if (object == null) {
+ String message = name + " reference in the proxy admin config holder is null";
+ log.error(message);
+ throw new TopologyMgtException(message);
+ }
+ }
+
+ public UserRegistry getGovernanceRegistry() {
+ return governanceRegistry;
+ }
+
+ public void setGovernanceRegistry(UserRegistry governanceRegistry) {
+ this.governanceRegistry = governanceRegistry;
+ }
+
+// public SynapseEnvironmentService getSynapseEnvironmentService(int id) {
+// return synapseEnvironmentServices.get(id);
+// }
+//
+// public void addSynapseEnvironmentService(int id,
+// SynapseEnvironmentService synapseEnvironmentService) {
+// synapseEnvironmentServices.put(id, synapseEnvironmentService);
+// }
+//
+// public void removeSynapseEnvironmentService(int id) {
+// synapseEnvironmentServices.remove(id);
+// }
+//
+// public Map<Integer, SynapseEnvironmentService> getSynapseEnvironmentServices() {
+// return synapseEnvironmentServices;
+// }
+
+ public ConfigurationContext getConfigCtxt() {
+ return configCtxt;
+ }
+
+ public void setConfigCtxt(ConfigurationContext configCtxt) {
+ this.configCtxt = configCtxt;
+ }
+
+ public void setLbConfigService(LoadBalancerConfigurationService lbConfigSer) {
+ this.lbConfigService = lbConfigSer;
+ }
+
+ public LoadBalancerConfiguration getLbConfig() {
+ return (LoadBalancerConfiguration) lbConfigService.getLoadBalancerConfig();
+ }
+
+ public TaskService getTaskService() {
+ return taskService;
+ }
+
+ public void setTaskService(TaskService taskService) {
+ this.taskService = taskService;
+ }
+
+ public BlockingQueue getSharedTopologyDiffQueue() {
+ return sharedTopologyDiffQueue;
+ }
+
+ public void setSharedTopologyDiffQueue(BlockingQueue sharedTopologyDiffQueue) {
+ this.sharedTopologyDiffQueue = sharedTopologyDiffQueue;
+ }
+
+ public void setServiceConfigs(Map<String, List<ServiceConfiguration>> serviceNameToServiceConfigurations) {
+
+ this.serviceNameToServiceConfigurations = serviceNameToServiceConfigurations;
+ }
+
+ public Map<String, List<ServiceConfiguration>> getServiceConfigs(){
+ return serviceNameToServiceConfigurations;
+ }
+
+ public String getPreviousMessage() {
+ return previousMessage;
+ }
+
+ public void setPreviousMessage(String previousMessage) {
+ this.previousMessage = previousMessage;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyConstants.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyConstants.java
new file mode 100644
index 0000000..984610d
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyConstants.java
@@ -0,0 +1,13 @@
+package org.apache.stratos.adc.topology.mgt.util;
+
+public class TopologyConstants {
+
+ public static final String TOPIC_NAME = "cloud-controller-topology";
+ public static final String MB_SERVER_IP = "mb.server.ip";
+ public static final String DEFAULT_MB_SERVER_IP = "localhost:5673";
+
+ public static final String TOPOLOGY_SYNC_CRON = "1 * * * * ? *";
+ public static final String TOPOLOGY_SYNC_TASK_NAME = "TopologySubscriberTaskOfADC";
+ public static final String TOPOLOGY_SYNC_TASK_TYPE = "TOPOLOGY_SUBSCRIBER_TASK";
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyMgtUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyMgtUtil.java b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyMgtUtil.java
new file mode 100644
index 0000000..01ff6db
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/java/org/apache/stratos/adc/topology/mgt/util/TopologyMgtUtil.java
@@ -0,0 +1,5 @@
+package org.apache.stratos.adc.topology.mgt.util;
+
+public class TopologyMgtUtil {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/resources/META-INF/services.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/resources/META-INF/services.xml
new file mode 100644
index 0000000..ef91287
--- /dev/null
+++ b/components/org.apache.stratos.adc.topology.mgt/2.1.3/src/main/resources/META-INF/services.xml
@@ -0,0 +1,9 @@
+<serviceGroup>
+ <service name="TopologyMgtService" scope="application">
+ <parameter name="ServiceClass">org.apache.stratos.adc.topology.mgt.service.impl.TopologyManagementServiceImpl</parameter>
+ <messageReceivers>
+ <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
+ <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
+ </messageReceivers>
+ </service>
+</serviceGroup>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.wso2.carbon.adc.mgt.cli/2.1.3/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/pom.xml b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/pom.xml
new file mode 100644
index 0000000..5396a74
--- /dev/null
+++ b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/pom.xml
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- ~ Copyright (c) 2009-2010, WSO2 Inc. (http://www.wso2.org) All Rights
+ Reserved. ~ ~ Licensed 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>adc-mgt</artifactId>
+ <version>2.1.0</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.wso2.carbon.adc.mgt.cli</artifactId>
+ <version>2.1.3</version>
+ <packaging>jar</packaging>
+ <name>WSO2 Carbon - ADC Management CLI</name>
+ <description>ADC management CLI bundle</description>
+ <url>http://wso2.org</url>
+
+ <properties>
+ <slf4j.version>1.7.5</slf4j.version>
+ </properties>
+
+ <dependencies>
+ <!-- <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.ui</artifactId>
+ </dependency> -->
+ <!-- Adding HttpClient dependencies. Those were resolved with above one -->
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.securevault</groupId>
+ <artifactId>org.wso2.securevault</artifactId>
+ <version>1.0.0-wso2v2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents.wso2</groupId>
+ <artifactId>httpcore</artifactId>
+ <version>4.1.0-wso2v1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.adc.mgt.stub</artifactId>
+ <version>4.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>jline</groupId>
+ <artifactId>jline</artifactId>
+ <version>2.11</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-validator</groupId>
+ <artifactId>commons-validator</artifactId>
+ <version>1.4.0</version>
+ </dependency>
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.1</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.wso2.carbon.adc.mgt.cli.CliTool</mainClass>
+ </manifest>
+ </archive>
+ <descriptors>
+ <descriptor>src/main/assembly/src.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-assembly</id> <!-- this is used for inheritance merges -->
+ <phase>package</phase> <!-- bind to the packaging phase -->
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/assembly/src.xml
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/assembly/src.xml b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/assembly/src.xml
new file mode 100644
index 0000000..80e2e06
--- /dev/null
+++ b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/assembly/src.xml
@@ -0,0 +1,33 @@
+<!--
+ ~ Copyright 2005-2011 WSO2, Inc. (http://wso2.com)
+ ~
+ ~ Licensed 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.
+ -->
+<assembly
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>Tool</id>
+ <formats>
+ <format>jar</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/</outputDirectory>
+ <useProjectArtifact>true</useProjectArtifact>
+ <unpack>true</unpack>
+ <scope>runtime</scope>
+ </dependencySet>
+ </dependencySets>
+</assembly>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CliTool.java
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CliTool.java b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CliTool.java
new file mode 100644
index 0000000..1ff4f91
--- /dev/null
+++ b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CliTool.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2013, WSO2, Inc. http://wso2.org
+ *
+ * Licensed 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.wso2.carbon.adc.mgt.cli;
+
+import static org.wso2.carbon.adc.mgt.cli.utils.CliConstants.STRATOS_DIR;
+
+import java.io.File;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class is used for input the commands through CLITool, command prompt.
+ */
+public class CliTool {
+
+ private static final Logger logger = LoggerFactory.getLogger(CliTool.class);
+
+ /**
+ * Main executable method used to call from CLI.
+ *
+ */
+ public static void main(final String[] args) {
+ CliTool cliTool = new CliTool();
+ cliTool.createConfigDirectory();
+ cliTool.handleConsoleInputs(args);
+ }
+
+ /**
+ * Here is the place all the command line inputs get processed
+ *
+ * @param arguments
+ * passed to CLI tool.
+ */
+ private void handleConsoleInputs(String[] arguments) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Stratos CLI Started...");
+ }
+ StratosApplication application = new StratosApplication();
+ application.start(arguments);
+ }
+
+ private void createConfigDirectory() {
+ File stratosFile = new File(System.getProperty("user.home"), STRATOS_DIR);
+ if (stratosFile.exists()) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Using directory: {}", stratosFile.getPath());
+ }
+ } else {
+ if (stratosFile.mkdir()) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Created directory: {}", stratosFile.getPath());
+ }
+ } else if (logger.isWarnEnabled()) {
+ logger.warn("Failed to created directory: {}", stratosFile.getPath());
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/Command.java
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/Command.java b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/Command.java
new file mode 100644
index 0000000..5e3a250
--- /dev/null
+++ b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/Command.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2013, WSO2, Inc. http://wso2.org
+ *
+ * Licensed 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.wso2.carbon.adc.mgt.cli;
+
+import org.apache.commons.cli.Options;
+import org.wso2.carbon.adc.mgt.cli.exception.CommandException;
+
+public interface Command<T extends CommandContext> {
+
+ /**
+ * @return The name of the command
+ */
+ String getName();
+
+ /**
+ * Information about the command
+ *
+ * @return The description of the command
+ */
+ String getDescription();
+
+ /**
+ * This should return the syntax required for the command.
+ *
+ * Used to display help.
+ *
+ * @return The syntax for this command
+ */
+ String getArgumentSyntax();
+
+ /**
+ * The options accepted by the command
+ *
+ * @return The Options for the commands
+ */
+ Options getOptions();
+
+ /**
+ * Executing the commands. Returns a code
+ *
+ * @param context
+ * The context assoicated with the Command Line Application
+ * @param args
+ * The arguments for the command
+ * @return The status code
+ * @throws CommandException
+ * if any errors occur when executing the command
+ */
+ int execute(T context, String[] args) throws CommandException;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandContext.java
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandContext.java b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandContext.java
new file mode 100644
index 0000000..59364ff
--- /dev/null
+++ b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandContext.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2013, WSO2, Inc. http://wso2.org
+ *
+ * Licensed 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.wso2.carbon.adc.mgt.cli;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Observable;
+
+public class CommandContext extends Observable {
+
+ /**
+ * Properties for the context.
+ */
+ private Map<String, Object> properties;
+
+ /**
+ * The application
+ */
+ private final CommandLineApplication<? extends CommandContext> application;
+
+ public CommandContext(CommandLineApplication<? extends CommandContext> application) {
+ properties = new HashMap<String, Object>();
+ this.application = application;
+ }
+
+ public final CommandLineApplication<? extends CommandContext> getApplication() {
+ return application;
+ }
+
+ /**
+ * Set property in the context
+ *
+ * @param key
+ * The key
+ * @param o
+ * The value for the key
+ * @return The previous value or null
+ */
+ public Object put(String key, Object o) {
+ Object previous = properties.put(key, o);
+ setChanged();
+ notifyObservers();
+ return previous;
+ }
+
+ /**
+ * Get property value from the context
+ *
+ * @param key
+ * The key
+ * @return The value
+ */
+ public Object getObject(String key) {
+ return properties.get(key);
+ }
+
+ /**
+ * Get the string value, or null
+ *
+ * @param key
+ * The key
+ * @return The string value, or null.
+ */
+ public String getString(String key) {
+ Object o = getObject(key);
+ if (o instanceof String) {
+ return (String) o;
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/4f217859/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineApplication.java
----------------------------------------------------------------------
diff --git a/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineApplication.java b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineApplication.java
new file mode 100644
index 0000000..bafc14d
--- /dev/null
+++ b/components/org.wso2.carbon.adc.mgt.cli/2.1.3/src/main/java/org/wso2/carbon/adc/mgt/cli/CommandLineApplication.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2013, WSO2, Inc. http://wso2.org
+ *
+ * Licensed 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.wso2.carbon.adc.mgt.cli;
+
+import java.io.File;
+import java.io.IOException;
+
+import jline.console.ConsoleReader;
+import jline.console.history.FileHistory;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.wso2.carbon.adc.mgt.cli.utils.CliConstants;
+
+public abstract class CommandLineApplication<T extends CommandContext> {
+
+ private static final Logger logger = LoggerFactory.getLogger(CommandLineApplication.class);
+
+ protected final ConsoleReader reader;
+ protected FileHistory history;
+
+ public CommandLineApplication() {
+ reader = createConsoleReader();
+ }
+
+ /**
+ * Creates new jline ConsoleReader.
+ *
+ * @return a jline ConsoleReader instance
+ */
+ protected ConsoleReader createConsoleReader() {
+ ConsoleReader consoleReader = null;
+ try {
+ consoleReader = new ConsoleReader();
+ consoleReader.setPrompt(getPrompt());
+ history = new FileHistory(getHistoryFile());
+ consoleReader.setHistory(history);
+ } catch (IOException e) {
+ throw new IllegalStateException("Cannot create jline console reader", e);
+ }
+ return consoleReader;
+ }
+
+ public ConsoleReader getConsoleReader() {
+ return reader;
+ }
+
+ protected abstract String getPrompt();
+
+ /**
+ * Get the history file for the Console Reader.
+ *
+ * @return File for storing history
+ */
+ protected abstract File getHistoryFile();
+
+ public final void start(String[] args) {
+ Thread shutdownHookThread = new Thread("CLI Shutdown Hook") {
+ @Override
+ public void run() {
+ performDestroy();
+ }
+ };
+ Runtime.getRuntime().addShutdownHook(shutdownHookThread);
+ int returnCode = run(args);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Exiting with error code {}", returnCode);
+ }
+ System.exit(returnCode);
+ }
+
+ protected abstract int run(String[] args);
+
+ protected void promptLoop() {
+ String line = null;
+ boolean exit = false;
+
+ try {
+ while (!exit && (reader != null && ((line = reader.readLine()) != null))) {
+ if ("".equals(line)) {
+ continue;
+ }
+ if (StringUtils.isNotBlank(line)) {
+ execute(line);
+ exit = CliConstants.EXIT_ACTION.equals(line.trim());
+ }
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Error in reading line", e);
+ }
+ }
+
+ private int execute(String line) {
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing command line: \"{}\"", line);
+ }
+ int returnCode = executeCommand(line);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Command line executed \"{}\". Return code: {}", line, returnCode);
+ }
+ return returnCode;
+ } catch (RuntimeException e) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error executing command line: " + line, e);
+ }
+ return 1;
+ }
+ }
+
+ protected abstract int executeCommand(String line);
+
+ private void performDestroy() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Shutting down application... Invoking destroy methods");
+ }
+ if (history != null) {
+ try {
+ history.flush();
+ } catch (IOException e) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error flushing history.", e);
+ }
+ }
+ }
+ destroy();
+ }
+
+ /**
+ * May override to perform action before destroying
+ */
+ protected void destroy() {
+ };
+
+ public String getInput(String prompt) {
+ return getInput(prompt, null);
+ }
+
+ public String getInput(String prompt, Character mask) {
+ String line = null;
+ try {
+ reader.setPrompt(prompt + ": ");
+ while ((line = reader.readLine(mask)) != null) {
+ if ("".equals(line)) {
+ continue;
+ }
+ return line;
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Error in reading line", e);
+ } finally {
+ reader.setPrompt(CliConstants.STRATOS_SHELL_PROMPT);
+ }
+ return line;
+ }
+
+ /**
+ * @return {@code true if user confirmed}
+ */
+ public boolean getConfirmation(String prompt) {
+ prompt = prompt + " [yes/no]";
+
+ String input = "";
+ int tries = 0;
+ do {
+ tries++;
+ input = getInput(prompt);
+ } while (!"y".equals(input) && !"yes".equals(input) && !"n".equals(input) && !"no".equals(input) && tries < 3);
+
+ return "y".equals(input) || "yes".equals(input);
+ }
+
+}