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