use of alien4cloud.tosca.parser.ParsingContext in project alien4cloud by alien4cloud.
the class SuggestionService method postProcessSuggestionFromArchive.
public void postProcessSuggestionFromArchive(ParsingResult<ArchiveRoot> parsingResult) {
ArchiveRoot archiveRoot = parsingResult.getResult();
ParsingContext context = parsingResult.getContext();
if (archiveRoot.hasToscaTopologyTemplate()) {
Topology topology = archiveRoot.getTopology();
Map<String, NodeTemplate> nodeTemplateMap = topology.getNodeTemplates();
if (MapUtils.isEmpty(nodeTemplateMap)) {
return;
}
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplateMap.entrySet()) {
NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
String nodeName = nodeTemplateEntry.getKey();
if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
checkProperties(nodeName, nodeTemplate.getProperties(), NodeType.class, nodeTemplate.getType(), context);
}
Map<String, Capability> capabilityMap = nodeTemplate.getCapabilities();
if (MapUtils.isNotEmpty(capabilityMap)) {
for (Map.Entry<String, Capability> capabilityEntry : capabilityMap.entrySet()) {
String capabilityName = capabilityEntry.getKey();
Capability capability = capabilityEntry.getValue();
if (MapUtils.isNotEmpty(capability.getProperties())) {
checkProperties(nodeName + ".capabilities." + capabilityName, capability.getProperties(), CapabilityType.class, capability.getType(), context);
}
}
}
Map<String, RelationshipTemplate> relationshipTemplateMap = nodeTemplate.getRelationships();
if (MapUtils.isNotEmpty(relationshipTemplateMap)) {
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : relationshipTemplateMap.entrySet()) {
String relationshipName = relationshipEntry.getKey();
RelationshipTemplate relationship = relationshipEntry.getValue();
if (MapUtils.isNotEmpty(relationship.getProperties())) {
checkProperties(nodeName + ".relationships." + relationshipName, relationship.getProperties(), RelationshipType.class, relationship.getType(), context);
}
}
}
}
}
if (archiveRoot.hasToscaTypes()) {
Map<String, NodeType> allNodeTypes = archiveRoot.getNodeTypes();
if (MapUtils.isNotEmpty(allNodeTypes)) {
for (Map.Entry<String, NodeType> nodeTypeEntry : allNodeTypes.entrySet()) {
NodeType nodeType = nodeTypeEntry.getValue();
if (nodeType.getRequirements() != null && !nodeType.getRequirements().isEmpty()) {
for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) {
NodeFilter nodeFilter = requirementDefinition.getNodeFilter();
if (nodeFilter != null) {
Map<String, FilterDefinition> capabilitiesFilters = nodeFilter.getCapabilities();
if (MapUtils.isNotEmpty(capabilitiesFilters)) {
for (Map.Entry<String, FilterDefinition> capabilityFilterEntry : capabilitiesFilters.entrySet()) {
FilterDefinition filterDefinition = capabilityFilterEntry.getValue();
for (Map.Entry<String, List<PropertyConstraint>> constraintEntry : filterDefinition.getProperties().entrySet()) {
List<PropertyConstraint> constraints = constraintEntry.getValue();
checkPropertyConstraints("node_filter.capabilities", CapabilityType.class, capabilityFilterEntry.getKey(), constraintEntry.getKey(), constraints, context);
}
}
}
// FIXME check also the value properties filter of a node filter
}
}
}
}
}
}
}
use of alien4cloud.tosca.parser.ParsingContext in project alien4cloud by alien4cloud.
the class CsarGitService method processImport.
private List<ParsingResult<Csar>> processImport(CsarGitRepository csarGitRepository, CsarGitCheckoutLocation csarGitCheckoutLocation, String gitHash) {
// find all the archives under the given hierarchy and zip them to create archives
Path archiveZipRoot = tempZipDirPath.resolve(csarGitRepository.getId());
Path archiveGitRoot = tempDirPath.resolve(csarGitRepository.getId());
if (csarGitCheckoutLocation.getSubPath() != null && !csarGitCheckoutLocation.getSubPath().isEmpty()) {
archiveGitRoot = archiveGitRoot.resolve(csarGitCheckoutLocation.getSubPath());
}
Set<Path> archivePaths = csarFinderService.prepare(archiveGitRoot, archiveZipRoot);
List<ParsingResult<Csar>> parsingResults = Lists.newArrayList();
Map<CSARDependency, CsarDependenciesBean> csarDependenciesBeans = uploadService.preParsing(archivePaths, parsingResults);
List<CsarDependenciesBean> sorted = sort(csarDependenciesBeans);
for (CsarDependenciesBean csarBean : sorted) {
String archiveRepoPath = archiveZipRoot.relativize(csarBean.getPath().getParent()).toString();
if (csarGitCheckoutLocation.getLastImportedHash() != null && csarGitCheckoutLocation.getLastImportedHash().equals(gitHash) && csarService.get(csarBean.getSelf().getName(), csarBean.getSelf().getVersion()) != null) {
// no commit since last import and the archive still exist in the repo, so do not import
addAlreadyImportParsingResult(archiveRepoPath, parsingResults);
continue;
}
try {
// FIXME Add possibility to choose an workspace
ParsingResult<Csar> result = uploadService.upload(csarBean.getPath(), CSARSource.GIT, AlienConstants.GLOBAL_WORKSPACE_ID);
result.getContext().setFileName(archiveRepoPath + "/" + result.getContext().getFileName());
parsingResults.add(result);
} catch (ParsingException e) {
ParsingResult<Csar> failedResult = new ParsingResult<>();
failedResult.setContext(new ParsingContext(archiveRepoPath));
failedResult.getContext().setParsingErrors(e.getParsingErrors());
parsingResults.add(failedResult);
log.debug("Failed to import archive from git as it cannot be parsed", e);
} catch (AlreadyExistException | ToscaTypeAlreadyDefinedInOtherCSAR | CSARUsedInActiveDeployment e) {
ParsingResult<Csar> failedResult = new ParsingResult<>();
failedResult.setContext(new ParsingContext(archiveRepoPath));
failedResult.getContext().setParsingErrors(Lists.newArrayList(UploadExceptionUtil.parsingErrorFromException(e)));
parsingResults.add(failedResult);
}
}
return parsingResults;
}
use of alien4cloud.tosca.parser.ParsingContext in project alien4cloud by alien4cloud.
the class CsarGitService method addAlreadyImportParsingResult.
/**
* Just add a parsing info to the list stating that the archive is already imported and
*
* @param archivePath The path of the archive in the repo.
* @param parsingResults The list of parsing results.
*/
private void addAlreadyImportParsingResult(String archivePath, List<ParsingResult<Csar>> parsingResults) {
ParsingResult<Csar> result = new ParsingResult<>();
result.setContext(new ParsingContext(archivePath));
result.getContext().setParsingErrors(Lists.newArrayList(new ParsingError(ParsingErrorLevel.INFO, ErrorCode.CSAR_ALREADY_INDEXED, "No new commit since last import and archive already indexed.", null, null, null, null)));
parsingResults.add(result);
}
use of alien4cloud.tosca.parser.ParsingContext in project alien4cloud by alien4cloud.
the class ArchiveParserUtil method cleanup.
public static <T> ParsingResult<T> cleanup(ParsingResult<?> result) {
ParsingContext context = new ParsingContext(result.getContext().getFileName());
context.getParsingErrors().addAll(result.getContext().getParsingErrors());
return new ParsingResult<T>(null, context);
}
use of alien4cloud.tosca.parser.ParsingContext in project alien4cloud by alien4cloud.
the class ArchiveParserUtil method toParsingContext.
public static ParsingContext toParsingContext(String filename, List<ParsingError> parsingErrors) {
ParsingContext context = new ParsingContext(filename);
context.setParsingErrors(parsingErrors);
return context;
}
Aggregations