mirror of https://github.com/apache/cloudstack.git
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
This commit is contained in:
parent
0f2a0950b6
commit
0be6e2e02b
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);");
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue