use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class GroupPostProcessor method process.
@Override
public void process(NodeGroup instance) {
final ArchiveRoot archiveRoot = (ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance();
// ensure that member groups exists and add the group to the nodes.
Iterator<String> groupMembers = instance.getMembers().iterator();
while (groupMembers.hasNext()) {
String nodeTemplateId = groupMembers.next();
NodeTemplate nodeTemplate = archiveRoot.getTopology().getNodeTemplates().get(nodeTemplateId);
if (nodeTemplate == null) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
// add an error to the context
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKOWN_GROUP_MEMBER, null, node.getStartMark(), null, node.getEndMark(), nodeTemplateId));
// and remove the member
groupMembers.remove();
} else {
Set<String> groups = nodeTemplate.getGroups();
if (groups == null) {
groups = Sets.newHashSet();
nodeTemplate.setGroups(groups);
}
groups.add(instance.getName());
}
}
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class PropertyDefinitionPostProcessor method process.
@Override
public void process(Map.Entry<String, PropertyDefinition> instance) {
PropertyDefinition propertyDefinition = instance.getValue();
validateType(propertyDefinition);
if (propertyDefinition.getConstraints() != null) {
Set<String> definedConstraints = Sets.newHashSet();
for (PropertyConstraint constraint : propertyDefinition.getConstraints()) {
validate(propertyDefinition, constraint);
if (!definedConstraints.add(constraint.getClass().getName())) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(constraint);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.VALIDATION_ERROR, "ToscaPropertyConstraintDuplicate", node.getStartMark(), "Constraint duplicated", node.getEndMark(), "constraint"));
}
}
}
if (propertyDefinition.getDefault() != null) {
checkDefaultValue(instance.getKey(), propertyDefinition);
}
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class NodeTemplatePostProcessor method process.
@Override
public void process(final NodeTemplate instance) {
// ensure type exists
referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), NodeType.class));
final NodeType nodeType = ToscaContext.get(NodeType.class, instance.getType());
if (nodeType == null) {
// error managed by the reference post processor.
return;
}
// FIXME we should check that the artifact is defined at the type level.
safe(instance.getArtifacts()).values().forEach(templateDeploymentArtifactPostProcessor);
// TODO Manage interfaces inputs to copy them to all operations.
safe(instance.getInterfaces()).values().stream().flatMap(anInterface -> safe(anInterface.getOperations()).values().stream()).map(Operation::getImplementationArtifact).filter(Objects::nonNull).forEach(implementationArtifactPostProcessor);
// Merge the node template with data coming from the type (default values etc.).
NodeTemplate tempObject = TemplateBuilder.buildNodeTemplate(nodeType, instance, false);
safe(instance.getCapabilities()).keySet().forEach(s -> {
if (!safe(tempObject.getCapabilities()).containsKey(s)) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(s);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_CAPABILITY, null, node.getStartMark(), null, node.getEndMark(), s));
}
});
instance.setAttributes(tempObject.getAttributes());
instance.setCapabilities(tempObject.getCapabilities());
instance.setProperties(tempObject.getProperties());
instance.setRequirements(tempObject.getRequirements());
instance.setArtifacts(tempObject.getArtifacts());
instance.setInterfaces(tempObject.getInterfaces());
// apply post processor to capabilities defined locally on the element (no need to post-processed the one merged)
safe(instance.getCapabilities()).entrySet().forEach(capabilityPostProcessor);
safe(instance.getRequirements()).entrySet().forEach(requirementPostProcessor);
propertyValueChecker.checkProperties(nodeType, instance.getProperties(), instance.getName());
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class FailGetArtifactParser method parse.
@Override
public Object parse(Node node, ParsingContextExecution context) {
if (node instanceof MappingNode) {
NodeTuple nodeTuple = ((MappingNode) node).getValue().get(0);
if (nodeTuple.getKeyNode() instanceof ScalarNode) {
String key = ((ScalarNode) nodeTuple.getKeyNode()).getValue();
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNRECOGNIZED_PROPERTY, "Ignored field during import", nodeTuple.getKeyNode().getStartMark(), "tosca key is not recognized", nodeTuple.getValueNode().getEndMark(), key));
}
}
return null;
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class ImportParser method parse.
@Override
public CSARDependency parse(Node node, ParsingContextExecution context) {
CSARDependency dependency = laxImportParser.parse(node, context);
if (dependency == null) {
return null;
}
String valueAsString = dependency.getName() + ":" + dependency.getVersion();
String currentArchiveVersion = context.<ArchiveRoot>getRootObj().getArchive().getVersion();
Csar csar = ToscaContext.get().getArchive(dependency.getName(), dependency.getVersion());
log.debug("Import {} {} {}", dependency.getName(), dependency.getVersion(), csar);
if (csar == null) {
// error is not a blocker, as long as no type is missing we just mark it as a warning.
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.MISSING_DEPENDENCY, "Import definition is not valid", node.getStartMark(), "Specified dependency is not found in Alien 4 Cloud repository.", node.getEndMark(), valueAsString));
return null;
} else {
if (!VersionUtil.isSnapshot(currentArchiveVersion) && VersionUtil.isSnapshot(dependency.getVersion())) {
// the current archive is a released version but depends on a snapshot version
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.SNAPSHOT_DEPENDENCY, "Import definition is not valid", node.getStartMark(), "A released archive cannot depends on snapshots archives.", node.getEndMark(), valueAsString));
}
dependency.setHash(csar.getHash());
ToscaContext.get().addDependency(dependency);
return dependency;
}
}
Aggregations