Search in sources :

Example 11 with DataStorageFile

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);
}
Also used : DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 12 with DataStorageFile

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;
}
Also used : DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) HashMap(java.util.HashMap)

Example 13 with DataStorageFile

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);
}
Also used : DataStorageListing(com.epam.pipeline.entity.datastorage.DataStorageListing) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) AbstractDataStorageItem(com.epam.pipeline.entity.datastorage.AbstractDataStorageItem) ArrayList(java.util.ArrayList) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 14 with DataStorageFile

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;
}
Also used : DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Attachment(com.epam.pipeline.entity.issue.Attachment) UUID(java.util.UUID)

Example 15 with DataStorageFile

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());
}
Also used : DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) NFSDataStorage(com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage) Matchers.anyString(org.mockito.Matchers.anyString) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Aggregations

DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)15 AbstractDataStorageItem (com.epam.pipeline.entity.datastorage.AbstractDataStorageItem)5 DataStorageListing (com.epam.pipeline.entity.datastorage.DataStorageListing)4 NFSDataStorage (com.epam.pipeline.entity.datastorage.nfs.NFSDataStorage)4 File (java.io.File)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)3 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)3 DataStorageFolder (com.epam.pipeline.entity.datastorage.DataStorageFolder)3 InputStream (java.io.InputStream)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ListObjectsV2Request (com.amazonaws.services.s3.model.ListObjectsV2Request)2 ListObjectsV2Result (com.amazonaws.services.s3.model.ListObjectsV2Result)2 MessageHelper (com.epam.pipeline.common.MessageHelper)2 DataStorageDao (com.epam.pipeline.dao.datastorage.DataStorageDao)2 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)2 DataStorageException (com.epam.pipeline.entity.datastorage.DataStorageException)2 DataStorageStreamingContent (com.epam.pipeline.entity.datastorage.DataStorageStreamingContent)2 CmdExecutor (com.epam.pipeline.manager.CmdExecutor)2