package com.bocloud.ims.entity.resource;

import com.bocloud.common.utils.DateDeserializer;
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.bocloud.ims.entity.resource.powervc.PowervcHmc;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;

/**
 * 物理机器类
 *
 * @author wei wei
 * @version 1.0
 * @since 2016.02.26
 */
@Table("server")
@Data
public class Server extends GenericEntity {

	@PK(value = PKStrategy.AUTO)
	private Long id; // ID
	@Column("expired_time")
	@JsonSerialize(using = DateSerializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date expiredTime;// 过期时间
	@Column("asset_category")
	private String assetCategory;// 资产类别
	@Column("category")
	private String category; // 类别
	@Column("catalog")
	private String catalog;
	@Column("uuid")
	private String uuid; // UUID
	@Column("manage_ip")
	private String manageIp; // 管理IP
	@Column("dc_id")
	private Long dcId; // 数据中心ID
	@Column("room_id")
	private Long roomId; // 机房ID
	@Column("rack_id")
	private Long rackId; // 机柜ID
	@Column("hostname")
	private String hostname;
	@Column("service_ip")
	private String serviceIp;
	@Column("tenant_id")
	private Long tenantId;
	@Column("vendor_id")
	private Long vendorId;
	@Column("is_connected")
	private Boolean connected; // 连接状态
	@Column("is_maintained")
	private Boolean maintained; // 维护模式
	@Column("ipv6_enabled")
	private Boolean ipv6Enabled; // 启用ipv6
	@Column("power_state")
	private String powerState; // 电源状态
	@Column("cluster_id")
	private Long clusterId;
	@Column("vdc_id")
	private Long vdcId;
	@Column("resource_id")
	private String resourceId; // 资源ID
	@Column("is_accurated")
	private Boolean accurated;
	@Column("root_disk_id")
	private Long rootDiskId;
	@Column("cpu_model")
	private String cpuModel;
	@Column("model_name")
	private String modelName;
	@Column("enabled")
	private Boolean enabled;
	/**
	 * WINDOWS, LINUX
	 */
	@Column("os_category")
	private String osCategory;// 系统类别
	/**
	 * CENTOS, UBUNTU, REDHAT, ESXI, WINDOWSSERVER, SUSE
	 */
	@Column("os")
	private String os;// 操作系统详细信息
	@Column("resource_group")
	private String resourceGroup;// 资源分组
	@Column("vmotion_ip")
	private String vmotionIp;
	@Column("exporter_installed")
	private Boolean exporterInstalled;

	@Column("az_uuid")
	private String azUuid;

	@IgnoreAll
	private String azName;

	@IgnoreAll
	private String resourceGroupName;
	@IgnoreAll
	private String GroupName; // 所属资源池
	@IgnoreAll
	private String vendorName; // 云供应商名称
	@IgnoreAll
	private String vendorType; // 云供应商类型
	@IgnoreAll
	private String roomname;
	@IgnoreAll
	private String rackname;
	@IgnoreAll
	private String dcname;
	@IgnoreAll
	private String clusterName;
	@IgnoreAll
	private String vdcName;
	@IgnoreAll
	private List<String> stores;
	@IgnoreAll
	private List<NetworkCard> netcards;
	@IgnoreAll
	private List<Network> networks;
	@IgnoreAll
	private List<CloudServer> servers;// 云主机
	@IgnoreAll
	private List<DataStore> dataStores;
	@IgnoreAll
	private Integer vmNum;// 宿主机（物理机）上的云主机数量
	@IgnoreAll
	private Integer templateNum;// 宿主机（物理机）上的云主机数量
	@IgnoreAll
	private Integer datastoreNum;// 数据存储数量
	@IgnoreAll
	private ServerConfig config;
	@IgnoreAll
	private ServerAssets assets;
	@IgnoreAll
	private List<Switcher> switchers;
	@Column("guid")
	private String guid;// 全局唯一标识
	@IgnoreAll
	private List<StoreHost> storeHosts;
	@IgnoreAll
	private List<PowervcHmc> powervcHmcs;

	/** 物理装机相关开始 */
	/**
	 * cop的地址信息
	 * <p>
	 * 192.168.2.85:18084
	 */
	@Column("instance")
	private String instance;
	/**
	 * 该节点在rackhd里面的id
	 * <p>
	 * 5c3e9bd5c324b5b4163c3643
	 */
	@Column("rackhd_node_id")
	private String rackhdNodeId;
	/**
	 * 装机使用的image id
	 */
	@Column("image_id")
	private Long imageId;
	@IgnoreAll
	private String imageName;
	@IgnoreAll
	private String imageIsoName;
	/**
	 * 发现任务开始的时间
	 */
	@JsonSerialize(using = DateSerializer.class)
	@JsonDeserialize(using = DateDeserializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Column("discover_time")
	private Date discoverTime;
	/**
	 * 该节点是否是被rackhd发现过
	 * <p>
	 * 如果被发现过，catalog信息都是ok的
	 * <p>
	 * 如果没有被发现过，只提供一部分功能，如设备监控
	 */
	@Column("discovered")
	private Boolean discovered;

	/**
	 * 该节点执行机器发现操作人id
	 */
	@Column("discover_user_id")
	private Long discoverUserId;
	/**
	 * 发现该物理时，使用的dhcp网卡的mac地址
	 * <p>
	 * f8:bc:12:3e:dc:64
	 */
	@Column("identifier")
	private String identifier;
	/**
	 * 物理装机相关结束
	 */

	@Column("role")
	private String role; // 角色
	@Column("services")
	private String services; // 运行的服务
	@Column("clock_diff")
	private Long clockDiff; // 服务器时间差，毫秒
	@Column("resource_label")
	private String resourceLabel; // 标签
	@IgnoreAll
	private Boolean reboot;

	@IgnoreAll
	private Integer cpuDistributable;// CPU可分配
	@IgnoreAll
	private Integer memDistributable;// 内存可分配
	@IgnoreAll
	private Long cpuRemainder;// cpu剩余
	@IgnoreAll
	private Long memoryRemainder;// 内存剩余
	@IgnoreAll
	private Long diskRemainder;// 磁盘剩余
	@IgnoreAll
	private Disk rootDisk;
	@IgnoreAll
	private Integer diskCnt;
	@IgnoreAll
	private String iqn;
	@IgnoreAll
	private List<String> roles;
	/** end */

	// fc 纳管
	@Column("uri")
	private String uri;//访问该cluster对应的uri地址
	@Column("arch")
	private String arch;
	@IgnoreAll
	private Integer cpuAmount; //cpu 数量
	@IgnoreAll
	private Long cpuHz;//cpu总
	@IgnoreAll
	private Long cpuUsed;//已使用
	@IgnoreAll
	private Double memoryCapacity;//内存容量
	@IgnoreAll
	private Double memUsed;//内存已使用
	// fc 纳管

	// 深信服超融合 start
	@Column("alert")
	private String alert;
	@Column("master")
	private Integer master;
	@Column("type")
	private String type;
	@Column("urgent")
	private Integer urgent;
	@Column("cpu_ratio")
	private String cpuRatio;
	@Column("mem_ratio")
	private String memRatio;
	@Column("io_ratio")
	private String ioRatio;
	@Column("detail")
	private String detail;
	@Column("con_mem_ratio")
	private String conMemRatio;
	// 深信服超融合 end

	//深信服v6.8字段
	@Column("sangfor_az_id")
	private String sangforAzId;
	@Column("memory")
	private String memory;
	@Column("disk")
	private String disk;
	@Column("socket_count")
	private Long socketCount;
	@Column("cpu_core")
	private Long cpuCore;
	@Column("used_cpu")
	private String usedCpu;
	@Column("used_memory")
	private String usedMemory;
	@Column("cpu_total_mhz")
	private String cpuTotalMhz;



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

}
