mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Separate ListAccounts cmd to use two different views.
This commit is contained in:
parent
312ff76f69
commit
d2922b9254
@ -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);
|
||||
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
@ -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" );
|
||||
}
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
}
|
||||
@ -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");
|
||||
}
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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){
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user