29. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/2/2017 7:00:17 AM Central Daylight 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.

29.1 Files compared

# Location File Last Modified
1 cds.zip\cds\product\production\cdsinvocation\cds-metrics-collection-service\src\main\java\com\cognitive\cds\services\jmx JMXPollingService.java Wed Jul 12 18:43:52 2017 UTC
2 cds.zip\cds\product\production\cdsinvocation\cds-metrics-collection-service\src\main\java\com\cognitive\cds\services\jmx JMXPollingService.java Thu Sep 28 16:20:21 2017 UTC

29.2 Comparison summary

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

29.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

29.4 Active regular expressions

No regular expressions were active.

29.5 Comparison detail

  1   /*
  2    * COPYRIG HT STATUS:  © 2015, 2 016.  This  work, aut hored by C ognitive M edical Sys tems
  3    * employe es, was fu nded in wh ole or in  part by Th e Departme nt of Vete rans
  4    * Affairs  under U.S . Governme nt contrac t VA118-11 -D-1011 /  VA118-1011 -0013.
  5    * The cop yright hol der agrees  to post o r allow th e Governme nt to post  all or
  6    * part of  this work  in open-s ource repo sitories s ubject to  the Apache  License,
  7    * Version  2.0, date d January  2004. All  other righ ts are res erved by t he
  8    * copyrig ht owner.
  9    *
  10    * For use  outside t he Governm ent, the f ollowing n otice appl ies:
  11    *
  12    *     Cop yright 201 5 © Cognit ive Medica l Systems
  13    *
  14    *     Lic ensed unde r the Apac he License , Version  2.0 (the " License");  you may
  15    *     not  use this  file excep t in compl iance with  the Licen se. You ma y obtain
  16    *     a c opy of the  License a t http://w ww.apache. org/licens es/LICENSE -2.0
  17    *
  18    *     Unl ess requir ed by appl icable law  or agreed  to in wri ting, soft ware
  19    *     dis tributed u nder the L icense is  distribute d on an "A S IS" BASI S,
  20    *     WIT HOUT WARRA NTIES OR C ONDITIONS  OF ANY KIN D, either  express or  implied.
  21    *     See  the Licen se for the  specific  language g overning p ermissions  and
  22    *     lim itations u nder the L icense.
  23    *
  24    */
  25   package co m.cognitiv e.cds.serv ices.jmx;
  26  
  27   import jav a.io.IOExc eption;
  28   import jav a.sql.Time stamp;
  29   import jav a.util.Arr ayList;
  30   import jav a.util.Dat e;
  31   import jav a.util.Has hMap;
  32   import jav a.util.Ite rator;
  33   import jav a.util.Set ;
  34   import jav a.util.con current.Co ncurrentHa shMap;
  35   import jav a.util.con current.Sc heduledFut ure;
  36  
  37   import jav ax.annotat ion.PostCo nstruct;
  38   import jav ax.annotat ion.PreDes troy;
  39   import jav ax.managem ent.MBeanS erverConne ction;
  40   import jav ax.managem ent.Object Name;
  41   import jav ax.managem ent.remote .JMXConnec tor;
  42   import jav ax.managem ent.remote .JMXConnec torFactory ;
  43   import jav ax.managem ent.remote .JMXServic eURL;
  44  
  45   import org .bson.Docu ment;
  46   import org .slf4j.Log ger;
  47   import org .slf4j.Log gerFactory ;
  48   import org .springfra mework.bea ns.factory .annotatio n.Autowire d;
  49   import org .springfra mework.sch eduling.Ta skSchedule r;
  50   import org .springfra mework.ste reotype.Co mponent;
  51  
  52   import com .cognitive .cds.invoc ation.mode l.EngineIn stanceStat e;
  53   import com .cognitive .cds.invoc ation.mong o.EngineIn foDao;
  54   import com .cognitive .cds.invoc ation.mong o.MongoDbD ao;
  55   import com .cognitive .cds.servi ces.metric s.model.Ob servation;
  56   import com .fasterxml .jackson.c ore.JsonGe nerationEx ception;
  57   import com .fasterxml .jackson.d atabind.Js onMappingE xception;
  58   import com .fasterxml .jackson.d atabind.Ob jectMapper ;
  59   import com .mongodb.c lient.Mong oDatabase;
  60  
  61   /**
  62    * Basic J MX Polling  Service t o pull met ric data o n an inter val from a nother
  63    * system.
  64    * 
  65    * @author  jfox
  66    */
  67   @Component
  68   public cla ss JMXPoll ingService  {
  69           
  70       privat e static f inal Logge r LOGGER =  LoggerFac tory.getLo gger(JMXPo llingServi ce.class);
  71       
  72           @A utowired
  73           pr ivate Task Scheduler  taskSchedu ler;
  74       
  75       //The  only engin e type we' re current ly working  with is O penCDS.
  76       privat e static f inal Strin g ENGINE_T YPE = "Ope nCDS";
  77           
  78           pr ivate int  port =  PORT ;
  79           pr ivate long  period =  60000; //  1 minute i n ms
  80           pr ivate Mong oDbDao mon goDbDao;
  81           pr ivate Engi neInfoDao  engineInfo Dao;
  82           
  83           pr ivate bool ean dynami cRegistryE nabled = t rue;
  84           // mapping th e dynamica lly config ured engin es by name  to their  scheduled  future obj ects
  85           pr ivate Conc urrentHash Map<String , Schedule dFuture<?> > engineMa p = new Co ncurrentHa shMap<Stri ng, Schedu ledFuture< ?>>();
  86           
  87           pr ivate  Arr ayList<Eng ineInstanc eState> ha rdwiredEng ines = new  ArrayList <EngineIns tanceState >();
  88           
  89           pu blic Mongo DbDao getM ongoDbDao( ) {
  90                    retu rn mongoDb Dao;
  91           }
  92  
  93           pu blic void  setMongoDb Dao(MongoD bDao mongo DbDao) {
  94                    this .mongoDbDa o = mongoD bDao;
  95           }
  96           
  97           pu blic Engin eInfoDao g etEngineIn foDao() {
  98                    retu rn engineI nfoDao;
  99           }
  100  
  101           pu blic void  setEngineI nfoDao(Eng ineInfoDao  engineInf oDao) {
  102                    this .engineInf oDao = eng ineInfoDao ;
  103           }
  104           
  105           pu blic void  setPort(in t port) {
  106                    this .port = po rt;
  107           }
  108           
  109           pu blic void  setDynamic RegistryEn abled(bool ean dynami cRegistryE nabled) {
  110                    this .dynamicRe gistryEnab led = dyna micRegistr yEnabled;
  111           }
  112           
  113           pu blic void  setEngines (ArrayList <EngineIns tanceState > hardwire dEngines)  {
  114                    this .hardwired Engines =  hardwiredE ngines;
  115           }
  116           
  117           pu blic void  setPeriod( int period ) {
  118                    this .period =  period;
  119           }
  120           
  121           @P ostConstru ct
  122           pu blic void  init() thr ows Except ion {
  123                    
  124                    LOGG ER.info("J MXPollingS ervice.ini t()");
  125                    
  126                    //fi rst, init  any manual ly configu red poller s (if ther e are any)
  127                    if(h ardwiredEn gines.size () > 0) {
  128                             for (E ngineInsta nceState e is : hardw iredEngine s) {
  129                                      LOGGER.i nfo("addin g poller f or engine:  " + eis.g etName()); ;
  130                                      //not tr acking the  Scheduled Future for  these as  we would n eed a rest art to rem ove them a nyways.
  131                                      taskSche duler.sche duleWithFi xedDelay(n ew JMXPoll er(eis.get Host(), ei s.getName( )), period );
  132                             }
  133                    }
  134                    
  135                    Arra yList<Engi neInstance State> ins tances = n ew ArrayLi st<EngineI nstanceSta te>();
  136                    if(d ynamicRegi stryEnable d) {
  137                             instan ces.addAll (engineInf oDao.getAc tiveEngine s(ENGINE_T YPE));
  138                             LOGGER .info("dyn amically c onfigured  instances  to be poll ed: " + in stances.si ze());
  139                             
  140                             //begi n new engi ne check p rocess
  141                             taskSc heduler.sc heduleAtFi xedRate(ne w Runnable () {
  142                                 @O verride
  143                                 pu blic void  run() {
  144                                      updateEn gineList() ;
  145                                 }
  146                             }, new  Date(Syst em.current TimeMillis () + perio d), period );
  147                             //end  new engine  check
  148                             
  149                    } el se {
  150                             LOGGER .info("dyn amic engin e registry  polling i s disabled ");
  151                    }
  152                    
  153                    for  (EngineIns tanceState  eis : ins tances) {
  154                             LOGGER .info("Add ing Poller  for engin e name: "  + eis.getN ame() + "  at " + eis .getHost()  + ":" + e is.getPort ());
  155                             Schedu ledFuture< ?> sf = ta skSchedule r.schedule WithFixedD elay(new J MXPoller(e is.getHost (), eis.ge tName()),  period);
  156                             engine Map.put(ei s.getName( ), sf);
  157                    }
  158  
  159                    if(i nstances.s ize() == 0 ) {
  160                             LOGGER .info("No  configured  engine in stances we re found f or JMX Pol ler.");
  161                    }
  162           }
  163           
  164           /* *
  165            *  FUTURE:
  166            *  This is q uick, but  inelegant  way to che ck for new  engine in stances.   This
  167            *  should be  revisited  and proba bly put in to a centr alized pla ce in the  future.
  168            * /
  169           pu blic void  updateEngi neList() {
  170                    
  171                    LOGG ER.info("C hecking fo r new engi ne instanc es.");
  172                    Arra yList<Engi neInstance State> upd atedInstan ces = engi neInfoDao. getActiveE ngines(ENG INE_TYPE);
  173                    //ne xt, lets m ap these b y name to  make it ea sier to wo rk with be low...
  174                    Hash Map<String , EngineIn stanceStat e> updated EngineMap  = new Hash Map<String , EngineIn stanceStat e>();              
  175                    for  (EngineIns tanceState  updatedIn stance : u pdatedInst ances) {
  176                             update dEngineMap .put(updat edInstance .getName() , updatedI nstance);
  177                    }
  178                    
  179                    for  (String ke y : engine Map.keySet ()) {
  180                             if(upd atedEngine Map.contai nsKey(key) ) {
  181                                      //we hav e one for  this engin e already  here...rem ove it fro m the list  so we can  see what' s left.
  182                                      updatedE ngineMap.r emove(key) ;
  183                             } else  {
  184                                      //it's n ot on the  list anymo re.  Stop  the poller  and remov e the entr y.
  185                                      LOGGER.i nfo("remov ing poller  for engin e: " + key );
  186                                      engineMa p.get(key) .cancel(tr ue); //tru e means 'i nterrupt i f running' .
  187                                      engineMa p.remove(k ey);
  188                             }
  189                    }
  190                    //ad d any that  we were m issing.
  191                    for  (String ke y : update dEngineMap .keySet())  {
  192                             LOGGER .info("add ing poller  for: " +  key);
  193                             
  194                             Schedu ledFuture< ?> sf = ta skSchedule r.schedule WithFixedD elay(new J MXPoller(u pdatedEngi neMap.get( key).getHo st(), upda tedEngineM ap.get(key ).getName( )), period );
  195                             engine Map.put(ke y, sf);
  196                    }
  197  
  198           }
  199           
  200           @P reDestroy
  201           pu blic void  cleanUp()  throws Exc eption {
  202                    LOGG ER.info("J MXPollingS ervice.cle anUp()");
  203           }
  204           
  205           pr ivate clas s JMXPolle r implemen ts Runnabl e {
  206  
  207                    priv ate JMXCon nector jmx Connector;
  208                    priv ate JMXSer viceURL se rviceUrl;
  209                    priv ate MBeanS erverConne ction mbea nServerCon n;
  210                    
  211                    priv ate String  host;
  212                    priv ate String  origin;
  213                    
  214                    publ ic JMXPoll er(String  host, Stri ng origin)  {
  215                             this.h ost = host ;
  216                             this.o rigin = or igin;
  217                    }
  218                                 
  219                    @Ove rride
  220                public v oid run()  {
  221                    
  222                    try  {
  223                                      serviceU rl = new J MXServiceU RL("servic e:jmx:rmi: ///jndi/rm i://" + ho st + ":" +  port + "/ jmxrmi");
  224                                      jmxConne ctor = JMX ConnectorF actory.con nect(servi ceUrl, nul l);
  225                                      mbeanSer verConn =  jmxConnect or.getMBea nServerCon nection();
  226                                      
  227                                      Set<Obje ctName> ob jectName =  mbeanServ erConn.que ryNames(ne w ObjectNa me("org.dr ools.kbase s:*"),null  );
  228  
  229                                      Long ses sionCount  = 0L;
  230                                 It erator<Obj ectName> i terator =  objectName .iterator( );
  231                                 if (iterator. hasNext())  {
  232                                      ObjectNa me setElem ent = iter ator.next( );
  233                                      sessionC ount = (Lo ng)mbeanSe rverConn.g etAttribut e(setEleme nt, "Sessi onCount");
  234                                      LOGGER.d ebug("Sess ionCount:  " + sessio nCount);
  235                                 }  else {
  236                                      LOGGER.d ebug("Noth ing to log  - is the  Drools MBe an enabled ?");
  237                                 }
  238                                      
  239                                 Ob servation  observatio n = new Ob servation( );
  240                                 ob servation. setName("S essionCoun t");
  241                                 ob servation. setValue(s essionCoun t.doubleVa lue());
  242                                 ob servation. setTime(ne w Timestam p(new Date ().getTime ()));
  243                                 ob servation. setOrigin( origin);
  244                                      
  245                                      writeToM etricsDb(o bservation );
  246                             
  247                             } catc h(Exceptio n e) {
  248                                      LOGGER.w arn("Error  Retrievin g Metrics  via JMX :  " + e.getM essage());
  249                             } fina lly {
  250                                      if (jmxC onnector ! = null) {
  251                                               try {
  252                                                       jm xConnector .close();
  253                                               } catch (I OException  ioe) {
  254                                                       // not really  important ...
  255                                               }
  256                                               jmxConnect or = null;
  257                                      }
  258                             }
  259                }
  260           }
  261  
  262           /* *
  263            *  This is c urrently a  duplicati on of what 's in Metr icsCollect ionService .
  264            *  This meth od can be  refactored  into an a ppropriate  place to  share betw een
  265            *  both clas ses in the  future.
  266            *  
  267            *  @param me tric
  268            *  @throws I OException
  269            *  @throws J sonMapping Exception
  270            *  @throws J sonGenerat ionExcepti on
  271            * /
  272       public  void writ eToMetrics Db(Observa tion obser vation) 
  273                throws I OException , JsonMapp ingExcepti on, JsonGe nerationEx ception
  274       {
  275           // ---------- ---------- ---------- --------
  276           //  parse Obj ect to Jso n, 
  277           //  then can  send to me tric DB
  278           // ---------- ---------- ---------- --------
  279           Ob jectMapper  mapper =  new Object Mapper();
  280           St ring toSen d = mapper .writeValu eAsString( observatio n);
  281           
  282           LO GGER.info( "========= => JMXPoll ingService .writeToMe tricsDb: "  + mongoDb Dao);
  283           LO GGER.info( "Observati on and Ori gin: " + o bservation .getName()  + " from  " + observ ation.getO rigin());;
  284           
  285                    try  {
  286                             Docume nt callMet ricBson =  Document.p arse(toSen d);
  287                             MongoD atabase da tabase = m ongoDbDao. getMongoCl ient().get Database(" metric");
  288                             databa se.getColl ection("ob servation" ).insertOn e(callMetr icBson);
  289                    } ca tch (Excep tion e) {
  290                    LOGG ER.info("= =========>  JMXPollin gService.e rror: " +  e.getLocal izedMessag e(),e);
  291                    }
  292       }
  293       
  294   }