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;
}
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);
}
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());
}
}
}
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);
});
}
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()));
}
Aggregations