Coverage Report - org.galagosearch.tupleflow.execution.StageGroupDescription
 
Classes in this File Line Coverage Branch Coverage Complexity
StageGroupDescription
0%
0/42
0%
0/22
0
StageGroupDescription$DataPipeRegion
0%
0/11
0%
0/2
0
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 2  
 
 3  
 package org.galagosearch.tupleflow.execution;
 4  
 
 5  
 import java.util.ArrayList;
 6  
 import java.util.HashMap;
 7  
 import java.util.List;
 8  
 import java.util.Map;
 9  
 import org.galagosearch.tupleflow.execution.StageInstanceDescription.PipeInput;
 10  
 import org.galagosearch.tupleflow.execution.StageInstanceDescription.PipeOutput;
 11  
 
 12  
 /**
 13  
  *
 14  
  * @author trevor
 15  
  */
 16  0
 public class StageGroupDescription {
 17  
     /// A stage object (probably genereated by the JobConstructor parser)
 18  
     Stage stage;
 19  
     
 20  
     public HashMap<String, DataPipeRegion> inputs;
 21  
     public HashMap<String, DataPipeRegion> outputs;
 22  
     
 23  
     /// Count of instances of this stage
 24  
     public int instanceCount;
 25  
 
 26  
     /// URL of the Master for this job.
 27  
     String masterURL;
 28  
     
 29  
     public static class DataPipeRegion {
 30  
         DataPipe pipe;
 31  
         int start;
 32  
         int end;
 33  
         ConnectionPointType direction;
 34  
         
 35  0
         public DataPipeRegion(DataPipe pipe, int start, int end, ConnectionPointType direction) {
 36  0
             this.pipe = pipe;
 37  0
             this.start = start;
 38  0
             this.end = end;
 39  0
             this.direction = direction;
 40  0
         }
 41  
         
 42  
         public int fileCount() {
 43  0
             int count = 0;
 44  
             
 45  0
             for(int i=start; i<end; i++) {
 46  0
                 String[] filenames = pipe.getOutputFileNames(i);
 47  0
                 count += filenames.length;
 48  
             }
 49  
             
 50  0
             return count;
 51  
         }
 52  
     }
 53  
     
 54  
     public StageGroupDescription(Stage stage) {
 55  0
         this(stage, 1, "");
 56  0
     }
 57  
     
 58  
     /** Creates a new instance of StageGroupDescription */
 59  0
     public StageGroupDescription(Stage stage, int instanceCount, String masterURL) {
 60  0
         this.stage = stage;
 61  0
         this.inputs = new HashMap<String, DataPipeRegion>();
 62  0
         this.outputs = new HashMap<String, DataPipeRegion>();
 63  0
         this.instanceCount = instanceCount;
 64  0
         this.masterURL = masterURL;
 65  0
     }
 66  
     
 67  
     public String getName() {
 68  0
         return stage.name;
 69  
     }
 70  
 
 71  
     public String getMasterURL() {
 72  0
         return masterURL;
 73  
     }
 74  
 
 75  
     public void setMasterURL(String masterURL) {
 76  0
         this.masterURL = masterURL;
 77  0
     }
 78  
 
 79  
     public boolean containsInput(String name) {
 80  0
         return inputs.containsKey(name);
 81  
     }
 82  
     
 83  
     public boolean containsOutput(String name) {
 84  0
         return outputs.containsKey(name);
 85  
     }
 86  
 
 87  
     public Stage getStage() {
 88  0
         return stage;
 89  
     }
 90  
 
 91  
     public int getInstanceCount() {
 92  0
         return instanceCount;
 93  
     }
 94  
 
 95  
     @Override
 96  
     public String toString() {
 97  0
         return stage.toString();
 98  
     }
 99  
 
 100  
 
 101  
     public List<StageInstanceDescription> getInstances() {
 102  0
         ArrayList<StageInstanceDescription> instances = new ArrayList();
 103  
         
 104  0
         for(int i=0; i<instanceCount; i++) {
 105  0
             Map<String, PipeInput> instanceOutputs = new HashMap<String, PipeInput>();
 106  
             
 107  0
             for(String key : outputs.keySet()) {
 108  0
                 DataPipeRegion region = outputs.get(key);
 109  
                 
 110  0
                 if(region.end - region.start <= 1) {
 111  0
                     instanceOutputs.put(key, new PipeInput(region.pipe, 0));
 112  
                 } else {
 113  0
                     assert region.end - region.start == instanceCount;
 114  0
                     instanceOutputs.put(key, new PipeInput(region.pipe, region.start + i));
 115  
                 }
 116  0
             }
 117  
             
 118  0
             Map<String, PipeOutput> instanceInputs = new HashMap<String, PipeOutput>();
 119  
 
 120  0
             for(String key : inputs.keySet()) {
 121  0
                 DataPipeRegion region = inputs.get(key);
 122  
                 
 123  0
                 if(region.end - region.start <= 1) {
 124  0
                     instanceInputs.put(key, new PipeOutput(region.pipe, 0));
 125  0
                 } else if(instanceCount == 1 && region.end - region.start > 1) {
 126  
                     // assignment == "combined"
 127  0
                     instanceInputs.put(key, new PipeOutput(region.pipe, region.start, region.end));
 128  
                 } else {
 129  0
                     assert region.end - region.start == instanceCount;
 130  0
                     instanceInputs.put(key, new PipeOutput(region.pipe, region.start + i));
 131  
                 }
 132  0
             }
 133  
 
 134  0
             StageInstanceDescription instance =
 135  
                     new StageInstanceDescription(
 136  
                             stage, i, instanceOutputs, instanceInputs, masterURL);
 137  0
             instances.add(instance);
 138  
         }
 139  
         
 140  0
         return instances;
 141  
     }
 142  
 }