mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
restoring proper licensing notices originally committed in ad79436f2c304db27f5aee355527ffce18cf2590 but unintentionally reverted when trying to fix a few build issues
This commit is contained in:
parent
639f25c259
commit
15302b03da
@ -1,37 +1,51 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*
|
*
|
||||||
*/
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage;
|
package com.cloud.usage;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.ejb.Local;
|
import javax.ejb.Local;
|
||||||
import javax.mail.Authenticator;
|
import javax.mail.Authenticator;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.PasswordAuthentication;
|
import javax.mail.PasswordAuthentication;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.URLName;
|
import javax.mail.URLName;
|
||||||
import javax.mail.Message.RecipientType;
|
import javax.mail.Message.RecipientType;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.alert.AlertManager;
|
import com.cloud.alert.AlertManager;
|
||||||
import com.cloud.alert.AlertVO;
|
import com.cloud.alert.AlertVO;
|
||||||
import com.cloud.alert.dao.AlertDao;
|
import com.cloud.alert.dao.AlertDao;
|
||||||
import com.cloud.configuration.dao.ConfigurationDao;
|
import com.cloud.configuration.dao.ConfigurationDao;
|
||||||
import com.cloud.utils.NumbersUtil;
|
import com.cloud.utils.NumbersUtil;
|
||||||
import com.cloud.utils.component.ComponentLocator;
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
import com.sun.mail.smtp.SMTPMessage;
|
import com.sun.mail.smtp.SMTPMessage;
|
||||||
import com.sun.mail.smtp.SMTPSSLTransport;
|
import com.sun.mail.smtp.SMTPSSLTransport;
|
||||||
import com.sun.mail.smtp.SMTPTransport;
|
import com.sun.mail.smtp.SMTPTransport;
|
||||||
|
|
||||||
@Local(value={AlertManager.class})
|
@Local(value={AlertManager.class})
|
||||||
public class UsageAlertManagerImpl implements AlertManager {
|
public class UsageAlertManagerImpl implements AlertManager {
|
||||||
@ -188,7 +202,7 @@ public class UsageAlertManagerImpl implements AlertManager {
|
|||||||
|
|
||||||
// TODO: make sure this handles SSL transport (useAuth is true) and regular
|
// TODO: make sure this handles SSL transport (useAuth is true) and regular
|
||||||
public void sendAlert(short alertType, long dataCenterId, Long podId, String subject, String content) throws MessagingException, UnsupportedEncodingException {
|
public void sendAlert(short alertType, long dataCenterId, Long podId, String subject, String content) throws MessagingException, UnsupportedEncodingException {
|
||||||
AlertVO alert = null;
|
AlertVO alert = null;
|
||||||
|
|
||||||
if ((alertType != AlertManager.ALERT_TYPE_HOST) &&
|
if ((alertType != AlertManager.ALERT_TYPE_HOST) &&
|
||||||
(alertType != AlertManager.ALERT_TYPE_USERVM) &&
|
(alertType != AlertManager.ALERT_TYPE_USERVM) &&
|
||||||
@ -252,9 +266,9 @@ public class UsageAlertManagerImpl implements AlertManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recalculateCapacity() {
|
public void recalculateCapacity() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*
|
*
|
||||||
*/
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage;
|
package com.cloud.usage;
|
||||||
|
|
||||||
import com.cloud.usage.UsageJobVO;
|
import com.cloud.usage.UsageJobVO;
|
||||||
|
|||||||
@ -1,13 +1,27 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*
|
*
|
||||||
*/
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage;
|
package com.cloud.usage;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -39,7 +53,7 @@ import com.cloud.usage.dao.UsagePortForwardingRuleDao;
|
|||||||
import com.cloud.usage.dao.UsageStorageDao;
|
import com.cloud.usage.dao.UsageStorageDao;
|
||||||
import com.cloud.usage.dao.UsageVMInstanceDao;
|
import com.cloud.usage.dao.UsageVMInstanceDao;
|
||||||
import com.cloud.usage.dao.UsageVolumeDao;
|
import com.cloud.usage.dao.UsageVolumeDao;
|
||||||
import com.cloud.usage.parser.IPAddressUsageParser;
|
import com.cloud.usage.parser.IPAddressUsageParser;
|
||||||
import com.cloud.usage.parser.LoadBalancerUsageParser;
|
import com.cloud.usage.parser.LoadBalancerUsageParser;
|
||||||
import com.cloud.usage.parser.NetworkOfferingUsageParser;
|
import com.cloud.usage.parser.NetworkOfferingUsageParser;
|
||||||
import com.cloud.usage.parser.NetworkUsageParser;
|
import com.cloud.usage.parser.NetworkUsageParser;
|
||||||
@ -94,7 +108,7 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
private String m_version = null;
|
private String m_version = null;
|
||||||
private String m_name = null;
|
private String m_name = null;
|
||||||
private final Calendar m_jobExecTime = Calendar.getInstance();
|
private final Calendar m_jobExecTime = Calendar.getInstance();
|
||||||
private int m_aggregationDuration = 0;
|
private int m_aggregationDuration = 0;
|
||||||
private int m_sanityCheckInterval = 0;
|
private int m_sanityCheckInterval = 0;
|
||||||
String m_hostname = null;
|
String m_hostname = null;
|
||||||
int m_pid = 0;
|
int m_pid = 0;
|
||||||
@ -102,10 +116,10 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
private final GlobalLock m_heartbeatLock = GlobalLock.getInternLock("usage.job.heartbeat.check");
|
private final GlobalLock m_heartbeatLock = GlobalLock.getInternLock("usage.job.heartbeat.check");
|
||||||
|
|
||||||
private final ScheduledExecutorService m_executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-Job"));
|
private final ScheduledExecutorService m_executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-Job"));
|
||||||
private final ScheduledExecutorService m_heartbeatExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-HB"));
|
private final ScheduledExecutorService m_heartbeatExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-HB"));
|
||||||
private final ScheduledExecutorService m_sanityExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-Sanity"));
|
private final ScheduledExecutorService m_sanityExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Usage-Sanity"));
|
||||||
private Future m_scheduledFuture = null;
|
private Future m_scheduledFuture = null;
|
||||||
private Future m_heartbeat = null;
|
private Future m_heartbeat = null;
|
||||||
private Future m_sanity = null;
|
private Future m_sanity = null;
|
||||||
|
|
||||||
protected UsageManagerImpl() {
|
protected UsageManagerImpl() {
|
||||||
@ -151,15 +165,15 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
|
|
||||||
String execTime = configs.get("usage.stats.job.exec.time");
|
String execTime = configs.get("usage.stats.job.exec.time");
|
||||||
String aggregationRange = configs.get("usage.stats.job.aggregation.range");
|
String aggregationRange = configs.get("usage.stats.job.aggregation.range");
|
||||||
String execTimeZone = configs.get("usage.execution.timezone");
|
String execTimeZone = configs.get("usage.execution.timezone");
|
||||||
String aggreagationTimeZone = configs.get("usage.aggregation.timezone");
|
String aggreagationTimeZone = configs.get("usage.aggregation.timezone");
|
||||||
String sanityCheckInterval = configs.get("usage.sanity.check.interval");
|
String sanityCheckInterval = configs.get("usage.sanity.check.interval");
|
||||||
if(sanityCheckInterval != null){
|
if(sanityCheckInterval != null){
|
||||||
m_sanityCheckInterval = Integer.parseInt(sanityCheckInterval);
|
m_sanityCheckInterval = Integer.parseInt(sanityCheckInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_usageTimezone = TimeZone.getTimeZone(aggreagationTimeZone);
|
m_usageTimezone = TimeZone.getTimeZone(aggreagationTimeZone);
|
||||||
s_logger.debug("Usage stats aggregation time zone: "+aggreagationTimeZone);
|
s_logger.debug("Usage stats aggregation time zone: "+aggreagationTimeZone);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ((execTime == null) || (aggregationRange == null)) {
|
if ((execTime == null) || (aggregationRange == null)) {
|
||||||
@ -221,10 +235,10 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
// use the configured exec time and aggregation duration for scheduling the job
|
// use the configured exec time and aggregation duration for scheduling the job
|
||||||
m_scheduledFuture = m_executor.scheduleAtFixedRate(this, m_jobExecTime.getTimeInMillis() - System.currentTimeMillis(), m_aggregationDuration * 60 * 1000, TimeUnit.MILLISECONDS);
|
m_scheduledFuture = m_executor.scheduleAtFixedRate(this, m_jobExecTime.getTimeInMillis() - System.currentTimeMillis(), m_aggregationDuration * 60 * 1000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
m_heartbeat = m_heartbeatExecutor.scheduleAtFixedRate(new Heartbeat(), /* start in 15 seconds...*/15*1000, /* check database every minute*/60*1000, TimeUnit.MILLISECONDS);
|
m_heartbeat = m_heartbeatExecutor.scheduleAtFixedRate(new Heartbeat(), /* start in 15 seconds...*/15*1000, /* check database every minute*/60*1000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
if(m_sanityCheckInterval > 0){
|
if(m_sanityCheckInterval > 0){
|
||||||
m_sanity = m_sanityExecutor.scheduleAtFixedRate(new SanityCheck(), 1, m_sanityCheckInterval, TimeUnit.DAYS);
|
m_sanity = m_sanityExecutor.scheduleAtFixedRate(new SanityCheck(), 1, m_sanityCheckInterval, TimeUnit.DAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction usageTxn = Transaction.open(Transaction.USAGE_DB);
|
Transaction usageTxn = Transaction.open(Transaction.USAGE_DB);
|
||||||
@ -251,7 +265,7 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
|
|
||||||
public boolean stop() {
|
public boolean stop() {
|
||||||
m_heartbeat.cancel(true);
|
m_heartbeat.cancel(true);
|
||||||
m_scheduledFuture.cancel(true);
|
m_scheduledFuture.cancel(true);
|
||||||
m_sanity.cancel(true);
|
m_sanity.cancel(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -469,13 +483,13 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
} finally {
|
} finally {
|
||||||
userTxn.close();
|
userTxn.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fetch a maximum number of events and process them before moving on to the next range of events
|
// TODO: Fetch a maximum number of events and process them before moving on to the next range of events
|
||||||
|
|
||||||
// - get a list of the latest events
|
// - get a list of the latest events
|
||||||
// - insert the latest events into the usage.events table
|
// - insert the latest events into the usage.events table
|
||||||
List<UsageEventVO> events = _usageEventDao.getRecentEvents(new Date(endDateMillis));
|
List<UsageEventVO> events = _usageEventDao.getRecentEvents(new Date(endDateMillis));
|
||||||
|
|
||||||
|
|
||||||
Transaction usageTxn = Transaction.open(Transaction.USAGE_DB);
|
Transaction usageTxn = Transaction.open(Transaction.USAGE_DB);
|
||||||
try {
|
try {
|
||||||
@ -726,13 +740,13 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
s_logger.debug("network offering usage successfully parsed? " + parsed + " (for account: " + account.getAccountName() + ", id: " + account.getId() + ")");
|
s_logger.debug("network offering usage successfully parsed? " + parsed + " (for account: " + account.getAccountName() + ", id: " + account.getId() + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed = IPAddressUsageParser.parse(account, currentStartDate, currentEndDate);
|
parsed = IPAddressUsageParser.parse(account, currentStartDate, currentEndDate);
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
s_logger.debug("IPAddress usage successfully parsed? " + parsed + " (for account: " + account.getAccountName() + ", id: " + account.getId() + ")");
|
s_logger.debug("IPAddress usage successfully parsed? " + parsed + " (for account: " + account.getAccountName() + ", id: " + account.getId() + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
@ -841,16 +855,16 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
usageInstance.setEndDate(event.getCreateDate());
|
usageInstance.setEndDate(event.getCreateDate());
|
||||||
m_usageInstanceDao.update(usageInstance);
|
m_usageInstanceDao.update(usageInstance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sc = m_usageInstanceDao.createSearchCriteria();
|
sc = m_usageInstanceDao.createSearchCriteria();
|
||||||
sc.addAnd("vmInstanceId", SearchCriteria.Op.EQ, Long.valueOf(vmId));
|
sc.addAnd("vmInstanceId", SearchCriteria.Op.EQ, Long.valueOf(vmId));
|
||||||
sc.addAnd("endDate", SearchCriteria.Op.NULL);
|
sc.addAnd("endDate", SearchCriteria.Op.NULL);
|
||||||
sc.addAnd("usageType", SearchCriteria.Op.EQ, UsageTypes.ALLOCATED_VM);
|
sc.addAnd("usageType", SearchCriteria.Op.EQ, UsageTypes.ALLOCATED_VM);
|
||||||
usageInstances = m_usageInstanceDao.search(sc, null);
|
usageInstances = m_usageInstanceDao.search(sc, null);
|
||||||
if (usageInstances == null || (usageInstances.size() == 0)) {
|
if (usageInstances == null || (usageInstances.size() == 0)) {
|
||||||
s_logger.error("Cannot find allocated vm entry for a vm running with id: " + vmId);
|
s_logger.error("Cannot find allocated vm entry for a vm running with id: " + vmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Long templateId = event.getTemplateId();
|
Long templateId = event.getTemplateId();
|
||||||
@ -1021,22 +1035,22 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
size = event.getSize();
|
size = event.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
|
if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
|
||||||
SearchCriteria<UsageVolumeVO> sc = m_usageVolumeDao.createSearchCriteria();
|
SearchCriteria<UsageVolumeVO> sc = m_usageVolumeDao.createSearchCriteria();
|
||||||
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
|
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
|
||||||
sc.addAnd("id", SearchCriteria.Op.EQ, volId);
|
sc.addAnd("id", SearchCriteria.Op.EQ, volId);
|
||||||
sc.addAnd("deleted", SearchCriteria.Op.NULL);
|
sc.addAnd("deleted", SearchCriteria.Op.NULL);
|
||||||
List<UsageVolumeVO> volumesVOs = m_usageVolumeDao.search(sc, null);
|
List<UsageVolumeVO> volumesVOs = m_usageVolumeDao.search(sc, null);
|
||||||
if (volumesVOs.size() > 0) {
|
if (volumesVOs.size() > 0) {
|
||||||
//This is a safeguard to avoid double counting of volumes.
|
//This is a safeguard to avoid double counting of volumes.
|
||||||
s_logger.error("Found duplicate usage entry for volume: " + volId + " assigned to account: " + event.getAccountId() + "; marking as deleted...");
|
s_logger.error("Found duplicate usage entry for volume: " + volId + " assigned to account: " + event.getAccountId() + "; marking as deleted...");
|
||||||
}
|
}
|
||||||
for (UsageVolumeVO volumesVO : volumesVOs) {
|
for (UsageVolumeVO volumesVO : volumesVOs) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("deleting volume: " + volumesVO.getId() + " from account: " + volumesVO.getAccountId());
|
s_logger.debug("deleting volume: " + volumesVO.getId() + " from account: " + volumesVO.getAccountId());
|
||||||
}
|
}
|
||||||
volumesVO.setDeleted(event.getCreateDate());
|
volumesVO.setDeleted(event.getCreateDate());
|
||||||
m_usageVolumeDao.update(volumesVO);
|
m_usageVolumeDao.update(volumesVO);
|
||||||
}
|
}
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("create volume with id : " + volId + " for account: " + event.getAccountId());
|
s_logger.debug("create volume with id : " + volId + " for account: " + event.getAccountId());
|
||||||
@ -1391,21 +1405,21 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
|||||||
sc.addAnd("scheduled", SearchCriteria.Op.EQ, Integer.valueOf(0));
|
sc.addAnd("scheduled", SearchCriteria.Op.EQ, Integer.valueOf(0));
|
||||||
m_usageJobDao.expunge(sc);
|
m_usageJobDao.expunge(sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SanityCheck implements Runnable {
|
private class SanityCheck implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
UsageSanityChecker usc = new UsageSanityChecker();
|
UsageSanityChecker usc = new UsageSanityChecker();
|
||||||
try {
|
try {
|
||||||
String errors = usc.runSanityCheck();
|
String errors = usc.runSanityCheck();
|
||||||
if(errors.length() > 0){
|
if(errors.length() > 0){
|
||||||
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USAGE_SANITY_RESULT, 0, new Long(0), "Usage Sanity Check failed", errors);
|
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_USAGE_SANITY_RESULT, 0, new Long(0), "Usage Sanity Check failed", errors);
|
||||||
} else {
|
} else {
|
||||||
_alertMgr.clearAlert(AlertManager.ALERT_TYPE_USAGE_SANITY_RESULT, 0, 0);
|
_alertMgr.clearAlert(AlertManager.ALERT_TYPE_USAGE_SANITY_RESULT, 0, 0);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
s_logger.error("Error in sanity check", e);
|
s_logger.error("Error in sanity check", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,21 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.cloud.usage;
|
package com.cloud.usage;
|
||||||
|
|||||||
@ -1,9 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*
|
*
|
||||||
*/
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage;
|
package com.cloud.usage;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|||||||
@ -1,16 +1,30 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*
|
*
|
||||||
*/
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage.parser;
|
package com.cloud.usage.parser;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
@ -21,7 +35,7 @@ import com.cloud.usage.UsageVO;
|
|||||||
import com.cloud.usage.dao.UsageDao;
|
import com.cloud.usage.dao.UsageDao;
|
||||||
import com.cloud.usage.dao.UsageIPAddressDao;
|
import com.cloud.usage.dao.UsageIPAddressDao;
|
||||||
import com.cloud.user.AccountVO;
|
import com.cloud.user.AccountVO;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.component.ComponentLocator;
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
|
||||||
public class IPAddressUsageParser {
|
public class IPAddressUsageParser {
|
||||||
@ -30,136 +44,136 @@ public class IPAddressUsageParser {
|
|||||||
private static ComponentLocator _locator = ComponentLocator.getLocator(UsageServer.Name, "usage-components.xml", "log4j-cloud_usage");
|
private static ComponentLocator _locator = ComponentLocator.getLocator(UsageServer.Name, "usage-components.xml", "log4j-cloud_usage");
|
||||||
private static UsageDao m_usageDao = _locator.getDao(UsageDao.class);
|
private static UsageDao m_usageDao = _locator.getDao(UsageDao.class);
|
||||||
private static UsageIPAddressDao m_usageIPAddressDao = _locator.getDao(UsageIPAddressDao.class);
|
private static UsageIPAddressDao m_usageIPAddressDao = _locator.getDao(UsageIPAddressDao.class);
|
||||||
|
|
||||||
|
|
||||||
public static boolean parse(AccountVO account, Date startDate, Date endDate) {
|
public static boolean parse(AccountVO account, Date startDate, Date endDate) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Parsing IP Address usage for account: " + account.getId());
|
s_logger.debug("Parsing IP Address usage for account: " + account.getId());
|
||||||
}
|
}
|
||||||
if ((endDate == null) || endDate.after(new Date())) {
|
if ((endDate == null) || endDate.after(new Date())) {
|
||||||
endDate = new Date();
|
endDate = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - query usage_ip_address table with the following criteria:
|
// - query usage_ip_address table with the following criteria:
|
||||||
// - look for an entry for accountId with start date in the given range
|
// - look for an entry for accountId with start date in the given range
|
||||||
// - look for an entry for accountId with end date in the given range
|
// - look for an entry for accountId with end date in the given range
|
||||||
// - look for an entry for accountId with end date null (currently running vm or owned IP)
|
// - look for an entry for accountId with end date null (currently running vm or owned IP)
|
||||||
// - look for an entry for accountId with start date before given range *and* end date after given range
|
// - look for an entry for accountId with start date before given range *and* end date after given range
|
||||||
List<UsageIPAddressVO> usageIPAddress = m_usageIPAddressDao.getUsageRecords(account.getId(), account.getDomainId(), startDate, endDate);
|
List<UsageIPAddressVO> usageIPAddress = m_usageIPAddressDao.getUsageRecords(account.getId(), account.getDomainId(), startDate, endDate);
|
||||||
|
|
||||||
if(usageIPAddress.isEmpty()){
|
if(usageIPAddress.isEmpty()){
|
||||||
s_logger.debug("No IP Address usage for this period");
|
s_logger.debug("No IP Address usage for this period");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This map has both the running time *and* the usage amount.
|
// This map has both the running time *and* the usage amount.
|
||||||
Map<String, Pair<Long, Long>> usageMap = new HashMap<String, Pair<Long, Long>>();
|
Map<String, Pair<Long, Long>> usageMap = new HashMap<String, Pair<Long, Long>>();
|
||||||
|
|
||||||
Map<String, IpInfo> IPMap = new HashMap<String, IpInfo>();
|
Map<String, IpInfo> IPMap = new HashMap<String, IpInfo>();
|
||||||
|
|
||||||
// loop through all the usage IPs, create a usage record for each
|
// loop through all the usage IPs, create a usage record for each
|
||||||
for (UsageIPAddressVO usageIp : usageIPAddress) {
|
for (UsageIPAddressVO usageIp : usageIPAddress) {
|
||||||
long IpId = usageIp.getId();
|
long IpId = usageIp.getId();
|
||||||
|
|
||||||
String key = ""+IpId;
|
String key = ""+IpId;
|
||||||
|
|
||||||
// store the info in the IP map
|
// store the info in the IP map
|
||||||
IPMap.put(key, new IpInfo(usageIp.getZoneId(), IpId, usageIp.getAddress(), usageIp.isSourceNat()));
|
IPMap.put(key, new IpInfo(usageIp.getZoneId(), IpId, usageIp.getAddress(), usageIp.isSourceNat()));
|
||||||
|
|
||||||
Date IpAssignDate = usageIp.getAssigned();
|
Date IpAssignDate = usageIp.getAssigned();
|
||||||
Date IpReleaseDeleteDate = usageIp.getReleased();
|
Date IpReleaseDeleteDate = usageIp.getReleased();
|
||||||
|
|
||||||
if ((IpReleaseDeleteDate == null) || IpReleaseDeleteDate.after(endDate)) {
|
if ((IpReleaseDeleteDate == null) || IpReleaseDeleteDate.after(endDate)) {
|
||||||
IpReleaseDeleteDate = endDate;
|
IpReleaseDeleteDate = endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clip the start date to the beginning of our aggregation range if the vm has been running for a while
|
// clip the start date to the beginning of our aggregation range if the vm has been running for a while
|
||||||
if (IpAssignDate.before(startDate)) {
|
if (IpAssignDate.before(startDate)) {
|
||||||
IpAssignDate = startDate;
|
IpAssignDate = startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
long currentDuration = (IpReleaseDeleteDate.getTime() - IpAssignDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
|
long currentDuration = (IpReleaseDeleteDate.getTime() - IpAssignDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
|
||||||
|
|
||||||
updateIpUsageData(usageMap, key, usageIp.getId(), currentDuration);
|
updateIpUsageData(usageMap, key, usageIp.getId(), currentDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String ipIdKey : usageMap.keySet()) {
|
for (String ipIdKey : usageMap.keySet()) {
|
||||||
Pair<Long, Long> ipTimeInfo = usageMap.get(ipIdKey);
|
Pair<Long, Long> ipTimeInfo = usageMap.get(ipIdKey);
|
||||||
long useTime = ipTimeInfo.second().longValue();
|
long useTime = ipTimeInfo.second().longValue();
|
||||||
|
|
||||||
// Only create a usage record if we have a runningTime of bigger than zero.
|
// Only create a usage record if we have a runningTime of bigger than zero.
|
||||||
if (useTime > 0L) {
|
if (useTime > 0L) {
|
||||||
IpInfo info = IPMap.get(ipIdKey);
|
IpInfo info = IPMap.get(ipIdKey);
|
||||||
createUsageRecord(info.getZoneId(), useTime, startDate, endDate, account, info.getIpId(), info.getIPAddress(), info.isSourceNat());
|
createUsageRecord(info.getZoneId(), useTime, startDate, endDate, account, info.getIpId(), info.getIPAddress(), info.isSourceNat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateIpUsageData(Map<String, Pair<Long, Long>> usageDataMap, String key, long ipId, long duration) {
|
private static void updateIpUsageData(Map<String, Pair<Long, Long>> usageDataMap, String key, long ipId, long duration) {
|
||||||
Pair<Long, Long> ipUsageInfo = usageDataMap.get(key);
|
Pair<Long, Long> ipUsageInfo = usageDataMap.get(key);
|
||||||
if (ipUsageInfo == null) {
|
if (ipUsageInfo == null) {
|
||||||
ipUsageInfo = new Pair<Long, Long>(new Long(ipId), new Long(duration));
|
ipUsageInfo = new Pair<Long, Long>(new Long(ipId), new Long(duration));
|
||||||
} else {
|
} else {
|
||||||
Long runningTime = ipUsageInfo.second();
|
Long runningTime = ipUsageInfo.second();
|
||||||
runningTime = new Long(runningTime.longValue() + duration);
|
runningTime = new Long(runningTime.longValue() + duration);
|
||||||
ipUsageInfo = new Pair<Long, Long>(ipUsageInfo.first(), runningTime);
|
ipUsageInfo = new Pair<Long, Long>(ipUsageInfo.first(), runningTime);
|
||||||
}
|
}
|
||||||
usageDataMap.put(key, ipUsageInfo);
|
usageDataMap.put(key, ipUsageInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createUsageRecord(long zoneId, long runningTime, Date startDate, Date endDate, AccountVO account, long IpId, String IPAddress, boolean isSourceNat) {
|
private static void createUsageRecord(long zoneId, long runningTime, Date startDate, Date endDate, AccountVO account, long IpId, String IPAddress, boolean isSourceNat) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Total usage time " + runningTime + "ms");
|
s_logger.debug("Total usage time " + runningTime + "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
float usage = runningTime / 1000f / 60f / 60f;
|
float usage = runningTime / 1000f / 60f / 60f;
|
||||||
|
|
||||||
DecimalFormat dFormat = new DecimalFormat("#.######");
|
DecimalFormat dFormat = new DecimalFormat("#.######");
|
||||||
String usageDisplay = dFormat.format(usage);
|
String usageDisplay = dFormat.format(usage);
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Creating IP usage record with id: " + IpId + ", usage: " + usageDisplay + ", startDate: " + startDate + ", endDate: " + endDate + ", for account: " + account.getId());
|
s_logger.debug("Creating IP usage record with id: " + IpId + ", usage: " + usageDisplay + ", startDate: " + startDate + ", endDate: " + endDate + ", for account: " + account.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
String usageDesc = "IPAddress: "+IPAddress;
|
String usageDesc = "IPAddress: "+IPAddress;
|
||||||
|
|
||||||
// Create the usage record
|
// Create the usage record
|
||||||
|
|
||||||
UsageVO usageRecord = new UsageVO(zoneId, account.getAccountId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs",
|
UsageVO usageRecord = new UsageVO(zoneId, account.getAccountId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs",
|
||||||
UsageTypes.IP_ADDRESS, new Double(usage), null, null, null, null, IpId, startDate, endDate, (isSourceNat?"SourceNat":""));
|
UsageTypes.IP_ADDRESS, new Double(usage), null, null, null, null, IpId, startDate, endDate, (isSourceNat?"SourceNat":""));
|
||||||
m_usageDao.persist(usageRecord);
|
m_usageDao.persist(usageRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class IpInfo {
|
private static class IpInfo {
|
||||||
private long zoneId;
|
private long zoneId;
|
||||||
private long IpId;
|
private long IpId;
|
||||||
private String IPAddress;
|
private String IPAddress;
|
||||||
private boolean isSourceNat;
|
private boolean isSourceNat;
|
||||||
|
|
||||||
public IpInfo(long zoneId,long IpId, String IPAddress, boolean isSourceNat) {
|
public IpInfo(long zoneId,long IpId, String IPAddress, boolean isSourceNat) {
|
||||||
this.zoneId = zoneId;
|
this.zoneId = zoneId;
|
||||||
this.IpId = IpId;
|
this.IpId = IpId;
|
||||||
this.IPAddress = IPAddress;
|
this.IPAddress = IPAddress;
|
||||||
this.isSourceNat = isSourceNat;
|
this.isSourceNat = isSourceNat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getZoneId() {
|
public long getZoneId() {
|
||||||
return zoneId;
|
return zoneId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getIpId() {
|
public long getIpId() {
|
||||||
return IpId;
|
return IpId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIPAddress() {
|
public String getIPAddress() {
|
||||||
return IPAddress;
|
return IPAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSourceNat() {
|
public boolean isSourceNat() {
|
||||||
return isSourceNat;
|
return isSourceNat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*/
|
*
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage.parser;
|
package com.cloud.usage.parser;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*/
|
*
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage.parser;
|
package com.cloud.usage.parser;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*/
|
*
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage.parser;
|
package com.cloud.usage.parser;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*/
|
*
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage.parser;
|
package com.cloud.usage.parser;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*/
|
*
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage.parser;
|
package com.cloud.usage.parser;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@ -61,7 +76,7 @@ public class StorageUsageParser {
|
|||||||
long storageId = usageStorage.getId();
|
long storageId = usageStorage.getId();
|
||||||
int storage_type = usageStorage.getStorageType();
|
int storage_type = usageStorage.getStorageType();
|
||||||
long size = usageStorage.getSize();
|
long size = usageStorage.getSize();
|
||||||
long zoneId = usageStorage.getZoneId();
|
long zoneId = usageStorage.getZoneId();
|
||||||
Long sourceId = usageStorage.getSourceId();
|
Long sourceId = usageStorage.getSourceId();
|
||||||
|
|
||||||
String key = ""+storageId+"Z"+zoneId+"T"+storage_type;
|
String key = ""+storageId+"Z"+zoneId+"T"+storage_type;
|
||||||
@ -127,14 +142,14 @@ public class StorageUsageParser {
|
|||||||
s_logger.debug("Creating Storage usage record for type: "+ type + " with id: " + storageId + ", usage: " + usageDisplay + ", startDate: " + startDate + ", endDate: " + endDate + ", for account: " + account.getId());
|
s_logger.debug("Creating Storage usage record for type: "+ type + " with id: " + storageId + ", usage: " + usageDisplay + ", startDate: " + startDate + ", endDate: " + endDate + ", for account: " + account.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
String usageDesc = "";
|
String usageDesc = "";
|
||||||
Long tmplSourceId = null;
|
Long tmplSourceId = null;
|
||||||
|
|
||||||
int usage_type = 0;
|
int usage_type = 0;
|
||||||
switch(type){
|
switch(type){
|
||||||
case StorageTypes.TEMPLATE:
|
case StorageTypes.TEMPLATE:
|
||||||
usage_type = UsageTypes.TEMPLATE;
|
usage_type = UsageTypes.TEMPLATE;
|
||||||
usageDesc += "Template ";
|
usageDesc += "Template ";
|
||||||
tmplSourceId = sourceId;
|
tmplSourceId = sourceId;
|
||||||
break;
|
break;
|
||||||
case StorageTypes.ISO:
|
case StorageTypes.ISO:
|
||||||
@ -158,14 +173,14 @@ public class StorageUsageParser {
|
|||||||
private static class StorageInfo {
|
private static class StorageInfo {
|
||||||
private long zoneId;
|
private long zoneId;
|
||||||
private long storageId;
|
private long storageId;
|
||||||
private int storageType;
|
private int storageType;
|
||||||
private Long sourceId;
|
private Long sourceId;
|
||||||
private long size;
|
private long size;
|
||||||
|
|
||||||
public StorageInfo(long zoneId, long storageId, int storageType, Long sourceId, long size) {
|
public StorageInfo(long zoneId, long storageId, int storageType, Long sourceId, long size) {
|
||||||
this.zoneId = zoneId;
|
this.zoneId = zoneId;
|
||||||
this.storageId = storageId;
|
this.storageId = storageId;
|
||||||
this.storageType = storageType;
|
this.storageType = storageType;
|
||||||
this.sourceId = sourceId;
|
this.sourceId = sourceId;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
@ -181,11 +196,11 @@ public class StorageUsageParser {
|
|||||||
public int getStorageType() {
|
public int getStorageType() {
|
||||||
return storageType;
|
return storageType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getSourceId() {
|
public long getSourceId() {
|
||||||
return sourceId;
|
return sourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getSize() {
|
public long getSize() {
|
||||||
return size;
|
return size;
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*/
|
*
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage.parser;
|
package com.cloud.usage.parser;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*/
|
*
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage.parser;
|
package com.cloud.usage.parser;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
/**
|
|
||||||
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
/**
|
||||||
*
|
* * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
|
||||||
*/
|
*
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.cloud.usage.parser;
|
package com.cloud.usage.parser;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user