use of alien4cloud.exception.NotFoundException 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 alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class ToscaTypeConverter method toPropertyValue.
@SuppressWarnings("unchecked")
public PropertyValue toPropertyValue(Object resolvedPropertyValue, PropertyDefinition propertyDefinition) {
if (resolvedPropertyValue == null) {
return null;
}
if (ToscaTypes.isSimple(propertyDefinition.getType())) {
return new ScalarPropertyValue(resolvedPropertyValue.toString());
}
switch(propertyDefinition.getType()) {
case ToscaTypes.MAP:
if (resolvedPropertyValue instanceof Map) {
Map<String, Object> map = (Map<String, Object>) resolvedPropertyValue;
Map<String, Object> resultMap = Maps.newHashMap();
map.forEach((key, value) -> resultMap.put(key, toPropertyValue(value, propertyDefinition.getEntrySchema())));
return new ComplexPropertyValue(resultMap);
} else {
throw new IllegalStateException("Property value: expected type [" + Map.class.getSimpleName() + "] but got [" + resolvedPropertyValue.getClass().getName() + "]");
}
case ToscaTypes.LIST:
if (resolvedPropertyValue instanceof Collection) {
List list = (List) resolvedPropertyValue;
List resultList = new LinkedList();
for (Object item : list) {
resultList.add(toPropertyValue(item, propertyDefinition.getEntrySchema()));
}
return new ListPropertyValue(resultList);
} else {
throw new IllegalStateException("Property value: expected type [" + Collection.class.getSimpleName() + "] but got [" + resolvedPropertyValue.getClass().getName() + "]");
}
default:
DataType dataType = findDataType(propertyDefinition.getType());
if (dataType == null) {
throw new NotFoundException("Data type [" + propertyDefinition.getType() + "] cannot be found");
}
if (dataType.isDeriveFromSimpleType()) {
return new ScalarPropertyValue(resolvedPropertyValue.toString());
} else if (resolvedPropertyValue instanceof Map) {
Map<String, Object> map = (Map<String, Object>) resolvedPropertyValue;
/*
* Map<String, Object> resultMap = Maps.newHashMap();
*
* map.forEach((key, value) -> {
* PropertyDefinition entryDefinition = dataType.getProperties().get(key);
* if(entryDefinition == null){
* throw new IllegalStateException("DataType [" + propertyDefinition.getType() + "] does not contains any definition for entry [" + key + "]");
* }
* resultMap.put(key, toPropertyValue(value, entryDefinition));
* });
* return new ComplexPropertyValue(resultMap);
*/
return new ComplexPropertyValue(map);
} else {
throw new IllegalStateException("Property value: expected type [" + propertyDefinition.getType() + "] but got [" + resolvedPropertyValue.getClass().getName() + "]");
}
}
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class AddCapabilitySubstitutionTypeProcessor method process.
@Override
public void process(Csar csar, Topology topology, AddCapabilitySubstitutionTypeOperation operation) {
if (topology.getNodeTemplates() == null || !topology.getNodeTemplates().containsKey(operation.getNodeTemplateName())) {
throw new NotFoundException("Node " + operation.getNodeTemplateName() + " do not exist");
}
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(operation.getNodeTemplateName());
if (nodeTemplate.getCapabilities() == null || !nodeTemplate.getCapabilities().containsKey(operation.getCapabilityId())) {
throw new NotFoundException("Capability " + operation.getCapabilityId() + " do not exist for node " + operation.getNodeTemplateName());
}
if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
throw new NotFoundException("No substitution type has been found");
}
Map<String, SubstitutionTarget> substitutionCapabilities = topology.getSubstitutionMapping().getCapabilities();
if (substitutionCapabilities == null) {
substitutionCapabilities = Maps.newHashMap();
topology.getSubstitutionMapping().setCapabilities(substitutionCapabilities);
} else if (substitutionCapabilities.containsKey(operation.getSubstitutionCapabilityId())) {
// ensure name unicity
throw new AlreadyExistException(String.format("A substitution with capability id <%s> already exists", operation.getSubstitutionCapabilityId()));
}
substitutionCapabilities.put(operation.getSubstitutionCapabilityId(), new SubstitutionTarget(operation.getNodeTemplateName(), operation.getCapabilityId()));
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class AddSubstitutionTypeProcessor method process.
@Override
public void process(Csar csar, Topology topology, AddSubstitutionTypeOperation operation) {
if (topology.getSubstitutionMapping() == null) {
topology.setSubstitutionMapping(new SubstitutionMapping());
}
NodeType nodeType = toscaTypeSearchService.getElementInDependencies(NodeType.class, operation.getElementId(), topology.getDependencies());
// if not null the node type exists in the dependencies, there is no choices for this type version
if (nodeType == null) {
// the node type does'nt exist in this topology dependencies
// we need to find the latest version of this component and use it as default
nodeType = toscaTypeSearchService.findMostRecent(NodeType.class, operation.getElementId());
if (nodeType == null) {
throw new NotFoundException("Node type with name <" + operation.getElementId() + "> cannot be found in the catalog.");
}
topologyService.loadType(topology, nodeType);
}
topology.getSubstitutionMapping().setSubstitutionType(operation.getElementId());
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class RemoveCapabilitySubstitutionTypeProcessor method process.
@Override
public void process(Csar csar, Topology topology, RemoveCapabilitySubstitutionTypeOperation operation) {
if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
throw new NotFoundException("No substitution type has been found");
}
Map<String, SubstitutionTarget> substitutionCapabilities = topology.getSubstitutionMapping().getCapabilities();
if (substitutionCapabilities == null) {
throw new NotFoundException("No substitution capabilities has been found");
}
SubstitutionTarget target = substitutionCapabilities.remove(operation.getSubstitutionCapabilityId());
if (target == null) {
throw new NotFoundException("No substitution capability has been found for key " + operation.getSubstitutionCapabilityId());
}
}
Aggregations