use of org.eclipse.winery.repository.backend.IRepository 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.repository.backend.IRepository in project winery by eclipse.
the class TopologyTemplateResource method computeDi.
@POST
@Path("kvcomparison")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public PropertyDiffList computeDi(UpdateInfo updateInfo) {
List<String> resolvedProperties = new ArrayList<>();
List<String> removedProperties = new ArrayList<>();
List<String> newProperties = new ArrayList<>();
Optional<TEntityTemplate> foundTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate().stream().filter(template -> template.getId().equals(updateInfo.getNodeTemplateId())).filter(template -> template.getProperties() != null).findFirst();
if (foundTemplate.isPresent() && Objects.nonNull(foundTemplate.get().getProperties()) && Objects.nonNull(ModelUtilities.getPropertiesKV(foundTemplate.get()))) {
HashMap<String, String> oldKvs = ModelUtilities.getPropertiesKV(foundTemplate.get());
QName qNameType = QName.valueOf(updateInfo.getNewComponentType());
IRepository repository = RepositoryFactory.getRepository();
TEntityType newNodeTypeVersion = repository.getElement(new NodeTypeId(qNameType));
if (Objects.nonNull(newNodeTypeVersion) && Objects.nonNull(newNodeTypeVersion.getWinerysPropertiesDefinition())) {
List<PropertyDefinitionKV> newKvs = newNodeTypeVersion.getWinerysPropertiesDefinition().getPropertyDefinitions();
resolvedProperties = newKvs.stream().map(PropertyDefinitionKV::getKey).filter(keys -> oldKvs.keySet().stream().map(String::toLowerCase).collect(Collectors.toList()).contains(keys.toLowerCase())).collect(Collectors.toList());
removedProperties = oldKvs.keySet().stream().filter(keys -> !newKvs.stream().map(newProp -> newProp.getKey().toLowerCase()).collect(Collectors.toList()).contains(keys.toLowerCase())).collect(Collectors.toList());
newProperties = newKvs.stream().map(PropertyDefinitionKV::getKey).filter(keys -> !oldKvs.keySet().stream().map(String::toLowerCase).collect(Collectors.toList()).contains(keys.toLowerCase())).collect(Collectors.toList());
}
}
return new PropertyDiffList(resolvedProperties, removedProperties, newProperties);
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class TopologyTemplateResource method getNewVersionList.
@GET
@Path("newversions")
@Produces(MediaType.APPLICATION_JSON)
public List<NewVersionListElement> getNewVersionList() {
IRepository repository = RepositoryFactory.getRepository();
Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class);
Map<QName, List<WineryVersion>> versionElements = new HashMap<>();
for (TNodeTemplate node : this.topologyTemplate.getNodeTemplates()) {
if (nodeTypes.containsKey(node.getType())) {
NodeTypeId nodeTypeId = new NodeTypeId(node.getType());
if (!versionElements.containsKey(nodeTypeId.getQName())) {
List<WineryVersion> versionList = WineryVersionUtils.getAllVersionsOfOneDefinition(nodeTypeId, repository).stream().filter(wineryVersion -> {
QName qName = VersionSupport.getDefinitionInTheGivenVersion(nodeTypeId, wineryVersion).getQName();
NamespaceProperties namespaceProperties = repository.getNamespaceManager().getNamespaceProperties(qName.getNamespaceURI());
return !(namespaceProperties.isGeneratedNamespace() || ModelUtilities.isFeatureType(qName, nodeTypes));
}).collect(Collectors.toList());
versionElements.put(nodeTypeId.getQName(), versionList);
}
}
}
return versionElements.entrySet().stream().map(qNameListEntry -> new NewVersionListElement(qNameListEntry.getKey(), qNameListEntry.getValue())).collect(Collectors.toList());
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class GitWebSocket method onMessage.
@OnMessage
public void onMessage(String message, Session session) {
try {
GitData data = JacksonProvider.mapper.readValue(message, GitData.class);
Map<String, Map<DiffEntry, String>> repoEntryList = new HashMap<>();
if (RepositoryFactory.getRepository() instanceof MultiRepository) {
IRepository gitRepo;
for (IRepository repo : ((MultiRepository) RepositoryFactory.getRepository()).getRepositories()) {
gitRepo = repo;
if (gitRepo instanceof GitBasedRepository) {
handleGitRepository((GitBasedRepository) gitRepo, data, repoEntryList);
}
}
setGitDifferences(repoEntryList);
} else if (RepositoryFactory.getRepository() instanceof GitBasedRepository) {
handleGitRepository((GitBasedRepository) RepositoryFactory.getRepository(), data, repoEntryList);
setGitDifferences(repoEntryList);
}
} catch (IOException e) {
writeInSession(session, "{ \"error\": \"Could not parse message!\" }");
}
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class Splitting method splitTopologyOfServiceTemplate.
/**
* Splits the topology template of the given service template. Creates a new service template with "-split" suffix
* as id. Any existing "-split" service template will be deleted. Matches the split topology template to the cloud
* providers according to the target labels. Creates a new service template with "-matched" suffix as id. Any
* existing "-matched" service template will be deleted.
*
* @param id of the ServiceTemplate switch should be split and matched to cloud providers
* @return id of the ServiceTemplate which contains the matched topology
*/
public ServiceTemplateId splitTopologyOfServiceTemplate(ServiceTemplateId id) throws SplittingException, IOException {
long start = System.currentTimeMillis();
IRepository repository = RepositoryFactory.getRepository();
TServiceTemplate serviceTemplate = repository.getElement(id);
// create wrapper service template
ServiceTemplateId splitServiceTemplateId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionSupport.getNewComponentVersionId(id, "split"), false);
repository.forceDelete(splitServiceTemplateId);
repository.flagAsExisting(splitServiceTemplateId);
TServiceTemplate splitServiceTemplate = new TServiceTemplate();
splitServiceTemplate.setName(splitServiceTemplateId.getXmlId().getDecoded());
splitServiceTemplate.setId(splitServiceTemplate.getName());
splitServiceTemplate.setTargetNamespace(id.getNamespace().getDecoded());
TTopologyTemplate splitTopologyTemplate = split(serviceTemplate.getTopologyTemplate());
splitServiceTemplate.setTopologyTemplate(splitTopologyTemplate);
LOGGER.debug("Persisting...");
repository.setElement(splitServiceTemplateId, splitServiceTemplate);
LOGGER.debug("Persisted.");
// create wrapper service template
ServiceTemplateId matchedServiceTemplateId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionSupport.getNewComponentVersionId(id, "split-matched"), false);
repository.forceDelete(matchedServiceTemplateId);
repository.flagAsExisting(matchedServiceTemplateId);
TServiceTemplate matchedServiceTemplate = new TServiceTemplate();
matchedServiceTemplate.setName(matchedServiceTemplateId.getXmlId().getDecoded());
matchedServiceTemplate.setId(matchedServiceTemplate.getName());
matchedServiceTemplate.setTargetNamespace(id.getNamespace().getDecoded());
TTopologyTemplate matchedTopologyTemplate = hostMatchingWithDefaultHostSelection(splitTopologyTemplate);
matchedServiceTemplate.setTopologyTemplate(matchedTopologyTemplate);
LOGGER.debug("Persisting...");
repository.setElement(matchedServiceTemplateId, matchedServiceTemplate);
LOGGER.debug("Persisted.");
long duration = System.currentTimeMillis() - start;
LOGGER.debug("Execution Time in millisec: " + duration + "ms");
return matchedServiceTemplateId;
}
Aggregations