You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@twill.apache.org by chtyim <gi...@git.apache.org> on 2015/12/24 05:38:31 UTC

[GitHub] incubator-twill pull request: (TWILL-158) Added FileContext Locati...

GitHub user chtyim opened a pull request:

    https://github.com/apache/incubator-twill/pull/73

    (TWILL-158) Added FileContext Location and LocationFactory

    - Added new unit-tests.
    - Minor improvement on HDFSLocationFactory to handle creation URI correctly

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

    $ git pull https://github.com/chtyim/incubator-twill feature/TWILL-158

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

    https://github.com/apache/incubator-twill/pull/73.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 #73
    
----
commit 1e789ee83c23cb4d49888e57accfda276e0fd23f
Author: Terence Yim <ch...@apache.org>
Date:   2015-12-24T04:38:03Z

    (TWILL-158) Added FileContext Location and LocationFactory
    
    - Added new unit-tests.
    - Minor improvement on HDFSLocationFactory to handle creation URI correctly

----


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

[GitHub] incubator-twill pull request: (TWILL-158) Added FileContext Locati...

Posted by chtyim <gi...@git.apache.org>.
Github user chtyim commented on a diff in the pull request:

    https://github.com/apache/incubator-twill/pull/73#discussion_r48785616
  
    --- Diff: twill-yarn/src/main/java/org/apache/twill/filesystem/FileContextLocationFactory.java ---
    @@ -0,0 +1,119 @@
    +/*
    + * 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.filesystem;
    +
    +import com.google.common.base.Preconditions;
    +import com.google.common.base.Throwables;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.hadoop.fs.FileContext;
    +import org.apache.hadoop.fs.Path;
    +import org.apache.hadoop.fs.UnsupportedFileSystemException;
    +
    +import java.net.URI;
    +import java.util.Objects;
    +
    +/**
    + * A {@link LocationFactory} implementation that uses {@link FileContext} to create {@link Location}.
    + */
    +public class FileContextLocationFactory implements LocationFactory {
    +
    +  private final Configuration configuration;
    +  private final FileContext fc;
    +  private final Path pathBase;
    +
    +  /**
    +   * Same as {@link #FileContextLocationFactory(Configuration, String) FileContextLocationFactory(configuration, "/")}.
    +   */
    +  public FileContextLocationFactory(Configuration configuration) {
    +    this(configuration, "/");
    +  }
    +
    +  /**
    +   * Creates a new instance.
    +   *
    +   * @param configuration the hadoop configuration
    +   * @param pathBase base path for all non-absolute location created through this {@link LocationFactory}.
    +   */
    +  public FileContextLocationFactory(Configuration configuration, String pathBase) {
    +    this.configuration = configuration;
    +    this.fc = createFileContext(configuration);
    +    this.pathBase = new Path(pathBase.startsWith("/") ? pathBase : "/" + pathBase);
    +  }
    +
    +  @Override
    +  public Location create(String path) {
    +    if (path.startsWith("/")) {
    +      path = path.substring(1);
    +    }
    +    Path locationPath;
    +    if (path.isEmpty()) {
    +      locationPath = pathBase;
    +    } else {
    +      locationPath = new Path(path);
    +    }
    +    locationPath = locationPath.makeQualified(fc.getDefaultFileSystem().getUri(), pathBase);
    +    return new FileContextLocation(this, fc, locationPath);
    +  }
    +
    +  @Override
    +  public Location create(URI uri) {
    +    URI contextURI = fc.getWorkingDirectory().toUri();
    +    if (Objects.equals(contextURI.getScheme(), uri.getScheme())
    +      && Objects.equals(contextURI.getAuthority(), uri.getAuthority())) {
    +      // A full URI
    +      return new FileContextLocation(this, fc, new Path(uri));
    +    }
    +
    +    if (uri.isAbsolute()) {
    --- End diff --
    
    It's documented in the URI class.


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

[GitHub] incubator-twill pull request: (TWILL-158) Added FileContext Locati...

Posted by poornachandra <gi...@git.apache.org>.
Github user poornachandra commented on the pull request:

    https://github.com/apache/incubator-twill/pull/73#issuecomment-168839845
  
    LGTM


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

[GitHub] incubator-twill pull request: (TWILL-158) Added FileContext Locati...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-twill/pull/73


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

[GitHub] incubator-twill pull request: (TWILL-158) Added FileContext Locati...

Posted by chtyim <gi...@git.apache.org>.
Github user chtyim commented on the pull request:

    https://github.com/apache/incubator-twill/pull/73#issuecomment-168841391
  
    Deprecating the HDFSLocationFactory seems like a good idea. Will do.


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

[GitHub] incubator-twill pull request: (TWILL-158) Added FileContext Locati...

Posted by poornachandra <gi...@git.apache.org>.
Github user poornachandra commented on the pull request:

    https://github.com/apache/incubator-twill/pull/73#issuecomment-168818870
  
    Since the JIRA says `HDFSLocationFactory` _uses a hacky way to implement rename()_, should we deprecate `HDFSLocationFactory`?


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

[GitHub] incubator-twill pull request: (TWILL-158) Added FileContext Locati...

Posted by poornachandra <gi...@git.apache.org>.
Github user poornachandra commented on a diff in the pull request:

    https://github.com/apache/incubator-twill/pull/73#discussion_r48784930
  
    --- Diff: twill-yarn/src/main/java/org/apache/twill/filesystem/FileContextLocationFactory.java ---
    @@ -0,0 +1,119 @@
    +/*
    + * 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.filesystem;
    +
    +import com.google.common.base.Preconditions;
    +import com.google.common.base.Throwables;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.hadoop.fs.FileContext;
    +import org.apache.hadoop.fs.Path;
    +import org.apache.hadoop.fs.UnsupportedFileSystemException;
    +
    +import java.net.URI;
    +import java.util.Objects;
    +
    +/**
    + * A {@link LocationFactory} implementation that uses {@link FileContext} to create {@link Location}.
    + */
    +public class FileContextLocationFactory implements LocationFactory {
    +
    +  private final Configuration configuration;
    +  private final FileContext fc;
    +  private final Path pathBase;
    +
    +  /**
    +   * Same as {@link #FileContextLocationFactory(Configuration, String) FileContextLocationFactory(configuration, "/")}.
    +   */
    +  public FileContextLocationFactory(Configuration configuration) {
    +    this(configuration, "/");
    +  }
    +
    +  /**
    +   * Creates a new instance.
    +   *
    +   * @param configuration the hadoop configuration
    +   * @param pathBase base path for all non-absolute location created through this {@link LocationFactory}.
    +   */
    +  public FileContextLocationFactory(Configuration configuration, String pathBase) {
    +    this.configuration = configuration;
    +    this.fc = createFileContext(configuration);
    +    this.pathBase = new Path(pathBase.startsWith("/") ? pathBase : "/" + pathBase);
    +  }
    +
    +  @Override
    +  public Location create(String path) {
    +    if (path.startsWith("/")) {
    +      path = path.substring(1);
    +    }
    +    Path locationPath;
    +    if (path.isEmpty()) {
    +      locationPath = pathBase;
    +    } else {
    +      locationPath = new Path(path);
    +    }
    +    locationPath = locationPath.makeQualified(fc.getDefaultFileSystem().getUri(), pathBase);
    +    return new FileContextLocation(this, fc, locationPath);
    +  }
    +
    +  @Override
    +  public Location create(URI uri) {
    +    URI contextURI = fc.getWorkingDirectory().toUri();
    +    if (Objects.equals(contextURI.getScheme(), uri.getScheme())
    +      && Objects.equals(contextURI.getAuthority(), uri.getAuthority())) {
    +      // A full URI
    +      return new FileContextLocation(this, fc, new Path(uri));
    +    }
    +
    +    if (uri.isAbsolute()) {
    --- End diff --
    
    It will be good to have a comment on what a full URI and an absolute URI mean.


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