All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gw.common.utils.ConfigUtils Maven / Gradle / Ivy

package com.gw.common.utils;

import java.util.HashMap;
import java.util.List;

import com.app.common.cluster.ServerInfo;
import com.app.common.config.ATSROOTConfig;
import com.app.common.config.PropertiesHelper;
import com.app.common.config.RegisterParams;
import com.app.common.config.ServerParams;

public class ConfigUtils {
	public static ServerInfo getServerInfo(String serverKey) {
		try {
			PropertiesHelper atsrootConfig = ATSROOTConfig.getATSROOTConfig();
			ServerParams serverParams = atsrootConfig.findServerParam(serverKey);
			return getServiceInfo(serverParams);
		} catch (Exception e) {
			//e.printStackTrace();
		}
		ServerParams serverParams=new ServerParams();
		serverParams.ServiceName=serverKey.replace("SERVER.", "");
		serverParams.RegisterEnable=true;
		serverParams.RegType=2;
		return getServiceInfo(serverParams);
	}

	private static ServerInfo getServiceInfo(ServerParams serverParams) {
		ServerInfo serverInfo = new ServerInfo();
		serverInfo.setName(serverParams.ServiceName);
		serverInfo.setType(serverParams.RegType);
		serverInfo.setGroup("group1");
		serverInfo.setHost(serverParams.Host);
		serverInfo.setPort(serverParams.Port);
		serverInfo.setRegisterEnable(serverParams.RegisterEnable);
		HashMap hm = new HashMap<>();
		List registries = serverParams.RegisterConfigs;
		String hosts="";
		for (RegisterParams registerParams : registries) {
			hosts=hosts+registerParams.Host+":"+registerParams.Port+",";
		}
		PropertiesHelper atsrootConfig = ATSROOTConfig.getATSROOTConfig();
		String userName = atsrootConfig.getProperty("REGISTER.UserName");
		String password = atsrootConfig.getProperty("REGISTER.Password");
		String privateKey = atsrootConfig.getProperty("REGISTER.PrivateKey");

		if (hosts.length() > 0) {
			hosts = hosts.substring(0, hosts.length() - 1);
			hm.put("Cluster.Zookeeper.Hosts", hosts);
			if (userName != null) {
				hm.put("Cluster.Zookeeper.UserName", userName);
			}
			if (password != null) {
				hm.put("Cluster.Zookeeper.Password", password);
			}
			if (privateKey != null) {
				hm.put("Cluster.Zookeeper.PrivateKey", privateKey);
			}
		}		 

		serverInfo.setAtts(hm);
		return serverInfo;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy