Advertisement
Guest User

Untitled

a guest
May 9th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import org.apache.crunch.MapFn;
  2. import org.apache.crunch.PCollection;
  3. import org.apache.crunch.Pipeline;
  4. import org.apache.crunch.PipelineExecution;
  5. import org.apache.crunch.impl.mr.MRPipeline;
  6. import org.apache.crunch.types.writable.Writables;
  7.  
  8. public class FailTest {
  9.  
  10.   public static void main(String[] args) {
  11.     Pipeline pipeline = new MRPipeline(FailTest.class);
  12.     PCollection<String> p = pipeline.readTextFile("/user/jgauci/inputs");
  13.     PCollection<Integer> result = p.parallelDo(new MapFn<String, Integer>() {
  14.  
  15.       @Override
  16.       public Integer map(String input) {
  17.         int c = 0;
  18.         return 1 / c;
  19.       }
  20.     }, Writables.ints());
  21.  
  22.     Iterable<Integer> localResult = result.materialize();
  23.  
  24.     PipelineExecution execution = pipeline.runAsync();
  25.  
  26.     while (!execution.isDone() && !execution.isCancelled()
  27.         && execution.getStatus() != PipelineExecution.Status.FAILED
  28.         && execution.getResult() == null) {
  29.       try {
  30.         Thread.sleep(1000);
  31.         System.out.println("Job Status: " + execution.getStatus().toString());
  32.       } catch (InterruptedException e) {
  33.         System.err.println("ABORTING");
  34.         e.printStackTrace();
  35.         try {
  36.           execution.kill();
  37.           execution.waitUntilDone();
  38.         } catch (InterruptedException e1) {
  39.           throw new RuntimeException(e1);
  40.         }
  41.         throw new RuntimeException(e);
  42.       }
  43.     }
  44.     System.out.println("Finished running job.");
  45.     if (execution.isCancelled()) {
  46.       throw new RuntimeException("Job failed");
  47.     }
  48.  
  49.     for (Integer d : localResult) {
  50.       System.out.println(d);
  51.     }
  52.   }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement