use of com.epam.pipeline.elasticsearchagent.model.PermissionsContainer 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);
}
}
}
use of com.epam.pipeline.elasticsearchagent.model.PermissionsContainer in project cloud-pipeline by epam.
the class NFSSynchronizer 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);
String storageName = getStorageName(dataStorage.getPath());
Path mountFolder = Paths.get(rootMountPoint, getMountDirName(dataStorage.getPath()), storageName);
createDocuments(indexName, mountFolder, dataStorage, permissionsContainer);
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);
}
}
}
use of com.epam.pipeline.elasticsearchagent.model.PermissionsContainer in project cloud-pipeline by epam.
the class AbstractCloudPipelineEntityLoader method loadPermissions.
protected PermissionsContainer loadPermissions(final Long id, final AclClass entityClass) {
PermissionsContainer permissionsContainer = new PermissionsContainer();
if (entityClass == null) {
return permissionsContainer;
}
EntityPermissionVO entityPermission = apiClient.loadPermissionsForEntity(id, entityClass);
if (entityPermission != null) {
String owner = entityPermission.getOwner();
permissionsContainer.add(entityPermission.getPermissions(), owner);
}
return permissionsContainer;
}
use of com.epam.pipeline.elasticsearchagent.model.PermissionsContainer 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);
}
}
use of com.epam.pipeline.elasticsearchagent.model.PermissionsContainer in project cloud-pipeline by epam.
the class PipelineRunLoader method loadPermissions.
@Override
protected PermissionsContainer loadPermissions(final Long id, final AclClass entityClass) {
PipelineRun run = getApiClient().loadPipelineRun(id);
Long pipelineId = run.getPipelineId();
if (pipelineId == null) {
PermissionsContainer permissionsContainer = new PermissionsContainer();
permissionsContainer.add(Collections.emptyList(), run.getOwner());
return permissionsContainer;
}
return super.loadPermissions(pipelineId, AclClass.PIPELINE);
}
Aggregations