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