    001/*
    002 * Copyright (c) 2007-2016 Concurrent, Inc. All Rights Reserved.
    003 *
    004 * Project and contact information: http://www.cascading.org/
    005 *
    006 * This file is part of the Cascading project.
    007 *
    008 * Licensed under the Apache License, Version 2.0 (the "License");
    009 * you may not use this file except in compliance with the License.
    010 * You may obtain a copy of the License at
    011 *
    012 *     http://www.apache.org/licenses/LICENSE-2.0
    013 *
    014 * Unless required by applicable law or agreed to in writing, software
    015 * distributed under the License is distributed on an "AS IS" BASIS,
    016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    017 * See the License for the specific language governing permissions and
    018 * limitations under the License.
    019 */
    020
    021package cascading.tap.hadoop;
    022
    023import java.beans.ConstructorProperties;
    024import java.io.IOException;
    025
    026import cascading.scheme.Scheme;
    027import cascading.tap.SinkMode;
    028import cascading.tap.TapException;
    029import org.apache.hadoop.conf.Configuration;
    030import org.apache.hadoop.fs.FileSystem;
    031
    032/**
    033 * Class Lfs is a {@link cascading.tap.Tap} class that provides access to the Local File System via Hadoop.
    034 * <p/>
    035 * Note that using a Lfs {@link cascading.tap.Tap} instance in a {@link cascading.flow.Flow} will force a portion of not the whole Flow to be executed
    036 * in "local" mode forcing the Flow to execute in the current JVM. Mixing with {@link cascading.tap.hadoop.Dfs} and other Tap
    037 * types is possible, providing a means to implement complex file/data management functions.
    038 * <p/>
    039 * Use {@link cascading.tap.hadoop.Hfs} if you need a Tap instance that inherits the default {@link FileSystem} used by Hadoop.
    040 */
    041public class Lfs extends Hfs
    042  {
    043  @ConstructorProperties({"scheme"})
    044  Lfs( Scheme scheme )
    045    {
    046    super( scheme );
    047    }
    048
    049  /**
    050   * Constructor Lfs creates a new Lfs instance.
    051   *
    052   * @param scheme     of type Scheme
    053   * @param stringPath of type String
    054   */
    055  @ConstructorProperties({"scheme", "stringPath"})
    056  public Lfs( Scheme scheme, String stringPath )
    057    {
    058    super( scheme, stringPath );
    059    }
    060
    061  /**
    062   * Constructor Lfs creates a new Lfs instance.
    063   *
    064   * @param scheme     of type Scheme
    065   * @param stringPath of type String
    066   * @param sinkMode   of type SinkMode
    067   */
    068  @ConstructorProperties({"scheme", "stringPath", "sinkMode"})
    069  public Lfs( Scheme scheme, String stringPath, SinkMode sinkMode )
    070    {
    071    super( scheme, stringPath, sinkMode );
    072    }
    073
    074  protected void setStringPath( String stringPath )
    075    {
    076    if( stringPath.matches( ".*://.*" ) && !stringPath.startsWith( "file://" ) )
    077      throw new IllegalArgumentException( "uri must use the file scheme" );
    078
    079    super.setStringPath( stringPath );
    080    }
    081
    082  @Override
    083  protected FileSystem getFileSystem( Configuration conf )
    084    {
    085    try
    086      {
    087      return FileSystem.getLocal( conf );
    088      }
    089    catch( IOException exception )
    090      {
    091      throw new TapException( "unable to get handle to get local filesystem", exception );
    092      }
    093    }
    094  }