diff --git a/api/src/com/cloud/api/BaseAsyncCmd.java b/api/src/com/cloud/api/BaseAsyncCmd.java index 69a18f3ce39..93ddfdcb5f6 100644 --- a/api/src/com/cloud/api/BaseAsyncCmd.java +++ b/api/src/com/cloud/api/BaseAsyncCmd.java @@ -19,6 +19,8 @@ package com.cloud.api; import com.cloud.api.response.AsyncJobResponse; import com.cloud.async.AsyncJob; +import com.cloud.user.User; +import com.cloud.user.UserContext; /** * A base command for supporting asynchronous API calls. When an API command is received, the command will be @@ -92,4 +94,34 @@ public abstract class BaseAsyncCmd extends BaseCmd { public AsyncJob.Type getInstanceType() { return AsyncJob.Type.None; } + + protected long saveStartedEvent(){ + return saveStartedEvent(getEventType(), "Executing job for "+getEventDescription(), getStartEventId()); + } + + protected long saveStartedEvent(String eventType, String description, Long startEventId){ + UserContext ctx = UserContext.current(); + Long userId = ctx.getUserId(); + userId = (userId == null) ? User.UID_SYSTEM : userId; + Long startEvent = startEventId; + if(startEvent == null){ + startEvent = 0L; + } + return _mgr.saveStartedEvent((userId == null) ? User.UID_SYSTEM : userId, getEntityOwnerId(), eventType, description, startEvent); + } + + protected long saveCompletedEvent(String level, String description){ + return saveCompletedEvent(level, getEventType(), description, getStartEventId()); + } + + protected long saveCompletedEvent(String level, String eventType, String description, Long startEventId){ + UserContext ctx = UserContext.current(); + Long userId = ctx.getUserId(); + userId = (userId == null) ? User.UID_SYSTEM : userId; + Long startEvent = startEventId; + if(startEvent == null){ + startEvent = 0L; + } + return _mgr.saveCompletedEvent((userId == null) ? User.UID_SYSTEM : userId, getEntityOwnerId(), level, eventType, description, startEvent); + } } diff --git a/api/src/com/cloud/api/BaseAsyncCreateCmd.java b/api/src/com/cloud/api/BaseAsyncCreateCmd.java index 93a0c2ef9c5..1194a6093df 100644 --- a/api/src/com/cloud/api/BaseAsyncCreateCmd.java +++ b/api/src/com/cloud/api/BaseAsyncCreateCmd.java @@ -23,4 +23,12 @@ public abstract class BaseAsyncCreateCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); return _responseGenerator.toSerializedString(response, getResponseType()); } + + public String getCreateEventType() { + return null; + } + + public String getCreateEventDescription() { + return null; + } } diff --git a/api/src/com/cloud/api/commands/DeleteIpForwardingRuleCmd.java b/api/src/com/cloud/api/commands/DeleteIpForwardingRuleCmd.java index 901d584791d..6822b8363ce 100644 --- a/api/src/com/cloud/api/commands/DeleteIpForwardingRuleCmd.java +++ b/api/src/com/cloud/api/commands/DeleteIpForwardingRuleCmd.java @@ -79,7 +79,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_NET_RULE_ADD; + return EventTypes.EVENT_NET_RULE_DELETE; } @Override diff --git a/api/src/com/cloud/api/commands/DeployVMCmd.java b/api/src/com/cloud/api/commands/DeployVMCmd.java index e96a92be249..bb9c6bfe563 100644 --- a/api/src/com/cloud/api/commands/DeployVMCmd.java +++ b/api/src/com/cloud/api/commands/DeployVMCmd.java @@ -205,12 +205,22 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { @Override public String getEventType() { - return EventTypes.EVENT_VM_CREATE; + return EventTypes.EVENT_VM_START; } + @Override + public String getCreateEventType() { + return EventTypes.EVENT_VM_CREATE; + } + + @Override + public String getCreateEventDescription() { + return "creating Vm"; + } + @Override public String getEventDescription() { - return "deploying Vm"; + return "starting Vm"; } @Override @@ -264,4 +274,5 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage()); } } + } diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index 16b55ae0fd3..6715ca2d2a4 100644 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -417,5 +417,9 @@ public interface ManagementService { * @throws IllegalArgumentException */ boolean unregisterPreallocatedLun(DeletePreallocatedLunCmd cmd) throws IllegalArgumentException; + + public Long saveStartedEvent(Long userId, Long accountId, String type, String description, long startEventId); + + public Long saveCompletedEvent(Long userId, Long accountId, String level, String type, String description, long startEventId); } diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index b18558b194f..5329bd9314e 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -29,6 +29,7 @@ import org.apache.log4j.Logger; import com.cloud.api.BaseCmd.CommandType; import com.cloud.async.AsyncCommandQueued; +import com.cloud.event.EventVO; import com.cloud.exception.AccountLimitException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; @@ -62,78 +63,127 @@ public class ApiDispatcher { } public void dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map params) { + + boolean created = false; + String errorMsg = ""; + long startId = 0; + + if(cmd.getCreateEventType() != null){ + startId = cmd.saveStartedEvent(cmd.getCreateEventType(), cmd.getCreateEventDescription(), 0L); + } + setupParameters(cmd, params); try { cmd.create(); + created = true; } catch (Throwable t) { if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { s_logger.info(t.getMessage()); + errorMsg = "Parameter error"; throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); }else if (t instanceof PermissionDeniedException) { s_logger.info("PermissionDenied: " + t.getMessage()); + errorMsg = "Permission denied"; throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage()); }else if (t instanceof AccountLimitException) { s_logger.info(t.getMessage()); + errorMsg = "Account resource limit error"; throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage()); }else if (t instanceof InsufficientCapacityException) { s_logger.info(t.getMessage()); + errorMsg = "Insufficient capacity"; throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage()); }else if (t instanceof ResourceAllocationException) { s_logger.info(t.getMessage()); + errorMsg = "Resource allocation error"; throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage()); }else if (t instanceof ResourceUnavailableException) { s_logger.warn("Exception: ", t); + errorMsg = "Resource unavailable error"; throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage()); }else if (t instanceof ServerApiException) { s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription()); + errorMsg = ((ServerApiException) t).getDescription(); throw new ServerApiException(((ServerApiException) t).getErrorCode(), ((ServerApiException) t).getDescription()); }else if (t instanceof AsyncCommandQueued) { throw (AsyncCommandQueued)t; }else { + errorMsg = "Internal error"; + s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t); + if (UserContext.current().getAccount() == null || UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage()); + else + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE); + } + } finally { + if(cmd.getCreateEventType() != null){ + if (created){ + cmd.saveCompletedEvent(EventVO.LEVEL_INFO, cmd.getCreateEventType(), cmd.getCreateEventDescription()+" successfull. Id: "+cmd.getEntityId(), startId); + } else { + cmd.saveCompletedEvent(EventVO.LEVEL_ERROR, cmd.getCreateEventType(), cmd.getCreateEventDescription()+" failed. "+errorMsg, startId); + } + } + } + } + + public void dispatch(BaseCmd cmd, Map params) { + boolean success = false; + String errorMsg = ""; + setupParameters(cmd, params); + try { + if(cmd instanceof BaseAsyncCmd){ + ((BaseAsyncCmd)cmd).saveStartedEvent(); + } + cmd.execute(); + success = true; + } catch (Throwable t) { + if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { + s_logger.info(t.getMessage()); + errorMsg = "Parameter error"; + throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); + }else if (t instanceof PermissionDeniedException) { + s_logger.info("PermissionDenied: " + t.getMessage()); + errorMsg = "Permission denied"; + throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage()); + }else if (t instanceof AccountLimitException) { + s_logger.info(t.getMessage()); + errorMsg = "Account resource limit error"; + throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage()); + }else if (t instanceof InsufficientCapacityException) { + s_logger.info(t.getMessage()); + errorMsg = "Insufficient capacity"; + throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage()); + }else if (t instanceof ResourceAllocationException) { + s_logger.warn("Exception: ", t); + errorMsg = "Resource allocation error"; + throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage()); + }else if (t instanceof ResourceUnavailableException) { + s_logger.warn("Exception: ", t); + errorMsg = "Resource unavailable error"; + throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage()); + }else if (t instanceof ServerApiException) { + errorMsg = ((ServerApiException) t).getDescription(); + s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription()); + throw new ServerApiException(((ServerApiException) t).getErrorCode(), ((ServerApiException) t).getDescription()); + } else if (t instanceof AsyncCommandQueued) { + throw (AsyncCommandQueued)t; + }else { + errorMsg = "Internal error"; s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t); if (UserContext.current().getAccount() == null || UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage()); else throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE); } - } - } - - public void dispatch(BaseCmd cmd, Map params) { - setupParameters(cmd, params); - try { - cmd.execute(); - } catch (Throwable t) { - if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { - s_logger.info(t.getMessage()); - throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); - }else if (t instanceof PermissionDeniedException) { - s_logger.info("PermissionDenied: " + t.getMessage()); - throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage()); - }else if (t instanceof AccountLimitException) { - s_logger.info(t.getMessage()); - throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage()); - }else if (t instanceof InsufficientCapacityException) { - s_logger.info(t.getMessage()); - throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage()); - }else if (t instanceof ResourceAllocationException) { - s_logger.warn("Exception: ", t); - throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage()); - }else if (t instanceof ResourceUnavailableException) { - s_logger.warn("Exception: ", t); - throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage()); - }else if (t instanceof ServerApiException) { - s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription()); - throw new ServerApiException(((ServerApiException) t).getErrorCode(), ((ServerApiException) t).getDescription()); - } else if (t instanceof AsyncCommandQueued) { - throw (AsyncCommandQueued)t; - }else { - s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t); - if (UserContext.current().getAccount() == null || UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage()); - else - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE); + } finally { + if(cmd instanceof BaseAsyncCmd){ + BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmd; + if(success){ + asyncCmd.saveCompletedEvent(EventVO.LEVEL_INFO, asyncCmd.getEventDescription()+" completed successfully"); + } else { + asyncCmd.saveCompletedEvent(EventVO.LEVEL_ERROR, asyncCmd.getEventDescription()+" failed. "+errorMsg); + } } } } diff --git a/server/src/com/cloud/async/executor/CopyTemplateExecutor.java b/server/src/com/cloud/async/executor/CopyTemplateExecutor.java index fa46b50b461..2364e5df66b 100644 --- a/server/src/com/cloud/async/executor/CopyTemplateExecutor.java +++ b/server/src/com/cloud/async/executor/CopyTemplateExecutor.java @@ -49,7 +49,7 @@ public class CopyTemplateExecutor extends BaseAsyncJobExecutor { ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer(); try { - boolean success = managementServer.copyTemplate(param.getUserId(), param.getTemplateId(), param.getSourceZoneId(), param.getDestZoneId(), param.getEventId()); + boolean success = managementServer.copyTemplate(param.getUserId(), param.getTemplateId(), param.getSourceZoneId(), param.getDestZoneId()); if (success) { VMTemplateVO template = managementServer.findTemplateById(param.getTemplateId()); diff --git a/server/src/com/cloud/async/executor/RebootVMExecutor.java b/server/src/com/cloud/async/executor/RebootVMExecutor.java index 1c81cedb445..0051893dd7c 100644 --- a/server/src/com/cloud/async/executor/RebootVMExecutor.java +++ b/server/src/com/cloud/async/executor/RebootVMExecutor.java @@ -25,9 +25,6 @@ import com.cloud.api.BaseCmd; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobResult; import com.cloud.async.AsyncJobVO; -import com.cloud.event.EventTypes; -import com.cloud.event.EventUtils; -import com.cloud.event.EventVO; import com.cloud.serializer.GsonHelper; import com.cloud.server.ManagementServer; import com.cloud.vm.UserVmVO; @@ -75,10 +72,7 @@ public class RebootVMExecutor extends VMOperationExecutor { public void processAnswer(VMOperationListener listener, long agentId, long seq, Answer answer) { UserVmVO vm = listener.getVm(); - VMOperationParam param = listener.getParam(); AsyncJobManager asyncMgr = getAsyncJobMgr(); - ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer(); - String params = "id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId(); boolean jobStatusUpdated = false; try { @@ -89,16 +83,11 @@ public class RebootVMExecutor extends VMOperationExecutor { asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_SUCCEEDED, 0, VMExecutorHelper.composeResultObject(asyncMgr.getExecutorContext().getManagementServer(), vm, null)); jobStatusUpdated = true; - EventUtils.saveEvent(param.getUserId(), param.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_REBOOT, - "Successfully rebooted VM instance : " + vm.getName(), params, param.getEventId()); } else { asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR, "Agent is unable to execute the command"); jobStatusUpdated = true; - EventUtils.saveEvent(param.getUserId(), param.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_REBOOT, - "Failed to reboot VM instance : " + vm.getName(), params, param.getEventId()); - } } catch(Exception e) { @@ -134,24 +123,13 @@ public class RebootVMExecutor extends VMOperationExecutor { private void processDisconnectAndTimeout(VMOperationListener listener, String resultMessage) { - UserVmVO vm = listener.getVm(); - VMOperationParam param = listener.getParam(); AsyncJobManager asyncMgr = getAsyncJobMgr(); - EventVO event = new EventVO(); - event.setUserId(param.getUserId()); - event.setAccountId(vm.getAccountId()); - event.setType(EventTypes.EVENT_VM_REBOOT); - event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId()); - event.setDescription("failed to reboot VM instance : " + vm.getName() + " due to " + resultMessage); - event.setLevel(EventVO.LEVEL_ERROR); - boolean jobStatusUpdated = false; try { asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, 0, resultMessage); jobStatusUpdated = true; - asyncMgr.getExecutorContext().getEventDao().persist(event); } catch (Exception e) { s_logger.error("Unexpected exception " + e.getMessage(), e); if(!jobStatusUpdated) diff --git a/server/src/com/cloud/async/executor/StartConsoleProxyExecutor.java b/server/src/com/cloud/async/executor/StartConsoleProxyExecutor.java index b2c3d3d45a9..740f34ee6e6 100644 --- a/server/src/com/cloud/async/executor/StartConsoleProxyExecutor.java +++ b/server/src/com/cloud/async/executor/StartConsoleProxyExecutor.java @@ -45,7 +45,7 @@ public class StartConsoleProxyExecutor extends VMOperationExecutor { return true; } else { try { - ConsoleProxyVO proxy = managementServer.startConsoleProxy(param.getVmId(), param.getEventId()); + ConsoleProxyVO proxy = managementServer.startConsoleProxy(param.getVmId()); if(proxy != null) asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_SUCCEEDED, 0, ConsoleProxyExecutorHelper.composeResultObject(managementServer, proxy)); diff --git a/server/src/com/cloud/async/executor/StopVMExecutor.java b/server/src/com/cloud/async/executor/StopVMExecutor.java index 8453105e463..f4acbf41816 100644 --- a/server/src/com/cloud/async/executor/StopVMExecutor.java +++ b/server/src/com/cloud/async/executor/StopVMExecutor.java @@ -25,9 +25,6 @@ import com.cloud.api.BaseCmd; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobResult; import com.cloud.async.AsyncJobVO; -import com.cloud.event.EventTypes; -import com.cloud.event.EventUtils; -import com.cloud.event.EventVO; import com.cloud.serializer.GsonHelper; import com.cloud.server.ManagementServer; import com.cloud.vm.UserVmVO; @@ -74,8 +71,6 @@ public class StopVMExecutor extends VMOperationExecutor { UserVmVO vm = listener.getVm(); VMOperationParam param = listener.getParam(); AsyncJobManager asyncMgr = getAsyncJobMgr(); - ManagementServer managementServer = asyncMgr.getExecutorContext().getManagementServer(); - String params = "id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId(); if(s_logger.isDebugEnabled()) s_logger.debug("Execute asynchronize stop VM command: received answer, " + vm.getHostId() + "-" + seq); @@ -87,7 +82,7 @@ public class StopVMExecutor extends VMOperationExecutor { try { if(stopped) { // completeStopCommand will log the event, if we log it here we will end up with duplicated stop event - asyncMgr.getExecutorContext().getVmMgr().completeStopCommand(param.getUserId(), vm, Event.OperationSucceeded, param.getEventId()); + asyncMgr.getExecutorContext().getVmMgr().completeStopCommand(param.getUserId(), vm, Event.OperationSucceeded); asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_SUCCEEDED, 0, VMExecutorHelper.composeResultObject(asyncMgr.getExecutorContext().getManagementServer(), vm, null)); jobStatusUpdated = true; @@ -97,8 +92,6 @@ public class StopVMExecutor extends VMOperationExecutor { AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR, "Agent failed to stop VM"); jobStatusUpdated = true; - EventUtils.saveEvent(param.getUserId(), param.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, - "Failed to stop VM instance : " + vm.getName(), params, param.getEventId()); } } catch(Exception e) { s_logger.error("Unexpected exception " + e.getMessage(), e); @@ -109,8 +102,6 @@ public class StopVMExecutor extends VMOperationExecutor { } else { asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, BaseCmd.INTERNAL_ERROR, "Agent failed to stop VM"); - EventUtils.saveEvent(param.getUserId(), param.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, - "Failed to stop VM instance : " + vm.getName(), params, param.getEventId()); } } } finally { @@ -137,17 +128,8 @@ public class StopVMExecutor extends VMOperationExecutor { VMOperationParam param = listener.getParam(); AsyncJobManager asyncMgr = getAsyncJobMgr(); - EventVO event = new EventVO(); - event.setUserId(param.getUserId()); - event.setAccountId(vm.getAccountId()); - event.setType(EventTypes.EVENT_VM_STOP); - event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId()); - event.setDescription("failed to stop VM instance : " + vm.getName() + " due to " + resultMessage); - event.setLevel(EventVO.LEVEL_ERROR); - asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_FAILED, 0, resultMessage); - asyncMgr.getExecutorContext().getEventDao().persist(event); asyncMgr.releaseSyncSource(this); } diff --git a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java index 2e28b1ed964..b573b44cf66 100644 --- a/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java @@ -253,22 +253,22 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu } @Override - public ConsoleProxyVO startProxy(long proxyVmId, long startEventId) { + public ConsoleProxyVO startProxy(long proxyVmId) { return null; } @Override - public boolean destroyProxy(long proxyVmId, long startEventId) { + public boolean destroyProxy(long proxyVmId) { return false; } @Override - public boolean rebootProxy(long proxyVmId, long startEventId) { + public boolean rebootProxy(long proxyVmId) { return false; } @Override - public boolean stopProxy(long proxyVmId, long startEventId) { + public boolean stopProxy(long proxyVmId) { return false; } @@ -324,13 +324,13 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu } @Override - public ConsoleProxyVO start(long vmId, long startEventId) throws InsufficientCapacityException, StorageUnavailableException, + public ConsoleProxyVO start(long vmId) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException { return null; } @Override - public boolean stop(ConsoleProxyVO vm, long startEventId) throws AgentUnavailableException { + public boolean stop(ConsoleProxyVO vm) throws AgentUnavailableException { return false; } diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java index 6ffe5236aa9..cc123d9f480 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java @@ -42,10 +42,10 @@ public interface ConsoleProxyManager extends Manager { public ConsoleProxyInfo assignProxy(long dataCenterId, long userVmId); - public ConsoleProxyVO startProxy(long proxyVmId, long startEventId); - public boolean stopProxy(long proxyVmId, long startEventId); - public boolean rebootProxy(long proxyVmId, long startEventId); - public boolean destroyProxy(long proxyVmId, long startEventId); + public ConsoleProxyVO startProxy(long proxyVmId); + public boolean stopProxy(long proxyVmId); + public boolean rebootProxy(long proxyVmId); + public boolean destroyProxy(long proxyVmId); public void onLoadReport(ConsoleProxyLoadReportCommand cmd); public AgentControlAnswer onConsoleAccessAuthentication(ConsoleAccessAuthenticationCommand cmd); diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 09e90dd36dc..ce82d1322dc 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -80,7 +80,6 @@ import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.event.Event; import com.cloud.event.EventTypes; -import com.cloud.event.EventUtils; import com.cloud.event.EventVO; import com.cloud.event.dao.EventDao; import com.cloud.exception.AgentUnavailableException; @@ -91,8 +90,8 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.host.Host; -import com.cloud.host.Host.Type; import com.cloud.host.HostVO; +import com.cloud.host.Host.Type; import com.cloud.host.dao.HostDao; import com.cloud.info.ConsoleProxyConnectionInfo; import com.cloud.info.ConsoleProxyInfo; @@ -116,9 +115,9 @@ import com.cloud.servlet.ConsoleProxyServlet; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.VMTemplateHostVO; -import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VolumeVO; +import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplateHostDao; @@ -345,7 +344,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx try { if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - proxy = startProxy(proxyVmId, 0); + proxy = startProxy(proxyVmId); if (proxy == null) { // @@ -366,7 +365,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (s_logger.isInfoEnabled()) { s_logger.info("Unable to start console proxy, proxy vm Id : " + proxyVmId + " will recycle it and restart a new one"); } - destroyProxy(proxyVmId, 0); + destroyProxy(proxyVmId); return null; } else { if (s_logger.isTraceEnabled()) { @@ -532,9 +531,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } @Override - public ConsoleProxyVO startProxy(long proxyVmId, long startEventId) { + public ConsoleProxyVO startProxy(long proxyVmId) { try { - return start(proxyVmId, startEventId); + return start(proxyVmId); } catch (StorageUnavailableException e) { s_logger.warn("Exception while trying to start console proxy", e); return null; @@ -548,7 +547,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } @Override - public ConsoleProxyVO start(long proxyVmId, long startEventId) throws ResourceUnavailableException, InsufficientCapacityException { + public ConsoleProxyVO start(long proxyVmId) throws ResourceUnavailableException, InsufficientCapacityException { ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId); Account systemAcct = _accountMgr.getSystemAccount(); User systemUser = _accountMgr.getSystemUser(); @@ -1056,7 +1055,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx try { if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - readyProxy = start(readyProxy.getId(), 0); + readyProxy = start(readyProxy.getId()); } finally { proxyLock.unlock(); } @@ -1258,7 +1257,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx try { if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - proxy = startProxy(proxyVmId, 0); + proxy = startProxy(proxyVmId); } finally { proxyLock.unlock(); } @@ -1279,7 +1278,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } if (proxyFromStoppedPool) { - destroyProxy(proxyVmId, 0); + destroyProxy(proxyVmId); } } else { if (s_logger.isInfoEnabled()) { @@ -1454,7 +1453,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } @Override - public boolean stopProxy(long proxyVmId, long startEventId) { + public boolean stopProxy(long proxyVmId) { AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); if (asyncExecutor != null) { @@ -1479,7 +1478,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx * proxyVmId, startEventId); */ try { - return stop(proxy, startEventId); + return stop(proxy); } catch (AgentUnavailableException e) { if (s_logger.isDebugEnabled()) { s_logger.debug("Stopping console proxy " + proxy.getName() + " failed : exception " + e.toString()); @@ -1489,7 +1488,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } @Override - public boolean rebootProxy(long proxyVmId, long startEventId) { + public boolean rebootProxy(long proxyVmId) { AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); if (asyncExecutor != null) { AsyncJobVO job = asyncExecutor.getJob(); @@ -1532,7 +1531,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx event.setAccountId(Account.ACCOUNT_ID_SYSTEM); event.setType(EventTypes.EVENT_PROXY_REBOOT); event.setLevel(EventVO.LEVEL_INFO); - event.setStartId(startEventId); + // event.setStartId(startEventId); event.setDescription("Console proxy rebooted - " + proxy.getName()); _eventDao.persist(event); return true; @@ -1546,24 +1545,24 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx event.setAccountId(Account.ACCOUNT_ID_SYSTEM); event.setType(EventTypes.EVENT_PROXY_REBOOT); event.setLevel(EventVO.LEVEL_ERROR); - event.setStartId(startEventId); + // event.setStartId(startEventId); event.setDescription("Rebooting console proxy failed - " + proxy.getName()); _eventDao.persist(event); return false; } } else { - return startProxy(proxyVmId, 0) != null; + return startProxy(proxyVmId) != null; } } @Override public boolean destroy(ConsoleProxyVO proxy) throws AgentUnavailableException { - return destroyProxy(proxy.getId(), 0); + return destroyProxy(proxy.getId()); } @Override @DB - public boolean destroyProxy(long vmId, long startEventId) { + public boolean destroyProxy(long vmId) { AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); if (asyncExecutor != null) { AsyncJobVO job = asyncExecutor.getJob(); @@ -1621,7 +1620,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx event.setAccountId(Account.ACCOUNT_ID_SYSTEM); event.setType(EventTypes.EVENT_PROXY_DESTROY); event.setLevel(EventVO.LEVEL_INFO); - event.setStartId(startEventId); + //event.setStartId(startEventId); event.setDescription("Console proxy destroyed - " + vm.getName()); _eventDao.persist(event); @@ -1672,7 +1671,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } @Override - public boolean stop(ConsoleProxyVO proxy, long startEventId) throws AgentUnavailableException { + public boolean stop(ConsoleProxyVO proxy) throws AgentUnavailableException { if (!_itMgr.stateTransitTo(proxy, VirtualMachine.Event.StopRequested, proxy.getHostId())) { s_logger.debug("Unable to stop console proxy: " + proxy.toString()); return false; @@ -1703,7 +1702,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx event.setAccountId(Account.ACCOUNT_ID_SYSTEM); event.setType(EventTypes.EVENT_PROXY_STOP); event.setLevel(EventVO.LEVEL_ERROR); - event.setStartId(startEventId); + //event.setStartId(startEventId); event.setDescription("Stopping console proxy failed due to negative answer from agent - " + proxy.getName()); _eventDao.persist(event); return false; @@ -1721,7 +1720,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx event.setAccountId(Account.ACCOUNT_ID_SYSTEM); event.setType(EventTypes.EVENT_PROXY_STOP); event.setLevel(EventVO.LEVEL_INFO); - event.setStartId(startEventId); + //event.setStartId(startEventId); event.setDescription("Console proxy stopped - " + proxy.getName()); _eventDao.persist(event); return true; @@ -1731,7 +1730,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx event.setAccountId(Account.ACCOUNT_ID_SYSTEM); event.setType(EventTypes.EVENT_PROXY_STOP); event.setLevel(EventVO.LEVEL_ERROR); - event.setStartId(startEventId); + //event.setStartId(startEventId); event.setDescription("Stopping console proxy failed due to operation time out - " + proxy.getName()); _eventDao.persist(event); throw new AgentUnavailableException(proxy.getHostId()); @@ -1999,9 +1998,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a console proxy with id " + proxyId); } - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_DESTROY, "destroying console proxy with Id: "+proxyId); - - return destroyProxy(proxyId, eventId); + return destroyProxy(proxyId); } @@ -2137,8 +2134,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if(updateCertAns.getResult() == true) { //we have the cert copied over on cpvm - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_REBOOT, "rebooting console proxy with Id: "+consoleProxy.getId()); - rebootProxy(consoleProxy.getId(), eventId); + rebootProxy(consoleProxy.getId()); //when cp reboots, the context will be reinit with the new cert s_logger.info("Successfully rebooted console proxy resource after custom certificate application for proxy:"+cmd.getProxyVmId()); return true; @@ -2157,18 +2153,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx return false;//cert already applied in previous cycles } - private Long saveScheduledEvent(Long userId, Long accountId, String type, String description) - { - EventVO event = new EventVO(); - event.setUserId(userId); - event.setAccountId(accountId); - event.setType(type); - event.setState(Event.State.Scheduled); - event.setDescription("Scheduled async job for "+description); - event = _eventDao.persist(event); - return event.getId(); - } - @Override public ConsoleProxyVO persist(ConsoleProxyVO proxy) { return _consoleProxyDao.persist(proxy); diff --git a/server/src/com/cloud/event/EventUtils.java b/server/src/com/cloud/event/EventUtils.java index 3290955034e..6810f0784c6 100755 --- a/server/src/com/cloud/event/EventUtils.java +++ b/server/src/com/cloud/event/EventUtils.java @@ -46,6 +46,17 @@ public class EventUtils { return event.getId(); } + public static Long saveStartedEvent(Long userId, Long accountId, String type, String description) { + EventVO event = new EventVO(); + event.setUserId(userId); + event.setAccountId(accountId); + event.setType(type); + event.setState(Event.State.Started); + event.setDescription(description); + event = _eventDao.persist(event); + return event.getId(); + } + public static Long saveEvent(Long userId, Long accountId, String level, String type, String description) { EventVO event = new EventVO(); event.setUserId(userId); diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java index 854daf37113..84ee6ead81c 100644 --- a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java +++ b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java @@ -440,7 +440,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager { } try { - VMInstanceVO started = mgr.start(vm.getId(), 0); + VMInstanceVO started = mgr.start(vm.getId()); if (started != null) { s_logger.info("VM is now restarted: " + vmId + " on " + started.getHostId()); return null; @@ -866,7 +866,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager { try { if (work.getWorkType() == WorkType.Stop) { if (vm.getHostId() != null) { - if (mgr.stop(vm, 0)) { + if (mgr.stop(vm)) { s_logger.info("Successfully stopped " + vm.toString()); return null; } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index 978906e0aba..7b674748297 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -72,7 +72,7 @@ public interface VirtualNetworkApplianceManager extends Manager { boolean getRouterStatistics(long vmId, Map netStats, Map diskStats); - boolean rebootRouter(long routerId, long eventId); + boolean rebootRouter(long routerId); /** * @param hostId get all of the virtual machine routers on a host. diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index f2c7c7cec5f..f6aeb987074 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -108,14 +108,14 @@ import com.cloud.network.IpAddress; import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; -import com.cloud.network.Networks.BroadcastDomainType; -import com.cloud.network.Networks.IsolationType; -import com.cloud.network.Networks.TrafficType; import com.cloud.network.PublicIpAddress; import com.cloud.network.RemoteAccessVpnVO; import com.cloud.network.SshKeysDistriMonitor; import com.cloud.network.VirtualNetworkApplianceService; import com.cloud.network.VpnUserVO; +import com.cloud.network.Networks.BroadcastDomainType; +import com.cloud.network.Networks.IsolationType; +import com.cloud.network.Networks.TrafficType; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; @@ -362,7 +362,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return true; } - if (!stop(router, 0)) { + if (!stop(router)) { s_logger.debug("Unable to stop the router: " + routerId); return false; } @@ -634,7 +634,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.debug("Stopping router " + routerId); } - return stop(_routerDao.findById(routerId), eventId); + return stop(_routerDao.findById(routerId)); } @Override @@ -656,10 +656,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian throw new PermissionDeniedException("Unable to stop router with id " + routerId + ". Permission denied"); } - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_ROUTER_STOP, - "stopping Router with Id: " + routerId); - - boolean success = stopRouter(routerId, eventId); + boolean success = stopRouter(routerId, 0); if (success) { return _routerDao.findById(routerId); @@ -738,7 +735,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public boolean rebootRouter(final long routerId, long startEventId) { + public boolean rebootRouter(final long routerId) { AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); if (asyncExecutor != null) { AsyncJobVO job = asyncExecutor.getJob(); @@ -755,21 +752,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - EventVO event = new EventVO(); - event.setUserId(1L); - event.setAccountId(router.getAccountId()); - event.setType(EventTypes.EVENT_ROUTER_REBOOT); - event.setState(Event.State.Started); - event.setDescription("Rebooting Router with Id: " + routerId); - event.setStartId(startEventId); - _eventDao.persist(event); - - event = new EventVO(); - event.setUserId(1L); - event.setAccountId(router.getAccountId()); - event.setType(EventTypes.EVENT_ROUTER_REBOOT); - event.setStartId(startEventId); - return false; // FIXME Alena if (router.getState() == State.Running && @@ -812,10 +794,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), router.getDomainId())) { throw new PermissionDeniedException("Unable to reboot domain router with id " + routerId + ". Permission denied"); } - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_ROUTER_REBOOT, - "rebooting Router with Id: " + routerId); - if (rebootRouter(routerId, eventId)) { + if (rebootRouter(routerId)) { return _routerDao.findById(routerId); } else { throw new CloudRuntimeException("Fail to reboot router " + routerId); @@ -1028,7 +1008,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override @DB - public boolean stop(DomainRouterVO router, long eventId) { + public boolean stop(DomainRouterVO router) { long routerId = router.getId(); router = _routerDao.acquireInLockTable(routerId); @@ -1037,18 +1017,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - EventVO event = new EventVO(); - event.setUserId(1L); - event.setAccountId(router.getAccountId()); - event.setType(EventTypes.EVENT_ROUTER_STOP); - event.setState(Event.State.Started); - event.setDescription("Stopping Router with Id: " + routerId); - event.setStartId(eventId); - event = _eventDao.persist(event); - if (eventId == 0) { - eventId = event.getId(); - } - try { if (s_logger.isDebugEnabled()) { @@ -1067,11 +1035,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return true; } - event = new EventVO(); + EventVO event = new EventVO(); event.setUserId(1L); event.setAccountId(router.getAccountId()); event.setType(EventTypes.EVENT_ROUTER_STOP); - event.setStartId(eventId); if (!_itMgr.stateTransitTo(router, VirtualMachine.Event.StopRequested, hostId)) { s_logger.debug("VM " + router.toString() + " is not in a state to be stopped."); @@ -1773,8 +1740,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } _accountMgr.checkAccess(account, router); - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_ROUTER_START, - "starting Router with Id: " + routerId); UserVO user = _userDao.findById(UserContext.current().getUserId()); return this.start(router, user, account); } @@ -1806,8 +1771,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _accountMgr.checkAccess(account, router); - long eventId = EventUtils.saveScheduledEvent(userId, accountId, EventTypes.EVENT_ROUTER_STOP, "stopping Router with Id: " + routerId); - UserVO user = _userDao.findById(context.getUserId()); if (!_itMgr.stop(router, user, account)) { @@ -1988,7 +1951,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public DomainRouterVO start(long vmId, long startEventId) throws InsufficientCapacityException, StorageUnavailableException, + public DomainRouterVO start(long vmId) throws InsufficientCapacityException, StorageUnavailableException, ConcurrentOperationException { // TODO Auto-generated method stub return null; diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index 581a0daae21..3c74dfa168f 100644 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -248,8 +248,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { description = "failed to create new " + ruleName + " rule [" + newRule.getSourceIpAddress() + ":" + newRule.getSourcePortStart() + "]->[" + newRule.getDestinationIpAddress() + ":" + newRule.getDestinationPortStart() + "]" + " " + newRule.getProtocol(); } - - EventUtils.saveEvent(UserContext.current().getUserId(), vm.getAccountId(), level, EventTypes.EVENT_NET_RULE_ADD, description); } } @@ -302,15 +300,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { } description.append(" ").append(rule.getProtocol()); - // save off an event for removing the network rule - EventVO event = new EventVO(); - event.setUserId(userId); - event.setAccountId(rule.getAccountId()); - event.setType(EventTypes.EVENT_NET_RULE_DELETE); - event.setDescription(description.toString()); - event.setLevel(EventVO.LEVEL_INFO); - _eventDao.persist(event); - txn.commit(); } diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index a98c9feb25b..d068c8884cc 100755 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -160,7 +160,7 @@ public interface ManagementServer extends ManagementService { * @param attach whether to attach or detach the iso from the instance * @return */ - boolean attachISOToVM(long vmId, long userId, long isoId, boolean attach, long startEventId); + boolean attachISOToVM(long vmId, long userId, long isoId, boolean attach); /** * Retrieves a host by id @@ -303,7 +303,7 @@ public interface ManagementServer extends ManagementService { * @return true if success * @throws InternalErrorException */ - boolean copyTemplate(long userId, long templateId, long sourceZoneId, long destZoneId, long startEventId); + boolean copyTemplate(long userId, long templateId, long sourceZoneId, long destZoneId); /** * Finds a template by the specified ID. @@ -379,9 +379,9 @@ public interface ManagementServer extends ManagementService { void logoutUser(Long userId); ConsoleProxyInfo getConsoleProxy(long dataCenterId, long userVmId); - ConsoleProxyVO startConsoleProxy(long instanceId, long startEventId); - ConsoleProxyVO stopConsoleProxy(long instanceId, long startEventId); - ConsoleProxyVO rebootConsoleProxy(long instanceId, long startEventId); + ConsoleProxyVO startConsoleProxy(long instanceId); + ConsoleProxyVO stopConsoleProxy(long instanceId); + ConsoleProxyVO rebootConsoleProxy(long instanceId); String getConsoleAccessUrlRoot(long vmId); ConsoleProxyVO findConsoleProxyById(long instanceId); VMInstanceVO findSystemVMById(long instanceId); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 74efffcd0ac..30f16a5eb3e 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -765,14 +765,9 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public boolean attachISOToVM(long vmId, long userId, long isoId, boolean attach, long startEventId) { + public boolean attachISOToVM(long vmId, long userId, long isoId, boolean attach) { UserVmVO vm = _userVmDao.findById(vmId); VMTemplateVO iso = _templateDao.findById(isoId); - if(attach){ - EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_ISO_ATTACH, "Attaching ISO: "+isoId+" to Vm: "+vmId, startEventId); - } else { - EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_ISO_DETACH, "Detaching ISO: "+isoId+" from Vm: "+vmId, startEventId); - } boolean success = _vmMgr.attachISOToVM(vmId, isoId, attach); if (success) { @@ -782,19 +777,6 @@ public class ManagementServerImpl implements ManagementServer { vm.setIsoId(null); } _userVmDao.update(vmId, vm); - - if (attach) { - EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ISO_ATTACH, "Successfully attached ISO: " + iso.getName() + " to VM with ID: " + vmId, - null, startEventId); - } else { - EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ISO_DETACH, "Successfully detached ISO from VM with ID: " + vmId, null, startEventId); - } - } else { - if (attach) { - EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ISO_ATTACH, "Failed to attach ISO: " + iso.getName() + " to VM with ID: " + vmId, null, startEventId); - } else { - EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ISO_DETACH, "Failed to detach ISO from VM with ID: " + vmId, null, startEventId); - } } return success; } @@ -2043,10 +2025,10 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public boolean copyTemplate(long userId, long templateId, long sourceZoneId, long destZoneId, long startEventId) { + public boolean copyTemplate(long userId, long templateId, long sourceZoneId, long destZoneId) { boolean success = false; try { - success = _tmpltMgr.copy(userId, templateId, sourceZoneId, destZoneId, startEventId); + success = _tmpltMgr.copy(userId, templateId, sourceZoneId, destZoneId); } catch (Exception e) { s_logger.warn("Unable to copy template " + templateId + " from zone " + sourceZoneId + " to " + destZoneId , e); success = false; @@ -2994,19 +2976,19 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public ConsoleProxyVO startConsoleProxy(long instanceId, long startEventId) { - return _consoleProxyMgr.startProxy(instanceId, startEventId); + public ConsoleProxyVO startConsoleProxy(long instanceId) { + return _consoleProxyMgr.startProxy(instanceId); } @Override - public ConsoleProxyVO stopConsoleProxy(long instanceId, long startEventId) { - _consoleProxyMgr.stopProxy(instanceId, startEventId); + public ConsoleProxyVO stopConsoleProxy(long instanceId) { + _consoleProxyMgr.stopProxy(instanceId); return _consoleProxyDao.findById(instanceId); } @Override - public ConsoleProxyVO rebootConsoleProxy(long instanceId, long startEventId) { - _consoleProxyMgr.rebootProxy(instanceId, startEventId); + public ConsoleProxyVO rebootConsoleProxy(long instanceId) { + _consoleProxyMgr.rebootProxy(instanceId); return _consoleProxyDao.findById(instanceId); } @@ -4112,22 +4094,22 @@ public class ManagementServerImpl implements ManagementServer { return _domainDao.isChildDomain(parentId, childId); } - public SecondaryStorageVmVO startSecondaryStorageVm(long instanceId, long startEventId) { - return _secStorageVmMgr.startSecStorageVm(instanceId, startEventId); + public SecondaryStorageVmVO startSecondaryStorageVm(long instanceId) { + return _secStorageVmMgr.startSecStorageVm(instanceId); } - public SecondaryStorageVmVO stopSecondaryStorageVm(long instanceId, long startEventId) { - _secStorageVmMgr.stopSecStorageVm(instanceId, startEventId); + public SecondaryStorageVmVO stopSecondaryStorageVm(long instanceId) { + _secStorageVmMgr.stopSecStorageVm(instanceId); return _secStorageVmDao.findById(instanceId); } - public SecondaryStorageVmVO rebootSecondaryStorageVm(long instanceId, long startEventId) { - _secStorageVmMgr.rebootSecStorageVm(instanceId, startEventId); + public SecondaryStorageVmVO rebootSecondaryStorageVm(long instanceId) { + _secStorageVmMgr.rebootSecStorageVm(instanceId); return _secStorageVmDao.findById(instanceId); } - public boolean destroySecondaryStorageVm(long instanceId, long startEventId) { - return _secStorageVmMgr.destroySecStorageVm(instanceId, startEventId); + public boolean destroySecondaryStorageVm(long instanceId) { + return _secStorageVmMgr.destroySecStorageVm(instanceId); } @Override @@ -4229,11 +4211,9 @@ public class ManagementServerImpl implements ManagementServer { } if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_START, "Starting console proxy with Id: "+id); - return startConsoleProxy(id, eventId); + return startConsoleProxy(id); } else { - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "Starting secondary storage Vm Id: "+id); - return startSecondaryStorageVm(id, eventId); + return startSecondaryStorageVm(id); } } @@ -4249,11 +4229,9 @@ public class ManagementServerImpl implements ManagementServer { } if (systemVm.getType() == VirtualMachine.Type.ConsoleProxy) { - long eventId = EventUtils.saveScheduledEvent(callerId, callerAccountId, EventTypes.EVENT_PROXY_START, "Starting console proxy with Id: "+vmId); - return startConsoleProxy(vmId, eventId); + return startConsoleProxy(vmId); } else if (systemVm.getType() == VirtualMachine.Type.SecondaryStorageVm) { - long eventId = EventUtils.saveScheduledEvent(callerId, callerAccountId, EventTypes.EVENT_SSVM_START, "Starting secondary storage Vm Id: "+vmId); - return startSecondaryStorageVm(vmId, eventId); + return startSecondaryStorageVm(vmId); } else { throw new InvalidParameterValueException("Unable to find a system vm: " + vmId); } @@ -4274,11 +4252,9 @@ public class ManagementServerImpl implements ManagementServer { // FIXME: We need to return the system VM from this method, so what do we do with the boolean response from stopConsoleProxy and stopSecondaryStorageVm? if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ - long eventId = EventUtils.saveScheduledEvent(callerId, callerAccountId, EventTypes.EVENT_PROXY_STOP, "stopping console proxy with Id: "+vmId); - return stopConsoleProxy(vmId, eventId); + return stopConsoleProxy(vmId); } else { - long eventId = EventUtils.saveScheduledEvent(callerId, callerAccountId, EventTypes.EVENT_SSVM_STOP, "stopping secondary storage Vm Id: "+vmId); - return stopSecondaryStorageVm(vmId, eventId); + return stopSecondaryStorageVm(vmId); } } @@ -4294,11 +4270,9 @@ public class ManagementServerImpl implements ManagementServer { // FIXME: We need to return the system VM from this method, so what do we do with the boolean response from stopConsoleProxy and stopSecondaryStorageVm? if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_STOP, "stopping console proxy with Id: "+id); - return stopConsoleProxy(id, eventId); + return stopConsoleProxy(id); } else { - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, "stopping secondary storage Vm Id: "+id); - return stopSecondaryStorageVm(id, eventId); + return stopSecondaryStorageVm(id); } } @@ -4311,11 +4285,9 @@ public class ManagementServerImpl implements ManagementServer { } if (systemVm.getType().equals(VirtualMachine.Type.ConsoleProxy)){ - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_REBOOT, "Rebooting console proxy with Id: "+cmd.getId()); - return rebootConsoleProxy(cmd.getId(), eventId); + return rebootConsoleProxy(cmd.getId()); } else { - long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_REBOOT, "Rebooting secondary storage vm with Id: "+cmd.getId()); - return rebootSecondaryStorageVm(cmd.getId(), eventId); + return rebootSecondaryStorageVm(cmd.getId()); } } @@ -4817,6 +4789,16 @@ public class ManagementServerImpl implements ManagementServer { event = _eventDao.persist(event); return event.getId(); } + + public Long saveStartedEvent(Long userId, Long accountId, String type, String description, long startEventId) + { + return EventUtils.saveStartedEvent(userId, accountId, type, description, startEventId); + } + + public Long saveCompletedEvent(Long userId, Long accountId, String level, String type, String description, long startEventId) + { + return EventUtils.saveEvent(userId, accountId, level, type, description, startEventId); + } @Override @DB public String uploadCertificate(UploadCustomCertificateCmd cmd) throws ServerApiException{ @@ -4895,7 +4877,7 @@ public class ManagementServerImpl implements ManagementServer { { //we have the cert copied over on cpvm long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_REBOOT, "rebooting console proxy with Id: "+cp.getId()); - _consoleProxyMgr.rebootProxy(cp.getId(), eventId); + _consoleProxyMgr.rebootProxy(cp.getId()); //when cp reboots, the context will be reinit with the new cert if(s_logger.isDebugEnabled()) { s_logger.debug("Successfully updated custom certificate on console proxy vm id:"+cp.getId()+" ,console proxy host id:"+cpHostId); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index a1b099906de..0af65909b17 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -139,7 +139,6 @@ import com.cloud.storage.snapshot.SnapshotScheduler; import com.cloud.template.TemplateManager; import com.cloud.user.Account; import com.cloud.user.AccountManager; -import com.cloud.user.User; import com.cloud.user.UserContext; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; @@ -2295,11 +2294,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag //make sure it is not restarted again, update config to set flag to false _configMgr.updateConfiguration(userId, "consoleproxy.restart", "false"); - //create a dummy event - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_STOP, "stopping console proxy with Id: "+vmInstance.getId()); - //call the consoleproxymanager - if(!_consoleProxyMgr.stopProxy(vmInstance.getId(), eventId)) + if(!_consoleProxyMgr.stopProxy(vmInstance.getId())) { String errorMsg = "There was an error stopping the console proxy id: "+vmInstance.getId()+" ,cannot enable storage maintenance"; s_logger.warn(errorMsg); @@ -2309,13 +2305,10 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } else if(restart) { - //create a dummy event - long eventId1 = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_START, "starting console proxy with Id: "+vmInstance.getId()); - //Restore config val for consoleproxy.restart to true _configMgr.updateConfiguration(userId, "consoleproxy.restart", "true"); - if(_consoleProxyMgr.startProxy(vmInstance.getId(), eventId1)==null) + if(_consoleProxyMgr.startProxy(vmInstance.getId())==null) { String errorMsg = "There was an error starting the console proxy id: "+vmInstance.getId()+" on another storage pool, cannot enable primary storage maintenance"; s_logger.warn(errorMsg); @@ -2330,9 +2323,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag if(vmInstance.getType().equals(VirtualMachine.Type.User)) { //create a dummy event - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_VM_STOP, "stopping user vm with Id: "+vmInstance.getId()); - - if(!_userVmMgr.stopVirtualMachine(userId, vmInstance.getId(),eventId)) + if(!_userVmMgr.stopVirtualMachine(userId, vmInstance.getId())) { String errorMsg = "There was an error stopping the user vm id: "+vmInstance.getId()+" ,cannot enable storage maintenance"; s_logger.warn(errorMsg); @@ -2345,10 +2336,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag //if the instance is of type secondary storage vm, call the secondary storage vm manager if(vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) { - //create a dummy event - long eventId1 = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, "stopping ssvm with Id: "+vmInstance.getId()); - - if(!_secStorageMgr.stopSecStorageVm(vmInstance.getId(), eventId1)) + if(!_secStorageMgr.stopSecStorageVm(vmInstance.getId())) { String errorMsg = "There was an error stopping the ssvm id: "+vmInstance.getId()+" ,cannot enable storage maintenance"; s_logger.warn(errorMsg); @@ -2358,9 +2346,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } else if(restart) { - //create a dummy event and restart the ssvm immediately - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "starting ssvm with Id: "+vmInstance.getId()); - if(_secStorageMgr.startSecStorageVm(vmInstance.getId(), eventId)==null) + if(_secStorageMgr.startSecStorageVm(vmInstance.getId())==null) { String errorMsg = "There was an error starting the ssvm id: "+vmInstance.getId()+" on another storage pool, cannot enable primary storage maintenance"; s_logger.warn(errorMsg); @@ -2374,10 +2360,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag //if the instance is of type domain router vm, call the network manager if(vmInstance.getType().equals(VirtualMachine.Type.DomainRouter)) { - //create a dummy event - long eventId2 = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_ROUTER_STOP, "stopping domain router with Id: "+vmInstance.getId()); - - if(!_routerMgr.stopRouter(vmInstance.getId(), eventId2)) + if(!_routerMgr.stopRouter(vmInstance.getId(), 0)) { String errorMsg = "There was an error stopping the domain router id: "+vmInstance.getId()+" ,cannot enable primary storage maintenance"; s_logger.warn(errorMsg); @@ -2387,8 +2370,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } else if(restart) { - //create a dummy event and restart the domr immediately - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_START, "starting domr with Id: "+vmInstance.getId()); // FIXME if(_routerMgr.startRouter(vmInstance.getId(), eventId)==null) // { // String errorMsg = "There was an error starting the domain router id: "+vmInstance.getId()+" on another storage pool, cannot enable primary storage maintenance"; @@ -2478,10 +2459,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag if(vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) { - //create a dummy event - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_START, "starting console proxy with Id: "+vmInstance.getId()); - - if(_consoleProxyMgr.startProxy(vmInstance.getId(), eventId) == null) + if(_consoleProxyMgr.startProxy(vmInstance.getId()) == null) { String msg = "There was an error starting the console proxy id: "+vmInstance.getId()+" on storage pool, cannot complete primary storage maintenance"; s_logger.warn(msg); @@ -2493,10 +2471,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag if(vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) { - //create a dummy event - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "starting ssvm with Id: "+vmInstance.getId()); - - if(_secStorageMgr.startSecStorageVm(vmInstance.getId(), eventId) == null) + if(_secStorageMgr.startSecStorageVm(vmInstance.getId()) == null) { String msg = "There was an error starting the ssvm id: "+vmInstance.getId()+" on storage pool, cannot complete primary storage maintenance"; s_logger.warn(msg); @@ -2508,9 +2483,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag if(vmInstance.getType().equals(VirtualMachine.Type.User)) { - //create a dummy event - long eventId = saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_VM_START, "starting user vm with Id: "+vmInstance.getId()); - try { if(_userVmMgr.startUserVm(vmInstance.getId()) == null) { diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index d8e8502642b..21d5e26b685 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -226,9 +226,9 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V private final GlobalLock _allocLock = GlobalLock.getInternLock(getAllocLockName()); @Override - public SecondaryStorageVmVO startSecStorageVm(long secStorageVmId, long startEventId) { + public SecondaryStorageVmVO startSecStorageVm(long secStorageVmId) { try { - return start(secStorageVmId, startEventId); + return start(secStorageVmId); } catch (StorageUnavailableException e) { s_logger.warn("Exception while trying to start secondary storage vm", e); return null; @@ -244,7 +244,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } @Override - public SecondaryStorageVmVO start(long secStorageVmId, long startEventId) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException { + public SecondaryStorageVmVO start(long secStorageVmId) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException { SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId); Account systemAcct = _accountMgr.getSystemAccount(); User systemUser = _accountMgr.getSystemUser(); @@ -533,7 +533,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V try { if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - readysecStorageVm = start(readysecStorageVm.getId(), 0); + readysecStorageVm = start(readysecStorageVm.getId()); } finally { secStorageVmLock.unlock(); } @@ -726,7 +726,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V try { if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - secStorageVm = startSecStorageVm(secStorageVmId, 0); + secStorageVm = startSecStorageVm(secStorageVmId); } finally { secStorageVmLock.unlock(); } @@ -748,7 +748,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } if (secStorageVmFromStoppedPool) { - destroySecStorageVm(secStorageVmId, 0); + destroySecStorageVm(secStorageVmId); } } else { if (s_logger.isInfoEnabled()) { @@ -1012,7 +1012,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } @Override - public boolean stopSecStorageVm(long secStorageVmId, long startEventId) { + public boolean stopSecStorageVm(long secStorageVmId) { AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); if (asyncExecutor != null) { @@ -1023,21 +1023,17 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } _asyncMgr.updateAsyncJobAttachment(job.getId(), "secStorageVm", secStorageVmId); } - long eventId = saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, "Stopping secondary storage Vm with Id: "+secStorageVmId, startEventId); - if(startEventId == 0){ - startEventId = eventId; - } - SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId); + + SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId); if (secStorageVm == null) { String msg = "Stopping secondary storage vm failed: secondary storage vm " + secStorageVmId + " no longer exists"; if (s_logger.isDebugEnabled()) { s_logger.debug(msg); } - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, msg, startEventId); return false; } try { - return stop(secStorageVm, startEventId); + return stop(secStorageVm); } catch (AgentUnavailableException e) { if (s_logger.isDebugEnabled()) { s_logger.debug("Stopping secondary storage vm " + secStorageVm.getName() + " faled : exception " + e.toString()); @@ -1047,7 +1043,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } @Override - public boolean rebootSecStorageVm(long secStorageVmId, long startEventId) { + public boolean rebootSecStorageVm(long secStorageVmId) { AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); if (asyncExecutor != null) { AsyncJobVO job = asyncExecutor.getJob(); @@ -1060,13 +1056,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V final SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId); - long eventId = saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_REBOOT, "Rebooting secondary storage Vm Id: "+secStorageVmId, startEventId); - if(startEventId == 0 ){ - startEventId = eventId; - } - if (secStorageVm == null || secStorageVm.getState() == State.Destroyed) { - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_REBOOT, "Rebooting secondary storage Vm failed", startEventId); return false; } @@ -1086,38 +1076,28 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null) ); - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_SSVM_REBOOT); - event.setLevel(EventVO.LEVEL_INFO); - event.setStartId(startEventId); - event.setDescription("Secondary Storage Vm rebooted - " + secStorageVm.getName()); - _eventDao.persist(event); return true; } else { String msg = "Rebooting Secondary Storage VM failed - " + secStorageVm.getName(); - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_REBOOT, msg, startEventId); if (s_logger.isDebugEnabled()) { s_logger.debug(msg); } return false; } } else { - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_REBOOT, "Secondary Storage not in running state. Starting Vm", startEventId); - return startSecStorageVm(secStorageVmId, 0) != null; + return startSecStorageVm(secStorageVmId) != null; } } @Override public boolean destroy(SecondaryStorageVmVO secStorageVm) throws AgentUnavailableException { - return destroySecStorageVm(secStorageVm.getId(), 0); + return destroySecStorageVm(secStorageVm.getId()); } @Override @DB - public boolean destroySecStorageVm(long vmId, long startEventId) { + public boolean destroySecStorageVm(long vmId) { AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); if (asyncExecutor != null) { AsyncJobVO job = asyncExecutor.getJob(); @@ -1128,18 +1108,12 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V _asyncMgr.updateAsyncJobAttachment(job.getId(), "secstorage_vm", vmId); } - long eventId = saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_DESTROY, "Destroying secondary storage Vm Id: "+vmId, startEventId); - if(startEventId == 0 ){ - startEventId = eventId; - } - SecondaryStorageVmVO vm = _secStorageVmDao.findById(vmId); if (vm == null || vm.getState() == State.Destroyed) { String msg = "Unable to find vm or vm is destroyed: " + vmId; if (s_logger.isDebugEnabled()) { s_logger.debug(msg); } - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_DESTROY, msg, startEventId); return true; } @@ -1150,7 +1124,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V if (! _itMgr.stateTransitTo(vm, VirtualMachine.Event.DestroyRequested, null)) { String msg = "Unable to destroy the vm because it is not in the correct state: " + vmId; s_logger.debug(msg); - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_DESTROY, msg, startEventId); return false; } @@ -1175,14 +1148,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V _secStorageVmDao.remove(vm.getId()); - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_SSVM_DESTROY); - event.setLevel(EventVO.LEVEL_INFO); - event.setStartId(startEventId); - event.setDescription("Secondary Storage Vm destroyed - " + vm.getName()); - _eventDao.persist(event); txn.commit(); } catch (Exception e) { s_logger.error("Caught this error: ", e); @@ -1229,11 +1194,10 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } @Override - public boolean stop(SecondaryStorageVmVO secStorageVm, long startEventId) throws AgentUnavailableException { + public boolean stop(SecondaryStorageVmVO secStorageVm) throws AgentUnavailableException { if (! _itMgr.stateTransitTo(secStorageVm, VirtualMachine.Event.StopRequested, secStorageVm.getHostId())) { String msg = "Unable to stop secondary storage vm: " + secStorageVm.toString(); s_logger.debug(msg); - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, msg, startEventId); return false; } @@ -1254,7 +1218,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V if (answer == null || !answer.getResult()) { String msg = "Unable to stop due to " + (answer == null ? "answer is null" : answer.getDetails()); s_logger.debug(msg); - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, msg, startEventId); return false; } completeStopCommand(secStorageVm, VirtualMachine.Event.OperationSucceeded); @@ -1270,13 +1233,10 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V event.setAccountId(Account.ACCOUNT_ID_SYSTEM); event.setType(EventTypes.EVENT_SSVM_STOP); event.setLevel(EventVO.LEVEL_INFO); - event.setStartId(startEventId); event.setDescription("Secondary Storage Vm stopped - " + secStorageVm.getName()); _eventDao.persist(event); return true; } catch (OperationTimedoutException e) { - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, - "Stopping secondary storage vm failed due to operation time out - " + secStorageVm.getName(), startEventId); throw new AgentUnavailableException(secStorageVm.getHostId()); } } finally { @@ -1285,8 +1245,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } else { String msg = "Unable to acquire secondary storage vm lock : " + secStorageVm.toString(); s_logger.debug(msg); - saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_STOP, msg, startEventId); - return false; } } finally { diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageVmManager.java b/server/src/com/cloud/storage/secondary/SecondaryStorageVmManager.java index 36d2ef4e41b..0939be937be 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageVmManager.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageVmManager.java @@ -28,10 +28,10 @@ public interface SecondaryStorageVmManager extends Manager { public static final String ALERT_SUBJECT = "secondarystoragevm-alert"; - public SecondaryStorageVmVO startSecStorageVm(long ssVmVmId, long startEventId); - public boolean stopSecStorageVm(long ssVmVmId, long startEventId); - public boolean rebootSecStorageVm(long ssVmVmId, long startEventId); - public boolean destroySecStorageVm(long ssVmVmId, long startEventId); + public SecondaryStorageVmVO startSecStorageVm(long ssVmVmId); + public boolean stopSecStorageVm(long ssVmVmId); + public boolean rebootSecStorageVm(long ssVmVmId); + public boolean destroySecStorageVm(long ssVmVmId); public void onAgentConnect(Long dcId, StartupCommand cmd); public boolean generateFirewallConfiguration(Long agentId); public boolean generateSetupCommand(Long zoneId); diff --git a/server/src/com/cloud/template/TemplateManager.java b/server/src/com/cloud/template/TemplateManager.java index 3eeee5ca657..3d9da38deb2 100755 --- a/server/src/com/cloud/template/TemplateManager.java +++ b/server/src/com/cloud/template/TemplateManager.java @@ -106,7 +106,7 @@ public interface TemplateManager { * @throws StorageUnavailableException * @throws InvalidParameterValueException */ - boolean copy(long userId, long templateId, long sourceZoneId, long destZoneId, long startEventId) throws StorageUnavailableException; + boolean copy(long userId, long templateId, long sourceZoneId, long destZoneId) throws StorageUnavailableException; /** * Deletes a template from secondary storage servers diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index d28cf33a099..ac80bd74ba5 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -57,7 +57,6 @@ import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenterVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.domain.dao.DomainDao; -import com.cloud.event.Event; import com.cloud.event.EventTypes; import com.cloud.event.EventUtils; import com.cloud.event.EventVO; @@ -74,22 +73,22 @@ import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.SnapshotVO; import com.cloud.storage.Storage; -import com.cloud.storage.Storage.ImageFormat; -import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePool; import com.cloud.storage.StoragePoolHostVO; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.Upload; -import com.cloud.storage.Upload.Type; import com.cloud.storage.UploadVO; import com.cloud.storage.VMTemplateHostVO; import com.cloud.storage.VMTemplateStoragePoolVO; import com.cloud.storage.VMTemplateStorageResourceAssoc; -import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.VMTemplateZoneVO; import com.cloud.storage.VolumeVO; +import com.cloud.storage.Storage.ImageFormat; +import com.cloud.storage.Storage.TemplateType; +import com.cloud.storage.Upload.Type; +import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.StoragePoolHostDao; @@ -719,7 +718,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe @Override @DB - public boolean copy(long userId, long templateId, long sourceZoneId, long destZoneId, long startEventId) throws StorageUnavailableException { + public boolean copy(long userId, long templateId, long sourceZoneId, long destZoneId) throws StorageUnavailableException { HostVO srcSecHost = _storageMgr.getSecondaryStorageHost(sourceZoneId); HostVO dstSecHost = _storageMgr.getSecondaryStorageHost(destZoneId); DataCenterVO destZone = _dcDao.findById(destZoneId); @@ -752,15 +751,6 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe throw new InvalidParameterValueException("Please specify a template that is installed on secondary storage host: " + srcSecHost.getName()); } - EventVO event = new EventVO(); - event.setUserId(userId); - event.setAccountId(vmTemplate.getAccountId()); - event.setType(EventTypes.EVENT_TEMPLATE_COPY); - event.setState(Event.State.Started); - event.setDescription("Copying template with Id: "+templateId); - event.setStartId(startEventId); - event = _eventDao.persist(event); - // Event details String params = "id=" + templateId + "\ndcId="+destZoneId+"\nsize="+srcTmpltHost.getSize(); Account account = _accountDao.findById(vmTemplate.getAccountId()); @@ -822,7 +812,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe UsageEventVO usageEvent = new UsageEventVO(copyEventType, account.getId(), destZoneId, templateId, null, null, null, srcTmpltHost.getSize()); _usageEventDao.persist(usageEvent); - saveEvent(userId, account.getId(), account.getDomainId(), copyEventType, copyEventDescription, EventVO.LEVEL_INFO, params, startEventId); + saveEvent(userId, account.getId(), account.getDomainId(), copyEventType, copyEventDescription, EventVO.LEVEL_INFO, params); return true; } @@ -849,8 +839,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe String errMsg = "Unable to copy ISO " + isoId; userId = accountAndUserValidation(account, userId, null, iso, errMsg); - long eventId = EventUtils.saveScheduledEvent(userId, iso.getAccountId(), EventTypes.EVENT_ISO_COPY, "copying iso with Id: " + isoId +" from zone: " + sourceZoneId +" to: " + destZoneId); - boolean success = copy(userId, isoId, sourceZoneId, destZoneId, eventId); + boolean success = copy(userId, isoId, sourceZoneId, destZoneId); VMTemplateVO copiedIso = null; if (success) { @@ -884,8 +873,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe String errMsg = "Unable to copy template " + templateId; userId = accountAndUserValidation(account, userId, null, template, errMsg); - long eventId = EventUtils.saveScheduledEvent(userId, template.getAccountId(), EventTypes.EVENT_TEMPLATE_COPY, "copying template with Id: " + templateId+" from zone: " + sourceZoneId +" to: " + destZoneId); - boolean success = copy(userId, templateId, sourceZoneId, destZoneId, eventId); + boolean success = copy(userId, templateId, sourceZoneId, destZoneId); VMTemplateVO copiedTemplate = null; if (success) { diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 98601b9510e..86222d06ec8 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -41,19 +41,18 @@ import com.cloud.api.commands.DisableUserCmd; import com.cloud.api.commands.EnableAccountCmd; import com.cloud.api.commands.EnableUserCmd; import com.cloud.api.commands.ListResourceLimitsCmd; -import com.cloud.api.commands.LockAccountCmd; import com.cloud.api.commands.LockUserCmd; import com.cloud.api.commands.UpdateAccountCmd; import com.cloud.api.commands.UpdateResourceLimitCmd; import com.cloud.api.commands.UpdateUserCmd; import com.cloud.configuration.ConfigurationManager; -import com.cloud.configuration.ResourceCount.ResourceType; import com.cloud.configuration.ResourceLimitVO; +import com.cloud.configuration.ResourceCount.ResourceType; import com.cloud.configuration.dao.ResourceCountDao; import com.cloud.configuration.dao.ResourceLimitDao; import com.cloud.dc.PodVlanMapVO; -import com.cloud.dc.Vlan.VlanType; import com.cloud.dc.VlanVO; +import com.cloud.dc.Vlan.VlanType; import com.cloud.dc.dao.PodVlanMapDao; import com.cloud.dc.dao.VlanDao; import com.cloud.domain.Domain; @@ -820,10 +819,14 @@ public class AccountManagerImpl implements AccountManager, AccountService { } for (UserVmVO vm : vms) { + long startEventId = EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Destroyed VM instance : " + vm.getName(), 0); if (!_vmMgr.destroyVirtualMachine(userId, vm.getId())) { s_logger.error("Unable to destroy vm: " + vm.getId()); accountCleanupNeeded = true; - } + EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_DESTROY, "Unable to destroy vm: " + vm.getId(), startEventId); + } else { + EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_DESTROY, "Successfully destroyed VM instance : " + vm.getName(), startEventId); + } } // Mark the account's volumes as destroyed @@ -955,7 +958,7 @@ public class AccountManagerImpl implements AccountManager, AccountService { boolean success = true; for (UserVmVO vm : vms) { try { - success = (success && _vmMgr.stop(vm, 0)); + success = (success && _vmMgr.stop(vm)); } catch (AgentUnavailableException aue) { s_logger.warn("Agent running on host " + vm.getHostId() + " is unavailable, unable to stop vm " + vm.getName()); success = false; diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java index 593036e20cb..c9aa34edeb1 100644 --- a/server/src/com/cloud/vm/UserVmManager.java +++ b/server/src/com/cloud/vm/UserVmManager.java @@ -64,11 +64,10 @@ public interface UserVmManager extends VirtualMachineGuru{ * Stops the virtual machine * @param userId the id of the user performing the action * @param vmId - * @param eventId -- id of the scheduled event for stopping vm * @return true if stopped; false if problems. */ - boolean stopVirtualMachine(long userId, long vmId, long eventId); - void completeStopCommand(long userId, UserVmVO vm, Event e, long startEventId); + boolean stopVirtualMachine(long userId, long vmId); + void completeStopCommand(long userId, UserVmVO vm, Event e); /** diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index d3f68ea9743..effbd88b81d 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -309,9 +309,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (result) { userVm.setPassword(password); - EventUtils.saveEvent(userId, userVm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_RESETPASSWORD, "successfully reset password for VM : " + userVm.getName(), null); - } else { - EventUtils.saveEvent(userId, userVm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_RESETPASSWORD, "unable to reset password for VM : " + userVm.getName(), null); } return userVm; @@ -334,12 +331,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } if (_routerMgr.savePasswordToRouter(vmInstance.getDomainRouterId(), vmInstance.getPrivateIpAddress(), password)) { // Need to reboot the virtual machine so that the password gets redownloaded from the DomR, and reset on the VM + long startId = EventUtils.saveStartedEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_REBOOT, "Reboot vm with id:"+vmId); if (!rebootVirtualMachine(userId, vmId)) { + EventUtils.saveEvent(userId, vmInstance.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_REBOOT, "Failed to reboot vm with id:"+vmId, startId); if (vmInstance.getState() == State.Stopped) { return true; } return false; } else { + EventUtils.saveEvent(userId, vmInstance.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_REBOOT, "Successfully rebooted vm with id:"+vmId, startId); return true; } } else { @@ -354,7 +354,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } @Override - public boolean stopVirtualMachine(long userId, long vmId, long eventId) { + public boolean stopVirtualMachine(long userId, long vmId) { boolean status = false; if (s_logger.isDebugEnabled()) { s_logger.debug("Stopping vm=" + vmId); @@ -367,16 +367,16 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager return true; } - EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+vmId, eventId); + long startEventId = EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+vmId); - status = stop(userId, vm, 0); + status = stop(userId, vm); if(status){ - EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_STOP, "Successfully stopped VM instance : " + vmId); + EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_STOP, "Successfully stopped VM instance : " + vmId, startEventId); return status; } else { - EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, "Error stopping VM instance : " + vmId); + EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, "Error stopping VM instance : " + vmId, startEventId); return status; } } @@ -463,17 +463,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } } - long startEventId = EventUtils.saveScheduledEvent(1L, volume.getAccountId(), EventTypes.EVENT_VOLUME_ATTACH, "attaching volume: "+volumeId+" to Vm: "+vmId); - - EventVO event = new EventVO(); - event.setType(EventTypes.EVENT_VOLUME_ATTACH); - event.setUserId(1L); - event.setAccountId(volume.getAccountId()); - event.setState(Event.State.Started); - event.setStartId(startEventId); - event.setDescription("Attaching volume: "+volumeId+" to Vm: "+vmId); - _eventDao.persist(event); - VolumeVO rootVolumeOfVm = null; List rootVolumesOfVm = _volsDao.findByInstanceAndType(vmId, VolumeType.ROOT); if (rootVolumesOfVm.size() != 1) { @@ -602,12 +591,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } } - event = new EventVO(); - event.setAccountId(volume.getAccountId()); - event.setUserId(1L); - event.setType(EventTypes.EVENT_VOLUME_ATTACH); - event.setState(Event.State.Completed); - event.setStartId(startEventId); if (!sendCommand || (answer != null && answer.getResult())) { // Mark the volume as attached if( sendCommand ) { @@ -615,13 +598,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } else { _volsDao.attachVolume(volume.getId(), vmId, deviceId); } - if(!vm.getName().equals(vm.getDisplayName())) { - event.setDescription("Volume: " +volume.getName()+ " successfully attached to VM: "+vm.getName()+"("+vm.getDisplayName()+")"); - } else { - event.setDescription("Volume: " +volume.getName()+ " successfully attached to VM: "+vm.getName()); - } - event.setLevel(EventVO.LEVEL_INFO); - _eventDao.persist(event); return _volsDao.findById(volumeId); } else { if (answer != null) { @@ -706,8 +682,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager throw new InvalidParameterValueException("Please specify a VM that is either running or stopped."); } - long eventId = EventUtils.saveScheduledEvent(1L, volume.getAccountId(), EventTypes.EVENT_VOLUME_DETACH, "detaching volume: "+volumeId+" from Vm: "+vmId); - AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); if(asyncExecutor != null) { AsyncJobVO job = asyncExecutor.getJob(); @@ -743,7 +717,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager event.setUserId(1L); event.setType(EventTypes.EVENT_VOLUME_DETACH); event.setState(Event.State.Completed); - event.setStartId(eventId); if (!sendCommand || (answer != null && answer.getResult())) { // Mark the volume as detached _volsDao.detachVolume(volume.getId()); @@ -826,32 +799,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager return false; } - EventVO event = new EventVO(); - event.setUserId(userId); - event.setAccountId(vm.getAccountId()); - event.setType(EventTypes.EVENT_VM_REBOOT); - event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId()); - if (vm.getState() == State.Running && vm.getHostId() != null) { RebootCommand cmd = new RebootCommand(vm.getInstanceName()); RebootAnswer answer = (RebootAnswer)_agentMgr.easySend(vm.getHostId(), cmd); if (answer != null) { - if(!vm.getName().equals(vm.getDisplayName())) { - event.setDescription("Successfully rebooted VM instance : " + vm.getName()+"("+vm.getDisplayName()+")"); - } else { - event.setDescription("Successfully rebooted VM instance : " + vm.getName()); - } - _eventDao.persist(event); return true; } else { - if(!vm.getName().equals(vm.getDisplayName())) { - event.setDescription("failed to reboot VM instance : " + vm.getName()+"("+vm.getDisplayName()+")"); - } else { - event.setDescription("failed to reboot VM instance : " + vm.getName()); - } - event.setLevel(EventVO.LEVEL_ERROR); - _eventDao.persist(event); return false; } } else { @@ -927,9 +881,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager "new service offering tags: " + newTags); } - // FIXME: save this eventId somewhere as part of the async process? - /*long eventId = */EventUtils.saveScheduledEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_UPGRADE, "upgrading Vm with Id: "+vmInstance.getId()); - UserVmVO vmForUpdate = _vmDao.createForUpdate(); vmForUpdate.setServiceOfferingId(serviceOfferingId); vmForUpdate.setHaEnabled(_serviceOfferingDao.findById(serviceOfferingId).getOfferHA()); @@ -1087,24 +1038,18 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager s_logger.debug("Destroying vm " + vmId); } - if (!stop(userId, vm, 0)) { - s_logger.error("Unable to stop vm so we can't destroy it: " + vmId); - return false; - } + long startEventId = EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+vmId); + if (!stop(userId, vm)) { + s_logger.error("Unable to stop vm so we can't destroy it: " + vmId); + EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, "Error stopping VM instance : " + vmId, startEventId); + return false; + } else { + EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_STOP, "Successfully stopped VM instance : " + vmId, startEventId); + } + Transaction txn = Transaction.currentTxn(); txn.start(); - EventVO event = new EventVO(); - event.setUserId(userId); - event.setAccountId(vm.getAccountId()); - event.setType(EventTypes.EVENT_VM_DESTROY); - event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId()); - if(!vm.getName().equals(vm.getDisplayName())) { - event.setDescription("Successfully destroyed VM instance : " + vm.getName()+"("+vm.getDisplayName()+")"); - } else { - event.setDescription("Successfully destroyed VM instance : " + vm.getName()); - } - _eventDao.persist(event); _accountMgr.decrementResourceCount(vm.getAccountId(), ResourceType.user_vm); @@ -1166,12 +1111,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager s_logger.debug("Recovering vm " + vmId); } - EventVO event = new EventVO(); - event.setUserId(1L); - event.setAccountId(vm.getAccountId()); - event.setType(EventTypes.EVENT_VM_CREATE); - event.setParameters("id="+vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId()); - Transaction txn = Transaction.currentTxn(); AccountVO account = null; txn.start(); @@ -1187,13 +1126,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (_accountMgr.resourceLimitExceeded(account, ResourceType.user_vm)) { ResourceAllocationException rae = new ResourceAllocationException("Maximum number of virtual machines for account: " + account.getAccountName() + " has been exceeded."); rae.setResourceType("vm"); - event.setLevel(EventVO.LEVEL_ERROR); - if(!vm.getName().equals(vm.getDisplayName())) { - event.setDescription("Failed to recover VM instance : " + vm.getName()+"("+vm.getDisplayName()+")" + "; the resource limit for account: " + account.getAccountName() + " has been exceeded."); - } else { - event.setDescription("Failed to recover VM instance : " + vm.getName() + "; the resource limit for account: " + account.getAccountName() + " has been exceeded."); - } - _eventDao.persist(event); txn.commit(); throw rae; } @@ -1232,14 +1164,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager _accountMgr.incrementResourceCount(account.getId(), ResourceType.volume, new Long(volumes.size())); - event.setLevel(EventVO.LEVEL_INFO); - if(!vm.getName().equals(vm.getDisplayName())) { - event.setDescription("successfully recovered VM instance : " + vm.getName()+"("+vm.getDisplayName()+")"); - } else { - event.setDescription("successfully recovered VM instance : " + vm.getName()); - } - _eventDao.persist(event); - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); _usageEventDao.persist(usageEvent); txn.commit(); @@ -1344,12 +1268,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager @Override public void completeStopCommand(UserVmVO instance) { - completeStopCommand(1L, instance, VirtualMachine.Event.AgentReportStopped, 0); + completeStopCommand(1L, instance, VirtualMachine.Event.AgentReportStopped); } @Override @DB - public void completeStopCommand(long userId, UserVmVO vm, VirtualMachine.Event e, long startEventId) { + public void completeStopCommand(long userId, UserVmVO vm, VirtualMachine.Event e) { Transaction txn = Transaction.currentTxn(); try { String vnet = vm.getVnet(); @@ -1378,20 +1302,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager throw new CloudRuntimeException("Error during stop: ", th); } - EventVO event = new EventVO(); - event.setUserId(userId); - event.setAccountId(vm.getAccountId()); - event.setType(EventTypes.EVENT_VM_STOP); - event.setState(Event.State.Completed); - event.setStartId(startEventId); - event.setParameters("id="+vm.getId() + "\n" + "vmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId()); - if(!vm.getName().equals(vm.getDisplayName())) { - event.setDescription("Successfully stopped VM instance : " + vm.getName()+"("+vm.getDisplayName()+")"); - } else { - event.setDescription("Successfully stopped VM instance : " + vm.getName()); - } - _eventDao.persist(event); - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_STOP, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); _usageEventDao.persist(usageEvent); @@ -1418,7 +1328,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } @Override - public UserVmVO start(long vmId, long startEventId) throws StorageUnavailableException, ConcurrentOperationException { + public UserVmVO start(long vmId) throws StorageUnavailableException, ConcurrentOperationException { return null; // FIXME start(1L, vmId, null, null, startEventId); } @@ -1428,11 +1338,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } @Override - public boolean stop(UserVmVO vm, long startEventId) { - return stop(1L, vm, startEventId); + public boolean stop(UserVmVO vm) { + return stop(1L, vm); } - private boolean stop(long userId, UserVmVO vm, long startEventId) { + private boolean stop(long userId, UserVmVO vm) { State state = vm.getState(); if (state == State.Stopped) { if (s_logger.isDebugEnabled()) { @@ -1456,13 +1366,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager return false; } - EventVO event = new EventVO(); - event.setUserId(userId); - event.setAccountId(vm.getAccountId()); - event.setType(EventTypes.EVENT_VM_STOP); - event.setStartId(startEventId); - event.setParameters("id="+vm.getId() + "\n" + "vmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId()); - StopCommand stop = new StopCommand(vm, vm.getInstanceName(), vm.getVnet()); boolean stopped = false; @@ -1480,16 +1383,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } if (stopped) { - completeStopCommand(userId, vm, VirtualMachine.Event.OperationSucceeded, 0); + completeStopCommand(userId, vm, VirtualMachine.Event.OperationSucceeded); } else { - if(!vm.getName().equals(vm.getDisplayName())) { - event.setDescription("failed to stop VM instance : " + vm.getName()+"("+vm.getDisplayName()+")"); - } else { - event.setDescription("failed to stop VM instance : " + vm.getName()); - } - event.setLevel(EventVO.LEVEL_ERROR); - _eventDao.persist(event); _itMgr.stateTransitTo(vm, VirtualMachine.Event.OperationFailed, vm.getHostId()); s_logger.error("Unable to stop vm " + vm.getName()); } @@ -1839,11 +1735,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager true, hyperType); - // FIXME: scheduled events should get saved when the command is actually scheduled, not when it starts executing, need another callback - // for when the command is scheduled? Could this fit into the setup / execute / response lifecycle? Right after setup you would - // know your job is being scheduled, so you could save this kind of event in setup after verifying params. - /*long eventId = */EventUtils.saveScheduledEvent(userId, volume.getAccountId(), EventTypes.EVENT_TEMPLATE_CREATE, "creating template" +name); - return _templateDao.persist(privateTemplate); } @@ -2110,7 +2001,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager _vmDao.updateVM(id, displayName, ha); // create a event for the change in HA Enabled flag - EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, EventTypes.EVENT_VM_UPDATE, "Successfully updated virtual machine: "+vm.getName()+". "+description, null); + EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, EventTypes.EVENT_VM_UPDATE, "Successfully updated virtual machine: "+vm.getName()+". "+description); return _vmDao.findById(id); } @@ -2138,15 +2029,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager userId = accountAndUserValidation(vmId, account, userId, vmInstance); - EventUtils.saveScheduledEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_REBOOT, "Rebooting Vm with Id: "+vmId); - boolean status = rebootVirtualMachine(userId, vmId); if (status) { - EventUtils.saveEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_REBOOT, "Successfully rebooted vm with id:"+vmId); return _vmDao.findById(vmId); } else { - EventUtils.saveEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_REBOOT, "Failed to reboot vm with id:"+vmId); throw new CloudRuntimeException("Failed to reboot vm with id: " + vmId); } } @@ -2676,7 +2563,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); } - long eventId = EventUtils.saveScheduledEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+ vmId); userId = accountAndUserValidation(vmId, caller, userId, vm); UserVO user = _userDao.findById(userId); @@ -2714,8 +2600,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find a virtual machine with id " + vmId); } - long eventId = EventUtils.saveScheduledEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_START, "Starting Vm with Id: "+vmId); - userId = accountAndUserValidation(vmId, account, userId, vm); UserVO user = _userDao.findById(userId); VolumeVO disk = _volsDao.findByInstance(vmId).get(0); @@ -2737,18 +2621,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager userId = accountAndUserValidation(vmId, account, userId, vm); User caller = _userDao.findById(userId); - EventUtils.saveScheduledEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Destroying Vm with Id: "+vmId); - boolean status; status = _itMgr.destroy(vm, caller, account); if (status) { - EventUtils.saveEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Successfully destroyed vm with id:"+vmId); UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); _usageEventDao.persist(usageEvent); return _vmDao.findById(vmId); } else { - EventUtils.saveEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Failed to destroy vm with id:"+vmId); throw new CloudRuntimeException("Failed to destroy vm with id " + vmId); } } diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java index 31a49beda1b..3478465e612 100644 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ b/server/src/com/cloud/vm/VirtualMachineGuru.java @@ -111,7 +111,7 @@ public interface VirtualMachineGuru { * @throws ExecutionException * @throws ResourceUnavailableException */ - T start(long vmId, long startEventId) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException; + T start(long vmId) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException; /** * stop the vm @@ -120,7 +120,7 @@ public interface VirtualMachineGuru { * @return true if stopped and false if not. * @throws AgentUnavailableException if the agent is unavailable. */ - boolean stop(T vm, long startEventId) throws AgentUnavailableException; + boolean stop(T vm) throws AgentUnavailableException; /** * Produce a cleanup command to be sent to the agent to cleanup anything diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 0d1d93bb1f6..36e966b8517 100644 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -50,6 +50,7 @@ import com.cloud.deploy.DeploymentPlanner; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.domain.dao.DomainDao; import com.cloud.event.EventTypes; +import com.cloud.event.EventUtils; import com.cloud.event.EventVO; import com.cloud.event.UsageEventVO; import com.cloud.event.dao.UsageEventDao; @@ -59,18 +60,17 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; -import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.HypervisorGuru; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.stateListener.VMStateListener; import com.cloud.storage.DiskOfferingVO; -import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageManager; import com.cloud.storage.VMTemplateVO; -import com.cloud.storage.VolumeVO; +import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Volume.VolumeType; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.user.Account; @@ -260,10 +260,15 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster if (s_logger.isDebugEnabled()) { s_logger.debug("Destroying vm " + vm); } + long userId = caller.getId(); + long startEventId = EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+vm.getId()); if (!stop(vm, caller, account)) { s_logger.error("Unable to stop vm so we can't destroy it: " + vm); + EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, "Error stopping VM instance : " + vm.getId(), startEventId); return false; + } else { + EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_STOP, "Successfully stopped VM instance : " + vm.getId(), startEventId); } //Clean up volumes based on the vm's instance id @@ -504,13 +509,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster String reservationId = vm.getReservationId(); - EventVO event = new EventVO(); - event.setUserId(user.getId()); - event.setAccountId(vm.getAccountId()); - event.setType(EventTypes.EVENT_VM_STOP); - event.setStartId(1); // FIXME: - event.setParameters("id="+vm.getId() + "\n" + "vmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId()); - StopCommand stop = new StopCommand(vm, vm.getInstanceName(), null); boolean stopped = false;