use of com.epam.pipeline.elasticsearchagent.service.BulkRequestCreator 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