Search in sources :

Example 16 with YTServiceTemplate

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());
}
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)

Example 17 with YTServiceTemplate

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());
}
Also used : YTInterfaceDefinition(org.eclipse.winery.model.tosca.yaml.YTInterfaceDefinition) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) YTNodeType(org.eclipse.winery.model.tosca.yaml.YTNodeType) AbstractConverterTest(org.eclipse.winery.repository.converter.AbstractConverterTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with YTServiceTemplate

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();
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) FileNotFoundException(java.io.FileNotFoundException) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) ToCanonical(org.eclipse.winery.repository.yaml.converter.ToCanonical) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) FileInputStream(java.io.FileInputStream)

Example 19 with YTServiceTemplate

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());
    }
}
Also used : Path(java.nio.file.Path) ScannerException(org.yaml.snakeyaml.scanner.ScannerException) ExceptionInterpreter(org.eclipse.winery.repository.converter.validator.support.ExceptionInterpreter) YAMLParserException(org.eclipse.winery.model.converter.support.exception.YAMLParserException) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) ObjectValidator(org.eclipse.winery.repository.converter.validator.ObjectValidator) ConstructorException(org.yaml.snakeyaml.constructor.ConstructorException) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) Validator(org.eclipse.winery.repository.converter.validator.Validator) ObjectValidator(org.eclipse.winery.repository.converter.validator.ObjectValidator)

Aggregations

YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)19 YamlReader (org.eclipse.winery.repository.converter.reader.YamlReader)10 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)9 InputStream (java.io.InputStream)7 FileInputStream (java.io.FileInputStream)6 AbstractConverterTest (org.eclipse.winery.repository.converter.AbstractConverterTest)5 Test (org.junit.jupiter.api.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Path (java.nio.file.Path)4 LinkedHashMap (java.util.LinkedHashMap)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Map (java.util.Map)3 JAXBException (javax.xml.bind.JAXBException)3 YTArtifactDefinition (org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition)3 YTTopologyTemplateDefinition (org.eclipse.winery.model.tosca.yaml.YTTopologyTemplateDefinition)3 YTMapImportDefinition (org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition)3 YamlWriter (org.eclipse.winery.repository.converter.writer.YamlWriter)3 AbstractMap (java.util.AbstractMap)2 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)2