package com.lanyuanxiaoyao.service.web.entity;

import cn.hutool.core.util.ObjectUtil;
import com.eshore.odcp.hudi.connector.utils.NameHelper;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
import com.lanyuanxiaoyao.service.web.utils.DatetimeUtil;
import java.time.Instant;

/**
 * YarnApplication 展示类
 *
 * @author lanyuanxiaoyao
 * @date 2023-04-21
 */
public class YarnApplicationVO {
    @JsonIgnore
    private final YarnApplication yarnApplication;

    private final Boolean isHudiApplication;
    private String startTimeFromNow;
    private String finishTimeFromNow;

    public YarnApplicationVO(YarnApplication yarnApplication) {
        this.yarnApplication = yarnApplication;

        isHudiApplication = NameHelper.isSyncJob(yarnApplication.getName()) || NameHelper.isCompactionJob(yarnApplication.getName());

        long now = Instant.now().toEpochMilli();
        if (ObjectUtil.isNotNull(yarnApplication.getStartedTime()) && yarnApplication.getStartedTime() != 0) {
            startTimeFromNow = DatetimeUtil.fromNow(now, yarnApplication.getStartedTime());
        }
        if (ObjectUtil.isNotNull(yarnApplication.getFinishedTime()) && yarnApplication.getFinishedTime() != 0) {
            finishTimeFromNow = DatetimeUtil.fromNow(now, yarnApplication.getFinishedTime());
        }
    }

    public String getId() {
        return yarnApplication.getId();
    }

    public String getUser() {
        return yarnApplication.getUser();
    }

    public String getQueue() {
        return yarnApplication.getQueue();
    }

    public String getName() {
        return yarnApplication.getName();
    }

    public String getState() {
        return yarnApplication.getState();
    }

    public String getFinalStatus() {
        return yarnApplication.getFinalStatus();
    }

    public Float getProgress() {
        return yarnApplication.getProgress();
    }

    public String getDiagnostics() {
        return yarnApplication.getDiagnostics();
    }

    public String getApplicationType() {
        return yarnApplication.getApplicationType();
    }

    public Long getStartedTime() {
        return yarnApplication.getStartedTime();
    }

    public Long getLaunchTime() {
        return yarnApplication.getLaunchTime();
    }

    public Long getFinishedTime() {
        return yarnApplication.getFinishedTime();
    }

    public Long getElapsedTime() {
        return yarnApplication.getElapsedTime();
    }

    public String getTrackingUrl() {
        return yarnApplication.getTrackingUrl();
    }

    public Long getAllocatedMB() {
        return yarnApplication.getAllocatedMB();
    }

    public Long getAllocatedVCores() {
        return yarnApplication.getAllocatedVCores();
    }

    public Integer getRunningContainers() {
        return yarnApplication.getRunningContainers();
    }

    public Float getQueueUsagePercentage() {
        return yarnApplication.getQueueUsagePercentage();
    }

    public Float getClusterUsagePercentage() {
        return yarnApplication.getClusterUsagePercentage();
    }

    public Boolean getHudiApplication() {
        return isHudiApplication;
    }

    public String getStartTimeFromNow() {
        return startTimeFromNow;
    }

    public String getFinishTimeFromNow() {
        return finishTimeFromNow;
    }
}
