Search in sources :

Example 1 with TrafficSentinelResource

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;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) Host(com.cloud.host.Host) URI(java.net.URI) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TrafficSentinelResource(com.cloud.network.resource.TrafficSentinelResource)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 Host (com.cloud.host.Host)1 HostVO (com.cloud.host.HostVO)1 TrafficSentinelResource (com.cloud.network.resource.TrafficSentinelResource)1 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 ConfigurationException (javax.naming.ConfigurationException)1