package com.bocloud.ims.entity.resource.hmc;

import com.bocloud.entity.annotations.Column;
import com.bocloud.entity.annotations.IgnoreAll;
import com.bocloud.entity.annotations.PK;
import com.bocloud.entity.annotations.Table;
import com.bocloud.entity.meta.PKStrategy;
import com.bocloud.ims.entity.common.MathUtils;

/**
 * HMC系统内存配置
 * 
 * @author sxp
 * @since May 22, 2018
 */
@Deprecated
@Table("hmc_system_memory_config")
public class HmcSystemMemoryConfig {
    @PK(value = PKStrategy.AUTO)
    private Long id;

    @Column("server_id")
    private Long serverId;

    @Column("current_available_system_memory")
    private Long currentAvailableSystemMemory;

    @Column("memory_used_by_hypervisor")
    private Long memoryUsedByHypervisor;

    @Column("configurable_system_memory")
    private Long configurableSystemMemory;

    @Column("installed_system_memory")
    private Long installedSystemMemory;

    @Column("memory_region_size")
    private Long memoryRegionSize;

    @Column("current_available_huge_pages")
    private Long currentAvailableHugePages;

    @Column("configurable_huge_pages")
    private Long configurableHugePages;

    @Column("huge_page_size")
    private Long hugePageSize;

    @Column("maximum_huge_pages")
    private Long maximumHugePages;

    @Column("requested_huge_pages")
    private Long requestedHugePages;

    @Column("total_barrier_synchronization_register_arrays")
    private Long totalBarrierSynchronizationRegisterArrays;

    @Column("barrier_synchronization_register_array_size")
    private Long barrierSynchronizationRegisterArraySize;

    @Column("available_barrier_synchronization_register_arrays")
    private Long availableBarrierSynchronizationRegisterArrays;

    @IgnoreAll
    private String activeMemorySharingCapable;
    @IgnoreAll
    private Long assignedSystemMemory;

    @IgnoreAll
    private Double currentAvailableSystemMemoryGB;
    @IgnoreAll
    private Double memoryUsedByHypervisorGB;
    @IgnoreAll
    private Double configurableSystemMemoryGB;
    @IgnoreAll
    private Double installedSystemMemoryGB;
    @IgnoreAll
    private Double memoryRegionSizeGB;
    @IgnoreAll
    private Double assignedSystemMemoryGB;

    public HmcSystemMemoryConfig() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getServerId() {
        return serverId;
    }

    public void setServerId(Long serverId) {
        this.serverId = serverId;
    }

    public Long getCurrentAvailableSystemMemory() {
        return currentAvailableSystemMemory;
    }

    public void setCurrentAvailableSystemMemory(Long currentAvailableSystemMemory) {
        this.currentAvailableSystemMemory = currentAvailableSystemMemory;
    }

    public Long getMemoryUsedByHypervisor() {
        return memoryUsedByHypervisor;
    }

    public void setMemoryUsedByHypervisor(Long memoryUsedByHypervisor) {
        this.memoryUsedByHypervisor = memoryUsedByHypervisor;
    }

    public Long getConfigurableSystemMemory() {
        return configurableSystemMemory;
    }

    public void setConfigurableSystemMemory(Long configurableSystemMemory) {
        this.configurableSystemMemory = configurableSystemMemory;
    }

    public Long getInstalledSystemMemory() {
        return installedSystemMemory;
    }

    public void setInstalledSystemMemory(Long installedSystemMemory) {
        this.installedSystemMemory = installedSystemMemory;
    }

    public Long getMemoryRegionSize() {
        return memoryRegionSize;
    }

    public void setMemoryRegionSize(Long memoryRegionSize) {
        this.memoryRegionSize = memoryRegionSize;
    }

    public Long getCurrentAvailableHugePages() {
        return currentAvailableHugePages;
    }

    public void setCurrentAvailableHugePages(Long currentAvailableHugePages) {
        this.currentAvailableHugePages = currentAvailableHugePages;
    }

    public Long getConfigurableHugePages() {
        return configurableHugePages;
    }

    public void setConfigurableHugePages(Long configurableHugePages) {
        this.configurableHugePages = configurableHugePages;
    }

    public Long getHugePageSize() {
        return hugePageSize;
    }

    public void setHugePageSize(Long hugePageSize) {
        this.hugePageSize = hugePageSize;
    }

    public Long getMaximumHugePages() {
        return maximumHugePages;
    }

    public void setMaximumHugePages(Long maximumHugePages) {
        this.maximumHugePages = maximumHugePages;
    }

    public Long getRequestedHugePages() {
        return requestedHugePages;
    }

    public void setRequestedHugePages(Long requestedHugePages) {
        this.requestedHugePages = requestedHugePages;
    }

    public Long getTotalBarrierSynchronizationRegisterArrays() {
        return totalBarrierSynchronizationRegisterArrays;
    }

    public void setTotalBarrierSynchronizationRegisterArrays(Long totalBarrierSynchronizationRegisterArrays) {
        this.totalBarrierSynchronizationRegisterArrays = totalBarrierSynchronizationRegisterArrays;
    }

    public Long getBarrierSynchronizationRegisterArraySize() {
        return barrierSynchronizationRegisterArraySize;
    }

    public void setBarrierSynchronizationRegisterArraySize(Long barrierSynchronizationRegisterArraySize) {
        this.barrierSynchronizationRegisterArraySize = barrierSynchronizationRegisterArraySize;
    }

    public Long getAvailableBarrierSynchronizationRegisterArrays() {
        return availableBarrierSynchronizationRegisterArrays;
    }

    public void setAvailableBarrierSynchronizationRegisterArrays(Long availableBarrierSynchronizationRegisterArrays) {
        this.availableBarrierSynchronizationRegisterArrays = availableBarrierSynchronizationRegisterArrays;
    }

    public Long getAssignedSystemMemory() {
        return assignedSystemMemory;
    }

    public void setAssignedSystemMemory(Long assignedSystemMemory) {
        this.assignedSystemMemory = assignedSystemMemory;
    }

    public Double getCurrentAvailableSystemMemoryGB() {
        return currentAvailableSystemMemoryGB;
    }

    public void setCurrentAvailableSystemMemoryGB(Double currentAvailableSystemMemoryGB) {
        this.currentAvailableSystemMemoryGB = currentAvailableSystemMemoryGB;
    }

    public Double getMemoryUsedByHypervisorGB() {
        return memoryUsedByHypervisorGB;
    }

    public void setMemoryUsedByHypervisorGB(Double memoryUsedByHypervisorGB) {
        this.memoryUsedByHypervisorGB = memoryUsedByHypervisorGB;
    }

    public Double getConfigurableSystemMemoryGB() {
        return configurableSystemMemoryGB;
    }

    public void setConfigurableSystemMemoryGB(Double configurableSystemMemoryGB) {
        this.configurableSystemMemoryGB = configurableSystemMemoryGB;
    }

    public Double getInstalledSystemMemoryGB() {
        return installedSystemMemoryGB;
    }

    public void setInstalledSystemMemoryGB(Double installedSystemMemoryGB) {
        this.installedSystemMemoryGB = installedSystemMemoryGB;
    }

    public Double getMemoryRegionSizeGB() {
        return memoryRegionSizeGB;
    }

    public void setMemoryRegionSizeGB(Double memoryRegionSizeGB) {
        this.memoryRegionSizeGB = memoryRegionSizeGB;
    }

    public String getActiveMemorySharingCapable() {
        return activeMemorySharingCapable;
    }

    public void setActiveMemorySharingCapable(String activeMemorySharingCapable) {
        this.activeMemorySharingCapable = activeMemorySharingCapable;
    }

    public Double getAssignedSystemMemoryGB() {
        return assignedSystemMemoryGB;
    }

    public void setAssignedSystemMemoryGB(Double assignedSystemMemoryGB) {
        this.assignedSystemMemoryGB = assignedSystemMemoryGB;
    }

    public void calculateAssignedSystemMemory() {
        if (currentAvailableSystemMemory == null || configurableSystemMemory == null
                || memoryUsedByHypervisor == null) {
            return;
        }

        // 可配置的 - 可用的 - 保留的
        long assigned = configurableSystemMemory - currentAvailableSystemMemory - memoryUsedByHypervisor;
        assignedSystemMemory = assigned;
    }

    /**
     * 计算出GB为后缀的变量的值
     * 
     * @author sxp
     * @since May 23, 2018
     */
    public void calculateMemoryGB() {
        if (currentAvailableSystemMemory != null) {
            currentAvailableSystemMemoryGB = MathUtils.round((double) currentAvailableSystemMemory / 1024, 2);
        }
        if (memoryUsedByHypervisor != null) {
            memoryUsedByHypervisorGB = MathUtils.round((double) memoryUsedByHypervisor / 1024, 2);
        }
        if (configurableSystemMemory != null) {
            configurableSystemMemoryGB = MathUtils.round((double) configurableSystemMemory / 1024, 2);
        }
        if (installedSystemMemory != null) {
            installedSystemMemoryGB = MathUtils.round((double) installedSystemMemory / 1024, 2);
        }
        if (memoryRegionSize != null) {
            memoryRegionSizeGB = MathUtils.round((double) memoryRegionSize / 1024, 2);
        }

        if (currentAvailableSystemMemoryGB == null || configurableSystemMemoryGB == null
                || memoryUsedByHypervisorGB == null) {
            return;
        }

        // 可配置的 - 可用的 - 保留的
        double assigned = configurableSystemMemoryGB - currentAvailableSystemMemoryGB - memoryUsedByHypervisorGB;
        assignedSystemMemoryGB = MathUtils.round(assigned, 2);
    }
}
