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

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.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import lombok.Data;

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

import org.springframework.format.annotation.DateTimeFormat;

/**
 * k8s节点
 *
 * @author weiwei
 */
@Table("kube_node")
@Data
public class KubeNode extends GenericEntity {

	@PK(value = PKStrategy.AUTO)
	private Long id; // ID
	@Column("instance_id")
	private String instanceId;// 实例ID
	@Column("address")
	private String address;// 地址
	@Column("pod_cidr")
	private String podCidr;// pod cidr
	@Column("role")
	private String role; // 角色
	@Column("vendor_id")
	private Long vendorId; // 云供应商Id
	@Column("labels")
	private String labels;
	@Column("schedulable")
	private Boolean schedulable;
	@Column("annotations")
	private String annotations;
	@Column("machine_id")
	private String machineId;
	@Column("system_uuid")
	private String systemUuid;
	@Column("boot_id")
	private String bootId;
	@Column("kernel_version")
	private String kernelVersion;
	@Column("os_image")
	private String osImage;
	@Column("container_runtime_version")
	private String containerRuntimeVersion;
	@Column("kubelet_version")
	private String kubeletVersion;
	@Column("kube_proxy_version")
	private String kubeProxyVersion;
	@Column("operating_system")
	private String operatingSystem;
	@Column("architecture")
	private String architecture;
	@Column("node_ip")
	private String nodeIp;
	@Column("uid")
	private String uid;// uuid
	@Column("kind")
	private String kind;
	@Column("api_version")
	private String apiVersion;
	// 用于cms
	@IgnoreAll
	private String thresholdGroupName;// 阈值组
	@IgnoreAll
	private String policyName;// 分发策略
	@IgnoreAll
	private Long ruleRelationId;// 关联关系id
	@IgnoreAll
	private Long thresholdGroupId; // 阈值组ID
	@IgnoreAll
	private Long policyId; // 分发策略ID

	@Column("cpu")
	private Integer cpu;
	@Column("memory")
	private BigDecimal memory;
	@Column("cpu_used")
	private String cpuUsed;
	@Column("memory_used")
	private String memoryUsed;
	@Column("cpu_percent")
	private String cpuPercent;
	@Column("memory_percent")
	private String memoryPercent;

	@Column("creation_time")
	@JsonSerialize(using = com.bocloud.common.utils.DateSerializer.class)
	@JsonDeserialize(using = com.bocloud.common.utils.DateDeserializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date creationTime;

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