Search in sources :

Example 1 with VmExitReason

use of org.ovirt.engine.core.common.businessentities.VmExitReason in project ovirt-engine by oVirt.

the class VdsBrokerObjectsBuilder method updateVMDynamicData.

public static void updateVMDynamicData(VmDynamic vm, Map<String, Object> struct, VDS host) {
    if (struct.containsKey(VdsProperties.vm_guid)) {
        vm.setId(new Guid((String) struct.get(VdsProperties.vm_guid)));
    }
    if (struct.containsKey(VdsProperties.session)) {
        String session = (String) struct.get(VdsProperties.session);
        try {
            vm.setSession(SessionState.valueOf(session));
        } catch (Exception e) {
            log.error("Illegal vm session '{}'.", session);
        }
    }
    if (struct.containsKey(VdsProperties.acpiEnable)) {
        vm.setAcpiEnable(Boolean.parseBoolean((String) struct.get(VdsProperties.acpiEnable)));
    }
    if (struct.containsKey(VdsProperties.status)) {
        vm.setStatus(convertToVmStatus((String) struct.get(VdsProperties.status)));
    }
    boolean hasGraphicsInfo = updateGraphicsInfo(vm, struct);
    if (!hasGraphicsInfo) {
        updateGraphicsInfoFromConf(vm, struct);
    }
    adjustDisplayIp(vm.getGraphicsInfos(), host);
    if (struct.containsKey(VdsProperties.utc_diff)) {
        String utc_diff = struct.get(VdsProperties.utc_diff).toString();
        if (utc_diff.startsWith("+")) {
            utc_diff = utc_diff.substring(1);
        }
        try {
            vm.setUtcDiff(Integer.parseInt(utc_diff));
        } catch (NumberFormatException e) {
            log.error("Illegal vm offset (utc_diff) '{}'.", utc_diff);
        }
    }
    // ------------- vm internal agent data
    if (struct.containsKey(VdsProperties.vm_host)) {
        vm.setVmHost(assignStringValue(struct, VdsProperties.vm_host));
    }
    if (struct.containsKey(VdsProperties.guest_cur_user_name)) {
        vm.setGuestCurrentUserName(assignStringValue(struct, VdsProperties.guest_cur_user_name));
    }
    initAppsList(struct, vm);
    initGuestContainers(struct, vm);
    if (struct.containsKey(VdsProperties.guest_os)) {
        vm.setGuestOs(assignStringValue(struct, VdsProperties.guest_os));
    }
    if (struct.containsKey(VdsProperties.VM_FQDN)) {
        vm.setFqdn(assignStringValue(struct, VdsProperties.VM_FQDN));
        String fqdn = vm.getFqdn().trim();
        if ("localhost".equalsIgnoreCase(fqdn) || "localhost.localdomain".equalsIgnoreCase(fqdn)) {
            vm.setFqdn(null);
        } else {
            vm.setFqdn(fqdn);
        }
    }
    if (struct.containsKey(VdsProperties.exit_code)) {
        String exitCodeStr = struct.get(VdsProperties.exit_code).toString();
        vm.setExitStatus(VmExitStatus.forValue(Integer.parseInt(exitCodeStr)));
    }
    if (struct.containsKey(VdsProperties.exit_message)) {
        String exitMsg = (String) struct.get(VdsProperties.exit_message);
        vm.setExitMessage(exitMsg);
    }
    if (struct.containsKey(VdsProperties.exit_reason)) {
        String exitReasonStr = struct.get(VdsProperties.exit_reason).toString();
        VmExitReason exitReason = VmExitReason.forValue(Integer.parseInt(exitReasonStr));
        if (exitReason == null) {
            log.warn("Illegal exit reason: {}, replacing with Unknown", exitReasonStr);
            exitReason = VmExitReason.Unknown;
        }
        vm.setExitReason(exitReason);
    }
    // if monitorResponse returns negative it means its erroneous
    if (struct.containsKey(VdsProperties.monitorResponse)) {
        int response = Integer.parseInt(struct.get(VdsProperties.monitorResponse).toString());
        if (response < 0) {
            vm.setStatus(VMStatus.NotResponding);
        }
    }
    if (struct.containsKey(VdsProperties.clientIp)) {
        vm.setClientIp(struct.get(VdsProperties.clientIp).toString());
    }
    if (struct.containsKey(VdsProperties.pauseCode)) {
        String pauseCodeStr = (String) struct.get(VdsProperties.pauseCode);
        try {
            vm.setPauseStatus(VmPauseStatus.valueOf(pauseCodeStr));
        } catch (IllegalArgumentException ex) {
            log.error("Error in parsing vm pause status. Setting value to NONE");
        }
    }
    if (struct.containsKey(VdsProperties.watchdogEvent)) {
        Map<String, Object> watchdogStruct = (Map<String, Object>) struct.get(VdsProperties.watchdogEvent);
        double time = Double.parseDouble(watchdogStruct.get(VdsProperties.time).toString());
        // vdsm may not send the action http://gerrit.ovirt.org/14134
        String action = watchdogStruct.containsKey(VdsProperties.action) ? watchdogStruct.get(VdsProperties.action).toString() : null;
        vm.setLastWatchdogEvent((long) time);
        vm.setLastWatchdogAction(action);
    }
    if (struct.containsKey(VdsProperties.CDRom)) {
        Path fileName = Paths.get((String) struct.get(VdsProperties.CDRom)).getFileName();
        if (fileName != null) {
            String isoName = fileName.toString();
            vm.setCurrentCd(isoName);
        }
    }
    if (struct.containsKey(VdsProperties.GUEST_CPU_COUNT)) {
        vm.setGuestCpuCount(assignIntValue(struct, VdsProperties.GUEST_CPU_COUNT));
    }
    // Guest OS Info
    if (struct.containsKey(VdsProperties.GUEST_OS_INFO)) {
        updateGuestOsInfo(vm, struct);
    }
    // Guest Timezone
    if (struct.containsKey(VdsProperties.GUEST_TIMEZONE)) {
        Map<String, Object> guestTimeZoneStruct = (Map<String, Object>) struct.get(VdsProperties.GUEST_TIMEZONE);
        vm.setGuestOsTimezoneName(assignStringValue(guestTimeZoneStruct, VdsProperties.GUEST_TIMEZONE_ZONE));
        vm.setGuestOsTimezoneOffset(assignIntValue(guestTimeZoneStruct, VdsProperties.GUEST_TIMEZONE_OFFSET));
    }
}
Also used : Path(java.nio.file.Path) Guid(org.ovirt.engine.core.compat.Guid) ParseException(java.text.ParseException) VmExitReason(org.ovirt.engine.core.common.businessentities.VmExitReason) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Path (java.nio.file.Path)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 VmExitReason (org.ovirt.engine.core.common.businessentities.VmExitReason)1 Guid (org.ovirt.engine.core.compat.Guid)1