use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class DataStorageManager method create.
@Transactional(propagation = Propagation.REQUIRED)
public AbstractDataStorage create(DataStorageVO dataStorageVO, Boolean proceedOnCloud, Boolean checkExistence, boolean replaceStoragePath) throws DataStorageException {
Assert.isTrue(!StringUtils.isEmpty(dataStorageVO.getName()), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_NULL_OR_EMPTY, "name"));
assertDataStorageMountPoint(dataStorageVO);
dataStorageVO.setName(dataStorageVO.getName().trim());
checkDatastorageDoesntExist(dataStorageVO.getName(), dataStorageVO.getPath());
verifyStoragePolicy(dataStorageVO, dataStorageVO.getStoragePolicy(), true);
AbstractDataStorage dataStorage = dataStorageFactory.convertToDataStorage(dataStorageVO);
if (StringUtils.isBlank(dataStorage.getMountOptions())) {
dataStorage.setMountOptions(storageProviderManager.getStorageProvider(dataStorage).getDefaultMountOptions());
}
if (proceedOnCloud) {
if (replaceStoragePath) {
dataStorage.setPath(adjustStoragePath(dataStorage.getPath(), dataStorage.getType()));
}
String created = storageProviderManager.createBucket(dataStorage);
dataStorage.setPath(created);
} else if (checkExistence && !storageProviderManager.checkStorage(dataStorage)) {
throw new IllegalStateException(messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NOT_FOUND_BY_NAME, dataStorage.getName(), dataStorage.getPath()));
}
dataStorage.setOwner(authManager.getAuthorizedUser());
if (dataStorage.getParentFolderId() != null) {
Folder parent = folderManager.load(dataStorage.getParentFolderId());
dataStorage.setParent(parent);
}
dataStorageDao.createDataStorage(dataStorage);
if (dataStorage.isPolicySupported()) {
storageProviderManager.applyStoragePolicy(dataStorage);
}
return dataStorage;
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class DataStorageManager method updateDataStorageObjectTags.
public Map<String, String> updateDataStorageObjectTags(Long id, String path, Map<String, String> tagsToAdd, String version, Boolean rewrite) {
AbstractDataStorage dataStorage = load(id);
checkDataStorageVersioning(dataStorage, version);
Map<String, String> resultingTags = new HashMap<>();
if (!rewrite) {
resultingTags = storageProviderManager.listObjectTags(dataStorage, path, version);
}
resultingTags.putAll(tagsToAdd);
return storageProviderManager.updateObjectTags(dataStorage, path, resultingTags, version);
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class DataStorageManager method update.
@Transactional(propagation = Propagation.REQUIRED)
public AbstractDataStorage update(DataStorageVO dataStorageVO) {
assertDataStorageMountPoint(dataStorageVO);
AbstractDataStorage dataStorage = load(dataStorageVO.getId());
AbstractDataStorage updated = updateDataStorageObject(dataStorage, dataStorageVO);
dataStorageDao.updateDataStorage(updated);
return updated;
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class DataStorageManager method getDataStorageItemContent.
public DataStorageItemContent getDataStorageItemContent(Long id, String path, String version) {
AbstractDataStorage dataStorage = load(id);
checkDataStorageVersioning(dataStorage, version);
return storageProviderManager.getFile(dataStorage, path, version);
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class NFSStorageProvider method unmountNFSIfEmpty.
private synchronized void unmountNFSIfEmpty(AbstractDataStorage storage) {
String storagePath = storage.getPath();
File mntDir = Paths.get(rootMountPoint, getMountDirName(storagePath)).toFile();
List<AbstractDataStorage> remaining = dataStorageDao.loadDataStoragesByNFSPath(getNfsRootPath(storagePath));
LOGGER.debug("Remaining NFS: " + remaining.stream().map(AbstractDataStorage::getPath).collect(Collectors.joining(";")) + " related with current root path");
if (mntDir.exists() && isStorageOnlyOnNFS(storage, remaining)) {
try {
String umountCmd = String.format(NFS_UNMOUNT_CMD_PATTERN, mntDir.getAbsolutePath());
cmdExecutor.executeCommand(umountCmd);
FileUtils.deleteDirectory(mntDir);
} catch (IOException e) {
throw new DataStorageException(e);
}
}
}
Aggregations