use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class LocationService method autoConfigure.
/**
* This method calls the orchestrator plugin to try to auto-configure the
*
* @param orchestrator The orchestrator for which to auto-configure a location.
* @param location The location to auto-configure
* @return the List of {@link LocationResourceTemplate} generated from the location auto-configuration call, null is a valid answer.
*/
private List<LocationResourceTemplate> autoConfigure(Orchestrator orchestrator, Location location) throws UnsupportedOperationException {
// get the orchestrator plugin instance
IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.getOrFail(orchestrator.getId());
ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
ILocationResourceAccessor accessor = locationResourceService.accessor(location.getId());
// let's try to auto-configure the location
List<LocationResourceTemplate> templates = configuratorPlugin.instances(accessor);
if (templates != null) {
// save the instances
for (LocationResourceTemplate template : templates) {
// initialize the instances from data.
template.setId(UUID.randomUUID().toString());
template.setLocationId(location.getId());
template.setGenerated(true);
template.setEnabled(true);
NodeType nodeType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, template.getTemplate().getType(), location.getDependencies());
nodeType.getDerivedFrom().add(0, template.getTemplate().getType());
template.setTypes(nodeType.getDerivedFrom());
LocationTemplateCreated event = new LocationTemplateCreated(this);
event.setTemplate(template);
event.setLocation(location);
event.setToscaType(nodeType);
applicationContext.publishEvent(event);
}
alienDAO.save(templates.toArray(new LocationResourceTemplate[templates.size()]));
alienDAO.save(location);
}
return templates;
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class NodeMatcherService method populateLocationResourcesWithServiceResource.
/**
* Populate this {@link LocationResources} using these {@link ServiceResource}s in order to make them available as {@link LocationResourceTemplate} for
* matching purpose.
*
* TODO: Improve this ugly code to put ServiceResource in LocationResourceTemplates.
*/
private void populateLocationResourcesWithServiceResource(LocationResources locationResources, List<ServiceResource> services, String locationId) {
for (ServiceResource serviceResource : services) {
LocationResourceTemplate lrt = new LocationResourceTemplate();
lrt.setService(true);
lrt.setEnabled(true);
// for a service we also want to display the version, so just add it to the name
lrt.setName(serviceResource.getName() + ":" + serviceResource.getVersion());
lrt.setId(serviceResource.getId());
ServiceNodeTemplate serviceNodeTemplate = new ServiceNodeTemplate(serviceResource.getNodeInstance());
lrt.setTemplate(serviceNodeTemplate);
lrt.setLocationId(locationId);
String serviceTypeName = serviceResource.getNodeInstance().getNodeTemplate().getType();
List<String> types = Lists.newArrayList(serviceTypeName);
lrt.setTypes(types);
NodeType serviceType = toscaTypeSearchService.findOrFail(NodeType.class, serviceTypeName, serviceResource.getNodeInstance().getTypeVersion());
types.addAll(serviceType.getDerivedFrom());
locationResources.getNodeTypes().put(serviceTypeName, serviceType);
Csar csar = toscaTypeSearchService.getArchive(serviceType.getArchiveName(), serviceType.getArchiveVersion());
Set<CSARDependency> dependencies = Sets.newHashSet();
if (csar.getDependencies() != null) {
dependencies.addAll(csar.getDependencies());
}
dependencies.add(new CSARDependency(csar.getName(), csar.getVersion()));
if (serviceType.getCapabilities() != null && !serviceType.getCapabilities().isEmpty()) {
for (CapabilityDefinition capabilityDefinition : serviceType.getCapabilities()) {
locationResources.getCapabilityTypes().put(capabilityDefinition.getType(), csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), dependencies));
}
}
locationResources.getNodeTemplates().add(lrt);
}
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class LocationResourceGeneratorService method buildComputeContext.
public ComputeContext buildComputeContext(String elementType, String namePefix, String imageIdPropertyName, String flavorIdPropertyName, ILocationResourceAccessor resourceAccessor) {
ComputeContext context = new ComputeContext();
context.setFlavorIdPropertyName(flavorIdPropertyName);
context.setImageIdPropertyName(imageIdPropertyName);
context.setGeneratedNamePrefix(namePefix);
try {
NodeType nodeType = resourceAccessor.getIndexedToscaElement(elementType);
context.getNodeTypes().add(nodeType);
} catch (NotFoundException e) {
log.warn("No compute found with the element id: " + elementType, e);
}
return context;
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class TopologyService method initializeTypeLoader.
private ToscaTypeLoader initializeTypeLoader(Topology topology, boolean failOnTypeNotFound) {
// FIXME we should use ToscaContext here, and why not allowing the caller to pass ona Context?
ToscaTypeLoader loader = new ToscaTypeLoader(csarDependencyLoader);
Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, false, failOnTypeNotFound);
Map<String, RelationshipType> relationshipTypes = topologyServiceCore.getIndexedRelationshipTypesFromTopology(topology, failOnTypeNotFound);
Map<String, PolicyType> policyTypes = topologyServiceCore.getPolicyTypesFromTopology(topology, failOnTypeNotFound);
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
NodeType nodeType = nodeTypes.get(nodeTemplate.getType());
// just load found types: the type might be null when failOnTypeNotFound is set to false.
if (nodeType != null) {
loader.loadType(nodeTemplate.getType(), csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()));
}
for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
RelationshipType relationshipType = relationshipTypes.get(relationshipTemplate.getType());
// just load found types: the type might be null when failOnTypeNotFound is set to false.
if (relationshipType != null) {
loader.loadType(relationshipTemplate.getType(), csarDependencyLoader.buildDependencyBean(relationshipType.getArchiveName(), relationshipType.getArchiveVersion()));
}
}
}
for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) {
PolicyType policyType = policyTypes.get(policyTemplate.getType());
if (policyType != null) {
loader.loadType(policyTemplate.getType(), csarDependencyLoader.buildDependencyBean(policyType.getArchiveName(), policyType.getArchiveVersion()));
}
}
if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) {
NodeType substitutionType = nodeTypes.get(topology.getSubstitutionMapping().getSubstitutionType());
loader.loadType(substitutionType.getElementId(), csarDependencyLoader.buildDependencyBean(substitutionType.getArchiveName(), substitutionType.getArchiveVersion()));
for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getCapabilities()).values()) {
initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
}
for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getRequirements()).values()) {
initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
}
}
return loader;
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class TopologyService method findReplacementForNode.
/**
* Find replacements nodes for a node template
*
* @param nodeTemplateName the node to search for replacements
* @param topology the topology
* @return all possible replacement types for this node
*/
@SneakyThrows(IOException.class)
public NodeType[] findReplacementForNode(String nodeTemplateName, Topology topology) {
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateName);
Map<String, Map<String, Set<String>>> nodeTemplatesToFilters = Maps.newHashMap();
Entry<String, NodeTemplate> nodeTempEntry = Maps.immutableEntry(nodeTemplateName, nodeTemplate);
NodeType indexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
processNodeTemplate(topology, nodeTempEntry, nodeTemplatesToFilters);
List<SuggestionsTask> topoTasks = searchForNodeTypes(topology.getWorkspace(), nodeTemplatesToFilters, MapUtil.newHashMap(new String[] { nodeTemplateName }, new NodeType[] { indexedNodeType }), false);
if (CollectionUtils.isEmpty(topoTasks)) {
return null;
}
return removeDuplicatedNodeTypeForReplacement(indexedNodeType.getElementId(), topoTasks.get(0).getSuggestedNodeTypes());
}
Aggregations