use of com.epam.pipeline.entity.datastorage.DataStorageFile in project cloud-pipeline by epam.
the class NFSStorageProvider method createFile.
@Override
public DataStorageFile createFile(NFSDataStorage dataStorage, String path, InputStream dataStream) throws DataStorageException {
File dataStorageDir = mount(dataStorage);
File file = new File(dataStorageDir, path);
try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file))) {
IOUtils.copy(dataStream, outputStream);
setUmask(file);
} catch (IOException e) {
throw new DataStorageException(e);
}
return new DataStorageFile(path, file);
}
use of com.epam.pipeline.entity.datastorage.DataStorageFile in project cloud-pipeline by epam.
the class AbstractS3ObjectWrapper method convertToStorageFile.
public DataStorageFile convertToStorageFile(String requestPath) {
String relativePath = getKey();
if ((relativePath.endsWith(S3Constants.DELIMITER) && relativePath.equals(requestPath)) || StringUtils.endsWithIgnoreCase(relativePath, S3Constants.FOLDER_TOKEN_FILE.toLowerCase())) {
return null;
}
if (relativePath.endsWith(S3Constants.DELIMITER)) {
relativePath = relativePath.substring(0, relativePath.length() - 1);
}
String fileName = relativePath.substring(requestPath.length());
DataStorageFile file = new DataStorageFile();
file.setName(fileName);
file.setPath(relativePath);
file.setSize(getSize());
file.setVersion(getVersion());
file.setChanged(S3Constants.getAwsDateFormat().format(getChanged()));
file.setDeleteMarker(getDeleteMarker());
Map<String, String> labels = new HashMap<>();
if (getStorageClass() != null) {
labels.put("StorageClass", getStorageClass());
}
file.setLabels(labels);
return file;
}
use of com.epam.pipeline.entity.datastorage.DataStorageFile in project cloud-pipeline by epam.
the class S3Helper method listFiles.
private DataStorageListing listFiles(AmazonS3 client, String bucket, String requestPath, Integer pageSize, String marker) {
ListObjectsV2Request req = new ListObjectsV2Request();
req.setBucketName(bucket);
req.setPrefix(requestPath);
req.setDelimiter(S3Constants.DELIMITER);
if (pageSize != null) {
req.setMaxKeys(pageSize);
}
if (StringUtils.hasValue(marker)) {
req.setStartAfter(marker);
}
ListObjectsV2Result listing;
List<AbstractDataStorageItem> items = new ArrayList<>();
String previous = null;
do {
listing = client.listObjectsV2(req);
for (String name : listing.getCommonPrefixes()) {
previous = getPreviousKey(previous, name);
items.add(parseFolder(requestPath, name));
}
for (S3ObjectSummary s3ObjectSummary : listing.getObjectSummaries()) {
DataStorageFile file = AbstractS3ObjectWrapper.getWrapper(s3ObjectSummary).convertToStorageFile(requestPath);
if (file != null) {
previous = getPreviousKey(previous, s3ObjectSummary.getKey());
items.add(file);
}
}
req.setContinuationToken(listing.getNextContinuationToken());
} while (listing.isTruncated() && (pageSize == null || items.size() < pageSize));
String returnToken = listing.isTruncated() ? previous : null;
return new DataStorageListing(returnToken, items);
}
use of com.epam.pipeline.entity.datastorage.DataStorageFile in project cloud-pipeline by epam.
the class AttachmentFileManager method uploadAttachment.
public Attachment uploadAttachment(InputStream attachmentInputStream, String fileName) {
String systemDataStorageName = preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME);
Assert.notNull(systemDataStorageName, messageHelper.getMessage(MessageConstants.ERROR_ATTACHMENT_SYSTEM_DATA_STORAGE_NOT_CONFIGURED));
AbstractDataStorage attachmentStorage = dataStorageManager.loadByNameOrId(systemDataStorageName);
UUID uuid = UUID.randomUUID();
String uniqueName = uuid.toString() + "-" + fileName;
DataStorageFile uploadedFile = dataStorageManager.createDataStorageFile(attachmentStorage.getId(), ATTACHMENTS_DIRECTORY, uniqueName, attachmentInputStream);
Attachment attachment = new Attachment();
attachment.setPath(uploadedFile.getPath());
attachment.setName(fileName);
attachment.setCreatedDate(DateUtils.now());
attachment.setOwner(authManager.getAuthorizedUser());
attachmentManager.create(attachment);
return attachment;
}
use of com.epam.pipeline.entity.datastorage.DataStorageFile in project cloud-pipeline by epam.
the class NFSStorageProviderTest method testEditFile.
@Test
public void testEditFile() {
NFSDataStorage dataStorage = new NFSDataStorage(0L, "testStorage", TEST_PATH + 3 + ":/test");
nfsProvider.createStorage(dataStorage);
String testFileName = "testFile.txt";
byte[] testContent = "testContent".getBytes();
byte[] newContent = "new content".getBytes();
DataStorageFile file = nfsProvider.createFile(dataStorage, testFileName, testContent);
Assert.assertArrayEquals(testContent, nfsProvider.getFile(dataStorage, testFileName, file.getVersion(), Long.MAX_VALUE).getContent());
DataStorageFile updatedFile = nfsProvider.createFile(dataStorage, testFileName, newContent);
Assert.assertArrayEquals(newContent, nfsProvider.getFile(dataStorage, testFileName, updatedFile.getVersion(), Long.MAX_VALUE).getContent());
}
Aggregations