Search in sources :

Example 86 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class NodeMatchingCandidateModifier method getNodeTypes.

private Map<String, NodeType> getNodeTypes(Topology topology) {
    Map<String, NodeType> nodeTypes = Maps.newHashMap();
    for (NodeTemplate template : safe(topology.getNodeTemplates()).values()) {
        if (!nodeTypes.containsKey(template.getType())) {
            NodeType nodeType = ToscaContext.getOrFail(NodeType.class, template.getType());
            nodeTypes.put(nodeType.getElementId(), nodeType);
        }
    }
    return nodeTypes;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 87 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class DeploymentTopologyDTOBuilder method enrichSubstitutionTypesWithServicesDependencies.

/**
 * Enrich {@link LocationResourceTypes} adding types coming from on demand service resources.
 */
private void enrichSubstitutionTypesWithServicesDependencies(Collection<LocationResourceTemplate> resourceTemplates, LocationResourceTypes locationResourceTypes) {
    Set<String> serviceTypes = Sets.newHashSet();
    Set<CSARDependency> dependencies = Sets.newHashSet();
    for (LocationResourceTemplate resourceTemplate : resourceTemplates) {
        if (resourceTemplate.isService()) {
            String serviceId = resourceTemplate.getId();
            ServiceResource serviceResource = serviceResourceService.getOrFail(serviceId);
            NodeType serviceType = ToscaContext.get(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType());
            if (serviceType == null || !serviceType.getArchiveVersion().equals(serviceResource.getNodeInstance().getTypeVersion())) {
                serviceType = toscaTypeSearchService.findOrFail(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType(), serviceResource.getNodeInstance().getTypeVersion());
            }
            dependencies.addAll(csarDependencyLoader.getDependencies(serviceType.getArchiveName(), serviceType.getArchiveVersion()));
            dependencies.add(new CSARDependency(serviceType.getArchiveName(), serviceType.getArchiveVersion()));
            serviceTypes.add(serviceResource.getNodeInstance().getNodeTemplate().getType());
        }
    }
    locationResourceService.fillLocationResourceTypes(serviceTypes, locationResourceTypes, dependencies);
}
Also used : PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) ServiceResource(alien4cloud.model.service.ServiceResource) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 88 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TopologyCompositionService method recursivelyDetectTopologyCompositionCyclicReference.

/**
 * Deeply explore composition in order to detect cyclic reference: if a descendant references the mainTopologyId.
 */
public void recursivelyDetectTopologyCompositionCyclicReference(String mainTopologyId, String substitutionTopologyId) {
    Topology child = topologyServiceCore.getOrFail(substitutionTopologyId);
    if (child == null || child.getNodeTemplates() == null || child.getNodeTemplates().isEmpty()) {
        return;
    }
    for (Entry<String, NodeTemplate> nodeEntry : child.getNodeTemplates().entrySet()) {
        String type = nodeEntry.getValue().getType();
        NodeType nodeType = csarRepoSearchService.getElementInDependencies(NodeType.class, type, child.getDependencies());
        if (nodeType.getSubstitutionTopologyId() != null) {
            if (nodeType.getSubstitutionTopologyId().equals(mainTopologyId)) {
                throw new CyclicReferenceException("Cyclic reference : a topology template can not reference itself (even indirectly)");
            }
            recursivelyDetectTopologyCompositionCyclicReference(mainTopologyId, nodeType.getSubstitutionTopologyId());
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Topology(org.alien4cloud.tosca.model.templates.Topology) CyclicReferenceException(alien4cloud.exception.CyclicReferenceException)

Example 89 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class LocationResourceService method fillLocationResourceTypes.

/**
 * Put the exposed types to the appropriate List of locationResourceTypes passed as param
 */
public void fillLocationResourceTypes(Collection<String> exposedTypes, LocationResourceTypes locationResourceTypes, final Set<CSARDependency> dependencies) {
    fillLocationResourceTypes(exposedTypes, locationResourceTypes, dependencies, (exposedType) -> {
        NodeType nodeType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, exposedType, dependencies);
        addExposedNodeType(locationResourceTypes, dependencies, nodeType);
    });
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 90 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class LocationResourceService method duplicateResourceTemplate.

@Override
public LocationResourceTemplateWithDependencies duplicateResourceTemplate(String resourceId) {
    LocationResourceTemplate locationResourceTemplate = getOrFail(resourceId);
    locationResourceTemplate.setId(UUID.randomUUID().toString());
    locationResourceTemplate.setName(locationResourceTemplate.getName() + "_" + "copy");
    locationResourceTemplate.setGenerated(false);
    Location location = locationService.getOrFail(locationResourceTemplate.getLocationId());
    NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, locationResourceTemplate.getTemplate().getType(), location.getDependencies());
    publishCreatedEventAndSaveResource(location, locationResourceTemplate, resourceType);
    return new LocationResourceTemplateWithDependencies(locationResourceTemplate, Sets.newHashSet(location.getDependencies()));
}
Also used : PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) LocationResourceTemplateWithDependencies(alien4cloud.model.orchestrators.locations.LocationResourceTemplateWithDependencies) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7