Search in sources :

Example 56 with AbstractPropertyValue

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

Example 57 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project yorc-a4c-plugin by ystia.

the class MappingTosca method quoteProperties.

public static void quoteProperties(final PaaSTopologyDeploymentContext ctx) {
    PaaSTopology ptopo = ctx.getPaaSTopology();
    for (PaaSNodeTemplate node : ptopo.getAllNodes().values()) {
        NodeTemplate nt = node.getTemplate();
        Map<String, AbstractPropertyValue> ntProperties = nt.getProperties();
        for (String prop : ntProperties.keySet()) {
            AbstractPropertyValue absval = ntProperties.get(prop);
            if (absval instanceof ScalarPropertyValue) {
                ScalarPropertyValue scaval = (ScalarPropertyValue) absval;
                if (scaval.getValue().contains("\"")) {
                    scaval.setValue(scaval.getValue().replace("\"", "\\\""));
                }
                log.debug("Property: " + prop + "=" + ((ScalarPropertyValue) nt.getProperties().get(prop)).getValue());
            }
        }
    }
}
Also used : PaaSTopology(alien4cloud.paas.model.PaaSTopology) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)57 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)23 Map (java.util.Map)18 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)14 Capability (org.alien4cloud.tosca.model.templates.Capability)14 NotFoundException (alien4cloud.exception.NotFoundException)10 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)9 Test (org.junit.Test)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)7 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)7 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)5 List (java.util.List)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)4 ListPropertyValue (org.alien4cloud.tosca.model.definitions.ListPropertyValue)4 HashMap (java.util.HashMap)3