use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class PolicyTemplatePostProcessor method process.
@Override
public void process(final PolicyTemplate instance) {
// ensure type exists
referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), PolicyType.class));
final PolicyType policyType = ToscaContext.get(PolicyType.class, instance.getType());
if (policyType == null) {
// error managed by the reference post processor.
return;
}
final Topology topology = ((ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance()).getTopology();
// check that the targets are exiting node templates
// TODO should we also check the type of the target, see if it matches with one provided in PolicyType.getTargets() ?
safe(instance.getTargets()).forEach(target -> {
if (!safe((topology.getNodeTemplates())).containsKey(target)) {
// Dispatch an error.
Node node = ParsingContextExecution.getObjectToNodeMap().get(instance.getTargets());
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.POLICY_TARGET_NOT_FOUND, instance.getName(), node.getStartMark(), null, node.getEndMark(), target));
}
});
// Merge the policy template with data coming from the type (default values etc.).
PolicyTemplate tempObject = TemplateBuilder.buildPolicyTemplate(policyType, instance, false);
instance.setProperties(tempObject.getProperties());
propertyValueChecker.checkProperties(policyType, instance.getProperties(), instance.getName());
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class PropertyDefinitionPostProcessor method validate.
private void validate(PropertyDefinition propertyDefinition, PropertyConstraint constraint) {
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(propertyDefinition.getType());
if (toscaType == null) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition.getType());
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.INVALID_CONSTRAINT, "Constraint parsing issue", node.getStartMark(), "Limitation - Constraint cannot be used for type " + propertyDefinition.getType(), node.getEndMark(), "constraint"));
} else {
try {
constraint.initialize(toscaType);
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(constraint);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.VALIDATION_ERROR, "ToscaPropertyConstraint", node.getStartMark(), e.getMessage(), node.getEndMark(), "constraint"));
}
}
}
use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.
the class PropertyDefinitionPostProcessor method validateType.
private void validateType(PropertyDefinition propertyDefinition) {
String propertyType = propertyDefinition.getType();
if (propertyType == null) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyType);
if (node == null) {
node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition);
}
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.VALIDATION_ERROR, "ToscaPropertyType", node.getStartMark(), "Property type must be defined", node.getEndMark(), "type"));
} else if (!ToscaTypes.isSimple(propertyType)) {
if (ToscaTypes.LIST.equals(propertyType) || ToscaTypes.MAP.equals(propertyType)) {
PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
if (entrySchema == null) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.VALIDATION_ERROR, "ToscaPropertyType", node.getStartMark(), "Type " + propertyType + " must define entry schema", node.getEndMark(), "type"));
} else {
validateType(entrySchema);
}
} else {
// It's data type
ArchiveRoot archiveRoot = ParsingContextExecution.getRootObj();
if (!archiveRoot.getDataTypes().containsKey(propertyType)) {
DataType dataType = ToscaContext.get(DataType.class, propertyType);
if (dataType == null) {
Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyType);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.TYPE_NOT_FOUND, "ToscaPropertyType", node.getStartMark(), "Type " + propertyType + " is not found.", node.getEndMark(), "type"));
}
}
}
}
}
use of alien4cloud.tosca.parser.ParsingError 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.ParsingError in project alien4cloud by alien4cloud.
the class UploadCSARSStepDefinition method iThereShouldBeAParsingErrorLevelAndCode.
@And("^I there should be a parsing error level \"([^\"]*)\" and code \"([^\"]*)\"$")
public void iThereShouldBeAParsingErrorLevelAndCode(ParsingErrorLevel errorLevel, ErrorCode expectedCode) throws Throwable {
RestResponse<CsarUploadResult> result = JsonUtil.read(Context.getInstance().getRestResponse(), CsarUploadResult.class);
Assert.assertFalse("There must have messages after parsing the csar", result.getData().getErrors().isEmpty());
int errorCount = 0;
boolean found = false;
for (List<ParsingError> errors : result.getData().getErrors().values()) {
for (ParsingError error : errors) {
if (Objects.equals(error.getErrorCode(), expectedCode) && Objects.equals(error.getErrorLevel(), errorLevel)) {
found = true;
break;
}
}
if (found) {
break;
}
}
Assert.assertTrue(found);
}
Aggregations