use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class PropertyValueChecker method checkProperties.
/**
* Check that the value of a property has the right type and match constraints.
*
* @param type The type that defines the properties (NodeType, CapabilityType, RequirementType).
* @param propertyValues The map of values.
* @param templateName The name of the node template /capability template / requirement template.
*/
public void checkProperties(final AbstractInheritableToscaType type, final Map<String, AbstractPropertyValue> propertyValues, final String templateName) {
if (type == null) {
// if the type is null we cannot check properties against their definition. Error is managed elsewhere.
return;
}
ArchiveRoot archiveRoot = (ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance();
Topology topology = archiveRoot.getTopology();
for (Map.Entry<String, AbstractPropertyValue> propertyEntry : safe(propertyValues).entrySet()) {
String propertyName = propertyEntry.getKey();
AbstractPropertyValue propertyValue = propertyEntry.getValue();
Node propertyValueNode = ParsingContextExecution.getObjectToNodeMap().get(propertyValue);
if (type.getProperties() == null || !type.getProperties().containsKey(propertyName)) {
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.UNRECOGNIZED_PROPERTY, templateName, propertyValueNode.getStartMark(), "Property " + propertyName + " does not exist in type " + type.getElementId(), propertyValueNode.getEndMark(), propertyName));
continue;
}
PropertyDefinition propertyDefinition = type.getProperties().get(propertyName);
checkProperty(propertyName, propertyValueNode, propertyValue, propertyDefinition, topology.getInputs(), templateName);
}
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaDefinitionVersionParser method parse.
@Override
public String parse(Node node, ParsingContextExecution context) {
ArchiveRoot archiveRoot = (ArchiveRoot) context.getParent();
String toscaDefinitionVersion = ParserUtils.getScalar(node, context);
if (toscaDefinitionVersion != null) {
CSARDependency dependency = ToscaNormativeImports.IMPORTS.get(toscaDefinitionVersion);
if (dependency != null) {
// File based parsing implementation of the requirement of normative types will load them from file (meaning basically that we will loop here)
if (loadingNormative.get() == null) {
loadingNormative.set(true);
} else {
return toscaDefinitionVersion;
}
Csar csar = ToscaContext.get().getArchive(dependency.getName(), dependency.getVersion());
if (csar == null) {
return toscaDefinitionVersion;
}
// Normative imports are automatically injected and supposed to be accessible, no specific validation is performed here.
dependency.setHash(csar.getHash());
ToscaContext.get().addDependency(dependency);
Set<CSARDependency> dependencies = archiveRoot.getArchive().getDependencies();
if (dependencies == null) {
dependencies = new HashSet<>();
archiveRoot.getArchive().setDependencies(dependencies);
}
dependencies.add(dependency);
loadingNormative.remove();
}
}
return toscaDefinitionVersion;
}
use of alien4cloud.tosca.model.ArchiveRoot 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.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class MetaDataParser method parse.
@Override
public Csar parse(Node node, ParsingContextExecution context) {
ArchiveRoot parent = (ArchiveRoot) context.getParent();
Csar csar = parent.getArchive();
List<Tag> tagList = Lists.newArrayList();
if (node instanceof MappingNode) {
MappingNode mapNode = (MappingNode) node;
for (NodeTuple entry : mapNode.getValue()) {
String key = scalarParser.parse(entry.getKeyNode(), context);
String value = scalarParser.parse(entry.getValueNode(), context);
if (TEMPLATE_NAME.equals(key)) {
csar.setName(value);
} else if (TEMPLATE_AUTHOR.equals(key)) {
csar.setTemplateAuthor(value);
} else if (TEMPLATE_VERSION.equals(key)) {
csar.setVersion(value);
if (!VersionUtil.isValid(value)) {
ParserUtils.addTypeError(entry.getValueNode(), context.getParsingErrors(), "version");
}
} else if (value != null) {
tagList.add(new Tag(key, value));
}
}
csar.setTags(tagList);
} else {
ParserUtils.addTypeError(node, context.getParsingErrors(), "meta-data");
}
return csar;
}
use of alien4cloud.tosca.model.ArchiveRoot 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