Skip to content

Commit 62157f2

Browse files
committed
updating usage per convo with kishan and frank
1 parent 162e5cf commit 62157f2

14 files changed

Lines changed: 150 additions & 444 deletions

usage/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/core"/>
66
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/utils"/>
77
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
8+
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/premium"/>
89
<classpathentry kind="src" path="/api"/>
910
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
1011
<classpathentry kind="output" path="bin"/>

usage/src/com/cloud/usage/UsageAlertManagerImpl.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
/**
2-
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
3-
*
4-
*
5-
* This software is licensed under the GNU General Public License v3 or later.
6-
*
7-
* It is free software: you can redistribute it and/or modify
8-
* it under the terms of the GNU General Public License as published by
9-
* the Free Software Foundation, either version 3 of the License, or any later version.
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
18-
19-
*
20-
*
2+
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
213
*/
224

235
package com.cloud.usage;

usage/src/com/cloud/usage/UsageManager.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
/**
2-
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
3-
*
4-
*
5-
* This software is licensed under the GNU General Public License v3 or later.
6-
*
7-
* It is free software: you can redistribute it and/or modify
8-
* it under the terms of the GNU General Public License as published by
9-
* the Free Software Foundation, either version 3 of the License, or any later version.
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
18-
*
19-
*
2+
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
203
*/
214

225
package com.cloud.usage;

usage/src/com/cloud/usage/UsageManagerImpl.java

Lines changed: 15 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
/**
2-
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
3-
*
4-
*
5-
* This software is licensed under the GNU General Public License v3 or later.
6-
*
7-
* It is free software: you can redistribute it and/or modify
8-
* it under the terms of the GNU General Public License as published by
9-
* the Free Software Foundation, either version 3 of the License, or any later version.
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
18-
19-
*
20-
*
2+
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
213
*/
224

235
package com.cloud.usage;
246

257
import java.net.InetAddress;
26-
import java.sql.SQLException;
278
import java.util.Calendar;
289
import java.util.Date;
2910
import java.util.HashMap;
@@ -55,7 +36,6 @@
5536
import com.cloud.usage.dao.UsageStorageDao;
5637
import com.cloud.usage.dao.UsageVMInstanceDao;
5738
import com.cloud.usage.dao.UsageVolumeDao;
58-
import com.cloud.usage.parser.IPAddressUsageParser;
5939
import com.cloud.usage.parser.LoadBalancerUsageParser;
6040
import com.cloud.usage.parser.NetworkOfferingUsageParser;
6141
import com.cloud.usage.parser.NetworkUsageParser;
@@ -110,19 +90,16 @@ public class UsageManagerImpl implements UsageManager, Runnable {
11090
private String m_version = null;
11191
private String m_name = null;
11292
private final Calendar m_jobExecTime = Calendar.getInstance();
113-
private int m_aggregationDuration = 0;
114-
private int m_sanityCheckInterval = 0;
93+
private int m_aggregationDuration = 0;
11594
String m_hostname = null;
11695
int m_pid = 0;
117-
TimeZone m_usageTimezone = null;
96+
TimeZone m_usageTimezone = TimeZone.getTimeZone("GMT");;
11897
private final GlobalLock m_heartbeatLock = GlobalLock.getInternLock("usage.job.heartbeat.check");
11998

12099
private final ScheduledExecutorService m_executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-Job"));
121-
private final ScheduledExecutorService m_heartbeatExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-HB"));
122-
private final ScheduledExecutorService m_sanityExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-Sanity"));
100+
private final ScheduledExecutorService m_heartbeatExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-HB"));
123101
private Future m_scheduledFuture = null;
124-
private Future m_heartbeat = null;
125-
private Future m_sanity = null;
102+
private Future m_heartbeat = null;
126103

127104
protected UsageManagerImpl() {
128105
}
@@ -167,14 +144,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
167144

168145
String execTime = configs.get("usage.stats.job.exec.time");
169146
String aggregationRange = configs.get("usage.stats.job.aggregation.range");
170-
String execTimeZone = configs.get("usage.execution.timezone");
171-
String sanityCheckInterval = configs.get("usage.sanity.check.interval");
172-
if(sanityCheckInterval != null){
173-
m_sanityCheckInterval = Integer.parseInt(sanityCheckInterval);
174-
}
175-
176-
m_usageTimezone = TimeZone.getTimeZone("GMT");
147+
String execTimeZone = configs.get("usage.execution.timezone");
148+
String aggreagationTimeZone = configs.get("usage.aggregation.timezone");
177149

150+
m_usageTimezone = TimeZone.getTimeZone(aggreagationTimeZone);
151+
s_logger.debug("Usage stats aggregation time zone: "+aggreagationTimeZone);
152+
178153
try {
179154
if ((execTime == null) || (aggregationRange == null)) {
180155
s_logger.error("missing configuration values for usage job, usage.stats.job.exec.time = " + execTime + ", usage.stats.job.aggregation.range = " + aggregationRange);
@@ -235,11 +210,7 @@ public boolean start() {
235210
// use the configured exec time and aggregation duration for scheduling the job
236211
m_scheduledFuture = m_executor.scheduleAtFixedRate(this, m_jobExecTime.getTimeInMillis() - System.currentTimeMillis(), m_aggregationDuration * 60 * 1000, TimeUnit.MILLISECONDS);
237212

238-
m_heartbeat = m_heartbeatExecutor.scheduleAtFixedRate(new Heartbeat(), /* start in 15 seconds...*/15*1000, /* check database every minute*/60*1000, TimeUnit.MILLISECONDS);
239-
240-
if(m_sanityCheckInterval > 0){
241-
m_sanity = m_sanityExecutor.scheduleAtFixedRate(new SanityCheck(), 1, m_sanityCheckInterval, TimeUnit.DAYS);
242-
}
213+
m_heartbeat = m_heartbeatExecutor.scheduleAtFixedRate(new Heartbeat(), /* start in 15 seconds...*/15*1000, /* check database every minute*/60*1000, TimeUnit.MILLISECONDS);
243214

244215
Transaction usageTxn = Transaction.open(Transaction.USAGE_DB);
245216
try {
@@ -265,10 +236,7 @@ public boolean start() {
265236

266237
public boolean stop() {
267238
m_heartbeat.cancel(true);
268-
m_scheduledFuture.cancel(true);
269-
if(m_sanityCheckInterval > 0){
270-
m_sanity.cancel(true);
271-
}
239+
m_scheduledFuture.cancel(true);
272240
return true;
273241
}
274242

@@ -742,13 +710,6 @@ private boolean parseHelperTables(AccountVO account, Date currentStartDate, Date
742710
if (!parsed) {
743711
s_logger.debug("network offering usage successfully parsed? " + parsed + " (for account: " + account.getAccountName() + ", id: " + account.getId() + ")");
744712
}
745-
}
746-
747-
parsed = IPAddressUsageParser.parse(account, currentStartDate, currentEndDate);
748-
if (s_logger.isDebugEnabled()) {
749-
if (!parsed) {
750-
s_logger.debug("IPAddress usage successfully parsed? " + parsed + " (for account: " + account.getAccountName() + ", id: " + account.getId() + ")");
751-
}
752713
}
753714

754715
return parsed;
@@ -857,16 +818,7 @@ private void createVMHelperEvent(UsageEventVO event) {
857818
usageInstance.setEndDate(event.getCreateDate());
858819
m_usageInstanceDao.update(usageInstance);
859820
}
860-
}
861-
}
862-
863-
sc = m_usageInstanceDao.createSearchCriteria();
864-
sc.addAnd("vmInstanceId", SearchCriteria.Op.EQ, Long.valueOf(vmId));
865-
sc.addAnd("endDate", SearchCriteria.Op.NULL);
866-
sc.addAnd("usageType", SearchCriteria.Op.EQ, UsageTypes.ALLOCATED_VM);
867-
usageInstances = m_usageInstanceDao.search(sc, null);
868-
if (usageInstances == null || (usageInstances.size() == 0)) {
869-
s_logger.error("Cannot find allocated vm entry for a vm running with id: " + vmId);
821+
}
870822
}
871823

872824
Long templateId = event.getTemplateId();
@@ -1037,30 +989,15 @@ private void createVolumeHelperEvent(UsageEventVO event) {
1037989
size = event.getSize();
1038990
}
1039991

1040-
if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
1041-
SearchCriteria<UsageVolumeVO> sc = m_usageVolumeDao.createSearchCriteria();
1042-
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
1043-
sc.addAnd("id", SearchCriteria.Op.EQ, volId);
1044-
sc.addAnd("deleted", SearchCriteria.Op.NULL);
1045-
List<UsageVolumeVO> volumesVOs = m_usageVolumeDao.search(sc, null);
1046-
if (volumesVOs.size() > 0) {
1047-
//This is a safeguard to avoid double counting of volumes.
1048-
s_logger.error("Found duplicate usage entry for volume: " + volId + " assigned to account: " + event.getAccountId() + "; marking as deleted...");
1049-
}
1050-
for (UsageVolumeVO volumesVO : volumesVOs) {
1051-
if (s_logger.isDebugEnabled()) {
1052-
s_logger.debug("deleting volume: " + volumesVO.getId() + " from account: " + volumesVO.getAccountId());
1053-
}
1054-
volumesVO.setDeleted(event.getCreateDate());
1055-
m_usageVolumeDao.update(volumesVO);
1056-
}
992+
if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
1057993
if (s_logger.isDebugEnabled()) {
1058994
s_logger.debug("create volume with id : " + volId + " for account: " + event.getAccountId());
1059995
}
1060996
Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
1061997
UsageVolumeVO volumeVO = new UsageVolumeVO(volId, zoneId, event.getAccountId(), acct.getDomainId(), doId, templateId, size, event.getCreateDate(), null);
1062998
m_usageVolumeDao.persist(volumeVO);
1063999
} else if (EventTypes.EVENT_VOLUME_DELETE.equals(event.getType())) {
1000+
// at this point it's not a sourceNat IP, so find the usage record with this IP and a null released date, update the released date
10641001
SearchCriteria<UsageVolumeVO> sc = m_usageVolumeDao.createSearchCriteria();
10651002
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
10661003
sc.addAnd("id", SearchCriteria.Op.EQ, volId);
@@ -1407,21 +1344,5 @@ protected void deleteOneOffJobs(String hostname, int pid) {
14071344
sc.addAnd("scheduled", SearchCriteria.Op.EQ, Integer.valueOf(0));
14081345
m_usageJobDao.expunge(sc);
14091346
}
1410-
}
1411-
1412-
private class SanityCheck implements Runnable {
1413-
public void run() {
1414-
UsageSanityChecker usc = new UsageSanityChecker();
1415-
try {
1416-
String errors = usc.runSanityCheck();
1417-
if(errors.length() > 0){
1418-
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USAGE_SANITY_RESULT, 0, new Long(0), "Usage Sanity Check failed", errors);
1419-
} else {
1420-
_alertMgr.clearAlert(AlertManager.ALERT_TYPE_USAGE_SANITY_RESULT, 0, 0);
1421-
}
1422-
} catch (SQLException e) {
1423-
s_logger.error("Error in sanity check", e);
1424-
}
1425-
}
14261347
}
14271348
}

usage/src/com/cloud/usage/UsageServer.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
/**
2-
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
3-
*
4-
*
5-
* This software is licensed under the GNU General Public License v3 or later.
6-
*
7-
* It is free software: you can redistribute it and/or modify
8-
* it under the terms of the GNU General Public License as published by
9-
* the Free Software Foundation, either version 3 of the License, or any later version.
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
17-
*
2+
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
183
*/
194

205
package com.cloud.usage;

0 commit comments

Comments
 (0)