Search in sources :

Example 1 with OTParticipant

use of org.eclipse.winery.model.tosca.extensions.OTParticipant 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 2 with OTParticipant

use of org.eclipse.winery.model.tosca.extensions.OTParticipant in project winery by eclipse.

the class EdmmConverter method transform.

public EntityGraph transform(TServiceTemplate serviceTemplate) {
    EntityGraph entityGraph = new EntityGraph();
    setMetadata(entityGraph);
    List<TNodeTemplate> nodeTemplates = serviceTemplate.getTopologyTemplate().getNodeTemplates();
    List<TRelationshipTemplate> relationshipTemplates = serviceTemplate.getTopologyTemplate().getRelationshipTemplates();
    if (!nodeTemplates.isEmpty()) {
        entityGraph.addEntity(new MappingEntity(EntityGraph.COMPONENTS, entityGraph));
    }
    nodeTemplates.forEach(nodeTemplate -> createNode(nodeTemplate, entityGraph));
    relationshipTemplates.forEach(relationship -> createRelation(relationship, entityGraph));
    List<OTParticipant> participants = serviceTemplate.getTopologyTemplate().getParticipants();
    if (participants != null && !participants.isEmpty()) {
        entityGraph.addEntity(new MappingEntity(EntityGraph.PARTICIPANTS, entityGraph));
        participants.forEach(participant -> createParticipant(participant, nodeTemplates, entityGraph));
    }
    createTechnologyMapping(nodeTemplates, entityGraph);
    return entityGraph;
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) MappingEntity(io.github.edmm.core.parser.MappingEntity) OTParticipant(org.eclipse.winery.model.tosca.extensions.OTParticipant)

Example 3 with OTParticipant

use of org.eclipse.winery.model.tosca.extensions.OTParticipant in project winery by eclipse.

the class ServiceTemplateResource method createPlaceholderSubstituteVersion.

@Path("placeholdersubstitution")
@POST()
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createPlaceholderSubstituteVersion() throws IOException, SplittingException {
    TTopologyTemplate originTopologyTemplate = this.getServiceTemplate().getTopologyTemplate();
    if (originTopologyTemplate == null) {
        return Response.notModified().build();
    }
    List<TTag> tagsOfServiceTemplate = this.getServiceTemplate().getTags();
    List<OTParticipant> participants = originTopologyTemplate.getParticipants();
    String participantId = "";
    List<TTag> newTagList = new ArrayList<>();
    for (TTag tagOfServiceTemplate : tagsOfServiceTemplate) {
        if (tagOfServiceTemplate.getName().equals("participant")) {
            participantId = tagOfServiceTemplate.getValue();
            newTagList.add(tagOfServiceTemplate);
        } else if (!tagOfServiceTemplate.getName().equals("choreography")) {
            newTagList.add(tagOfServiceTemplate);
        }
    }
    final String finalParticipantId = participantId;
    List<String> nodeTemplatesWithNewHost = new ArrayList<>();
    for (TNodeTemplate tNodeTemplate : originTopologyTemplate.getNodeTemplates()) {
        // Multiple participants can be annotated on one node template
        Optional<String> nodeOwners = ModelUtilities.getParticipant(tNodeTemplate);
        if (nodeOwners.isPresent() && nodeOwners.get().contains(finalParticipantId)) {
            for (TRelationshipTemplate tRelationshipTemplate : ModelUtilities.getIncomingRelationshipTemplates(originTopologyTemplate, tNodeTemplate)) {
                nodeTemplatesWithNewHost.add(ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(originTopologyTemplate, tRelationshipTemplate).getId());
            }
        }
    }
    ServiceTemplateId id = (ServiceTemplateId) this.getId();
    WineryVersion version = VersionUtils.getVersion(id.getXmlId().getDecoded());
    WineryVersion newVersion = new WineryVersion("_substituted_" + version.toString(), 1, 1);
    ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionUtils.getNameWithoutVersion(id.getXmlId().getDecoded()) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), false);
    IRepository repo = RepositoryFactory.getRepository();
    if (repo.exists(newId)) {
        repo.forceDelete(newId);
    }
    ResourceResult response = RestUtils.duplicate(id, newId);
    TServiceTemplate newServiceTemplate = repo.getElement(newId);
    newServiceTemplate.setTopologyTemplate(BackendUtils.clone(originTopologyTemplate));
    newServiceTemplate.getTopologyTemplate().setParticipants(participants);
    Splitting splitting = new Splitting();
    Map<String, List<TTopologyTemplate>> resultList = splitting.getHostingInjectionOptions(BackendUtils.clone(newServiceTemplate.getTopologyTemplate()));
    for (Map.Entry<String, List<TTopologyTemplate>> entry : resultList.entrySet()) {
        Optional<String> nodeOwners = ModelUtilities.getParticipant(newServiceTemplate.getTopologyTemplate().getNodeTemplate(entry.getKey()));
        if (nodeOwners.isPresent() && nodeOwners.get().contains(finalParticipantId)) {
            if (nodeTemplatesWithNewHost.contains(entry.getKey()) && !resultList.get(entry.getKey()).isEmpty()) {
                Map<String, TTopologyTemplate> choiceTopologyTemplate = new LinkedHashMap<>();
                choiceTopologyTemplate.put(entry.getKey(), entry.getValue().get(0));
                splitting.injectNodeTemplates(newServiceTemplate.getTopologyTemplate(), choiceTopologyTemplate, InjectRemoval.REMOVE_REPLACED);
                for (TNodeTemplate injectNodeTemplate : choiceTopologyTemplate.get(entry.getKey()).getNodeTemplates()) {
                    injectNodeTemplate.getOtherAttributes().put(QNAME_PARTICIPANT, finalParticipantId);
                }
            }
        }
    }
    String choreoValue = splitting.calculateChoreographyTag(newServiceTemplate.getTopologyTemplate().getNodeTemplates(), participantId);
    TTag choreoTag = new TTag();
    choreoTag.setName("choreography");
    choreoTag.setValue(choreoValue);
    newTagList.add(choreoTag);
    newServiceTemplate.setTags(newTagList);
    repo.setElement(newId, newServiceTemplate);
    if (response.getStatus() == Status.CREATED) {
        response.setUri(null);
        response.setMessage(new QNameApiData(newId));
    }
    return response.getResponse();
}
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) LinkedHashMap(java.util.LinkedHashMap) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) Splitting(org.eclipse.winery.repository.splitting.Splitting) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) List(java.util.List) ArrayList(java.util.ArrayList) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) 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)

Aggregations

OTParticipant (org.eclipse.winery.model.tosca.extensions.OTParticipant)3 ArrayList (java.util.ArrayList)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WineryVersion (org.eclipse.winery.common.version.WineryVersion)2 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)2 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)2 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)2 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)2 TTag (org.eclipse.winery.model.tosca.TTag)2 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)2 IRepository (org.eclipse.winery.repository.backend.IRepository)2 ResourceResult (org.eclipse.winery.repository.rest.resources._support.ResourceResult)2 QNameApiData (org.eclipse.winery.repository.rest.resources.apiData.QNameApiData)2 Splitting (org.eclipse.winery.repository.splitting.Splitting)2 EntityGraph (io.github.edmm.core.parser.EntityGraph)1 MappingEntity (io.github.edmm.core.parser.MappingEntity)1 ApiResponse (io.swagger.annotations.ApiResponse)1 LinkedHashMap (java.util.LinkedHashMap)1