use of com.cloud.event.UsageEventVO in project cloudstack by apache.
the class Upgrade218to22 method convertSnapshotEvent.
private UsageEventVO convertSnapshotEvent(EventVO event, Connection conn) throws IOException, SQLException {
Properties snapEventParams = new Properties();
long snapId = -1L;
long snapSize = -1L;
Long zoneId = 0L;
UsageEventVO usageEvent = null;
snapEventParams.load(new StringReader(event.getParameters()));
snapId = Long.parseLong(snapEventParams.getProperty("id"));
String snapshotName = snapEventParams.getProperty("ssName");
String size = snapEventParams.getProperty("size");
if (size != null) {
snapSize = Long.parseLong(size);
}
String zoneString = snapEventParams.getProperty("dcId");
if (zoneString != null) {
zoneId = Long.parseLong(zoneString);
}
Long accountId = event.getAccountId();
// Get snapshot info (there was a bug in 2.1.x - accountId is 0, and data_center info is not present in events table
if (accountId.longValue() == 0L || zoneId.longValue() == 0L) {
try (PreparedStatement pstmt = conn.prepareStatement("SELECT zone_id, account_id from usage_event where resource_id=? and type like '%SNAPSHOT%'")) {
pstmt.setLong(1, snapId);
try (ResultSet rs = pstmt.executeQuery()) {
if (rs.next()) {
zoneId = rs.getLong(1);
accountId = rs.getLong(2);
}
}
if (EventTypes.EVENT_SNAPSHOT_CREATE.equals(event.getType())) {
usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_CREATE, accountId, zoneId, snapId, snapshotName, null, null, snapSize);
} else if (EventTypes.EVENT_SNAPSHOT_DELETE.equals(event.getType())) {
usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, accountId, zoneId, snapId, snapshotName, null, null, 0L);
}
}
}
return usageEvent;
}
use of com.cloud.event.UsageEventVO in project cloudstack by apache.
the class Upgrade218to22 method convertVMEvent.
private UsageEventVO convertVMEvent(EventVO event) throws IOException {
Properties vmEventParams = new Properties();
UsageEventVO usageEvent = null;
long vmId = -1L;
// service offering id
long soId = -1L;
long zoneId = -1L;
String eventParams = event.getParameters();
if (eventParams != null) {
vmEventParams.load(new StringReader(eventParams));
vmId = Long.parseLong(vmEventParams.getProperty("id"));
soId = Long.parseLong(vmEventParams.getProperty("soId"));
zoneId = Long.parseLong(vmEventParams.getProperty("dcId"));
}
if (EventTypes.EVENT_VM_START.equals(event.getType())) {
long templateId = 0;
String tId = vmEventParams.getProperty("tId");
if (tId != null) {
templateId = Long.parseLong(tId);
}
usageEvent = new UsageEventVO(EventTypes.EVENT_VM_START, event.getAccountId(), zoneId, vmId, vmEventParams.getProperty("vmName"), soId, templateId, "");
} else if (EventTypes.EVENT_VM_STOP.equals(event.getType())) {
usageEvent = new UsageEventVO(EventTypes.EVENT_VM_STOP, event.getAccountId(), zoneId, vmId, vmEventParams.getProperty("vmName"));
} else if (EventTypes.EVENT_VM_CREATE.equals(event.getType())) {
Long templateId = null;
String tId = vmEventParams.getProperty("tId");
if (tId != null) {
templateId = new Long(Long.parseLong(tId));
}
usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE, event.getAccountId(), zoneId, vmId, vmEventParams.getProperty("vmName"), soId, templateId, "");
} else if (EventTypes.EVENT_VM_DESTROY.equals(event.getType())) {
usageEvent = new UsageEventVO(EventTypes.EVENT_VM_DESTROY, event.getAccountId(), zoneId, vmId, vmEventParams.getProperty("vmName"));
}
return usageEvent;
}
use of com.cloud.event.UsageEventVO in project cloudstack by apache.
the class Upgrade218to22 method convertVolumeEvent.
private UsageEventVO convertVolumeEvent(EventVO event, Connection conn) throws IOException, SQLException {
Properties volEventParams = new Properties();
long volId = -1L;
Long doId = -1L;
long zoneId = -1L;
Long templateId = -1L;
long size = -1L;
UsageEventVO usageEvent = null;
volEventParams.load(new StringReader(event.getParameters()));
volId = Long.parseLong(volEventParams.getProperty("id"));
if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
doId = Long.parseLong(volEventParams.getProperty("doId"));
zoneId = Long.parseLong(volEventParams.getProperty("dcId"));
templateId = Long.parseLong(volEventParams.getProperty("tId"));
size = Long.parseLong(volEventParams.getProperty("size"));
size = (size * 1048576);
if (doId == -1) {
doId = null;
}
if (templateId == -1) {
templateId = null;
}
}
// Get volume name information
String volumeName = "";
try (PreparedStatement pstmt = conn.prepareStatement("SELECT name, data_center_id from volumes where id=?")) {
pstmt.setLong(1, volId);
try (ResultSet rs = pstmt.executeQuery()) {
if (rs.next()) {
volumeName = rs.getString(1);
zoneId = rs.getLong(2);
}
if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, event.getAccountId(), zoneId, volId, volumeName, doId, templateId, size);
} else if (EventTypes.EVENT_VOLUME_DELETE.equals(event.getType())) {
usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, event.getAccountId(), zoneId, volId, volumeName);
}
}
}
return usageEvent;
}
use of com.cloud.event.UsageEventVO in project cloudstack by apache.
the class Upgrade218to22 method convertISOEvent.
private UsageEventVO convertISOEvent(EventVO event) throws IOException {
Properties isoEventParams = new Properties();
long isoId = -1L;
long isoSize = -1L;
long zoneId = -1L;
UsageEventVO usageEvent = null;
isoEventParams.load(new StringReader(event.getParameters()));
isoId = Long.parseLong(isoEventParams.getProperty("id"));
if (isoEventParams.getProperty("dcId") != null) {
zoneId = Long.parseLong(isoEventParams.getProperty("dcId"));
}
if (EventTypes.EVENT_ISO_CREATE.equals(event.getType()) || EventTypes.EVENT_ISO_COPY.equals(event.getType())) {
isoSize = Long.parseLong(isoEventParams.getProperty("size"));
usageEvent = new UsageEventVO(event.getType(), event.getAccountId(), zoneId, isoId, "", null, null, isoSize);
} else if (EventTypes.EVENT_ISO_DELETE.equals(event.getType())) {
usageEvent = new UsageEventVO(event.getType(), event.getAccountId(), zoneId, isoId, null);
}
return usageEvent;
}
use of com.cloud.event.UsageEventVO in project cloudstack by apache.
the class UsageEventDaoImpl method listLatestEvents.
@Override
public List<UsageEventVO> listLatestEvents(Date endDate) {
Filter filter = new Filter(UsageEventVO.class, "createDate", Boolean.TRUE, null, null);
SearchCriteria<UsageEventVO> sc = latestEventsSearch.create();
sc.setParameters("processed", false);
sc.setParameters("enddate", endDate);
return listBy(sc, filter);
}
Aggregations