use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class IGenericRepository method getReferenceCount.
default int getReferenceCount(ArtifactTemplateId id) {
// We do not use a database, therefore, we have to go through all possibilities pointing to the artifact template
// DAs and IAs point to an artifact template
// DAs are contained in Node Type Implementations and Node Templates
// IAs are contained in Node Type Implementations and Relationship Type Implementations
int count = 0;
Collection<TDeploymentArtifact> allDAs = new HashSet<>();
Collection<TImplementationArtifact> allIAs = new HashSet<>();
// handle Node Type Implementation, which contains DAs and IAs
SortedSet<NodeTypeImplementationId> nodeTypeImplementations = this.getAllDefinitionsChildIds(NodeTypeImplementationId.class);
for (NodeTypeImplementationId ntiId : nodeTypeImplementations) {
final TNodeTypeImplementation nodeTypeImplementation = this.getElement(ntiId);
TDeploymentArtifacts deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
}
TImplementationArtifacts implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts.getImplementationArtifact());
}
}
// check all Relationshiptype Implementations for IAs
SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
TImplementationArtifacts implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts.getImplementationArtifact());
}
}
// check all node templates for DAs
SortedSet<ServiceTemplateId> serviceTemplates = this.getAllDefinitionsChildIds(ServiceTemplateId.class);
for (ServiceTemplateId sid : serviceTemplates) {
TTopologyTemplate topologyTemplate = this.getElement(sid).getTopologyTemplate();
if (topologyTemplate != null) {
List<TEntityTemplate> nodeTemplateOrRelationshipTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate();
for (TEntityTemplate template : nodeTemplateOrRelationshipTemplate) {
if (template instanceof TNodeTemplate) {
TNodeTemplate nodeTemplate = (TNodeTemplate) template;
TDeploymentArtifacts deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts.getDeploymentArtifact());
}
}
}
}
}
// now we have all DAs and IAs
QName ourQName = id.getQName();
// check DAs for artifact templates
for (TDeploymentArtifact da : allDAs) {
QName artifactRef = da.getArtifactRef();
if (ourQName.equals(artifactRef)) {
count++;
}
}
// check IAs for artifact templates
for (TImplementationArtifact ia : allIAs) {
QName artifactRef = ia.getArtifactRef();
if (ourQName.equals(artifactRef)) {
count++;
}
}
return count;
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class Detection method detectPattern.
public List<List<String>> detectPattern() {
TTopologyTemplate tTopologyTemplate = RepositoryFactory.getRepository().getElement(serviceTemplateId).getTopologyTemplate();
searchForKeywords(tTopologyTemplate);
detectPattern(tTopologyTemplate);
List<List<String>> listLists = new ArrayList<>();
listLists.add(detectedPattern);
listLists.add(patternProbabilityHigh);
listLists.add(patternProbabilityMedium);
listLists.add(patternProbabilityLow);
listLists.add(impossiblePattern);
return listLists;
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class ProviderRepository method getAllTopologyFragmentsForLocationAndOfferingCapability.
/**
* Pointing to a concrete node template has to be done by putting this node template into a separeate namespace <p>
* The given targetLocation is appended to {@see NS_NAME_START} to gain the namespace. All NodeTemplates in this
* namespace and all "lower" namespaces (e.g., starting with that string) are returned.
*
* @return All node templates available for the given targetLocation.
*/
public List<TTopologyTemplate> getAllTopologyFragmentsForLocationAndOfferingCapability(String targetLocation, TRequirement requirement) {
QName reqTypeQName = requirement.getType();
RequirementTypeId reqTypeId = new RequirementTypeId(reqTypeQName);
QName requiredCapabilityType = RepositoryFactory.getRepository().getElement(reqTypeId).getRequiredCapabilityType();
return getAllTopologyFragmentsForLocation(targetLocation).stream().filter(tf -> {
Optional<TNodeTemplate> nodeTemplate = ModelUtilities.getAllNodeTemplates(tf).stream().filter(nt -> nt.getCapabilities() != null).filter(nt -> nt.getCapabilities().getCapability().stream().anyMatch(cap -> cap.getType().equals(requiredCapabilityType))).findAny();
if (nodeTemplate.isPresent()) {
return true;
} else {
return false;
}
}).collect(Collectors.toList());
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class ProviderRepository method getAllTopologyFragmentsFromServiceTemplate.
private List<TTopologyTemplate> getAllTopologyFragmentsFromServiceTemplate(TTopologyTemplate topologyTemplate) {
List<TTopologyTemplate> topologyFragments = new ArrayList<>();
Splitting helperFunctions = new Splitting();
List<TNodeTemplate> nodeTemplatesWithoutIncomingRelationship = helperFunctions.getNodeTemplatesWithoutIncomingHostedOnRelationships(topologyTemplate);
List<TNodeTemplate> visitedNodeTemplates = new ArrayList<>();
// It can only be one topology fragment contained in the service template
if (nodeTemplatesWithoutIncomingRelationship.size() == 1) {
TDocumentation documentation = new TDocumentation();
Optional<String> targetLabel = ModelUtilities.getTargetLabel(nodeTemplatesWithoutIncomingRelationship.get(0));
String label;
if (!targetLabel.isPresent()) {
label = "unkown";
} else {
label = targetLabel.get();
}
documentation.getContent().add("Stack of Node Template " + nodeTemplatesWithoutIncomingRelationship.get(0).getId() + " from Provider Repository " + label);
topologyTemplate.getDocumentation().add(documentation);
topologyFragments.add(topologyTemplate);
} else {
for (TNodeTemplate nodeWithoutIncomingRel : nodeTemplatesWithoutIncomingRelationship) {
if (!visitedNodeTemplates.contains(nodeWithoutIncomingRel)) {
TTopologyTemplate topologyFragment = new TTopologyTemplate();
TDocumentation documentation = new TDocumentation();
Optional<String> targetLabel = ModelUtilities.getTargetLabel(nodeWithoutIncomingRel);
String label;
if (!targetLabel.isPresent()) {
label = "unkown";
} else {
label = targetLabel.get();
}
documentation.getContent().add("Stack of Node Template " + nodeWithoutIncomingRel.getId() + " from Provider Repository " + label);
topologyFragment.getDocumentation().add(documentation);
topologyFragment.getNodeTemplateOrRelationshipTemplate().addAll(breadthFirstSearch(nodeWithoutIncomingRel, topologyTemplate));
topologyFragments.add(topologyFragment);
topologyFragment.getNodeTemplateOrRelationshipTemplate().stream().filter(et -> et instanceof TNodeTemplate).map(TNodeTemplate.class::cast).forEach(nt -> visitedNodeTemplates.add(nt));
}
}
}
return topologyFragments;
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class WineryRepositoryClient method getTopologyTemplate.
@Override
public TTopologyTemplate getTopologyTemplate(QName serviceTemplate) {
// we try all repositories until the first hit
for (WebResource wr : this.repositoryResources) {
WebResource r = WineryRepositoryClient.getTopologyTemplateWebResource(wr, serviceTemplate);
ClientResponse response = r.accept(MediaType.TEXT_XML).get(ClientResponse.class);
if (response.getClientResponseStatus() == ClientResponse.Status.OK) {
TTopologyTemplate topologyTemplate;
Document doc = this.parseAndValidateTOSCAXML(response.getEntityInputStream());
if (doc == null) {
// no valid document
return null;
}
try {
topologyTemplate = WineryRepositoryClient.createUnmarshaller().unmarshal(doc.getDocumentElement(), TTopologyTemplate.class).getValue();
} catch (JAXBException e) {
LOGGER.debug("Could not parse topology, returning null", e);
return null;
}
// first hit: immediately stop and return result
return topologyTemplate;
}
}
// nothing found
return null;
}
Aggregations