mirror of https://github.com/apache/cloudstack.git
Refactoring listStoragePoolsAndHosts command to new API framework.
This commit is contained in:
parent
1e46e2e588
commit
460ef94299
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
|
@ -26,14 +27,21 @@ import java.util.Set;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.response.HostResponse;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostStats;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.storage.GuestOSCategoryVO;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
|
||||
@Implementation(method="searchForServers")
|
||||
public class ListHostsCmd extends BaseListCmd {
|
||||
|
|
@ -135,60 +143,56 @@ public class ListHostsCmd extends BaseListCmd {
|
|||
hostResponse.setVersion(host.getVersion());
|
||||
|
||||
// TODO: implement
|
||||
// GuestOSCategoryVO guestOSCategory = getManagementServer().getHostGuestOSCategory(server.getId());
|
||||
// if (guestOSCategory != null) {
|
||||
// serverData.add(new Pair<String, Object>(BaseCmd.Properties.OS_CATEGORY_ID.getName(), guestOSCategory.getId()));
|
||||
// serverData.add(new Pair<String, Object>(BaseCmd.Properties.OS_CATEGORY_NAME.getName(), guestOSCategory.getName()));
|
||||
// hostResponse.setOsCategoryId(osCategoryId);
|
||||
// hostResponse.setOsCategoryName(osCategoryName);
|
||||
// }
|
||||
// hostResponse.setZoneName(zoneName);
|
||||
// serverData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), getManagementServer().getDataCenterBy(server.getDataCenterId()).getName()));
|
||||
// hostResponse.setPodName(podName);
|
||||
// serverData.add(new Pair<String, Object>(BaseCmd.Properties.POD_NAME.getName(), getManagementServer().findHostPodById(server.getPodId()).getName()));
|
||||
GuestOSCategoryVO guestOSCategory = getManagementServer().getHostGuestOSCategory(host.getId());
|
||||
if (guestOSCategory != null) {
|
||||
hostResponse.setOsCategoryId(guestOSCategory.getId());
|
||||
hostResponse.setOsCategoryName(guestOSCategory.getName());
|
||||
}
|
||||
hostResponse.setZoneName(getManagementServer().getDataCenterBy(host.getDataCenterId()).getName());
|
||||
hostResponse.setPodName(getManagementServer().findHostPodById(host.getPodId()).getName());
|
||||
|
||||
// calculate cpu allocated by vm
|
||||
// int cpu = 0;
|
||||
// String cpuAlloc = null;
|
||||
// DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
// List<UserVmVO> instances = getManagementServer().listUserVMsByHostId(host.getId());
|
||||
// for (UserVmVO vm : instances) {
|
||||
// ServiceOffering so = getManagementServer().findServiceOfferingById(vm.getServiceOfferingId());
|
||||
// cpu += so.getCpu() * so.getSpeed();
|
||||
// }
|
||||
// cpuAlloc = decimalFormat.format(((float) cpu / (float) (host.getCpus() * host.getSpeed())) * 100f) + "%";
|
||||
// hostResponse.setCpuAllocated(cpuAlloc);
|
||||
int cpu = 0;
|
||||
String cpuAlloc = null;
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
List<UserVmVO> instances = getManagementServer().listUserVMsByHostId(host.getId());
|
||||
for (UserVmVO vm : instances) {
|
||||
ServiceOffering so = getManagementServer().findServiceOfferingById(vm.getServiceOfferingId());
|
||||
cpu += so.getCpu() * so.getSpeed();
|
||||
}
|
||||
cpuAlloc = decimalFormat.format(((float) cpu / (float) (host.getCpus() * host.getSpeed())) * 100f) + "%";
|
||||
hostResponse.setCpuAllocated(cpuAlloc);
|
||||
|
||||
// calculate cpu utilized
|
||||
// String cpuUsed = null;
|
||||
// HostStats hostStats = getManagementServer().getHostStatistics(host.getId());
|
||||
// if (hostStats != null) {
|
||||
// float cpuUtil = (float) hostStats.getCpuUtilization();
|
||||
// cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
||||
// hostResponse.setCpuUsed(cpuUsed);
|
||||
// hostResponse.setAverageLoad((long)hostStats.getAverageLoad());
|
||||
// hostResponse.setNetworkKbsRead((long)hostStats.getNetworkReadKBs());
|
||||
// hostResponse.setNetworkKbsWrite((long)hostStats.getNetworkWriteKBs());
|
||||
// }
|
||||
String cpuUsed = null;
|
||||
HostStats hostStats = getManagementServer().getHostStatistics(host.getId());
|
||||
if (hostStats != null) {
|
||||
float cpuUtil = (float) hostStats.getCpuUtilization();
|
||||
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
||||
hostResponse.setCpuUsed(cpuUsed);
|
||||
hostResponse.setAverageLoad((long)hostStats.getAverageLoad());
|
||||
hostResponse.setNetworkKbsRead((long)hostStats.getNetworkReadKBs());
|
||||
hostResponse.setNetworkKbsWrite((long)hostStats.getNetworkWriteKBs());
|
||||
}
|
||||
|
||||
if (host.getType() == Host.Type.Routing) {
|
||||
hostResponse.setMemoryTotal(host.getTotalMemory());
|
||||
|
||||
// calculate memory allocated by systemVM and userVm
|
||||
// long mem = getManagementServer().getMemoryUsagebyHost(host.getId());
|
||||
// hostResponse.setMemoryAllocated(mem);
|
||||
// hostResponse.setMemoryUsed(mem);
|
||||
long mem = getManagementServer().getMemoryUsagebyHost(host.getId());
|
||||
hostResponse.setMemoryAllocated(mem);
|
||||
hostResponse.setMemoryUsed(mem);
|
||||
} else if (host.getType().toString().equals("Storage")) {
|
||||
hostResponse.setDiskSizeTotal(host.getTotalSize());
|
||||
hostResponse.setDiskSizeAllocated(0L);
|
||||
}
|
||||
|
||||
// if (host.getClusterId() != null) {
|
||||
// ClusterVO cluster = getManagementServer().findClusterById(host.getClusterId());
|
||||
// hostResponse.setClusterName(cluster.getName());
|
||||
// }
|
||||
if (host.getClusterId() != null) {
|
||||
ClusterVO cluster = getManagementServer().findClusterById(host.getClusterId());
|
||||
hostResponse.setClusterName(cluster.getName());
|
||||
}
|
||||
|
||||
// hostResponse.setLocalStorageActive(getManagementServer().isLocalStorageActiveOnHost(host));
|
||||
hostResponse.setLocalStorageActive(getManagementServer().isLocalStorageActiveOnHost(host));
|
||||
|
||||
Set<Event> possibleEvents = host.getStatus().getPossibleEvents();
|
||||
if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -18,38 +18,37 @@
|
|||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.response.HostResponse;
|
||||
import com.cloud.api.response.StoragePoolResponse;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.host.HostStats;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.storage.GuestOSCategoryVO;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.StorageStats;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
|
||||
@Implementation(method="")
|
||||
public class ListStoragePoolsAndHostsCmd extends BaseListCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListStoragePoolsAndHostsCmd.class.getName());
|
||||
|
||||
private static final String s_name = "liststoragepoolsandhostsresponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
private static final ListStoragePoolsCmd storagePoolsCmd = new ListStoragePoolsCmd();
|
||||
private static final ListHostsCmd storageHostsCmd = new ListHostsCmd();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.IP_ADDRESS, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PATH, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.POD_ID, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.STATE, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.TYPE, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.FALSE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
|
|
@ -117,34 +116,153 @@ public class ListStoragePoolsAndHostsCmd extends BaseListCmd {
|
|||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResponse() {
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public String getResponse() {
|
||||
List<Object> poolsAndHosts = (List<Object>)getResponseObject();
|
||||
|
||||
List<Object> response = new ArrayList<Object>();
|
||||
for (Object poolOrHost : poolsAndHosts) {
|
||||
if (poolOrHost instanceof StoragePoolVO) {
|
||||
StoragePoolVO pool = (StoragePoolVO)poolOrHost;
|
||||
response.add(constructStoragePoolResponse(pool));
|
||||
} else if (poolOrHost instanceof HostVO) {
|
||||
HostVO host = (HostVO)poolOrHost;
|
||||
response.add(constructHostResponse(host));
|
||||
}
|
||||
}
|
||||
|
||||
return SerializerHelper.toSerializedString(response);
|
||||
}
|
||||
|
||||
private StoragePoolResponse constructStoragePoolResponse(StoragePoolVO pool) {
|
||||
StoragePoolResponse poolResponse = new StoragePoolResponse();
|
||||
poolResponse.setId(pool.getId());
|
||||
poolResponse.setName(pool.getName());
|
||||
poolResponse.setPath(pool.getPath());
|
||||
poolResponse.setIpAddress(pool.getHostAddress());
|
||||
poolResponse.setZoneId(pool.getDataCenterId());
|
||||
poolResponse.setZoneName(getManagementServer().getDataCenterBy(pool.getDataCenterId()).getName());
|
||||
if (pool.getPoolType() != null) {
|
||||
poolResponse.setType(pool.getPoolType().toString());
|
||||
}
|
||||
if (pool.getPodId() != null) {
|
||||
poolResponse.setPodId(pool.getPodId());
|
||||
poolResponse.setPodName(getManagementServer().getPodBy(pool.getPodId()).getName());
|
||||
}
|
||||
if (pool.getCreated() != null) {
|
||||
poolResponse.setCreated(pool.getCreated());
|
||||
}
|
||||
|
||||
StorageStats stats = getManagementServer().getStoragePoolStatistics(pool.getId());
|
||||
long capacity = pool.getCapacityBytes();
|
||||
long available = pool.getAvailableBytes() ;
|
||||
long used = capacity - available;
|
||||
|
||||
if (stats != null) {
|
||||
used = stats.getByteUsed();
|
||||
available = capacity - used;
|
||||
}
|
||||
|
||||
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
|
||||
poolResponse.setDiskSizeAllocated(used);
|
||||
|
||||
if (pool.getClusterId() != null) {
|
||||
ClusterVO cluster = getManagementServer().findClusterById(pool.getClusterId());
|
||||
poolResponse.setClusterId(cluster.getId());
|
||||
poolResponse.setClusterName(cluster.getName());
|
||||
}
|
||||
|
||||
poolResponse.setTags(getManagementServer().getStoragePoolTags(pool.getId()));
|
||||
|
||||
return poolResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
List<Pair<String, Object>> poolTags = storagePoolsCmd.execute(params);
|
||||
List<Pair<String, Object>> hostTags = new ArrayList<Pair<String, Object>>();
|
||||
String ipAddress = (String)params.get(BaseCmd.Properties.IP_ADDRESS.getName());
|
||||
String path = (String)params.get(BaseCmd.Properties.PATH.getName());
|
||||
if (ipAddress == null && path == null){
|
||||
params.put(BaseCmd.Properties.TYPE.getName(), Host.Type.Storage.toString());
|
||||
hostTags = storageHostsCmd.execute(params);
|
||||
}
|
||||
poolTags.addAll(hostTags);
|
||||
return poolTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setManagementServer(ManagementServer ms) {
|
||||
storagePoolsCmd.setManagementServer(ms);
|
||||
storageHostsCmd.setManagementServer(ms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> validateParams(Map<String, String> params, boolean decode) {
|
||||
Map<String, Object> result = storagePoolsCmd.validateParams(params, decode);
|
||||
result.putAll(storageHostsCmd.validateParams(params, decode));
|
||||
return result;
|
||||
|
||||
private HostResponse constructHostResponse(HostVO host) {
|
||||
HostResponse hostResponse = new HostResponse();
|
||||
hostResponse.setId(host.getId());
|
||||
hostResponse.setCapabilities(host.getCapabilities());
|
||||
hostResponse.setClusterId(host.getClusterId());
|
||||
hostResponse.setCpuNumber(host.getCpus());
|
||||
hostResponse.setZoneId(host.getDataCenterId());
|
||||
hostResponse.setDisconnectedOn(host.getDisconnectedOn());
|
||||
hostResponse.setHypervisor(host.getHypervisorType());
|
||||
hostResponse.setHostType(host.getType());
|
||||
hostResponse.setLastPinged(new Date(host.getLastPinged()));
|
||||
hostResponse.setManagementServerId(host.getManagementServerId());
|
||||
hostResponse.setName(host.getName());
|
||||
hostResponse.setPodId(host.getPodId());
|
||||
hostResponse.setRemoved(host.getRemoved());
|
||||
hostResponse.setCpuSpeed(host.getSpeed());
|
||||
hostResponse.setState(host.getStatus());
|
||||
hostResponse.setIpAddress(host.getPrivateIpAddress());
|
||||
hostResponse.setVersion(host.getVersion());
|
||||
|
||||
// TODO: implement
|
||||
GuestOSCategoryVO guestOSCategory = getManagementServer().getHostGuestOSCategory(host.getId());
|
||||
if (guestOSCategory != null) {
|
||||
hostResponse.setOsCategoryId(guestOSCategory.getId());
|
||||
hostResponse.setOsCategoryName(guestOSCategory.getName());
|
||||
}
|
||||
hostResponse.setZoneName(getManagementServer().getDataCenterBy(host.getDataCenterId()).getName());
|
||||
hostResponse.setPodName(getManagementServer().findHostPodById(host.getPodId()).getName());
|
||||
|
||||
// calculate cpu allocated by vm
|
||||
int cpu = 0;
|
||||
String cpuAlloc = null;
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
List<UserVmVO> instances = getManagementServer().listUserVMsByHostId(host.getId());
|
||||
for (UserVmVO vm : instances) {
|
||||
ServiceOffering so = getManagementServer().findServiceOfferingById(vm.getServiceOfferingId());
|
||||
cpu += so.getCpu() * so.getSpeed();
|
||||
}
|
||||
cpuAlloc = decimalFormat.format(((float) cpu / (float) (host.getCpus() * host.getSpeed())) * 100f) + "%";
|
||||
hostResponse.setCpuAllocated(cpuAlloc);
|
||||
|
||||
// calculate cpu utilized
|
||||
String cpuUsed = null;
|
||||
HostStats hostStats = getManagementServer().getHostStatistics(host.getId());
|
||||
if (hostStats != null) {
|
||||
float cpuUtil = (float) hostStats.getCpuUtilization();
|
||||
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
||||
hostResponse.setCpuUsed(cpuUsed);
|
||||
hostResponse.setAverageLoad((long)hostStats.getAverageLoad());
|
||||
hostResponse.setNetworkKbsRead((long)hostStats.getNetworkReadKBs());
|
||||
hostResponse.setNetworkKbsWrite((long)hostStats.getNetworkWriteKBs());
|
||||
}
|
||||
|
||||
if (host.getType() == Host.Type.Routing) {
|
||||
hostResponse.setMemoryTotal(host.getTotalMemory());
|
||||
|
||||
// calculate memory allocated by systemVM and userVm
|
||||
long mem = getManagementServer().getMemoryUsagebyHost(host.getId());
|
||||
hostResponse.setMemoryAllocated(mem);
|
||||
hostResponse.setMemoryUsed(mem);
|
||||
} else if (host.getType().toString().equals("Storage")) {
|
||||
hostResponse.setDiskSizeTotal(host.getTotalSize());
|
||||
hostResponse.setDiskSizeAllocated(0L);
|
||||
}
|
||||
|
||||
if (host.getClusterId() != null) {
|
||||
ClusterVO cluster = getManagementServer().findClusterById(host.getClusterId());
|
||||
hostResponse.setClusterName(cluster.getName());
|
||||
}
|
||||
|
||||
hostResponse.setLocalStorageActive(getManagementServer().isLocalStorageActiveOnHost(host));
|
||||
|
||||
Set<Event> possibleEvents = host.getStatus().getPossibleEvents();
|
||||
if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
|
||||
String events = "";
|
||||
Iterator<Event> iter = possibleEvents.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Event event = iter.next();
|
||||
events += event.toString();
|
||||
if (iter.hasNext()) {
|
||||
events += "; ";
|
||||
}
|
||||
}
|
||||
hostResponse.setEvents(events);
|
||||
}
|
||||
|
||||
return hostResponse;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ import com.cloud.api.commands.ListPublicIpAddressesCmd;
|
|||
import com.cloud.api.commands.ListRoutersCmd;
|
||||
import com.cloud.api.commands.ListServiceOfferingsCmd;
|
||||
import com.cloud.api.commands.ListSnapshotsCmd;
|
||||
import com.cloud.api.commands.ListStoragePoolsAndHostsCmd;
|
||||
import com.cloud.api.commands.ListStoragePoolsCmd;
|
||||
import com.cloud.api.commands.ListSystemVMsCmd;
|
||||
import com.cloud.api.commands.ListTemplateOrIsoPermissionsCmd;
|
||||
|
|
@ -1310,6 +1311,13 @@ public interface ManagementServer {
|
|||
*/
|
||||
List<? extends StoragePoolVO> searchForStoragePools(ListStoragePoolsCmd cmd);
|
||||
|
||||
/**
|
||||
* List storage pools and storage hosts that match the given criteria
|
||||
* @param cmd the command that wraps the search criteria (zone, pod, name, IP address, path, state)
|
||||
* @return a list of storage pools and hosts that match the given criteria
|
||||
*/
|
||||
List<Object> searchForStoragePoolsAndHosts(ListStoragePoolsAndHostsCmd cmd);
|
||||
|
||||
SnapshotPolicyVO findSnapshotPolicyById(Long policyId);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ import com.cloud.api.commands.ListPublicIpAddressesCmd;
|
|||
import com.cloud.api.commands.ListRoutersCmd;
|
||||
import com.cloud.api.commands.ListServiceOfferingsCmd;
|
||||
import com.cloud.api.commands.ListSnapshotsCmd;
|
||||
import com.cloud.api.commands.ListStoragePoolsAndHostsCmd;
|
||||
import com.cloud.api.commands.ListStoragePoolsCmd;
|
||||
import com.cloud.api.commands.ListSystemVMsCmd;
|
||||
import com.cloud.api.commands.ListTemplateOrIsoPermissionsCmd;
|
||||
|
|
@ -167,6 +168,7 @@ import com.cloud.exception.NetworkRuleConflictException;
|
|||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.StorageUnavailableException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostStats;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
|
|
@ -2800,9 +2802,6 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
|
||||
@Override
|
||||
public List<HostVO> searchForServers(ListHostsCmd cmd) {
|
||||
Filter searchFilter = new Filter(HostVO.class, "id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
SearchCriteria<HostVO> sc = _hostDao.createSearchCriteria();
|
||||
|
||||
Object name = cmd.getHostName();
|
||||
Object type = cmd.getType();
|
||||
Object state = cmd.getState();
|
||||
|
|
@ -2812,6 +2811,13 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
Object id = cmd.getId();
|
||||
Object keyword = cmd.getKeyword();
|
||||
|
||||
return searchForServers(cmd.getStartIndex(), cmd.getPageSizeVal(), name, type, state, zone, pod, cluster, id, keyword);
|
||||
}
|
||||
|
||||
private List<HostVO> searchForServers(Long startIndex, Long pageSize, Object name, Object type, Object state, Object zone, Object pod, Object cluster, Object id, Object keyword) {
|
||||
Filter searchFilter = new Filter(HostVO.class, "id", Boolean.TRUE, startIndex, pageSize);
|
||||
SearchCriteria<HostVO> sc = _hostDao.createSearchCriteria();
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<HostVO> ssc = _hostDao.createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
|
|
@ -6265,6 +6271,32 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
return _poolDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> searchForStoragePoolsAndHosts(ListStoragePoolsAndHostsCmd cmd) {
|
||||
Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
c.addCriteria(Criteria.NAME, cmd.getStoragePoolName());
|
||||
c.addCriteria(Criteria.ADDRESS, cmd.getIpAddress());
|
||||
c.addCriteria(Criteria.KEYWORD, cmd.getKeyword());
|
||||
c.addCriteria(Criteria.PATH, cmd.getPath());
|
||||
c.addCriteria(Criteria.PODID, cmd.getPodId());
|
||||
c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId());
|
||||
|
||||
List<Object> poolsAndHosts = new ArrayList<Object>();
|
||||
List<? extends StoragePoolVO> pools = searchForStoragePools(c);
|
||||
if ((pools != null) && !pools.isEmpty()) {
|
||||
poolsAndHosts.addAll(pools);
|
||||
}
|
||||
|
||||
if ((cmd.getPath() == null) && (cmd.getIpAddress() == null)) {
|
||||
List<HostVO> hosts = searchForServers(cmd.getStartIndex(), cmd.getPageSizeVal(), cmd.getStoragePoolName(), Host.Type.Storage.toString(), cmd.getState(), cmd.getZoneId(), cmd.getPodId(), null, null, cmd.getKeyword());
|
||||
if ((hosts != null) && !hosts.isEmpty()) {
|
||||
poolsAndHosts.addAll(hosts);
|
||||
}
|
||||
}
|
||||
|
||||
return poolsAndHosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageStats getStoragePoolStatistics(long id) {
|
||||
return _statsCollector.getStoragePoolStats(id);
|
||||
|
|
|
|||
Loading…
Reference in New Issue