3333import com .cloud .agent .api .to .PortForwardingRuleTO ;
3434import com .cloud .agent .api .to .LoadBalancerTO .DestinationTO ;
3535import com .cloud .agent .api .to .LoadBalancerTO .StickinessPolicyTO ;
36- import com .cloud .agent .resource .virtualnetwork .VirtualRoutingResource ;
3736import com .cloud .network .rules .LbStickinessMethod .StickinessMethodType ;
3837import com .cloud .utils .net .NetUtils ;
3938
4039
4140public class HAProxyConfigurator implements LoadBalancerConfigurator {
4241
4342 private static final Logger s_logger = Logger .getLogger (HAProxyConfigurator .class );
43+ private static final String blankLine = "\t " ;
4444 private static String [] globalSection = { "global" ,
4545 "\t log 127.0.0.1:3914 local0 warning" ,
4646 "\t maxconn 4096" ,
@@ -86,17 +86,17 @@ public String[] generateConfiguration(List<PortForwardingRuleTO> fwRules) {
8686 List <String > result = new ArrayList <String >();
8787
8888 result .addAll (Arrays .asList (globalSection ));
89- result .add (getBlankLine () );
89+ result .add (blankLine );
9090 result .addAll (Arrays .asList (defaultsSection ));
91- result .add (getBlankLine () );
91+ result .add (blankLine );
9292
9393 if (pools .isEmpty ()) {
9494 // haproxy cannot handle empty listen / frontend or backend, so add
9595 // a dummy listener
9696 // on port 9
9797 result .addAll (Arrays .asList (defaultListen ));
9898 }
99- result .add (getBlankLine () );
99+ result .add (blankLine );
100100
101101 for (Map .Entry <String , List <PortForwardingRuleTO >> e : pools .entrySet ()) {
102102 List <String > poolRules = getRulesForPool (e .getKey (), e .getValue ());
@@ -143,7 +143,7 @@ private List<String> getRulesForPool(String poolName,
143143 .append (rule .getDstPortRange ()[0 ]).append (" check" );
144144 result .add (sb .toString ());
145145 }
146- result .add (getBlankLine () );
146+ result .add (blankLine );
147147 return result ;
148148 }
149149
@@ -507,14 +507,10 @@ private List<String> getRulesForPool(LoadBalancerTO lbTO) {
507507 result .add (sb .toString ());
508508 }
509509
510- result .add (getBlankLine () );
510+ result .add (blankLine );
511511 return result ;
512512 }
513513
514- private String getBlankLine () {
515- return new String ("\t " );
516- }
517-
518514 private String generateStatsRule (LoadBalancerConfigCommand lbCmd ,
519515 String ruleName , String statsIp ) {
520516 StringBuilder rule = new StringBuilder ("\n listen " ).append (ruleName )
@@ -534,7 +530,7 @@ public String[] generateConfiguration(LoadBalancerConfigCommand lbCmd) {
534530 List <String > result = new ArrayList <String >();
535531
536532 result .addAll (Arrays .asList (globalSection ));
537- result .add (getBlankLine () );
533+ result .add (blankLine );
538534 result .addAll (Arrays .asList (defaultsSection ));
539535 if (!lbCmd .lbStatsVisibility .equals ("disabled" )) {
540536 /* new rule : listen admin_page guestip/link-local:8081 */
@@ -568,7 +564,7 @@ public String[] generateConfiguration(LoadBalancerConfigCommand lbCmd) {
568564 }
569565
570566 }
571- result .add (getBlankLine () );
567+ result .add (blankLine );
572568 boolean has_listener = false ;
573569 for (LoadBalancerTO lbTO : lbCmd .getLoadBalancers ()) {
574570 if ( lbTO .isRevoked () ) {
@@ -578,7 +574,7 @@ public String[] generateConfiguration(LoadBalancerConfigCommand lbCmd) {
578574 result .addAll (poolRules );
579575 has_listener = true ;
580576 }
581- result .add (getBlankLine () );
577+ result .add (blankLine );
582578 if ( !has_listener ) {
583579 // haproxy cannot handle empty listen / frontend or backend, so add
584580 // a dummy listener
0 commit comments