Formatting RuleTasksDelegator class and removing unused lines
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c595ef8f Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c595ef8f Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c595ef8f Branch: refs/heads/master Commit: c595ef8fea98455ddbec9dda4168feb8bb77b02e Parents: efe1f79 Author: Lahiru Sandaruwan <[email protected]> Authored: Tue Mar 17 11:29:00 2015 +0530 Committer: Lahiru Sandaruwan <[email protected]> Committed: Tue Mar 17 11:29:00 2015 +0530 ---------------------------------------------------------------------- .../autoscaler/rule/RuleTasksDelegator.java | 49 +++++++++----------- 1 file changed, 23 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/c595ef8f/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java index a5571b9..c4d643b 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java @@ -34,9 +34,7 @@ import org.apache.stratos.autoscaler.context.member.MemberStatsContext; import org.apache.stratos.autoscaler.context.partition.ClusterLevelPartitionContext; import org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetworkPartitionContext; import org.apache.stratos.autoscaler.event.publisher.InstanceNotificationPublisher; -import org.apache.stratos.autoscaler.exception.cartridge.TerminationException; import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor; -import org.apache.stratos.autoscaler.util.AutoscalerConstants; import org.apache.stratos.cloud.controller.stub.domain.MemberContext; import org.apache.stratos.common.client.CloudControllerServiceClient; import org.apache.stratos.common.constants.StratosConstants; @@ -46,8 +44,6 @@ import org.apache.stratos.common.constants.StratosConstants; */ public class RuleTasksDelegator { - public static final double SCALE_UP_FACTOR = 0.8; //get from config - public static final double SCALE_DOWN_FACTOR = 0.2; private static boolean arspiIsSet = false; private static final Log log = LogFactory.getLog(RuleTasksDelegator.class); @@ -89,12 +85,12 @@ public class RuleTasksDelegator { public int getNumberOfInstancesRequiredBasedOnMemoryConsumption(float threshold, double predictedValue, int min, int max) { double numberOfAdditionalInstancesRequired = 0; - if(predictedValue != threshold) { + if (predictedValue != threshold) { float scalingRange = 100 - threshold; int instanceRange = max - min; - if(instanceRange != 0){ + if (instanceRange != 0) { float gradient = scalingRange / instanceRange; numberOfAdditionalInstancesRequired = (predictedValue - threshold) / gradient; @@ -108,7 +104,7 @@ public class RuleTasksDelegator { int min) { double numberOfInstances; - if(threshold != 0) { + if (threshold != 0) { numberOfInstances = (min * predictedValue) / threshold; return (int) Math.ceil(numberOfInstances); @@ -144,7 +140,7 @@ public class RuleTasksDelegator { PartitionAlgorithm autoscaleAlgorithm = null; //FIXME to not parse for algo when partition is chosen by the parent - if(partitionAlgorithm == null) { + if (partitionAlgorithm == null) { //Send one after another as default partitionAlgorithm = StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID; } @@ -176,10 +172,11 @@ public class RuleTasksDelegator { /** * Invoked from drools to start an instance. + * * @param clusterMonitorPartitionContext Cluster monitor partition context - * @param clusterId Cluster id - * @param clusterInstanceId Instance id - * @param isPrimary Is a primary member + * @param clusterId Cluster id + * @param clusterInstanceId Instance id + * @param isPrimary Is a primary member */ public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext, String clusterId, String clusterInstanceId, boolean isPrimary) { @@ -188,8 +185,8 @@ public class RuleTasksDelegator { String nwPartitionId = clusterMonitorPartitionContext.getNetworkPartitionId(); // Calculate accumulation of minimum counts of all the partition of current network partition - int minimumCountOfNetworkPartition = 0; - ClusterMonitor clusterMonitor = (ClusterMonitor) AutoscalerContext.getInstance().getClusterMonitor(clusterId); + int minimumCountOfNetworkPartition; + ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId); ClusterContext clusterContext = (ClusterContext) clusterMonitor.getClusterContext(); ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext = clusterContext.getNetworkPartitionCtxt(nwPartitionId); @@ -230,7 +227,7 @@ public class RuleTasksDelegator { public void delegateScalingDependencyNotification(String clusterId, String networkPartitionId, String instanceId, int requiredInstanceCount, int minimumInstanceCount) { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Scaling dependent notification is going to the [parentInstance] " + instanceId); } //Notify parent for checking scaling dependencies @@ -244,7 +241,7 @@ public class RuleTasksDelegator { } public void delegateScalingOverMaxNotification(String clusterId, String networkPartitionId, String instanceId) { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Scaling max out notification is going to the [parentInstance] " + instanceId); } //Notify parent for checking scaling dependencies @@ -257,7 +254,7 @@ public class RuleTasksDelegator { } public void delegateScalingDownBeyondMinNotification(String clusterId, String networkPartitionId, String instanceId) { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug("Scaling down lower min notification is going to the [parentInstance] " + instanceId); } //Notify parent for checking scaling dependencies @@ -276,19 +273,19 @@ public class RuleTasksDelegator { if (clusterMonitorPartitionContext.activeMemberAvailable(memberId)) { log.info(String.format("[scale-down] Moving active member to termination pending list [member id] %s " + - "[partition] %s [network partition] %s" , memberId, + "[partition] %s [network partition] %s", memberId, clusterMonitorPartitionContext.getPartitionId(), clusterMonitorPartitionContext.getNetworkPartitionId())); - clusterMonitorPartitionContext.moveActiveMemberToTerminationPendingMembers(memberId); - clusterMonitorPartitionContext.removeMemberStatsContext(memberId); + clusterMonitorPartitionContext.moveActiveMemberToTerminationPendingMembers(memberId); + clusterMonitorPartitionContext.removeMemberStatsContext(memberId); } else if (clusterMonitorPartitionContext.pendingMemberAvailable(memberId)) { log.info(String.format("[scale-down] Moving pending member to termination pending list [member id] %s " + - "[partition] %s [network partition] %s" , memberId, + "[partition] %s [network partition] %s", memberId, clusterMonitorPartitionContext.getPartitionId(), clusterMonitorPartitionContext.getNetworkPartitionId())); - clusterMonitorPartitionContext.movePendingMemberToObsoleteMembers(memberId); - clusterMonitorPartitionContext.removeMemberStatsContext(memberId); + clusterMonitorPartitionContext.movePendingMemberToObsoleteMembers(memberId); + clusterMonitorPartitionContext.removeMemberStatsContext(memberId); } } catch (Exception e) { log.error("[scale-down] Cannot move member to termination pending list ", e); @@ -314,7 +311,7 @@ public class RuleTasksDelegator { CloudControllerServiceClient.getInstance().terminateInstance(memberId); } catch (Exception e) { log.error("Cannot terminate instance", e); - } + } } //Grouping @@ -329,7 +326,7 @@ public class RuleTasksDelegator { } } catch (Exception e) { log.error("Cannot terminate instance", e); - } + } } public int getPredictedReplicasForStat(int minReplicas, float statUpperLimit, float statPredictedValue) { @@ -353,7 +350,7 @@ public class RuleTasksDelegator { double memberPredictedLoadAverage = getPredictedValueForNextMinute(memberAverageLoadAverage, memberGredientLoadAverage, memberSecondDerivativeLoadAverage, 1); - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug(String.format("[member-id] $s [predicted load average] $s ", memberStatsContext.getMemberId() , memberPredictedLoadAverage)); } @@ -383,7 +380,7 @@ public class RuleTasksDelegator { double memberPredictedMemoryConsumption = getPredictedValueForNextMinute(memberMemoryConsumptionAverage, memberMemoryConsumptionGredient, memberMemoryConsumptionSecondDerivative, 1); - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug(String.format("[member-id] $s [predicted memory consumption] $s ", memberStatsContext.getMemberId() , memberPredictedMemoryConsumption)); }
