Search in sources :

Example 1 with HostForMigrationResponse

use of com.cloud.api.response.HostForMigrationResponse in project cosmic by MissionCriticalCloud.

the class FindHostsForMigrationCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    ListResponse<HostForMigrationResponse> response = null;
    final Pair<List<? extends Host>, Integer> result;
    final Map<Host, Boolean> hostsRequiringStorageMotion;
    final Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal(), this.getKeyword());
    result = hostsForMigration.first();
    final List<? extends Host> hostsWithCapacity = hostsForMigration.second();
    hostsRequiringStorageMotion = hostsForMigration.third();
    response = new ListResponse<>();
    final List<HostForMigrationResponse> hostResponses = new ArrayList<>();
    for (final Host host : result.first()) {
        final HostForMigrationResponse hostResponse = _responseGenerator.createHostForMigrationResponse(host);
        Boolean suitableForMigration = false;
        if (hostsWithCapacity.contains(host)) {
            suitableForMigration = true;
        }
        hostResponse.setSuitableForMigration(suitableForMigration);
        final Boolean requiresStorageMotion = hostsRequiringStorageMotion.get(host);
        if (requiresStorageMotion != null && requiresStorageMotion) {
            hostResponse.setRequiresStorageMotion(true);
        } else {
            hostResponse.setRequiresStorageMotion(false);
        }
        hostResponse.setObjectName("host");
        hostResponses.add(hostResponse);
    }
    response.setResponses(hostResponses, result.second());
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ArrayList(java.util.ArrayList) Host(com.cloud.host.Host) HostForMigrationResponse(com.cloud.api.response.HostForMigrationResponse) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 2 with HostForMigrationResponse

use of com.cloud.api.response.HostForMigrationResponse in project cosmic by MissionCriticalCloud.

the class ViewResponseHelper method createHostForMigrationResponse.

public static List<HostForMigrationResponse> createHostForMigrationResponse(final EnumSet<HostDetails> details, final HostJoinVO... hosts) {
    final Hashtable<Long, HostForMigrationResponse> vrDataList = new Hashtable<>();
    // Initialise the vrdatalist with the input data
    for (final HostJoinVO vr : hosts) {
        HostForMigrationResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this vm
            vrData = ApiDBUtils.newHostForMigrationResponse(vr, details);
        } else {
            // update tags
            vrData = ApiDBUtils.fillHostForMigrationDetails(vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<>(vrDataList.values());
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) HostJoinVO(com.cloud.api.query.vo.HostJoinVO) HostForMigrationResponse(com.cloud.api.response.HostForMigrationResponse)

Example 3 with HostForMigrationResponse

use of com.cloud.api.response.HostForMigrationResponse in project cosmic by MissionCriticalCloud.

the class HostJoinDaoImpl method newHostForMigrationResponse.

@Override
public HostForMigrationResponse newHostForMigrationResponse(final HostJoinVO host, final EnumSet<HostDetails> details) {
    final HostForMigrationResponse hostResponse = new HostForMigrationResponse();
    hostResponse.setId(host.getUuid());
    hostResponse.setCapabilities(host.getCapabilities());
    hostResponse.setClusterId(host.getClusterUuid());
    hostResponse.setCpuNumber(host.getCpus());
    hostResponse.setZoneId(host.getZoneUuid());
    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.getPodUuid());
    hostResponse.setRemoved(host.getRemoved());
    hostResponse.setState(host.getStatus());
    hostResponse.setIpAddress(host.getPrivateIpAddress());
    hostResponse.setVersion(host.getVersion());
    hostResponse.setCreated(host.getCreated());
    final DedicatedResourceVO dedicatedResourceVO = dedicatedResourceDao.findByHostId(host.getId());
    if (dedicatedResourceVO != null) {
        hostResponse.setDedicated(true);
        final DomainVO domainVO = domainDao.findById(dedicatedResourceVO.getDomainId());
        if (domainVO != null) {
            hostResponse.setDomainId(domainVO.getUuid());
            hostResponse.setDomainName(domainVO.getName());
        }
        final AccountVO accountVO = accountDao.findById(dedicatedResourceVO.getAccountId());
        if (accountVO != null) {
            hostResponse.setAccountId(accountVO.getUuid());
            hostResponse.setAccountName(accountVO.getAccountName());
        }
        final AffinityGroupVO affinityGroupVO = affinityGroupDao.findById(dedicatedResourceVO.getAffinityGroupId());
        if (affinityGroupVO != null) {
            hostResponse.setAffinityGroupId(affinityGroupVO.getUuid());
            hostResponse.setAffinityGroupName(affinityGroupVO.getName());
        }
    }
    if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity) || details.contains(HostDetails.stats) || details.contains(HostDetails.events)) {
        hostResponse.setOsCategoryId(host.getOsCategoryUuid());
        hostResponse.setOsCategoryName(host.getOsCategoryName());
        hostResponse.setZoneName(host.getZoneName());
        hostResponse.setPodName(host.getPodName());
        if (host.getClusterId() > 0) {
            hostResponse.setClusterName(host.getClusterName());
            hostResponse.setClusterType(host.getClusterType().toString());
        }
    }
    final DecimalFormat decimalFormat = new DecimalFormat("#.##");
    if (host.getType() == Host.Type.Routing) {
        if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
            // set allocated capacities
            final Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity();
            final Long cpu = host.getCpuReservedCapacity() + host.getCpuReservedCapacity();
            hostResponse.setMemoryAllocated(mem);
            hostResponse.setMemoryTotal(host.getTotalMemory());
            final String hostTags = host.getTag();
            hostResponse.setHostTags(host.getTag());
            final String haTag = ApiDBUtils.getHaTag();
            if (haTag != null && !haTag.isEmpty() && hostTags != null && !hostTags.isEmpty()) {
                if (haTag.equalsIgnoreCase(hostTags)) {
                    hostResponse.setHaHost(true);
                } else {
                    hostResponse.setHaHost(false);
                }
            } else {
                hostResponse.setHaHost(false);
            }
            hostResponse.setHypervisorVersion(host.getHypervisorVersion());
            final String cpuAlloc = decimalFormat.format(((float) cpu / (float) host.getCpus()) * 100f) + "%";
            hostResponse.setCpuAllocated(cpuAlloc);
            final String cpuWithOverprovisioning = Float.toString(host.getCpus() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()));
            hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning);
        }
        if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) {
            // set CPU/RAM/Network stats
            final String cpuUsed;
            final HostStats hostStats = ApiDBUtils.getHostStatistics(host.getId());
            if (hostStats != null) {
                final float cpuUtil = (float) hostStats.getCpuUtilization();
                cpuUsed = decimalFormat.format(cpuUtil) + "%";
                hostResponse.setCpuUsed(cpuUsed);
                hostResponse.setMemoryUsed((new Double(hostStats.getUsedMemory())).longValue());
                hostResponse.setNetworkKbsRead((new Double(hostStats.getNetworkReadKBs())).longValue());
                hostResponse.setNetworkKbsWrite((new Double(hostStats.getNetworkWriteKBs())).longValue());
            }
        }
    } else if (host.getType() == Host.Type.SecondaryStorage) {
        final StorageStats secStorageStats = ApiDBUtils.getSecondaryStorageStatistics(host.getId());
        if (secStorageStats != null) {
            hostResponse.setDiskSizeTotal(secStorageStats.getCapacityBytes());
            hostResponse.setDiskSizeAllocated(secStorageStats.getByteUsed());
        }
    }
    hostResponse.setLocalStorageActive(ApiDBUtils.isLocalStorageActiveOnHost(host.getId()));
    if (details.contains(HostDetails.all) || details.contains(HostDetails.events)) {
        final Set<com.cloud.host.Status.Event> possibleEvents = host.getStatus().getPossibleEvents();
        if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
            String events = "";
            final Iterator<com.cloud.host.Status.Event> iter = possibleEvents.iterator();
            while (iter.hasNext()) {
                final com.cloud.host.Status.Event event = iter.next();
                events += event.toString();
                if (iter.hasNext()) {
                    events += "; ";
                }
            }
            hostResponse.setEvents(events);
        }
    }
    hostResponse.setResourceState(host.getResourceState().toString());
    // set async job
    hostResponse.setJobId(host.getJobUuid());
    hostResponse.setJobStatus(host.getJobStatus());
    hostResponse.setObjectName("host");
    return hostResponse;
}
Also used : AffinityGroupVO(com.cloud.affinity.AffinityGroupVO) StorageStats(com.cloud.storage.StorageStats) DecimalFormat(java.text.DecimalFormat) HostForMigrationResponse(com.cloud.api.response.HostForMigrationResponse) AccountVO(com.cloud.user.AccountVO) Date(java.util.Date) DomainVO(com.cloud.domain.DomainVO) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostStats(com.cloud.host.HostStats)

Aggregations

HostForMigrationResponse (com.cloud.api.response.HostForMigrationResponse)3 ArrayList (java.util.ArrayList)2 AffinityGroupVO (com.cloud.affinity.AffinityGroupVO)1 HostJoinVO (com.cloud.api.query.vo.HostJoinVO)1 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)1 DomainVO (com.cloud.domain.DomainVO)1 Host (com.cloud.host.Host)1 HostStats (com.cloud.host.HostStats)1 StorageStats (com.cloud.storage.StorageStats)1 AccountVO (com.cloud.user.AccountVO)1 Pair (com.cloud.utils.Pair)1 DecimalFormat (java.text.DecimalFormat)1 Date (java.util.Date)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Map (java.util.Map)1