Uploaded image for project: 'Apache Twill'
  1. Apache Twill
  2. TWILL-244

Provide access to ResourceReport to TwillRunnable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: api
    • Labels:
      None

      Description

      One of the use case for this is to let TwillRunnable know about what containers are running at the moment, which could be useful when building fencing mechanism for single-master + HA type of applications.

      This information can be available via the TwillContext object.

        Issue Links

          Activity

          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user chtyim opened a pull request:

          https://github.com/apache/twill/pull/61

          (TWILL-244) Make resource report available to TwillRunnable

          • Make resource report available to TwillContext
          • Enhance tracker service to provide more resource related endpoints
          • Provide endpoints to fetch specific part of the report to reduce bandwidth
          • Added a ResourceReporter API to provide programmatic access
          • Make resource report available via TwillContext
          • Fixed a concurrent modification bug in ZKDiscoveryService.close

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/chtyim/twill feature/TWILL-244-resource-report-runnable

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/twill/pull/61.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #61


          commit 53312962b33cc20c2f272b217d076730c498644d
          Author: Terence Yim <chtyim@apache.org>
          Date: 2017-08-28T23:47:45Z

          (TWILL-244) Make resource report available to TwillContext

          • Enhance tracker service to provide more resource related endpoints
          • Provide endpoints to fetch specific part of the report to reduce
            bandwidth
          • Added a ResourceReporter API to provide programmatic access
          • Make resource report available via TwillContext

          commit 31facdf2f7f93f06c8fd131960be6d4c52fd646e
          Author: Terence Yim <chtyim@apache.org>
          Date: 2017-08-29T01:33:53Z

          Fix a concurrent modification bug in ZKDiscoveryService.close


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user chtyim opened a pull request: https://github.com/apache/twill/pull/61 ( TWILL-244 ) Make resource report available to TwillRunnable Make resource report available to TwillContext Enhance tracker service to provide more resource related endpoints Provide endpoints to fetch specific part of the report to reduce bandwidth Added a ResourceReporter API to provide programmatic access Make resource report available via TwillContext Fixed a concurrent modification bug in ZKDiscoveryService.close You can merge this pull request into a Git repository by running: $ git pull https://github.com/chtyim/twill feature/ TWILL-244 -resource-report-runnable Alternatively you can review and apply these changes as the patch at: https://github.com/apache/twill/pull/61.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #61 commit 53312962b33cc20c2f272b217d076730c498644d Author: Terence Yim <chtyim@apache.org> Date: 2017-08-28T23:47:45Z ( TWILL-244 ) Make resource report available to TwillContext Enhance tracker service to provide more resource related endpoints Provide endpoints to fetch specific part of the report to reduce bandwidth Added a ResourceReporter API to provide programmatic access Make resource report available via TwillContext commit 31facdf2f7f93f06c8fd131960be6d4c52fd646e Author: Terence Yim <chtyim@apache.org> Date: 2017-08-29T01:33:53Z Fix a concurrent modification bug in ZKDiscoveryService.close
          Hide
          githubbot ASF GitHub Bot added a comment -

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

          https://github.com/apache/twill/pull/61#discussion_r136476455

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

          even if all urls fail to fetch - why is that ok?

          Show
          githubbot ASF GitHub Bot added a comment - Github user anwar6953 commented on a diff in the pull request: https://github.com/apache/twill/pull/61#discussion_r136476455 — 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 – even if all urls fail to fetch - why is that ok?
          Hide
          githubbot ASF GitHub Bot added a comment -

          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.

          Show
          githubbot ASF GitHub Bot added a comment - 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.

            People

            • Assignee:
              Unassigned
              Reporter:
              chtyim Terence Yim
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Development