Search in sources :

Example 56 with AbstractDataStorage

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

the class DataStorageManagerTest method testFailUpdateOfStorageWithForbiddenMountPoint.

@Test(expected = IllegalArgumentException.class)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testFailUpdateOfStorageWithForbiddenMountPoint() {
    DataStorageVO storageVO = ObjectCreatorUtils.constructDataStorageVO(NAME, DESCRIPTION, DataStorageType.NFS, PATH, WITHOUT_PARENT_ID, TEST_MOUNT_POINT, TEST_MOUNT_OPTIONS);
    AbstractDataStorage saved = storageManager.create(storageVO, false, false, false);
    storageVO.setId(saved.getId());
    storageVO.setMountPoint(FORBIDDEN_MOUNT_POINT);
    storageManager.update(storageVO);
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageVO(com.epam.pipeline.controller.vo.DataStorageVO) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with AbstractDataStorage

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

the class FolderManagerTest method shouldCloneFolderWithDataStorages.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void shouldCloneFolderWithDataStorages() {
    Folder sourceFolder = new Folder();
    sourceFolder.setName(FOLDER_TO_CLONE);
    folderManager.create(sourceFolder);
    DataStorageVO dataStorageVO = constructDataStorageVO(TEST_NAME, TEST_DESCRIPTION, DataStorageType.S3, TEST_PATH, STS_DURATION, LTS_DURATION, sourceFolder.getId(), TEST_MOUNT_POINT, TEST_MOUNT_OPTIONS);
    StoragePolicy storagePolicy = dataStorageVO.getStoragePolicy();
    storagePolicy.setBackupDuration(BACKUP_DURATION);
    dataStorageVO.setStoragePolicy(storagePolicy);
    AbstractDataStorage expectedDataStorage = dataStorageManager.create(dataStorageVO, true, true, false);
    Folder childSourceFolder = new Folder();
    childSourceFolder.setName(CHILD_FOLDER_TO_CLONE);
    childSourceFolder.setParentId(sourceFolder.getId());
    folderManager.create(childSourceFolder);
    dataStorageVO.setParentFolderId(childSourceFolder.getId());
    dataStorageVO.setName(TEST_NAME_1);
    dataStorageVO.setPath(TEST_NAME_1);
    dataStorageManager.create(dataStorageVO, true, true, false);
    Folder destinationFolder = new Folder();
    destinationFolder.setName(TEST_NAME);
    folderManager.create(destinationFolder);
    folderManager.cloneFolder(sourceFolder.getId(), destinationFolder.getId(), TEST_CLONE_PREFIX);
    destinationFolder = folderManager.loadByNameOrId(TEST_NAME);
    destinationFolder = folderManager.load(destinationFolder.getId());
    Folder clonedFolder = destinationFolder.getChildFolders().get(0);
    AbstractDataStorage clonedDataStorage = clonedFolder.getStorages().get(0);
    clonedDataStorage = dataStorageManager.load(clonedDataStorage.getId());
    assertTrue(clonedDataStorage.getName().startsWith(TEST_CLONE_PREFIX + storageSuffix));
    assertTrue(clonedDataStorage.getPath().startsWith((TEST_CLONE_PREFIX + storageSuffix).toLowerCase()));
    assertDataStorages(expectedDataStorage, clonedDataStorage);
    Folder clonedChildFolder = clonedFolder.getChildFolders().get(0);
    clonedDataStorage = clonedChildFolder.getStorages().get(0);
    clonedDataStorage = dataStorageManager.load(clonedDataStorage.getId());
    assertTrue(clonedDataStorage.getName().startsWith(TEST_CLONE_PREFIX + storageSuffix));
    assertTrue(clonedDataStorage.getPath().startsWith((TEST_CLONE_PREFIX + storageSuffix).toLowerCase()));
    assertDataStorages(expectedDataStorage, clonedDataStorage);
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageVO(com.epam.pipeline.controller.vo.DataStorageVO) ObjectCreatorUtils.constructDataStorageVO(com.epam.pipeline.manager.ObjectCreatorUtils.constructDataStorageVO) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) Folder(com.epam.pipeline.entity.pipeline.Folder) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 58 with AbstractDataStorage

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

the class FolderManagerTest method loadFolderWithPipelineAndStorage.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void loadFolderWithPipelineAndStorage() throws Exception {
    folderManager.create(folder);
    PipelineVO pipelineVO = constructPipelineVO(TEST_NAME, TEST_REPO, folder.getId());
    DataStorageVO storageVO = constructDataStorageVO(TEST_NAME, TEST_DESCRIPTION, DataStorageType.S3, TEST_PATH, STS_DURATION, LTS_DURATION, folder.getId(), TEST_MOUNT_POINT, TEST_MOUNT_OPTIONS);
    Pipeline pipeline = pipelineManager.create(pipelineVO);
    AbstractDataStorage storage = dataStorageManager.create(storageVO, false, false, false);
    Folder loaded = folderManager.load(folder.getId());
    Pipeline loadedPipe = loaded.getPipelines().get(0);
    assertNotNull(loadedPipe);
    assertEquals(pipeline.getId(), loadedPipe.getId());
    assertEquals(pipeline.getName(), loadedPipe.getName());
    assertEquals(pipeline.getParentFolderId(), loadedPipe.getParentFolderId());
    AbstractDataStorage loadedStorage = loaded.getStorages().get(0);
    assertNotNull(loadedStorage);
    assertEquals(storage.getId(), loadedStorage.getId());
    assertEquals(storage.getName(), loadedStorage.getName());
    assertEquals(storage.getParentFolderId(), loadedStorage.getParentFolderId());
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageVO(com.epam.pipeline.controller.vo.DataStorageVO) ObjectCreatorUtils.constructDataStorageVO(com.epam.pipeline.manager.ObjectCreatorUtils.constructDataStorageVO) Folder(com.epam.pipeline.entity.pipeline.Folder) ObjectCreatorUtils.constructPipelineVO(com.epam.pipeline.manager.ObjectCreatorUtils.constructPipelineVO) PipelineVO(com.epam.pipeline.controller.vo.PipelineVO) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with AbstractDataStorage

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

the class FolderManagerTest method deleteFolderAfterMovingPipelineAndStorage.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void deleteFolderAfterMovingPipelineAndStorage() throws Exception {
    folderManager.create(folder);
    PipelineVO pipelineVO = constructPipelineVO(TEST_NAME, TEST_REPO, folder.getId());
    DataStorageVO storageVO = constructDataStorageVO(TEST_NAME, TEST_DESCRIPTION, DataStorageType.S3, TEST_PATH, STS_DURATION, LTS_DURATION, folder.getId(), TEST_MOUNT_POINT, TEST_MOUNT_OPTIONS);
    Pipeline pipeline = pipelineManager.create(pipelineVO);
    AbstractDataStorage storage = dataStorageManager.create(storageVO, false, false, false);
    pipelineVO.setId(pipeline.getId());
    pipelineVO.setParentFolderId(null);
    pipelineManager.update(pipelineVO);
    storageVO.setParentFolderId(null);
    storageVO.setId(storage.getId());
    dataStorageManager.update(storageVO);
    folderManager.delete(folder.getId());
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageVO(com.epam.pipeline.controller.vo.DataStorageVO) ObjectCreatorUtils.constructDataStorageVO(com.epam.pipeline.manager.ObjectCreatorUtils.constructDataStorageVO) ObjectCreatorUtils.constructPipelineVO(com.epam.pipeline.manager.ObjectCreatorUtils.constructPipelineVO) PipelineVO(com.epam.pipeline.controller.vo.PipelineVO) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with AbstractDataStorage

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

the class NFSSynchronizer method createDocuments.

private void createDocuments(final String indexName, final Path mountFolder, final AbstractDataStorage dataStorage, final PermissionsContainer permissionsContainer) {
    try (Stream<Path> files = Files.walk(mountFolder);
        IndexRequestContainer walker = new IndexRequestContainer(requests -> elasticsearchServiceClient.sendRequests(indexName, requests), bulkInsertSize)) {
        files.filter(file -> file.toFile().isFile()).forEach(file -> {
            IndexRequest request = new IndexRequest(indexName, DOC_MAPPING_TYPE).source(dataStorageToDocument(getLastModified(file), getSize(file), getRelativePath(mountFolder, file), dataStorage.getId(), dataStorage.getName(), permissionsContainer));
            walker.add(request);
        });
    } catch (IOException e) {
        throw new IllegalArgumentException("An error occurred during creating document.", e);
    }
}
Also used : Path(java.nio.file.Path) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) ElasticsearchSynchronizer(com.epam.pipeline.elasticsearchagent.service.ElasticsearchSynchronizer) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchServiceClient(com.epam.pipeline.elasticsearchagent.service.ElasticsearchServiceClient) Value(org.springframework.beans.factory.annotation.Value) IndexRequest(org.elasticsearch.action.index.IndexRequest) Matcher(java.util.regex.Matcher) Service(org.springframework.stereotype.Service) SearchDocumentType(com.epam.pipeline.entity.search.SearchDocumentType) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) Path(java.nio.file.Path) Files(java.nio.file.Files) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) IOException(java.io.IOException) DataStorageType(com.epam.pipeline.entity.datastorage.DataStorageType) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) PermissionsContainer(com.epam.pipeline.elasticsearchagent.model.PermissionsContainer) Pattern(java.util.regex.Pattern) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) StringUtils(org.springframework.util.StringUtils) IOException(java.io.IOException) IndexRequest(org.elasticsearch.action.index.IndexRequest)

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