Search in sources :

Example 46 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.

the class DanglingRequirementService method setPropertiesFromFilter.

// TODO This is a workaround as right now matching does not use filter but properties.
private void setPropertiesFromFilter(NodeTemplate danglingTemplate, NodeType danglingNodeType) {
    if (danglingTemplate.getNodeFilter() == null) {
        return;
    }
    for (Entry<String, List<PropertyConstraint>> constraintEntry : safe(danglingTemplate.getNodeFilter().getProperties()).entrySet()) {
        if (constraintEntry.getValue().size() == 1 && constraintEntry.getValue().get(0) instanceof EqualConstraint && ToscaTypes.isSimple(danglingNodeType.getProperties().get(constraintEntry.getKey()).getType())) {
            danglingTemplate.getProperties().put(constraintEntry.getKey(), new ScalarPropertyValue(((EqualConstraint) constraintEntry.getValue().get(0)).getEqual()));
        }
    }
    for (Entry<String, FilterDefinition> capabilityFilter : safe(danglingTemplate.getNodeFilter().getCapabilities()).entrySet()) {
        Capability capability = getCapability(danglingTemplate, capabilityFilter.getKey());
        CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
        for (Entry<String, List<PropertyConstraint>> constraintEntry : safe(capabilityFilter.getValue().getProperties()).entrySet()) {
            if (constraintEntry.getValue().size() == 1 && constraintEntry.getValue().get(0) instanceof EqualConstraint && ToscaTypes.isSimple(capabilityType.getProperties().get(constraintEntry.getKey()).getType())) {
                capability.getProperties().put(constraintEntry.getKey(), new ScalarPropertyValue(((EqualConstraint) constraintEntry.getValue().get(0)).getEqual()));
            }
        }
    }
}
Also used : FilterDefinition(org.alien4cloud.tosca.model.definitions.FilterDefinition) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) List(java.util.List) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)

Example 47 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.

the class NodeTemplateUtilsTest method getCapabilityByTypeOrFailTest.

@Test
public void getCapabilityByTypeOrFailTest() {
    NodeTemplate nodeTemplate = new NodeTemplate();
    Capability nodeCapability = new Capability("org.alien4cloud.capabilities.SampleCapability", null);
    nodeTemplate.setCapabilities(Maps.newHashMap("test", nodeCapability));
    // if the capability type exactly equals then no tosca context and request is required
    Capability capability = getCapabilityByTypeOrFail(nodeTemplate, "org.alien4cloud.capabilities.SampleCapability");
    assertSame(nodeCapability, capability);
    // if the capability derives from parent type then a TOSCA context and query is required to fetch the type.
    CapabilityType capabilityType = new CapabilityType();
    capabilityType.setElementId("org.alien4cloud.capabilities.SampleCapability");
    capabilityType.setDerivedFrom(Lists.newArrayList("org.alien4cloud.capabilities.TestCapability"));
    Mockito.reset(csarRepositorySearchService);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("org.alien4cloud.capabilities.SampleCapability"), Mockito.any(Set.class))).thenReturn(capabilityType);
    capability = toscaContextualAspect.execInToscaContext(() -> getCapabilityByTypeOrFail(nodeTemplate, "org.alien4cloud.capabilities.TestCapability"), false, Sets.newHashSet(new CSARDependency("org.alien4cloud.testArchive", "1.0.0-SNAPSHOT")));
    assertSame(nodeCapability, capability);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 48 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.

the class NodeTemplateUtilsTest method getMissingCapabilityByTypeOrFailTest.

@Test(expected = NotFoundException.class)
public void getMissingCapabilityByTypeOrFailTest() {
    NodeTemplate nodeTemplate = new NodeTemplate();
    Capability nodeCapability = new Capability("org.alien4cloud.capabilities.SampleCapability", null);
    nodeTemplate.setCapabilities(Maps.newHashMap("test", nodeCapability));
    // if the capability derives from parent type then a TOSCA context and query is required to fetch the type.
    CapabilityType capabilityType = new CapabilityType();
    capabilityType.setElementId("org.alien4cloud.capabilities.SampleCapability");
    capabilityType.setDerivedFrom(Lists.newArrayList("org.alien4cloud.capabilities.TestCapability"));
    Mockito.reset(csarRepositorySearchService);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("org.alien4cloud.capabilities.SampleCapability"), Mockito.any(Set.class))).thenReturn(capabilityType);
    Capability capability = toscaContextualAspect.execInToscaContext(() -> getCapabilityByTypeOrFail(nodeTemplate, "org.alien4cloud.capabilities.Unknown"), false, Sets.newHashSet(new CSARDependency("org.alien4cloud.testArchive", "1.0.0-SNAPSHOT")));
    assertNull(capability);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 49 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.

the class CapabilityMatcherService method getCompatibleCapabilityByType.

@Override
public Map<String, Capability> getCompatibleCapabilityByType(NodeTemplate nodeTemplate, String type) {
    Map<String, Capability> capabilities = nodeTemplate.getCapabilities();
    if (capabilities == null) {
        return Collections.emptyMap();
    }
    Map<String, Capability> targetCapabilitiesMatch = Maps.newHashMap();
    for (Map.Entry<String, Capability> capabilityEntry : capabilities.entrySet()) {
        String capabilityTypeName = capabilityEntry.getValue().getType();
        CapabilityType capabilityType = toscaContextFinder.find(CapabilityType.class, capabilityTypeName);
        if (ToscaTypeUtils.isOfType(capabilityType, type)) {
            targetCapabilitiesMatch.put(capabilityEntry.getKey(), capabilityEntry.getValue());
        }
    }
    return targetCapabilitiesMatch;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) Map(java.util.Map)

Example 50 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project yorc-a4c-plugin by ystia.

the class FipTopologyModifier method doProcess.

private void doProcess(Topology topology, FlowExecutionContext context) {
    Csar csar = new Csar(topology.getArchiveName(), topology.getArchiveVersion());
    Set<NodeTemplate> publicNetworksNodes = TopologyNavigationUtil.getNodesOfType(topology, "yorc.nodes.openstack.PublicNetwork", false);
    String fipConnectivityCap = "yorc.capabilities.openstack.FIPConnectivity";
    String fipNodeType = "yorc.nodes.openstack.FloatingIP";
    NodeType fipType = toscaTypeSearchService.findMostRecent(NodeType.class, fipNodeType);
    Set<NodeTemplate> nodesToRemove = new HashSet<NodeTemplate>();
    List<NetworkRelationshipConfig> relationshipsToAdd = new ArrayList<NetworkRelationshipConfig>();
    publicNetworksNodes.forEach(networkNodeTemplate -> {
        final AbstractPropertyValue networkName = networkNodeTemplate.getProperties().get("floating_network_name");
        // Network, creating a new Floating IP Node Template
        for (NodeTemplate nodeTemplate : new ArrayList<>(topology.getNodeTemplates().values())) {
            if (nodeTemplate.getRelationships() == null)
                continue;
            nodeTemplate.getRelationships().forEach((rel, relationshipTemplate) -> {
                if (relationshipTemplate.getTarget().equals(networkNodeTemplate.getName())) {
                    Map<String, AbstractPropertyValue> properties = new LinkedHashMap<>();
                    properties.put("floating_network_name", networkName);
                    Map<String, Capability> capabilities = new LinkedHashMap<>();
                    Capability connectionCap = new Capability();
                    connectionCap.setType(fipConnectivityCap);
                    capabilities.put("connection", connectionCap);
                    if (fipType == null) {
                        context.log().error("Node type with name <{}> cannot be found in the catalog.", fipNodeType);
                        return;
                    }
                    // Creating a new Floating IP Node Template that will be
                    // associated to this Node Template requiring a
                    // connection to the Public Network
                    String fipName = "FIP" + nodeTemplate.getName();
                    NodeTemplate fipNodeTemplate = addNodeTemplate(csar, topology, fipName, fipType.getElementId(), fipType.getArchiveVersion());
                    fipNodeTemplate.setProperties(properties);
                    fipNodeTemplate.setCapabilities(capabilities);
                    // The public network Node Template will be removed
                    // now that a Floating IP Node Template Node
                    // provides the required connectivity
                    nodesToRemove.add(networkNodeTemplate);
                    // Creating a new relationship between the Node template
                    // and the Floating IP node.
                    // Not attempting to re-use/modify the relationship
                    // existing between the Node Template and the Public
                    // Network, as once the Public Network will be removed,
                    // all related relationhips will be removed.
                    // The new relationship will be created outside of the
                    // foreach loops, as its creation modifies elements on
                    // which these loops are iterating.
                    relationshipsToAdd.add(new NetworkRelationshipConfig(// source
                    nodeTemplate, // target
                    fipNodeTemplate.getName(), relationshipTemplate.getRequirementName(), relationshipTemplate.getTargetedCapabilityName()));
                    context.log().info("<{}> created to provide a Floating IP address to <{}> on network <{}>", fipName, nodeTemplate.getName(), networkNodeTemplate.getName());
                }
            });
        }
    });
    // Removing Public Network nodes for which a new Floating IP Node
    // template was created
    nodesToRemove.forEach(pnn -> removeNode(topology, pnn));
    // Creating a relationship between each new Floating IP Node Template
    // and the Source Node Template having a connectivity requirement
    relationshipsToAdd.forEach(rel -> addRelationshipTemplate(csar, topology, rel.sourceNode, rel.targetNodeName, NormativeRelationshipConstants.NETWORK, rel.requirementName, rel.targetCapabilityName));
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Capability(org.alien4cloud.tosca.model.templates.Capability) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) HashSet(java.util.HashSet)

Aggregations

Capability (org.alien4cloud.tosca.model.templates.Capability)50 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)27 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)26 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)14 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)12 Map (java.util.Map)10 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 NotFoundException (alien4cloud.exception.NotFoundException)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 Test (org.junit.Test)9 Set (java.util.Set)8 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 HashMap (java.util.HashMap)4 List (java.util.List)4 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 Location (alien4cloud.model.orchestrators.locations.Location)3 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)3