Search in sources :

Example 1 with DataStorageException

use of com.epam.pipeline.entity.datastorage.DataStorageException in project cloud-pipeline by epam.

the class DataStorageManager method restoreVersion.

public void restoreVersion(Long id, String path, String version) throws DataStorageException {
    Assert.notNull(path, "Path is required to restore file version");
    Assert.notNull(version, "Version is required to restore file version");
    AbstractDataStorage dataStorage = load(id);
    if (!dataStorage.isVersioningEnabled()) {
        throw new DataStorageException(messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_VERSIONING_REQUIRED, dataStorage.getName()));
    }
    storageProviderManager.restoreFileVersion(dataStorage, path, version);
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException)

Example 2 with DataStorageException

use of com.epam.pipeline.entity.datastorage.DataStorageException in project cloud-pipeline by epam.

the class DataStorageManager method delete.

@Transactional(propagation = Propagation.REQUIRED)
public AbstractDataStorage delete(Long id, boolean proceedOnCloud) {
    AbstractDataStorage dataStorage = load(id);
    validateStorageIsNotUsedAsDefault(id, roleManager.loadRolesByDefaultStorage(id));
    validateStorageIsNotUsedAsDefault(id, userManager.loadUsersByDeafultStorage(id));
    if (proceedOnCloud) {
        try {
            storageProviderManager.deleteBucket(dataStorage);
        } catch (DataStorageException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    dataStorageDao.deleteDataStorage(id);
    return dataStorage;
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DataStorageException

use of com.epam.pipeline.entity.datastorage.DataStorageException in project cloud-pipeline by epam.

the class NFSStorageProvider method mount.

private synchronized File mount(NFSDataStorage dataStorage) {
    File mntDir = Paths.get(rootMountPoint, getMountDirName(dataStorage.getPath())).toFile();
    try {
        if (!mntDir.exists()) {
            Assert.isTrue(mntDir.mkdirs(), messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NFS_MOUNT_DIRECTORY_NOT_CREATED));
            String rootNfsPath = getNfsRootPath(dataStorage.getPath());
            String mountOptions = String.format(DEFAULT_NFS_OPTIONS_PATTERN, rsize, wsize);
            String mountCmd = String.format(NFS_MOUNT_CMD_PATTERN, mountOptions, rootNfsPath, mntDir.getAbsolutePath());
            try {
                cmdExecutor.executeCommand(mountCmd);
            } catch (CmdExecutionException e) {
                FileUtils.deleteDirectory(mntDir);
                LOGGER.error(messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NFS_MOUNT_2, mountCmd, e.getMessage()));
                throw new DataStorageException(messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NFS_MOUNT, dataStorage.getName(), dataStorage.getPath()), e);
            }
        }
    } catch (IOException e) {
        throw new DataStorageException(messageHelper.getMessage(messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NFS_MOUNT, dataStorage.getName(), dataStorage.getPath())), e);
    }
    String storageName = getStorageName(dataStorage.getPath());
    return new File(mntDir, storageName);
}
Also used : DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) CmdExecutionException(com.epam.pipeline.exception.CmdExecutionException) IOException(java.io.IOException) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) File(java.io.File)

Example 4 with DataStorageException

use of com.epam.pipeline.entity.datastorage.DataStorageException in project cloud-pipeline by epam.

the class NFSStorageProvider method move.

private File move(NFSDataStorage dataStorage, String oldPath, String newPath) {
    File dataStorageDir = mount(dataStorage);
    File file = new File(dataStorageDir, oldPath);
    File newFile = new File(dataStorageDir, newPath);
    try {
        if (file.isDirectory()) {
            FileUtils.moveDirectory(file, newFile);
        } else {
            FileUtils.moveFile(file, newFile);
        }
    } catch (IOException e) {
        throw new DataStorageException(e);
    }
    return newFile;
}
Also used : DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) IOException(java.io.IOException) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) File(java.io.File)

Example 5 with DataStorageException

use of com.epam.pipeline.entity.datastorage.DataStorageException in project cloud-pipeline by epam.

the class NFSStorageProvider method deleteStorage.

/**
 * Deletes NFS storage from the filesystem.
 * @param dataStorage a storage to delete
 * @throws DataStorageException if datastorage cannot be deleted
 */
@Override
public void deleteStorage(NFSDataStorage dataStorage) throws DataStorageException {
    File dataStorageRoot = mount(dataStorage);
    if (dataStorageRoot.exists()) {
        try {
            FileUtils.deleteDirectory(dataStorageRoot);
            LOGGER.debug("Storage: " + dataStorage.getPath() + " with local path: " + dataStorageRoot + " was successfully deleted");
        } catch (IOException e) {
            unmountNFSIfEmpty(dataStorage);
            throw new DataStorageException(messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NFS_DELETE_DIRECTORY), e);
        }
    }
    unmountNFSIfEmpty(dataStorage);
}
Also used : DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) IOException(java.io.IOException) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) File(java.io.File)

Aggregations

DataStorageException (com.epam.pipeline.entity.datastorage.DataStorageException)28 IOException (java.io.IOException)14 DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)12 File (java.io.File)11 AmazonS3 (com.amazonaws.services.s3.AmazonS3)8 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)5 DataStorageItemContent (com.epam.pipeline.entity.datastorage.DataStorageItemContent)5 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)4 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)4 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 DataStorageFolder (com.epam.pipeline.entity.datastorage.DataStorageFolder)4 DataStorageStreamingContent (com.epam.pipeline.entity.datastorage.DataStorageStreamingContent)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 SdkClientException (com.amazonaws.SdkClientException)3 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)3 InputStream (java.io.InputStream)3 Date (java.util.Date)3 List (java.util.List)3 Test (org.junit.Test)3