incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [44/50] [abbrv] git commit: bug CS-14982: Make traffic sentinel metering zones configurable. Global config default will be used when no zones are listed while adding Traffic Sentinel Host status CS-14982: resolved fixed reviewed-by: Nitin
Date Mon, 24 Dec 2012 00:57:38 GMT
bug CS-14982: Make traffic sentinel metering zones configurable. Global config default will
be used when no zones are listed while adding Traffic Sentinel Host
status CS-14982: resolved fixed
reviewed-by: Nitin

Conflicts:
	api/src/com/cloud/api/ApiConstants.java


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/0be6e2e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/0be6e2e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/0be6e2e0

Branch: refs/heads/api_refactoring
Commit: 0be6e2e02b0c6a16e277adadea7fb4913bd9a8ce
Parents: 0f2a095
Author: kishan <kishan@cloud.com>
Authored: Wed May 23 18:38:25 2012 +0530
Committer: Kishan Kavala <kishan@cloud.com>
Committed: Mon Dec 17 15:18:31 2012 +0530

----------------------------------------------------------------------
 api/src/com/cloud/api/ApiConstants.java            |    2 +
 .../cloud/agent/api/DirectNetworkUsageCommand.java |   23 ++++++++-
 .../network/resource/TrafficSentinelResource.java  |   39 ++++++++++++---
 .../cloud/api/commands/AddTrafficMonitorCmd.java   |   14 +++++
 server/src/com/cloud/configuration/Config.java     |    2 +
 .../com/cloud/network/NetworkUsageManagerImpl.java |   28 ++++++++---
 6 files changed, 92 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0be6e2e0/api/src/com/cloud/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java
index 9f1c5ea..588cdc6 100755
--- a/api/src/com/cloud/api/ApiConstants.java
+++ b/api/src/com/cloud/api/ApiConstants.java
@@ -393,6 +393,8 @@ public class ApiConstants {
     public static final String S3_CONNECTION_TIMEOUT = "connectiontimeout";
     public static final String S3_MAX_ERROR_RETRY = "maxerrorretry";
     public static final String S3_SOCKET_TIMEOUT = "sockettimeout";
+    public static final String INCL_ZONES = "includezones";
+    public static final String EXCL_ZONES = "excludezones";
     
     public static final String SOURCE = "source";
     public static final String COUNTER_ID = "counterid";

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0be6e2e0/core/src/com/cloud/agent/api/DirectNetworkUsageCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/DirectNetworkUsageCommand.java b/core/src/com/cloud/agent/api/DirectNetworkUsageCommand.java
index 97dcf90..86e794a 100644
--- a/core/src/com/cloud/agent/api/DirectNetworkUsageCommand.java
+++ b/core/src/com/cloud/agent/api/DirectNetworkUsageCommand.java
@@ -24,11 +24,15 @@ public class DirectNetworkUsageCommand extends Command {
     private List<String> publicIps;
     private Date start;
     private Date end;
+    private String includeZones;
+    private String excludeZones;
 
-	public DirectNetworkUsageCommand(List<String> publicIps, Date start, Date end) {
+	public DirectNetworkUsageCommand(List<String> publicIps, Date start, Date end, String
includeZones, String excludeZones) {
 	    this.setPublicIps(publicIps);
 	    this.setStart(start);
 	    this.setEnd(end);
+	    this.setIncludeZones(includeZones);
+	    this.setExcludeZones(excludeZones);
     }
 	
 	@Override
@@ -59,4 +63,21 @@ public class DirectNetworkUsageCommand extends Command {
     public Date getEnd() {
         return end;
     }
+
+	public String getIncludeZones() {
+		return includeZones;
+	}
+
+	public void setIncludeZones(String includeZones) {
+		this.includeZones = includeZones;
+	}
+
+	public String getExcludeZones() {
+		return excludeZones;
+	}
+
+	public void setExcludeZones(String excludeZones) {
+		this.excludeZones = excludeZones;
+	}
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0be6e2e0/core/src/com/cloud/network/resource/TrafficSentinelResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/network/resource/TrafficSentinelResource.java b/core/src/com/cloud/network/resource/TrafficSentinelResource.java
index a9088d0..a13e080 100644
--- a/core/src/com/cloud/network/resource/TrafficSentinelResource.java
+++ b/core/src/com/cloud/network/resource/TrafficSentinelResource.java
@@ -49,7 +49,6 @@ import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupTrafficMonitorCommand;
 import com.cloud.host.Host;
 import com.cloud.resource.ServerResource;
-import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.exception.ExecutionException;
 
 public class TrafficSentinelResource implements ServerResource {
@@ -59,8 +58,8 @@ public class TrafficSentinelResource implements ServerResource {
     private String _ip;
     private String _guid;
     private String _url;
-    private static Integer _numRetries;
-    private static Integer _timeoutInSeconds;
+    private String _inclZones;
+    private String _exclZones;
 	
 	
 	private static final Logger s_logger = Logger.getLogger(TrafficSentinelResource.class);
@@ -91,9 +90,8 @@ public class TrafficSentinelResource implements ServerResource {
                 throw new ConfigurationException("Unable to find url");
             }
             
-            _numRetries = NumbersUtil.parseInt((String) params.get("numRetries"), 1);
-            
-            _timeoutInSeconds = NumbersUtil.parseInt((String) params.get("timeoutInSeconds"),
300);
+            _inclZones = (String)params.get("inclZones");
+            _exclZones = (String)params.get("exclZones");
 
     		return true;
     	} catch (Exception e) {
@@ -197,6 +195,15 @@ public class TrafficSentinelResource implements ServerResource {
 		try {
 		  //Direct Network Usage
             URL trafficSentinel;
+            //Use Global include/exclude zones if there are no per TS zones 
+            if(_inclZones == null){
+            	_inclZones = cmd.getIncludeZones();
+            }
+            
+            if(_exclZones == null){
+            	_exclZones = cmd.getExcludeZones();
+            }
+            
             try {
                 //Query traffic Sentinel
                 trafficSentinel = new URL(_url+"/inmsf/Query?script="+URLEncoder.encode(getScript(cmd.getPublicIps(),
cmd.getStart(), cmd.getEnd()),"UTF-8")
@@ -247,12 +254,28 @@ public class TrafficSentinelResource implements ServerResource {
 	            IpAddresses += ",";
 	        }
 	    }
+	    String destZoneCondition = "";
+	    if(_inclZones !=null && !_inclZones.isEmpty()){
+	    	destZoneCondition = " & destinationzone = "+_inclZones; 
+	    }
+	    if(_exclZones !=null && !_exclZones.isEmpty()){
+	    	destZoneCondition += " & destinationzone != "+_exclZones; 
+	    }
+	    
+	    String srcZoneCondition = "";
+	    if(_inclZones !=null && !_inclZones.isEmpty()){
+	    	srcZoneCondition = " & sourcezone = "+_inclZones; 
+	    }
+	    if(_exclZones !=null && !_exclZones.isEmpty()){
+	    	srcZoneCondition += " & sourcezone != "+_exclZones; 
+	    }
+	    
 	    String startDate = getDateString(start);
 	    String endtDate = getDateString(end);
 	    StringBuffer sb = new StringBuffer();
 	    sb.append("var q = Query.topN(\"historytrmx\",");
 	    sb.append("                 \"ipsource,bytes\",");
-        sb.append("                 \"ipsource = "+IpAddresses+" & destinationzone =
EXTERNAL\",");
+        sb.append("                 \"ipsource = "+IpAddresses+destZoneCondition+"\",");
         sb.append("                 \""+startDate+", "+endtDate+"\",");
 	    sb.append("                 \"bytes\",");
 	    sb.append("                 100000);");
@@ -265,7 +288,7 @@ public class TrafficSentinelResource implements ServerResource {
 	    sb.append("  });");
         sb.append("var q = Query.topN(\"historytrmx\",");
         sb.append("                 \"ipdestination,bytes\",");
-        sb.append("                 \"ipdestination = "+IpAddresses+" & sourcezone =
EXTERNAL\",");
+        sb.append("                 \"ipdestination = "+IpAddresses+srcZoneCondition+"\",");
         sb.append("                 \""+startDate+", "+endtDate+"\",");
         sb.append("                 \"bytes\",");
         sb.append("                 100000);");	    

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0be6e2e0/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java b/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java
index 6bbdde7..f253b37 100644
--- a/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java
+++ b/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java
@@ -50,11 +50,25 @@ public class AddTrafficMonitorCmd extends BaseCmd {
 	
 	@Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL
of the traffic monitor Host")
 	private String url;	 
+
+	@Parameter(name=ApiConstants.INCL_ZONES, type=CommandType.STRING, description="Traffic going
into the listed zones will be metered")
+	private String inclZones;	 
+	
+	@Parameter(name=ApiConstants.EXCL_ZONES, type=CommandType.STRING, description="Traffic going
into the listed zones will not be metered")
+	private String exclZones;	 
 	
 	///////////////////////////////////////////////////
 	/////////////////// Accessors ///////////////////////
 	/////////////////////////////////////////////////////
 	 
+	public String getInclZones() {
+		return inclZones;
+	}
+	
+	public String getExclZones() {
+		return exclZones;
+	}
+
 	public Long getZoneId() {
 	    return zoneId;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0be6e2e0/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index 9b82fcc..2eb269f 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -274,6 +274,8 @@ public enum Config {
     DirectNetworkStatsInterval("Usage", ManagementServer.class, Integer.class, "direct.network.stats.interval",
"86400", "Interval (in seconds) to collect stats from Traffic Monitor", null),
     UsageSanityCheckInterval("Usage", ManagementServer.class, Integer.class, "usage.sanity.check.interval",
null, "Interval (in days) to check sanity of usage data", null),
     UsageAggregationTimezone("Usage", ManagementServer.class, String.class, "usage.aggregation.timezone",
"GMT", "The timezone to use for usage stats aggregation", null),
+    TrafficSentinelIncludeZones("Usage", ManagementServer.class, Integer.class, "traffic.sentinel.include.zones",
"EXTERNAL", "Traffic going into specified list of zones is metered. For metering all traffic
leave this parameter empty", null),
+    TrafficSentinelExcludeZones("Usage", ManagementServer.class, Integer.class, "traffic.sentinel.exclude.zones",
"", "Traffic going into specified list of zones is not metered.", null),
     
 	// Hidden
 	UseSecondaryStorageVm("Hidden", ManagementServer.class, Boolean.class, "secondary.storage.vm",
"false", "Deploys a VM per zone to manage secondary storage if true, otherwise secondary storage
is mounted on management server", null),

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0be6e2e0/server/src/com/cloud/network/NetworkUsageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkUsageManagerImpl.java b/server/src/com/cloud/network/NetworkUsageManagerImpl.java
index 13e5e24..42c72ad 100755
--- a/server/src/com/cloud/network/NetworkUsageManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkUsageManagerImpl.java
@@ -108,6 +108,8 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta
 	@Inject ResourceManager _resourceMgr;
     ScheduledExecutorService _executor;
     int _networkStatsInterval;
+    String _TSinclZones;
+    String _TSexclZones;
     protected SearchBuilder<IPAddressVO> AllocatedIpSearch;
 
     @Override
@@ -148,8 +150,8 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta
         hostParams.put("zone", String.valueOf(zoneId));
         hostParams.put("ipaddress", ipAddress);
         hostParams.put("url", cmd.getUrl());
-        //hostParams("numRetries", numRetries);
-        //hostParams("timeout", timeout);
+        hostParams.put("inclZones", (cmd.getInclZones() != null) ? cmd.getInclZones() : _TSinclZones);
+        hostParams.put("exclZones", (cmd.getExclZones() != null) ? cmd.getExclZones() : _TSexclZones);
         hostParams.put("guid", guid);
         hostParams.put("name", guid);
 
@@ -162,7 +164,14 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager,
ResourceSta
         Map<String, String> hostDetails = new HashMap<String, String>();
         hostDetails.put("url", cmd.getUrl());
         hostDetails.put("last_collection", ""+System.currentTimeMillis());
-
+        if(cmd.getInclZones() != null){
+        	hostDetails.put("inclZones", cmd.getInclZones());
+        }
+        if(cmd.getExclZones() != null){
+        	hostDetails.put("exclZones", cmd.getExclZones());
+        }
+        
+        
         Host trafficMonitor = _resourceMgr.addHost(zoneId, resource, Host.Type.TrafficMonitor,
hostDetails);
         return trafficMonitor;
     }
@@ -222,6 +231,8 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta
         AllocatedIpSearch.done();
         
         _networkStatsInterval = NumbersUtil.parseInt(_configDao.getValue(Config.DirectNetworkStatsInterval.key()),
86400);
+        _TSinclZones = _configDao.getValue(Config.TrafficSentinelIncludeZones.key());
+        _TSexclZones = _configDao.getValue(Config.TrafficSentinelExcludeZones.key());
         _agentMgr.registerForHostEvents(new DirectNetworkStatsListener( _networkStatsInterval),
true, false, false);
         _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
         return true;
@@ -372,7 +383,7 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta
             
             //Get usage for Ips which were assigned for the entire duration
             if(fullDurationIpUsage.size() > 0){
-                DirectNetworkUsageCommand cmd = new DirectNetworkUsageCommand(IpList, lastCollection,
now);
+                DirectNetworkUsageCommand cmd = new DirectNetworkUsageCommand(IpList, lastCollection,
now, _TSinclZones, _TSexclZones);
                 DirectNetworkUsageAnswer answer = (DirectNetworkUsageAnswer) _agentMgr.easySend(host.getId(),
cmd);
                 if (answer == null || !answer.getResult()) {
                     String details = (answer != null) ? answer.getDetails() : "details unavailable";
@@ -405,7 +416,7 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager, ResourceSta
             for(UsageIPAddressVO usageIp : IpPartialUsage){
                 IpList = new ArrayList<String>() ;
                 IpList.add(usageIp.getAddress());
-                DirectNetworkUsageCommand cmd = new DirectNetworkUsageCommand(IpList, usageIp.getAssigned(),
usageIp.getReleased());
+                DirectNetworkUsageCommand cmd = new DirectNetworkUsageCommand(IpList, usageIp.getAssigned(),
usageIp.getReleased(), _TSinclZones, _TSexclZones);
                 DirectNetworkUsageAnswer answer = (DirectNetworkUsageAnswer) _agentMgr.easySend(host.getId(),
cmd);
                 if (answer == null || !answer.getResult()) {
                     String details = (answer != null) ? answer.getDetails() : "details unavailable";
@@ -532,8 +543,11 @@ public class NetworkUsageManagerImpl implements NetworkUsageManager,
ResourceSta
 
 	@Override
     public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage)
throws UnableDeleteHostException {
-	    // TODO Auto-generated method stub
-	    return null;
+		if(host.getType() != Host.Type.TrafficMonitor){
+			return null;
+		}
+		
+		return new DeleteHostAnswer(true);
     }
 
 }


Mime
View raw message