Search in sources :

Example 1 with YamlReader

use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.

the class YamlRepository method readServiceTemplate.

/**
 * Reads service template from referenced definition
 *
 * @param ref repository file reference
 * @return yaml service template
 */
private YTServiceTemplate readServiceTemplate(RepositoryFileReference ref) throws IOException, MultiException {
    Path targetPath = ref2AbsolutePath(ref);
    InputStream in = newInputStream(targetPath);
    LOGGER.debug("Reading service template from reference {} resolved as {}", ref, targetPath);
    return new YamlReader().parse(in);
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader)

Example 2 with YamlReader

use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.

the class ImportVisitor method visit.

@Override
public Result visit(YTServiceTemplate node, Parameter parameter) {
    YamlReader reader = new YamlReader();
    if (!this.namespace.equals(Namespaces.TOSCA_YAML_NS)) {
        Set<String> typeDefinitions = new HashSet<>(Arrays.asList(Defaults.TOSCA_NORMATIVE_TYPES, Defaults.TOSCA_NONNORMATIVE_TYPES));
        String tmpNamespace = this.namespace;
        this.namespace = Namespaces.TOSCA_YAML_NS;
        Path tmpDir = Utils.getTmpDir(Paths.get("types"));
        for (String typeDefinition : typeDefinitions) {
            try {
                Path outFilePath = tmpDir.resolve(typeDefinition);
                InputStream inputStream = this.getClass().getResourceAsStream(// Do not use File.separator here (https://stackoverflow.com/a/41677152/8235252)
                "/".concat(typeDefinition));
                Files.copy(inputStream, outFilePath, StandardCopyOption.REPLACE_EXISTING);
                YTServiceTemplate serviceTemplate = reader.parseSkipTest(outFilePath, Namespaces.TOSCA_YAML_NS);
                if (Objects.nonNull(serviceTemplate)) {
                    serviceTemplate.accept(this, new Parameter());
                }
            } catch (MultiException e) {
                setException(e);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        this.namespace = tmpNamespace;
    }
    super.visit(node, parameter);
    return null;
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) Parameter(org.eclipse.winery.repository.converter.validator.support.Parameter) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) HashSet(java.util.HashSet)

Example 3 with YamlReader

use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.

the class YamlReaderTest method testPropertyFunctionReading.

@Test
public void testPropertyFunctionReading() throws Exception {
    YamlReader reader = new YamlReader();
    InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/property_functions.yml");
    YTServiceTemplate template = reader.parse(is);
    Assertions.assertNotNull(template);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) AbstractConverterTest(org.eclipse.winery.repository.converter.AbstractConverterTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with YamlReader

use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.

the class YamlReaderTest method testBasicTopologyTemplate.

@DisplayName("Basic Topology Template Reader Test")
@Test
public void testBasicTopologyTemplate() throws Exception {
    YamlReader reader = new YamlReader();
    InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/simple-tests/valid-topology_templates-1_3.yml");
    YTServiceTemplate serviceTemplate = reader.parse(is);
    Assertions.assertNotNull(serviceTemplate);
    YTTopologyTemplateDefinition topoTemplate = serviceTemplate.getTopologyTemplate();
    Assertions.assertNotNull(topoTemplate);
    Assertions.assertEquals(topoTemplate.getPolicies().size(), 2);
    Assertions.assertEquals(topoTemplate.getNodeTemplates().size(), 1);
    Assertions.assertEquals(topoTemplate.getRelationshipTemplates().size(), 1);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YTTopologyTemplateDefinition(org.eclipse.winery.model.tosca.yaml.YTTopologyTemplateDefinition) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) AbstractConverterTest(org.eclipse.winery.repository.converter.AbstractConverterTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with YamlReader

use of org.eclipse.winery.repository.converter.reader.YamlReader in project winery by eclipse.

the class ImportVisitor method visit.

@Override
public Result visit(YTImportDefinition node, Parameter parameter) {
    YamlReader reader = new YamlReader();
    String importNamespace = node.getNamespaceUri() == null ? this.namespace : node.getNamespaceUri();
    try {
        YTServiceTemplate serviceTemplate = reader.parse(node, path, importNamespace);
        if (serviceTemplate != null) {
            String tmpNamespace = this.namespace;
            this.namespace = importNamespace;
            this.visit(serviceTemplate, new Parameter());
            this.namespace = tmpNamespace;
        }
        super.visit(node, parameter);
    } catch (MultiException e) {
        this.setException(e);
    }
    return null;
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) Parameter(org.eclipse.winery.repository.converter.validator.support.Parameter) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException)

Aggregations

YamlReader (org.eclipse.winery.repository.converter.reader.YamlReader)13 YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)10 InputStream (java.io.InputStream)9 FileInputStream (java.io.FileInputStream)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)5 AbstractConverterTest (org.eclipse.winery.repository.converter.AbstractConverterTest)5 Test (org.junit.jupiter.api.Test)5 YTTopologyTemplateDefinition (org.eclipse.winery.model.tosca.yaml.YTTopologyTemplateDefinition)3 Path (java.nio.file.Path)2 AbstractMap (java.util.AbstractMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 YTImportDefinition (org.eclipse.winery.model.tosca.yaml.YTImportDefinition)2 Parameter (org.eclipse.winery.repository.converter.validator.support.Parameter)2 DisplayName (org.junit.jupiter.api.DisplayName)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1