use of org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV in project winery by eclipse.
the class DataFlowResource method createNodeTemplate.
/**
* Create a NodeTemplate corresponding to the given filter with the given type, properties and artifacts and add it
* to the topology of the incomplete deployment model.
*/
private TTopologyTemplate createNodeTemplate(TTopologyTemplate topology, NodeTypeId nodeTypeId, String templateName, Map<String, String> properties, List<QName> artifacts) {
// get NodeType to access Requirements for the completion and available properties
IRepository repo = RepositoryFactory.getRepository();
TNodeType nodeType = repo.getElement(nodeTypeId);
if (Objects.isNull(nodeType)) {
return null;
}
TNodeTemplate.Builder templateBuilder = new TNodeTemplate.Builder(templateName, nodeTypeId.getQName());
// add the defined properties to the NodeTemplate
if (Objects.nonNull(properties)) {
LinkedHashMap<String, String> propertyList = new LinkedHashMap<>();
if (Objects.nonNull(nodeType.getWinerysPropertiesDefinition())) {
// add empty property for NodeType properties to avoid errors due to missing properties
WinerysPropertiesDefinition def = nodeType.getWinerysPropertiesDefinition();
for (PropertyDefinitionKV prop : def.getPropertyDefinitions()) {
propertyList.put(prop.getKey(), "");
}
}
// add all properties which are defined at the filter
propertyList.putAll(properties);
TEntityTemplate.WineryKVProperties nodeProperties = new TEntityTemplate.WineryKVProperties();
nodeProperties.setKVProperties(propertyList);
templateBuilder.setProperties(nodeProperties);
}
// add all requirements which are defined by the corresponding NodeType
if (nodeType.getRequirementDefinitions() != null) {
for (TRequirementDefinition requirementDef : nodeType.getRequirementDefinitions()) {
String requirementId = templateName + "-" + requirementDef.getName();
templateBuilder.addRequirement(new TRequirement.Builder(requirementId, requirementDef.getName(), requirementDef.getRequirementType()).build());
}
}
// add the DAs to the NodeTemplate
if (Objects.nonNull(artifacts) && !artifacts.isEmpty()) {
LOGGER.debug("{} artifacts specified for filter {}", artifacts.size(), templateName);
// get the IDs of all available ArtifactTemplates
List<ArtifactTemplateId> artifactTemplateIds = repo.getAllDefinitionsChildIds().stream().filter(id -> id.getGroup().equals(ARTIFACT_TEMPLATE_GROUP) && id instanceof ArtifactTemplateId).map(id -> (ArtifactTemplateId) id).collect(Collectors.toList());
for (QName artifactName : artifacts) {
Optional<ArtifactTemplateId> idOptional = artifactTemplateIds.stream().filter(id -> id.getQName().equals(artifactName)).findFirst();
if (idOptional.isPresent()) {
ArtifactTemplateId artifactTemplateId = idOptional.get();
TArtifactTemplate artifactTemplate = repo.getElement(artifactTemplateId);
templateBuilder.addDeploymentArtifact(new TDeploymentArtifact.Builder(artifactName.toString(), artifactTemplate.getType()).setArtifactRef(artifactName).build());
} else {
LOGGER.warn("Filter '{}' specifies DA with name '{}' but no such artifact available in repository!", templateName, artifactName);
}
}
}
topology.addNodeTemplate(templateBuilder.build());
return topology;
}
use of org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV in project winery by eclipse.
the class DataFlowResource method createRelationshipTemplate.
private TRelationshipTemplate createRelationshipTemplate(RelationshipTypeId relationshipTypeId, TNodeTemplate source, TNodeTemplate target, String dataTransferType) {
// get ConnectsTo RelationshipType to access available properties
IRepository repo = RepositoryFactory.getRepository();
TRelationshipType relationshipType = repo.getElement(relationshipTypeId);
if (Objects.isNull(relationshipType)) {
return null;
}
String relationId = source.getId() + "-connectsTo-" + target.getId();
TRelationshipTemplate.Builder builder = new TRelationshipTemplate.Builder(relationId, relationshipTypeId.getQName(), source, target).setName(relationId);
// add empty properties to avoid errors due to missing properties
if (Objects.nonNull(relationshipType.getWinerysPropertiesDefinition())) {
LinkedHashMap<String, String> propertyList = new LinkedHashMap<>();
WinerysPropertiesDefinition def = relationshipType.getWinerysPropertiesDefinition();
for (PropertyDefinitionKV prop : def.getPropertyDefinitions()) {
propertyList.put(prop.getKey(), "");
}
TEntityTemplate.WineryKVProperties relationProperties = new TEntityTemplate.WineryKVProperties();
relationProperties.setElementName(def.getElementName());
relationProperties.setNamespace(def.getNamespace());
relationProperties.setKVProperties(propertyList);
builder.setProperties(relationProperties);
}
TRelationshipTemplate relation = builder.build();
// evaluate pipe attribute to determine connectsTo direction
if (Objects.nonNull(dataTransferType) && dataTransferType.equalsIgnoreCase(DATA_TRANSFER_TYPE_PULL)) {
// change connectsTo direction in case the corresponding target filter is pulling
relation.setSourceNodeTemplate(target);
relation.setTargetNodeTemplate(source);
relation.getOtherAttributes().put(ModelUtilities.RELATIONSHIP_TEMPLATE_TRANSFER_TYPE, RELATIONSHIP_TEMPLATE_TRANSFER_TYPE_PULL);
}
return relation;
}
use of org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV in project winery by eclipse.
the class PropertiesResource method getEffectiveProperties.
/**
* Get effective properties.
*
* An effective property is either a defined property or a default.
* Inheritance is considered.
* Only winery properties definitions are considered.
*/
@GET
@Path("effective")
@Produces(MediaType.APPLICATION_JSON)
public LinkedHashMap<String, String> getEffectiveProperties() {
// Get entity type of current template
TEntityType entityType = RepositoryFactory.getRepository().getTypeForTemplate(this.template);
// Get complete inheritance hierarchy
List<TEntityType> hierarchy = RepositoryFactory.getRepository().getParentsAndChild(entityType);
// Merge properties definitions
List<PropertyDefinitionKV> propertiesDefinitions = ModelUtilities.mergePropertiesDefinitions(hierarchy);
// Construct effective properties by assigning only defined properties or defaults
LinkedHashMap<String, String> assignedProperties = ModelUtilities.getPropertiesKV(this.template);
LinkedHashMap<String, String> effectiveProperties = new LinkedHashMap<>();
propertiesDefinitions.forEach(propDef -> {
String effectiveValue;
if (assignedProperties != null) {
effectiveValue = assignedProperties.getOrDefault(propDef.getKey(), propDef.getDefaultValue());
} else {
effectiveValue = propDef.getDefaultValue();
}
if (effectiveValue != null) {
effectiveProperties.put(propDef.getKey(), effectiveValue);
}
});
return effectiveProperties;
}
use of org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV in project winery by eclipse.
the class EdmmDependantTest method setup.
@BeforeEach
void setup() {
// region *** NodeType setup ***
QName nodeType1QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type");
TNodeType nodeType1 = new TNodeType();
nodeType1.setName(nodeType1QName.getLocalPart());
nodeType1.setTargetNamespace(nodeType1QName.getNamespaceURI());
nodeTypes.put(nodeType1QName, nodeType1);
QName nodeType2QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type_2");
TNodeType nodeType2 = new TNodeType();
nodeType2.setName(nodeType2QName.getLocalPart());
nodeType2.setTargetNamespace(nodeType2QName.getNamespaceURI());
TEntityType.DerivedFrom derivedFrom = new TNodeType.DerivedFrom();
derivedFrom.setTypeRef(nodeType1QName);
nodeType2.setDerivedFrom(derivedFrom);
nodeTypes.put(nodeType2QName, nodeType2);
QName nodeType3QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type_3");
TNodeType nodeType3 = new TNodeType();
nodeType3.setName(nodeType3QName.getLocalPart());
nodeType3.setTargetNamespace(nodeType3QName.getNamespaceURI());
List<PropertyDefinitionKV> kvList = new ArrayList<>(Arrays.asList(new PropertyDefinitionKV("os_family", "xsd:string"), new PropertyDefinitionKV("public_key", "xsd:string"), new PropertyDefinitionKV("ssh_port", "number")));
WinerysPropertiesDefinition wpd = new WinerysPropertiesDefinition();
wpd.setPropertyDefinitions(kvList);
ModelUtilities.replaceWinerysPropertiesDefinition(nodeType3, wpd);
nodeType3.setProperties(wpd);
nodeTypes.put(nodeType3QName, nodeType3);
QName nodeType4QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type_4");
TNodeType nodeType4 = new TNodeType();
nodeType4.setName(nodeType4QName.getLocalPart());
nodeType4.setTargetNamespace(nodeType4QName.getNamespaceURI());
TOperation start = new TOperation();
start.setName("start");
TOperation stop = new TOperation();
stop.setName("stop");
TInterface lifecycle = new TInterface();
lifecycle.setName("lifecycle_interface");
lifecycle.getOperations().add(start);
lifecycle.getOperations().add(stop);
List<TInterface> tInterfaces = new ArrayList<>();
tInterfaces.add(lifecycle);
nodeType4.setInterfaces(tInterfaces);
nodeTypes.put(nodeType4QName, nodeType4);
// endregion
// region *** ArtifactTemplates setup ***
QName startIaQName = QName.valueOf("{" + NAMESPACE + "}" + "Start_IA");
artifactTemplates.put(startIaQName, new TArtifactTemplate.Builder("Start_IA", startIaQName).addArtifactReference(new TArtifactReference.Builder("/artifacttemplates/" + NAMESPACE_DOUBLE_ENCODED + "/startTestNode4/files/script.sh").build()).build());
QName stopIaQName = QName.valueOf("{" + NAMESPACE + "}" + "Stop_IA");
TArtifactTemplate stopIa = new TArtifactTemplate.Builder("Stop_IA", stopIaQName).addArtifactReference(new TArtifactReference.Builder("/artifacttemplates/" + NAMESPACE_DOUBLE_ENCODED + "/startTestNode4/files/script.sh").build()).build();
artifactTemplates.put(stopIaQName, stopIa);
QName deploymentArtifactIAQName = QName.valueOf("{" + NAMESPACE + "}" + "TestNode1-DA");
TArtifactTemplate deploymentArtifactTemplate = new TArtifactTemplate.Builder("TestNode1-DA", deploymentArtifactIAQName).addArtifactReference(new TArtifactReference.Builder("/artifacttemplates/" + NAMESPACE_DOUBLE_ENCODED + "/testNode1-DA/files/da.war").build()).build();
artifactTemplates.put(deploymentArtifactIAQName, deploymentArtifactTemplate);
// endregion
// region *** NodeTypeImplementations setup ***
QName nodeTypeImpl4QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type_Impl_4");
TImplementationArtifact startArtifact = new TImplementationArtifact.Builder(QName.valueOf("{ex.org}test")).setArtifactRef(startIaQName).setInterfaceName("lifecycle_interface").setOperationName("start").build();
TImplementationArtifact stopArtifact = new TImplementationArtifact.Builder(QName.valueOf("{ex.org}test")).setArtifactRef(stopIaQName).setInterfaceName("lifecycle_interface").setOperationName("stop").build();
nodeTypeImplementations.put(nodeTypeImpl4QName, new TNodeTypeImplementation.Builder(nodeTypeImpl4QName.getLocalPart(), nodeType4QName).addImplementationArtifact(startArtifact).addImplementationArtifact(stopArtifact).build());
// endregion
// region *** RelationType setup ***
QName hostedOnQName = QName.valueOf("{" + NAMESPACE + "}" + "hostedOn");
TRelationshipType hostedOnType = new TRelationshipType();
hostedOnType.setName(hostedOnQName.getLocalPart());
hostedOnType.setTargetNamespace(hostedOnQName.getNamespaceURI());
relationshipTypes.put(hostedOnQName, hostedOnType);
QName connectsToQName = QName.valueOf("{" + NAMESPACE + "}" + "connectsTo");
TRelationshipType connectsToType = new TRelationshipType();
connectsToType.setName(connectsToQName.getLocalPart());
connectsToType.setTargetNamespace(connectsToQName.getNamespaceURI());
relationshipTypes.put(connectsToQName, connectsToType);
// endregion
// region *** create NodeTemplates ***
TDeploymentArtifact artifact = new TDeploymentArtifact.Builder("test_artifact", QName.valueOf("{" + NAMESPACE + "}" + "WAR")).setArtifactRef(deploymentArtifactIAQName).build();
TNodeTemplate nt1 = new TNodeTemplate.Builder("test_node_1", nodeType1QName).setName("test_node_1").addDeploymentArtifact(artifact).build();
nodeTemplates.put(nt1.getId(), nt1);
TNodeTemplate nt2 = new TNodeTemplate();
nt2.setType(nodeType2QName);
nt2.setId("test_node_2");
nt2.setName("test_node_2");
nodeTemplates.put(nt2.getId(), nt2);
TNodeTemplate nt3 = new TNodeTemplate();
nt3.setType(nodeType3QName);
nt3.setId("test_node_3");
nt3.setName("test_node_3");
TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
LinkedHashMap<String, String> nt3Properties = new LinkedHashMap<>();
nt3Properties.put("os_family", "ubuntu");
nt3Properties.put("public_key", "-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----");
nt3Properties.put("ssh_port", "22");
properties.setKVProperties(nt3Properties);
nt3.setProperties(properties);
nodeTemplates.put(nt3.getId(), nt3);
TNodeTemplate nt4 = new TNodeTemplate();
nt4.setType(nodeType4QName);
nt4.setId("test_node_4");
nt4.setName("test_node_4");
nodeTemplates.put(nt4.getId(), nt4);
// endregion
// region *** create RelationshipTemplate ***
TRelationshipTemplate rt13 = new TRelationshipTemplate();
rt13.setType(hostedOnQName);
rt13.setId("1_hosted_on_3");
rt13.setName("1_hosted_on_3");
rt13.setSourceNodeTemplate(nt1);
rt13.setTargetNodeTemplate(nt3);
relationshipTemplates.put(rt13.getId(), rt13);
TRelationshipTemplate rt23 = new TRelationshipTemplate();
rt23.setType(hostedOnQName);
rt23.setId("2_hosted_on_3");
rt23.setName("2_hosted_on_3");
rt23.setSourceNodeTemplate(nt2);
rt23.setTargetNodeTemplate(nt3);
relationshipTemplates.put(rt23.getId(), rt23);
TRelationshipTemplate rt41 = new TRelationshipTemplate();
rt41.setType(hostedOnQName);
rt41.setId("4_hosted_on_1");
rt41.setName("4_hosted_on_1");
rt41.setSourceNodeTemplate(nt4);
rt41.setTargetNodeTemplate(nt1);
relationshipTemplates.put(rt41.getId(), rt41);
TRelationshipTemplate rt12 = new TRelationshipTemplate();
rt12.setType(connectsToQName);
rt12.setId("1_connects_to_2");
rt12.setName("1_connects_to_2");
rt12.setSourceNodeTemplate(nt1);
rt12.setTargetNodeTemplate(nt2);
relationshipTemplates.put(rt12.getId(), rt12);
// endregion
// region *** create edmm type mapping ***
edmm1to1Mapping.put(nodeType1QName, EdmmType.SOFTWARE_COMPONENT);
// edmmTypeMapping.put(nodeType2QName, EdmmType.SOFTWARE_COMPONENT);
edmmTypeExtendsMapping.put(nodeType3QName, EdmmType.COMPUTE);
edmmTypeExtendsMapping.put(nodeType4QName, EdmmType.WEB_APPLICATION);
edmm1to1Mapping.put(hostedOnQName, EdmmType.HOSTED_ON);
edmm1to1Mapping.put(connectsToQName, EdmmType.CONNECTS_TO);
// endregion
}
use of org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV in project winery by eclipse.
the class BackendUtils method initializeProperties.
/**
* Properties need to be initialized in the case of K/V Properties
*
* @param repository The repository to work on
* @param entityTemplate the entity template to update
*/
public static void initializeProperties(IRepository repository, TEntityTemplate entityTemplate) {
Objects.requireNonNull(repository);
Objects.requireNonNull(entityTemplate);
Objects.requireNonNull(entityTemplate.getType());
final TEntityType entityType = repository.getTypeForTemplate(entityTemplate);
final WinerysPropertiesDefinition winerysPropertiesDefinition = entityType.getWinerysPropertiesDefinition();
if (winerysPropertiesDefinition == null) {
return;
}
final LinkedHashMap<String, String> emptyKVProperties = new LinkedHashMap<>();
for (PropertyDefinitionKV definitionKV : winerysPropertiesDefinition.getPropertyDefinitions()) {
emptyKVProperties.put(definitionKV.getKey(), "");
}
TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
properties.setNamespace(winerysPropertiesDefinition.getNamespace());
properties.setElementName(winerysPropertiesDefinition.getElementName());
properties.setKVProperties(emptyKVProperties);
entityTemplate.setProperties(properties);
}
Aggregations