use of org.alien4cloud.tosca.model.templates.Capability in project yorc-a4c-plugin by ystia.
the class ShowTopology method printNode.
/**
* Print info about a Node
* @param node
*/
private static void printNode(PaaSNodeTemplate node) {
log.debug("******* Compute Node " + node.getId() + " *******");
NodeTemplate nt = node.getTemplate();
log.debug("CsarPath = " + node.getCsarPath());
log.debug("Type = " + nt.getType());
// Children
List<PaaSNodeTemplate> children = node.getChildren();
for (PaaSNodeTemplate child : children) {
log.info("Child: " + child.getId());
}
// properties
for (String prop : nt.getProperties().keySet()) {
AbstractPropertyValue absval = nt.getProperties().get(prop);
if (absval instanceof ScalarPropertyValue) {
ScalarPropertyValue scaval = (ScalarPropertyValue) absval;
log.debug(">> Property: " + prop + "=" + scaval.getValue());
}
}
// Attributes
Map<String, IValue> attrs = nt.getAttributes();
if (attrs != null) {
for (String attname : attrs.keySet()) {
IValue att = attrs.get(attname);
log.debug(">> Attribute: " + attname + "=" + att);
}
}
// capabilities
Map<String, Capability> capabilities = nt.getCapabilities();
if (capabilities != null) {
for (String capname : capabilities.keySet()) {
Capability cap = capabilities.get(capname);
log.debug(">> Capability " + capname);
log.debug("type : " + cap.getType());
log.debug("properties : " + cap.getProperties());
}
}
// requirements
Map<String, Requirement> requirements = nt.getRequirements();
if (requirements != null) {
for (String reqname : requirements.keySet()) {
Requirement req = requirements.get(reqname);
log.debug(">> Requirement: " + reqname);
log.debug("type : " + req.getType());
log.debug("properties : " + req.getProperties());
}
}
// relationships
Map<String, RelationshipTemplate> relations = nt.getRelationships();
if (relations != null) {
for (String relname : relations.keySet()) {
RelationshipTemplate rel = relations.get(relname);
log.debug(">> Relationship: " + relname);
log.debug("type : " + rel.getType());
log.debug("properties : " + rel.getProperties());
}
}
// artifacts
Map<String, DeploymentArtifact> artifacts = nt.getArtifacts();
if (artifacts != null) {
for (DeploymentArtifact art : artifacts.values()) {
printArtifact(art);
}
}
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class FunctionEvaluator method doGetProperty.
private static AbstractPropertyValue doGetProperty(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, FunctionPropertyValue function) {
if (targetTemplate == null) {
return null;
}
// If a requirement or capability name is defined then it is applied to the node template.
if (function.getCapabilityOrRequirementName() != null) {
if (targetTemplate instanceof RelationshipTemplate) {
throw new IllegalArgumentException("Get property that specifies a capability or relationship target must be placed on a node template and not a relationship template.");
}
AbstractPropertyValue propertyValue = null;
Capability targetCapability = safe(((NodeTemplate) targetTemplate).getCapabilities()).get(function.getCapabilityOrRequirementName());
if (targetCapability != null) {
propertyValue = getFromPath(evaluatorContext, targetTemplate, targetCapability.getProperties(), function.getElementNameToFetch());
}
if (propertyValue == null) {
Requirement requirement = safe(((NodeTemplate) targetTemplate).getRequirements()).get(function.getCapabilityOrRequirementName());
if (requirement != null) {
propertyValue = getFromPath(evaluatorContext, targetTemplate, requirement.getProperties(), function.getElementNameToFetch());
}
}
if (propertyValue == null) {
// try to find the value from the host node.
propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
}
return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
}
// Try to fetch from the node.
AbstractPropertyValue propertyValue = getFromPath(evaluatorContext, targetTemplate, targetTemplate.getProperties(), function.getElementNameToFetch());
if (propertyValue == null && targetTemplate instanceof NodeTemplate) {
propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
}
// if the property refers to a function (get_input/get_property then try to resolve it).
return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class SetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} does not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
if (operation.getCapabilityName().equals(FORBIDDEN_CAPABILITY)) {
throw new UnsupportedSecretException("We cannot set a secret on the capability " + operation.getCapabilityName());
}
if ("".equals(operation.getSecretPath())) {
throw new InvalidSecretPathException("The secret path to the property " + operation.getPropertyName() + "is null.");
}
FunctionPropertyValue getSecret = new FunctionPropertyValue();
getSecret.setFunction(ToscaFunctionConstants.GET_SECRET);
getSecret.setParameters(Arrays.asList(operation.getSecretPath()));
nodeTemplate.getCapabilities().get(operation.getCapabilityName()).getProperties().put(operation.getPropertyName(), getSecret);
log.debug("Set the property [ {} ] of capability template [ {} ] of node [ {} ] to the secret path [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class UnsetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
// check if the node property value is a get_secret
AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
if (currentValue != null && !isGetSecret(currentValue)) {
throw new NotFoundException("Property {} of node {} is not an secret.", operation.getPropertyName(), operation.getNodeName());
}
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
log.debug("Remove secret property [ {} ] of capability template [ {} ] of node [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class PaaSUtilsTest method buildPaaSNodeTemplate.
private PaaSNodeTemplate buildPaaSNodeTemplate() {
Map<String, Capability> capabilities = Maps.newHashMap();
capabilities.put(fakeCapa1, buildFakeCapability());
NodeTemplate nodeTemplate = buildFakeNodeTemplate(capabilities);
Map<String, Operation> operations = Maps.newHashMap();
operations.put(operation1, buildFakeOperation());
Map<String, Interface> interfaces = Maps.newHashMap();
interfaces.put(interface1, buildFakeInterface(operations));
return buildFakePaaSNodeTemplate(nodeTemplate, interfaces);
}
Aggregations