package com.bocloud.ims.entity.resource;

import com.bocloud.cmp.model.HostSystem;
import com.bocloud.common.utils.DateSerializer;
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.bean.GenericEntity;
import com.bocloud.entity.meta.PKStrategy;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Table("clusters")
@Data
public class Cluster extends GenericEntity {

    @PK(value = PKStrategy.AUTO)
    private Long id;
    @Column("uuid")
    private String uuid;
    @Column("vendor_id")
    private Long vendorId; // 云供应商ID
    @IgnoreAll
    private String vendorName; // 云供应商名称
    @Column("gmt_expired")
    @JsonSerialize(using = DateSerializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date gmtExpired;// 过期时间
    @Column("cpu_total")
    private Long cpuTotal;
    @Column("mem_total")
    private Double memTotal;
    @Column("disk_total")
    private Double diskTotal;
    @Column("cpu_used")
    private Long cpuUsed;
    @Column("mem_used")
    private Double memUsed;
    @Column("disk_used")
    private Double diskUsed;
    @IgnoreAll
    private Long cpuUnused;
    @IgnoreAll
    private Double memUnused;
    @IgnoreAll
    private Double diskUnused;
    @Column("vdc_id")
    private Long vdcId;
    @Column("category")
    private String category;
    @IgnoreAll
    private List<HostSystem> hosts;
    @IgnoreAll
    private String vdcName;
    @Column("host_num")
    private Integer hostNum;// 集群下物理主机数量
    @Column("vm_num")
    private Integer vmNum;// 集群下云主机数量
    @Column("template_num")
    private Integer templateNum;// 集群下模板数量
    @Column("cpu_core")
    private Integer cpuCore;// 集群中cpu核数
    @Column("cluster_val")
    private String clusterVal;
    @Column("type")
    private String type;
    @Column("version")
    private String version;
    @IgnoreAll
    private List<ClusterNode> nodes;
    @IgnoreAll
    private VmResourcePool resourcePool;
    @Column("guid")
    private String guid;// 全局唯一标识
    @Column("region_id")
    private Long regionId;
    @IgnoreAll
    private String regionName;
    @Column("cpu_excess_ratio")
    private Long cpuExcessRatio;// CPU超分比
    @Column("cpu_distributable_ratio")
    private BigDecimal cpuDistributableRatio;// CPU可分配百分比
    @Column("mem_distributable_ratio")
    private BigDecimal memDistributableRatio;// 内存可分配百分比
    @Column("policy_id")
    private Long policyId;// 策略ID
    @IgnoreAll
    private Integer vmCpuTotal;// 集群下云主机CPU总量
    @IgnoreAll
    private Integer cpuDistributable;// CPU可分配
    @IgnoreAll
    private Double memDistributable;// 内存可分配
    @Column("initial_policy")
    private String initialPolicy; // 布置策略

    // fc 纳管
    @Column("res_strategy")
    private String resStrategy;//集群的资源分配策略 loadBalance: 负载均衡、random: 随机、默认是负载均衡
    @Column("arch")
    private String arch;//集群架构，x86场景为“x86”，arm场景下为“arm”
    @Column("uri")
    private String uri;//访问该cluster对应的uri地址
    @Column("is_mem_overcommit")
    private Boolean isMemOvercommit;//内存复用开关
    @Column("is_enable_ha")
    private Boolean isEnableHa;//HA功能开关 (创建需要传递)
    @Column("is_enable_imc")
    private Boolean isEnableImc;//异构迁移集群(IMC)模式开关\true: 开启\false: 关闭
    @Column("is_enable_drs")
    private Boolean isEnableDrs;//DRS开关
    @Column("enable_guest_numa")
    private Boolean enableGuestNuma;//集群非统一内存访问开关（NUMA）
    @Column("enable_io_tailor")
    private Boolean enableIOTailor;//集群本地内存盘开关
    @Column("is_auto_adjust_numa")
    private Boolean isAutoAdjustNuma;//可选，是否开启NUMA结构自动调整
    @IgnoreAll
    private String cpuUsage;
    @IgnoreAll
    private String memUsage;
    // fc 纳管

    /**
     * @param creatorId
     * @param ownerId
     * @param menderId
     * @param id
     * @param uuid
     * @param vendorId
     * @param vendorName
     * @param gmtExpired
     * @param cpuTotal
     * @param memTotal
     * @param diskTotal
     * @param cpuUsed
     * @param memUsed
     * @param diskUsed
     */
    public Cluster(Long creatorId, Long ownerId, Long menderId, Long id, String uuid, Long vendorId, String vendorName,
            Date gmtExpired, Long cpuTotal, Double memTotal, Double diskTotal, Long cpuUsed, Double memUsed,
            Double diskUsed, Integer hostNum, Integer vmNum, Integer templateNum, Integer cpuCore, String clusterVal) {
        this.setCreatorId(creatorId);
        this.setOwnerId(ownerId);
        this.setMenderId(menderId);
        this.id = id;
        this.uuid = uuid;
        this.vendorId = vendorId;
        this.vendorName = vendorName;
        this.gmtExpired = gmtExpired;
        this.cpuTotal = cpuTotal;
        this.memTotal = memTotal;
        this.diskTotal = diskTotal;
        this.cpuUsed = cpuUsed;
        this.memUsed = memUsed;
        this.diskUsed = diskUsed;
        this.hostNum = hostNum;
        this.vmNum = vmNum;
        this.templateNum = templateNum;
        this.cpuCore = cpuCore;
        this.clusterVal = clusterVal;
    }

    public Cluster() {
        super();
    }

    public void preSave(Long creatorId, Long menderId, Long vendorId, Long vdcId) {
        this.setCreatorId(creatorId);
        this.setMenderId(menderId);
        this.setVendorId(vendorId);
        this.setVdcId(vdcId);
    }

}
