use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class AbstractArtifactPostProcessor method process.
@Override
public void process(AbstractArtifact instance) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
postProcessArtifactRef(node, instance.getArtifactRef());
ArchiveRoot archiveRoot = ParsingContextExecution.getRootObj();
// If archive name is already defined (by the type for example then don't override it)
if (StringUtils.isBlank(instance.getArchiveName())) {
instance.setArchiveName(archiveRoot.getArchive().getName());
instance.setArchiveVersion(archiveRoot.getArchive().getVersion());
}
if (instance.getArtifactType() == null) {
// try to get type from extension
instance.setArtifactType(getArtifactTypeByExtension(instance.getArtifactRef(), node, archiveRoot));
} else {
// check the type reference
referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getArtifactType(), ArtifactType.class));
}
if (instance.getRepositoryName() != null) {
RepositoryDefinition repositoryDefinition = archiveRoot.getRepositories() != null ? archiveRoot.getRepositories().get(instance.getRepositoryName()) : null;
if (repositoryDefinition == null) {
// Sometimes the information about repository has already been filled in the parent type
if (instance.getRepositoryURL() == null) {
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.UNKNOWN_REPOSITORY, "Implementation artifact", node.getStartMark(), "Repository definition not found", node.getEndMark(), instance.getArtifactRepository()));
}
} else {
instance.setRepositoryURL(repositoryDefinition.getUrl());
instance.setRepositoryCredential(repositoryDefinition.getCredential() != null ? repositoryDefinition.getCredential().getValue() : null);
instance.setRepositoryName(repositoryDefinition.getId());
instance.setArtifactRepository(repositoryDefinition.getType());
}
}
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ArchiveRootPostProcessor method processImports.
/**
* Process imports within the archive and compute its complete dependency set.
* Resolve all dependency version conflicts using the following rules:
* <ul>
* <li>If two direct dependencies conflict with each other, use the latest version</li>
* <li>If a transitive dependency conflicts with a direct dependency, use the direct dependency version</li>
* <li>If two transitive dependency conflict with each other, use the latest version.</li>
* </ul>
*
* @param archiveRoot The archive to process.
*/
private void processImports(ArchiveRoot archiveRoot) {
if (archiveRoot.getArchive().getDependencies() == null || archiveRoot.getArchive().getDependencies().isEmpty()) {
return;
}
// Dependencies defined in the import section only
// These should override transitive deps regardless of type of conflict ?
Set<CSARDependency> dependencies = archiveRoot.getArchive().getDependencies();
// Ensure the archive does not import itself
Csar archive = archiveRoot.getArchive();
if (dependencies.contains(new CSARDependency(archive.getName(), archive.getVersion(), archive.getHash()))) {
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.CSAR_IMPORT_ITSELF, AlienUtils.prefixWith(":", archive.getVersion(), archive.getName()), null, "Import itself", null, null));
}
/*
* Three types of conflicts :
* - A transitive dep has a different version than a direct dependency => Force transitive to direct version
* - Transitive dependencies with the same name and different version are used => Use latest
* - Direct dependencies with the same name and different version are used => Error or use latest ?
*/
// 1. Resolve all direct dependencies using latest version
dependencies.removeIf(dependency -> dependencyConflictsWithLatest(dependency, dependencies));
// Compute all distinct transitives dependencies
final Set<CSARDependency> transitiveDependencies = new HashSet<>(dependencies.stream().map(csarDependency -> ToscaContext.get().getArchive(csarDependency.getName(), csarDependency.getVersion())).map(Csar::getDependencies).filter(c -> c != null).reduce(Sets::union).orElse(Collections.emptySet()));
// 2. Resolve all transitive vs. direct dependencies conflicts using the direct dependency's version
transitiveDependencies.removeIf(transitiveDependency -> dependencyConflictsWithDirect(transitiveDependency, dependencies));
// 3. Resolve all transitive dependencies conflicts using latest version
transitiveDependencies.removeIf(transitiveDependency -> dependencyConflictsWithLatest(transitiveDependency, transitiveDependencies));
// Merge all dependencies (direct + transitives)
final Set<CSARDependency> mergedDependencies = new HashSet<>(Sets.union(dependencies, transitiveDependencies));
archiveRoot.getArchive().setDependencies(mergedDependencies);
// Update Tosca context with the complete dependency set
ToscaContext.get().resetDependencies(mergedDependencies);
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaArchiveParser method initFromToscaMeta.
private ArchiveRoot initFromToscaMeta(ParsingResult<ToscaMeta> toscaMeta) {
ArchiveRoot archiveRoot = new ArchiveRoot();
archiveRoot.getArchive().setName(toscaMeta.getResult().getName());
if (toscaMeta.getResult().getVersion() != null) {
archiveRoot.getArchive().setVersion(toscaMeta.getResult().getVersion());
}
if (toscaMeta.getResult().getCreatedBy() != null) {
archiveRoot.getArchive().setTemplateAuthor(toscaMeta.getResult().getCreatedBy());
}
return archiveRoot;
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class PluginArchiveIndexer method getArchivesToIndex.
/**
* From all exposed plugin archives of the location, get the one that are not yet indexed
*
* @param orchestrator
* @param location
* @return an object of type {@link ArchiveToIndex} with the indexable archives and the full list of dependencies
*/
private ArchiveToIndex getArchivesToIndex(Orchestrator orchestrator, Location location) {
Set<CSARDependency> dependencies = Sets.newHashSet();
IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.getOrFail(orchestrator.getId());
ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
List<PluginArchive> allPluginArchives = configuratorPlugin.pluginArchives();
Set<PluginArchive> archivesToIndex = Sets.newHashSet();
for (PluginArchive pluginArchive : safe(allPluginArchives)) {
ArchiveRoot archive = pluginArchive.getArchive();
Csar csar = csarService.get(archive.getArchive().getName(), archive.getArchive().getVersion());
String lastParsedHash = null;
if (csar == null) {
// the archive does not exist into the repository: should be indexed
lastParsedHash = archive.getArchive().getHash();
archivesToIndex.add(pluginArchive);
} else {
// Else, just take the hash
lastParsedHash = csar.getHash();
}
if (archive.getArchive().getDependencies() != null) {
dependencies.addAll(archive.getArchive().getDependencies());
}
dependencies.add(new CSARDependency(archive.getArchive().getName(), archive.getArchive().getVersion(), lastParsedHash));
}
return new ArchiveToIndex(dependencies, archivesToIndex);
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class PluginArchiveIndexer method indexArchive.
private void indexArchive(PluginArchive pluginArchive, Orchestrator orchestrator, Location location) {
ArchiveRoot archive = pluginArchive.getArchive();
// inject a specific tag to allow components catalog filtering search
injectWorkSpace(archive.getNodeTypes().values(), orchestrator, location);
injectWorkSpace(archive.getArtifactTypes().values(), orchestrator, location);
injectWorkSpace(archive.getCapabilityTypes().values(), orchestrator, location);
injectWorkSpace(archive.getRelationshipTypes().values(), orchestrator, location);
List<ParsingError> parsingErrors = Lists.newArrayList();
// index the archive in alien catalog
try {
archiveIndexer.importArchive(archive, CSARSource.ORCHESTRATOR, pluginArchive.getArchiveFilePath(), parsingErrors);
} catch (AlreadyExistException e) {
log.debug("Skipping location archive import as the released version already exists in the repository.");
} catch (CSARUsedInActiveDeployment e) {
log.debug("Skipping orchestrator archive import as it is used in an active deployment. " + e.getMessage());
} catch (ToscaTypeAlreadyDefinedInOtherCSAR e) {
log.debug("Skipping orchestrator archive import, it's archive contain's a tosca type already defined in an other archive." + e.getMessage());
}
// Publish event to allow plugins to post-process elements (portability plugin for example).
publishLocationTypeIndexedEvent(archive.getNodeTypes().values(), orchestrator, location);
}
Aggregations