diff --git a/api/src/com/cloud/network/VirtualNetworkApplianceService.java b/api/src/com/cloud/network/VirtualNetworkApplianceService.java index a3db2ffc253..ab7aaae7534 100644 --- a/api/src/com/cloud/network/VirtualNetworkApplianceService.java +++ b/api/src/com/cloud/network/VirtualNetworkApplianceService.java @@ -53,7 +53,7 @@ public interface VirtualNetworkApplianceService { * @throws ResourceUnavailableException * @throws InvalidParameterValueException, PermissionDeniedException */ - VirtualRouter stopRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException; + VirtualRouter stopDomainRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException; /** * Reboots domain router diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index ce82d1322dc..e0ce0d848eb 100644 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -78,8 +78,8 @@ import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; 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; @@ -344,6 +344,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx try { if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { + long accountId = proxy.getAccountId(); + long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, accountId, EventTypes.EVENT_PROXY_START, "Starting proxy : " + proxy.getName()); proxy = startProxy(proxyVmId); if (proxy == null) { @@ -365,6 +367,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"); } + EventUtils.saveEvent(User.UID_SYSTEM, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_PROXY_START, "Failed to start console proxy", startEventId); destroyProxy(proxyVmId); return null; } else { @@ -372,6 +375,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.trace("Console proxy " + proxy.getName() + " is started"); } + EventUtils.saveEvent(User.UID_SYSTEM, accountId, EventVO.LEVEL_INFO, EventTypes.EVENT_PROXY_START, "Started console proxy: "+proxy.getName(), startEventId); // if it is a new assignment or a changed assignment, // update the // record @@ -644,6 +648,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId); } + long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_CREATE, "Creating console proxy"); Map context = createProxyInstance(dataCenterId); long proxyVmId = (Long) context.get("proxyVmId"); @@ -651,13 +656,14 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (s_logger.isTraceEnabled()) { s_logger.trace("Creating proxy instance failed, data center id : " + dataCenterId); } - + EventUtils.saveEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventVO.LEVEL_ERROR, EventTypes.EVENT_PROXY_CREATE, "console proxy creation failed", startEventId); return null; } ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId); // allocProxyStorage(dataCenterId, proxyVmId); if (proxy != null) { + EventUtils.saveEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventVO.LEVEL_INFO, EventTypes.EVENT_PROXY_CREATE, "Succesfully created console proxy", startEventId); SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATED, dataCenterId, proxy.getId(), proxy, null)); return proxy; @@ -671,7 +677,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATE_FAILURE, dataCenterId, proxyVmId, null, "Unable to allocate storage")); - + EventUtils.saveEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventVO.LEVEL_ERROR, EventTypes.EVENT_PROXY_CREATE, "console proxy creation failed", startEventId); destroyProxyDBOnly(proxyVmId); } return null; @@ -1254,6 +1260,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (proxy != null) { long proxyVmId = proxy.getId(); GlobalLock proxyLock = GlobalLock.getInternLock(getProxyLockName(proxyVmId)); + long accountId = proxy.getAccountId(); + long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, accountId, EventTypes.EVENT_PROXY_START, "Starting proxy : " + proxy.getName()); try { if (proxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { @@ -1276,7 +1284,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx s_logger.info("Unable to start console proxy for standby capacity, proxy vm Id : " + proxyVmId + ", will recycle it and start a new one"); } - + EventUtils.saveEvent(User.UID_SYSTEM, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_PROXY_START, "Failed to start console proxy", startEventId); + if (proxyFromStoppedPool) { destroyProxy(proxyVmId); } @@ -1284,6 +1293,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx if (s_logger.isInfoEnabled()) { s_logger.info("Console proxy " + proxy.getName() + " is started"); } + + EventUtils.saveEvent(User.UID_SYSTEM, accountId, EventVO.LEVEL_INFO, EventTypes.EVENT_PROXY_START, "Started console proxy: "+proxy.getName(), startEventId); } } } @@ -1505,11 +1516,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx return false; } - /* - * saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, - * EventTypes.EVENT_PROXY_REBOOT, "Rebooting console proxy with Id: " + - * proxyVmId, startEventId); - */ if (proxy.getState() == State.Running && proxy.getHostId() != null) { final RebootCommand cmd = new RebootCommand(proxy.getInstanceName()); final Answer answer = _agentMgr.easySend(proxy.getHostId(), cmd); @@ -1526,28 +1532,12 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_REBOOTED, proxy.getDataCenterId(), proxy.getId(), proxy, null)); - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_PROXY_REBOOT); - event.setLevel(EventVO.LEVEL_INFO); - // event.setStartId(startEventId); - event.setDescription("Console proxy rebooted - " + proxy.getName()); - _eventDao.persist(event); return true; } else { if (s_logger.isDebugEnabled()) { s_logger.debug("failed to reboot console proxy : " + proxy.getName()); } - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_PROXY_REBOOT); - event.setLevel(EventVO.LEVEL_ERROR); - // event.setStartId(startEventId); - event.setDescription("Rebooting console proxy failed - " + proxy.getName()); - _eventDao.persist(event); return false; } } else { @@ -1580,11 +1570,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx } return true; } - /* - * saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, - * EventTypes.EVENT_PROXY_DESTROY, "Destroying console proxy with Id: " - * + vmId, startEventId); - */ + if (s_logger.isDebugEnabled()) { s_logger.debug("Destroying console proxy vm " + vmId); } @@ -1615,15 +1601,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx _consoleProxyDao.remove(vm.getId()); - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_PROXY_DESTROY); - event.setLevel(EventVO.LEVEL_INFO); - //event.setStartId(startEventId); - event.setDescription("Console proxy destroyed - " + vm.getName()); - _eventDao.persist(event); - txn.commit(); } catch (Exception e) { s_logger.error("Caught this error: ", e); @@ -1650,13 +1627,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx _consoleProxyDao.remove(vmId); - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_PROXY_DESTROY); - event.setLevel(EventVO.LEVEL_INFO); - event.setDescription("Console proxy destroyed - " + proxy.getName()); - _eventDao.persist(event); } txn.commit(); @@ -1696,15 +1666,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx StopAnswer answer = (StopAnswer) _agentMgr.send(proxyHostId, cmd); if (answer == null || !answer.getResult()) { s_logger.debug("Unable to stop due to " + (answer == null ? "answer is null" : answer.getDetails())); - - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_PROXY_STOP); - event.setLevel(EventVO.LEVEL_ERROR); - //event.setStartId(startEventId); - event.setDescription("Stopping console proxy failed due to negative answer from agent - " + proxy.getName()); - _eventDao.persist(event); return false; } completeStopCommand(proxy, VirtualMachine.Event.OperationSucceeded); @@ -1714,25 +1675,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_DOWN, proxy.getDataCenterId(), proxy.getId(), proxy, null)); - - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_PROXY_STOP); - event.setLevel(EventVO.LEVEL_INFO); - //event.setStartId(startEventId); - event.setDescription("Console proxy stopped - " + proxy.getName()); - _eventDao.persist(event); return true; } catch (OperationTimedoutException e) { - final EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(Account.ACCOUNT_ID_SYSTEM); - event.setType(EventTypes.EVENT_PROXY_STOP); - event.setLevel(EventVO.LEVEL_ERROR); - //event.setStartId(startEventId); - event.setDescription("Stopping console proxy failed due to operation time out - " + proxy.getName()); - _eventDao.persist(event); throw new AgentUnavailableException(proxy.getHostId()); } } finally { @@ -1858,21 +1802,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx return "consoleproxy." + id; } - private Long saveStartedEvent(Long userId, Long accountId, String type, String description, long startEventId) { - EventVO event = new EventVO(); - event.setUserId(userId); - event.setAccountId(accountId); - event.setType(type); - event.setState(Event.State.Started); - event.setDescription(description); - event.setStartId(startEventId); - event = _eventDao.persist(event); - if (event != null) { - return event.getId(); - } - return null; - } - @Override public boolean configure(String name, Map params) throws ConfigurationException { if (s_logger.isInfoEnabled()) { diff --git a/server/src/com/cloud/network/element/DhcpElement.java b/server/src/com/cloud/network/element/DhcpElement.java index b5a123ec3b2..6ec43fc3862 100644 --- a/server/src/com/cloud/network/element/DhcpElement.java +++ b/server/src/com/cloud/network/element/DhcpElement.java @@ -113,7 +113,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement{ if (router == null) { return true; } - return _routerMgr.stopRouter(router.getId(), 1); + return _routerMgr.stopRouter(router.getId()); } @Override diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index 3a2a01e66c7..f5ef8de72eb 100644 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -124,7 +124,7 @@ public class VirtualRouterElement extends AdapterBase implements NetworkElement if (router == null) { return true; } - return _routerMgr.stopRouter(router.getId(), 1); + return _routerMgr.stopRouter(router.getId()); } @Override diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index 7b674748297..b627335d58a 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -68,7 +68,7 @@ public interface VirtualNetworkApplianceManager extends Manager { boolean destroyRouter(long routerId); - boolean stopRouter(long routerId, long eventId); + boolean stopRouter(long routerId); boolean getRouterStatistics(long vmId, Map netStats, Map diskStats); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index f6aeb987074..df0cc944ce1 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -345,15 +345,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return false; } - EventVO event = new EventVO(); - event.setUserId(User.UID_SYSTEM); - event.setAccountId(router.getAccountId()); - event.setType(EventTypes.EVENT_ROUTER_DESTROY); - event.setState(Event.State.Started); - event.setParameters("id=" + routerId); - event.setDescription("Starting to destroy router : " + router.getName()); - event = _eventDao.persist(event); - try { if (router.getState() == State.Destroyed || router.getState() == State.Expunging || router.getRemoved() != null) { if (s_logger.isDebugEnabled()) { @@ -362,10 +353,15 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return true; } + long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, router.getAccountId(), EventTypes.EVENT_ROUTER_STOP, "Starting to stop router : " + router.getName()); if (!stop(router)) { s_logger.debug("Unable to stop the router: " + routerId); + EventUtils.saveEvent(User.UID_SYSTEM, router.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ROUTER_STOP, "Unable to stop router: " + router.getName(), startEventId); return false; + } else { + EventUtils.saveEvent(User.UID_SYSTEM, router.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ROUTER_STOP, "successfully stopped router : " + router.getName(), startEventId); } + router = _routerDao.findById(routerId); if (!_itMgr.stateTransitTo(router, VirtualMachine.Event.DestroyRequested, router.getHostId())) { s_logger.debug("VM " + router.toString() + " is not in a state to be destroyed."); @@ -390,15 +386,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.debug("Successfully destroyed router: " + routerId); } - EventVO completedEvent = new EventVO(); - completedEvent.setUserId(User.UID_SYSTEM); - completedEvent.setAccountId(router.getAccountId()); - completedEvent.setType(EventTypes.EVENT_ROUTER_DESTROY); - completedEvent.setStartId(event.getId()); - completedEvent.setParameters("id=" + routerId); - completedEvent.setDescription("successfully destroyed router : " + router.getName()); - _eventDao.persist(completedEvent); - return true; } @@ -619,7 +606,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } @Override - public boolean stopRouter(final long routerId, long eventId) { + public boolean stopRouter(final long routerId) { AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor(); if (asyncExecutor != null) { AsyncJobVO job = asyncExecutor.getJob(); @@ -633,15 +620,23 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (s_logger.isDebugEnabled()) { s_logger.debug("Stopping router " + routerId); } - - return stop(_routerDao.findById(routerId)); + DomainRouterVO router = _routerDao.findById(routerId); + long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, router.getAccountId(), EventTypes.EVENT_ROUTER_STOP, "Starting to stop router : " + router.getName()); + if (!stop(router)) { + s_logger.debug("Unable to stop the router: " + routerId); + EventUtils.saveEvent(User.UID_SYSTEM, router.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ROUTER_STOP, "Unable to stop router: " + router.getName(), startEventId); + return false; + } else { + EventUtils.saveEvent(User.UID_SYSTEM, router.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ROUTER_STOP, "successfully stopped router : " + router.getName(), startEventId); + return true; + } } @Override public VirtualRouter stopRouter(StopRouterCmd cmd) throws InvalidParameterValueException, PermissionDeniedException, ResourceUnavailableException, ConcurrentOperationException { if (_useNewNetworking) { - return stopRouter(cmd.getId()); + return stopDomainRouter(cmd.getId()); } Long routerId = cmd.getId(); Account account = UserContext.current().getAccount(); @@ -656,7 +651,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian throw new PermissionDeniedException("Unable to stop router with id " + routerId + ". Permission denied"); } - boolean success = stopRouter(routerId, 0); + boolean success = stopRouter(routerId); if (success) { return _routerDao.findById(routerId); @@ -1208,7 +1203,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.info("Found " + ids.size() + " routers to stop. "); for (final Long id : ids) { - stopRouter(id, 0); + stopRouter(id); } s_logger.info("Done my job. Time to rest."); } catch (Exception e) { @@ -1314,6 +1309,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian DomainRouterVO router = _routerDao.findByNetworkConfiguration(guestNetwork.getId()); if (router == null) { + long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, owner.getId(), EventTypes.EVENT_ROUTER_CREATE, "Starting to create router for accountId : " +owner.getAccountId()); long id = _routerDao.getNextInSequence(Long.class, "id"); if (s_logger.isDebugEnabled()) { s_logger.debug("Creating the router " + id); @@ -1357,9 +1353,26 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), _template.getId(), _template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), _offering.getOfferHA()); router = _itMgr.allocate(router, _template, _offering, networks, plan, null, owner); + if(router != null){ + EventUtils.saveEvent(User.UID_SYSTEM, owner.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ROUTER_CREATE, "successfully create router : " + router.getName(), startEventId); + } else { + EventUtils.saveEvent(User.UID_SYSTEM, owner.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ROUTER_CREATE, "router creation failed", startEventId); + } + } - return _itMgr.start(router, null, _accountService.getSystemUser(), _accountService.getSystemAccount(), null); + + State state = router.getState(); + if (state != State.Starting && state != State.Running) { + long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, owner.getId(), EventTypes.EVENT_ROUTER_START, "Starting router : " +router.getName()); + router = _itMgr.start(router, null, _accountService.getSystemUser(), _accountService.getSystemAccount(), null); + if(router != null){ + EventUtils.saveEvent(User.UID_SYSTEM, owner.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ROUTER_START, "successfully started router : " + router.getName(), startEventId); + } else { + EventUtils.saveEvent(User.UID_SYSTEM, owner.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ROUTER_START, "failed to start router", startEventId); + } + } + return router; } @Override @@ -1377,6 +1390,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian DomainRouterVO router = _routerDao.findByNetworkConfiguration(guestNetwork.getId()); if (router == null) { + long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, owner.getId(), EventTypes.EVENT_ROUTER_CREATE, "Starting to create router for accountId : " +owner.getAccountId()); long id = _routerDao.getNextInSequence(Long.class, "id"); if (s_logger.isDebugEnabled()) { s_logger.debug("Creating the router " + id); @@ -1396,9 +1410,23 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), _offering.getOfferHA()); router.setRole(Role.DHCP_USERDATA); router = _itMgr.allocate(router, _template, _offering, networks, plan, null, owner); + if(router != null){ + EventUtils.saveEvent(User.UID_SYSTEM, owner.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ROUTER_CREATE, "successfully create router : " + router.getName(), startEventId); + } else { + EventUtils.saveEvent(User.UID_SYSTEM, owner.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ROUTER_CREATE, "router creation failed", startEventId); + } } - - return _itMgr.start(router, null, _accountService.getSystemUser(), _accountService.getSystemAccount(), null); + State state = router.getState(); + if (state != State.Starting && state != State.Running) { + long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, owner.getId(), EventTypes.EVENT_ROUTER_START, "Starting router : " +router.getName()); + router = _itMgr.start(router, null, _accountService.getSystemUser(), _accountService.getSystemAccount(), null); + if(router != null){ + EventUtils.saveEvent(User.UID_SYSTEM, owner.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ROUTER_START, "successfully started router : " + router.getName(), startEventId); + } else { + EventUtils.saveEvent(User.UID_SYSTEM, owner.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ROUTER_START, "failed to start router", startEventId); + } + } + return router; } @Override @@ -1757,7 +1785,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian * , PermissionDeniedException */ @Override - public VirtualRouter stopRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException { + public VirtualRouter stopDomainRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException { UserContext context = UserContext.current(); Account account = context.getAccount(); long accountId = account.getId(); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 30f16a5eb3e..4d7b328e105 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -4219,9 +4219,6 @@ public class ManagementServerImpl implements ManagementServer { @Override public VirtualMachine startSystemVm(long vmId) { - UserContext context = UserContext.current(); - long callerId = context.getUserId(); - long callerAccountId = context.getAccount().getId(); VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(vmId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); if (systemVm == null) { @@ -4239,10 +4236,6 @@ public class ManagementServerImpl implements ManagementServer { @Override public VirtualMachine stopSystemVm(long vmId) { - UserContext context = UserContext.current(); - - long callerId = context.getUserId(); - long callerAccountId = context.getAccount().getId(); // verify parameters VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(vmId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 0af65909b17..d279520aebd 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -2360,7 +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)) { - if(!_routerMgr.stopRouter(vmInstance.getId(), 0)) + if(!_routerMgr.stopRouter(vmInstance.getId())) { String errorMsg = "There was an error stopping the domain router id: "+vmInstance.getId()+" ,cannot enable primary storage maintenance"; s_logger.warn(errorMsg); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 86222d06ec8..0872d8888cf 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -819,7 +819,7 @@ 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); + long startEventId = EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Destroyed VM instance : " + vm.getName()); if (!_vmMgr.destroyVirtualMachine(userId, vm.getId())) { s_logger.error("Unable to destroy vm: " + vm.getId()); accountCleanupNeeded = true; @@ -846,9 +846,13 @@ public class AccountManagerImpl implements AccountManager, AccountService { boolean routersCleanedUp = true; for (DomainRouterVO router : routers) { + long startEventId = EventUtils.saveStartedEvent(userId, router.getAccountId(), EventTypes.EVENT_ROUTER_DESTROY, "Starting to destroy router : " + router.getName()); if (!_routerMgr.destroyRouter(router.getId())) { s_logger.error("Unable to destroy router: " + router.getId()); routersCleanedUp = false; + EventUtils.saveEvent(userId, router.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ROUTER_DESTROY, "Unable to destroy router: " + router.getName(), startEventId); + } else { + EventUtils.saveEvent(userId, router.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ROUTER_DESTROY, "successfully destroyed router : " + router.getName(), startEventId); } } @@ -967,7 +971,7 @@ public class AccountManagerImpl implements AccountManager, AccountService { List routers = _routerDao.listBy(accountId); for (DomainRouterVO router : routers) { - success = (success && _routerMgr.stopRouter(router.getId(), 0)); + success = (success && _routerMgr.stopRouter(router.getId())); } return success;