Search in sources :

Example 26 with AbstractDataStorage

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

the class DataStorageManager method updateDataStorageItems.

public List<AbstractDataStorageItem> updateDataStorageItems(final Long dataStorageId, List<UpdateDataStorageItemVO> list) throws DataStorageException {
    AbstractDataStorage dataStorage = load(dataStorageId);
    List<AbstractDataStorageItem> updatedItems = new ArrayList<>();
    for (UpdateDataStorageItemVO item : list) {
        updatedItems.add(updateDataStorageItem(dataStorage, item));
    }
    return updatedItems;
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) UpdateDataStorageItemVO(com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO) AbstractDataStorageItem(com.epam.pipeline.entity.datastorage.AbstractDataStorageItem) ArrayList(java.util.ArrayList)

Example 27 with AbstractDataStorage

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

the class DataStorageEventService method updateEventsWithChildrenAndIssues.

@Override
public void updateEventsWithChildrenAndIssues(final Long id) {
    AbstractDataStorage dataStorage = dataStorageManager.load(id);
    eventManager.addUpdateEventsForIssues(id, AclClass.DATA_STORAGE);
    eventManager.addUpdateEvent(dataStorage.getType().name(), id);
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage)

Example 28 with AbstractDataStorage

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

the class AttachmentFileManager method downloadAttachment.

public DataStorageStreamingContent downloadAttachment(long attachmentId) {
    String systemDataStorageName = preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME);
    Assert.notNull(systemDataStorageName, messageHelper.getMessage(MessageConstants.ERROR_ATTACHMENT_SYSTEM_DATA_STORAGE_NOT_CONFIGURED));
    AbstractDataStorage attachmentStorage = dataStorageManager.loadByNameOrId(systemDataStorageName);
    Attachment attachment = attachmentManager.load(attachmentId);
    DataStorageStreamingContent content = dataStorageManager.getStreamingContent(attachmentStorage.getId(), attachment.getPath(), null);
    return new DataStorageStreamingContent(content.getContent(), attachment.getName());
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) Attachment(com.epam.pipeline.entity.issue.Attachment)

Example 29 with AbstractDataStorage

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

the class FolderTemplateManagerTest method createFolderFromTemplateTest.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = TEST_USER)
public void createFolderFromTemplateTest() throws IOException {
    Map<String, PipeConfValue> metadata = new HashMap<>();
    metadata.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
    DataStorageWithMetadataVO dataStorageVO = new DataStorageWithMetadataVO();
    dataStorageVO.setName(DATASTORAGE_NAME_1);
    dataStorageVO.setType(DataStorageType.S3);
    dataStorageVO.setPath(TEST_PATH);
    dataStorageVO.setMetadata(metadata);
    PermissionVO permissionVO = new PermissionVO();
    permissionVO.setMask(AclPermission.READ.getMask());
    permissionVO.setUserName(TEST_ROLE);
    permissionVO.setPrincipal(false);
    FolderTemplate childFolderTemplate1 = FolderTemplate.builder().name(CHILD_TEMPLATE_FOLDER_NAME_1).build();
    FolderTemplate folderTemplate = FolderTemplate.builder().name(TEMPLATE_FOLDER_NAME).datastorages(Stream.of(dataStorageVO).collect(Collectors.toList())).children(Stream.of(childFolderTemplate1).collect(Collectors.toList())).metadata(metadata).permissions(Stream.of(permissionVO).collect(Collectors.toList())).build();
    Folder folder = new Folder();
    folder.setName(TEMPLATE_FOLDER_NAME);
    folderTemplateManager.createFolderFromTemplate(folder, folderTemplate);
    Folder savedRootFolder = folderManager.loadByNameOrId(TEMPLATE_FOLDER_NAME);
    savedRootFolder = folderManager.load(savedRootFolder.getId());
    Assert.assertNotNull(savedRootFolder);
    Long rootFolderId = savedRootFolder.getId();
    List<EntityVO> metadataEntries = Collections.singletonList(new EntityVO(rootFolderId, AclClass.FOLDER));
    Assert.assertEquals(metadata, metadataManager.listMetadataItems(metadataEntries).get(0).getData());
    AbstractDataStorage clonedDataStorage = savedRootFolder.getStorages().get(0);
    clonedDataStorage = dataStorageManager.load(clonedDataStorage.getId());
    Assert.assertTrue(clonedDataStorage.getName().startsWith(DATASTORAGE_NAME_1));
    Assert.assertTrue(clonedDataStorage.getPath().startsWith(TEST_PATH));
    metadataEntries = Collections.singletonList(new EntityVO(clonedDataStorage.getId(), AclClass.DATA_STORAGE));
    Assert.assertEquals(metadata, metadataManager.listMetadataItems(metadataEntries).get(0).getData());
    List<AclPermissionEntry> rootFolderPermissions = permissionManager.getPermissions(rootFolderId, AclClass.FOLDER).getPermissions();
    Assert.assertEquals(1, rootFolderPermissions.size());
    AclPermissionEntry actualPermission = rootFolderPermissions.get(0);
    Assert.assertEquals(permissionVO.getMask(), actualPermission.getMask());
    Assert.assertEquals(permissionVO.getPrincipal(), actualPermission.getSid().isPrincipal());
    Assert.assertEquals(permissionVO.getUserName(), actualPermission.getSid().getName());
    Folder savedChildFolder = folderManager.loadByNameOrId(TEMPLATE_FOLDER_NAME + "/" + CHILD_TEMPLATE_FOLDER_NAME_1);
    Assert.assertNotNull(savedChildFolder);
    Assert.assertEquals(rootFolderId, savedChildFolder.getParentId());
}
Also used : HashMap(java.util.HashMap) FolderTemplate(com.epam.pipeline.entity.templates.FolderTemplate) Folder(com.epam.pipeline.entity.pipeline.Folder) EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) AclPermissionEntry(com.epam.pipeline.entity.security.acl.AclPermissionEntry) DataStorageWithMetadataVO(com.epam.pipeline.controller.vo.data.storage.DataStorageWithMetadataVO) PermissionVO(com.epam.pipeline.controller.vo.PermissionVO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with AbstractDataStorage

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

the class S3Synchronizer method createIndexAndDocuments.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
void createIndexAndDocuments(final AbstractDataStorage dataStorage) {
    EntityPermissionVO entityPermission = cloudPipelineAPIClient.loadPermissionsForEntity(dataStorage.getId(), dataStorage.getAclClass());
    PermissionsContainer permissionsContainer = new PermissionsContainer();
    if (entityPermission != null) {
        permissionsContainer.add(entityPermission.getPermissions(), dataStorage.getOwner());
    }
    String alias = indexPrefix + indexName + String.format("-%d", dataStorage.getId());
    String indexName = generateRandomString(5).toLowerCase() + "-" + alias;
    try {
        String currentIndexName = elasticsearchServiceClient.getIndexNameByAlias(alias);
        elasticIndexService.createIndexIfNotExist(indexName, indexSettingsPath);
        DataStorageAction action = new DataStorageAction();
        action.setBucketName(dataStorage.getPath());
        action.setId(dataStorage.getId());
        action.setWrite(false);
        action.setRead(true);
        AbstractTemporaryCredentials credentials = cloudPipelineAPIClient.generateTemporaryCredentials(Collections.singletonList(action));
        BulkRequestCreator bulkRequestCreator = requests -> elasticsearchServiceClient.sendRequests(indexName, requests);
        S3Helper s3Helper = new S3Helper(enableTags, credentials, bulkRequestCreator, dataStorage, indexName, bulkInsertSize, permissionsContainer);
        s3Helper.addItems();
        elasticsearchServiceClient.createIndexAlias(indexName, alias);
        if (StringUtils.hasText(currentIndexName)) {
            elasticsearchServiceClient.deleteIndex(currentIndexName);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if (elasticsearchServiceClient.isIndexExists(indexName)) {
            elasticsearchServiceClient.deleteIndex(indexName);
        }
    }
}
Also used : AbstractTemporaryCredentials(com.epam.pipeline.entity.datastorage.AbstractTemporaryCredentials) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) LocalDateTime(java.time.LocalDateTime) ElasticsearchSynchronizer(com.epam.pipeline.elasticsearchagent.service.ElasticsearchSynchronizer) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageType(com.epam.pipeline.entity.datastorage.DataStorageType) ElasticsearchServiceClient(com.epam.pipeline.elasticsearchagent.service.ElasticsearchServiceClient) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) S3Helper(com.epam.pipeline.elasticsearchagent.utils.S3Helper) Value(org.springframework.beans.factory.annotation.Value) BulkRequestCreator(com.epam.pipeline.elasticsearchagent.service.BulkRequestCreator) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Service(org.springframework.stereotype.Service) PermissionsContainer(com.epam.pipeline.elasticsearchagent.model.PermissionsContainer) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) Collections(java.util.Collections) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) StringUtils(org.springframework.util.StringUtils) S3Helper(com.epam.pipeline.elasticsearchagent.utils.S3Helper) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) PermissionsContainer(com.epam.pipeline.elasticsearchagent.model.PermissionsContainer) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) AbstractTemporaryCredentials(com.epam.pipeline.entity.datastorage.AbstractTemporaryCredentials) BulkRequestCreator(com.epam.pipeline.elasticsearchagent.service.BulkRequestCreator)

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