Search in sources :

Example 1 with S3Helper

use of com.epam.pipeline.elasticsearchagent.utils.S3Helper 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

PermissionsContainer (com.epam.pipeline.elasticsearchagent.model.PermissionsContainer)1 BulkRequestCreator (com.epam.pipeline.elasticsearchagent.service.BulkRequestCreator)1 ElasticsearchServiceClient (com.epam.pipeline.elasticsearchagent.service.ElasticsearchServiceClient)1 ElasticsearchSynchronizer (com.epam.pipeline.elasticsearchagent.service.ElasticsearchSynchronizer)1 S3Helper (com.epam.pipeline.elasticsearchagent.utils.S3Helper)1 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)1 AbstractTemporaryCredentials (com.epam.pipeline.entity.datastorage.AbstractTemporaryCredentials)1 DataStorageAction (com.epam.pipeline.entity.datastorage.DataStorageAction)1 DataStorageType (com.epam.pipeline.entity.datastorage.DataStorageType)1 PasswordGenerator.generateRandomString (com.epam.pipeline.utils.PasswordGenerator.generateRandomString)1 EntityPermissionVO (com.epam.pipeline.vo.EntityPermissionVO)1 LocalDateTime (java.time.LocalDateTime)1 Collections (java.util.Collections)1 List (java.util.List)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Value (org.springframework.beans.factory.annotation.Value)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1 Service (org.springframework.stereotype.Service)1 StringUtils (org.springframework.util.StringUtils)1