Search in sources :

Example 6 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class ServiceTemplateResource method createParticipantsVersion.

@POST()
@Path("createparticipantsversion")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<Response> createParticipantsVersion() throws IOException {
    IRepository repo = RepositoryFactory.getRepository();
    // create list of responses because we create multiple resources at once
    List<Response> listOfResponses = new ArrayList<>();
    LOGGER.debug("Creating new participants version of Service Template {}...", this.getId());
    ServiceTemplateId id = (ServiceTemplateId) this.getId();
    WineryVersion version = VersionUtils.getVersion(id.getXmlId().getDecoded());
    TTopologyTemplate topologyTemplate = this.getTopology();
    List<TTag> tags = new ArrayList<>();
    Splitting splitting = new Splitting();
    if (topologyTemplate.getParticipants() != null) {
        for (OTParticipant participant : topologyTemplate.getParticipants()) {
            // check if tag with partner in service template
            WineryVersion newVersion = new WineryVersion(participant.getName() + "-" + version.toString().replace("gdm", "ldm"), 1, 1);
            List<OTParticipant> newParticipantList = new ArrayList<>(topologyTemplate.getParticipants());
            // new tag to define participant of service template
            tags.add(new TTag.Builder("participant", participant.getName()).build());
            String choreoValue = splitting.calculateChoreographyTag(this.getServiceTemplate().getTopologyTemplate().getNodeTemplates(), participant.getName());
            tags.add(new TTag.Builder("choreography", choreoValue).build());
            ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionUtils.getNameWithoutVersion(id.getXmlId().getDecoded()) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), false);
            if (repo.exists(newId)) {
                repo.forceDelete(newId);
            }
            ResourceResult response = RestUtils.duplicate(id, newId);
            if (response.getStatus() == Status.CREATED) {
                response.setUri(null);
                response.setMessage(new QNameApiData(newId));
            }
            TServiceTemplate tempServiceTempl = repo.getElement(newId);
            tempServiceTempl.setTags(tags);
            tempServiceTempl.getTopologyTemplate().setParticipants(newParticipantList);
            listOfResponses.add(response.getResponse());
            // set element to propagate changed tags
            repo.setElement(newId, tempServiceTempl);
        }
    }
    return listOfResponses;
}
Also used : TTag(org.eclipse.winery.model.tosca.TTag) QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) OTParticipant(org.eclipse.winery.model.tosca.extensions.OTParticipant) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) Splitting(org.eclipse.winery.repository.splitting.Splitting) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) IRepository(org.eclipse.winery.repository.backend.IRepository) WineryVersion(org.eclipse.winery.common.version.WineryVersion) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 7 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class TopologyTemplateResource method split.

@Path("split/")
@Produces(MediaType.TEXT_PLAIN)
@POST
public Response split(@Context UriInfo uriInfo) {
    Splitting splitting = new Splitting();
    ServiceTemplateId splitServiceTemplateId;
    try {
        splitServiceTemplateId = splitting.splitTopologyOfServiceTemplate((ServiceTemplateId) this.parent.getId());
    } catch (Exception e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not split. " + e.getMessage()).build();
    }
    URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(splitServiceTemplateId));
    return Response.created(url).build();
}
Also used : Splitting(org.eclipse.winery.repository.splitting.Splitting) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) URI(java.net.URI) InvalidParameterException(java.security.InvalidParameterException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) POST(javax.ws.rs.POST)

Example 8 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class TopologyTemplateResource method match.

@Path("match/")
@Produces(MediaType.TEXT_PLAIN)
@POST
public Response match(@Context UriInfo uriInfo) {
    Splitting splitting = new Splitting();
    ServiceTemplateId matchedServiceTemplateId;
    try {
        matchedServiceTemplateId = splitting.matchTopologyOfServiceTemplate((ServiceTemplateId) this.parent.getId());
    } catch (Exception e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not match. " + e.getMessage()).build();
    }
    URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(matchedServiceTemplateId));
    return Response.created(url).build();
}
Also used : Splitting(org.eclipse.winery.repository.splitting.Splitting) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) URI(java.net.URI) InvalidParameterException(java.security.InvalidParameterException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) POST(javax.ws.rs.POST)

Example 9 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class TopologyTemplateResource method getHTML.

@GET
@ApiOperation(value = "?edit is used in the URL to get the jsPlumb-based editor")
@Produces(MediaType.TEXT_HTML)
public // @formatter:off
Response getHTML(@QueryParam(value = "edit") String edit, @QueryParam(value = "script") @ApiParam(value = "the script to include in a <script> tag. The function wineryViewExternalScriptOnLoad if it is defined. Only available if 'view' is also set") String script, @QueryParam(value = "view") String view, @QueryParam(value = "autoLayoutOnLoad") String autoLayoutOnLoad, @Context UriInfo uriInfo) {
    // @formatter:on
    Response res;
    String JSPName;
    String location = Environments.getInstance().getUiConfig().getEndpoints().get("topologymodeler");
    location = uriInfo.getBaseUri().resolve(location).toString();
    // at the topology modeler, jersey needs to have an absolute path
    URI repositoryURI = uriInfo.getBaseUri();
    location = location + "/?repositoryURL=";
    location = location + EncodingUtil.URLencode(repositoryURI.toString());
    ServiceTemplateId serviceTemplate = (ServiceTemplateId) this.parent.getId();
    location = location + "&ns=";
    location = location + serviceTemplate.getNamespace().getEncoded();
    location = location + "&id=";
    location = location + serviceTemplate.getXmlId().getEncoded();
    if (edit == null) {
        // TODO: Render-only mode
        // currently also the edit mode
        URI uri = URI.create(location);
        res = Response.seeOther(uri).build();
    } else {
        // edit mode
        URI uri = URI.create(location);
        res = Response.seeOther(uri).build();
    }
    return res;
}
Also used : Response(javax.ws.rs.core.Response) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class TopologyTemplateResource method applyGroupingAndPlacement.

@POST
@Path("applyplacement")
@Produces(MediaType.APPLICATION_JSON)
public Response applyGroupingAndPlacement(@Context UriInfo uriInfo) {
    try {
        TTopologyTemplate topology = PlacementUtils.groupAndPlaceComponents((ServiceTemplateId) this.parent.getId(), this.topologyTemplate);
        this.parent.setTopology(topology, this.type);
        RestUtils.persist(this.parent);
        ServiceTemplateId thisServiceTemplateId = (ServiceTemplateId) this.parent.getId();
        URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(thisServiceTemplateId));
        return Response.created(url).build();
    } catch (InvalidParameterException e) {
        LOGGER.debug("Error while grouping and placing: {}", e.getMessage());
        return Response.serverError().entity(e.getMessage()).build();
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)126 Test (org.junit.jupiter.api.Test)73 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)44 ArrayList (java.util.ArrayList)41 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)40 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)35 QName (javax.xml.namespace.QName)25 IOException (java.io.IOException)24 IRepository (org.eclipse.winery.repository.backend.IRepository)19 List (java.util.List)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 HashMap (java.util.HashMap)15 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)15 Map (java.util.Map)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)14 URI (java.net.URI)13 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)13 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13