package com.lanyuanxiaoyao.service.yarn.configuration;

import java.util.Map;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.map.ImmutableMap;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * Yarn 配置
 *
 * @author lanyuanxiaoyao
 * @date 2023-04-23
 */
@Component
@ConfigurationProperties("yarn")
public class YarnConfiguration {
    private ImmutableMap<String, String> webUrls;

    public ImmutableMap<String, String> getWebUrls() {
        return webUrls;
    }

    public String getWebUrl(String cluster) {
        if (!webUrls.containsKey(cluster)) {
            throw new RuntimeException("Cluster not found");
        }
        return webUrls.get(cluster);
    }

    public void setWebUrls(Map<String, String> webUrls) {
        this.webUrls = Maps.immutable.ofAll(webUrls);
    }

    @Override
    public String toString() {
        return "YarnConfiguration{" +
                "clusters=" + webUrls +
                '}';
    }
}
