001    /*
002     * Copyright (c) 2007-2014 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    
021    package cascading.tap.hadoop;
022    
023    import java.beans.ConstructorProperties;
024    import java.io.IOException;
025    
026    import cascading.scheme.Scheme;
027    import cascading.tap.SinkMode;
028    import cascading.tap.TapException;
029    import cascading.tuple.Fields;
030    import org.apache.hadoop.fs.FileSystem;
031    import org.apache.hadoop.mapred.JobConf;
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     */
042    public 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 fields     of type Fields
054       * @param stringPath of type String
055       */
056      @ConstructorProperties({"fields", "stringPath"})
057      @Deprecated
058      public Lfs( Fields fields, String stringPath )
059        {
060        super( fields, stringPath );
061        }
062    
063      /**
064       * Constructor Lfs creates a new Lfs instance.
065       *
066       * @param scheme     of type Scheme
067       * @param stringPath of type String
068       */
069      @ConstructorProperties({"scheme", "stringPath"})
070      public Lfs( Scheme scheme, String stringPath )
071        {
072        super( scheme, stringPath );
073        }
074    
075      /**
076       * Constructor Lfs creates a new Lfs instance.
077       *
078       * @param scheme     of type Scheme
079       * @param stringPath of type String
080       * @param replace    of type boolean
081       */
082      @ConstructorProperties({"scheme", "stringPath", "replace"})
083      @Deprecated
084      public Lfs( Scheme scheme, String stringPath, boolean replace )
085        {
086        super( scheme, stringPath, replace );
087        }
088    
089      /**
090       * Constructor Lfs creates a new Lfs instance.
091       *
092       * @param fields     of type Fields
093       * @param stringPath of type String
094       * @param sinkMode   of type SinkMode
095       */
096      @ConstructorProperties({"fields", "stringPath", "sinkMode"})
097      @Deprecated
098      public Lfs( Fields fields, String stringPath, SinkMode sinkMode )
099        {
100        super( fields, stringPath, sinkMode );
101        }
102    
103      /**
104       * Constructor Lfs creates a new Lfs instance.
105       *
106       * @param scheme     of type Scheme
107       * @param stringPath of type String
108       * @param sinkMode   of type SinkMode
109       */
110      @ConstructorProperties({"scheme", "stringPath", "sinkMode"})
111      public Lfs( Scheme scheme, String stringPath, SinkMode sinkMode )
112        {
113        super( scheme, stringPath, sinkMode );
114        }
115    
116      protected void setStringPath( String stringPath )
117        {
118        if( stringPath.matches( ".*://.*" ) && !stringPath.startsWith( "file://" ) )
119          throw new IllegalArgumentException( "uri must use the file scheme" );
120    
121        super.setStringPath( stringPath );
122        }
123    
124      protected FileSystem getFileSystem( JobConf conf )
125        {
126        try
127          {
128          return FileSystem.getLocal( conf );
129          }
130        catch( IOException exception )
131          {
132          throw new TapException( "unable to get handle to get local filesystem", exception );
133          }
134        }
135      }