metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cestella <...@git.apache.org>
Subject [GitHub] incubator-metron pull request #210: METRON-366: Add MODEL_APPLY to Stellar
Date Fri, 19 Aug 2016 19:16:04 GMT
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/210#discussion_r75537367
  
    --- 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 --
    
    Yes it is trying 10 times to get an endpoint.  If an exception happens on an attempt then
we move on.  Frankly this is an excess of caution since we parse the URLs on the server side
before they go into zookeeper, so they are valid.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message