Search in sources :

Example 16 with ServiceTemplateId

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;
}
Also used : QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId)

Example 17 with ServiceTemplateId

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();
}
Also used : FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) URI(java.net.URI) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)

Example 18 with ServiceTemplateId

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));
}
Also used : PlanId(org.eclipse.winery.common.ids.elements.PlanId) XmlId(org.eclipse.winery.common.ids.XmlId) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) PlansId(org.eclipse.winery.common.ids.elements.PlansId)

Example 19 with ServiceTemplateId

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();
}
Also used : Response(javax.ws.rs.core.Response) Splitting(org.eclipse.winery.repository.splitting.Splitting) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) URI(java.net.URI) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 20 with ServiceTemplateId

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();
}
Also used : QName(javax.xml.namespace.QName) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.common.ids.definitions.ServiceTemplateId) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) POST(javax.ws.rs.POST)

Aggregations

ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)34 QName (javax.xml.namespace.QName)12 Test (org.junit.Test)12 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 RelationshipTypeId (org.eclipse.winery.common.ids.definitions.RelationshipTypeId)5 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)5 POST (javax.ws.rs.POST)4 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)4 NonNull (org.eclipse.jdt.annotation.NonNull)3 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)3 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)3 RequirementTypeId (org.eclipse.winery.common.ids.definitions.RequirementTypeId)3 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)3 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)3 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)3