use of com.cloud.network.resource.TrafficSentinelResource in project cloudstack by apache.
the class NetworkUsageManagerImpl method addTrafficMonitor.
@Override
public Host addTrafficMonitor(AddTrafficMonitorCmd cmd) {
long zoneId = cmd.getZoneId();
DataCenterVO zone = _dcDao.findById(zoneId);
String zoneName;
if (zone == null) {
throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
} else {
zoneName = zone.getName();
}
List<HostVO> trafficMonitorsInZone = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.TrafficMonitor, zoneId);
if (trafficMonitorsInZone.size() != 0) {
throw new InvalidParameterValueException("Already added an traffic monitor in zone: " + zoneName);
}
URI uri;
try {
uri = new URI(cmd.getUrl());
} catch (Exception e) {
s_logger.debug(e);
throw new InvalidParameterValueException(e.getMessage());
}
String ipAddress = uri.getHost();
//String numRetries = params.get("numretries");
//String timeout = params.get("timeout");
TrafficSentinelResource resource = new TrafficSentinelResource();
String guid = getTrafficMonitorGuid(zoneId, NetworkUsageResourceName.TrafficSentinel, ipAddress);
Map<String, Object> hostParams = new HashMap<String, Object>();
hostParams.put("zone", String.valueOf(zoneId));
hostParams.put("ipaddress", ipAddress);
hostParams.put("url", cmd.getUrl());
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);
try {
resource.configure(guid, hostParams);
} catch (ConfigurationException e) {
throw new CloudRuntimeException(e.getMessage());
}
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;
}
Aggregations