    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.flow.hadoop2;
    022
    023    import java.util.Map;
    024    import java.util.Properties;
    025    import java.util.Set;
    026
    027    import cascading.flow.hadoop.planner.HadoopPlanner;
    028    import org.apache.hadoop.conf.Configuration;
    029
    030    /**
    031     *
    032     */
    033    public class Hadoop2MR1Planner extends HadoopPlanner
    034      {
    035      /**
    036       * Method copyJobConf adds the given JobConf values to the given properties object. Use this method to pass
    037       * custom default Hadoop JobConf properties to Hadoop.
    038       *
    039       * @param properties    of type Map
    040       * @param configuration of type JobConf
    041       */
    042      public static void copyConfiguration( Map<Object, Object> properties, Configuration configuration )
    043        {
    044        for( Map.Entry<String, String> entry : configuration )
    045          properties.put( entry.getKey(), entry.getValue() );
    046        }
    047
    048    //  /**
    049    //   * Method createJobConf returns a new JobConf instance using the values in the given properties argument.
    050    //   *
    051    //   * @param properties of type Map
    052    //   * @return a JobConf instance
    053    //   */
    054    //  public static JobConf createJobConf( Map<Object, Object> properties )
    055    //    {
    056    //    JobConf conf = new JobConf();
    057    //
    058    //    copyProperties( conf, properties );
    059    //
    060    //    return conf;
    061    //    }
    062
    063      /**
    064       * Method copyProperties adds the given Map values to the given JobConf object.
    065       *
    066       * @param configuration of type JobConf
    067       * @param properties    of type Map
    068       */
    069      public static void copyProperties( Configuration configuration, Map<Object, Object> properties )
    070        {
    071        if( properties instanceof Properties )
    072          {
    073          Properties props = (Properties) properties;
    074          Set<String> keys = props.stringPropertyNames();
    075
    076          for( String key : keys )
    077            configuration.set( key, props.getProperty( key ) );
    078          }
    079        else
    080          {
    081          for( Map.Entry<Object, Object> entry : properties.entrySet() )
    082            {
    083            if( entry.getValue() != null )
    084              configuration.set( entry.getKey().toString(), entry.getValue().toString() );
    085            }
    086          }
    087        }
    088      }