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