Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions api/src/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.vm.ConsoleProxy;
import com.cloud.vm.Nic;
import com.cloud.vm.NicSecondaryIp;
import com.cloud.vm.SecondaryStorageVm;
import com.cloud.vm.VirtualMachine;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.usage.Usage;
Expand Down Expand Up @@ -557,13 +555,13 @@ public class EventTypes {
entityEventDetails.put(EVENT_ROUTER_HA, VirtualRouter.class);
entityEventDetails.put(EVENT_ROUTER_UPGRADE, VirtualRouter.class);

entityEventDetails.put(EVENT_PROXY_CREATE, ConsoleProxy.class);
entityEventDetails.put(EVENT_PROXY_DESTROY, ConsoleProxy.class);
entityEventDetails.put(EVENT_PROXY_START, ConsoleProxy.class);
entityEventDetails.put(EVENT_PROXY_STOP, ConsoleProxy.class);
entityEventDetails.put(EVENT_PROXY_REBOOT, ConsoleProxy.class);
entityEventDetails.put(EVENT_ROUTER_HA, ConsoleProxy.class);
entityEventDetails.put(EVENT_PROXY_HA, ConsoleProxy.class);
entityEventDetails.put(EVENT_PROXY_CREATE, VirtualMachine.class);
entityEventDetails.put(EVENT_PROXY_DESTROY, VirtualMachine.class);
entityEventDetails.put(EVENT_PROXY_START, VirtualMachine.class);
entityEventDetails.put(EVENT_PROXY_STOP, VirtualMachine.class);
entityEventDetails.put(EVENT_PROXY_REBOOT, VirtualMachine.class);
entityEventDetails.put(EVENT_ROUTER_HA, VirtualMachine.class);
entityEventDetails.put(EVENT_PROXY_HA, VirtualMachine.class);

entityEventDetails.put(EVENT_VNC_CONNECT, "VNC");
entityEventDetails.put(EVENT_VNC_DISCONNECT, "VNC");
Expand Down Expand Up @@ -668,12 +666,12 @@ public class EventTypes {
entityEventDetails.put(EVENT_ISO_UPLOAD, "Iso");

// SSVM
entityEventDetails.put(EVENT_SSVM_CREATE, SecondaryStorageVm.class);
entityEventDetails.put(EVENT_SSVM_DESTROY, SecondaryStorageVm.class);
entityEventDetails.put(EVENT_SSVM_START, SecondaryStorageVm.class);
entityEventDetails.put(EVENT_SSVM_STOP, SecondaryStorageVm.class);
entityEventDetails.put(EVENT_SSVM_REBOOT, SecondaryStorageVm.class);
entityEventDetails.put(EVENT_SSVM_HA, SecondaryStorageVm.class);
entityEventDetails.put(EVENT_SSVM_CREATE, VirtualMachine.class);
entityEventDetails.put(EVENT_SSVM_DESTROY, VirtualMachine.class);
entityEventDetails.put(EVENT_SSVM_START, VirtualMachine.class);
entityEventDetails.put(EVENT_SSVM_STOP, VirtualMachine.class);
entityEventDetails.put(EVENT_SSVM_REBOOT, VirtualMachine.class);
entityEventDetails.put(EVENT_SSVM_HA, VirtualMachine.class);

// Service Offerings
entityEventDetails.put(EVENT_SERVICE_OFFERING_CREATE, ServiceOffering.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ public void execute() {
public ApiCommandJobType getInstanceType() {
return ApiCommandJobType.Account;
}

@Override
public Long getInstanceId() {
return id;
}
}
10 changes: 10 additions & 0 deletions api/src/org/apache/cloudstack/context/CallContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Stack;
import java.util.UUID;

import com.cloud.projects.Project;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;

Expand Down Expand Up @@ -59,6 +60,7 @@ protected Stack<CallContext> initialValue() {
private User user;
private long userId;
private final Map<Object, Object> context = new HashMap<Object, Object>();
private Project project;

static EntityManager s_entityMgr;

Expand Down Expand Up @@ -314,6 +316,14 @@ public void setEventDescription(String eventDescription) {
this.eventDescription = eventDescription;
}

public Project getProject() {
return this.project;
}

public void setProject(Project project) {
this.project = project;
}

/**
* Whether to display the event to the end user.
* @return true - if the event is to be displayed to the end user, false otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,7 @@ public Network doInTransaction(TransactionStatus status) {
});

CallContext.current().setEventDetails("Network Id: " + network.getId());
CallContext.current().putContextParameter(Network.class, network.getUuid());
return network;
}

Expand Down
9 changes: 9 additions & 0 deletions server/src/com/cloud/api/ApiDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import javax.annotation.PostConstruct;
import javax.inject.Inject;

import com.cloud.projects.Project;
import com.cloud.utils.db.EntityManager;
import org.apache.log4j.Logger;

import org.apache.cloudstack.acl.ControlledEntity;
Expand Down Expand Up @@ -54,6 +56,9 @@ public class ApiDispatcher {
@Inject
AccountManager _accountMgr;

@Inject
EntityManager _entityMgr;

@Inject()
protected DispatchChainFactory dispatchChainFactory;

Expand Down Expand Up @@ -102,6 +107,10 @@ public void dispatch(final BaseCmd cmd, final Map<String, String> params, final

final CallContext ctx = CallContext.current();
ctx.setEventDisplayEnabled(cmd.isDisplay());
if(params.get(ApiConstants.PROJECT_ID) != null) {
Project project = _entityMgr.findByUuidIncludingRemoved(Project.class, params.get(ApiConstants.PROJECT_ID));
ctx.setProject(project);
}

// TODO This if shouldn't be here. Use polymorphism and move it to validateSpecificParameters
if (cmd instanceof BaseAsyncCmd) {
Expand Down
15 changes: 7 additions & 8 deletions server/src/com/cloud/api/ApiServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,19 @@ private void handleAsyncJobPublishEvent(String subject, String senderAddress, Ob
}
}
// For some reason, the instanceType / instanceId are not abstract, which means we may get null values.
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(
"management-server",
EventCategory.ASYNC_JOB_CHANGE_EVENT.getName(),
jobEvent,
(job.getInstanceType() != null ? job.getInstanceType().toString() : "unknown"), null);
String instanceType = job.getInstanceType() != null ? job.getInstanceType() : "unknown";
String instanceUuid = job.getInstanceId() != null ? ApiDBUtils.findJobInstanceUuid(job) : "";
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event("management-server", EventCategory.ASYNC_JOB_CHANGE_EVENT.getName(),
jobEvent, instanceType, instanceUuid);

Map<String, String> eventDescription = new HashMap<String, String>();
eventDescription.put("command", job.getCmd());
eventDescription.put("user", userJobOwner.getUuid());
eventDescription.put("account", jobOwner.getUuid());
eventDescription.put("processStatus", "" + job.getProcessStatus());
eventDescription.put("resultCode", "" + job.getResultCode());
eventDescription.put("instanceUuid", (job.getInstanceId() != null ? ApiDBUtils.findJobInstanceUuid(job) : "" ) );
eventDescription.put("instanceType", (job.getInstanceType() != null ? job.getInstanceType().toString() : "unknown"));
eventDescription.put("instanceUuid", instanceUuid);
eventDescription.put("instanceType", instanceType);
eventDescription.put("commandEventType", cmdEventType);
eventDescription.put("jobId", job.getUuid());
eventDescription.put("jobResult", job.getResult());
Expand Down Expand Up @@ -638,7 +637,7 @@ private String queueCommand(final BaseCmd cmdObj, final Map<String, String> para
params.put("id", objectId.toString());
Class entityClass = EventTypes.getEntityClassForEvent(createCmd.getEventType());
if (entityClass != null)
ctx.putContextParameter(entityClass.getName(), objectUuid);
ctx.putContextParameter(entityClass, objectUuid);
} else {
// Extract the uuid before params are processed and id reflects internal db id
objectUuid = params.get(ApiConstants.ID);
Expand Down
4 changes: 2 additions & 2 deletions server/src/com/cloud/api/dispatch/ParamProcessWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private Long translateUuidToInternalId(final String uuid, final Parameter annota
if (internalId != null){
// Populate CallContext for each of the entity.
for (final Class<?> entity : entities) {
CallContext.current().putContextParameter(entity.getName(), internalId);
CallContext.current().putContextParameter(entity, internalId);
}
return internalId;
}
Expand All @@ -434,7 +434,7 @@ private Long translateUuidToInternalId(final String uuid, final Parameter annota
}
// Return on first non-null Id for the uuid entity
if (internalId != null){
CallContext.current().putContextParameter(entity.getName(), uuid);
CallContext.current().putContextParameter(entity, uuid);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/com/cloud/event/ActionEventInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void interceptComplete(Method method, Object target, Object event) {
for (ActionEvent actionEvent : getActionEvents(method)) {
CallContext ctx = CallContext.current();
long userId = ctx.getCallingUserId();
long accountId = ctx.getCallingAccountId();
long accountId = ctx.getProject() != null ? ctx.getProject().getProjectAccountId() : ctx.getCallingAccountId(); //This should be the entity owner id rather than the Calling User Account Id.
long startEventId = ctx.getStartEventId();
String eventDescription = getEventDescription(actionEvent, ctx);
String eventType = getEventType(actionEvent, ctx);
Expand Down
40 changes: 8 additions & 32 deletions server/src/com/cloud/event/ActionEventUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.cloudstack.framework.events.EventBusException;

import com.cloud.configuration.Config;
import com.cloud.domain.Domain;
import com.cloud.event.dao.EventDao;
import com.cloud.server.ManagementService;
import com.cloud.user.Account;
Expand Down Expand Up @@ -121,7 +120,7 @@ public static void startNestedActionEvent(String eventType, String eventDescript
public static void onStartedActionEventFromContext(String eventType, String eventDescription, boolean eventDisplayEnabled) {
CallContext ctx = CallContext.current();
long userId = ctx.getCallingUserId();
long accountId = ctx.getCallingAccountId();
long accountId = ctx.getProject() != null ? ctx.getProject().getProjectAccountId() : ctx.getCallingAccountId(); //This should be the entity owner id rather than the Calling User Account Id.
long startEventId = ctx.getStartEventId();

if (!eventType.equals(""))
Expand Down Expand Up @@ -204,20 +203,15 @@ private static void publishOnEventBus(long userId, long accountId, String eventC
String entityType = null;
String entityUuid = null;
CallContext context = CallContext.current();
Class<?> entityKey = getEntityKey(eventType);
if (entityKey != null){
//FIXME - Remove this since it should be covered by the else if condition below.
entityUuid = (String)context.getContextParameter(entityKey);
if (entityUuid != null)
entityType = entityKey.getName();
}else if (EventTypes.getEntityClassForEvent(eventType) != null){
//Get entity Class(Example - VirtualMachine.class) from the event Type eg. - VM.CREATE
Class<?> entityClass = EventTypes.getEntityClassForEvent(eventType);

//Get entity Class(Example - VirtualMachine.class) from the event Type eg. - VM.CREATE
Class<?> entityClass = EventTypes.getEntityClassForEvent(eventType);
if (entityClass != null){
//Get uuid from id
if(context.getContextParameter(entityClass.getName()) != null){
Object param = context.getContextParameter(entityClass);
if(param != null){
try {
entityUuid = getEntityUuid(entityClass, context.getContextParameter(entityClass.getName()));
entityUuid = getEntityUuid(entityClass, param);
entityType = entityClass.getName();
} catch (Exception e){
s_logger.debug("Caught exception while finding entityUUID, moving on");
}
Expand Down Expand Up @@ -312,22 +306,4 @@ private static void populateFirstClassEntities(Map<String, String> eventDescript

}

private static Class<?> getEntityKey(String eventType)
{
// FIXME - Remove this
if (eventType.startsWith("DOMAIN."))
{
return Domain.class;
}
else if (eventType.startsWith("ACCOUNT."))
{
return Account.class;
}
else if (eventType.startsWith("USER."))
{
return User.class;
}

return null;
}
}
1 change: 1 addition & 0 deletions server/src/com/cloud/projects/ProjectManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public Project doInTransaction(TransactionStatus status) {

if (project != null) {
CallContext.current().setEventDetails("Project id=" + project.getId());
CallContext.current().putContextParameter(Project.class, project.getUuid());
}

//Increment resource count
Expand Down
1 change: 0 additions & 1 deletion server/src/com/cloud/server/ManagementServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3250,7 +3250,6 @@ public VMInstanceVO stopSystemVM(final StopSystemVmCmd cmd) throws ResourceUnava
}

@Override
@ActionEvent(eventType = EventTypes.EVENT_PROXY_REBOOT, eventDescription = "", async = true)
public VMInstanceVO rebootSystemVM(final RebootSystemVmCmd cmd) {
final VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(cmd.getId(), VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ public SnapshotPolicyVO createPolicy(CreateSnapshotPolicyCmd cmd, Account policy

}
// TODO - Make createSnapshotPolicy - BaseAsyncCreate and remove this.
CallContext.current().putContextParameter(SnapshotPolicy.class.getName(), policy.getUuid());
CallContext.current().putContextParameter(SnapshotPolicy.class, policy.getUuid());
return policy;
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ public UserVm addNicToVirtualMachine(AddNicToVMCmd cmd) throws InvalidParameterV
if (guestNic == null) {
throw new CloudRuntimeException("Unable to add NIC to " + vmInstance);
}
CallContext.current().putContextParameter(Nic.class.getName(), guestNic.getUuid());
CallContext.current().putContextParameter(Nic.class, guestNic.getUuid());
s_logger.debug("Successful addition of " + network + " from " + vmInstance);
return _vmDao.findById(vmInstance.getId());
}
Expand Down