diff --git a/server/src/com/cloud/api/commands/CreateVolumeCmd.java b/server/src/com/cloud/api/commands/CreateVolumeCmd.java index 2c40ebdeb3d..c0ca6f5c742 100644 --- a/server/src/com/cloud/api/commands/CreateVolumeCmd.java +++ b/server/src/com/cloud/api/commands/CreateVolumeCmd.java @@ -109,6 +109,7 @@ public class CreateVolumeCmd extends BaseCmd { /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// + @Override public String getName() { return s_name; } @@ -117,8 +118,8 @@ public class CreateVolumeCmd extends BaseCmd { return "volume"; } - public List> getProperties() { - return s_properties; + @Override + public String getResponse() { } @Override diff --git a/server/src/com/cloud/api/commands/ListAccountsCmd.java b/server/src/com/cloud/api/commands/ListAccountsCmd.java index 983467eb8f2..d4b7f3b9028 100644 --- a/server/src/com/cloud/api/commands/ListAccountsCmd.java +++ b/server/src/com/cloud/api/commands/ListAccountsCmd.java @@ -21,44 +21,29 @@ package com.cloud.api.commands; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Map; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; -import com.cloud.api.BaseCmd.CommandType; import com.cloud.api.BaseListCmd; +import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; +import com.cloud.api.response.AccountResponse; import com.cloud.configuration.ResourceCount.ResourceType; -import com.cloud.domain.DomainVO; +import com.cloud.serializer.SerializerHelper; import com.cloud.server.Criteria; import com.cloud.user.Account; import com.cloud.user.AccountVO; +import com.cloud.user.UserContext; import com.cloud.user.UserStatisticsVO; import com.cloud.uservm.UserVm; -import com.cloud.utils.Pair; import com.cloud.vm.State; - -public class ListAccountsCmd extends BaseListCmd{ + +@Implementation(method="searchForAccounts") +public class ListAccountsCmd extends BaseListCmd { public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName()); private static final String s_name = "listaccountsresponse"; - private static final List> s_properties = new ArrayList>(); - - static { - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_TYPE, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.IS_CLEANUP_REQUIRED, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.KEYWORD, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.NAME, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.PAGE, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.PAGESIZE, Boolean.FALSE)); - s_properties.add(new Pair(BaseCmd.Properties.STATE, Boolean.FALSE)); - - s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); - } ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -122,186 +107,121 @@ public class ListAccountsCmd extends BaseListCmd{ /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// + @Override public String getName() { return s_name; - } - public List> getProperties() { - return s_properties; - } - - @Override - public List> execute(Map params) { - Long id = (Long)params.get(BaseCmd.Properties.ID.getName()); - Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName()); - Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName()); - Long type = (Long)params.get(BaseCmd.Properties.ACCOUNT_TYPE.getName()); - String state = (String)params.get(BaseCmd.Properties.STATE.getName()); - Boolean needCleanup = (Boolean)params.get(BaseCmd.Properties.IS_CLEANUP_REQUIRED.getName()); - Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName()); - Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName()); - String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName()); - boolean isAdmin = false; - Long accountId = null; - - String accountName = null; - - if ((account == null) || isAdmin(account.getType())) { - accountName = (String)params.get(BaseCmd.Properties.NAME.getName()); - isAdmin = true; - if (domainId == null) { - // default domainId to the admin's domain - domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId()); - } else if (account != null) { - if (!getManagementServer().isChildDomain(account.getDomainId(), domainId)) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list accounts"); - } - } - } else { - accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName()); - accountId = account.getId(); - } - - Long startIndex = Long.valueOf(0); - int pageSizeNum = 50; - if (pageSize != null) { - pageSizeNum = pageSize.intValue(); - } - if (page != null) { - int pageNum = page.intValue(); - if (pageNum > 0) { - startIndex = Long.valueOf(pageSizeNum * (pageNum-1)); - } - } - Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum)); - if (isAdmin == true) { - c.addCriteria(Criteria.ID, id); - if (keyword == null) { - c.addCriteria(Criteria.ACCOUNTNAME, accountName); - c.addCriteria(Criteria.DOMAINID, domainId); - c.addCriteria(Criteria.TYPE, type); - c.addCriteria(Criteria.STATE, state); - c.addCriteria(Criteria.ISCLEANUPREQUIRED, needCleanup); - } else { - c.addCriteria(Criteria.KEYWORD, keyword); - } - } else { - c.addCriteria(Criteria.ID, accountId); - } - - List accounts = getManagementServer().searchForAccounts(c); - - List> accountTags = new ArrayList>(); - Object[] aTag = new Object[accounts.size()]; - int i = 0; - for (AccountVO accountO : accounts) { - boolean accountIsAdmin = (accountO.getType() == Account.ACCOUNT_TYPE_ADMIN); - - if ((accountO.getRemoved() == null)&&(accountO.getId() != 1)) { - List> accountData = new ArrayList>(); - accountData.add(new Pair(BaseCmd.Properties.ID.getName(), Long.valueOf(accountO.getId()).toString())); - accountData.add(new Pair(BaseCmd.Properties.NAME.getName(), accountO.getAccountName())); - accountData.add(new Pair(BaseCmd.Properties.ACCOUNT_TYPE.getName(), Short.valueOf(accountO.getType()).toString())); - DomainVO domain = getManagementServer().findDomainIdById(accountO.getDomainId()); - accountData.add(new Pair(BaseCmd.Properties.DOMAIN_ID.getName(), domain.getId().toString())); - accountData.add(new Pair(BaseCmd.Properties.DOMAIN.getName(), domain.getName())); - - //get network stat - List stats = getManagementServer().listUserStatsBy(accountO.getId()); - if (stats == null) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error searching for user stats"); - } - - long bytesSent = 0; - long bytesReceived = 0; - for (UserStatisticsVO stat : stats) { - long rx = stat.getNetBytesReceived() + stat.getCurrentBytesReceived(); - long tx = stat.getNetBytesSent() + stat.getCurrentBytesSent(); - bytesReceived = bytesReceived + Long.valueOf(rx); - bytesSent = bytesSent + Long.valueOf(tx); - } - accountData.add(new Pair(BaseCmd.Properties.BYTES_RECEIVED.getName(), Long.valueOf(bytesReceived).toString())); - accountData.add(new Pair(BaseCmd.Properties.BYTES_SENT.getName(), Long.valueOf(bytesSent).toString())); - - // Get resource limits and counts - - long vmLimit = getManagementServer().findCorrectResourceLimit(ResourceType.user_vm, accountO.getId()); - String vmLimitDisplay = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit); - long vmTotal = getManagementServer().getResourceCount(ResourceType.user_vm, accountO.getId()); - String vmAvail = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal); - accountData.add(new Pair(BaseCmd.Properties.VM_LIMIT.getName(), vmLimitDisplay)); - accountData.add(new Pair(BaseCmd.Properties.VM_TOTAL.getName(), vmTotal)); - accountData.add(new Pair(BaseCmd.Properties.VM_AVAIL.getName(), vmAvail)); - - long ipLimit = getManagementServer().findCorrectResourceLimit(ResourceType.public_ip, accountO.getId()); - String ipLimitDisplay = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit); - long ipTotal = getManagementServer().getResourceCount(ResourceType.public_ip, accountO.getId()); - String ipAvail = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit - ipTotal); - accountData.add(new Pair(BaseCmd.Properties.IP_LIMIT.getName(), ipLimitDisplay)); - accountData.add(new Pair(BaseCmd.Properties.IP_TOTAL.getName(), ipTotal)); - accountData.add(new Pair(BaseCmd.Properties.IP_AVAIL.getName(), ipAvail)); - - long volumeLimit = getManagementServer().findCorrectResourceLimit(ResourceType.volume, accountO.getId()); - String volumeLimitDisplay = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit); - long volumeTotal = getManagementServer().getResourceCount(ResourceType.volume, accountO.getId()); - String volumeAvail = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal); - accountData.add(new Pair(BaseCmd.Properties.VOLUME_LIMIT.getName(), volumeLimitDisplay)); - accountData.add(new Pair(BaseCmd.Properties.VOLUME_TOTAL.getName(), volumeTotal)); - accountData.add(new Pair(BaseCmd.Properties.VOLUME_AVAIL.getName(), volumeAvail)); - - long snapshotLimit = getManagementServer().findCorrectResourceLimit(ResourceType.snapshot, accountO.getId()); - String snapshotLimitDisplay = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit); - long snapshotTotal = getManagementServer().getResourceCount(ResourceType.snapshot, accountO.getId()); - String snapshotAvail = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal); - accountData.add(new Pair(BaseCmd.Properties.SNAPSHOT_LIMIT.getName(), snapshotLimitDisplay)); - accountData.add(new Pair(BaseCmd.Properties.SNAPSHOT_TOTAL.getName(), snapshotTotal)); - accountData.add(new Pair(BaseCmd.Properties.SNAPSHOT_AVAIL.getName(), snapshotAvail)); - - long templateLimit = getManagementServer().findCorrectResourceLimit(ResourceType.template, accountO.getId()); - String templateLimitDisplay = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit); - long templateTotal = getManagementServer().getResourceCount(ResourceType.template, accountO.getId()); - String templateAvail = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal); - accountData.add(new Pair(BaseCmd.Properties.TEMPLATE_LIMIT.getName(), templateLimitDisplay)); - accountData.add(new Pair(BaseCmd.Properties.TEMPLATE_TOTAL.getName(), templateTotal)); - accountData.add(new Pair(BaseCmd.Properties.TEMPLATE_AVAIL.getName(), templateAvail)); - - // Get stopped and running VMs - - int vmStopped = 0; - int vmRunning = 0; - - Long[] accountIds = new Long[1]; - accountIds[0] = accountO.getId(); - - Criteria c1 = new Criteria(); - c1.addCriteria(Criteria.ACCOUNTID, accountIds); - List virtualMachines = getManagementServer().searchForUserVMs(c1); - - //get Running/Stopped VMs - for (Iterator iter = virtualMachines.iterator(); iter.hasNext();) { - // count how many stopped/running vms we have - UserVm vm = iter.next(); - - if (vm.getState() == State.Stopped) { - vmStopped++; - } else if (vm.getState() == State.Running) { - vmRunning++; - } - } - - accountData.add(new Pair(BaseCmd.Properties.VM_STOPPED.getName(), vmStopped)); - accountData.add(new Pair(BaseCmd.Properties.VM_RUNNING.getName(), vmRunning)); - - //show this info to admins only - if (isAdmin == true) { - accountData.add(new Pair(BaseCmd.Properties.STATE.getName(), accountO.getState())); - accountData.add(new Pair(BaseCmd.Properties.IS_CLEANUP_REQUIRED.getName(), Boolean.valueOf(accountO.getNeedsCleanup()).toString())); - } - - aTag[i++] = accountData; - } - } - Pair accountTag = new Pair("account", aTag); - accountTags.add(accountTag); - return accountTags; + } + + @Override @SuppressWarnings("unchecked") + public String getResponse() { + List accounts = (List)getResponseObject(); + + List response = new ArrayList(); + for (AccountVO account : accounts) { + boolean accountIsAdmin = (account.getType() == Account.ACCOUNT_TYPE_ADMIN); + + AccountResponse acctResponse = new AccountResponse(); + acctResponse.setId(account.getId()); + acctResponse.setName(account.getAccountName()); + acctResponse.setAccountType(account.getType()); + acctResponse.setDomainId(account.getDomainId()); + acctResponse.setDomainName(getManagementServer().findDomainIdById(account.getDomainId()).getName()); + + //get network stat + List stats = getManagementServer().listUserStatsBy(account.getId()); + if (stats == null) { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error searching for user stats"); + } + + long bytesSent = 0; + long bytesReceived = 0; + for (UserStatisticsVO stat : stats) { + long rx = stat.getNetBytesReceived() + stat.getCurrentBytesReceived(); + long tx = stat.getNetBytesSent() + stat.getCurrentBytesSent(); + bytesReceived = bytesReceived + Long.valueOf(rx); + bytesSent = bytesSent + Long.valueOf(tx); + } + acctResponse.setBytesReceived(bytesReceived); + acctResponse.setBytesSent(bytesSent); + + // Get resource limits and counts + + long vmLimit = getManagementServer().findCorrectResourceLimit(ResourceType.user_vm, account.getId()); + String vmLimitDisplay = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit); + long vmTotal = getManagementServer().getResourceCount(ResourceType.user_vm, account.getId()); + String vmAvail = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal); + acctResponse.setVmLimit(vmLimitDisplay); + acctResponse.setVmTotal(vmTotal); + acctResponse.setVmAvailable(vmAvail); + + long ipLimit = getManagementServer().findCorrectResourceLimit(ResourceType.public_ip, account.getId()); + String ipLimitDisplay = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit); + long ipTotal = getManagementServer().getResourceCount(ResourceType.public_ip, account.getId()); + String ipAvail = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit - ipTotal); + acctResponse.setIpLimit(ipLimitDisplay); + acctResponse.setIpTotal(ipTotal); + acctResponse.setIpAvailable(ipAvail); + + long volumeLimit = getManagementServer().findCorrectResourceLimit(ResourceType.volume, account.getId()); + String volumeLimitDisplay = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit); + long volumeTotal = getManagementServer().getResourceCount(ResourceType.volume, account.getId()); + String volumeAvail = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal); + acctResponse.setVolumeLimit(volumeLimitDisplay); + acctResponse.setVolumeTotal(volumeTotal); + acctResponse.setVolumeAvailable(volumeAvail); + + long snapshotLimit = getManagementServer().findCorrectResourceLimit(ResourceType.snapshot, accountO.getId()); + String snapshotLimitDisplay = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit); + long snapshotTotal = getManagementServer().getResourceCount(ResourceType.snapshot, accountO.getId()); + String snapshotAvail = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal); + acctResponse.setSnapshotLimit(snapshotLimitDisplay); + acctResponse.setSnapshotTotal(snapshotTotal); + acctResponse.setSnapshotAvailable(snapshotAvail); + + long templateLimit = getManagementServer().findCorrectResourceLimit(ResourceType.template, accountO.getId()); + String templateLimitDisplay = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit); + long templateTotal = getManagementServer().getResourceCount(ResourceType.template, accountO.getId()); + String templateAvail = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal); + acctResponse.setTemplateLimit(templateLimitDisplay); + acctResponse.setTemplateTotal(templateTotal); + acctResponse.setTemplateAvailable(templateAvail); + + // Get stopped and running VMs + int vmStopped = 0; + int vmRunning = 0; + + Long[] accountIds = new Long[1]; + accountIds[0] = account.getId(); + + Criteria c1 = new Criteria(); + c1.addCriteria(Criteria.ACCOUNTID, accountIds); + List virtualMachines = getManagementServer().searchForUserVMs(c1); + + //get Running/Stopped VMs + for (Iterator iter = virtualMachines.iterator(); iter.hasNext();) { + // count how many stopped/running vms we have + UserVm vm = iter.next(); + + if (vm.getState() == State.Stopped) { + vmStopped++; + } else if (vm.getState() == State.Running) { + vmRunning++; + } + } + + acctResponse.setVmStopped(vmStopped); + acctResponse.setVmRunning(vmRunning); + + //show this info to admins only + Account ctxAccount = (Account)UserContext.current().getAccountObject(); + if ((ctxAccount == null) || isAdmin(ctxAccount.getType())) { + acctResponse.setState(account.getState()); + acctResponse.setCleanupRequired(account.getNeedsCleanup()); + } + + response.add(acctResponse); + } + + return SerializerHelper.toSerializedString(response); } } diff --git a/server/src/com/cloud/api/response/AccountResponse.java b/server/src/com/cloud/api/response/AccountResponse.java new file mode 100644 index 00000000000..b52970dec82 --- /dev/null +++ b/server/src/com/cloud/api/response/AccountResponse.java @@ -0,0 +1,309 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.api.response; + +import com.cloud.api.ResponseObject; +import com.cloud.serializer.Param; + +public class AccountResponse implements ResponseObject { + @Param(name="id") + private Long id; + + @Param(name="name") + private String name; + + @Param(name="accounttype") + private Short accountType; + + @Param(name="domainid") + private Long domainId; + + @Param(name="domain") + private String domainName; + + @Param(name="receivedbytes") + private Long bytesReceived; + + @Param(name="sentbytes") + private Long bytesSent; + + @Param(name="vmlimit") + private String vmLimit; + + @Param(name="vmtotal") + private Long vmTotal; + + @Param(name="vmavailable") + private String vmAvailable; + + @Param(name="iplimit") + private String ipLimit; + + @Param(name="iptotal") + private Long ipTotal; + + @Param(name="ipavailable") + private String ipAvailable; + + @Param(name="volumelimit") + private String volumeLimit; + + @Param(name="volumetotal") + private Long volumeTotal; + + @Param(name="volumeavailable") + private String volumeAvailable; + + @Param(name="snapshotlimit") + private String snapshotLimit; + + @Param(name="snapshottotal") + private Long snapshotTotal; + + @Param(name="snapshotavailable") + private String snapshotAvailable; + + @Param(name="templatelimit") + private String templateLimit; + + @Param(name="templatetotal") + private Long templateTotal; + + @Param(name="templateavailable") + private String templateAvailable; + + @Param(name="vmstopped") + private Integer vmStopped; + + @Param(name="vmrunning") + private Integer vmRunning; + + @Param(name="state") + private String state; + + @Param(name="iscleanuprequired") + private Boolean cleanupRequired; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Short getAccountType() { + return accountType; + } + + public void setAccountType(Short accountType) { + this.accountType = accountType; + } + + public Long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public Long getBytesReceived() { + return bytesReceived; + } + + public void setBytesReceived(Long bytesReceived) { + this.bytesReceived = bytesReceived; + } + + public Long getBytesSent() { + return bytesSent; + } + + public void setBytesSent(Long bytesSent) { + this.bytesSent = bytesSent; + } + + public String getVmLimit() { + return vmLimit; + } + + public void setVmLimit(String vmLimit) { + this.vmLimit = vmLimit; + } + + public Long getVmTotal() { + return vmTotal; + } + + public void setVmTotal(Long vmTotal) { + this.vmTotal = vmTotal; + } + + public String getVmAvailable() { + return vmAvailable; + } + + public void setVmAvailable(String vmAvailable) { + this.vmAvailable = vmAvailable; + } + + public String getIpLimit() { + return ipLimit; + } + + public void setIpLimit(String ipLimit) { + this.ipLimit = ipLimit; + } + + public Long getIpTotal() { + return ipTotal; + } + + public void setIpTotal(Long ipTotal) { + this.ipTotal = ipTotal; + } + + public String getIpAvailable() { + return ipAvailable; + } + + public void setIpAvailable(String ipAvailable) { + this.ipAvailable = ipAvailable; + } + + public String getVolumeLimit() { + return volumeLimit; + } + + public void setVolumeLimit(String volumeLimit) { + this.volumeLimit = volumeLimit; + } + + public Long getVolumeTotal() { + return volumeTotal; + } + + public void setVolumeTotal(Long volumeTotal) { + this.volumeTotal = volumeTotal; + } + + public String getVolumeAvailable() { + return volumeAvailable; + } + + public void setVolumeAvailable(String volumeAvailable) { + this.volumeAvailable = volumeAvailable; + } + + public String getSnapshotLimit() { + return snapshotLimit; + } + + public void setSnapshotLimit(String snapshotLimit) { + this.snapshotLimit = snapshotLimit; + } + + public Long getSnapshotTotal() { + return snapshotTotal; + } + + public void setSnapshotTotal(Long snapshotTotal) { + this.snapshotTotal = snapshotTotal; + } + + public String getSnapshotAvailable() { + return snapshotAvailable; + } + + public void setSnapshotAvailable(String snapshotAvailable) { + this.snapshotAvailable = snapshotAvailable; + } + + public String getTemplateLimit() { + return templateLimit; + } + + public void setTemplateLimit(String templateLimit) { + this.templateLimit = templateLimit; + } + + public Long getTemplateTotal() { + return templateTotal; + } + + public void setTemplateTotal(Long templateTotal) { + this.templateTotal = templateTotal; + } + + public String getTemplateAvailable() { + return templateAvailable; + } + + public void setTemplateAvailable(String templateAvailable) { + this.templateAvailable = templateAvailable; + } + + public Integer getVmStopped() { + return vmStopped; + } + + public void setVmStopped(Integer vmStopped) { + this.vmStopped = vmStopped; + } + + public Integer getVmRunning() { + return vmRunning; + } + + public void setVmRunning(Integer vmRunning) { + this.vmRunning = vmRunning; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public Boolean getCleanupRequired() { + return cleanupRequired; + } + + public void setCleanupRequired(Boolean cleanupRequired) { + this.cleanupRequired = cleanupRequired; + } +} diff --git a/server/src/com/cloud/server/ManagementServer.java b/server/src/com/cloud/server/ManagementServer.java index 3498511ce4d..3c89c823153 100644 --- a/server/src/com/cloud/server/ManagementServer.java +++ b/server/src/com/cloud/server/ManagementServer.java @@ -27,7 +27,6 @@ import com.cloud.api.commands.AssignPortForwardingServiceCmd; import com.cloud.api.commands.CreateDomainCmd; import com.cloud.api.commands.CreatePortForwardingServiceCmd; import com.cloud.api.commands.CreatePortForwardingServiceRuleCmd; -import com.cloud.api.commands.CreateSnapshotCmd; import com.cloud.api.commands.CreateUserCmd; import com.cloud.api.commands.DeletePortForwardingServiceCmd; import com.cloud.api.commands.DeleteUserCmd; @@ -35,6 +34,7 @@ import com.cloud.api.commands.DeployVMCmd; import com.cloud.api.commands.EnableAccountCmd; import com.cloud.api.commands.EnableUserCmd; import com.cloud.api.commands.GetCloudIdentifierCmd; +import com.cloud.api.commands.ListAccountsCmd; import com.cloud.api.commands.ListAlertsCmd; import com.cloud.api.commands.ListAsyncJobsCmd; import com.cloud.api.commands.ListCapacityCmd; @@ -1049,10 +1049,10 @@ public interface ManagementServer { /** * Searches for accounts by the specified search criteria * Can search by: "id", "name", "domainid", "type" - * @param c + * @param cmd * @return List of Accounts */ - List searchForAccounts(Criteria c); + List searchForAccounts(ListAccountsCmd cmd); /** diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 512cbcfc8c2..5f68f8a40fa 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -58,7 +58,6 @@ import com.cloud.api.commands.AssignPortForwardingServiceCmd; import com.cloud.api.commands.CreateDomainCmd; import com.cloud.api.commands.CreatePortForwardingServiceCmd; import com.cloud.api.commands.CreatePortForwardingServiceRuleCmd; -import com.cloud.api.commands.CreateSnapshotCmd; import com.cloud.api.commands.CreateUserCmd; import com.cloud.api.commands.CreateVolumeCmd; import com.cloud.api.commands.DeletePortForwardingServiceCmd; @@ -67,6 +66,7 @@ import com.cloud.api.commands.DeployVMCmd; import com.cloud.api.commands.EnableAccountCmd; import com.cloud.api.commands.EnableUserCmd; import com.cloud.api.commands.GetCloudIdentifierCmd; +import com.cloud.api.commands.ListAccountsCmd; import com.cloud.api.commands.ListAlertsCmd; import com.cloud.api.commands.ListAsyncJobsCmd; import com.cloud.api.commands.ListCapacityCmd; @@ -208,7 +208,6 @@ import com.cloud.storage.LaunchPermissionVO; import com.cloud.storage.Snapshot; import com.cloud.storage.Snapshot.SnapshotType; import com.cloud.storage.SnapshotPolicyVO; -import com.cloud.storage.SnapshotScheduleVO; import com.cloud.storage.SnapshotVO; import com.cloud.storage.Storage; import com.cloud.storage.Storage.ImageFormat; @@ -236,7 +235,6 @@ import com.cloud.storage.preallocatedlun.PreallocatedLunVO; import com.cloud.storage.preallocatedlun.dao.PreallocatedLunDao; import com.cloud.storage.secondary.SecondaryStorageVmManager; import com.cloud.storage.snapshot.SnapshotManager; -import com.cloud.storage.snapshot.SnapshotScheduler; import com.cloud.template.TemplateManager; import com.cloud.user.Account; import com.cloud.user.AccountManager; @@ -351,7 +349,6 @@ public class ManagementServerImpl implements ManagementServer { private final AsyncJobManager _asyncMgr; private final TemplateManager _tmpltMgr; private final SnapshotManager _snapMgr; - private final SnapshotScheduler _snapshotScheduler; private final NetworkGroupManager _networkGroupMgr; private final int _purgeDelay; private final boolean _directAttachNetworkExternalIpAllocator; @@ -444,7 +441,6 @@ public class ManagementServerImpl implements ManagementServer { _asyncMgr = locator.getManager(AsyncJobManager.class); _tmpltMgr = locator.getManager(TemplateManager.class); _snapMgr = locator.getManager(SnapshotManager.class); - _snapshotScheduler = locator.getManager(SnapshotScheduler.class); _networkGroupMgr = locator.getManager(NetworkGroupManager.class); _userAuthenticators = locator.getAdapters(UserAuthenticator.class); @@ -3372,16 +3368,31 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public List searchForAccounts(Criteria c) { - Filter searchFilter = new Filter(AccountVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit()); + public List searchForAccounts(ListAccountsCmd cmd) { + Account account = (Account)UserContext.current().getAccountObject(); + Long domainId = cmd.getDomainId(); + String accountName = cmd.getAccountName(); + Long accountId = cmd.getId(); - Object id = c.getCriteria(Criteria.ID); - Object accountname = c.getCriteria(Criteria.ACCOUNTNAME); - Object domainId = c.getCriteria(Criteria.DOMAINID); - Object type = c.getCriteria(Criteria.TYPE); - Object state = c.getCriteria(Criteria.STATE); - Object isCleanupRequired = c.getCriteria(Criteria.ISCLEANUPREQUIRED); - Object keyword = c.getCriteria(Criteria.KEYWORD); + if ((account == null) || isAdmin(account.getType())) { + if (domainId == null) { + // default domainId to the admin's domain + domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId()); + } else if (account != null) { + if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) { + throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list accounts"); + } + } + } else { + accountId = account.getId(); + } + + Filter searchFilter = new Filter(AccountVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); + + Object type = cmd.getAccountType(); + Object state = cmd.getState(); + Object isCleanupRequired = cmd.isCleanupRequired(); + Object keyword = cmd.getKeyword(); SearchBuilder sb = _accountDao.createSearchBuilder(); sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.LIKE); @@ -3390,7 +3401,7 @@ public class ManagementServerImpl implements ManagementServer { sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); sb.and("needsCleanup", sb.entity().getNeedsCleanup(), SearchCriteria.Op.EQ); - if ((id == null) && (domainId != null)) { + if ((accountId == null) && (domainId != null)) { // if accountId isn't specified, we can do a domain match for the admin case SearchBuilder domainSearch = _domainDao.createSearchBuilder(); domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE); @@ -3406,12 +3417,12 @@ public class ManagementServerImpl implements ManagementServer { sc.addAnd("accountName", SearchCriteria.Op.SC, ssc); } - if (accountname != null) { - sc.setParameters("accountName", "%" + accountname + "%"); + if (accountName != null) { + sc.setParameters("accountName", "%" + accountName + "%"); } - if (id != null) { - sc.setParameters("id", id); + if (accountId != null) { + sc.setParameters("id", accountId); } else if (domainId != null) { DomainVO domain = _domainDao.findById((Long)domainId); @@ -3719,7 +3730,7 @@ public class ManagementServerImpl implements ManagementServer { c.addCriteria(Criteria.HOSTID, cmd.getHostId()); } - c.addCriteria(Criteria.ACCOUNTID, accountId); + c.addCriteria(Criteria.ACCOUNTID, new Object[] {accountId}); c.addCriteria(Criteria.ISADMIN, isAdmin); return searchForUserVMs(c);