Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/210#discussion_r75536649
  
    --- Diff: 
metron-analytics/metron-maas-common/src/main/java/org/apache/metron/maas/discovery/ServiceDiscoverer.java
 ---
    @@ -143,14 +167,59 @@ public void unregisterByContainer(String containerId) 
{
         }
       }
     
    +  public void blacklist(ModelEndpoint endpoint) {
    +    blacklist(toUrl(endpoint.getEndpoint().getUrl()));
    +  }
    +
    +  public void blacklist(URL url) {
    +    rwLock.writeLock().lock();
    +    blacklist.put(url, true);
    +    rwLock.writeLock().unlock();
    +  }
    +
    +  public ModelEndpoint getEndpoint(String modelName) {
    +    String version = null;
    +    rwLock.readLock().lock();
    +    version = modelToCurrentVersion.get(modelName);
    +    rwLock.readLock().unlock();
    +    if(version == null) {
    +      throw new IllegalStateException("Unable to find version for " + 
modelName);
    +    }
    +    return getEndpoint(modelName, version);
    +  }
    +
    +  private static URL toUrl(String url) {
    +    try {
    +      return new URL(url);
    +    } catch (MalformedURLException e) {
    +      throw new IllegalStateException("Endpoint does not refer to an 
actual URL");
    +    }
    +  }
    +
    +  public ModelEndpoint getEndpoint(String modelName, String modelVersion) {
    +    return getEndpoint(new Model(modelName, modelVersion));
    +  }
       public ModelEndpoint getEndpoint(Model model) {
         rwLock.readLock().lock();
         try {
           List<ModelEndpoint> endpoints = state.get(model);
           ModelEndpoint ret = null;
           if(endpoints != null) {
    -        int i = ThreadLocalRandom.current().nextInt(endpoints.size());
    -        ret = endpoints.get(i);
    +        for(int j = 0;j < 10;++j) {
    +          int i = ThreadLocalRandom.current().nextInt(endpoints.size());
    +          ret = endpoints.get(i);
    +          try {
    +            if 
(blacklist.asMap().containsKey(toUrl(ret.getEndpoint().getUrl()))) {
    +              continue;
    +            }
    +            else {
    +              return ret;
    +            }
    +          }
    +          catch(IllegalStateException ise) {
    +
    +          }
    --- End diff --
    
    Do we intend to just eat the exception?  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to