/** * Simple call to {@link CallContext#current()} to retrieve the current calling account. * This method facilitates unit testing, it avoids mocking static methods. */ protected Account getCurrentAccount() { return CallContext.current().getCallingAccount(); }
@Override public boolean revokeIngressFirewallRule(long ruleId, boolean apply) { Account caller = CallContext.current().getCallingAccount(); long userId = CallContext.current().getCallingUserId(); return revokeFirewallRule(ruleId, apply, caller, userId); }
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); }
private Long getSnapshotUserId() { Long userId = CallContext.current().getCallingUserId(); if (userId == null) { return User.UID_SYSTEM; } return userId; }
@Override public void execute() throws ResourceUnavailableException { CallContext.current().setEventDetails("Rule Id: " + id); boolean result = _firewallService.revokeEgressFirewallRule(id, true); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete egress firewall rule"); } }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { final DataCenter dataCenter = _resourceService.getZone(getZoneId()); if (dataCenter == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find zone by ID: " + getZoneId()); } final boolean result = haConfigManager.enableHA(dataCenter); CallContext.current().setEventDetails("Zone Id:" + dataCenter.getId() + " HA enabled: true"); CallContext.current().putContextParameter(DataCenter.class, dataCenter.getUuid()); setupResponse(result); }
@Override public void execute() throws ConcurrentOperationException { CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getId())); boolean result = _volumeService.deleteVolume(id, CallContext.current().getCallingAccount()); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete volume"); } } }
/** * 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; }
@Override public String toString() { return new StringBuilder("CCtxt[acct=").append(getCallingAccountId()) .append("; user=") .append(getCallingUserId()) .append("; id=") .append(contextId) .append("]") .toString(); } }
@Override public void execute() throws ResourceUnavailableException, ConcurrentOperationException { CallContext.current().setEventDetails("Network ACL Id: " + id); boolean result = _vpcService.deleteVpcPrivateGateway(id); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete private gateway"); } }
public long getAutoscaleUserId() { if (autoscaleUserId != null) { return autoscaleUserId; } else { return CallContext.current().getCallingUserId(); } }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { final DataCenter dataCenter = _resourceService.getZone(getZoneId()); if (dataCenter == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find zone by ID: " + getZoneId()); } final boolean result = haConfigManager.disableHA(dataCenter); CallContext.current().setEventDetails("Zone Id:" + dataCenter.getId() + " HA enabled: false"); CallContext.current().putContextParameter(DataCenter.class, dataCenter.getUuid()); setupResponse(result); }
@Override public long getEntityOwnerId() { Account caller = CallContext.current().getCallingAccount(); return caller.getAccountId(); }
@Override public void execute() throws ResourceUnavailableException { CallContext.current().setEventDetails("Network ACL ID: " + id); boolean result = _networkACLService.deleteNetworkACL(id); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete network ACL"); } } }
@Override @ActionEvent(eventType = EventTypes.EVENT_FIREWALL_EGRESS_CLOSE, eventDescription = "revoking egress firewall rule", async = true) public boolean revokeEgressFirewallRule(long ruleId, boolean apply) { Account caller = CallContext.current().getCallingAccount(); long userId = CallContext.current().getCallingUserId(); return revokeFirewallRule(ruleId, apply, caller, userId); }
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); }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { final Cluster cluster = _resourceService.getCluster(getClusterId()); if (cluster == null) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find cluster by ID: " + getClusterId()); } final boolean result = haConfigManager.enableHA(cluster); CallContext.current().setEventDetails("Cluster Id:" + cluster.getId() + " HA enabled: true"); CallContext.current().putContextParameter(Cluster.class, cluster.getUuid()); setupResponse(result); }
@Override public long getEntityOwnerId() { Account account = CallContext.current().getCallingAccount(); if (account != null) { return account.getId(); } return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked }
@Override public void execute() { CallContext.current().setEventDetails("Guest OS Id: " + id); boolean result = _mgr.removeGuestOs(this); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove guest OS"); } }
private IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { Account caller = CallContext.current().getCallingAccount(); long callerUserId = CallContext.current().getCallingUserId(); // check permissions _accountMgr.checkAccess(caller, null, false, ipOwner); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId); return allocateIp(ipOwner, isSystem, caller, callerUserId, zone, null); }