Search in sources :

Example 11 with CapabilityDefinition

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

the class SearchDefinitionSteps method createAndIndexComponent.

private void createAndIndexComponent(int count, String type, String baseName, int countHavingProperty, String property, String propertyValue) throws Exception {
    testDataList.clear();
    Class<?> clazz = QUERY_TYPES.get(type).getIndexedToscaElementClass();
    String typeName = MappingBuilder.indexTypeFromClass(clazz);
    int remaining = countHavingProperty;
    baseName = baseName == null || baseName.isEmpty() ? typeName : baseName;
    for (int i = 0; i < count; i++) {
        AbstractToscaType componentTemplate = (AbstractToscaType) clazz.newInstance();
        String elementId = baseName + "_" + i;
        componentTemplate.setElementId(elementId);
        componentTemplate.setArchiveVersion(DEFAULT_ARCHIVE_VERSION);
        componentTemplate.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
        if (property != null && remaining > 0) {
            if (type.equalsIgnoreCase("node types")) {
                switch(property) {
                    case "capability":
                        ((NodeType) componentTemplate).setCapabilities(Lists.newArrayList(new CapabilityDefinition(propertyValue, propertyValue, 1)));
                        break;
                    case "requirement":
                        ((NodeType) componentTemplate).setRequirements((Lists.newArrayList(new RequirementDefinition(propertyValue, propertyValue))));
                        break;
                    case "default capability":
                        ((NodeType) componentTemplate).setDefaultCapabilities((Lists.newArrayList(propertyValue)));
                        break;
                    case "elementId":
                        ((NodeType) componentTemplate).setElementId(propertyValue);
                        break;
                    default:
                        break;
                }
            } else if (type.equalsIgnoreCase("relationship types")) {
                ((RelationshipType) componentTemplate).setValidSources(new String[] { propertyValue });
            }
            remaining -= 1;
        }
        String serializeDatum = JsonUtil.toString(componentTemplate);
        log.debug("Saving in ES: " + serializeDatum);
        esClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName).setSource(serializeDatum).setRefresh(true).execute().actionGet();
        if (componentTemplate instanceof NodeType) {
            testDataList.add((NodeType) (componentTemplate));
        }
    }
    indexedComponentTypes.put(type, typeName);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition)

Example 12 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition 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);
    }
}
Also used : ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) ServiceResource(alien4cloud.model.service.ServiceResource) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 13 with CapabilityDefinition

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

the class TopologyCapabilityBoundsValidationServices method isCapabilityUpperBoundReachedForTarget.

// 
public boolean isCapabilityUpperBoundReachedForTarget(String nodeTemplateName, Map<String, NodeTemplate> nodeTemplates, String capabilityName, Set<CSARDependency> dependencies) {
    NodeTemplate nodeTemplate = nodeTemplates.get(nodeTemplateName);
    NodeType relatedIndexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), dependencies);
    chekCapability(nodeTemplateName, capabilityName, nodeTemplate);
    CapabilityDefinition capabilityDefinition = getCapabilityDefinition(relatedIndexedNodeType.getCapabilities(), capabilityName);
    if (capabilityDefinition.getUpperBound() == Integer.MAX_VALUE) {
        return false;
    }
    List<RelationshipEntry> targetRelatedRelationships = TopologyUtils.getTargetRelationships(nodeTemplateName, nodeTemplates);
    if (targetRelatedRelationships == null || targetRelatedRelationships.isEmpty()) {
        return false;
    }
    int count = 0;
    for (RelationshipEntry relationshipEntry : targetRelatedRelationships) {
        if (relationshipEntry.getRelationship().getTargetedCapabilityName().equals(capabilityName)) {
            count++;
        }
    }
    return count >= capabilityDefinition.getUpperBound();
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipEntry(org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition)

Example 14 with CapabilityDefinition

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

the class ServiceResourceService method validateRelationshipTypes.

private void validateRelationshipTypes(ServiceResource serviceResource, final NodeType nodeType) {
    safe(serviceResource.getCapabilitiesRelationshipTypes()).forEach((capabilityName, relationshipTypeId) -> {
        RelationshipType relationshipType = toscaTypeSearchService.findByIdOrFail(RelationshipType.class, relationshipTypeId);
        String[] validTargets = relationshipType.getValidTargets();
        if (ArrayUtils.isNotEmpty(validTargets)) {
            CapabilityDefinition capabilityDefinition = nodeType.getCapabilities().stream().filter(c -> c.getId().equals(capabilityName)).findFirst().get();
            Csar csar = toscaTypeSearchService.getArchive(nodeType.getArchiveName(), nodeType.getArchiveVersion());
            Set<CSARDependency> allDependencies = new HashSet<>(safe(csar.getDependencies()));
            allDependencies.add(new CSARDependency(csar.getName(), csar.getVersion(), csar.getHash()));
            CapabilityType capabilityType = toscaTypeSearchService.getElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), allDependencies);
            Set<String> allAcceptedTypes = new HashSet<>();
            allAcceptedTypes.addAll(capabilityType.getDerivedFrom());
            allAcceptedTypes.add(capabilityType.getElementId());
            boolean isValid = false;
            for (String validTarget : validTargets) {
                if (allAcceptedTypes.contains(validTarget)) {
                    isValid = true;
                    break;
                }
            }
            if (!isValid) {
                throw new IncompatibleHalfRelationshipException("[" + relationshipType.getId() + "] is not compatible with [" + capabilityType.getId() + "]");
            }
        }
    });
    safe(serviceResource.getRequirementsRelationshipTypes()).forEach((k, v) -> {
        toscaTypeSearchService.findByIdOrFail(RelationshipType.class, v);
    });
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) IncompatibleHalfRelationshipException(org.alien4cloud.alm.service.exceptions.IncompatibleHalfRelationshipException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) HashSet(java.util.HashSet)

Example 15 with CapabilityDefinition

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

the class EsDaoCrudTest method prepareToscaElement.

private void prepareToscaElement() {
    List<CapabilityDefinition> capa = Arrays.asList(new CapabilityDefinition("container", "container", 1), new CapabilityDefinition("container1", "container1", 1), new CapabilityDefinition("container2", "container2", 1), new CapabilityDefinition("container3", "container3", 1));
    List<RequirementDefinition> req = Arrays.asList(new RequirementDefinition("Runtime", "Runtime"), new RequirementDefinition("server", "server"), new RequirementDefinition("blob", "blob"));
    List<String> der = Arrays.asList("Parent1", "Parent2");
    indexedNodeTypeTest = TestModelUtil.createIndexedNodeType("1", "positive", "1.0", "", capa, req, der, new ArrayList<String>(0), threeTags, new Date(), new Date());
}
Also used : ArrayList(java.util.ArrayList) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Date(java.util.Date)

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