use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class SustitutionMappingParser method parse.
@Override
public SubstitutionMapping parse(Node node, ParsingContextExecution context) {
Topology topology = (Topology) context.getParent();
if (!(node instanceof MappingNode)) {
// we expect a MappingNode
context.getParsingErrors().add(new ParsingError(ErrorCode.YAML_MAPPING_NODE_EXPECTED, null, node.getStartMark(), null, node.getEndMark(), null));
return null;
}
SubstitutionMapping result = new SubstitutionMapping();
MappingNode mappingNode = ((MappingNode) node);
List<NodeTuple> nodeTuples = mappingNode.getValue();
for (NodeTuple nodeTuple : nodeTuples) {
String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
Node valueNode = nodeTuple.getValueNode();
switch(key) {
case NODE_TYPE:
String nodeTypeName = scalarParser.parse(valueNode, context);
result.setSubstitutionType(nodeTypeName);
break;
case CAPABILITIES:
result.setCapabilities(parseSubstitutionTargets(valueNode, context));
break;
case REQUIREMENTS:
result.setRequirements(parseSubstitutionTargets(valueNode, context));
break;
default:
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNRECOGNIZED_PROPERTY, null, valueNode.getStartMark(), "Key <" + key + "> is not recognized for substitution mapping.", valueNode.getEndMark(), "key"));
}
}
return result;
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class LaxImportParser method parse.
@Override
public CSARDependency parse(Node node, ParsingContextExecution context) {
String valueAsString = scalarParser.parse(node, context);
if (StringUtils.isNotBlank(valueAsString)) {
if (valueAsString.contains(":")) {
String[] dependencyStrs = valueAsString.split(":");
if (dependencyStrs.length == 2) {
String dependencyName = dependencyStrs[0];
String dependencyVersion = dependencyStrs[1];
// check that version has the righ format
try {
VersionUtil.parseVersion(dependencyVersion);
} catch (InvalidVersionException e) {
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Version specified in the dependency is not a valid version.", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
return null;
}
return new CSARDependency(dependencyName, dependencyVersion);
}
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Import definition is not valid", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
} else {
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Relative import is currently not supported in Alien 4 Cloud", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
}
}
return null;
}
use of alien4cloud.tosca.parser.ParsingError 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);
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class SuggestionService method checkProperty.
private AbstractSuggestionEntry checkProperty(String nodePrefix, String propertyName, String propertyTextValue, Class<? extends AbstractInheritableToscaType> type, String elementId, ParsingContext context) {
AbstractSuggestionEntry suggestionEntry = getSuggestionEntry(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, type.getSimpleName().toLowerCase(), elementId, propertyName);
if (suggestionEntry != null) {
PriorityQueue<SuggestionService.MatchedSuggestion> similarValues = getJaroWinklerMatchedSuggestions(suggestionEntry.getSuggestions(), propertyTextValue, 0.8);
if (!similarValues.isEmpty()) {
// Has some similar values in the system already
SuggestionService.MatchedSuggestion mostMatched = similarValues.poll();
if (!mostMatched.getValue().equals(propertyTextValue)) {
// If user has entered a property value not the same as the most matched in the system
ParsingErrorLevel level;
if (mostMatched.getPriority() == 1.0) {
// It's really identical if we take out all white spaces and lower / upper case
level = ParsingErrorLevel.WARNING;
} else {
// It's pretty similar
level = ParsingErrorLevel.INFO;
// Add suggestion anyway
addSuggestionValueToSuggestionEntry(suggestionEntry.getId(), propertyTextValue);
}
context.getParsingErrors().add(new ParsingError(level, ErrorCode.POTENTIAL_BAD_PROPERTY_VALUE, null, null, null, null, "At path [" + nodePrefix + "." + propertyName + "] existing value [" + mostMatched.getValue() + "] is very similar to [" + propertyTextValue + "]"));
}
} else {
// Not similar add suggestion
addSuggestionValueToSuggestionEntry(suggestionEntry.getId(), propertyTextValue);
}
}
return suggestionEntry;
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class AbstractPluginArchiveService method parse.
/**
* Parse an archive given a path relative to the plugin
*
* @param archiveRelativePath Relative path where the archive is in the plugin
* @return The parsed archive as a @{@link PluginArchive}
* @throws PluginArchiveException
*/
public PluginArchive parse(String archiveRelativePath) throws PluginArchiveException {
String archiveErrorMsge = "Archive in path: [ " + archiveRelativePath + " ]";
// Parse the archives
ParsingResult<ArchiveRoot> result;
Path archivePath = selfContext.getPluginPath().resolve(archiveRelativePath);
try {
result = this.archiveParser.parseDir(archivePath, AlienConstants.GLOBAL_WORKSPACE_ID);
} catch (ParsingException e) {
throw new PluginArchiveException("Failed to parse " + archiveErrorMsge, e);
}
if (result.getContext().getParsingErrors() != null && !result.getContext().getParsingErrors().isEmpty()) {
log.error("Parsing errors for" + archiveErrorMsge);
for (ParsingError parsingError : result.getContext().getParsingErrors()) {
log.error(parsingError.toString());
}
throw new PluginArchiveException(archiveErrorMsge + " is invalid");
}
return new PluginArchive(result.getResult(), archivePath);
}
Aggregations