Search in sources :

Example 6 with QNameApiData

use of org.eclipse.winery.repository.rest.resources.apiData.QNameApiData 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 QNameApiData

use of org.eclipse.winery.repository.rest.resources.apiData.QNameApiData in project winery by eclipse.

the class TemplatesOfOneType method getJSON.

/**
 * returns a list of all implementations of a type using the getAllImplementations method
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getJSON() {
    Collection<? extends DefinitionsChildId> allImplementations = this.getAllImplementations();
    List<QNameApiData> res = new ArrayList<>(allImplementations.size());
    QNameConverter adapter = new QNameConverter();
    for (DefinitionsChildId id : allImplementations) {
        res.add(adapter.marshal(id.getQName()));
    }
    return Response.ok().entity(res).build();
}
Also used : QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArrayList(java.util.ArrayList) QNameConverter(org.eclipse.winery.repository.rest.resources.apiData.converter.QNameConverter) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with QNameApiData

use of org.eclipse.winery.repository.rest.resources.apiData.QNameApiData in project winery by eclipse.

the class CapabilityTypeResource method saveValidSourceTypes.

@PUT
@Path("constraints/")
public Response saveValidSourceTypes(ValidTypesListApiData newValidSourceTypes) {
    TCapabilityType t = this.getCapabilityType();
    t.setValidNodeTypes(newValidSourceTypes.getNodes().stream().map(QNameApiData::asQName).collect(Collectors.toList()));
    return RestUtils.persist(this);
}
Also used : QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 9 with QNameApiData

use of org.eclipse.winery.repository.rest.resources.apiData.QNameApiData in project winery by eclipse.

the class QNameConverter method marshal.

@Override
public QNameApiData marshal(QName v) {
    QNameApiData result = new QNameApiData();
    result.localname = v.getLocalPart();
    result.namespace = v.getNamespaceURI();
    return result;
}
Also used : QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData)

Example 10 with QNameApiData

use of org.eclipse.winery.repository.rest.resources.apiData.QNameApiData 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

QNameApiData (org.eclipse.winery.repository.rest.resources.apiData.QNameApiData)11 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 WineryVersion (org.eclipse.winery.common.version.WineryVersion)6 ArrayList (java.util.ArrayList)5 POST (javax.ws.rs.POST)5 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)5 ResourceResult (org.eclipse.winery.repository.rest.resources._support.ResourceResult)5 IRepository (org.eclipse.winery.repository.backend.IRepository)3 QNameConverter (org.eclipse.winery.repository.rest.resources.apiData.converter.QNameConverter)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)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 OTParticipant (org.eclipse.winery.model.tosca.extensions.OTParticipant)2 Splitting (org.eclipse.winery.repository.splitting.Splitting)2 ApiResponse (io.swagger.annotations.ApiResponse)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1