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));
}
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());
}
}
}
}
Aggregations