Search in sources :

Example 1 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.

the class EsDaoPaginatedSearchTest method saveDataToES.

private void saveDataToES() throws IOException, IndexingServiceException {
    testDataList.clear();
    Path path = Paths.get("src/test/resources/nodetypes-faceted-search-result.json");
    FacetedSearchResult res = jsonMapper.readValue(path.toFile(), FacetedSearchResult.class);
    Object[] data = res.getData();
    for (Object element : data) {
        String serializeDatum = jsonMapper.writeValueAsString(element);
        NodeType indexedNodeType = jsonMapper.readValue(serializeDatum, NodeType.class);
        indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
        String typeName = MappingBuilder.indexTypeFromClass(NodeType.class);
        dao.save(indexedNodeType);
        assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName, indexedNodeType.getId(), true);
        testDataList.add(indexedNodeType);
        for (CapabilityDefinition capaDef : indexedNodeType.getCapabilities()) {
            if (capaDef.getType().equals("jndi")) {
                jndiTestDataList.add(indexedNodeType);
            }
        }
    }
    refresh();
}
Also used : Path(java.nio.file.Path) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult)

Example 2 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method fillCapabilities.

private void fillCapabilities(Topology topology, NodeType substituteNodeType) {
    if (topology.getSubstitutionMapping().getCapabilities() != null) {
        for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getCapabilities().entrySet()) {
            String key = e.getKey();
            String nodeName = e.getValue().getNodeTemplateName();
            String capabilityName = e.getValue().getTargetId();
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
            NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
            CapabilityDefinition capabilityDefinition = IndexedModelUtils.getCapabilityDefinitionById(nodeTemplateType.getCapabilities(), capabilityName);
            // We cannot change the capability definition here or we will change the original one so we need a clone
            capabilityDefinition = CloneUtil.clone(capabilityDefinition);
            capabilityDefinition.setId(key);
            substituteNodeType.getCapabilities().add(capabilityDefinition);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) Map(java.util.Map)

Example 3 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.

the class TopologyDTOBuilder method getCapabilityTypes.

private <T extends Topology> Map<String, CapabilityType> getCapabilityTypes(AbstractTopologyDTO<T> topologyDTO) {
    Map<String, CapabilityType> types = Maps.newHashMap();
    Map<String, NodeType> delayedNodeTypeAddMap = Maps.newHashMap();
    for (NodeType nodeType : topologyDTO.getNodeTypes().values()) {
        if (nodeType != null) {
            for (CapabilityDefinition capabilityDefinition : safe(nodeType.getCapabilities())) {
                types.put(capabilityDefinition.getType(), ToscaContext.get(CapabilityType.class, capabilityDefinition.getType()));
            }
            for (RequirementDefinition requirementDefinition : safe(nodeType.getRequirements())) {
                CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, requirementDefinition.getType());
                if (capabilityType != null) {
                    types.put(requirementDefinition.getType(), capabilityType);
                } else {
                    // requirements are authorized to be a node type rather than a capability type TODO is it still possible in TOSCA ?
                    NodeType indexedNodeType = ToscaContext.get(NodeType.class, requirementDefinition.getType());
                    // add it to the actual node types map
                    delayedNodeTypeAddMap.put(requirementDefinition.getType(), indexedNodeType);
                }
            }
        }
    }
    for (Map.Entry<String, NodeType> delayedNodeType : delayedNodeTypeAddMap.entrySet()) {
        topologyDTO.getNodeTypes().put(delayedNodeType.getKey(), delayedNodeType.getValue());
    }
    return types;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.

the class EditorTopologyRecoveryHelperService method checkCapability.

/**
 * validate that a node still has a capability, by checkibg directly from the related node type
 *
 * @param capabilityName The name of the capability to check
 * @param nodeTemplate The node template in which to check for the capability
 */
private void checkCapability(String capabilityName, NodeTemplate nodeTemplate) {
    // FIXME check if the relationship is still valid concerning binded capability
    // This call should never throw a NotFoundException
    NodeType indexedNodeType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
    Map<String, CapabilityDefinition> capabilitiesMap = AlienUtils.fromListToMap(indexedNodeType.getCapabilities(), "id", true);
    if (!AlienUtils.safe(capabilitiesMap).containsKey(capabilityName)) {
        throw new InvalidStateException("A capability with name [" + capabilityName + "] cannot be found in the node [" + nodeTemplate.getName() + "].");
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition)

Example 5 with CapabilityDefinition

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

Aggregations

CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)24 NodeType (org.alien4cloud.tosca.model.types.NodeType)16 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)11 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)9 Capability (org.alien4cloud.tosca.model.templates.Capability)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 ArrayList (java.util.ArrayList)4 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)4 Date (java.util.Date)3 Map (java.util.Map)3 Csar (org.alien4cloud.tosca.model.Csar)3 FacetedSearchResult (alien4cloud.dao.model.FacetedSearchResult)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2 HashMap (java.util.HashMap)2 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)2 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)2 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)2 RelationshipEntry (org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry)2 Test (org.junit.Test)2