From ec764069426c3abd6f9a5102f8fa70ae79ffb284 Mon Sep 17 00:00:00 2001 From: alena Date: Fri, 25 Feb 2011 16:13:48 -0800 Subject: [PATCH] bug 8737: set entityOwnerId for all api commands including non-Async ones status 8737: resolved fixed --- api/src/com/cloud/api/BaseAsyncCmd.java | 8 -- api/src/com/cloud/api/BaseCmd.java | 7 ++ api/src/com/cloud/api/BaseListCmd.java | 6 ++ .../com/cloud/api/commands/AddClusterCmd.java | 8 +- .../com/cloud/api/commands/AddHostCmd.java | 6 ++ .../api/commands/AddSecondaryStorageCmd.java | 6 ++ .../cloud/api/commands/CreateAccountCmd.java | 7 ++ .../com/cloud/api/commands/CreateCfgCmd.java | 6 ++ .../api/commands/CreateDiskOfferingCmd.java | 7 +- .../cloud/api/commands/CreateDomainCmd.java | 6 ++ .../commands/CreateLoadBalancerRuleCmd.java | 5 + .../cloud/api/commands/CreateNetworkCmd.java | 21 ++++ .../commands/CreateNetworkOfferingCmd.java | 6 ++ .../com/cloud/api/commands/CreatePodCmd.java | 6 ++ .../api/commands/CreateSSHKeyPairCmd.java | 13 +++ .../api/commands/CreateSecurityGroupCmd.java | 21 ++++ .../commands/CreateServiceOfferingCmd.java | 8 +- .../api/commands/CreateSnapshotPolicyCmd.java | 26 +++-- .../api/commands/CreateStoragePoolCmd.java | 6 ++ .../com/cloud/api/commands/CreateUserCmd.java | 21 ++++ .../cloud/api/commands/CreateVMGroupCmd.java | 21 ++++ .../api/commands/CreateVlanIpRangeCmd.java | 6 ++ .../com/cloud/api/commands/CreateZoneCmd.java | 6 ++ .../cloud/api/commands/DeleteAccountCmd.java | 5 +- .../cloud/api/commands/DeleteClusterCmd.java | 6 ++ .../api/commands/DeleteDiskOfferingCmd.java | 6 ++ .../com/cloud/api/commands/DeleteHostCmd.java | 6 ++ .../commands/DeleteNetworkOfferingCmd.java | 6 ++ .../com/cloud/api/commands/DeletePodCmd.java | 6 ++ .../com/cloud/api/commands/DeletePoolCmd.java | 6 ++ .../api/commands/DeleteSSHKeyPairCmd.java | 36 ++++++- .../api/commands/DeleteSecurityGroupCmd.java | 12 +++ .../commands/DeleteServiceOfferingCmd.java | 6 ++ .../commands/DeleteSnapshotPoliciesCmd.java | 6 ++ .../com/cloud/api/commands/DeleteUserCmd.java | 12 +++ .../cloud/api/commands/DeleteVMGroupCmd.java | 12 +++ .../api/commands/DeleteVlanIpRangeCmd.java | 6 ++ .../cloud/api/commands/DeleteVolumeCmd.java | 12 +++ .../com/cloud/api/commands/DeleteZoneCmd.java | 6 ++ .../cloud/api/commands/DisableAccountCmd.java | 5 +- .../cloud/api/commands/DisableUserCmd.java | 8 +- .../cloud/api/commands/EnableAccountCmd.java | 10 ++ .../api/commands/EnableStaticNatCmd.java | 12 +++ .../com/cloud/api/commands/EnableUserCmd.java | 12 +++ .../api/commands/GetCloudIdentifierCmd.java | 6 ++ .../cloud/api/commands/GetVMPasswordCmd.java | 12 +++ .../api/commands/ListCapabilitiesCmd.java | 6 ++ .../api/commands/ListHypervisorsCmd.java | 5 + .../ListTemplateOrIsoPermissionsCmd.java | 9 ++ .../cloud/api/commands/LockAccountCmd.java | 27 ++++-- .../com/cloud/api/commands/LockUserCmd.java | 12 +++ .../api/commands/QueryAsyncJobResultCmd.java | 6 ++ .../com/cloud/api/commands/RecoverVMCmd.java | 11 +++ .../com/cloud/api/commands/RegisterCmd.java | 12 +++ .../cloud/api/commands/RegisterIsoCmd.java | 21 ++++ .../api/commands/RegisterSSHKeyPairCmd.java | 13 +++ .../api/commands/RegisterTemplateCmd.java | 21 ++++ .../cloud/api/commands/StartRouterCmd.java | 7 +- .../com/cloud/api/commands/StopRouterCmd.java | 7 +- .../cloud/api/commands/UpdateAccountCmd.java | 10 ++ .../com/cloud/api/commands/UpdateCfgCmd.java | 6 ++ .../api/commands/UpdateDiskOfferingCmd.java | 6 ++ .../cloud/api/commands/UpdateDomainCmd.java | 6 ++ .../com/cloud/api/commands/UpdateHostCmd.java | 6 ++ .../com/cloud/api/commands/UpdateIsoCmd.java | 11 +++ .../api/commands/UpdateIsoPermissionsCmd.java | 12 +++ .../commands/UpdateNetworkOfferingCmd.java | 6 ++ .../com/cloud/api/commands/UpdatePodCmd.java | 6 ++ .../api/commands/UpdateResourceLimitCmd.java | 21 ++++ .../commands/UpdateServiceOfferingCmd.java | 6 ++ .../api/commands/UpdateStoragePoolCmd.java | 6 ++ .../cloud/api/commands/UpdateTemplateCmd.java | 11 +++ .../UpdateTemplateOrIsoPermissionsCmd.java | 2 - .../UpdateTemplatePermissionsCmd.java | 12 +++ .../com/cloud/api/commands/UpdateUserCmd.java | 12 +++ .../com/cloud/api/commands/UpdateVMCmd.java | 11 +++ .../cloud/api/commands/UpdateVMGroupCmd.java | 11 +++ .../com/cloud/api/commands/UpdateZoneCmd.java | 6 ++ .../cloud/api/commands/UpgradeRouterCmd.java | 11 +++ .../com/cloud/api/commands/UpgradeVMCmd.java | 11 +++ server/src/com/cloud/api/ApiDispatcher.java | 5 +- .../com/cloud/network/NetworkManagerImpl.java | 4 + .../cloud/server/ManagementServerImpl.java | 97 +++++++++++-------- 83 files changed, 800 insertions(+), 99 deletions(-) diff --git a/api/src/com/cloud/api/BaseAsyncCmd.java b/api/src/com/cloud/api/BaseAsyncCmd.java index 923d166a60e..3a182a45f37 100644 --- a/api/src/com/cloud/api/BaseAsyncCmd.java +++ b/api/src/com/cloud/api/BaseAsyncCmd.java @@ -37,14 +37,6 @@ public abstract class BaseAsyncCmd extends BaseCmd { @Parameter(name="starteventid", type=CommandType.LONG) private Long startEventId; - - - /** - * For async commands the API framework needs to know the owner of the object being acted upon. This method is - * used to determine that information. - * @return the id of the account that owns the object being acted upon - */ - public abstract long getEntityOwnerId(); /** * For proper tracking of async commands through the system, events must be generated when the command is diff --git a/api/src/com/cloud/api/BaseCmd.java b/api/src/com/cloud/api/BaseCmd.java index 26fc9adb01c..eceb2dbd426 100755 --- a/api/src/com/cloud/api/BaseCmd.java +++ b/api/src/com/cloud/api/BaseCmd.java @@ -146,6 +146,13 @@ public abstract class BaseCmd { } public abstract String getCommandName(); + + /** + * For commands the API framework needs to know the owner of the object being acted upon. This method is + * used to determine that information. + * @return the id of the account that owns the object being acted upon + */ + public abstract long getEntityOwnerId(); public Object getResponseObject() { return _responseObject; diff --git a/api/src/com/cloud/api/BaseListCmd.java b/api/src/com/cloud/api/BaseListCmd.java index 5d248c84b50..4f6e08deec7 100755 --- a/api/src/com/cloud/api/BaseListCmd.java +++ b/api/src/com/cloud/api/BaseListCmd.java @@ -37,6 +37,12 @@ public abstract class BaseListCmd extends BaseCmd { public Integer getPageSize() { return pageSize; } + + @Override + public long getEntityOwnerId() { + //no owner is needed for list command + return 0; + } public Long getPageSizeVal() { Long pageSize = null; diff --git a/api/src/com/cloud/api/commands/AddClusterCmd.java b/api/src/com/cloud/api/commands/AddClusterCmd.java index da6ad9bd592..6636e3ca837 100644 --- a/api/src/com/cloud/api/commands/AddClusterCmd.java +++ b/api/src/com/cloud/api/commands/AddClusterCmd.java @@ -11,11 +11,10 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ClusterResponse; -import com.cloud.api.response.HostResponse; import com.cloud.api.response.ListResponse; import com.cloud.exception.DiscoveryException; -import com.cloud.host.Host; import com.cloud.org.Cluster; +import com.cloud.user.Account; @Implementation(description="Adds a new cluster", responseObject=ClusterResponse.class) public class AddClusterCmd extends BaseCmd { @@ -88,6 +87,11 @@ public class AddClusterCmd extends BaseCmd { public void setClusterType(String type) { this.clusterType = type; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/AddHostCmd.java b/api/src/com/cloud/api/commands/AddHostCmd.java index e73eb037864..6eb957d990e 100644 --- a/api/src/com/cloud/api/commands/AddHostCmd.java +++ b/api/src/com/cloud/api/commands/AddHostCmd.java @@ -31,6 +31,7 @@ import com.cloud.api.response.HostResponse; import com.cloud.api.response.ListResponse; import com.cloud.exception.DiscoveryException; import com.cloud.host.Host; +import com.cloud.user.Account; @Implementation(description="Adds a new host.", responseObject=HostResponse.class) public class AddHostCmd extends BaseCmd { @@ -112,6 +113,11 @@ public class AddHostCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ try { diff --git a/api/src/com/cloud/api/commands/AddSecondaryStorageCmd.java b/api/src/com/cloud/api/commands/AddSecondaryStorageCmd.java index 24df163a9fb..5b18d23bd6d 100644 --- a/api/src/com/cloud/api/commands/AddSecondaryStorageCmd.java +++ b/api/src/com/cloud/api/commands/AddSecondaryStorageCmd.java @@ -30,6 +30,7 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.HostResponse; import com.cloud.exception.DiscoveryException; import com.cloud.host.Host; +import com.cloud.user.Account; @Implementation(description="Adds secondary storage.", responseObject=HostResponse.class) public class AddSecondaryStorageCmd extends BaseCmd { @@ -67,6 +68,11 @@ public class AddSecondaryStorageCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ try { diff --git a/api/src/com/cloud/api/commands/CreateAccountCmd.java b/api/src/com/cloud/api/commands/CreateAccountCmd.java index 843248f1803..1a094451a5c 100644 --- a/api/src/com/cloud/api/commands/CreateAccountCmd.java +++ b/api/src/com/cloud/api/commands/CreateAccountCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.AccountResponse; import com.cloud.api.response.UserResponse; +import com.cloud.user.Account; import com.cloud.user.UserAccount; @Implementation(description="Creates an account", responseObject=UserResponse.class) @@ -115,6 +116,12 @@ public class CreateAccountCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override public void execute(){ UserAccount user = _accountService.createAccount(this); diff --git a/api/src/com/cloud/api/commands/CreateCfgCmd.java b/api/src/com/cloud/api/commands/CreateCfgCmd.java index 9d5e790f413..075ffd66727 100644 --- a/api/src/com/cloud/api/commands/CreateCfgCmd.java +++ b/api/src/com/cloud/api/commands/CreateCfgCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ConfigurationResponse; import com.cloud.configuration.Configuration; +import com.cloud.user.Account; @Implementation(description="Adds configuration value", responseObject=ConfigurationResponse.class) public class CreateCfgCmd extends BaseCmd { @@ -93,6 +94,11 @@ public class CreateCfgCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ Configuration cfg = _configService.addConfig(this); diff --git a/api/src/com/cloud/api/commands/CreateDiskOfferingCmd.java b/api/src/com/cloud/api/commands/CreateDiskOfferingCmd.java index eb3015c7b55..05792730eb9 100755 --- a/api/src/com/cloud/api/commands/CreateDiskOfferingCmd.java +++ b/api/src/com/cloud/api/commands/CreateDiskOfferingCmd.java @@ -24,9 +24,9 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; -import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.response.DiskOfferingResponse; import com.cloud.offering.DiskOffering; +import com.cloud.user.Account; @Implementation(description="Creates a disk offering.", responseObject=DiskOfferingResponse.class) public class CreateDiskOfferingCmd extends BaseCmd { @@ -92,6 +92,11 @@ public class CreateDiskOfferingCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ DiskOffering offering = _configService.createDiskOffering(this); diff --git a/api/src/com/cloud/api/commands/CreateDomainCmd.java b/api/src/com/cloud/api/commands/CreateDomainCmd.java index 121ad7431b0..126a4b1aeba 100644 --- a/api/src/com/cloud/api/commands/CreateDomainCmd.java +++ b/api/src/com/cloud/api/commands/CreateDomainCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.DomainResponse; import com.cloud.domain.Domain; +import com.cloud.user.Account; @Implementation(description="Creates a domain", responseObject=DomainResponse.class) public class CreateDomainCmd extends BaseCmd { @@ -66,6 +67,11 @@ public class CreateDomainCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ Domain domain = _mgr.createDomain(this); diff --git a/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java b/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java index ac2c44598f6..00b5ccc991e 100644 --- a/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java +++ b/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java @@ -181,5 +181,10 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer @Override public int getDefaultPortEnd() { return privatePort.intValue(); + } + + @Override + public long getEntityOwnerId() { + return getAccountId(); } } diff --git a/api/src/com/cloud/api/commands/CreateNetworkCmd.java b/api/src/com/cloud/api/commands/CreateNetworkCmd.java index 49f57d99e16..9b6d5f98204 100644 --- a/api/src/com/cloud/api/commands/CreateNetworkCmd.java +++ b/api/src/com/cloud/api/commands/CreateNetworkCmd.java @@ -29,6 +29,8 @@ import com.cloud.api.response.NetworkResponse; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.network.Network; +import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(description="Creates a network", responseObject=NetworkResponse.class) public class CreateNetworkCmd extends BaseCmd { @@ -150,6 +152,25 @@ public class CreateNetworkCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if ((account == null) || isAdmin(account.getType())) { + if ((domainId != null) && (accountName != null)) { + Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); + if (userAccount != null) { + return userAccount.getId(); + } + } + } + + 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() throws InsufficientCapacityException, ConcurrentOperationException{ Network result = _networkService.createNetwork(this); diff --git a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java index 0e316a0abe4..0ebf5579e56 100644 --- a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java +++ b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.NetworkOfferingResponse; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; +import com.cloud.user.Account; @Implementation(description="Creates a network offering.", responseObject=NetworkOfferingResponse.class) public class CreateNetworkOfferingCmd extends BaseCmd { @@ -113,6 +114,11 @@ public class CreateNetworkOfferingCmd extends BaseCmd { public String getCommandName() { return _name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/CreatePodCmd.java b/api/src/com/cloud/api/commands/CreatePodCmd.java index 04ab3678221..6fb8055eff0 100644 --- a/api/src/com/cloud/api/commands/CreatePodCmd.java +++ b/api/src/com/cloud/api/commands/CreatePodCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.PodResponse; import com.cloud.dc.Pod; +import com.cloud.user.Account; @Implementation(description="Creates a new Pod.", responseObject=PodResponse.class) public class CreatePodCmd extends BaseCmd { @@ -94,6 +95,11 @@ public class CreatePodCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/CreateSSHKeyPairCmd.java b/api/src/com/cloud/api/commands/CreateSSHKeyPairCmd.java index dc5dfb1b298..af6dcc82b1c 100644 --- a/api/src/com/cloud/api/commands/CreateSSHKeyPairCmd.java +++ b/api/src/com/cloud/api/commands/CreateSSHKeyPairCmd.java @@ -7,7 +7,9 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.SSHKeyPairResponse; +import com.cloud.user.Account; import com.cloud.user.SSHKeyPair; +import com.cloud.user.UserContext; @Implementation(description="Create a new keypair and returns the private key", responseObject=SSHKeyPairResponse.class) public class CreateSSHKeyPairCmd extends BaseCmd { @@ -35,6 +37,17 @@ public class CreateSSHKeyPairCmd extends BaseCmd { ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// + + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + + 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() { diff --git a/api/src/com/cloud/api/commands/CreateSecurityGroupCmd.java b/api/src/com/cloud/api/commands/CreateSecurityGroupCmd.java index 49ab8416e03..b6eff6ba50f 100644 --- a/api/src/com/cloud/api/commands/CreateSecurityGroupCmd.java +++ b/api/src/com/cloud/api/commands/CreateSecurityGroupCmd.java @@ -26,6 +26,8 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SecurityGroupResponse; import com.cloud.network.security.SecurityGroup; +import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(responseObject=SecurityGroupResponse.class, description="Creates a security group") public class CreateSecurityGroupCmd extends BaseCmd { @@ -80,6 +82,25 @@ public class CreateSecurityGroupCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if ((account == null) || isAdmin(account.getType())) { + if ((domainId != null) && (accountName != null)) { + Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); + if (userAccount != null) { + return userAccount.getId(); + } + } + } + + 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(){ SecurityGroup group = _securityGroupService.createSecurityGroup(this); diff --git a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java index c6f031cf8eb..254021d2e36 100644 --- a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java +++ b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ServiceOfferingResponse; import com.cloud.offering.ServiceOffering; +import com.cloud.user.Account; @Implementation(description="Creates a service offering.", responseObject=ServiceOfferingResponse.class) public class CreateServiceOfferingCmd extends BaseCmd { @@ -111,7 +112,12 @@ public class CreateServiceOfferingCmd extends BaseCmd { @Override public String getCommandName() { return _name; - } + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/CreateSnapshotPolicyCmd.java b/api/src/com/cloud/api/commands/CreateSnapshotPolicyCmd.java index d0f739aea8d..f8fa74da7dc 100644 --- a/api/src/com/cloud/api/commands/CreateSnapshotPolicyCmd.java +++ b/api/src/com/cloud/api/commands/CreateSnapshotPolicyCmd.java @@ -26,7 +26,9 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SnapshotPolicyResponse; +import com.cloud.storage.Volume; import com.cloud.storage.snapshot.SnapshotPolicy; +import com.cloud.user.Account; @Implementation(description="Creates a snapshot policy for the account.", responseObject=SnapshotPolicyResponse.class) public class CreateSnapshotPolicyCmd extends BaseCmd { @@ -38,12 +40,6 @@ public class CreateSnapshotPolicyCmd extends BaseCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="The account of the snapshot policy. The account parameter must be used with the domainId parameter.") - private String accountName; - - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="The domain ID of the snapshot. If used with the account parameter, specifies a domain for the account associated with the snapshot policy.") - private Long domainId; - @Parameter(name=ApiConstants.INTERVAL_TYPE, type=CommandType.STRING, required=true, description="valid values are HOURLY, DAILY, WEEKLY, and MONTHLY") private String intervalType; @@ -69,14 +65,6 @@ public class CreateSnapshotPolicyCmd extends BaseCmd { /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - public String getAccountName() { - return accountName; - } - - public Long getDomainId() { - return domainId; - } - public String getIntervalType() { return intervalType; } @@ -107,6 +95,16 @@ public class CreateSnapshotPolicyCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + Volume volume = _entityMgr.findById(Volume.class, getVolumeId()); + if (volume != null) { + return volume.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ SnapshotPolicy result = _snapshotService.createPolicy(this); diff --git a/api/src/com/cloud/api/commands/CreateStoragePoolCmd.java b/api/src/com/cloud/api/commands/CreateStoragePoolCmd.java index de1375958a2..87c51e4a47d 100644 --- a/api/src/com/cloud/api/commands/CreateStoragePoolCmd.java +++ b/api/src/com/cloud/api/commands/CreateStoragePoolCmd.java @@ -32,6 +32,7 @@ import com.cloud.api.response.StoragePoolResponse; import com.cloud.exception.ResourceInUseException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.storage.StoragePool; +import com.cloud.user.Account; @SuppressWarnings("rawtypes") @Implementation(description="Creates a storage pool.", responseObject=StoragePoolResponse.class) @@ -105,6 +106,11 @@ public class CreateStoragePoolCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/CreateUserCmd.java b/api/src/com/cloud/api/commands/CreateUserCmd.java index ca26a7baca6..203160e8520 100644 --- a/api/src/com/cloud/api/commands/CreateUserCmd.java +++ b/api/src/com/cloud/api/commands/CreateUserCmd.java @@ -26,7 +26,9 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.UserResponse; +import com.cloud.user.Account; import com.cloud.user.User; +import com.cloud.user.UserContext; @Implementation(description="Creates a user for an account that already exists", responseObject=UserResponse.class) public class CreateUserCmd extends BaseCmd { @@ -107,6 +109,25 @@ public class CreateUserCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if ((account == null) || isAdmin(account.getType())) { + if ((domainId != null) && (accountName != null)) { + Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); + if (userAccount != null) { + return userAccount.getId(); + } + } + } + + 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(){ User user = _accountService.createUser(this); diff --git a/api/src/com/cloud/api/commands/CreateVMGroupCmd.java b/api/src/com/cloud/api/commands/CreateVMGroupCmd.java index 9ad303f5a0a..ac30bfe289b 100644 --- a/api/src/com/cloud/api/commands/CreateVMGroupCmd.java +++ b/api/src/com/cloud/api/commands/CreateVMGroupCmd.java @@ -25,6 +25,8 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.InstanceGroupResponse; +import com.cloud.user.Account; +import com.cloud.user.UserContext; import com.cloud.vm.InstanceGroup; @Implementation(description="Creates a vm group", responseObject=InstanceGroupResponse.class) @@ -71,6 +73,25 @@ public class CreateVMGroupCmd extends BaseCmd{ return s_name; } + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if ((account == null) || isAdmin(account.getType())) { + if ((domainId != null) && (accountName != null)) { + Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); + if (userAccount != null) { + return userAccount.getId(); + } + } + } + + 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(){ InstanceGroup result = _userVmService.createVmGroup(this); diff --git a/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java b/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java index 66300fa072b..9d12fc6f057 100644 --- a/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java +++ b/api/src/com/cloud/api/commands/CreateVlanIpRangeCmd.java @@ -30,6 +30,7 @@ import com.cloud.dc.Vlan; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; @Implementation(description="Creates a VLAN IP range.", responseObject=VlanIpRangeResponse.class) public class CreateVlanIpRangeCmd extends BaseCmd { @@ -132,6 +133,11 @@ public class CreateVlanIpRangeCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute() throws ResourceUnavailableException{ try { diff --git a/api/src/com/cloud/api/commands/CreateZoneCmd.java b/api/src/com/cloud/api/commands/CreateZoneCmd.java index 92db2a59532..55e2b4c583d 100644 --- a/api/src/com/cloud/api/commands/CreateZoneCmd.java +++ b/api/src/com/cloud/api/commands/CreateZoneCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ZoneResponse; import com.cloud.dc.DataCenter; +import com.cloud.user.Account; @Implementation(description="Creates a Zone.", responseObject=ZoneResponse.class) public class CreateZoneCmd extends BaseCmd { @@ -130,6 +131,11 @@ public class CreateZoneCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ DataCenter result = _configService.createZone(this); diff --git a/api/src/com/cloud/api/commands/DeleteAccountCmd.java b/api/src/com/cloud/api/commands/DeleteAccountCmd.java index 7c0ca6ee6b9..5ebdca9e120 100644 --- a/api/src/com/cloud/api/commands/DeleteAccountCmd.java +++ b/api/src/com/cloud/api/commands/DeleteAccountCmd.java @@ -30,7 +30,6 @@ import com.cloud.api.response.SuccessResponse; import com.cloud.event.EventTypes; import com.cloud.user.Account; import com.cloud.user.User; -import com.cloud.user.UserContext; @Implementation(description="Deletes a account, and all users associated with this account", responseObject=SuccessResponse.class) public class DeleteAccountCmd extends BaseAsyncCmd { @@ -69,9 +68,9 @@ public class DeleteAccountCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = _entityMgr.findById(Account.class, getId()); if (account != null) { - return account.getId(); + return account.getAccountId(); } return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked diff --git a/api/src/com/cloud/api/commands/DeleteClusterCmd.java b/api/src/com/cloud/api/commands/DeleteClusterCmd.java index 56216ed5c17..78ea1a6d23e 100644 --- a/api/src/com/cloud/api/commands/DeleteClusterCmd.java +++ b/api/src/com/cloud/api/commands/DeleteClusterCmd.java @@ -8,6 +8,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Deletes a cluster.", responseObject=SuccessResponse.class) @@ -42,6 +43,11 @@ public class DeleteClusterCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ boolean result = _resourceService.deleteCluster(this); diff --git a/api/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java b/api/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java index b9500701628..a483c16ec15 100644 --- a/api/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java +++ b/api/src/com/cloud/api/commands/DeleteDiskOfferingCmd.java @@ -25,6 +25,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Updates a disk offering.", responseObject=SuccessResponse.class) public class DeleteDiskOfferingCmd extends BaseCmd { @@ -56,6 +57,11 @@ public class DeleteDiskOfferingCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ boolean result = _configService.deleteDiskOffering(this); diff --git a/api/src/com/cloud/api/commands/DeleteHostCmd.java b/api/src/com/cloud/api/commands/DeleteHostCmd.java index 9eaa58bd520..851897666ea 100644 --- a/api/src/com/cloud/api/commands/DeleteHostCmd.java +++ b/api/src/com/cloud/api/commands/DeleteHostCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Deletes a host.", responseObject=SuccessResponse.class) @@ -60,6 +61,11 @@ public class DeleteHostCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ boolean result = _resourceService.deleteHost(this); diff --git a/api/src/com/cloud/api/commands/DeleteNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/DeleteNetworkOfferingCmd.java index 9bfa06e56bf..97418546216 100644 --- a/api/src/com/cloud/api/commands/DeleteNetworkOfferingCmd.java +++ b/api/src/com/cloud/api/commands/DeleteNetworkOfferingCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Deletes a network offering.", responseObject=SuccessResponse.class) public class DeleteNetworkOfferingCmd extends BaseCmd{ @@ -58,6 +59,11 @@ public class DeleteNetworkOfferingCmd extends BaseCmd{ return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ boolean result = _configService.deleteNetworkOffering(this); diff --git a/api/src/com/cloud/api/commands/DeletePodCmd.java b/api/src/com/cloud/api/commands/DeletePodCmd.java index a3bf4e97614..73ca32a78a9 100644 --- a/api/src/com/cloud/api/commands/DeletePodCmd.java +++ b/api/src/com/cloud/api/commands/DeletePodCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Deletes a Pod.", responseObject=SuccessResponse.class) public class DeletePodCmd extends BaseCmd { @@ -56,6 +57,11 @@ public class DeletePodCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/DeletePoolCmd.java b/api/src/com/cloud/api/commands/DeletePoolCmd.java index 1e9b21a6c9e..0e7521eee19 100644 --- a/api/src/com/cloud/api/commands/DeletePoolCmd.java +++ b/api/src/com/cloud/api/commands/DeletePoolCmd.java @@ -8,6 +8,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Deletes a storage pool.", responseObject=SuccessResponse.class) public class DeletePoolCmd extends BaseCmd { @@ -40,6 +41,11 @@ public class DeletePoolCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ boolean result = _storageService.deletePool(this); diff --git a/api/src/com/cloud/api/commands/DeleteSSHKeyPairCmd.java b/api/src/com/cloud/api/commands/DeleteSSHKeyPairCmd.java index 47a0e24358e..318646be7b4 100644 --- a/api/src/com/cloud/api/commands/DeleteSSHKeyPairCmd.java +++ b/api/src/com/cloud/api/commands/DeleteSSHKeyPairCmd.java @@ -7,6 +7,8 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(description="Deletes a keypair by name", responseObject=SuccessResponse.class) public class DeleteSSHKeyPairCmd extends BaseCmd { @@ -21,6 +23,11 @@ public class DeleteSSHKeyPairCmd extends BaseCmd { @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="Name of the keypair") private String name; + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the keypair. Must be used with the domainId parameter.") + private String accountName; + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the keypair") + private Long domainId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -30,12 +37,20 @@ public class DeleteSSHKeyPairCmd extends BaseCmd { return name; } + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// - @Override + @Override public void execute() { boolean result = _mgr.deleteSSHKeyPair(this); SuccessResponse response = new SuccessResponse(getCommandName()); @@ -47,4 +62,23 @@ public class DeleteSSHKeyPairCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if ((account == null) || isAdmin(account.getType())) { + if ((domainId != null) && (accountName != null)) { + Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); + if (userAccount != null) { + return userAccount.getId(); + } + } + } + + 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 + } } diff --git a/api/src/com/cloud/api/commands/DeleteSecurityGroupCmd.java b/api/src/com/cloud/api/commands/DeleteSecurityGroupCmd.java index 2eb7e092a7b..204a01ea398 100644 --- a/api/src/com/cloud/api/commands/DeleteSecurityGroupCmd.java +++ b/api/src/com/cloud/api/commands/DeleteSecurityGroupCmd.java @@ -9,6 +9,8 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.exception.ResourceInUseException; +import com.cloud.network.security.SecurityGroup; +import com.cloud.user.Account; @Implementation(description="Deletes security group", responseObject=SuccessResponse.class) public class DeleteSecurityGroupCmd extends BaseCmd { @@ -55,6 +57,16 @@ public class DeleteSecurityGroupCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + SecurityGroup group = _entityMgr.findById(SecurityGroup.class, getId()); + if (group != null) { + return group.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/DeleteServiceOfferingCmd.java b/api/src/com/cloud/api/commands/DeleteServiceOfferingCmd.java index 654e120c602..bea544e50e8 100644 --- a/api/src/com/cloud/api/commands/DeleteServiceOfferingCmd.java +++ b/api/src/com/cloud/api/commands/DeleteServiceOfferingCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Deletes a service offering.", responseObject=SuccessResponse.class) public class DeleteServiceOfferingCmd extends BaseCmd{ @@ -57,6 +58,11 @@ public class DeleteServiceOfferingCmd extends BaseCmd{ public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/DeleteSnapshotPoliciesCmd.java b/api/src/com/cloud/api/commands/DeleteSnapshotPoliciesCmd.java index f1f35474325..6bfcfdfd730 100644 --- a/api/src/com/cloud/api/commands/DeleteSnapshotPoliciesCmd.java +++ b/api/src/com/cloud/api/commands/DeleteSnapshotPoliciesCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Deletes snapshot policies for the account.", responseObject=SuccessResponse.class) public class DeleteSnapshotPoliciesCmd extends BaseCmd { @@ -67,6 +68,11 @@ public class DeleteSnapshotPoliciesCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/DeleteUserCmd.java b/api/src/com/cloud/api/commands/DeleteUserCmd.java index a501cd36251..e7081c4b046 100644 --- a/api/src/com/cloud/api/commands/DeleteUserCmd.java +++ b/api/src/com/cloud/api/commands/DeleteUserCmd.java @@ -27,6 +27,8 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.api.response.UserResponse; +import com.cloud.user.Account; +import com.cloud.user.User; @Implementation(description="Creates a user for an account", responseObject=UserResponse.class) public class DeleteUserCmd extends BaseCmd { @@ -58,6 +60,16 @@ public class DeleteUserCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + User user = _entityMgr.findById(User.class, getId()); + if (user != null) { + return user.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ boolean result = _accountService.deleteUser(this); diff --git a/api/src/com/cloud/api/commands/DeleteVMGroupCmd.java b/api/src/com/cloud/api/commands/DeleteVMGroupCmd.java index 64e2b6b4a14..daab8259231 100644 --- a/api/src/com/cloud/api/commands/DeleteVMGroupCmd.java +++ b/api/src/com/cloud/api/commands/DeleteVMGroupCmd.java @@ -25,6 +25,8 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; +import com.cloud.vm.InstanceGroup; @Implementation(description="Deletes a vm group", responseObject=SuccessResponse.class) public class DeleteVMGroupCmd extends BaseCmd{ @@ -55,6 +57,16 @@ public class DeleteVMGroupCmd extends BaseCmd{ return s_name; } + @Override + public long getEntityOwnerId() { + InstanceGroup group = _entityMgr.findById(InstanceGroup.class, getId()); + if (group != null) { + return group.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ boolean result = _userVmService.deleteVmGroup(this); diff --git a/api/src/com/cloud/api/commands/DeleteVlanIpRangeCmd.java b/api/src/com/cloud/api/commands/DeleteVlanIpRangeCmd.java index 0cd05f8c886..a26804f5473 100644 --- a/api/src/com/cloud/api/commands/DeleteVlanIpRangeCmd.java +++ b/api/src/com/cloud/api/commands/DeleteVlanIpRangeCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Creates a VLAN IP range.", responseObject=SuccessResponse.class) public class DeleteVlanIpRangeCmd extends BaseCmd { @@ -56,6 +57,11 @@ public class DeleteVlanIpRangeCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/DeleteVolumeCmd.java b/api/src/com/cloud/api/commands/DeleteVolumeCmd.java index ccca8c2c592..a25388499ee 100644 --- a/api/src/com/cloud/api/commands/DeleteVolumeCmd.java +++ b/api/src/com/cloud/api/commands/DeleteVolumeCmd.java @@ -27,6 +27,8 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.exception.ConcurrentOperationException; +import com.cloud.storage.Volume; +import com.cloud.user.Account; import com.cloud.user.UserContext; @Implementation(description="Deletes a detached disk volume.", responseObject=SuccessResponse.class) @@ -63,6 +65,16 @@ public class DeleteVolumeCmd extends BaseCmd { public static String getResultObjectName() { return "volume"; } + + @Override + public long getEntityOwnerId() { + Volume volume = _entityMgr.findById(Volume.class, getId()); + if (volume != null) { + return volume.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public void execute() throws ConcurrentOperationException { diff --git a/api/src/com/cloud/api/commands/DeleteZoneCmd.java b/api/src/com/cloud/api/commands/DeleteZoneCmd.java index 9777aad7a05..bd39bdb98da 100644 --- a/api/src/com/cloud/api/commands/DeleteZoneCmd.java +++ b/api/src/com/cloud/api/commands/DeleteZoneCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.user.Account; @Implementation(description="Deletes a Zone.", responseObject=SuccessResponse.class) public class DeleteZoneCmd extends BaseCmd { @@ -58,6 +59,11 @@ public class DeleteZoneCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/DisableAccountCmd.java b/api/src/com/cloud/api/commands/DisableAccountCmd.java index 22b44c17023..6fd22777894 100644 --- a/api/src/com/cloud/api/commands/DisableAccountCmd.java +++ b/api/src/com/cloud/api/commands/DisableAccountCmd.java @@ -30,7 +30,6 @@ import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.user.Account; -import com.cloud.user.UserContext; @Implementation(description="Disables an account", responseObject=AccountResponse.class) public class DisableAccountCmd extends BaseAsyncCmd { @@ -78,9 +77,9 @@ public class DisableAccountCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); + Account account = _accountService.getActiveAccount(getAccountName(), getDomainId()); if (account != null) { - return account.getId(); + return account.getAccountId(); } return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked diff --git a/api/src/com/cloud/api/commands/DisableUserCmd.java b/api/src/com/cloud/api/commands/DisableUserCmd.java index 5985d7f2676..22745c42dfe 100644 --- a/api/src/com/cloud/api/commands/DisableUserCmd.java +++ b/api/src/com/cloud/api/commands/DisableUserCmd.java @@ -28,8 +28,8 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.UserResponse; import com.cloud.event.EventTypes; import com.cloud.user.Account; +import com.cloud.user.User; import com.cloud.user.UserAccount; -import com.cloud.user.UserContext; @Implementation(description="Disables a user account", responseObject=UserResponse.class) public class DisableUserCmd extends BaseAsyncCmd { @@ -67,9 +67,9 @@ public class DisableUserCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Account account = UserContext.current().getCaller(); - if (account != null) { - return account.getId(); + User user = _entityMgr.findById(User.class, getId()); + if (user != null) { + return user.getAccountId(); } return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked diff --git a/api/src/com/cloud/api/commands/EnableAccountCmd.java b/api/src/com/cloud/api/commands/EnableAccountCmd.java index 10c5df8b4d9..11b9229497c 100644 --- a/api/src/com/cloud/api/commands/EnableAccountCmd.java +++ b/api/src/com/cloud/api/commands/EnableAccountCmd.java @@ -61,6 +61,16 @@ public class EnableAccountCmd extends BaseCmd { @Override public String getCommandName() { return s_name; + } + + @Override + public long getEntityOwnerId() { + Account account = _accountService.getActiveAccount(getAccountName(), getDomainId()); + if (account != null) { + return account.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked } @Override diff --git a/api/src/com/cloud/api/commands/EnableStaticNatCmd.java b/api/src/com/cloud/api/commands/EnableStaticNatCmd.java index 81dbc4a251f..3b6262b8259 100644 --- a/api/src/com/cloud/api/commands/EnableStaticNatCmd.java +++ b/api/src/com/cloud/api/commands/EnableStaticNatCmd.java @@ -27,6 +27,8 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.user.Account; +import com.cloud.uservm.UserVm; @Implementation(description="Enables static nat for given ip address", responseObject=SuccessResponse.class) public class EnableStaticNatCmd extends BaseCmd{ @@ -64,6 +66,16 @@ public class EnableStaticNatCmd extends BaseCmd{ public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + UserVm userVm = _entityMgr.findById(UserVm.class, getVirtualMachineId()); + if (userVm != null) { + return userVm.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/EnableUserCmd.java b/api/src/com/cloud/api/commands/EnableUserCmd.java index a2e5048a566..73613a14a8a 100644 --- a/api/src/com/cloud/api/commands/EnableUserCmd.java +++ b/api/src/com/cloud/api/commands/EnableUserCmd.java @@ -26,6 +26,8 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.UserResponse; +import com.cloud.user.Account; +import com.cloud.user.User; import com.cloud.user.UserAccount; @Implementation(description="Enables a user account", responseObject=UserResponse.class) @@ -58,6 +60,16 @@ public class EnableUserCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + User user = _entityMgr.findById(User.class, getId()); + if (user != null) { + return user.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ UserAccount user = _accountService.enableUser(this); diff --git a/api/src/com/cloud/api/commands/GetCloudIdentifierCmd.java b/api/src/com/cloud/api/commands/GetCloudIdentifierCmd.java index 030d4985014..269da9e4c98 100644 --- a/api/src/com/cloud/api/commands/GetCloudIdentifierCmd.java +++ b/api/src/com/cloud/api/commands/GetCloudIdentifierCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.CloudIdentifierResponse; +import com.cloud.user.Account; @Implementation(description="Retrieves a cloud identifier.", responseObject=CloudIdentifierResponse.class) public class GetCloudIdentifierCmd extends BaseCmd { @@ -59,6 +60,11 @@ public class GetCloudIdentifierCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ ArrayList result = _mgr.getCloudIdentifierResponse(this); diff --git a/api/src/com/cloud/api/commands/GetVMPasswordCmd.java b/api/src/com/cloud/api/commands/GetVMPasswordCmd.java index 45ecafcba7a..c41ca77c836 100644 --- a/api/src/com/cloud/api/commands/GetVMPasswordCmd.java +++ b/api/src/com/cloud/api/commands/GetVMPasswordCmd.java @@ -9,6 +9,8 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.GetVMPasswordResponse; +import com.cloud.user.Account; +import com.cloud.uservm.UserVm; @Implementation(responseObject=GetVMPasswordResponse.class, description="Returns an encrypted password for the VM") public class GetVMPasswordCmd extends BaseCmd { @@ -45,6 +47,16 @@ public class GetVMPasswordCmd extends BaseCmd { this.setResponseObject(new GetVMPasswordResponse(getCommandName(), passwd)); } + + @Override + public long getEntityOwnerId() { + UserVm userVm = _entityMgr.findById(UserVm.class, getId()); + if (userVm != null) { + return userVm.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public String getCommandName() { diff --git a/api/src/com/cloud/api/commands/ListCapabilitiesCmd.java b/api/src/com/cloud/api/commands/ListCapabilitiesCmd.java index 3ff55fd8a03..22d44848484 100644 --- a/api/src/com/cloud/api/commands/ListCapabilitiesCmd.java +++ b/api/src/com/cloud/api/commands/ListCapabilitiesCmd.java @@ -24,6 +24,7 @@ import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.response.CapabilitiesResponse; +import com.cloud.user.Account; @Implementation(description="Lists capabilities", responseObject=CapabilitiesResponse.class) public class ListCapabilitiesCmd extends BaseCmd { @@ -36,6 +37,11 @@ public class ListCapabilitiesCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ Map capabilities = _mgr.listCapabilities(this); diff --git a/api/src/com/cloud/api/commands/ListHypervisorsCmd.java b/api/src/com/cloud/api/commands/ListHypervisorsCmd.java index e017fc2eb66..b25dd5edbde 100644 --- a/api/src/com/cloud/api/commands/ListHypervisorsCmd.java +++ b/api/src/com/cloud/api/commands/ListHypervisorsCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.HypervisorResponse; import com.cloud.api.response.ListResponse; +import com.cloud.user.Account; @Implementation(description="List hypervisors", responseObject=HypervisorResponse.class) public class ListHypervisorsCmd extends BaseCmd { @@ -57,6 +58,10 @@ public class ListHypervisorsCmd extends BaseCmd { ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/ListTemplateOrIsoPermissionsCmd.java b/api/src/com/cloud/api/commands/ListTemplateOrIsoPermissionsCmd.java index 2cd24400a0e..ae6fe30bfbb 100644 --- a/api/src/com/cloud/api/commands/ListTemplateOrIsoPermissionsCmd.java +++ b/api/src/com/cloud/api/commands/ListTemplateOrIsoPermissionsCmd.java @@ -67,6 +67,15 @@ public class ListTemplateOrIsoPermissionsCmd extends BaseCmd { ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// + @Override + public long getEntityOwnerId() { + VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId()); + if (template != null) { + return template.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public String getCommandName() { diff --git a/api/src/com/cloud/api/commands/LockAccountCmd.java b/api/src/com/cloud/api/commands/LockAccountCmd.java index fffa4feb84b..278f9354fe3 100644 --- a/api/src/com/cloud/api/commands/LockAccountCmd.java +++ b/api/src/com/cloud/api/commands/LockAccountCmd.java @@ -23,7 +23,6 @@ import com.cloud.api.ApiConstants; 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.AccountResponse; import com.cloud.user.Account; @@ -63,17 +62,27 @@ public class LockAccountCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + Account account = _accountService.getActiveAccount(getAccountName(), getDomainId()); + if (account != null) { + return account.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public void execute(){ - Account result = null; +// Account result = null; //result = _accountService.lockAccount(this); - if (result != null){ - AccountResponse response = _responseGenerator.createAccountResponse(result); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to lock account"); - } +// if (result != null){ +// AccountResponse response = _responseGenerator.createAccountResponse(result); +// response.setResponseName(getCommandName()); +// this.setResponseObject(response); +// } else { +// throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to lock account"); +// } } } diff --git a/api/src/com/cloud/api/commands/LockUserCmd.java b/api/src/com/cloud/api/commands/LockUserCmd.java index 5f46bc8f56c..85eeab33be4 100644 --- a/api/src/com/cloud/api/commands/LockUserCmd.java +++ b/api/src/com/cloud/api/commands/LockUserCmd.java @@ -25,6 +25,8 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.UserResponse; +import com.cloud.user.Account; +import com.cloud.user.User; import com.cloud.user.UserAccount; @Implementation(description="Locks a user account", responseObject=UserResponse.class) @@ -56,6 +58,16 @@ public class LockUserCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + User user = _entityMgr.findById(User.class, getId()); + if (user != null) { + return user.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/QueryAsyncJobResultCmd.java b/api/src/com/cloud/api/commands/QueryAsyncJobResultCmd.java index 95694874cde..910aea2df17 100644 --- a/api/src/com/cloud/api/commands/QueryAsyncJobResultCmd.java +++ b/api/src/com/cloud/api/commands/QueryAsyncJobResultCmd.java @@ -25,6 +25,7 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.AsyncJobResponse; +import com.cloud.user.Account; @Implementation(description="Retrieves the current status of asynchronous job.", responseObject=AsyncJobResponse.class) public class QueryAsyncJobResultCmd extends BaseCmd { @@ -54,6 +55,11 @@ public class QueryAsyncJobResultCmd extends BaseCmd { @Override public String getCommandName() { return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; } @Override diff --git a/api/src/com/cloud/api/commands/RecoverVMCmd.java b/api/src/com/cloud/api/commands/RecoverVMCmd.java index c048a87eda9..193f7e6a0f6 100644 --- a/api/src/com/cloud/api/commands/RecoverVMCmd.java +++ b/api/src/com/cloud/api/commands/RecoverVMCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.UserVmResponse; import com.cloud.exception.ResourceAllocationException; +import com.cloud.user.Account; import com.cloud.uservm.UserVm; @Implementation(description="Recovers a virtual machine.", responseObject=UserVmResponse.class) @@ -59,6 +60,16 @@ public class RecoverVMCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + UserVm userVm = _entityMgr.findById(UserVm.class, getId()); + if (userVm != null) { + return userVm.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute() throws ResourceAllocationException{ UserVm result = _userVmService.recoverVirtualMachine(this); diff --git a/api/src/com/cloud/api/commands/RegisterCmd.java b/api/src/com/cloud/api/commands/RegisterCmd.java index 62db077944e..8d44d7088c2 100644 --- a/api/src/com/cloud/api/commands/RegisterCmd.java +++ b/api/src/com/cloud/api/commands/RegisterCmd.java @@ -25,6 +25,8 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.RegisterResponse; +import com.cloud.user.Account; +import com.cloud.user.User; @Implementation(responseObject=RegisterResponse.class, description="This command allows a user to register for the developer API, returning a secret key and an API key. This request is made through the integration API port, so it is a privileged command and must be made on behalf of a user. It is up to the implementer just how the username and password are entered, and then how that translates to an integration API request. Both secret key and API key should be returned to the user") public class RegisterCmd extends BaseCmd { @@ -53,6 +55,16 @@ public class RegisterCmd extends BaseCmd { public String getCommandName() { return s_name; + } + + @Override + public long getEntityOwnerId() { + User user = _entityMgr.findById(User.class, getId()); + if (user != null) { + return user.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked } @Override diff --git a/api/src/com/cloud/api/commands/RegisterIsoCmd.java b/api/src/com/cloud/api/commands/RegisterIsoCmd.java index 20d83ce2725..8569d3e4763 100755 --- a/api/src/com/cloud/api/commands/RegisterIsoCmd.java +++ b/api/src/com/cloud/api/commands/RegisterIsoCmd.java @@ -28,6 +28,8 @@ import com.cloud.api.response.ListResponse; import com.cloud.api.response.TemplateResponse; import com.cloud.exception.ResourceAllocationException; import com.cloud.template.VirtualMachineTemplate; +import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(responseObject=TemplateResponse.class, description="Registers an existing ISO into the Cloud.com Cloud.") public class RegisterIsoCmd extends BaseCmd { @@ -122,6 +124,25 @@ public class RegisterIsoCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if ((account == null) || isAdmin(account.getType())) { + if ((domainId != null) && (accountName != null)) { + Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); + if (userAccount != null) { + return userAccount.getId(); + } + } + } + + 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() throws ResourceAllocationException{ VirtualMachineTemplate template = _templateService.registerIso(this); diff --git a/api/src/com/cloud/api/commands/RegisterSSHKeyPairCmd.java b/api/src/com/cloud/api/commands/RegisterSSHKeyPairCmd.java index 6ef442f3e58..c8ea6c2517b 100644 --- a/api/src/com/cloud/api/commands/RegisterSSHKeyPairCmd.java +++ b/api/src/com/cloud/api/commands/RegisterSSHKeyPairCmd.java @@ -7,7 +7,9 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.response.SSHKeyPairResponse; +import com.cloud.user.Account; import com.cloud.user.SSHKeyPair; +import com.cloud.user.UserContext; @Implementation(description="Register a public key in a keypair under a certain name", responseObject=SSHKeyPairResponse.class) public class RegisterSSHKeyPairCmd extends BaseCmd { @@ -43,6 +45,17 @@ public class RegisterSSHKeyPairCmd extends BaseCmd { /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + + 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() { SSHKeyPair result = _mgr.registerSSHKeyPair(this); diff --git a/api/src/com/cloud/api/commands/RegisterTemplateCmd.java b/api/src/com/cloud/api/commands/RegisterTemplateCmd.java index 1eb46a9ac20..33edc5e264e 100755 --- a/api/src/com/cloud/api/commands/RegisterTemplateCmd.java +++ b/api/src/com/cloud/api/commands/RegisterTemplateCmd.java @@ -31,6 +31,8 @@ import com.cloud.api.response.TemplateResponse; import com.cloud.async.AsyncJob; import com.cloud.exception.ResourceAllocationException; import com.cloud.template.VirtualMachineTemplate; +import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(description="Registers an existing template into the Cloud.com cloud. ", responseObject=TemplateResponse.class) public class RegisterTemplateCmd extends BaseCmd { @@ -163,6 +165,25 @@ public class RegisterTemplateCmd extends BaseCmd { public AsyncJob.Type getInstanceType() { return AsyncJob.Type.Template; } + + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if ((account == null) || isAdmin(account.getType())) { + if ((domainId != null) && (accountName != null)) { + Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); + if (userAccount != null) { + return userAccount.getId(); + } + } + } + + 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() throws ResourceAllocationException{ diff --git a/api/src/com/cloud/api/commands/StartRouterCmd.java b/api/src/com/cloud/api/commands/StartRouterCmd.java index 3a2e1c6565c..12468d8d9a9 100644 --- a/api/src/com/cloud/api/commands/StartRouterCmd.java +++ b/api/src/com/cloud/api/commands/StartRouterCmd.java @@ -34,7 +34,6 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.router.VirtualRouter; import com.cloud.user.Account; -import com.cloud.uservm.UserVm; @Implementation(responseObject=DomainRouterResponse.class, description="Starts a router.") @@ -73,9 +72,9 @@ public class StartRouterCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - UserVm vm = _entityMgr.findById(UserVm.class, getId()); - if (vm != null) { - return vm.getAccountId(); + VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId()); + if (router != null) { + return router.getAccountId(); } return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked diff --git a/api/src/com/cloud/api/commands/StopRouterCmd.java b/api/src/com/cloud/api/commands/StopRouterCmd.java index 71a619dc80c..d60ff779eea 100644 --- a/api/src/com/cloud/api/commands/StopRouterCmd.java +++ b/api/src/com/cloud/api/commands/StopRouterCmd.java @@ -33,7 +33,6 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.router.VirtualRouter; import com.cloud.user.Account; -import com.cloud.uservm.UserVm; @Implementation(description="Stops a router.", responseObject=DomainRouterResponse.class) @@ -70,9 +69,9 @@ public class StopRouterCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - UserVm vm = _entityMgr.findById(UserVm.class, getId()); - if (vm != null) { - return vm.getAccountId(); + VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId()); + if (router != null) { + return router.getAccountId(); } return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked diff --git a/api/src/com/cloud/api/commands/UpdateAccountCmd.java b/api/src/com/cloud/api/commands/UpdateAccountCmd.java index 1553b379c7a..165d586963f 100644 --- a/api/src/com/cloud/api/commands/UpdateAccountCmd.java +++ b/api/src/com/cloud/api/commands/UpdateAccountCmd.java @@ -70,6 +70,16 @@ public class UpdateAccountCmd extends BaseCmd{ return s_name; } + @Override + public long getEntityOwnerId() { + Account account = _accountService.getActiveAccount(getAccountName(), getDomainId()); + if (account != null) { + return account.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ Account result = _accountService.updateAccount(this); diff --git a/api/src/com/cloud/api/commands/UpdateCfgCmd.java b/api/src/com/cloud/api/commands/UpdateCfgCmd.java index a563be4b93d..40c3f0c126a 100644 --- a/api/src/com/cloud/api/commands/UpdateCfgCmd.java +++ b/api/src/com/cloud/api/commands/UpdateCfgCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ConfigurationResponse; import com.cloud.configuration.Configuration; +import com.cloud.user.Account; @Implementation(description="Updates a configuration.", responseObject=ConfigurationResponse.class) public class UpdateCfgCmd extends BaseCmd { @@ -64,6 +65,11 @@ public class UpdateCfgCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ Configuration cfg = _configService.updateConfiguration(this); diff --git a/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java index 668e3f89bfc..549e1067d6b 100644 --- a/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java +++ b/api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.DiskOfferingResponse; import com.cloud.offering.DiskOffering; +import com.cloud.user.Account; @Implementation(description="Updates a disk offering.", responseObject=DiskOfferingResponse.class) public class UpdateDiskOfferingCmd extends BaseCmd{ @@ -71,6 +72,11 @@ public class UpdateDiskOfferingCmd extends BaseCmd{ return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ DiskOffering result = _configService.updateDiskOffering(this); diff --git a/api/src/com/cloud/api/commands/UpdateDomainCmd.java b/api/src/com/cloud/api/commands/UpdateDomainCmd.java index f2ebe4179b0..f2897fb099a 100644 --- a/api/src/com/cloud/api/commands/UpdateDomainCmd.java +++ b/api/src/com/cloud/api/commands/UpdateDomainCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.DomainResponse; import com.cloud.domain.Domain; +import com.cloud.user.Account; @Implementation(description="Updates a domain with a new name", responseObject=DomainResponse.class) public class UpdateDomainCmd extends BaseCmd { @@ -63,6 +64,11 @@ public class UpdateDomainCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ Domain domain = _mgr.updateDomain(this); diff --git a/api/src/com/cloud/api/commands/UpdateHostCmd.java b/api/src/com/cloud/api/commands/UpdateHostCmd.java index 5869e8f224a..d3d557f2b52 100644 --- a/api/src/com/cloud/api/commands/UpdateHostCmd.java +++ b/api/src/com/cloud/api/commands/UpdateHostCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.HostResponse; import com.cloud.host.Host; +import com.cloud.user.Account; @Implementation(description="Updates a host.", responseObject=HostResponse.class) public class UpdateHostCmd extends BaseCmd { @@ -68,6 +69,11 @@ public class UpdateHostCmd extends BaseCmd { return "updatehost"; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ Host result = _resourceService.updateHost(this); diff --git a/api/src/com/cloud/api/commands/UpdateIsoCmd.java b/api/src/com/cloud/api/commands/UpdateIsoCmd.java index 27ac88735c9..a4e7cc544bd 100755 --- a/api/src/com/cloud/api/commands/UpdateIsoCmd.java +++ b/api/src/com/cloud/api/commands/UpdateIsoCmd.java @@ -24,6 +24,7 @@ import com.cloud.api.Implementation; import com.cloud.api.ServerApiException; import com.cloud.api.response.TemplateResponse; import com.cloud.template.VirtualMachineTemplate; +import com.cloud.user.Account; @Implementation(description="Updates an ISO file.", responseObject=TemplateResponse.class) public class UpdateIsoCmd extends UpdateTemplateOrIsoCmd { @@ -53,6 +54,16 @@ public class UpdateIsoCmd extends UpdateTemplateOrIsoCmd { return s_name; } + @Override + public long getEntityOwnerId() { + VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId()); + if (template != null) { + return template.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ VirtualMachineTemplate result = _mgr.updateTemplate(this); diff --git a/api/src/com/cloud/api/commands/UpdateIsoPermissionsCmd.java b/api/src/com/cloud/api/commands/UpdateIsoPermissionsCmd.java index a98fd336a84..cb640693f7d 100644 --- a/api/src/com/cloud/api/commands/UpdateIsoPermissionsCmd.java +++ b/api/src/com/cloud/api/commands/UpdateIsoPermissionsCmd.java @@ -6,6 +6,8 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.user.Account; @Implementation(description="Updates iso permissions", responseObject=SuccessResponse.class) public class UpdateIsoPermissionsCmd extends UpdateTemplateOrIsoPermissionsCmd { @@ -17,6 +19,16 @@ public class UpdateIsoPermissionsCmd extends UpdateTemplateOrIsoPermissionsCmd { return Logger.getLogger(UpdateIsoPermissionsCmd.class.getName()); } + @Override + public long getEntityOwnerId() { + VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId()); + if (template != null) { + return template.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ boolean result = _mgr.updateTemplatePermissions(this); diff --git a/api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java index 901a841240d..67909676340 100644 --- a/api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java +++ b/api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java @@ -28,6 +28,7 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.NetworkOfferingResponse; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; +import com.cloud.user.Account; @Implementation(description="Updates a network offering.", responseObject=NetworkOfferingResponse.class) public class UpdateNetworkOfferingCmd extends BaseCmd { @@ -77,6 +78,11 @@ public class UpdateNetworkOfferingCmd extends BaseCmd { public String getCommandName() { return _name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/UpdatePodCmd.java b/api/src/com/cloud/api/commands/UpdatePodCmd.java index b149c6d5aa4..5f1c8d5733f 100644 --- a/api/src/com/cloud/api/commands/UpdatePodCmd.java +++ b/api/src/com/cloud/api/commands/UpdatePodCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.PodResponse; import com.cloud.dc.Pod; +import com.cloud.user.Account; @Implementation(description="Updates a Pod.", responseObject=PodResponse.class) public class UpdatePodCmd extends BaseCmd { @@ -93,6 +94,11 @@ public class UpdatePodCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ Pod result = _configService.editPod(this); diff --git a/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java b/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java index f2b841b930c..5b6daf5d4db 100644 --- a/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java +++ b/api/src/com/cloud/api/commands/UpdateResourceLimitCmd.java @@ -27,6 +27,8 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ResourceLimitResponse; import com.cloud.configuration.ResourceLimit; +import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(description="Updates resource limits for an account or domain.", responseObject=ResourceLimitResponse.class) public class UpdateResourceLimitCmd extends BaseCmd { @@ -83,6 +85,25 @@ public class UpdateResourceLimitCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if ((account == null) || isAdmin(account.getType())) { + if ((domainId != null) && (accountName != null)) { + Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId); + if (userAccount != null) { + return userAccount.getId(); + } + } + } + + 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(){ diff --git a/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java b/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java index 0233bfa1065..ec4fe63549a 100644 --- a/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java +++ b/api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ServiceOfferingResponse; import com.cloud.offering.ServiceOffering; +import com.cloud.user.Account; @Implementation(description="Updates a service offering.", responseObject=ServiceOfferingResponse.class) public class UpdateServiceOfferingCmd extends BaseCmd { @@ -72,6 +73,11 @@ public class UpdateServiceOfferingCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java b/api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java index ce1df5174b2..e786dbd25c0 100644 --- a/api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java +++ b/api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.StoragePoolResponse; import com.cloud.storage.StoragePool; +import com.cloud.user.Account; @Implementation(description="Updates a storage pool.", responseObject=StoragePoolResponse.class) public class UpdateStoragePoolCmd extends BaseCmd { @@ -65,6 +66,11 @@ public class UpdateStoragePoolCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ StoragePool result = _storageService.updateStoragePool(this); diff --git a/api/src/com/cloud/api/commands/UpdateTemplateCmd.java b/api/src/com/cloud/api/commands/UpdateTemplateCmd.java index 3b1e3532729..800bc008f3c 100755 --- a/api/src/com/cloud/api/commands/UpdateTemplateCmd.java +++ b/api/src/com/cloud/api/commands/UpdateTemplateCmd.java @@ -24,6 +24,7 @@ import com.cloud.api.Implementation; import com.cloud.api.ServerApiException; import com.cloud.api.response.TemplateResponse; import com.cloud.template.VirtualMachineTemplate; +import com.cloud.user.Account; @Implementation(description="Updates attributes of a template.", responseObject=TemplateResponse.class) public class UpdateTemplateCmd extends UpdateTemplateOrIsoCmd { @@ -53,6 +54,16 @@ public class UpdateTemplateCmd extends UpdateTemplateOrIsoCmd { return null; } + @Override + public long getEntityOwnerId() { + VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId()); + if (template != null) { + return template.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ VirtualMachineTemplate result = _mgr.updateTemplate(this); diff --git a/api/src/com/cloud/api/commands/UpdateTemplateOrIsoPermissionsCmd.java b/api/src/com/cloud/api/commands/UpdateTemplateOrIsoPermissionsCmd.java index eb54c844e4d..b7079c68b91 100644 --- a/api/src/com/cloud/api/commands/UpdateTemplateOrIsoPermissionsCmd.java +++ b/api/src/com/cloud/api/commands/UpdateTemplateOrIsoPermissionsCmd.java @@ -12,8 +12,6 @@ public abstract class UpdateTemplateOrIsoPermissionsCmd extends BaseCmd { public Logger s_logger = getLogger(); protected String s_name = getResponseName(); - - ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/commands/UpdateTemplatePermissionsCmd.java b/api/src/com/cloud/api/commands/UpdateTemplatePermissionsCmd.java index 53e4881b750..5d20da6b4b4 100644 --- a/api/src/com/cloud/api/commands/UpdateTemplatePermissionsCmd.java +++ b/api/src/com/cloud/api/commands/UpdateTemplatePermissionsCmd.java @@ -24,6 +24,8 @@ import com.cloud.api.BaseCmd; import com.cloud.api.Implementation; import com.cloud.api.ServerApiException; import com.cloud.api.response.SuccessResponse; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.user.Account; @Implementation(responseObject=SuccessResponse.class, description="Updates a template visibility permissions. " + "A public template is visible to all accounts within the same domain. " + @@ -39,6 +41,16 @@ public class UpdateTemplatePermissionsCmd extends UpdateTemplateOrIsoPermissions return Logger.getLogger(UpdateTemplatePermissionsCmd.class.getName()); } + @Override + public long getEntityOwnerId() { + VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, getId()); + if (template != null) { + return template.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ boolean result = _mgr.updateTemplatePermissions(this); diff --git a/api/src/com/cloud/api/commands/UpdateUserCmd.java b/api/src/com/cloud/api/commands/UpdateUserCmd.java index 6c43d12b2f0..5fc9ae03863 100644 --- a/api/src/com/cloud/api/commands/UpdateUserCmd.java +++ b/api/src/com/cloud/api/commands/UpdateUserCmd.java @@ -26,6 +26,8 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.UserResponse; +import com.cloud.user.Account; +import com.cloud.user.User; import com.cloud.user.UserAccount; @Implementation(description="Updates a user account", responseObject=UserResponse.class) @@ -113,6 +115,16 @@ public class UpdateUserCmd extends BaseCmd { public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + User user = _entityMgr.findById(User.class, getId()); + if (user != null) { + return user.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/UpdateVMCmd.java b/api/src/com/cloud/api/commands/UpdateVMCmd.java index 2d57e2eced7..103871f8da7 100644 --- a/api/src/com/cloud/api/commands/UpdateVMCmd.java +++ b/api/src/com/cloud/api/commands/UpdateVMCmd.java @@ -25,6 +25,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.UserVmResponse; +import com.cloud.user.Account; import com.cloud.user.UserContext; import com.cloud.uservm.UserVm; @@ -88,6 +89,16 @@ public class UpdateVMCmd extends BaseCmd{ public static String getResultObjectName() { return "virtualmachine"; } + + @Override + public long getEntityOwnerId() { + UserVm userVm = _entityMgr.findById(UserVm.class, getId()); + if (userVm != null) { + return userVm.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/UpdateVMGroupCmd.java b/api/src/com/cloud/api/commands/UpdateVMGroupCmd.java index 6b7b2777a91..5d2523ac6e7 100644 --- a/api/src/com/cloud/api/commands/UpdateVMGroupCmd.java +++ b/api/src/com/cloud/api/commands/UpdateVMGroupCmd.java @@ -25,6 +25,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.InstanceGroupResponse; +import com.cloud.user.Account; import com.cloud.vm.InstanceGroup; @Implementation(description="Updates a vm group", responseObject=InstanceGroupResponse.class) @@ -63,6 +64,16 @@ public class UpdateVMGroupCmd extends BaseCmd{ public String getCommandName() { return s_name; } + + @Override + public long getEntityOwnerId() { + InstanceGroup group = _entityMgr.findById(InstanceGroup.class, getId()); + if (group != null) { + return group.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } @Override public void execute(){ diff --git a/api/src/com/cloud/api/commands/UpdateZoneCmd.java b/api/src/com/cloud/api/commands/UpdateZoneCmd.java index 75ef5246617..5d5dd696502 100644 --- a/api/src/com/cloud/api/commands/UpdateZoneCmd.java +++ b/api/src/com/cloud/api/commands/UpdateZoneCmd.java @@ -27,6 +27,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.ZoneResponse; import com.cloud.dc.DataCenter; +import com.cloud.user.Account; @Implementation(description="Updates a Zone.", responseObject=ZoneResponse.class) public class UpdateZoneCmd extends BaseCmd { @@ -114,6 +115,11 @@ public class UpdateZoneCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + @Override public void execute(){ DataCenter result = _configService.editZone(this); diff --git a/api/src/com/cloud/api/commands/UpgradeRouterCmd.java b/api/src/com/cloud/api/commands/UpgradeRouterCmd.java index 11ee5c60325..598ec6b3921 100644 --- a/api/src/com/cloud/api/commands/UpgradeRouterCmd.java +++ b/api/src/com/cloud/api/commands/UpgradeRouterCmd.java @@ -26,6 +26,7 @@ import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.DomainRouterResponse; import com.cloud.network.router.VirtualRouter; +import com.cloud.user.Account; @Implementation(description="Upgrades domain router to a new service offering", responseObject=DomainRouterResponse.class) public class UpgradeRouterCmd extends BaseCmd { @@ -63,6 +64,16 @@ public class UpgradeRouterCmd extends BaseCmd { return s_name; } + @Override + public long getEntityOwnerId() { + VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId()); + if (router != null) { + return router.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ VirtualRouter router = _routerService.upgradeRouter(this); diff --git a/api/src/com/cloud/api/commands/UpgradeVMCmd.java b/api/src/com/cloud/api/commands/UpgradeVMCmd.java index 6f087172aa6..1073ffdaa06 100644 --- a/api/src/com/cloud/api/commands/UpgradeVMCmd.java +++ b/api/src/com/cloud/api/commands/UpgradeVMCmd.java @@ -25,6 +25,7 @@ import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; import com.cloud.api.response.UserVmResponse; +import com.cloud.user.Account; import com.cloud.user.UserContext; import com.cloud.uservm.UserVm; @@ -70,6 +71,16 @@ public class UpgradeVMCmd extends BaseCmd { return "virtualmachine"; } + @Override + public long getEntityOwnerId() { + UserVm userVm = _entityMgr.findById(UserVm.class, getId()); + if (userVm != null) { + return userVm.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + @Override public void execute(){ UserContext.current().setEventDetails("Vm Id: "+getId()); diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index fb0be283bdb..598bf944585 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -124,10 +124,11 @@ public class ApiDispatcher { String errorMsg = ""; setupParameters(cmd, params); try { + UserContext ctx = UserContext.current(); + ctx.setAccountId(cmd.getEntityOwnerId()); if(cmd instanceof BaseAsyncCmd){ - UserContext ctx = UserContext.current(); + BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmd; - ctx.setAccountId(asyncCmd.getEntityOwnerId()); String startEventId = params.get("ctxStartEventId"); ctx.setStartEventId(Long.valueOf(startEventId)); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index d2a5900ce1c..2b7f5d836d9 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1728,6 +1728,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER); } + sb.and("removed", sb.entity().getRemoved(), Op.NULL); + SearchCriteria sc = sb.create(); if (!isSystem) { @@ -1787,6 +1789,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!isSystem && path != null && (isShared == null || !isShared)) { sc.setJoinParameters("domainSearch", "path", path + "%"); } + + List networks = _networksDao.search(sc, searchFilter); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index a8982b8928b..62bc35c81e0 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -4741,65 +4741,80 @@ public class ManagementServerImpl implements ManagementServer { @Override public SSHKeyPair createSSHKeyPair(CreateSSHKeyPairCmd cmd) { - Account account = UserContext.current().getCaller(); - SSHKeyPairVO s = _sshKeyPairDao.findByName(account.getAccountId(), account.getDomainId(), cmd.getName()); - if (s != null) { - throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists."); - } + Account account = UserContext.current().getCaller(); + SSHKeyPairVO s = _sshKeyPairDao.findByName(account.getAccountId(), account.getDomainId(), cmd.getName()); + if (s != null) { + throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists."); + } - SSHKeysHelper keys = new SSHKeysHelper(); + SSHKeysHelper keys = new SSHKeysHelper(); - String name = cmd.getName(); - String publicKey = keys.getPublicKey(); - String fingerprint = keys.getPublicKeyFingerPrint(); - String privateKey = keys.getPrivateKey(); + String name = cmd.getName(); + String publicKey = keys.getPublicKey(); + String fingerprint = keys.getPublicKeyFingerPrint(); + String privateKey = keys.getPrivateKey(); - return createAndSaveSSHKeyPair(name, fingerprint, publicKey, privateKey); + return createAndSaveSSHKeyPair(name, fingerprint, publicKey, privateKey); } @Override public boolean deleteSSHKeyPair(DeleteSSHKeyPairCmd cmd) { - Account account = UserContext.current().getCaller(); - SSHKeyPairVO s = _sshKeyPairDao.findByName(account.getAccountId(), account.getDomainId(), cmd.getName()); - if (s == null) { - throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' does not exist."); - } - - return _sshKeyPairDao.deleteByName(account.getAccountId(), account.getDomainId(), cmd.getName()); + Account caller = UserContext.current().getCaller(); + String accountName = cmd.getAccountName(); + Long domainId = cmd.getDomainId(); + Account owner = null; + + if (accountName != null && domainId != null) { + owner = _accountMgr.getActiveAccount(accountName, domainId); + } + + if (owner == null) { + owner = caller; + } else { + //check account permissions + _accountMgr.checkAccess(caller, owner); + } + + SSHKeyPairVO s = _sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), cmd.getName()); + if (s == null) { + throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' does not exist."); + } + + return _sshKeyPairDao.deleteByName(caller.getAccountId(), caller.getDomainId(), cmd.getName()); } @Override public List listSSHKeyPairs(ListSSHKeyPairsCmd cmd) { - Account account = UserContext.current().getCaller(); - - if (cmd.getName() != null && cmd.getName().length() > 0) { - return _sshKeyPairDao.listKeyPairsByName(account.getAccountId(), account.getDomainId(), cmd.getName()); - } - - if (cmd.getFingerprint() != null && cmd.getFingerprint().length() > 0) { - return _sshKeyPairDao.listKeyPairsByFingerprint(account.getAccountId(), account.getDomainId(), cmd.getFingerprint()); - } - - return _sshKeyPairDao.listKeyPairs(account.getAccountId(), account.getDomainId()); + Account account = UserContext.current().getCaller(); + + if (cmd.getName() != null && cmd.getName().length() > 0) { + return _sshKeyPairDao.listKeyPairsByName(account.getAccountId(), account.getDomainId(), cmd.getName()); + } + + if (cmd.getFingerprint() != null && cmd.getFingerprint().length() > 0) { + return _sshKeyPairDao.listKeyPairsByFingerprint(account.getAccountId(), account.getDomainId(), cmd.getFingerprint()); + } + + return _sshKeyPairDao.listKeyPairs(account.getAccountId(), account.getDomainId()); } @Override public SSHKeyPair registerSSHKeyPair(RegisterSSHKeyPairCmd cmd) { - Account account = UserContext.current().getCaller(); - SSHKeyPairVO s = _sshKeyPairDao.findByName(account.getAccountId(), account.getDomainId(), cmd.getName()); - if (s != null) { - throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists."); - } + Account account = UserContext.current().getCaller(); + SSHKeyPairVO s = _sshKeyPairDao.findByName(account.getAccountId(), account.getDomainId(), cmd.getName()); + if (s != null) { + throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists."); + } - String name = cmd.getName(); - String publicKey = SSHKeysHelper.getPublicKeyFromKeyMaterial(cmd.getPublicKey()); - String fingerprint = SSHKeysHelper.getPublicKeyFingerprint(publicKey); + String name = cmd.getName(); + String publicKey = SSHKeysHelper.getPublicKeyFromKeyMaterial(cmd.getPublicKey()); + String fingerprint = SSHKeysHelper.getPublicKeyFingerprint(publicKey); - if (publicKey == null) { - throw new InvalidParameterValueException("Public key is invalid"); - } + if (publicKey == null) { + throw new InvalidParameterValueException("Public key is invalid"); + } - return createAndSaveSSHKeyPair(name, fingerprint, publicKey, null); + return createAndSaveSSHKeyPair(name, fingerprint, publicKey, null); } private SSHKeyPair createAndSaveSSHKeyPair(String name, String fingerprint, String publicKey, String privateKey) {