You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2013/07/12 09:51:28 UTC
[33/50] git commit: updated refs/heads/sdnextensions to bcfb4e6
CLOUDSTACK-1673: AWS Regions - Events - User disable / Domain Delete event does not
include the UUID of the user/domain that was disabled.
- added enity type and enity UUID details to UserContext
- publish the entity type and UUID details for the action events
generated for accout/user/domain
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7f2c6596
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7f2c6596
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7f2c6596
Branch: refs/heads/sdnextensions
Commit: 7f2c659630821b41c84637b5f9cabbb8995db8df
Parents: 5c3013a
Author: Murali Reddy <mu...@gmail.com>
Authored: Thu Jul 11 17:48:07 2013 +0530
Committer: Murali Reddy <mu...@gmail.com>
Committed: Thu Jul 11 18:01:43 2013 +0530
----------------------------------------------------------------------
api/src/com/cloud/user/UserContext.java | 23 +++++++++++++++++
.../src/com/cloud/event/ActionEventUtils.java | 12 +++++++++
.../src/com/cloud/user/AccountManagerImpl.java | 26 +++++++++++++++++++-
.../src/com/cloud/user/DomainManagerImpl.java | 4 ++-
4 files changed, 63 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f2c6596/api/src/com/cloud/user/UserContext.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/user/UserContext.java b/api/src/com/cloud/user/UserContext.java
index bcb33b5..fdd19d4 100644
--- a/api/src/com/cloud/user/UserContext.java
+++ b/api/src/com/cloud/user/UserContext.java
@@ -29,6 +29,8 @@ public class UserContext {
private long accountId;
private String eventDetails;
private boolean apiServer;
+ private Class entityType;
+ private String entityUUID;
@Inject private AccountService _accountMgr = null;
@@ -137,4 +139,25 @@ public class UserContext {
public String getEventDetails() {
return eventDetails;
}
+
+ public void setEntityDetails(Class entityType, String uuid) {
+ this.entityType = entityType;
+ this.entityUUID = uuid;
+ }
+
+ public String getEntityType() {
+ return (entityType != null) ? entityType.getName() : null;
+ }
+
+ public void setEntityType(Class entityType) {
+ this.entityType = entityType;
+ }
+
+ public String getEntityUUID() {
+ return entityUUID;
+ }
+
+ public void setEntityUUID(String entityUUID) {
+ this.entityUUID = entityUUID;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f2c6596/server/src/com/cloud/event/ActionEventUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/ActionEventUtils.java b/server/src/com/cloud/event/ActionEventUtils.java
index eb3efed..906689f 100755
--- a/server/src/com/cloud/event/ActionEventUtils.java
+++ b/server/src/com/cloud/event/ActionEventUtils.java
@@ -24,6 +24,7 @@ import com.cloud.user.AccountVO;
import com.cloud.user.User;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
+import com.cloud.user.UserContext;
import com.cloud.utils.component.ComponentContext;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventBusException;
@@ -152,6 +153,15 @@ public class ActionEventUtils {
return; // no provider is configured to provide events bus, so just return
}
+ // get the entity details for which ActionEvent is generated
+ String entityType = null;
+ String entityUuid = null;
+ UserContext context = UserContext.current();
+ if (context != null) {
+ entityType = context.getEntityType();
+ entityUuid = context.getEntityUUID();
+ }
+
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(
ManagementServer.Name,
eventCategory,
@@ -170,6 +180,8 @@ public class ActionEventUtils {
eventDescription.put("account", account.getUuid());
eventDescription.put("event", eventType);
eventDescription.put("status", state.toString());
+ eventDescription.put("entity", entityType);
+ eventDescription.put("entityuuid", entityUuid);
event.setDescription(eventDescription);
try {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f2c6596/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java
index 6b4bf0e..283e832 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -910,6 +910,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
}
txn.commit();
+ UserContext.current().setEntityDetails(Account.class, account.getUuid());
+
//check success
return _userAccountDao.findById(user.getId());
}
@@ -1070,6 +1072,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
s_logger.error("error updating user", th);
throw new CloudRuntimeException("Unable to update user " + id);
}
+
+ UserContext.current().setEntityDetails(User.class, user.getUuid());
+
return _userAccountDao.findById(id);
}
@@ -1100,6 +1105,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
boolean success = doSetUserStatus(userId, State.disabled);
if (success) {
+
+ UserContext.current().setEntityDetails(User.class, user.getUuid());
+
// user successfully disabled
return _userAccountDao.findById(userId);
} else {
@@ -1146,6 +1154,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
if (success) {
// whenever the user is successfully enabled, reset the login attempts to zero
updateLoginAttempts(userId, 0, false);
+
+ UserContext.current().setEntityDetails(User.class, user.getUuid());
+
return _userAccountDao.findById(userId);
} else {
throw new CloudRuntimeException("Unable to enable user " + userId);
@@ -1207,6 +1218,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
}
if (success) {
+
+ UserContext.current().setEntityDetails(User.class, user.getUuid());
+
return _userAccountDao.findById(userId);
} else {
throw new CloudRuntimeException("Unable to lock user " + userId);
@@ -1252,6 +1266,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
throw new InvalidParameterValueException("The account id=" + accountId + " manages project(s) with ids " + projectIds + "and can't be removed");
}
+
+ UserContext.current().setEntityDetails(Account.class, account.getUuid());
+
return deleteAccount(account, callerUserId, caller);
}
@@ -1281,6 +1298,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
boolean success = enableAccount(account.getId());
if (success) {
+
+ UserContext.current().setEntityDetails(Account.class, account.getUuid());
+
return _accountDao.findById(account.getId());
} else {
throw new CloudRuntimeException("Unable to enable account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
@@ -1310,6 +1330,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
checkAccess(caller, null, true, account);
if (lockAccount(account.getId())) {
+ UserContext.current().setEntityDetails(Account.class, account.getUuid());
return _accountDao.findById(account.getId());
} else {
throw new CloudRuntimeException("Unable to lock account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
@@ -1339,6 +1360,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
checkAccess(caller, null, true, account);
if (disableAccount(account.getId())) {
+ UserContext.current().setEntityDetails(Account.class, account.getUuid());
return _accountDao.findById(account.getId());
} else {
throw new CloudRuntimeException("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
@@ -1421,6 +1443,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
txn.commit();
if (success) {
+ UserContext.current().setEntityDetails(Account.class, account.getUuid());
return _accountDao.findById(account.getId());
} else {
throw new CloudRuntimeException("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
@@ -1451,6 +1474,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
}
checkAccess(UserContext.current().getCaller(), null, true, account);
+ UserContext.current().setEntityDetails(User.class, user.getUuid());
return _userDao.remove(id);
}
@@ -1769,7 +1793,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
userUUID = UUID.randomUUID().toString();
}
UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, firstName, lastName, email, timezone, userUUID));
-
+ UserContext.current().setEntityDetails(User.class, user.getUuid());
return user;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7f2c6596/server/src/com/cloud/user/DomainManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/DomainManagerImpl.java b/server/src/com/cloud/user/DomainManagerImpl.java
index 562a0d8..aad5787 100644
--- a/server/src/com/cloud/user/DomainManagerImpl.java
+++ b/server/src/com/cloud/user/DomainManagerImpl.java
@@ -184,6 +184,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, domainUUID));
_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
txn.commit();
+ UserContext.current().setEntityDetails(Domain.class, domain.getUuid());
return domain;
}
@@ -280,6 +281,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
}
cleanupDomainOfferings(domain.getId());
+ UserContext.current().setEntityDetails(Domain.class, domain.getUuid());
return true;
} catch (Exception ex) {
s_logger.error("Exception deleting domain with id " + domain.getId(), ex);
@@ -604,7 +606,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
}
}
_domainDao.update(domainId, domain);
-
+ UserContext.current().setEntityDetails(Domain.class, domain.getUuid());
txn.commit();
return _domainDao.findById(domainId);