Coverage Report - org.galagosearch.tupleflow.execution.StageInstanceDescription
 
Classes in this File Line Coverage Branch Coverage Complexity
StageInstanceDescription
0%
0/20
0%
0/12
0
StageInstanceDescription$PipeInput
0%
0/6
N/A
0
StageInstanceDescription$PipeOutput
0%
0/20
0%
0/4
0
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 2  
 
 3  
 package org.galagosearch.tupleflow.execution;
 4  
 
 5  
 import java.io.File;
 6  
 import java.io.Serializable;
 7  
 import java.util.ArrayList;
 8  
 import java.util.Arrays;
 9  
 import java.util.Map;
 10  
 
 11  
 /**
 12  
  *
 13  
  * @author trevor
 14  
  */
 15  
 public class StageInstanceDescription implements Serializable {
 16  
 
 17  
     /// A stage object (probably genereated by the JobConstructor parser)
 18  
     Stage stage;
 19  
     /// The index of this job (between 0 and n-1 if there are n instances)
 20  
     int index;
 21  
 
 22  
     /// A map from stage input names to data pipe structures (note that the input to a pipe connects to a stage output)
 23  
     private Map<String, PipeOutput> readers;
 24  
     private /// A map from stage input names to data pipe structures (note that the input to a pipe connects to a stage output)
 25  
     Map<String, PipeInput> writers;
 26  
 
 27  
     /// The URL of the Master server for this job.
 28  
     String masterURL;
 29  
 
 30  
     public StageInstanceDescription(
 31  
             Stage stage, int index,
 32  
             Map<String, PipeInput> pipeInputs,
 33  
             Map<String, PipeOutput> pipeOutputs,
 34  0
             String masterURL) {
 35  0
         this.stage = stage;
 36  0
         this.index = index;
 37  0
         this.writers = pipeInputs;
 38  0
         this.readers = pipeOutputs;
 39  0
         this.masterURL = masterURL;
 40  0
     }
 41  
 
 42  
     /**
 43  
      * @return the readers
 44  
      */
 45  
     public Map<String, PipeOutput> getReaders() {
 46  0
         return readers;
 47  
     }
 48  
 
 49  
     /**
 50  
      * @return the writers
 51  
      */
 52  
     public Map<String, PipeInput> getWriters() {
 53  0
         return writers;
 54  
     }
 55  
 
 56  
     public static class PipeInput implements Serializable {
 57  
         private int index;
 58  
         private DataPipe pipe;
 59  
 
 60  0
         public PipeInput(DataPipe pipe, int index) {
 61  0
             this.index = index;
 62  0
             this.pipe = pipe;
 63  0
         }
 64  
 
 65  
         public String[] getFileNames() {
 66  0
             return pipe.getInputFileNames(index);
 67  
         }
 68  
 
 69  
         public DataPipe getPipe() {
 70  0
             return pipe;
 71  
         }
 72  
     }
 73  
 
 74  
     public static class PipeOutput implements Serializable {
 75  
         private int start;
 76  
         private int stop;
 77  
         private DataPipe pipe;
 78  
 
 79  
         public PipeOutput(DataPipe pipe, int index) {
 80  0
             this(pipe, index, index + 1);
 81  0
         }
 82  
 
 83  0
         public PipeOutput(DataPipe pipe, int start, int stop) {
 84  0
             this.start = start;
 85  0
             this.stop = stop;
 86  0
             this.pipe = pipe;
 87  0
         }
 88  
 
 89  
         public String[] getFileNames() {
 90  0
             ArrayList<String[]> allFilenames = new ArrayList();
 91  0
             int totalNames = 0;
 92  
 
 93  0
             for (int i = start; i < stop; i++) {
 94  0
                 String[] batch = pipe.getOutputFileNames(i);
 95  0
                 totalNames += batch.length;
 96  0
                 allFilenames.add(batch);
 97  
             }
 98  
 
 99  0
             String[] result = new String[totalNames];
 100  0
             int spot = 0;
 101  
 
 102  0
             for (String[] batch : allFilenames) {
 103  0
                 System.arraycopy(batch, 0, result, spot, batch.length);
 104  0
                 spot += batch.length;
 105  
             }
 106  
 
 107  0
             return result;
 108  
         }
 109  
 
 110  
         public DataPipe getPipe() {
 111  0
             return pipe;
 112  
         }
 113  
     }
 114  
 
 115  
     public String getName() {
 116  0
         return stage.name;
 117  
     }
 118  
 
 119  
     public int getIndex() {
 120  0
         return index;
 121  
     }
 122  
 
 123  
     public String getPath() {
 124  0
         return getName() + File.separator + getIndex();
 125  
     }
 126  
 
 127  
     public String getMasterURL() {
 128  0
         return masterURL;
 129  
     }
 130  
 
 131  
     public boolean writerExists(String specification, String className, String[] order) {
 132  0
         PipeInput input = getWriters().get(specification);
 133  0
         if (input == null) return false;
 134  0
         return input.getPipe().getClassName().equals(className) &&
 135  
                Arrays.equals(input.getPipe().getOrder(), order);
 136  
     }
 137  
 
 138  
     public boolean readerExists(String specification, String className, String[] order) {
 139  0
         PipeOutput output = getReaders().get(specification);
 140  0
         if (output == null) return false;
 141  0
         return output.getPipe().getClassName().equals(className) &&
 142  
                Arrays.equals(output.getPipe().getOrder(), order);
 143  
     }
 144  
 
 145  
     public Stage getStage() {
 146  0
         return stage;
 147  
     }
 148  
 }