use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class PostMatchingNodeSetupModifier method doMergeNode.
@Override
protected boolean doMergeNode(Topology topology, FlowExecutionContext context, String nodeTemplateId, NodePropsOverride nodePropsOverride) {
final ConfigChanged configChanged = new ConfigChanged();
// play the super method first. This will process nodetemplate properties
configChanged.changed = super.doMergeNode(topology, context, nodeTemplateId, nodePropsOverride);
// Then process capabilities
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateId);
Iterator<Entry<String, NodeCapabilitiesPropsOverride>> capabilitiesOverrideIter = safe(nodePropsOverride.getCapabilities()).entrySet().iterator();
while (capabilitiesOverrideIter.hasNext()) {
Entry<String, NodeCapabilitiesPropsOverride> overrideCapabilityProperties = capabilitiesOverrideIter.next();
Capability capability = safe(nodeTemplate.getCapabilities()).get(overrideCapabilityProperties.getKey());
if (capability == null) {
// Manage clean logic
configChanged.changed = true;
capabilitiesOverrideIter.remove();
} else {
// Merge logic
// When a selected node has changed we may need to cleanup properties that where defined but are not anymore on the capability
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
capability.setProperties(mergeProperties(overrideCapabilityProperties.getValue().getProperties(), capability.getProperties(), capabilityType.getProperties(), s -> {
configChanged.changed = true;
context.log().info("The property [" + s + "] previously specified to configure capability [" + overrideCapabilityProperties.getKey() + "] of node [" + nodeTemplateId + "] cannot be set anymore as it is already specified by the matched location resource or in the topology.");
}));
}
}
return configChanged.changed;
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class InputPropertiesStepDefinitions method i_define_the_capability_property_of_the_node_of_typeId_as_input_property.
@Given("^I define the capability \"(.*?)\" property \"(.*?)\" of the node \"(.*?)\" as input property$")
public void i_define_the_capability_property_of_the_node_of_typeId_as_input_property(String capabilityName, String propertyName, String nodeName) throws Throwable {
String url = String.format("/rest/v1/topologies/%s", Context.getInstance().getTopologyId());
String response = Context.getRestClientInstance().get(url);
TopologyDTO topologyDTO = JsonUtil.read(response, TopologyDTO.class, Context.getJsonMapper()).getData();
NodeTemplate template = MapUtils.getObject(topologyDTO.getTopology().getNodeTemplates(), nodeName);
Capability capability = template.getCapabilities().get(capabilityName);
CapabilityType capabilityType = topologyDTO.getCapabilityTypes().get(capability.getType());
PropertyDefinition propertyDefinition = capabilityType.getProperties().get(propertyName);
String fullUrl = String.format("/rest/v1/topologies/%s/inputs/%s", Context.getInstance().getTopologyId(), propertyName);
String json = JsonUtil.toString(propertyDefinition);
Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(fullUrl, json));
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class NodeInstanceService method updateCapabilities.
private void updateCapabilities(NodeTemplate nodeTemplate, Map<String, Capability> nodeCapabilities) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
for (Map.Entry<String, Capability> entry : nodeCapabilities.entrySet()) {
if (entry != null) {
Capability patchCapability = PatchUtil.realValue(entry.getValue());
if (patchCapability == null) {
throw new IllegalArgumentException("It is not allowed to set null to a capability.");
} else {
Capability targetCapability = nodeTemplate.getCapabilities().get(entry.getKey());
if (targetCapability == null) {
throw new NotFoundException("Capability <" + entry.getKey() + "> doesn't exists on the node.");
}
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, targetCapability.getType());
updateCapabilitiesProperties(capabilityType, targetCapability, patchCapability);
}
}
}
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class NodeTemplateUtilsTest method getCapabilityByTypeTest.
@Test
public void getCapabilityByTypeTest() {
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 = getCapabilityByType(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(() -> getCapabilityByType(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.types.CapabilityType in project alien4cloud by alien4cloud.
the class NodeTemplateUtilsTest method getMissingCapabilityByTypeTest.
@Test
public void getMissingCapabilityByTypeTest() {
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(() -> getCapabilityByType(nodeTemplate, "org.alien4cloud.capabilities.Unknown"), false, Sets.newHashSet(new CSARDependency("org.alien4cloud.testArchive", "1.0.0-SNAPSHOT")));
assertNull(capability);
}
Aggregations