Search in sources :

Example 41 with AbstractDataStorage

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;
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Folder(com.epam.pipeline.entity.pipeline.Folder) DataStorageFolder(com.epam.pipeline.entity.datastorage.DataStorageFolder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with AbstractDataStorage

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

Example 43 with AbstractDataStorage

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;
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with AbstractDataStorage

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

Example 45 with AbstractDataStorage

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

Aggregations

AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)62 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)22 Test (org.junit.Test)22 Transactional (org.springframework.transaction.annotation.Transactional)18 Folder (com.epam.pipeline.entity.pipeline.Folder)13 DataStorageVO (com.epam.pipeline.controller.vo.DataStorageVO)11 ArrayList (java.util.ArrayList)7 List (java.util.List)6 EntityVO (com.epam.pipeline.controller.vo.EntityVO)5 StoragePolicy (com.epam.pipeline.entity.datastorage.StoragePolicy)5 Service (org.springframework.stereotype.Service)5 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)4 UpdateDataStorageItemVO (com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO)3 DataStorageDownloadFileUrl (com.epam.pipeline.entity.datastorage.DataStorageDownloadFileUrl)3 DataStorageException (com.epam.pipeline.entity.datastorage.DataStorageException)3 DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)3 DataStorageLink (com.epam.pipeline.entity.pipeline.run.parameter.DataStorageLink)3 ObjectCreatorUtils.constructDataStorageVO (com.epam.pipeline.manager.ObjectCreatorUtils.constructDataStorageVO)3 IOException (java.io.IOException)3 MessageConstants (com.epam.pipeline.common.MessageConstants)2