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