Search in sources :

Example 1 with TBoundaryDefinitions

use of org.eclipse.winery.model.tosca.TBoundaryDefinitions in project winery by eclipse.

the class ThreatModelingUtilsWithGitBackendRepositoryTest method checkBoundaryDefinitionsOfServiceTemplate.

@Test
public void checkBoundaryDefinitionsOfServiceTemplate() throws Exception {
    this.setRevisionTo("origin/plain");
    ThreatModelingUtils tmu = new ThreatModelingUtils(repository);
    TServiceTemplate st = new TServiceTemplate.Builder("MyExample", new TTopologyTemplate.Builder().build()).build();
    assertFalse(tmu.hasBoundaryDefinitionMitigationPolicy(st));
    TPolicyTemplate myMitigation = new TPolicyTemplate.Builder("myMitigation", QName.valueOf(ThreatModelingConstants.MITIGATION_POLICY_ID)).build();
    TPolicy mitigationPolicy = new TPolicy.Builder(myMitigation.getTypeAsQName()).build();
    TBoundaryDefinitions stBoundaryDefinitions = new TBoundaryDefinitions.Builder().addPolicy(mitigationPolicy).build();
    st.setBoundaryDefinitions(stBoundaryDefinitions);
    assertTrue(tmu.hasBoundaryDefinitionMitigationPolicy(st));
}
Also used : TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test)

Example 2 with TBoundaryDefinitions

use of org.eclipse.winery.model.tosca.TBoundaryDefinitions in project winery by eclipse.

the class Visitor method visit.

public void visit(TServiceTemplate serviceTemplate) {
    Objects.requireNonNull(serviceTemplate);
    visit((TExtensibleElements) serviceTemplate);
    final TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
    if (topologyTemplate != null) {
        topologyTemplate.accept(this);
    }
    final List<TTag> tags = serviceTemplate.getTags();
    if (tags != null) {
        for (TTag tag : tags) {
            tag.accept(this);
        }
    }
    final List<TPlan> plans = serviceTemplate.getPlans();
    if (plans != null) {
        for (TPlan plan : plans) {
            plan.accept(this);
        }
    }
    final TBoundaryDefinitions boundaryDefinitions = serviceTemplate.getBoundaryDefinitions();
    if (boundaryDefinitions != null) {
        boundaryDefinitions.accept(this);
    }
}
Also used : TTag(org.eclipse.winery.model.tosca.TTag) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TPlan(org.eclipse.winery.model.tosca.TPlan) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions)

Example 3 with TBoundaryDefinitions

use of org.eclipse.winery.model.tosca.TBoundaryDefinitions in project winery by eclipse.

the class ServiceTemplateResource method getBoundaryDefinitionsResource.

@Path("boundarydefinitions/")
public BoundaryDefinitionsResource getBoundaryDefinitionsResource() {
    TBoundaryDefinitions boundaryDefinitions = this.getServiceTemplate().getBoundaryDefinitions();
    if (boundaryDefinitions == null) {
        boundaryDefinitions = new TBoundaryDefinitions.Builder().build();
        this.getServiceTemplate().setBoundaryDefinitions(boundaryDefinitions);
    }
    return new BoundaryDefinitionsResource(this, boundaryDefinitions);
}
Also used : BoundaryDefinitionsResource(org.eclipse.winery.repository.rest.resources.servicetemplates.boundarydefinitions.BoundaryDefinitionsResource) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) Path(javax.ws.rs.Path)

Example 4 with TBoundaryDefinitions

use of org.eclipse.winery.model.tosca.TBoundaryDefinitions in project winery by eclipse.

the class IGenericRepository 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) {
        TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
        if (policies != null) {
            for (TPolicy policy : policies.getPolicy()) {
                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)
    }
    if (serviceTemplate.getTopologyTemplate() != null) {
        for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
            QName qname = entityTemplate.getType();
            if (entityTemplate instanceof TNodeTemplate) {
                ids.add(new NodeTypeId(qname));
                TNodeTemplate n = (TNodeTemplate) entityTemplate;
                // crawl through deployment artifacts
                TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
                if (deploymentArtifacts != null) {
                    List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
                    for (TDeploymentArtifact da : das) {
                        ids.add(new ArtifactTypeId(da.getArtifactType()));
                        if ((qname = da.getArtifactRef()) != null) {
                            ids.add(new ArtifactTemplateId(qname));
                        }
                    }
                }
                // crawl through reqs/caps
                TNodeTemplate.Requirements requirements = n.getRequirements();
                if (requirements != null) {
                    for (TRequirement req : requirements.getRequirement()) {
                        QName type = req.getType();
                        RequirementTypeId rtId = new RequirementTypeId(type);
                        ids.add(rtId);
                    }
                }
                TNodeTemplate.Capabilities capabilities = n.getCapabilities();
                if (capabilities != null) {
                    for (TCapability cap : capabilities.getCapability()) {
                        QName type = cap.getType();
                        CapabilityTypeId ctId = new CapabilityTypeId(type);
                        ids.add(ctId);
                    }
                }
                // crawl through policies
                org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
                if (policies != null) {
                    for (TPolicy pol : policies.getPolicy()) {
                        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);
                        }
                    }
                }
            } else {
                assert (entityTemplate instanceof TRelationshipTemplate);
                ids.add(new RelationshipTypeId(qname));
            }
        }
    }
    return ids;
}
Also used : DefinitionsChildId(org.eclipse.winery.common.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.common.ids.definitions.ArtifactTypeId) TRequirement(org.eclipse.winery.model.tosca.TRequirement) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) RelationshipTypeId(org.eclipse.winery.common.ids.definitions.RelationshipTypeId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) CapabilityTypeId(org.eclipse.winery.common.ids.definitions.CapabilityTypeId) QName(javax.xml.namespace.QName) TCapability(org.eclipse.winery.model.tosca.TCapability) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.common.ids.definitions.ArtifactTemplateId) TDeploymentArtifacts(org.eclipse.winery.model.tosca.TDeploymentArtifacts) PolicyTypeId(org.eclipse.winery.common.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.common.ids.definitions.RequirementTypeId) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.common.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.common.ids.definitions.NodeTypeId)

Example 5 with TBoundaryDefinitions

use of org.eclipse.winery.model.tosca.TBoundaryDefinitions 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;
}
Also used : RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TArtifact(org.eclipse.winery.model.tosca.TArtifact) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TPolicy(org.eclipse.winery.model.tosca.TPolicy) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Aggregations

TBoundaryDefinitions (org.eclipse.winery.model.tosca.TBoundaryDefinitions)9 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)6 TPolicy (org.eclipse.winery.model.tosca.TPolicy)5 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)4 QName (javax.xml.namespace.QName)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 HashSet (java.util.HashSet)2 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)2 TCapability (org.eclipse.winery.model.tosca.TCapability)2 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)2 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)2 TNodeType (org.eclipse.winery.model.tosca.TNodeType)2 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)2 TRequirement (org.eclipse.winery.model.tosca.TRequirement)2 ArrayList (java.util.ArrayList)1 Path (javax.ws.rs.Path)1 ArtifactTemplateId (org.eclipse.winery.common.ids.definitions.ArtifactTemplateId)1 ArtifactTypeId (org.eclipse.winery.common.ids.definitions.ArtifactTypeId)1 CapabilityTypeId (org.eclipse.winery.common.ids.definitions.CapabilityTypeId)1 DefinitionsChildId (org.eclipse.winery.common.ids.definitions.DefinitionsChildId)1