Skip to content

Commit

Permalink
enable selfserviceapplicationurls in servicetemplates
Browse files Browse the repository at this point in the history
fix id scheme for relations during completion
  • Loading branch information
mbeisel committed Nov 21, 2023
1 parent d415e73 commit d7ea8d7
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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.TSelfServiceApplicationUrl;
import org.eclipse.winery.model.tosca.TServiceTemplate;
import org.eclipse.winery.model.tosca.TTag;
import org.eclipse.winery.model.tosca.TTopologyTemplate;
Expand Down Expand Up @@ -642,24 +643,26 @@ private static String getNextProvider(HashMap<String, List<TNodeTemplate>> provi
/**
* Completes the model based on given nodetype requirements.
*
* @param serviceTemplateId the ID of the ServiceTemplate to complete
* @param incompleteServiceTemplateId the ID of the ServiceTemplate to complete
* @param topology the incomplete TopologyTemplate to complete
* @return the completed TopologyTemplate if completion is successful, the cleared and blacklisted TopologyTemplate
* otherwise
*/
public static ServiceTemplateId completeModelBasedOnReqs(ServiceTemplateId serviceTemplateId, TTopologyTemplate topology, List<QName> blacklist, Map<String, String> policies) {
public static ServiceTemplateId completeModelBasedOnReqs(ServiceTemplateId incompleteServiceTemplateId, TTopologyTemplate topology, List<QName> blacklist, Map<String, String> policies) throws Exception {
Splitting splitting = new Splitting();
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);
TServiceTemplate incompleteServiceTemplate = repo.getElement(incompleteServiceTemplateId);
ServiceTemplateId placementId = new ServiceTemplateId(incompleteServiceTemplateId.getNamespace().getDecoded(),
VersionSupport.getNewComponentVersionId(incompleteServiceTemplateId, "placement"), false);
repo.forceDelete(placementId);
TServiceTemplate placementServiceTemplate = new TServiceTemplate.Builder(placementId.getXmlId().getDecoded(), topology)
.setName(placementId.getXmlId().getDecoded())
.setTargetNamespace(serviceTemplateId.getNamespace().getDecoded())
.setTargetNamespace(incompleteServiceTemplateId.getNamespace().getDecoded())
// .setBoundaryDefinitions(incompleteServiceTemplate.getBoundaryDefinitions())
.build();

// resolve open requirements until the topology is completed
Expand All @@ -678,27 +681,27 @@ public static ServiceTemplateId completeModelBasedOnReqs(ServiceTemplateId servi
placementId = newServiceTemplateId;
}

// Set selfserviceUrl for completed Templates

// Set selfserviceUrl for completed Templates that DO SPECIFY BOUNDARYDEFINITIONS required for selfserviceurl
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()) {
for (TEntityTemplate nt : completedST.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
String suitableIPKey = null;
String suitablePortKey = null;
if( nt.getProperties() != 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())){
for (Map.Entry<String, String> entry : kvProperties.entrySet()) {
if (allowedIPNames.contains(entry.getKey())) {
suitableIPKey = entry.getKey();
} if (allowedPortNames.contains(entry.getKey())){
}
if (allowedPortNames.contains(entry.getKey())) {
suitablePortKey = entry.getKey();
}
}
Expand All @@ -707,14 +710,15 @@ public static ServiceTemplateId completeModelBasedOnReqs(ServiceTemplateId servi
TPropertyMapping selfserviceProperty = new TPropertyMapping("/*[local-name()='selfserviceApplicationUrl']", nt, targetPropertyRef);
propertyMappings.add(selfserviceProperty);
properties.setPropertyMappings(propertyMappings);

properties.setSelfServiceApplicationUrl(new TSelfServiceApplicationUrl("http://www.eclipse.org/winery/model/selfservice"));
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"),
incompleteServiceTemplateId.getNamespace().getDecoded(),
VersionSupport.getNewComponentVersionId(incompleteServiceTemplateId, "completed"),
false);
completedST.setId(newId.getXmlId().getDecoded());
completedST.setName(newId.getXmlId().getDecoded());
Expand All @@ -724,12 +728,11 @@ public static ServiceTemplateId completeModelBasedOnReqs(ServiceTemplateId servi
}
}
}

// returned completed topologyId
return newId;
} catch (Exception e) {
LOGGER.error("Exception while completing topology: {}", e.getMessage());
return null;
throw new Exception(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public void accept(Visitor visitor) {
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"any",
"propertyMappings"
"propertyMappings",
"selfServiceApplicationUrl"
})
public static class Properties implements Serializable {

Expand All @@ -159,6 +160,18 @@ public static class Properties implements Serializable {
@XmlElementWrapper(name = "PropertyMappings")
@XmlElement(name = "PropertyMapping", required = true)
protected List<TPropertyMapping> propertyMappings;
@XmlElement(name = "SelfServiceApplicationUrl")
protected TSelfServiceApplicationUrl selfServiceApplicationUrl;

@Nullable
public TSelfServiceApplicationUrl getSelfServiceApplicationUrl() {
return selfServiceApplicationUrl;
}

public void setSelfServiceApplicationUrl(TSelfServiceApplicationUrl selfServiceApplicationUrl) {
this.selfServiceApplicationUrl = selfServiceApplicationUrl;
}


@Nullable
public Object getAny() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/

package org.eclipse.winery.model.tosca;

import java.io.Serializable;
import java.util.Objects;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

import org.eclipse.winery.model.tosca.visitor.Visitor;

import org.eclipse.jdt.annotation.NonNull;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "tSelfServiceApplicationUrl")
public class TSelfServiceApplicationUrl implements Serializable {

public String getSelfServiceApplicationUrl() {
return selfServiceApplicationUrl;
}

public void setSelfServiceApplicationUrl(String selfServiceApplicationUrl) {
this.selfServiceApplicationUrl = selfServiceApplicationUrl;
}

@XmlAttribute(name = "xmlns")
protected String selfServiceApplicationUrl;

@Deprecated // used for XML deserialization of API request content
public TSelfServiceApplicationUrl() {
}

public TSelfServiceApplicationUrl(@NonNull String selfServiceApplicationUrl) {
this.selfServiceApplicationUrl = selfServiceApplicationUrl;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof org.eclipse.winery.model.tosca.TSelfServiceApplicationUrl)) return false;
org.eclipse.winery.model.tosca.TSelfServiceApplicationUrl that = (org.eclipse.winery.model.tosca.TSelfServiceApplicationUrl) o;
return Objects.equals(selfServiceApplicationUrl, that.selfServiceApplicationUrl);
}

@Override
public int hashCode() {
return Objects.hash(selfServiceApplicationUrl);
}

public void accept(Visitor visitor) {
visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.eclipse.winery.model.tosca.TRelationshipTemplate;
import org.eclipse.winery.model.tosca.TRequirement;
import org.eclipse.winery.model.tosca.TRequirementRef;
import org.eclipse.winery.model.tosca.TSelfServiceApplicationUrl;
import org.eclipse.winery.model.tosca.TServiceTemplate;
import org.eclipse.winery.model.tosca.TTag;
import org.eclipse.winery.model.tosca.TTopologyTemplate;
Expand Down Expand Up @@ -326,6 +327,10 @@ public void visit(TBoundaryDefinitions.Properties properties) {
}
}

public void visit(TSelfServiceApplicationUrl applicationUrl) {
// this is a leaf, so no action to take
}

public void visit(TPropertyMapping propertyMapping) {
// this is a leaf, so no action to take
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public void accept(Visitor visitor) {
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"any",
"propertyMappings"
"propertyMappings",
"selfServiceApplicationUrl"
})
public static class Properties implements Serializable {

Expand All @@ -159,7 +160,17 @@ public static class Properties implements Serializable {
@XmlElementWrapper(name = "PropertyMappings")
@XmlElement(name = "PropertyMapping", required = true)
protected List<XTPropertyMapping> propertyMappings;
@XmlElement(name = "SelfServiceApplicationUrl")
protected XTSelfServiceApplicationUrl selfServiceApplicationUrl;

@Nullable
public XTSelfServiceApplicationUrl getSelfServiceApplicationUrl() {
return selfServiceApplicationUrl;
}

public void setSelfServiceApplicationUrl(XTSelfServiceApplicationUrl selfServiceApplicationUrl) {
this.selfServiceApplicationUrl = selfServiceApplicationUrl;
}
@Nullable
public Object getAny() {
return any;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.eclipse.winery.model.tosca.xml; /*******************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/


import java.io.Serializable;
import java.util.Objects;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

import org.eclipse.winery.model.tosca.xml.visitor.Visitor;

import org.eclipse.jdt.annotation.NonNull;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "tSelfServiceApplicationUrl")
public class XTSelfServiceApplicationUrl implements Serializable {

public String getSelfServiceApplicationUrl() {
return selfServiceApplicationUrl;
}

public void setSelfServiceApplicationUrl(String selfServiceApplicationUrl) {
this.selfServiceApplicationUrl = selfServiceApplicationUrl;
}

@XmlAttribute(name = "xmlns")
protected String selfServiceApplicationUrl;

@Deprecated // used for XML deserialization of API request content
public XTSelfServiceApplicationUrl() {
}

public XTSelfServiceApplicationUrl(@NonNull String selfServiceApplicationUrl) {
this.selfServiceApplicationUrl = selfServiceApplicationUrl;
}

private XTSelfServiceApplicationUrl(XTSelfServiceApplicationUrl.Builder builder) {
this.selfServiceApplicationUrl = builder.selfServiceApplicationUrl;
}


@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof org.eclipse.winery.model.tosca.xml.XTSelfServiceApplicationUrl)) return false;
org.eclipse.winery.model.tosca.xml.XTSelfServiceApplicationUrl that = (org.eclipse.winery.model.tosca.xml.XTSelfServiceApplicationUrl) o;
return Objects.equals(selfServiceApplicationUrl, that.selfServiceApplicationUrl);
}

@Override
public int hashCode() {
return Objects.hash(selfServiceApplicationUrl);
}


public static class Builder {

private final String selfServiceApplicationUrl;

public Builder(String selfServiceApplicationUrl) {
this.selfServiceApplicationUrl = selfServiceApplicationUrl;
}

public XTSelfServiceApplicationUrl build() {
return new XTSelfServiceApplicationUrl(this);
}
}

public void accept(Visitor visitor) {
visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.winery.model.tosca.xml.XTRelationshipTemplate;
import org.eclipse.winery.model.tosca.xml.XTRequirement;
import org.eclipse.winery.model.tosca.xml.XTRequirementRef;
import org.eclipse.winery.model.tosca.xml.XTSelfServiceApplicationUrl;
import org.eclipse.winery.model.tosca.xml.XTServiceTemplate;
import org.eclipse.winery.model.tosca.xml.XTTag;
import org.eclipse.winery.model.tosca.xml.XTTopologyTemplate;
Expand Down Expand Up @@ -312,6 +313,10 @@ public void visit(XTBoundaryDefinitions.Properties properties) {
}
}

public void visit(XTSelfServiceApplicationUrl selfServiceApplicationUrl) {
// this is a leaf, so no action to take
}

public void visit(XTPropertyMapping propertyMapping) {
// this is a leaf, so no action to take
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public Response completeModel(@Context UriInfo uriInfo, CompletionInputData comp
PlacementUtils.completeModelBasedOnReqs((ServiceTemplateId) this.parent.getId(), this.topologyTemplate, blacklist, policies);
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(newServiceTemplateId));
return Response.created(url).build();
} catch (InvalidParameterException e) {
} catch (Exception e) {
LOGGER.debug("Error while completing model: {}", e.getMessage());
return Response.serverError().entity(e.getMessage()).build();
}
Expand All @@ -633,7 +633,7 @@ public Response checkEquivalency(@Context UriInfo uriInfo) {

@POST
@Path("iscomplete")
@Produces(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response isComplete(@Context UriInfo uriInfo) {
try {
Boolean isComplete =
Expand Down
Loading

0 comments on commit d7ea8d7

Please sign in to comment.