Bug 12929: Added domain_id to event table. Populate domain_id while persisting events. Cleanedup EventUtils.

Status 12929: resolved fixed
Reviewed-By: Nitin
This commit is contained in:
kishan 2012-01-12 16:15:43 +05:30
parent eb1b709193
commit b589e49263
7 changed files with 32 additions and 80 deletions

View File

@ -40,10 +40,8 @@ public interface Event extends ControlledEntity{
long getUserId();
long getAccountId();
long getDomainId();
String getAccountName();
int getTotalSize();
String getLevel();
long getStartId();
String getParameters();
Short getAccountType();
}

View File

@ -28,8 +28,6 @@ import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
import javax.persistence.Transient;
@ -38,8 +36,6 @@ import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="event")
@SecondaryTable(name="account",
pkJoinColumns={@PrimaryKeyJoinColumn(name="account_id", referencedColumnName="id")})
public class EventVO implements Event, Identity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@ -65,18 +61,9 @@ public class EventVO implements Event, Identity {
@Column(name="account_id")
private long accountId;
@Column(name="domain_id", table="account", insertable=false, updatable=false)
@Column(name="domain_id")
private long domainId;
@Column(name="account_name", table="account", insertable=false, updatable=false)
private String accountName;
@Column(name="type", table="account", insertable=false, updatable=false)
private short accountType;
@Column(name="removed", table="account", insertable=false, updatable=false)
private Date removed;
@Column(name="level")
private String level = LEVEL_INFO;
@ -152,11 +139,10 @@ public class EventVO implements Event, Identity {
return domainId;
}
@Override
public String getAccountName() {
return accountName;
public void setDomainId(long domainId) {
this.domainId = domainId;
}
@Override
public int getTotalSize() {
return totalSize;
@ -197,9 +183,4 @@ public class EventVO implements Event, Identity {
this.uuid = uuid;
}
@Override
public Short getAccountType() {
return accountType;
}
}

View File

@ -20,15 +20,19 @@ package com.cloud.event;
import com.cloud.event.dao.EventDao;
import com.cloud.server.ManagementServer;
import com.cloud.user.AccountVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.component.ComponentLocator;
public class EventUtils {
private static EventDao _eventDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(EventDao.class);
private static AccountDao _accountDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(AccountDao.class);
public static Long saveEvent(Long userId, Long accountId, String type, String description) {
public static Long saveEvent(Long userId, Long accountId, Long domainId, String type, String description) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setDomainId(domainId);
event.setType(type);
event.setDescription(description);
event = _eventDao.persist(event);
@ -42,6 +46,7 @@ public class EventUtils {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setDomainId(getDomainId(accountId));
event.setType(type);
event.setStartId(startEventId);
event.setState(Event.State.Scheduled);
@ -57,52 +62,20 @@ public class EventUtils {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setDomainId(getDomainId(accountId));
event.setType(type);
event.setState(Event.State.Started);
event.setDescription("Starting job for "+description);
event.setStartId(startEventId);
event = _eventDao.persist(event);
return event.getId();
}
public static Long saveStartedEvent(Long userId, Long accountId, String type, String description) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setType(type);
event.setState(Event.State.Started);
event.setDescription(description);
event = _eventDao.persist(event);
return event.getId();
}
public static Long saveEvent(Long userId, Long accountId, String level, String type, String description) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setType(type);
event.setDescription(description);
event.setLevel(level);
event = _eventDao.persist(event);
return event.getId();
}
public static Long saveEvent(Long userId, Long accountId, String level, String type, String description, String params) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setType(type);
event.setDescription(description);
event.setLevel(level);
event.setParameters(params);
event = _eventDao.persist(event);
return event.getId();
}
}
public static Long saveEvent(Long userId, Long accountId, String level, String type, String description, long startEventId) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setDomainId(getDomainId(accountId));
event.setType(type);
event.setDescription(description);
event.setLevel(level);
@ -111,23 +84,11 @@ public class EventUtils {
return (event != null ? event.getId() : null);
}
public static Long saveEvent(Long userId, Long accountId, String level, String type, String description, String params, long startEventId) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setType(type);
event.setDescription(description);
event.setLevel(level);
event.setParameters(params);
event.setStartId(startEventId);
event = _eventDao.persist(event);
return event.getId();
}
public static Long saveCreatedEvent(Long userId, Long accountId, String level, String type, String description) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setDomainId(getDomainId(accountId));
event.setType(type);
event.setLevel(level);
event.setState(Event.State.Created);
@ -135,4 +96,9 @@ public class EventUtils {
event = _eventDao.persist(event);
return event.getId();
}
private static long getDomainId(long accountId){
AccountVO account = _accountDao.findByIdIncludingRemoved(accountId);
return account.getDomainId();
}
}

View File

@ -1410,10 +1410,13 @@ public class ManagementServerImpl implements ManagementServer {
}
if (listProjectResourcesCriteria != null) {
if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.EQ);
SearchBuilder<AccountVO> accountSearch = _accountDao.createSearchBuilder();
if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
accountSearch.and("accountType", accountSearch.entity().getType(), SearchCriteria.Op.EQ);
sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
} else if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.NEQ);
accountSearch.and("accountType", accountSearch.entity().getType(), SearchCriteria.Op.NEQ);
sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
}
}
@ -1430,7 +1433,7 @@ public class ManagementServerImpl implements ManagementServer {
SearchCriteria<EventVO> sc = sb.create();
if (listProjectResourcesCriteria != null) {
sc.setParameters("accountType", Account.ACCOUNT_TYPE_PROJECT);
sc.setJoinParameters("accountSearch","accountType", Account.ACCOUNT_TYPE_PROJECT);
}
if (!permittedAccounts.isEmpty()) {

View File

@ -1526,7 +1526,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
public void logoutUser(Long userId) {
UserAccount userAcct = _userAccountDao.findById(userId);
if (userAcct != null) {
EventUtils.saveEvent(userId, userAcct.getAccountId(), EventTypes.EVENT_USER_LOGOUT, "user has logged out");
EventUtils.saveEvent(userId, userAcct.getAccountId(), userAcct.getDomainId(), EventTypes.EVENT_USER_LOGOUT, "user has logged out");
} // else log some kind of error event? This likely means the user doesn't exist, or has been deleted...
}
@ -1649,7 +1649,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
if (s_logger.isDebugEnabled()) {
s_logger.debug("User: " + username + " in domain " + domainId + " has successfully logged in");
}
EventUtils.saveEvent(user.getId(), user.getAccountId(), EventTypes.EVENT_USER_LOGIN, "user has logged in");
EventUtils.saveEvent(user.getId(), user.getAccountId(), user.getDomainId(), EventTypes.EVENT_USER_LOGIN, "user has logged in");
return user;
} else {
if (s_logger.isDebugEnabled()) {

View File

@ -890,6 +890,7 @@ CREATE TABLE `cloud`.`event` (
`description` varchar(1024) NOT NULL,
`user_id` bigint unsigned NOT NULL,
`account_id` bigint unsigned NOT NULL,
`domain_id` bigint unsigned NOT NULL,
`created` datetime NOT NULL,
`level` varchar(16) NOT NULL,
`start_id` bigint unsigned NOT NULL DEFAULT 0,

View File

@ -604,3 +604,6 @@ CREATE TABLE `cloud`.`op_dc_storage_network_ip_address` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
update networks set guru_name='StorageNetworkGuru' where traffic_type='Storage';
ALTER TABLE `cloud`.`event` ADD COLUMN `domain_id` bigint unsigned NOT NULL;
UPDATE `cloud`.`event` e set e.domain_id = (select acc.domain_id from account acc where acc.id = e.account_id) where e.domain_id = 0;