Search in sources :

Example 1 with PermissionsContainer

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

Example 2 with PermissionsContainer

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);
        }
    }
}
Also used : Path(java.nio.file.Path) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) PermissionsContainer(com.epam.pipeline.elasticsearchagent.model.PermissionsContainer) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) IOException(java.io.IOException)

Example 3 with PermissionsContainer

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;
}
Also used : EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) PermissionsContainer(com.epam.pipeline.elasticsearchagent.model.PermissionsContainer)

Example 4 with 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);
    }
}
Also used : Path(java.nio.file.Path) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) ElasticsearchSynchronizer(com.epam.pipeline.elasticsearchagent.service.ElasticsearchSynchronizer) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticsearchServiceClient(com.epam.pipeline.elasticsearchagent.service.ElasticsearchServiceClient) Value(org.springframework.beans.factory.annotation.Value) IndexRequest(org.elasticsearch.action.index.IndexRequest) Matcher(java.util.regex.Matcher) Service(org.springframework.stereotype.Service) SearchDocumentType(com.epam.pipeline.entity.search.SearchDocumentType) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) Path(java.nio.file.Path) Files(java.nio.file.Files) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) IOException(java.io.IOException) DataStorageType(com.epam.pipeline.entity.datastorage.DataStorageType) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) PermissionsContainer(com.epam.pipeline.elasticsearchagent.model.PermissionsContainer) Pattern(java.util.regex.Pattern) EntityPermissionVO(com.epam.pipeline.vo.EntityPermissionVO) StringUtils(org.springframework.util.StringUtils) IOException(java.io.IOException) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 5 with PermissionsContainer

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);
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PermissionsContainer(com.epam.pipeline.elasticsearchagent.model.PermissionsContainer)

Aggregations

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