Coverage Report - org.apache.giraph.io.formats.multi.MultiEdgeInputFormat
 
Classes in this File Line Coverage Branch Coverage Complexity
MultiEdgeInputFormat
0%
0/29
0%
0/6
1.857
MultiEdgeInputFormat$1
0%
0/5
N/A
1.857
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.giraph.io.formats.multi;
 20  
 
 21  
 import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
 22  
 import org.apache.giraph.io.EdgeInputFormat;
 23  
 import org.apache.giraph.io.EdgeReader;
 24  
 import org.apache.giraph.io.internal.WrappedEdgeReader;
 25  
 import org.apache.hadoop.conf.Configuration;
 26  
 import org.apache.hadoop.io.Writable;
 27  
 import org.apache.hadoop.io.WritableComparable;
 28  
 import org.apache.hadoop.mapreduce.InputSplit;
 29  
 import org.apache.hadoop.mapreduce.JobContext;
 30  
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 31  
 
 32  
 import java.io.DataInput;
 33  
 import java.io.DataOutput;
 34  
 import java.io.IOException;
 35  
 import java.util.List;
 36  
 
 37  
 /**
 38  
  * Edge input format which wraps several edge input formats.
 39  
  * Provides the way to read data from multiple sources,
 40  
  * using several different input formats.
 41  
  *
 42  
  * @param <I> Vertex id
 43  
  * @param <E> Edge data
 44  
  */
 45  0
 public class MultiEdgeInputFormat<I extends WritableComparable,
 46  
     E extends Writable> extends EdgeInputFormat<I, E> {
 47  
   /** Edge input formats */
 48  
   private List<EdgeInputFormat<I, E>> edgeInputFormats;
 49  
 
 50  
   @Override public void checkInputSpecs(Configuration conf) {
 51  0
     for (EdgeInputFormat edgeInputFormat : edgeInputFormats) {
 52  0
       edgeInputFormat.checkInputSpecs(conf);
 53  0
     }
 54  0
   }
 55  
 
 56  
   @Override
 57  
   public void setConf(
 58  
       ImmutableClassesGiraphConfiguration<I, Writable, E> conf) {
 59  0
     super.setConf(conf);
 60  0
     edgeInputFormats =
 61  0
         EdgeInputFormatDescription.createEdgeInputFormats(getConf());
 62  0
     if (edgeInputFormats.isEmpty()) {
 63  0
       throw new IllegalStateException("setConf: Using MultiEdgeInputFormat " +
 64  
           "without specifying edge inputs");
 65  
     }
 66  0
   }
 67  
 
 68  
   @Override
 69  
   public EdgeReader<I, E> createEdgeReader(InputSplit inputSplit,
 70  
       TaskAttemptContext context) throws IOException {
 71  0
     if (inputSplit instanceof InputSplitWithInputFormatIndex) {
 72  
       // When multithreaded input is used we need to make sure other threads
 73  
       // don't change context's configuration while we use it
 74  0
       synchronized (context) {
 75  0
         InputSplitWithInputFormatIndex split =
 76  
             (InputSplitWithInputFormatIndex) inputSplit;
 77  0
         EdgeInputFormat<I, E> edgeInputFormat =
 78  0
             edgeInputFormats.get(split.getInputFormatIndex());
 79  0
         EdgeReader<I, E> edgeReader =
 80  0
             edgeInputFormat.createEdgeReader(split.getSplit(), context);
 81  0
         return new WrappedEdgeReader<I, E>(
 82  0
             edgeReader, edgeInputFormat.getConf()) {
 83  
           @Override
 84  
           public void initialize(InputSplit inputSplit,
 85  
               TaskAttemptContext context) throws IOException,
 86  
               InterruptedException {
 87  
             // When multithreaded input is used we need to make sure other
 88  
             // threads don't change context's configuration while we use it
 89  0
             synchronized (context) {
 90  0
               super.initialize(inputSplit, context);
 91  0
             }
 92  0
           }
 93  
         };
 94  0
       }
 95  
     } else {
 96  0
       throw new IllegalStateException("createEdgeReader: Got InputSplit which" +
 97  0
           " was not created by this class: " + inputSplit.getClass().getName());
 98  
     }
 99  
   }
 100  
 
 101  
   @Override
 102  
   public List<InputSplit> getSplits(JobContext context,
 103  
       int minSplitCountHint) throws IOException, InterruptedException {
 104  
     // When multithreaded input is used we need to make sure other threads don't
 105  
     // change context's configuration while we use it
 106  0
     synchronized (context) {
 107  0
       return MultiInputUtils.getSplits(
 108  
           context, minSplitCountHint, edgeInputFormats);
 109  0
     }
 110  
   }
 111  
 
 112  
   @Override
 113  
   public void writeInputSplit(InputSplit inputSplit,
 114  
       DataOutput dataOutput) throws IOException {
 115  0
     MultiInputUtils.writeInputSplit(inputSplit, dataOutput, edgeInputFormats);
 116  0
   }
 117  
 
 118  
   @Override
 119  
   public InputSplit readInputSplit(
 120  
       DataInput dataInput) throws IOException, ClassNotFoundException {
 121  0
     return MultiInputUtils.readInputSplit(dataInput, edgeInputFormats);
 122  
   }
 123  
 }