Search in sources :

Example 16 with UsageEventVO

use of com.cloud.event.UsageEventVO in project cloudstack by apache.

the class Upgrade218to22 method convertTemplateEvent.

private UsageEventVO convertTemplateEvent(EventVO event) throws IOException {
    Properties templateEventParams = new Properties();
    long templateId = -1L;
    long zoneId = -1L;
    long templateSize = -1L;
    UsageEventVO usageEvent = null;
    templateEventParams.load(new StringReader(event.getParameters()));
    templateId = Long.parseLong(templateEventParams.getProperty("id"));
    if (templateEventParams.getProperty("dcId") != null) {
        zoneId = Long.parseLong(templateEventParams.getProperty("dcId"));
    }
    if (EventTypes.EVENT_TEMPLATE_CREATE.equals(event.getType()) || EventTypes.EVENT_TEMPLATE_COPY.equals(event.getType())) {
        templateSize = Long.parseLong(templateEventParams.getProperty("size"));
        if (templateSize < 1) {
            return null;
        }
        if (zoneId == -1L) {
            return null;
        }
        usageEvent = new UsageEventVO(event.getType(), event.getAccountId(), zoneId, templateId, "", null, null, templateSize);
    } else if (EventTypes.EVENT_TEMPLATE_DELETE.equals(event.getType())) {
        usageEvent = new UsageEventVO(event.getType(), event.getAccountId(), zoneId, templateId, null);
    }
    return usageEvent;
}
Also used : StringReader(java.io.StringReader) UsageEventVO(com.cloud.event.UsageEventVO) Properties(java.util.Properties)

Example 17 with UsageEventVO

use of com.cloud.event.UsageEventVO in project cloudstack by apache.

the class Upgrade218to22 method convertIPEvent.

private UsageEventVO convertIPEvent(EventVO event, Connection conn) throws IOException, SQLException {
    Properties ipEventParams = new Properties();
    UsageEventVO usageEvent = null;
    ipEventParams.load(new StringReader(event.getParameters()));
    String ipAddress = ipEventParams.getProperty("address");
    if (ipAddress == null) {
        ipAddress = ipEventParams.getProperty("guestIPaddress");
        if (ipAddress == null) {
            // can not find IP address, bail for this event
            return null;
        }
    }
    // Get ip address information
    Long ipId = 0L;
    Long zoneId = 0L;
    try (PreparedStatement pstmt = conn.prepareStatement("SELECT id, data_center_id from user_ip_address where public_ip_address=?")) {
        pstmt.setString(1, ipAddress);
        try (ResultSet rs = pstmt.executeQuery()) {
            if (rs.next()) {
                ipId = rs.getLong(1);
                zoneId = rs.getLong(2);
            }
            boolean isSourceNat = Boolean.parseBoolean(ipEventParams.getProperty("sourceNat"));
            if (EventTypes.EVENT_NET_IP_ASSIGN.equals(event.getType())) {
                zoneId = Long.parseLong(ipEventParams.getProperty("dcId"));
                usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, event.getAccountId(), zoneId, ipId, ipAddress, isSourceNat, "", false);
            } else if (EventTypes.EVENT_NET_IP_RELEASE.equals(event.getType())) {
                usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, event.getAccountId(), zoneId, ipId, ipAddress, isSourceNat, "", false);
            }
        }
    }
    return usageEvent;
}
Also used : StringReader(java.io.StringReader) ResultSet(java.sql.ResultSet) UsageEventVO(com.cloud.event.UsageEventVO) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties)

Aggregations

UsageEventVO (com.cloud.event.UsageEventVO)17 StringReader (java.io.StringReader)6 Properties (java.util.Properties)6 Filter (com.cloud.utils.db.Filter)4 PreparedStatement (java.sql.PreparedStatement)4 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ResultSet (java.sql.ResultSet)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 ConfigurationException (javax.naming.ConfigurationException)3 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)3 VMTemplateZoneVO (com.cloud.storage.VMTemplateZoneVO)2 VolumeVO (com.cloud.storage.VolumeVO)2 Account (com.cloud.user.Account)2 AccountVO (com.cloud.user.AccountVO)2 UserStatisticsVO (com.cloud.user.UserStatisticsVO)2 DB (com.cloud.utils.db.DB)2 SQLException (java.sql.SQLException)2 Calendar (java.util.Calendar)2