package com.lanyuanxiaoyao.service.common.entity;

import com.lanyuanxiaoyao.service.common.utils.NameHelper;
import java.io.Serializable;

/**
 * 运行时参数
 *
 * @author ZhangJiacheng
 * @date 2023-05-11
 */
@SuppressWarnings("FieldMayBeFinal")
public class RunMeta implements Serializable {
    private String cluster;
    private Long flinkJobId;
    private String alias;
    private String flinkJobName;
    private String host;
    private String applicationId;
    private String containerId;
    private String containerPath;
    private String runType;
    private String executorVersion;
    private String jvmPid;
    private String applicationProxy;
    private String subscriptionName;

    public RunMeta() {
        this.flinkJobName = System.getenv("flink_job_name");
        this.host = System.getenv("NM_HOST");
        this.applicationId = System.getenv("_APP_ID");
        this.containerId = System.getenv("CONTAINER_ID");
        this.containerPath = System.getenv("PWD");
        this.runType = System.getenv("run_type");
        this.executorVersion = System.getenv("executor_version");
        this.jvmPid = System.getenv("JVM_PID");
        this.applicationProxy = System.getenv("APPLICATION_WEB_PROXY_BASE");
    }

    public RunMeta(String cluster, Long flinkJobId) {
        this();
        this.cluster = cluster;
        this.flinkJobId = flinkJobId;
    }

    public RunMeta(String cluster, Long flinkJobId, String alias) {
        this(cluster, flinkJobId);
        this.alias = alias;
        this.subscriptionName = NameHelper.pulsarSubscriptionName(flinkJobId, alias);
    }

    public String getCluster() {
        return cluster;
    }

    public Long getFlinkJobId() {
        return flinkJobId;
    }

    public String getAlias() {
        return alias;
    }

    public String getFlinkJobName() {
        return flinkJobName;
    }

    public String getHost() {
        return host;
    }

    public String getApplicationId() {
        return applicationId;
    }

    public String getContainerId() {
        return containerId;
    }

    public String getContainerPath() {
        return containerPath;
    }

    public String getRunType() {
        return runType;
    }

    public String getExecutorVersion() {
        return executorVersion;
    }

    public String getJvmPid() {
        return jvmPid;
    }

    public String getApplicationProxy() {
        return applicationProxy;
    }

    public String getSubscriptionName() {
        return subscriptionName;
    }

    @Override
    public String toString() {
        return "RunMeta{" +
                "cluster='" + cluster + '\'' +
                ", flinkJobId='" + flinkJobId + '\'' +
                ", flinkJobName='" + flinkJobName + '\'' +
                ", host='" + host + '\'' +
                ", applicationId='" + applicationId + '\'' +
                ", containerId='" + containerId + '\'' +
                ", containerPath='" + containerPath + '\'' +
                ", runType='" + runType + '\'' +
                ", executorVersion='" + executorVersion + '\'' +
                ", jvmPid='" + jvmPid + '\'' +
                ", applicationProxy='" + applicationProxy + '\'' +
                ", subscriptionName='" + subscriptionName + '\'' +
                '}';
    }
}
