Search in sources :

Example 11 with LocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.LocationResourceTemplate in project alien4cloud by alien4cloud.

the class LocationService method autoConfigure.

/**
 * Trigger plugin auto-configuration for the given location.
 *
 * @param locationId Id of the location.
 */
public List<LocationResourceTemplate> autoConfigure(String locationId) throws UnsupportedOperationException {
    Location location = getOrFail(locationId);
    Orchestrator orchestrator = orchestratorService.getOrFail(location.getOrchestratorId());
    List<LocationResourceTemplate> generatedLocationResources = autoConfigure(orchestrator, location);
    if (CollectionUtils.isEmpty(generatedLocationResources)) {
        generatedLocationResources = Lists.newArrayList();
    }
    return generatedLocationResources;
}
Also used : LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) Location(alien4cloud.model.orchestrators.locations.Location)

Example 12 with LocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.LocationResourceTemplate 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;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 13 with LocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.LocationResourceTemplate 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 14 with LocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.LocationResourceTemplate 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)

Example 15 with LocationResourceTemplate

use of alien4cloud.model.orchestrators.locations.LocationResourceTemplate in project alien4cloud by alien4cloud.

the class LocationResourceService method setTemplateCapabilityProperty.

/*
     * (non-Javadoc)
     * 
     * @see alien4cloud.orchestrators.locations.services.ILocationResourceService#setTemplateCapabilityProperty(java.lang.String, java.lang.String,
     * java.lang.String, java.lang.Object)
     */
@Override
public void setTemplateCapabilityProperty(String resourceId, String capabilityName, String propertyName, Object propertyValue) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
    LocationResourceTemplate resourceTemplate = getOrFail(resourceId);
    setTemplateCapabilityProperty(resourceTemplate, capabilityName, propertyName, propertyValue);
    saveResource(resourceTemplate);
}
Also used : PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate)

Aggregations

LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)27 NodeType (org.alien4cloud.tosca.model.types.NodeType)14 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)11 Test (org.junit.Test)11 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)6 PolicyLocationResourceTemplate (alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate)6 ILocationResourceAccessor (alien4cloud.orchestrators.plugin.ILocationResourceAccessor)6 HashMap (java.util.HashMap)6 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)5 Location (alien4cloud.model.orchestrators.locations.Location)4 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)3 LocationResources (alien4cloud.model.orchestrators.locations.LocationResources)3 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)3 ServiceResource (alien4cloud.model.service.ServiceResource)2 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)2 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)2 List (java.util.List)2 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)2 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)2 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)1