Skip to content

Commit d456f89

Browse files
author
kishan
committed
bug 8866: Direct Network Usage, TrafficSentinel support added, work in progress
1 parent bc360f4 commit d456f89

11 files changed

Lines changed: 84 additions & 69 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.agent.api;
20+
21+
import com.cloud.host.Host;
22+
23+
public class StartupTrafficMonitorCommand extends StartupCommand {
24+
public StartupTrafficMonitorCommand() {
25+
super(Host.Type.TrafficMonitor);
26+
}
27+
28+
}

‎api/src/com/cloud/host/Host.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public enum Type {
3535
ExternalFirewall(false),
3636
ExternalLoadBalancer(false),
3737
PxeServer(false),
38+
TrafficMonitor(false),
3839
ExternalDhcp(false);
3940

4041
boolean _virtual;

‎core/src/com/cloud/event/dao/UsageEventDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ public interface UsageEventDao extends GenericDao<UsageEventVO, Long> {
3535

3636
List<UsageEventVO> getRecentEvents(Date endDate) throws UsageServerException;
3737

38+
List<UsageEventVO> listIpEvents(Date startDate, Date endDate);
39+
3840
}

‎core/src/com/cloud/event/dao/UsageEventDaoImpl.java‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.apache.log4j.Logger;
3030

31+
import com.cloud.event.EventTypes;
3132
import com.cloud.event.UsageEventVO;
3233
import com.cloud.exception.UsageServerException;
3334
import com.cloud.utils.DateUtil;
@@ -43,6 +44,7 @@ public class UsageEventDaoImpl extends GenericDaoBase<UsageEventVO, Long> implem
4344
public static final Logger s_logger = Logger.getLogger(UsageEventDaoImpl.class.getName());
4445

4546
private final SearchBuilder<UsageEventVO> latestEventsSearch;
47+
private final SearchBuilder<UsageEventVO> IpeventsSearch;
4648
private static final String COPY_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type) " +
4749
"SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type FROM cloud.usage_event vmevt WHERE vmevt.id > ? and vmevt.id <= ? ";
4850
private static final String COPY_ALL_EVENTS = "INSERT INTO cloud_usage.usage_event (id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size, resource_type) " +
@@ -55,7 +57,15 @@ public UsageEventDaoImpl () {
5557
latestEventsSearch.and("processed", latestEventsSearch.entity().isProcessed(), SearchCriteria.Op.EQ);
5658
latestEventsSearch.and("enddate", latestEventsSearch.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
5759
latestEventsSearch.done();
58-
}
60+
61+
IpeventsSearch = createSearchBuilder();
62+
IpeventsSearch.and("startdate", IpeventsSearch.entity().getCreateDate(), SearchCriteria.Op.GTEQ);
63+
IpeventsSearch.and("enddate", IpeventsSearch.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
64+
IpeventsSearch.and().op("assignEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
65+
IpeventsSearch.or("releaseEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
66+
IpeventsSearch.closeParen();
67+
IpeventsSearch.done();
68+
}
5969

6070
@Override
6171
public List<UsageEventVO> listLatestEvents(Date endDate) {
@@ -159,4 +169,16 @@ private long getMaxEventId(Date endDate) throws UsageServerException {
159169
txn.close();
160170
}
161171
}
162-
}
172+
173+
@Override
174+
public List<UsageEventVO> listIpEvents(Date startDate, Date endDate) {
175+
Filter filter = new Filter(UsageEventVO.class, "createDate", Boolean.TRUE, null, null);
176+
SearchCriteria<UsageEventVO> sc = IpeventsSearch.create();
177+
sc.setParameters("startdate", startDate);
178+
sc.setParameters("enddate", endDate);
179+
sc.setParameters("assignEvent", EventTypes.EVENT_NET_IP_ASSIGN);
180+
sc.setParameters("releaseEvent", EventTypes.EVENT_NET_IP_RELEASE);
181+
return listBy(sc, filter);
182+
}
183+
184+
}

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.cloud.agent.api.StartupPxeServerCommand;
7070
import com.cloud.agent.api.StartupRoutingCommand;
7171
import com.cloud.agent.api.StartupStorageCommand;
72+
import com.cloud.agent.api.StartupTrafficMonitorCommand;
7273
import com.cloud.agent.api.UnsupportedAnswer;
7374
import com.cloud.agent.manager.allocator.HostAllocator;
7475
import com.cloud.agent.manager.allocator.PodAllocator;
@@ -2386,6 +2387,8 @@ public HostVO createHost(final StartupCommand startup, ServerResource resource,
23862387
type = Host.Type.PxeServer;
23872388
} else if (startup instanceof StartupExternalDhcpCommand) {
23882389
type = Host.Type.ExternalDhcp;
2390+
} else if (startup instanceof StartupTrafficMonitorCommand) {
2391+
type = Host.Type.TrafficMonitor;
23892392
} else {
23902393
assert false : "Did someone add a new Startup command?";
23912394
}
@@ -2645,7 +2648,7 @@ protected void updateHost(final HostVO host, final StartupCommand startup, final
26452648
}
26462649
Long podId = null;
26472650
if (p == null) {
2648-
if (type != Host.Type.SecondaryStorage && type != Host.Type.ExternalFirewall && type != Host.Type.ExternalLoadBalancer) {
2651+
if (type != Host.Type.SecondaryStorage && type != Host.Type.ExternalFirewall && type != Host.Type.ExternalLoadBalancer && type != Host.Type.TrafficMonitor) {
26492652

26502653
/*
26512654
* s_logger.info("Unable to find the pod so we are creating one." ); p = createPod(pod, dcId,

‎server/src/com/cloud/agent/manager/AgentMonitor.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public void run() {
106106

107107
for (HostVO host : hosts) {
108108
if (host.getType().equals(Host.Type.ExternalFirewall) ||
109-
host.getType().equals(Host.Type.ExternalLoadBalancer)) {
109+
host.getType().equals(Host.Type.ExternalLoadBalancer) ||
110+
host.getType().equals(Host.Type.TrafficMonitor)) {
110111
continue;
111112
}
112113

‎server/src/com/cloud/host/dao/HostDao.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,5 @@ public interface HostDao extends GenericDao<HostVO, Long> {
169169

170170
boolean directConnect(HostVO host, long msId, boolean secondConnect);
171171

172+
HostVO findTrafficMonitorHost();
172173
}

‎server/src/com/cloud/host/dao/HostDaoImpl.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,4 +799,17 @@ public List<HostVO> listSecondaryStorageHosts(long dataCenterId) {
799799

800800
return secondaryStorageHosts;
801801
}
802+
803+
@Override
804+
public HostVO findTrafficMonitorHost() {
805+
SearchCriteria<HostVO> sc = TypeSearch.create();
806+
sc.setParameters("type", Host.Type.TrafficMonitor);
807+
List<HostVO> trafficHosts = listBy(sc);
808+
809+
if (trafficHosts == null || trafficHosts.size() < 1) {
810+
return null;
811+
} else {
812+
return trafficHosts.get(0);
813+
}
814+
}
802815
}

‎server/src/com/cloud/network/dao/IPAddressDao.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
5050

5151
IPAddressVO findByAccountAndIp(long accountId, String ipAddress);
5252

53-
IPAddressVO findByIpAddress(String ipAddress);
53+
List<IPAddressVO> listAllocatedIps();
5454

5555
}

‎server/src/com/cloud/network/dao/IPAddressDaoImpl.java‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
5252
protected final GenericSearchBuilder<IPAddressVO, Integer> AllocatedIpCount;
5353
protected final GenericSearchBuilder<IPAddressVO, Integer> AllIpCountForDashboard;
5454
protected final GenericSearchBuilder<IPAddressVO, Integer> AllocatedIpCountForDashboard;
55+
protected final SearchBuilder<IPAddressVO> AllocatedIpSearch;
5556

5657

5758
// make it public for JUnit test
@@ -96,6 +97,10 @@ public IPAddressDaoImpl() {
9697
AllocatedIpCountForDashboard.and("dc", AllocatedIpCountForDashboard.entity().getDataCenterId(), Op.EQ);
9798
AllocatedIpCountForDashboard.and("allocated", AllocatedIpCountForDashboard.entity().getAllocatedTime(), Op.NNULL);
9899
AllocatedIpCountForDashboard.done();
100+
101+
AllocatedIpSearch = createSearchBuilder();
102+
AllocatedIpSearch.and("allocated", AllocatedIpSearch.entity().getAllocatedTime(), Op.NNULL);
103+
AllocatedIpSearch.done();
99104
}
100105

101106
@Override
@@ -269,9 +274,8 @@ public IPAddressVO markAsUnavailable(long ipAddressId) {
269274
}
270275

271276
@Override
272-
public IPAddressVO findByIpAddress(String ipAddress) {
273-
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
274-
sc.setParameters("ipAddress", ipAddress);
275-
return findOneBy(sc);
277+
public List<IPAddressVO> listAllocatedIps() {
278+
SearchCriteria<IPAddressVO> sc = AllocatedIpSearch.create();
279+
return listBy(sc);
276280
}
277281
}

0 commit comments

Comments
 (0)