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

    https://github.com/apache/storm/pull/2199#discussion_r135642971
  
    --- Diff: 
storm-server/src/main/java/org/apache/storm/scheduler/utils/ArtifactoryConfigLoader.java
 ---
    @@ -0,0 +1,395 @@
    +/**
    + * 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 java.io.File;
    +import java.io.FileOutputStream;
    +import java.io.IOException;
    +import java.net.URI;
    +import java.net.URISyntaxException;
    +import java.util.Collections;
    +import java.util.Comparator;
    +import java.util.Map;
    +import org.apache.http.HttpEntity;
    +import org.apache.http.HttpResponse;
    +import org.apache.http.client.HttpClient;
    +import org.apache.http.client.ResponseHandler;
    +import org.apache.http.client.config.RequestConfig;
    +import org.apache.http.client.methods.HttpGet;
    +import org.apache.http.client.utils.URIBuilder;
    +import org.apache.http.impl.client.HttpClientBuilder;
    +import org.apache.http.util.EntityUtils;
    +import org.apache.storm.Config;
    +import org.apache.storm.utils.Time;
    +import org.apache.storm.utils.Utils;
    +import org.json.simple.JSONArray;
    +import org.json.simple.JSONObject;
    +import org.json.simple.parser.JSONParser;
    +import org.json.simple.parser.ParseException;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.yaml.snakeyaml.Yaml;
    +import org.yaml.snakeyaml.constructor.SafeConstructor;
    +
    +/**
    + * A dynamic loader that can load scheduler configurations for user 
resource guarantees from Artifactory (an artifact repository manager).
    + */
    +public class ArtifactoryConfigLoader implements IConfigLoader {
    +    protected static final String LOCAL_ARTIFACT_DIR = 
"scheduler_artifacts";
    +    static final String cacheFilename = "latest.yaml";
    +    private static final String DEFAULT_ARTIFACTORY_BASE_DIRECTORY = 
"/artifactory";
    +    private static final int DEFAULT_POLLTIME_SECS = 600;
    +    private static final int DEFAULT_TIMEOUT_SECS = 10;
    +    private static final String ARTIFACTORY_SCHEME_PREFIX = "artifactory+";
    +
    +    private static final Logger LOG = 
LoggerFactory.getLogger(ArtifactoryConfigLoader.class);
    +
    +    @SuppressWarnings("rawtypes")
    +    private Map loaderParams;
    +    private int artifactoryPollTimeSecs = DEFAULT_POLLTIME_SECS;
    +    private boolean cacheInitialized = false;
    +    // Location of the file in the artifactory archive.  Also used to name 
file in cache.
    +    private String localCacheDir;
    +    private String baseDirectory = DEFAULT_ARTIFACTORY_BASE_DIRECTORY;
    +    private int lastReturnedTime = 0;
    +    private int timeoutSeconds = DEFAULT_TIMEOUT_SECS;
    +    private Map lastReturnedValue;
    +    private URI targetURI = null;
    +    private JSONParser jsonParser;
    +    private String scheme;
    +
    +    public ArtifactoryConfigLoader(Map loaderParams) {
    +        this.loaderParams = loaderParams;
    +        String thisTimeout = (String) 
loaderParams.get(ConfigLoaderConfiguration.SCHEDULER_CONFIG_LOADER_TIMEOUT_SECS);
    +        if (thisTimeout != null) {
    +            timeoutSeconds = Integer.parseInt(thisTimeout);
    +        }
    +        String thisPollTime = (String) 
loaderParams.get(ConfigLoaderConfiguration.SCHEDULER_CONFIG_LOADER_POLLTIME_SECS);
    +        if (thisPollTime != null) {
    +            artifactoryPollTimeSecs = Integer.parseInt(thisPollTime);
    +        }
    +        String thisBase = (String) 
loaderParams.get(ConfigLoaderConfiguration.ARTIFACTORY_BASE_DIRECTORY);
    +        if (thisBase != null) {
    +            baseDirectory = thisBase;
    +        }
    +        String uriString = (String) 
loaderParams.get(ConfigLoaderConfiguration.SCHEDULER_CONFIG_LOADER_URI);
    +        if (uriString == null) {
    +            LOG.error("No URI defined in {} configuration.", 
ConfigLoaderConfiguration.SCHEDULER_CONFIG_LOADER_URI);
    +        } else {
    +            try {
    +                targetURI = new URI(uriString);
    +                scheme = 
targetURI.getScheme().substring(ARTIFACTORY_SCHEME_PREFIX.length());
    +            } catch(URISyntaxException e) {
    +                LOG.error("Failed to parse uri={}", uriString);
    --- End diff --
    
    My movitation here is that if the ConfigLoader doesn't work correctly, we 
will just return null. Then [scheduler 
](https://github.com/apache/storm/pull/2199/files#diff-7f8f870479c8f56254f940ea9fc70c92R65)will
 fall back to use "multitenant-scheduler.xml" file, or the configuration from 
storm.yaml. But I'm not sure if it's good


---
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