You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/12/13 02:53:07 UTC
git commit: updated refs/heads/rbac to d2922b9
Updated Branches:
refs/heads/rbac 312ff76f6 -> d2922b925
Separate ListAccounts cmd to use two different views.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d2922b92
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d2922b92
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d2922b92
Branch: refs/heads/rbac
Commit: d2922b9254cdc93f579a66ed5e5ea79bb0feaedc
Parents: 312ff76
Author: Min Chen <mi...@citrix.com>
Authored: Thu Dec 12 17:52:45 2013 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Thu Dec 12 17:52:45 2013 -0800
----------------------------------------------------------------------
.../cloudstack/api/ResponseGenerator.java | 4 +-
.../command/admin/account/CreateAccountCmd.java | 17 +++---
.../admin/account/DisableAccountCmd.java | 9 +--
.../command/admin/account/EnableAccountCmd.java | 8 ++-
.../admin/account/ListAccountsCmdByAdmin.java | 26 +++++++++
.../command/admin/account/UpdateAccountCmd.java | 8 ++-
.../zone/MarkDefaultZoneForAccountCmd.java | 8 ++-
.../command/user/account/ListAccountsCmd.java | 8 ++-
.../api/command/LdapCreateAccountCmd.java | 8 ++-
server/src/com/cloud/api/ApiDBUtils.java | 4 +-
server/src/com/cloud/api/ApiResponseHelper.java | 8 +--
.../com/cloud/api/query/QueryManagerImpl.java | 9 ++-
.../com/cloud/api/query/ViewResponseHelper.java | 4 +-
.../com/cloud/api/query/dao/AccountJoinDao.java | 3 +-
.../cloud/api/query/dao/AccountJoinDaoImpl.java | 58 ++++++++++----------
15 files changed, 115 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
index efc1726..4bb2907 100644
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -198,7 +198,7 @@ import com.cloud.vm.snapshot.VMSnapshot;
public interface ResponseGenerator {
UserResponse createUserResponse(UserAccount user);
- AccountResponse createAccountResponse(Account account);
+ AccountResponse createAccountResponse(ResponseView view, Account account);
DomainResponse createDomainResponse(Domain domain);
@@ -317,7 +317,7 @@ public interface ResponseGenerator {
UserResponse createUserResponse(User user);
- AccountResponse createUserAccountResponse(UserAccount user);
+ AccountResponse createUserAccountResponse(ResponseView view, UserAccount user);
Long getSecurityGroupId(String groupName, long accountId);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
index 94325f6..539cddd 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
@@ -16,23 +16,24 @@
// under the License.
package org.apache.cloudstack.api.command.admin.account;
-import com.cloud.user.Account;
-import com.cloud.user.UserAccount;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.context.CallContext;
-import org.apache.log4j.Logger;
-
-import java.util.Collection;
-import java.util.Map;
+import com.cloud.user.Account;
+import com.cloud.user.UserAccount;
@APICommand(name = "createAccount", description="Creates an account", responseObject=AccountResponse.class)
public class CreateAccountCmd extends BaseCmd {
@@ -166,9 +167,9 @@ public class CreateAccountCmd extends BaseCmd {
UserAccount userAccount = _accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(),
getDomainId(), getNetworkDomain(), getDetails(), getAccountUUID(), getUserUUID());
if (userAccount != null) {
- AccountResponse response = _responseGenerator.createUserAccountResponse(userAccount);
+ AccountResponse response = _responseGenerator.createUserAccountResponse(ResponseView.Full, userAccount);
response.setResponseName(getCommandName());
- this.setResponseObject(response);
+ setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a user account");
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
index 806a8a5..c47ea24 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
@@ -18,20 +18,21 @@ package org.apache.cloudstack.api.command.admin.account;
import javax.inject.Inject;
+import org.apache.log4j.Logger;
+
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.region.RegionService;
-import org.apache.log4j.Logger;
-
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceUnavailableException;
@@ -120,9 +121,9 @@ public class DisableAccountCmd extends BaseAsyncCmd {
CallContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
Account result = _regionService.disableAccount(this);
if (result != null){
- AccountResponse response = _responseGenerator.createAccountResponse(result);
+ AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
response.setResponseName(getCommandName());
- this.setResponseObject(response);
+ setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, lockRequested == true ? "Failed to lock account" : "Failed to disable account" );
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java
index b9a9f6d..82ba9cc 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java
@@ -18,16 +18,18 @@ package org.apache.cloudstack.api.command.admin.account;
import javax.inject.Inject;
+import org.apache.log4j.Logger;
+
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.region.RegionService;
-import org.apache.log4j.Logger;
import com.cloud.user.Account;
@@ -96,9 +98,9 @@ public class EnableAccountCmd extends BaseCmd {
public void execute(){
Account result = _regionService.enableAccount(this);
if (result != null){
- AccountResponse response = _responseGenerator.createAccountResponse(result);
+ AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
response.setResponseName(getCommandName());
- this.setResponseObject(response);
+ setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable account");
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/api/src/org/apache/cloudstack/api/command/admin/account/ListAccountsCmdByAdmin.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/ListAccountsCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/account/ListAccountsCmdByAdmin.java
new file mode 100644
index 0000000..555567b
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/ListAccountsCmdByAdmin.java
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.account;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
+import org.apache.cloudstack.api.response.AccountResponse;
+
+@APICommand(name = "listAccounts", description = "Lists accounts and provides detailed account information for listed accounts", responseObject = AccountResponse.class, responseView = ResponseView.Full)
+public class ListAccountsCmdByAdmin extends ListAccountsCmd {
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java
index 60d1a97..6d4e403 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java
@@ -21,16 +21,18 @@ import java.util.Map;
import javax.inject.Inject;
+import org.apache.log4j.Logger;
+
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.region.RegionService;
-import org.apache.log4j.Logger;
import com.cloud.user.Account;
@@ -126,9 +128,9 @@ public class UpdateAccountCmd extends BaseCmd{
public void execute(){
Account result = _regionService.updateAccount(this);
if (result != null){
- AccountResponse response = _responseGenerator.createAccountResponse(result);
+ AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
response.setResponseName(getCommandName());
- this.setResponseObject(response);
+ setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update account");
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java
index 5696bfd..6f50623 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java
@@ -17,17 +17,19 @@
package org.apache.cloudstack.api.command.admin.zone;
+import org.apache.log4j.Logger;
+
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
-import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.user.Account;
@@ -103,9 +105,9 @@ public class MarkDefaultZoneForAccountCmd extends BaseAsyncCmd {
public void execute(){
Account result = _configService.markDefaultZone(getAccountName(),getDomainId(), getDefaultZoneId());
if (result != null) {
- AccountResponse response = _responseGenerator.createAccountResponse(result);
+ AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
response.setResponseName(getCommandName());
- this.setResponseObject(response);
+ setResponseObject(response);
}
else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to mark the account with the default zone");
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java b/api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
index ebf2e4b..d9dcada 100644
--- a/api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
@@ -16,15 +16,17 @@
// under the License.
package org.apache.cloudstack.api.command.user.account;
+import org.apache.log4j.Logger;
+
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ListResponse;
-import org.apache.log4j.Logger;
-@APICommand(name = "listAccounts", description="Lists accounts and provides detailed account information for listed accounts", responseObject=AccountResponse.class)
+@APICommand(name = "listAccounts", description = "Lists accounts and provides detailed account information for listed accounts", responseObject = AccountResponse.class, responseView = ResponseView.Restricted)
public class ListAccountsCmd extends BaseListDomainResourcesCmd {
public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName());
private static final String s_name = "listaccountsresponse";
@@ -87,6 +89,6 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd {
public void execute(){
ListResponse<AccountResponse> response = _queryService.searchForAccounts(this);
response.setResponseName(getCommandName());
- this.setResponseObject(response);
+ setResponseObject(response);
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java
index 981e72e..fbb652e 100644
--- a/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java
+++ b/plugins/user-authenticators/ldap/src/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java
@@ -23,19 +23,21 @@ import java.util.Map;
import javax.inject.Inject;
import javax.naming.NamingException;
+import org.apache.log4j.Logger;
+import org.bouncycastle.util.encoders.Base64;
+
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.ldap.LdapManager;
import org.apache.cloudstack.ldap.LdapUser;
-import org.apache.log4j.Logger;
-import org.bouncycastle.util.encoders.Base64;
import com.cloud.user.Account;
import com.cloud.user.AccountService;
@@ -106,7 +108,7 @@ public class LdapCreateAccountCmd extends BaseCmd {
final UserAccount userAccount = createCloudstackUserAccount(user);
if (userAccount != null) {
final AccountResponse response = _responseGenerator
- .createUserAccountResponse(userAccount);
+ .createUserAccountResponse(ResponseView.Full, userAccount);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index e54884b..5b894fb 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -1607,8 +1607,8 @@ public class ApiDBUtils {
}
- public static AccountResponse newAccountResponse(AccountJoinVO ve) {
- return _accountJoinDao.newAccountResponse(ve);
+ public static AccountResponse newAccountResponse(ResponseView view, AccountJoinVO ve) {
+ return _accountJoinDao.newAccountResponse(view, ve);
}
public static AccountJoinVO newAccountView(Account e){
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 1470d43..b3f42f8 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -335,14 +335,14 @@ public class ApiResponseHelper implements ResponseGenerator {
// this method is used for response generation via createAccount (which
// creates an account + user)
@Override
- public AccountResponse createUserAccountResponse(UserAccount user) {
- return ApiDBUtils.newAccountResponse(ApiDBUtils.findAccountViewById(user.getAccountId()));
+ public AccountResponse createUserAccountResponse(ResponseView view, UserAccount user) {
+ return ApiDBUtils.newAccountResponse(view, ApiDBUtils.findAccountViewById(user.getAccountId()));
}
@Override
- public AccountResponse createAccountResponse(Account account) {
+ public AccountResponse createAccountResponse(ResponseView view, Account account) {
AccountJoinVO vUser = ApiDBUtils.newAccountView(account);
- return ApiDBUtils.newAccountResponse(vUser);
+ return ApiDBUtils.newAccountResponse(view, vUser);
}
@Override
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java
index 64b606c..ce2eccd 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -43,6 +43,7 @@ import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
import org.apache.cloudstack.api.ResourceDetail;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.account.ListAccountsCmdByAdmin;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.internallb.ListInternalLBVMsCmd;
import org.apache.cloudstack.api.command.admin.iso.ListIsosCmdByAdmin;
@@ -1773,7 +1774,13 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
public ListResponse<AccountResponse> searchForAccounts(ListAccountsCmd cmd) {
Pair<List<AccountJoinVO>, Integer> result = searchForAccountsInternal(cmd);
ListResponse<AccountResponse> response = new ListResponse<AccountResponse>();
- List<AccountResponse> accountResponses = ViewResponseHelper.createAccountResponse(result.first().toArray(
+
+ ResponseView respView = ResponseView.Restricted;
+ if (cmd instanceof ListAccountsCmdByAdmin) {
+ respView = ResponseView.Full;
+ }
+
+ List<AccountResponse> accountResponses = ViewResponseHelper.createAccountResponse(respView, result.first().toArray(
new AccountJoinVO[result.first().size()]));
response.setResponses(accountResponses, result.second());
return response;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/server/src/com/cloud/api/query/ViewResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/ViewResponseHelper.java b/server/src/com/cloud/api/query/ViewResponseHelper.java
index ae46328..478cbfb 100644
--- a/server/src/com/cloud/api/query/ViewResponseHelper.java
+++ b/server/src/com/cloud/api/query/ViewResponseHelper.java
@@ -338,10 +338,10 @@ public class ViewResponseHelper {
}
- public static List<AccountResponse> createAccountResponse(AccountJoinVO... accounts) {
+ public static List<AccountResponse> createAccountResponse(ResponseView view, AccountJoinVO... accounts) {
List<AccountResponse> respList = new ArrayList<AccountResponse>();
for (AccountJoinVO vt : accounts){
- respList.add(ApiDBUtils.newAccountResponse(vt));
+ respList.add(ApiDBUtils.newAccountResponse(view, vt));
}
return respList;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/server/src/com/cloud/api/query/dao/AccountJoinDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/AccountJoinDao.java b/server/src/com/cloud/api/query/dao/AccountJoinDao.java
index 01d37a6..1e19774 100644
--- a/server/src/com/cloud/api/query/dao/AccountJoinDao.java
+++ b/server/src/com/cloud/api/query/dao/AccountJoinDao.java
@@ -16,6 +16,7 @@
// under the License.
package com.cloud.api.query.dao;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ResourceLimitAndCountResponse;
@@ -25,7 +26,7 @@ import com.cloud.utils.db.GenericDao;
public interface AccountJoinDao extends GenericDao<AccountJoinVO, Long> {
- AccountResponse newAccountResponse(AccountJoinVO vol);
+ AccountResponse newAccountResponse(ResponseView view, AccountJoinVO vol);
AccountJoinVO newAccountView(Account vol);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d2922b92/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java
index bcc5e1a..da13bad 100644
--- a/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/AccountJoinDaoImpl.java
@@ -24,6 +24,7 @@ import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
+import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.AclGroupResponse;
import org.apache.cloudstack.api.response.ResourceLimitAndCountResponse;
@@ -60,7 +61,7 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
}
@Override
- public AccountResponse newAccountResponse(AccountJoinVO account) {
+ public AccountResponse newAccountResponse(ResponseView view, AccountJoinVO account) {
AccountResponse accountResponse = new AccountResponse();
accountResponse.setId(account.getUuid());
accountResponse.setName(account.getAccountName());
@@ -76,14 +77,14 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
accountResponse.setBytesReceived(account.getBytesReceived());
accountResponse.setBytesSent(account.getBytesSent());
- boolean accountIsAdmin = (_accountMgr.isRootAdmin(account.getId()));
- setResourceLimits(account, accountIsAdmin, accountResponse);
+ boolean fullView = (view == ResponseView.Full);
+ setResourceLimits(account, fullView, accountResponse);
//get resource limits for projects
long projectLimit = ApiDBUtils.findCorrectResourceLimit(account.getProjectLimit(), account.getId(), ResourceType.project);
- String projectLimitDisplay = (accountIsAdmin || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
+ String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
long projectTotal = (account.getProjectTotal() == null) ? 0 : account.getProjectTotal();
- String projectAvail = (accountIsAdmin || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
+ String projectAvail = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
accountResponse.setProjectLimit(projectLimitDisplay);
accountResponse.setProjectTotal(projectTotal);
accountResponse.setProjectAvailable(projectAvail);
@@ -113,18 +114,18 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
@Override
- public void setResourceLimits(AccountJoinVO account, boolean accountIsAdmin, ResourceLimitAndCountResponse response) {
+ public void setResourceLimits(AccountJoinVO account, boolean fullView, ResourceLimitAndCountResponse response) {
// Get resource limits and counts
long vmLimit = ApiDBUtils.findCorrectResourceLimit(account.getVmLimit(), account.getId(), ResourceType.user_vm);
- String vmLimitDisplay = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit);
+ String vmLimitDisplay = (fullView || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit);
long vmTotal = (account.getVmTotal() == null) ? 0 : account.getVmTotal();
- String vmAvail = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal);
+ String vmAvail = (fullView || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal);
response.setVmLimit(vmLimitDisplay);
response.setVmTotal(vmTotal);
response.setVmAvailable(vmAvail);
long ipLimit = ApiDBUtils.findCorrectResourceLimit(account.getIpLimit(), account.getId(), ResourceType.public_ip);
- String ipLimitDisplay = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit);
+ String ipLimitDisplay = (fullView || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit);
long ipTotal = (account.getIpTotal() == null) ? 0 : account.getIpTotal();
Long ips = ipLimit - ipTotal;
@@ -137,32 +138,32 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
unlimited = false;
}
- String ipAvail = ((accountIsAdmin || ipLimit == -1) && unlimited) ? "Unlimited" : String.valueOf(ips);
+ String ipAvail = ((fullView || ipLimit == -1) && unlimited) ? "Unlimited" : String.valueOf(ips);
response.setIpLimit(ipLimitDisplay);
response.setIpTotal(ipTotal);
response.setIpAvailable(ipAvail);
long volumeLimit = ApiDBUtils.findCorrectResourceLimit(account.getVolumeLimit(), account.getId(), ResourceType.volume);
- String volumeLimitDisplay = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit);
+ String volumeLimitDisplay = (fullView || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit);
long volumeTotal = (account.getVolumeTotal() == 0) ? 0 : account.getVolumeTotal();
- String volumeAvail = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal);
+ String volumeAvail = (fullView || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal);
response.setVolumeLimit(volumeLimitDisplay);
response.setVolumeTotal(volumeTotal);
response.setVolumeAvailable(volumeAvail);
long snapshotLimit = ApiDBUtils.findCorrectResourceLimit(account.getSnapshotLimit(), account.getId(), ResourceType.snapshot);
- String snapshotLimitDisplay = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit);
+ String snapshotLimitDisplay = (fullView || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit);
long snapshotTotal = (account.getSnapshotTotal() == null) ? 0 : account.getSnapshotTotal();
- String snapshotAvail = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal);
+ String snapshotAvail = (fullView || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal);
response.setSnapshotLimit(snapshotLimitDisplay);
response.setSnapshotTotal(snapshotTotal);
response.setSnapshotAvailable(snapshotAvail);
Long templateLimit = ApiDBUtils.findCorrectResourceLimit(account.getTemplateLimit(), account.getId(), ResourceType.template);
- String templateLimitDisplay = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit);
+ String templateLimitDisplay = (fullView || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit);
Long templateTotal = (account.getTemplateTotal() == null) ? 0 : account.getTemplateTotal();
- String templateAvail = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal);
+ String templateAvail = (fullView || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal);
response.setTemplateLimit(templateLimitDisplay);
response.setTemplateTotal(templateTotal);
response.setTemplateAvailable(templateAvail);
@@ -173,54 +174,55 @@ public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> impl
//get resource limits for networks
long networkLimit = ApiDBUtils.findCorrectResourceLimit(account.getNetworkLimit(), account.getId(), ResourceType.network);
- String networkLimitDisplay = (accountIsAdmin || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit);
+ String networkLimitDisplay = (fullView || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit);
long networkTotal = (account.getNetworkTotal() == null) ? 0 : account.getNetworkTotal();
- String networkAvail = (accountIsAdmin || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit - networkTotal);
+ String networkAvail = (fullView || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit - networkTotal);
response.setNetworkLimit(networkLimitDisplay);
response.setNetworkTotal(networkTotal);
response.setNetworkAvailable(networkAvail);
//get resource limits for vpcs
long vpcLimit = ApiDBUtils.findCorrectResourceLimit(account.getVpcLimit(), account.getId(), ResourceType.vpc);
- String vpcLimitDisplay = (accountIsAdmin || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit);
+ String vpcLimitDisplay = (fullView || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit);
long vpcTotal = (account.getVpcTotal() == null) ? 0 : account.getVpcTotal();
- String vpcAvail = (accountIsAdmin || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit - vpcTotal);
+ String vpcAvail = (fullView || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit - vpcTotal);
response.setVpcLimit(vpcLimitDisplay);
response.setVpcTotal(vpcTotal);
response.setVpcAvailable(vpcAvail);
//get resource limits for cpu cores
long cpuLimit = ApiDBUtils.findCorrectResourceLimit(account.getCpuLimit(), account.getId(), ResourceType.cpu);
- String cpuLimitDisplay = (accountIsAdmin || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit);
+ String cpuLimitDisplay = (fullView || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit);
long cpuTotal = (account.getCpuTotal() == null) ? 0 : account.getCpuTotal();
- String cpuAvail = (accountIsAdmin || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit - cpuTotal);
+ String cpuAvail = (fullView || cpuLimit == -1) ? "Unlimited" : String.valueOf(cpuLimit - cpuTotal);
response.setCpuLimit(cpuLimitDisplay);
response.setCpuTotal(cpuTotal);
response.setCpuAvailable(cpuAvail);
//get resource limits for memory
long memoryLimit = ApiDBUtils.findCorrectResourceLimit(account.getMemoryLimit(), account.getId(), ResourceType.memory);
- String memoryLimitDisplay = (accountIsAdmin || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit);
+ String memoryLimitDisplay = (fullView || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit);
long memoryTotal = (account.getMemoryTotal() == null) ? 0 : account.getMemoryTotal();
- String memoryAvail = (accountIsAdmin || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit - memoryTotal);
+ String memoryAvail = (fullView || memoryLimit == -1) ? "Unlimited" : String.valueOf(memoryLimit - memoryTotal);
response.setMemoryLimit(memoryLimitDisplay);
response.setMemoryTotal(memoryTotal);
response.setMemoryAvailable(memoryAvail);
//get resource limits for primary storage space and convert it from Bytes to GiB
long primaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getPrimaryStorageLimit(), account.getId(), ResourceType.primary_storage);
- String primaryStorageLimitDisplay = (accountIsAdmin || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf(primaryStorageLimit / ResourceType.bytesToGiB);
+ String primaryStorageLimitDisplay = (fullView || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf(primaryStorageLimit / ResourceType.bytesToGiB);
long primaryStorageTotal = (account.getPrimaryStorageTotal() == null) ? 0 : (account.getPrimaryStorageTotal() / ResourceType.bytesToGiB);
- String primaryStorageAvail = (accountIsAdmin || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf((primaryStorageLimit / ResourceType.bytesToGiB) - primaryStorageTotal);
+ String primaryStorageAvail = (fullView || primaryStorageLimit == -1) ? "Unlimited" : String.valueOf((primaryStorageLimit / ResourceType.bytesToGiB) - primaryStorageTotal);
response.setPrimaryStorageLimit(primaryStorageLimitDisplay);
response.setPrimaryStorageTotal(primaryStorageTotal);
response.setPrimaryStorageAvailable(primaryStorageAvail);
//get resource limits for secondary storage space and convert it from Bytes to GiB
long secondaryStorageLimit = ApiDBUtils.findCorrectResourceLimit(account.getSecondaryStorageLimit(), account.getId(), ResourceType.secondary_storage);
- String secondaryStorageLimitDisplay = (accountIsAdmin || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf(secondaryStorageLimit / ResourceType.bytesToGiB);
+ String secondaryStorageLimitDisplay = (fullView || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf(secondaryStorageLimit / ResourceType.bytesToGiB);
long secondaryStorageTotal = (account.getSecondaryStorageTotal() == null) ? 0 : (account.getSecondaryStorageTotal() / ResourceType.bytesToGiB);
- String secondaryStorageAvail = (accountIsAdmin || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf((secondaryStorageLimit / ResourceType.bytesToGiB) - secondaryStorageTotal);
+ String secondaryStorageAvail = (fullView || secondaryStorageLimit == -1) ? "Unlimited" : String.valueOf((secondaryStorageLimit / ResourceType.bytesToGiB)
+ - secondaryStorageTotal);
response.setSecondaryStorageLimit(secondaryStorageLimitDisplay);
response.setSecondaryStorageTotal(secondaryStorageTotal);
response.setSecondaryStorageAvailable(secondaryStorageAvail);