use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.
the class YamlReaderTest method testPolicyDefinitionsAsList.
@Test
public void testPolicyDefinitionsAsList() throws Exception {
YamlReader reader = new YamlReader();
InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/simple-tests/valid-topology_templates-1_3.yml");
YTServiceTemplate template = reader.parse(is);
Assertions.assertNotNull(template);
YTTopologyTemplateDefinition topologyTemplate = template.getTopologyTemplate();
Assertions.assertNotNull(topologyTemplate);
Assertions.assertEquals(2, topologyTemplate.getPolicies().size());
}
use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.
the class YamlReaderTest method testSupportedInterfaceDefinitions.
@Test
public void testSupportedInterfaceDefinitions() throws Exception {
YamlReader reader = new YamlReader();
InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/supported_interfaces.yml");
YTServiceTemplate template = reader.parse(is);
Assertions.assertNotNull(template);
YTNodeType server = template.getNodeTypes().get("server");
Assertions.assertEquals(2, server.getArtifacts().size());
YTInterfaceDefinition standard = server.getInterfaces().get("Standard");
Assertions.assertEquals(2, standard.getOperations().size());
Assertions.assertEquals(1, standard.getInputs().size());
}
use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.
the class YamlCsarImporter method parseDefinitionsElement.
@Override
protected Optional<TDefinitions> parseDefinitionsElement(Path entryDefinitionsPath, final List<String> errors) {
YamlReader reader = new YamlReader();
YTServiceTemplate serviceTemplate;
try {
serviceTemplate = reader.parse(new FileInputStream(entryDefinitionsPath.toFile()));
String name = serviceTemplate.getMetadata().get("name");
if (name == null) {
// fallback to filename
name = entryDefinitionsPath.toString().substring(entryDefinitionsPath.toString().indexOf("__") + 2, entryDefinitionsPath.toString().indexOf(".tosca"));
}
ToCanonical converter = new ToCanonical(targetRepository);
return Optional.of(converter.convert(serviceTemplate, name, serviceTemplate.getMetadata().get("targetNamespace"), true));
} catch (MultiException | FileNotFoundException e) {
e.printStackTrace();
LOGGER.error("Could not read the given entry definition " + e.getMessage());
}
return Optional.empty();
}
use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.
the class YamlReader method readServiceTemplate.
private YTServiceTemplate readServiceTemplate(Path path, Path file, String namespace) throws MultiException {
Path filePath;
if (Objects.isNull(path)) {
filePath = file;
} else {
filePath = path.resolve(file);
}
if (!fileChanged(filePath)) {
if (exceptionBuffer.containsKey(filePath)) {
throw exceptionBuffer.get(filePath);
}
if (serviceTemplateBuffer.containsKey(filePath)) {
return serviceTemplateBuffer.get(filePath);
}
}
logger.debug("Read Service Template: {}", filePath);
try {
// pre parse checking
try {
ObjectValidator objectValidator = new ObjectValidator();
objectValidator.validateObject(readObject(filePath));
} catch (ConstructorException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (ScannerException e) {
ExceptionInterpreter interpreter = new ExceptionInterpreter();
throw new MultiException().add(interpreter.interpret(e));
} catch (YAMLParserException e) {
throw new MultiException().add(e);
}
// parse checking
YTServiceTemplate result = buildServiceTemplate(readObject(filePath), namespace);
// post parse checking
Validator validator = new Validator(path);
validator.validate(result, namespace);
serviceTemplateBuffer.put(filePath, result);
return result;
} catch (MultiException e) {
exceptionBuffer.put(filePath, e);
throw e.add(file.toString());
}
}
Aggregations