bug 7842: Move events to service layer from http api

This commit is contained in:
kishan 2011-01-14 03:48:09 +05:30
parent f6ffdd2888
commit a2752c6207
8 changed files with 39 additions and 30 deletions

View File

@ -28,4 +28,6 @@ import java.lang.annotation.Target;
@Retention(RUNTIME)
public @interface ActionEvent {
boolean create() default false;
String eventType();
String eventDescription();
}

View File

@ -30,7 +30,8 @@ public class UserContext {
private long userId;
private String sessionId;
private Account account;
private Account account;
private long startEventId = 0;
private boolean apiServer;
@ -101,5 +102,14 @@ public class UserContext {
public static void unregisterContext() {
s_currentContext.set(null);
}
}
public void setStartEventId(long startEventId) {
this.startEventId = startEventId;
}
public long getStartEventId() {
return startEventId;
}
}

View File

@ -933,6 +933,7 @@ public abstract class CitrixResourceBase implements ServerResource {
for (NicTO nic : nics) {
if(nic.getType() == TrafficType.Control){
networkUsage(conn, nic.getIp(), "create", null);
break;
}
}
}

View File

@ -386,12 +386,14 @@ public class ApiServer implements HttpRequestHandler {
params.put("ctxAccountId", String.valueOf(account.getId()));
}
long startEventId = ctx.getStartEventId();
// save the scheduled event
Long eventId = EventUtils.saveScheduledEvent((userId == null) ? User.UID_SYSTEM : userId, asyncCmd.getEntityOwnerId(),
asyncCmd.getEventType(), asyncCmd.getEventDescription());
if (eventId != null) {
params.put("starteventid", eventId.toString());
asyncCmd.getEventType(), asyncCmd.getEventDescription(), startEventId);
if(startEventId == 0){
ctx.setStartEventId(eventId);
}
AsyncJobVO job = new AsyncJobVO();

View File

@ -24,7 +24,6 @@ import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import com.cloud.api.BaseAsyncCmd;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.user.UserContext;
@ -40,28 +39,20 @@ public class ActionEventCallback implements MethodInterceptor, AnnotationInterce
@Override
public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
if(args.length > 0){
if((args[0] != null) && (args[0] instanceof BaseAsyncCmd)){
UserContext ctx = UserContext.current();
Long userID = ctx.getCallerUserId();
userId = (userID == null) ? User.UID_SYSTEM : userID;
BaseAsyncCmd cmd = (BaseAsyncCmd)args[0];
eventType = cmd.getEventType();
accountId = cmd.getEntityOwnerId();
description = cmd.getEventDescription();
Long startEventID = cmd.getStartEventId();
if(startEventID == null){
startEventId = 0;
}
}
}
EventVO event = null;
ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
EventVO event = null;
if (actionEvent != null) {
create = actionEvent.create();
}
if(!create){
event = interceptStart(method);
UserContext ctx = UserContext.current();
Long userID = ctx.getCallerUserId();
userId = (userID == null) ? User.UID_SYSTEM : userID;
eventType = actionEvent.eventType();
description = actionEvent.eventDescription();
startEventId = ctx.getStartEventId();
if(!create){
event = interceptStart(method);
}
}
try {
return methodProxy.invokeSuper(object, args);
@ -114,6 +105,8 @@ public class ActionEventCallback implements MethodInterceptor, AnnotationInterce
if(create){
//This start event has to be used for subsequent events of this action
startEventId = EventUtils.saveCreatedEvent(userId, accountId, EventVO.LEVEL_INFO, eventType, "Successfully created entity for "+description);
UserContext ctx = UserContext.current();
ctx.setStartEventId(startEventId);
} else {
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, eventType, "Successfully completed "+description, startEventId);
}

View File

@ -20,12 +20,13 @@ public class EventUtils {
/*
* Save event after scheduling an async job
*/
public static Long saveScheduledEvent(Long userId, Long accountId, String type, String description) {
public static Long saveScheduledEvent(Long userId, Long accountId, String type, String description, long startEventId) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setType(type);
event.setState(Event.State.Scheduled);
event.setStartId(startEventId);
event.setDescription("Scheduled async job for "+description);
event = _eventDao.persist(event);
return event.getId();

View File

@ -2918,7 +2918,7 @@ public class ManagementServerImpl implements ManagementServer {
}
}
@Override @ActionEvent
@Override
public boolean deleteDomain(DeleteDomainCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
Account account = UserContext.current().getCaller();
Long domainId = cmd.getId();

View File

@ -1570,7 +1570,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
/*Just allocate a volume in the database, don't send the createvolume cmd to hypervisor. The volume will be finally created only when it's attached to a VM.*/
@Override @ActionEvent (create=true)
@Override
public VolumeVO allocVolume(CreateVolumeCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, ResourceAllocationException {
// FIXME: some of the scheduled event stuff might be missing here...
Account account = UserContext.current().getCaller();
@ -1728,7 +1728,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
return volume;
}
@Override @DB @ActionEvent
@Override @DB
public VolumeVO createVolume(CreateVolumeCmd cmd) {
VolumeVO volume = _volsDao.findById(cmd.getEntityId());
// VolumeVO createdVolume = null;