NIFI-7338 This closes #4169. Added comment about com.hierynomus.smbj.SMBClient syncronicity

- added file.size attribute on GetSmbFile

Signed-off-by: Joe Witt <joewitt@apache.org>
This commit is contained in:
bibistroc 2020-08-05 12:17:21 +03:00 committed by Joe Witt
parent 71d155e874
commit 51091a5fca
No known key found for this signature in database
GPG Key ID: 9093BF854F811A1A
3 changed files with 11 additions and 2 deletions

View File

@ -203,6 +203,7 @@ public class GetSmbFile extends AbstractProcessor {
public static final String FILE_CREATION_TIME_ATTRIBUTE = "file.creationTime";
public static final String FILE_LAST_MODIFY_TIME_ATTRIBUTE = "file.lastModifiedTime";
public static final String FILE_LAST_ACCESS_TIME_ATTRIBUTE = "file.lastAccessTime";
public static final String FILE_SIZE_ATTRIBUTE = "file.size";
public static final String FILE_MODIFY_DATE_ATTR_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
final static DateFormat dateFormatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US);
@ -222,7 +223,7 @@ public class GetSmbFile extends AbstractProcessor {
private final AtomicLong queueLastUpdated = new AtomicLong(0L);
private SMBClient smbClient = null;
private SMBClient smbClient = null; // this gets synchronized when the `connect` method is called
private Pattern filePattern;
private Pattern pathPattern;
@ -468,6 +469,7 @@ public class GetSmbFile extends AbstractProcessor {
final long importMillis = TimeUnit.MILLISECONDS.convert(importNanos, TimeUnit.NANOSECONDS);
final FileAllInformation fileInfo = f.getFileInformation();
final FileBasicInformation fileBasicInfo = fileInfo.getBasicInformation();
final long fileSize = fileInfo.getStandardInformation().getEndOfFile();
flowFile = session.putAttribute(flowFile, CoreAttributes.FILENAME.key(), filename);
flowFile = session.putAttribute(flowFile, CoreAttributes.PATH.key(), filePath);
@ -475,6 +477,7 @@ public class GetSmbFile extends AbstractProcessor {
flowFile = session.putAttribute(flowFile, FILE_CREATION_TIME_ATTRIBUTE, dateFormatter.format(fileBasicInfo.getCreationTime().toDate()));
flowFile = session.putAttribute(flowFile, FILE_LAST_ACCESS_TIME_ATTRIBUTE, dateFormatter.format(fileBasicInfo.getLastAccessTime().toDate()));
flowFile = session.putAttribute(flowFile, FILE_LAST_MODIFY_TIME_ATTRIBUTE, dateFormatter.format(fileBasicInfo.getLastWriteTime().toDate()));
flowFile = session.putAttribute(flowFile, FILE_SIZE_ATTRIBUTE, String.valueOf(fileSize));
flowFile = session.putAttribute(flowFile, HOSTNAME.getName(), hostname);
flowFile = session.putAttribute(flowFile, SHARE.getName(), shareName);
session.getProvenanceReporter().receive(flowFile, uri.toString(), importMillis);

View File

@ -162,7 +162,7 @@ public class PutSmbFile extends AbstractProcessor {
private Set<Relationship> relationships;
private SMBClient smbClient = null;
private SMBClient smbClient = null; // this gets synchronized when the `connect` method is called
private Set<SMB2ShareAccess> sharedAccess;
@Override

View File

@ -21,6 +21,7 @@ import com.hierynomus.msfscc.FileAttributes;
import com.hierynomus.msfscc.fileinformation.FileAllInformation;
import com.hierynomus.msfscc.fileinformation.FileBasicInformation;
import com.hierynomus.msfscc.fileinformation.FileIdBothDirectoryInformation;
import com.hierynomus.msfscc.fileinformation.FileStandardInformation;
import com.hierynomus.mssmb2.SMB2CreateDisposition;
import com.hierynomus.smbj.SMBClient;
import com.hierynomus.smbj.auth.AuthenticationContext;
@ -120,8 +121,13 @@ public class GetSmbFileTest {
FileAllInformation fileAllInfo = mock(FileAllInformation.class);
FileTime fileTime = FileTime.ofEpochMillis(0);
FileBasicInformation fileBasicInfo = new FileBasicInformation(fileTime, fileTime, fileTime, fileTime, 0);
FileStandardInformation fileStandardInformation = mock(FileStandardInformation.class);
when(smbfile.getFileInformation()).thenReturn(fileAllInfo);
when(fileAllInfo.getBasicInformation()).thenReturn(fileBasicInfo);
when(fileAllInfo.getStandardInformation()).thenReturn(fileStandardInformation);
when(fileStandardInformation.getEndOfFile()).thenReturn((long) 0);
return fdInfo;
}