Produced by Araxis Merge on 12/5/2017 12:06:49 PM 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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\TransactionLoggerLocalDataSourceProvider\main\src\java\gov\va\med\imaging\access\je | BDBRecoverer.java | Mon Dec 4 21:35:02 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\TransactionLoggerLocalDataSourceProvider\main\src\java\gov\va\med\imaging\access\je | BDBRecoverer.java | Mon Dec 4 22:06:07 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 626 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| 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 |
No regular expressions were active.
| 1 | /** | |
| 2 | * Package : MAG - Vi stA Imagin g | |
| 3 | * WARNING : Per VHA Directive 2004-038, this routi ne should not be mod ified. | |
| 4 | * Date Cr eated: May 27, 2008 | |
| 5 | * Site Na me: Washi ngton OI F ield Offic e, Silver Spring, MD | |
| 6 | * @author
|
|
| 7 | * @versio n 1.0 | |
| 8 | * | |
| 9 | * ------- ---------- ---------- ---------- ---------- ---------- ------- | |
| 10 | * Propert y of the U S Governme nt. | |
| 11 | * No perm ission to copy or re distribute this soft ware is gi ven. | |
| 12 | * Use of unreleased versions of this so ftware req uires the user | |
| 13 | * to exec ute a writ ten test a greement w ith the Vi stA Imagin g | |
| 14 | * Develop ment Offic e of the D epartment of Veteran s Affairs, | |
| 15 | * telepho ne (301) 7 34-0100. | |
| 16 | * | |
| 17 | * The Foo d and Drug Administr ation clas sifies thi s software as | |
| 18 | * a Class II medica l device. As such, it may not be change d | |
| 19 | * in any way. Modi fications to this so ftware may result in an | |
| 20 | * adulter ated medic al device under 21CF R820, the use of whi ch | |
| 21 | * is cons idered to be a viola tion of US Federal S tatutes. | |
| 22 | * ------- ---------- ---------- ---------- ---------- ---------- ------- | |
| 23 | */ | |
| 24 | package go v.va.med.i maging.acc ess.je; | |
| 25 | ||
| 26 | ||
| 27 | import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception; | |
| 28 | ||
| 29 | import jav a.io.File; | |
| 30 | import jav a.io.FileI nputStream ; | |
| 31 | import jav a.io.FileO utputStrea m; | |
| 32 | import jav a.io.Buffe redInputSt ream; | |
| 33 | import jav a.io.Buffe redOutputS tream; | |
| 34 | import jav a.io.Print Stream; | |
| 35 | import jav a.io.Print Writer; | |
| 36 | import jav a.util.Dat e; | |
| 37 | import jav a.util.Vec tor; | |
| 38 | import jav a.util.Map ; | |
| 39 | import jav a.util.Has htable; | |
| 40 | import jav a.util.Col lections; | |
| 41 | import jav a.text.Sim pleDateFor mat; | |
| 42 | ||
| 43 | import org .apache.lo gging.log4 j.LogManag er; | |
| 44 | import org .apache.lo gging.log4 j.Logger; | |
| 45 | ||
| 46 | import com .sleepycat .je.Databa seExceptio n; | |
| 47 | ||
| 48 | ||
| 49 | /** | |
| 50 | * | |
| 51 | * If BDB Environmen t initiali zation fai ls, then t ry running the recov ery routin e(s) here. | |
| 52 | * | |
| 53 | * @author vhaiswbat esl1 | |
| 54 | * | |
| 55 | */ | |
| 56 | public cla ss BDBReco verer impl ements Run nable | |
| 57 | { | |
| 58 | ||
| 59 | private static fi nal String fylSep = System.get Property ( "file.sepa rator"); | |
| 60 | ||
| 61 | private Logger lo gger = Log Manager.ge tLogger(th is.getClas s ()); | |
| 62 | ||
| 63 | private File data baseDirect ory = null ; | |
| 64 | ||
| 65 | private Process a ppProc = n ull; | |
| 66 | private boolean p rocessRunn ing = fals e; | |
| 67 | private boolean p rocessFini shed = tru e; | |
| 68 | private StringBui lder sbCon soleOutput = null; | |
| 69 | ||
| 70 | ||
| 71 | /** | |
| 72 | * Cons truct with the BDB E nvironment directory . | |
| 73 | * @par am databas eDirectory The direc tory with the BDB fi les. | |
| 74 | */ | |
| 75 | public BDBRecover er (File d atabaseDir ectory) | |
| 76 | { | |
| 77 | ||
| 78 | this .databaseD irectory = databaseD irectory; | |
| 79 | ||
| 80 | } // BD BRecoverer | |
| 81 | ||
| 82 | ||
| 83 | /** | |
| 84 | * 1. I f there ar en't any . jdb files, forget it . | |
| 85 | * 2. B ackup .jdb files to Database D irectory s lash BDBRe covererBac kup- today 's date. | |
| 86 | * 3. S tarting wi th the lat est .jdb f ile, and w orking bac kwards to the first | |
| 87 | * "000 00000.jdb" file, rem ove the fi le from pl ay and run DbVerify against | |
| 88 | * the .jdb files still lef t until Db Verify rep orts every thing is A OK. | |
| 89 | * @thr ows Databa seExceptio n if anyth ing goes w rong. | |
| 90 | */ | |
| 91 | public void recov er () thro ws MethodE xception | |
| 92 | { | |
| 93 | ||
| 94 | File shel lScript = null; | |
| 95 | ||
| 96 | try | |
| 97 | { | |
| 98 | logger.inf o ("Attemp ting To Re cover BDB Environmen t " + data baseDirect ory.getCan onicalPath ()); | |
| 99 | ||
| 100 | Vector <File> vJd bFyls = ne w Vector<F ile> (); | |
| 101 | Fi le[] fylLs t = databa seDirector y.listFile s (); | |
| 102 | ||
| 103 | for (F ile fyl : fylLst) | |
| 104 | { | |
| 105 | if (fyl.isFi le () && f yl.getName ().endsWi th (".jdb" )) vJdbFyl s.add (fyl ); | |
| 106 | } | |
| 107 | ||
| 108 | if (vJ dbFyls.isE mpty ()) | |
| 109 | { | |
| 110 | th row new Me thodExcept ion ("BDB Environmen t Recovery Failed - No \".jdb\ " Files Fo und"); | |
| 111 | } | |
| 112 | ||
| 113 | Vector <Long> vJd bFylNums = new Vecto r<Long> () ; | |
| 114 | Map<Lo ng, File> mapJdbFyls = new Has htable<Lon g, File> ( ); | |
| 115 | for (F ile fyl : vJdbFyls) | |
| 116 | { | |
| 117 | in t idx1 = f yl.getName ().indexO f (".jdb") ; | |
| 118 | St ring fileN umTxt = fy l.getName ().substri ng (0, idx 1); | |
| 119 | Lo ng fileNum = new Lon g (Long.pa rseLong (f ileNumTxt, 16)); | |
| 120 | vJ dbFylNums. add (fileN um); | |
| 121 | ma pJdbFyls.p ut (fileNu m, fyl); | |
| 122 | } | |
| 123 | Collec tions.sort (vJdbFylN ums); | |
| 124 | ||
| 125 | Simple DateFormat sdf = new SimpleDat eFormat (" yyyy-MM-dd "); | |
| 126 | String dateTxt = sdf.forma t(new Date ()); | |
| 127 | File b ackupDir = new File (databaseD irectory.g etCanonica lPath() + fylSep + " BDBRecover erBackup-" + dateTxt ); | |
| 128 | backup Dir.mkdir (); | |
| 129 | ||
| 130 | logger .info ("Ba cking Up \ ".jdb\" Fi les To " + backupDir .getCanoni calPath () ); | |
| 131 | ||
| 132 | in t size = 1 000000; | |
| 133 | byte[] fil eBytes = n ew byte[si ze]; | |
| 134 | for (F ile fyl : vJdbFyls) | |
| 135 | { | |
| 136 | File ba kFyl = new File (bac kupDir.get CanonicalP ath () + f ylSep + fy l.getName ()); | |
| 137 | Buffe redOutputS tream bos = new Buff eredOutput Stream (ne w FileOutp utStream ( bakFyl)); | |
| 138 | ||
| 139 | Buffere dInputStre am bis = n ew Buffere dInputStre am (new Fi leInputStr eam (fyl)) ; | |
| 140 | int num Read = bis .read (fil eBytes); | |
| 141 | while ( numRead > 0) | |
| 142 | { | |
| 143 | bos.wr ite (fileB ytes, 0, n umRead); | |
| 144 | numR ead = bis. read (file Bytes); | |
| 145 | } | |
| 146 | bis.clo se (); | |
| 147 | ||
| 148 | bos.f lush (); | |
| 149 | bos.c lose (); | |
| 150 | } | |
| 151 | ||
| 152 | boolean is Unix = (fy lSep.equal s ("/") ? true : fal se); | |
| 153 | String scr ipt = (isU nix ? "dbv erify.sh" : "dbverif y.bat"); | |
| 154 | shellScrip t = new Fi le (System .getProper ty ("java. io.tmpdir" ) + fylSep + script) ; | |
| 155 | ||
| 156 | String jav aExe = "ja va"; | |
| 157 | String jav aHome = Sy stem.geten v ("JAVA_H OME"); | |
| 158 | if (javaHo me != null ) javaExe = "\"".con cat (javaH ome).conca t (fylSep) .concat (" bin").conc at (fylSep ).concat ( "java\""); | |
| 159 | ||
| 160 | String cat alinaHome = System.g etenv("CAT ALINA_HOME "); | |
| 161 | logger.inf o("Catalin a Home: [" + catalin aHome + "] "); | |
| 162 | logger.inf o("fylSep: [" + fylS ep + "]"); | |
| 163 | ||
| 164 | String lib Dir = cata linaHome + fylSep + "lib"; | |
| 165 | logger.inf o("libDir: [" + libD ir + "]"); | |
| 166 | File jeJar = new Fil e (libDir + fylSep + "je-3.2.7 6.jar"); | |
| 167 | logger.inf o("jeJar p ath [" + j eJar.getAb solutePath () + "]"); | |
| 168 | ||
| 169 | if (!jeJar .exists () ) | |
| 170 | { | |
| 171 | th row new Me thodExcept ion ("BDB Environmen t Recovery Failed - Can't Find File " + jeJar.getC anonicalPa th ()); | |
| 172 | } | |
| 173 | ||
| 174 | PrintWrite r pw = new PrintWrit er (new Fi leOutputSt ream (shel lScript)); | |
| 175 | if (isUnix ) pw.print ln ("#!/bi n/sh"); | |
| 176 | pw .println ( javaExe + " -cp \"" + jeJar.ge tCanonical Path () + "\" com.sl eepycat.je .util.DbVe rify -h \" " | |
| 177 | + datab aseDirecto ry.getCano nicalPath( ) + "\""); | |
| 178 | pw.flush ( ); | |
| 179 | pw.close ( ); | |
| 180 | ||
| 181 | shellScrip t.setExecu table (tru e); | |
| 182 | ||
| 183 | int jd bKtr = vJd bFylNums.s ize () - 1 ; | |
| 184 | while (jdbKtr >= 0) | |
| 185 | { | |
| 186 | Lo ng fileNum = (Long) vJdbFylNum s.get (jdb Ktr); | |
| 187 | Fi le jdbFyl = mapJdbFy ls.get (fi leNum); | |
| 188 | ||
| 189 | lo gger.info ("Verifyin g " + jdbF yl.getName ()); | |
| 190 | ||
| 191 | Fi le bakFyl = new File (jdbFyl.g etCanonica lPath () + ".bak"); | |
| 192 | jd bFyl.renam eTo (bakFy l); | |
| 193 | ||
| 194 | sb ConsoleOut put = new StringBuil der (); | |
| 195 | ||
| 196 | ap pProc = Ru ntime.getR untime (). exec (shel lScript.ge tCanonical Path ()); | |
| 197 | proces sFinished = false; | |
| 198 | proces sRunning = true; | |
| 199 | new Th read (this ).start () ; | |
| 200 | appPro c.waitFor (); | |
| 201 | proces sRunning = false; | |
| 202 | while (!processF inished); | |
| 203 | ||
| 204 | // logg er.info("D one proces sing: \n" + sbConsol eOutput.to String()); | |
| 205 | ||
| 206 | if (sb ConsoleOut put.toStri ng ().toLo werCase () .indexOf ( "exit stat us = true" ) >= 0) br eak; | |
| 207 | ||
| 208 | jd bKtr--; | |
| 209 | } | |
| 210 | ||
| 211 | for (F ile fyl : vJdbFyls) | |
| 212 | { | |
| 213 | Fi le bakFyl = new File (fyl.getC anonicalPa th () + ". bak"); | |
| 214 | if (bakFyl.e xists ()) bakFyl.del ete (); | |
| 215 | } | |
| 216 | ||
| 217 | if (jd bKtr < 0) | |
| 218 | { | |
| 219 | th row new Me thodExcept ion ("BDB Environmen t Recovery Failed - No Valid \ ".jdb\" Fi les Found" ); | |
| 220 | } | |
| 221 | ||
| 222 | Long fileN um = (Long ) vJdbFylN ums.get (j dbKtr); | |
| 223 | File jdbFy l = mapJdb Fyls.get ( fileNum); | |
| 224 | logger.inf o ("Proble m Found Wi th File " + jdbFyl.g etName () + | |
| 225 | ". Thi s And All Later File s Have Bee n Deleted. "); | |
| 226 | ||
| 227 | if (shellS cript != n ull && she llScript.e xists ()) shellScrip t.delete ( ); | |
| 228 | } | |
| 229 | ||
| 230 | catch (Da tabaseExce ption dbe) | |
| 231 | { | |
| 232 | t hrow (dbe) ; | |
| 233 | } | |
| 234 | ||
| 235 | catch (Ex ception x) | |
| 236 | { | |
| 237 | t hrow new M ethodExcep tion (x); | |
| 238 | } | |
| 239 | ||
| 240 | fin ally | |
| 241 | { | |
| 242 | if (shell Script != null && sh ellScript. exists ()) shellScri pt.delete (); | |
| 243 | } | |
| 244 | ||
| 245 | } // re cover | |
| 246 | ||
| 247 | ||
| 248 | /** | |
| 249 | * The script and its comma nds are ha ndled by a separate process. | |
| 250 | * Use this Threa d here to monitor an d capture any consol e output p roduced by | |
| 251 | * runn ing the sc ript. | |
| 252 | */ | |
| 253 | public void run ( ) | |
| 254 | { | |
| 255 | ||
| 256 | Buff eredInputS tream appI n = new Bu fferedInpu tStream (a ppProc.get InputStrea m ()); | |
| 257 | BufferedIn putStream appErr = n ew Buffere dInputStre am (appPro c.getError Stream ()) ; | |
| 258 | PrintStrea m appOut = new Print Stream (ap pProc.getO utputStrea m (), true ); | |
| 259 | ||
| 260 | whil e (true) | |
| 261 | { | |
| 262 | try | |
| 263 | { | |
| 264 | int nu mIn = 0; | |
| 265 | int nu mErr = 0; | |
| 266 | ||
| 267 | while ((numIn = appIn.avai lable ()) > 0) | |
| 268 | { | |
| 269 | by te[] bfr = new byte[ numIn]; | |
| 270 | ap pIn.read ( bfr, 0, nu mIn); | |
| 271 | // Sy stem.out.p rint (new String (bf r)); | |
| 272 | sbConsol eOutput.ap pend (new String (bf r)); | |
| 273 | } | |
| 274 | ||
| 275 | while ((numErr = appErr.av ailable () ) > 0) | |
| 276 | { | |
| 277 | by te[] bfr = new byte[ numErr]; | |
| 278 | ap pErr.read (bfr, 0, n umErr); | |
| 279 | // Sy stem.out.p rint (new String (bf r)); | |
| 280 | sbConsol eOutput.ap pend (new String (bf r)); | |
| 281 | } | |
| 282 | ||
| 283 | if (!process Running || processFi nished) br eak; | |
| 284 | } | |
| 285 | ||
| 286 | catch (Exception x) | |
| 287 | { | |
| 288 | // System .out.print ln (x.getC lass ().ge tName () + ": " + x. getMessage ()); | |
| 289 | lo gger.error (x.getCla ss ().getN ame () + " : " + x.ge tMessage ( )); | |
| 290 | sb ConsoleOut put.setLen gth (0); | |
| 291 | br eak; | |
| 292 | } | |
| 293 | } | |
| 294 | ||
| 295 | try | |
| 296 | { | |
| 297 | if (appOut != null) appOut.clo se (); | |
| 298 | if (appErr != null) appErr.clo se (); | |
| 299 | if (appIn != null) a ppIn.close (); | |
| 300 | } | |
| 301 | ||
| 302 | catc h (Excepti on ignore) | |
| 303 | { | |
| 304 | } | |
| 305 | ||
| 306 | appO ut = null; | |
| 307 | appE rr = null; | |
| 308 | appI n = null; | |
| 309 | ||
| 310 | proc essFinishe d = true; | |
| 311 | ||
| 312 | } // ru n | |
| 313 | ||
| 314 | } // class BDBRecove rer |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.