public static Long onCompletedActionEvent(Long userId, Long accountId, String level, String type, String description, long startEventId) { return onCompletedActionEvent(userId, accountId, level, type, true, description, startEventId); }
if(param != null){ try { entityUuid = getEntityUuid(entityClass, param); entityType = entityClass.getName(); } catch (Exception e){ eventDescription.put("entityuuid", entityUuid); populateFirstClassEntities(eventDescription); eventDescription.put("description", description);
@Override public void logoutUser(long userId) { UserAccount userAcct = _userAccountDao.findById(userId); if (userAcct != null) { ActionEventUtils.onActionEvent(userId, userAcct.getAccountId(), userAcct.getDomainId(), EventTypes.EVENT_USER_LOGOUT, "user has logged out"); } // else log some kind of error event? This likely means the user doesn't exist, or has been deleted... }
@Override public void interceptException(Method method, Object target, Object event) { for (ActionEvent actionEvent : getActionEvents(method)) { CallContext ctx = CallContext.current(); long userId = ctx.getCallingUserId(); long accountId = ctx.getCallingAccountId(); long startEventId = ctx.getStartEventId(); String eventDescription = getEventDescription(actionEvent, ctx); String eventType = getEventType(actionEvent, ctx); boolean isEventDisplayEnabled = ctx.isEventDisplayEnabled(); if (eventType.equals("")) return; if (actionEvent.create()) { long eventId = ActionEventUtils.onCreatedActionEvent(userId, accountId, EventVO.LEVEL_ERROR, eventType, isEventDisplayEnabled, "Error while creating entity for " + eventDescription); ctx.setStartEventId(eventId); } else { ActionEventUtils.onCompletedActionEvent(userId, accountId, EventVO.LEVEL_ERROR, eventType, isEventDisplayEnabled, "Error while " + eventDescription, startEventId); } } }
public static void onStartedActionEventFromContext(String eventType, String eventDescription, boolean eventDisplayEnabled) { CallContext ctx = CallContext.current(); long userId = ctx.getCallingUserId(); long accountId = ctx.getProject() != null ? ctx.getProject().getProjectAccountId() : ctx.getCallingAccountId(); //This should be the entity owner id rather than the Calling User Account Id. long startEventId = ctx.getStartEventId(); if (!eventType.equals("")) ActionEventUtils.onStartedActionEvent(userId, accountId, eventType, eventDescription, eventDisplayEnabled, startEventId); }
ActionEventUtils.onScheduledActionEvent(User.UID_SYSTEM, volume.getAccountId(), EventTypes.EVENT_SNAPSHOT_CREATE, "creating snapshot for volume Id:" + volumeId, true, 0);
private static void populateFirstClassEntities(Map<String, String> eventDescription){ CallContext context = CallContext.current(); Map<Object, Object> contextMap = context.getContextParameters(); for(Map.Entry<Object, Object> entry : contextMap.entrySet()){ try{ Class<?> clz = (Class<?>)entry.getKey(); if(clz != null && Identity.class.isAssignableFrom(clz)){ String uuid = getEntityUuid(clz, entry.getValue()); eventDescription.put(ReflectUtil.getEntityName(clz), uuid); } } catch (Exception e){ s_logger.trace("Caught exception while populating first class entities for event bus, moving on"); } } }
private static Event persistActionEvent(Long userId, Long accountId, Long domainId, String level, String type, Event.State state, boolean eventDisplayEnabled, String description, Long startEventId) { EventVO event = new EventVO(); event.setUserId(userId); event.setAccountId(accountId); event.setType(type); event.setState(state); event.setDescription(description); event.setDisplay(eventDisplayEnabled); if (domainId != null) { event.setDomainId(domainId); } else { event.setDomainId(getDomainId(accountId)); } if (level != null && !level.isEmpty()) { event.setLevel(level); } if (startEventId != null) { event.setStartId(startEventId); } event = s_eventDao.persist(event); return event; }
@Override public void interceptComplete(Method method, Object target, Object event) { for (ActionEvent actionEvent : getActionEvents(method)) { CallContext ctx = CallContext.current(); long userId = ctx.getCallingUserId(); long accountId = ctx.getProject() != null ? ctx.getProject().getProjectAccountId() : ctx.getCallingAccountId(); //This should be the entity owner id rather than the Calling User Account Id. long startEventId = ctx.getStartEventId(); String eventDescription = getEventDescription(actionEvent, ctx); String eventType = getEventType(actionEvent, ctx); boolean isEventDisplayEnabled = ctx.isEventDisplayEnabled(); if (eventType.equals("")) return; if (actionEvent.create()) { //This start event has to be used for subsequent events of this action startEventId = ActionEventUtils.onCreatedActionEvent(userId, accountId, EventVO.LEVEL_INFO, eventType, isEventDisplayEnabled, "Successfully created entity for " + eventDescription); ctx.setStartEventId(startEventId); } else { ActionEventUtils.onCompletedActionEvent(userId, accountId, EventVO.LEVEL_INFO, eventType, isEventDisplayEnabled, "Successfully completed " + eventDescription, startEventId); } } }
ActionEventUtils.onStartedActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(), EventTypes.EVENT_MAINTENANCE_PREPARE, "starting maintenance for host " + hostId, true, 0); _agentMgr.pullAgentToMaintenance(hostId); setHostMaintenanceRetries(host);
ActionEventUtils.onScheduledActionEvent((callerUserId == null) ? (Long)User.UID_SYSTEM : callerUserId, asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(), asyncCmd.getEventDescription(), asyncCmd.isDisplay(), startEventId); if (startEventId == 0) {
/** * Log and persist event for direct download failure */ private void logUsageEvent(VMTemplateVO template, long poolId) { String event = EventTypes.EVENT_TEMPLATE_DIRECT_DOWNLOAD_FAILURE; if (template.getFormat() == ImageFormat.ISO) { event = EventTypes.EVENT_ISO_DIRECT_DOWNLOAD_FAILURE; } String description = "Direct Download for template Id: " + template.getId() + " on pool Id: " + poolId + " failed"; s_logger.error(description); ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), template.getAccountId(), EventVO.LEVEL_INFO, event, description, 0); }
ActionEventUtils.onActionEvent(user.getId(), user.getAccountId(), user.getDomainId(), EventTypes.EVENT_USER_LOGIN, "user has logged in from IP Address " + loginIpAddress);
protected void allocateVnetComplete(Network network, NetworkVO implemented, long dcId, long physicalNetworkId, String reservationId, String vnet) { //TODO(VXLAN): Add new event type for vxlan? ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone vNet: " + vnet + " Network Id: " + network.getId(), 0); }
public boolean transitionHAState(final HAConfig.Event event, final HAConfig haConfig) { if (event == null || haConfig == null) { return false; } final HAConfig.HAState currentHAState = haConfig.getState(); try { final HAConfig.HAState nextState = HAConfig.HAState.getStateMachine().getNextState(currentHAState, event); boolean result = HAConfig.HAState.getStateMachine().transitTo(haConfig, event, null, haConfigDao); if (result) { final String message = String.format("Transitioned host HA state from:%s to:%s due to event:%s for the host id:%d", currentHAState, nextState, event, haConfig.getResourceId()); if (LOG.isTraceEnabled()) { LOG.trace(message); } if (nextState == HAConfig.HAState.Recovering || nextState == HAConfig.HAState.Fencing || nextState == HAConfig.HAState.Fenced) { ActionEventUtils.onActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(), Domain.ROOT_DOMAIN, EventTypes.EVENT_HA_STATE_TRANSITION, message); } } return result; } catch (NoTransitionException e) { if (LOG.isTraceEnabled()) { LOG.trace("Unable to find next HA state for current HA state: " + currentHAState + " for event: " + event + " for host" + haConfig.getResourceId()); } } return false; }
/** * Safely transit host into Maintenance mode */ protected boolean setHostIntoMaintenance(HostVO host) throws NoTransitionException { s_logger.debug("Host " + host.getUuid() + " entering in Maintenance"); resourceStateTransitTo(host, ResourceState.Event.InternalEnterMaintenance, _nodeId); ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_MAINTENANCE_PREPARE, "completed maintenance for host " + host.getId(), 0); return true; }
private boolean transitionPowerState(OutOfBandManagement.PowerState.Event event, OutOfBandManagement outOfBandManagementHost) { if (outOfBandManagementHost == null) { return false; } OutOfBandManagement.PowerState currentPowerState = outOfBandManagementHost.getPowerState(); try { OutOfBandManagement.PowerState newPowerState = OutOfBandManagement.PowerState.getStateMachine().getNextState(currentPowerState, event); boolean result = OutOfBandManagement.PowerState.getStateMachine().transitTo(outOfBandManagementHost, event, null, outOfBandManagementDao); if (result) { final String message = String.format("Transitioned out-of-band management power state from:%s to:%s due to event:%s for the host id:%d", currentPowerState, newPowerState, event, outOfBandManagementHost.getHostId()); LOG.debug(message); if (newPowerState == OutOfBandManagement.PowerState.Unknown) { ActionEventUtils.onActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(), Domain.ROOT_DOMAIN, EventTypes.EVENT_HOST_OUTOFBAND_MANAGEMENT_POWERSTATE_TRANSITION, message); } } return result; } catch (NoTransitionException ignored) { LOG.trace(String.format("Unable to transition out-of-band management power state for host id=%s for the event=%s and current power state=%s", outOfBandManagementHost.getHostId(), event, currentPowerState)); } return false; }
private void postCreateRecurringSnapshotForPolicy(long userId, long volumeId, long snapshotId, long policyId) { // Use count query SnapshotVO spstVO = _snapshotDao.findById(snapshotId); Type type = spstVO.getRecurringType(); int maxSnaps = type.getMax(); List<SnapshotVO> snaps = listSnapsforVolumeTypeNotDestroyed(volumeId, type); SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId); if (policy != null && policy.getMaxSnaps() < maxSnaps) { maxSnaps = policy.getMaxSnaps(); } while (snaps.size() > maxSnaps && snaps.size() > 1) { SnapshotVO oldestSnapshot = snaps.get(0); long oldSnapId = oldestSnapshot.getId(); if (policy != null) { s_logger.debug("Max snaps: " + policy.getMaxSnaps() + " exceeded for snapshot policy with Id: " + policyId + ". Deleting oldest snapshot: " + oldSnapId); } if (deleteSnapshot(oldSnapId)) { //log Snapshot delete event ActionEventUtils.onCompletedActionEvent(User.UID_SYSTEM, oldestSnapshot.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_SNAPSHOT_DELETE, "Successfully deleted oldest snapshot: " + oldSnapId, 0); } snaps.remove(oldestSnapshot); } }
vmIdCountMap.remove(nicId); decrementCount = false; ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, Domain.ROOT_DOMAIN, EventTypes.EVENT_NETWORK_EXTERNAL_DHCP_VM_IPFETCH, "VM " + vmId + " nic id " + nicId + " ip address " + vmIp + " got fetched successfully");
@Override public void shutdown(final NetworkProfile profile, final NetworkOffering offering) { if (profile.getBroadcastUri() == null) { return; // Nothing to do here if the uri is null already } if ((profile.getBroadcastDomainType() == BroadcastDomainType.Vlan || profile.getBroadcastDomainType() == BroadcastDomainType.Vxlan) && !offering.isSpecifyVlan()) { s_logger.debug("Releasing vnet for the network id=" + profile.getId()); _dcDao.releaseVnet(BroadcastDomainType.getValue(profile.getBroadcastUri()), profile.getDataCenterId(), profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId()); ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), profile.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_RELEASE, "Released Zone Vnet: " + BroadcastDomainType.getValue(profile.getBroadcastUri()) + " for Network: " + profile.getId(), 0); } profile.setBroadcastUri(null); }