Ejemplo n.º 1
0
 private StageResult executeMasterStage(MasterStage stage) {
   stage.init(state);
   if (log.isDebugEnabled())
     log.debug("Starting master stage " + stage.getName() + ". Details:" + stage);
   else log.info("Starting master stage " + stage.getName() + ".");
   long start = System.currentTimeMillis(), end = start;
   try {
     StageResult result = stage.execute();
     end = System.currentTimeMillis();
     if (result.isError()) {
       log.error("Execution of master stage " + stage.getName() + " failed.");
     } else {
       log.info("Finished master stage " + stage.getName());
     }
     return result;
   } catch (Exception e) {
     end = System.currentTimeMillis();
     log.error("Caught exception", e);
     return StageResult.FAIL;
   } finally {
     state
         .getTimeline()
         .addEvent(Stage.STAGE, new Timeline.IntervalEvent(start, stage.getName(), end - start));
   }
 }
Ejemplo n.º 2
0
 private StageResult executeDistStage(int stageId, DistStage stage) {
   if (log.isDebugEnabled())
     log.debug("Starting distributed stage " + stage.getName() + ". Details:" + stage);
   else log.info("Starting distributed stage " + stage.getName() + ".");
   int numSlaves = state.getClusterSize();
   Map<String, Object> masterData;
   try {
     stage.initOnMaster(state);
     masterData = stage.createMasterData();
   } catch (Exception e) {
     log.error("Failed to initialize stage", e);
     return StageResult.EXIT;
   }
   List<DistStageAck> responses = null;
   try {
     responses = connection.runStage(stageId, masterData, numSlaves);
   } catch (IOException e) {
     log.error("Error when communicating to slaves");
     return StageResult.EXIT;
   }
   if (responses.size() > 1) {
     Collections.sort(
         responses,
         new Comparator<DistStageAck>() {
           @Override
           public int compare(DistStageAck o1, DistStageAck o2) {
             int thisVal = o1.getSlaveIndex();
             int anotherVal = o2.getSlaveIndex();
             return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
           }
         });
   }
   StageResult result;
   try {
     result = stage.processAckOnMaster(responses);
   } catch (Exception e) {
     log.error("Processing acks on master failed", e);
     return StageResult.EXIT;
   }
   if (result.isError()) {
     log.error("Execution of distribute stage " + stage.getName() + " failed.");
   } else {
     log.info("Finished distributed stage " + stage.getName() + ".");
   }
   return result;
 }