use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.
the class ArchiveUploadService method preParsing.
@ToscaContextual
public Map<CSARDependency, CsarDependenciesBean> preParsing(Set<Path> paths, List<ParsingResult<Csar>> parsingResults) {
Map<CSARDependency, CsarDependenciesBean> csarDependenciesBeans = Maps.newHashMap();
for (Path path : paths) {
try {
// FIXME cleanup git import archives
ParsingResult<CsarDependenciesBean> parsingResult = parser.parseImports(path);
parsingResult.getResult().setPath(path);
csarDependenciesBeans.put(parsingResult.getResult().getSelf(), parsingResult.getResult());
} catch (ParsingException e) {
ParsingResult<Csar> failedResult = new ParsingResult<>();
failedResult.setContext(new ParsingContext(path.getFileName().toString()));
failedResult.getContext().setParsingErrors(e.getParsingErrors());
parsingResults.add(failedResult);
log.debug("Not able to parse archive, ignoring it", e);
}
}
return csarDependenciesBeans;
}
use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.
the class TopologyTreeBuilderService method getNonNativesNodes.
/**
* Get the non-natives node of a topology.
*
* @param topology
* @return a Map of non-natives nodes.
*/
@ToscaContextual
public Map<String, NodeTemplate> getNonNativesNodes(Topology topology) {
Map<String, NodeTemplate> nonNativesNode = new HashMap<>();
if (topology.getNodeTemplates() != null) {
for (Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
NodeTemplate template = templateEntry.getValue();
NodeType indexedToscaElement = ToscaContext.getOrFail(NodeType.class, template.getType());
boolean isCompute = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeComputeConstants.COMPUTE_TYPE);
boolean isNetwork = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeNetworkConstants.NETWORK_TYPE);
boolean isVolume = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeBlockStorageConstants.BLOCKSTORAGE_TYPE);
if (!isCompute && !isNetwork && !isVolume) {
nonNativesNode.put(templateEntry.getKey(), template);
}
}
}
return nonNativesNode;
}
use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.
the class ToscaTypeIndexerService method indexInheritableElement.
@Override
@ToscaContextual
public void indexInheritableElement(String archiveName, String archiveVersion, AbstractInheritableToscaType element, Collection<CSARDependency> dependencies) {
if (CollectionUtils.isNotEmpty(element.getDerivedFrom())) {
boolean deriveFromSimpleType = false;
String parentId = element.getDerivedFrom().get(0);
if (element.getDerivedFrom().size() == 1 && ToscaTypes.isSimple(parentId)) {
deriveFromSimpleType = true;
}
if (!deriveFromSimpleType) {
AbstractInheritableToscaType superElement = ToscaContext.getOrFail(element.getClass(), parentId);
IndexedModelUtils.mergeInheritableIndex(superElement, element);
}
}
alienDAO.save(element);
refreshIndexForSearching();
}
use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.
the class CsarDependencyLoader method buildDependencyBean.
@Override
@ToscaContextual
public CSARDependency buildDependencyBean(String name, String version) {
CSARDependency newDependency = new CSARDependency(name, version);
Csar csar = ToscaContext.get().getArchive(name, version);
if (csar != null) {
newDependency.setHash(csar.getHash());
}
return newDependency;
}
use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.
the class ArchiveUploadService method upload.
/**
* Upload a TOSCA archive and index its components.
*
* @param path The archive path.
* @param csarSource The source of the upload.
* @return The Csar object from the parsing.
* @throws ParsingException
* @throws CSARUsedInActiveDeployment
*/
@ToscaContextual
public ParsingResult<Csar> upload(Path path, CSARSource csarSource, String workspace) throws ParsingException, CSARUsedInActiveDeployment, ToscaTypeAlreadyDefinedInOtherCSAR {
// parse the archive.
ParsingResult<ArchiveRoot> parsingResult = parser.parseWithExistingContext(path, workspace);
final ArchiveRoot archiveRoot = parsingResult.getResult();
// check if any blocker error has been found during parsing process.
if (parsingResult.hasError(ParsingErrorLevel.ERROR)) {
// do not save anything if any blocker error has been found during import.
return ArchiveParserUtil.toSimpleResult(parsingResult);
}
archiveIndexer.importArchive(archiveRoot, csarSource, path, parsingResult.getContext().getParsingErrors());
try {
suggestionService.postProcessSuggestionFromArchive(parsingResult);
suggestionService.setAllSuggestionIdOnPropertyDefinition();
} catch (Exception e) {
log.error("Could not post process suggestion for the archive <" + archiveRoot.getArchive().getName() + "/" + archiveRoot.getArchive().getVersion() + ">", e);
}
return ArchiveParserUtil.toSimpleResult(parsingResult);
}
Aggregations