Search in sources :

Example 1 with AbstractRunConfigurationEntry

use of com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry in project cloud-pipeline by epam.

the class ParameterMapper method resolveParameters.

/**
 * Gets configuration for a list of {@link AbstractRunConfigurationEntry} resolving
 * template parameters from
 * @param entity        to use for parameters template mapping
 * @param entries       to resolve
 * @param projectData   metadata of associated project {@link com.epam.pipeline.entity.pipeline.Folder}
 * @return configuration for all input entries
 */
public ResolvedConfiguration resolveParameters(MetadataEntity entity, List<? extends AbstractRunConfigurationEntry> entries, Map<String, PipeConfValue> projectData) {
    if (CollectionUtils.isEmpty(entries)) {
        return new ResolvedConfiguration(entity, Collections.emptyMap());
    }
    if (entity == null) {
        return new ResolvedConfiguration(null, entries.stream().collect(Collectors.toMap(AbstractRunConfigurationEntry::getName, this::getEntryConfiguration)));
    }
    Map<MetadataKey, MetadataEntity> entityReferences = loadReferences(entity);
    Map<String, PipelineConfiguration> resolved = new HashMap<>();
    entries.forEach(entry -> {
        checkClassIdMatch(entity, entry.getRootEntityId());
        PipelineConfiguration configuration = getEntryConfiguration(entry);
        if (MapUtils.isNotEmpty(configuration.getParameters())) {
            configuration.setParameters(mapParameters(entity, projectData, configuration.getParameters(), entityReferences));
        }
        resolved.put(entry.getName(), configuration);
    });
    return new ResolvedConfiguration(entity, resolved);
}
Also used : ResolvedConfiguration(com.epam.pipeline.entity.pipeline.ResolvedConfiguration) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) HashMap(java.util.HashMap) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration)

Example 2 with AbstractRunConfigurationEntry

use of com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry in project cloud-pipeline by epam.

the class ParameterMapper method resolveConfigurations.

public List<ResolvedConfiguration> resolveConfigurations(AnalysisConfiguration<? extends AbstractRunConfigurationEntry> configuration) {
    FolderWithMetadata project = folderManager.getProject(configuration.getConfigurationId(), AclClass.CONFIGURATION);
    Map<String, PipeConfValue> projectData = project == null ? new HashMap<>() : project.getData();
    List<? extends AbstractRunConfigurationEntry> entries = configuration.getEntries();
    if (CollectionUtils.isEmpty(configuration.getEntitiesIds())) {
        return Collections.singletonList(resolveParameters(entries, projectData));
    }
    // In case of array references one entity may be expanded to
    // list of references entities, e.g. SampleSet is expanded
    // to list of Sample entities
    // TODO: The only reason to store it as map - is to add association to run
    // TODO: to initial entity, from which link comes. Find better solution.
    Map<Long, List<MetadataEntity>> targetEntities = fetchAndExpandInputEntities(configuration);
    // resolve all parameter references in configurations
    Map<Long, ResolvedConfiguration> resolvedConfigurations = targetEntities.values().stream().flatMap(Collection::stream).collect(Collectors.toMap(BaseEntity::getId, entity -> resolveParameters(entity, entries, projectData)));
    return targetEntities.entrySet().stream().map(idToEntities -> idToEntities.getValue().stream().map(entity -> {
        ResolvedConfiguration currentConfiguration = resolvedConfigurations.get(entity.getId());
        currentConfiguration.getAssociatedEntityIds().add(idToEntities.getKey());
        return currentConfiguration;
    }).collect(Collectors.toList())).flatMap(Collection::stream).collect(Collectors.toList());
}
Also used : EntityTypeField(com.epam.pipeline.manager.metadata.parser.EntityTypeField) Setter(lombok.Setter) Getter(lombok.Getter) MessageConstants(com.epam.pipeline.common.MessageConstants) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) PipeConfValueVO(com.epam.pipeline.entity.configuration.PipeConfValueVO) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MessageHelper(com.epam.pipeline.common.MessageHelper) AnalysisConfiguration(com.epam.pipeline.manager.pipeline.runner.AnalysisConfiguration) Service(org.springframework.stereotype.Service) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) MapUtils(org.apache.commons.collections4.MapUtils) BaseEntity(com.epam.pipeline.entity.BaseEntity) Logger(org.slf4j.Logger) Collection(java.util.Collection) JsonMapper(com.epam.pipeline.config.JsonMapper) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) ResolvedConfiguration(com.epam.pipeline.entity.pipeline.ResolvedConfiguration) Objects(java.util.Objects) List(java.util.List) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) MetadataEntityManager(com.epam.pipeline.manager.metadata.MetadataEntityManager) AclClass(com.epam.pipeline.entity.security.acl.AclClass) PipelineStart(com.epam.pipeline.entity.pipeline.run.PipelineStart) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) Assert(org.springframework.util.Assert) ResolvedConfiguration(com.epam.pipeline.entity.pipeline.ResolvedConfiguration) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) ArrayList(java.util.ArrayList) List(java.util.List) FolderWithMetadata(com.epam.pipeline.entity.metadata.FolderWithMetadata)

Example 3 with AbstractRunConfigurationEntry

use of com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry in project cloud-pipeline by epam.

the class ConfigurationRunner method runConfiguration.

/**
 * Schedules execution of a {@link RunConfiguration} and creates a number
 * of associated {@link PipelineRun} instances. Default values of {@link RunConfiguration}
 * may be overriden by {@code runConfiguration} parameter. If {@code entitiesIds} or {@code metadataClass}
 * are passed method will try to resolve {@link RunConfiguration} parameters according to
 * {@link MetadataEntity} instances. For {@code metadataClass} method will try to find
 * {@link MetadataEntity} instances in the whole project with matching {@link MetadataClass}.
 * For each resolved {@link MetadataEntity} instance a separate {@link PipelineRun} or several ones
 * will be created.
 *
 * @param refreshToken      authorization token for Firecloud
 * @param runConfiguration  to run. Must specify {@code id} parameter of existing in DB
 *                          {@link RunConfiguration} instance. Any other parameter may be specified,
 *                          in this case it will override the same parameter from DB instance.
 *                          For cluster (producing several {@link PipelineRun}) configurations if a list of
 *                          {@link RunConfigurationEntry} is passed in {@code entries} field,
 *                          only entries from this list will be scheduled. If {@code entitiesIds} are specified in
 *                          {@link RunConfigurationWithEntitiesVO} for each entity id a separate run(s)
 *                          of {@link RunConfiguration} will be scheduled. If {@code metadataClass} is set
 *                          a separate run(s) will be scheduled for each {@link MetadataEntity} instance
 *                          with a matching {@link MetadataClass} in current project.
 * @param expansionExpression   expression to convert actual entities from {@code entitiesIds}
 *                              to required {@code rootEntityId} specified in {@link RunConfigurationEntry}
 * @return list of scheduled {@link PipelineRun}
 */
public List<PipelineRun> runConfiguration(String refreshToken, RunConfigurationWithEntitiesVO runConfiguration, String expansionExpression) {
    RunConfiguration dbConfiguration = configurationManager.load(runConfiguration.getId());
    RunConfiguration configuration = mergeRunConfigurations(dbConfiguration, runConfigurationMapper.toRunConfiguration(runConfiguration));
    configurationManager.validateConfiguration(configuration);
    configuration.getEntries().forEach(entry -> configurationProvider.assertExecutionEnvironment(entry));
    List<Long> entitiesIds = getIdsToProcess(runConfiguration);
    return configuration.getEntries().stream().collect(Collectors.groupingBy(AbstractRunConfigurationEntry::getExecutionEnvironment)).entrySet().stream().map(env -> {
        AnalysisConfiguration<AbstractRunConfigurationEntry> conf = AnalysisConfiguration.builder().configurationId(configuration.getId()).entries(env.getValue()).entitiesIds(entitiesIds).expansionExpression(expansionExpression).refreshToken(refreshToken).build();
        return configurationProvider.runAnalysis(conf);
    }).flatMap(Collection::stream).collect(Collectors.toList());
}
Also used : RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry)

Example 4 with AbstractRunConfigurationEntry

use of com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry in project cloud-pipeline by epam.

the class ConfigurationProviderManager method runAnalysis.

public List<PipelineRun> runAnalysis(AnalysisConfiguration<AbstractRunConfigurationEntry> configuration) {
    checkAllEntriesOfTheSameType(configuration.getEntries());
    AbstractRunConfigurationEntry entry = configuration.getEntries().get(0);
    return getConfigurationProvider(entry).runAnalysis(configuration);
}
Also used : AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry)

Example 5 with AbstractRunConfigurationEntry

use of com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry in project cloud-pipeline by epam.

the class ConfigurationEntryMapper method getContentBuilder.

private XContentBuilder getContentBuilder(final EntityContainer<ConfigurationEntryDoc> container) {
    RunConfiguration configuration = container.getEntity().getConfiguration();
    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        jsonBuilder.startObject();
        AbstractRunConfigurationEntry entry = container.getEntity().getEntry();
        jsonBuilder.field(DOC_TYPE_FIELD, SearchDocumentType.CONFIGURATION.name()).field("id", container.getEntity().getId()).field("name", Optional.ofNullable(entry).map(AbstractRunConfigurationEntry::getName).orElse(configuration.getName())).field("description", configuration.getName() + " " + StringUtils.defaultIfBlank(configuration.getDescription(), StringUtils.EMPTY)).field("createdDate", parseDataToString(configuration.getCreatedDate())).field("parentId", Optional.ofNullable(configuration.getParent()).map(BaseEntity::getId).orElse(null));
        buildUserContent(container.getOwner(), jsonBuilder);
        buildMetadata(container.getMetadata(), jsonBuilder);
        buildPermissions(container.getPermissions(), jsonBuilder);
        if (entry != null) {
            buildConfigurationEntry(entry, container.getEntity().getPipeline(), jsonBuilder);
        }
        jsonBuilder.endObject();
        return jsonBuilder;
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to create elasticsearch document for run configuration: ", e);
    }
}
Also used : RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) BaseEntity(com.epam.pipeline.entity.BaseEntity) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

AbstractRunConfigurationEntry (com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry)5 BaseEntity (com.epam.pipeline.entity.BaseEntity)2 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)2 RunConfiguration (com.epam.pipeline.entity.configuration.RunConfiguration)2 MetadataEntity (com.epam.pipeline.entity.metadata.MetadataEntity)2 ResolvedConfiguration (com.epam.pipeline.entity.pipeline.ResolvedConfiguration)2 HashMap (java.util.HashMap)2 MessageConstants (com.epam.pipeline.common.MessageConstants)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 JsonMapper (com.epam.pipeline.config.JsonMapper)1 PipeConfValueVO (com.epam.pipeline.entity.configuration.PipeConfValueVO)1 FolderWithMetadata (com.epam.pipeline.entity.metadata.FolderWithMetadata)1 PipeConfValue (com.epam.pipeline.entity.metadata.PipeConfValue)1 PipelineStart (com.epam.pipeline.entity.pipeline.run.PipelineStart)1 AclClass (com.epam.pipeline.entity.security.acl.AclClass)1 MetadataEntityManager (com.epam.pipeline.manager.metadata.MetadataEntityManager)1 EntityTypeField (com.epam.pipeline.manager.metadata.parser.EntityTypeField)1 AnalysisConfiguration (com.epam.pipeline.manager.pipeline.runner.AnalysisConfiguration)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 IOException (java.io.IOException)1