throw new InvalidConfigurationException(String.format("Invalid tenant identifier regular expression: %s", tenantIdentifierRegex), e);
}
configuration.setTenantIdentifierRegex(tenantIdentifierRegex);
}
Node algorithmsNode = loadBalancerNode.findChildNodeByName(Constants.CONF_ELEMENT_ALGORITHMS);
validateRequiredNode(loadBalancerNode, Constants.CONF_ELEMENT_ALGORITHMS);
for (Node algorithmNode : algorithmsNode.getChildNodes()) {
String className = algorithmNode.getProperty(Constants.CONF_PROPERTY_CLASS_NAME);
validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CLASS_NAME, className, "algorithm", algorithmNode.getName());
Algorithm algorithm = new Algorithm(algorithmNode.getName(), className);
configuration.addAlgorithm(algorithm);
}
if (!configuration.isTopologyEventListenerEnabled()) {
Node servicesNode = loadBalancerNode.findChildNodeByName(Constants.CONF_ELEMENT_SERVICES);
validateRequiredNode(servicesNode, Constants.CONF_ELEMENT_SERVICES);
for (Node serviceNode : servicesNode.getChildNodes()) {
ServiceType serviceType = ServiceType.SingleTenant;
String multiTenant = serviceNode.getProperty(Constants.CONF_PROPERTY_MULTI_TENANT);
if (StringUtils.isNotBlank(multiTenant) && (Boolean.parseBoolean(multiTenant))) {
serviceType = ServiceType.MultiTenant;
}
Service service = new Service(serviceNode.getName(), serviceType);
Node clustersNode = serviceNode.findChildNodeByName(Constants.CONF_ELEMENT_CLUSTERS);
for (Node clusterNode : clustersNode.getChildNodes()) {
String clusterId = clusterNode.getName();
Cluster cluster = new Cluster(service.getServiceName(), clusterId, null, null);
String tenantRange = clusterNode.getProperty(Constants.CONF_PROPERTY_TENANT_RANGE);
if (StringUtils.isNotBlank(tenantRange)) {
if (service.getServiceType() != ServiceType.MultiTenant) {
throw new InvalidConfigurationException(String.format("%s property is not valid for non multi-tenant service cluster: [service] %s [cluster] %s",
Constants.CONF_PROPERTY_TENANT_RANGE, service.getServiceName(), cluster.getClusterId()));
}
cluster.setTenantRange(tenantRange);
}
String algorithm = clusterNode.getProperty(Constants.CONF_PROPERTY_ALGORITHM);
if (StringUtils.isNotBlank(algorithm)) {
cluster.setLoadBalanceAlgorithmName(algorithm);
}
String hosts = clusterNode.getProperty(Constants.CONF_ELEMENT_HOSTS);
validateRequiredPropertyInNode(Constants.CONF_ELEMENT_HOSTS, hosts, "cluster", clusterNode.getName());
String[] hostsArray = hosts.split(",");
for (String hostsName : hostsArray) {
cluster.addHostName(hostsName.trim());
}
Node membersNode = clusterNode.findChildNodeByName(Constants.CONF_ELEMENT_MEMBERS);
validateRequiredNode(membersNode, Constants.CONF_ELEMENT_MEMBERS, String.format("cluster %s", clusterId));
for (Node memberNode : membersNode.getChildNodes()) {
String memberId = memberNode.getName();
Member member = new Member(cluster.getServiceName(), cluster.getClusterId(), Constants.STATIC_NETWORK_PARTITION, Constants.STATIC_PARTITION, memberId);
String ip = memberNode.getProperty(Constants.CONF_PROPERTY_IP);
validateRequiredPropertyInNode(Constants.CONF_PROPERTY_IP, ip, String.format("member %s", memberId));
member.setMemberIp(ip);
Node portsNode = memberNode.findChildNodeByName(Constants.CONF_ELEMENT_PORTS);
validateRequiredNode(portsNode, Constants.CONF_ELEMENT_PORTS, String.format("member %s", memberId));
for (Node portNode : portsNode.getChildNodes()) {
String value = portNode.getProperty(Constants.CONF_PROPERTY_VALUE);
validateRequiredPropertyInNode(Constants.CONF_PROPERTY_VALUE, value, "port", String.format("member %s", memberId));
String proxy = portNode.getProperty(Constants.CONF_PROPERTY_PROXY);
validateRequiredPropertyInNode(Constants.CONF_PROPERTY_PROXY, proxy, "port", String.format("member %s", memberId));