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

    https://github.com/apache/twill/pull/61#discussion_r137130751
  
    --- Diff: 
twill-core/src/main/java/org/apache/twill/internal/ResourceReportClient.java ---
    @@ -0,0 +1,116 @@
    +/*
    + * 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.twill.internal;
    +
    +import com.google.common.base.Charsets;
    +import org.apache.twill.api.ResourceReport;
    +import org.apache.twill.api.ResourceReporter;
    +import org.apache.twill.api.TwillRunResources;
    +import org.apache.twill.internal.json.ResourceReportAdapter;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.BufferedReader;
    +import java.io.IOException;
    +import java.io.InputStreamReader;
    +import java.io.Reader;
    +import java.lang.reflect.Type;
    +import java.net.URL;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.Map;
    +import javax.annotation.Nullable;
    +
    +/**
    + * A {@link ResourceReporter} that fetches reports from the given set of 
URLs.
    + */
    +public final class ResourceReportClient implements ResourceReporter {
    +
    +  private static final Logger LOG = 
LoggerFactory.getLogger(ResourceReportClient.class);
    +
    +  private final List<URL> resourceUrls;
    +
    +  public ResourceReportClient(List<URL> resourceUrls) {
    +    this.resourceUrls = resourceUrls;
    +  }
    +
    +  @Nullable
    +  @Override
    +  public ResourceReport getResourceReport() {
    +    for (URL url : resourceUrls) {
    +      try {
    +        return fetchURL(url, "", ResourceReport.class);
    +      } catch (IOException e) {
    +        // Just log a trace as it's ok to not able to fetch resource report
    +        LOG.trace("Exception raised when getting resource report from 
{}.", url, e);
    +      }
    +    }
    --- End diff --
    
    That's the contract of the `ResourceReporter`. If the report is not 
available for whatever reason, it'll just return `null` / empty collection.


---

Reply via email to