Added one more parameter - haHost(boolean) - to listHosts api command. The parameter identifies if the host is dedicated for ha only

Conflicts:

	server/src/com/cloud/api/ApiResponseHelper.java
This commit is contained in:
Alena Prokharchyk 2012-04-12 11:42:12 -07:00
parent fcc9ec2f55
commit 676a28177b
6 changed files with 100 additions and 170 deletions

View File

@ -329,6 +329,7 @@ public class ApiConstants {
public static final String IS_TAGGED = "istagged";
public static final String INSTANCE_NAME = "instancename";
public static final String START_VM = "startvm";
public static final String HA_HOST = "hahost";
public enum HostDetails {

View File

@ -74,7 +74,10 @@ public class ListHostsCmd extends BaseListCmd {
private String resourceState;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma separated list of host details requested, value can be a list of [ min, all, capacity, events, stats]" )
private List<String> viewDetails;
private List<String> viewDetails;
@Parameter(name=ApiConstants.HA_HOST, type=CommandType.BOOLEAN, description="if true, list only hosts dedicated to HA")
private Boolean haHost;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -103,6 +106,10 @@ public class ListHostsCmd extends BaseListCmd {
public String getType() {
return type;
}
public Boolean getHaHost() {
return haHost;
}
public Long getZoneId() {
return zoneId;

View File

@ -149,6 +149,9 @@ public class HostResponse extends BaseResponse {
@SerializedName(ApiConstants.HYPERVISOR_VERSION) @Param(description="the hypervisor version")
private String hypervisorVersion;
@SerializedName(ApiConstants.HA_HOST) @Param(description="true if the host is Ha host (dedicated to vms started by HA process; false otherwise")
private Boolean haHost;
@Override
public Long getObjectId() {
@ -163,122 +166,62 @@ public class HostResponse extends BaseResponse {
this.id.setValue(id);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Status getState() {
return state;
}
public void setState(Status state) {
this.state = state;
}
public Date getDisconnectedOn() {
return disconnectedOn;
}
public void setDisconnectedOn(Date disconnectedOn) {
this.disconnectedOn = disconnectedOn;
}
public Host.Type getHostType() {
return hostType;
}
public void setHostType(Host.Type hostType) {
this.hostType = hostType;
}
public Long getOsCategoryId() {
return osCategoryId.getValue();
}
public void setOsCategoryId(Long osCategoryId) {
this.osCategoryId.setValue(osCategoryId);
}
public String getOsCategoryName() {
return osCategoryName;
}
public void setOsCategoryName(String osCategoryName) {
this.osCategoryName = osCategoryName;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public Long getZoneId() {
return zoneId.getValue();
}
public void setZoneId(Long zoneId) {
this.zoneId.setValue(zoneId);
}
public String getZoneName() {
return zoneName;
}
public void setZoneName(String zoneName) {
this.zoneName = zoneName;
}
public Long getPodId() {
return podId.getValue();
}
public void setPodId(Long podId) {
this.podId.setValue(podId);
}
public String getPodName() {
return podName;
}
public void setPodName(String podName) {
this.podName = podName;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public HypervisorType getHypervisor() {
return hypervisor;
}
public void setHypervisor(HypervisorType hypervisor) {
this.hypervisor = hypervisor;
}
public Integer getCpuNumber() {
return cpuNumber;
}
public void setCpuNumber(Integer cpuNumber) {
this.cpuNumber = cpuNumber;
}
public Long getCpuSpeed() {
return cpuSpeed;
}
public void setCpuSpeed(Long cpuSpeed) {
this.cpuSpeed = cpuSpeed;
}
@ -291,177 +234,90 @@ public class HostResponse extends BaseResponse {
this.cpuAllocated = cpuAllocated;
}
public String getCpuUsed() {
return cpuUsed;
}
public void setCpuUsed(String cpuUsed) {
this.cpuUsed = cpuUsed;
}
public Long getAverageLoad() {
return averageLoad;
}
public void setAverageLoad(Long averageLoad) {
this.averageLoad = averageLoad;
}
public Long getNetworkKbsRead() {
return networkKbsRead;
}
public void setNetworkKbsRead(Long networkKbsRead) {
this.networkKbsRead = networkKbsRead;
}
public Long getNetworkKbsWrite() {
return networkKbsWrite;
}
public void setNetworkKbsWrite(Long networkKbsWrite) {
this.networkKbsWrite = networkKbsWrite;
}
public Long getMemoryTotal() {
return memoryTotal;
}
public void setMemoryTotal(Long memoryTotal) {
this.memoryTotal = memoryTotal;
}
public Long getMemoryAllocated() {
return memoryAllocated;
}
public void setMemoryAllocated(Long memoryAllocated) {
this.memoryAllocated = memoryAllocated;
}
public Long getMemoryUsed() {
return memoryUsed;
}
public void setMemoryUsed(Long memoryUsed) {
this.memoryUsed = memoryUsed;
}
public Long getDiskSizeTotal() {
return diskSizeTotal;
}
public void setDiskSizeTotal(Long diskSizeTotal) {
this.diskSizeTotal = diskSizeTotal;
}
public Long getDiskSizeAllocated() {
return diskSizeAllocated;
}
public void setDiskSizeAllocated(Long diskSizeAllocated) {
this.diskSizeAllocated = diskSizeAllocated;
}
public String getCapabilities() {
return capabilities;
}
public void setCapabilities(String capabilities) {
this.capabilities = capabilities;
}
public Date getLastPinged() {
return lastPinged;
}
public void setLastPinged(Date lastPinged) {
this.lastPinged = lastPinged;
}
public Long getManagementServerId() {
return managementServerId;
}
public void setManagementServerId(Long managementServerId) {
this.managementServerId = managementServerId;
}
public Long getClusterId() {
return clusterId.getValue();
}
public void setClusterId(Long clusterId) {
this.clusterId.setValue(clusterId);
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public String getClusterType() {
return clusterType;
}
public void setClusterType(String clusterType) {
this.clusterType = clusterType;
}
public Boolean isLocalStorageActive() {
return localStorageActive;
}
public void setLocalStorageActive(Boolean localStorageActive) {
this.localStorageActive = localStorageActive;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getRemoved() {
return removed;
}
public void setRemoved(Date removed) {
this.removed = removed;
}
public String getEvents() {
return events;
}
public void setEvents(String events) {
this.events = events;
}
public String getHostTags() {
return hostTags;
}
public void setHostTags(String hostTags) {
this.hostTags = hostTags;
}
public Boolean hasEnoughCapacity() {
return hasEnoughCapacity;
}
public void setHasEnoughCapacity(Boolean hasEnoughCapacity) {
this.hasEnoughCapacity = hasEnoughCapacity;
}
public Boolean isSuitableForMigration() {
return suitableForMigration;
}
public void setSuitableForMigration(Boolean suitableForMigration) {
this.suitableForMigration = suitableForMigration;
@ -487,8 +343,23 @@ public class HostResponse extends BaseResponse {
this.hypervisorVersion = hypervisorVersion;
}
public String getHypervisorVersion() {
return hypervisorVersion;
}
public void setOsCategoryId(IdentityProxy osCategoryId) {
this.osCategoryId = osCategoryId;
}
public void setZoneId(IdentityProxy zoneId) {
this.zoneId = zoneId;
}
public void setPodId(IdentityProxy podId) {
this.podId = podId;
}
public void setClusterId(IdentityProxy clusterId) {
this.clusterId = clusterId;
}
public void setHaHost(Boolean haHost) {
this.haHost = haHost;
}
}

View File

@ -40,6 +40,7 @@ import com.cloud.dc.dao.VlanDao;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.host.Host;
import com.cloud.host.HostStats;
import com.cloud.host.HostVO;
@ -182,6 +183,7 @@ public class ApiDBUtils {
private static ResourceManager _resourceMgr;
private static AccountDetailsDao _accountDetailsDao;
private static NetworkDomainDao _networkDomainDao;
private static HighAvailabilityManager _haMgr;
static {
_ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name);
@ -233,6 +235,7 @@ public class ApiDBUtils {
_resourceMgr = locator.getManager(ResourceManager.class);
_accountDetailsDao = locator.getDao(AccountDetailsDao.class);
_networkDomainDao = locator.getDao(NetworkDomainDao.class);
_haMgr = locator.getManager(HighAvailabilityManager.class);
// Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
_statsCollector = StatsCollector.getInstance();
@ -729,4 +732,8 @@ public class ApiDBUtils {
public static IpAddress findIpByAssociatedVmId(long vmId) {
return _ipAddressDao.findByAssociatedVmId(vmId);
}
public static String getHaTag() {
return _haMgr.getHaTag();
}
}

View File

@ -597,7 +597,6 @@ public class ApiResponseHelper implements ResponseGenerator {
DecimalFormat decimalFormat = new DecimalFormat("#.##");
if (host.getType() == Host.Type.Routing) {
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
// set allocated capacities
Long mem = ApiDBUtils.getMemoryOrCpuCapacitybyHost(host.getId(), Capacity.CAPACITY_TYPE_MEMORY);
@ -605,7 +604,15 @@ public class ApiResponseHelper implements ResponseGenerator {
hostResponse.setMemoryAllocated(mem);
hostResponse.setMemoryTotal(host.getTotalMemory());
hostResponse.setHostTags(ApiDBUtils.getHostTags(host.getId()));
String hostTags = ApiDBUtils.getHostTags(host.getId());
hostResponse.setHostTags(hostTags);
String haTag = ApiDBUtils.getHaTag();
if (haTag != null && !haTag.isEmpty() && hostTags != null && !hostTags.isEmpty()) {
if (haTag.equalsIgnoreCase(hostTags)) {
hostResponse.setHaHost(true);
}
}
hostResponse.setHypervisorVersion(host.getHypervisorVersion());
String cpuAlloc = decimalFormat.format(((float) cpu / (float) (host.getCpus() * host.getSpeed())) * 100f) + "%";
@ -656,7 +663,6 @@ public class ApiResponseHelper implements ResponseGenerator {
}
hostResponse.setResourceState(host.getResourceState().toString());
hostResponse.setObjectName("host");
return hostResponse;
@ -1665,7 +1671,7 @@ public class ApiResponseHelper implements ResponseGenerator {
vmResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
vmResponse.setLinkLocalNetmask(singleNicProfile.getNetmask());
} else if (network.getTrafficType() == TrafficType.Public || network.getTrafficType() == TrafficType.Guest) {
/*In basic zone, public ip has TrafficType.Guest*/
/*In basic zone, public ip has TrafficType.Guest*/
vmResponse.setPublicIp(singleNicProfile.getIp4Address());
vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
vmResponse.setPublicNetmask(singleNicProfile.getNetmask());
@ -3352,4 +3358,4 @@ public class ApiResponseHelper implements ResponseGenerator {
return response;
}
}
}

View File

@ -139,12 +139,15 @@ import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.host.DetailVO;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.host.HostTagVO;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.host.dao.HostTagsDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.HypervisorCapabilities;
import com.cloud.hypervisor.HypervisorCapabilitiesVO;
@ -305,6 +308,10 @@ public class ManagementServerImpl implements ManagementServer {
private final ResourceManager _resourceMgr;
@Inject
SnapshotManager _snapshotMgr;
@Inject
HighAvailabilityManager _haMgr;
@Inject
HostTagsDao _hostTagsDao;
private final KeystoreManager _ksMgr;
@ -857,8 +864,9 @@ public class ManagementServerImpl implements ManagementServer {
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Object resourceState = cmd.getResourceState();
Object haHosts = cmd.getHaHost();
return searchForServers(cmd.getStartIndex(), cmd.getPageSizeVal(), name, type, state, zoneId, pod, cluster, id, keyword, resourceState);
return searchForServers(cmd.getStartIndex(), cmd.getPageSizeVal(), name, type, state, zoneId, pod, cluster, id, keyword, resourceState, haHosts);
}
@Override
@ -920,7 +928,7 @@ public class ManagementServerImpl implements ManagementServer {
s_logger.debug("Searching for all hosts in cluster: " + cluster + " for migrating VM " + vm);
}
List<? extends Host> allHostsInCluster = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, null, null);
List<? extends Host> allHostsInCluster = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, null, null, null);
// filter out the current host
allHostsInCluster.remove(srcHost);
@ -960,9 +968,35 @@ public class ManagementServerImpl implements ManagementServer {
}
private List<HostVO> searchForServers(Long startIndex, Long pageSize, Object name, Object type, Object state, Object zone, Object pod, Object cluster, Object id, Object keyword,
Object resourceState) {
Object resourceState, Object haHosts) {
Filter searchFilter = new Filter(HostVO.class, "id", Boolean.TRUE, startIndex, pageSize);
SearchCriteria<HostVO> sc = _hostDao.createSearchCriteria();
SearchBuilder<HostVO> sb = _hostDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.LIKE);
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
sb.and("resourceState", sb.entity().getResourceState(), SearchCriteria.Op.EQ);
String haTag = _haMgr.getHaTag();
SearchBuilder<HostTagVO> hostTagSearch = null;
if (haHosts != null && haTag != null && !haTag.isEmpty()) {
hostTagSearch = _hostTagsDao.createSearchBuilder();
if ((Boolean)haHosts) {
hostTagSearch.and().op("tag", hostTagSearch.entity().getTag(), SearchCriteria.Op.EQ);
} else {
hostTagSearch.and().op("tag", hostTagSearch.entity().getTag(), SearchCriteria.Op.NEQ);
hostTagSearch.or("tagNull", hostTagSearch.entity().getTag(), SearchCriteria.Op.NULL);
}
hostTagSearch.cp();
sb.join("hostTagSearch", hostTagSearch, sb.entity().getId(), hostTagSearch.entity().getHostId(), JoinBuilder.JoinType.LEFTOUTER);
}
SearchCriteria<HostVO> sc = sb.create();
if (keyword != null) {
SearchCriteria<HostVO> ssc = _hostDao.createSearchCriteria();
@ -974,30 +1008,34 @@ public class ManagementServerImpl implements ManagementServer {
}
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
sc.setParameters("id", id);
}
if (name != null) {
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
sc.setParameters("name", "%" + name + "%");
}
if (type != null) {
sc.addAnd("type", SearchCriteria.Op.LIKE, "%" + type);
sc.setParameters("type", "%" + type);
}
if (state != null) {
sc.addAnd("status", SearchCriteria.Op.EQ, state);
sc.setParameters("status", state);
}
if (zone != null) {
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zone);
sc.setParameters("dataCenterId", zone);
}
if (pod != null) {
sc.addAnd("podId", SearchCriteria.Op.EQ, pod);
sc.setParameters("podId", pod);
}
if (cluster != null) {
sc.addAnd("clusterId", SearchCriteria.Op.EQ, cluster);
sc.setParameters("clusterId", cluster);
}
if (resourceState != null) {
sc.addAnd("resourceState", SearchCriteria.Op.EQ, resourceState);
sc.setParameters("resourceState", resourceState);
}
if (haHosts != null && haTag != null && !haTag.isEmpty()) {
sc.setJoinParameters("hostTagSearch", "tag", haTag);
}
return _hostDao.search(sc, searchFilter);