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;
}
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;
}
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();
}
Aggregations