45. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 11/14/2017 6:57:20 AM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

45.1 Files compared

# Location File Last Modified
1 cbs.zip\cbs\cbs\src\main\java\gov\va\cpss\job CbssBaseJob.java Thu Nov 9 14:19:48 2017 UTC
2 cbs.zip\cbs\cbs\src\main\java\gov\va\cpss\job CbssBaseJob.java Tue Nov 14 12:25:55 2017 UTC

45.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 822
Changed 1 2
Inserted 0 0
Removed 0 0

45.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

45.4 Active regular expressions

No regular expressions were active.

45.5 Comparison detail

  1   package go v.va.cpss. job;
  2  
  3   import jav a.util.Lis t;
  4  
  5   import org .apache.lo g4j.Logger ;
  6   import org .quartz.Jo bExecution Context;
  7   import org .quartz.Jo bExecution Exception;
  8   import org .quartz.Sc heduler;
  9   import org .quartz.Sc hedulerExc eption;
  10   import org .springfra mework.bat ch.core.Ex itStatus;
  11   import org .springfra mework.bat ch.core.Jo bExecution ;
  12   import org .springfra mework.bat ch.core.Jo bParameter s;
  13   import org .springfra mework.bat ch.core.jo b.flow.Flo wJob;
  14   import org .springfra mework.bat ch.core.la unch.JobLa uncher;
  15   import org .springfra mework.bea ns.factory .annotatio n.Autowire d;
  16   import org .springfra mework.sch eduling.qu artz.Quart zJobBean;
  17  
  18   import gov .va.cpss.m odel.Batch Job;
  19   import gov .va.cpss.m odel.Batch Run;
  20   import gov .va.cpss.p erformance .Performan ceAnalyzer ;
  21   import gov .va.cpss.s ervice.Bat chService;
  22   import gov .va.cpss.s ervice.Ema ilService;
  23  
  24   /**
  25    * Base jo b class fo r CBSS qua rtz jobs.  All custom  jobs shou ld extend  this class
  26    * and imp lement the  runJob me thod.
  27    * 
  28    * @author   DN S      BROWNL
  29    */
  30   public abs tract clas s CbssBase Job extend s QuartzJo bBean {
  31  
  32           pr otected st atic final  Logger jo bLogger =  Logger.get Logger(Cbs sBaseJob.c lass.getCa nonicalNam e());
  33           
  34           pr ivate stat ic final i nt MAX_ERR OR_LENGTH  = 2048;
  35  
  36           /* *
  37            *  The batch  job name  that is po pulated fr om the dat abase at s cheduler
  38            *  initializ ation.
  39            * /
  40           pr otected St ring name;
  41  
  42           /* *
  43            *  The servi ce used to  manage ba tch issues .
  44            * /
  45           @A utowired
  46           pr otected Ba tchService  batchServ ice;
  47  
  48           /* *
  49            *  Spring Ba tch JobLau ncher for  starting F lowJobs
  50            * /
  51           @A utowired
  52           pr otected Jo bLauncher  jobLaunche r;
  53  
  54           /* *
  55            *  The servi ce used to  send emai l.
  56            * /
  57           @A utowired
  58           pr otected Em ailService  emailServ ice;
  59  
  60           /* *
  61            *  Report me mory usage .
  62            * /
  63           @A utowired
  64           pr otected Pe rformanceA nalyzer me moryAnalyz er;
  65  
  66           /*
  67            *  The infor mational p ortion of  the messag e for the  batch run.
  68            * /
  69           pr ivate Stri ng infoMes sage;
  70  
  71           /*
  72            *  The error  portion o f the mess age for th e batch ru n.
  73            * /
  74           pr ivate Stri ng errorMe ssage;
  75  
  76           pu blic Strin g getName( ) {
  77                    retu rn name;
  78           }
  79  
  80           pu blic void  setName(St ring name)  {
  81                    this .name = na me;
  82           }
  83  
  84           pu blic Strin g getInfoM essage() {
  85                    retu rn infoMes sage;
  86           }
  87  
  88           pu blic Strin g getError Message()  {
  89                    retu rn errorMe ssage;
  90           }
  91  
  92           pu blic void  resetMessa ges() {
  93                    info Message =  null;
  94                    erro rMessage =  null;
  95           }
  96  
  97           /* *
  98            *  The entry  point for  job execu tion.
  99            * /
  100           @O verride
  101           pr otected vo id execute Internal(J obExecutio nContext c tx) throws  JobExecut ionExcepti on {
  102  
  103                    // E nsure no o ther quart z job is r unning.
  104                    if ( notAlready Running(ct x)) {
  105  
  106                             // Rep ort Memory  Before Pr ocessing
  107                             memory Analyzer.r eport("at  " + name +  " Start") ;
  108  
  109                             // Res et the mes sage.
  110                             resetM essages();
  111  
  112                             // Get  the batch  job.
  113                             BatchJ ob bj = ba tchService .getBatchJ obByName(n ame);
  114  
  115                             // Sta rt a batch  run.
  116                             BatchR un bR = ba tchService .startRun( bj.getId() );
  117  
  118                             if (bR  != null)  {
  119  
  120                                      jobLogge r.info("Jo b " + name  + " Start ed: " + bR .getStartD ate());
  121  
  122                                      if (getJ ob() == nu ll) {
  123                                               jobLogger. error("Job  batch is  null");
  124                                               errorRun(b R);
  125                                      } else {
  126                                               try {
  127                                                       fi nal boolea n runSucce ss = runJo b(bR, getJ ob());
  128                                                       
  129                                                       if  (runSucce ss) {
  130                                                                comp leteRun(bR );
  131                                                       }  else {
  132                                                                erro rRun(bR);
  133                                                       }
  134                                               } catch (E xception e ) {
  135                                                       fi nal String  errorMess age = "Job  " + name  + " encoun tered an e rror: " +  e.getMessa ge();
  136                                                       jo bLogger.er ror(errorM essage, e) ;
  137                                                       ap pendErrorM essage(err orMessage) ;
  138                                                       er rorRun(bR) ;
  139                                               }
  140                                      }
  141  
  142                                      emailSer vice.cpssR eadyToSend Email(bj.g etEmail(),  buildEmai lSubject(b j), buildE mailMessag e(bj, bR)) ;
  143  
  144                             } else  {
  145                                      final St ring error Message =  "Problem S tarting Jo b " + name ;
  146                                      jobLogge r.error(er rorMessage );
  147                                      emailSer vice.cpssR eadyToSend Email(bj.g etEmail(),  buildEmai lSubject(b j), errorM essage);
  148                             }
  149  
  150                             // Rep ort Memory  After Pro cessing
  151                             memory Analyzer.r eport("at  " + name +  " End");
  152                    }
  153           }
  154  
  155           /* *
  156            *  Ensure th e quartz j ob is not  already ru nning.
  157            *  
  158            *  @param ct x
  159            *              The job  execution  context fo r the curr ent job.
  160            *  @return B oolean fla g indicati ng if the  job is not  already r unning.
  161            * /
  162           pr ivate bool ean notAlr eadyRunnin g(JobExecu tionContex t ctx) {
  163  
  164                    bool ean runnin g = false;
  165  
  166                    try  {
  167                             Schedu ler schedu ler = ctx. getSchedul er();
  168                             List<J obExecutio nContext>  jobs = sch eduler.get CurrentlyE xecutingJo bs();
  169                             for (J obExecutio nContext j ob : jobs)  {
  170                                      // We ar e only con cerned whe re the job  detail is  the same  as
  171                                      // this  job.
  172                                      if (job. getJobDeta il().equal s(ctx.getJ obDetail() )) {
  173                                               // If a di fferent tr igger then  it is obv iously a d uplicate
  174                                               // so do n ot allow t o run.
  175                                               // If it i s same tri gger but d ifferent f ire instan ce ID then
  176                                               // it is a lso a dupl icate so d o not allo w to run.
  177                                               if (!job.g etTrigger( ).equals(c tx.getTrig ger())) {
  178                                                       ru nning = tr ue;
  179                                                       jo bLogger.wa rn(
  180                                                                         "Attem pted to st art job bu t a differ ent contex t is alrea dy running  with a di fferent tr igger");
  181                                                       br eak;
  182                                               } else if  (!job.getF ireInstanc eId().equa ls(ctx.get FireInstan ceId())) {
  183                                                       ru nning = tr ue;
  184                                                       jo bLogger.wa rn(
  185                                                                         "Attem pted to st art job bu t a differ ent contex t is alrea dy running  with the  same trigg er");
  186                                                       br eak;
  187                                               }
  188                                      }
  189                             }
  190                    } ca tch (Sched ulerExcept ion e) {
  191                             // If  scheduler  has a prob lem then a ssume fata l error an d do not r un
  192                             // job .
  193                             jobLog ger.error( "Could not  check if  job alread y running:  " + e.get Message()) ;
  194                             runnin g = true;
  195                    }
  196  
  197                    retu rn !runnin g;
  198           }
  199  
  200           /* *
  201            *  Complete  and end a  successful  job run.
  202            *  
  203            *  @param bR
  204            *              The batc h run data base entry .
  205            * /
  206           pr otected vo id complet eRun(Batch Run bR) {
  207  
  208                    setM essage(bR) ;
  209  
  210                    if ( batchServi ce.complet eRun(bR))  {
  211                             jobLog ger.info(" Job " + na me + " End ed: " + bR .getEndDat e());
  212                    } el se {
  213                             jobLog ger.error( "Problem E nding Job  " + name);
  214                    }
  215           }
  216  
  217           /* *
  218            *  Error and  end a job  run.
  219            *  
  220            *  @param bR
  221            *              The batc h run data base entry .
  222            * /
  223           pr otected vo id errorRu n(BatchRun  bR) {
  224  
  225                    setM essage(bR) ;
  226  
  227                    if ( batchServi ce.errorRu n(bR)) {
  228                             jobLog ger.error( "Job " + n ame + " Co mpleted wi th Error:  " + bR.get EndDate()) ;
  229                    } el se {
  230                             jobLog ger.error( "Problem E nding Job  " + name +  " with Er ror");
  231                    }
  232           }
  233           
  234           /* *
  235            *  Get the b atch job a ssociated  with this  quartz job .
  236            *  @return T he associa ted job.
  237            * /
  238           pr otected ab stract Flo wJob getJo b();
  239  
  240           /* *
  241            *  Entry met hod to run  the batch  job. Subc lasses sho uld implem ent this
  242            *  method wi th custom  business l ogic.
  243            *  
  244            *  @param jo b
  245            *              The batc h job to r un.
  246            *  @param bR
  247            *              The batc h run for  this job.
  248            *  @return B oolean val ue that in dicates if  the batch  job ran s uccessfull y or
  249            *          n ot.
  250            * /
  251           pr otected ab stract boo lean runJo b(BatchRun  bR, FlowJ ob job);
  252  
  253           /* *
  254            *  Execute t he specifi ed batch j ob using t he specifi ed paramet ers.
  255            *  
  256            *  @param jo b
  257            *              The batc h job.
  258            *  @param pa rameters
  259            *              The para meters to  use for jo b executio n.
  260            *  @return B oolean val ue indicat ing succes s or failu re of the  job run.
  261            * /
  262           pr otected Jo bExecution  executeJo b(FlowJob  job, JobPa rameters p arameters)  {
  263  
  264                    JobE xecution e xecution =  null;
  265  
  266                    try  {
  267  
  268                             execut ion = jobL auncher.ru n(job, par ameters);
  269  
  270                             if (!e xecution.g etExitStat us().equal s(ExitStat us.COMPLET ED)) {
  271                                      if (!exe cution.get ExitStatus ().getExit Descriptio n().isEmpt y()) {
  272                                               appendErro rMessage(e xecution.g etExitStat us().getEx itDescript ion());
  273                                      } else {
  274                                               appendErro rMessage(e xecution.g etExitStat us().getEx itCode().t oString()) ;
  275                                      }
  276                             }
  277  
  278                    } ca tch (Excep tion e) {
  279  
  280                             logExe cuteJobExc eption("Ca ught excep tion durin g job exec ution: " +  e.getMess age());
  281  
  282                             if (ex ecution ==  null) {
  283                                      appendEr rorMessage ("Job ende d with nul l executio n");
  284                             }
  285                    }
  286  
  287                    retu rn executi on;
  288           }
  289  
  290           /* *
  291            *  Append th e informat ional mess age. This  allows cap ture of mu ltiple
  292            *  informati onal messa ges over t he course  of multipl e job runs .
  293            * /
  294           pr otected vo id appendI nfoMessage (final Str ing messag e) {
  295                    Stri ngBuilder  infoBuilde r = new St ringBuilde r();
  296                    if ( (infoMessa ge != null ) && !info Message.is Empty()) {
  297                             infoBu ilder.appe nd(infoMes sage);
  298                             infoBu ilder.appe nd("\n");
  299                    }
  300                    info Builder.ap pend(messa ge);
  301                    info Message =  infoBuilde r.toString ();
  302           }
  303  
  304           /* *
  305            *  Append th e error me ssage. Thi s allows c apture of  multiple e rrors over  the
  306            *  course of  multiple  job runs.
  307            * /
  308           pr otected vo id appendE rrorMessag e(final St ring messa ge) {
  309                    Stri ngBuilder  errorBuild er = new S tringBuild er();
  310                    if ( (errorMess age != nul l) && !err orMessage. isEmpty())  {
  311                             errorB uilder.app end(errorM essage);
  312                             errorB uilder.app end("\n");
  313                    } el se {
  314                             errorB uilder.app end("\n\nE rror Messa ge:\n");
  315                    }
  316                    erro rBuilder.a ppend(mess age);
  317                    erro rMessage =  errorBuil der.toStri ng();
  318           }
  319  
  320           /* *
  321            *  Log excep tion in ex ecuteJob.  Moved to s eparate me thod so su bclasses c an
  322            *  override.
  323            * /
  324           pr otected vo id logExec uteJobExce ption(fina l String m essage) {
  325                    jobL ogger.erro r(message) ;
  326           }
  327  
  328           /* *
  329            *  Set the b atch run m essage to  save in th e database .
  330            * /
  331           pr ivate void  setMessag e(BatchRun  bR) {
  332                    Stri ngBuilder  messageBui lder = new  StringBui lder();
  333  
  334                    if ( (infoMessa ge != null ) && !info Message.is Empty()) {
  335                             messag eBuilder.a ppend(info Message);
  336                    }
  337  
  338                    if ( (errorMess age != nul l) && !err orMessage. isEmpty())  {
  339                             messag eBuilder.a ppend(erro rMessage);
  340                    }
  341  
  342                    Stri ng runMess age = mess ageBuilder .toString( );
  343  
  344                    if ( runMessage .length()  > MAX_ERRO R_LENGTH)  {
  345                             jobLog ger.warn(" Error mess age will b e truncate d in the d atabase");
  346                    }
  347  
  348                    // I f necessar y, truncat e error me ssage to m ax size al lowed by t able.
  349                    bR.s etMessage( runMessage .substring (0, Math.m in(MAX_ERR OR_LENGTH,  runMessag e.length() )));
  350           }
  351  
  352           /* *
  353            *  Build an  email subj ect.
  354            *  
  355            *  @return
  356            * /
  357           pr otected St ring build EmailSubje ct(BatchJo b batchJob ) {
  358                    retu rn batchJo b.getDescr iption();
  359           }
  360  
  361           /* *
  362            *  Build an  email mess age that c ommunicate s informat ion based  on the
  363            *  specific  type of jo b.
  364            * /
  365           pr otected St ring build EmailMessa ge(BatchJo b batchJob , BatchRun  batchRun)  {
  366                    Stri ngBuffer s trBuff = b uildEmailC ommonInfo( batchJob,  batchRun);
  367                    strB uff.append (buildEmai lCustomInf o());
  368                    strB uff.append (buildEmai lErrorInfo ());
  369                    retu rn strBuff .toString( );
  370           }
  371  
  372           /* *
  373            *  Build the  first por tion of an  email wit h informat ion that e very job h as
  374            *  in common .
  375            * /
  376           pr otected St ringBuffer  buildEmai lCommonInf o(BatchJob  batchJob,  BatchRun  batchRun)  {
  377                    Stri ngBuffer s trBuff = n ew StringB uffer();
  378                    strB uff.append ("\nBatch  Process Na me: ");
  379                    strB uff.append (batchJob. getDescrip tion()); / / Read the  Job class  running
  380                    strB uff.append ("\nStart:  ");
  381                    strB uff.append (batchRun. getServerS tartDateSt ring()); / / Read the  start
  382                                                                                                                                               //  date
  383                    strB uff.append ("\nEnd: " );
  384                    strB uff.append (batchRun. getServerE ndDateStri ng()); //  Read the e nd date
  385                    strB uff.append ("\nStatus : ");
  386                    strB uff.append (batchRun. getBatchSt atus().get Descriptio n()); // R ead the
  387                                                                                                                                                        // s tatus
  388                                                                                                                                                        // d escription
  389                    retu rn strBuff ;
  390           }
  391  
  392           /* *
  393            *  Build the  error por tion of an  email.
  394            * /
  395           pr otected St ring build EmailError Info() {
  396                    if ( (errorMess age != nul l) && !err orMessage. isEmpty())  {
  397                             return  errorMess age;
  398                    }
  399                    retu rn "";
  400           }
  401  
  402           /* *
  403            *  Build the  second po rtion of a n email th at contain s informat ion specif ic
  404            *  to the de rived job  class.
  405            * /
  406           pr otected St ring build EmailCusto mInfo() {
  407                    if ( (infoMessa ge != null ) && !info Message.is Empty()) {
  408                             return  infoMessa ge;
  409                    }
  410                    retu rn "";
  411           }
  412   }