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