bug 5360: Adding scheduled and started events for USER.DELETE.

status 5360: resolved fixed
This commit is contained in:
nit 2010-09-27 20:39:05 +05:30
parent 6c683e733a
commit 27a32380f2
3 changed files with 42 additions and 5 deletions

View File

@ -25,8 +25,10 @@ import com.cloud.async.AsyncJobManager;
import com.cloud.async.AsyncJobResult;
import com.cloud.async.AsyncJobVO;
import com.cloud.async.BaseAsyncJobExecutor;
import com.cloud.event.EventTypes;
import com.cloud.serializer.GsonHelper;
import com.cloud.server.ManagementServer;
import com.cloud.user.User;
import com.google.gson.Gson;
public class DeleteUserExecutor extends BaseAsyncJobExecutor {
@ -37,10 +39,15 @@ public class DeleteUserExecutor extends BaseAsyncJobExecutor {
AsyncJobManager asyncMgr = getAsyncJobMgr();
AsyncJobVO job = getJob();
ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer();
Long param = gson.fromJson(job.getCmdInfo(), Long.class);
DeleteUserParam param = gson.fromJson(job.getCmdInfo(), DeleteUserParam.class);
try {
if(managementServer.deleteUser(param.longValue())) {
try {
User user = managementServer.getUser(param.getUserId(), true);
String description = "Starting deleting User " + user.getUsername() + " (id: " + param.getUserId()
+ ") for accountId = " + user.getAccountId();
managementServer.saveStartedEvent(1L, 1L, EventTypes.EVENT_USER_DELETE, description, param.getEventId());
if(managementServer.deleteUser(param.getUserId())) {
asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_SUCCEEDED, 0,
"success");
} else {
@ -48,7 +55,7 @@ public class DeleteUserExecutor extends BaseAsyncJobExecutor {
"operation failed");
}
} catch(Exception e) {
s_logger.warn("Unable to delete User " + param.longValue() + ": " + e.getMessage(), e);
s_logger.warn("Unable to delete User " + param.getUserId() + ": " + e.getMessage(), e);
asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR,
e.getMessage());
}

View File

@ -0,0 +1,25 @@
package com.cloud.async.executor;
public class DeleteUserParam {
private Long userId;
private Long eventId;
public DeleteUserParam() {}
public DeleteUserParam(Long userId, Long eventId) {
this.userId = userId;
this.eventId = eventId;
}
public Long getUserId() {
return userId;
}
public Long getEventId() {
return eventId;
}
}

View File

@ -97,6 +97,7 @@ import com.cloud.async.executor.CreatePrivateTemplateParam;
import com.cloud.async.executor.DeleteDomainParam;
import com.cloud.async.executor.DeleteRuleParam;
import com.cloud.async.executor.DeleteTemplateParam;
import com.cloud.async.executor.DeleteUserParam;
import com.cloud.async.executor.DeployVMParam;
import com.cloud.async.executor.DisassociateIpAddressParam;
import com.cloud.async.executor.ExtractJobResultObject;
@ -903,7 +904,11 @@ public class ManagementServerImpl implements ManagementServer {
@Override
public long deleteUserAsync(long userId) {
Long param = new Long(userId);
User user = getUser(userId, true);
String description = "User " + user.getUsername() + " (id: " + userId
+ ") and accountId = " + user.getAccountId();
long eventId = saveScheduledEvent(1L, 1L, EventTypes.EVENT_USER_DELETE, description);
DeleteUserParam param = new DeleteUserParam(userId, eventId);
Gson gson = GsonHelper.getBuilder().create();
AsyncJobVO job = new AsyncJobVO();