use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project winery by eclipse.
the class Visitor method visit.
public void visit(TNodeTypeImplementation nodeTypeImplementation) {
Objects.requireNonNull(nodeTypeImplementation);
visit((TEntityTypeImplementation) nodeTypeImplementation);
if (nodeTypeImplementation.getDeploymentArtifacts() != null) {
for (TDeploymentArtifact da : nodeTypeImplementation.getDeploymentArtifacts()) {
da.accept(this);
}
}
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project winery by eclipse.
the class BackendUtils method getArtifactTemplatesOfReferencedDeploymentArtifacts.
public static Collection<QName> getArtifactTemplatesOfReferencedDeploymentArtifacts(TNodeTemplate nodeTemplate, IRepository repo) {
// DAs may be assigned directly to a node template
Collection<QName> allReferencedArtifactTemplates = getAllReferencedArtifactTemplatesInDAs(nodeTemplate.getDeploymentArtifacts());
List<QName> list = new ArrayList<>(allReferencedArtifactTemplates);
// DAs may be assigned via node type implementations
QName nodeTypeQName = nodeTemplate.getType();
Collection<NodeTypeImplementationId> allNodeTypeImplementations = repo.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, nodeTypeQName);
for (NodeTypeImplementationId nodeTypeImplementationId : allNodeTypeImplementations) {
List<TDeploymentArtifact> deploymentArtifacts = repo.getElement(nodeTypeImplementationId).getDeploymentArtifacts();
allReferencedArtifactTemplates = getAllReferencedArtifactTemplatesInDAs(deploymentArtifacts);
list.addAll(allReferencedArtifactTemplates);
}
return list;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project winery by eclipse.
the class IRepository 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);
List<TDeploymentArtifact> deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts);
}
List<TImplementationArtifact> implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts);
}
}
// check all RelationshipTypeImplementations for IAs
SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
List<TImplementationArtifact> implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts);
}
}
// 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;
List<TDeploymentArtifact> deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts);
}
}
}
}
}
// 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.TDeploymentArtifact in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
// We have to use a HashSet to ensure that no duplicate ids are added<
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TServiceTemplate serviceTemplate = this.getElement(id);
// add included things to export queue
TBoundaryDefinitions boundaryDefs;
if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
List<TPolicy> policies = boundaryDefs.getPolicies();
if (policies != null) {
for (TPolicy policy : policies) {
PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
ids.add(policyTypeId);
PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
ids.add(policyTemplateId);
}
}
// reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
}
final TTopologyTemplate topology = serviceTemplate.getTopologyTemplate();
if (topology != null) {
if (Objects.nonNull(topology.getPolicies())) {
topology.getPolicies().stream().filter(Objects::nonNull).forEach(p -> {
QName type = p.getPolicyType();
PolicyTypeId policyTypeIdId = new PolicyTypeId(type);
ids.add(policyTypeIdId);
});
}
for (TEntityTemplate entityTemplate : topology.getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through policies
List<TPolicy> policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
QName template = pol.getPolicyRef();
if (template != null) {
PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
ids.add(policyTemplateId);
}
}
}
// Crawl RequirementTypes and Capabilities for their references
getReferencedRequirementTypeIds(ids, n);
getCapabilitiesReferences(ids, n);
// TODO: this information is collected differently for YAML and XML modes
// crawl through deployment artifacts
List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
for (TDeploymentArtifact da : deploymentArtifacts) {
if (da.getArtifactType() != null) {
// This is considered Nullable, because the test case ConsistencyCheckerTest#hasError
// expects an empty artifactType and thus it may be null.
ids.add(new ArtifactTypeId(da.getArtifactType()));
}
if (da.getArtifactRef() != null) {
ids.add(new ArtifactTemplateId(da.getArtifactRef()));
}
}
}
// Store all referenced artifact types
List<TArtifact> artifacts = n.getArtifacts();
if (Objects.nonNull(artifacts)) {
artifacts.forEach(a -> ids.add(new ArtifactTypeId(a.getType())));
}
TNodeType nodeType = this.getElement(new NodeTypeId(qname));
if (Objects.nonNull(nodeType.getInterfaceDefinitions())) {
nodeType.getInterfaceDefinitions().stream().filter(Objects::nonNull).forEach(iDef -> {
if (Objects.nonNull(iDef.getType())) {
ids.add(new InterfaceTypeId(iDef.getType()));
}
});
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.model.tosca.TDeploymentArtifact in project winery by eclipse.
the class NodeTemplateResourceTest method addStateArtifactToNodeTemplateThatAlreadyHasADeploymentArtifact.
@Test
public void addStateArtifactToNodeTemplateThatAlreadyHasADeploymentArtifact() throws Exception {
this.setRevisionTo("origin/plain");
Path filePath = MavenTestingUtils.getProjectFilePath("src/test/resources/servicetemplates/plan.zip");
this.assertNoContentPost("servicetemplates/http%253A%252F%252Fopentosca.org%252Fexamples%252Fservicetemplates/ServiceTemplateWithDeploymentArtifact_w1-wip1/" + "topologytemplate/nodetemplates/StatefulComponent_w1-wip1/state", filePath);
TNodeTemplate nodeTemplate = getObjectFromGetRequest("servicetemplates/" + "http%253A%252F%252Fopentosca.org%252Fexamples%252Fservicetemplates/ServiceTemplateWithDeploymentArtifact_w1-wip1/" + "topologytemplate/nodetemplates/StatefulComponent_w1-wip1", TNodeTemplate.class);
List<TDeploymentArtifact> deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
assertNotNull(deploymentArtifacts);
assertEquals(2, deploymentArtifacts.size());
Optional<TDeploymentArtifact> testArtifact = deploymentArtifacts.stream().filter(artifact -> artifact.getName().equals("test-artifact")).findFirst();
assertTrue(testArtifact.isPresent());
assertNotNull(testArtifact.get());
assertNotNull(deploymentArtifacts);
Optional<TDeploymentArtifact> state = deploymentArtifacts.stream().filter(artifact -> artifact.getName().equals("state")).findFirst();
assertTrue(state.isPresent());
assertEquals(OpenToscaBaseTypes.stateArtifactType, state.get().getArtifactType());
}
Aggregations