Search in sources :

Example 6 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate 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 7 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate 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)

Example 8 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.

the class FromCanonical method convert.

/**
 * Converts canonical TDefinitions to a TOSCA YAML ServiceTemplate
 */
@NonNull
public YTServiceTemplate convert(TDefinitions node, boolean convertImports) {
    LOGGER.debug("Convert TServiceTemplate: {}", node.getIdFromIdOrNameField());
    YTServiceTemplate.Builder builder = new YTServiceTemplate.Builder(Defaults.TOSCA_DEFINITIONS_VERSION).setDescription(convertDocumentation(node.getElement().getDocumentation())).setArtifactTypes(convert(node.getArtifactTypes())).setCapabilityTypes(convert(node.getCapabilityTypes())).setRelationshipTypes(convert(node.getRelationshipTypes())).setNodeTypes(convert(node.getNodeTypes())).setPolicyTypes(convert(node.getPolicyTypes())).setInterfaceTypes(convert(node.getInterfaceTypes())).setDataTypes(convert(node.getDataTypes())).setGroupTypes(convert(node.getGroupTypes()));
    if (node.getServiceTemplates().size() == 1) {
        builder.setTopologyTemplate(convert(node.getServiceTemplates().get(0)));
        builder.addMetadata("targetNamespace", node.getTargetNamespace());
    }
    if (convertImports) {
        List<YTMapImportDefinition> imports = convertImports();
        YTMapImportDefinition existingImports = prepareExistingImports(node.getImportDefinitions());
        if (Objects.nonNull(imports)) {
            imports.stream().findFirst().ifPresent(def -> def.putAll(existingImports));
        } else if (!existingImports.isEmpty()) {
            imports = new ArrayList<>();
            imports.add(existingImports);
        }
        builder.setImports(imports);
    }
    return builder.build();
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) ArrayList(java.util.ArrayList) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 9 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.

the class YamlRepository method createNewCacheNodeTypeWithArtifact.

/**
 * Creates new cache node type and saves artifact until it's referenced
 *
 * @param ref              repository file reference
 * @param artifactTemplate new artifact template
 * @param artifact         yaml artifact
 * @param imports          imports
 * @return new yaml service template
 */
private YTServiceTemplate createNewCacheNodeTypeWithArtifact(RepositoryFileReference ref, TArtifactTemplate artifactTemplate, YTArtifactDefinition artifact, List<YTMapImportDefinition> imports) {
    YTServiceTemplate serviceTemplate = createEmptyCacheNodeType(((ArtifactTemplateId) ref.getParent()).getQName().getNamespaceURI());
    Map<String, YTArtifactDefinition> artifacts = new LinkedHashMap<>();
    artifacts.put(artifactTemplate.getIdFromIdOrNameField(), artifact);
    serviceTemplate.getNodeTypes().entrySet().iterator().next().getValue().setArtifacts(artifacts);
    serviceTemplate.setImports(imports);
    return serviceTemplate;
}
Also used : YTArtifactDefinition(org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.

the class YamlRepository method convertToDefinitions.

/**
 * Reads service template from target path and converts it to XML Definition
 *
 * @param targetPath      target path of service template
 * @param id              id of requested Definition
 * @param targetNamespace targetNamespace of requested Definition
 * @return xml definitions
 */
private TDefinitions convertToDefinitions(Path targetPath, String id, String targetNamespace) throws IOException, MultiException {
    YTServiceTemplate serviceTemplate = readServiceTemplate(targetPath);
    ToCanonical converter = new ToCanonical(this);
    return converter.convert(serviceTemplate, id, targetNamespace, targetPath.endsWith("ServiceTemplate.tosca"));
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) ToCanonical(org.eclipse.winery.repository.yaml.converter.ToCanonical)

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