You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2014/10/12 23:25:12 UTC

[2/4] git commit: updated name of the new filename

updated name of the new filename

Project: http://git-wip-us.apache.org/repos/asf/incubator-argus/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-argus/commit/5f4053e6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-argus/tree/5f4053e6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-argus/diff/5f4053e6

Branch: refs/heads/master
Commit: 5f4053e66ad5a505054ddf413f6654b4be896407
Parents: cd863f2
Author: mneethiraj <mn...@hortonworks.com>
Authored: Sun Oct 12 00:54:18 2014 -0700
Committer: mneethiraj <mn...@hortonworks.com>
Committed: Sun Oct 12 00:54:18 2014 -0700

----------------------------------------------------------------------
 .../audit/provider/hdfs/HdfsLogDestination.java | 50 ++++++++++++++++++--
 1 file changed, 47 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/5f4053e6/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java
----------------------------------------------------------------------
diff --git a/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java b/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java
index f31e4cb..a5ec60b 100644
--- a/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java
+++ b/agents-audit/src/main/java/com/xasecure/audit/provider/hdfs/HdfsLogDestination.java
@@ -200,7 +200,7 @@ public class HdfsLogDestination<T> implements LogDestination<T> {
 					if(mIsAppend) {
 						ostream = fileSystem.append(pathLogfile);
 					} else {
-						mHdfsFilename =  MiscUtil.replaceTokens(mDirectory + org.apache.hadoop.fs.Path.SEPARATOR + mFile, System.currentTimeMillis());
+						mHdfsFilename =  getNewFilename(mHdfsFilename, fileSystem);
 						pathLogfile   = new Path(mHdfsFilename);
 					}
 				}
@@ -211,7 +211,7 @@ public class HdfsLogDestination<T> implements LogDestination<T> {
 				}
 			} catch(IOException excp) {
 				// append may not be supported by the filesystem; or the file might already be open by another application. Try a different filename - with current timestamp
-				mHdfsFilename =  MiscUtil.replaceTokens(mDirectory + org.apache.hadoop.fs.Path.SEPARATOR + mFile, System.currentTimeMillis());
+				mHdfsFilename =  getNewFilename(mHdfsFilename, fileSystem);
 				pathLogfile   = new Path(mHdfsFilename);
 			}
 
@@ -324,8 +324,52 @@ public class HdfsLogDestination<T> implements LogDestination<T> {
 
 	    return writer;
 	}
+
+    private String getNewFilename(String fileName, FileSystem fileSystem) {
+    	if(fileName == null) {
+    		return "";
+    	}
+
+        for(int i = 1; ; i++) {
+        	String ret = fileName;
+
+	        String strToAppend = "-" + Integer.toString(i);
+	
+	        int extnPos = ret.lastIndexOf(".");
+	
+	        if(extnPos < 0) {
+	            ret += strToAppend;
+	        } else {
+	            String extn = ret.substring(extnPos);
 	
-	private void logException(String msg, IOException excp) {
+	            ret = ret.substring(0, extnPos) + strToAppend + extn;
+	        }
+	        
+	        if(fileSystem != null && fileExists(ret, fileSystem)) {
+        		continue;
+	        } else {
+	        	return ret;
+	        }
+    	}
+    }
+    
+    private boolean fileExists(String fileName, FileSystem fileSystem) {
+    	boolean ret = false;
+
+    	if(fileName != null && fileSystem != null) {
+    		Path path = new Path(fileName);
+
+    		try {
+    			ret = fileSystem.exists(path);
+    		} catch(IOException excp) {
+    			// ignore
+    		}
+    	}
+ 
+    	return ret;
+    }
+
+    private void logException(String msg, IOException excp) {
 		// during shutdown, the underlying FileSystem might already be closed; so don't print error details
 
 		if(mIsStopInProgress) {