use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class ServiceTemplatesResource method getXaaSPackageTemplates.
private Collection<ServiceTemplateId> getXaaSPackageTemplates(QName artifactType) {
Collection<ServiceTemplateId> xaasPackages = new ArrayList<ServiceTemplateId>();
for (ServiceTemplateId serviceTemplate : this.getXaaSPackageTemplates()) {
String artifactTypeTagValue = RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageArtifactType");
QName taggedArtifactType = QName.valueOf(artifactTypeTagValue);
if (taggedArtifactType.equals(artifactType)) {
xaasPackages.add(serviceTemplate);
}
}
return xaasPackages;
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class ServiceTemplatesResource method createFromArtifact.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createFromArtifact(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body, @FormDataParam("artifactType") QName artifactType, @FormDataParam("nodeTypes") List<FormDataBodyPart> nodeTypesList, @FormDataParam("infrastructureNodeType") QName infrastructureNodeType, @FormDataParam("tags") List<FormDataBodyPart> sentTagsList, @Context UriInfo uriInfo) throws IllegalArgumentException, JAXBException, IOException {
Set<String> sentTags = new HashSet<>();
if (sentTagsList != null) {
for (FormDataBodyPart tag : sentTagsList) {
sentTags.add(tag.getValue());
}
}
Set<String> tags = RestUtils.clean(sentTags);
Set<QName> nodeTypes = new HashSet<>();
for (FormDataBodyPart nodetype : nodeTypesList) {
nodeTypes.add(QName.valueOf(nodetype.getValue()));
}
nodeTypes = RestUtils.cleanQNameSet(nodeTypes);
Collection<ServiceTemplateId> xaasPackages = this.getXaaSPackageTemplates(artifactType);
Collection<ServiceTemplateId> toRemove = new ArrayList<ServiceTemplateId>();
// check whether the serviceTemplate contains all the given nodeTypes
for (ServiceTemplateId serviceTemplate : xaasPackages) {
if (!RestUtils.containsNodeTypes(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), nodeTypes) | !RestUtils.containsTags(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), tags)) {
toRemove.add(serviceTemplate);
continue;
}
if (infrastructureNodeType != null && !infrastructureNodeType.getLocalPart().equals("undefined")) {
if (RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageInfrastructure") == null) {
toRemove.add(serviceTemplate);
continue;
} else {
String value = RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageInfrastructure");
String localName = value.split("}")[1];
String namespace = value.split("}")[0].substring(1);
if (!infrastructureNodeType.equals(new QName(namespace, localName))) {
toRemove.add(serviceTemplate);
}
}
}
}
xaasPackages.removeAll(toRemove);
if (xaasPackages.size() <= 0) {
return Response.serverError().entity("No suitable ServiceTemplate found for given artifact and configuration").build();
}
// take the first found serviceTemplate
ServiceTemplateId serviceTemplate = xaasPackages.iterator().next();
// create new name for the cloned sTemplate
String newTemplateName = fileDetail.getFileName() + "ServiceTemplate";
// create artifactTemplate for the uploaded artifact
ArtifactTemplateId artifactTemplateId = RestUtils.createArtifactTemplate(uploadedInputStream, fileDetail, body, artifactType, uriInfo);
// clone serviceTemplate
ServiceTemplateId serviceTemplateId = RestUtils.cloneServiceTemplate(serviceTemplate, newTemplateName, fileDetail.getFileName());
if (RestUtils.hasDA(serviceTemplateId, RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageNode"), RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageDeploymentArtifact"))) {
// inject artifact as DA into cloned ServiceTemplate
BackendUtils.injectArtifactTemplateIntoDeploymentArtifact(serviceTemplateId, RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageNode"), RestUtils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageDeploymentArtifact"), artifactTemplateId);
} else {
return Response.serverError().entity("Tagged DeploymentArtifact couldn't be found on given specified NodeTemplate").build();
}
URI absUri = RestUtils.getAbsoluteURI(serviceTemplateId);
// http://localhost:8080/winery/servicetemplates/winery/servicetemplates/http%253A%252F%252Fopentosca.org%252Fservicetemplates/hs_err_pid13228.logServiceTemplate/
// http://localhost:8080/winery/servicetemplates/winery/servicetemplates/http%253A%252F%252Fopentosca.org%252Fservicetemplates/java0.logServiceTemplate/
String absUriString = absUri.toString().replace("/winery/servicetemplates", "");
absUri = URI.create(absUriString);
return Response.created(absUri).build();
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class PlanResource method getId.
/**
* Determines the id of the current resource
*/
private PlanId getId() {
ServiceTemplateId sId = (ServiceTemplateId) this.getServiceTemplateResource().getId();
PlansId psId = new PlansId(sId);
return new PlanId(psId, new XmlId(this.o.getId(), false));
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TopologyTemplateResource method composeServiceTemplates.
@POST
@Path("compose/")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response composeServiceTemplates(CompositionData compositionData, @Context UriInfo uriInfo) {
Splitting splitting = new Splitting();
String newComposedSolutionServiceTemplateId = compositionData.getTargetid();
List<ServiceTemplateId> compositionServiceTemplateIDs = new ArrayList<>();
compositionData.getCspath().stream().forEach(entry -> {
QName qName = QName.valueOf(entry);
compositionServiceTemplateIDs.add(new ServiceTemplateId(qName.getNamespaceURI(), qName.getLocalPart(), false));
});
ServiceTemplateId composedServiceTemplateId;
try {
composedServiceTemplateId = splitting.composeServiceTemplates(newComposedSolutionServiceTemplateId, compositionServiceTemplateIDs);
} catch (Exception e) {
e.printStackTrace();
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
}
Response mergeResponse = this.mergeWithOtherTopologyTemplate(composedServiceTemplateId.getQName().toString());
if (mergeResponse.getStatus() == 500) {
return mergeResponse;
}
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(serviceTemplateRes.getId()));
String location = url.toString();
location = location + "topologytemplate?edit";
url = RestUtils.createURI(location);
LOGGER.debug("URI of the composed Service Template {}", url.toString());
return Response.created(url).build();
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TopologyTemplateResource method mergeWithOtherTopologyTemplate.
/**
* Only works for relationship templates connecting node templates; and not capabilities
*/
@Path("merge/")
@Consumes(MediaType.TEXT_PLAIN)
@POST
public Response mergeWithOtherTopologyTemplate(String strOtherServiceTemplateQName) {
QName otherServiceTemplateQName = QName.valueOf(strOtherServiceTemplateQName);
ServiceTemplateId otherServiceTemplateId = new ServiceTemplateId(otherServiceTemplateQName);
ServiceTemplateId thisServiceTemplateId = (ServiceTemplateId) this.serviceTemplateRes.getId();
try {
BackendUtils.mergeServiceTemplateAinServiceTemplateB(otherServiceTemplateId, thisServiceTemplateId);
} catch (IOException e) {
LOGGER.debug("Could not merge", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e).build();
}
return Response.noContent().build();
}
Aggregations