diff --git a/api/src/com/cloud/event/Event.java b/api/src/com/cloud/event/Event.java index 1ff945d22bb..fca4bb5b1d2 100644 --- a/api/src/com/cloud/event/Event.java +++ b/api/src/com/cloud/event/Event.java @@ -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(); } diff --git a/core/src/com/cloud/event/EventVO.java b/core/src/com/cloud/event/EventVO.java index a7eeddc80c6..99b468915f2 100644 --- a/core/src/com/cloud/event/EventVO.java +++ b/core/src/com/cloud/event/EventVO.java @@ -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; - } - } diff --git a/server/src/com/cloud/event/EventUtils.java b/server/src/com/cloud/event/EventUtils.java index a47e1e163a9..ea5ecf63a0b 100755 --- a/server/src/com/cloud/event/EventUtils.java +++ b/server/src/com/cloud/event/EventUtils.java @@ -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(); + } } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index bf2bb165299..361b3bd1d11 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -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 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 sc = sb.create(); if (listProjectResourcesCriteria != null) { - sc.setParameters("accountType", Account.ACCOUNT_TYPE_PROJECT); + sc.setJoinParameters("accountSearch","accountType", Account.ACCOUNT_TYPE_PROJECT); } if (!permittedAccounts.isEmpty()) { diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 17abc9cec03..d153f465fd9 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -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()) { diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 3ea69992573..694b5e336d5 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -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, diff --git a/setup/db/db/schema-2214to30.sql b/setup/db/db/schema-2214to30.sql index 20274e10fd8..a7f3a7922f4 100755 --- a/setup/db/db/schema-2214to30.sql +++ b/setup/db/db/schema-2214to30.sql @@ -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;