changed getAccountId to getEntityOwnerId

This commit is contained in:
Alex Huang 2010-12-03 11:59:25 -08:00
parent 7a80bf102f
commit 96ac136b8c
57 changed files with 101 additions and 69 deletions

View File

@ -37,7 +37,7 @@ public abstract class BaseAsyncCmd extends BaseCmd {
* used to determine that information.
* @return the id of the account that owns the object being acted upon
*/
public abstract long getAccountId();
public abstract long getEntityOwnerId();
/**
* For proper tracking of async commands through the system, events must be generated when the command is

View File

@ -93,7 +93,7 @@ public class AddVpnUserCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -113,7 +113,7 @@ public class AddVpnUserCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "Add Remote Access VPN user for account " + getAccountId() + " username= " + getUserName();
return "Add Remote Access VPN user for account " + getEntityOwnerId() + " username= " + getUserName();
}

View File

@ -79,7 +79,7 @@ public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getLoadBalancerId());
if (lb == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked

View File

@ -71,7 +71,7 @@ public class AttachIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate iso = _responseGenerator.findTemplateById(getId());
if (iso == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked

View File

@ -96,7 +96,7 @@ public class AttachVolumeCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Volume volume = _responseGenerator.findVolumeById(getId());
if (volume == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked

View File

@ -153,7 +153,7 @@ public class AuthorizeNetworkGroupIngressCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {

View File

@ -70,7 +70,7 @@ public class CancelMaintenanceCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -69,7 +69,7 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -81,7 +81,7 @@ public class CopyIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate iso = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (iso != null) {
return iso.getAccountId();

View File

@ -82,7 +82,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (template != null) {
return template.getAccountId();

View File

@ -30,7 +30,6 @@ import com.cloud.api.response.FirewallRuleResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
@ -109,8 +108,8 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Por
}
@Override
public long getAccountId() {
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
public long getEntityOwnerId() {
return _entityMgr.findById(PortForwardingRule.class, getEntityId()).getAccountId();
}
@Override
@ -188,4 +187,9 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Por
return -1;
}
@Override
public long getAccountId() {
throw new UnsupportedOperationException("Get the account id from network");
}
}

View File

@ -23,18 +23,20 @@ import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseAsyncCreateCmd;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.LoadBalancerResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
@Implementation(description="Creates a load balancer rule", responseObject=LoadBalancerResponse.class)
public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer {
public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd implements LoadBalancer {
public static final Logger s_logger = Logger.getLogger(CreateLoadBalancerRuleCmd.class.getName());
private static final String s_name = "createloadbalancerruleresponse";
@ -184,5 +186,26 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer {
@Override
public List<? extends Destination> getDestinations() {
throw new UnsupportedOperationException("not supported");
}
@Override
public void callCreate() {
// TODO Auto-generated method stub
}
@Override
public long getEntityOwnerId() {
return _entityMgr.findById(LoadBalancer.class, getEntityId()).getAccountId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_LOAD_BALANCER_CREATE;
}
@Override
public String getEventDescription() {
return "Create load balancer";
}
}

View File

@ -35,7 +35,7 @@ import com.cloud.user.UserContext;
import com.cloud.utils.net.Ip;
@Implementation(description="Creates a port forwarding rule", responseObject=FirewallRuleResponse.class)
public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements PortForwardingRule {
public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements PortForwardingRule {
public static final Logger s_logger = Logger.getLogger(CreatePortForwardingRuleCmd.class.getName());
private static final String s_name = "createportforwardingruleresponse";
@ -162,8 +162,8 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
}
@Override
public long getAccountId() {
throw new UnsupportedOperationException("Get the account id from network");
public long getEntityOwnerId() {
return _entityMgr.findById(PortForwardingRule.class, getEntityId()).getAccountId();
}
@Override
@ -207,4 +207,9 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
return ("Creating an port forwarding rule for "+ipAddress+" with virtual machine:"+virtualMachineId);
}
@Override
public long getAccountId() {
throw new UnsupportedOperationException("Get the account id from network");
}
}

View File

@ -105,7 +105,7 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -125,7 +125,7 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
@Override
public String getEventDescription() {
return "Create Remote Access VPN for account " + getAccountId() + " in zone " + getZoneId();
return "Create Remote Access VPN for account " + getEntityOwnerId() + " in zone " + getZoneId();
}
@Override

View File

@ -93,7 +93,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
if (volume != null) {
return volume.getAccountId();

View File

@ -134,7 +134,7 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Long volumeId = getVolumeId();
Long snapshotId = getSnapshotId();
if (volumeId != null) {

View File

@ -115,7 +115,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {

View File

@ -68,7 +68,7 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Domain domain = _entityMgr.findById(Domain.class, getId());
if (domain != null) {
return domain.getAccountId();

View File

@ -73,7 +73,7 @@ public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}

View File

@ -73,7 +73,7 @@ public class DeleteIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate iso = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (iso != null) {
return iso.getAccountId();

View File

@ -60,7 +60,7 @@ public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getId());
if (lb != null) {
return lb.getAccountId();

View File

@ -79,7 +79,7 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -99,7 +99,7 @@ public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "Delete Remote Access VPN for account " + getAccountId() + " in zone " + getZoneId();
return "Delete Remote Access VPN for account " + getEntityOwnerId() + " in zone " + getZoneId();
}
@Override

View File

@ -63,7 +63,7 @@ public class DeleteSnapshotCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Snapshot snapshot = _entityMgr.findById(Snapshot.class, getId());
if (snapshot != null) {
return snapshot.getAccountId();

View File

@ -75,7 +75,7 @@ public class DeleteTemplateCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (template != null) {
return template.getAccountId();

View File

@ -68,7 +68,7 @@ public class DeleteUserCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -175,7 +175,7 @@ public class DeployVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {

View File

@ -202,7 +202,7 @@ public class DeployVm2Cmd extends BaseAsyncCreateCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {

View File

@ -64,7 +64,7 @@ public class DestroyConsoleProxyCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = (Account)UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -64,7 +64,7 @@ public class DestroyVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -61,7 +61,7 @@ public class DetachIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _entityMgr.findById(UserVm.class, getVirtualMachineId());
if (vm != null) {
return vm.getAccountId();

View File

@ -88,7 +88,7 @@ public class DetachVolumeCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Long volumeId = getId();
if (volumeId != null) {
Volume volume = _responseGenerator.findVolumeById(volumeId);

View File

@ -72,7 +72,7 @@ public class DisableAccountCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -66,7 +66,7 @@ public class DisableUserCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -88,7 +88,7 @@ public class ExtractIsoCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate iso = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (iso != null) {
return iso.getAccountId();
@ -120,7 +120,7 @@ public class ExtractIsoCmd extends BaseAsyncCmd {
try {
Long uploadId = _templateService.extract(this);
if (uploadId != null){
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getAccountId(), mode);
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
response.setResponseName(getName());
response.setObjectName("iso");
this.setResponseObject(response);

View File

@ -88,7 +88,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId());
if (template != null) {
return template.getAccountId();
@ -121,7 +121,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd {
try {
Long uploadId = _templateService.extract(this);
if (uploadId != null){
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getAccountId(), mode);
ExtractResponse response = _responseGenerator.createExtractResponse(uploadId, id, zoneId, getEntityOwnerId(), mode);
response.setResponseName(getName());
this.setResponseObject(response);
} else {

View File

@ -102,7 +102,7 @@ public class ExtractVolumeCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Volume volume = _entityMgr.findById(Volume.class, getId());
if (volume != null) {
return volume.getAccountId();
@ -138,7 +138,7 @@ public class ExtractVolumeCmd extends BaseAsyncCmd {
response.setMode(mode);
response.setUploadId(uploadId);
response.setState(uploadInfo.getUploadState().toString());
response.setAccountId(getAccountId());
response.setAccountId(getEntityOwnerId());
//FIX ME - Need to set the url once the gson jar is upgraded since it is throwing an error right now.
response.setUrl(uploadInfo.getUploadUrl().replaceAll("/", "%2F"));
this.setResponseObject(response);

View File

@ -67,7 +67,7 @@ public class PrepareForMaintenanceCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -65,7 +65,7 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -62,7 +62,7 @@ public class RebootRouterCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId());
if (router != null) {
return router.getAccountId();

View File

@ -64,7 +64,7 @@ public class RebootSystemVmCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -61,7 +61,7 @@ public class RebootVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -69,7 +69,7 @@ public class ReconnectHostCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -80,7 +80,7 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getId());
if (lb == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked

View File

@ -81,7 +81,7 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {
@ -101,7 +101,7 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
return "Remove Remote Access VPN user for account " + getAccountId() + " username= " + getUserName();
return "Remove Remote Access VPN user for account " + getEntityOwnerId() + " username= " + getUserName();
}

View File

@ -78,7 +78,7 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -127,7 +127,7 @@ public class RevokeNetworkGroupIngressCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if ((account == null) || isAdmin(account.getType())) {
if ((domainId != null) && (accountName != null)) {

View File

@ -72,7 +72,7 @@ public class StartRouterCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _entityMgr.findById(UserVm.class, getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -68,7 +68,7 @@ public class StartSystemVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -71,7 +71,7 @@ public class StartVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -66,7 +66,7 @@ public class StopRouterCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _entityMgr.findById(UserVm.class, getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -64,7 +64,7 @@ public class StopSystemVmCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
Account account = UserContext.current().getAccount();
if (account != null) {
return account.getId();

View File

@ -67,7 +67,7 @@ public class StopVMCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
UserVm vm = _responseGenerator.findUserVmById(getId());
if (vm != null) {
return vm.getAccountId();

View File

@ -88,7 +88,7 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getId());
if (lb == null) {
return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked

View File

@ -76,7 +76,7 @@ public class UpdatePortForwardingRuleCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
IpAddress addr = _entityMgr.findById(IpAddress.class, getPublicIp());
if (addr != null) {
return addr.getAccountId();

View File

@ -62,7 +62,7 @@ public class UploadCustomCertificateCmd extends BaseAsyncCmd {
}
@Override
public long getAccountId() {
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}

View File

@ -389,7 +389,7 @@ public class ApiServer implements HttpRequestHandler {
}
// save the scheduled event
Long eventId = EventUtils.saveScheduledEvent((userId == null) ? User.UID_SYSTEM : userId, asyncCmd.getAccountId(),
Long eventId = EventUtils.saveScheduledEvent((userId == null) ? User.UID_SYSTEM : userId, asyncCmd.getEntityOwnerId(),
asyncCmd.getEventType(), asyncCmd.getEventDescription());
if (eventId != null) {

View File

@ -3579,9 +3579,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
throw new InvalidParameterValueException("No valid account specified for deploying a virtual machine.");
}
AccountVO owner = _accountDao.findById(cmd.getAccountId());
AccountVO owner = _accountDao.findById(cmd.getEntityOwnerId());
if (owner == null || owner.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find account: " + cmd.getAccountId());
throw new InvalidParameterValueException("Unable to find account: " + cmd.getEntityOwnerId());
}
Domain domain = _domainDao.findById(owner.getDomainId());