Skip to content

Commit

Permalink
adding selfserviceurl
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeisel committed Nov 20, 2023
1 parent cb1bc76 commit d415e73
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -675,8 +678,55 @@ public static ServiceTemplateId completeModelBasedOnReqs(ServiceTemplateId servi
placementId = newServiceTemplateId;
}

// Set selfserviceUrl for completed Templates

TServiceTemplate completedST = repo.getElement(placementId);

final List<String> allowedPortNames = List.of("VMOpenPorts");
final List<String> allowedIPNames = List.of("VMIP");

TBoundaryDefinitions definitions = new TBoundaryDefinitions();
TBoundaryDefinitions.Properties properties = new TBoundaryDefinitions.Properties();
List<TPropertyMapping> propertyMappings = new ArrayList<>();

assert completedST.getTopologyTemplate() != null;
for (TEntityTemplate nt: completedST.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
String suitableIPKey = null;
String suitablePortKey = null;
if( nt.getProperties() != null){
LinkedHashMap<String, String> kvProperties = ((TEntityTemplate.WineryKVProperties) nt.getProperties()).getKVProperties();
for ( Map.Entry<String, String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d415e73

Please sign in to comment.