You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2013/11/04 08:28:43 UTC
[1/3] Removed obsolete component
org.apache.stratos.mediator.autoscale and feature
org.apache.stratos.mediator.autoscale.feature
Updated Branches:
refs/heads/master 3959b1ad7 -> 947eb5a6b
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscalerTaskDSHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscalerTaskDSHolder.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscalerTaskDSHolder.java
deleted file mode 100644
index 7b8e50f..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscalerTaskDSHolder.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.util;
-
-import org.apache.axis2.clustering.ClusteringAgent;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.LBConfiguration;
-import org.apache.stratos.lb.common.service.LoadBalancerConfigurationService;
-import org.wso2.carbon.registry.core.session.UserRegistry;
-import org.apache.stratos.cloud.controller.interfaces.CloudControllerService;
-import org.wso2.carbon.user.core.service.RealmService;
-import org.wso2.carbon.utils.ConfigurationContextService;
-
-/**
- * Singleton class to hold Agent Management Service
- */
-public class AutoscalerTaskDSHolder {
-
- private ConfigurationContextService configurationContextService;
- private LoadBalancerConfiguration wholeLbConfig;
- private CloudControllerService cloudControllerService;
-
- private RealmService realmService;
- private ClusteringAgent agent;
- private ConfigurationContext configCtxt;
- private UserRegistry configRegistry;
- private UserRegistry governanceRegistry;
-
- private static AutoscalerTaskDSHolder instance = new AutoscalerTaskDSHolder();
-
- private AutoscalerTaskDSHolder(){
-
- }
-
- public static AutoscalerTaskDSHolder getInstance(){
- return instance;
- }
-
- public ConfigurationContextService getConfigurationContextServiceService(){
- return this.configurationContextService;
- }
-
- public void setConfigurationContextService(ConfigurationContextService cCtxService){
- this.configurationContextService = cCtxService;
- }
-
- public LoadBalancerConfiguration getWholeLoadBalancerConfig() {
- return wholeLbConfig;
- }
-
- public LBConfiguration getLoadBalancerConfig() {
- return wholeLbConfig.getLoadBalancerConfig();
- }
-
- public ClusteringAgent getAgent() {
- return agent;
- }
-
- public void setAgent(ClusteringAgent agent) {
- this.agent = agent;
- }
-
-
- public void setRealmService(RealmService realmService) {
- this.realmService = realmService;
- }
-
- public RealmService getRealmService() {
- return realmService;
- }
-
- public void setLbConfigService(LoadBalancerConfigurationService lbConfigSer) {
- if (lbConfigSer != null) {
- this.wholeLbConfig = (LoadBalancerConfiguration) lbConfigSer.getLoadBalancerConfig();
- } else {
- this.wholeLbConfig = null;
- }
- }
-
- public void setConfigCtxt(ConfigurationContext configCtxt) {
- this.configCtxt = configCtxt;
- }
-
- public ConfigurationContext getConfigCtxt() {
- return configCtxt;
- }
-
- public void setCloudControllerService(CloudControllerService cc) {
- this.cloudControllerService = cc;
- }
-
- public CloudControllerService getCloudControllerService() {
- return cloudControllerService;
- }
-
- public UserRegistry getConfigRegistry() {
- return configRegistry;
- }
-
- public void setConfigRegistry(UserRegistry configRegistry) {
- this.configRegistry = configRegistry;
- }
-
- public UserRegistry getGovernanceRegistry() {
- return governanceRegistry;
- }
-
- public void setGovernanceRegistry(UserRegistry governanceRegistry) {
- this.governanceRegistry = governanceRegistry;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/resources/META-INF/services/org.apache.synapse.config.xml.MediatorFactory
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/resources/META-INF/services/org.apache.synapse.config.xml.MediatorFactory b/components/org.apache.stratos.mediator.autoscale/src/main/resources/META-INF/services/org.apache.synapse.config.xml.MediatorFactory
deleted file mode 100644
index 0bbcc57..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/resources/META-INF/services/org.apache.synapse.config.xml.MediatorFactory
+++ /dev/null
@@ -1,19 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-org.wso2.carbon.mediator.autoscale.ec2autoscale.mediators.AutoscaleInMediatorFactory
-org.wso2.carbon.mediator.autoscale.ec2autoscale.mediators.AutoscaleOutMediatorFactory
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/resources/META-INF/services/org.apache.synapse.config.xml.MediatorSerializer
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/resources/META-INF/services/org.apache.synapse.config.xml.MediatorSerializer b/components/org.apache.stratos.mediator.autoscale/src/main/resources/META-INF/services/org.apache.synapse.config.xml.MediatorSerializer
deleted file mode 100644
index 1b962cb..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/resources/META-INF/services/org.apache.synapse.config.xml.MediatorSerializer
+++ /dev/null
@@ -1,19 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-org.wso2.carbon.mediator.autoscale.ec2autoscale.mediators.AutoscaleInMediatorSerializer
-org.wso2.carbon.mediator.autoscale.ec2autoscale.mediators.AutoscaleOutMediatorSerializer
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-load-average.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-load-average.xml b/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-load-average.xml
deleted file mode 100644
index 4791709..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-load-average.xml
+++ /dev/null
@@ -1,138 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- # 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.
- -->
-<!-- The default synapse configuration shipped with the WSO2 Load Balancer
- This handles the load balancing and the autoscaling of the stratos services
- -->
-
-<definitions xmlns="http://ws.apache.org/ns/synapse">
-
- <!-- You can add any flat sequences, endpoints, etc.. to this synapse-messages-in-flight.xml file if you do
- *not* want to have the defaults given below, specific to WSO2 LB and auto-scaler
- -->
-
-
- <!-- Given below is the auto-scale mediator specific task. Uncomment it, if you want to
- auto-scale your applications.
- -->
-
- <task class="org.wso2.carbon.mediator.autoscale2.LoadAverageBasedEC2LoadAnalyzerTask"
- name="LoadAnalyzer">
-
-
- <!--
- The private key for the ec2
- -->
- <property name="ec2PrivateKey" value="/mnt/payload/pk.pem"/>
-
- <!--
- The certificate for the ec2
- -->
- <property name="ec2Cert" value="/mnt/payload/cert.pem"/>
-
- <!--
- The amazon instance type for the load balanced service instances.
- Recommended and the default is m1.large.
- -->
- <property name="instanceType" value="m1.large"/>
-
- <!--
- The amazon instance type for the instances of the load balancer itself.
- Default is m1.large. Can be changed to m1.small too.
- -->
- <property name="loadBalancerInstanceType" value="m1.large"/>
-
- <!--
- The group of the service being load balanced.
- -->
- <property name="applicationGroup" value="as-2011-02-23,cloud-mysql,default"/>
-
- <!--
- The group of the load balancer.
- -->
- <property name="loadBalancerGroup" value="stratos-appserver-lb,cloud-mysql,default"/>
-
- <!--
- The Amazon availability zone for the instances. 1-c is given as the default
- -->
- <property name="availabilityZone" value="us-east-1c"/>
-
- <!--
- Additional information for the amazon instances
- -->
- <property name="instanceAdditionalInfo" value="EC2 autoscale instance"/>
-
- <!--
- The key pair
- -->
- <property name="key" value="stratos-1.0.0-keypair"/>
-
- <!--
- The service payload file which should be loaded to the bucket
- -->
- <property name="applicationPayload" value="resources/cluster_node.zip"/>
-
- <!--
- The load balancer payload file which should be loaded to the bucket
- -->
- <property name="loadBalancerPayload" value="/mnt/payload.zip"/>
-
- <!--
- The elasticIP property can be overriden by the ELASTIC_IP environment var,
- which is set in the payload
- -->
- <property name="elasticIP" value="${ELASTIC_IP}"/>
-
- <!--
- The minimum and maximum limits of the load balanced service instances
- -->
- <property name="minAppInstances" value="1"/>
- <property name="maxAppInstances" value="5"/>
-
- <!--
- The minimum and maximum limits of the load balancer instances
- -->
- <property name="minLoadBalancerInstances" value="1"/>
-
- <property name="roundsToAverage" value="10"/>
-
- <!--
- The instances spawned at once, per scaling up decision.
- Default and the recommended value is 1
- -->
- <property name="instancesPerScaleUp" value="1"/>
-
- <!--
- The low and high limits of the load average
- -->
- <property name="loadAverageLowerLimit" value="2"/>
- <property name="loadAverageHigherLimit" value="5"/>
-
- <!--
- The Load Balanced Service Ports
- -->
- <property name="serviceHttpPort" value="9763"/>
- <property name="serviceHttpsPort" value="9443"/>
-
- <!--
- The interval to trigger the task in seconds
- -->
- <trigger interval="5"/>
- </task>
-</definitions>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-messages-in-flight.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-messages-in-flight.xml b/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-messages-in-flight.xml
deleted file mode 100644
index ac68a7b..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-messages-in-flight.xml
+++ /dev/null
@@ -1,135 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- # 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.
- -->
-<!-- The default synapse configuration shipped with the WSO2 Load Balancer
- This handles the load balancing and the autoscaling of the stratos services
- -->
-
-<definitions xmlns="http://ws.apache.org/ns/synapse">
-
- <!-- You can add any flat sequences, endpoints, etc.. to this synapse-messages-in-flight.xml file if you do
- *not* want to have the defaults given below, specific to WSO2 LB and auto-scaler
- -->
-
-
- <!-- Given below is the auto-scale mediator specific task. Uncomment it, if you want to
- auto-scale your applications.
- -->
-
- <task class="org.wso2.carbon.mediator.autoscale2.MessagesInFlightBasedEC2LoadAnalyzerTask"
- name="LoadAnalyzer">
-
-
- <!--
- The private key for the ec2
- -->
- <property name="ec2PrivateKey" value="/mnt/payload/pk.pem"/>
-
- <!--
- The certificate for the ec2
- -->
- <property name="ec2Cert" value="/mnt/payload/cert.pem"/>
-
- <!--
- The amazon instance type for the load balanced service instances.
- Recommended and the default is m1.large.
- -->
- <property name="instanceType" value="m1.large"/>
-
- <!--
- The amazon instance type for the instances of the load balancer itself.
- Default is m1.large. Can be changed to m1.small too.
- -->
- <property name="loadBalancerInstanceType" value="m1.large"/>
-
- <!--
- The group of the service being load balanced.
- -->
- <property name="applicationGroup" value="as-2011-02-23,cloud-mysql,default"/>
-
- <!--
- The group of the load balancer.
- -->
- <property name="loadBalancerGroup" value="stratos-appserver-lb,cloud-mysql,default"/>
-
- <!--
- The Amazon availability zone for the instances. 1-c is given as the default
- -->
- <property name="availabilityZone" value="us-east-1c"/>
-
- <!--
- Additional information for the amazon instances
- -->
- <property name="instanceAdditionalInfo" value="EC2 autoscale instance"/>
-
- <!--
- The key pair
- -->
- <property name="key" value="stratos-1.0.0-keypair"/>
-
- <!--
- The service payload file which should be loaded to the bucket
- -->
- <property name="applicationPayload" value="resources/cluster_node.zip"/>
-
- <!--
- The load balancer payload file which should be loaded to the bucket
- -->
- <property name="loadBalancerPayload" value="/mnt/payload.zip"/>
-
- <!--
- The elasticIP property can be overriden by the ELASTIC_IP environment var,
- which is set in the payload
- -->
- <property name="elasticIP" value="${ELASTIC_IP}"/>
-
- <!--
- The time in milliseconds which the message takes to expire
- -->
- <property name="messageExpiryTime" value="60000"/>
-
- <!--
- The minimum and maximum limits of the load balanced service instances
- -->
- <property name="minAppInstances" value="1"/>
- <property name="maxAppInstances" value="5"/>
-
- <!--
- The number of load balancer instances
- -->
- <property name="loadBalancerInstances" value="1"/>
-
- <!--
- The given queue length per node, for the calculation in scaling up
- -->
- <property name="queueLengthPerNode" value="400"/>
- <property name="roundsToAverage" value="10"/>
-
- <!--
- The instances spawned at once, per scaling up decision.
- Default and the recommended value is 1
- -->
- <property name="instancesPerScaleUp" value="1"/>
-
- <!--
- The interval to trigger the task in seconds
- -->
- <trigger interval="5"/>
- </task>
-</definitions>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-service-messages-in-flight.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-service-messages-in-flight.xml b/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-service-messages-in-flight.xml
deleted file mode 100644
index a996b35..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/resources/synapse-service-messages-in-flight.xml
+++ /dev/null
@@ -1,108 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- # 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.
- -->
-<!-- The default synapse configuration shipped with the WSO2 Load Balancer
- This handles the load balancing and the autoscaling of the stratos services
- -->
-
-<definitions xmlns="http://ws.apache.org/ns/synapse">
-
- <!-- You can add any flat sequences, endpoints, etc.. to this synapse-messages-in-flight.xml file if you do
- *not* want to have the defaults given below, specific to WSO2 LB and auto-scaler
- -->
-
-
- <!-- Given below is the auto-scale mediator specific task. Uncomment it, if you want to
- auto-scale your applications.
- -->
- <task class="org.wso2.carbon.mediator.autoscale.lbautoscale.ServiceRequestsInFlightAutoscaler"
- name="LoadAnalyzer">
-
- <!--
- The private key for ec2
- -->
- <property name="ec2PrivateKey" value="/mnt/payload/pk.pem"/>
-
- <!--
- The certificate for ec2
- -->
- <property name="ec2Cert" value="/mnt/payload/cert.pem"/>
- <!--
- The key pair
- -->
- <property name="sshKey" value="stratos-1.0.0-keypair"/>
-
- <property name="loadBalancer">
- <loadBalancer>
- <property name="securityGroup" value="stratos-appserver-lb"/>
- <property name="instanceType" value="m1.large"/>
- <property name="instances" value="1"/>
- <property name="elasticIP" value="${ELASTIC_IP}"/>
- <property name="availabilityZone" value="us-east-1c"/>
- <property name="payload" value="/mnt/payload.zip"/>
- </loadBalancer>
- </property>
-
- <property name="services">
- <services>
- <defaults>
- <property name="payload" value="resources/cluster_node.zip"/>
- <property name="availabilityZone" value="us-east-1c"/>
- <property name="securityGroup" value="as-2011-02-23"/>
- <property name="instanceType" value="m1.large"/>
- <property name="minAppInstances" value="1"/>
- <property name="maxAppInstances" value="5"/>
- <property name="queueLengthPerNode" value="400"/>
- <property name="roundsToAverage" value="10"/>
- <property name="instancesPerScaleUp" value="1"/>
- <property name="messageExpiryTime" value="60000"/>
- </defaults>
- <service domain="wso2.as.domain">
- <property name="payload" value="resources/cluster_node.zip"/>
- <property name="availabilityZone" value="us-east-1c"/>
- </service>
- <service domain="wso2.ds.domain">
- <property name="payload" value="resources/cluster_node.zip"/>
- <property name="minAppInstances" value="1"/>
- <property name="maxAppInstances" value="5"/>
- <property name="queueLengthPerNode" value="400"/>
- <property name="roundsToAverage" value="10"/>
- <property name="instancesPerScaleUp" value="1"/>
- <property name="availabilityZone" value="us-east-1c"/>
- <property name="securityGroup" value="ds-2011-02-23"/>
- </service>
- <service domain="wso2.bps.domain">
- <property name="payload" value="resources/cluster_node.zip"/>
- <property name="minAppInstances" value="1"/>
- <property name="maxAppInstances" value="5"/>
- <property name="queueLengthPerNode" value="400"/>
- <property name="roundsToAverage" value="10"/>
- <property name="instancesPerScaleUp" value="1"/>
- <property name="availabilityZone" value="us-east-1c"/>
- <property name="securityGroup" value="bps-2011-02-23"/>
- </service>
- </services>
- </property>
-
- <!--
- The interval to trigger the task in seconds
- -->
- <trigger interval="5"/>
- </task>
-</definitions>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/test/java/org/apache/stratos/mediator/autoscale/lbautoscale/AppDomainContextsTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/test/java/org/apache/stratos/mediator/autoscale/lbautoscale/AppDomainContextsTest.java b/components/org.apache.stratos.mediator.autoscale/src/test/java/org/apache/stratos/mediator/autoscale/lbautoscale/AppDomainContextsTest.java
deleted file mode 100644
index e3f2158..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/test/java/org/apache/stratos/mediator/autoscale/lbautoscale/AppDomainContextsTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale;
-
-import org.apache.axis2.clustering.ClusteringAgent;
-import org.apache.axis2.clustering.tribes.TribesClusteringAgent;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.ServiceConfiguration;
-import org.apache.stratos.lb.common.group.mgt.SubDomainAwareGroupManagementAgent;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleUtil;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import java.io.File;
-import java.util.Iterator;
-import java.util.Map;
-
-@RunWith(JUnit4.class)
-public class AppDomainContextsTest {
- private static Map<String, Map<String, ?>> map;
- private static LoadBalancerConfiguration lbConfig;
- private static ConfigurationContext configCtx;
- private static ClusteringAgent clusteringAgent;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- configCtx = ConfigurationContextFactory.createEmptyConfigurationContext();
- clusteringAgent = new TribesClusteringAgent();
- clusteringAgent.addGroupManagementAgent(new SubDomainAwareGroupManagementAgent(
- "worker"),
- "wso2.as1.domain", "worker", -1);
- clusteringAgent.addGroupManagementAgent(new SubDomainAwareGroupManagementAgent(
- "mgt"),
- "wso2.as1.domain", "mgt", -1);
- clusteringAgent.addGroupManagementAgent(new SubDomainAwareGroupManagementAgent(
- "mgt"),
- "wso2.as2.domain", "mgt", -1);
- configCtx.getAxisConfiguration().setClusteringAgent(clusteringAgent);
-
- File f = new File("src/test/resources/loadbalancer.conf");
- System.setProperty("loadbalancer.conf", f.getAbsolutePath());
- lbConfig = LoadBalancerConfiguration.getInstance();
-
- map = AutoscaleUtil.getAppDomainContexts(configCtx, lbConfig);
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- // Remove service configurations since lbConfig is singleton
- lbConfig = LoadBalancerConfiguration.getInstance();
- lbConfig.removeServiceConfiguration("wso2.as1.domain", "worker");
- lbConfig.removeServiceConfiguration("wso2.as1.domain", "mgt");
- lbConfig.removeServiceConfiguration("wso2.as2.domain", "mgt");
- map = AutoscaleUtil.getAppDomainContexts(configCtx, lbConfig);
- }
-
- @Test
- public void testRemoval(){
- // Removing a cluster domain with only 1 sub domain
- lbConfig.removeServiceConfiguration("wso2.as2.domain", "mgt");
- map = AutoscaleUtil.getAppDomainContexts(configCtx, lbConfig);
-
- Assert.assertEquals(true, !map.containsKey("wso2.as2.domain"));
-
- // Removing a cluster domain with more than 1 sub domain
- lbConfig.removeServiceConfiguration("wso2.as1.domain", "mgt");
- map = AutoscaleUtil.getAppDomainContexts(configCtx, lbConfig);
-
- Assert.assertEquals(true, map.containsKey("wso2.as1.domain"));
- Assert.assertEquals(true, map.get("wso2.as1.domain").get("mgt") == null);
- Assert.assertEquals(true, map.get("wso2.as1.domain").get("worker") != null);
- }
-
- @Test
- public void testAddition(){
- ServiceConfiguration config1 = lbConfig.new ServiceConfiguration();
- config1.setDomain("wso2.as3.domain");
- config1.setSub_domain("mgt");
- lbConfig.addServiceConfiguration(config1);
- clusteringAgent.addGroupManagementAgent(new SubDomainAwareGroupManagementAgent(
- "mgt"),
- "wso2.as3.domain", "mgt", -1);
- map = AutoscaleUtil.getAppDomainContexts(configCtx, lbConfig);
-
- Assert.assertEquals(true, map.containsKey("wso2.as3.domain"));
- Assert.assertEquals(true, map.get("wso2.as3.domain").get("mgt") != null);
-
- // Remove service configuration since lbConfig is singleton
- lbConfig.removeServiceConfiguration("wso2.as3.domain", "mgt");
- map = AutoscaleUtil.getAppDomainContexts(configCtx, lbConfig);
- }
-
- @Deprecated // use only for writing test cases
- void printKeys(Map<?,?> map){
- for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
- Object type = iterator.next();
- System.out.println(type);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/test/resources/loadbalancer.conf
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/test/resources/loadbalancer.conf b/components/org.apache.stratos.mediator.autoscale/src/test/resources/loadbalancer.conf
deleted file mode 100644
index 7b2a80a..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/test/resources/loadbalancer.conf
+++ /dev/null
@@ -1,50 +0,0 @@
-loadbalancer {
- instances 1;
- enable_autoscaler true;
- # interval between two task executions in milliseconds
- autoscaler_task_interval 5000;
- # after an instance booted up, task will wait till this much of time and let the server started up
- server_startup_delay 15000; #default will be 60000ms
-}
-
-services {
- defaults {
- min_app_instances 1;
- max_app_instances 5;
- max_requests_per_second 400;
- alarming_upper_rate 0.65;
- alarming_lower_rate 0.2;
- scale_down_factor 0.25;
- rounds_to_average 10;
- instances_per_scale_up 1;
- message_expiry_time 60000;
- }
-
- appserver {
- hosts appserver.cloud-test.wso2.com, as.cloud-test.wso2.com;
- sub_domain worker1;
- domains {
- wso2.as1.domain {
- hosts as1.cloud-test.wso2.com;
- min_app_instances 0;
- sub_domain worker;
- tenant_range 1-5;
- }
- wso2.as1.domain {
- hosts mgt.as1.cloud-test.wso2.com;
- min_app_instances 0;
- sub_domain mgt;
- tenant_range 1-5;
- }
- wso2.as2.domain {
- hosts mgt.as2.cloud-test.wso2.com;
- min_app_instances 0;
- sub_domain mgt;
- tenant_range 1-5;
- }
-
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/features/autoscaler/org.apache.stratos.mediator.autoscale.feature/pom.xml
----------------------------------------------------------------------
diff --git a/features/autoscaler/org.apache.stratos.mediator.autoscale.feature/pom.xml b/features/autoscaler/org.apache.stratos.mediator.autoscale.feature/pom.xml
deleted file mode 100644
index 60ec672..0000000
--- a/features/autoscaler/org.apache.stratos.mediator.autoscale.feature/pom.xml
+++ /dev/null
@@ -1,91 +0,0 @@
-<?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>autoscaler-feature</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>org.apache.stratos.mediator.autoscale.feature</artifactId>
- <packaging>pom</packaging>
- <name>Apache Stratos - Autoscaler Feature</name>
- <url>http://apache.org</url>
- <description>This feature contains the required bundles for autoscaling functionality</description>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.stratos</groupId>
- <artifactId>org.apache.stratos.lb.cartridge.autoscaler.service.stub</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.stratos</groupId>
- <artifactId>org.apache.stratos.mediator.autoscale</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.wso2.maven</groupId>
- <artifactId>carbon-p2-plugin</artifactId>
- <version>${carbon.p2.plugin.version}</version>
- <executions>
- <execution>
- <id>4-p2-feature-generation</id>
- <phase>package</phase>
- <goals>
- <goal>p2-feature-gen</goal>
- </goals>
- <configuration>
- <id>org.apache.stratos.mediator.autoscale</id>
- <propertiesFile>../../../etc/feature.properties</propertiesFile>
- <adviceFile>
- <properties>
- <propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
- <propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
- </properties>
- </adviceFile>
- <bundles>
- <bundleDef>org.apache.stratos:org.apache.stratos.lb.cartridge.autoscaler.service.stub:${project.version}</bundleDef>
- <bundleDef>org.apache.stratos:org.apache.stratos.mediator.autoscale:${project.version}</bundleDef>
- <bundleDef>org.slf4j:slf4j-api:1.6.4</bundleDef>
- <bundleDef>org.slf4j:slf4j-log4j12:1.6.4</bundleDef>
- </bundles>
- <importFeatures>
- <importFeatureDef>org.apache.synapse.wso2:${synapse.wso2.version}</importFeatureDef>
- <importFeatureDef>org.apache.stratos.lb.common:${project.version}</importFeatureDef>
- </importFeatures>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/products/load-balancer/modules/distribution/src/main/license/LICENSE
----------------------------------------------------------------------
diff --git a/products/load-balancer/modules/distribution/src/main/license/LICENSE b/products/load-balancer/modules/distribution/src/main/license/LICENSE
index 231f6de..63ea050 100644
--- a/products/load-balancer/modules/distribution/src/main/license/LICENSE
+++ b/products/load-balancer/modules/distribution/src/main/license/LICENSE
@@ -245,7 +245,7 @@ openstack-keystone_1.6.1.incubating.jar, openstack-nova_1.6.1.incubating.jar,
org.apache.felix.gogo.command_0.8.0.v201108120515.jar, org.apache.felix.gogo.runtime_0.8.0.v201108120515.jar
org.apache.felix.gogo.shell_0.8.0.v201110170705.jar, org.apache.jasper.glassfish_2.2.2.v201205150955.jar,
org.apache.stratos.lb.cartridge.autoscaler.service.stub_3.0.0.SNAPSHOT.jar, org.apache.stratos.lb.common_3.0.0.SNAPSHOT.jar
-org.apache.stratos.lb.endpoint_3.0.0.SNAPSHOT.jar, org.apache.stratos.mediator.autoscale_3.0.0.SNAPSHOT.jar
+org.apache.stratos.lb.endpoint_3.0.0.SNAPSHOT.jar
org.jboss.netty_3.3.0.Final.jar, org.wso2.carbon.addressing_4.1.0.jar
org.wso2.carbon.apache.jasper.fragment_4.1.0.jar, org.wso2.carbon.application.deployer_4.1.0.jar
org.wso2.carbon.authenticator.proxy_4.1.0.jar, org.wso2.carbon.authenticator.stub_4.1.0.jar
[2/3] Removed obsolete component
org.apache.stratos.mediator.autoscale and feature
org.apache.stratos.mediator.autoscale.feature
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/mediators/AutoscaleOutMediator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/mediators/AutoscaleOutMediator.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/mediators/AutoscaleOutMediator.java
deleted file mode 100644
index 3640c08..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/mediators/AutoscaleOutMediator.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.mediators;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleConstants;
-import org.apache.synapse.ManagedLifecycle;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.core.SynapseEnvironment;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
-import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.AppDomainContext;
-
-import java.util.Map;
-
-/**
- * This Synapse mediator removes the request token generated by the {@link AutoscaleInMediator}
- *
- * @see AutoscaleInMediator
- */
-public class AutoscaleOutMediator extends AbstractMediator implements ManagedLifecycle {
-
- public boolean mediate(MessageContext synCtx) {
-
- log.debug("Mediation started ....... " + AutoscaleOutMediator.class.getName());
-
- ConfigurationContext configCtx =
- ((Axis2MessageContext) synCtx).getAxis2MessageContext().getConfigurationContext();
-
- String domain = (String) synCtx.getProperty(AutoscaleConstants.TARGET_DOMAIN);
- // gets the corresponding sub domain
- String subDomain = (String) synCtx.getProperty(AutoscaleConstants.TARGET_SUB_DOMAIN);
-
- String tokenId = (String) synCtx.getProperty(AutoscaleConstants.REQUEST_ID);
- @SuppressWarnings("unchecked")
- Map<String, Map<String, AppDomainContext>> appDomainContexts =
- (Map<String, Map<String, AppDomainContext>>) configCtx.getPropertyNonReplicable(AutoscaleConstants.APP_DOMAIN_CONTEXTS);
- AppDomainContext appDomainContext = null ;
-
- if(appDomainContexts.get(domain) != null){
- appDomainContext = appDomainContexts.get(domain).get(subDomain);
- }
-
- if (appDomainContext != null) {
- appDomainContext.removeRequestToken(tokenId);
- System.setProperty(AutoscaleConstants.IS_TOUCHED, "true");
- } else {
- log.debug("AppDomainContext not found for domain " + domain+" and sub domain : "+subDomain);
- }
- return true;
- }
-
- @Override
- public void destroy() {
- log.debug("Autoscale out mediator destroyed...");
- }
-
- @Override
- public void init(SynapseEnvironment arg0) {
- log.debug("Autoscale out mediator started...");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/state/check/PendingInstancesStateChecker.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/state/check/PendingInstancesStateChecker.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/state/check/PendingInstancesStateChecker.java
deleted file mode 100644
index 3cf1c85..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/state/check/PendingInstancesStateChecker.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.state.check;
-
-import org.apache.axis2.clustering.management.GroupManagementAgent;
-import org.apache.stratos.mediator.autoscale.lbautoscale.clients.CloudControllerClient;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.LoadBalancerContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleConstants;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleUtil;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class PendingInstancesStateChecker implements Runnable {
-
- private static final Log log = LogFactory.getLog(PendingInstancesStateChecker.class);
- private LoadBalancerContext groupCtxt = null;
- private String domain;
- private String subDomain;
- private int expectedIncrementOfinstanceCount, originalRunningInstanceCount;
- private CloudControllerClient ccClient;
-
- public PendingInstancesStateChecker(LoadBalancerContext ctxt, String aDomain, String aSubDomain,
- int anexpectedInstanceCount, int currentCount, CloudControllerClient client) {
- groupCtxt = ctxt;
- domain = aDomain;
- subDomain = aSubDomain;
- expectedIncrementOfinstanceCount = anexpectedInstanceCount;
- originalRunningInstanceCount = currentCount;
- ccClient = client;
- }
-
- @Override
- public void run() {
-
- if (groupCtxt != null) {
-
- int totalWaitedTime = 0;
- int serverStartupDelay = AutoscalerTaskDSHolder
- .getInstance()
- .getWholeLoadBalancerConfig()
- .getLoadBalancerConfig()
- .getServerStartupDelay();
-
- log.debug("Pending Instances State Checker has started for: " +
- AutoscaleUtil.domainSubDomainString(domain, subDomain) + ". Check expiry time : " + serverStartupDelay);
-
- // for each sub domain, get the clustering group management agent
- GroupManagementAgent agent =
- AutoscalerTaskDSHolder.getInstance().getAgent()
- .getGroupManagementAgent(domain,
- subDomain);
- int startingRunningInstanceCount = agent.getMembers().size();
-
- // we give some time for the server to get joined, we'll check time to time
- // whether the instance has actually joined the ELB.
- while ((agent.getMembers().size() < (originalRunningInstanceCount + expectedIncrementOfinstanceCount)) &&
- totalWaitedTime < serverStartupDelay) {
- int upToDateRunningInstanceCount = agent.getMembers().size();
-
- log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain) +
- " - Number of current running instances " +
- upToDateRunningInstanceCount);
-
- if (upToDateRunningInstanceCount > startingRunningInstanceCount) {
- int newlyJoinedInstanceCount = upToDateRunningInstanceCount - startingRunningInstanceCount;
- // set new running instance count
- groupCtxt.setRunningInstanceCount(upToDateRunningInstanceCount);
- // decrement the pending instance count
- groupCtxt.decrementPendingInstancesIfNotZero(newlyJoinedInstanceCount);
- // update the starting running instance count
- startingRunningInstanceCount = upToDateRunningInstanceCount;
-
- log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain) +
- " - Instances newly joined: " +
- newlyJoinedInstanceCount);
- }
-
- try {
- Thread.sleep(AutoscaleConstants.INSTANCE_REMOVAL_CHECK_TIME);
- } catch (InterruptedException ignore) {
- }
-
- totalWaitedTime += AutoscaleConstants.INSTANCE_REMOVAL_CHECK_TIME;
- }
-
- log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain) + "- Waited for : " +
- totalWaitedTime +
- " (milliseconds) till pending members get joined.");
-
- if (agent.getMembers().size() < (originalRunningInstanceCount + expectedIncrementOfinstanceCount)) {
-
- int instanceCountFailedToJoin =
- originalRunningInstanceCount + expectedIncrementOfinstanceCount - agent.getMembers().size();
- log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain) +
- "Instances that are failed to join: " +
- instanceCountFailedToJoin);
-
- // to avoid an infinite loop
- int retries = instanceCountFailedToJoin + 2;
-
- while (instanceCountFailedToJoin > 0 && retries > 0) {
- // instances spawned haven't joined ELB, so we assume that instance is
- // corrupted.
- // hence, we ask CC to terminate it.
- try {
- log.debug("Terminating lastly spwaned instance of " +
- AutoscaleUtil.domainSubDomainString(domain, subDomain));
- ccClient.terminateLastlySpawnedInstance(domain, subDomain);
- instanceCountFailedToJoin--;
- // decrement pending count
- groupCtxt.decrementPendingInstancesIfNotZero(1);
- } catch (Exception e) {
- log
- .error(
- "Instance termination failed for " +
- AutoscaleUtil.domainSubDomainString(domain, subDomain),
- e);
- } finally {
- retries--;
- }
- }
-
- // decrement pending count
- groupCtxt.decrementPendingInstancesIfNotZero(instanceCountFailedToJoin);
- }
-
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/state/check/TerminatingInstancesStateChecker.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/state/check/TerminatingInstancesStateChecker.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/state/check/TerminatingInstancesStateChecker.java
deleted file mode 100644
index d135d22..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/state/check/TerminatingInstancesStateChecker.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.state.check;
-
-import org.apache.axis2.clustering.management.GroupManagementAgent;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.LoadBalancerContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleConstants;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleUtil;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class TerminatingInstancesStateChecker implements Runnable {
-
- private static final Log log = LogFactory.getLog(TerminatingInstancesStateChecker.class);
- private LoadBalancerContext groupCtxt = null;
- private String domain;
- private String subDomain;
-
- public TerminatingInstancesStateChecker(LoadBalancerContext ctxt, String aDomain, String aSubDomain) {
- groupCtxt = ctxt;
- domain = aDomain;
- subDomain = aSubDomain;
- }
-
- @Override
- public void run() {
-
- if (groupCtxt != null) {
-
- groupCtxt.incrementTerminatingInstances(1);
-
- int totalWaitedTime = 0;
- int serverStartupDelay = AutoscalerTaskDSHolder
- .getInstance()
- .getWholeLoadBalancerConfig()
- .getLoadBalancerConfig()
- .getServerStartupDelay();
- log.info("Terminating Instances State Checker has started for: " +
- AutoscaleUtil.domainSubDomainString(domain, subDomain) + ". Check expiry time : " + serverStartupDelay);
-
- // for each sub domain, get the clustering group management agent
- GroupManagementAgent agent =
- AutoscalerTaskDSHolder.getInstance().getAgent()
- .getGroupManagementAgent(domain,
- subDomain);
-
- int startingRunningInstanceCount = agent.getMembers().size();
-
- // we give some time for the server to be terminated, we'll check time to time
- // whether the instance has actually left the cluster.
- while (agent.getMembers().size() == startingRunningInstanceCount &&
- totalWaitedTime < serverStartupDelay) {
-
- try {
- Thread.sleep(AutoscaleConstants.INSTANCE_REMOVAL_CHECK_TIME);
- } catch (InterruptedException ignore) {
- }
-
- totalWaitedTime += AutoscaleConstants.INSTANCE_REMOVAL_CHECK_TIME;
- }
-
- log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain) + "- Waited for : " +
- totalWaitedTime +
- " (milliseconds) till terminating member left the cluster.");
-
- // we recalculate number of alive instances
- groupCtxt.decrementTerminatingInstancesIfNotZero(1);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalerTaskInitializer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalerTaskInitializer.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalerTaskInitializer.java
deleted file mode 100644
index a38fecd..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalerTaskInitializer.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.stratos.mediator.autoscale.lbautoscale.task;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.synapse.task.TaskConstants;
-import org.apache.synapse.task.TaskDescriptionRepository;
-import org.apache.synapse.task.TaskScheduler;
-import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver;
-
-public class AutoscalerTaskInitializer extends AbstractAxis2ConfigurationContextObserver {
-
- public static final java.lang.String CARBON_TASK_SCHEDULER = "CARBON_TASK_SCHEDULER";
- public static final java.lang.String CARBON_TASK_REPOSITORY = "CARBON_TASK_REPOSITORY";
-
- public void createdConfigurationContext(ConfigurationContext configContext) {
- TaskScheduler scheduler = (TaskScheduler)configContext.getProperty(AutoscalerTaskInitializer.CARBON_TASK_SCHEDULER);
- if (scheduler == null) {
- scheduler = new TaskScheduler(TaskConstants.TASK_SCHEDULER);
- scheduler.init(null);
- configContext.setProperty(AutoscalerTaskInitializer.CARBON_TASK_SCHEDULER, scheduler);
- } else if(!scheduler.isInitialized()) {
- scheduler.init(null);
- }
-
- if (configContext.getProperty(AutoscalerTaskInitializer.CARBON_TASK_REPOSITORY) == null) {
- TaskDescriptionRepository repository = new TaskDescriptionRepository();
- configContext.setProperty(
- AutoscalerTaskInitializer.CARBON_TASK_REPOSITORY, repository);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalerTaskMgmtAdminService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalerTaskMgmtAdminService.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalerTaskMgmtAdminService.java
deleted file mode 100644
index 5f83f7e..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalerTaskMgmtAdminService.java
+++ /dev/null
@@ -1,348 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.task;
-
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.util.AXIOMUtil;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.task.TaskDescription;
-import org.apache.synapse.task.TaskDescriptionFactory;
-import org.apache.synapse.task.TaskDescriptionSerializer;
-import org.apache.synapse.task.service.TaskManagementService;
-import org.wso2.carbon.core.AbstractAdmin;
-import org.wso2.carbon.task.TaskManagementException;
-import org.wso2.carbon.task.TaskManager;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import java.util.*;
-
-public class AutoscalerTaskMgmtAdminService extends AbstractAdmin implements TaskManagementService{
-
- private static final Log log = LogFactory.getLog(AutoscalerTaskMgmtAdminService.class);
-
- private TaskSchedulingManager schedulingManager;
-
-
- private static final String TASK_EXTENSION_NS =
- "http://www.wso2.org/tasks";
-
- private static final OMFactory FACTORY = OMAbstractFactory.getOMFactory();
-
- private static final OMNamespace TASK_OM_NAMESPACE = FACTORY.createOMNamespace(
- TASK_EXTENSION_NS, "task");
-
- public AutoscalerTaskMgmtAdminService(){}
-
- public AutoscalerTaskMgmtAdminService(ConfigurationContext configurationContext) {
- this.schedulingManager = TaskSchedulingManager.getInstance();
- this.configurationContext = configurationContext;
- }
-
- public void shutdown() {
- schedulingManager.shutDown(getConfigContext());
- }
-
- public void addTaskDescription(TaskDescription taskDescription, Map<String, Object> resources)
- throws Exception {
- if (log.isDebugEnabled()) {
- log.debug("Adding the Task " + taskDescription.getName());
- }
- try {
- schedulingManager.scheduleTask(taskDescription, resources, getConfigContext());
- } catch (Exception e) {
- String msg = "Cannot add the task " + taskDescription.getName() + "..";
- log.error(msg, e);
- throw e;
- }
- }
-
- /**
- * Passing the Task Description to scheduling manager to actually add it to the Task
- * Description Repository.
- *
- * @param taskDescription TaskDescription
- */
- public void addTaskDescription(TaskDescription taskDescription) {
- if (log.isDebugEnabled()) {
- log.debug("Adding the Task " + taskDescription.getName());
- }
- try {
- Map<String, Object> resources = new HashMap<String, Object>();
- schedulingManager.scheduleTask(taskDescription, resources, getConfigContext());
- } catch (Exception e) {
- String msg = "Cannot add the task";
- log.error(msg, e);
- }
- }
-
- public void addTaskDescriptionInAnOmElement(String taskElementString) throws
- TaskManagementException,
- XMLStreamException {
- OMElement taskElement = AXIOMUtil.stringToOM(taskElementString);
- if (log.isDebugEnabled()) {
- log.debug("Add TaskDescription - Get a Task configuration :" + taskElement);
- }
- TaskDescription taskDescription = validateAndCreate(taskElement);
-
- try {
- addTaskDescription(taskDescription);
- } catch (Exception e) {
- try {
- getTaskManager().deleteTaskDescription(taskDescription.getName(),
- taskDescription.getGroup());
- } catch (Exception ignored) {
- }
- handleException("Error creating a task : " + e.getMessage(), e);
- }
- }
-
-
-
- public void deleteTaskDescription(TaskDescription taskDescription) {
- String taskName = taskDescription.getName();
- if (log.isDebugEnabled()) {
- log.debug("Deleting the task " + taskName);
- }
- try {
- schedulingManager.deleteTaskDescription(taskDescription, getConfigContext());
- } catch (Exception e) {
- log.error("Cannot delete the task " + taskName, e);
- }
- }
-
- /**
- * Indicating Task Scheduling manager to delete the task with the given task Name.
- *
- * @param taskName taskName
- */
- public void deleteTaskDescription(String taskName) {
- if (log.isDebugEnabled()) {
- log.debug("Deleting the task " + taskName);
- }
- try {
- TaskDescription taskDescription = new TaskDescription();
- taskDescription.setName(taskName);
- schedulingManager.deleteTaskDescription(taskDescription, getConfigContext());
- } catch (Exception e) {
- log.error("Cannot delete the task " + taskName, e);
- }
- }
-
- /**
- * Notifying the Task Scheduling Manager to delete the previous Task Description from the
- * Task Description Repository and add the edited task.
- *
- * @param taskDescription TaskDescription
- */
- public void editTaskDescription(TaskDescription taskDescription) {
- if (log.isDebugEnabled()) {
- log.debug("Editing the task " + taskDescription.getName());
- }
- if (schedulingManager.isContains(taskDescription.getName(), getConfigContext())) {
- schedulingManager.deleteTaskDescription(taskDescription, getConfigContext());
- schedulingManager.scheduleTask(taskDescription, null, getConfigContext());
- } else {
- log.error("Task " + taskDescription.getName() + "does not exist");
- }
- }
-
- public void editTaskDescriptionInOmElement(
- String taskElementString) throws TaskManagementException, XMLStreamException {
- OMElement taskElement = AXIOMUtil.stringToOM(taskElementString);
- if (log.isDebugEnabled()) {
- log.debug("Edit TaskDescription - Get a Task configuration :" + taskElement);
- }
- try {
- editTaskDescription(validateAndCreate(taskElement));
- } catch (Exception e) {
- String msg = "Error editing Task";
- throw new TaskManagementException(msg, e);
- }
- }
-
- /**
- * Returns the list of Task Descriptions that have been already added to the Task Description
- * Repository.
- *
- * @return A list of Task Descriptions
- */
- public List<TaskDescription> getAllTaskDescriptions() {
- List<TaskDescription> taskDescriptions = new ArrayList<TaskDescription>();
- Iterator<TaskDescription> iterator = schedulingManager.getAllTaskDescriptions(
- getConfigContext());
-
- while (iterator.hasNext()) {
- TaskDescription taskDescription = iterator.next();
- if (taskDescription != null) {
- taskDescriptions.add(taskDescription);
- }
- }
- if (log.isDebugEnabled()) {
- log.debug("All available Task based Scheduled Functions " + taskDescriptions);
- }
- return taskDescriptions;
- }
-
- public String getAllTaskDescriptionsInAnOMElement() throws AxisFault {
- OMElement rootElement =
- OMAbstractFactory.getOMFactory().createOMElement(new QName(TASK_EXTENSION_NS,
- "taskExtension", "task"));
- try {
- List<TaskDescription> descriptions = getAllTaskDescriptions();
- for (TaskDescription taskDescription : descriptions) {
- if (taskDescription != null) {
- OMElement taskElement =
- TaskDescriptionSerializer.serializeTaskDescription(TASK_OM_NAMESPACE,
- taskDescription);
- validateTaskElement(taskElement);
- rootElement.addChild(taskElement);
- }
- }
- } catch (TaskManagementException e) {
- String msg = "Error loading all tasks";
- log.error(msg, e);
- throw new AxisFault(msg, e);
- }
- if (log.isDebugEnabled()) {
- log.debug("Returning all TaskDescriptions as :" + rootElement);
- }
- return rootElement.toString();
- }
-
- /**
- * Returns the names of job groups that are being executed.
- *
- * @return An array of strings
- */
- public String[] getAllJobGroups() {
- List<String> strings = getTaskManager().getAllJobGroups();
- return strings.toArray(new String[strings.size()]);
- }
-
- /**
- * Returns the TaskDescription associates with a particular task name
- *
- * @param taskName Task Name
- * @return TaskDescription
- */
- public TaskDescription getTaskDescription(String taskName) {
- return schedulingManager.getTaskDescription(taskName, getConfigContext());
- }
-
- public boolean isContains(String taskName) {
- return schedulingManager.isContains(taskName, getConfigContext());
- }
-
- /**
- * @param taskClass taskClass
- * @return list of strings containing properties of the task class
- */
- public List<String> getPropertyNames(String taskClass) {
- return null;
- }
-
- /**
- * Returns the TaskManager instance currently being used
- *
- * @return TaskManager
- */
- private synchronized TaskManager getTaskManager() {
- return (TaskManager) getConfigContext().getProperty(
- TaskManager.CARBON_TASK_MANAGER);
- }
-
- /**
- * Validates the OMElement which has a particular TaskDescription
- * serialized into it.
- *
- * @param taskElement taskElement
- * @throws TaskManagementException TaskManagementException
- */
- private static void validateTaskElement(
- OMElement taskElement) throws TaskManagementException {
- if (taskElement == null) {
- handleException("Task Description OMElement can not be found.");
- }
- }
-
- /**
- * Handles the exception thrown and logs it.
- *
- * @param msg message to be logged
- * @throws TaskManagementException TaskManagementException
- */
- private static void handleException(String msg) throws TaskManagementException {
- log.error(msg);
- throw new TaskManagementException(msg);
- }
-
- /**
- * Handles the exception thrown and logs it.
- *
- * @param msg message to be logged
- * @param e exception thrown
- * @throws TaskManagementException TaskManagementException
- */
- private static void handleException(String msg, Exception e) throws TaskManagementException {
- log.error(msg, e);
- throw new TaskManagementException(msg, e);
- }
-
- /**
- * Validates an OMElement which has a TaskDescription serialized into it
- * and returns the corresponding TaskDescription
- *
- * @param taskElement OMElement containing the TaskDescription
- * @return TaskDescription
- * @throws TaskManagementException TaskManagementException
- */
- private static TaskDescription validateAndCreate(
- OMElement taskElement) throws TaskManagementException {
-
- validateTaskElement(taskElement);
- TaskDescription taskDescription =
- TaskDescriptionFactory.createTaskDescription(taskElement, TASK_OM_NAMESPACE);
- validateTaskDescription(taskDescription);
- if (log.isDebugEnabled()) {
- log.debug("Task Description : " + taskDescription);
- }
- return taskDescription;
- }
-
- /**
- * Validates TaskDescriptions
- *
- * @param description TaskDescription
- * @throws TaskManagementException TaskManagementException
- */
- private static void validateTaskDescription(
- TaskDescription description) throws TaskManagementException {
- if (description == null) {
- handleException("Task Description can not be found.");
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalingJob.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalingJob.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalingJob.java
deleted file mode 100644
index 852c6bd..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/AutoscalingJob.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.stratos.mediator.autoscale.lbautoscale.task;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.ManagedLifecycle;
-import org.apache.synapse.task.Task;
-import org.quartz.Job;
-import org.quartz.JobDetail;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
-import java.util.Map;
-
-public class AutoscalingJob implements Job {
-
- public static final String AUTOSCALER_TASK = "autoscalerTask";
-
- public static final String SYNAPSE_ENVI = "synapseEnv";
-
- private static final Log log = LogFactory.getLog(AutoscalingJob.class);
-
- public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
-
- try {
-
- Task task = null;
-
- JobDetail jobDetail = jobExecutionContext.getJobDetail();
-
- if (log.isDebugEnabled()) {
- log.debug("Executing Autoscaler task : " + jobDetail.getKey().getName());
- }
-
- @SuppressWarnings("rawtypes")
- Map mjdm = jobExecutionContext.getMergedJobDataMap();
-
- task = (Task) mjdm.get(AUTOSCALER_TASK);
-
- if (task instanceof ManagedLifecycle) {
- // Execute Autoscaler task
- ((ServiceRequestsInFlightAutoscaler) task).execute();
- }
-
- } catch (Exception e) {
- throw new JobExecutionException(e);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/ServiceRequestsInFlightAutoscaler.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/ServiceRequestsInFlightAutoscaler.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/ServiceRequestsInFlightAutoscaler.java
deleted file mode 100644
index 9e2562f..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/ServiceRequestsInFlightAutoscaler.java
+++ /dev/null
@@ -1,525 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.task;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import org.apache.axis2.clustering.ClusteringAgent;
-import org.apache.axis2.clustering.ClusteringFault;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.callables.InstanceCountCallable;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.ManagedLifecycle;
-import org.apache.synapse.core.SynapseEnvironment;
-import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
-import org.apache.synapse.task.Task;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
-import org.apache.stratos.mediator.autoscale.lbautoscale.callables.AppNodeSanityCheckCallable;
-import org.apache.stratos.mediator.autoscale.lbautoscale.callables.AutoscaleDeciderCallable;
-import org.apache.stratos.mediator.autoscale.lbautoscale.clients.CloudControllerClient;
-import org.apache.stratos.mediator.autoscale.lbautoscale.clients.CloudControllerOsgiClient;
-import org.apache.stratos.mediator.autoscale.lbautoscale.clients.CloudControllerStubClient;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.AppDomainContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.LoadBalancerContext;
-import org.apache.stratos.lb.common.replication.RequestTokenReplicationCommand;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleConstants;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleUtil;
-
-/**
- * Service request in flight autoscaler task for Stratos service level auto-scaling
- */
-public class ServiceRequestsInFlightAutoscaler implements Task, ManagedLifecycle {
-
- private static final Log log = LogFactory.getLog(ServiceRequestsInFlightAutoscaler.class);
-
- /**
- * This instance holds the loadbalancer configuration
- */
- private LoadBalancerConfiguration loadBalancerConfig;
-
- /**
- * Autoscaler service client instance
- */
- private CloudControllerClient autoscalerService;
-
- /**
- * AppDomainContexts for each domain
- * Key - domain
- * Value - Map of key - sub domain
- * value - {@link AppDomainContext}
- */
- private Map<String, Map<String, ?>> appDomainContexts =
- new HashMap<String, Map<String, ?>>();
-
- /**
- * LB Context for LB cluster
- */
- private final LoadBalancerContext lbContext = new LoadBalancerContext();
-
- /**
- * Attribute to keep track whether this instance is the primary load balancer.
- */
- private boolean isPrimaryLoadBalancer;
-
- /**
- * Keeps track whether this task is still running
- */
- private boolean isTaskRunning;
-
- /**
- * Thread pool used in this task to execute parallel tasks.
- */
- private ExecutorService executor = Executors.newFixedThreadPool(100);
-
- /**
- * Check that all app nodes in all clusters meet the minimum configuration
- */
- private void appNodesSanityCheck() {
-
- List<Future<Boolean>> jobList = new ArrayList<Future<Boolean>>();
-
- for (String serviceDomain : loadBalancerConfig.getServiceDomains()) {
-
- String msg =
- "Sanity check is failed to run. No Appdomain context is generated for the" +
- " domain " + serviceDomain;
-
- // get the list of service sub_domains specified in loadbalancer config
- String[] serviceSubDomains = loadBalancerConfig.getServiceSubDomains(serviceDomain);
-
- for (String serviceSubDomain : serviceSubDomains) {
- log.debug("Sanity check has started for: "+AutoscaleUtil.domainSubDomainString(serviceDomain, serviceSubDomain));
- AppDomainContext appCtxt;
- if (appDomainContexts.get(serviceDomain) != null) {
- appCtxt = (AppDomainContext) appDomainContexts.get(serviceDomain).get(serviceSubDomain);
-
- if (appCtxt != null) {
- // Concurrently perform the application node sanity check.
- Callable<Boolean> worker =
- new AppNodeSanityCheckCallable(serviceDomain, serviceSubDomain, autoscalerService, appCtxt);
- Future<Boolean> appNodeSanityCheck = executor.submit(worker);
- jobList.add(appNodeSanityCheck);
-
- } else{
- log.error(msg + " and sub domain " + serviceSubDomain + " combination.");
- }
- } else{
- log.error(msg);
- }
- }
- }
-
- // Retrieve the results of the concurrently performed sanity checks.
- for (Future<Boolean> job : jobList) {
- try {
- job.get();
- } catch (Exception ignore) {
- log.error(ignore.getMessage(), ignore);
- // no need to throw
- }
- }
-
- }
-
- /**
- * Autoscale the entire system, analyzing the requests in flight of each domain - sub domain
- */
- private void autoscale() {
- List<Future<Boolean>> jobList = new ArrayList<Future<Boolean>>();
-
- for (String serviceDomain : loadBalancerConfig.getServiceDomains()) {
-
- String msg =
- "Autoscaler check is failed to run. No Appdomain context is generated for the" +
- " domain " + serviceDomain;
-
- // get the list of service sub_domains specified in loadbalancer config
- String[] serviceSubDomains = loadBalancerConfig.getServiceSubDomains(serviceDomain);
-
- for (String serviceSubDomain : serviceSubDomains) {
-
- log.debug("Autoscaling analysis is starting to run for domain: " + serviceDomain +
- " and sub domain: " + serviceSubDomain);
-
- AppDomainContext appCtxt;
- if (appDomainContexts.get(serviceDomain) != null) {
- appCtxt = (AppDomainContext) appDomainContexts.get(serviceDomain).get(serviceSubDomain);
-
- if (appCtxt != null) {
-
- // Concurrently make the auto-scaling decisions
- Callable<Boolean> worker =
- new AutoscaleDeciderCallable(serviceDomain, serviceSubDomain, autoscalerService, appCtxt);
- Future<Boolean> autoscalerDeciderCheck = executor.submit(worker);
- jobList.add(autoscalerDeciderCheck);
-
- } else {
- log.error(msg + " and sub domain " + serviceSubDomain + " combination.");
- }
- } else {
- log.error(msg);
- }
- }
- }
-
- // Retrieve the results of the concurrently performed sanity checks.
- for (Future<Boolean> job : jobList) {
- try {
- job.get();
- } catch (Exception ignore) {
- log.error(ignore.getMessage(), ignore);
- // no need to throw
- }
- }
- }
-
- /**
- * We compute the number of running instances of a particular domain using clustering agent.
- */
- private void computeRunningAndPendingInstances() {
-
- int runningInstances = 0, pendingInstances = 0;
-
- List<Future<Boolean>> jobList = new ArrayList<Future<Boolean>>();
-
- for (String serviceDomain : loadBalancerConfig.getServiceDomains()) {
-
- // get the list of service sub_domains specified in loadbalancer config
- String[] serviceSubDomains = loadBalancerConfig.getServiceSubDomains(serviceDomain);
-
- for (String serviceSubDomain : serviceSubDomains) {
-
- AppDomainContext appCtxt;
- if (appDomainContexts.get(serviceDomain) != null) {
- appCtxt = (AppDomainContext) appDomainContexts.get(serviceDomain).get(serviceSubDomain);
-
- log.debug("Values in App domain context: " +
- appCtxt.getPendingInstanceCount() +
- " - " +
- appCtxt.getRunningInstanceCount() +
- " - Ctxt: " +
- appCtxt.hashCode());
-
- if (appCtxt != null) {
- Callable<Boolean> worker =
- new InstanceCountCallable(serviceDomain, serviceSubDomain, autoscalerService, appCtxt);
- Future<Boolean> countInstancesJob = executor.submit(worker);
- jobList.add(countInstancesJob);
- }
- }
- }
- }
-
- for (Future<Boolean> job : jobList) {
- try {
- job.get();
- } catch (Exception ignore) {
- log.error(ignore.getMessage(), ignore);
- // no need to throw
- }
- }
-
- /* Calculate running load balancer instances */
-
- // count this LB instance in.
- runningInstances = 1;
-
- runningInstances += AutoscalerTaskDSHolder.getInstance().getAgent().getAliveMemberCount();
-
- lbContext.setRunningInstanceCount(runningInstances);
-
- if (AutoscalerTaskDSHolder.getInstance().getAgent().getParameter("domain") == null) {
- String msg = "Clustering Agent's domain parameter is null. Please specify a domain" +
- " name in axis2.xml of Elastic Load Balancer.";
- log.error(msg);
- throw new RuntimeException(msg);
- }
-
- String lbDomain = AutoscalerTaskDSHolder.getInstance().getAgent().getParameter("domain").getValue().toString();
-
- String lbSubDomain = null;
-
- if (AutoscalerTaskDSHolder.getInstance().getAgent().getParameter("subDomain") != null) {
- lbSubDomain =
- AutoscalerTaskDSHolder.getInstance().getAgent().getParameter("subDomain").getValue().toString();
- }
-
- // reset
- pendingInstances = 0;
- try {
- pendingInstances = lbContext.getPendingInstanceCount();
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- // no need to throw
- }
-
- lbContext.setPendingInstanceCount(pendingInstances);
-
- log.debug("Load Balancer members of domain: " +
- lbDomain +
- " and sub domain: " +
- lbSubDomain +
- " running instances (including this): " +
- runningInstances +
- " - pending instances: "
- +
- pendingInstances);
-
- }
-
- @Override
- public void destroy() {
- appDomainContexts.clear();
- log.debug("Cleared AppDomainContext Map.");
- }
-
- /**
- * This is method that gets called periodically when the task runs.
- * <p/>
- * The exact sequence of execution is shown in this method.
- */
- @Override
- public void execute() {
-
- appDomainContexts =
- AutoscaleUtil.getAppDomainContexts(
- AutoscalerTaskDSHolder.getInstance().getConfigCtxt(),
- loadBalancerConfig);
-
- if (isTaskRunning) {
- log.debug("Task is already running!");
- return;
- }
- try {
- isTaskRunning = true;
- setIsPrimaryLB();
- if (!isPrimaryLoadBalancer) {
- log.debug("This is not the primary load balancer, hence will not " +
- "perform any sanity check.");
- return;
- }
- sanityCheck();
- autoscale();
- } finally {
- // if there are any changes in the request length
- if (Boolean.parseBoolean(System.getProperty(AutoscaleConstants.IS_TOUCHED))) {
- // primary LB will send out replication message to all load balancers
- sendReplicationMessage();
- }
- isTaskRunning = false;
- log.debug("Task finished a cycle.");
- }
- }
-
- @Override
- public void init(final SynapseEnvironment synEnv) {
-
- String msg = "Autoscaler Service initialization failed and cannot proceed.";
-
- loadBalancerConfig = AutoscalerTaskDSHolder.getInstance().getWholeLoadBalancerConfig();
-
- if (loadBalancerConfig == null) {
- log.error(msg + "Reason: Load balancer configuration is null.");
- throw new RuntimeException(msg);
- }
-
- ConfigurationContext configCtx = ((Axis2SynapseEnvironment) synEnv).getAxis2ConfigurationContext();
- AutoscalerTaskDSHolder.getInstance().setConfigCtxt(configCtx);
-
- appDomainContexts = AutoscaleUtil.getAppDomainContexts(configCtx, loadBalancerConfig);
-
- AutoscalerTaskDSHolder.getInstance().setAgent(configCtx.getAxisConfiguration().getClusteringAgent());
-
- boolean useEmbeddedAutoscaler = loadBalancerConfig.getLoadBalancerConfig().useEmbeddedAutoscaler();
-
- try {
-
- if(useEmbeddedAutoscaler){
- autoscalerService = new CloudControllerOsgiClient();
- } else{
- autoscalerService = new CloudControllerStubClient();
- }
- // let's initialize the auto-scaler service
- autoscalerService.init();
-
- }catch (Exception e) {
- log.error(msg, e);
- throw new RuntimeException(msg, e);
- }
-
- if (log.isDebugEnabled()) {
-
- log.debug("Autoscaler task is initialized.");
-
- }
- }
-
- /**
- * Sanity check to see whether the number of LBs is the number specified in the LB config
- */
- private void loadBalancerSanityCheck() {
-
- log.debug("Load balancer sanity check has started.");
-
- // get current LB instance count
- int currentLBInstances = lbContext.getInstances();
-
- LoadBalancerConfiguration.LBConfiguration lbConfig =
- loadBalancerConfig.getLoadBalancerConfig();
-
- // get minimum requirement of LB instances
- int requiredInstances = lbConfig.getInstances();
-
- if (currentLBInstances < requiredInstances) {
- log.debug("LB Sanity check failed. Running/Pending LB instances: " + currentLBInstances +
- ". Required LB instances: " + requiredInstances);
- int diff = requiredInstances - currentLBInstances;
-
- // gets the domain of the LB
- String lbDomain =
- AutoscalerTaskDSHolder
- .getInstance()
- .getAgent()
- .getParameter("domain")
- .getValue()
- .toString();
- String lbSubDomain =
- AutoscalerTaskDSHolder
- .getInstance()
- .getAgent()
- .getParameter("subDomain")
- .getValue()
- .toString();
-
- // Launch diff number of LB instances
- log.debug("Launching " + diff + " LB instances.");
-
- runInstances(lbContext, lbDomain, lbSubDomain, diff);
- }
- }
-
- private int runInstances(final LoadBalancerContext context, final String domain,
- final String subDomain,
- int diff) {
-
- int successfullyStartedInstanceCount = diff;
-
- while (diff > 0) {
- // call autoscaler service and ask to spawn an instance
- // and increment pending instance count only if autoscaler service returns
- // true.
- try {
- String ip = autoscalerService.startInstance(domain, subDomain);
-
- if (ip == null || ip.isEmpty()) {
- log.debug("Instance start up failed. domain: " +
- domain +
- ", sub domain: " +
- subDomain);
- successfullyStartedInstanceCount--;
- } else {
- log.debug("An instance of domain: " +
- domain +
- " and sub domain: " +
- subDomain +
- " is started up.");
- if (context != null) {
- context.incrementPendingInstances(1);
- }
- }
- } catch (Exception e) {
- log.error("Failed to start an instance of sub domain: " + subDomain +
- " of domain : " + domain + ".\n", e);
- successfullyStartedInstanceCount--;
- }
-
- diff--;
- }
-
- return successfullyStartedInstanceCount;
- }
-
- /**
- * This method makes sure that the minimum configuration of the clusters in the system is
- * maintained
- */
- private void sanityCheck() {
-
- if (!isPrimaryLoadBalancer) {
- log.debug("This is not the primary load balancer, hence will not " +
- "perform any sanity check.");
- return;
- }
-
- log.debug("This is the primary load balancer, starting to perform sanity checks.");
-
- computeRunningAndPendingInstances();
- loadBalancerSanityCheck();
- appNodesSanityCheck();
- }
-
- /**
- * Replicate information needed to take autoscaling decision for other ELBs
- * in the cluster.
- */
- private void sendReplicationMessage() {
-
- ClusteringAgent clusteringAgent = AutoscalerTaskDSHolder.getInstance().getAgent();
- if (clusteringAgent != null) {
- RequestTokenReplicationCommand msg = new RequestTokenReplicationCommand();
- msg.setAppDomainContexts(appDomainContexts);
- try {
- clusteringAgent.sendMessage(msg, true);
- System.setProperty(AutoscaleConstants.IS_TOUCHED, "false");
- log.debug("Request token replication messages sent out successfully!!");
-
- } catch (ClusteringFault e) {
- log.error("Failed to send the request token replication message.", e);
- }
- }
- else {
- log
- .debug("Clustering Agent is null. Hence, unable to send out the replication message.");
- }
- }
-
- /**
- * This method will check whether this LB is the primary LB or not and set
- * attribute accordingly.
- */
- private void setIsPrimaryLB() {
-
- ClusteringAgent clusteringAgent = AutoscalerTaskDSHolder.getInstance().getAgent();
- if (clusteringAgent != null) {
-
- isPrimaryLoadBalancer = clusteringAgent.isCoordinator();
-
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/TaskSchedulingManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/TaskSchedulingManager.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/TaskSchedulingManager.java
deleted file mode 100644
index b97deb4..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/task/TaskSchedulingManager.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.task;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.task.TaskDescription;
-import org.apache.synapse.task.TaskDescriptionRepository;
-import org.apache.synapse.task.TaskScheduler;
-import org.wso2.carbon.task.TaskManager;
-
-import java.util.Iterator;
-import java.util.Map;
-
-public class TaskSchedulingManager {
-
- private static final Log log = LogFactory.getLog(TaskSchedulingManager.class);
-
- private static TaskSchedulingManager thisInstance = new TaskSchedulingManager();
-
- public static TaskSchedulingManager getInstance() {
- return thisInstance;
- }
-
- /**
- * This method adds a particular Task to the Task Description Repository and schedule it
- * for the execution.
- *
- * @param taskDescription TaskDescription
- * @param resources Map containing require meta data for the task execution.
- * @param configurationContext ConfigurationContext
- */
- public void scheduleTask(TaskDescription taskDescription, Map<String, Object> resources,
- ConfigurationContext configurationContext) {
- if (log.isDebugEnabled()) {
- log.debug("Adding a Task Description to the Task Description Repository");
- }
-
- getTaskDescriptionRepository(configurationContext).addTaskDescription(taskDescription);
- getTaskScheduler(configurationContext).scheduleTask(
- taskDescription, resources, AutoscalingJob.class);
-
- if (log.isDebugEnabled()) {
- log.debug("Task Description " + taskDescription.getName() +
- " added to the Task Description Repository");
- }
- }
-
- /**
- * Returns a Task Description with a given name from the Task Description Repository.
- *
- * @param taskName taskName
- * @param configurationContext ConfigurationContext
- * @return TaskDescription
- */
- public TaskDescription getTaskDescription(
- String taskName, ConfigurationContext configurationContext) {
- if (log.isDebugEnabled()) {
- log.debug("Returning a Start up : " + taskName + " from the configuration");
- }
-
- TaskDescription taskDescription = getTaskDescriptionRepository(
- configurationContext).getTaskDescription(taskName);
-
- if (taskDescription != null) {
- if (log.isDebugEnabled()) {
- log.debug("Returning a Task Description : " + taskDescription);
-
- }
- return taskDescription;
- } else {
- if (log.isDebugEnabled()) {
- log.debug("No Task Description can be found with name :" + taskName);
- }
- return null;
- }
- }
-
- /**
- * This method search for a given Task which has already been added to the Task Description
- * Repository and removes it.
- *
- * @param taskDescription TaskDescription
- * @param configurationContext ConfigurationContext
- */
- public void deleteTaskDescription(TaskDescription taskDescription, ConfigurationContext configurationContext) {
- String taskName = null;
- if (taskDescription != null) {
- taskName = taskDescription.getName();
- getTaskDescriptionRepository(configurationContext).removeTaskDescription(taskName);
- getTaskScheduler(configurationContext).deleteTask(taskName, taskDescription.getGroup());
-
- if (log.isDebugEnabled()) {
- log.debug("Deleted TaskDescription : " + taskName + " from the configuration");
- }
- } else {
- log.warn("Unable to delete the Task " + taskName
- + ",as it doesn't exist in the Repository");
- }
- }
-
- /**
- * Retrieves all Task Descriptions added to the Task Description Repository at a given instance.
- *
- * @param configurationContext ConfigurationContext
- * @return TaskDescription Iterator
- */
- public Iterator<TaskDescription> getAllTaskDescriptions(
- ConfigurationContext configurationContext) {
- if (log.isDebugEnabled()) {
- log.debug("Returning a All TaskDescription from the configuration");
- }
- return getTaskDescriptionRepository(configurationContext).getAllTaskDescriptions();
- }
-
- /**
- * This method checks whether a particular Task has already been added to the Task Description
- * Repository associated with the context of this execution and returns a flag indicating the
- * existence.
- *
- * @param taskName Name of the task to be searched
- * @param configurationContext ConfigurationContext
- * @return a boolean depending on the existence of a task
- */
- public boolean isContains(String taskName, ConfigurationContext configurationContext) {
- return !getTaskDescriptionRepository(configurationContext).isUnique(taskName);
- }
-
- /**
- * Returns the Carbon TaskDescriptionRepository instance that carries details of the added
- * tasks for execution.
- *
- * @param configurationContext ConfigurationContext
- * @return TaskDescriptionRepository
- */
- private synchronized TaskDescriptionRepository getTaskDescriptionRepository(
- ConfigurationContext configurationContext) {
- if (log.isDebugEnabled()) {
- log.debug("Retrieving access to Task Description Repository");
- }
- return (TaskDescriptionRepository) configurationContext.getProperty(
- TaskManager.CARBON_TASK_REPOSITORY);
- }
-
- /**
- * Returns the carbon TaskScheduler associated with the context of scheduling the task execution
- *
- * @param configurationContext ConfigurationContext
- * @return TaskScheduler
- */
- private synchronized TaskScheduler getTaskScheduler(ConfigurationContext configurationContext) {
- if (log.isDebugEnabled()) {
- log.debug("Retrieving access to Task Scheduler");
- }
- return (TaskScheduler) configurationContext.getProperty(
- TaskManager.CARBON_TASK_SCHEDULER);
- }
-
- public void shutDown(ConfigurationContext configurationContext) {
- if (log.isDebugEnabled()) {
- log.debug("Starting to shut down tasks");
- }
-
-// getTaskDescriptionRepository(configurationContext).addTaskDescription(taskDescription);
- getTaskScheduler(configurationContext).shutDown();
-
- if (log.isDebugEnabled()) {
- log.debug("All tasks shut down");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscaleConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscaleConstants.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscaleConstants.java
deleted file mode 100644
index ed549c3..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscaleConstants.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.util;
-
-/**
- * Constants
- */
-public final class AutoscaleConstants {
- public static final String REQUEST_ID = "request.id";
- public static final String APP_DOMAIN_CONTEXTS = "autoscale.app.domain.contexts";
- public static final String TARGET_DOMAIN = "autoscale.target.domain";
- public static final String TARGET_SUB_DOMAIN = "autoscale.target.sub.domain";
- public static final String LOAD_BALANCER_CONFIG = "loadbalancer.conf";
-
- /**
- * we use this to track the changes happen to request token list lengths.
- */
- public static final String IS_TOUCHED = "is_touched";
-
- /**
- * We'll check whether a server is started up in every this much of time.
- * (in milliseconds)
- */
- public static final int SERVER_START_UP_CHECK_TIME = 30000;
-
- /**
- * We'll check whether an instance is left the cluster in every this much of time.
- * (in milliseconds)
- */
- public static final int INSTANCE_REMOVAL_CHECK_TIME = 5000;
-
- /**
- * Name of the EC2 instance tag which if set on an instance, the autoscaler will not
- * terminate such instance
- */
- public static final String AVOID_TERMINATION = "avoidTermination";
-
- public static enum InstanceState {
- RUNNING("running"), PENDING("pending"), TERMINATED("terminated"), SHUTTING_DOWN("shutting-down");
-
- private String state;
-
- InstanceState(String state) {
- this.state = state;
- }
-
- public String getState() {
- return state;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscaleUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscaleUtil.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscaleUtil.java
deleted file mode 100644
index 747d3a2..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/util/AutoscaleUtil.java
+++ /dev/null
@@ -1,359 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.util;
-
-import org.apache.axiom.om.util.Base64;
-import org.apache.axis2.clustering.ClusteringAgent;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.http.protocol.HTTP;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
-import org.apache.stratos.mediator.autoscale.lbautoscale.clients.CloudControllerClient;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.AppDomainContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.LoadBalancerContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.state.check.PendingInstancesStateChecker;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Utility methods for Autoscale mediator
- */
-public final class AutoscaleUtil {
-
- private static final Log log = LogFactory.getLog(AutoscaleUtil.class);
-
- private AutoscaleUtil() {
- }
-
- /**
- * handles the exception
- *
- * @param msg exception message
- */
- public static void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- /**
- * handles the exception
- *
- * @param msg exception message
- * @param e exception
- */
- public static void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
-
- /**
- * Returns the contents of the file in a byte array
- *
- * @param file - Input File
- * @return Bytes from the file
- * @throws java.io.IOException, if retrieving the file contents failed.
- */
- public static byte[] getBytesFromFile(File file) throws IOException {
- if (!file.exists()) {
- log.error("Payload file " + file.getAbsolutePath() + " does not exist");
- return null;
- }
- InputStream is = new FileInputStream(file);
- byte[] bytes;
-
- try {
- // Get the size of the file
- long length = file.length();
-
- // You cannot create an array using a long type.
- // It needs to be an int type.
- // Before converting to an int type, check
- // to ensure that file is not larger than Integer.MAX_VALUE.
- if (length > Integer.MAX_VALUE) {
- if (log.isDebugEnabled()) {
- log.debug("File is too large");
- }
- }
-
- // Create the byte array to hold the data
- bytes = new byte[(int) length];
-
- // Read in the bytes
- int offset = 0;
- int numRead;
- while (offset < bytes.length
- && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
- offset += numRead;
- }
-
- // Ensure all the bytes have been read in
- if (offset < bytes.length) {
- throw new IOException("Could not completely read file " + file.getName());
- }
- } finally {
- // Close the input stream and return bytes
- is.close();
- }
-
- return bytes;
- }
-
- /**
- * Replaces the variables
- *
- * @param text input string
- * @return output String
- */
- public static String replaceVariables(String text) {
- int indexOfStartingChars;
- int indexOfClosingBrace;
-
- // The following condition deals with properties.
- // Properties are specified as ${system.property},
- // and are assumed to be System properties
- if ((indexOfStartingChars = text.indexOf("${")) != -1 &&
- (indexOfClosingBrace = text.indexOf("}")) != -1) { // Is a property used?
- String var = text.substring(indexOfStartingChars + 2,
- indexOfClosingBrace);
-
- String propValue = System.getProperty(var);
- if (propValue == null) {
- propValue = System.getenv(var);
- }
- if (propValue != null) {
- text = text.substring(0, indexOfStartingChars) + propValue +
- text.substring(indexOfClosingBrace + 1);
- }
- }
- return text;
- }
-
-/* public static InstanceManager createEC2InstanceManager(String accessKey,
- String secretKey,
- String instanceMgtEPR) {
- AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
- AmazonEC2Client ec2Client = new AmazonEC2Client(awsCredentials);
- ec2Client.setEndpoint(instanceMgtEPR);
- return new InstanceManager(ec2Client);
- }*/
-
- public static String getUserData(String payloadFileName) {
- String userData = null;
- try {
- File file = new File(payloadFileName);
- if (!file.exists()) {
- handleException("Payload file " + payloadFileName + " does not exist");
- }
- if (!file.canRead()) {
- handleException("Payload file " + payloadFileName + " does cannot be read");
- }
- byte[] bytes = AutoscaleUtil.getBytesFromFile(file);
- if (bytes != null) {
-// /BASE64.e encoder = new BASE64Encoder();
- userData = Base64.encode(bytes);
- }
- } catch (IOException e) {
- AutoscaleUtil.handleException("Cannot read data from payload file " + payloadFileName,
- e);
- }
- return userData;
- }
-
- /*public static boolean areEqual(List<GroupIdentifier> securityGroups1, String[] sourceGroups2) {
- for (String sourceGroup : sourceGroups2) {
- boolean isSourceGroupFound = false;
- for (GroupIdentifier securityGroup : securityGroups1) {
- if (securityGroup.getGroupName().equals(sourceGroup)) {
- isSourceGroupFound = true;
- }
- }
- if (!isSourceGroupFound) {
- return false;
- }
- }
- return true;
- } */
-
- /**
- * TODO These methods should use to common place since these are using endpoints and mediators
- */
- public static int getTenantId(String url) {
- String address = url;
- String servicesPrefix = "/t/";
- if (address != null && address.contains(servicesPrefix)) {
- int domainNameStartIndex =
- address.indexOf(servicesPrefix) + servicesPrefix.length();
- int domainNameEndIndex = address.indexOf('/', domainNameStartIndex);
- String domainName = address.substring(domainNameStartIndex,
- domainNameEndIndex == -1 ? address.length() : domainNameEndIndex);
- // return tenant id if domain name is not null
- if (domainName != null) {
- try {
- return AutoscalerTaskDSHolder.getInstance().getRealmService().getTenantManager().getTenantId(domainName);
- } catch (org.wso2.carbon.user.api.UserStoreException e) {
- log.error("An error occurred while obtaining the tenant id.", e);
- }
- }
- }
- // return 0 if the domain name is null
- return 0;
- }
-
- /**
- * TODO These methods should use to common place since these are using endpoints and mediators
- */
- @SuppressWarnings("unchecked")
- public static String getTargetHost(MessageContext synCtx) {
- org.apache.axis2.context.MessageContext axis2MessageContext =
- ((Axis2MessageContext) synCtx).getAxis2MessageContext();
- Map<String, String> headers =
- (Map<String, String>) axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
- String address = headers.get(HTTP.TARGET_HOST);
- if (address.contains(":")) {
- address = address.substring(0, address.indexOf(":"));
- }
- return address;
- }
-
- @SuppressWarnings("unchecked")
- public static Map<String, Map<String, ?>> getAppDomainContexts(ConfigurationContext configCtx,
- LoadBalancerConfiguration lbConfig) {
- Map<String, Map<String, ?>> oldAppDomainContexts =
- (Map<String, Map<String, ?>>) configCtx.getPropertyNonReplicable(AutoscaleConstants.APP_DOMAIN_CONTEXTS);
- Map<String, Map<String, ?>> newAppDomainContexts = new HashMap<String, Map<String, ?>>();
-
- ClusteringAgent clusteringAgent = configCtx.getAxisConfiguration().getClusteringAgent();
-
- for (String domain : lbConfig.getServiceDomains()) {
-
- for (String subDomain : lbConfig.getServiceSubDomains(domain)) {
- if (clusteringAgent.getGroupManagementAgent(domain, subDomain) == null) {
- throw new SynapseException("Axis2 clustering GroupManagementAgent for domain: " + domain +
- ", sub-domain: " + subDomain +
- " has not been defined");
- }
-
- if(oldAppDomainContexts == null || oldAppDomainContexts.get(domain) == null ||
- (oldAppDomainContexts.get(domain) != null && oldAppDomainContexts.get(domain).get(subDomain) == null)){
-
- AppDomainContext appCtxt = new AppDomainContext(lbConfig.getServiceConfig(domain,
- subDomain));
-
- addAppDomainContext(newAppDomainContexts, domain, subDomain, appCtxt);
-
- } else {
- addAppDomainContext(newAppDomainContexts, domain, subDomain, (AppDomainContext) oldAppDomainContexts.get(domain).get(subDomain));
- }
-
- }
-
- }
-// }
- configCtx.setNonReplicableProperty(AutoscaleConstants.APP_DOMAIN_CONTEXTS,
- newAppDomainContexts);
-
- return newAppDomainContexts;
- }
-
-
- private static void addAppDomainContext(Map<String, Map<String, ?>> appDomainContexts,
- String domain, String subDomain, AppDomainContext appCtxt) {
-
- Map<String, AppDomainContext> map ;
-
- if(appDomainContexts.containsKey(domain)){
- map = (Map<String, AppDomainContext>) appDomainContexts.get(domain);
- }
- else{
- map = new HashMap<String, AppDomainContext>();
- }
- // put this appDomainContext
- map.put(subDomain, appCtxt);
-
- // update the parent map
- appDomainContexts.put(domain, map);
-
- }
-
- public static String domainSubDomainString(String domain, String subDomain){
- return "Domain: "+domain+" - Sub Domain: "+subDomain;
- }
-
- public static int runInstances(final CloudControllerClient client, final LoadBalancerContext context, final String domain,
- final String subDomain, int diff) {
-
- int successfullyStartedInstanceCount = diff;
-
- if(context == null){
- // can't help
- return 0;
- }
-
- while (diff > 0) {
- // call autoscaler service and ask to spawn an instance
- // and increment pending instance count only if autoscaler service returns
- // true.
- try {
- String ip = client.startInstance(domain, subDomain);
-
- if (ip == null || ip.isEmpty()) {
- log.debug("Instance start up failed for " + domainSubDomainString(domain, subDomain));
- successfullyStartedInstanceCount--;
-
- } else {
- log.debug("An instance of " + domainSubDomainString(domain, subDomain) +
- " is started up.");
- if (context != null) {
- context.incrementPendingInstances(1);
- }
- }
- } catch (Exception e) {
- log.error("Failed to start an instance of " + domainSubDomainString(domain, subDomain) + ".\n", e);
- successfullyStartedInstanceCount--;
- }
-
- diff--;
- }
-
- if (successfullyStartedInstanceCount > 0) {
-
- Thread stateChecker =
- new Thread(new PendingInstancesStateChecker(
- context,
- domain,
- subDomain,
- successfullyStartedInstanceCount,
- context.getRunningInstanceCount(),
- client));
- stateChecker.start();
- }
-
- return successfullyStartedInstanceCount;
- }
-
-}
[3/3] git commit: Removed obsolete component
org.apache.stratos.mediator.autoscale and feature
org.apache.stratos.mediator.autoscale.feature
Posted by im...@apache.org.
Removed obsolete component org.apache.stratos.mediator.autoscale and feature org.apache.stratos.mediator.autoscale.feature
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/947eb5a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/947eb5a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/947eb5a6
Branch: refs/heads/master
Commit: 947eb5a6b59d2372f07bd7e4bbf3ec2e65bfcb7d
Parents: 3959b1a
Author: Imesh Gunaratne <im...@apache.org>
Authored: Mon Nov 4 12:58:31 2013 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Mon Nov 4 12:58:31 2013 +0530
----------------------------------------------------------------------
.../pom.xml | 135 -----
.../callables/AppNodeSanityCheckCallable.java | 86 ---
.../callables/AutoscaleDeciderCallable.java | 241 ---------
.../callables/InstanceCountCallable.java | 78 ---
.../callables/PendingInstanceCountCallable.java | 65 ---
.../callables/RunningInstanceCountCallable.java | 68 ---
.../clients/CloudControllerClient.java | 66 ---
.../clients/CloudControllerOsgiClient.java | 82 ---
.../clients/CloudControllerStubClient.java | 93 ----
.../lbautoscale/context/AppDomainContext.java | 170 ------
.../context/LoadBalancerContext.java | 104 ----
.../AutoscalerTaskServiceComponent.java | 325 ------------
.../lbautoscale/internal/RegistryManager.java | 54 --
.../mediators/AutoscaleInMediator.java | 174 ------
.../mediators/AutoscaleOutMediator.java | 78 ---
.../check/PendingInstancesStateChecker.java | 148 ------
.../check/TerminatingInstancesStateChecker.java | 89 ----
.../task/AutoscalerTaskInitializer.java | 50 --
.../task/AutoscalerTaskMgmtAdminService.java | 348 ------------
.../lbautoscale/task/AutoscalingJob.java | 68 ---
.../task/ServiceRequestsInFlightAutoscaler.java | 525 -------------------
.../lbautoscale/task/TaskSchedulingManager.java | 188 -------
.../lbautoscale/util/AutoscaleConstants.java | 68 ---
.../lbautoscale/util/AutoscaleUtil.java | 359 -------------
.../util/AutoscalerTaskDSHolder.java | 129 -----
...rg.apache.synapse.config.xml.MediatorFactory | 19 -
...apache.synapse.config.xml.MediatorSerializer | 19 -
.../src/main/resources/synapse-load-average.xml | 138 -----
.../resources/synapse-messages-in-flight.xml | 135 -----
.../synapse-service-messages-in-flight.xml | 108 ----
.../lbautoscale/AppDomainContextsTest.java | 122 -----
.../src/test/resources/loadbalancer.conf | 50 --
.../pom.xml | 91 ----
.../distribution/src/main/license/LICENSE | 2 +-
34 files changed, 1 insertion(+), 4474 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/pom.xml b/components/org.apache.stratos.mediator.autoscale/pom.xml
deleted file mode 100644
index 47e17b7..0000000
--- a/components/org.apache.stratos.mediator.autoscale/pom.xml
+++ /dev/null
@@ -1,135 +0,0 @@
-<?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.
- ~
- -->
-
-
-<!--
-We need to modify this file since this copied from branch
--->
-<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>4.0.0-SNAPSHOT</version>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.stratos</groupId>
- <artifactId>org.apache.stratos.mediator.autoscale</artifactId>
- <packaging>bundle</packaging>
- <name>Apache Stratos - Autoscale Mediator BE</name>
- <url>http://apache.org</url>
-
- <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>
- <version>1.4.0</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
- <Bundle-Name>${project.artifactId}</Bundle-Name>
- <Export-Package>
- !org.org.apache.stratos.mediator.autoscale.lbautoscale.internal,
- org.apache.stratos.mediator.autoscale.*
- </Export-Package>
- <Private-Package>org.apache.stratos.mediator.autoscale.lbautoscale.internal</Private-Package>
- <Import-Package>
- !javax.xml.namespace,
- javax.xml.namespace; version=0.0.0,
- !org.apache.commons.logging,
- org.apache.commons.logging; version=0.0.0,
- org.apache.axis2.*,
- org.apache.synapse.*,
- org.wso2.carbon.task.*; version=0.0.0,
- org.wso2.carbon.core.*,
- org.apache.stratos.lb.common.*,
- org.apache.stratos.lb.autoscaler.service.stub.*; version=0.0.0,
- org.wso2.carbon.utils.*,
- org.apache.axiom.om; version="${axiom.osgi.version.range}",
- org.apache.stratos.cloud.controller.*,
- *; resolution:=optional
- </Import-Package>
- <DynamicImport-Package>*</DynamicImport-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.axis2.wso2</groupId>
- <artifactId>axis2</artifactId>
- <version>1.6.1.wso2v9</version>
- </dependency>
- <dependency>
- <groupId>org.apache.synapse</groupId>
- <artifactId>synapse-core</artifactId>
- <version>${synapse.core.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.stratos</groupId>
- <artifactId>org.apache.stratos.lb.cartridge.autoscaler.service.stub</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.core</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.apache.stratos</groupId>
- <artifactId>org.apache.stratos.lb.common</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.stratos</groupId>
- <artifactId>org.apache.stratos.cloud.controller</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.task</artifactId>
- <version>${wso2carbon.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.synapse</groupId>
- <artifactId>synapse-tasks</artifactId>
- <version>2.1.1-wso2v4</version>
- </dependency>
-
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/AppNodeSanityCheckCallable.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/AppNodeSanityCheckCallable.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/AppNodeSanityCheckCallable.java
deleted file mode 100644
index c535489..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/AppNodeSanityCheckCallable.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.stratos.mediator.autoscale.lbautoscale.callables;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.ServiceConfiguration;
-import org.apache.stratos.mediator.autoscale.lbautoscale.clients.CloudControllerClient;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.AppDomainContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleUtil;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-
-import java.util.concurrent.Callable;
-
-/** Performing sanity checks for each service domain, sub domain combination **/
-public class AppNodeSanityCheckCallable implements Callable<Boolean> {
-
- private static final Log log = LogFactory.getLog(AppNodeSanityCheckCallable.class);
- private String domain;
- private String subDomain;
- private CloudControllerClient client;
- private AppDomainContext appDomainContext;
- private ServiceConfiguration serviceConfig;
-
- public AppNodeSanityCheckCallable(String domain, String subDomain, CloudControllerClient client, AppDomainContext appCtxt){
- this.domain = domain;
- this.subDomain = subDomain;
- this.client = client;
- this.appDomainContext = appCtxt;
- serviceConfig =
- AutoscalerTaskDSHolder.getInstance().getWholeLoadBalancerConfig().getServiceConfig(this.domain,
- this.subDomain);
- }
-
- @Override
- public Boolean call() throws Exception {
-
- if (appDomainContext != null) {
- int currentInstances = 0;
- // we're considering both running and pending instance count
- currentInstances = appDomainContext.getInstances();
-
- int requiredInstances = serviceConfig.getMinAppInstances();
-
- // we try to maintain the minimum number of instances required
- if (currentInstances < requiredInstances) {
- log.debug("App domain Sanity check failed for " +
- AutoscaleUtil.domainSubDomainString(domain, subDomain) +
- " . Current instances: " +
- currentInstances +
- ". Required instances: " +
- requiredInstances);
-
- int diff = requiredInstances - currentInstances;
-
- // Launch diff number of App instances
- log.debug("Launching " +
- diff +
- " App instances for " +AutoscaleUtil.domainSubDomainString(domain, subDomain));
-
- // FIXME: should we need to consider serviceConfig.getInstancesPerScaleUp()?
- AutoscaleUtil.runInstances(client, appDomainContext, this.domain, this.subDomain, diff);
- }
- }
-
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/AutoscaleDeciderCallable.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/AutoscaleDeciderCallable.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/AutoscaleDeciderCallable.java
deleted file mode 100644
index 84705bb..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/AutoscaleDeciderCallable.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.callables;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration.ServiceConfiguration;
-import org.apache.stratos.mediator.autoscale.lbautoscale.clients.CloudControllerClient;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.AppDomainContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.state.check.TerminatingInstancesStateChecker;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleUtil;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-
-import java.util.concurrent.Callable;
-
-/** Take auto-scaling decisions for each service domain, sub domain combination **/
-public class AutoscaleDeciderCallable implements Callable<Boolean> {
-
- private static final Log log = LogFactory.getLog(AutoscaleDeciderCallable.class);
- private String domain;
- private String subDomain;
- private CloudControllerClient client;
- private AppDomainContext appDomainContext;
- private ServiceConfiguration serviceConfig;
- private String clusterStr;
-
- public AutoscaleDeciderCallable(String domain, String subDomain, CloudControllerClient client, AppDomainContext appCtxt){
- this.domain = domain;
- this.subDomain = subDomain;
- this.client = client;
- this.appDomainContext = appCtxt;
- clusterStr = AutoscaleUtil.domainSubDomainString(domain, subDomain);
- }
-
- @Override
- public Boolean call() throws Exception {
-
- // expire tokens
- if (appDomainContext != null) {
- appDomainContext.expireRequestTokens();
-
- serviceConfig = appDomainContext.getServiceConfig();
-
- appDomainContext.recordRequestTokenListLength();
- if (!appDomainContext.canMakeScalingDecision()) {
- return true;
- }
-
- long average = appDomainContext.getAverageRequestsInFlight();
- int runningAppInstances = appDomainContext.getRunningInstanceCount();
- int terminatingAppInstances = appDomainContext.getTerminatingInstanceCount();
-
- int maxRPS = serviceConfig.getMaxRequestsPerSecond();
- double taskInterval =
- AutoscalerTaskDSHolder
- .getInstance()
- .getWholeLoadBalancerConfig()
- .getLoadBalancerConfig()
- .getAutoscalerTaskInterval() / (double)1000;
- double aur = serviceConfig.getAlarmingUpperRate();
- double alr = serviceConfig.getAlarmingLowerRate();
- double scaleDownFactor = serviceConfig.getScaleDownFactor();
-
- // scale up early
- double maxhandleableReqs = maxRPS * taskInterval * aur;
- // scale down slowly
- double minhandleableReqs = maxRPS * taskInterval * alr * scaleDownFactor;
-
- if (log.isDebugEnabled()) {
- log.debug(clusterStr +": Average requests in flight: " + average + " **** Handleable requests: " +
- (runningAppInstances * maxhandleableReqs));
- }
- if (average > (runningAppInstances * maxhandleableReqs) && maxhandleableReqs > 0) {
-
- // estimate number of instances we might want to spawn
- int requiredInstances = (int) Math.ceil(average/maxhandleableReqs);
-
- log.debug(clusterStr+" : Required instance count: "+requiredInstances);
-
- // current average is higher than that can be handled by current nodes.
- scaleUp(requiredInstances - runningAppInstances);
- } else if (terminatingAppInstances == 0 && average < ((runningAppInstances - 1) * minhandleableReqs)) {
- // current average is less than that can be handled by (current nodes - 1).
- scaleDown();
- }
- }
-
- return true;
- }
-
- private void scaleDown() {
-
- int runningInstances = appDomainContext.getRunningInstanceCount();
-// int pendingInstances = appDomainContext.getPendingInstanceCount();
- int terminatingInstances = appDomainContext.getTerminatingInstanceCount();
- int minAppInstances = serviceConfig.getMinAppInstances();
-// int serverStartupDelay = AutoscalerTaskDSHolder
-// .getInstance()
-// .getWholeLoadBalancerConfig()
-// .getLoadBalancerConfig()
-// .getServerStartupDelay();
-
- if ( (runningInstances - terminatingInstances) > minAppInstances) {
-
- if (log.isDebugEnabled()) {
- log.debug("Scale Down - " +
- clusterStr +
- ". Running instances:" +
- runningInstances +
- ". Terminating instances: " +
- terminatingInstances +
- ". Min instances:" +
- minAppInstances);
- }
- // ask to scale down
- try {
- if (client.terminateInstance(domain, subDomain)) {
-
- Thread th = new Thread(new TerminatingInstancesStateChecker(appDomainContext, domain, subDomain));
- th.start();
-
-// log.debug(clusterStr +": There's an instance who's in shutting down state " +
-// "(but still not left ELB), hence we should wait till " +
-// "it leaves the cluster.");
-//
-// int totalWaitedTime = 0;
-//
-// log.debug(clusterStr +": Task will wait maximum of (milliseconds) : " +
-// serverStartupDelay +
-// ", to let the member leave the cluster.");
-//
-// // for each sub domain, get the clustering group management agent
-// GroupManagementAgent agent =
-// AutoscalerTaskDSHolder.getInstance().getAgent()
-// .getGroupManagementAgent(domain,
-// subDomain);
-//
-// // we give some time for the server to be terminated, we'll check time to time
-// // whether the instance has actually left the cluster.
-// while (agent.getMembers().size() == runningInstances &&
-// totalWaitedTime < serverStartupDelay) {
-//
-// try {
-// Thread.sleep(AutoscaleConstants.INSTANCE_REMOVAL_CHECK_TIME);
-// } catch (InterruptedException ignore) {
-// }
-//
-// totalWaitedTime += AutoscaleConstants.INSTANCE_REMOVAL_CHECK_TIME;
-// }
-//
-// log.debug(clusterStr+ " : task waited for (milliseconds) : " + totalWaitedTime);
-//
-// // we recalculate number of alive instances
-// runningInstances = agent.getMembers().size();
-//
-// appDomainContext.setRunningInstanceCount(runningInstances);
-//
-// log.debug(clusterStr+" : New running instance count: " + runningInstances);
- }
-
- } catch (Exception e) {
- log.error("Instance termination failed for " + clusterStr, e);
- }
- }
-
- }
-
- private void scaleUp(int requiredInstanceCount) {
-
- int maxAppInstances = serviceConfig.getMaxAppInstances();
-// int instancesPerScaleUp = serviceConfig.getInstancesPerScaleUp();
-// int runningInstances = appDomainContext.getRunningInstanceCount();
-// int pendingInstances = appDomainContext.getPendingInstanceCount();
- int totalInstanceCount = appDomainContext.getInstances();
-
- log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain)+ " - Total Running/Pending instance count: "+totalInstanceCount);
-
- if(maxAppInstances > totalInstanceCount){
-
- int availableQuotaOfInstances = maxAppInstances - totalInstanceCount;
-
- log.debug(AutoscaleUtil.domainSubDomainString(domain, subDomain)+ " - Available Quota of Instances: "+availableQuotaOfInstances);
-
- requiredInstanceCount = requiredInstanceCount <= availableQuotaOfInstances ? requiredInstanceCount : availableQuotaOfInstances;
-
- log.debug(clusterStr + " - Going to start " +
- requiredInstanceCount + " instance/s.");
-
- AutoscaleUtil.runInstances(client, appDomainContext, domain, subDomain,
- requiredInstanceCount);
-
- } else if (totalInstanceCount > maxAppInstances) {
- log.fatal("Number of running instances has over reached the maximum limit of " +
- maxAppInstances + " of " + clusterStr);
- }
-
-// int failedInstances = 0;
-// if (runningInstances < maxAppInstances && pendingInstances == 0) {
-//
-// log.debug(clusterStr + " - Going to start " +
-// requiredInstanceCount + " instance/s. Running instances:" + runningInstances);
-//
-// AutoscaleUtil.runInstances(client, appDomainContext, domain, subDomain,
-// requiredInstanceCount);
-
-// if (successfullyStarted != instancesPerScaleUp) {
-// failedInstances = instancesPerScaleUp - successfullyStarted;
-// if (log.isDebugEnabled()) {
-// log.debug(successfullyStarted +
-// " instances successfully started and\n" + failedInstances +
-// " instances failed to start for " + clusterStr);
-// }
-// }
-//
-// // we increment the pending instance count
-// // appDomainContext.incrementPendingInstances(instancesPerScaleUp);
-// else {
-// log.debug("Successfully started " + successfullyStarted +
-// " instances of " + clusterStr);
-// }
-
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/InstanceCountCallable.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/InstanceCountCallable.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/InstanceCountCallable.java
deleted file mode 100644
index 90c2c3a..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/InstanceCountCallable.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.callables;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.mediator.autoscale.lbautoscale.clients.CloudControllerClient;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.AppDomainContext;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-/** Calculate instances of each service domain, sub domain combination **/
-public class InstanceCountCallable implements Callable<Boolean> {
-
- private static final Log log = LogFactory.getLog(InstanceCountCallable.class);
- private String domain;
- private String subDomain;
- private CloudControllerClient client;
- private AppDomainContext appCtxt;
- private ExecutorService executor = Executors.newFixedThreadPool(10);
-
- public InstanceCountCallable(String domain, String subDomain, CloudControllerClient client, AppDomainContext appCtxt){
- this.domain = domain;
- this.subDomain = subDomain;
- this.client = client;
- this.appCtxt = appCtxt;
- }
-
- @Override
- public Boolean call() throws Exception {
- log.debug("Computation of instance counts started for domain: " + this.domain +
- " and sub domain: " + this.subDomain);
-
- Callable<Integer> worker = new RunningInstanceCountCallable(this.domain, this.subDomain);
- Future<Integer> runningInstanceCount = executor.submit(worker);
-
-// worker = new PendingInstanceCountCallable(this.domain, this.subDomain, client);
-// Future<Integer> pendingInstanceCount = executor.submit(worker);
-
- int runningInstances = 0, pendingInstances = 0;
- if (appCtxt != null) {
-
- try {
- // get the values of Callables
- runningInstances = runningInstanceCount.get();
- pendingInstances = appCtxt.getPendingInstanceCount();
- } catch (Exception e) {
- // no need to throw
- log.error(e.getMessage(), e);
- }
-
- appCtxt.setRunningInstanceCount(runningInstances);
- appCtxt.setPendingInstanceCount(pendingInstances);
-
- }
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/PendingInstanceCountCallable.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/PendingInstanceCountCallable.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/PendingInstanceCountCallable.java
deleted file mode 100644
index 27cf50e..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/PendingInstanceCountCallable.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.callables;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.mediator.autoscale.lbautoscale.clients.CloudControllerClient;
-
-import java.util.concurrent.Callable;
-
-/** Calculate pending instances of each service domain, sub domain combination **/
-public class PendingInstanceCountCallable implements Callable<Integer> {
-
- private static final Log log = LogFactory.getLog(PendingInstanceCountCallable.class);
- private String domain;
- private String subDomain;
- private CloudControllerClient client;
-
- public PendingInstanceCountCallable(String domain, String subDomain, CloudControllerClient client){
- this.domain = domain;
- this.subDomain = subDomain;
- this.client = client;
- }
-
- @Override
- public Integer call() throws Exception {
- int pendingInstanceCount = 0;
-
- try {
- pendingInstanceCount =
- client.getPendingInstanceCount(this.domain,
- this.subDomain);
-
- } catch (Exception e) {
- log.error("Failed to retrieve pending instance count for domain: " +
- this.domain + " and sub domain: " + this.subDomain, e);
- }
-
- log.debug("Pending instance count for domain: " +
- this.domain +
- ", sub domain: " +
- this.subDomain +
- " is " +
- pendingInstanceCount);
-
- return pendingInstanceCount;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/RunningInstanceCountCallable.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/RunningInstanceCountCallable.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/RunningInstanceCountCallable.java
deleted file mode 100644
index 3bc3db5..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/callables/RunningInstanceCountCallable.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.callables;
-
-import org.apache.axis2.clustering.management.GroupManagementAgent;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-
-import java.util.concurrent.Callable;
-
-/** Calculate running instances of each service domain, sub domain combination **/
-public class RunningInstanceCountCallable implements Callable<Integer> {
-
- private static final Log log = LogFactory.getLog(RunningInstanceCountCallable.class);
- private String domain;
- private String subDomain;
-
- public RunningInstanceCountCallable(String domain, String subDomain){
- this.domain = domain;
- this.subDomain = subDomain;
- }
-
- @Override
- public Integer call() throws Exception {
- int runningInstances;
- // for each sub domain, get the clustering group management agent
- GroupManagementAgent agent =
- AutoscalerTaskDSHolder.getInstance().getAgent()
- .getGroupManagementAgent(this.domain,
- this.subDomain);
-
- // if it isn't null
- if (agent != null) {
- // we calculate running instance count for this service domain
- runningInstances = agent.getMembers().size();
- } else {
- // if agent is null, we assume no service instances are running
- runningInstances = 0;
- }
-
- log.debug("Running instance count for domain: " +
- this.domain +
- ", sub domain: " +
- this.subDomain +
- " is " +
- runningInstances);
-
- return runningInstances;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerClient.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerClient.java
deleted file mode 100644
index ec9e1bb..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerClient.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.clients;
-
-/**
- * Each Implementation which provides access to Cloud Controller, should implement this interface.
- */
-public abstract class CloudControllerClient {
-
- /**
- * Initializes the client.
- */
- public abstract void init();
-
- /**
- * Should start an instance.
- * @param domainName clustering domain.
- * @param subDomainName clustering sub domain.
- * @return Public IP of the spawned instance.
- * @throws Exception
- */
- public abstract String startInstance(String domainName, String subDomainName) throws Exception;
-
- /**
- * Terminates an instance belongs to the given cluster.
- * @param domainName clustering domain.
- * @param subDomainName clustering sub domain.
- * @return whether the termination is successful or not.
- * @throws Exception
- */
- public abstract boolean terminateInstance(String domainName, String subDomainName) throws Exception;
-
- /**
- * Terminates lastly spawned instance of the given cluster.
- * @param domainName clustering domain.
- * @param subDomainName clustering sub domain.
- * @return whether the termination is successful or not.
- * @throws Exception
- */
- public abstract boolean terminateLastlySpawnedInstance(String domainName, String subDomainName) throws Exception;
-
- /**
- * Return pending instance count of the given cluster.
- * @param domainName clustering domain.
- * @param subDomainName clustering sub domain.
- * @return pending instance count.
- * @throws Exception
- */
- public abstract int getPendingInstanceCount(String domainName, String subDomainName) throws Exception;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerOsgiClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerOsgiClient.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerOsgiClient.java
deleted file mode 100644
index 907a894..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerOsgiClient.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.clients;
-
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.interfaces.CloudControllerService;
-
-/**
- * This is the client class this calls Autoscaler service.
- */
-public class CloudControllerOsgiClient extends CloudControllerClient {
-
- private CloudControllerService cloudControllerService;
-
- private static final Log log = LogFactory.getLog(CloudControllerOsgiClient.class);
-
- // public CloudControllerStubClient(String epr) throws AxisFault {
- //
- // try {
- //
- // stub = new CloudControllerServiceStub(epr);
- // stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(90000);
- //
- // } catch (AxisFault axisFault) {
- // String msg =
- // "Failed to initiate AutoscalerService client. " + axisFault.getMessage();
- // log.error(msg, axisFault);
- // throw new AxisFault(msg, axisFault);
- // }
- // }
-
- // public boolean init(boolean isSpi) throws Exception {
- //
- // return stub.initAutoscaler(isSpi);
- // }
-
- public String startInstance(String domainName, String subDomainName) throws Exception {
-
- return cloudControllerService.startInstance(domainName, subDomainName);
- }
-
- public boolean terminateInstance(String domainName, String subDomainName) throws Exception {
-
- return cloudControllerService.terminateInstance(domainName, subDomainName);
- }
-
- public boolean
- terminateLastlySpawnedInstance(String domainName, String subDomainName) throws Exception {
-
- return cloudControllerService.terminateLastlySpawnedInstance(domainName, subDomainName);
- }
-
- public int getPendingInstanceCount(String domainName, String subDomainName) throws Exception {
-
- return cloudControllerService.getPendingInstanceCount(domainName, subDomainName);
- }
-
- @Override
- public void init() {
-
- cloudControllerService = AutoscalerTaskDSHolder.getInstance().getCloudControllerService();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerStubClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerStubClient.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerStubClient.java
deleted file mode 100644
index 34954e9..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/clients/CloudControllerStubClient.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.clients;
-
-import org.apache.axis2.AxisFault;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.stub.CloudControllerServiceStub;
-
-/**
- * This is the client class this calls Autoscaler service.
- */
-public class CloudControllerStubClient extends CloudControllerClient {
-
- private CloudControllerServiceStub stub;
- private static final String CLOUD_CONTROLLER_EPR = AutoscalerTaskDSHolder.getInstance().getLoadBalancerConfig().getAutoscalerServiceEpr();
-
- private static final Log log = LogFactory.getLog(CloudControllerStubClient.class);
-
- // public CloudControllerStubClient(String epr) throws AxisFault {
- //
- // try {
- //
- // stub = new CloudControllerServiceStub(epr);
- // stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(90000);
- //
- // } catch (AxisFault axisFault) {
- // String msg =
- // "Failed to initiate AutoscalerService client. " + axisFault.getMessage();
- // log.error(msg, axisFault);
- // throw new AxisFault(msg, axisFault);
- // }
- // }
-
- // public boolean init(boolean isSpi) throws Exception {
- //
- // return stub.initAutoscaler(isSpi);
- // }
-
- public String startInstance(String domainName, String subDomainName) throws Exception {
-
- return stub.startInstance(domainName, subDomainName);
- }
-
- public boolean terminateInstance(String domainName, String subDomainName) throws Exception {
-
- return stub.terminateInstance(domainName, subDomainName);
- }
-
- public boolean
- terminateLastlySpawnedInstance(String domainName, String subDomainName) throws Exception {
-
- return stub.terminateLastlySpawnedInstance(domainName, subDomainName);
- }
-
- public int getPendingInstanceCount(String domainName, String subDomainName) throws Exception {
-
- return stub.getPendingInstanceCount(domainName, subDomainName);
- }
-
- @Override
- public void init() {
-
- try {
-
- stub = new CloudControllerServiceStub(CLOUD_CONTROLLER_EPR);
- stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(300000);
-
- } catch (AxisFault axisFault) {
- String msg = "Failed to initiate AutoscalerService client. " + axisFault.getMessage();
- log.error(msg, axisFault);
- throw new RuntimeException(msg, axisFault);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/context/AppDomainContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/context/AppDomainContext.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/context/AppDomainContext.java
deleted file mode 100644
index f8155a7..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/context/AppDomainContext.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.context;
-
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
-
-
-/**
- * Contextual information related to autoscaling for a particular clustering domain
- */
-public class AppDomainContext extends LoadBalancerContext{
-
- private static final long serialVersionUID = 6582721801663800609L;
-
- private static final Log log = LogFactory.getLog(AppDomainContext.class);
-
- /**
- * Request tokens of requests in flight
- * <p/>
- * Key - request token ID, Value - message received time
- */
- private Map<String, Long> requestTokens = new ConcurrentHashMap<String, Long>();
- private List<Integer> requestTokenListLengths;
- private LoadBalancerConfiguration.ServiceConfiguration serviceConfig;
-
- public AppDomainContext(LoadBalancerConfiguration.ServiceConfiguration serviceConfig) {
- this.serviceConfig = serviceConfig;
- requestTokenListLengths = new Vector<Integer>(serviceConfig.getRoundsToAverage());
- }
-
- public LoadBalancerConfiguration.ServiceConfiguration getServiceConfig() {
- return serviceConfig;
- }
-
- /**
- * If there is insufficient number of messages we cannot make a scaling decision.
- *
- * @return true - if a scaling decision can be made
- */
- public boolean canMakeScalingDecision() {
- return requestTokenListLengths.size() >= serviceConfig.getRoundsToAverage();
- }
-
- public void addRequestToken(String tokenId) {
- requestTokens.put(tokenId, System.currentTimeMillis());
- if (log.isDebugEnabled()) {
- log.debug("Request Tokens Added : "+requestTokens.size());
- }
- }
-
- public void removeRequestToken(String tokenId) {
- requestTokens.remove(tokenId);
- }
-
-// public int getRunningInstanceCount() {
-// return super.getRunningInstanceCount();
-// }
-
- /**
- * This will set the running instance count for this app domain
- * and also will return the difference of current running instance count and previous count.
- * @param runningInstanceCount current running instance count
- * @return difference of current running instance count and previous count.
- */
-// public int setRunningInstanceCount(int runningInstanceCount) {
-// int diff = 0;
-//
-// if(this.runningInstanceCount < runningInstanceCount){
-// diff = runningInstanceCount - this.runningInstanceCount;
-// }
-//
-// this.runningInstanceCount = runningInstanceCount;
-//
-// return diff;
-// }
-
- public void expireRequestTokens() {
- for (Map.Entry<String, Long> entry : requestTokens.entrySet()) {
- if (System.currentTimeMillis() - entry.getValue() >= serviceConfig.getMessageExpiryTime()) {
- requestTokens.remove(entry.getKey());
- if (log.isDebugEnabled()) {
- log.debug("Request Tokens Expired : " + requestTokens.get(entry.getKey()));
- }
- }
- }
- }
-
- public void recordRequestTokenListLength() {
- if (requestTokenListLengths.size() >= serviceConfig.getRoundsToAverage()) {
- int count = requestTokenListLengths.remove(0);
- if (log.isDebugEnabled()) {
- log.debug("Request Tokens Removed : " + count);
- }
- }
- if (log.isDebugEnabled()) {
- log.debug("Request Tokens Added : " + requestTokens.size());
- }
- requestTokenListLengths.add(requestTokens.size());
- }
-
-
-// public synchronized int getPendingInstances() {
-// return pendingInstances;
-// }
-
-// public synchronized void incrementPendingInstances() {
-// this.pendingInstances++;
-// }
-
-// public synchronized void decrementPendingInstancesIfNotZero(int diff) {
-//
-// while (diff > 0 && this.pendingInstances > 0 ){
-// this.pendingInstances--;
-// diff--;
-// }
-//
-// }
-
-// public synchronized int getInstances() {
-// return runningInstanceCount + pendingInstances;
-// }
-
- /**
- * Get the average requests in flight, averaged over the number of of observations rounds
- *
- * @return number of average requests in flight. -1 if there no requests were received
- */
- public long getAverageRequestsInFlight() {
- long total = 0;
- for (Integer messageQueueLength : requestTokenListLengths) {
- total += messageQueueLength;
- }
- int size = requestTokenListLengths.size();
- if (size == 0) {
- return -1; // -1 means that no requests have been received
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Total Tokens : "+total+ " : Size: "+size);
- }
- return (long) total / size;
- }
-
-
-// public synchronized void resetRunningPendingInstances() {
-// pendingInstances = 0;
-// runningInstanceCount = 0;
-// }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/context/LoadBalancerContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/context/LoadBalancerContext.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/context/LoadBalancerContext.java
deleted file mode 100644
index b6a6d9b..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/context/LoadBalancerContext.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.context;
-
-import java.io.Serializable;
-
-/**
- * Contextual information related to autoscaling for a particular domain
- */
-public class LoadBalancerContext implements Serializable{
-
- private static final long serialVersionUID = -2022110665957598060L;
- private int runningInstances;
- private int pendingInstances;
- private int terminatingInstances;
-
- public synchronized int getTerminatingInstanceCount() {
- return terminatingInstances;
- }
-
- public synchronized int getRunningInstanceCount() {
- return runningInstances;
- }
-
- public synchronized int getPendingInstanceCount() {
- return pendingInstances;
- }
-
- /**
- * This will set the running instance count for a domain
- * and also will return the difference of current running instance count and previous count.
- * @param runningInstanceCount current running instance count
- * @return difference of current running instance count and previous count.
- */
- public synchronized int setRunningInstanceCount(int count) {
- int diff = 0;
-
- if (this.runningInstances < count) {
- diff = count - this.runningInstances;
- }
-
- this.runningInstances = count;
-
- return diff;
- }
-
- public synchronized int getInstances() {
- return runningInstances + pendingInstances;
- }
-
- public synchronized void setPendingInstanceCount(int count) {
-
- this.pendingInstances = count;
- }
-
- public synchronized void setTerminatingInstanceCount(int count) {
-
- this.terminatingInstances = count;
- }
-
- public synchronized void incrementPendingInstances(int diff) {
-
- this.pendingInstances += diff;
- }
-
- public synchronized void incrementTerminatingInstances(int diff) {
-
- this.terminatingInstances += diff;
- }
-
- public synchronized void decrementPendingInstancesIfNotZero(int diff) {
-
- while (diff > 0 && this.pendingInstances > 0) {
- this.pendingInstances--;
- diff--;
- }
-
- }
-
- public synchronized void decrementTerminatingInstancesIfNotZero(int diff) {
-
- while (diff > 0 && this.terminatingInstances > 0) {
- this.terminatingInstances--;
- diff--;
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/internal/AutoscalerTaskServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/internal/AutoscalerTaskServiceComponent.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/internal/AutoscalerTaskServiceComponent.java
deleted file mode 100644
index 41811eb..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/internal/AutoscalerTaskServiceComponent.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.internal;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.description.Parameter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
-import org.apache.stratos.lb.common.service.LoadBalancerConfigurationService;
-import org.apache.stratos.mediator.autoscale.lbautoscale.mediators.AutoscaleInMediator;
-import org.apache.stratos.mediator.autoscale.lbautoscale.mediators.AutoscaleOutMediator;
-import org.apache.stratos.mediator.autoscale.lbautoscale.task.*;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-import org.apache.synapse.ManagedLifecycle;
-import org.apache.synapse.Mediator;
-import org.apache.synapse.SynapseConstants;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.core.SynapseEnvironment;
-import org.apache.synapse.mediators.base.SequenceMediator;
-import org.apache.synapse.mediators.filters.InMediator;
-import org.apache.synapse.mediators.filters.OutMediator;
-import org.apache.synapse.task.Task;
-import org.apache.synapse.task.TaskConstants;
-import org.apache.synapse.task.TaskDescription;
-import org.apache.synapse.task.TaskScheduler;
-import org.apache.synapse.task.service.TaskManagementService;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.component.ComponentContext;
-import org.quartz.JobBuilder;
-import org.quartz.JobDetail;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.registry.core.service.RegistryService;
-import org.apache.stratos.cloud.controller.interfaces.CloudControllerService;
-import org.wso2.carbon.user.core.service.RealmService;
-import org.wso2.carbon.utils.Axis2ConfigurationContextObserver;
-import org.wso2.carbon.utils.ConfigurationContextService;
-
-import java.util.Date;
-import java.util.Map;
-
-/**
- * @scr.component name="autoscaler.task.component" immediate="true"
- * @scr.reference name="carbon.core.configurationContextService"
- * interface="org.wso2.carbon.utils.ConfigurationContextService"
- * cardinality="1..1" policy="dynamic"
- * bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
- * @scr.reference name="user.realmservice.default"
- * interface="org.wso2.carbon.user.core.service.RealmService"
- * cardinality="1..1" policy="dynamic" bind="setRealmService"
- * unbind="unsetRealmService"
- * @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="registry.service"
- * interface="org.wso2.carbon.registry.core.service.RegistryService"
- * cardinality="1..1" policy="dynamic"
- * bind="setRegistryService" unbind="unsetRegistryService"
- * @scr.reference name="org.apache.stratos.cloud.controller"
- * interface="org.apache.stratos.cloud.controller.interfaces.CloudControllerService"
- * cardinality="1..1" policy="dynamic" bind="setCloudControllerService"
- * unbind="unsetCloudControllerService"
- */
-public class AutoscalerTaskServiceComponent {
-
- private static final Log log = LogFactory.getLog(AutoscalerTaskServiceComponent.class);
- private ConfigurationContext configurationContext = null;
-
- protected void activate(ComponentContext context) {
-
- try{
-
- // read config file
-// String configURL = System.getProperty(AutoscaleConstants.LOAD_BALANCER_CONFIG);
-// LoadBalancerConfiguration lbConfig = new LoadBalancerConfiguration();
-// lbConfig.init(configURL);
-
- if(configurationContext == null){
- String msg = "Configuration context is null. Autoscaler task activation failed.";
- log.fatal(msg);
- throw new RuntimeException(msg);
- }
-
- // load synapse environment
- Parameter synEnv =
- configurationContext.getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_ENV);
-
- if (synEnv == null || synEnv.getValue() == null ||
- !(synEnv.getValue() instanceof SynapseEnvironment)) {
-
- String message = "Unable to initialize the Synapse Configuration : Can not find the ";
- log.fatal(message + "Synapse Environment");
- throw new SynapseException(message + "Synapse Environment");
- }
-
- SynapseEnvironment synapseEnv = (SynapseEnvironment) synEnv.getValue();
-
- /** Initializing autoscaleIn and autoscaleOut Mediators.**/
-
- LoadBalancerConfiguration lbConfig = AutoscalerTaskDSHolder.getInstance().getWholeLoadBalancerConfig();
- // check whether autoscaling is enabled
- if (lbConfig.getLoadBalancerConfig().isAutoscaleEnabled()) {
-
- // get the main sequence mediator
- SequenceMediator mainSequence =
- (SequenceMediator) synapseEnv.getSynapseConfiguration().getSequence("main");
-
- // iterate through its child mediators
- for (Mediator child : mainSequence.getList()) {
-
- // find the InMediator
- if (child instanceof InMediator) {
- InMediator inSequence = (InMediator) child;
-
- // if the first child of InMediator isn't an AutoscaleInMediator
- if (!(inSequence.getList().get(0) instanceof AutoscaleInMediator)) {
-
- // we gonna add it!
- inSequence.getList().add(0, new AutoscaleInMediator());
- if (log.isDebugEnabled()) {
- log.debug("Added Mediator: " + inSequence.getChild(0) + "" +
- " to InMediator. Number of child mediators in InMediator" + " is " +
- inSequence.getList().size() + ".");
- }
- }
-
- }
-
- // find the OutMediator
- if (child instanceof OutMediator) {
-
- OutMediator outSequence = (OutMediator) child;
-
- // if the first child of OutMediator isn't an AutoscaleOutMediator
- if (!(outSequence.getList().get(0) instanceof AutoscaleOutMediator)) {
-
- // we gonna add it!
- outSequence.getList().add(0, new AutoscaleOutMediator());
-
- if (log.isDebugEnabled()) {
- log.debug("Added Mediator: " + outSequence.getChild(0) + "" +
- " to OutMediator. Number of child mediators in OutMediator" +
- " is " + outSequence.getList().size() + ".");
- }
-
- }
- }
- }
-
- /** Initializing Autoscaler Task **/
-
- BundleContext bundleContext = context.getBundleContext();
- if (log.isDebugEnabled()) {
- log.debug("Initiating Autoscaler task service component");
- }
-
- if (bundleContext.getServiceReference(TaskManagementService.class.getName()) != null) {
- bundleContext.registerService(TaskManagementService.class.getName(),
- new AutoscalerTaskMgmtAdminService(), null);
- }
-
-
- AutoscalerTaskInitializer listener = new AutoscalerTaskInitializer();
-
- if (bundleContext.getServiceReference(Axis2ConfigurationContextObserver.class.getName()) != null) {
- bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(),
- listener, null);
- }
-
- if (configurationContext != null) {
- TaskScheduler scheduler =
- (TaskScheduler) configurationContext.getProperty(AutoscalerTaskInitializer.CARBON_TASK_SCHEDULER);
- if (scheduler == null) {
- scheduler = new TaskScheduler(TaskConstants.TASK_SCHEDULER);
- scheduler.init(null);
- configurationContext.setProperty(AutoscalerTaskInitializer.CARBON_TASK_SCHEDULER,
- scheduler);
- } else if (!scheduler.isInitialized()) {
- scheduler.init(null);
- }
- }
-
- String autoscalerClass = lbConfig.getLoadBalancerConfig().getAutoscalerTaskClass();
- Task task;
- if (autoscalerClass != null) {
- try {
- task = (Task) Class.forName(autoscalerClass).newInstance();
- } catch (Exception e) {
- String msg = "Cannot instantiate Autoscaling Task. Class: " + autoscalerClass
- +". It should implement 'org.apache.synapse.task.Task' and "
- +"'org.apache.synapse.ManagedLifecycle' interfaces.";
- log.error(msg, e);
- throw new RuntimeException(msg, e);
- }
- } else {
- task = new ServiceRequestsInFlightAutoscaler();
- }
-
-// ServiceRequestsInFlightAutoscaler autoscalerTask =
-// new ServiceRequestsInFlightAutoscaler();
-
- ((ManagedLifecycle) task).init(synapseEnv);
-
- // specify scheduler task details
- JobBuilder jobBuilder = JobBuilder.newJob(AutoscalingJob.class)
- .withIdentity("autoscalerJob");
- JobDetail job = jobBuilder.build();
-
- Map<String, Object> dataMap = job.getJobDataMap();
- dataMap.put(AutoscalingJob.AUTOSCALER_TASK, task);
- dataMap.put(AutoscalingJob.SYNAPSE_ENVI, synapseEnv);
-
- final TaskDescription taskDescription = new TaskDescription();
- taskDescription.setTaskClass(ServiceRequestsInFlightAutoscaler.class.getName());
- taskDescription.setName("autoscaler");
- //taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
-
- int interval = AutoscalerTaskDSHolder.getInstance().getLoadBalancerConfig().getAutoscalerTaskInterval();
- taskDescription.setInterval(interval);
- taskDescription.setStartTime(new Date(System.currentTimeMillis() + (interval*2)));
-
- TaskSchedulingManager scheduler = new TaskSchedulingManager();
- scheduler.scheduleTask(taskDescription, dataMap, configurationContext);
-
-
- } else {
-
- log.info("Autoscaling is disabled.");
- }
- } catch (Throwable e) {
- log.error("Failed to activate Autoscaler Task Service Component. ", e);
- }
- }
-
-
- protected void deactivate(ComponentContext ctx) {
- AutoscalerTaskDSHolder.getInstance().setConfigurationContextService(null);
- if (log.isDebugEnabled()) {
- log.debug("Autoscaler task bundle is deactivated");
- }
- }
-
- protected void setCloudControllerService(CloudControllerService cc) {
- AutoscalerTaskDSHolder.getInstance().setCloudControllerService(cc);
- }
-
- protected void unsetCloudControllerService(CloudControllerService cc) {
- AutoscalerTaskDSHolder.getInstance().setCloudControllerService(null);
- }
-
- protected void setConfigurationContextService(ConfigurationContextService context) {
- if (log.isDebugEnabled()) {
- log.debug("ConfigurationContextService bound to the Autoscaler task initialization process");
- }
- this.configurationContext = context.getServerConfigContext();
- AutoscalerTaskDSHolder.getInstance().setConfigurationContextService(context);
- }
-
- protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
- if (log.isDebugEnabled()) {
- log.debug("ConfigurationContextService unbound from the Autoscaler task");
- }
- this.configurationContext = null;
- AutoscalerTaskDSHolder.getInstance().setConfigurationContextService(null);
- }
-
- protected void setRealmService(RealmService realmService) {
- if (log.isDebugEnabled()) {
- log.debug("Bound realm service from the Autoscaler task");
- }
- AutoscalerTaskDSHolder.getInstance().setRealmService(realmService);
- }
-
- protected void unsetRealmService(RealmService realmService) {
- if (log.isDebugEnabled()) {
- log.debug("Unbound realm service from the Autoscaler task");
- }
- AutoscalerTaskDSHolder.getInstance().setRealmService(null);
- }
-
- protected void setLoadBalancerConfigurationService(LoadBalancerConfigurationService lbConfigSer){
- AutoscalerTaskDSHolder.getInstance().setLbConfigService(lbConfigSer);
- }
-
- protected void unsetLoadBalancerConfigurationService(LoadBalancerConfigurationService lbConfigSer){
- AutoscalerTaskDSHolder.getInstance().setLbConfigService(null);
- }
-
- protected void setRegistryService(RegistryService regService) {
- if (log.isDebugEnabled()) {
- log.debug("RegistryService bound to the endpoint component");
- }
- try {
- AutoscalerTaskDSHolder.getInstance().setConfigRegistry(regService.getConfigSystemRegistry());
- AutoscalerTaskDSHolder.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");
- }
- AutoscalerTaskDSHolder.getInstance().setConfigRegistry(null);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/internal/RegistryManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/internal/RegistryManager.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/internal/RegistryManager.java
deleted file mode 100644
index 0f5a03d..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/internal/RegistryManager.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.internal;
-
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.lb.common.util.DomainMapping;
-import org.wso2.carbon.registry.core.Resource;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.registry.core.session.UserRegistry;
-
-public class RegistryManager {
- UserRegistry governanceRegistry = AutoscalerTaskDSHolder.getInstance().getGovernanceRegistry();
- private static final Log log = LogFactory.getLog(RegistryManager.class);
- /**
- *
- */
- private Resource resource = null;
- public static final String HOST_INFO = "hostinfo/";
- public static final String ACTUAL_HOST = "actual.host";
-
- public DomainMapping getMapping(String hostName) {
- DomainMapping domainMapping;
- try {
- if (governanceRegistry.resourceExists(HOST_INFO + hostName)) {
- resource = governanceRegistry.get(HOST_INFO + hostName);
- domainMapping = new DomainMapping(hostName);
- domainMapping.setActualHost(resource.getProperty(ACTUAL_HOST));
- return domainMapping;
- }
- } catch (RegistryException e) {
- log.info("Error while getting registry resource");
- throw new RuntimeException(e);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/947eb5a6/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/mediators/AutoscaleInMediator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/mediators/AutoscaleInMediator.java b/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/mediators/AutoscaleInMediator.java
deleted file mode 100644
index 6ec1da3..0000000
--- a/components/org.apache.stratos.mediator.autoscale/src/main/java/org/apache/stratos/mediator/autoscale/lbautoscale/mediators/AutoscaleInMediator.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.stratos.mediator.autoscale.lbautoscale.mediators;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.context.AppDomainContext;
-import org.apache.stratos.mediator.autoscale.lbautoscale.internal.RegistryManager;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleConstants;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscaleUtil;
-import org.apache.stratos.mediator.autoscale.lbautoscale.util.AutoscalerTaskDSHolder;
-import org.apache.http.protocol.HTTP;
-import org.apache.synapse.ManagedLifecycle;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.core.SynapseEnvironment;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
-import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.stratos.lb.common.conf.LoadBalancerConfiguration;
-import org.apache.stratos.lb.common.conf.util.HostContext;
-import org.apache.stratos.lb.common.cache.URLMappingCache;
-import org.apache.stratos.lb.common.util.DomainMapping;
-
-import java.util.Map;
-
-/**
- * This Synapse mediator generates a token per request received. These tokens are used for tracking
- * the number of requests in flight. Once a response is received, the relevant token will be removed
- * by the {@link AutoscaleOutMediator}
- *
- * @see AutoscaleOutMediator
- */
-public class AutoscaleInMediator extends AbstractMediator implements ManagedLifecycle {
-
- private LoadBalancerConfiguration lbConfig;
- private Map<String, HostContext> hostCtxts;
- /**
- * keep the size of cache which used to keep hostNames of url mapping.
- */
- private URLMappingCache mappingCache;
- private RegistryManager registryManager;
- private int sizeOfCache;
-
- public AutoscaleInMediator() {
-
- this.lbConfig = AutoscalerTaskDSHolder.getInstance().getWholeLoadBalancerConfig();
- hostCtxts = lbConfig.getHostContextMap();
- sizeOfCache = lbConfig.getLoadBalancerConfig().getSizeOfCache();
- mappingCache = URLMappingCache.getInstance(sizeOfCache);
- }
-
- public boolean mediate(MessageContext synCtx) {
-
- if (log.isDebugEnabled()) {
- log.debug("Mediation started .......... " + AutoscaleInMediator.class.getName());
-
- }
-
- ConfigurationContext configCtx =
- ((Axis2MessageContext) synCtx).getAxis2MessageContext()
- .getConfigurationContext();
- String uuid = org.apache.axiom.util.UIDGenerator.generateUID();
- synCtx.setProperty(AutoscaleConstants.REQUEST_ID, uuid);
-
- Map<String, Map<String, ?>> appDomainContexts =
- AutoscaleUtil.getAppDomainContexts(configCtx,
- lbConfig);
- org.apache.axis2.context.MessageContext axis2MessageContext =
- ((Axis2MessageContext) synCtx).getAxis2MessageContext();
- Map<String, String> transportHeaders = (Map<String, String>) axis2MessageContext.
- getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
- String targetHost = transportHeaders.get(HTTP.TARGET_HOST);
-
- String toAddress = synCtx.getTo().getAddress();
- if (targetHost.contains(":")) {
- targetHost = targetHost.substring(0, targetHost.indexOf(':'));
- }
-
- int tenantId = AutoscaleUtil.getTenantId(synCtx.getTo().toString());
-
- String domain = null, subDomain = null;
-
- log.debug("************ Target Host: "+targetHost + " -- Tenant id : "+tenantId);
-
- HostContext ctxt = hostCtxts.get(targetHost);
-
- if (ctxt == null) {
-
- DomainMapping domainMapping = mappingCache.getMapping(targetHost);
- if (domainMapping == null) {
- registryManager = new RegistryManager();
- domainMapping = registryManager.getMapping(targetHost);
- mappingCache.addValidMapping(targetHost, domainMapping);
- }
- if (domainMapping != null) {
-
- String actualHost = domainMapping.getActualHost();
-
- // get the HostContext from the actual host name in the case of domain
- // mapping.
- ctxt = hostCtxts.get(actualHost);
-
- }
- }
-
- if (ctxt == null) {
- log.debug("Host Context is null.");
- // we don't need to do anything
- return true;
- }
-
-
- // gets the corresponding domain
- domain = ctxt.getDomainFromTenantId(tenantId);
- synCtx.setProperty(AutoscaleConstants.TARGET_DOMAIN, domain);
-
- // gets the corresponding sub domain
- subDomain = ctxt.getSubDomainFromTenantId(tenantId);
- synCtx.setProperty(AutoscaleConstants.TARGET_SUB_DOMAIN, subDomain);
-
- if (appDomainContexts.get(domain) == null) {
- // if we do not find a correct context, we just ignore
- log.debug("AppDomainContext not found for domain " + domain);
-
- } else {
- AppDomainContext appDomainContext = (AppDomainContext) appDomainContexts.get(domain).get(subDomain);
-
- if (appDomainContext != null) {
- appDomainContext.addRequestToken(uuid);
- System.setProperty(AutoscaleConstants.IS_TOUCHED, "true");
-
- } else {
- // if we do not find a correct context, we just ignore
- log.debug("AppDomainContext not found for sub domain: " + subDomain +
- " of domain: " + domain);
- }
- }
-
- return true;
- }
-
- @Override
- public void destroy() {
-
- log.info("Mediator destroyed! " + AutoscaleInMediator.class.getName());
- }
-
- @Override
- public void init(SynapseEnvironment arg0) {
-
- if (log.isDebugEnabled()) {
- log.debug("Mediator initialized! " + AutoscaleInMediator.class.getName());
- }
- }
-
- private void throwException(String msg){
- log.error(msg);
- throw new RuntimeException(msg);
- }
-}