Search in sources :

Example 26 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class MockPaaSProvider method switchMaintenanceMode.

@Override
public void switchMaintenanceMode(PaaSDeploymentContext deploymentContext, boolean maintenanceModeOn) {
    String deploymentPaaSId = deploymentContext.getDeploymentPaaSId();
    MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentContext.getDeploymentPaaSId());
    Topology topology = runtimeDeploymentInfo.getDeploymentContext().getDeploymentTopology();
    Map<String, Map<String, InstanceInformation>> nodes = runtimeDeploymentInfo.getInstanceInformations();
    if (nodes == null || nodes.isEmpty()) {
        return;
    }
    for (Entry<String, Map<String, InstanceInformation>> nodeEntry : nodes.entrySet()) {
        String nodeTemplateId = nodeEntry.getKey();
        Map<String, InstanceInformation> nodeInstances = nodeEntry.getValue();
        if (nodeInstances != null && !nodeInstances.isEmpty()) {
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateId);
            NodeType nodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
            if (ToscaTypeUtils.isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE)) {
                for (Entry<String, InstanceInformation> nodeInstanceEntry : nodeInstances.entrySet()) {
                    String instanceId = nodeInstanceEntry.getKey();
                    InstanceInformation instanceInformation = nodeInstanceEntry.getValue();
                    if (instanceInformation != null) {
                        switchInstanceMaintenanceMode(deploymentPaaSId, nodeTemplateId, instanceId, instanceInformation, maintenanceModeOn);
                    }
                }
            }
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map)

Example 27 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class LocationResourceService method setTemplateCapabilityProperty.

private void setTemplateCapabilityProperty(LocationResourceTemplate resourceTemplate, String capabilityName, String propertyName, Object propertyValue) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
    Location location = locationService.getOrFail(resourceTemplate.getLocationId());
    NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, resourceTemplate.getTemplate().getType(), location.getDependencies());
    Capability capability = getOrFailCapability(resourceTemplate.getTemplate(), capabilityName);
    CapabilityDefinition capabilityDefinition = getOrFailCapabilityDefinition(resourceType, capabilityName);
    CapabilityType capabilityType = csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), location.getDependencies());
    PropertyDefinition propertyDefinition = getOrFailCapabilityPropertyDefinition(capabilityType, propertyName);
    propertyService.setCapabilityPropertyValue(location.getDependencies(), capability, propertyDefinition, propertyName, propertyValue);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Location(alien4cloud.model.orchestrators.locations.Location)

Example 28 with NodeType

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

Example 29 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class PluginArchiveIndexer method publishLocationTypeIndexedEvent.

private void publishLocationTypeIndexedEvent(Collection<NodeType> collection, IOrchestratorPluginFactory orchestratorFactory, Location location) {
    if (CollectionUtils.isNotEmpty(collection)) {
        for (NodeType nodeType : collection) {
            LocationTypeIndexed event = new LocationTypeIndexed(this);
            event.setNodeType(nodeType);
            event.setLocation(location);
            event.setOrchestratorFactory(orchestratorFactory);
            applicationContext.publishEvent(event);
        }
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) LocationTypeIndexed(alien4cloud.events.LocationTypeIndexed)

Example 30 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType 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)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7