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

    https://github.com/apache/storm/pull/1785#discussion_r88934621
  
    --- Diff: 
storm-core/src/jvm/org/apache/storm/scheduler/utils/ArtifactoryConfigLoader.java
 ---
    @@ -0,0 +1,388 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.storm.scheduler.utils;
    +
    +import org.apache.storm.utils.Time;
    +import org.apache.storm.Config;
    +import java.io.File;
    +import java.io.FileOutputStream;
    +import java.io.IOException;
    +import java.net.URI;
    +import java.util.Collections;
    +import java.util.Comparator;
    +import java.util.Map;
    +import org.json.simple.JSONArray;
    +import org.json.simple.JSONObject;
    +import org.json.simple.parser.ParseException;
    +import org.json.simple.parser.JSONParser;
    +import org.apache.http.HttpEntity;
    +import org.apache.http.HttpResponse;
    +import org.apache.http.client.ClientProtocolException;
    +import org.apache.http.client.ResponseHandler;
    +import org.apache.http.client.methods.HttpGet;
    +import org.apache.http.client.config.RequestConfig; 
    +import org.apache.http.client.utils.URIBuilder;
    +import org.apache.http.impl.client.HttpClientBuilder; 
    +import org.apache.http.client.HttpClient; 
    +import org.apache.http.util.EntityUtils;
    +import org.yaml.snakeyaml.Yaml;
    +import org.yaml.snakeyaml.constructor.SafeConstructor;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +public class ArtifactoryConfigLoader implements IConfigLoader {
    +    /**
    +     * Configuration items for this config loader are passed in via confg 
settings in 
    +     * each scheduler that has a configurable loader.
    +     *
    +     * For example, the resource aware scheduler has configuration items 
defined in Config.java
    +     * that allow a user to configure which implementation of 
IConfigLoader to use to load
    +     * specific scheduler configs as well as any parameters to pass into 
the prepare method of
    +     * tht configuration.
    +     *
    +     * resource.aware.scheduler.user.pools.loader can be set to 
org.apache.storm.scheduler.utils.ArtifactoryConfigLoader
    +     *
    +     * and then
    +     *
    +     * resource.aware.scheduler.user.pools.loader.params can be set to any 
of the following
    +     *
    +     *  {"artifactory.config.loader.uri": 
"http://artifactory.example.org:9989/artifactory/confs/my_cluster/mt_user_pool"}
    +     *
    +     *  {"artifactory.config.loader.uri": 
"file:///confs/my_cluster/mt_user_pool"}
    +     *
    +     *  {"artifactory.config.loader.uri": 
"file:///confs/my_cluster/mt_user_pool", 
"artifactory.config.loader.timeout.secs" : "60"}
    +     **/
    +    protected static final String ARTIFACTORY_URI = 
"artifactory.config.loader.uri";
    +    protected static final String 
ARTIFACTORY_TIMEOUT_SECS="artifactory.config.loader.timeout.secs";
    +    protected static final String 
ARTIFACTORY_POLL_TIME_SECS="artifactory.config.loader.polltime.secs";
    +    protected static final String 
ARTIFACTORY_SCHEME="artifactory.config.loader.scheme";
    +    protected static final String 
ARTIFACTORY_BASE_DIRECTORY="artifactory.config.loader.base.directory";
    +    protected static final String LOCAL_ARTIFACT_DIR="scheduler_artifacts";
    +    static final String cacheFilename = "latest.yaml";
    +
    +    private static final Logger LOG = 
LoggerFactory.getLogger(ArtifactoryConfigLoader.class);
    +
    +    @SuppressWarnings("rawtypes")
    +    private Map _conf;
    +    private int _artifactoryPollTimeSecs = 600;
    +    private boolean _cacheInitialized = false;
    +    // Location of the file in the artifactory archive.  Also used to name 
file in cache.
    +    private String _localCacheDir;
    +    private String _artifactoryScheme = "http";
    +    private String _baseDirectory = "/artifactory";
    +    private int _lastReturnedTime = 0;
    +    private int _timeoutSeconds = 10;
    +    private Map _lastReturnedValue;
    +
    +    private static class OurResponseHandler implements 
ResponseHandler<String> {
    +        private static OurResponseHandler singleton = null;
    +
    +        public static OurResponseHandler getInstance() {
    +            if (singleton == null) {
    +                singleton = new OurResponseHandler();
    +            }
    +            return singleton;
    +        }
    +
    +        @Override
    +        public String handleResponse(final HttpResponse response) throws 
IOException {
    +            int status = response.getStatusLine().getStatusCode();
    +            if (status >= 200 && status < 300) {
    +                HttpEntity entity = response.getEntity();
    +                return entity != null ? EntityUtils.toString(entity) : 
null;
    +            } else {
    +                LOG.error("Got unexpected response code {}", status);
    +                return null;
    +            }
    +        }
    +    };
    +
    +    // Protected so we can override this in testing
    +    protected String doGet(String api, String artifact, String host, 
Integer port) {
    +        URIBuilder builder = new 
URIBuilder().setScheme(_artifactoryScheme).setHost(host).setPort(port);
    +
    +        if (api != null) {
    +            builder.setPath(_baseDirectory + api + artifact);
    +        } else {
    +            builder.setPath(_baseDirectory + artifact);
    --- End diff --
    
    Do we want to filter out double back slashes? "//".  If I remember 
correctly I think I have had issues with artifactory and too many / characters, 
almost like it is running jetty behind the scenes.


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

Reply via email to