Skip to content

Commit b589e49

Browse files
author
kishan
committed
Bug 12929: Added domain_id to event table. Populate domain_id while persisting events. Cleanedup EventUtils.
Status 12929: resolved fixed Reviewed-By: Nitin
1 parent eb1b709 commit b589e49

7 files changed

Lines changed: 32 additions & 80 deletions

File tree

api/src/com/cloud/event/Event.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ public enum State {
4040
long getUserId();
4141
long getAccountId();
4242
long getDomainId();
43-
String getAccountName();
4443
int getTotalSize();
4544
String getLevel();
4645
long getStartId();
4746
String getParameters();
48-
Short getAccountType();
4947
}

core/src/com/cloud/event/EventVO.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import javax.persistence.GeneratedValue;
2929
import javax.persistence.GenerationType;
3030
import javax.persistence.Id;
31-
import javax.persistence.PrimaryKeyJoinColumn;
32-
import javax.persistence.SecondaryTable;
3331
import javax.persistence.Table;
3432
import javax.persistence.Transient;
3533

@@ -38,8 +36,6 @@
3836

3937
@Entity
4038
@Table(name="event")
41-
@SecondaryTable(name="account",
42-
pkJoinColumns={@PrimaryKeyJoinColumn(name="account_id", referencedColumnName="id")})
4339
public class EventVO implements Event, Identity {
4440
@Id
4541
@GeneratedValue(strategy=GenerationType.IDENTITY)
@@ -65,18 +61,9 @@ public class EventVO implements Event, Identity {
6561
@Column(name="account_id")
6662
private long accountId;
6763

68-
@Column(name="domain_id", table="account", insertable=false, updatable=false)
64+
@Column(name="domain_id")
6965
private long domainId;
7066

71-
@Column(name="account_name", table="account", insertable=false, updatable=false)
72-
private String accountName;
73-
74-
@Column(name="type", table="account", insertable=false, updatable=false)
75-
private short accountType;
76-
77-
@Column(name="removed", table="account", insertable=false, updatable=false)
78-
private Date removed;
79-
8067
@Column(name="level")
8168
private String level = LEVEL_INFO;
8269

@@ -152,11 +139,10 @@ public long getDomainId() {
152139
return domainId;
153140
}
154141

155-
@Override
156-
public String getAccountName() {
157-
return accountName;
142+
public void setDomainId(long domainId) {
143+
this.domainId = domainId;
158144
}
159-
145+
160146
@Override
161147
public int getTotalSize() {
162148
return totalSize;
@@ -197,9 +183,4 @@ public void setUuid(String uuid) {
197183
this.uuid = uuid;
198184
}
199185

200-
@Override
201-
public Short getAccountType() {
202-
return accountType;
203-
}
204-
205186
}

server/src/com/cloud/event/EventUtils.java

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@
2020

2121
import com.cloud.event.dao.EventDao;
2222
import com.cloud.server.ManagementServer;
23+
import com.cloud.user.AccountVO;
24+
import com.cloud.user.dao.AccountDao;
2325
import com.cloud.utils.component.ComponentLocator;
2426

2527
public class EventUtils {
2628
private static EventDao _eventDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(EventDao.class);
29+
private static AccountDao _accountDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(AccountDao.class);
2730

28-
public static Long saveEvent(Long userId, Long accountId, String type, String description) {
31+
public static Long saveEvent(Long userId, Long accountId, Long domainId, String type, String description) {
2932
EventVO event = new EventVO();
3033
event.setUserId(userId);
3134
event.setAccountId(accountId);
35+
event.setDomainId(domainId);
3236
event.setType(type);
3337
event.setDescription(description);
3438
event = _eventDao.persist(event);
@@ -42,6 +46,7 @@ public static Long saveScheduledEvent(Long userId, Long accountId, String type,
4246
EventVO event = new EventVO();
4347
event.setUserId(userId);
4448
event.setAccountId(accountId);
49+
event.setDomainId(getDomainId(accountId));
4550
event.setType(type);
4651
event.setStartId(startEventId);
4752
event.setState(Event.State.Scheduled);
@@ -57,52 +62,20 @@ public static Long saveStartedEvent(Long userId, Long accountId, String type, St
5762
EventVO event = new EventVO();
5863
event.setUserId(userId);
5964
event.setAccountId(accountId);
65+
event.setDomainId(getDomainId(accountId));
6066
event.setType(type);
6167
event.setState(Event.State.Started);
6268
event.setDescription("Starting job for "+description);
6369
event.setStartId(startEventId);
6470
event = _eventDao.persist(event);
6571
return event.getId();
66-
}
67-
68-
public static Long saveStartedEvent(Long userId, Long accountId, String type, String description) {
69-
EventVO event = new EventVO();
70-
event.setUserId(userId);
71-
event.setAccountId(accountId);
72-
event.setType(type);
73-
event.setState(Event.State.Started);
74-
event.setDescription(description);
75-
event = _eventDao.persist(event);
76-
return event.getId();
77-
}
78-
79-
public static Long saveEvent(Long userId, Long accountId, String level, String type, String description) {
80-
EventVO event = new EventVO();
81-
event.setUserId(userId);
82-
event.setAccountId(accountId);
83-
event.setType(type);
84-
event.setDescription(description);
85-
event.setLevel(level);
86-
event = _eventDao.persist(event);
87-
return event.getId();
88-
}
89-
90-
public static Long saveEvent(Long userId, Long accountId, String level, String type, String description, String params) {
91-
EventVO event = new EventVO();
92-
event.setUserId(userId);
93-
event.setAccountId(accountId);
94-
event.setType(type);
95-
event.setDescription(description);
96-
event.setLevel(level);
97-
event.setParameters(params);
98-
event = _eventDao.persist(event);
99-
return event.getId();
100-
}
72+
}
10173

10274
public static Long saveEvent(Long userId, Long accountId, String level, String type, String description, long startEventId) {
10375
EventVO event = new EventVO();
10476
event.setUserId(userId);
10577
event.setAccountId(accountId);
78+
event.setDomainId(getDomainId(accountId));
10679
event.setType(type);
10780
event.setDescription(description);
10881
event.setLevel(level);
@@ -111,28 +84,21 @@ public static Long saveEvent(Long userId, Long accountId, String level, String t
11184
return (event != null ? event.getId() : null);
11285
}
11386

114-
public static Long saveEvent(Long userId, Long accountId, String level, String type, String description, String params, long startEventId) {
115-
EventVO event = new EventVO();
116-
event.setUserId(userId);
117-
event.setAccountId(accountId);
118-
event.setType(type);
119-
event.setDescription(description);
120-
event.setLevel(level);
121-
event.setParameters(params);
122-
event.setStartId(startEventId);
123-
event = _eventDao.persist(event);
124-
return event.getId();
125-
}
126-
12787
public static Long saveCreatedEvent(Long userId, Long accountId, String level, String type, String description) {
12888
EventVO event = new EventVO();
12989
event.setUserId(userId);
13090
event.setAccountId(accountId);
91+
event.setDomainId(getDomainId(accountId));
13192
event.setType(type);
13293
event.setLevel(level);
13394
event.setState(Event.State.Created);
13495
event.setDescription(description);
13596
event = _eventDao.persist(event);
13697
return event.getId();
13798
}
99+
100+
private static long getDomainId(long accountId){
101+
AccountVO account = _accountDao.findByIdIncludingRemoved(accountId);
102+
return account.getDomainId();
103+
}
138104
}

server/src/com/cloud/server/ManagementServerImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,10 +1410,13 @@ public List<EventVO> searchForEvents(ListEventsCmd cmd) {
14101410
}
14111411

14121412
if (listProjectResourcesCriteria != null) {
1413-
if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
1414-
sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.EQ);
1413+
SearchBuilder<AccountVO> accountSearch = _accountDao.createSearchBuilder();
1414+
if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
1415+
accountSearch.and("accountType", accountSearch.entity().getType(), SearchCriteria.Op.EQ);
1416+
sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
14151417
} else if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
1416-
sb.and("accountType", sb.entity().getAccountType(), SearchCriteria.Op.NEQ);
1418+
accountSearch.and("accountType", accountSearch.entity().getType(), SearchCriteria.Op.NEQ);
1419+
sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
14171420
}
14181421
}
14191422

@@ -1430,7 +1433,7 @@ public List<EventVO> searchForEvents(ListEventsCmd cmd) {
14301433

14311434
SearchCriteria<EventVO> sc = sb.create();
14321435
if (listProjectResourcesCriteria != null) {
1433-
sc.setParameters("accountType", Account.ACCOUNT_TYPE_PROJECT);
1436+
sc.setJoinParameters("accountSearch","accountType", Account.ACCOUNT_TYPE_PROJECT);
14341437
}
14351438

14361439
if (!permittedAccounts.isEmpty()) {

server/src/com/cloud/user/AccountManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ public UserVO createUser(long accountId, String userName, String password, Strin
15261526
public void logoutUser(Long userId) {
15271527
UserAccount userAcct = _userAccountDao.findById(userId);
15281528
if (userAcct != null) {
1529-
EventUtils.saveEvent(userId, userAcct.getAccountId(), EventTypes.EVENT_USER_LOGOUT, "user has logged out");
1529+
EventUtils.saveEvent(userId, userAcct.getAccountId(), userAcct.getDomainId(), EventTypes.EVENT_USER_LOGOUT, "user has logged out");
15301530
} // else log some kind of error event? This likely means the user doesn't exist, or has been deleted...
15311531
}
15321532

@@ -1649,7 +1649,7 @@ public UserAccount authenticateUser(String username, String password, Long domai
16491649
if (s_logger.isDebugEnabled()) {
16501650
s_logger.debug("User: " + username + " in domain " + domainId + " has successfully logged in");
16511651
}
1652-
EventUtils.saveEvent(user.getId(), user.getAccountId(), EventTypes.EVENT_USER_LOGIN, "user has logged in");
1652+
EventUtils.saveEvent(user.getId(), user.getAccountId(), user.getDomainId(), EventTypes.EVENT_USER_LOGIN, "user has logged in");
16531653
return user;
16541654
} else {
16551655
if (s_logger.isDebugEnabled()) {

setup/db/create-schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ CREATE TABLE `cloud`.`event` (
890890
`description` varchar(1024) NOT NULL,
891891
`user_id` bigint unsigned NOT NULL,
892892
`account_id` bigint unsigned NOT NULL,
893+
`domain_id` bigint unsigned NOT NULL,
893894
`created` datetime NOT NULL,
894895
`level` varchar(16) NOT NULL,
895896
`start_id` bigint unsigned NOT NULL DEFAULT 0,

setup/db/db/schema-2214to30.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,3 +604,6 @@ CREATE TABLE `cloud`.`op_dc_storage_network_ip_address` (
604604
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
605605

606606
update networks set guru_name='StorageNetworkGuru' where traffic_type='Storage';
607+
608+
ALTER TABLE `cloud`.`event` ADD COLUMN `domain_id` bigint unsigned NOT NULL;
609+
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;

0 commit comments

Comments
 (0)