HMSDebuggerComponent { public Date parseDateFromFileName( String logArchiveName ) throws HmsException { if ( isParameterNotNullNonEmpty( logArchiveName ) && logArchiveName.matches( HMS_ARCHIVE_REGEX ) ) { String fileTimeStamp = null; Pattern p = Pattern.compile( HMS_TIMESTAMP_EXTRACTION_REGEX ); Matcher m = p.matcher( logArchiveName ); if ( m.find() ) { logger.debug( "Extracted timestamp for log archive [ " + logArchiveName + " ] is [ " + m.group( 1 ) + " ]" ); fileTimeStamp = m.group( 1 ); } DateFormat df = new SimpleDateFormat( TIMESTAMP_FORMAT ); Date parsedDate; try { parsedDate = df.parse( fileTimeStamp ); logger.debug( "Parsed date :" + parsedDate ); return parsedDate; } catch ( ParseException e ) { String err = "Unable to parse date from the filename [ " + logArchiveName + " ]"; logger.error( err ); throw new HmsException( err, e ); } } else { String err = "Cannot get Date from log Archive name [ " + logArchiveName + " ], because either it is null or empty. or it doesnot matches the regular expression [ " + HMS_ARCHIVE_REGEX + " ]"; logger.error( err ); throw new HmsException( err ); } }  String archiveHmsDebugLogs( final String host_id, final String hmsIpAddr, final String hmsOobUsername,
                                       final String hmsLogArchiverScript, final String hmsLogArchiveLocation,
                                       final String hmsOobLogLocation, final String hmsIbLogLocation,
                                       final int noOfLines, final EventComponent component ); boolean writeAllEventsToFile( ServerNode node, String fileName, String logDirectoryPath ); boolean writeNBSwitchInfoToFile( NBSwitchInfo node, String fileName, String logDirectoryPath ); boolean writeServerInfoToFile( ServerInfo host, String fileName, String logDirectoryPath ); boolean writeFile( String eventsLogFilePath, String content ); String getAbsoluteFilePath( String directoryLocation, String filename ); String getEventsDataAsString( ServerNode node ); String getSwitchEventsDataAsString( SwitchNode node ); boolean writeHmsLogs( String node_id, String hmsLogArchiverScript, String hmsLogArchiveLocation,
                                 String timestamp, int noOfLines, String nodeInfoLogFileName, String hmsArchiveName,
                                 String hmsOobLogLocation, String hmsIbLogLocation,
                                 final EventComponent isHostOrSwitch ); boolean callLogArchiverShellScript( String node_id, String hmsLogArchiverScript,
                                               String hmsLogArchiveLocation, String eventsLogFileName,
                                               String hmsArchiveName, String host_id, String timestamp,
                                               String hmsOobLogFileName, String hmsIbLogLocation, int noOfLines ); boolean callServerLogArchiverShellScript( String node_id, String hmsLogArchiverScript,
                                                     String hmsLogArchiveLocation, String serverInfoFileName,
                                                     String hmsArchiveName, String host_id, String timestamp,
                                                     String hmsOobLogLocation, String hmsIbLogLocation, int noOfLines,
                                                     String eventLogFileName ); boolean isParameterNotNullNonEmpty( String param ); String getCurrentTimestamp(); String getServerInfoOrNBSwitchInfoLogFilename( String host_id, String timestamp,
                                                          EventComponent isHostOrSwitch ); String getHmsEventsLogFilename( String host_id, String timestamp ); String getHmsOobLogFilename( String host_id, String timestamp ); String getHmsLogArchiveName( String host_id, String timestamp ); boolean cleanHmsDebugLogs( String logArchiveDirectoryName ); boolean isFileDeleteable( String logArchiveName ); Date parseDateFromFileName( String logArchiveName ); void setHmsSwitchManager( HmsSwitchManager hmsSwitchManager ); final String TIMESTAMP_FORMAT; final String HMS_ARCHIVE_REGEX; final String HMS_TIMESTAMP_EXTRACTION_REGEX; final long logClearDurationInHours; }
@Test public void parseDateFromFileName_validInput() throws HmsException { String currentTimeString = "N1_hms_logs_2015-03-03_00-00-00.zip"; Date currentDate = debuggerUtil.parseDateFromFileName( currentTimeString ); assertNotNull( currentDate ); }
@Test( expected = HmsException.class ) public void parseDateFromFileName_invalidInput() throws HmsException { String invalidTimeString = "N1_hms_logs_2015-03-03_00"; Date currentDate = debuggerUtil.parseDateFromFileName( invalidTimeString ); assertNotNull( currentDate ); }