feat(configuration): 增加yarn集群的相关配置

This commit is contained in:
2024-02-26 18:31:47 +08:00
parent 8dfc797dfa
commit 834980f880
17 changed files with 254 additions and 60 deletions

View File

@@ -0,0 +1,35 @@
package com.lanyuanxiaoyao.service.configuration.entity.yarn;
import java.util.List;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Yarn 部署信息
*
* @author lanyuanxiaoyao
* @date 2024-02-26
*/
@ConfigurationProperties("yarn-cluster")
@Component
public class YarnClusterProperties {
private String syncClusters = "";
private String compactionClusters = "";
public String getSyncClusters() {
return syncClusters;
}
public void setSyncClusters(String syncClusters) {
this.syncClusters = syncClusters;
}
public String getCompactionClusters() {
return compactionClusters;
}
public void setCompactionClusters(String compactionClusters) {
this.compactionClusters = compactionClusters;
}
}

View File

@@ -0,0 +1,94 @@
package com.lanyuanxiaoyao.service.configuration.entity.yarn;
import cn.hutool.core.map.MapUtil;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* Yarn 集群信息
*
* @author lanyuanxiaoyao
* @date 2024-02-26
*/
@Component
public class YarnClusters {
private static final Logger logger = LoggerFactory.getLogger(YarnClusters.class);
private final ImmutableMap<String, Cluster> clusters = Maps.immutable.ofAll(
MapUtil.<String, Cluster>builder()
.put("a4", new Cluster("http://132.121.107.91:8088"))
.put("b1", new Cluster("http://132.122.98.13:8088"))
.put("b4", new Cluster("http://132.122.112.30:8088"))
.put("b5", new Cluster("http://132.122.116.12:8088"))
.put("t5", new Cluster("http://132.121.126.84:8088"))
.put("b12", new Cluster("http://132.126.207.125:8088"))
.build()
);
private final ImmutableList<String> activeClusters;
private final String defaultSyncCluster;
private final ImmutableList<String> syncClusters;
private final String defaultCompactionCluster;
private final ImmutableList<String> compactionClusters;
public YarnClusters(YarnClusterProperties yarnClusterProperties) {
syncClusters = Lists.immutable.of(yarnClusterProperties.getSyncClusters().split(",")).select(clusters::containsKey);
defaultSyncCluster = syncClusters.getFirstOptional().orElse("");
compactionClusters = Lists.immutable.of(yarnClusterProperties.getCompactionClusters().split(",")).select(clusters::containsKey);
defaultCompactionCluster = compactionClusters.getFirstOptional().orElse("");
activeClusters = syncClusters.newWithAll(compactionClusters).distinct();
}
public ImmutableMap<String, Cluster> getClusters() {
return clusters;
}
public ImmutableList<String> getActiveClusters() {
return activeClusters;
}
public String getDefaultSyncCluster() {
return defaultSyncCluster;
}
public ImmutableList<String> getSyncClusters() {
return syncClusters;
}
public String getDefaultCompactionCluster() {
return defaultCompactionCluster;
}
public ImmutableList<String> getCompactionClusters() {
return compactionClusters;
}
public static final class Cluster {
private String webUrl;
public Cluster(String webUrl) {
this.webUrl = webUrl;
}
public String getWebUrl() {
return webUrl;
}
public void setWebUrl(String webUrl) {
this.webUrl = webUrl;
}
@Override
public String toString() {
return "Cluster{" +
"webUrl='" + webUrl + '\'' +
'}';
}
}
}