@Test public void testFilterLocalResources() throws Exception { Map<Path,List<String>> localResources = new HashMap<>(); Path path1 = new Path("/data1/liba.so"); Path path2 = new Path("/data1/liba_centos7.so"); List<String> syms1 = Arrays.asList("liba.so"); List<String> syms2 = Arrays.asList("_native_centos7_liba.so"); localResources.put(path1, syms1); localResources.put(path2, syms2); OwnLocalResources centos7_olr = new OwnLocalResources("centos7"); Map<Path, List<String>> fLRs = centos7_olr.filterLocalResources(localResources); assertEquals(syms1, fLRs.get(path2)); assertEquals(null, fLRs.get(path1)); OwnLocalResources centos6_olr = new OwnLocalResources("centos6"); fLRs = centos6_olr.filterLocalResources(localResources); assertEquals(null, fLRs.get(path2)); assertEquals(syms1, fLRs.get(path1)); }
public Map<Path,List<String>> filterLocalResources(Map<Path,List<String>> originLocalResources){ Map<Path,Path> linkNameMap = new HashMap<>(); Map<Path,List<String>> filteredLRs = new HashMap<>(); Map<Path,Path> taggingLinkNameMap = new HashMap<>(); Map<String,Path> ignores = new HashMap<>(); if(thisNodeTag == null){ return new HashMap<>(originLocalResources); } for(Map.Entry<Path,List<String>> entry: originLocalResources.entrySet()) { Path localCachePath = entry.getKey(); List<String> links = entry.getValue(); for (String item : links) { Path link = new Path(item); Pair<String, Path> pair = splitTagAndBasename(link); if(pair == null) { List<String> syms = filteredLRs.get(localCachePath); if(syms == null) { syms = new ArrayList<>(); filteredLRs.put(localCachePath, syms); } syms.add(item); linkNameMap.put(link, localCachePath); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { taggingLinkNameMap.put(taggingLinkName, localCachePath); } else { ignores.put(item, localCachePath); } } } } for(Map.Entry<Path, Path> entry: taggingLinkNameMap.entrySet()){ Path linkName = entry.getKey(); Path thisCachePath = entry.getValue(); List<String> syms; Path thatCachePath = linkNameMap.get(linkName); if(thatCachePath != null){ syms = filteredLRs.remove(thatCachePath); for(String sym:syms){ ignores.put(sym, thatCachePath); } } else { syms = new ArrayList<>(); for(String sym: originLocalResources.get(thisCachePath)){ Pair<String,Path> pair = splitTagAndBasename(new Path(sym)); if(pair == null){ syms.add(sym); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { syms.add(taggingLinkName.toString()); } else { ignores.put(sym, thisCachePath); } } } } filteredLRs.put(thisCachePath, syms); } if(ignores.size() > 0 || taggingLinkNameMap.size() > 0) { LOG.info("Ignored LRs:" + ignores + " Node Own LRs:" + taggingLinkNameMap); } return filteredLRs; }
OwnLocalResources { public Map<Path,List<String>> filterLocalResources(Map<Path,List<String>> originLocalResources){ Map<Path,Path> linkNameMap = new HashMap<>(); Map<Path,List<String>> filteredLRs = new HashMap<>(); Map<Path,Path> taggingLinkNameMap = new HashMap<>(); Map<String,Path> ignores = new HashMap<>(); if(thisNodeTag == null){ return new HashMap<>(originLocalResources); } for(Map.Entry<Path,List<String>> entry: originLocalResources.entrySet()) { Path localCachePath = entry.getKey(); List<String> links = entry.getValue(); for (String item : links) { Path link = new Path(item); Pair<String, Path> pair = splitTagAndBasename(link); if(pair == null) { List<String> syms = filteredLRs.get(localCachePath); if(syms == null) { syms = new ArrayList<>(); filteredLRs.put(localCachePath, syms); } syms.add(item); linkNameMap.put(link, localCachePath); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { taggingLinkNameMap.put(taggingLinkName, localCachePath); } else { ignores.put(item, localCachePath); } } } } for(Map.Entry<Path, Path> entry: taggingLinkNameMap.entrySet()){ Path linkName = entry.getKey(); Path thisCachePath = entry.getValue(); List<String> syms; Path thatCachePath = linkNameMap.get(linkName); if(thatCachePath != null){ syms = filteredLRs.remove(thatCachePath); for(String sym:syms){ ignores.put(sym, thatCachePath); } } else { syms = new ArrayList<>(); for(String sym: originLocalResources.get(thisCachePath)){ Pair<String,Path> pair = splitTagAndBasename(new Path(sym)); if(pair == null){ syms.add(sym); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { syms.add(taggingLinkName.toString()); } else { ignores.put(sym, thisCachePath); } } } } filteredLRs.put(thisCachePath, syms); } if(ignores.size() > 0 || taggingLinkNameMap.size() > 0) { LOG.info("Ignored LRs:" + ignores + " Node Own LRs:" + taggingLinkNameMap); } return filteredLRs; } }
OwnLocalResources { public Map<Path,List<String>> filterLocalResources(Map<Path,List<String>> originLocalResources){ Map<Path,Path> linkNameMap = new HashMap<>(); Map<Path,List<String>> filteredLRs = new HashMap<>(); Map<Path,Path> taggingLinkNameMap = new HashMap<>(); Map<String,Path> ignores = new HashMap<>(); if(thisNodeTag == null){ return new HashMap<>(originLocalResources); } for(Map.Entry<Path,List<String>> entry: originLocalResources.entrySet()) { Path localCachePath = entry.getKey(); List<String> links = entry.getValue(); for (String item : links) { Path link = new Path(item); Pair<String, Path> pair = splitTagAndBasename(link); if(pair == null) { List<String> syms = filteredLRs.get(localCachePath); if(syms == null) { syms = new ArrayList<>(); filteredLRs.put(localCachePath, syms); } syms.add(item); linkNameMap.put(link, localCachePath); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { taggingLinkNameMap.put(taggingLinkName, localCachePath); } else { ignores.put(item, localCachePath); } } } } for(Map.Entry<Path, Path> entry: taggingLinkNameMap.entrySet()){ Path linkName = entry.getKey(); Path thisCachePath = entry.getValue(); List<String> syms; Path thatCachePath = linkNameMap.get(linkName); if(thatCachePath != null){ syms = filteredLRs.remove(thatCachePath); for(String sym:syms){ ignores.put(sym, thatCachePath); } } else { syms = new ArrayList<>(); for(String sym: originLocalResources.get(thisCachePath)){ Pair<String,Path> pair = splitTagAndBasename(new Path(sym)); if(pair == null){ syms.add(sym); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { syms.add(taggingLinkName.toString()); } else { ignores.put(sym, thisCachePath); } } } } filteredLRs.put(thisCachePath, syms); } if(ignores.size() > 0 || taggingLinkNameMap.size() > 0) { LOG.info("Ignored LRs:" + ignores + " Node Own LRs:" + taggingLinkNameMap); } return filteredLRs; } OwnLocalResources(String thisNodeTag);  OwnLocalResources(); }
OwnLocalResources { public Map<Path,List<String>> filterLocalResources(Map<Path,List<String>> originLocalResources){ Map<Path,Path> linkNameMap = new HashMap<>(); Map<Path,List<String>> filteredLRs = new HashMap<>(); Map<Path,Path> taggingLinkNameMap = new HashMap<>(); Map<String,Path> ignores = new HashMap<>(); if(thisNodeTag == null){ return new HashMap<>(originLocalResources); } for(Map.Entry<Path,List<String>> entry: originLocalResources.entrySet()) { Path localCachePath = entry.getKey(); List<String> links = entry.getValue(); for (String item : links) { Path link = new Path(item); Pair<String, Path> pair = splitTagAndBasename(link); if(pair == null) { List<String> syms = filteredLRs.get(localCachePath); if(syms == null) { syms = new ArrayList<>(); filteredLRs.put(localCachePath, syms); } syms.add(item); linkNameMap.put(link, localCachePath); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { taggingLinkNameMap.put(taggingLinkName, localCachePath); } else { ignores.put(item, localCachePath); } } } } for(Map.Entry<Path, Path> entry: taggingLinkNameMap.entrySet()){ Path linkName = entry.getKey(); Path thisCachePath = entry.getValue(); List<String> syms; Path thatCachePath = linkNameMap.get(linkName); if(thatCachePath != null){ syms = filteredLRs.remove(thatCachePath); for(String sym:syms){ ignores.put(sym, thatCachePath); } } else { syms = new ArrayList<>(); for(String sym: originLocalResources.get(thisCachePath)){ Pair<String,Path> pair = splitTagAndBasename(new Path(sym)); if(pair == null){ syms.add(sym); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { syms.add(taggingLinkName.toString()); } else { ignores.put(sym, thisCachePath); } } } } filteredLRs.put(thisCachePath, syms); } if(ignores.size() > 0 || taggingLinkNameMap.size() > 0) { LOG.info("Ignored LRs:" + ignores + " Node Own LRs:" + taggingLinkNameMap); } return filteredLRs; } OwnLocalResources(String thisNodeTag);  OwnLocalResources(); static Set<String> getLocalResourcesAllTags(); static String getThisLocalResourceTag(); Pair<String,Path> splitTagAndBasename(Path path); Map<Path,List<String>> filterLocalResources(Map<Path,List<String>> originLocalResources); }
OwnLocalResources { public Map<Path,List<String>> filterLocalResources(Map<Path,List<String>> originLocalResources){ Map<Path,Path> linkNameMap = new HashMap<>(); Map<Path,List<String>> filteredLRs = new HashMap<>(); Map<Path,Path> taggingLinkNameMap = new HashMap<>(); Map<String,Path> ignores = new HashMap<>(); if(thisNodeTag == null){ return new HashMap<>(originLocalResources); } for(Map.Entry<Path,List<String>> entry: originLocalResources.entrySet()) { Path localCachePath = entry.getKey(); List<String> links = entry.getValue(); for (String item : links) { Path link = new Path(item); Pair<String, Path> pair = splitTagAndBasename(link); if(pair == null) { List<String> syms = filteredLRs.get(localCachePath); if(syms == null) { syms = new ArrayList<>(); filteredLRs.put(localCachePath, syms); } syms.add(item); linkNameMap.put(link, localCachePath); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { taggingLinkNameMap.put(taggingLinkName, localCachePath); } else { ignores.put(item, localCachePath); } } } } for(Map.Entry<Path, Path> entry: taggingLinkNameMap.entrySet()){ Path linkName = entry.getKey(); Path thisCachePath = entry.getValue(); List<String> syms; Path thatCachePath = linkNameMap.get(linkName); if(thatCachePath != null){ syms = filteredLRs.remove(thatCachePath); for(String sym:syms){ ignores.put(sym, thatCachePath); } } else { syms = new ArrayList<>(); for(String sym: originLocalResources.get(thisCachePath)){ Pair<String,Path> pair = splitTagAndBasename(new Path(sym)); if(pair == null){ syms.add(sym); } else { String tag = pair.getFirst(); Path taggingLinkName = pair.getSecond(); if(tag.equals(thisNodeTag)) { syms.add(taggingLinkName.toString()); } else { ignores.put(sym, thisCachePath); } } } } filteredLRs.put(thisCachePath, syms); } if(ignores.size() > 0 || taggingLinkNameMap.size() > 0) { LOG.info("Ignored LRs:" + ignores + " Node Own LRs:" + taggingLinkNameMap); } return filteredLRs; } OwnLocalResources(String thisNodeTag);  OwnLocalResources(); static Set<String> getLocalResourcesAllTags(); static String getThisLocalResourceTag(); Pair<String,Path> splitTagAndBasename(Path path); Map<Path,List<String>> filterLocalResources(Map<Path,List<String>> originLocalResources); static final String LR_PREFIX; static final String LR_TAG_CENTOS6; static final String LR_TAG_CENTOS7; static final String LR_TAG_MACOS10; static final String LR_TAG_DELIM; }