From d415e73b5b0210daada46b2c2851561572571e52 Mon Sep 17 00:00:00 2001 From: mbeisel Date: Mon, 20 Nov 2023 19:38:13 +0100 Subject: [PATCH] adding selfserviceurl --- .../adaptation/placement/PlacementUtils.java | 52 ++++++++++++++++++- .../repository/splitting/Splitting.java | 1 + 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/org.eclipse.winery.model.adaptation/src/main/java/org/eclipse/winery/model/adaptation/placement/PlacementUtils.java b/org.eclipse.winery.model.adaptation/src/main/java/org/eclipse/winery/model/adaptation/placement/PlacementUtils.java index e70d7c5757..009abc1e55 100644 --- a/org.eclipse.winery.model.adaptation/src/main/java/org/eclipse/winery/model/adaptation/placement/PlacementUtils.java +++ b/org.eclipse.winery.model.adaptation/src/main/java/org/eclipse/winery/model/adaptation/placement/PlacementUtils.java @@ -31,9 +31,11 @@ import javax.xml.namespace.QName; import org.eclipse.winery.model.ids.definitions.ServiceTemplateId; +import org.eclipse.winery.model.tosca.TBoundaryDefinitions; import org.eclipse.winery.model.tosca.TEntityTemplate; import org.eclipse.winery.model.tosca.TNodeTemplate; import org.eclipse.winery.model.tosca.TPolicy; +import org.eclipse.winery.model.tosca.TPropertyMapping; import org.eclipse.winery.model.tosca.TRelationshipTemplate; import org.eclipse.winery.model.tosca.TServiceTemplate; import org.eclipse.winery.model.tosca.TTag; @@ -650,6 +652,7 @@ public static ServiceTemplateId completeModelBasedOnReqs(ServiceTemplateId servi IRepository repo = RepositoryFactory.getRepository(); try { + ServiceTemplateId newId = null; // create new temporary ServiceTemplate as working copy ServiceTemplateId placementId = new ServiceTemplateId(serviceTemplateId.getNamespace().getDecoded(), VersionSupport.getNewComponentVersionId(serviceTemplateId, "placement"), false); @@ -675,8 +678,55 @@ public static ServiceTemplateId completeModelBasedOnReqs(ServiceTemplateId servi placementId = newServiceTemplateId; } + // Set selfserviceUrl for completed Templates + + TServiceTemplate completedST = repo.getElement(placementId); + + final List allowedPortNames = List.of("VMOpenPorts"); + final List allowedIPNames = List.of("VMIP"); + + TBoundaryDefinitions definitions = new TBoundaryDefinitions(); + TBoundaryDefinitions.Properties properties = new TBoundaryDefinitions.Properties(); + List propertyMappings = new ArrayList<>(); + + assert completedST.getTopologyTemplate() != null; + for (TEntityTemplate nt: completedST.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) { + String suitableIPKey = null; + String suitablePortKey = null; + if( nt.getProperties() != null){ + LinkedHashMap kvProperties = ((TEntityTemplate.WineryKVProperties) nt.getProperties()).getKVProperties(); + for ( Map.Entry entry : kvProperties.entrySet()) { + if (allowedIPNames.contains(entry.getKey())){ + suitableIPKey = entry.getKey(); + } if (allowedPortNames.contains(entry.getKey())){ + suitablePortKey = entry.getKey(); + } + } + if (suitableIPKey != null && suitablePortKey != null) { + String targetPropertyRef = "concat('http://', " + nt.getId() + ".Properties." + suitableIPKey + ", ':', " + nt.getId() + ".Properties." + suitablePortKey + "')"; + TPropertyMapping selfserviceProperty = new TPropertyMapping("/*[local-name()='selfserviceApplicationUrl']", nt, targetPropertyRef); + propertyMappings.add(selfserviceProperty); + properties.setPropertyMappings(propertyMappings); + definitions.setProperties(properties); + completedST.setBoundaryDefinitions(definitions); +// repo.setElement(placementId, completedST); + + //save completed ServiceTemplate using originalname + completed + newId = new ServiceTemplateId( + serviceTemplateId.getNamespace().getDecoded(), + VersionSupport.getNewComponentVersionId(serviceTemplateId, "completed"), + false); + completedST.setId(newId.getXmlId().getDecoded()); + completedST.setName(newId.getXmlId().getDecoded()); + repo.setElement(newId, completedST); + repo.forceDelete(placementId); + break; + } + } + } + // returned completed topologyId - return placementId; + return newId; } catch (Exception e) { LOGGER.error("Exception while completing topology: {}", e.getMessage()); return null; diff --git a/org.eclipse.winery.repository/src/main/java/org/eclipse/winery/repository/splitting/Splitting.java b/org.eclipse.winery.repository/src/main/java/org/eclipse/winery/repository/splitting/Splitting.java index 49e340b967..1087f5c5f3 100644 --- a/org.eclipse.winery.repository/src/main/java/org/eclipse/winery/repository/splitting/Splitting.java +++ b/org.eclipse.winery.repository/src/main/java/org/eclipse/winery/repository/splitting/Splitting.java @@ -1800,6 +1800,7 @@ public TTopologyTemplate getMatchingTopology(TServiceTemplate serviceTemplate, L // Filter NodeTemplates based on Blacklist compatibleNodeTemplates = compatibleNodeTemplates.stream().filter(nt -> !blacklist.contains(nt.getType())).toList(); +// compatibleNodeTemplates = compatibleNodeTemplates.stream().filter(nt -> blacklist.stream().noneMatch(bl -> bl.getLocalPart().equals(nt.getType().getLocalPart()))).toList(); // Filter NodeTemplates based on Policies IRepository repositoryFactory = RepositoryFactory.getRepository();