use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class LocationResourceService method addResourceTemplate.
private LocationResourceTemplate addResourceTemplate(Location location, String resourceName, String resourceTypeName) {
NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, resourceTypeName, location.getDependencies());
NodeTemplate nodeTemplate = templateBuilder.buildNodeTemplate(location.getDependencies(), resourceType);
LocationResourceTemplate locationResourceTemplate = new LocationResourceTemplate();
locationResourceTemplate.setGenerated(false);
fillAndSaveLocationResourceTemplate(location, resourceName, locationResourceTemplate, resourceType, nodeTemplate);
return locationResourceTemplate;
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologyTreeBuilderService method buildPaaSNodeTemplates.
/**
* Fetch information from the repository to complete the topology node template informations with additional data such as artifacts paths etc.
*
* @param topology The topology for which to build PaaSNodeTemplate map.
* @return A map of PaaSNodeTemplate that match the one of the NodeTempaltes in the given topology (and filled with artifact paths etc.).
*/
public Map<String, PaaSNodeTemplate> buildPaaSNodeTemplates(Topology topology) {
Map<String, PaaSNodeTemplate> nodeTemplates = Maps.newHashMap();
// Fill in PaaSNodeTemplate by fetching node types and CSAR path from the repositories.
if (topology.getNodeTemplates() != null) {
for (Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
NodeTemplate template = templateEntry.getValue();
PaaSNodeTemplate paaSNodeTemplate = new PaaSNodeTemplate(templateEntry.getKey(), template);
fillType(topology, template, paaSNodeTemplate, NodeType.class);
mergeInterfaces(paaSNodeTemplate, template);
if (template.getRelationships() != null) {
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : template.getRelationships().entrySet()) {
RelationshipTemplate relationshipTemplate = relationshipEntry.getValue();
PaaSRelationshipTemplate paaSRelationshipTemplate = new PaaSRelationshipTemplate(relationshipEntry.getKey(), relationshipTemplate, paaSNodeTemplate.getId());
fillType(topology, relationshipTemplate, paaSRelationshipTemplate, RelationshipType.class);
mergeInterfaces(paaSRelationshipTemplate, relationshipTemplate);
paaSNodeTemplate.getRelationshipTemplates().add(paaSRelationshipTemplate);
}
}
Capability scalableCapability = TopologyUtils.getScalableCapability(topology, templateEntry.getKey(), false);
if (scalableCapability != null) {
ScalingPolicy scalingPolicy = TopologyUtils.getScalingPolicy(scalableCapability);
// A node with a scaling policy 1, 1, 1 is a simple node and so do not set scaling policy
if (!ScalingPolicy.NOT_SCALABLE_POLICY.equals(scalingPolicy)) {
paaSNodeTemplate.setScalingPolicy(scalingPolicy);
}
}
if (topology.getGroups() != null) {
Set<String> nodeGroups = Sets.newHashSet();
for (Map.Entry<String, NodeGroup> groupEntry : topology.getGroups().entrySet()) {
if (groupEntry.getValue().getMembers() != null && groupEntry.getValue().getMembers().contains(templateEntry.getKey())) {
nodeGroups.add(groupEntry.getKey());
}
}
paaSNodeTemplate.setGroups(nodeGroups);
}
nodeTemplates.put(templateEntry.getKey(), paaSNodeTemplate);
}
}
return nodeTemplates;
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class FunctionEvaluator method extractRuntimeInformationProperty.
/**
* Extract property value from runtime informations
*
* @param topology
* @param propertyOrAttributeName
* @param nodes
* @return
*/
private static String extractRuntimeInformationProperty(Topology topology, String propertyOrAttributeName, List<? extends IPaaSTemplate> nodes) {
AbstractPropertyValue propertyOrAttributeValue;
NodeTemplate template = null;
for (IPaaSTemplate node : nodes) {
String nodeName = node.getId();
template = topology.getNodeTemplates().get(nodeName);
if (template != null && template.getProperties() != null) {
propertyOrAttributeValue = template.getProperties().get(propertyOrAttributeName);
if (propertyOrAttributeValue != null) {
return PropertyUtil.getScalarValue(propertyOrAttributeValue);
}
}
}
log.warn("Couldn't find property [ {} ] of node [ {} ]", propertyOrAttributeName, nodes);
return "[" + nodes + "." + propertyOrAttributeName + "=Error!]";
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class LocationResourceGeneratorService method generateComputeFromImageAndFlavor.
/**
* Generate resources of type compute given a set of images and flavors
*
* @param imageContext
* @param flavorContext
* @param linuxComputeContext
* @param windowsComputeContext
* @param resourceAccessor
* @return
*/
public List<LocationResourceTemplate> generateComputeFromImageAndFlavor(ImageFlavorContext imageContext, ImageFlavorContext flavorContext, ComputeContext linuxComputeContext, ComputeContext windowsComputeContext, ILocationResourceAccessor resourceAccessor) {
List<LocationResourceTemplate> images = imageContext.getTemplates();
List<LocationResourceTemplate> flavors = flavorContext.getTemplates();
Set<CSARDependency> dependencies = resourceAccessor.getDependencies();
List<LocationResourceTemplate> generated = Lists.newArrayList();
for (LocationResourceTemplate image : images) {
for (LocationResourceTemplate flavor : flavors) {
String defaultComputeName = generateDefaultName(image, flavor);
int count = 0;
ComputeContext computeContext = isWindowsImage(image) && windowsComputeContext != null ? windowsComputeContext : linuxComputeContext;
for (NodeType indexedNodeType : computeContext.getNodeTypes()) {
String name = StringUtils.isNotBlank(computeContext.getGeneratedNamePrefix()) ? computeContext.getGeneratedNamePrefix() : defaultComputeName;
if (count > 0) {
name = name + "_" + count;
}
NodeTemplate node = templateBuilder.buildNodeTemplate(dependencies, indexedNodeType);
// set the imageId
node.getProperties().put(computeContext.getImageIdPropertyName(), image.getTemplate().getProperties().get(imageContext.getIdPropertyName()));
// set the flavorId
node.getProperties().put(computeContext.getFlavorIdPropertyName(), flavor.getTemplate().getProperties().get(flavorContext.getIdPropertyName()));
// copy os and host capabilities properties
copyCapabilityBasedOnTheType(image.getTemplate(), node, "os");
copyCapabilityBasedOnTheType(flavor.getTemplate(), node, "host");
LocationResourceTemplate resource = new LocationResourceTemplate();
resource.setService(false);
resource.setTemplate(node);
resource.setName(name);
count++;
generated.add(resource);
}
}
}
return generated;
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class RuntimeController method validateCommand.
private void validateCommand(OperationExecRequest operationRequest, Topology topology) throws ConstraintFunctionalException {
NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operationRequest.getNodeTemplateName(), TopologyUtils.getNodeTemplates(topology));
NodeType indexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
Map<String, Interface> interfaces = IndexedModelUtils.mergeInterfaces(indexedNodeType.getInterfaces(), nodeTemplate.getInterfaces());
if (interfaces == null || interfaces.get(operationRequest.getInterfaceName()) == null) {
throw new NotFoundException("Interface [" + operationRequest.getInterfaceName() + "] not found in the node template [" + operationRequest.getNodeTemplateName() + "] related to [" + indexedNodeType.getId() + "]");
}
Interface interfass = interfaces.get(operationRequest.getInterfaceName());
validateOperation(interfass, operationRequest, topology.getDependencies());
}
Aggregations