ClusterSubdomainAffinityAlgorithm extends CallIDAffinityBalancerAlgorithm { public void loadSubclusters(String subclustersString) { ConcurrentHashMap<String, List<String>> map = new ConcurrentHashMap<String, List<String>>(); if(subclustersString != null) { subclustersString = subclustersString.replaceAll(" ", ""); String[] groups = subclustersString.split("\\)\\("); for(int q=0; q<groups.length; q++) { String group = groups[q]; group = group.replaceAll("\\(", "").replaceAll("\\)",""); String[] hosts = group.split(","); LinkedList<String> hostGroupList = new LinkedList<String>(); for(String host:hosts) { if(host.length()>0) { if(hostGroupList.contains(host)) { throw new RuntimeException("Duplicate host " + host + " in " + hosts); } hostGroupList.add(host); } } for(String host:hosts) { List<String> tmp = new LinkedList<String>(hostGroupList); tmp.remove(host); map.put(host, tmp); } } } nodeToNodeGroup = map; }  void init(); void loadSubclusters(String subclustersString); String dumpSubcluster(); void configurationChanged();  }
@Test public void testGroupsLoad2() throws Exception, ParseException { ClusterSubdomainAffinityAlgorithm algorithm = new ClusterSubdomainAffinityAlgorithm(); try { algorithm.loadSubclusters(groups2); } catch (Exception e) { return; } fail("Excpeted excpetion"); }
@Test public void testPartnerFailover() throws Exception, ParseException { try { ClusterSubdomainAffinityAlgorithm algorithm = new ClusterSubdomainAffinityAlgorithm(); algorithm.balancerContext = new BalancerContext(); algorithm.balancerContext.lbConfig = new LoadBalancerConfiguration(); algorithm.balancerContext.lbConfig.getSipConfiguration().getAlgorithmConfiguration().setSubclusterMap(failoverGroup); algorithm.balancerContext.smppToNodeAlgorithmClassName = algorithm.balancerContext.lbConfig.getSmppConfiguration().getSmppToNodeAlgorithmClass(); algorithm.balancerContext.smppToProviderAlgorithmClassName = algorithm.balancerContext.lbConfig.getSmppConfiguration().getSmppToProviderAlgorithmClass(); algorithm.balancerContext.algorithmClassName = ClusterSubdomainAffinityAlgorithm.class.getName(); InvocationContext ctx = new InvocationContext("0",algorithm.balancerContext); ctx.sipNodeMap(false).clear(); for(int q=0;q<100;q++) { Node node = new Node("alphabeticalNoise"+q, "alphabeticalNoise"+q); ctx.sipNodeMap(false).put(new KeySip(node,false),node); } for(int q=0;q<100;q++) { Node node = new Node(q+"alphabeticalNoise"+q, q+"alphabeticalNoise"+q); ctx.sipNodeMap(false).put(new KeySip(node,false),node); } Node originalNode = new Node("original", "original"); Node partnerNode = new Node("partner", "partner"); ctx.sipNodeMap(false).put(new KeySip(partnerNode,false), partnerNode); for(int q=0;q<100;q++) { Node node = new Node("nonParner"+q, "nonPartner"+q); ctx.sipNodeMap(false).put(new KeySip(node,false),node); } algorithm.callIdMap.put("cid", originalNode); Request request = SipFactory.getInstance().createMessageFactory().createRequest(inviteRequest); algorithm.loadSubclusters(failoverGroup); algorithm.invocationContext = ctx; Node resultNode = algorithm.processExternalRequest(request,false); assertEquals("partner", resultNode.getIp()); originalNode = null; partnerNode = null; resultNode = null; } finally { } }