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);
}
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;
}
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);
}
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;
}
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);
}
Aggregations