Skip to content

Commit a9fd67c

Browse files
author
kishan
committed
bug 8362: Included VmId in event description
status 8362: resolved fixed
1 parent ee1c53e commit a9fd67c

4 files changed

Lines changed: 30 additions & 7 deletions

File tree

api/src/com/cloud/api/commands/DeployVMCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public String getCreateEventDescription() {
215215

216216
@Override
217217
public String getEventDescription() {
218-
return "starting Vm";
218+
return "starting Vm. Vm Id: "+getEntityId();
219219
}
220220

221221
@Override
@@ -227,6 +227,7 @@ public AsyncJob.Type getInstanceType() {
227227
public void execute(){
228228
UserVm result;
229229
try {
230+
UserContext.current().setEventDetails("Vm Id: "+getEntityId());
230231
result = _userVmService.startVirtualMachine(this);
231232
if (result != null) {
232233
UserVmResponse response = _responseGenerator.createUserVmResponse(result);

api/src/com/cloud/user/UserContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class UserContext {
3232
private Account account;
3333
private long startEventId = 0;
3434
private long accountId;
35+
private String eventDetails;
3536

3637
private boolean apiServer;
3738

@@ -126,4 +127,12 @@ public long getAccountId() {
126127
public void setAccountId(long accountId) {
127128
this.accountId = accountId;
128129
}
130+
131+
public void setEventDetails(String eventDetails) {
132+
this.eventDetails = eventDetails;
133+
}
134+
135+
public String getEventDetails() {
136+
return eventDetails;
137+
}
129138
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ public EventVO interceptStart(AnnotatedElement element) {
6666
long userId = ctx.getCallerUserId();
6767
long accountId = ctx.getAccountId();
6868
long startEventId = ctx.getStartEventId();
69-
EventUtils.saveStartedEvent(userId, accountId, actionEvent.eventType(), actionEvent.eventDescription(), startEventId);
69+
String eventDescription = actionEvent.eventDescription();
70+
if(ctx.getEventDetails() != null){
71+
eventDescription += ". "+ctx.getEventDetails();
72+
}
73+
EventUtils.saveStartedEvent(userId, accountId, actionEvent.eventType(), eventDescription, startEventId);
7074
}
7175
}
7276
return event;
@@ -81,12 +85,16 @@ public void interceptComplete(AnnotatedElement element, EventVO event) {
8185
long userId = ctx.getCallerUserId();
8286
long accountId = ctx.getAccountId();
8387
long startEventId = ctx.getStartEventId();
88+
String eventDescription = actionEvent.eventDescription();
89+
if(ctx.getEventDetails() != null){
90+
eventDescription += ". "+ctx.getEventDetails();
91+
}
8492
if(actionEvent.create()){
8593
//This start event has to be used for subsequent events of this action
86-
startEventId = EventUtils.saveCreatedEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully created entity for "+actionEvent.eventDescription());
94+
startEventId = EventUtils.saveCreatedEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully created entity for "+eventDescription);
8795
ctx.setStartEventId(startEventId);
8896
} else {
89-
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully completed "+actionEvent.eventDescription(), startEventId);
97+
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully completed "+eventDescription, startEventId);
9098
}
9199
}
92100
}
@@ -100,11 +108,15 @@ public void interceptException(AnnotatedElement element, EventVO event) {
100108
long userId = ctx.getCallerUserId();
101109
long accountId = ctx.getAccountId();
102110
long startEventId = ctx.getStartEventId();
111+
String eventDescription = actionEvent.eventDescription();
112+
if(ctx.getEventDetails() != null){
113+
eventDescription += ". "+ctx.getEventDetails();
114+
}
103115
if(actionEvent.create()){
104-
long eventId = EventUtils.saveCreatedEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while creating entity for "+actionEvent.eventDescription());
116+
long eventId = EventUtils.saveCreatedEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while creating entity for "+eventDescription);
105117
ctx.setStartEventId(eventId);
106118
} else {
107-
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while "+actionEvent.eventDescription(), startEventId);
119+
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while "+eventDescription, startEventId);
108120
}
109121
}
110122
}

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ private boolean validPassword(String password) {
18781878
return true;
18791879
}
18801880

1881-
@Override @DB @ActionEvent (eventType=EventTypes.EVENT_VM_CREATE, eventDescription="creating Vm", create=true)
1881+
@Override @DB @ActionEvent (eventType=EventTypes.EVENT_VM_CREATE, eventDescription="deploying Vm", create=true)
18821882
public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, ResourceAllocationException {
18831883
Account caller = UserContext.current().getCaller();
18841884

@@ -2119,6 +2119,7 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
21192119
if (s_logger.isDebugEnabled()) {
21202120
s_logger.debug("Successfully allocated DB entry for " + vm);
21212121
}
2122+
UserContext.current().setEventDetails("Vm Id: "+vm.getId());
21222123
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE, accountId, dc.getId(), vm.getId(), vm.getName(), offering.getId(), template.getId(), null);
21232124
_usageEventDao.persist(usageEvent);
21242125

0 commit comments

Comments
 (0)