Search in sources :

Example 1 with Spm

use of org.ovirt.engine.api.model.Spm in project ovirt-engine by oVirt.

the class HostMapper method map.

@Mapping(from = VDS.class, to = Host.class)
public static Host map(VDS entity, Host template) {
    Host model = template != null ? template : new Host();
    model.setId(entity.getId().toString());
    model.setName(entity.getName());
    model.setComment(entity.getComment());
    if (entity.getClusterId() != null) {
        Cluster cluster = new Cluster();
        cluster.setId(entity.getClusterId().toString());
        model.setCluster(cluster);
    }
    model.setAddress(entity.getHostName());
    if (entity.getPort() > 0) {
        model.setPort(entity.getPort());
    }
    // We return always STOMP because support for XML-RPC was removed in version 4.1 of the engine.
    model.setProtocol(HostProtocol.STOMP);
    HostStatus status = map(entity.getStatus(), null);
    model.setStatus(status);
    if (entity.getExternalStatus() != null) {
        ExternalStatus externalStatus = ExternalStatusMapper.map(entity.getExternalStatus());
        model.setExternalStatus(externalStatus);
    }
    if (status == HostStatus.NON_OPERATIONAL) {
        model.setStatusDetail(entity.getNonOperationalReason().name().toLowerCase());
    } else if (status == HostStatus.MAINTENANCE || status == HostStatus.PREPARING_FOR_MAINTENANCE) {
        model.setStatusDetail(entity.getMaintenanceReason());
    }
    Spm spm = new Spm();
    spm.setPriority(entity.getVdsSpmPriority());
    if (entity.getSpmStatus() != null) {
        spm.setStatus(mapSpmStatus(entity.getSpmStatus()));
    }
    model.setSpm(spm);
    if (entity.getVersion() != null && entity.getVersion().getMajor() != -1 && entity.getVersion().getMinor() != -1 && entity.getVersion().getRevision() != -1 && entity.getVersion().getBuild() != -1) {
        Version version = new Version();
        version.setMajor(entity.getVersion().getMajor());
        version.setMinor(entity.getVersion().getMinor());
        version.setRevision(entity.getVersion().getRevision());
        version.setBuild(entity.getVersion().getBuild());
        version.setFullVersion(entity.getVersion().getRpmName());
        model.setVersion(version);
    }
    model.setOs(mapOperatingSystem(entity));
    model.setKsm(new Ksm());
    model.getKsm().setEnabled(Boolean.TRUE.equals(entity.getKsmState()));
    model.setTransparentHugepages(new TransparentHugePages());
    model.getTransparentHugepages().setEnabled(!(entity.getTransparentHugePagesState() == null || entity.getTransparentHugePagesState() == VdsTransparentHugePagesState.Never));
    if (entity.getIScsiInitiatorName() != null) {
        model.setIscsi(new IscsiDetails());
        model.getIscsi().setInitiator(entity.getIScsiInitiatorName());
    }
    model.setPowerManagement(map(entity, (PowerManagement) null));
    model.setHardwareInformation(map(entity, (HardwareInformation) null));
    model.setSsh(map(entity.getStaticData(), null));
    Cpu cpu = new Cpu();
    CpuTopology cpuTopology = new CpuTopology();
    if (entity.getCpuSockets() != null) {
        cpuTopology.setSockets(entity.getCpuSockets());
        if (entity.getCpuCores() != null) {
            cpuTopology.setCores(entity.getCpuCores() / entity.getCpuSockets());
            if (entity.getCpuThreads() != null) {
                cpuTopology.setThreads(entity.getCpuThreads() / entity.getCpuCores());
            }
        }
    }
    cpu.setTopology(cpuTopology);
    cpu.setName(entity.getCpuModel());
    if (entity.getCpuSpeedMh() != null) {
        cpu.setSpeed(new BigDecimal(entity.getCpuSpeedMh()));
    }
    model.setCpu(cpu);
    VmSummary vmSummary = new VmSummary();
    vmSummary.setActive(entity.getVmActive());
    vmSummary.setMigrating(entity.getVmMigrating());
    vmSummary.setTotal(entity.getVmCount());
    model.setSummary(vmSummary);
    if (entity.getVdsType() != null) {
        HostType type = map(entity.getVdsType(), null);
        model.setType(type);
    }
    model.setMemory(Long.valueOf(entity.getPhysicalMemMb() == null ? 0 : entity.getPhysicalMemMb() * BYTES_IN_MEGABYTE));
    model.setMaxSchedulingMemory((int) entity.getMaxSchedulingMemory() * BYTES_IN_MEGABYTE);
    if (entity.getLibvirtVersion() != null && entity.getLibvirtVersion().getMajor() != -1 && entity.getLibvirtVersion().getMinor() != -1 && entity.getLibvirtVersion().getRevision() != -1 && entity.getLibvirtVersion().getBuild() != -1) {
        Version version = new Version();
        version.setMajor(entity.getLibvirtVersion().getMajor());
        version.setMinor(entity.getLibvirtVersion().getMinor());
        version.setRevision(entity.getLibvirtVersion().getRevision());
        version.setBuild(entity.getLibvirtVersion().getBuild());
        version.setFullVersion(entity.getLibvirtVersion().getRpmName());
        model.setLibvirtVersion(version);
    }
    if (entity.getConsoleAddress() != null && !"".equals(entity.getConsoleAddress())) {
        model.setDisplay(new Display());
        model.getDisplay().setAddress(entity.getConsoleAddress());
    }
    model.setKdumpStatus(map(entity.getKdumpStatus(), null));
    model.setSeLinux(map(entity, (SeLinux) null));
    model.setAutoNumaStatus(map(entity.getAutoNumaBalancing(), null));
    model.setNumaSupported(entity.isNumaSupport());
    if (entity.getHostProviderId() != null) {
        model.setExternalHostProvider(new ExternalHostProvider());
        model.getExternalHostProvider().setId(entity.getHostProviderId().toString());
    }
    model.setUpdateAvailable(entity.isUpdateAvailable());
    HostDevicePassthrough devicePassthrough = model.getDevicePassthrough();
    if (devicePassthrough == null) {
        devicePassthrough = new HostDevicePassthrough();
        model.setDevicePassthrough(devicePassthrough);
    }
    devicePassthrough.setEnabled(entity.isHostDevicePassthroughEnabled());
    if (entity.getHostName() != null) {
        String subject = CertificateSubjectHelper.getCertificateSubject(entity.getHostName());
        model.setCertificate(new Certificate());
        model.getCertificate().setSubject(subject);
        model.getCertificate().setOrganization(subject.split(",")[0].replace("O=", ""));
    }
    return model;
}
Also used : ExternalHostProvider(org.ovirt.engine.api.model.ExternalHostProvider) Ksm(org.ovirt.engine.api.model.Ksm) IscsiDetails(org.ovirt.engine.api.model.IscsiDetails) HostDevicePassthrough(org.ovirt.engine.api.model.HostDevicePassthrough) TransparentHugePages(org.ovirt.engine.api.model.TransparentHugePages) Cluster(org.ovirt.engine.api.model.Cluster) Cpu(org.ovirt.engine.api.model.Cpu) Host(org.ovirt.engine.api.model.Host) HardwareInformation(org.ovirt.engine.api.model.HardwareInformation) BigDecimal(java.math.BigDecimal) ExternalStatus(org.ovirt.engine.api.model.ExternalStatus) CpuTopology(org.ovirt.engine.api.model.CpuTopology) Spm(org.ovirt.engine.api.model.Spm) PowerManagement(org.ovirt.engine.api.model.PowerManagement) HostType(org.ovirt.engine.api.model.HostType) VmSummary(org.ovirt.engine.api.model.VmSummary) Version(org.ovirt.engine.api.model.Version) HostStatus(org.ovirt.engine.api.model.HostStatus) SeLinux(org.ovirt.engine.api.model.SeLinux) Display(org.ovirt.engine.api.model.Display) Certificate(org.ovirt.engine.api.model.Certificate)

Example 2 with Spm

use of org.ovirt.engine.api.model.Spm in project ovirt-engine by oVirt.

the class V3HostInAdapter method adapt.

@Override
public Host adapt(V3Host from) {
    Host to = new Host();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptIn(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetAddress()) {
        to.setAddress(from.getAddress());
    }
    if (from.isSetAutoNumaStatus()) {
        to.setAutoNumaStatus(AutoNumaStatus.fromValue(from.getAutoNumaStatus()));
    }
    if (from.isSetCertificate()) {
        to.setCertificate(adaptIn(from.getCertificate()));
    }
    if (from.isSetCluster()) {
        to.setCluster(adaptIn(from.getCluster()));
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetCpu()) {
        to.setCpu(adaptIn(from.getCpu()));
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDevicePassthrough()) {
        to.setDevicePassthrough(adaptIn(from.getDevicePassthrough()));
    }
    if (from.isSetDisplay()) {
        to.setDisplay(adaptIn(from.getDisplay()));
    }
    if (from.isSetExternalHostProvider()) {
        to.setExternalHostProvider(adaptIn(from.getExternalHostProvider()));
    }
    if (from.isSetExternalStatus() && from.getExternalStatus().isSetState()) {
        to.setExternalStatus(ExternalStatus.fromValue(from.getExternalStatus().getState()));
    }
    if (from.isSetHardwareInformation()) {
        to.setHardwareInformation(adaptIn(from.getHardwareInformation()));
    }
    if (from.isSetHooks()) {
        to.setHooks(new Hooks());
        to.getHooks().getHooks().addAll(adaptIn(from.getHooks().getHooks()));
    }
    if (from.isSetHostedEngine()) {
        to.setHostedEngine(adaptIn(from.getHostedEngine()));
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetIscsi()) {
        to.setIscsi(adaptIn(from.getIscsi()));
    }
    if (from.isSetKatelloErrata()) {
        to.setKatelloErrata(new KatelloErrata());
        to.getKatelloErrata().getKatelloErrata().addAll(adaptIn(from.getKatelloErrata().getKatelloErrata()));
    }
    if (from.isSetKdumpStatus()) {
        to.setKdumpStatus(KdumpStatus.fromValue(from.getKdumpStatus()));
    }
    if (from.isSetKsm()) {
        to.setKsm(adaptIn(from.getKsm()));
    }
    if (from.isSetLibvirtVersion()) {
        to.setLibvirtVersion(adaptIn(from.getLibvirtVersion()));
    }
    if (from.isSetMaxSchedulingMemory()) {
        to.setMaxSchedulingMemory(from.getMaxSchedulingMemory());
    }
    if (from.isSetMemory()) {
        to.setMemory(from.getMemory());
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetNumaSupported()) {
        to.setNumaSupported(from.isNumaSupported());
    }
    if (from.isSetOs()) {
        to.setOs(adaptIn(from.getOs()));
    }
    if (from.isSetOverrideIptables()) {
        to.setOverrideIptables(from.isOverrideIptables());
    }
    if (from.isSetPort()) {
        to.setPort(from.getPort());
    }
    if (from.isSetPowerManagement()) {
        to.setPowerManagement(adaptIn(from.getPowerManagement()));
    }
    if (from.isSetRootPassword()) {
        to.setRootPassword(from.getRootPassword());
    }
    if (from.isSetSelinux()) {
        to.setSeLinux(adaptIn(from.getSelinux()));
    }
    // This is for the old and deprecated "storage_manager" element:
    V3StorageManager storageManager = from.getStorageManager();
    if (storageManager != null) {
        Spm spm = new Spm();
        Boolean value = storageManager.isValue();
        if (value != null) {
            spm.setStatus(value ? SpmStatus.SPM : SpmStatus.NONE);
        }
        Integer priority = spm.getPriority();
        if (storageManager.getPriority() != null) {
            spm.setPriority(priority);
        }
        to.setSpm(spm);
    }
    // element to override the old element when both are provided):
    if (from.isSetSpm()) {
        to.setSpm(adaptIn(from.getSpm()));
    }
    if (from.isSetSsh()) {
        to.setSsh(adaptIn(from.getSsh()));
    }
    if (from.isSetStatistics()) {
        to.setStatistics(new Statistics());
        to.getStatistics().getStatistics().addAll(adaptIn(from.getStatistics().getStatistics()));
    }
    V3Status status = from.getStatus();
    if (status != null) {
        if (status.isSetState()) {
            to.setStatus(HostStatus.fromValue(status.getState()));
        }
        if (status.isSetDetail()) {
            to.setStatusDetail(status.getDetail());
        }
    }
    if (from.isSetStorageConnectionExtensions()) {
        to.setStorageConnectionExtensions(new StorageConnectionExtensions());
        to.getStorageConnectionExtensions().getStorageConnectionExtensions().addAll(adaptIn(from.getStorageConnectionExtensions().getStorageConnectionExtension()));
    }
    if (from.isSetSummary()) {
        to.setSummary(adaptIn(from.getSummary()));
    }
    if (from.isSetTransparentHugepages()) {
        to.setTransparentHugepages(adaptIn(from.getTransparentHugepages()));
    }
    if (from.isSetType()) {
        // In version 3 of the API the string for the RHEV_H value was "rhev-h", with a dash instead of an
        // underscore, and we need to accept that for backwards compatibility:
        String fromType = from.getType();
        HostType toType = fromType.equalsIgnoreCase("rhev-h") ? HostType.RHEV_H : HostType.fromValue(fromType);
        to.setType(toType);
    }
    if (from.isSetUpdateAvailable()) {
        to.setUpdateAvailable(from.isUpdateAvailable());
    }
    if (from.isSetVersion()) {
        to.setVersion(adaptIn(from.getVersion()));
    }
    return to;
}
Also used : Spm(org.ovirt.engine.api.model.Spm) HostType(org.ovirt.engine.api.model.HostType) KatelloErrata(org.ovirt.engine.api.model.KatelloErrata) Host(org.ovirt.engine.api.model.Host) V3Host(org.ovirt.engine.api.v3.types.V3Host) Hooks(org.ovirt.engine.api.model.Hooks) V3Status(org.ovirt.engine.api.v3.types.V3Status) StorageConnectionExtensions(org.ovirt.engine.api.model.StorageConnectionExtensions) Statistics(org.ovirt.engine.api.model.Statistics) V3StorageManager(org.ovirt.engine.api.v3.types.V3StorageManager)

Example 3 with Spm

use of org.ovirt.engine.api.model.Spm in project ovirt-engine by oVirt.

the class V3HostOutAdapter method adapt.

@Override
public V3Host adapt(Host from) {
    V3Host to = new V3Host();
    // Remove the links for "rels" that are new in version 4 of the API:
    if (from.isSetLinks()) {
        List<Link> links = from.getLinks().stream().filter(link -> !RELS_TO_REMOVE.contains(link.getRel())).collect(toList());
        to.getLinks().addAll(adaptOut(links));
    }
    if (from.isSetActions()) {
        to.setActions(adaptOut(from.getActions()));
    }
    if (from.isSetAddress()) {
        to.setAddress(from.getAddress());
    }
    if (from.isSetAutoNumaStatus()) {
        to.setAutoNumaStatus(from.getAutoNumaStatus().value());
    }
    if (from.isSetCertificate()) {
        to.setCertificate(adaptOut(from.getCertificate()));
    }
    if (from.isSetCluster()) {
        to.setCluster(adaptOut(from.getCluster()));
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetCpu()) {
        to.setCpu(adaptOut(from.getCpu()));
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDevicePassthrough()) {
        to.setDevicePassthrough(adaptOut(from.getDevicePassthrough()));
    }
    if (from.isSetDisplay()) {
        to.setDisplay(adaptOut(from.getDisplay()));
    }
    if (from.isSetExternalHostProvider()) {
        to.setExternalHostProvider(adaptOut(from.getExternalHostProvider()));
    }
    if (from.isSetExternalStatus()) {
        V3Status status = new V3Status();
        status.setState(from.getExternalStatus().value());
        to.setExternalStatus(status);
    }
    if (from.isSetHardwareInformation()) {
        to.setHardwareInformation(adaptOut(from.getHardwareInformation()));
    }
    if (from.isSetHooks()) {
        to.setHooks(new V3Hooks());
        to.getHooks().getHooks().addAll(adaptOut(from.getHooks().getHooks()));
    }
    if (from.isSetHostedEngine()) {
        to.setHostedEngine(adaptOut(from.getHostedEngine()));
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetIscsi()) {
        to.setIscsi(adaptOut(from.getIscsi()));
    }
    if (from.isSetKatelloErrata()) {
        to.setKatelloErrata(new V3KatelloErrata());
        to.getKatelloErrata().getKatelloErrata().addAll(adaptOut(from.getKatelloErrata().getKatelloErrata()));
    }
    if (from.isSetKdumpStatus()) {
        to.setKdumpStatus(from.getKdumpStatus().value());
    }
    if (from.isSetKsm()) {
        to.setKsm(adaptOut(from.getKsm()));
    }
    if (from.isSetLibvirtVersion()) {
        to.setLibvirtVersion(adaptOut(from.getLibvirtVersion()));
    }
    // All hosts support live snapshots now
    to.setLiveSnapshotSupport(true);
    if (from.isSetMaxSchedulingMemory()) {
        to.setMaxSchedulingMemory(from.getMaxSchedulingMemory());
    }
    if (from.isSetMemory()) {
        to.setMemory(from.getMemory());
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetNumaSupported()) {
        to.setNumaSupported(from.isNumaSupported());
    }
    if (from.isSetOs()) {
        to.setOs(adaptOut(from.getOs()));
    }
    if (from.isSetOverrideIptables()) {
        to.setOverrideIptables(from.isOverrideIptables());
    }
    if (from.isSetPort()) {
        to.setPort(from.getPort());
    }
    if (from.isSetPowerManagement()) {
        to.setPowerManagement(adaptOut(from.getPowerManagement()));
    }
    if (from.isSetProtocol()) {
        to.setProtocol(from.getProtocol().value());
    }
    if (from.isSetRootPassword()) {
        to.setRootPassword(from.getRootPassword());
    }
    if (from.isSetSeLinux()) {
        to.setSelinux(adaptOut(from.getSeLinux()));
    }
    Spm spm = from.getSpm();
    if (spm != null) {
        // This is for the old and deprecated "storage_manager" element:
        V3StorageManager storageManager = new V3StorageManager();
        SpmStatus status = spm.getStatus();
        if (status != null) {
            storageManager.setValue(status == SpmStatus.SPM);
        }
        if (spm.isSetPriority()) {
            storageManager.setPriority(spm.getPriority());
        }
        to.setStorageManager(storageManager);
        // This is for the new and recommended "spm" element (the order here isn't relevant, as we are populating
        // both output elements):
        to.setSpm(adaptOut(spm));
    }
    if (from.isSetSsh()) {
        to.setSsh(adaptOut(from.getSsh()));
    }
    if (from.isSetStatistics()) {
        to.setStatistics(new V3Statistics());
        to.getStatistics().getStatistics().addAll(adaptOut(from.getStatistics().getStatistics()));
    }
    if (from.isSetStatus()) {
        V3Status status = to.getStatus();
        if (status == null) {
            status = new V3Status();
            to.setStatus(status);
        }
        status.setState(from.getStatus().value());
    }
    if (from.isSetStatusDetail()) {
        V3Status status = to.getStatus();
        if (status == null) {
            status = new V3Status();
            to.setStatus(status);
        }
        status.setDetail(from.getStatusDetail());
    }
    if (from.isSetStorageConnectionExtensions()) {
        to.setStorageConnectionExtensions(new V3StorageConnectionExtensions());
        to.getStorageConnectionExtensions().getStorageConnectionExtension().addAll(adaptOut(from.getStorageConnectionExtensions().getStorageConnectionExtensions()));
    }
    if (from.isSetSummary()) {
        to.setSummary(adaptOut(from.getSummary()));
    }
    if (from.isSetTransparentHugepages()) {
        to.setTransparentHugepages(adaptOut(from.getTransparentHugepages()));
    }
    if (from.isSetType()) {
        // In version 3 of the API the string for the RHEV_H value was "rhev-h", with a dash instead of an
        // underscore, and we need to preserve that for backwards compatibility:
        HostType fromType = from.getType();
        String toType = fromType == HostType.RHEV_H ? "rhev-h" : fromType.value();
        to.setType(toType);
    }
    if (from.isSetUpdateAvailable()) {
        to.setUpdateAvailable(from.isUpdateAvailable());
    }
    if (from.isSetVersion()) {
        to.setVersion(adaptOut(from.getVersion()));
    }
    return to;
}
Also used : V3Status(org.ovirt.engine.api.v3.types.V3Status) V3StorageManager(org.ovirt.engine.api.v3.types.V3StorageManager) Host(org.ovirt.engine.api.model.Host) V3Adapter(org.ovirt.engine.api.v3.V3Adapter) V3Hooks(org.ovirt.engine.api.v3.types.V3Hooks) V3KatelloErrata(org.ovirt.engine.api.v3.types.V3KatelloErrata) SpmStatus(org.ovirt.engine.api.model.SpmStatus) Set(java.util.Set) V3Statistics(org.ovirt.engine.api.v3.types.V3Statistics) HashSet(java.util.HashSet) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) V3Host(org.ovirt.engine.api.v3.types.V3Host) Link(org.ovirt.engine.api.model.Link) HostType(org.ovirt.engine.api.model.HostType) Spm(org.ovirt.engine.api.model.Spm) V3OutAdapters.adaptOut(org.ovirt.engine.api.v3.adapters.V3OutAdapters.adaptOut) V3StorageConnectionExtensions(org.ovirt.engine.api.v3.types.V3StorageConnectionExtensions) V3KatelloErrata(org.ovirt.engine.api.v3.types.V3KatelloErrata) V3Statistics(org.ovirt.engine.api.v3.types.V3Statistics) SpmStatus(org.ovirt.engine.api.model.SpmStatus) Spm(org.ovirt.engine.api.model.Spm) V3StorageConnectionExtensions(org.ovirt.engine.api.v3.types.V3StorageConnectionExtensions) HostType(org.ovirt.engine.api.model.HostType) V3Host(org.ovirt.engine.api.v3.types.V3Host) V3Status(org.ovirt.engine.api.v3.types.V3Status) V3Hooks(org.ovirt.engine.api.v3.types.V3Hooks) Link(org.ovirt.engine.api.model.Link) V3StorageManager(org.ovirt.engine.api.v3.types.V3StorageManager)

Aggregations

Host (org.ovirt.engine.api.model.Host)3 HostType (org.ovirt.engine.api.model.HostType)3 Spm (org.ovirt.engine.api.model.Spm)3 V3Host (org.ovirt.engine.api.v3.types.V3Host)2 V3Status (org.ovirt.engine.api.v3.types.V3Status)2 V3StorageManager (org.ovirt.engine.api.v3.types.V3StorageManager)2 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 Certificate (org.ovirt.engine.api.model.Certificate)1 Cluster (org.ovirt.engine.api.model.Cluster)1 Cpu (org.ovirt.engine.api.model.Cpu)1 CpuTopology (org.ovirt.engine.api.model.CpuTopology)1 Display (org.ovirt.engine.api.model.Display)1 ExternalHostProvider (org.ovirt.engine.api.model.ExternalHostProvider)1 ExternalStatus (org.ovirt.engine.api.model.ExternalStatus)1 HardwareInformation (org.ovirt.engine.api.model.HardwareInformation)1 Hooks (org.ovirt.engine.api.model.Hooks)1