Search in sources :

Example 36 with NodeTypeId

use of org.eclipse.winery.model.ids.definitions.NodeTypeId 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)

Example 37 with NodeTypeId

use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.

the class ConsistencyChecker method checkServiceTemplate.

private void checkServiceTemplate(ServiceTemplateId id) {
    TServiceTemplate serviceTemplate;
    try {
        serviceTemplate = configuration.getRepository().getElement(id);
    } catch (IllegalStateException e) {
        LOGGER.debug("Illegal State Exception during reading of id {}", id.toReadableString(), e);
        printAndAddError(id, "Reading error " + e.getMessage());
        return;
    }
    if (serviceTemplate.getTopologyTemplate() == null) {
        return;
    }
    @NonNull final List<TNodeTemplate> nodeTemplates = serviceTemplate.getTopologyTemplate().getNodeTemplates();
    for (TNodeTemplate nodeTemplate : nodeTemplates) {
        NodeTypeId nodeTypeId = new NodeTypeId(nodeTemplate.getType());
        TNodeType nodeType;
        try {
            nodeType = configuration.getRepository().getElement(nodeTypeId);
        } catch (IllegalStateException e) {
            LOGGER.debug("Illegal State Exception during reading of id {}", nodeTypeId.toReadableString(), e);
            printAndAddError(nodeTypeId, "Reading error " + e.getMessage());
            return;
        }
        final WinerysPropertiesDefinition winerysPropertiesDefinition = nodeType.getWinerysPropertiesDefinition();
        if (winerysPropertiesDefinition != null) {
            List<PropertyDefinitionKV> list = winerysPropertiesDefinition.getPropertyDefinitions();
            if (list != null) {
                // iterate on all defined properties
                for (PropertyDefinitionKV propdef : list) {
                    String key = propdef.getKey();
                    if (key == null) {
                        printAndAddError(id, "key is null");
                        continue;
                    }
                    // assign value, but change "null" to "" if no property is defined
                    final Map<String, String> propertiesKV = ModelUtilities.getPropertiesKV(nodeTemplate);
                    if (propertiesKV == null) {
                        printAndAddError(id, "propertiesKV of node template " + nodeTemplate.getId() + " is null");
                    }
                }
            }
        }
    }
}
Also used : PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) NonNull(org.eclipse.jdt.annotation.NonNull) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 38 with NodeTypeId

use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.

the class VersionSupport method getDefinitionInTheGivenVersion.

public static DefinitionsChildId getDefinitionInTheGivenVersion(DefinitionsChildId childId, WineryVersion otherVersion) {
    if (childId.getVersion().compareTo(otherVersion) == 0) {
        return childId;
    }
    String localPart = childId.getNameWithoutVersion() + (otherVersion.toString().length() > 0 ? WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + otherVersion.toString() : "");
    QName qName = new QName(childId.getNamespace().getDecoded(), localPart);
    if (childId instanceof RelationshipTypeImplementationId) {
        return new RelationshipTypeImplementationId(qName);
    } else if (childId instanceof NodeTypeImplementationId) {
        return new NodeTypeImplementationId(qName);
    } else if (childId instanceof RequirementTypeId) {
        return new RequirementTypeId(qName);
    } else if (childId instanceof NodeTypeId) {
        return new NodeTypeId(qName);
    } else if (childId instanceof RelationshipTypeId) {
        return new RelationshipTypeId(qName);
    } else if (childId instanceof CapabilityTypeId) {
        return new CapabilityTypeId(qName);
    } else if (childId instanceof ArtifactTypeId) {
        return new ArtifactTypeId(qName);
    } else if (childId instanceof PolicyTypeId) {
        return new PolicyTypeId(qName);
    } else if (childId instanceof PolicyTemplateId) {
        return new PolicyTemplateId(qName);
    } else if (childId instanceof ServiceTemplateId) {
        return new ServiceTemplateId(qName);
    } else if (childId instanceof ArtifactTemplateId) {
        return new ArtifactTemplateId(qName);
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
}
Also used : NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId)

Example 39 with NodeTypeId

use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.

the class RestUtilsWithGitBackendTest method renameAllVersionNamespacesOfOneComponent.

@Test
public void renameAllVersionNamespacesOfOneComponent() throws Exception {
    this.setRevisionTo("origin/plain");
    String version = "_0.3.4-w3";
    String name = "NodeTypeWith5Versions";
    String oldNamespace = "http://opentosca.org/nodetypes";
    String newNamespace = "http://example.org/nodetypes";
    DefinitionsChildId oldId = new NodeTypeId(oldNamespace, name + version, false);
    DefinitionsChildId newId = new NodeTypeId(newNamespace, name + version, false);
    Response response = RestUtils.renameAllVersionsOfOneDefinition(oldId, newId);
    String expectedEntity = "http://localhost:8080/winery/nodetypes/" + EncodingUtil.URLencode(EncodingUtil.URLencode(newNamespace)) + "/" + name + version + "/";
    assertEquals(201, response.getStatus());
    assertEquals(expectedEntity, response.getEntity());
    assertEquals(5, WineryVersionUtils.getAllVersionsOfOneDefinition(oldId, repository).size());
    assertEquals(5, WineryVersionUtils.getAllVersionsOfOneDefinition(newId, repository).size());
}
Also used : Response(javax.ws.rs.core.Response) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) Test(org.junit.jupiter.api.Test)

Example 40 with NodeTypeId

use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.

the class RestUtilsWithGitBackendTest method releaseComponentWhichDoesNotHaveChanges.

@Test
public void releaseComponentWhichDoesNotHaveChanges() throws Exception {
    this.setRevisionTo("origin/plain");
    DefinitionsChildId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2-wip1", false);
    DefinitionsChildId releasedId = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2", false);
    int formerVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository).size();
    Response response = RestUtils.releaseVersion(id);
    int finalVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(releasedId, repository).size();
    WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(releasedId, repository);
    assertEquals(201, response.getStatus());
    assertEquals(formerVersionCount + 1, finalVersionCount);
    assertFalse(version.isReleasable());
    assertEquals(0, version.getWorkInProgressVersion());
}
Also used : Response(javax.ws.rs.core.Response) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Aggregations

NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)67 TNodeType (org.eclipse.winery.model.tosca.TNodeType)36 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 Test (org.junit.jupiter.api.Test)27 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)23 QName (javax.xml.namespace.QName)21 IRepository (org.eclipse.winery.repository.backend.IRepository)20 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)15 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)15 WineryVersion (org.eclipse.winery.common.version.WineryVersion)14 Response (javax.ws.rs.core.Response)13 IOException (java.io.IOException)12 LinkedHashMap (java.util.LinkedHashMap)12 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)11 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)11 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)10 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)10 ArrayList (java.util.ArrayList)9 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)9 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)9