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